BoxService.php 48 KB

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