| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\db\Query;
- use \think\Request;
- use \think\Db;
- use const http\Client\Curl\IPRESOLVE_V4;
- class WorkOrderSpotCheck extends Api{
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- /**
- * 首页
- */
- public function index()
- {
- $this->success('请求成功');
- }
- /**
- * 报工查询
- *
- */
- public function getList() {
- // 判断请求是否为 GET 请求
- 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'];
- // 根据不同的 code 值执行不同的逻辑
- switch ($params['code']) {
- case '出库':
- $query = \db('工单_基本资料')->alias('j')
- ->field('y.订单编号, y.子订单编号, y.颜色, y.款号, j.款式, y.ck_rq,y.颜色备注')
- ->distinct('y.子订单编号')
- ->join('工单_印件资料 y', 'j.订单编号 = y.订单编号', 'inner');
- if (strpos($order, '-') !== false) {
- $query->where('y.子订单编号', $order);
- } else {
- $query->where('y.订单编号', 'like', '%' . $order . '%');
- }
- $query->where(function($query) {
- $query->whereNull('y.Mod_rq')
- ->whereOr('y.Mod_rq', '');
- });
- $data = $query->select();
- if (isset($data)) {
- usort($data, function($a, $b) {
- // 判断是否出库
- $a_status = !empty($a['ck_rq']) ? 1 : 0;
- $b_status = !empty($b['ck_rq']) ? 1 : 0;
- if ($a_status == $b_status) {
- // 如果出库状态相同,则按 ck_rq 倒序排序
- return strcmp($b['ck_rq'], $a['ck_rq']);
- } else {
- // 先显示未出库(0),再显示已出库(1)
- return $a_status - $b_status;
- }
- });
- foreach ($data as &$item) {
- $item['是否出库'] = !empty($item['ck_rq']) ? '已出库' : '未出库';
- $item['ck_rq'] = substr($item['ck_rq'], 0, 10);
- }
- $result = [
- 'data' => $data,
- 'rq' => date("Y-m-d"),
- 'total' => count($data)
- ];
- $this->success('请求成功', $result);
- }
- break;
- case '裁剪':
- //订单编号
- $ddh = explode('-', $order)[0];
- $currentDateTime = date("Y-m-d H:i:s");
- // 查询未出库的记录,若存在则进行批量出库和日志记录
- $data = \db('工单_印件资料')
- ->where(['子订单编号' => $order, 'ck_rq' => null])
- ->find();
- if ($data) {
- // 检查并更新工单_基本资料表的出库日期
- $sql = \db('工单_基本资料')
- ->where('订单编号', $ddh)
- ->whereNull('出库日期')
- ->fetchSql(true)
- ->update(['出库日期' => $currentDateTime]);
- \db()->query($sql);
- // 获取相同颜色备注的未出库子订单编号列表
- $sameColorList = \db('工单_印件资料')
- ->where(['订单编号' => $ddh, 'Mod_rq' => null, 'ck_rq' => null])
- ->field('子订单编号')
- ->select();
- // 更新工单_印件资料表的出库日期
- $sql = \db('工单_印件资料')
- ->where('订单编号', $ddh)
- ->whereNull('Mod_rq')
- ->whereNull('ck_rq')
- ->fetchSql(true)
- ->update(['ck_rq' => $currentDateTime]);
- $updateCount1 = \db()->query($sql);
- if ($updateCount1 > 0) {
- // 批量生成并插入日志数据
- $logData = array_map(function ($item) use ($currentDateTime, $params) {
- return [
- 'order_id' => $item['子订单编号'],
- 'rq' => $currentDateTime,
- 'name' => $params['code'],
- 'sys_id' => '裁剪自动出库'
- ];
- }, $sameColorList);
- \db('设备_报工日志')->insertAll($logData);
- } else {
- return $this->error('网络异常,重新尝试');
- }
- }
- //查询子订单编号对应数据【条码查询】
- if (strpos($order, '-') !== false) {
- if (preg_match('/-(\d{2})$/', $order, $matches)) {
- $number = (int)$matches[1];
- //船样单子
- 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.cmsl1, y.cmsl2, y.cmsl3, y.cmsl4, y.cmsl5, y.cmsl6, y.cmsl7, y.cmsl8, y.cmsl9, y.cmsl10,
- y.scsl1, y.scsl2, y.scsl3, y.scsl4, y.scsl5, y.scsl6, y.scsl7, y.scsl8, y.scsl9, y.scsl10'
- )
- ->join('工单_印件资料 y', 'j.订单编号 = y.订单编号', 'left')
- ->where('y.船样',1)
- ->where(function($query) {
- $query->whereNull('y.Mod_rq')->whereOr('y.Mod_rq', '');
- }) // 查询未删除数据
- ->where('y.子订单编号', $order)
- ->select();
- } else {
- //获取原始子订单编号【-01】
- $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.cmsl1, y.cmsl2, y.cmsl3, y.cmsl4, y.cmsl5, y.cmsl6, y.cmsl7, y.cmsl8, y.cmsl9, y.cmsl10,
- y.scsl1, y.scsl2, y.scsl3, y.scsl4, y.scsl5, y.scsl6, y.scsl7, y.scsl8, y.scsl9, y.scsl10'
- )
- ->join('工单_印件资料 y', 'j.订单编号 = y.订单编号', 'left')
- ->where('y.船样',0)
- ->where(function($query) {
- $query->whereNull('y.Mod_rq')->whereOr('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.cmsl1, y.cmsl2, y.cmsl3, y.cmsl4, y.cmsl5, y.cmsl6, y.cmsl7, y.cmsl8, y.cmsl9, y.cmsl10,
- y.scsl1, y.scsl2, y.scsl3, y.scsl4, y.scsl5, y.scsl6, y.scsl7, y.scsl8, y.scsl9, y.scsl10'
- )
- ->join('工单_印件资料 y', 'j.订单编号 = y.订单编号', 'left')
- ->where('y.船样',0)
- ->where(function($query) {
- $query->whereNull('y.Mod_rq')->whereOr('y.Mod_rq', '');
- }) // 查询未删除数据
- ->where('y.子订单编号', 'like', '%' . $ddbh . '%')
- ->select();
- }
- // echo "<pre>";
- // print_r($data);
- // echo "<pre>";
- $dataEntry = [];
- $list = [];
- $headers = [];//存放尺码表头
- foreach ($data as $item) {
- // 初始化尺码与数量映射数组
- $cmScslMapping = [];
- for ($i = 1; $i <= 10; $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 <= 10; $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;
- }
- //打印当前订单所有尺码数据
- // echo "<pre>";print_r($list);echo "<pre>";die;
- // // 合并子订单
- // $merged = [];
- // foreach ($list as $item) {
- // $key = $item['子订单编号'];
- // // 生成合并的唯一键,以 color_id 和 颜色备注 为依据
- // $mergeKey = $item['color_id'] . '-' . $item['颜色备注'];
- // if (!isset($merged[$mergeKey])) {
- // // 如果不存在,则初始化
- // $merged[$mergeKey] = $item;
- // } else {
- // // 如果已经存在,则合并数量
- // for ($i = 1; $i <= 10; $i++) {
- // $sizeKey = 'cm' . $i;
- // $qtyKey = 'cmsl' . $i;
- // if (!empty($item[$sizeKey]) && $item[$sizeKey] === $merged[$mergeKey][$sizeKey]) {
- // $merged[$mergeKey][$qtyKey] = (int)$merged[$mergeKey][$qtyKey] + (int)$item[$qtyKey];
- // }
- // }
- // // 累加总数量等字段
- // $merged[$mergeKey]['zdtotal'] += $item['zdtotal'];
- // }
- // }
- // 重置索引为连续数字索引
- // $mergeds = array_values($merged);
- // 创建新的合并子订单列表
- $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;
- }
- }
- }
- // echo "<pre>";
- // print_r($finalMerged);
- // echo "</pre>";
- // die;
- // 在 $mergeds 中查找匹配的子订单编号 对应的一条数据
- $matchedOrder = null;
- foreach ($list as $mergedOrder) {
- if ($mergedOrder['子订单编号'] === $order) {
- $matchedOrder = $mergedOrder;
- break; // 找到后可以退出循环
- }
- }
- // $matchedOrder = null;
- // foreach ($finalMerged as $mergedOrder) {
- // if ($mergedOrder['子订单编号'] === $order) {
- // $matchedOrder = $mergedOrder;
- // break; // 找到后可以退出循环
- // }
- // }
- // echo "<pre>";print_r($matchedOrder);echo "</pre>";die;
- // // 合并子订单
- // $merged = [];
- // foreach ($list as $item) {
- // $key = $item['子订单编号'];
- // // 生成合并的唯一键,以 color_id 和 颜色备注 为依据
- // $mergeKey = $item['color_id'] . '-' . $item['颜色备注'];
- // if (!isset($merged[$mergeKey])) {
- // // 如果不存在,则初始化
- // $merged[$mergeKey] = $item;
- // } else {
- // // 如果已经存在,则合并数量
- // for ($i = 1; $i <= 10; $i++) {
- // $sizeKey = 'cm' . $i;
- // $qtyKey = 'cmsl' . $i;
- // if (!empty($item[$sizeKey]) && $item[$sizeKey] === $merged[$mergeKey][$sizeKey]) {
- // $merged[$mergeKey][$qtyKey] = (int)$merged[$mergeKey][$qtyKey] + (int)$item[$qtyKey];
- // }
- // }
- // // 也可以累加其他字段,如总数量等
- // $merged[$mergeKey]['zdtotal'] += $item['zdtotal'];
- // }
- // }
- // $mergeds = array_values($merged); // 重置索引为连续数字索引
- // //打印输出合并后订单数据
- // echo "<pre>";print_r($mergeds);echo "</pre>";die;
- //
- // // 在 $mergeds 中查找匹配的子订单编号 对应的一条数据
- // $matchedOrder = null;
- // foreach ($mergeds as $mergedOrder) {
- // if ($mergedOrder['子订单编号'] === $order) {
- // $matchedOrder = $mergedOrder;
- // break; // 找到后可以退出循环
- // }
- // }
- // echo "<pre>";print_r($matchedOrder);echo "</pre>";die;
- //产量进度汇总记录
- $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') // 查询未删除数据
- ->where(function($query) {
- $query->whereNotNull('y.ck_rq')->where('y.ck_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.cmsl1, y.cmsl2, y.cmsl3, y.cmsl4, y.cmsl5, y.cmsl6, y.cmsl7, y.cmsl8, y.cmsl9, y.cmsl10,
- y.scsl1, y.scsl2, y.scsl3, y.scsl4, y.scsl5, y.scsl6, y.scsl7, y.scsl8, y.scsl9, y.scsl10'
- )
- ->join('工单_印件资料 y', 'j.订单编号 = y.订单编号', 'left')
- // ->where('y.船样',1)
- ->where(function($query) {
- $query->whereNull('y.Mod_rq')->whereOr('y.Mod_rq', '');
- }) // 查询未删除数据
- // ->where($where)
- ->where('y.订单编号', 'like', '%' . $order . '%')
- ->select();
- $headers = [];//存放尺码表头
- foreach ($data as $item) {
- // 初始化尺码与数量映射数组
- $cmScslMapping = [];
- for ($i = 1; $i <= 10; $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.尺码, c.数量, 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)
- ->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 = ['XXS' => 1,'XS' => 2,'S' => 3, 'M' => 4, 'L' => 5, 'XL' => 6, 'XXL' => 7, 'XXXL' => 8];
- 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.cmsl1, y.cmsl2, y.cmsl3, y.cmsl4, y.cmsl5, y.cmsl6, y.cmsl7, y.cmsl8, y.cmsl9, y.cmsl10,
- y.scsl1, y.scsl2, y.scsl3, y.scsl4, y.scsl5, y.scsl6, y.scsl7, y.scsl8, y.scsl9, y.scsl10'
- )
- ->join('工单_印件资料 y', 'j.订单编号 = y.订单编号', 'left')
- ->where('y.船样',1)
- ->where(function($query) {
- $query->whereNull('y.Mod_rq')->whereOr('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.cmsl1, y.cmsl2, y.cmsl3, y.cmsl4, y.cmsl5, y.cmsl6, y.cmsl7, y.cmsl8, y.cmsl9, y.cmsl10,
- y.scsl1, y.scsl2, y.scsl3, y.scsl4, y.scsl5, y.scsl6, y.scsl7, y.scsl8, y.scsl9, y.scsl10'
- )
- ->join('工单_印件资料 y', 'j.订单编号 = y.订单编号', 'left')
- ->where('y.船样',0)
- ->where(function($query) {
- $query->whereNull('y.Mod_rq')->whereOr('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.cmsl1, y.cmsl2, y.cmsl3, y.cmsl4, y.cmsl5, y.cmsl6, y.cmsl7, y.cmsl8, y.cmsl9, y.cmsl10,
- y.scsl1, y.scsl2, y.scsl3, y.scsl4, y.scsl5, y.scsl6, y.scsl7, y.scsl8, y.scsl9, y.scsl10'
- )
- ->join('工单_印件资料 y', 'j.订单编号 = y.订单编号', 'left')
- ->where('y.船样',0)
- ->where(function($query) {
- $query->whereNull('y.Mod_rq')->whereOr('y.Mod_rq', '');
- }) // 查询未删除数据
- ->where('y.子订单编号', 'like', '%' . $ddbh . '%')
- ->select();
- }
- // echo "<pre>";
- // print_r($data);
- // echo "<pre>";
- $dataEntry = [];
- $list = [];
- $headers = [];//存放尺码表头
- foreach ($data as $item) {
- // 初始化尺码与数量映射数组
- $cmScslMapping = [];
- for ($i = 1; $i <= 10; $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 <= 10; $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;
- }
- //打印当前订单所有尺码数据
- // echo "<pre>";print_r($list);echo "<pre>";die;
- // // 合并子订单
- // $merged = [];
- // foreach ($list as $item) {
- // $key = $item['子订单编号'];
- // // 生成合并的唯一键,以 color_id 和 颜色备注 为依据
- // $mergeKey = $item['color_id'] . '-' . $item['颜色备注'];
- // if (!isset($merged[$mergeKey])) {
- // // 如果不存在,则初始化
- // $merged[$mergeKey] = $item;
- // } else {
- // // 如果已经存在,则合并数量
- // for ($i = 1; $i <= 10; $i++) {
- // $sizeKey = 'cm' . $i;
- // $qtyKey = 'cmsl' . $i;
- // if (!empty($item[$sizeKey]) && $item[$sizeKey] === $merged[$mergeKey][$sizeKey]) {
- // $merged[$mergeKey][$qtyKey] = (int)$merged[$mergeKey][$qtyKey] + (int)$item[$qtyKey];
- // }
- // }
- // // 也可以累加其他字段,如总数量等
- // $merged[$mergeKey]['zdtotal'] += $item['zdtotal'];
- // }
- // }
- // $mergeds = array_values($merged); // 重置索引为连续数字索引
- // //打印输出合并后订单数据
- // echo "<pre>";print_r($mergeds);echo "</pre>";die;
- // 在 $mergeds 中查找匹配的子订单编号 对应的一条数据
- $matchedOrder = null;
- foreach ($list as $mergedOrder) {
- if ($mergedOrder['子订单编号'] === $order) {
- $matchedOrder = $mergedOrder;
- break; // 找到后可以退出循环
- }
- }
- $allScslEmpty = true;
- for ($i = 1; $i <= 10; $i++) {
- if (!empty($matchedOrder["scsl$i"])) {
- $allScslEmpty = false;
- break;
- }
- }
- if ($allScslEmpty) {
- $this->error('当前订单还未进行裁剪,请裁剪后再报工');
- }
- // 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);
- // $sb_cljc = \db('设备_产量计酬')
- // ->field('子订单编号,尺码,数量,工序名称,sczl_jtbh')
- // ->where('子订单编号', $order)
- // ->where('工序名称','裁剪')
- // ->where(function($query) {
- // $query->whereNull('mod_rq')->whereOr('mod_rq', '');
- // })
- // ->select();
- // echo "<pre>";
- // print_r($sb_cljc);
- // echo "<pre>";die;
- $this->success('请求成功', [
- 'serial' => $serial['serial'], // 流水号
- 'serial_num' => $serial['serial_num'], // 序号
- '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'] // 查询历史记录
- ]);
- // $this->success('请求成功');
- }
- break;
- case '手工':
- //判断是否为标签参数数据
- if (strpos($order, ',') !== false) {
- if (!isset($params['sys_sbID']) || empty($params['sys_sbID'])) {
- $this->error('未获取到机台号');
- }
- // 将子订单编号, 机台号, 工序, 尺码, 数量, 尾包, 流水号(包)分割为数组
- $paramArray = explode(',', $order);
- // 获取车缝报工生成小票的数据
- $Uniqid = \db('设备_产量计酬')
- ->where([
- '子订单编号' => $paramArray[0],
- '尺码' => $paramArray[3],
- '数量' => $paramArray[4],
- 'serial' => $paramArray[6],
- ])
- ->find();
- // 判断是否成功获取到数据
- if ($Uniqid) {
- $orderlist = \db('工单_基本资料')
- ->where('订单编号', $Uniqid['订单编号'])
- ->field('订单编号, 生产款号, 款式')
- ->find();
- $yinjianlist = \db('工单_印件资料')
- ->where('订单编号', $orderlist['订单编号'])
- ->field('zdtotal, sctotal,颜色,颜色备注')
- ->find();
- } else {
- $this->error('当前扫码小票无效');
- }
- // 获取当前手工机台上报的数据
- $res = \db('设备_产量计酬')
- ->where([
- '子订单编号' => $paramArray[0],
- '尺码' => $paramArray[3],
- '数量' => $paramArray[4],
- 'serial' => $paramArray[6],
- 'sczl_jtbh' => $params['sys_sbID'],
- 'mod_rq' => null,
- ])
- ->order('UniqId desc')
- ->find();
- if (empty($res)) {
- $ci_num = $paramArray[4];
- } else {
- $ci_num = $res["ci_num"];
- }
- $result = [
- 'sys_sbID' => $params['sys_sbID'],//设备编号
- 'ci_num' => $ci_num,//剩余数量
- 'UniqId' => $Uniqid['UniqId'],
- 'order' => $paramArray[0],//子订单编号
- 'zb' => $params['sys_sbID'],//组别
- 'gx' => 4,//默认固定工序
- 'cm' => $paramArray[3],//尺码
- 'sl' => $paramArray[4],//数量
- 'wb' => $paramArray[5],//尾包
- '订单编号' => $orderlist['订单编号'],
- '生产款号' => $orderlist['生产款号'],
- '款式' => $orderlist['款式'],
- 'sctotal' => $yinjianlist['sctotal'],
- 'zdtotal' => $yinjianlist['zdtotal'],
- '颜色' => $yinjianlist['颜色备注'],
- ];
- // 查询历史记录
- $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.子订单编号', $paramArray[0])
- ->where('c.工序名称', '手工')
- ->where('c.sczl_jtbh', $params['sys_sbID'])
- ->whereNull('c.mod_rq') // 查询未删除数据
- ->where(function($query) {
- $query->whereNotNull('y.ck_rq')->where('y.ck_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']);
- });
- $this->success('请求成功', [
- 'result' => $result,//小票数据
- 'headers' => $sizes, // 尺码表头
- 'records' => $sizeSummary // 历史记录
- ]);
- }else{
- // 查询历史记录
- $res = \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.订单编号', 'like', '%' . explode('DC',$order)[1] . '%')
- ->where('c.工序名称', $params['code'])
- ->where('c.sczl_jtbh', $params['sys_sbID'])
- ->whereNull('c.mod_rq') // 查询未删除数据
- ->order('UniqId desc')
- ->select();
- // 初始化返回数据的结构
- $reslist = [];
- $sizes = [];
- // 遍历查询结果,构造需要的结构化数据
- foreach ($res as $record) {
- $size = $record['尺码']; // 记录的尺码
- $quantity = $record['数量']; // 每个记录的数量
- $serial = $record['serial']; // 记录的serial
- // 记录所有不同的尺码,避免重复
- if (!in_array($size, $sizes)) {
- $sizes[] = $size;
- }
- // 构造每条记录的详细信息
- $reslist[] = [
- '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']
- ];
- }
- // 按 sys_rq (时间) 或 UniqId 排序(按实际需求选)
- usort($reslist, function ($a, $b) {
- return strtotime($b['sys_rq']) - strtotime($a['sys_rq']);
- });
- // 返回结构化的查询结果
- $this->success('请求成功', [
- 'result' => $res, // 原始查询结果
- 'headers' => $sizes, // 尺码表头
- 'records' => $reslist // 处理后的记录列表
- ]);
- }
- break;
- case '大烫':
- if (strpos($order, ',') !== false) {
- if (!isset($params['sys_sbID']) || empty($params['sys_sbID'])) {
- $this->error('未获取到机台号');
- }
- // 将子订单编号, 机台号, 工序, 尺码, 数量, 尾包, 流水号(包)分割为数组
- $paramArray = explode(',', $order);
- // 获取车缝报工生成小票的数据
- $Uniqid = \db('设备_产量计酬')
- ->where([
- '子订单编号' => $paramArray[0],
- '尺码' => $paramArray[3],
- '数量' => $paramArray[4],
- 'serial' => $paramArray[6],
- ])
- ->find();
- // 获取上一个机台是否已上报过
- $baogonglist = \db('设备_产量计酬')
- ->where([
- '子订单编号' => $paramArray[0],
- '尺码' => $paramArray[3],
- '数量' => $paramArray[4],
- 'serial' => $paramArray[6],
- 'Mod_rq' => null,
- ])
- ->where('sczl_jtbh', 'like', 'HD%')
- ->select();
- if(empty($baogonglist)){
- $this->error('当前小票'.'【手工报工】'.'未上报,请上报后再操作');
- }
- // 判断是否成功获取到数据
- if ($Uniqid) {
- $orderlist = \db('工单_基本资料')
- ->where('订单编号', $Uniqid['订单编号'])
- ->field('订单编号, 生产款号, 款式')
- ->find();
- $yinjianlist = \db('工单_印件资料')
- ->where('订单编号', $orderlist['订单编号'])
- ->field('zdtotal, sctotal,颜色,颜色备注')
- ->find();
- } else {
- $this->error('当前扫码小票无效');
- }
- // 获取当前手工机台上报的数据
- $res = \db('设备_产量计酬')
- ->where([
- '子订单编号' => $paramArray[0],
- '尺码' => $paramArray[3],
- '数量' => $paramArray[4],
- 'serial' => $paramArray[6],
- 'sczl_jtbh' => $params['sys_sbID'],
- 'mod_rq' => null,
- ])
- ->order('UniqId desc')
- ->find();
- if (empty($res)) {
- $ci_num = $paramArray[4];
- } else {
- $ci_num = $res["ci_num"];
- // // 累加 s_num
- // $total_s_num = 0;
- // foreach ($res as $item) {
- // $total_s_num += $item['s_num'];
- // }
- // if ($total_s_num >= $paramArray[4]) {
- // $ci_num = 0;
- // } else {
- // $ci_num = $res[0]['ci_num'];
- // }
- }
- // 判断是否已报工并给出提示
- // if (!empty($res) && $paramArray[4] == $res[0]['s_num'] || $ci_num === '' || $ci_num === 0) {
- // $this->error('已上报,无需再次报工');
- // }
- // if (!empty($res) && $res["ci_num"] == 0) {
- // $this->success('已上报,无需再次报工');
- // }
- $result = [
- 'sys_sbID' => $params['sys_sbID'],//设备编号
- 'ci_num' => $ci_num,//剩余数量
- 'UniqId' => $Uniqid['UniqId'],
- 'order' => $paramArray[0],//子订单编号
- 'zb' => $params['sys_sbID'],//组别
- 'gx' => 4,//默认固定工序
- 'cm' => $paramArray[3],//尺码
- 'sl' => $paramArray[4],//数量
- 'wb' => $paramArray[5],//尾包
- '订单编号' => $orderlist['订单编号'],
- '生产款号' => $orderlist['生产款号'],
- '款式' => $orderlist['款式'],
- 'sctotal' => $yinjianlist['sctotal'],
- 'zdtotal' => $yinjianlist['zdtotal'],
- '颜色' => $yinjianlist['颜色备注'],
- ];
- // 查询历史记录
- $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.子订单编号', $paramArray[0])
- ->where('c.工序名称', '大烫')
- ->where('c.sczl_jtbh', $params['sys_sbID'])
- ->whereNull('c.mod_rq') // 查询未删除数据
- ->where(function($query) {
- $query->whereNotNull('y.ck_rq')->where('y.ck_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']);
- });
- $this->success('请求成功', [
- 'result' => $result,//小票数据
- 'headers' => $sizes, // 尺码表头
- 'records' => $sizeSummary // 历史记录
- ]);
- }else{
- // 查询历史记录
- $res = \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.订单编号', 'like', '%' . explode('DC',$order)[1] . '%')
- ->where('c.工序名称', $params['code'])
- ->where('c.sczl_jtbh', $params['sys_sbID'])
- ->whereNull('c.mod_rq') // 查询未删除数据
- ->order('UniqId desc')
- ->select();
- // 初始化返回数据的结构
- $reslist = [];
- $sizes = [];
- // 遍历查询结果,构造需要的结构化数据
- foreach ($res as $record) {
- $size = $record['尺码']; // 记录的尺码
- $quantity = $record['数量']; // 每个记录的数量
- $serial = $record['serial']; // 记录的serial
- // 记录所有不同的尺码,避免重复
- if (!in_array($size, $sizes)) {
- $sizes[] = $size;
- }
- // 构造每条记录的详细信息
- $reslist[] = [
- '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']
- ];
- }
- // 按 sys_rq (时间) 或 UniqId 排序(按实际需求选)
- usort($reslist, function ($a, $b) {
- return strtotime($b['sys_rq']) - strtotime($a['sys_rq']);
- });
- // 返回结构化的查询结果
- $this->success('请求成功', [
- 'result' => $res, // 原始查询结果
- 'headers' => $sizes, // 尺码表头
- 'records' => $reslist // 处理后的记录列表
- ]);
- }
- break;
- case '总检':
- if (strpos($order, ',') !== false) {
- if (!isset($params['sys_sbID']) || empty($params['sys_sbID'])) {
- $this->error('未获取到机台号');
- }
- // 将子订单编号, 机台号, 工序, 尺码, 数量, 尾包, 流水号(包)分割为数组
- $paramArray = explode(',', $order);
- // 获取车缝报工生成小票的数据
- $Uniqid = \db('设备_产量计酬')
- ->where([
- '子订单编号' => $paramArray[0],
- '尺码' => $paramArray[3],
- '数量' => $paramArray[4],
- 'serial' => $paramArray[6],
- ])
- ->find();
- // 获取上一个机台是否已上报过
- $baogonglist = \db('设备_产量计酬')
- ->where([
- '子订单编号' => $paramArray[0],
- '尺码' => $paramArray[3],
- '数量' => $paramArray[4],
- 'serial' => $paramArray[6],
- 'Mod_rq' => null,
- ])
- ->where('sczl_jtbh', 'like', 'DT%')
- ->select();
- if(empty($baogonglist)){
- $this->error('当前小票'.'【大烫报工】'.'未上报,请上报后再操作');
- }
- // 判断是否成功获取到数据
- if ($Uniqid) {
- $orderlist = \db('工单_基本资料')
- ->where('订单编号', $Uniqid['订单编号'])
- ->field('订单编号, 生产款号, 款式')
- ->find();
- $yinjianlist = \db('工单_印件资料')
- ->where('订单编号', $orderlist['订单编号'])
- ->field('zdtotal, sctotal,颜色,颜色备注')
- ->find();
- } else {
- $this->error('当前扫码小票无效');
- }
- // 获取当前手工机台上报的数据
- $res = \db('设备_产量计酬')
- ->where([
- '子订单编号' => $paramArray[0],
- '尺码' => $paramArray[3],
- '数量' => $paramArray[4],
- 'serial' => $paramArray[6],
- 'sczl_jtbh' => $params['sys_sbID'],
- 'mod_rq' => null,
- ])
- ->order('UniqId desc')
- ->find();
- if (empty($res)) {
- $ci_num = $paramArray[4];
- } else {
- $ci_num = $res["ci_num"];
- // // 累加 s_num
- // $total_s_num = 0;
- // foreach ($res as $item) {
- // $total_s_num += $item['s_num'];
- // }
- // if ($total_s_num >= $paramArray[4]) {
- // $ci_num = 0;
- // } else {
- // $ci_num = $res[0]['ci_num'];
- // }
- }
- // 判断是否已报工并给出提示
- // if (!empty($res) && $paramArray[4] == $res[0]['s_num'] || $ci_num === '' || $ci_num === 0) {
- // $this->error('已上报,无需再次报工');
- // }
- // if (!empty($res) && $res["ci_num"] == 0) {
- // $this->error('已上报,无需再次报工');
- // }
- $result = [
- 'sys_sbID' => $params['sys_sbID'],//设备编号
- 'ci_num' => $ci_num,//剩余数量
- 'UniqId' => $Uniqid['UniqId'],
- 'order' => $paramArray[0],//子订单编号
- 'zb' => $params['sys_sbID'],//组别
- 'gx' => 4,//默认固定工序
- 'cm' => $paramArray[3],//尺码
- 'sl' => $paramArray[4],//数量
- 'wb' => $paramArray[5],//尾包
- '订单编号' => $orderlist['订单编号'],
- '生产款号' => $orderlist['生产款号'],
- '款式' => $orderlist['款式'],
- 'sctotal' => $yinjianlist['sctotal'],
- 'zdtotal' => $yinjianlist['zdtotal'],
- '颜色' => $yinjianlist['颜色备注'],
- ];
- // 查询历史记录
- $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.子订单编号', $paramArray[0])
- ->where('c.sczl_jtbh', $params['sys_sbID'])
- ->whereNull('c.mod_rq') // 查询未删除数据
- ->where(function($query) {
- $query->whereNotNull('y.ck_rq')->where('y.ck_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']);
- });
- $this->success('请求成功', [
- 'result' => $result,//小票数据
- 'headers' => $sizes, // 尺码表头
- 'records' => $sizeSummary // 历史记录
- ]);
- }else{
- // 查询历史记录
- $res = \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.订单编号', 'like', '%' . explode('DC',$order)[1] . '%')
- ->where('c.工序名称', $params['code'])
- ->where('c.sczl_jtbh', $params['sys_sbID'])
- ->whereNull('c.mod_rq') // 查询未删除数据
- ->order('UniqId desc')
- ->select();
- // 初始化返回数据的结构
- $reslist = [];
- $sizes = [];
- // 遍历查询结果,构造需要的结构化数据
- foreach ($res as $record) {
- $size = $record['尺码']; // 记录的尺码
- $quantity = $record['数量']; // 每个记录的数量
- $serial = $record['serial']; // 记录的serial
- // 记录所有不同的尺码,避免重复
- if (!in_array($size, $sizes)) {
- $sizes[] = $size;
- }
- // 构造每条记录的详细信息
- $reslist[] = [
- 'UniqId' => $record['UniqId'],
- '订单编号' => $record['订单编号'],
- '子订单编号' => $record['子订单编号'],
- '上报数量' => $record['s_num'],
- '次品数量' => $record['数量'] - $record['ci_num'],
- '生产款号' => $record['款号'],
- '尺码' => $record['尺码'],
- '工序编号' => $record['工序编号'],
- '工序名称' => $record['工序名称'],
- '数量' => $quantity,
- '尾包' => $record['尾包'] == 1 ? '是' : '否',
- '颜色' => $record['颜色备注'],
- '组别' => $record['sczl_jtbh'],
- '款式' => $record['款式'],
- 'serial' => '第('.$serial.')包',
- 'sys_rq' => $record['sys_rq']
- ];
- }
- // 按 sys_rq (时间) 或 UniqId 排序(按实际需求选)
- usort($reslist, function ($a, $b) {
- return strtotime($b['sys_rq']) - strtotime($a['sys_rq']);
- });
- // 返回结构化的查询结果
- $this->success('请求成功', [
- 'result' => $res, // 原始查询结果
- 'headers' => $sizes, // 尺码表头
- 'records' => $reslist // 处理后的记录列表
- ]);
- }
- break;
- case '包装':
- if (strpos($order, ',') !== false) {
- if (!isset($params['sys_sbID']) || empty($params['sys_sbID'])) {
- $this->error('未获取到机台号');
- }
- // 将子订单编号, 机台号, 工序, 尺码, 数量, 尾包, 流水号(包)分割为数组
- $paramArray = explode(',', $order);
- // 获取车缝报工生成小票的数据
- $Uniqid = \db('设备_产量计酬')
- ->where([
- '子订单编号' => $paramArray[0],
- '尺码' => $paramArray[3],
- '数量' => $paramArray[4],
- 'serial' => $paramArray[6],
- ])
- ->find();
- // 获取上一个机台是否已上报过
- $baogonglist = \db('设备_产量计酬')
- ->where([
- '子订单编号' => $paramArray[0],
- '尺码' => $paramArray[3],
- '数量' => $paramArray[4],
- 'serial' => $paramArray[6],
- 'Mod_rq' => null,
- ])
- ->where('sczl_jtbh', 'like', 'ZJ%')
- ->select();
- if(empty($baogonglist)){
- $this->error('当前小票'.'【总检报工】'.'未上报,请上报后再操作');
- }
- // 判断是否成功获取到数据
- if ($Uniqid) {
- $orderlist = \db('工单_基本资料')
- ->where('订单编号', $Uniqid['订单编号'])
- ->field('订单编号, 生产款号, 款式')
- ->find();
- $yinjianlist = \db('工单_印件资料')
- ->where('订单编号', $orderlist['订单编号'])
- ->field('zdtotal, sctotal,颜色,颜色备注')
- ->find();
- } else {
- $this->error('当前扫码小票无效');
- }
- // 获取当前手工机台上报的数据
- $res = \db('设备_产量计酬')
- ->where([
- '子订单编号' => $paramArray[0],
- '尺码' => $paramArray[3],
- '数量' => $paramArray[4],
- 'serial' => $paramArray[6],
- 'sczl_jtbh' => $params['sys_sbID'],
- 'mod_rq' => null,
- ])
- ->order('UniqId desc')
- ->find();
- if (empty($res)) {
- $ci_num = $paramArray[4];
- } else {
- $ci_num = $res["ci_num"];
- // // 累加 s_num
- // $total_s_num = 0;
- // foreach ($res as $item) {
- // $total_s_num += $item['s_num'];
- // }
- // if ($total_s_num >= $paramArray[4]) {
- // $ci_num = 0;
- // } else {
- // $ci_num = $res[0]['ci_num'];
- // }
- }
- // 判断是否已报工并给出提示
- // if (!empty($res) && $paramArray[4] == $res[0]['s_num'] || $ci_num === '' || $ci_num === 0) {
- // $this->error('已上报,无需再次报工');
- // }
- // if (!empty($res) && $res["ci_num"] == 0) {
- // $this->error('已上报,无需再次报工');
- // }
- $result = [
- 'sys_sbID' => $params['sys_sbID'],//设备编号
- 'ci_num' => $ci_num,//剩余数量
- 'UniqId' => $Uniqid['UniqId'],
- 'order' => $paramArray[0],//子订单编号
- 'zb' => $params['sys_sbID'],//组别
- 'gx' => 4,//默认固定工序
- 'cm' => $paramArray[3],//尺码
- 'sl' => $paramArray[4],//数量
- 'wb' => $paramArray[5],//尾包
- '订单编号' => $orderlist['订单编号'],
- '生产款号' => $orderlist['生产款号'],
- '款式' => $orderlist['款式'],
- 'sctotal' => $yinjianlist['sctotal'],
- 'zdtotal' => $yinjianlist['zdtotal'],
- '颜色' => $yinjianlist['颜色备注'],
- ];
- // 查询历史记录
- $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.子订单编号', $paramArray[0])
- ->where('c.sczl_jtbh', $params['sys_sbID'])
- ->whereNull('c.mod_rq') // 查询未删除数据
- ->where(function($query) {
- $query->whereNotNull('y.ck_rq')->where('y.ck_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']);
- });
- $this->success('请求成功', [
- 'result' => $result,//小票数据
- 'headers' => $sizes, // 尺码表头
- 'records' => $sizeSummary // 历史记录
- ]);
- }else{
- // 查询历史记录
- $res = \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.订单编号', 'like', '%' . explode('DC',$order)[1] . '%')
- ->where('c.工序名称', $params['code'])
- ->where('c.sczl_jtbh', $params['sys_sbID'])
- ->whereNull('c.mod_rq') // 查询未删除数据
- ->order('UniqId desc')
- ->select();
- // 初始化返回数据的结构
- $reslist = [];
- $sizes = [];
- // 遍历查询结果,构造需要的结构化数据
- foreach ($res as $record) {
- $size = $record['尺码']; // 记录的尺码
- $quantity = $record['数量']; // 每个记录的数量
- $serial = $record['serial']; // 记录的serial
- // 记录所有不同的尺码,避免重复
- if (!in_array($size, $sizes)) {
- $sizes[] = $size;
- }
- // 构造每条记录的详细信息
- $reslist[] = [
- 'UniqId' => $record['UniqId'],
- '订单编号' => $record['订单编号'],
- '子订单编号' => $record['子订单编号'],
- '上报数量' => $record['s_num'],
- '次品数量' => $record['数量'] - $record['ci_num'],
- '生产款号' => $record['款号'],
- '尺码' => $record['尺码'],
- '工序编号' => $record['工序编号'],
- '工序名称' => $record['工序名称'],
- '数量' => $quantity,
- '尾包' => $record['尾包'] == 1 ? '是' : '否',
- '颜色' => $record['颜色备注'],
- '组别' => $record['sczl_jtbh'],
- '款式' => $record['款式'],
- 'serial' => '第('.$serial.')包',
- 'sys_rq' => $record['sys_rq']
- ];
- }
- // 按 sys_rq (时间) 或 UniqId 排序(按实际需求选)
- usort($reslist, function ($a, $b) {
- return strtotime($b['sys_rq']) - strtotime($a['sys_rq']);
- });
- // 返回结构化的查询结果
- $this->success('请求成功', [
- 'result' => $res, // 原始查询结果
- 'headers' => $sizes, // 尺码表头
- 'records' => $reslist // 处理后的记录列表
- ]);
- }
- 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,
- '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('数据插入失败');
- }
- }
- /**
- * 裁剪新增、车缝新增、手工新增、大烫新增、总检新增、包装新增
- * /work_order_spot_check/search
- */
- 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;
- }
- //将前端传过来的数据存到数据库
- $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); // 查询的结果可能是多条记录,确保是数组
- // 查询子订单编号对应的最大 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 '手工':
- case '大烫':
- case '总检':
- case '包装':
- //调用reportWork方法名函数
- $this->reportWork($params);
- 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() {
- if (!$this->request->isGet()) {
- return $this->error('请求错误');
- }
- $param = $this->request->param();
- if (empty($param['UniqId'])) {
- return $this->error('UniqId参数错误');
- }
- // 将 $param['UniqId'] 的值按逗号分割成数组
- $printIdArray = explode(',', $param['UniqId']);
- // 初始化失败计数器
- $failureCount = 0;
- foreach ($printIdArray as $uniqId) {
- // 根据 UniqId 查询 设备_产量计酬 表中的订单编号、尺码和数量
- $result = \db('设备_产量计酬')->where('UniqId', $uniqId)
- ->field('订单编号,尺码,数量')
- ->find();
- // 检查是否找到结果
- if (!$result) {
- $failureCount++;
- continue; // 跳过当前循环,处理下一个 UniqId
- }
- // 根据订单编号查询工单_印件资料表,并排除有修改日期的记录
- $yresult = \db('工单_印件资料')->where('订单编号', $result['订单编号'])
- ->whereNull('Mod_rq')
- ->find();
- // 检查是否找到结果
- if (!$yresult) {
- $failureCount++;
- continue; // 跳过当前循环,处理下一个 UniqId
- }
- // 获取 result 中的尺码和数量
- $size = $result['尺码'];
- $quantity = $result['数量'];
- // 遍历 yresult 中的 cm1 到 cm10 字段,查找匹配的尺码
- for ($i = 1; $i <= 10; $i++) {
- $cmField = 'cm' . $i;
- $scslField = 'scsl' . $i;
- // 检查 yresult 中是否存在对应的尺码字段,且值等于 result 中的尺码
- if (isset($yresult[$cmField]) && $yresult[$cmField] === $size) {
- // 找到对应 scsl 字段并进行数量减法
- if (isset($yresult[$scslField])) {
- $yresult[$scslField] -= $quantity;
- // 防止数量变成负数
- if ($yresult[$scslField] < 0) {
- $yresult[$scslField] = 0;
- }
- // 更新数据库中的 scsl 字段
- \db('工单_印件资料')
- ->where('订单编号', $result['订单编号'])
- ->update([$scslField => $yresult[$scslField]]);
- }
- break; // 找到并处理后,跳出循环
- }
- }
- // 重新计算 scsl1 到 scsl10 的总和并更新 sctotal 字段
- $newTotal = 0;
- for ($i = 1; $i <= 10; $i++) {
- $scslField = 'scsl' . $i;
- if (isset($yresult[$scslField])) {
- $newTotal += $yresult[$scslField];
- }
- }
- // 更新 sctotal 的最新值到数据库
- \db('工单_印件资料')
- ->where('订单编号', $result['订单编号'])
- ->update(['sctotal' => $newTotal]);
- // 更新设备_产量计酬表的mod_rq和delsys_id字段
- $updateData = [
- 'mod_rq' => date('Y-m-d H:i:s'),
- 'delsys_id' => $param['sys_id']
- ];
- $result = \db('设备_产量计酬')->where('UniqId', $uniqId)->fetchSql(true)->update($updateData);
- $sql = \db()->query($result);
- // 检查更新是否成功
- if ($sql === false) {
- $failureCount++;
- }
- }
- // 如果没有失败记录,则表示删除成功
- if ($failureCount === 0) {
- return $this->success('删除成功');
- } else {
- return $this->error("操作完成,但有 {$failureCount} 条记录更新失败");
- }
- }
- }
|