BoxService.php 47 KB

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