BoxService.php 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129
  1. <?php
  2. namespace App\Service\Box;
  3. use App\Model\Box;
  4. use App\Model\BoxDetail;
  5. use App\Model\DispatchSub;
  6. use App\Model\Header_ext;
  7. use App\Model\OrdersProduct;
  8. use App\Model\OrdersProductBom;
  9. use App\Model\OrdersProductProcess;
  10. use App\Model\SaleOrdersProduct;
  11. use App\Model\Team;
  12. use App\Service\DispatchService;
  13. use App\Service\FinishedOrderService;
  14. use App\Service\FyySqlServerService;
  15. use App\Service\Service;
  16. use Illuminate\Support\Facades\DB;
  17. /**
  18. * 包装相关
  19. * @package App\Models
  20. */
  21. class BoxService extends Service
  22. {
  23. protected static $instance;
  24. protected static $box_header;
  25. protected static $box_detail_header;
  26. protected static $box_hook;
  27. public $lock_key = 'hc_box_add';
  28. public function __construct()
  29. {
  30. self::$box_header = Header_ext::where('type', 'box')->pluck('value', 'key')->toArray();
  31. self::$box_detail_header = Header_ext::where('type', 'box_detail')->pluck('value', 'key')->toArray();
  32. self::$box_hook = BoxHookService::getInstance();
  33. }
  34. /**
  35. * 包装
  36. * @param $data
  37. * @return array
  38. */
  39. public function boxIn($data,$user)
  40. {
  41. $ids = [];
  42. $sale_ids = [];
  43. $top_order_no = $data['order_no'];
  44. $box_no = isset($data['box_no']) ? $data['box_no'] : '';
  45. $transport_no = isset($data['transport_no']) ? $data['transport_no'] : '';
  46. $data = $data['param'];
  47. $key_list = [];
  48. foreach ($data as $v) {
  49. if($v['id'] < 0) $sale_ids[] = -$v['id'];
  50. else $ids[] = $v['id'];
  51. if($v['id'] < 0) $v['id'] = -$v['id'];
  52. $total = 0;
  53. foreach ($v['params'] as $vv) {
  54. $total += $vv;
  55. }
  56. $key_list[$v['id']] = [
  57. 'detail' => $v['params'],
  58. 'total' => $total,
  59. 'team_id' => isset($v['team_id']) ? $v['team_id'] : 0,
  60. ];
  61. }
  62. $insert = [];
  63. //限制频率
  64. $limit_key = $this->lock_key;
  65. list($status,$msg) = $this->limitingSendRequestBackgNeed($limit_key);
  66. if(! $status) return [false, '正在生成包装数据,以及用友数据,请稍后操作!'];
  67. try{
  68. DB::beginTransaction();
  69. //数据获取
  70. $product_list = OrdersProduct::wherein('id', $ids)->get()->toArray();
  71. $flag = "";
  72. foreach ($product_list as $value){
  73. $key = $value['out_order_no'] . $value['product_no'] . $value['technology_name'];
  74. if(! empty($flag)){
  75. if($flag != $key) {
  76. $this->dellimitingSendRequestBackgNeed($limit_key);
  77. return [false , "一次包装只允许包一种产品的一种颜色!"];
  78. }
  79. }else{
  80. $flag = $key;
  81. }
  82. }
  83. $sale_product_list = SaleOrdersProduct::wherein('id', $sale_ids)->get()->toArray();
  84. //生产订单包装----------------
  85. $box_insert = [];
  86. foreach ($product_list as $v) {
  87. $num_list = $key_list[$v['id']];
  88. $total = $num_list['total'];
  89. $detail = $num_list['detail'];
  90. $team_id = $num_list['team_id'];
  91. $un_box_num = bcsub($v['dispatch_complete_quantity'] , $v['box_num'],3);
  92. if ($total > $un_box_num) {
  93. $this->dellimitingSendRequestBackgNeed($limit_key);
  94. return [false, $v['product_title'] . ' ' . $v['technology_name'] . ' 可包装的数量不足'];
  95. }
  96. $ext_1 = $v['product_no'];//产品编号
  97. $ext_2 = $v['technology_material']; //工艺材质 废弃
  98. $ext_3 = $v['technology_name'];//工艺名称 改为颜色
  99. $ext_4 = $v['wood_name'];//木皮 废弃
  100. $ext_5 = $v['process_mark'];//工艺备注 废弃
  101. $ext_8 = $v['product_title'];//产品名称
  102. $out_order_no = $insert['out_order_no'] = $v['out_order_no'];
  103. $top_id = $v['sale_orders_product_id'];
  104. foreach ($detail as $vv){
  105. $box_insert[] = [
  106. 'out_order_no' => $out_order_no,
  107. 'top_id' => $top_id,
  108. 'orders_product_id' => $v['id'],
  109. 'ext_1' => $ext_1,//产品编号
  110. 'ext_2' => $ext_2,
  111. 'ext_3' => $ext_3,//颜色
  112. 'ext_4' => $ext_4,
  113. 'ext_5' => $ext_5,
  114. 'ext_8' => $ext_8,//产品名称
  115. 'num' => $vv,
  116. 'price' => $v['price'],
  117. 'box_type' => 1,
  118. 'team_id' => $team_id,
  119. 'shipment_order_no' => $transport_no,
  120. ];
  121. }
  122. //修改销售订单 生产订单 包装数量
  123. SaleOrdersProduct::where('id',$v['sale_orders_product_id'])->update([
  124. 'box_num' => DB::raw('box_num + '.$total),
  125. ]);
  126. OrdersProduct::where('id',$v['id'])->update([
  127. 'box_num' => DB::raw('box_num + '.$total),
  128. ]);
  129. }
  130. //销售订单包装----------------todo 目前只能按找生产包所以continue
  131. foreach ($sale_product_list as $v) {continue;
  132. $box_type = 0;
  133. if($v['id'] < 0) {
  134. $v['id'] = -$v['id'];
  135. $box_type = 1;
  136. }
  137. $num_list = $key_list[$v['id']];
  138. $total = $num_list['total'];
  139. $detail = $num_list['detail'];
  140. $team_id = $num_list['team_id'];
  141. $box_detail = new BoxDetail(['channel'=>$top_order_no]);
  142. $un_box_num = $v['order_quantity'] - $v['box_num'] - $box_detail->where('top_id',$v['id'])->where('del_time',0)->where('box_type',1)->sum('num');
  143. if ($total > $un_box_num) return [false, $v['product_title'] . '数量不足'];
  144. $ext_1 = $v['product_no'];//产品编号
  145. $ext_2 = $v['technology_material']; //工艺材质 废弃
  146. $ext_3 = $v['technology_name'];//工艺名称 改为颜色
  147. $ext_4 = $v['wood_name'];//木皮 废弃
  148. $ext_5 = $v['process_mark'];//工艺备注 废弃
  149. $ext_8 = $v['product_title'];//产品名称
  150. $out_order_no = $insert['out_order_no'] = $v['out_order_no'];
  151. $top_id = $v['id'];
  152. foreach ($detail as $vv){
  153. $box_insert[] = [
  154. 'out_order_no' => $out_order_no,
  155. 'top_id' => $top_id,
  156. 'orders_product_id' => 0,
  157. 'ext_1' => $ext_1,
  158. 'ext_2' => $ext_2,
  159. 'ext_3' => $ext_3,
  160. 'ext_4' => $ext_4,
  161. 'ext_5' => $ext_5,
  162. 'ext_8' => $ext_8,
  163. 'num' => $vv,
  164. 'price' => $v['price'],
  165. 'box_type' => $box_type,
  166. 'team_id' => $team_id,
  167. 'shipment_order_no' => $transport_no,
  168. ];
  169. }
  170. //修改销售订单 包装数量
  171. SaleOrdersProduct::where('id',$v['id'])->update([
  172. 'box_num' => DB::raw('box_num + '.$total),
  173. ]);
  174. }
  175. //客户名称
  176. $ext_1 = "";
  177. if(empty($ext_1) && isset($sale_product_list[0]['customer_name'])) $ext_1 = $sale_product_list[0]['customer_name'];
  178. if(empty($ext_1) && isset($product_list[0]['customer_name'])) $ext_1 = $product_list[0]['customer_name'];
  179. $insert['ext_1'] = $ext_1;
  180. $insert['detail'] = $box_insert;
  181. $insert['top_order_no'] = $top_order_no;
  182. $insert['order_no'] = $box_no;
  183. $insert['shipment_order_no'] = $transport_no;
  184. list($status,$msg) = self::$box_hook->boxInsert($insert);
  185. if(! $status) {
  186. $this->dellimitingSendRequestBackgNeed($limit_key);
  187. DB::rollBack();
  188. return [false,$msg];
  189. }
  190. //更新完工数量
  191. list($status, $msg1) = $this->updateFinish($product_list,$key_list);
  192. if(! $status) {
  193. $this->dellimitingSendRequestBackgNeed($limit_key);
  194. DB::rollBack();
  195. return [false,$msg1];
  196. }
  197. //用友 ------产成品入库
  198. $package_data = $msg->toArray();
  199. if(! empty($package_data)) {
  200. $service = new FinishedOrderService();
  201. list($status,$msg) = $service->U8Rdrecord10Save($package_data,$user);
  202. if(! $status) {
  203. $this->dellimitingSendRequestBackgNeed($limit_key);
  204. DB::rollBack();
  205. return [false, $msg];
  206. }
  207. }
  208. DB::commit();
  209. $this->dellimitingSendRequestBackgNeed($limit_key);
  210. return [true, ['package_data' => $package_data]];
  211. }catch (\Throwable $e){
  212. DB::rollBack();
  213. $this->dellimitingSendRequestBackgNeed($limit_key);
  214. if (str_contains($e->getMessage(), '1062') || str_contains($e->getMessage(), 'Duplicate entry')) {
  215. return [false, '网络波动,请重新操作!'];
  216. }
  217. return [false,$e->getLine().':'.$e->getMessage()];
  218. }
  219. }
  220. public function delBoxLock(){
  221. $this->dellimitingSendRequestBackgNeed($this->lock_key);
  222. }
  223. public function updateFinish($production_list = [], $map){
  224. if(empty($production_list)) return [true,''];
  225. //组织派工数据
  226. $dispatch = DispatchSub::where('del_time',0)
  227. ->whereIn('order_product_id', array_column($production_list,'id'))
  228. ->get()->toArray();
  229. if(empty($dispatch)) return [true,''];
  230. $dispatch_map = [];
  231. foreach ($dispatch as $value){
  232. $key = $value['order_product_id'] . '|' . $value['crt_time']; //同一次下的派工单
  233. $dispatch_map[$key][] = $value;
  234. }
  235. $result = [];
  236. foreach ($dispatch_map as $value){
  237. $dispatch_quantity = array_sum(array_column($value, 'dispatch_quantity'));
  238. $finished_num = array_sum(array_column($value, 'finished_num'));
  239. if($dispatch_quantity == $finished_num) continue; //同一批派工 且 全部完工的 跳过
  240. foreach ($value as $val){
  241. if($val['dispatch_quantity'] <= $val['finished_num']) continue; //某一个工序完工
  242. //包装数量
  243. $tmp_num = $map[$val['order_product_id']]['total'] ?? 0;
  244. if($tmp_num < 0) continue;
  245. $tmp_num2 = bcsub($val['dispatch_quantity'] , $val['finished_num'],3);
  246. if($tmp_num2 >= $tmp_num){
  247. $val['quantity'] = $tmp_num;
  248. }else{
  249. $val['quantity'] = $tmp_num2;
  250. }
  251. $result[] = $val;
  252. }
  253. }
  254. if(empty($result)) return [true,''];
  255. $time = time();
  256. try {
  257. DB::beginTransaction();
  258. //根据派工数据回写
  259. foreach ($result as $value){
  260. $finished_num = $value['quantity'] + $value['finished_num'];
  261. DispatchSub::where('id',$value['id'])->update([
  262. 'finished_num' => $finished_num
  263. ]);
  264. $quantity = $value['quantity'] * 1000;
  265. //工序表
  266. $process_model = new OrdersProductProcess(['channel' => date("Ymd",$value['out_order_no_time'])]);
  267. $process_model->where('order_product_id',$value['order_product_id'])
  268. ->where('process_id',$value['process_id'])
  269. ->where('dispatch_no',$value['dispatch_no'])
  270. ->where('status', 1)
  271. ->take($quantity)
  272. ->update([
  273. 'finished_time' => $time,
  274. 'status' => 2,
  275. 'finished_id' => 1,
  276. 'team_id' => 72,
  277. 'equipment_id' => 13,
  278. ]);
  279. }
  280. $service = new FinishedOrderService();
  281. //反写数量
  282. //生产订单
  283. $id = array_column($result,'order_product_id');
  284. $service->writeFinishedQuantityByOrdersProductId($id);
  285. //销售订单
  286. $service->writeFinishedQuantity($id);
  287. DB::commit();
  288. }catch (\Throwable $exception){
  289. DB::rollBack();
  290. return [false, $exception->getLine().':'.$exception->getMessage() . ':' . $exception->getFile()];
  291. }
  292. return [true, ''];
  293. }
  294. public function saveOutOrder($data,$user){
  295. list($status,$msg) = $this->saveOutOrderRule($data,$user);
  296. if(! $status) return [false, $msg];
  297. $limit_key = "saveOutOrder" . $user['id'];
  298. list($status,$msg) = $this->limitingSendRequestBackgNeed($limit_key);
  299. if(! $status) return [false, '正在生成销售出库订单数据,请稍后尝试!'];
  300. try {
  301. DB::beginTransaction();
  302. //组织数据
  303. $yongyou_data = $update = [];
  304. foreach ($data['out_data'] as $value){
  305. $pro_tmp = [];
  306. foreach ($value['product'] as $p){
  307. $t_k = $p['cinvcode'] . $p['cfree1'];
  308. $pro_tmp[$t_k] = [
  309. 'cinvcode' => $p['cinvcode'],
  310. 'cfree1' => $p['cfree1'],
  311. 'iquantity' => $p['iquantity'],
  312. 'line' => $p['line'],
  313. ];
  314. }
  315. if(isset($yongyou_data[$value['customer_code']])){
  316. $yongyou_data[$value['customer_code']]['cdlcode_string'] .= ',' . $value['cdlcode'];
  317. foreach ($pro_tmp as $k => $v){
  318. if(isset($yongyou_data[$value['customer_code']]['product'][$k])){
  319. $yongyou_data[$value['customer_code']]['product'][$k]['iquantity'] += $v['iquantity'];
  320. }else{
  321. $yongyou_data[$value['customer_code']]['product'][$k] = $v;
  322. }
  323. }
  324. }else{
  325. $yongyou_data[$value['customer_code']] = [
  326. 'customer_code' => $value['customer_code'],
  327. 'cdlcode_string' => $value['cdlcode'],
  328. 'product' => $pro_tmp
  329. ];
  330. }
  331. foreach ($value['box_no'] as $box_no){
  332. $update[$box_no] = $value['cdlcode'];
  333. }
  334. }
  335. if(empty($yongyou_data)) {
  336. $this->dellimitingSendRequestBackgNeed($limit_key);
  337. return [false, '暂无写入用友发货出库数据!'];
  338. }
  339. //用友 ------发货出库
  340. $service = new FinishedOrderService();
  341. list($status,$msg) = $service->U8Rdrecord32Save($yongyou_data,$user);
  342. if(! $status) {
  343. $this->dellimitingSendRequestBackgNeed($limit_key);
  344. return [false, $msg];
  345. }
  346. //本地数据更新
  347. if(! empty($update)){
  348. foreach ($update as $key => $value){
  349. Box::where('order_no', $key)->update([
  350. 'shipment_order_no' => $value
  351. ]);
  352. }
  353. }
  354. DB::commit();
  355. $this->dellimitingSendRequestBackgNeed($limit_key);
  356. }catch (\Throwable $exception){
  357. $this->dellimitingSendRequestBackgNeed($limit_key);
  358. DB::rollBack();
  359. return [false, $exception->getFile() . $exception->getFile() . $exception->getMessage()];
  360. }
  361. return [true, ''];
  362. }
  363. public function saveOutOrderRule($data,$user){
  364. if(empty($data['out_data'])) return [false, '未获取到发货数据,操作失败!'];
  365. //客户校验
  366. $customer_code = array_column($data['out_data'],'customer_code');
  367. $isAllSame = count(array_unique($customer_code)) === 1;
  368. if(! $isAllSame) return [false, '发货出库,请选择同一个客户的订单!'];
  369. $box_no = array_column($data['out_data'],'box_no');
  370. if(empty($box_no)) return [false, '包装单信息不能为空'];
  371. $box_arr = [];
  372. foreach ($box_no as $value){
  373. foreach ($value as $val){
  374. $box_arr[] = $val;
  375. }
  376. }
  377. $box_map = Box::where('del_time',0)
  378. ->whereIn('order_no',$box_arr)
  379. ->pluck('shipment_order_no', "order_no")
  380. ->toArray();
  381. foreach ($box_arr as $value){
  382. $tmp = $box_map[$value] ?? "";
  383. if($tmp != "") return [false, "包装单:" . $value . "已在发货单(" . $tmp .")中发出!"];
  384. }
  385. //用友发货数据查询
  386. $cdlcode = array_column($data['out_data'],'cdlcode');
  387. $service = new FyySqlServerService($user);
  388. if($service->error) return [false, $service->error];
  389. $out_data_map = $service->getDataFromDispatchListForCheck(['cdlcode' => $cdlcode]);
  390. if(empty($out_data_map)) return [false, '未在用友发货数据中查找到相关数据!'];
  391. //数据校验
  392. foreach ($data['out_data'] as $value){
  393. if(empty($value['cdlcode'])) return [false, '发货单号不能为空!'];
  394. if(! isset($out_data_map[$value['cdlcode']])) return [false, '发货单号:' . $value['cdlcode'] . '不存在或已被删除!'];
  395. $tmp = $out_data_map[$value['cdlcode']];
  396. if(empty($value['customer_code'])) return [false, '客户编码不能为空!'];
  397. if($tmp['customer_code'] != $value['customer_code']) return [false, '客户编码与用友数据中不一致!'];
  398. if(empty($tmp['product'])) return [false, '发货单号:' . $value['cdlcode'] . '未查找到用友的发货产品数据!'];
  399. $tmp_pro = [];
  400. foreach ($tmp['product'] as $t){
  401. $t_k = $t['cinvcode'] . $t['cfree1'];
  402. $tmp_pro[$t_k] = bcsub($t['iquantity'] , $t['out_quantity'],3);//未发货数量
  403. }
  404. if(empty($value['product'])) return [false, '发货产品不能为空!'];
  405. foreach ($value['product'] as $p){
  406. if(empty($p['line'])) return [false, '存货行号不能为空!'];
  407. if(empty($p['cinvcode'])) return [false, '存货编码不能为空!'];
  408. if(empty($p['cfree1'])) return [false, '存货颜色不能为空!'];
  409. $p_k = $p['cinvcode'] . $p['cfree1'];
  410. if(! isset($tmp_pro[$p_k])) return [false, '发货单号:' . $value['cdlcode'] . '下无该发货产品:编码为' . $p['cinvcode'] . ',颜色为:' . $p['cfree1']];
  411. if(empty($p['iquantity']) || $p['iquantity'] <= 0) return [false, '发货数量不能为空!'];
  412. $last = $tmp_pro[$p_k];
  413. if($p['iquantity'] > $last) return [false, '发货单号:' . $value['cdlcode'] . '下的发货产品:编码为' . $p['cinvcode'] . ',颜色为' . $p['cfree1'] . '的未发货数量为' . $last];
  414. }
  415. }
  416. return [true, ''];
  417. }
  418. /**
  419. * 根据发货单包装(恒成塑业不需要 如果有调用 直接返回)
  420. * @param $data
  421. * @return array
  422. */
  423. public function transportBoxIn($data)
  424. {
  425. return [true,''];
  426. $param = $data['params'];
  427. $shipment_order_no = $data['transport_no'];
  428. $sale_order_nos = [];
  429. $key_list = [];
  430. foreach ($param as $v){
  431. if(!in_array($v['order_no'],$sale_order_nos)) $sale_order_nos[] = $v['order_no'];
  432. $key = $this->getKey($v);
  433. $key_list[$key] = [
  434. 'num' => $v['num'],
  435. 'order_no' => $v['order_no'],
  436. 'team_id' => isset($v['team_id']) ? $v['team_id'] : 0,
  437. ];
  438. }
  439. $sale_order_product_list = SaleOrdersProduct::wherein('out_order_no',$sale_order_nos)->get()->toArray();
  440. $sale_order_product_key_list = [];
  441. foreach ($sale_order_product_list as $v){
  442. $key = $this->getKey($v);
  443. $sale_order_product_key_list[$key] = $v['id'];
  444. }
  445. $param = [];
  446. foreach ($key_list as $k=>$v){
  447. if(!isset($sale_order_product_key_list[$k])) return [false,$k.' 不存在!'];
  448. $param[$v['order_no']][] = [
  449. 'id' => -(intval($sale_order_product_key_list[$k])),
  450. 'team_id' => $v['team_id'],
  451. 'params' => [$v['num']]
  452. ];
  453. }
  454. // $box_no = self::$box_hook->setOrderNo(); todo
  455. foreach ($param as $k=>$v){
  456. $top_order_no = SaleOrdersProduct::where('out_order_no',$k)->value('order_no');
  457. $postParam = [
  458. 'order_no' => $top_order_no,
  459. 'param' => $v,
  460. 'box_no' => $box_no,
  461. 'transport_no' => $shipment_order_no,
  462. ];
  463. $this->boxIn($postParam);
  464. }
  465. return [true,''];
  466. }
  467. protected function getKey($data){
  468. return $data['product_no'].'_'.$data['technology_material'].'_'.$data['technology_name'].'_'.$data['wood_name'].'_'.$data['process_mark'];
  469. }
  470. /**
  471. * 包装详情1用于包装前
  472. * @param $data
  473. * @return array
  474. */
  475. public function boxDetail($data)
  476. {
  477. list($status, $data) = self::$box_hook->boxDetail($data);
  478. if (!$status) return [false, $data];
  479. $return = [];
  480. foreach ($data as $v){
  481. $key = $v['ext_1'] . $v['ext_3'];
  482. if(! isset($return[$key])){
  483. $return[$key] = $v;
  484. }else{
  485. $return[$key]['num'] += $v['num'];
  486. }
  487. }
  488. $sale_orders_product_ids = array_unique(array_column($data,'top_id'));
  489. $list = SaleOrdersProduct::wherein('id',$sale_orders_product_ids)->get()->toArray();
  490. $key_list = [];
  491. foreach ($list as $v){
  492. $key_list[$v['id']] = $v;
  493. }
  494. foreach ($return as &$v){
  495. $detail = $key_list[$v['top_id']];
  496. $v['customer_no'] = $detail['customer_no'];
  497. $v['customer_name'] = $detail['customer_name'];
  498. }
  499. return [true, array_values($return)];
  500. }
  501. public function boxProductList($data){
  502. if(empty($data['id']) && empty($data['out_order_no'])) return [false,'请选择数据!'];
  503. if(! empty($data['id'])){
  504. $sale_order_ids = $data['id'];
  505. }else{
  506. $ids = SaleOrdersProduct::where('del_time',0)
  507. ->where('out_order_no','Like','%'. $data['out_order_no'] . '%')
  508. ->select('id')
  509. ->get()->toArray();
  510. $sale_order_ids = array_column($ids,'id');
  511. if(empty($sale_order_ids)) return [false, '暂无数据!'];
  512. }
  513. $model = SaleOrdersProduct::where('del_time',0)
  514. ->whereIn('id',$sale_order_ids)
  515. ->select('id','out_order_no','order_no','customer_no','customer_name','product_no','product_title','product_size','crt_time as production_time','id as sale_orders_product_id','finished_num as dispatch_complete_quantity','box_num','technology_name','wood_name','crt_time','order_quantity','technology_material','technology_name','wood_name','process_mark')
  516. ->orderBy('id','desc')
  517. ->get()->toArray();
  518. //原先按照完工数量 未包装 = 完工数量 - 已包数量
  519. $product_list = ordersProduct::where('del_time',0)
  520. ->whereIn('sale_orders_product_id',$sale_order_ids)->select('id','out_order_no','customer_no','customer_name','product_no','sale_orders_product_id','product_title','product_size','box_num','technology_name','wood_name','crt_time','production_quantity','dispatch_complete_quantity','technology_material','technology_name','wood_name','process_mark',"production_no")
  521. ->get()->toArray();
  522. $model_key_list = [];
  523. foreach ($model as $v){
  524. $model_key_list[$v['id']] = $v;
  525. }
  526. $model = [];
  527. //存在生产订单,组织数据
  528. if(! empty($product_list)){
  529. $product_key_num_list = [];
  530. foreach ($product_list as $v){
  531. if($v['production_quantity'] == $v['box_num']) continue;
  532. if(!isset($product_key_num_list[$v['sale_orders_product_id']][$v['id']])) {
  533. $product_key_num_list[$v['sale_orders_product_id']][$v['id']] = [
  534. 'product_num' => 0 ,
  535. 'box_num' => 0 ,
  536. ];
  537. }
  538. $product_key_num_list[$v['sale_orders_product_id']][$v['id']]['product_num'] += $v['production_quantity'];
  539. $product_key_num_list[$v['sale_orders_product_id']][$v['id']]['box_num'] += $v['box_num'];
  540. $detail = $model_key_list[$v['sale_orders_product_id']];
  541. $detail['box_type'] = 1;
  542. $detail['id'] = $v['id'];
  543. $detail['box_num'] = $v['box_num'];
  544. $detail['dispatch_complete_quantity'] = $v['dispatch_complete_quantity'];
  545. $detail['un_box_num'] = bcsub($v['dispatch_complete_quantity'] , $v['box_num'],3);
  546. $detail['type'] = 1;
  547. $detail['production_no'] = $v['production_no'];
  548. $detail['production_quantity'] = $v['production_quantity'];
  549. $model[] = $detail;
  550. }
  551. }
  552. $return = [];
  553. foreach ($model as $v){
  554. if(!isset($v['box_type'])) {continue; //没有销售订单直接包了。
  555. $product_num = 0;
  556. $box_num = 0;
  557. if(isset($product_key_num_list[$v['id']])){
  558. foreach ($product_key_num_list[$v['id']] as $vv){
  559. $product_num += $vv['product_num'];
  560. $box_num += $vv['box_num'];
  561. }
  562. }
  563. if(($v['order_quantity'] - $product_num) === 0) continue;
  564. $product_key_list[$v['sale_orders_product_id']] = [
  565. 'out_order_no' => $v['out_order_no'],
  566. 'order_no' => $v['order_no'],
  567. 'production_no' => "",
  568. 'production_time' => '未下生产',
  569. 'customer_no' => $v['customer_no'],
  570. 'customer_name' => $v['customer_name'],
  571. 'product_no' => $v['product_no'],
  572. 'product_title' => $v['product_title'],
  573. 'product_size' => $v['product_size'],
  574. 'id' => -$v['sale_orders_product_id'],
  575. 'technology_material' => $v['technology_material'],
  576. 'technology_name' => $v['technology_name'],
  577. 'wood_name' => $v['wood_name'],
  578. 'process_mark' => $v['process_mark'],
  579. 'type' => '2',
  580. 'is_box_num' => $v['box_num'] - $box_num,
  581. 'un_box_num' => $v['order_quantity'] - ($v['box_num'] - $box_num) - $product_num,
  582. 'sale_num' => $v['order_quantity'],
  583. ];
  584. }else{
  585. $return[] = [
  586. 'id' => $v['id'],
  587. 'technology_material' => $v['technology_material'],
  588. 'technology_name' => $v['technology_name'],
  589. 'wood_name' => $v['wood_name'],
  590. 'order_no' => $v['order_no'],
  591. 'production_no' => $v['production_no'],
  592. 'process_mark' => $v['process_mark'],
  593. 'out_order_no' => $v['out_order_no'],
  594. 'production_time' => date('Y-m-d',$v['crt_time']),
  595. 'customer_no' => $v['customer_no'],
  596. 'customer_name' => $v['customer_name'],
  597. 'product_no' => $v['product_no'],
  598. 'product_title' => $v['product_title'],
  599. 'product_size' => $v['product_size'],
  600. 'type' => '1',
  601. 'is_box_num' => $v['box_num'],
  602. 'un_box_num' => $v['un_box_num'],
  603. 'sale_num' => $v['order_quantity'],
  604. 'production_num' => $v['production_quantity'],
  605. 'dispatch_complete_quantity' => $v['dispatch_complete_quantity']
  606. ];
  607. }
  608. }
  609. return [true,$return];
  610. }
  611. /**
  612. * 包装详情2用于包装后
  613. * @param $data
  614. * @return array
  615. */
  616. public function boxOrderDetail($data)
  617. {
  618. list($status, $data) = self::$box_hook->boxDetail($data);
  619. // var_dump($data);die;
  620. $sale_orders_product_ids = [];
  621. foreach ($data as $v){
  622. $sale_orders_product_ids[] = $v['top_id'];
  623. }
  624. $list = SaleOrdersProduct::wherein('id',$sale_orders_product_ids)->get()->toArray();
  625. $key_list = [];
  626. foreach ($list as $v){
  627. $key_list[$v['id']] = $v;
  628. }
  629. foreach ($data as &$v){
  630. $v['ext_3'] = $key_list[$v['top_id']]['product_no'];
  631. $v['wood_name'] = $key_list[$v['top_id']]['wood_name'];
  632. $v['technology_name'] = $key_list[$v['top_id']]['technology_name'];
  633. $v['process_mark'] = $key_list[$v['top_id']]['process_mark'];
  634. $v['technology_material'] = $key_list[$v['top_id']]['technology_material'];
  635. }
  636. if (!$status) return [false, $data];
  637. return [true, $data];
  638. }
  639. /**
  640. * 通过销售单号获取包装单
  641. * @param $data
  642. * @return array
  643. */
  644. public function boxOrderDetailByTop($data){
  645. $list = new Box();
  646. if(isset($data['top_order_no'])&&!empty($data['top_order_no'])) $list = $list->wherein('top_order_no',$data['top_order_no']);
  647. if(isset($data['transport_no'])&&!empty($data['transport_no'])) $list = $list->wherein('shipment_order_no',$data['transport_no']);
  648. // if(isset($data['top_order_no'])) $list = $list->wherein('top_order_no',$data['top_order_no']);
  649. // if(isset($data['transport_no'])) $list = $list->wherein('shipment_order_no',$data['transport_no']);
  650. $list = $list->select('top_order_no','order_no','crt_time')->where('del_time',0)->groupBy('order_no')->get()->toArray();
  651. return [true,$list];
  652. }
  653. /**
  654. * 通过包装单获取包装详情
  655. * @param $data
  656. * @return array
  657. */
  658. public function boxOrderDetailByOrderNo($data){
  659. $order_nos = $data['order_nos'];
  660. $order_nos = array_unique($order_nos);
  661. $list = Box::where('del_time',0)->wherein('order_no',$order_nos)->select('order_no','out_order_no','top_order_no','shipment_order_no as transport_no')->get()->toArray();
  662. $detail_list = [];
  663. foreach ($list as $v){
  664. $model = new BoxDetail(['channel'=>$v['top_order_no']]);
  665. $detail_list = array_merge($detail_list,$model->where('order_no',$v['order_no'])->where('top_order_no',$v['top_order_no'])->get()->toArray());
  666. }
  667. $list = $detail_list;
  668. $ids = [];
  669. foreach ($list as $v){
  670. $ids[] = $v['top_id'];
  671. }
  672. $sale_orders_product = SaleOrdersProduct::wherein('id',$ids)->get()->toArray();
  673. $sale_orders_key_product = [];
  674. foreach ($sale_orders_product as $v){
  675. $sale_orders_key_product[$v['id']] = $v;
  676. }
  677. $team_key_list = Team::pluck('title','id')->toArray();
  678. foreach ($list as &$v){
  679. $detail = $sale_orders_key_product[$v['top_id']];
  680. // var_dump($detail);die;
  681. $v['customer_name'] = $detail['customer_name'];
  682. $v['table_body_mark'] = $detail['table_body_mark'];
  683. $v['ext_4'] = $detail['product_title'];
  684. $v['ext_5'] = $detail['product_size'];
  685. $v['customer_name'] = $detail['customer_name'];
  686. $v['technology_material'] = $detail['technology_material'];
  687. $v['transport_no'] = $v['shipment_order_no'];
  688. $v['wood_name'] = $detail['wood_name'];
  689. $v['team_name'] = isset($team_key_list[$v['team_id']]) ? $team_key_list[$v['team_id']] : '' ;
  690. }
  691. return [true,$list];
  692. }
  693. public function boxOrderGroup($data){
  694. $list = new Box();
  695. if(empty($data['top_order_no']) && empty($data['transport_no'])) return [false,'请输入单号!'];
  696. if(! empty($data['top_order_no'])) $list = $list->whereIn('top_order_no',$data['top_order_no']);
  697. if(! empty($data['transport_no'])) {
  698. if(is_array($data['transport_no'])){
  699. $list = $list->whereIn('shipment_order_no',$data['transport_no']);
  700. }else{
  701. $list = $list->where('shipment_order_no','Like','%'. $data['transport_no'] . '%');
  702. }
  703. }
  704. $list = $list->select('top_order_no','order_no as box_no','crt_time','shipment_order_no')->where('del_time',0)
  705. ->get()->toArray();
  706. foreach ($list as $key => $value){
  707. $list[$key]['crt_time'] = date('Y-m-d H:i:s',$value['crt_time']);
  708. }
  709. return [true,$list];
  710. }
  711. public function boxOrderGroupGwp($data){
  712. $out_order_no = $data['out_order_no'] ?? "";
  713. $model = Box::where('del_time',0)
  714. ->when(! empty($out_order_no), function ($query) use ($out_order_no) {
  715. return $query->where('out_order_no','Like','%'. $out_order_no . '%');
  716. })
  717. ->select('out_order_no','ext_1','top_order_no','order_no','crt_time','shipment_order_no',DB::raw("count(id) as package_num"))
  718. ->groupBy('out_order_no');
  719. $list = $this->limit($model,'',$data);
  720. $list = $this->fillData($list);
  721. return [true, $list];
  722. }
  723. public function fillData($data){
  724. if(empty($data['data'])) return $data;
  725. foreach ($data['data'] as $key => $value){
  726. $model = new BoxDetail(['channel'=> $value['top_order_no']]);
  727. $tmp = $model->where('del_time',0)
  728. ->where('out_order_no',$value['out_order_no'])
  729. ->select('num')
  730. ->get()->toArray();
  731. $data['data'][$key]['num'] = array_sum(array_column($tmp,'num'));
  732. }
  733. return $data;
  734. }
  735. public function boxOrderGroupGwpDetail($data){
  736. if(empty($data['top_order_no']) || empty($data['out_order_no'])) return [false, '请选择数据!'];
  737. $top_order_no = $data['top_order_no'];
  738. $model = new BoxDetail(['channel'=> $top_order_no]);
  739. $detail_list = $model->where('del_time',0)
  740. ->where('out_order_no',$data['out_order_no'])
  741. ->get()->toArray();
  742. $map = Box::whereIn('order_no',array_unique(array_column($detail_list,'order_no')))
  743. ->pluck('ext_1','order_no')
  744. ->toArray();
  745. $return = [];
  746. foreach ($detail_list as $value){
  747. //销售订单号 包装单号 产品编码 颜色
  748. $key = $value['out_order_no'] . $value['order_no'] . $value['ext_1'] . $value['ext_3'];
  749. if(isset($return[$key])){
  750. $return[$key]['num'] += $value['num'];
  751. }else{
  752. $return[$key] = [
  753. 'box_no' => $value['order_no'],
  754. 'out_order_no' => $value['out_order_no'],
  755. 'ext_8' => $value['ext_8'],
  756. 'ext_3' => $value['ext_3'],
  757. 'num' => $value['num'],
  758. 'crt_time' => date("Y-m-d",$value['crt_time']),
  759. 'top_order_no' => $value['top_order_no'],
  760. 'customer_name' => $map[$value['order_no']] ?? "",
  761. ];
  762. }
  763. }
  764. return [true, array_values($return)];
  765. }
  766. public function transportNo(){
  767. $list = Box::where('del_time',0)->where('shipment_order_no','<>','')->groupBy('shipment_order_no')->pluck('shipment_order_no')->toArray();
  768. return [true,$list];
  769. }
  770. public function delBoxDetail($data){
  771. if(empty($data['order_nos'])) return [false, '请选择包装单!'];
  772. $order_nos = $data['order_nos'];
  773. try {
  774. DB::beginTransaction();
  775. //更新销售订单 生产订单数据
  776. $orders_product_id_map = [];
  777. foreach ($order_nos as $v){
  778. $list = self::$box_hook->delBox($v);
  779. if(empty($list)) continue;
  780. foreach ($list as $vv){
  781. SaleOrdersProduct::where('id',$vv['top_id'])->update([
  782. 'box_num' => DB::raw('box_num - '.$vv['num'])
  783. ]);
  784. OrdersProduct::where('id',$vv['orders_product_id'])->update([
  785. 'box_num' => DB::raw('box_num - '.$vv['num'])
  786. ]);
  787. if(isset($orders_product_id_map[$vv['orders_product_id']])){
  788. $num = bcadd($orders_product_id_map[$vv['orders_product_id']], $vv['num'],3);
  789. $orders_product_id_map[$vv['orders_product_id']] = $num;
  790. }else{
  791. $orders_product_id_map[$vv['orders_product_id']] = $vv['num'];
  792. }
  793. }
  794. }
  795. //更新完工数据 和 底表数据
  796. list($status,$msg) = $this->updateFinishDel($orders_product_id_map);
  797. if(! $status) return [false, $msg];
  798. DB::commit();
  799. }catch (\Throwable $exception){
  800. DB::rollBack();
  801. return [false, $exception->getMessage()];
  802. }
  803. return [true, ''];
  804. }
  805. public function updateFinishDel($orders_product_id_map){
  806. if(empty($orders_product_id_map)) return [true,''];
  807. $production_list = array_keys($orders_product_id_map);
  808. //组织派工数据
  809. $dispatch = DispatchSub::where('del_time',0)
  810. ->whereIn('order_product_id', $production_list)
  811. ->get()->toArray();
  812. if(empty($dispatch)) return [true,''];
  813. foreach ($dispatch as $key => $value){
  814. $dispatch[$key]['out_number'] = $orders_product_id_map[$value['order_product_id']] ?? 0;
  815. }
  816. try {
  817. DB::beginTransaction();
  818. //根据派工数据回写
  819. foreach ($dispatch as $value){
  820. $finished_num = bcsub($value['finished_num'], $value['out_number'],3);
  821. DispatchSub::where('id',$value['id'])->update([
  822. 'finished_num' => $finished_num
  823. ]);
  824. $quantity = $value['out_number'] * 1000;
  825. //工序表
  826. $process_model = new OrdersProductProcess(['channel' => date("Ymd",$value['out_order_no_time'])]);
  827. $process_model->where('order_product_id',$value['order_product_id'])
  828. ->where('process_id',$value['process_id'])
  829. ->where('dispatch_no',$value['dispatch_no'])
  830. ->where('status', 2)
  831. ->take($quantity)
  832. ->update([
  833. 'finished_time' => 0,
  834. 'status' => 1,
  835. 'finished_id' => 0,
  836. 'team_id' => 0,
  837. 'equipment_id' => 0,
  838. ]);
  839. }
  840. DB::commit();
  841. }catch (\Throwable $exception){
  842. DB::rollBack();
  843. return [false, $exception->getLine().':'.$exception->getMessage() . ':' . $exception->getFile()];
  844. }
  845. return [true, ''];
  846. }
  847. public function boxAdd($data)
  848. {
  849. list($status,$msg) = $this->boxAddRule($data);
  850. if(! $status) return [false,$msg];
  851. try{
  852. DB::beginTransaction();
  853. $box = new Box();
  854. $box->order_no = $msg['order_no'];
  855. $box->save();
  856. DB::table('box_detail')->insert($msg['detail']);
  857. DB::commit();
  858. return [true,''];
  859. }catch (\Exception $e){
  860. DB::rollBack();
  861. return [false,$e->getLine().':'.$e->getMessage()];
  862. }
  863. }
  864. public function boxAddRule($data)
  865. {
  866. if(empty($data['param'])) return [false,'请选择包装数据'];
  867. // $order_no = (new BoxHookService())->setOrderNo();
  868. $order_no = "";
  869. if(empty($order_no)) return [false,'包装单号不能为空'];
  870. $detail = [];
  871. foreach ($data['param'] as $value) {
  872. $key = $this->lock_key.'_'.$value['idlsid'];
  873. list($status,$msg) = $this->limitingSendRequestBackg($key);
  874. if(! $status) return [false,$msg];
  875. // if(empty($value['submit_quantity']) || ! is_numeric($value['submit_quantity']) || $value['submit_quantity'] > $value['quantity']) return [false,'包装数量错误'];
  876. if(empty($value['team_id'])) return [false,'班组必须选择'];
  877. $tmp = $value;
  878. $tmp['iquantity'] = $value['submit_quantity'];
  879. $detail[] = [
  880. 'order_no' => $order_no,
  881. 'out_order_no' => $value['csocode']??'',
  882. 'crt_time' => time(),
  883. 'upd_time' => time(),
  884. 'type' => 1,
  885. 'ext_1' => $value['cinvcode'],
  886. 'ext_2' => $value['technology_material'],
  887. 'ext_3' => $value['cfree1'] ?? "",
  888. 'ext_4' => $value['cfree2'] ?? "",
  889. 'ext_5' => $value['process_mark'],
  890. 'ext_6' => $value['customer_name'] ?? "",
  891. 'ext_7' => $value['cuscode'] ?? "",
  892. 'ext_8' => $value['product_title'],
  893. 'ext_9' => $value['product_size'],
  894. 'ext_10' => $value['table_header_mark'],
  895. 'ext_11' => $value['table_body_mark'],
  896. 'top_id' => $value['idlsid'],
  897. 'state' => 0,
  898. 'num' => $value['submit_quantity'],
  899. 'box_type' => 2,
  900. 'team_id' => $value['team_id'],
  901. 'shipment_order_no' => $value['cdlcode'],
  902. 'post' => json_encode($tmp),
  903. ];
  904. }
  905. return [true,['order_no' => $order_no, 'detail' => $detail]];
  906. }
  907. public function boxFhDetail($data){
  908. if(empty($data['idlsid'])) return [false,'请选择数据'];
  909. $result = DB::table('box_detail')->where('del_time',0)
  910. ->where('top_id',$data['idlsid'])
  911. ->select('order_no','ext_6','ext_7','ext_1','ext_8','ext_9','num','ext_2','ext_3','ext_4','ext_5','ext_10','ext_11')
  912. ->get()->toArray();
  913. if(! empty($result)){
  914. foreach ($result as $key => $value){
  915. $result[$key] = (array)$value;
  916. }
  917. }
  918. return [true,$result];
  919. }
  920. public function boxFhDel($data){
  921. if(empty($data['order_nos'])) return [false,'包装单号不能为空'];
  922. $box = Box::whereIn('order_no',$data['order_nos'])->update(['del_time' => time()]);
  923. DB::table('box_detail')->whereIn('order_no',$data['order_nos'])->where('del_time',0)->update([
  924. 'del_time' => time()
  925. ]);
  926. return [true,''];
  927. }
  928. public function transportDetail($data){
  929. if(empty($data['order_nos'])) return [false,'包装单号不能为空'];
  930. $order_nos = $data['order_nos'];
  931. $list = BoxDetail::wherein('order_no',$order_nos)->select('ext_1','ext_2','ext_3','ext_4','ext_5','ext_6','ext_7','ext_8','ext_9','num','order_no','shipment_order_no','post')->get()->toArray();
  932. foreach ($list as &$v){
  933. $v['product_no'] = $v['ext_1'];
  934. $v['technology_material'] = $v['ext_2'];
  935. $v['technology_name'] = $v['ext_3'];
  936. $v['wood_name'] = $v['ext_4'];
  937. $v['process_mark'] = $v['ext_5'];
  938. $v['customer_no'] = $v['ext_6'];
  939. $v['customer_name'] = $v['ext_7'];
  940. $v['product_title'] = $v['ext_8'];
  941. $v['product_size'] = $v['ext_9'];
  942. $v['post'] = json_decode($v['post'],true);
  943. }
  944. return [200,$list];
  945. }
  946. public function boxFhBzDetail($data){
  947. if(empty($data['order_no'])) return [false,'请选择包装单数据'];
  948. $result = DB::table('box_detail')->where('del_time',0)
  949. ->whereIn('order_no',$data['order_no'])
  950. ->select('order_no','ext_6','ext_7','ext_1','ext_8','ext_9','num','ext_2','ext_3','ext_4','ext_5','shipment_order_no','crt_time','team_id','ext_10','ext_11')
  951. ->get()->toArray();
  952. if(! empty($result)){
  953. foreach ($result as $key => $value){
  954. $result[$key] = (array)$value;
  955. }
  956. $map = Team::where('id',array_unique(array_column($result,'team_id')))->pluck('title','id')->toArray();
  957. foreach ($result as $key => $value){
  958. $result[$key]['team_name'] = $map[$value['team_id']] ?? '';
  959. }
  960. }
  961. return [true,$result];
  962. }
  963. public function boxFhBzList($data){
  964. if(empty($data['shipment_order_no'])) return [false, '请输入发货单号'];
  965. $model = DB::table('box_detail')->where('del_time',0)
  966. ->where('shipment_order_no','LIKE', '%'.$data['shipment_order_no'].'%')
  967. ->select('order_no','crt_time','shipment_order_no');
  968. $return = [];
  969. $result = $model->get()->toArray();
  970. if(! empty($result)){
  971. foreach ($result as $value){
  972. $return[$value->order_no] = [
  973. 'order_no' => $value->order_no,
  974. 'shipment_order_no' => $value->shipment_order_no,
  975. 'crt_time' => date("Y-m-d H:i:s",$value->crt_time)
  976. ];
  977. }
  978. }
  979. return [true,array_values($return)];
  980. }
  981. public function boxOrderDetailByOrderNoNew($data){
  982. if(empty($data['order_nos'])) return [false, '包装单号不能为空'];
  983. $order_nos = $data['order_nos'];
  984. $order_nos = array_unique($order_nos);
  985. $list = Box::where('del_time',0)
  986. ->whereIn('order_no',$order_nos)
  987. ->select('order_no','out_order_no','top_order_no','shipment_order_no as transport_no')
  988. ->get()->toArray();
  989. $detail_list = [];
  990. foreach ($list as $v){
  991. if(! empty($v['transport_no'])) return [false, "包装单:" . $v['transport_no'] . "已在发货单(" . $v['transport_no'] .")中发出!"];
  992. $model = new BoxDetail(['channel'=>$v['top_order_no']]);
  993. $detail_list = array_merge($detail_list,$model->where('order_no',$v['order_no'])->where('top_order_no',$v['top_order_no'])->get()->toArray());
  994. }
  995. $return = [];
  996. foreach ($detail_list as $value){
  997. //销售订单号 产品编码 颜色
  998. $return[] = [
  999. 'ext_1' => $value['ext_1'],
  1000. 'ext_3' => $value['ext_3'],
  1001. 'ext_8' => $value['ext_8'],
  1002. 'num' => $value['num'],
  1003. 'out_order_no' => $value['out_order_no'],
  1004. 'box_no' => $value['order_no']
  1005. ];
  1006. }
  1007. return [true, array_values($return)];
  1008. }
  1009. }