WorkOrder.php 84 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  5. use PhpOffice\PhpSpreadsheet\Writer\Pdf\Tcpdf;
  6. use think\Config;
  7. use think\Db;
  8. use think\Request;
  9. use PhpOffice\PhpSpreadsheet\IOFactory;
  10. use function fast\e;
  11. /**
  12. * 工单资料管理
  13. */
  14. class WorkOrder extends Api
  15. {
  16. protected $noNeedLogin = ['*'];
  17. protected $noNeedRight = ['*'];
  18. public function _initialize()
  19. {
  20. if (isset($_SERVER['HTTP_ORIGIN'])) {
  21. header('Access-Control-Expose-Headers: __token__');//跨域让客户端获取到
  22. }
  23. //跨域检测
  24. check_cors_request();
  25. if (!isset($_COOKIE['PHPSESSID'])) {
  26. Config::set('session.id', $this->request->server("HTTP_SID"));
  27. }
  28. parent::_initialize();
  29. }
  30. /**
  31. * 工单资料菜单列表
  32. *
  33. * @ApiMethod (GET)
  34. * @return false|string
  35. * @throws \think\Exception
  36. */
  37. public function DataList()
  38. {
  39. $where['j.Mod_rq'] = null;
  40. $allCustomers = \db('erp_客户供应商')->alias('e')
  41. ->field('e.编号 as 客户编号')
  42. ->select();
  43. $customerData = [];
  44. foreach ($allCustomers as $customer) {
  45. $customerID = $customer['客户编号'];
  46. $customerData[$customerID] = ['计划中' => 0, '生产中' => 0];
  47. }
  48. $data = \db('erp_客户供应商')->alias('e')
  49. ->join('工单_基本资料 j', 'e.编号 = j.客户编号', 'LEFT')
  50. ->field('e.编号 as 客户编号, j.订单编号, j.gd_statu')
  51. ->where($where)
  52. ->select();
  53. foreach ($data as $row) {
  54. $customerID = $row['客户编号'];
  55. $status = $row['gd_statu'];
  56. if ($status == '1-计划中') {
  57. $customerData[$customerID]['计划中']++;
  58. } elseif ($status == '2-生产中') {
  59. $customerData[$customerID]['生产中']++;
  60. }
  61. }
  62. ksort($customerData);
  63. $output = [];
  64. foreach ($customerData as $customerID => $statusCounts) {
  65. $statusString = [];
  66. if ($statusCounts['计划中'] > 0) {
  67. $statusString[] = "计划中:{$statusCounts['计划中']}";
  68. }
  69. if ($statusCounts['生产中'] > 0) {
  70. $statusString[] = "生产中:{$statusCounts['生产中']}";
  71. }
  72. $output[] = "{$customerID}【" . implode(' ', $statusString) . "】";
  73. }
  74. $this->success('成功', $output);
  75. }
  76. /**
  77. * 工单基本资料列表
  78. * @ApiMethod (GET)
  79. * @param string $limit 查询长度
  80. * @param string $Gd_khdh 客户代号
  81. * @param string $startTime 接单日期开始时间
  82. * @param string $endTime 接单日期结束时间
  83. * @return \think\response\Json
  84. * @throws \think\exception\DbException
  85. */
  86. public function WorkOrderList()
  87. {
  88. if ($this->request->isGet() === false) {
  89. $this->error('请求错误');
  90. }
  91. $search = input('search');
  92. $page = input('page');
  93. $limit = input('limit');
  94. $param = $this->request->param();
  95. $where = [];
  96. if (!empty($search)) {
  97. $where['订单编号|生产款号|客户编号|款式|审核|Sys_id'] = ['like', '%' . $search . '%'];
  98. }
  99. $where['Mod_rq'] = null;
  100. $list = \db('工单_基本资料')
  101. ->where($where)
  102. ->order('订单编号 desc, Gd_statu desc, Sys_rq desc')
  103. ->limit(($page - 1) * $limit, $limit)
  104. ->select();
  105. // 提取所有订单编号
  106. $orderIds = array_column($list, '订单编号');
  107. // 查询所有在“工单_相关附件”表中存在的订单编号
  108. $relatedOrders = \db('工单_相关附件')
  109. ->whereIn('关联编号', $orderIds)
  110. ->whereIn('附件备注', '技术附件')
  111. ->column('关联编号');
  112. // 遍历数据,判断每个订单编号是否在相关附件表中
  113. foreach ($list as &$value) {
  114. if (in_array($value['订单编号'], $relatedOrders)) {
  115. $value['status'] = ''; // 有相关附件,status为空
  116. } else {
  117. $value['status'] = '*'; // 没有相关附件,标记为新订单
  118. }
  119. }
  120. $this->success('成功', ['data' => $list, 'total' => count($list)]);
  121. }
  122. /**
  123. * 编辑页面展示
  124. * @ApiMethod (GET)
  125. * @param string $workOrder 工单编号
  126. * @return void
  127. * @throws \think\db\exception\DataNotFoundException
  128. * @throws \think\db\exception\ModelNotFoundException
  129. * @throws \think\exception\DbException
  130. */
  131. // public function DataCorrection()
  132. // {
  133. // if ($this->request->isGet() === false){
  134. // $this->error('请求错误');
  135. // }
  136. // $workOrder = input('Gd_gdbh');
  137. // if (empty($workOrder)){
  138. // $this->error('参数错误');
  139. // }
  140. // $field = 'rtrim(Gd_lx) as 重点工单,rtrim(Gd_gdbh) as 工单编号,rtrim(Gd_生产分类) as 生产类型,rtrim(Gd_khdh) as 客户代号,rtrim(Gd_客户名称) as 客户名称,
  141. // rtrim(Gd_cpdh) as 印件代号,rtrim(Gd_cpmc) as 印件名称,rtrim(成品代号) as 产品代号,rtrim(成品名称) as 产品名称,rtrim(接单日期) as 开单日期,rtrim(订单数量) as 订单数量,rtrim(交货日期) as 交货日期,
  142. // rtrim(投料率) as 投料率,rtrim(实际投料) as 万小张,rtrim(计量单位) as 单位,rtrim(投料大箱) as 投料大箱,rtrim(排产时库存) as 库存大箱,rtrim(警语版面) as 警语版面,
  143. // rtrim(销售订单号) as 销售订单号,rtrim(产品版本号) as 版本号,rtrim(客户ERP编码) as 客户ERP编码,rtrim(码源数量) as 码源数量,rtrim(进程备注) as 进程备注,rtrim(Gd_desc) as 备注,rtrim(Uniqid) as Uniqid,rtrim(计划投料) as 平张投料';
  144. // $list = \db('工单_基本资料')->where('Gd_gdbh',$workOrder)->field($field)->find();
  145. // if (empty($list)){
  146. // $this->error('未找到该工单信息');
  147. // }
  148. // $printData = \db('工单_印件资料')
  149. // ->where('Yj_Gdbh',$workOrder)
  150. // ->field('rtrim(yj_yjmc) as 印件名称,rtrim(yj_Yjdh) as 印件代号,rtrim(Uniqid) as id')
  151. // ->cache(true,84600)
  152. // ->find();
  153. // if (empty($printData)){
  154. // $list['印件名称'] = '';
  155. // $list['印件代号'] = '';
  156. // $list['印件ID'] = '';
  157. // }else{
  158. // $list['印件名称'] = $printData['印件名称'];
  159. // $list['印件代号'] = $printData['印件代号'];
  160. // $list['印件ID'] = $printData['id'];
  161. // }
  162. // $this->success('成功',$list);
  163. // }
  164. /**
  165. * 工单资料修改
  166. * @ApiMethod (POST)
  167. * @param void
  168. * @return void
  169. * @throws \think\Exception
  170. * @throws \think\exception\PDOException
  171. */
  172. // public function WorkOrderEdit()
  173. // {
  174. // if (Request::instance()->isPost() === false){
  175. // $this->error('请求错误');
  176. // }
  177. // $param = Request::instance()->post();
  178. // if (empty($param) || isset($param['Uniqid']) === false){
  179. // $this->error('参数错误');
  180. // }
  181. // $row = [
  182. // 'Gd_lx' => isset($param['lx'])?$param['lx']:'',
  183. // '开单日期' => isset($param['kdrq'])?$param['kdrq']:'',
  184. // 'Gd_gdbh' => isset($param['gdbh'])?$param['gdbh']:'',
  185. // 'Gd_生产分类' => isset($param['scfl'])?$param['scfl']:'',
  186. // 'Gd_客户代号' => isset($param['khdh'])?$param['khdh']:'',
  187. // 'Gd_客户名称' => isset($param['khmc'])?$param['khmc']:'',
  188. // '成品代号' => isset($param['cpdh'])?$param['cpdh']:'',
  189. // '成品名称' => isset($param['cpmc'])?$param['cpmc']:'',
  190. // '订单数量' => isset($param['ddsl'])?$param['ddsl']:'',
  191. // '交货日期' => isset($param['jhrq'])?$param['jhrq']:'',
  192. // '投料率' => isset($param['tll'])?$param['tll']:'',
  193. // '计划投料' => isset($param['jhtl'])?$param['jhtl']:'',
  194. // '实际投料' => isset($param['sjtl'])?$param['sjtl']:'',
  195. // '计量单位' => isset($param['jldw'])?$param['jldw']:'',
  196. // '投料大箱' => isset($param['tldx'])?$param['tldx']:'',
  197. // '销售订单号' => isset($param['xsddh'])?$param['xsddh']:'',
  198. // '警语版面' => isset($param['jymb'])?$param['jymb']:'',
  199. // '产品版本号' => isset($param['bbh'])?$param['bbh']:'',
  200. // '客户ERP编码' => isset($param['erp'])?$param['erp']:'',
  201. // '码源数量' => isset($param['ymsl'])?$param['ymsl']:'',
  202. // '进程备注' => isset($param['jcbz'])?$param['jcbz']:'',
  203. // 'Gd_desc' => isset($param['desc'])?$param['desc']:'',
  204. // '排产时库存' => isset($param['kc'])?$param['kc']:'',
  205. // '平均合格率' => isset($param['avg'])?$param['avg']:'',
  206. // ];
  207. // //获取印件资料
  208. // $printCode = \db('工单_印件资料')
  209. // ->where('Uniqid',$param['printID'])
  210. // ->value('yj_Yjno');
  211. // if (!empty($printCode)){
  212. // if ((int)$param['jhtl'] >0){
  213. // //修改工单工艺计划产量
  214. // $result = $this->PlannedProcessYield($param['gdbh'],$printCode,0,$param['jhtl']);
  215. // if ($result === false){
  216. // $this->success('分配工序计划产量失败');
  217. // }
  218. // }
  219. //
  220. // //修改印件信息
  221. // $printSql = \db('工单_印件资料')
  222. // ->where('Uniqid',$param['printID'])
  223. // ->fetchSql(true)
  224. // ->update(['Yj_Gdbh'=>$param['gdbh'],'yj_yjmc'=>$param['yjmc'],'yj_Yjdh'=>$param['yjdh'],'yj_平张投料'=>$param['jhtl']]);
  225. // $printRes = Db::query($printSql);
  226. // }
  227. // //修改工单信息
  228. // $sql = \db('工单_基本资料')->where('Uniqid',$param['Uniqid'])->fetchSql(true)->update($row);
  229. // $res = Db::query($sql);
  230. // //修改订单数量该工单下的订单数量
  231. // //1. 查询该id下的工单编号, 防止其手动修改工单编号导致条件错误
  232. // $gdbh = \db('工单_基本资料')->where('Uniqid',$param['Uniqid'])->value('Gd_gdbh');
  233. // //2. 根据查出的工单编号修改订单数量
  234. // $sql = \db('工单_基本资料')->where('Gd_gdbh',$param['gdbh'])->fetchSql(true)->update(['订单数量'=>$row['订单数量']]);
  235. // $res1 = Db::query($sql);
  236. // if ($res !== false && $res1 !== false){
  237. // $this->success('成功');
  238. // }else{
  239. // $this->error('失败');
  240. // }
  241. // }
  242. /**
  243. * U8投料试算
  244. * @ApiMethod (GET)
  245. * @param string $processCode 产品编号
  246. * @return void
  247. * @throws \think\db\exception\DataNotFoundException
  248. * @throws \think\db\exception\ModelNotFoundException
  249. * @throws \think\exception\DbException
  250. */
  251. // public function U8Trial()
  252. // {
  253. // if ($this->request->isGet() === false)
  254. // {
  255. // $this->error('请求错误');
  256. // }
  257. // $productCode = input('productCode');
  258. // if (empty($productCode)){
  259. // $this->error('参数错误');
  260. // }
  261. // $field = 'rtrim(Gy0_cpdh) as 产品代号,rtrim(Gy0_yjno) as 印件号,rtrim(Gy0_gxh) as 工序号,rtrim(gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc,
  262. // rtrim(Gy0_Ms) as 墨色数,rtrim(Gy0_shdh) as 损耗代号,rtrim(损耗系数) as 损耗系数,rtrim(Gy0_ls) as 加工联数';
  263. // $list = \db('产品_工艺资料')->where('Gy0_cpdh',$productCode)->field($field)->select();
  264. // if (empty($list)){
  265. // $this->success('未找到该产品工序');
  266. // }
  267. // foreach ($list as $key=>$value){
  268. // $data = \db('dic_lzsh')->where('sys_bh',$value['损耗代号'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->cache(true)->find();
  269. // $list[$key]['调机损耗'] = isset($data['rate0'])?$data['rate0']:'';
  270. // $list[$key]['运行损耗率'] = isset($data['rate1'])?$data['rate1']:'';
  271. // if ($value['add_gxmc'] !== ''){
  272. // $list[$key]['工序名称'] = $value['gxmc'].'【'.$value['add_gxmc'].'】';
  273. // }else{
  274. // $list[$key]['工序名称'] = $value['gxmc'];
  275. // }
  276. // unset($list[$key]['gxmc'],$list[$key]['add_gxmc']);
  277. // }
  278. // $this->success('成功',$list);
  279. // }
  280. /**
  281. * 月度客户订单汇总
  282. */
  283. public function ProductInformation()
  284. {
  285. if ($this->request->isGet() === false) {
  286. $this->error('请求错误');
  287. }
  288. // 查询生产中和未生产的数据,使用 CASE WHEN 进行分类统计
  289. $data = \db('工单_基本资料')->alias('j')
  290. ->field('
  291. j.客户编号,
  292. REPLACE(DATE_FORMAT(j.Sys_rq, "%Y-%m"), "-", "") as 年月,
  293. SUM(CASE WHEN j.gd_statu = "2-生产中" THEN 1 ELSE 0 END) as 生产中数量,
  294. SUM(CASE WHEN j.gd_statu = "1-计划中" THEN 1 ELSE 0 END) as 未生产数量
  295. ')
  296. ->where('j.Mod_rq', null) // 统一的查询条件
  297. ->group('j.客户编号, 年月')
  298. ->order('j.客户编号 asc')
  299. ->select();
  300. // 格式化数据
  301. $result = [];
  302. foreach ($data as $item) {
  303. $result[$item['年月']][] = $item['客户编号'] . '【生产中' . $item['生产中数量'] . ',计划中' . $item['未生产数量'] . '】';
  304. }
  305. $this->success('请求成功', ['data' => $result]);
  306. }
  307. // public function ProductInformation(){
  308. // if ($this->request->isGet() === false) {
  309. // $this->error('请求错误');
  310. // }
  311. // $where['j.gd_statu'] = '2-生产中';
  312. // $where['j.Mod_rq'] = null;
  313. //
  314. // $data = \db('工单_基本资料')->alias('j')
  315. // ->field('j.客户编号, REPLACE(DATE_FORMAT(j.Sys_rq, "%Y-%m"), "-", "") as 年月, GROUP_CONCAT(DISTINCT j.订单编号) as 订单编号')
  316. // ->where($where)
  317. // ->order('j.客户编号 asc')
  318. // ->group('j.客户编号, 年月')
  319. // ->select();
  320. // $result = [];
  321. // foreach ($data as $item) {
  322. // $orderlist = count(explode(',', $item['订单编号']));
  323. // $result[$item['年月']][] = [$item['客户编号'] . '【生产中:' . $orderlist . '】',
  324. // ];
  325. // }
  326. //
  327. // $this->success('请求成功', ['data' => $result]);
  328. // }
  329. /**
  330. * 引用产品资料->复制产品工艺资料
  331. * @ApiMethod (POST)
  332. * @param string $oldWorkOrder 被复制工单编号
  333. * @param string $newWorkOrder 复制工单编号
  334. * @return void
  335. * @throws \think\Exception
  336. * @throws \think\db\exception\DataNotFoundException
  337. * @throws \think\db\exception\ModelNotFoundException
  338. * @throws \think\exception\DbException
  339. * @throws \think\exception\PDOException
  340. */
  341. // public function ProductInformationEdit()
  342. // {
  343. // if (Request::instance()->isPost() === false)
  344. // {
  345. // $this->error('请求错误');
  346. // }
  347. // $oldWorkOrder = input('oldWorkOrder');
  348. // $newWorkOrder = input('newWorkOrder');
  349. // if (empty($oldWorkOrder) || empty($newWorkOrder))
  350. // {
  351. // $this->error('参数错误');
  352. // }
  353. // $lastId = \db('工单_工艺资料')->order('UniqId desc')->value('UniqId');
  354. // if ($lastId<10000000){
  355. // $lastId = 10000000;
  356. // }else{
  357. // $lastId = $lastId + 1;
  358. // }
  359. // //获取原工单工艺资料
  360. // $oldProcessData = \db('工单_工艺资料')->where('Gy0_gdbh',$newWorkOrder)->select();
  361. // $ProsessUniqId = \db('工单_工艺资料')->field('UniqId')->order('UniqId desc')->find();
  362. // foreach ($oldProcessData as $k=>$v){
  363. // $oldProcessData[$k]['Gy0_gdbh'] = $oldWorkOrder;
  364. // $oldProcessData[$k]['Sys_id'] = '';
  365. // $oldProcessData[$k]['Gy0_sj1'] = '1900-01-01 00:00:00';
  366. // $oldProcessData[$k]['Gy0_sj2'] = '1900-01-01 00:00:00';
  367. // $oldProcessData[$k]['UniqId'] = $lastId + $k;
  368. // $oldProcessData[$k]['PD_WG'] = '1900-01-01 00:00:00';
  369. // }
  370. // if (\db('工单_工艺资料')->where('Gy0_gdbh',$oldWorkOrder)->find()){
  371. // \db('工单_工艺资料')->where('Gy0_gdbh',$oldWorkOrder)->delete();
  372. // }
  373. // //获取原工单印件资料
  374. // $lastUniqId = \db('工单_印件资料')->order('UniqId desc')->value('UniqId');
  375. // if ($lastUniqId<1000000){
  376. // $lastUniqId = 1000000;
  377. // }else{
  378. // $lastUniqId = $lastUniqId + 1;
  379. // }
  380. // $oldPrintData = \db('工单_印件资料')->where('Yj_Gdbh',$newWorkOrder)->select();
  381. // $PrintUniqId = \db('工单_印件资料')->field('Uniqid')->order('Uniqid desc')->find();
  382. // foreach ($oldPrintData as $k=>$v){
  383. // $oldPrintData[$k]['Yj_Gdbh'] = $oldWorkOrder;
  384. // $oldPrintData[$k]['Sys_id'] = '';
  385. // $oldPrintData[$k]['Uniqid'] = $lastUniqId +$k +1;
  386. // }
  387. // if (\db('工单_印件资料')->where('Yj_Gdbh',$oldWorkOrder)->find()){
  388. // \db('工单_印件资料')->where('Yj_Gdbh',$oldWorkOrder)->delete();
  389. // }
  390. // //复制印件、工艺资料
  391. // $ProcessSQL = \db('工单_工艺资料')->fetchSql(true)->insertAll($oldProcessData);
  392. // $ProcessRes = Db::query($ProcessSQL);
  393. // $PrintSQL = \db('工单_印件资料')->fetchSql(true)->insertAll($oldPrintData);
  394. // $PrintRes = Db::query($PrintSQL);
  395. // if ($ProcessRes !== false && $PrintRes !== false){
  396. // $this->success('成功');
  397. // }else{
  398. // $this->error('失败');
  399. // }
  400. // }
  401. /**
  402. * 工艺流程调成->获取当前工单工艺资料
  403. * @ApiMethod (GET)
  404. * @param string $workorder 当前工单编号
  405. * @return void
  406. * @throws \think\db\exception\DataNotFoundException
  407. * @throws \think\db\exception\ModelNotFoundException
  408. * @throws \think\exception\DbException
  409. */
  410. // public function ProcessFlow()
  411. // {
  412. // if ($this->request->isGet() === false){
  413. // $this->error('请求错误');
  414. // }
  415. // $workOrder = input('workOrder');
  416. // if (empty($workOrder)){
  417. // $this->error('参数错误');
  418. // }
  419. // $list = \db('工单_基本资料')->where('Gd_gdbh',$workOrder)->field('rtrim(成品代号) as 成品编号,rtrim(成品名称) as 成品名称')->find();
  420. // if (empty($list)){
  421. // $this->success('未找到工单信息');
  422. // }
  423. // $filed = 'rtrim(Gy0_方案) as 方案,rtrim(Gy0_yjno) as 印件号,rtrim(Gy0_gxh) as 工序号,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc,
  424. // rtrim(工价系数) as 工价系数,rtrim(损耗系数) as 损耗系数,rtrim(Gy0_ks) as ks,rtrim(Gy0_ls) as ls,rtrim(工序备注) as 备注,rtrim(Gy0_SITE) as 车间,
  425. // rtrim(Gy0_sbbh) as 设备编号,rtrim(Gy0_sbmc) as 设备名称,rtrim(Sys_id) as 建档用户,rtrim(Sys_rq) as 建档时间,rtrim(Mod_rq) as 更新时间,rtrim(UniqId) as UniqId';
  426. // $process = \db('工单_工艺资料')->where('Gy0_gdbh',$workOrder)->cache(true,84600)->field($filed)->select();
  427. // if (empty($process)){
  428. // $this->error('未找到该工单工艺资料');
  429. // }
  430. // foreach ($process as $key=>$value){
  431. // if (isset($value['add_gxmc'])){
  432. // $process[$key]['工序名称'] = $value['gxmc'] . '【'.$value['add_gxmc'].'】';
  433. // }else{
  434. // $process[$key]['工序名称'] = $value['gxmc'];
  435. // }
  436. // $process[$key]['工价系数'] = (float)$value['工价系数'];
  437. // $process[$key]['损耗系数'] = (float)$value['损耗系数'];
  438. // $process[$key]['开数*联数'] = $value['ks'].'*'.$value['ls'];
  439. // }
  440. // $list['process'] = $process;
  441. // $this->success('成功',$list);
  442. // }
  443. /**
  444. * 参照工单列表获取
  445. * @ApiMethod (GET)
  446. * @param string $workOrder 工单编号
  447. * @param string $productCode 产品代号
  448. * @return void
  449. */
  450. // public function ReferenceWorkOrder()
  451. // {
  452. // if ($this->request->isGet() === false){
  453. // $this->error('请求错误');
  454. // }
  455. // $productCode = input('productCode');
  456. // $workOrder = input('workOrder');
  457. // if (empty($productCode) || empty($workOrder)){
  458. // $this->error('参数错误');
  459. // }
  460. // $list = \db('工单_基本资料')->where('成品代号',$productCode)->distinct(true)->where('Gd_gdbh','<>',$workOrder)->column('Gd_gdbh');
  461. // if (empty($list)){
  462. // $this->success('未获取该产品其他工单信息');
  463. // }
  464. // $this->success('成功',$list);
  465. // }
  466. /**
  467. * 工艺资料复制
  468. * @ApiMethod (POST)
  469. * @param string $oldWorkOrder 被复制工单编号
  470. * @param string $newWorkOrder 复制工单编号
  471. * @return void
  472. * @throws \think\Exception
  473. * @throws \think\db\exception\DataNotFoundException
  474. * @throws \think\db\exception\ModelNotFoundException
  475. * @throws \think\exception\DbException
  476. * @throws \think\exception\PDOException
  477. *
  478. */
  479. // public function ProcessCopy()
  480. // {
  481. // if (Request::instance()->isPost() === false){
  482. // $this->error('请求错误');
  483. // }
  484. // $param = Request::instance()->post();
  485. // if (empty($param)){
  486. // $this->error('参数错误');
  487. // }
  488. // $UniqId = [];
  489. // $lastId = \db('工单_工艺资料')->field('rtrim(UniqId) as id')->order('UniqId desc')->find();
  490. // if ($lastId['id']>10000000){
  491. // $lastUniqId = $lastId['id'];
  492. // }else{
  493. // $lastUniqId = 10000000;
  494. // }
  495. // foreach ($param as $key=>$value){
  496. // $UniqId[$key] = $value['UniqId'];
  497. // }
  498. // $processList = \db('工单_工艺资料')->where('UniqId','in',$UniqId)->select();
  499. // if (empty($processList)){
  500. // $this->success('未找到工艺资料');
  501. // }
  502. // $data = [];
  503. // foreach ($param as $key=>$value){
  504. // foreach ($processList as $k=>$v){
  505. // if ($value['UniqId'] = $v['UniqId']){
  506. // $data[$key] = $v;
  507. // $data[$key]['Gy0_gxh'] = $value['gxh'];
  508. // $data[$key]['Gy0_gdbh'] = $value['workOrder'];
  509. // $data[$key]['UniqId'] = $lastUniqId + $key + 1;
  510. // }
  511. // }
  512. // }
  513. // $res = \db('工单_工艺资料')->where(['Gy0_gdbh'=>$param[0]['workOrder']])->delete();
  514. // if ($res !== false){
  515. // $result = \db('工单_工艺资料')->insertAll($data);
  516. // if ($result !== false){
  517. // $this->success('成功');
  518. // }else{
  519. // $this->error('失败');
  520. // }
  521. // }else{
  522. // $this->error('失败');
  523. // }
  524. // }
  525. /**
  526. * U8工单列表
  527. * @ApiMethod (GET)
  528. * @param void
  529. * @return void
  530. * @throws \think\db\exception\DataNotFoundException
  531. * @throws \think\db\exception\ModelNotFoundException
  532. * @throws \think\exception\DbException
  533. */
  534. // public function U8workOrder()
  535. // {
  536. // if ($this->request->isGet() === false){
  537. // $this->error('请求错误');
  538. // }
  539. // $param = $this->request->param();
  540. // if (empty($param)){
  541. // $this->error('参数错误');
  542. // }
  543. // $filed = 'rtrim(Gd_gdbh) as 工单编号,rtrim(行号) as 行号,rtrim(Gd_客户代号) as 客户代号,rtrim(Gd_客户名称) as 客户名称,
  544. // rtrim(成品代号) as 成品代号,rtrim(成品名称) as 成品名称,rtrim(Mod_rq) as 获取日期,rtrim(Uniqid) as 序号';
  545. // $list = \db('工单_基本资料')->where('Gd_gdbh',$param['workOrder'])->field($filed)->select();
  546. // if (empty($list)){
  547. // $this->success('未找到工单');
  548. // }
  549. // $this->success('成功',$list);
  550. // }
  551. /**
  552. * U8工单资料删除
  553. * @param string $workOrder 工单编号
  554. * @return void
  555. * @throws \think\Exception
  556. * @throws \think\exception\PDOException
  557. */
  558. public function orderDataDel()
  559. {
  560. if($this->request->isGet() === false){
  561. $this->error('请求错误');
  562. }
  563. $workOrder = input('Uniqid');
  564. if (empty($workOrder)){
  565. $this->error('参数错误');
  566. }
  567. $order = \db('工单_基本资料')->where('UniqId',$workOrder)->find();
  568. \db()->startTrans();
  569. try {
  570. \db('工单_印件资料')->where('订单编号',$order['订单编号'])->update(['Mod_rq'=>date('Y-m-d H:i:s')]);
  571. \db('工单_工艺资料')->where('订单编号',$order['订单编号'])->update(['Mod_rq'=>date('Y-m-d H:i:s')]);
  572. $res = \db('工单_基本资料')->where('UniqId',$workOrder)->update(['Mod_rq'=>date('Y-m-d H:i:s')]);
  573. \db()->commit();
  574. } catch (\Exception $e){
  575. \db()->rollback();
  576. }
  577. if ($res !== false){
  578. $this->success('成功');
  579. }else{
  580. $this->error('失败');
  581. }
  582. }
  583. /**
  584. *
  585. */
  586. // public function TestCoefficient()
  587. // {
  588. // }
  589. /**
  590. *
  591. */
  592. // public function TestCoefficientEdit()
  593. // {
  594. // }
  595. /**
  596. *
  597. */
  598. // public function AccountingParameter()
  599. // {
  600. // }
  601. /**
  602. *
  603. */
  604. // public function AccountingParameterEdit()
  605. // {
  606. // }
  607. /**
  608. * 印件资料修改
  609. * @ApiMethod (POST)
  610. * @param void
  611. * @return void
  612. * @throws \think\Exception
  613. * @throws \think\exception\PDOException
  614. */
  615. public function PrintedEdit()
  616. {
  617. if (Request::instance()->isPost() === false){
  618. $this->error('请求错误');
  619. }
  620. $param = Request::instance()->post();
  621. if (empty($param) || isset($param['Uniqid']) === false){
  622. $this->error('参数错误');
  623. }
  624. $param['Yj_Gdbh'] = \db('工单_印件资料')->where('Uniqid',$param['Uniqid'])->value('Yj_Gdbh');
  625. $data = [
  626. 'Yj_Gdbh' =>$param['Yj_Gdbh'],
  627. 'yj_Yjno' =>$param['yjno'],
  628. 'yj_Yjdh' =>$param['yjdh'],
  629. 'yj_yjmc' =>$param['yjmc'],
  630. 'yj_zzdh' =>$param['zzdh'],
  631. 'yj_zzdh1' =>$param['zzdh1'],
  632. 'yj_zzdh2' =>$param['zzdh2'],
  633. 'yj_zzdh3' =>$param['zzdh3'],
  634. 'yj_zzdh4' =>$param['zzdh4'],
  635. 'yj_zzmc' =>$param['zzmc'],
  636. 'yj_zzmc1' =>$param['zzmc1'],
  637. 'yj_zzmc2' =>$param['zzmc2'],
  638. 'yj_zzmc3' =>$param['zzmc3'],
  639. 'yj_zzmc4' =>$param['zzmc4'],
  640. 'yj_tlgg' =>$param['tlgg'],
  641. 'yj_klgg' =>$param['klgg'],
  642. 'Yj_核算规格' =>$param['hsgg'],
  643. 'yj_成品数量' =>$param['cpsl'],
  644. 'yj_平张投料' =>$param['pztl'],
  645. 'yj_ks' =>$param['ks'],
  646. 'yj_ls' =>$param['ls'],
  647. 'yj_desc' =>$param['desc'],
  648. ];
  649. $UniqId = $param['Uniqid'];
  650. $sql = \db('工单_印件资料')->where('Uniqid',$UniqId)->fetchSql(true)->update($data);
  651. $res = Db::query($sql);
  652. $process = \db('工单_工艺资料')
  653. ->where('Gy0_gdbh',$data['Yj_Gdbh'])
  654. ->where('Gy0_yjno',$data['yj_Yjno'])
  655. ->select();
  656. if ((int)$data['yj_平张投料'] > 0 && !empty($process)){
  657. //重新分配工序计划产量
  658. $result = $this->PlannedProcessYield($data['Yj_Gdbh'],$data['yj_Yjno'],0,$data['yj_平张投料']);
  659. if ($result === false){
  660. $this->success('修改工序产量失败');
  661. }
  662. }
  663. if ($res !== false){
  664. $this->success('成功');
  665. }else{
  666. $this->error('失败');
  667. }
  668. }
  669. /**
  670. * 工艺资料修改
  671. * @ApiMethod (POST)
  672. */
  673. public function ProcessDetailEdit()
  674. {
  675. if (Request::instance()->isPost() === false){
  676. $this->error('请求错误');
  677. }
  678. $param = Request::instance()->post();
  679. if (empty($param) || isset($param['UniqId']) === false){
  680. $this->error('参数错误');
  681. }
  682. if (empty($param['Gy0_shdh'])){
  683. $rate['rate0'] = 0;
  684. $rate['rate1'] = 0;
  685. }else{
  686. $rate = \db('dic_lzsh')->where('sys_bh',$param['Gy0_shdh'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->find();
  687. }
  688. $param['Gy0_Rate0']= isset($rate['rate0'])?$rate['rate0']:0;
  689. $param['Gy0_Rate1'] = isset($rate['rate1'])?$rate['rate1']:0;
  690. $param['Mod_rq'] = date('Y-m-d H:i:s',time());
  691. $UniqId = $param['UniqId'];
  692. unset($param['UniqId']);
  693. //修改工艺资料
  694. $sql = \db('工单_工艺资料')->where('UniqId',$UniqId)->fetchSql(true)->update($param);
  695. $res = Db::query($sql);
  696. //获取工艺资料数据
  697. $list = \db('工单_工艺资料')->where('UniqId',$UniqId)->field('Gy0_yjno,Gy0_gxh,rtrim(Gy0_计划接货数) as 计划接货数')->find();
  698. // //修改工单状态
  699. // $status = \db('工单_基本资料')->where('Gd_gdbh',$param['Gy0_gdbh'])->field('rtrim(gd_statu) as status')->find();
  700. // if ($status['status'] !== '2-生产中'){
  701. // $statusSql = \db('工单_基本资料')->where('Gd_gdbh',$param['Gy0_gdbh'])->fetchSql(true)->update(['gd_statu'=>'2-生产中']);
  702. // Db::query($statusSql);
  703. // }
  704. //重新分配工序计划产量
  705. if ((int)$list['计划接货数'] > 0){
  706. $result = $this->PlannedProcessYield($param['Gy0_gdbh'],$list['Gy0_yjno'],$list['Gy0_gxh'],$list['计划接货数']);
  707. }
  708. if ($res !== false){
  709. $this->success('成功');
  710. }else{
  711. $this->error('失败');
  712. }
  713. }
  714. /**
  715. *
  716. */
  717. // public function MachineList()
  718. // {
  719. // }
  720. /**
  721. *
  722. */
  723. // public function PrintCodeList()
  724. // {
  725. // }
  726. /**
  727. *
  728. */
  729. // public function ProcessCodeList()
  730. // {
  731. // }
  732. /**
  733. *
  734. */
  735. // public function PrintJobOrder()
  736. // {
  737. // }
  738. /**
  739. *
  740. */
  741. // public function workOrderDetailGet($workOrder,$yjno)
  742. // {
  743. // }
  744. /**
  745. */
  746. // public function MaterielDetailGet($workOrder)
  747. // {
  748. // }
  749. /**
  750. */
  751. // public function PrintDetailGet($workOrder,$yjno,$gxh)
  752. // {
  753. // }
  754. /**
  755. *
  756. */
  757. // public function capacityList(){
  758. // }
  759. /**
  760. * 新增工单->添加工单
  761. * @ApiMethod (POST)
  762. * @param
  763. */
  764. public function WorkOrderAdd()
  765. {
  766. // var_dump(1);exit;
  767. if (Request::instance()->isPost() === false){
  768. $this->error('请求错误');
  769. }
  770. $param = Request::instance()->post();
  771. if (empty($param)){
  772. $this->error('参数错误');
  773. }
  774. $param['Sys_rq'] = date('Y-m-d H:i:s');
  775. $param['gd_statu'] = '1-计划中';
  776. $prefix = substr($param['订单编号'], 0, 2); // e.g., "DC"
  777. $maxOrder = \db('工单_基本资料')
  778. ->where('订单编号', 'like', "{$prefix}%")
  779. ->order('订单编号', 'desc')
  780. ->limit(1)
  781. ->value('订单编号');
  782. if ($maxOrder) {
  783. $numericPart = substr($maxOrder, 2);
  784. $newNumericPart = str_pad((int)$numericPart + 1, strlen($numericPart), '0', STR_PAD_LEFT);
  785. $param['订单编号'] = $prefix . $newNumericPart;
  786. } else {
  787. $param['订单编号'] = $param['订单编号'];
  788. }
  789. $massage = $param['面料'].',粘衬:'.$param['粘衬'];
  790. $mianliao = $this->Gpt($massage);
  791. $data = [];
  792. foreach ($mianliao as $key => $value){
  793. $data[$key] = [
  794. 'BOM_工单编号' => $param['订单编号'],
  795. 'BOM_物料名称' => $value,
  796. 'Sys_rq' => date('Y-m-d H:i:s',time()),
  797. 'Sys_id' => $param['Sys_id']
  798. ];
  799. }
  800. Db::startTrans();
  801. try {
  802. //插入工单基本资料
  803. $sql= \db('工单_基本资料')->fetchSql(true)->insert($param);
  804. $res = \db()->query($sql);
  805. //插入订单物料信息
  806. $BomSql = \db('工单_bom资料')->fetchSql(true)->insertAll($data);
  807. $BomRes = \db()->query($BomSql);
  808. //提交
  809. Db::commit();
  810. }catch (\Exception $e){
  811. //回滚
  812. Db::rollback();
  813. }
  814. $this->success('成功');
  815. }
  816. /**
  817. *
  818. */
  819. // public function ClientList(){
  820. // }
  821. /**
  822. *
  823. */
  824. // public function ProductCodeList(){
  825. // }
  826. /**
  827. * 新增印件资料->印件资料添加
  828. * @return void
  829. * @throws \think\db\exception\BindParamException
  830. * @throws \think\exception\PDOException
  831. */
  832. public function PrintDetailAdd()
  833. {
  834. if (Request::instance()->isPost() === false){
  835. $this->error('请求错误');
  836. }
  837. $param = Request::instance()->post();
  838. if (empty($param)){
  839. $this->error('参数错误');
  840. }
  841. $param['Sys_rq'] = date('Y-m-d H:i:s',time());
  842. $process = [
  843. ['1','仓库出库'],['2','裁剪'],['3','车缝'],['4','后道收样'],['5','大烫'],['6','总检'],['7','包装']
  844. ];
  845. $processDetail = [];
  846. foreach ($process as $key=>$value){
  847. $total = null;
  848. if ($key !== 0){
  849. $total = $param['zdtotal'];
  850. }
  851. $processDetail[$key] = [
  852. '订单编号' => $param['订单编号'],
  853. '子订单编号' => $param['子订单编号'],
  854. '款号' => $param['款号'],
  855. '颜色' => $param['颜色'],
  856. '颜色备注' => $param['颜色备注'],
  857. '工序编号' => $value[0],
  858. '工序名称' => $value[1],
  859. '计划产量' => $total,
  860. 'Sys_id' => $param['Sys_id'],
  861. 'Sys_rq' => $param['Sys_rq']
  862. ];
  863. }
  864. //开启事务
  865. db()->startTrans();
  866. try{
  867. $priSql = \db('工单_印件资料')->fetchSql(true)->insert($param);
  868. $priRes = \db()->query($priSql);
  869. $proSql = \db('工单_工艺资料')->fetchSql(true)->insertAll($processDetail);
  870. $proRes = \db()->query($proSql);
  871. // 提交事务
  872. db()->commit();
  873. } catch (\Exception $e) {
  874. // 回滚事务
  875. db()->rollback();
  876. $this->error($e->getMessage());
  877. }
  878. if ($priRes !== false && $proRes !== false){
  879. $this->success('成功');
  880. }else{
  881. $this->error('失败');
  882. }
  883. }
  884. /**
  885. *
  886. */
  887. // public function ProcessDetailAdd(){
  888. // }
  889. /**
  890. *
  891. */
  892. // public function PrintDetailList(){
  893. // }
  894. /**
  895. * 子订单列表
  896. * @return null
  897. * @throws \think\db\exception\DataNotFoundException
  898. * @throws \think\db\exception\ModelNotFoundException
  899. * @throws \think\exception\DbException
  900. */
  901. public function PrintListData()
  902. {
  903. // 检查请求方式
  904. if ($this->request->isGet() === false) {
  905. $this->error('请求错误');
  906. }
  907. $param = $this->request->param();
  908. // 检查参数是否存在
  909. if (isset($param) === false) {
  910. $this->error('参数错误');
  911. }
  912. // 查询型号
  913. $where['Mod_rq'] = null;
  914. $xhdata = \db('工单_印件资料')
  915. ->where('订单编号', $param['order'])
  916. ->where($where)
  917. ->field('cm1,cm2,cm3,cm4,cm5,cm6,cm7,cm8,cm9,cm10')
  918. ->select();
  919. $arr = [];
  920. // 收集cm1到cm10的非空非null值
  921. foreach ($xhdata as $key => $value) {
  922. for ($i = 1; $i <= 10; $i++) {
  923. if ($value['cm' . $i] !== '' && $value['cm' . $i] !== null) {
  924. array_push($arr, $value['cm' . $i]);
  925. }
  926. }
  927. }
  928. $arr = array_unique($arr);
  929. sort($arr);
  930. // 查询详细列表
  931. $list = \db('工单_印件资料')
  932. ->where('订单编号', $param['order'])
  933. ->where($where)
  934. ->field('订单编号,子订单编号,款号,颜色,船样,zdtotal,Sys_id,Sys_rq,ck_rq,sc_rq,cm1,cm2,cm3,cm4,cm5,cm6,updatatime as 更新时间,颜色备注,color_id,cm7,cm8,cm9,cm10,cmsl1,cmsl2,cmsl3,cmsl4,cmsl5,cmsl6,cmsl7,cmsl8,cmsl9,cmsl10,Uniqid')
  935. ->select();
  936. // 遍历列表并处理cm和cmsl字段
  937. foreach ($list as $key => $value) {
  938. for ($i = 1; $i <= 10; $i++) {
  939. if ($value['cm' . $i] !== '') {
  940. // 如果 cmsl 的值为 0,则设置为空字符串
  941. $list[$key][$value['cm' . $i]] = ($value['cmsl' . $i] === 0) ? '' : $value['cmsl' . $i];
  942. }
  943. // 删除原有的 cm 和 cmsl 字段
  944. // unset($list[$key]['cm' . $i], $list[$key]['cmsl' . $i]);
  945. }
  946. }
  947. // 自定义型号排序
  948. $customOrder = array('XXS','XS','S', 'M', 'L', 'XL','XXL', 'XXXL', 'XXXXL', '2XL', '3XL', '4XL');
  949. usort($arr, function ($a, $b) use ($customOrder) {
  950. $posA = array_search($a, $customOrder);
  951. $posB = array_search($b, $customOrder);
  952. return $posA - $posB;
  953. });
  954. // 返回结果
  955. $data['型号'] = $arr;
  956. $data['列表'] = $list;
  957. $this->success('成功', $data);
  958. }
  959. /**
  960. * 工单资料管理->印件资料删除
  961. * @return void
  962. * @throws \think\Exception
  963. * @throws \think\exception\PDOException
  964. */
  965. public function PrintDetailDel()
  966. {
  967. if ($this->request->isGet() === false){
  968. $this->error('请求错误');
  969. }
  970. $param = $this->request->param();
  971. if (isset($param['UniqId']) === false){
  972. $this->error('参数错误');
  973. }
  974. $printId = explode(',',$param['UniqId']);
  975. $i = 0;
  976. foreach ($printId as $value){
  977. $res = \db('工单_印件资料')
  978. ->where('Uniqid',$value)
  979. ->update(['Mod_rq'=>date('Y-m-d H:i:s',time())]);
  980. if ($res === false){
  981. $i++;
  982. }
  983. }
  984. if ($i === 0){
  985. $this->success('删除成功');
  986. }else{
  987. $this->error('删除失败');
  988. }
  989. }
  990. /**
  991. * 月度车间报工汇总->报工删除记录
  992. */
  993. public function ProcessDetailDel()
  994. {
  995. if ($this->request->isGet() === false){
  996. $this->error('请求错误');
  997. }
  998. $where['a.mod_rq'] = ['neq', ''];
  999. $list = \db('设备_产量计酬')->alias('a')
  1000. ->join('工单_印件资料 b', 'b.订单编号 = a.订单编号 AND a.子订单编号 = a.子订单编号')
  1001. ->join('工单_基本资料 j', 'b.订单编号 = j.订单编号', 'LEFT')
  1002. ->field('
  1003. b.订单编号, b.子订单编号, b.款号, b.颜色, b.船样, a.尺码, b.zdtotal as 制单数,b.颜色备注,
  1004. a.数量, a.sys_rq as 上报时间,a.UniqId,a.mod_rq,a.delsys_id,a.sczl_bh,
  1005. j.客户编号,j.生产款号,j.款式
  1006. ')
  1007. ->where($where)
  1008. ->order('a.mod_rq desc')
  1009. ->group('a.UniqId')
  1010. ->select();
  1011. // 提取所有的尺码,并去重
  1012. $sizeList = array_values(array_unique(array_column($list, '尺码')));
  1013. // 动态将尺码的数量添加到每个订单中,并替换已完成字段
  1014. foreach ($list as &$item) {
  1015. $size = $item['尺码'];
  1016. $item[$size] = $item['数量']; // 动态添加尺码字段,值为数量
  1017. // unset($item['数量']); // 移除原来的已完成字段
  1018. }
  1019. $data['total'] = count($list);
  1020. $data['table'] = $list;
  1021. $this->success('成功',$data);
  1022. }
  1023. /**
  1024. *
  1025. */
  1026. // public function WastageList(){
  1027. // }
  1028. /**
  1029. *
  1030. */
  1031. // public function getAnnexTable(){
  1032. // }
  1033. /**
  1034. *
  1035. */
  1036. // public function annexAdd(){
  1037. // }
  1038. /**
  1039. *
  1040. */
  1041. // public function annexDel(){
  1042. // }
  1043. /**
  1044. *
  1045. */
  1046. // public function getGdAnnexTable(){
  1047. // }
  1048. /**
  1049. * 产品附件新增
  1050. * 1.前端进行上传xlsx文件表格
  1051. * 2.接口接受数据文件进行保存xlsx文件以及pdf转换
  1052. * 3.前端进行预览pdf图片显示文件中的内容再页面上
  1053. */
  1054. public function gdAnnexAdd() {
  1055. ini_set('display_errors', 'On');
  1056. ini_set('error_reporting', E_ALL);
  1057. if (!$this->request->isPost()) {
  1058. $this->error('请求方式错误');
  1059. }
  1060. // 获取请求参数
  1061. $req = $this->request->param();
  1062. $relateId = $req['关联编号'];
  1063. $attachmentContent = $req['附件内容'];
  1064. $attachmentType = $req['附件类型'];
  1065. $prefixDir = ROOT_PATH . '/public/';
  1066. $uploadDir = ''.'uploads/' . date('Ymd') . '/' . $relateId;
  1067. DB::name('工单_基本资料')
  1068. ->where('订单编号', $relateId)
  1069. ->update(['gd_statu' => '2-生产中']);
  1070. // 检查并创建目录
  1071. if (!is_dir($prefixDir . $uploadDir)) {
  1072. mkdir($prefixDir . $uploadDir, 0777, true);
  1073. }
  1074. // 处理 Base64 附件内容
  1075. if (strpos($attachmentContent, 'base64,') !== false) {
  1076. $attachmentContent = explode('base64,', $attachmentContent)[1];
  1077. }
  1078. $fileContent = base64_decode($attachmentContent);
  1079. $filename = time();
  1080. // 初始化文件路径变量
  1081. $xlsxFilePath = '';
  1082. $pdfFilePath = '';
  1083. if ($attachmentType === 'pdf') {
  1084. // 保存 PDF 文件
  1085. $pdfFilePath = $uploadDir . '/' . $filename . '.pdf';
  1086. file_put_contents($prefixDir . $pdfFilePath, $fileContent);
  1087. } elseif ($attachmentType === 'xlsx') {
  1088. // 保存 Excel 文件
  1089. $xlsxFilePath = $uploadDir . '/' . $filename . '.xlsx';
  1090. file_put_contents($prefixDir . $xlsxFilePath, $fileContent);
  1091. // 转换为 PDF 文件
  1092. $pdfFilePath = $uploadDir . '/' . $filename . '.pdf';
  1093. $cmd = sprintf(
  1094. 'libreoffice --headless --convert-to pdf --outdir %s %s',
  1095. escapeshellarg($prefixDir . $uploadDir),
  1096. escapeshellarg($prefixDir . $xlsxFilePath)
  1097. );
  1098. exec($cmd, $out, $retval);
  1099. if ($retval !== 0) {
  1100. $this->error('Excel 转 PDF 失败');
  1101. }
  1102. } else {
  1103. $this->error('不支持的附件类型');
  1104. }
  1105. // 组织数据
  1106. $data = [
  1107. '关联编号' => $relateId,
  1108. 'sys_id' => $req['sys_id'],
  1109. '附件备注' => $req['附件备注'],
  1110. '附件类型' => $attachmentType,
  1111. 'sys_rq' => date('Y-m-d H:i:s'),
  1112. 'url' => $xlsxFilePath, // 保存 xlsx 文件路径(如果存在)
  1113. 'pdf' => $pdfFilePath // 保存 pdf 文件路径
  1114. ];
  1115. // 数据库事务处理
  1116. db()->startTrans();
  1117. try {
  1118. // 插入数据
  1119. $sql = db('工单_相关附件')->fetchSql(true)->insert($data);
  1120. $result = db()->query($sql);
  1121. db()->commit();
  1122. } catch (\Exception $e) {
  1123. // 回滚事务
  1124. db()->rollback();
  1125. $this->error($e->getMessage());
  1126. }
  1127. if ($result === false) {
  1128. $this->error('失败');
  1129. }
  1130. $this->success('成功');
  1131. }
  1132. /**
  1133. *
  1134. */
  1135. // public function gdAnnexDel()
  1136. // {
  1137. // }
  1138. /**
  1139. *
  1140. */
  1141. // public function WorkOrderDetailCope()
  1142. // {
  1143. // }
  1144. //
  1145. /**
  1146. *
  1147. */
  1148. // public function WorkOrderDetailListCope()
  1149. // {
  1150. // }
  1151. /**
  1152. *
  1153. */
  1154. // public function ProductCopeDetail()
  1155. // {
  1156. // }
  1157. /**
  1158. *
  1159. */
  1160. // public function PlannedProcessYield($workOrder,$yjno,$gxh,$feed)
  1161. // {
  1162. // }
  1163. /**
  1164. *
  1165. */
  1166. // public function WorkOrderDel()
  1167. // {
  1168. // }
  1169. /**
  1170. *
  1171. */
  1172. // public function ProductNameData()
  1173. // {
  1174. // }
  1175. /**
  1176. *
  1177. */
  1178. // public function getCouplet()
  1179. // }
  1180. /**
  1181. * 订单打印接口
  1182. * order:订单编号
  1183. * 通过订单编号获取订单表数据以及子订单数据
  1184. */
  1185. public function orderPrint(){
  1186. if ($this->request->isGet() === false){$this->error('请求错误');}
  1187. $param = $this->request->param();
  1188. if (empty($param['order'])){$this->error('参数错误');}
  1189. $where['Mod_rq'] = null;
  1190. //订单信息
  1191. $list = \db('工单_基本资料')
  1192. ->where('订单编号',$param['order'])
  1193. ->where($where)
  1194. ->field('订单编号,img,生产款号,客户编号,款式,落货日期,箱唛要求,面料,船样描述,船样合计,粘衬,订单数量,审核,审核日期,要求,water')
  1195. ->find();
  1196. //尺码表格表头
  1197. $xhdata = \db('工单_印件资料')->where('订单编号', $param['order'])->where($where)->select();
  1198. $arr = [];
  1199. foreach ($xhdata as $key => $value) {
  1200. for ($i = 1; $i <= 10; $i++) {
  1201. if ($value['cm' . $i] !== '' && $value['cm' . $i] !== null) {
  1202. array_push($arr, $value['cm' . $i]);
  1203. }
  1204. }
  1205. }
  1206. // 去重并重新索引
  1207. $arr = array_unique($arr);
  1208. $arr = array_values($arr);
  1209. // 自定义排序函数
  1210. usort($arr, function($a, $b) {
  1211. // 判断是否为数字
  1212. $isNumericA = is_numeric($a);
  1213. $isNumericB = is_numeric($b);
  1214. if ($isNumericA && $isNumericB) {
  1215. // 如果都是数字,按从小到大排序
  1216. return $a - $b;
  1217. } elseif (!$isNumericA && !$isNumericB) {
  1218. // 如果都是字母,按字母顺序排序(可以自定义顺序)
  1219. $sizeOrder = ['XXS', 'XS', 'S', 'M', 'L', 'XL', 'XXL', 'XXXL','XXXXL'];
  1220. $posA = array_search($a, $sizeOrder);
  1221. $posB = array_search($b, $sizeOrder);
  1222. return $posA - $posB;
  1223. } else {
  1224. // 如果一个是数字一个是字母,数字排在前
  1225. return $isNumericA ? -1 : 1;
  1226. }
  1227. });
  1228. //打印table数据表格
  1229. $porlis = \db('工单_印件资料')
  1230. ->where('订单编号',$param['order'])
  1231. ->where('船样',0)
  1232. ->where($where)
  1233. ->field('子订单编号')
  1234. ->select();
  1235. //合并后的子订单条码数据
  1236. $subOrder = $porlis[0]['子订单编号'];
  1237. // 找到子订单编号中的 '-' 位置
  1238. $dashPos = strpos($subOrder, '-');
  1239. if ($dashPos !== false) {
  1240. // 提取 '-' 后面的部分
  1241. $afterDash = substr($subOrder, $dashPos + 1);
  1242. // 判断长度是否等于2或等于4
  1243. if (strlen($afterDash) == 2) {
  1244. // 查询船样为0的数据
  1245. $processlist = \db('工单_印件资料')
  1246. ->where('订单编号', $param['order'])
  1247. ->where($where)
  1248. ->where('船样', 0)
  1249. ->field('子订单编号,颜色,款号,zdtotal,颜色备注,color_id,
  1250. cm1,cm2,cm3,cm4,cm5,cm6,cm7,cm8,cm9,cm10,
  1251. cmsl1,cmsl2,cmsl3,cmsl4,cmsl5,cmsl6,cmsl7,cmsl8,cmsl9,cmsl10,Uniqid')
  1252. ->select();
  1253. // 初始化汇总数组
  1254. $scslTotals = [
  1255. "cmsl1" => 0,
  1256. "cmsl2" => 0,
  1257. "cmsl3" => 0,
  1258. "cmsl4" => 0,
  1259. "cmsl5" => 0,
  1260. "cmsl6" => 0,
  1261. "cmsl7" => 0,
  1262. "cmsl8" => 0,
  1263. "cmsl9" => 0,
  1264. "cmsl10" => 0,
  1265. "zdtotal" => 0, // 总计数量
  1266. ];
  1267. // 遍历数据集进行汇总
  1268. foreach ($processlist as $item) {
  1269. // 遍历每个尺码字段(cmsl1 到 cmsl10)
  1270. for ($i = 1; $i <= 10; $i++) {
  1271. // 获取当前字段的数量
  1272. $sizeQty = $item['cmsl' . $i];
  1273. // 判断数量是否有效(非空且大于0)
  1274. if (!empty($sizeQty)) {
  1275. // 累加当前字段的数量
  1276. $scslTotals['cmsl' . $i] += $sizeQty;
  1277. // 累加到总计字段
  1278. $scslTotals['zdtotal'] += $sizeQty;
  1279. }
  1280. }
  1281. }
  1282. $data['scslTotals'] = $scslTotals;
  1283. foreach ($processlist as $key => $value) {
  1284. // 将尺码和对应的数量从 cm1-cm10 和 cmsl1-cmsl10 转换为动态键值对
  1285. for ($i = 1; $i <= 10; $i++) {
  1286. if ($value['cm' . $i] !== '' && $value['cm' . $i] !== null) {
  1287. $processlist[$key][$value['cm' . $i]] = $value['cmsl' . $i];
  1288. }
  1289. // 移除原始的 cm 和 cmsl 字段
  1290. unset($processlist[$key]['cm' . $i], $processlist[$key]['cmsl' . $i]);
  1291. }
  1292. }
  1293. // 用于存储合并后的数据
  1294. $mergedData = [];
  1295. // 按颜色备注进行合并
  1296. foreach ($processlist as $item) {
  1297. $key = $item['颜色备注'];
  1298. if (!isset($mergedData[$key])) {
  1299. $mergedData[$key] = $item;
  1300. // 添加条码字段,值为子订单编号
  1301. $mergedData[$key]['条码'] = $item['子订单编号'];
  1302. } else {
  1303. // 合并尺码对应的数量
  1304. foreach ($item as $size => $quantity) {
  1305. if (is_numeric($size)) {
  1306. if (!isset($mergedData[$key][$size])) {
  1307. $mergedData[$key][$size] = 0;
  1308. }
  1309. $mergedData[$key][$size] += $quantity;
  1310. }
  1311. }
  1312. // 合并 zdtotal
  1313. $mergedData[$key]['zdtotal'] += $item['zdtotal'];
  1314. }
  1315. }
  1316. // 查询船样为1的数据
  1317. $chuanyang = \db('工单_印件资料')
  1318. ->where('订单编号', $param['order'])
  1319. ->where($where)
  1320. ->where('船样', 1)
  1321. ->field('子订单编号,颜色,款号,zdtotal,颜色备注,color_id,
  1322. cm1,cm2,cm3,cm4,cm5,cm6,cm7,cm8,cm9,cm10,
  1323. cmsl1,cmsl2,cmsl3,cmsl4,cmsl5,cmsl6,cmsl7,cmsl8,cmsl9,cmsl10,Uniqid')
  1324. ->select();
  1325. foreach ($chuanyang as $key => $value) {
  1326. // 将尺码和对应的数量从 cm1-cm10 和 cmsl1-cmsl10 转换为动态键值对
  1327. for ($i = 1; $i <= 10; $i++) {
  1328. if ($value['cm' . $i] !== '' && $value['cm' . $i] !== null) {
  1329. $chuanyang[$key][$value['cm' . $i]] = $value['cmsl' . $i];
  1330. }
  1331. // 移除原始的 cm 和 cmsl 字段
  1332. unset($chuanyang[$key]['cm' . $i], $chuanyang[$key]['cmsl' . $i]);
  1333. }
  1334. // 添加条码字段,值为子订单编号
  1335. $chuanyang[$key]['条码'] = $value['子订单编号'];
  1336. }
  1337. // 将合并后的数据插入到相应颜色备注的原始数据尾部
  1338. $finalList = [];
  1339. $groupedData = [];
  1340. // 将原始数据按颜色备注分组
  1341. foreach ($processlist as $item) {
  1342. $key = $item['颜色备注'];
  1343. if (!isset($groupedData[$key])) {
  1344. $groupedData[$key] = [];
  1345. }
  1346. $groupedData[$key][] = $item;
  1347. }
  1348. // 将合并后的数据插入到对应的颜色备注组的尾部
  1349. foreach ($groupedData as $key => $items) {
  1350. $finalList = array_merge($finalList, $items); // 先添加原始数据
  1351. if (isset($mergedData[$key])) {
  1352. $finalList[] = $mergedData[$key]; // 在组的尾部添加合并数据
  1353. }
  1354. }
  1355. // 将船样为1的数据添加到最终列表中
  1356. $finalList = array_merge($finalList, $chuanyang);
  1357. $data['process'] = $finalList;
  1358. $data['order'] = $list;
  1359. $data['xhdata'] = $arr;
  1360. $this->success('成功',$data);
  1361. } elseif (strlen($afterDash) == 4) {
  1362. //一条子订单编号一个条码,统计颜色
  1363. // $processlist = \db('工单_印件资料')
  1364. // ->where('订单编号', $param['order'])
  1365. // ->whereNull('Mod_rq') // 查询未删除数据
  1366. // ->select();
  1367. //
  1368. // $table = [];
  1369. // foreach ($processlist as $item) {
  1370. // // 当前子订单编号的数据
  1371. // $subOrder = [
  1372. // '颜色备注' => $item['颜色备注'],
  1373. // '色系名称' => $item['颜色'],
  1374. // '订单编号' => $item['订单编号'],
  1375. // '子订单编号' => $item['子订单编号'],
  1376. // '条码' => $item['子订单编号'],
  1377. // '款号' => $item['款号'],
  1378. // ];
  1379. // // 当前子订单编号的合计
  1380. // $subOrderTotal = 0;
  1381. // for ($i = 1; $i <= 10; $i++) {
  1382. // if (!empty($item['cm' . $i])) {
  1383. // $subOrder[$item['cm' . $i]] = $item['cmsl' . $i];
  1384. // // 累加每个尺码的数量
  1385. // $subOrderTotal += $item['cmsl' . $i];
  1386. // }
  1387. // unset($item['cm' . $i], $item['cmsl' . $i]);
  1388. // }
  1389. // $subOrder['合计'] = $subOrderTotal; // 添加合计
  1390. // $table[] = $subOrder; // 将当前子订单的数据添加到 $table 中
  1391. // }
  1392. $processlist = \db('工单_印件资料')
  1393. ->where('订单编号', $param['order'])
  1394. ->whereNull('Mod_rq') // 查询未删除数据
  1395. ->select();
  1396. $table = [];
  1397. foreach ($processlist as $item) {
  1398. // 当前子订单编号的数据
  1399. $subOrder = [
  1400. '颜色备注' => $item['颜色备注'],
  1401. '色系名称' => $item['颜色'],
  1402. '订单编号' => $item['订单编号'],
  1403. '子订单编号' => $item['子订单编号'],
  1404. '条码' => $item['子订单编号'],
  1405. '款号' => $item['款号'],
  1406. ];
  1407. // 当前子订单编号的合计
  1408. $subOrderTotal = 0;
  1409. for ($i = 1; $i <= 10; $i++) {
  1410. // 判断 cm 和 cmsl 是否有值,空值不显示,0 则显示
  1411. if (isset($item['cm' . $i]) && $item['cm' . $i] !== '') {
  1412. $subOrder[$item['cm' . $i]] = $item['cmsl' . $i] ?? 0; // 默认数量为 0
  1413. // 累加每个尺码的数量
  1414. $subOrderTotal += (int)$item['cmsl' . $i]; // 确保是数值类型
  1415. }
  1416. // 清理字段
  1417. unset($item['cm' . $i], $item['cmsl' . $i]);
  1418. }
  1419. $subOrder['合计'] = $subOrderTotal; // 添加合计
  1420. $table[] = $subOrder; // 将当前子订单的数据添加到 $table 中
  1421. }
  1422. // 初始化汇总数组
  1423. $scslTotals = [
  1424. "cmsl1" => 0,
  1425. "cmsl2" => 0,
  1426. "cmsl3" => 0,
  1427. "cmsl4" => 0,
  1428. "cmsl5" => 0,
  1429. "cmsl6" => 0,
  1430. "cmsl7" => 0,
  1431. "cmsl8" => 0,
  1432. "cmsl9" => 0,
  1433. "cmsl10" => 0,
  1434. "zdtotal" => 0, // 总计数量
  1435. ];
  1436. // 遍历数据集进行汇总
  1437. foreach ($processlist as $item) {
  1438. // 遍历每个尺码字段(cmsl1 到 cmsl10)
  1439. for ($i = 1; $i <= 10; $i++) {
  1440. // 获取当前字段的数量
  1441. $sizeQty = $item['cmsl' . $i];
  1442. // 判断数量是否有效(非空且大于0)
  1443. if (!empty($sizeQty)) {
  1444. // 累加当前字段的数量
  1445. $scslTotals['cmsl' . $i] += $sizeQty;
  1446. // 累加到总计字段
  1447. $scslTotals['zdtotal'] += $sizeQty;
  1448. }
  1449. }
  1450. }
  1451. $data['scslTotals'] = $scslTotals;
  1452. $data['process'] = $table;//汇总数据集
  1453. $data['order'] = $list;//表格数据
  1454. $data['xhdata'] = $arr;//尺码表头
  1455. $this->success('成功', $data);
  1456. // }
  1457. } else {
  1458. echo "子订单编号 - 后不是2位也不是4位:$afterDash";
  1459. }
  1460. } else {
  1461. echo "子订单编号中没有找到'-'";
  1462. }
  1463. }
  1464. /**
  1465. * 订单编号自动获取
  1466. * @return void
  1467. * @throws \think\db\exception\DataNotFoundException
  1468. * @throws \think\db\exception\ModelNotFoundException
  1469. * @throws \think\exception\DbException
  1470. */
  1471. public function getWorkOrder()
  1472. {
  1473. if ($this->request->isGet() === false){
  1474. $this->error('请求错误');
  1475. }
  1476. $time =substr( date('Ym',time()),2);
  1477. $lastOrder = \db('工单_基本资料')
  1478. ->where('订单编号','like','%'.$time.'%')
  1479. ->order('Uniqid desc')
  1480. ->find();
  1481. if (empty($lastOrder)){
  1482. $newNumber = 1;
  1483. }else{
  1484. $lastNumber = substr($lastOrder['订单编号'],6);
  1485. $newNumber = (int)$lastNumber + 1;
  1486. }
  1487. if ($newNumber<10){
  1488. $newOrder = 'DC'.$time.'00'.$newNumber;
  1489. }elseif ($newNumber>=10 && $newNumber<100){
  1490. $newOrder = 'DC'.$time.'0'.$newNumber;
  1491. }else{
  1492. $newOrder = 'DC'.$time.$newNumber;
  1493. }
  1494. $this->success('成功',$newOrder);
  1495. }
  1496. /**
  1497. * 获取子订单编号
  1498. * @return void
  1499. * @throws \think\db\exception\DataNotFoundException
  1500. * @throws \think\db\exception\ModelNotFoundException
  1501. * @throws \think\exception\DbException
  1502. */
  1503. public function getSuborder(){
  1504. // 确保是GET请求
  1505. if ($this->request->isGet() === false) {
  1506. $this->error('请求错误');
  1507. }
  1508. $param = $this->request->param();
  1509. if (empty($param) || !isset($param['cy']) || !isset($param['order'])) {
  1510. $this->error('参数错误');
  1511. }
  1512. // 判断是否“船样”获取对应的子订单编号
  1513. if ($param['cy'] == '否') {
  1514. //1.通过色系名称查询对应的编号
  1515. $colorlist = \db('工单_颜色编号')
  1516. ->field('colorcode, colorname')
  1517. ->where('colorname', $param['colorname'] ?? '')
  1518. ->find();
  1519. if (empty($colorlist)) {
  1520. $this->error('未找到对应的颜色编号');
  1521. }
  1522. $num = $param['order'] . '-' . $colorlist['colorcode'];
  1523. // 查询子订单编号
  1524. $data = \db('工单_印件资料')
  1525. ->field('子订单编号,cm1,cm2,cm3,cm4,cm5,cm6,cm7,cm8,cm9,cm10')
  1526. ->where('子订单编号', 'like', '%' . $num . '%')
  1527. ->where('船样', '=', 0)
  1528. ->order('子订单编号', 'desc')
  1529. ->find();
  1530. if (empty($data)) {
  1531. // 如果没有找到数据,生成默认的订单编号,后两位从00开始
  1532. $order = $param['order'] . '-' . $colorlist['colorcode'] . '00';
  1533. } else {
  1534. if (strlen($data['子订单编号']) == 12) {
  1535. $data = \db('工单_印件资料')
  1536. ->where('订单编号',$param['order'])
  1537. ->where('船样',0)
  1538. ->order('子订单编号 desc')
  1539. ->find();
  1540. if(empty($data)){
  1541. $order = $param['order'].'-01';
  1542. }else{
  1543. $num = (int)substr($data['子订单编号'],10) + 1;
  1544. if ($num<10){
  1545. $order = $param['order'].'-0'.$num;
  1546. }else{
  1547. $order = $param['order'].'-'.$num;
  1548. }
  1549. }
  1550. }else{
  1551. // 如果找到数据,提取子订单编号并递增
  1552. $order = $data['子订单编号'];
  1553. if (preg_match('/(.*-' . $colorlist['colorcode'] . ')(\d{2})$/', $order, $matches)) {
  1554. $prefix = $matches[1]; // 前缀部分(包括订单编号和颜色代码)
  1555. $number = $matches[2]; // 数字部分(后两位)
  1556. // 循环生成子订单编号并检查数据库中是否存在相同编号
  1557. do {
  1558. $incrementedNumber = (int)$number + 1;
  1559. // 将数字部分补充为两位数,例如 1 -> 01,2 -> 02
  1560. $order = $prefix . str_pad($incrementedNumber, 2, '0', STR_PAD_LEFT);
  1561. $exists = \db('工单_印件资料')->where('子订单编号', '=', $order)->find();
  1562. $number = $incrementedNumber; // 更新 number 用于下一次循环
  1563. } while ($exists); // 如果存在相同编号则继续循环递增
  1564. } else {
  1565. $this->error('订单编号格式错误');
  1566. }
  1567. }
  1568. }
  1569. //2.获取色系名称信息
  1570. $colorlist = \db('工单_颜色编号')->select();
  1571. //3.获取历史尺码数据
  1572. $cm_list = \db('工单_印件资料')
  1573. ->where('订单编号', $param['order'])
  1574. ->group('订单编号')
  1575. ->find();
  1576. $cm_data = [];
  1577. if ($cm_list) {
  1578. // 精准筛选字段名以 "cm" 开头并跟1到2位数字的字段
  1579. foreach ($cm_list as $key => $value) {
  1580. if (preg_match('/^cm\d{1,2}$/', $key)) {
  1581. $cm_data[$key] = $value ?? ''; // 如果值为 null,设为空字符串
  1582. }
  1583. }
  1584. } else {
  1585. // 如果查询结果为空,将 cm1 到 cm10 都设置为空
  1586. for ($i = 1; $i <= 10; $i++) {
  1587. $cm_data["cm$i"] = '';
  1588. }
  1589. }
  1590. $result = ['order' => $order,'colorlist' => $colorlist,'cm' => $cm_data];
  1591. $this->success('成功', $result);
  1592. } else if ($param['cy'] == '是') {
  1593. //1.获取船样子订单编号
  1594. $data = \db('工单_印件资料')
  1595. ->where('订单编号', $param['order'])
  1596. ->where('船样', '=', 1)
  1597. ->order('子订单编号 asc')
  1598. ->find();
  1599. if (empty($data)) {
  1600. // 如果没有数据,初始子订单编号为 '99'
  1601. $order = $param['order'] . '-99';
  1602. } else {
  1603. // 提取子订单编号中的数字部分
  1604. $subOrder = $data['子订单编号']; // 例如 "DC2410006-99"
  1605. if (preg_match('/-(\d+)$/', $subOrder, $matches)) {
  1606. $numberPart = (int)$matches[1]; // 提取到的数字部分
  1607. $newNumber = $numberPart - 1; // 减 1
  1608. // 将新的数字拼接回订单编号
  1609. $order = preg_replace('/-\d+$/', '-' . $newNumber, $subOrder);
  1610. } else {
  1611. $this->error('订单编号格式错误');
  1612. }
  1613. }
  1614. $this->success('成功', $order);
  1615. }
  1616. }
  1617. /**
  1618. * 获取PO号 【代码展示未用到】
  1619. */
  1620. public function getPonumber() {
  1621. if ($this->request->isGet() === false){
  1622. $this->error('请求错误');
  1623. }
  1624. $param = $this->request->param();
  1625. if (empty($param)){
  1626. $this->error('参数错误');
  1627. }
  1628. // $num = substr($param['child_order'], 0, 12); // 如果需要,可以用这个方式截取子订单编号
  1629. // $sql = "SELECT * FROM `工单_印件资料` WHERE `子订单编号` LIKE '{$num}%' ORDER BY `子订单编号` DESC LIMIT 1";
  1630. // $data = \db()->query($sql);
  1631. $colorlist = \db('工单_颜色编号')
  1632. ->field('colorcode,colorname')
  1633. ->where('colorname',$param['child_order'])
  1634. ->find();
  1635. $num = $param['order'] . '-' . $colorlist['colorcode']; // 生成 num,用于模糊查询
  1636. $data = \db('工单_印件资料')
  1637. ->where('子订单编号', 'like', '%' . $num . '%')
  1638. ->order('子订单编号', 'desc')
  1639. ->find();
  1640. if(count($data) === 1){
  1641. $order = $num.'01';
  1642. }else{
  1643. $number = (int)substr($data['子订单编号'],12,14) + 1;
  1644. if ($num<10){
  1645. $order = $num.'0'.$number;
  1646. }else{
  1647. $order = $num.$number;
  1648. }
  1649. }
  1650. $this->success('成功',$order);
  1651. }
  1652. /**
  1653. * 订单资料修改
  1654. * @return void
  1655. * @throws \think\Exception
  1656. * @throws \think\db\exception\BindParamException
  1657. * @throws \think\exception\PDOException
  1658. */
  1659. public function WorkOrderEdit()
  1660. {
  1661. if (Request::instance()->isPost() === false){
  1662. $this->error('请求错误');
  1663. }
  1664. $param = Request::instance()->post();
  1665. if (empty($param)){
  1666. $this->error('参数错误');
  1667. }
  1668. $id = $param['id'];
  1669. unset($param['id']);
  1670. $sql = \db('工单_基本资料')
  1671. ->where('Uniqid',$id)
  1672. ->fetchSql(true)
  1673. ->update($param);
  1674. $res = \db()->query($sql);
  1675. if ($res === false){
  1676. $this->error('失败');
  1677. }else{
  1678. $this->success('成功');
  1679. }
  1680. }
  1681. /**
  1682. * 颜色资料修改
  1683. * @return void
  1684. * @throws \think\Exception
  1685. * @throws \think\db\exception\BindParamException
  1686. * @throws \think\exception\PDOException
  1687. */
  1688. public function PrintDataEdit()
  1689. {
  1690. if(Request::instance()->post() === false){
  1691. $this->error('请求错误');
  1692. }
  1693. $param = Request::instance()->post();
  1694. if (empty($param)){
  1695. $this->error('参数错误');
  1696. }
  1697. // $id = $param['id'];
  1698. // unset($param['id']);
  1699. // $findlist = \db('工单_印件资料')
  1700. // ->where('Uniqid', $param['id'])
  1701. // ->find();
  1702. $updata = [
  1703. '订单编号' => $param['订单编号'],
  1704. '子订单编号' => $param['子订单编号'],
  1705. '款号' => $param['款号'],
  1706. '船样' => $param['船样'],
  1707. '颜色' => $param['颜色'],
  1708. 'color_id' => $param['color_id'],
  1709. '颜色备注' => $param['颜色备注'],
  1710. 'zdtotal' => $param['zdtotal']
  1711. ];
  1712. for ($i = 1; $i <= 10; $i++) {
  1713. $updata["cmsl{$i}"] = isset($param["cmsl{$i}"]) ? $param["cmsl{$i}"] : '';
  1714. }
  1715. $sql = \db('工单_印件资料')
  1716. ->where('Uniqid', $param['id'])
  1717. ->fetchSql(true)
  1718. ->update($updata);
  1719. $res = \db()->query($sql);
  1720. if ($res !== false) {
  1721. $this->success('修改成功');
  1722. } else {
  1723. $this->error('修改失败');
  1724. }
  1725. }
  1726. /**
  1727. * 图片上传
  1728. * @return void
  1729. */
  1730. public function ImgUpload(){
  1731. $file = request()->file('image');
  1732. if($file){
  1733. $info = $file->validate(['size'=>10485760,'ext'=>'jpg,png'])->move(ROOT_PATH . 'public' . DS . 'uploads');
  1734. if($info){
  1735. $fileName = $info->getSaveName();
  1736. // $ymd = date('Ymd');
  1737. // $imageUrl = '/uploads/' . $ymd.'/'.$fileName;
  1738. $imageUrl = '/uploads/' . str_replace('\\', '/', $fileName);
  1739. return json(['code' => 0, 'msg' => '成功', 'data' => ['url' => $imageUrl]]);
  1740. }else{
  1741. $res = $file->getError();
  1742. return json(['code' => 1, 'msg' => '失败', 'data' => $res]);
  1743. }
  1744. }
  1745. return json(['code' => 1, 'msg' => '没有文件上传', 'data' => null]);
  1746. }
  1747. /**
  1748. * 工单技术附件
  1749. * @return void
  1750. * @throws \think\db\exception\DataNotFoundException
  1751. * @throws \think\db\exception\ModelNotFoundException
  1752. * @throws \think\exception\DbException
  1753. */
  1754. public function OrderAttachments()
  1755. {
  1756. if ($this->request->isGet() === false){
  1757. $this->error('请求错误');
  1758. }
  1759. $param = $this->request->param();
  1760. if (empty($param)){
  1761. $this->error('参数错误');
  1762. }
  1763. $list = \db('工单_相关附件')
  1764. ->where('关联编号',$param['order'])
  1765. ->where('附件备注',$param['desc'])
  1766. ->whereNull('Mod_rq')
  1767. ->order('sys_rq desc')
  1768. ->limit(1)
  1769. ->select();
  1770. $this->success('成功',$list);
  1771. }
  1772. /**
  1773. * 订单BOM资料显示
  1774. * @return void
  1775. * @throws \think\db\exception\DataNotFoundException
  1776. * @throws \think\db\exception\ModelNotFoundException
  1777. * @throws \think\exception\DbException
  1778. */
  1779. public function OrderBomList()
  1780. {
  1781. if ($this->request->isGet() === false){
  1782. $this->error('请求错误');
  1783. }
  1784. $param = $this->request->param();
  1785. if (empty($param) || !isset($param['order'])){
  1786. $this->error('参数错误');
  1787. }
  1788. $where = ['a.BOM_工单编号'=>$param['order']];
  1789. $list = \db('工单_bom资料')
  1790. ->alias('a')
  1791. ->join('工单_基本资料 b','b.订单编号 = a.BOM_工单编号')
  1792. ->field('a.BOM_工单编号 as 订单编号,b.生产款号 as 生产款号,b.客户编号 as 客户编号,b.款式 as 款式,
  1793. a.BOM_物料名称 as 物料名称,a.BOM_投料单位 as 投料单位,a.BOM_计划用量 as 计划用料,a.BOM_标准用量 as 定额用料,
  1794. a.BOM_实际用量 as 裁床实际用料,a.BOM_领用数量 as 裁床领用面料,a.BOM_退还数量 as 裁床退回仓库面料,
  1795. a.BOM_desc as 备注,a.UNIQID,a.BOM_库存总量 as 入库总量,a.BOM_门封 as 门封,a.BOM_面料结余 as 面料结余,a.Sys_ID as ID,a.Sys_rq as 日期')
  1796. ->where($where)
  1797. ->select();
  1798. if (!empty($list)){
  1799. $this->success('成功',$list);
  1800. }
  1801. }
  1802. /**
  1803. * 订单面料修改接口
  1804. * @return void
  1805. * @throws \think\Exception
  1806. * @throws \think\db\exception\BindParamException
  1807. * @throws \think\exception\PDOException
  1808. */
  1809. public function FabricEdit()
  1810. {
  1811. if ($this->request->isPost() === false){
  1812. $this->error('请求错误');
  1813. }
  1814. $param = Request::instance()->post();
  1815. if (empty($param)){
  1816. $this->error('请求错误');
  1817. }
  1818. foreach ($param as $key=>$value){
  1819. $data = $value;
  1820. unset($data['UNIQID']);
  1821. if ($value['UNIQID'] !== '' || !empty($value['UNIQID'])){
  1822. $sql = \db('工单_bom资料')
  1823. ->where('UNIQID',$value['UNIQID'])
  1824. ->fetchSql(true)
  1825. ->update($data);
  1826. $res = \db()->query($sql);
  1827. }else{
  1828. $sql = \db('工单_bom资料')
  1829. ->fetchSql(true)
  1830. ->insert($value);
  1831. $res = \db()->query($sql);
  1832. }
  1833. if ($res === false){
  1834. $this->error('修改失败');
  1835. }
  1836. }
  1837. $this->success('修改成功');
  1838. }
  1839. /**
  1840. * 订单BOM出库、退还详情显示
  1841. * @return void
  1842. * @throws \think\db\exception\DataNotFoundException
  1843. * @throws \think\db\exception\ModelNotFoundException
  1844. * @throws \think\exception\DbException
  1845. */
  1846. public function FabricDetail()
  1847. {
  1848. if ($this->request->isGet() === false){
  1849. $this->error('请求错误');
  1850. }
  1851. $param = $this->request->param();
  1852. if (empty($param) || !isset($param['order'])){
  1853. $this->error('参数错误');
  1854. }
  1855. if (isset($param['searchh']) || !empty($param['search'])){
  1856. $list['入库记录'] = \db('设备_报工日志')
  1857. ->where('order_id|款号',$param['order'])
  1858. ->where('name','入库')
  1859. ->field('order_id as 订单编号,款号,number as 数量,rq as 入库时间,sys_id as 上报机台,recipient as 入仓人员')
  1860. ->order('入库时间 desc')
  1861. ->select();
  1862. }else{
  1863. //出库记录查询
  1864. $list['出库记录'] = \db('设备_报工日志')
  1865. ->where('order_id|款号',$param['order'])
  1866. ->where('name','出库')
  1867. ->field('order_id as 订单编号,款号,number as 数量,rq as 出库时间,sys_id as 上报机台,receipt_number as 出库单据编号,recipient as 出库人员')
  1868. ->order('出库时间 desc')
  1869. ->select();
  1870. //退还记录查询
  1871. $list['退还记录'] = \db('设备_报工日志')
  1872. ->where('order_id|款号',$param['order'])
  1873. ->where('name','退还')
  1874. ->field('order_id as 订单编号,款号,number as 数量,rq as 退还时间,sys_id as 上报机台,recipient as 退还人员')
  1875. ->order('退还时间 desc')
  1876. ->select();
  1877. }
  1878. $this->success('成功',$list);
  1879. }
  1880. //GPT
  1881. public function Gpt($massage)
  1882. {
  1883. // 设置 API 密钥
  1884. $apiKey = 'sk-e0JuPjMntkbgi1BoMjrqyyzMKzAxILkQzyGMSy3xiMupuoWY'; // 替换为您的 API 密钥
  1885. // 要发送给 GPT 的消息
  1886. $messages = [
  1887. [
  1888. 'role' => 'user',
  1889. 'content' => '你好,帮我按照:面料1、面料2、面料3……来整理归纳下面的面料信息,我只需要面料信息,不需要其他:'.$massage
  1890. ]
  1891. ];
  1892. // 创建请求数据
  1893. $data = [
  1894. 'model' => 'gpt-3.5-turbo', // 使用的模型
  1895. 'messages' => $messages,
  1896. 'max_tokens' => 100, // 设置最大 token 数
  1897. ];
  1898. // 初始化 cURL
  1899. $ch = curl_init('https://niubi.zeabur.app/v1/chat/completions');
  1900. // 设置 cURL 选项
  1901. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1902. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  1903. 'Content-Type: application/json',
  1904. 'Authorization: Bearer ' . $apiKey,
  1905. ]);
  1906. curl_setopt($ch, CURLOPT_POST, true);
  1907. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
  1908. curl_setopt($ch, CURLOPT_CAINFO, ROOT_PATH . '/public/uploads/cacert.pem');
  1909. // 执行请求
  1910. $response = curl_exec($ch);
  1911. // 检查错误
  1912. if (curl_errno($ch)) {
  1913. echo 'Error:' . curl_error($ch);
  1914. }
  1915. // 关闭 cURL
  1916. curl_close($ch);
  1917. // 解析和输出响应
  1918. $responseData = json_decode($response, true);
  1919. // 获取 GPT 的回复
  1920. if (isset($responseData['choices'][0]['message']['content'])) {
  1921. //获取返回内容
  1922. $gptReply = $responseData['choices'][0]['message']['content'];
  1923. // halt($gptReply);
  1924. //返回面料信息
  1925. $gptArray = explode('面料',$gptReply);
  1926. array_shift($gptArray);
  1927. foreach ($gptArray as $key=>$value){
  1928. $gptArray[$key] = preg_replace('/\s+/', '', substr($value,4));
  1929. }
  1930. return $gptArray;
  1931. } else {
  1932. echo "未能获取 GPT 的回复。";
  1933. }
  1934. }
  1935. /**
  1936. * 面料库存
  1937. * @return void
  1938. * @throws \think\db\exception\DataNotFoundException
  1939. * @throws \think\db\exception\ModelNotFoundException
  1940. * @throws \think\exception\DbException
  1941. */
  1942. public function fabricList()
  1943. {
  1944. if ($this->request->isGet() === false){
  1945. $this->error('请求错误');
  1946. }
  1947. $param = $this->request->param();
  1948. $where = [];
  1949. if (isset($param['order'])){
  1950. $where = ['a.BOM_工单编号'=>$param['order']];
  1951. }
  1952. if (isset($param['mouth'])){
  1953. $where = ['a.Sys_rq'=>['like',$param['mouth'].'%']];
  1954. }
  1955. $list = \db('工单_bom资料')
  1956. ->alias('a')
  1957. ->join('工单_基本资料 b','b.订单编号 = a.BOM_工单编号')
  1958. ->field('a.BOM_工单编号 as 订单编号,b.生产款号 as 生产款号,b.客户编号 as 客户编号,b.款式 as 款式,
  1959. a.BOM_物料名称 as 物料名称,a.BOM_投料单位 as 投料单位,a.BOM_库存总量 as 库存总量,a.BOM_面料结余 as 面料结余,
  1960. a.UNIQID')
  1961. ->where($where)
  1962. ->select();
  1963. if (!empty($list)){
  1964. $this->success('成功',$list);
  1965. }
  1966. }
  1967. /**
  1968. * 单条面料详情
  1969. * @return void
  1970. * @throws \think\db\exception\DataNotFoundException
  1971. * @throws \think\db\exception\ModelNotFoundException
  1972. * @throws \think\exception\DbException
  1973. */
  1974. public function oneFabricDetail()
  1975. {
  1976. if ($this->request->isGet() === false){
  1977. $this->error('请求错误');
  1978. }
  1979. $param = $this->request->param();
  1980. if (empty($param)){
  1981. $this->error('参数错误');
  1982. }
  1983. //面料入库记录
  1984. $list['入库'] = \db('设备_报工日志')
  1985. ->where('order_id',$param['order'])
  1986. ->where('物料名称',$param['fabricName'])
  1987. ->where('name','入库')
  1988. ->field('order_id as 订单编号,款号,物料名称,number as 数量,rq as 日期,sys_id as 操作机台,recipient as 入仓人员')
  1989. ->select();
  1990. //面料出库记录
  1991. $list['出库'] = \db('设备_报工日志')
  1992. ->where('order_id',$param['order'])
  1993. ->where('物料名称',$param['fabricName'])
  1994. ->where('name','出库')
  1995. ->field('order_id as 订单编号,款号,物料名称,number as 数量,rq as 日期,sys_id as 操作机台,receipt_number as 出库单据编号,recipient as 领用人员')
  1996. ->select();
  1997. //面料退还记录
  1998. $list['退还'] = \db('设备_报工日志')
  1999. ->where('order_id',$param['order'])
  2000. ->where('物料名称',$param['fabricName'])
  2001. ->where('name','退还')
  2002. ->field('order_id as 订单编号,款号,物料名称,number as 数量,rq as 日期,sys_id as 操作机台,recipient as 退还人员')
  2003. ->select();
  2004. $this->success('成功',$list);
  2005. }
  2006. /**
  2007. * 单据号查询数据
  2008. * @return void
  2009. * @throws \think\db\exception\DataNotFoundException
  2010. * @throws \think\db\exception\ModelNotFoundException
  2011. * @throws \think\exception\DbException
  2012. */
  2013. public function ReceiptDetail()
  2014. {
  2015. if ($this->request->isGet() === false){
  2016. $this->error('请求错误');
  2017. }
  2018. $param = $this->request->param();
  2019. if (empty($param)){
  2020. $this->error('参数错误');
  2021. }
  2022. $list = \db('设备_报工日志')
  2023. ->where('receipt_number','like','%',$param['receipt'].'%')
  2024. ->field('order_id as 订单编号,款号,物料名称,number as 数量,rq as 日期,sys_id as 操作机台,receipt_number as 出库单据编号,recipient as 领用人员')
  2025. ->select();
  2026. if (empty($list)){
  2027. $this->error('未找到该出库单');
  2028. }else{
  2029. $this->success('成功',$list);
  2030. }
  2031. }
  2032. /**
  2033. * 出库单列表
  2034. * @return void
  2035. * @throws \think\db\exception\DataNotFoundException
  2036. * @throws \think\db\exception\ModelNotFoundException
  2037. * @throws \think\exception\DbException
  2038. */
  2039. public function ReceiptList()
  2040. {
  2041. if ($this->request->isGet() === false){
  2042. $this->error('请求错误');
  2043. }
  2044. $param = $this->request->param();
  2045. if (empty($param)){
  2046. $this->error('参数错误');
  2047. }
  2048. $list = \db('设备_报工日志')
  2049. ->where('rq','like','%'.$param['mouth'].'%')
  2050. ->field('receipt_number as 出库单,order_id as 订单编号,款号,物料名称,rq as 日期,sys_id as 操作机台,recipient as 领料人员')
  2051. ->group('出库单')
  2052. ->order('rq desc')
  2053. ->select();
  2054. if (empty($list)){
  2055. $this->success('未找到数据');
  2056. }else{
  2057. $this->success('成功',$list);
  2058. }
  2059. }
  2060. /**
  2061. * 出库单左侧菜单
  2062. * @return void
  2063. * @throws \think\db\exception\DataNotFoundException
  2064. * @throws \think\db\exception\ModelNotFoundException
  2065. * @throws \think\exception\DbException
  2066. */
  2067. public function getReceiptTab()
  2068. {
  2069. if ($this->request->isGet() === false){
  2070. $this->error('请求错误');
  2071. }
  2072. $list = \db('设备_报工日志')
  2073. ->field([
  2074. "DATE_FORMAT(rq, '%Y-%m') AS month",
  2075. ])
  2076. ->group('month')
  2077. ->order('month DESC')
  2078. ->select();
  2079. if (empty($list)){
  2080. $this->error('未找到数据');
  2081. }else{
  2082. $this->success('成功',$list);
  2083. }
  2084. }
  2085. /**
  2086. * 获取入库单号、出库单号
  2087. * @return void
  2088. */
  2089. public function gitReceiptNumber()
  2090. {
  2091. if ($this->request->isGet() === false){
  2092. $this->error('请求错误');
  2093. }
  2094. $param = $this->request->param();
  2095. if (empty($param)){
  2096. $this->error('参数错误');
  2097. }
  2098. $lastNumber = \db('设备_报工日志')
  2099. ->where('receipt_number','like',$param['number'].'%')
  2100. ->order('receipt_number desc')
  2101. ->limit(1)
  2102. ->column('receipt_number as 单号');
  2103. if (empty($lastNumber)){
  2104. $num = 1;
  2105. }else{
  2106. $num = (int)(substr($lastNumber[0],12,3))+1;
  2107. }
  2108. if ($num < 10){
  2109. $num = '00'.$num;
  2110. }elseif ($num>=10 && $num<100){
  2111. $num = '0'.$num;
  2112. }else{
  2113. $num;
  2114. }
  2115. $number = $param['number'].date('Ymd',time()).'-'.$num;
  2116. $this->success('成功',$number);
  2117. }
  2118. /**
  2119. * 面料汇总左侧菜单
  2120. * @return void
  2121. * @throws \think\db\exception\DataNotFoundException
  2122. * @throws \think\db\exception\ModelNotFoundException
  2123. * @throws \think\exception\DbException
  2124. */
  2125. public function getFabricTab()
  2126. {
  2127. if ($this->request->isGet() === false){
  2128. $this->error('请求错误');
  2129. }
  2130. $list = \db('工单_bom资料')
  2131. ->field([
  2132. "DATE_FORMAT(Sys_rq, '%Y-%m') AS month",
  2133. ])
  2134. ->group('month')
  2135. ->order('month DESC')
  2136. ->select();
  2137. if (empty($list)){
  2138. $this->error('未找到数据');
  2139. }else{
  2140. $this->success('成功',$list);
  2141. }
  2142. }
  2143. }