BoxService.php 48 KB

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