WorkOrder.php 88 KB

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