| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258 |
- <?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();
- }
- $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 ($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();
- }
- $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 ($mergeds 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);
- $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();
- // 根据不同的 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_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' => $item['sl'],
- 'serial_num' => $item['serial_num'],
- '尺码' => $item['cm'],
- '数量' => $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} 条记录更新失败");
- }
- }
- }
|