BoxService.php 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132
  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. //下派工数量 就是 能包的数量 相等以后 踢掉数据
  532. if($v['dispatch_complete_quantity'] == $v['box_num']) continue;
  533. if(!isset($product_key_num_list[$v['sale_orders_product_id']][$v['id']])) {
  534. $product_key_num_list[$v['sale_orders_product_id']][$v['id']] = [
  535. 'product_num' => 0 ,
  536. 'box_num' => 0 ,
  537. ];
  538. }
  539. $product_key_num_list[$v['sale_orders_product_id']][$v['id']]['product_num'] += $v['production_quantity'];
  540. $product_key_num_list[$v['sale_orders_product_id']][$v['id']]['box_num'] += $v['box_num'];
  541. $detail = $model_key_list[$v['sale_orders_product_id']];
  542. $detail['box_type'] = 1;
  543. $detail['id'] = $v['id'];
  544. $detail['box_num'] = $v['box_num'];
  545. $detail['dispatch_complete_quantity'] = $v['dispatch_complete_quantity'];
  546. $detail['un_box_num'] = bcsub($v['dispatch_complete_quantity'] , $v['box_num'],3);
  547. $detail['type'] = 1;
  548. $detail['production_no'] = $v['production_no'];
  549. $detail['production_quantity'] = $v['production_quantity'];
  550. $model[] = $detail;
  551. }
  552. }
  553. $return = [];
  554. foreach ($model as $v){
  555. if(!isset($v['box_type'])) {continue; //没有销售订单直接包了。
  556. $product_num = 0;
  557. $box_num = 0;
  558. if(isset($product_key_num_list[$v['id']])){
  559. foreach ($product_key_num_list[$v['id']] as $vv){
  560. $product_num += $vv['product_num'];
  561. $box_num += $vv['box_num'];
  562. }
  563. }
  564. if(($v['order_quantity'] - $product_num) === 0) continue;
  565. $product_key_list[$v['sale_orders_product_id']] = [
  566. 'out_order_no' => $v['out_order_no'],
  567. 'order_no' => $v['order_no'],
  568. 'production_no' => "",
  569. 'production_time' => '未下生产',
  570. 'customer_no' => $v['customer_no'],
  571. 'customer_name' => $v['customer_name'],
  572. 'product_no' => $v['product_no'],
  573. 'product_title' => $v['product_title'],
  574. 'product_size' => $v['product_size'],
  575. 'id' => -$v['sale_orders_product_id'],
  576. 'technology_material' => $v['technology_material'],
  577. 'technology_name' => $v['technology_name'],
  578. 'wood_name' => $v['wood_name'],
  579. 'process_mark' => $v['process_mark'],
  580. 'type' => '2',
  581. 'is_box_num' => $v['box_num'] - $box_num,
  582. 'un_box_num' => $v['order_quantity'] - ($v['box_num'] - $box_num) - $product_num,
  583. 'sale_num' => $v['order_quantity'],
  584. ];
  585. }else{
  586. $return[] = [
  587. 'id' => $v['id'],
  588. 'technology_material' => $v['technology_material'],
  589. 'technology_name' => $v['technology_name'],
  590. 'wood_name' => $v['wood_name'],
  591. 'order_no' => $v['order_no'],
  592. 'production_no' => $v['production_no'],
  593. 'process_mark' => $v['process_mark'],
  594. 'out_order_no' => $v['out_order_no'],
  595. 'production_time' => date('Y-m-d',$v['crt_time']),
  596. 'customer_no' => $v['customer_no'],
  597. 'customer_name' => $v['customer_name'],
  598. 'product_no' => $v['product_no'],
  599. 'product_title' => $v['product_title'],
  600. 'product_size' => $v['product_size'],
  601. 'type' => '1',
  602. 'is_box_num' => $v['box_num'],
  603. 'un_box_num' => $v['un_box_num'],
  604. 'sale_num' => $v['order_quantity'],
  605. 'production_num' => $v['production_quantity'],
  606. 'dispatch_complete_quantity' => $v['dispatch_complete_quantity']
  607. ];
  608. }
  609. }
  610. return [true,$return];
  611. }
  612. /**
  613. * 包装详情2用于包装后
  614. * @param $data
  615. * @return array
  616. */
  617. public function boxOrderDetail($data)
  618. {
  619. list($status, $data) = self::$box_hook->boxDetail($data);
  620. // var_dump($data);die;
  621. $sale_orders_product_ids = [];
  622. foreach ($data as $v){
  623. $sale_orders_product_ids[] = $v['top_id'];
  624. }
  625. $list = SaleOrdersProduct::wherein('id',$sale_orders_product_ids)->get()->toArray();
  626. $key_list = [];
  627. foreach ($list as $v){
  628. $key_list[$v['id']] = $v;
  629. }
  630. foreach ($data as &$v){
  631. $v['ext_3'] = $key_list[$v['top_id']]['product_no'];
  632. $v['wood_name'] = $key_list[$v['top_id']]['wood_name'];
  633. $v['technology_name'] = $key_list[$v['top_id']]['technology_name'];
  634. $v['process_mark'] = $key_list[$v['top_id']]['process_mark'];
  635. $v['technology_material'] = $key_list[$v['top_id']]['technology_material'];
  636. }
  637. if (!$status) return [false, $data];
  638. return [true, $data];
  639. }
  640. /**
  641. * 通过销售单号获取包装单
  642. * @param $data
  643. * @return array
  644. */
  645. public function boxOrderDetailByTop($data){
  646. $list = new Box();
  647. if(isset($data['top_order_no'])&&!empty($data['top_order_no'])) $list = $list->wherein('top_order_no',$data['top_order_no']);
  648. if(isset($data['transport_no'])&&!empty($data['transport_no'])) $list = $list->wherein('shipment_order_no',$data['transport_no']);
  649. // if(isset($data['top_order_no'])) $list = $list->wherein('top_order_no',$data['top_order_no']);
  650. // if(isset($data['transport_no'])) $list = $list->wherein('shipment_order_no',$data['transport_no']);
  651. $list = $list->select('top_order_no','order_no','crt_time')->where('del_time',0)->groupBy('order_no')->get()->toArray();
  652. return [true,$list];
  653. }
  654. /**
  655. * 通过包装单获取包装详情
  656. * @param $data
  657. * @return array
  658. */
  659. public function boxOrderDetailByOrderNo($data){
  660. $order_nos = $data['order_nos'];
  661. $order_nos = array_unique($order_nos);
  662. $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();
  663. $detail_list = [];
  664. foreach ($list as $v){
  665. $model = new BoxDetail(['channel'=>$v['top_order_no']]);
  666. $detail_list = array_merge($detail_list,$model->where('order_no',$v['order_no'])->where('top_order_no',$v['top_order_no'])->get()->toArray());
  667. }
  668. $list = $detail_list;
  669. $ids = [];
  670. foreach ($list as $v){
  671. $ids[] = $v['top_id'];
  672. }
  673. $sale_orders_product = SaleOrdersProduct::wherein('id',$ids)->get()->toArray();
  674. $sale_orders_key_product = [];
  675. foreach ($sale_orders_product as $v){
  676. $sale_orders_key_product[$v['id']] = $v;
  677. }
  678. $team_key_list = Team::pluck('title','id')->toArray();
  679. foreach ($list as &$v){
  680. $detail = $sale_orders_key_product[$v['top_id']];
  681. // var_dump($detail);die;
  682. $v['customer_name'] = $detail['customer_name'];
  683. $v['table_body_mark'] = $detail['table_body_mark'];
  684. $v['ext_4'] = $detail['product_title'];
  685. $v['ext_5'] = $detail['product_size'];
  686. $v['customer_name'] = $detail['customer_name'];
  687. $v['technology_material'] = $detail['technology_material'];
  688. $v['transport_no'] = $v['shipment_order_no'];
  689. $v['wood_name'] = $detail['wood_name'];
  690. $v['team_name'] = isset($team_key_list[$v['team_id']]) ? $team_key_list[$v['team_id']] : '' ;
  691. }
  692. return [true,$list];
  693. }
  694. public function boxOrderGroup($data){
  695. $list = new Box();
  696. if(empty($data['top_order_no']) && empty($data['transport_no'])) return [false,'请输入单号!'];
  697. if(! empty($data['top_order_no'])) $list = $list->whereIn('top_order_no',$data['top_order_no']);
  698. if(! empty($data['transport_no'])) {
  699. if(is_array($data['transport_no'])){
  700. $list = $list->whereIn('shipment_order_no',$data['transport_no']);
  701. }else{
  702. $list = $list->where('shipment_order_no','Like','%'. $data['transport_no'] . '%');
  703. }
  704. }
  705. $list = $list->select('top_order_no','order_no as box_no','crt_time','shipment_order_no')->where('del_time',0)
  706. ->get()->toArray();
  707. foreach ($list as $key => $value){
  708. $list[$key]['crt_time'] = date('Y-m-d H:i:s',$value['crt_time']);
  709. }
  710. return [true,$list];
  711. }
  712. public function boxOrderGroupGwp($data){
  713. $out_order_no = $data['out_order_no'] ?? "";
  714. $model = Box::where('del_time',0)
  715. ->when(! empty($out_order_no), function ($query) use ($out_order_no) {
  716. return $query->where('out_order_no','Like','%'. $out_order_no . '%');
  717. })
  718. ->select('out_order_no','ext_1','top_order_no','order_no','crt_time','shipment_order_no',DB::raw("count(id) as package_num"))
  719. ->groupBy('out_order_no');
  720. $list = $this->limit($model,'',$data);
  721. $list = $this->fillData($list);
  722. return [true, $list];
  723. }
  724. public function fillData($data){
  725. if(empty($data['data'])) return $data;
  726. foreach ($data['data'] as $key => $value){
  727. $model = new BoxDetail(['channel'=> $value['top_order_no']]);
  728. $tmp = $model->where('del_time',0)
  729. ->where('out_order_no',$value['out_order_no'])
  730. ->select('num')
  731. ->get()->toArray();
  732. $data['data'][$key]['num'] = array_sum(array_column($tmp,'num'));
  733. }
  734. return $data;
  735. }
  736. public function boxOrderGroupGwpDetail($data){
  737. if(empty($data['top_order_no']) || empty($data['out_order_no'])) return [false, '请选择数据!'];
  738. $top_order_no = $data['top_order_no'];
  739. $model = new BoxDetail(['channel'=> $top_order_no]);
  740. $detail_list = $model->where('del_time',0)
  741. ->where('out_order_no',$data['out_order_no'])
  742. ->get()->toArray();
  743. $map = Box::whereIn('order_no',array_unique(array_column($detail_list,'order_no')))
  744. ->pluck('ext_1','order_no')
  745. ->toArray();
  746. $return = [];
  747. foreach ($detail_list as $value){
  748. //销售订单号 包装单号 产品编码 颜色
  749. $key = $value['out_order_no'] . $value['order_no'] . $value['ext_1'] . $value['ext_3'];
  750. if(isset($return[$key])){
  751. $return[$key]['num'] += $value['num'];
  752. }else{
  753. $return[$key] = [
  754. 'box_no' => $value['order_no'],
  755. 'out_order_no' => $value['out_order_no'],
  756. 'ext_8' => $value['ext_8'],
  757. 'ext_3' => $value['ext_3'],
  758. 'num' => $value['num'],
  759. 'crt_time' => date("Y-m-d",$value['crt_time']),
  760. 'top_order_no' => $value['top_order_no'],
  761. 'customer_name' => $map[$value['order_no']] ?? "",
  762. ];
  763. }
  764. }
  765. return [true, array_values($return)];
  766. }
  767. public function transportNo(){
  768. $list = Box::where('del_time',0)->where('shipment_order_no','<>','')->groupBy('shipment_order_no')->pluck('shipment_order_no')->toArray();
  769. return [true,$list];
  770. }
  771. public function delBoxDetail($data){
  772. if(empty($data['order_nos'])) return [false, '请选择包装单!'];
  773. $order_nos = $data['order_nos'];
  774. try {
  775. DB::beginTransaction();
  776. //更新销售订单 生产订单数据
  777. $orders_product_id_map = [];
  778. foreach ($order_nos as $v){
  779. $list = self::$box_hook->delBox($v);
  780. if(empty($list)) continue;
  781. foreach ($list as $vv){
  782. SaleOrdersProduct::where('id',$vv['top_id'])->update([
  783. 'box_num' => DB::raw('box_num - '.$vv['num']),
  784. 'finished_num' => DB::raw('finished_num - '.$vv['num'])
  785. ]);
  786. OrdersProduct::where('id',$vv['orders_product_id'])->update([
  787. 'box_num' => DB::raw('box_num - '.$vv['num']),
  788. 'finished_num' => DB::raw('finished_num - '.$vv['num'])
  789. ]);
  790. if(isset($orders_product_id_map[$vv['orders_product_id']])){
  791. $num = bcadd($orders_product_id_map[$vv['orders_product_id']], $vv['num'],3);
  792. $orders_product_id_map[$vv['orders_product_id']] = $num;
  793. }else{
  794. $orders_product_id_map[$vv['orders_product_id']] = $vv['num'];
  795. }
  796. }
  797. }
  798. //更新完工数据 和 底表数据
  799. list($status,$msg) = $this->updateFinishDel($orders_product_id_map);
  800. if(! $status) return [false, $msg];
  801. DB::commit();
  802. }catch (\Throwable $exception){
  803. DB::rollBack();
  804. return [false, $exception->getMessage()];
  805. }
  806. return [true, ''];
  807. }
  808. public function updateFinishDel($orders_product_id_map){
  809. if(empty($orders_product_id_map)) return [true,''];
  810. $production_list = array_keys($orders_product_id_map);
  811. //组织派工数据
  812. $dispatch = DispatchSub::where('del_time',0)
  813. ->whereIn('order_product_id', $production_list)
  814. ->get()->toArray();
  815. if(empty($dispatch)) return [true,''];
  816. foreach ($dispatch as $key => $value){
  817. $dispatch[$key]['out_number'] = $orders_product_id_map[$value['order_product_id']] ?? 0;
  818. }
  819. try {
  820. DB::beginTransaction();
  821. //根据派工数据回写
  822. foreach ($dispatch as $value){
  823. $finished_num = bcsub($value['finished_num'], $value['out_number'],3);
  824. DispatchSub::where('id',$value['id'])->update([
  825. 'finished_num' => $finished_num
  826. ]);
  827. $quantity = $value['out_number'] * 1000;
  828. //工序表
  829. $process_model = new OrdersProductProcess(['channel' => date("Ymd",$value['out_order_no_time'])]);
  830. $process_model->where('order_product_id',$value['order_product_id'])
  831. ->where('process_id',$value['process_id'])
  832. ->where('dispatch_no',$value['dispatch_no'])
  833. ->where('status', 2)
  834. ->take($quantity)
  835. ->update([
  836. 'finished_time' => 0,
  837. 'status' => 1,
  838. 'finished_id' => 0,
  839. 'team_id' => 0,
  840. 'equipment_id' => 0,
  841. ]);
  842. }
  843. DB::commit();
  844. }catch (\Throwable $exception){
  845. DB::rollBack();
  846. return [false, $exception->getLine().':'.$exception->getMessage() . ':' . $exception->getFile()];
  847. }
  848. return [true, ''];
  849. }
  850. public function boxAdd($data)
  851. {
  852. list($status,$msg) = $this->boxAddRule($data);
  853. if(! $status) return [false,$msg];
  854. try{
  855. DB::beginTransaction();
  856. $box = new Box();
  857. $box->order_no = $msg['order_no'];
  858. $box->save();
  859. DB::table('box_detail')->insert($msg['detail']);
  860. DB::commit();
  861. return [true,''];
  862. }catch (\Exception $e){
  863. DB::rollBack();
  864. return [false,$e->getLine().':'.$e->getMessage()];
  865. }
  866. }
  867. public function boxAddRule($data)
  868. {
  869. if(empty($data['param'])) return [false,'请选择包装数据'];
  870. // $order_no = (new BoxHookService())->setOrderNo();
  871. $order_no = "";
  872. if(empty($order_no)) return [false,'包装单号不能为空'];
  873. $detail = [];
  874. foreach ($data['param'] as $value) {
  875. $key = $this->lock_key.'_'.$value['idlsid'];
  876. list($status,$msg) = $this->limitingSendRequestBackg($key);
  877. if(! $status) return [false,$msg];
  878. // if(empty($value['submit_quantity']) || ! is_numeric($value['submit_quantity']) || $value['submit_quantity'] > $value['quantity']) return [false,'包装数量错误'];
  879. if(empty($value['team_id'])) return [false,'班组必须选择'];
  880. $tmp = $value;
  881. $tmp['iquantity'] = $value['submit_quantity'];
  882. $detail[] = [
  883. 'order_no' => $order_no,
  884. 'out_order_no' => $value['csocode']??'',
  885. 'crt_time' => time(),
  886. 'upd_time' => time(),
  887. 'type' => 1,
  888. 'ext_1' => $value['cinvcode'],
  889. 'ext_2' => $value['technology_material'],
  890. 'ext_3' => $value['cfree1'] ?? "",
  891. 'ext_4' => $value['cfree2'] ?? "",
  892. 'ext_5' => $value['process_mark'],
  893. 'ext_6' => $value['customer_name'] ?? "",
  894. 'ext_7' => $value['cuscode'] ?? "",
  895. 'ext_8' => $value['product_title'],
  896. 'ext_9' => $value['product_size'],
  897. 'ext_10' => $value['table_header_mark'],
  898. 'ext_11' => $value['table_body_mark'],
  899. 'top_id' => $value['idlsid'],
  900. 'state' => 0,
  901. 'num' => $value['submit_quantity'],
  902. 'box_type' => 2,
  903. 'team_id' => $value['team_id'],
  904. 'shipment_order_no' => $value['cdlcode'],
  905. 'post' => json_encode($tmp),
  906. ];
  907. }
  908. return [true,['order_no' => $order_no, 'detail' => $detail]];
  909. }
  910. public function boxFhDetail($data){
  911. if(empty($data['idlsid'])) return [false,'请选择数据'];
  912. $result = DB::table('box_detail')->where('del_time',0)
  913. ->where('top_id',$data['idlsid'])
  914. ->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')
  915. ->get()->toArray();
  916. if(! empty($result)){
  917. foreach ($result as $key => $value){
  918. $result[$key] = (array)$value;
  919. }
  920. }
  921. return [true,$result];
  922. }
  923. public function boxFhDel($data){
  924. if(empty($data['order_nos'])) return [false,'包装单号不能为空'];
  925. $box = Box::whereIn('order_no',$data['order_nos'])->update(['del_time' => time()]);
  926. DB::table('box_detail')->whereIn('order_no',$data['order_nos'])->where('del_time',0)->update([
  927. 'del_time' => time()
  928. ]);
  929. return [true,''];
  930. }
  931. public function transportDetail($data){
  932. if(empty($data['order_nos'])) return [false,'包装单号不能为空'];
  933. $order_nos = $data['order_nos'];
  934. $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();
  935. foreach ($list as &$v){
  936. $v['product_no'] = $v['ext_1'];
  937. $v['technology_material'] = $v['ext_2'];
  938. $v['technology_name'] = $v['ext_3'];
  939. $v['wood_name'] = $v['ext_4'];
  940. $v['process_mark'] = $v['ext_5'];
  941. $v['customer_no'] = $v['ext_6'];
  942. $v['customer_name'] = $v['ext_7'];
  943. $v['product_title'] = $v['ext_8'];
  944. $v['product_size'] = $v['ext_9'];
  945. $v['post'] = json_decode($v['post'],true);
  946. }
  947. return [200,$list];
  948. }
  949. public function boxFhBzDetail($data){
  950. if(empty($data['order_no'])) return [false,'请选择包装单数据'];
  951. $result = DB::table('box_detail')->where('del_time',0)
  952. ->whereIn('order_no',$data['order_no'])
  953. ->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')
  954. ->get()->toArray();
  955. if(! empty($result)){
  956. foreach ($result as $key => $value){
  957. $result[$key] = (array)$value;
  958. }
  959. $map = Team::where('id',array_unique(array_column($result,'team_id')))->pluck('title','id')->toArray();
  960. foreach ($result as $key => $value){
  961. $result[$key]['team_name'] = $map[$value['team_id']] ?? '';
  962. }
  963. }
  964. return [true,$result];
  965. }
  966. public function boxFhBzList($data){
  967. if(empty($data['shipment_order_no'])) return [false, '请输入发货单号'];
  968. $model = DB::table('box_detail')->where('del_time',0)
  969. ->where('shipment_order_no','LIKE', '%'.$data['shipment_order_no'].'%')
  970. ->select('order_no','crt_time','shipment_order_no');
  971. $return = [];
  972. $result = $model->get()->toArray();
  973. if(! empty($result)){
  974. foreach ($result as $value){
  975. $return[$value->order_no] = [
  976. 'order_no' => $value->order_no,
  977. 'shipment_order_no' => $value->shipment_order_no,
  978. 'crt_time' => date("Y-m-d H:i:s",$value->crt_time)
  979. ];
  980. }
  981. }
  982. return [true,array_values($return)];
  983. }
  984. public function boxOrderDetailByOrderNoNew($data){
  985. if(empty($data['order_nos'])) return [false, '包装单号不能为空'];
  986. $order_nos = $data['order_nos'];
  987. $order_nos = array_unique($order_nos);
  988. $list = Box::where('del_time',0)
  989. ->whereIn('order_no',$order_nos)
  990. ->select('order_no','out_order_no','top_order_no','shipment_order_no as transport_no')
  991. ->get()->toArray();
  992. $detail_list = [];
  993. foreach ($list as $v){
  994. if(! empty($v['transport_no'])) return [false, "包装单:" . $v['transport_no'] . "已在发货单(" . $v['transport_no'] .")中发出!"];
  995. $model = new BoxDetail(['channel'=>$v['top_order_no']]);
  996. $detail_list = array_merge($detail_list,$model->where('order_no',$v['order_no'])->where('top_order_no',$v['top_order_no'])->get()->toArray());
  997. }
  998. $return = [];
  999. foreach ($detail_list as $value){
  1000. //销售订单号 产品编码 颜色
  1001. $return[] = [
  1002. 'ext_1' => $value['ext_1'],
  1003. 'ext_3' => $value['ext_3'],
  1004. 'ext_8' => $value['ext_8'],
  1005. 'num' => $value['num'],
  1006. 'out_order_no' => $value['out_order_no'],
  1007. 'box_no' => $value['order_no']
  1008. ];
  1009. }
  1010. return [true, array_values($return)];
  1011. }
  1012. }