| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use \think\Request;
- use \think\Db;
- use const http\Client\Curl\IPRESOLVE_V4;
- class WorkOrderSpotCheck extends Api{
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- /**
- * index测试接口是否
- */
- public function index() {$this->success('请求成功');}
- /**
- * 报工查询接口
- *
- */
- public function getList() {
- if (!$this->request->isGet()) {
- $this->error('请求方式错误');
- }
- $params = $this->request->param();
- //参数是否存在且不为空
- $requiredParams = ['order','code'];
- foreach ($requiredParams as $param) {
- if (!isset($params[$param]) || empty($params[$param])) {
- $this->error("$param 参数错误");
- }
- }
- //如果订单编号没有 DC 前缀,自动添加 DC
- if (strpos($params['order'], 'DC') !== 0) {
- $params['order'] = 'DC' . $params['order'];
- }
- $order = $params['order'];
- switch ($params['code']) {
- case '裁剪':
- //获取订单编号
- $ddbh = explode('-', $order)[0];
- //查询未出库的记录,若存在则进行批量出库和日志记录
- $data = \db('工单_印件资料')
- ->where(['子订单编号' => $order, 'ck_rq' => null])
- ->find();
- if ($data) {
- // 检查并更新工单_基本资料表的出库日期
- $sql = \db('工单_基本资料')
- ->where('订单编号', $ddbh)
- ->whereNull('出库日期')
- ->fetchSql(true)
- ->update(['出库日期' => date("Y-m-d H:i:s")]);
- \db()->query($sql);
- // 更新工单_印件资料表的出库日期
- $sql = \db('工单_印件资料')
- ->where('子订单编号', $order)
- ->whereNull('Mod_rq')
- ->whereNull('ck_rq')
- ->fetchSql(true)
- ->update(['ck_rq' => date("Y-m-d H:i:s")]);
- \db()->query($sql);
- }
- //查询子订单编号对应数据
- if (strpos($order, '-') !== false) {
- //判断 $order -后面是否是两位
- if (preg_match('/-(\d{2})$/', $order, $matches)) {
- $number = (int)$matches[1];
- //船样单子为:订单编号-90~99
- if ($number > 70) {
- $data = \db('工单_基本资料')->alias('j')
- ->distinct('y.子订单编号')
- ->field('
- y.订单编号, y.子订单编号, y.款号, j.款式, y.颜色,
- y.zdtotal, y.sctotal, j.单位, y.Sys_id, y.Sys_rq,
- y.UniqId, y.sc_rq, y.颜色备注, y.color_id,y.船样,
- y.cm1, y.cm2, y.cm3, y.cm4, y.cm5, y.cm6, y.cm7, y.cm8, y.cm9, y.cm10,y.cm11,y.cm12,y.cm13,y.cm14,
- y.cmsl1, y.cmsl2, y.cmsl3, y.cmsl4, y.cmsl5, y.cmsl6, y.cmsl7, y.cmsl8, y.cmsl9, y.cmsl10,y.cmsl11,y.cmsl12,y.cmsl13,y.cmsl14,
- y.scsl1, y.scsl2, y.scsl3, y.scsl4, y.scsl5, y.scsl6, y.scsl7, y.scsl8, y.scsl9, y.scsl10, y.scsl11, y.scsl12, y.scsl13, y.scsl14'
- )
- ->join('工单_印件资料 y', 'j.订单编号 = y.订单编号', 'left')
- ->where('y.船样',1)
- ->where('y.子订单编号', $order)
- ->select();
- } else {
- //获取原始子订单编号【-01】后期不需要else中代码可以删除掉
- //【查询尺码、制单数、填写报工新增实裁数】
- $data = \db('工单_基本资料')->alias('j')
- ->distinct('y.子订单编号')
- ->field('
- y.订单编号, y.子订单编号, y.款号, j.款式, y.颜色,
- y.zdtotal, y.sctotal, j.单位, y.Sys_id, y.Sys_rq,
- y.UniqId, y.sc_rq, y.颜色备注, y.color_id,y.船样,
- y.cm1, y.cm2, y.cm3, y.cm4, y.cm5, y.cm6, y.cm7, y.cm8, y.cm9, y.cm10,y.cm11,y.cm12,y.cm13,y.cm14,
- y.cmsl1, y.cmsl2, y.cmsl3, y.cmsl4, y.cmsl5, y.cmsl6, y.cmsl7, y.cmsl8, y.cmsl9, y.cmsl10,y.cmsl11,y.cmsl12,y.cmsl13,y.cmsl14,
- y.scsl1, y.scsl2, y.scsl3, y.scsl4, y.scsl5, y.scsl6, y.scsl7, y.scsl8, y.scsl9, y.scsl10, y.scsl11, y.scsl12, y.scsl13, y.scsl14'
- )
- ->join('工单_印件资料 y', 'j.订单编号 = y.订单编号', 'left')
- ->where('y.船样',0)
- ->whereNull('y.Mod_rq')
- ->where('y.子订单编号', 'like', '%' . $ddbh . '%')
- ->select();
- }
- }else{
- // $ddbh = explode('-', $order)[0];//获取订单编号
- //【查询尺码、制单数、填写报工新增实裁数】
- $data = \db('工单_基本资料')->alias('j')
- ->distinct('y.子订单编号')
- ->field('
- y.订单编号, y.子订单编号, y.款号, j.款式, y.颜色,
- y.zdtotal, y.sctotal, j.单位, y.Sys_id, y.Sys_rq,
- y.UniqId, y.sc_rq, y.颜色备注, y.color_id,y.船样,
- y.cm1, y.cm2, y.cm3, y.cm4, y.cm5, y.cm6, y.cm7, y.cm8, y.cm9, y.cm10,y.cm11,y.cm12,y.cm13,y.cm14,
- y.cmsl1, y.cmsl2, y.cmsl3, y.cmsl4, y.cmsl5, y.cmsl6, y.cmsl7, y.cmsl8, y.cmsl9, y.cmsl10,y.cmsl11,y.cmsl12,y.cmsl13,y.cmsl14,
- y.scsl1, y.scsl2, y.scsl3, y.scsl4, y.scsl5, y.scsl6, y.scsl7, y.scsl8, y.scsl9, y.scsl10, y.scsl11, y.scsl12, y.scsl13, y.scsl14'
- )
- ->join('工单_印件资料 y', 'j.订单编号 = y.订单编号', 'left')
- ->where('y.船样',0)
- ->whereNull('y.Mod_rq')
- ->where('y.订单编号', 'like', '%' . $ddbh . '%')
- ->select();
- }
- $dataEntry = [];
- $list = [];
- $headers = [];//存放尺码表头
- foreach ($data as $item) {
- // 初始化尺码与数量映射数组
- $cmScslMapping = [];
- for ($i = 1; $i <= 14; $i++) {
- $cmValue = $item['cm' . $i];
- $scslValue = $item['scsl' . $i];
- if (!is_null($cmValue) && $cmValue !== 0) {
- $cmScslMapping[$cmValue] = ($scslValue === 0 || is_null($scslValue)) ? '' : $scslValue;
- if (!in_array($cmValue, $headers)) {
- $headers[] = $cmValue;
- }
- }
- }
- // 将尺码数据平铺到主要数据中(表格数据)
- $orderData = [
- '订单编号' => $item['订单编号'],
- '子订单编号' => $item['子订单编号'],
- '款号' => $item['款号'],
- '款式' => $item['款式'],
- '颜色' => $item['颜色备注'],
- 'zdtotal' => $item['zdtotal'],
- 'sctotal' => $item['sctotal'],
- '单位' => $item['单位'],
- 'Sys_id' => $item['Sys_id'],
- 'Sys_rq' => $item['Sys_rq'],
- ];
- // 平铺尺码映射数据
- $orderData = array_merge($orderData, $cmScslMapping);
- $dataEntry[] = $orderData;
- // list 列表部分
- $entry = [];
- for ($i = 1; $i <= 14; $i++) {
- $entry['cm' . $i] = ($item['cm' . $i] === 0 || is_null($item['cm' . $i])) ? '' : $item['cm' . $i];
- $entry['cmsl' . $i] = ($item['cmsl' . $i] === 0 || is_null($item['cmsl' . $i])) ? '' : $item['cmsl' . $i];
- $entry['scsl' . $i] = ($item['scsl' . $i] === 0 || is_null($item['scsl' . $i])) ? '' : $item['scsl' . $i];
- }
- $entry['订单编号'] = $item['订单编号'];
- $entry['子订单编号'] = $item['子订单编号'];
- $entry['UniqId'] = $item['UniqId'];
- $entry['zdtotal'] = $item['zdtotal'];
- $entry['颜色'] = $item['颜色'];
- $entry['款式'] = $item['款式'];
- $entry['款号'] = $item['款号'];
- $entry['color_id'] = $item['color_id'];
- $entry['颜色备注'] = $item['颜色备注'];
- $list[] = $entry;
- }
- // 创建新的合并子订单列表
- $finalMerged = [];
- foreach ($list as $mergedItem) {
- $colorId = $mergedItem['color_id'];
- // 查找原始列表中具有相同 color_id 的子订单编号
- foreach ($list as $item) {
- if ($item['color_id'] === $colorId) {
- // 复制合并后的数据,并替换子订单编号
- $newMergedItem = $mergedItem;
- $newMergedItem['子订单编号'] = $item['子订单编号'];
- $finalMerged[] = $newMergedItem;
- }
- }
- }
- // 在 $mergeds 中查找匹配的子订单编号 对应的一条数据
- $matchedOrder = null;
- foreach ($list as $mergedOrder) {
- if ($mergedOrder['子订单编号'] === $order) {
- $matchedOrder = $mergedOrder;
- break; // 找到后可以退出循环
- }
- }
- //产量进度汇总记录
- $rows = db()->table('设备_产量计酬')->alias('c')
- // ->join('工单_印件资料 y', 'c.订单编号 = y.订单编号', 'left')
- ->field('c.款号, c.订单编号, c.子订单编号, c.sys_rq as 上报时间, c.尺码, c.数量')
- ->where([
- 'c.子订单编号' => $params['order'],
- 'c.mod_rq' => null,
- 'c.工序名称' => $params['code']
- ])
- ->select();
- $formattedRows = [];
- foreach ($rows as $item) {
- if (!empty($item['尺码'])) {
- $key = $item['款号'];
- if (!isset($formattedRows[$key])) {
- $formattedRows[$key] = [
- '订单编号' => $item['订单编号'],
- '款号' => $item['款号'],
- '上报时间' => $item['上报时间'],
- '子订单编号' => $item['子订单编号'],
- '颜色' => $list[0]['颜色备注'],
- '裁剪数' => 0
- ];
- }
- // 累加尺码数量
- if (isset($formattedRows[$key][$item['尺码']])) {
- $formattedRows[$key][$item['尺码']] += $item['数量'];
- } else {
- $formattedRows[$key][$item['尺码']] = $item['数量'];
- }
- // 累加当前尺码的数量【裁剪数】
- $formattedRows[$key]['裁剪数'] += $item['数量'];
- }
- }
- //重置索引为连续数字索引
- $finalResult = array_values($formattedRows);
- // 报工历史记录
- $existingRecords = \db('设备_产量计酬')->alias('c')
- ->field('
- c.订单编号, c.子订单编号, c.款号, c.工序编号, c.工序名称, c.尺码, c.数量, c.sczl_jtbh,
- c.尾包,c.UniqId,c.ci_num,c.s_num,c.sys_rq, c.serial,
- j.款式,
- y.zdtotal, y.sctotal, y.颜色,y.颜色备注
- ')
- ->join('工单_印件资料 y', 'c.子订单编号 = y.子订单编号', 'left')
- ->join('工单_基本资料 j', 'c.订单编号 = j.订单编号', 'left')
- ->where('c.子订单编号', $params['order'])
- ->where('c.工序名称', $params['code'])
- // ->where('c.sczl_jtbh', $params['sys_sbID'])
- ->whereNull('c.mod_rq') // 查询未删除数据
- ->whereNull('y.mod_rq') // 查询未删除数据
- ->order('c.UniqId', 'desc')
- ->distinct('c.子订单编号')
- ->select();
- $sizeSummary = [];
- $sizes = [];
- foreach ($existingRecords as $record) {
- $size = $record['尺码'];
- $quantity = $record['数量'];
- $serial = $record['serial'];
- // 如果尺码还没有出现过,加入尺码列表
- if (!in_array($size, $sizes)) {
- $sizes[] = $size;
- }
- if (!isset($sizeSummary[$record['UniqId']])) {
- $sizeSummary[$record['UniqId']] = [
- 'UniqId' => $record['UniqId'],
- '订单编号' => $record['订单编号'],
- '子订单编号' => $record['子订单编号'],
- '上报数量' => $record['s_num'],
- '剩余数量' => $record['ci_num'],
- '次品数量' => $record['数量'] - $record['ci_num'],
- '生产款号' => $record['款号'],
- '尺码' => $record['尺码'],
- '工序编号' => $record['工序编号'],
- '工序名称' => $record['工序名称'],
- '数量' => $quantity,
- '尾包' => $record['尾包'] == 1 ? '是' : '否',
- '颜色' => $record['颜色备注'],
- '组别' => $record['sczl_jtbh'],
- '款式' => $record['款式'],
- 'serial' => '第('.$serial.')包',
- 'sys_rq' => $record['sys_rq']
- ];
- }
- }
- // 将 $sizeSummary 转换为索引数组
- $sizeSummary = array_values($sizeSummary);
- // 对 $sizeSummary 按 sys_rq 降序排序
- usort($sizeSummary, function ($a, $b) {
- return strtotime($b['UniqId']) - strtotime($a['UniqId']);
- });
- $result = [
- 'list' => $matchedOrder,
- 'headers' => $headers,
- 'table' => $finalResult,
- 'bgtable' => $existingRecords
- ];
- }else {
- //查询订单编号对应的数据
- $data = \db('工单_基本资料')->alias('j')
- ->distinct('y.子订单编号')
- ->field('
- y.订单编号, y.子订单编号, y.款号, j.款式, y.颜色,
- y.zdtotal, y.sctotal, j.单位, y.Sys_id, y.Sys_rq,
- y.UniqId, y.sc_rq, y.颜色备注, y.color_id,y.船样,
- y.cm1, y.cm2, y.cm3, y.cm4, y.cm5, y.cm6, y.cm7, y.cm8, y.cm9, y.cm10,y.cm11,y.cm12,y.cm13,y.cm14,
- y.cmsl1, y.cmsl2, y.cmsl3, y.cmsl4, y.cmsl5, y.cmsl6, y.cmsl7, y.cmsl8, y.cmsl9, y.cmsl10,y.cmsl11,y.cmsl12,y.cmsl13,y.cmsl14,
- y.scsl1, y.scsl2, y.scsl3, y.scsl4, y.scsl5, y.scsl6, y.scsl7, y.scsl8, y.scsl9, y.scsl10, y.scsl11, y.scsl12, y.scsl13, y.scsl14'
- )
- ->join('工单_印件资料 y', 'j.订单编号 = y.订单编号', 'left')
- // ->where('y.船样',1)
- ->whereNull('y.Mod_rq')
- ->where('y.订单编号', 'like', '%' . $order . '%')
- ->select();
- $headers = [];//存放尺码表头
- foreach ($data as $item) {
- // 初始化尺码与数量映射数组
- $cmScslMapping = [];
- for ($i = 1; $i <= 14; $i++) {
- $cmValue = $item['cm' . $i];
- $scslValue = $item['scsl' . $i];
- if (!is_null($cmValue) && $cmValue !== 0) {
- $cmScslMapping[$cmValue] = ($scslValue === 0 || is_null($scslValue)) ? '' : $scslValue;
- if (!in_array($cmValue, $headers)) {
- $headers[] = $cmValue;
- }
- }
- }
- }
- //【查询产量计酬历史记录】
- $where['c.订单编号'] = ['like','%'.explode('C',$order)[1].'%'];
- $where['c.工序名称'] = $params['code'];
- $rows = db()->table('设备_产量计酬')->alias('c')
- ->field('c.款号, c.订单编号, c.子订单编号, c.sys_rq as 上报时间, c.尺码, c.数量')
- ->where([
- 'c.mod_rq' => null,
- // 'c.订单编号' => $order,
- // 'c.工序名称' => $params['code']
- ])
- ->where($where)
- ->select();
- $formattedRows = [];
- foreach ($rows as $item) {
- if (!empty($item['尺码'])) {
- $key = $item['上报时间'];
- if (!isset($formattedRows[$key])) {
- $formattedRows[$key] = [
- '订单编号' => $item['订单编号'],
- '款号' => $item['款号'],
- '上报时间' => $item['上报时间'],
- '子订单编号' => $item['子订单编号'],
- '裁剪数' => 0
- ];
- }
- // 累加尺码数量
- if (isset($formattedRows[$key][$item['尺码']])) {
- $formattedRows[$key][$item['尺码']] += $item['数量'];
- } else {
- $formattedRows[$key][$item['尺码']] = $item['数量'];
- }
- // 累加当前尺码的数量【裁剪数】
- $formattedRows[$key]['裁剪数'] += $item['数量'];
- }
- }
- // 重置索引为连续数字索引
- $finalResult = array_values($formattedRows);
- $result = [
- 'table' => $finalResult,
- 'headers' => $headers,
- 'list' => '',
- 'total' => '',
- ];
- }
- $this->success('请求成功', $result);
- break;
- case '车缝':
- // 查询历史记录并生成尺寸汇总
- function getSizeSummary($order) {
- $where = [];
- if (strpos($order, '-') !== false) {
- $where['c.子订单编号'] = $order;
- } else {
- $where['c.订单编号'] = ['like', '%' . $order . '%'];
- }
- $where['c.工序编号'] = '3';
- $where['c.mod_rq'] = null;
- $existingRecords = \db('设备_产量计酬')->alias('c')
- ->field('c.订单编号, c.子订单编号, c.款号, c.工序编号, c.工序名称, c.尺码,
- CASE
- WHEN c.工序名称 IN ("裁剪", "车缝") THEN c.数量
- ELSE c.s_num
- END as 数量,
- c.sczl_jtbh, c.sczl_bh, c.尾包, c.sys_rq, c.serial, c.serial_num,c.UniqId,
- y.zdtotal, y.sctotal, j.款式, y.颜色,y.颜色备注, CAST(c.serial_num AS SIGNED) as serial_num_numeric')
- ->join('工单_印件资料 y', 'c.子订单编号 = y.子订单编号', 'left')
- ->join('工单_基本资料 j', 'c.订单编号 = j.订单编号', 'left')
- ->where($where)
- // ->limit(1,100)
- ->order('c.sys_rq desc')
- ->group('c.订单编号, c.子订单编号, c.款号, c.工序编号, c.工序名称, c.尺码, c.数量, c.sczl_jtbh, c.sczl_bh, c.尾包, c.sys_rq, c.serial, c.serial_num, j.款式')
- ->select();
- $sizeSummary = [];
- $sizes = [];
- foreach ($existingRecords as $record) {
- $size = $record['尺码'];
- $quantity = $record['数量'];
- $serial = $record['serial'];
- $serialNum = $record['serial_num']; // serial_num 分组
- $processNumber = $record['工序编号']; // 工序编号
- // 初始化尺码
- if (!in_array($size, $sizes)) {
- $sizes[] = $size;
- }
- // 检查是否已有相同的 serial_num 组合
- if (!isset($sizeSummary[$serialNum])) {
- $sizeSummary[$serialNum] = [
- '订单编号' => $record['订单编号'],
- '子订单编号' => $record['子订单编号'],
- '款号' => $record['款号'],
- '款式' => $record['款式'],
- '工序编号' => $record['工序编号'],
- '工序名称' => $record['工序名称'],
- '数量' => '0', // 记录总数量
- '尾包' => $record['尾包'] == 1 ? '是' : '否',
- '颜色' => $record['颜色'],
- '颜色备注' => $record['颜色备注'],
- '机台号' => $record['sczl_jtbh'],
- '组别' => $record['sczl_bh'],
- 'serial' => [], // 流水号数组
- 'sys_rq' => $record['sys_rq'],
- 'UniqId' => $record['UniqId'],
- '尺码数据' => [] // 用于存储每个尺码对应的流水号和数量
- ];
- }
- // 将流水号添加到 serial 数组
- $sizeSummary[$serialNum]['serial'][] = $serial;
- // 累加数量到总数量
- $sizeSummary[$serialNum]['数量'] += $quantity;
- // 记录尺码数据
- if (!isset($sizeSummary[$serialNum]['尺码数据'][$size])) {
- $sizeSummary[$serialNum]['尺码数据'][$size] = [];
- }
- // 添加尺码对应的流水号和数量
- $sizeSummary[$serialNum]['尺码数据'][$size][] = $serial . ' (' . $quantity . ')';
- }
- // 对每个工序的 serial 进行处理,并转换为逗号分隔的字符串
- $finalRecords = [];
- foreach ($sizeSummary as &$summary) {
- // 将 serial 数组按数值降序排序
- sort($summary['serial'], SORT_NUMERIC);
- $summary['serial'] = implode(',', $summary['serial']);
- // 合并尺码数据到同一层级
- foreach ($summary['尺码数据'] as $size => $serials) {
- $summary[$size] = implode(', ', $serials); // 尺码对应的流水号和数量
- }
- unset($summary['尺码数据']); // 移除尺码数据数组,直接将数据合并到 summary
- $finalRecords[] = $summary;
- }
- // 尺码排序(数字在前,字母在后)
- usort($sizes, function ($a, $b) {
- $sizeOrder = [
- 'XXXS' => 1,
- 'XXS' => 2,
- 'XS' => 3,
- 'S' => 4,
- 'M' => 5,
- 'L' => 6,
- 'XL' => 7,
- '2XL' => 8,
- 'XXL' => 9,
- '3XL' => 10,
- 'XXXL' => 11,
- '4XL' => 12,
- 'XXXXL' => 13,
- '5XL' => 14,
- 'XXXXXL' => 15
- ];
- if (is_numeric($a) && is_numeric($b)) return $a - $b;
- if (is_numeric($a)) return -1;
- if (is_numeric($b)) return 1;
- return ($sizeOrder[$a] ?? 100) - ($sizeOrder[$b] ?? 100);
- });
- return ['headers' => $sizes, 'records' => $finalRecords];
- }
- if (strpos($order, '-') !== false) {
- if (!isset($params['sys_sbID']) || empty($params['sys_sbID'])) {
- $this->error('sys_sbID 参数错误');
- }
- if (preg_match('/-(\d{2})$/', $order, $matches)) {
- $number = (int)$matches[1];
- if ($number > 70) {
- //echo '船样';
- //获取订单编号
- // $ddbh = explode('-', $order)[0];
- //1.查询尺码、制单数、填写报工新增实裁数
- $data = \db('工单_基本资料')->alias('j')
- ->distinct('y.子订单编号')
- ->field('
- y.订单编号, y.子订单编号, y.款号, j.款式, y.颜色,
- y.zdtotal, y.sctotal, j.单位, y.Sys_id, y.Sys_rq,
- y.UniqId, y.sc_rq, y.颜色备注, y.color_id,y.船样,
- y.cm1, y.cm2, y.cm3, y.cm4, y.cm5, y.cm6, y.cm7, y.cm8, y.cm9, y.cm10,y.cm11,y.cm12,y.cm13,y.cm14,
- y.cmsl1, y.cmsl2, y.cmsl3, y.cmsl4, y.cmsl5, y.cmsl6, y.cmsl7, y.cmsl8, y.cmsl9, y.cmsl10,y.cmsl11,y.cmsl12,y.cmsl13,y.cmsl14,
- y.scsl1, y.scsl2, y.scsl3, y.scsl4, y.scsl5, y.scsl6, y.scsl7, y.scsl8, y.scsl9, y.scsl10, y.scsl11, y.scsl12, y.scsl13, y.scsl14'
- )
- ->join('工单_印件资料 y', 'j.订单编号 = y.订单编号', 'left')
- ->where('y.船样',1)
- ->whereNull('y.Mod_rq')
- ->where('y.子订单编号', $order)
- ->select();
- } else {
- //echo '两位数子订单';
- $ddbh = explode('-', $order)[0];//获取订单编号
- //【查询尺码、制单数、填写报工新增实裁数】
- $data = \db('工单_基本资料')->alias('j')
- ->distinct('y.子订单编号')
- ->field('
- y.订单编号, y.子订单编号, y.款号, j.款式, y.颜色,
- y.zdtotal, y.sctotal, j.单位, y.Sys_id, y.Sys_rq,
- y.UniqId, y.sc_rq, y.颜色备注, y.color_id,y.船样,
- y.cm1, y.cm2, y.cm3, y.cm4, y.cm5, y.cm6, y.cm7, y.cm8, y.cm9, y.cm10,y.cm11,y.cm12,y.cm13,y.cm14,
- y.cmsl1, y.cmsl2, y.cmsl3, y.cmsl4, y.cmsl5, y.cmsl6, y.cmsl7, y.cmsl8, y.cmsl9, y.cmsl10,y.cmsl11,y.cmsl12,y.cmsl13,y.cmsl14,
- y.scsl1, y.scsl2, y.scsl3, y.scsl4, y.scsl5, y.scsl6, y.scsl7, y.scsl8, y.scsl9, y.scsl10, y.scsl11, y.scsl12, y.scsl13, y.scsl14'
- )
- ->join('工单_印件资料 y', 'j.订单编号 = y.订单编号', 'left')
- ->where('y.船样',0)->whereNull('y.Mod_rq')
- ->where('y.子订单编号', 'like', '%' . $ddbh . '%')
- ->select();
- }
- }else{
- $ddbh = explode('-', $order)[0];//获取订单编号
- //【查询尺码、制单数、填写报工新增实裁数】
- $data = \db('工单_基本资料')->alias('j')
- ->distinct('y.子订单编号')
- ->field('
- y.订单编号, y.子订单编号, y.款号, j.款式, y.颜色,
- y.zdtotal, y.sctotal, j.单位, y.Sys_id, y.Sys_rq,
- y.UniqId, y.sc_rq, y.颜色备注, y.color_id,y.船样,
- y.cm1, y.cm2, y.cm3, y.cm4, y.cm5, y.cm6, y.cm7, y.cm8, y.cm9, y.cm10,y.cm11,y.cm12,y.cm13,y.cm14,
- y.cmsl1, y.cmsl2, y.cmsl3, y.cmsl4, y.cmsl5, y.cmsl6, y.cmsl7, y.cmsl8, y.cmsl9, y.cmsl10,y.cmsl11,y.cmsl12,y.cmsl13,y.cmsl14,
- y.scsl1, y.scsl2, y.scsl3, y.scsl4, y.scsl5, y.scsl6, y.scsl7, y.scsl8, y.scsl9, y.scsl10, y.scsl11, y.scsl12, y.scsl13, y.scsl14'
- )
- ->join('工单_印件资料 y', 'j.订单编号 = y.订单编号', 'left')
- ->where('y.船样',0)->whereNull('y.Mod_rq')
- ->where('y.子订单编号', 'like', '%' . $ddbh . '%')
- ->select();
- }
- $dataEntry = [];
- $list = [];
- $headers = [];//存放尺码表头
- foreach ($data as $item) {
- // 初始化尺码与数量映射数组
- $cmScslMapping = [];
- for ($i = 1; $i <= 14; $i++) {
- $cmValue = $item['cm' . $i];
- $scslValue = $item['scsl' . $i];
- if (!is_null($cmValue) && $cmValue !== 0) {
- $cmScslMapping[$cmValue] = ($scslValue === 0 || is_null($scslValue)) ? '' : $scslValue;
- if (!in_array($cmValue, $headers)) {
- $headers[] = $cmValue;
- }
- }
- }
- // 将尺码数据平铺到主要数据中(表格数据)
- $orderData = [
- '订单编号' => $item['订单编号'],
- '子订单编号' => $item['子订单编号'],
- '款号' => $item['款号'],
- '款式' => $item['款式'],
- '颜色' => $item['颜色备注'],
- 'zdtotal' => $item['zdtotal'],
- 'sctotal' => $item['sctotal'],
- '单位' => $item['单位'],
- 'Sys_id' => $item['Sys_id'],
- 'Sys_rq' => $item['Sys_rq'],
- ];
- // 平铺尺码映射数据
- $orderData = array_merge($orderData, $cmScslMapping);
- $dataEntry[] = $orderData;
- // list 列表部分
- $entry = [];
- for ($i = 1; $i <= 14; $i++) {
- $entry['cm' . $i] = ($item['cm' . $i] === 0 || is_null($item['cm' . $i])) ? '' : $item['cm' . $i];
- $entry['cmsl' . $i] = ($item['cmsl' . $i] === 0 || is_null($item['cmsl' . $i])) ? '' : $item['cmsl' . $i];
- $entry['scsl' . $i] = ($item['scsl' . $i] === 0 || is_null($item['scsl' . $i])) ? '' : $item['scsl' . $i];
- }
- $entry['订单编号'] = $item['订单编号'];
- $entry['子订单编号'] = $item['子订单编号'];
- $entry['UniqId'] = $item['UniqId'];
- $entry['zdtotal'] = $item['zdtotal'];
- $entry['颜色'] = $item['颜色'];
- $entry['款式'] = $item['款式'];
- $entry['款号'] = $item['款号'];
- $entry['color_id'] = $item['color_id'];
- $entry['颜色备注'] = $item['颜色备注'];
- $list[] = $entry;
- }
- // 在 $mergeds 中查找匹配的子订单编号 对应的一条数据
- $matchedOrder = null;
- foreach ($list as $mergedOrder) {
- if ($mergedOrder['子订单编号'] === $order) {
- $matchedOrder = $mergedOrder;
- break; // 找到后可以退出循环
- }
- }
- $allScslEmpty = true;
- for ($i = 1; $i <= 14; $i++) {
- if (!empty($matchedOrder["scsl$i"])) {
- $allScslEmpty = false;
- break;
- }
- }
- if ($allScslEmpty) {
- $this->success('当前订单未裁剪 请裁剪后报工', [
- 'code' => 1,
- 'serial' => '',
- 'serial_num' => '',
- 'headers' => '',
- 'records' => '',
- ]);
- return;
- }
- // echo "<pre>";print_r($matchedOrder);echo "</pre>";die;
- $sizeData = getSizeSummary($order);
- // 查询流水号(包数)和序号
- $serial = \db('设备_产量计酬')
- ->field('子订单编号, MAX(CAST(serial AS UNSIGNED)) as serial, MAX(CAST(serial_num AS UNSIGNED)) as serial_num')
- ->where('子订单编号', $order)
- ->where(function($query) {
- $query->whereNull('mod_rq')->whereOr('mod_rq', '');
- }) // 查询未删除数据
- ->where('sczl_jtbh', $params['sys_sbID'])
- ->group('子订单编号')
- ->find();
- $serial['serial'] = empty($serial['serial']) ? '000' : str_pad($serial['serial'], 3, '0', STR_PAD_LEFT);
- $serial['serial_num'] = empty($serial['serial_num']) ? '0' : $serial['serial_num'];
- $clwhere['sczl_jtbh'] = $params['sys_sbID'];
- $clwhere['子订单编号'] = $order;
- $clwhere['mod_rq'] = null;
- $clwhere['工序名称'] = $params['code'];
- $cljclist = \db('设备_产量计酬')
- ->field('订单编号,子订单编号,尺码,数量,mod_rq')
- ->where($clwhere)
- ->select();
- $result = [];
- $totalQuantity = 0; // 总数量初始化
- $orderNumber = ''; // 订单编号初始化
- foreach ($cljclist as $item) {
- $size = $item['尺码'];
- $orderNumber = $item['订单编号'];
- if (isset($result[$size])) {
- $result[$size] += $item['数量'];
- } else {
- $result[$size] = $item['数量'];
- }
- // 累加总数量
- $totalQuantity += $item['数量'];
- }
- $result['订单编号'] = $orderNumber;
- foreach ($result as $size => $quantity) {
- if ($size !== '订单编号' && $size !== '数量') {
- $result[$size] = '合计(' . $quantity . ')';
- }
- }
- $result['数量'] = '合计(' . $totalQuantity . ')';
- // 初始化 $sizeData['records'],以防万一它不存在
- if (!isset($sizeData['records'])) {
- $sizeData['records'] = [];
- }
- // 将 $result 插入到 $sizeData['records'] 的最前面
- array_unshift($sizeData['records'], $result);
- $this->success('请求成功', [
- 'serial' => $serial['serial']+1, // 流水号
- 'serial_num' => $serial['serial_num']+1, // 序号
- 'list' => $matchedOrder, // 报工
- 'headers' => $sizeData['headers'], // 尺码表头
- 'records' => $sizeData['records'] // 查询历史记录
- ]);
- }else{
- $sizeData = getSizeSummary($order);
- // 查询流水号(包数)和序号
- $serial = \db('设备_产量计酬')
- ->field('子订单编号, MAX(CAST(serial AS UNSIGNED)) as serial, MAX(CAST(serial_num AS UNSIGNED)) as serial_num')
- ->where('订单编号', $order)
- ->group('订单编号')
- ->find();
- $serial['serial'] = empty($serial['serial']) ? '000' : str_pad($serial['serial'], 3, '0', STR_PAD_LEFT);
- $serial['serial_num'] = empty($serial['serial_num']) ? '0' : $serial['serial_num'];
- $clwhere['sczl_jtbh'] = $params['sys_sbID'];
- $clwhere['订单编号'] = $order;
- $clwhere['工序名称'] = $params['code'];
- $clwhere['mod_rq'] = null;
- $cljclist = \db('设备_产量计酬')
- ->field('订单编号,子订单编号,尺码,数量,mod_rq')
- ->where($clwhere)
- ->select();
- $result = [];
- $totalQuantity = 0; // 总数量初始化
- $orderNumber = ''; // 订单编号初始化
- foreach ($cljclist as $item) {
- $size = $item['尺码'];
- $orderNumber = $item['订单编号'];
- if (isset($result[$size])) {
- $result[$size] += $item['数量'];
- } else {
- $result[$size] = $item['数量'];
- }
- // 累加总数量
- $totalQuantity += $item['数量'];
- }
- foreach ($result as $size => $quantity) {
- if ($size !== '订单编号' && $size !== '数量') {
- $result[$size] = '合计(' . $quantity . ')';
- }
- }
- $result['订单编号'] = $orderNumber;
- $result['数量'] = '合计(' . $totalQuantity . ')';
- // 初始化 $sizeData['records'],以防万一它不存在
- if (!isset($sizeData['records'])) {
- $sizeData['records'] = [];
- }
- // 将 $result 插入到 $sizeData['records'] 的最前面
- array_unshift($sizeData['records'], $result);
- $this->success('请求成功', [
- 'serial' => $serial['serial'], // 流水号
- 'serial_num' => $serial['serial_num'], // 序号
- // 'list' => $matchedOrder, // 报工
- 'headers' => $sizeData['headers'], // 尺码表头
- 'records' => $sizeData['records'] // 查询历史记录
- ]);
- }
- break;
- case '手工':
- $gongxuname = '手工';
- $gongxuncode = '4';
- //判断是否为标签二维码参数数据
- if (strpos($order, ',') !== false) {
- //将子订单编号, 机台号, 工序, 尺码, 数量, 尾包, 流水号(包)分割为数组
- $paramArray = explode(',', $order);
- //通过子订单编号,尺码, 数量,流水号(包)查询数据库是否存在(且未删除数据)
- $res = \db('设备_产量计酬')
- ->where([
- '子订单编号' => $paramArray[0],
- '尺码' => $paramArray[3],
- '数量' => $paramArray[4],
- 'serial' => $paramArray[6],
- 'mod_rq' => null,
- ])
- ->order('UniqId desc')
- ->find();
- //如果不存在, 则返回当前扫码小票无效
- if (!$res) {
- $this->success('当前扫码小票无效', [
- 'code' => 1,
- 'result' => '',
- 'headers' => '',
- 'records' => ''
- ]);
- return;
- }
- $orderlist = \db('工单_基本资料')
- ->where('订单编号', $res['订单编号'])
- ->field('订单编号, 生产款号, 款式')
- ->find();
- $yinjianlist = \db('工单_印件资料')
- ->where('订单编号', $res['订单编号'])
- ->field('zdtotal, sctotal,颜色,颜色备注')
- ->find();
- if (empty($res)) {
- $ci_num = $paramArray[4];
- } else {
- $ci_num = $res["ci_num"];
- }
- $results = [
- 'sys_sbID' => $params['sys_sbID'],//设备编号
- 'ci_num' => $ci_num,//剩余数量
- 'UniqId' => $res['UniqId'],
- 'order' => $paramArray[0],//子订单编号
- 'zb' => $params['sys_sbID'],//组别
- 'gx' => $gongxuncode,//默认固定工序
- 'cm' => $paramArray[3],//尺码
- 'sl' => $paramArray[4],//数量
- 'wb' => $paramArray[5],//尾包
- '订单编号' => $orderlist['订单编号'],
- '生产款号' => $orderlist['生产款号'],
- '款式' => $orderlist['款式'],
- 'sctotal' => $yinjianlist['sctotal'],
- 'zdtotal' => $yinjianlist['zdtotal'],
- '颜色' => $yinjianlist['颜色备注'],
- ];
- $clwhere['sczl_jtbh'] = $params['sys_sbID'];
- $clwhere['订单编号'] = $res['订单编号'];
- $clwhere['工序名称'] = $gongxuname;
- $clwhere['mod_rq'] = null;
- $cljclist = \db('设备_产量计酬')
- ->field('订单编号,子订单编号,尺码,s_num as 数量,mod_rq')
- ->where($clwhere)
- ->select();
- $result = [];
- $totalQuantity = 0; // 总数量初始化
- $orderNumber = ''; // 订单编号初始化
- foreach ($cljclist as $item) {
- $size = $item['尺码'];
- $orderNumber = $item['订单编号'];
- if (isset($result[$size])) {
- $result[$size] += $item['数量'];
- } else {
- $result[$size] = $item['数量'];
- }
- // 累加总数量
- $totalQuantity += $item['数量'];
- }
- foreach ($result as $size => $quantity) {
- if ($size !== '订单编号' && $size !== '数量') {
- $result[$size] = '合计(' . $quantity . ')';
- }
- }
- $result['订单编号'] = $orderNumber;
- $result['数量'] = '合计(' . $totalQuantity . ')';
- $where = [];
- if (strpos($paramArray[0], '-') !== false) {
- $where['c.子订单编号'] = $paramArray[0];
- } else {
- $where['c.订单编号'] = ['like', '%' . $paramArray[0] . '%'];
- }
- $where['c.工序编号'] = $gongxuncode;
- $where['c.mod_rq'] = null;
- $existingRecords = \db('设备_产量计酬')->alias('c')
- ->field('c.订单编号, c.子订单编号, c.款号, c.工序编号, c.工序名称, c.尺码, c.s_num 数量, c.sczl_jtbh, c.sczl_bh, c.尾包, c.sys_rq, c.serial, c.serial_num,c.UniqId,
- ci_num,s_num,
- y.zdtotal, y.sctotal, j.款式, y.颜色,y.颜色备注, CAST(c.serial_num AS SIGNED) as serial_num_numeric')
- ->join('工单_印件资料 y', 'c.子订单编号 = y.子订单编号', 'left')
- ->join('工单_基本资料 j', 'c.订单编号 = j.订单编号', 'left')
- ->where($where)
- ->order('c.sys_rq desc')
- ->select();
- $sizeSummary = [];
- $sizes = [];
- // 遍历数据库查询结果,根据 UniqId + 尺码 进行分组
- foreach ($existingRecords as $record) {
- $size = $record['尺码'];
- $quantity = $record['数量'];
- $serial = $record['serial'];
- $uniqId = $record['UniqId'];
- // 初始化尺码数据
- if (!in_array($size, $sizes)) {
- $sizes[] = $size;
- }
- // 为每条记录创建独立的分组
- $groupKey = $uniqId . '_' . $size;
- if (!isset($sizeSummary[$groupKey])) {
- $sizeSummary[$groupKey] = [
- '订单编号' => $record['订单编号'],
- '子订单编号' => $record['子订单编号'],
- '款号' => $record['款号'],
- '款式' => $record['款式'],
- '工序编号' => $record['工序编号'],
- '工序名称' => $record['工序名称'],
- '剩余数量' => $record['ci_num'],
- '数量' => $quantity, // 直接使用当前记录的数量
- '尾包' => $record['尾包'] == 1 ? '是' : '否',
- '颜色' => $record['颜色'],
- '颜色备注' => $record['颜色备注'],
- '机台号' => $record['sczl_jtbh'],
- '组别' => $record['sczl_bh'],
- 'serial' => $serial, // 直接使用流水号,不需要数组
- 'sys_rq' => $record['sys_rq'],
- 'UniqId' => $record['UniqId'],
- '尺码数据' => [] // 用于存储尺码对应的数据
- ];
- }
- // 记录尺码数据
- if (!isset($sizeSummary[$groupKey]['尺码数据'][$size])) {
- $sizeSummary[$groupKey]['尺码数据'][$size] = [];
- }
- // 添加尺码对应的流水号和数量
- $sizeSummary[$groupKey]['尺码数据'][$size][] = $serial . ' (' . $quantity . ')';
- }
- // 处理最终记录
- $finalRecords = [];
- foreach ($sizeSummary as &$summary) {
- // 合并尺码数据到同一层级
- foreach ($summary['尺码数据'] as $size => $serials) {
- $summary[$size] = implode(', ', $serials); // 尺码对应的流水号和数量
- }
- unset($summary['尺码数据']); // 移除尺码数据数组
- $finalRecords[] = $summary;
- }
- // 尺码排序(数字在前,字母在后)
- usort($sizes, function ($a, $b) {
- $sizeOrder = [
- 'XXXS' => 1,
- 'XXS' => 2,
- 'XS' => 3,
- 'S' => 4,
- 'M' => 5,
- 'L' => 6,
- 'XL' => 7,
- '2XL' => 8,
- 'XXL' => 9,
- '3XL' => 10,
- 'XXXL' => 11,
- '4XL' => 12,
- 'XXXXL' => 13,
- '5XL' => 14,
- 'XXXXXL' => 15
- ];
- if (is_numeric($a) && is_numeric($b)) return $a - $b;
- if (is_numeric($a)) return -1;
- if (is_numeric($b)) return 1;
- return ($sizeOrder[$a] ?? 100) - ($sizeOrder[$b] ?? 100);
- });
- // 将汇总合计记录添加到最前面
- array_unshift($finalRecords, $result);
- $this->success('请求成功', [
- 'result' => $results,//小票数据
- 'headers' => $sizes, // 尺码表头
- 'records' => $finalRecords // 查询历史记录
- ]);
- } else {
- // 查询历史记录
- $this->success('请求成功', [
- 'result' => '',
- 'headers' => '',
- 'records' => ''
- ]);
- }
- break;
- case '大烫':
- $gongxuname = '大烫';
- $gongxuncode = '5';
- //判断是否为标签二维码参数数据
- if (strpos($order, ',') !== false) {
- //将子订单编号, 机台号, 工序, 尺码, 数量, 尾包, 流水号(包)分割为数组
- $paramArray = explode(',', $order);
- //通过子订单编号,尺码, 数量,流水号(包)查询数据库是否存在(且未删除数据)
- $res = \db('设备_产量计酬')
- ->where([
- '子订单编号' => $paramArray[0],
- '尺码' => $paramArray[3],
- '数量' => $paramArray[4],
- 'serial' => $paramArray[6],
- 'mod_rq' => null,
- ])
- ->order('UniqId desc')
- ->find();
- //如果不存在, 则返回当前扫码小票无效
- if (!$res) {
- $this->success('当前扫码小票无效', [
- 'code' => 1,
- 'result' => '',
- 'headers' => '',
- 'records' => ''
- ]);
- return;
- }
- $orderlist = \db('工单_基本资料')
- ->where('订单编号', $res['订单编号'])
- ->field('订单编号, 生产款号, 款式')
- ->find();
- $yinjianlist = \db('工单_印件资料')
- ->where('订单编号', $res['订单编号'])
- ->field('zdtotal, sctotal,颜色,颜色备注')
- ->find();
- // if (empty($res)) {
- $ci_num = $paramArray[4];
- // } else {
- // $ci_num = $res["ci_num"];
- // }
- $results = [
- 'sys_sbID' => $params['sys_sbID'],//设备编号
- 'ci_num' => $ci_num,//剩余数量
- 'UniqId' => $res['UniqId'],
- 'order' => $paramArray[0],//子订单编号
- 'zb' => $params['sys_sbID'],//组别
- 'gx' => $gongxuncode,//默认固定工序
- 'cm' => $paramArray[3],//尺码
- 'sl' => $paramArray[4],//数量
- 'wb' => $paramArray[5],//尾包
- '订单编号' => $orderlist['订单编号'],
- '生产款号' => $orderlist['生产款号'],
- '款式' => $orderlist['款式'],
- 'sctotal' => $yinjianlist['sctotal'],
- 'zdtotal' => $yinjianlist['zdtotal'],
- '颜色' => $yinjianlist['颜色备注'],
- ];
- $clwhere['sczl_jtbh'] = $params['sys_sbID'];
- $clwhere['订单编号'] = $res['订单编号'];
- $clwhere['工序名称'] = $gongxuname;
- $clwhere['mod_rq'] = null;
- $cljclist = \db('设备_产量计酬')
- ->field('订单编号,子订单编号,尺码,s_num as 数量,mod_rq')
- ->where($clwhere)
- ->select();
- $result = [];
- $totalQuantity = 0; // 总数量初始化
- $orderNumber = ''; // 订单编号初始化
- foreach ($cljclist as $item) {
- $size = $item['尺码'];
- $orderNumber = $item['订单编号'];
- if (isset($result[$size])) {
- $result[$size] += $item['数量'];
- } else {
- $result[$size] = $item['数量'];
- }
- // 累加总数量
- $totalQuantity += $item['数量'];
- }
- foreach ($result as $size => $quantity) {
- if ($size !== '订单编号' && $size !== '数量') {
- $result[$size] = '合计(' . $quantity . ')';
- }
- }
- $result['订单编号'] = $orderNumber;
- $result['数量'] = '合计(' . $totalQuantity . ')';
- $where = [];
- if (strpos($paramArray[0], '-') !== false) {
- $where['c.子订单编号'] = $paramArray[0];
- } else {
- $where['c.订单编号'] = ['like', '%' . $paramArray[0] . '%'];
- }
- $where['c.工序编号'] = $gongxuncode;
- $where['c.mod_rq'] = null;
- $existingRecords = \db('设备_产量计酬')->alias('c')
- ->field('c.订单编号, c.子订单编号, c.款号, c.工序编号, c.工序名称, c.尺码, c.s_num 数量, c.sczl_jtbh, c.sczl_bh, c.尾包, c.sys_rq, c.serial, c.serial_num,c.UniqId,
- ci_num,s_num,
- y.zdtotal, y.sctotal, j.款式, y.颜色,y.颜色备注, CAST(c.serial_num AS SIGNED) as serial_num_numeric')
- ->join('工单_印件资料 y', 'c.子订单编号 = y.子订单编号', 'left')
- ->join('工单_基本资料 j', 'c.订单编号 = j.订单编号', 'left')
- ->where($where)
- ->order('c.sys_rq desc')
- ->select();
- $sizeSummary = [];
- $sizes = [];
- // 遍历数据库查询结果,根据 UniqId + 尺码 进行分组
- foreach ($existingRecords as $record) {
- $size = $record['尺码'];
- $quantity = $record['数量'];
- $serial = $record['serial'];
- $uniqId = $record['UniqId'];
- // 初始化尺码数据
- if (!in_array($size, $sizes)) {
- $sizes[] = $size;
- }
- // 为每条记录创建独立的分组
- $groupKey = $uniqId . '_' . $size;
- if (!isset($sizeSummary[$groupKey])) {
- $sizeSummary[$groupKey] = [
- '订单编号' => $record['订单编号'],
- '子订单编号' => $record['子订单编号'],
- '款号' => $record['款号'],
- '款式' => $record['款式'],
- '工序编号' => $record['工序编号'],
- '工序名称' => $record['工序名称'],
- '剩余数量' => $record['ci_num'],
- '数量' => $quantity, // 直接使用当前记录的数量
- '尾包' => $record['尾包'] == 1 ? '是' : '否',
- '颜色' => $record['颜色'],
- '颜色备注' => $record['颜色备注'],
- '机台号' => $record['sczl_jtbh'],
- '组别' => $record['sczl_bh'],
- 'serial' => $serial, // 直接使用流水号,不需要数组
- 'sys_rq' => $record['sys_rq'],
- 'UniqId' => $record['UniqId'],
- '尺码数据' => [] // 用于存储尺码对应的数据
- ];
- }
- // 记录尺码数据
- if (!isset($sizeSummary[$groupKey]['尺码数据'][$size])) {
- $sizeSummary[$groupKey]['尺码数据'][$size] = [];
- }
- // 添加尺码对应的流水号和数量
- $sizeSummary[$groupKey]['尺码数据'][$size][] = $serial . ' (' . $quantity . ')';
- }
- // 处理最终记录
- $finalRecords = [];
- foreach ($sizeSummary as &$summary) {
- // 合并尺码数据到同一层级
- foreach ($summary['尺码数据'] as $size => $serials) {
- $summary[$size] = implode(', ', $serials); // 尺码对应的流水号和数量
- }
- unset($summary['尺码数据']); // 移除尺码数据数组
- $finalRecords[] = $summary;
- }
- // 尺码排序(数字在前,字母在后)
- usort($sizes, function ($a, $b) {
- $sizeOrder = [
- 'XXXS' => 1,
- 'XXS' => 2,
- 'XS' => 3,
- 'S' => 4,
- 'M' => 5,
- 'L' => 6,
- 'XL' => 7,
- '2XL' => 8,
- 'XXL' => 9,
- '3XL' => 10,
- 'XXXL' => 11,
- '4XL' => 12,
- 'XXXXL' => 13,
- '5XL' => 14,
- 'XXXXXL' => 15
- ];
- if (is_numeric($a) && is_numeric($b)) return $a - $b;
- if (is_numeric($a)) return -1;
- if (is_numeric($b)) return 1;
- return ($sizeOrder[$a] ?? 100) - ($sizeOrder[$b] ?? 100);
- });
- // 将汇总合计记录添加到最前面
- array_unshift($finalRecords, $result);
- $this->success('请求成功', [
- 'result' => $results,//小票数据
- 'headers' => $sizes, // 尺码表头
- 'records' => $finalRecords // 查询历史记录
- ]);
- } else {
- // 查询历史记录
- $this->success('请求成功', [
- 'result' => '',
- 'headers' => '',
- 'records' => ''
- ]);
- }
- break;
- case '总检':
- //判断是否为子订单编号【$order:DC2503291-0703 子订单编号】
- if (strpos($order, '-') !== false) {
- // 定义查询字段
- $field = "
- y.订单编号, y.子订单编号, y.款号, j.款式, y.颜色,
- y.zdtotal, y.sctotal, j.单位, y.Sys_id, y.Sys_rq,
- y.UniqId, y.sc_rq, y.颜色备注, y.color_id,y.船样,
- y.cm1, y.cm2, y.cm3, y.cm4, y.cm5, y.cm6, y.cm7, y.cm8, y.cm9, y.cm10,y.cm11,y.cm12,y.cm13,y.cm14,
- y.cmsl1, y.cmsl2, y.cmsl3, y.cmsl4, y.cmsl5, y.cmsl6, y.cmsl7, y.cmsl8, y.cmsl9, y.cmsl10,y.cmsl11,y.cmsl12,y.cmsl13,y.cmsl14,
- y.scsl1, y.scsl2, y.scsl3, y.scsl4, y.scsl5, y.scsl6, y.scsl7, y.scsl8, y.scsl9, y.scsl10, y.scsl11, y.scsl12, y.scsl13, y.scsl14
- ";
- // 根据订单类型查询数据
- if (preg_match('/-(\d{2})$/', $order, $matches)) {
- $number = (int)$matches[1];
- if ($number > 70) {
- // 船样订单查询
- $data = \db('工单_基本资料')->alias('j')
- ->distinct('y.子订单编号')
- ->field($field)
- ->join('工单_印件资料 y', 'j.订单编号 = y.订单编号', 'left')
- ->where('y.船样',1)
- ->whereNull('y.Mod_rq')
- ->where('y.子订单编号', $order)
- ->select();
- } else {
- // 普通两位数子订单
- $ddbh = explode('-', $order)[0];//获取订单编号
- $data = \db('工单_基本资料')->alias('j')
- ->distinct('y.子订单编号')
- ->field($field)
- ->join('工单_印件资料 y', 'j.订单编号 = y.订单编号', 'left')
- ->where('y.船样',0)->whereNull('y.Mod_rq')
- ->where('y.子订单编号', 'like', '%' . $ddbh . '%')
- ->select();
- }
- } else {
- // 其他子订单
- $ddbh = explode('-', $order)[0];//获取订单编号
- $data = \db('工单_基本资料')->alias('j')
- ->distinct('y.子订单编号')
- ->field($field)
- ->join('工单_印件资料 y', 'j.订单编号 = y.订单编号', 'left')
- ->where('y.船样',0)->whereNull('y.Mod_rq')
- ->where('y.子订单编号', 'like', '%' . $ddbh . '%')
- ->select();
- }
- // 处理查询到的数据
- $dataEntry = [];
- $list = [];
- $headers = [];//存放尺码表头
- foreach ($data as $item) {
- // 处理尺码与数量映射
- $cmScslMapping = [];
- for ($i = 1; $i <= 14; $i++) {
- $cmValue = $item['cm' . $i];
- $scslValue = $item['scsl' . $i];
- if (!is_null($cmValue) && $cmValue !== 0) {
- $cmScslMapping[$cmValue] = ($scslValue === 0 || is_null($scslValue)) ? '' : $scslValue;
- if (!in_array($cmValue, $headers)) {
- $headers[] = $cmValue;
- }
- }
- }
- // 构建表格数据
- $orderData = [
- '订单编号' => $item['订单编号'],
- '子订单编号' => $item['子订单编号'],
- '款号' => $item['款号'],
- '款式' => $item['款式'],
- '颜色' => $item['颜色备注'],
- 'zdtotal' => $item['zdtotal'],
- 'sctotal' => $item['sctotal'],
- '单位' => $item['单位'],
- 'Sys_id' => $item['Sys_id'],
- 'Sys_rq' => $item['Sys_rq'],
- ];
- $orderData = array_merge($orderData, $cmScslMapping);
- $dataEntry[] = $orderData;
- // 构建列表数据
- $entry = [];
- for ($i = 1; $i <= 14; $i++) {
- $entry['cm' . $i] = ($item['cm' . $i] === 0 || is_null($item['cm' . $i])) ? '' : $item['cm' . $i];
- $entry['cmsl' . $i] = ($item['cmsl' . $i] === 0 || is_null($item['cmsl' . $i])) ? '' : $item['cmsl' . $i];
- $entry['scsl' . $i] = ($item['scsl' . $i] === 0 || is_null($item['scsl' . $i])) ? '' : $item['scsl' . $i];
- }
- $entry['订单编号'] = $item['订单编号'];
- $entry['子订单编号'] = $item['子订单编号'];
- $entry['UniqId'] = $item['UniqId'];
- $entry['zdtotal'] = $item['zdtotal'];
- $entry['颜色'] = $item['颜色'];
- $entry['款式'] = $item['款式'];
- $entry['款号'] = $item['款号'];
- $entry['color_id'] = $item['color_id'];
- $entry['颜色备注'] = $item['颜色备注'];
- $list[] = $entry;
- }
- // 获取匹配的订单数据
- $order = explode(',', $order)[0];
- $matchedOrder = null;
- foreach ($list as $mergedOrder) {
- if ($mergedOrder['子订单编号'] === $order) {
- $matchedOrder = $mergedOrder;
- break;
- }
- }
- // 检查实裁数是否为空
- $allScslEmpty = true;
- if ($matchedOrder) {
- for ($i = 1; $i <= 14; $i++) {
- if (!empty($matchedOrder["scsl$i"])) {
- $allScslEmpty = false;
- break;
- }
- }
- }
- if ($allScslEmpty) {
- // 当前订单未裁剪 请裁剪后报工
- $this->success('查询失败', [
- 'code' => 1,
- 'serial' => '',
- 'serial_num' => '',
- 'headers' => '',
- 'records' => '',
- ]);
- return;
- }
- // 查询产量计酬记录
- $clwhere = [
- 'sczl_jtbh' => $params['sys_sbID'],
- '子订单编号' => $order,
- 'mod_rq' => null,
- '工序名称' => $params['code']
- ];
- $cljclist = \db('设备_产量计酬')
- ->field('订单编号,子订单编号,尺码,数量,mod_rq')
- ->where($clwhere)
- ->select();
- // 汇总产量记录
- $result = [];
- $totalQuantity = 0;
- $orderNumber = '';
- foreach ($cljclist as $item) {
- $size = $item['尺码'];
- $orderNumber = $item['订单编号'];
- if (isset($result[$size])) {
- $result[$size] += $item['数量'];
- } else {
- $result[$size] = $item['数量'];
- }
- $totalQuantity += $item['数量'];
- }
- $result['订单编号'] = $orderNumber;
- foreach ($result as $size => $quantity) {
- if ($size !== '订单编号' && $size !== '数量') {
- $result[$size] = '合计(' . $quantity . ')';
- }
- }
- $result['数量'] = '合计(' . $totalQuantity . ')';
- // 查询现有工序记录
- $where = [
- 'c.子订单编号' => $order,
- 'c.工序编号' => '6',
- 'c.mod_rq' => null
- ];
- $existingRecords = \db('设备_产量计酬')->alias('c')
- ->field('c.订单编号, c.子订单编号, c.款号, c.工序编号, c.工序名称, c.尺码,
- CASE
- WHEN c.工序名称 IN ("裁剪", "车缝") THEN c.数量
- ELSE c.s_num
- END as 数量,
- c.sczl_jtbh, c.sczl_bh, c.尾包, c.sys_rq, c.serial, c.serial_num,c.UniqId,
- y.zdtotal, y.sctotal, j.款式, y.颜色,y.颜色备注')
- ->join('工单_印件资料 y', 'c.子订单编号 = y.子订单编号', 'left')
- ->join('工单_基本资料 j', 'c.订单编号 = j.订单编号', 'left')
- ->where($where)
- ->order('c.UniqId desc')
- ->group('c.订单编号, c.子订单编号, c.款号, c.工序编号, c.工序名称, c.尺码, c.数量, c.sczl_jtbh, c.sczl_bh, c.尾包, c.sys_rq, c.serial, c.serial_num, j.款式')
- ->select();
- // 处理现有记录
- $sizeSummary = [];
- $sizes = [];
- foreach ($existingRecords as $record) {
- $size = $record['尺码'];
- $quantity = $record['数量'];
- $serial = $record['serial'];
- $serialNum = $record['serial_num'];
- // 收集尺码
- if (!in_array($size, $sizes)) {
- $sizes[] = $size;
- }
- // 初始化serial_num分组
- if (!isset($sizeSummary[$serialNum])) {
- $sizeSummary[$serialNum] = [
- '订单编号' => $record['订单编号'],
- '子订单编号' => $record['子订单编号'],
- '款号' => $record['款号'],
- '款式' => $record['款式'],
- '工序编号' => $record['工序编号'],
- '工序名称' => $record['工序名称'],
- '数量' => 0,
- '尾包' => $record['尾包'] == 1 ? '是' : '否',
- '颜色' => $record['颜色'],
- '颜色备注' => $record['颜色备注'],
- '机台号' => $record['sczl_jtbh'],
- '组别' => $record['sczl_bh'],
- 'serial' => [],
- 'sys_rq' => $record['sys_rq'],
- 'UniqId' => $record['UniqId'],
- '尺码数据' => []
- ];
- }
- // 添加流水号
- $sizeSummary[$serialNum]['serial'][] = $serial;
- $sizeSummary[$serialNum]['数量'] += $quantity;
- // 记录尺码数据
- if (!isset($sizeSummary[$serialNum]['尺码数据'][$size])) {
- $sizeSummary[$serialNum]['尺码数据'][$size] = [];
- }
- $sizeSummary[$serialNum]['尺码数据'][$size][] = $serial . ' (' . $quantity . ')';
- }
- // 最终记录处理
- $finalRecords = [];
- foreach ($sizeSummary as &$summary) {
- // 排序并合并流水号
- sort($summary['serial'], SORT_NUMERIC);
- $summary['serial'] = implode(',', $summary['serial']);
- // 合并尺码数据
- foreach ($summary['尺码数据'] as $size => $serials) {
- $summary[$size] = implode(', ', $serials);
- }
- unset($summary['尺码数据']);
- $finalRecords[] = $summary;
- }
- // 尺码排序
- $sizeOrder = [
- 'XXXS' => 1, 'XXS' => 2, 'XS' => 3, 'S' => 4, 'M' => 5,
- 'L' => 6, 'XL' => 7, '2XL' => 8, 'XXL' => 9, '3XL' => 10,
- 'XXXL' => 11, '4XL' => 12, 'XXXXL' => 13, '5XL' => 14, 'XXXXXL' => 15
- ];
- usort($sizes, function ($a, $b) use ($sizeOrder) {
- if (is_numeric($a) && is_numeric($b)) return $a - $b;
- if (is_numeric($a)) return -1;
- if (is_numeric($b)) return 1;
- return ($sizeOrder[$a] ?? 100) - ($sizeOrder[$b] ?? 100);
- });
- // 添加汇总记录到最前面
- array_unshift($finalRecords, $result);
- // 查询流水号信息
- $res_serial = \db('设备_产量计酬')
- ->field('子订单编号, MAX(CAST(serial AS UNSIGNED)) as serial, MAX(CAST(serial_num AS UNSIGNED)) as serial_num')
- ->where('子订单编号', $order)
- ->whereNull('mod_rq')
- // ->where('sczl_jtbh', $params['sys_sbID'])
- ->group('子订单编号')
- ->find();
- // 处理流水号
- $res_serial['serial'] = empty($res_serial['serial']) ? '000' : str_pad($res_serial['serial'], 3, '0', STR_PAD_LEFT);
- $res_serial['serial_num'] = empty($res_serial['serial_num']) ? '000' : str_pad($res_serial['serial_num'], 3, '0', STR_PAD_LEFT);
- $next_serial = str_pad((int)$res_serial['serial'] + 1, 3, '0', STR_PAD_LEFT);
- $next_serial_num = str_pad((int)$res_serial['serial_num'] + 1, 3, '0', STR_PAD_LEFT);
- $this->success('请求成功', [
- 'serial' => $next_serial,
- 'serial_num' => $next_serial_num,
- 'list' => $matchedOrder,
- 'headers' => $sizes,
- 'records' => $finalRecords
- ]);
- } else {
- // 按照订单编号查询
- $this->success('请求成功', [
- 'serial' => '',
- 'serial_num' => '',
- 'list' => '',
- 'headers' => '',
- 'records' => ''
- ]);
- }
- // //判断是否为子订单编号【$order:DC2503291-0703 子订单编号】
- // if (strpos($order, '-') !== false) {
- // $field = "
- // y.订单编号, y.子订单编号, y.款号, j.款式, y.颜色,
- // y.zdtotal, y.sctotal, j.单位, y.Sys_id, y.Sys_rq,
- // y.UniqId, y.sc_rq, y.颜色备注, y.color_id,y.船样,
- // y.cm1, y.cm2, y.cm3, y.cm4, y.cm5, y.cm6, y.cm7, y.cm8, y.cm9, y.cm10,y.cm11,y.cm12,y.cm13,y.cm14,
- // y.cmsl1, y.cmsl2, y.cmsl3, y.cmsl4, y.cmsl5, y.cmsl6, y.cmsl7, y.cmsl8, y.cmsl9, y.cmsl10,y.cmsl11,y.cmsl12,y.cmsl13,y.cmsl14,
- // y.scsl1, y.scsl2, y.scsl3, y.scsl4, y.scsl5, y.scsl6, y.scsl7, y.scsl8, y.scsl9, y.scsl10, y.scsl11, y.scsl12, y.scsl13, y.scsl14
- // ";
- // if (preg_match('/-(\d{2})$/', $order, $matches)) {
- // $number = (int)$matches[1];
- // if ($number > 70) {
- // $data = \db('工单_基本资料')->alias('j')
- // ->distinct('y.子订单编号')
- // ->field($field)
- // ->join('工单_印件资料 y', 'j.订单编号 = y.订单编号', 'left')
- // ->where('y.船样',1)
- // ->whereNull('y.Mod_rq')
- // ->where('y.子订单编号', $order)
- // ->select();
- // } else {
- // //echo '两位数子订单';
- // $ddbh = explode('-', $order)[0];//获取订单编号
- // //【查询尺码、制单数、填写报工新增实裁数】
- // $data = \db('工单_基本资料')->alias('j')
- // ->distinct('y.子订单编号')
- // ->field($field)
- // ->join('工单_印件资料 y', 'j.订单编号 = y.订单编号', 'left')
- // ->where('y.船样',0)->whereNull('y.Mod_rq')
- // ->where('y.子订单编号', 'like', '%' . $ddbh . '%')
- // ->select();
- // }
- // }else{
- // $ddbh = explode('-', $order)[0];//获取订单编号
- // //【查询尺码、制单数、填写报工新增实裁数】
- // $data = \db('工单_基本资料')->alias('j')
- // ->distinct('y.子订单编号')
- // ->field($field)
- // ->join('工单_印件资料 y', 'j.订单编号 = y.订单编号', 'left')
- // ->where('y.船样',0)->whereNull('y.Mod_rq')
- // ->where('y.子订单编号', 'like', '%' . $ddbh . '%')
- // ->select();
- // }
- //
- // $dataEntry = [];
- // $list = [];
- // $headers = [];//存放尺码表头
- // foreach ($data as $item) {
- // // 初始化尺码与数量映射数组
- // $cmScslMapping = [];
- // for ($i = 1; $i <= 14; $i++) {
- // $cmValue = $item['cm' . $i];
- // $scslValue = $item['scsl' . $i];
- // if (!is_null($cmValue) && $cmValue !== 0) {
- // $cmScslMapping[$cmValue] = ($scslValue === 0 || is_null($scslValue)) ? '' : $scslValue;
- // if (!in_array($cmValue, $headers)) {
- // $headers[] = $cmValue;
- // }
- // }
- // }
- //
- // // 将尺码数据平铺到主要数据中(表格数据)
- // $orderData = [
- // '订单编号' => $item['订单编号'],
- // '子订单编号' => $item['子订单编号'],
- // '款号' => $item['款号'],
- // '款式' => $item['款式'],
- // '颜色' => $item['颜色备注'],
- // 'zdtotal' => $item['zdtotal'],
- // 'sctotal' => $item['sctotal'],
- // '单位' => $item['单位'],
- // 'Sys_id' => $item['Sys_id'],
- // 'Sys_rq' => $item['Sys_rq'],
- // ];
- // // 平铺尺码映射数据
- // $orderData = array_merge($orderData, $cmScslMapping);
- // $dataEntry[] = $orderData;
- // // list 列表部分
- // $entry = [];
- // for ($i = 1; $i <= 14; $i++) {
- // $entry['cm' . $i] = ($item['cm' . $i] === 0 || is_null($item['cm' . $i])) ? '' : $item['cm' . $i];
- // $entry['cmsl' . $i] = ($item['cmsl' . $i] === 0 || is_null($item['cmsl' . $i])) ? '' : $item['cmsl' . $i];
- // $entry['scsl' . $i] = ($item['scsl' . $i] === 0 || is_null($item['scsl' . $i])) ? '' : $item['scsl' . $i];
- // }
- // $entry['订单编号'] = $item['订单编号'];
- // $entry['子订单编号'] = $item['子订单编号'];
- // $entry['UniqId'] = $item['UniqId'];
- // $entry['zdtotal'] = $item['zdtotal'];
- // $entry['颜色'] = $item['颜色'];
- // $entry['款式'] = $item['款式'];
- // $entry['款号'] = $item['款号'];
- // $entry['color_id'] = $item['color_id'];
- // $entry['颜色备注'] = $item['颜色备注'];
- // $list[] = $entry;
- // }
- //
- //
- // // 如果 $order 含逗号,取第一个逗号前的子订单编号
- // $order = explode(',', $order)[0];
- // $matchedOrder = null;
- // foreach ($list as $mergedOrder) {
- // if ($mergedOrder['子订单编号'] === $order) {
- // $matchedOrder = $mergedOrder;
- // break;
- // }
- // }
- // $allScslEmpty = true;
- // for ($i = 1; $i <= 14; $i++) {
- // if (!empty($matchedOrder["scsl$i"])) {
- // $allScslEmpty = false;
- // break;
- // }
- // }
- //
- // if ($allScslEmpty) {
- // //当前订单未裁剪 请裁剪后报工
- // $this->success('查询失败', [
- // 'code' => 1,
- // 'serial' => '',
- // 'serial_num' => '',
- // 'headers' => '',
- // 'records' => '',
- // ]);
- // return;
- // }
- //
- // $clwhere['sczl_jtbh'] = $params['sys_sbID'];
- // $clwhere['子订单编号'] = $order;
- // $clwhere['mod_rq'] = null;
- // $clwhere['工序名称'] = $params['code'];
- // $cljclist = \db('设备_产量计酬')
- // ->field('订单编号,子订单编号,尺码,数量,mod_rq')
- // ->where($clwhere)
- // ->select();
- // $result = [];
- // $totalQuantity = 0; // 总数量初始化
- // $orderNumber = ''; // 订单编号初始化
- // foreach ($cljclist as $item) {
- // $size = $item['尺码'];
- // $orderNumber = $item['订单编号'];
- // if (isset($result[$size])) {
- // $result[$size] += $item['数量'];
- // } else {
- // $result[$size] = $item['数量'];
- // }
- // // 累加总数量
- // $totalQuantity += $item['数量'];
- // }
- // $result['订单编号'] = $orderNumber;
- // foreach ($result as $size => $quantity) {
- // if ($size !== '订单编号' && $size !== '数量') {
- // $result[$size] = '合计(' . $quantity . ')';
- // }
- // }
- // $result['数量'] = '合计(' . $totalQuantity . ')';
- //
- // $where = [];
- // if (strpos($order, '-') !== false) {
- // $where['c.子订单编号'] = $order;
- // } else {
- // $where['c.订单编号'] = ['like', '%' . $order . '%'];
- // }
- //
- // $where['c.工序编号'] = '6';
- // $where['c.mod_rq'] = null;
- // $existingRecords = \db('设备_产量计酬')->alias('c')
- // ->field('c.订单编号, c.子订单编号, c.款号, c.工序编号, c.工序名称, c.尺码,
- // CASE
- // WHEN c.工序名称 IN ("裁剪", "车缝") THEN c.数量
- // ELSE c.s_num
- // END as 数量,
- // c.sczl_jtbh, c.sczl_bh, c.尾包, c.sys_rq, c.serial, c.serial_num,c.UniqId,
- // y.zdtotal, y.sctotal, j.款式, y.颜色,y.颜色备注')
- // ->join('工单_印件资料 y', 'c.子订单编号 = y.子订单编号', 'left')
- // ->join('工单_基本资料 j', 'c.订单编号 = j.订单编号', 'left')
- // ->where($where)
- // ->order('c.UniqId desc')
- // ->group('c.订单编号, c.子订单编号, c.款号, c.工序编号, c.工序名称, c.尺码, c.数量, c.sczl_jtbh, c.sczl_bh, c.尾包, c.sys_rq, c.serial, c.serial_num, j.款式')
- // ->select();
- //
- // $sizeSummary = [];
- // $sizes = [];
- // foreach ($existingRecords as $record) {
- // $size = $record['尺码'];
- // $quantity = $record['数量'];
- // $serial = $record['serial'];
- // $serialNum = $record['serial_num']; // serial_num 分组
- // $processNumber = $record['工序编号']; // 工序编号
- // // 初始化尺码
- // if (!in_array($size, $sizes)) {
- // $sizes[] = $size;
- // }
- // // 检查是否已有相同的 serial_num 组合
- // if (!isset($sizeSummary[$serialNum])) {
- // $sizeSummary[$serialNum] = [
- // '订单编号' => $record['订单编号'],
- // '子订单编号' => $record['子订单编号'],
- // '款号' => $record['款号'],
- // '款式' => $record['款式'],
- // '工序编号' => $record['工序编号'],
- // '工序名称' => $record['工序名称'],
- // '数量' => '0', // 记录总数量
- // '尾包' => $record['尾包'] == 1 ? '是' : '否',
- // '颜色' => $record['颜色'],
- // '颜色备注' => $record['颜色备注'],
- // '机台号' => $record['sczl_jtbh'],
- // '组别' => $record['sczl_bh'],
- // 'serial' => [], // 流水号数组
- // 'sys_rq' => $record['sys_rq'],
- // 'UniqId' => $record['UniqId'],
- // '尺码数据' => [] // 用于存储每个尺码对应的流水号和数量
- // ];
- // }
- //
- // // 将流水号添加到 serial 数组
- // $sizeSummary[$serialNum]['serial'][] = $serial;
- //
- // // 累加数量到总数量
- // $sizeSummary[$serialNum]['数量'] += $quantity;
- //
- // // 记录尺码数据
- // if (!isset($sizeSummary[$serialNum]['尺码数据'][$size])) {
- // $sizeSummary[$serialNum]['尺码数据'][$size] = [];
- // }
- //
- // // 添加尺码对应的流水号和数量
- // $sizeSummary[$serialNum]['尺码数据'][$size][] = $serial . ' (' . $quantity . ')';
- // }
- //
- // // 对每个工序的 serial 进行处理,并转换为逗号分隔的字符串
- // $finalRecords = [];
- // foreach ($sizeSummary as &$summary) {
- // // 将 serial 数组按数值降序排序
- // sort($summary['serial'], SORT_NUMERIC);
- // $summary['serial'] = implode(',', $summary['serial']);
- //
- // // 合并尺码数据到同一层级
- // foreach ($summary['尺码数据'] as $size => $serials) {
- // $summary[$size] = implode(', ', $serials); // 尺码对应的流水号和数量
- // }
- //
- // unset($summary['尺码数据']); // 移除尺码数据数组,直接将数据合并到 summary
- // $finalRecords[] = $summary;
- // }
- //
- // // 尺码排序(数字在前,字母在后)
- // usort($sizes, function ($a, $b) {
- // $sizeOrder = [
- // 'XXXS' => 1,
- // 'XXS' => 2,
- // 'XS' => 3,
- // 'S' => 4,
- // 'M' => 5,
- // 'L' => 6,
- // 'XL' => 7,
- // '2XL' => 8,
- // 'XXL' => 9,
- // '3XL' => 10,
- // 'XXXL' => 11,
- // '4XL' => 12,
- // 'XXXXL' => 13,
- // '5XL' => 14,
- // 'XXXXXL' => 15
- // ];
- // if (is_numeric($a) && is_numeric($b)) return $a - $b;
- // if (is_numeric($a)) return -1;
- // if (is_numeric($b)) return 1;
- // return ($sizeOrder[$a] ?? 100) - ($sizeOrder[$b] ?? 100);
- // });
- //
- // // 将汇总合计记录添加到最前面
- // array_unshift($finalRecords, $result);
- //
- // // 查询流水号(包数)序号
- // $res_serial = \db('设备_产量计酬')
- // ->field('子订单编号, MAX(CAST(serial AS UNSIGNED)) as serial, MAX(CAST(serial_num AS UNSIGNED)) as serial_num')
- // ->where('子订单编号', $order)
- // ->whereNull('mod_rq')// 查询未删除数据
- // ->where('sczl_jtbh', $params['sys_sbID'])
- // ->group('子订单编号')
- // ->find();
- // // 默认值填充(字符串带前导零)
- // $res_serial['serial'] = empty($res_serial['serial']) ? '000' : str_pad($res_serial['serial'], 3, '0', STR_PAD_LEFT);
- // $res_serial['serial_num'] = empty($res_serial['serial_num']) ? '000' : str_pad($res_serial['serial_num'], 3, '0', STR_PAD_LEFT);
- // // 先加 1,再格式化为 3 位
- // $next_serial = str_pad((int)$res_serial['serial'] + 1, 3, '0', STR_PAD_LEFT);
- // $next_serial_num = str_pad((int)$res_serial['serial_num'] + 1, 3, '0', STR_PAD_LEFT);
- //
- // $this->success('请求成功', [
- // 'serial' => $next_serial, // 流水号
- // 'serial_num' => $next_serial_num, // 序号
- // 'list' => $matchedOrder, // 报工前需要的数据
- // 'headers' => $sizes, // 尺码表头
- // 'records' =>$finalRecords // 查询报工后历史记录
- // ]);
- // }else{
- // //按照订单编号查询
- // $this->success('请求成功', [
- // 'serial' => '', // // 流水号(包数)
- // 'serial_num' => '', // 序号
- // 'list' => '', // 报工
- // 'headers' => '',// 尺码表头
- // 'records' => '' // 查询历史记录
- // ]);
- // }
- break;
- case '包装':
- //判断是否为子订单编号【$order:DC2503291-0703 子订单编号】
- if (strpos($order, '-') !== false) {
- // 定义查询字段
- $field = "
- y.订单编号, y.子订单编号, y.款号, j.款式, y.颜色,
- y.zdtotal, y.sctotal, j.单位, y.Sys_id, y.Sys_rq,
- y.UniqId, y.sc_rq, y.颜色备注, y.color_id,y.船样,
- y.cm1, y.cm2, y.cm3, y.cm4, y.cm5, y.cm6, y.cm7, y.cm8, y.cm9, y.cm10,y.cm11,y.cm12,y.cm13,y.cm14,
- y.cmsl1, y.cmsl2, y.cmsl3, y.cmsl4, y.cmsl5, y.cmsl6, y.cmsl7, y.cmsl8, y.cmsl9, y.cmsl10,y.cmsl11,y.cmsl12,y.cmsl13,y.cmsl14,
- y.scsl1, y.scsl2, y.scsl3, y.scsl4, y.scsl5, y.scsl6, y.scsl7, y.scsl8, y.scsl9, y.scsl10, y.scsl11, y.scsl12, y.scsl13, y.scsl14
- ";
- // 根据订单类型查询数据
- if (preg_match('/-(\d{2})$/', $order, $matches)) {
- $number = (int)$matches[1];
- if ($number > 70) {
- // 船样订单查询
- $data = \db('工单_基本资料')->alias('j')
- ->distinct('y.子订单编号')
- ->field($field)
- ->join('工单_印件资料 y', 'j.订单编号 = y.订单编号', 'left')
- ->where('y.船样',1)
- ->whereNull('y.Mod_rq')
- ->where('y.子订单编号', $order)
- ->select();
- } else {
- // 普通两位数子订单
- $ddbh = explode('-', $order)[0];//获取订单编号
- $data = \db('工单_基本资料')->alias('j')
- ->distinct('y.子订单编号')
- ->field($field)
- ->join('工单_印件资料 y', 'j.订单编号 = y.订单编号', 'left')
- ->where('y.船样',0)->whereNull('y.Mod_rq')
- ->where('y.子订单编号', 'like', '%' . $ddbh . '%')
- ->select();
- }
- } else {
- // 其他子订单
- $ddbh = explode('-', $order)[0];//获取订单编号
- $data = \db('工单_基本资料')->alias('j')
- ->distinct('y.子订单编号')
- ->field($field)
- ->join('工单_印件资料 y', 'j.订单编号 = y.订单编号', 'left')
- ->where('y.船样',0)->whereNull('y.Mod_rq')
- ->where('y.子订单编号', 'like', '%' . $ddbh . '%')
- ->select();
- }
- // 处理查询到的数据
- $dataEntry = [];
- $list = [];
- $headers = [];//存放尺码表头
- foreach ($data as $item) {
- // 处理尺码与数量映射
- $cmScslMapping = [];
- for ($i = 1; $i <= 14; $i++) {
- $cmValue = $item['cm' . $i];
- $scslValue = $item['scsl' . $i];
- if (!is_null($cmValue) && $cmValue !== 0) {
- $cmScslMapping[$cmValue] = ($scslValue === 0 || is_null($scslValue)) ? '' : $scslValue;
- if (!in_array($cmValue, $headers)) {
- $headers[] = $cmValue;
- }
- }
- }
- // 构建表格数据
- $orderData = [
- '订单编号' => $item['订单编号'],
- '子订单编号' => $item['子订单编号'],
- '款号' => $item['款号'],
- '款式' => $item['款式'],
- '颜色' => $item['颜色备注'],
- 'zdtotal' => $item['zdtotal'],
- 'sctotal' => $item['sctotal'],
- '单位' => $item['单位'],
- 'Sys_id' => $item['Sys_id'],
- 'Sys_rq' => $item['Sys_rq'],
- ];
- $orderData = array_merge($orderData, $cmScslMapping);
- $dataEntry[] = $orderData;
- // 构建列表数据
- $entry = [];
- for ($i = 1; $i <= 14; $i++) {
- $entry['cm' . $i] = ($item['cm' . $i] === 0 || is_null($item['cm' . $i])) ? '' : $item['cm' . $i];
- $entry['cmsl' . $i] = ($item['cmsl' . $i] === 0 || is_null($item['cmsl' . $i])) ? '' : $item['cmsl' . $i];
- $entry['scsl' . $i] = ($item['scsl' . $i] === 0 || is_null($item['scsl' . $i])) ? '' : $item['scsl' . $i];
- }
- $entry['订单编号'] = $item['订单编号'];
- $entry['子订单编号'] = $item['子订单编号'];
- $entry['UniqId'] = $item['UniqId'];
- $entry['zdtotal'] = $item['zdtotal'];
- $entry['颜色'] = $item['颜色'];
- $entry['款式'] = $item['款式'];
- $entry['款号'] = $item['款号'];
- $entry['color_id'] = $item['color_id'];
- $entry['颜色备注'] = $item['颜色备注'];
- $list[] = $entry;
- }
- // 获取匹配的订单数据
- $order = explode(',', $order)[0];
- $matchedOrder = null;
- foreach ($list as $mergedOrder) {
- if ($mergedOrder['子订单编号'] === $order) {
- $matchedOrder = $mergedOrder;
- break;
- }
- }
- // 检查实裁数是否为空
- $allScslEmpty = true;
- if ($matchedOrder) {
- for ($i = 1; $i <= 14; $i++) {
- if (!empty($matchedOrder["scsl$i"])) {
- $allScslEmpty = false;
- break;
- }
- }
- }
- if ($allScslEmpty) {
- // 当前子订单未裁剪 请裁剪后报工
- $this->success('当前子订单未裁剪 请裁剪后报工', [
- 'code' => 1,
- 'serial' => '',
- 'serial_num' => '',
- 'headers' => '',
- 'records' => '',
- ]);
- return;
- }
- // 查询产量计酬记录
- $clwhere = [
- 'sczl_jtbh' => $params['sys_sbID'],
- '子订单编号' => $order,
- 'mod_rq' => null,
- '工序名称' => $params['code']
- ];
- $cljclist = \db('设备_产量计酬')
- ->field('订单编号,子订单编号,尺码,数量,mod_rq')
- ->where($clwhere)
- ->select();
- // 汇总产量记录
- $result = [];
- $totalQuantity = 0;
- $orderNumber = '';
- foreach ($cljclist as $item) {
- $size = $item['尺码'];
- $orderNumber = $item['订单编号'];
- if (isset($result[$size])) {
- $result[$size] += $item['数量'];
- } else {
- $result[$size] = $item['数量'];
- }
- $totalQuantity += $item['数量'];
- }
- $result['订单编号'] = $orderNumber;
- foreach ($result as $size => $quantity) {
- if ($size !== '订单编号' && $size !== '数量') {
- $result[$size] = '合计(' . $quantity . ')';
- }
- }
- $result['数量'] = '合计(' . $totalQuantity . ')';
- // 查询现有工序记录
- $where = [
- 'c.子订单编号' => $order,
- 'c.工序编号' => '7',
- 'c.mod_rq' => null
- ];
- $existingRecords = \db('设备_产量计酬')->alias('c')
- ->field('c.订单编号, c.子订单编号, c.款号, c.工序编号, c.工序名称, c.尺码,
- CASE
- WHEN c.工序名称 IN ("裁剪", "车缝") THEN c.数量
- ELSE c.s_num
- END as 数量,
- c.sczl_jtbh, c.sczl_bh, c.尾包, c.sys_rq, c.serial, c.serial_num,c.UniqId,
- y.zdtotal, y.sctotal, j.款式, y.颜色,y.颜色备注')
- ->join('工单_印件资料 y', 'c.子订单编号 = y.子订单编号', 'left')
- ->join('工单_基本资料 j', 'c.订单编号 = j.订单编号', 'left')
- ->where($where)
- ->order('c.UniqId desc')
- ->group('c.订单编号, c.子订单编号, c.款号, c.工序编号, c.工序名称, c.尺码, c.数量, c.sczl_jtbh, c.sczl_bh, c.尾包, c.sys_rq, c.serial, c.serial_num, j.款式')
- ->select();
- // 处理现有记录
- $sizeSummary = [];
- $sizes = [];
- foreach ($existingRecords as $record) {
- $size = $record['尺码'];
- $quantity = $record['数量'];
- $serial = $record['serial'];
- $serialNum = $record['serial_num'];
- // 收集尺码
- if (!in_array($size, $sizes)) {
- $sizes[] = $size;
- }
- // 初始化serial_num分组
- if (!isset($sizeSummary[$serialNum])) {
- $sizeSummary[$serialNum] = [
- '订单编号' => $record['订单编号'],
- '子订单编号' => $record['子订单编号'],
- '款号' => $record['款号'],
- '款式' => $record['款式'],
- '工序编号' => $record['工序编号'],
- '工序名称' => $record['工序名称'],
- '数量' => 0,
- '尾包' => $record['尾包'] == 1 ? '是' : '否',
- '颜色' => $record['颜色'],
- '颜色备注' => $record['颜色备注'],
- '机台号' => $record['sczl_jtbh'],
- '组别' => $record['sczl_bh'],
- 'serial' => [],
- 'sys_rq' => $record['sys_rq'],
- 'UniqId' => $record['UniqId'],
- '尺码数据' => []
- ];
- }
- // 添加流水号
- $sizeSummary[$serialNum]['serial'][] = $serial;
- $sizeSummary[$serialNum]['数量'] += $quantity;
- // 记录尺码数据
- if (!isset($sizeSummary[$serialNum]['尺码数据'][$size])) {
- $sizeSummary[$serialNum]['尺码数据'][$size] = [];
- }
- $sizeSummary[$serialNum]['尺码数据'][$size][] = $serial . ' (' . $quantity . ')';
- }
- // 最终记录处理
- $finalRecords = [];
- foreach ($sizeSummary as &$summary) {
- // 排序并合并流水号
- sort($summary['serial'], SORT_NUMERIC);
- $summary['serial'] = implode(',', $summary['serial']);
- // 合并尺码数据
- foreach ($summary['尺码数据'] as $size => $serials) {
- $summary[$size] = implode(', ', $serials);
- }
- unset($summary['尺码数据']);
- $finalRecords[] = $summary;
- }
- // 尺码排序
- $sizeOrder = [
- 'XXXS' => 1, 'XXS' => 2, 'XS' => 3, 'S' => 4, 'M' => 5,
- 'L' => 6, 'XL' => 7, '2XL' => 8, 'XXL' => 9, '3XL' => 10,
- 'XXXL' => 11, '4XL' => 12, 'XXXXL' => 13, '5XL' => 14, 'XXXXXL' => 15
- ];
- usort($sizes, function ($a, $b) use ($sizeOrder) {
- if (is_numeric($a) && is_numeric($b)) return $a - $b;
- if (is_numeric($a)) return -1;
- if (is_numeric($b)) return 1;
- return ($sizeOrder[$a] ?? 100) - ($sizeOrder[$b] ?? 100);
- });
- // 添加汇总记录到最前面
- array_unshift($finalRecords, $result);
- // 查询流水号信息
- $res_serial = \db('设备_产量计酬')
- ->field('子订单编号, MAX(CAST(serial AS UNSIGNED)) as serial, MAX(CAST(serial_num AS UNSIGNED)) as serial_num')
- ->where('子订单编号', $order)
- ->whereNull('mod_rq')
- ->where('sczl_jtbh', $params['sys_sbID'])
- ->group('子订单编号')
- ->find();
- // 处理流水号
- $res_serial['serial'] = empty($res_serial['serial']) ? '000' : str_pad($res_serial['serial'], 3, '0', STR_PAD_LEFT);
- $res_serial['serial_num'] = empty($res_serial['serial_num']) ? '000' : str_pad($res_serial['serial_num'], 3, '0', STR_PAD_LEFT);
- $next_serial = str_pad((int)$res_serial['serial'] + 1, 3, '0', STR_PAD_LEFT);
- $next_serial_num = str_pad((int)$res_serial['serial_num'] + 1, 3, '0', STR_PAD_LEFT);
- $this->success('请求成功', [
- 'serial' => $next_serial,
- 'serial_num' => $next_serial_num,
- 'list' => $matchedOrder,
- 'headers' => $sizes,
- 'records' => $finalRecords
- ]);
- } else {
- // 按照订单编号查询
- $this->success('请求成功', [
- 'serial' => '',
- 'serial_num' => '',
- 'list' => '',
- 'headers' => '',
- 'records' => ''
- ]);
- }
- break;
- default:
- $this->error('无效的 code 参数');
- break;
- }
- }
- /**
- * 出库报工日志
- * 确认出库 恢复出库状态
- */
- public function getTab() {
- if (!$this->request->isPost()) {
- $this->error('非法请求');
- }
- $params = $this->request->param();
- // 校验子订单编号和出库日期
- if (empty($params['order_id'])) {
- $this->error('子订单编号不能为空');
- }
- // 处理出库逻辑
- if ($params['code'] == '出库') {
- if (strpos($params['order_id'], '-') !== false) {
- // 查询传入的子订单编号的记录,获取其颜色备注
- $cklist = \db('工单_印件资料')
- ->field('子订单编号, ck_rq, 颜色备注')
- ->where('子订单编号', $params['order_id'])
- ->find();
- if ($cklist) {
- if (!empty($cklist['ck_rq'])) {
- $this->error('该子订单已完成出库操作,请勿重复操作。');
- } else {
- // 获取相同颜色备注的所有子订单记录
- $sameColorList = \db('工单_印件资料')
- ->field('子订单编号, ck_rq')
- ->where('颜色备注', $cklist['颜色备注'])
- ->whereNull('ck_rq') // 只选择未出库的记录
- ->select();
- // 开始出库操作
- $updateCount1 = 0;
- foreach ($sameColorList as $item) {
- // 更新 '工单_印件资料' 表中所有相同颜色备注的子订单的出库日期
- $result1 = \db('工单_印件资料')
- ->where('子订单编号', $item['子订单编号'])
- ->update(['ck_rq' => date("Y-m-d H:i:s")]);
- if ($result1 !== false) {
- $updateCount1 += $result1;
- }
- }
- // 检查 '工单_基本资料' 表的 '出库日期' 是否为空
- $order = explode('-', $params['order_id'])[0];
- $basicInfo = \db('工单_基本资料')
- ->field('出库日期')
- ->where('订单编号', $order)
- ->find();
- $updateCount2 = 0;
- if (empty($basicInfo['出库日期'])) {
- // 如果 '出库日期' 为空,则更新
- $jbzl = \db('工单_基本资料')
- ->where('订单编号', $order)
- ->fetchSql(true)
- ->update(['出库日期' => date("Y-m-d H:i:s")]);
- $result2 = \db()->query($jbzl);
- if ($result2 !== false) {
- $updateCount2 = $result2;
- }
- }
- // if ($updateCount1 > 0) {
- // // 插入日志
- // foreach ($sameColorList as $item) {
- // $addlist = [
- // 'order_id' => $item['子订单编号'],
- // 'rq' => date("Y-m-d H:i:s"),
- // 'name' => $params['code'],
- // 'sys_id' => $params['sys_id']
- // ];
- // \db('库存_出入库明细')->insertGetId($addlist);
- // }
- // $this->success("出库成功");
- // } else {
- // $this->error('出库失败');
- // }
- }
- } else {
- $this->error('未找到对应的出库订单');
- }
- } else {
- $this->error('请扫描子订单编号进行出库');
- }
- }
- // 处理恢复逻辑
- else if ($params['code'] == '恢复') {
- $cklist = \db('工单_印件资料')
- ->field('子订单编号, ck_rq')
- ->where('子订单编号', $params['order_id'])
- ->find();
- if (!empty($cklist['ck_rq'])) {
- $result1 = \db('工单_印件资料')
- ->where('子订单编号', $params['order_id'])
- ->fetchSql(true)
- ->update(['ck_rq' => null]);
- $updateCount1 = \db()->query($result1);
- // 更新 '工单_基本资料' 表
- $order = explode('-', $params['order_id'])[0];
- $result2 = \db('工单_基本资料')
- ->where('订单编号', $order)
- ->fetchSql(true)
- ->update(['出库日期' => null,'gd_statu'=>'1-计划中']);
- $updateCount2 = \db()->query($result2);
- // if ($updateCount1 > 0 && $updateCount2 > 0) {
- // // 插入日志
- // $addlist = [
- // 'order_id' => $params['order_id'],
- // 'rq' => date("Y-m-d H:i:s"),
- // 'name' => $params['code'],
- // 'sys_id' => $params['sys_id']
- // ];
- // \db('库存_出入库明细')->insertGetId($addlist);
- // $this->success($params['order_id'] . "恢复未出库");
- // } else {
- // $this->error($params['order_id'] . '该子订单是未出库状态,无需再次恢复');
- // }
- } else {
- $this->error('该子订单是未出库状态,无需再次恢复');
- }
- }
- }
- /**
- * 裁剪完工报工修改工单_印件资料表一条数据
- */
- public function getInfo(){
- if (!$this->request->isPost()) {
- $this->error('非法请求');
- }
- $params = $this->request->param();
- // 检查子订单编号和日期是否都存在
- if (!isset($params['order_id']) || empty($params['order_id'])) {
- $this->error('参数错误,子订单编号不能为空');
- }
- if (!isset($params['rq']) || empty($params['rq'])) {
- $this->error('参数错误,日期不能为空');
- }
- function setIfNotEmpty($value) {
- return (!empty($value) && $value != 0) ? $value : '';
- }
- // 先查询当前记录的原始数据
- $existingData = \db('工单_印件资料')
- ->where('子订单编号', $params['order_id'])
- // ->where(function($query) {
- // $query->whereNull('Mod_rq')->whereOr('Mod_rq', '');
- // }) // 查询未删除数据
- // ->order('子订单编号 desc')
- ->find();
- if ($existingData) {
- // 计算新的累加值
- $updateData = [
- 'sc_rq' => date('Y-m-d H:i:s'),//生产报工日期
- 'scsl1' => isset($params['scsl1']) && is_numeric($params['scsl1']) ? $existingData['scsl1'] + $params['scsl1'] : $existingData['scsl1'] + 0,
- 'scsl2' => isset($params['scsl2']) && is_numeric($params['scsl2']) ? $existingData['scsl2'] + $params['scsl2'] : $existingData['scsl2'] + 0,
- 'scsl3' => isset($params['scsl3']) && is_numeric($params['scsl3']) ? $existingData['scsl3'] + $params['scsl3'] : $existingData['scsl3'] + 0,
- 'scsl4' => isset($params['scsl4']) && is_numeric($params['scsl4']) ? $existingData['scsl4'] + $params['scsl4'] : $existingData['scsl4'] + 0,
- 'scsl5' => isset($params['scsl5']) && is_numeric($params['scsl5']) ? $existingData['scsl5'] + $params['scsl5'] : $existingData['scsl5'] + 0,
- 'scsl6' => isset($params['scsl6']) && is_numeric($params['scsl6']) ? $existingData['scsl6'] + $params['scsl6'] : $existingData['scsl6'] + 0,
- 'scsl7' => isset($params['scsl7']) && is_numeric($params['scsl7']) ? $existingData['scsl7'] + $params['scsl7'] : $existingData['scsl7'] + 0,
- 'scsl8' => isset($params['scsl8']) && is_numeric($params['scsl8']) ? $existingData['scsl8'] + $params['scsl8'] : $existingData['scsl8'] + 0,
- 'scsl9' => isset($params['scsl9']) && is_numeric($params['scsl9']) ? $existingData['scsl9'] + $params['scsl9'] : $existingData['scsl9'] + 0,
- 'scsl10' => isset($params['scsl10']) && is_numeric($params['scsl10']) ? $existingData['scsl10'] + $params['scsl10'] : $existingData['scsl10'] + 0,
- 'scsl11' => isset($params['scsl11']) && is_numeric($params['scsl11']) ? $existingData['scsl11'] + $params['scsl11'] : $existingData['scsl11'] + 0,
- 'scsl12' => isset($params['scsl12']) && is_numeric($params['scsl12']) ? $existingData['scsl12'] + $params['scsl12'] : $existingData['scsl12'] + 0,
- 'scsl13' => isset($params['scsl13']) && is_numeric($params['scsl13']) ? $existingData['scsl13'] + $params['scsl13'] : $existingData['scsl13'] + 0,
- 'scsl14' => isset($params['scsl14']) && is_numeric($params['scsl14']) ? $existingData['scsl14'] + $params['scsl14'] : $existingData['scsl14'] + 0,
- 'sctotal' => isset($params['sctotal']) && is_numeric($params['sctotal']) ? $existingData['sctotal'] + $params['sctotal'] : $existingData['sctotal'] + 0,
- // 你可以在这里继续添加其他字段
- ];
- $updateCount = \db('工单_印件资料')
- ->where('子订单编号', $params['order_id'])
- ->fetchSql(true)
- // ->where(function($query) {
- // $query->whereNull('Mod_rq')->whereOr('Mod_rq', '');
- // }) // 查询未删除数据
- ->update($updateData);
- $list_gd = \db()->query($updateCount);
- } else {
- echo "没有找到相关记录";
- }
- // 检查更新结果
- if ($list_gd > 0) {
- $this->success("更新成功");
- } else {
- // 查询数据库,是否能找到对应的子订单编号
- $existingRecord = \db('工单_印件资料')
- ->where('子订单编号', $params['order_id'])
- // ->where('UniqId', $params['UniqId'])
- ->find();
- if ($existingRecord) {
- $this->error('更新失败,可能是提供的更新数据与现有数据相同,未进行任何更改');
- } else {
- $this->error('更新失败,未找到对应的子订单编号');
- }
- }
- }
- /**
- * 手工、大烫、总检、包装完工报工【通用的报工操作函数】
- */
- function reportWork($params) {
- // 查询设备_产量计酬表的数据
- $bglist = \db('设备_产量计酬')->field('订单编号,子订单编号,数量,ci_num,款号,sys_rq,serial,serial_num')
- ->where('UniqId', $params['UniqId'])->fetchSql(true)->find();
- $list_gd = \db()->query($bglist);
- // 查询工单基本资料表的数据
- $orderlist = \db('工单_基本资料')->where('订单编号', $list_gd[0]['订单编号'])->find();
- // 检查code是否为 "包装"
- if ($params['code'] == '包装') {
- // 如果是 "包装",则增加工单基本资料表中的入仓数量
- $addorder['工单入仓数量'] = $orderlist['工单入仓数量'] + $params['sl'];
- $result = \db('工单_基本资料')->where('订单编号', $list_gd[0]['订单编号'])->fetchSql(true)->update($addorder);
- $sql = \db()->query($result);
- }
- // 构建单条记录的函数,传递 $list_gd 作为参数
- function buildRecords($item, $list_gd) {
- return [
- '订单编号' => $item['order'],
- '子订单编号' => $item['order_id'],
- '款号' => $list_gd[0]['款号'],
- 'serial' => $list_gd[0]['serial'],
- 'serial_num' => $list_gd[0]['serial_num'],
- '工序编号' => $item['gx'],
- '工序名称' => $item['gxmc'],
- '尺码' => $item['cm'],
- '数量' => $item['sl'],
- 'sczl_jtbh' => $item['sczl_jtbh'],
- 'sczl_bh' => $item['sczl_bh'],
- '尾包' => $item['wb'],
- 'sys_id' => $item['sys_id'],
- 'sys_rq' => date('Y-m-d H:i:s'),
- 'sczl_rq' => date('Y-m-d'),
- 'ci_num' => $item['ci_num'] - $item['s_num'],
- 's_num' => $item['s_num'],
- ];
- }
- // 检查是否是索引数组(多条记录)
- if (isset($params[0]) && is_array($params[0])) {
- foreach ($params as $item) {
- $list[] = buildRecords($item, $list_gd);
- }
- } else {
- // 处理单条记录
- $list[] = buildRecords($params, $list_gd);
- }
- // 插入数据到设备_产量计酬表
- $result = \db('设备_产量计酬')->insertAll($list);
- if ($result) {
- $this->success('数据插入成功 : ' . date('H:i:s'));
- } else {
- $this->error('数据插入失败');
- }
- }
- /**
- * 报工:裁剪、车缝、手工、大烫、总检、包装
- */
- public function search(){
- if (!$this->request->isPost()) {
- $this->error('非法请求');
- }
- $params = $this->request->param();
- if($params['order_id'] == ''){
- $this->error('请扫描订单后再报工');
- }
- // 根据不同的 code 值执行不同的逻辑
- switch ($params['code']) {
- case '裁剪':
- $order_id = explode('-', $params['order_id']);
- $order = $order_id[0];
- //先查询这条订单是否存在
- $sql = \db('工单_基本资料')->where('订单编号', $order)->fetchSql(true)->find();
- $order_list = \db()->query($sql);
- if (empty($order_list)) {
- $this->error('没有找到对应的订单信息');
- return;
- }
- if($order_list[0]['gd_statu'] == '1-计划中' || $order_list[0]['gd_statu'] == '生产中' || $order_list[0]['gd_statu'] == '2-生产中'){
- DB::name('工单_基本资料')
- ->where('订单编号', $order)
- ->update(['gd_statu' => '已裁剪']);
- }
- //将前端传过来的数据存到数据库
- $insertData = [];
- $dataList = isset($params[0]) && is_array($params[0]) ? $params : [$params];
- foreach ($dataList as $item) {
- $list = [
- '订单编号' => $order_list[0]['订单编号'],
- '款号' => $order_list[0]['生产款号'],
- '子订单编号' => $item['order_id'],
- '工序编号' => '2',
- '工序名称' => '裁剪',
- '尺码' => $item['cm'],
- '数量' => $item['sl'],
- 'sczl_jtbh' => $item['sczl_jtbh'],
- 'sys_id' => $item['sys_id'],
- 'sczl_bh' => $item['sczl_bh'],
- 'sczl_rq' => date('Y-m-d 00:00:00'),
- 'sys_rq' => date('Y-m-d H:i:s')
- ];
- $insertData[] = $list;
- }
- $result = \db('设备_产量计酬')->insertAll($insertData);
- $result ? $this->success('数据插入成功 : ' . date('H:i:s')) : $this->error('数据插入失败');
- break;
- case '车缝':
- $list = [];
- $order_id = explode('-', $params['order_id']);
- $order = $order_id[0];
- $sql = \db('工单_基本资料')->where('订单编号', $order)->fetchSql(true)->find();
- $list_gd = \db()->query($sql); // 查询的结果可能是多条记录,确保是数组
- if($list_gd[0]['gd_statu'] == '1-计划中' || $list_gd[0]['gd_statu'] == '已裁剪' || $list_gd[0]['gd_statu'] == '2-生产中'){
- DB::name('工单_基本资料')
- ->where('订单编号', $order)
- ->update(['gd_statu' => '已车缝']);
- }
- // 查询子订单编号对应的最大 serial 值
- $list_order_id = \db('设备_产量计酬')
- ->field('子订单编号, MAX(serial) as serial')
- ->where('子订单编号', $params['order_id'])
- ->where(function($query) {
- $query->whereNull('mod_rq')->whereOr('mod_rq', '');
- }) // 查询未删除数据
- ->group('子订单编号')
- ->find();
- function buildRecord($item, $list_gd, $list_order_id) {
- return [
- '订单编号' => $list_gd[0]['订单编号'],
- '款号' => $list_gd[0]['生产款号'],
- '子订单编号' => $item['order_id'],
- '工序编号' => 3,
- '工序名称' => '车缝',
- 'serial' => $item['serial'],
- 'ci_num' => (int)$item['sl'],
- 'serial_num' => $item['serial_num'],
- '尺码' => $item['cm'],
- '数量' => (int)$item['sl'],
- 'sczl_jtbh' => $item['sczl_jtbh'],
- 'sys_rq' => date('Y-m-d H:i:s'),
- 'sczl_rq' => date('Y-m-d'),
- '尾包' => $item['wb'],
- 'sys_id' => $item['sys_id'],
- 'sczl_bh' => $item['sczl_bh']
- ];
- }
- if (isset($params[0]) && is_array($params[0])) {
- foreach ($params as $item) {
- $list[] = buildRecord($item, $list_gd, $list_order_id); // 所有记录使用相同的 serial
- }
- } else {
- // 处理单条记录
- $list[] = buildRecord($params, $list_gd, $list_order_id); // 单条记录
- }
- $result = \db('设备_产量计酬')->insertAll($list);
- if ($result) {
- $this->success('数据插入成功 : ' . date('H:i:s'));
- } else {
- $this->error('数据插入失败');
- }
- break;
- case '手工':
- $this->reportWork($params);
- break;
- case '大烫':
- $this->reportWork($params);
- break;
- case '总检':
- $order_id_parts = explode('-', $params['order_id']);
- $order = $order_id_parts[0];
- //查询订单信息
- $list_gd = Db::name('工单_基本资料')
- ->where('订单编号', $order)
- ->whereNull('Mod_rq')
- ->find();
- if (!$list_gd) {
- $this->error('订单不存在');
- }
- $insert_cp_list = [];
- $insert_cj_list = [];
- $isBatch = isset($params[0]) && is_array($params[0]);
- $dataList = $isBatch ? $params : [$params];
- foreach ($dataList as $item) {
- // ---------------- 入仓数据 ----------------
- $insert_cp_list[] = [
- 'order' => $list_gd['订单编号'],
- 'customer' => $list_gd['客户编号'],
- 'order_id' => $item['order_id'],
- 'sl' => (int)$item['sl'],
- 'cm' => $item['cm'],
- 'wb' => $item['wb'],
- 'sys_id' => $item['sys_id'],
- 'sys_rq' => date('Y-m-d H:i:s')
- ];
- // ---------------- 产量计酬数据 ----------------
- $insert_cj_list[] = [
- '订单编号' => $list_gd['订单编号'],
- '款号' => $list_gd['生产款号'],
- '子订单编号' => $item['order_id'],
- '工序编号' => 6,
- '工序名称' => '总检',
- 'serial' => $item['serial'],
- 'ci_num' => (int)$item['sl'],
- 'serial_num' => $item['serial_num'],
- '尺码' => $item['cm'],
- '数量' => (int)$item['sl'],
- 's_num' => (int)$item['sl'],
- 'sczl_jtbh' => $item['sczl_jtbh'],
- 'sys_rq' => date('Y-m-d H:i:s'),
- 'sczl_rq' => date('Y-m-d'),
- '尾包' => $item['wb'],
- 'sys_id' => $item['sys_id'],
- 'sczl_bh' => $item['sczl_bh']
- ];
- }
- $res1 = \db('成品入仓')->insertAll($insert_cp_list);
- $res2 = \db('设备_产量计酬')->insertAll($insert_cj_list);
- $orderNo = $list_gd['订单编号'];
- // 累计入仓(所有时间)
- $cumulativeData = Db::name('成品入仓')
- ->alias('a')
- ->field('a.order as 订单编号, SUM(a.sl) as 累计入仓数量')
- ->where('a.order', $orderNo)
- ->whereNull('a.mod_rq')
- ->group('a.order')
- ->select();
- $cumulativeMap = [];
- foreach ($cumulativeData as $row) {
- $cumulativeMap[$row['订单编号']] = (int)$row['累计入仓数量'];
- }
- // 裁剪产量(所有时间)
- $prodRecords = Db::name('设备_产量计酬')
- ->field('订单编号, SUM(数量) as 裁剪数量')
- ->where('订单编号', $orderNo)
- ->where('工序名称', '裁剪')
- ->group('订单编号')
- ->select();
- $cutMap = [];
- foreach ($prodRecords as $row) {
- $cutMap[$row['订单编号']] = (int)$row['裁剪数量'];
- }
- $cutQty = $cutMap[$orderNo] ?? 0;
- $cumulativeQty = $cumulativeMap[$orderNo] ?? 0;
- $passRate = $cutQty > 0 ? round($cumulativeQty / $cutQty * 100, 2) : 0;
- $passRateDisplay = $cutQty > 0 ? $passRate . '%' : '0%';
- // 根据合格率决定显示状态
- if($passRate > 95) {
- $status = '已完工';
- } else {
- $status = '已总检' . $passRateDisplay;
- }
- if (in_array($list_gd['gd_statu'], ['1-计划中','已车缝', '2-生产中']) || strpos($list_gd['gd_statu'], '已总检') !== false) {
- DB::name('工单_基本资料')
- ->where('订单编号', $order)
- ->update(['gd_statu' => $status]);
- }
- if ($res1 && $res2) {
- $this->success('数据报工成功 : ' . date('H:i:s'));
- } else {
- $this->error('数据插入失败');
- }
- break;
- case '包装':
- $order_id_parts = explode('-', $params['order_id']);
- $order = $order_id_parts[0];
- $list_gd = \db('工单_基本资料')->where('订单编号', $order)
- ->whereNull('Mod_rq')
- ->find();
- $insert_cj_list = [];
- $isBatch = isset($params[0]) && is_array($params[0]);
- $dataList = $isBatch ? $params : [$params];
- foreach ($dataList as $item) {
- // ---------------- 产量计酬数据 ----------------
- $insert_cj_list[] = [
- '订单编号' => $list_gd['订单编号'],
- '款号' => $list_gd['生产款号'],
- '子订单编号' => $item['order_id'],
- '工序编号' => 7,
- '工序名称' => '包装',
- 'serial' => $item['serial'],
- 'ci_num' => (int)$item['sl'],
- 'serial_num' => $item['serial_num'],
- '尺码' => $item['cm'],
- '数量' => (int)$item['sl'],
- 's_num' => (int)$item['sl'],
- 'sczl_jtbh' => $item['sczl_jtbh'],
- 'sys_rq' => date('Y-m-d H:i:s'),
- 'sczl_rq' => date('Y-m-d'),
- '尾包' => $item['wb'],
- 'sys_id' => $item['sys_id'],
- 'sczl_bh' => $item['sczl_bh']
- ];
- }
- $res2 = \db('设备_产量计酬')->insertAll($insert_cj_list);
- if ($res2) {
- $this->success('数据报工成功 : ' . date('H:i:s'));
- } else {
- $this->error('数据插入失败');
- }
- break;
- default:
- $this->error('无效的 code 参数');
- break;
- }
- }
- /**
- * 物理地址获取机台编号
- * /work_order_spot_check/getMachineMac
- */
- public function getMachineMac(){
- if ($this->request->isGet() == false){$this->error('非法请求');}
- $params = $this->request->get();
- if (empty($params['sys_sbID'])){$this->error('物理地址参数不能为空');}
- $data = \db('设备_基本资料')->where('sys_sbID', $params['sys_sbID'])
- ->field('设备编号 as 机台号,生产工序,工序,rtrim(设备编组) as 组别,组长,sys_sbID')
- // ->where('生产工序',$params['code'])
- ->find();
- $this->success('请求成功', $data);
- }
- /**
- * 删除报工记录
- * /work_order_spot_check/del
- */
- public function del() {
- // 判断请求方式是否为 GET
- if (!$this->request->isGet()) {
- return $this->error('请求错误');
- }
- // 获取请求参数
- $param = $this->request->param();
- // 检查 UniqId 参数是否存在
- if (empty($param['UniqId'])) {
- return $this->error('UniqId 参数错误');
- }
- // 将 UniqId 的值按逗号分割成数组
- $printIdArray = explode(',', $param['UniqId']);
- // 初始化失败计数器
- $failureCount = 0;
- // 开启事务
- \db()->startTrans();
- try {
- foreach ($printIdArray as $uniqId) {
- // 根据 UniqId 查询设备_产量计酬表中的数据
- $result = \db('设备_产量计酬')->where('UniqId', $uniqId)
- ->field('子订单编号, 订单编号, 尺码, 数量, sczl_bh, 工序名称')
- ->find();
- // 如果查询不到数据,跳过当前处理
- if (!$result) {
- $failureCount++;
- continue;
- }
- // 判断工序名称是否是“裁剪”
- if (isset($param['sys_id']) && strpos($param['sys_id'], '裁剪') !== false) {
- // 如果工序名称包含“裁剪”,更新工单_印件资料表
- $yresult = \db('工单_印件资料')->where('子订单编号', $result['子订单编号'])
- ->whereNull('Mod_rq') // 仅更新没有修改日期的记录
- ->find();
- // 如果没有查询到工单印件资料表的数据,跳过
- if (!$yresult) {
- $failureCount++;
- continue;
- }
- // 处理尺码和数量更新
- $size = $result['尺码'];
- $quantity = $result['数量'];
- $updateData = [];
- // 遍历工单中的尺码字段(cm1 到 cm10),找到匹配的尺码
- for ($i = 1; $i <= 14; $i++) {
- $cmField = 'cm' . $i;
- $scslField = 'scsl' . $i;
- if (isset($yresult[$cmField]) && $yresult[$cmField] === $size) {
- // 找到匹配的尺码后,更新对应的数量字段
- if (isset($yresult[$scslField])) {
- $yresult[$scslField] -= $quantity;
- if ($yresult[$scslField] < 0) {
- $yresult[$scslField] = 0; // 防止数量为负数
- }
- $updateData[$scslField] = $yresult[$scslField];
- }
- break;
- }
- }
- // 计算更新后的总数量
- $newTotal = 0;
- for ($i = 1; $i <= 14; $i++) {
- $scslField = 'scsl' . $i;
- if (isset($yresult[$scslField])) {
- $newTotal += $yresult[$scslField];
- }
- }
- // 更新工单_印件资料表
- \db('工单_印件资料')
- ->where('子订单编号', $result['子订单编号'])
- ->update(['sctotal' => $newTotal] + $updateData);
- }
- // 更新设备_产量计酬表
- $updateData = [
- 'mod_rq' => date('Y-m-d H:i:s'),
- 'delsys_id' => $param['sys_id']
- ];
- // 执行更新操作
- $updateResult = \db('设备_产量计酬')->where('UniqId', $uniqId)->update($updateData);
- // 如果更新失败,记录失败
- if ($updateResult === false) {
- $failureCount++;
- }
- }
- // 提交事务
- \db()->commit();
- } catch (\Exception $e) {
- // 发生异常时回滚事务
- \db()->rollback();
- return $this->error('操作失败:' . $e->getMessage());
- }
- // 返回操作结果
- if ($failureCount === 0) {
- return $this->success('删除成功');
- } else {
- return $this->error("操作完成,但有 {$failureCount} 条记录更新失败");
- }
- }
- /**
- * 面料出库报工
- */
- public function outReport()
- {
- if ($this->request->isPost() === false){
- $this->error('请求错误');
- }
- $param = Request::instance()->post();
- if (empty($param)){
- $this->error('参数错误');
- }
- foreach ($param as $item) {
- // 更新库存数据
- $Inventory = \db('物料_库存')
- ->where('批次号',$item['批次号'])
- ->field('库存数量,领用数量')
- ->find();
- $InventoryData = [
- '批次号' => $item['批次号'],
- '关联号' => $item['关联编号'],
- '物料编号' => $item['物料编码'],
- '物料名称' => $item['物料名称'],
- '领用数量' => (float)$Inventory['领用数量'] + (float)$item['number'],
- '库存数量' => (float)$Inventory['库存数量'] - (float)$item['number'],
- '实际门幅' => $item['实际门幅'],
- '单位' => $item['单位'],
- '状态' => 1,
- 'departname' => $item['departname'],
- 'remark' => isset($item['remark']) ? $item['remark'] : '',
- 'sys_id' => $item['sys_id'],
- 'sys_rq' => date('Y-m-d H:i:s'),
- ];
- $sql = \db('物料_库存')->where('批次号',$item['批次号'])->fetchSql(true)->update($InventoryData);
- \db()->query($sql);
- // 记录入库报工日志
- $ReportData = [
- '批次号' => $item['批次号'],
- 'order_id' => $item['order_id'],
- '款号' => $item['款号'],
- '物料编码' => $item['物料编码'],
- '物料名称' => $item['物料名称'],
- '库存数量' => $item['number'],
- 'number' => $item['number'],
- 'rq' => $item['rq'],
- 'name' => $item['name'],
- 'sys_id' => $item['sys_id'],
- 'receipt_number' => $item['receipt_number'],
- '客户编号' => $item['客户编号'],
- 'departname' => $item['departname'],
- 'remark' => isset($item['remark']) ? $item['remark'] : '',
- '款式' => $item['款式'],
- 'sys_rq' => date('Y-m-d H:i:s'),
- ];
- $sql = \db('库存_出入库明细')->fetchSql(true)->insert($ReportData);
- \db()->query($sql);
- }
- $this->success('成功');
- }
- /**
- * 入库订单信息模糊查询
- */
- public function InputOrderSearch()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $param = $this->request->param();
- if (empty($param)){
- $this->error('参数错误');
- }
- $list = \db('工单_基本资料')->alias('a')
- ->field('
- a.订单编号,
- a.生产款号,
- a.客户编号,
- a.款式,
- a.订单数量,
- a.落货日期,
- a.接单日期,
- a.Sys_id as 创建人员,
- a.Sys_rq as 创建时间,
- b.BOM_颜色 as 颜色,
- b.BOM_物料编码 as 物料编码,
- b.BOM_物料名称 as 物料名称,
- GROUP_CONCAT(DISTINCT c.订单编号 SEPARATOR ",") AS 关联订单,
- c.关联编号')
- ->group('物料编码')
- ->join('工单_面料资料 b','a.订单编号 = b.BOM_工单编号')
- ->join('工单关联表 c','a.订单编号 = c.订单编号 AND b.BOM_物料编码 = c.物料编号')
- ->where('a.生产款号|a.订单编号|b.BOM_物料编码','like','%'.$param['search'].'%')
- ->where('a.Mod_rq',null)
- ->where('b.Mod_rq',null)
- ->where('c.Mod_rq',null)
- ->order('a.订单编号 desc')
- ->select();
- if (empty($list)){
- $res = \db('工单_基本资料')->alias('a')
- ->join('工单_印件资料 b','a.订单编号 = b.订单编号')
- ->join('工单_bom资料 c','a.订单编号 = c.BOM_工单编号')
- ->where('b.订单编号','like','%'.$param['search'].'%')
- ->field('a.订单编号,a.生产款号,b.颜色备注,c.BOM_物料名称,a.Sys_id')
- ->where('a.Mod_rq',null)
- ->where('b.Mod_rq',null)
- ->where('c.Mod_rq',null)
- ->group('c.BOM_物料名称')
- ->select();
- foreach ($res as $index => &$item) {
- $item['物料编码'] = $item['生产款号'] . '-' . $item['颜色备注'] . ($index + 1);
- }
- unset($item);
- $arr = \db('工单关联表')
- ->orderRaw("CAST(SUBSTRING(关联编号, 5) AS UNSIGNED) DESC")
- ->find();
- // 2. 提取数字部分并加一
- $num = intval(substr($arr['关联编号'], 4)) + 1;
- // 3. 重新拼接新的编号(保留 GDGL 前缀)
- $newCode = 'GDGL' . $num;
- // 3. 定义当前日期
- $today = date('Y-m-d');
- // 4. 循环插入到两个表
- foreach ($res as $row) {
- // 插入到 工单_面料资料
- $sql = \db('工单_面料资料')->fetchSql(true)->insert([
- 'BOM_工单编号' => $row['订单编号'],
- 'BOM_颜色' => $row['颜色备注'],
- 'BOM_物料编码' => $row['物料编码'],
- 'BOM_物料名称' => $row['BOM_物料名称'],
- 'Sys_ID' => $row['Sys_id'],
- 'Sys_rq' => $today,
- ]);
- \db()->query($sql);
- // 插入到 工单关联表
- $sqll = \db('工单关联表')->fetchSql(true)->insert([
- '关联编号' => $newCode,
- '订单编号' => $row['订单编号'],
- '生产款号' => $row['生产款号'],
- '颜色' => $row['颜色备注'],
- '物料编号' => $row['物料编码'],
- '物料名称' => $row['BOM_物料名称'],
- 'Sys_id' => $row['Sys_id'],
- 'Sys_rq' => $today,
- ]);
- \db()->query($sqll);
- }
- $list = \db('工单_基本资料')
- ->alias('a')
- ->join('工单_面料资料 b','a.订单编号 = b.BOM_工单编号')
- ->join('工单关联表 c','a.订单编号 = c.订单编号 AND b.BOM_物料编码 = c.物料编号')
- ->where('a.生产款号|a.订单编号|b.BOM_物料编码','like','%'.$param['search'].'%')
- ->where('a.Mod_rq',null)
- ->where('b.Mod_rq',null)
- ->where('c.Mod_rq',null)
- ->field('a.订单编号,a.生产款号,a.客户编号,a.款式,a.订单数量,a.落货日期,a.接单日期,a.Sys_id as 创建人员,
- a.Sys_rq as 创建时间,b.BOM_颜色 as 颜色,b.BOM_物料编码 as 物料编码,b.BOM_物料名称 as 物料名称,GROUP_CONCAT(DISTINCT c.订单编号 SEPARATOR ",") AS 关联订单,c.关联编号')
- ->group('物料编码')
- ->order('a.订单编号 desc')
- ->select();
- $this->success('成功',$list);
- }else{
- if(count($list) > 800){
- $this->success('成功','');
- }else{
- $this->success('成功',$list);
- }
- // $this->success('成功',$list);
- }
- }
- /**
- * 面料入库报工
- */
- public function inputStash()
- {
- if (!$this->request->isPost()) {
- $this->error('请求错误');
- }
- $param = Request::instance()->post();
- if (empty($param)) {
- $this->error('参数错误');
- }
- // 开启事务
- Db::startTrans();
- try {
- //获取最大批次号(兼容 GDGL 前缀)
- $lastBatch = Db::name('物料_库存')
- ->where('批次号', 'like', 'GDGL%')
- ->orderRaw('CAST(SUBSTRING(批次号, 5) AS UNSIGNED) DESC')
- ->value('批次号');
- $currentNumber = $lastBatch ? intval(substr($lastBatch, 4)) : 0;
- $insertInventory = []; // 新入库
- $updateInventory = []; // 更新库存
- $insertLogs = []; // 出入库日志
- foreach ($param as $item) {
- if (empty($item['物料编码']) || empty($item['关联编号']) || !isset($item['number']) || !is_numeric($item['number']) || $item['number'] <= 0) {
- continue;
- }
- // 唯一KEY:物料编码 + 物料名称 + 关联号 + 未删除
- $existingBatch = Db::name('物料_库存')
- ->where('物料编号', $item['物料编码'])
- ->where('物料名称', $item['物料名称'])
- ->where('关联号', $item['关联编号'])
- ->whereNull('Mod_rq')
- ->value('批次号');
- if ($existingBatch) {
- //更新库存
- $updateData = [
- '入仓总量' => Db::raw('入仓总量 + ' . intval($item['number'])),
- '库存数量' => Db::raw('库存数量 + ' . intval($item['number'])),
- '实际门幅' => $item['实际门幅'],
- 'departname' => $item['departname'],
- 'remark' => $item['remark'] ?? '',
- 'sys_rq' => date('Y-m-d H:i:s'),
- ];
- Db::name('物料_库存')
- ->where('批次号', $existingBatch)
- ->update($updateData);
- $BatchNumber = $existingBatch;
- } else {
- //新增库存
- $currentNumber++;
- $BatchNumber = 'GDGL' . $currentNumber;
- $insertInventory[] = [
- '批次号' => $BatchNumber,
- '关联号' => $item['关联编号'],
- '物料编号' => $item['物料编码'],
- '物料名称' => $item['物料名称'],
- '入仓总量' => $item['number'],
- '库存数量' => $item['number'],
- '单位' => $item['单位'],
- '实际门幅' => $item['实际门幅'],
- '状态' => 1,
- 'departname' => $item['departname'],
- 'remark' => $item['remark'] ?? '',
- 'sys_id' => $item['sys_id'],
- 'sys_rq' => date('Y-m-d H:i:s'),
- ];
- }
- //日志
- $insertLogs[] = [
- '批次号' => $BatchNumber,
- 'order_id' => $item['order_id'],
- '款号' => $item['款号'],
- '物料编码' => $item['物料编码'],
- '物料名称' => $item['物料名称'],
- '库存数量' => $item['number'],
- 'number' => $item['number'],
- 'rq' => $item['rq'],
- 'name' => $item['name'],
- 'sys_id' => $item['sys_id'],
- 'receipt_number' => $item['receipt_number'],
- 'departname' => $item['departname'],
- 'remark' => $item['remark'] ?? '',
- '客户编号' => $item['客户编号'],
- '款式' => $item['款式'],
- 'sys_rq' => date('Y-m-d H:i:s'),
- ];
- }
- // 批量新增
- if (!empty($insertInventory)) {
- Db::name('物料_库存')->insertAll($insertInventory);
- }
- // 批量日志
- if (!empty($insertLogs)) {
- Db::name('库存_出入库明细')->insertAll($insertLogs);
- }
- Db::commit();
- $this->success('入库成功');
- } catch (\Exception $e) {
- Db::rollback();
- $this->error('操作失败:' . $e->getMessage());
- }
- }
- // public function inputStash()
- // {
- // if (!$this->request->isPost()) {
- // $this->error('请求错误');
- // }
- //
- // $param = Request::instance()->post();
- // if (empty($param)) {
- // $this->error('参数错误');
- // }
- //
- // // 获取当前最大批次号
- // $lastBatch = \db('物料_库存')
- // ->field("批次号")
- // ->orderRaw("CAST(SUBSTRING(批次号, 4) AS UNSIGNED) DESC")
- // ->limit(1)
- // ->value('批次号');
- //
- // $currentNumber = 0;
- // if (!empty($lastBatch) && preg_match('/^PCH(\d+)$/i', $lastBatch, $match)) {
- // $currentNumber = intval($match[1]);
- // }
- //
- // foreach ($param as $item) {
- // // 查找是否已有相同物料编号 + 关联号的库存记录
- // $existingBatch = \db('物料_库存')
- // ->where('物料编号', $item['物料编码'])
- // ->where('物料名称', $item['物料名称'])
- // ->whereNull('Mod_rq')
- // ->where('关联号', $item['关联编号'])
- // ->value('批次号');
- //
- //
- // // 更新库存数据
- // $Inventory = \db('物料_库存')
- // ->where('批次号',$item['批次号'])
- // ->field('库存数量,入仓总量')
- // ->find();
- //
- //
- // if ($existingBatch) {
- // $BatchNumber = $existingBatch; // 已入库,使用原批次号
- // $InventoryData = [
- // '批次号' => $item['批次号'],
- // '关联号' => $item['关联编号'],
- // '物料编号' => $item['物料编码'],
- // '物料名称' => $item['物料名称'],
- // '入仓总量' => $Inventory['入仓总量'] + $item['number'],
- // '库存数量' => $Inventory['库存数量'] + $item['number'],
- // '实际门幅' => $item['实际门幅'],
- // '单位' => $item['单位'],
- // '状态' => 1,
- // 'departname' => $item['departname'],
- // 'remark' => isset($item['remark']) ? $item['remark'] : '',
- // 'sys_id' => $item['sys_id'],
- // 'sys_rq' => date('Y-m-d H:i:s'),
- // ];
- // $sql = \db('物料_库存')->fetchSql(true)->where('批次号',$BatchNumber)->update($InventoryData);
- // \db()->query($sql);
- // } else {
- // // 生成新批次号
- // $currentNumber++;
- // $BatchNumber = 'PCH' . $currentNumber;
- //
- // // 插入库存表
- // $InventoryData = [
- // '批次号' => $BatchNumber,
- // '关联号' => $item['关联编号'],
- // '物料编号' => $item['物料编码'],
- // '物料名称' => $item['物料名称'],
- // '入仓总量' => $item['number'],
- // '库存数量' => $item['number'],
- // '单位' => $item['单位'],
- // '实际门幅' => $item['实际门幅'],
- // '状态' => 1,
- // 'departname' => $item['departname'],
- // 'remark' => isset($item['remark']) ? $item['remark'] : '',
- // 'sys_id' => $item['sys_id'],
- // 'sys_rq' => date('Y-m-d H:i:s'),
- // ];
- // $sql = \db('物料_库存')->fetchSql(true)->insert($InventoryData);
- // \db()->query($sql);
- // }
- //
- // // 每条都写一条报工日志
- // $ReportData = [
- // '批次号' => $BatchNumber,
- // 'order_id' => $item['order_id'],
- // '款号' => $item['款号'],
- // '物料编码' => $item['物料编码'],
- // '物料名称' => $item['物料名称'],
- // '库存数量' => $item['number'],
- // 'number' => $item['number'],
- // 'rq' => $item['rq'],
- // 'name' => $item['name'],
- // 'sys_id' => $item['sys_id'],
- // 'receipt_number' => $item['receipt_number'],
- // 'departname' => $item['departname'],
- // 'remark' => isset($item['remark']) ? $item['remark'] : '',
- // '客户编号' => $item['客户编号'],
- // '款式' => $item['款式'],
- // 'sys_rq' => date('Y-m-d H:i:s'),
- // ];
- // $sql = \db('库存_出入库明细')->fetchSql(true)->insert($ReportData);
- // \db()->query($sql);
- // }
- //
- // $this->success('成功');
- // }
- /**
- * 出库订单信息查询
- */
- public function OutOrderSearch()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $param = $this->request->param();
- if (empty($param)){
- $this->error('参数错误');
- }
- $list = \db('工单_基本资料')
- ->alias('a')
- ->join('工单_面料资料 b','a.订单编号 = b.BOM_工单编号')
- ->join('物料_库存 c','b.BOM_物料编码 = c.物料编号','left')
- ->join('工单关联表 d','a.订单编号 = d.订单编号 AND d.物料编号 = b.BOM_物料编码')
- ->where('a.生产款号|a.订单编号|b.BOM_物料编码','like','%'.$param['search'].'%')
- ->where('a.Mod_rq',null)
- ->where('b.Mod_rq',null)
- ->where('c.状态',1)
- ->field('a.订单编号,a.生产款号,a.客户编号,a.款式,a.订单数量,a.落货日期,a.接单日期,a.Sys_id as 创建人员,
- a.Sys_rq as 创建时间,b.BOM_颜色 as 颜色,b.BOM_物料编码 as 物料编码,b.BOM_物料名称 as 物料名称,c.批次号,d.关联编号')
- ->order('a.订单编号 desc')
- ->select();
- if (empty($list)){
- $this->success('未找到相关订单信息');
- }else{
- $this->success('成功',$list);
- }
- }
- /**
- * 获取入库面料信息
- */
- public function getInputDetail()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $param = $this->request->param();
- if (empty($param)){
- $this->error('参数错误');
- }
- $list = \db('工单_面料资料')
- ->alias('b')
- ->join('物料_库存 a', 'a.物料编号 = b.BOM_物料编码 AND a.物料名称 = b.BOM_物料名称 AND a.Mod_rq IS NULL', 'left')
- ->join('工单关联表 c', 'b.BOM_物料编码 = c.物料编号 AND b.BOM_工单编号 = c.订单编号')
- ->field('a.Mod_rq, a.批次号, c.关联编号, b.BOM_物料编码, b.BOM_物料名称, a.入仓总量, a.库存数量, a.领用数量, a.退还数量, a.单位, a.实际门幅,
- a.departname, b.BOM_工单编号, b.BOM_颜色, b.BOM_计划门幅 as 计划门幅, b.BOM_定额门幅, b.BOM_计划用量 as 计划用料, b.BOM_标准用量 as 定额用料')
- ->where('c.关联编号', $param['关联编号'])
- ->where('c.订单编号', $param['订单编号'])
- ->where('b.BOM_物料编码', $param['物料编码'])
- ->where('a.Mod_rq',null)
- ->where('b.Mod_rq',null)
- ->where('c.Mod_rq',null)
- ->find();
- // if (empty($param['Mod_rq'])) { // 如果 Mod_rq 为空,才关联物料库存表
- // $list = $list->join('物料_库存 a', 'a.物料编号 = b.BOM_物料编码 AND a.物料名称 = b.BOM_物料名称 AND a.Mod_rq IS NULL', 'left')
- // ->field('a.批次号, a.入仓总量, a.库存数量, a.领用数量, a.退还数量, a.单位, a.实际门幅, a.departname');
- // }
- // $list = $list->where('c.关联编号', $param['关联编号'])
- // ->where('c.订单编号', $param['订单编号'])
- // ->where('b.BOM_物料编码', $param['物料编码'])
- // ->find();
- $orderList = \db('工单关联表')
- ->where('关联编号',$param['关联编号'])
- ->column('GROUP_CONCAT(DISTINCT 订单编号 SEPARATOR ",") AS 关联订单');
- $list['关联订单'] = $orderList[0];
- $this->success('成功',$list);
- }
- /**
- * 裁剪面料退货包工
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public function TuihuoReport()
- {
- if ($this->request->isPost() === false){
- $this->error('请求错误');
- }
- $param = Request::instance()->post();
- if (empty($param)){
- $this->error('参数错误');
- }
- foreach ($param as $item) {
- // 查询库存数据
- $number = \db('物料_库存')
- ->where('批次号', $item['批次号'])
- ->where('关联号', $item['关联编号'])
- ->where('物料编号', $item['物料编码'])
- ->whereNull('Mod_rq')
- ->field('库存数量, 退还数量')
- ->find();
- // 根据类型调整库存
- if ($item['type'] === '退仓') {
- $returnQuantity = (float)$number['退还数量'] + (float)$item['number'];
- $stockQuantity = (float)$number['库存数量'] + (float)$item['number'];
- } elseif ($item['type'] === '退厂商') {
- $returnQuantity = (float)$number['退还数量'] + (float)$item['number'];
- $stockQuantity = (float)$number['库存数量'] - (float)$item['number'];
- } elseif ($item['type'] === '销售') {
- $returnQuantity = (float)$number['退还数量'] + (float)$item['number'];
- $stockQuantity = (float)$number['库存数量'] - (float)$item['number'];
- }elseif ($item['type'] === '退客户') {
- $returnQuantity = (float)$number['退还数量'] + (float)$item['number'];
- $stockQuantity = (float)$number['库存数量'] - (float)$item['number'];
- // 检查库存是否足够
- if ($stockQuantity < 0) {
- $this->error('库存不足,无法进行退客户操作。当前库存:' . $number['库存数量']);
- }
- }else{
- $returnQuantity = (float)$number['退还数量'] + (float)$item['number'];
- $stockQuantity = (float)$number['库存数量'] ;
- }
- // 构建库存数据
- $inventoryData = [
- '批次号' => $item['批次号'],
- '关联号' => $item['关联编号'],
- '物料编号' => $item['物料编码'],
- '物料名称' => $item['物料名称'],
- '实际门幅' => $item['实际门幅'],
- '单位' => $item['单位'],
- '状态' => 1,
- 'sys_id' => $item['sys_id'],
- 'departname' => $item['departname'],
- 'remark' => isset($item['remark']) ? $item['remark'] : '',
- 'sys_rq' => date('Y-m-d H:i:s'),
- '退还数量' => $returnQuantity,
- '库存数量' => $stockQuantity,
- ];
- $InventorySql = \db('物料_库存')
- ->where('批次号',$item['批次号'])
- ->where('关联号',$item['关联编号'])
- ->where('物料编号',$item['物料编码'])
- ->whereNull('Mod_rq')
- ->fetchSql(true)
- ->update($inventoryData);
- \db()->query($InventorySql);
- // 记录入库报工日志
- $ReportData = [
- '批次号' => $item['批次号'],
- 'order_id' => $item['order_id'],
- '款号' => $item['款号'],
- '物料编码' => $item['物料编码'],
- '物料名称' => $item['物料名称'],
- '库存数量' => $item['number'],
- 'number' => $item['number'],
- 'rq' => $item['rq'],
- 'name' => $item['name'],
- 'sys_id' => $item['sys_id'],
- 'receipt_number' => $item['receipt_number'],
- 'departname' => $item['departname'],
- 'remark' => isset($item['remark']) ? $item['remark'] : '',
- '客户编号' => $item['客户编号'],
- '款式' => $item['款式'],
- 'type' => $item['type'],
- 'sys_rq' => date('Y-m-d H:i:s'),
- ];
- $sql = \db('库存_出入库明细')->fetchSql(true)->insert($ReportData);
- \db()->query($sql);
- }
- $this->success('成功');
- }
- /**
- * 总检日产量汇总
- * code:工序名称
- */
- public function DailyProductionReport(){
- if ($this->request->isGet() === false) {
- $this->error('请求错误');
- }
- $param = $this->request->param();
- if (!empty($param['code'])) {
- $threeMonthsAgo = date('Y-m-d H:i:s', strtotime('-1 months'));
- // 先获取每个分组的最新日期和汇总数据
- $subQuery = Db::name('设备_产量计酬')->alias('c')
- ->field('c.订单编号, c.子订单编号, c.尺码, SUM(c.数量) as 总数量, MAX(c.sys_rq) as rq')
- ->where('工序名称', $param['code'])
- ->where('c.sys_rq', '>=', $threeMonthsAgo)
- ->group('c.子订单编号, c.尺码')
- ->buildSql();
- // 主查询关联工单信息并排序
- $res = Db::table($subQuery . ' t')
- ->field('t.订单编号, t.子订单编号, t.总数量, t.尺码,j.生产款号, j.款式')
- ->join('工单_基本资料 j', 't.订单编号 = j.订单编号', 'left')
- ->order('t.rq desc, t.订单编号, t.子订单编号, t.尺码')
- ->select();
- $this->success('成功', [
- 'riqi' => date('Y-m-d'),
- 'list' => $res,
- 'total' => count($res)
- ]);
- }else{
- $this->error('缺少工序,参数错误');
- }
- }
- }
|