BoxService.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. <?php
  2. namespace App\Service\Box;
  3. use App\Model\Box;
  4. use App\Model\BoxDetail;
  5. use App\Model\Header_ext;
  6. use App\Model\OrdersProduct;
  7. use App\Model\SaleOrdersProduct;
  8. use App\Model\Team;
  9. use App\Service\Service;
  10. use Illuminate\Support\Facades\DB;
  11. /**
  12. * 包装相关
  13. * @package App\Models
  14. */
  15. class BoxService extends Service
  16. {
  17. protected static $instance;
  18. protected static $box_header;
  19. protected static $box_detail_header;
  20. protected static $box_hook;
  21. public $lock_key = 'box';
  22. public function __construct()
  23. {
  24. self::$box_header = Header_ext::where('type', 'box')->pluck('value', 'key')->toArray();
  25. self::$box_detail_header = Header_ext::where('type', 'box_detail')->pluck('value', 'key')->toArray();
  26. self::$box_hook = BoxHookService::getInstance();
  27. }
  28. /**
  29. * 包装
  30. * @param $data
  31. * @return array
  32. */
  33. public function boxIn($data)
  34. {
  35. $ids = [];
  36. $sale_ids = [];
  37. $top_order_no = $data['order_no'];
  38. $box_no = isset($data['box_no']) ? $data['box_no'] : '';
  39. $transport_no = isset($data['transport_no']) ? $data['transport_no'] : '';
  40. $data = $data['param'];
  41. $key_list = [];
  42. foreach ($data as $v) {
  43. if($v['id'] < 0) $sale_ids[] = -$v['id'];
  44. else $ids[] = $v['id'];
  45. if($v['id'] < 0) $v['id'] = -$v['id'];
  46. $total = 0;
  47. foreach ($v['params'] as $vv) {
  48. $total += $vv;
  49. }
  50. $key_list[$v['id']] = [
  51. 'detail' => $v['params'],
  52. 'total' => $total,
  53. 'team_id' => isset($v['team_id']) ? $v['team_id'] : 0,
  54. ];
  55. }
  56. $insert = [];
  57. try{
  58. DB::beginTransaction();
  59. $key = $this->lock_key.'_'.$v['id'];
  60. $lock_status = $this->isLock($key);
  61. if(!$lock_status) return [false,'操作过于频繁'];
  62. $product_list = OrdersProduct::wherein('id', $ids)->get()->toArray();
  63. $sale_product_list = SaleOrdersProduct::wherein('id', $sale_ids)->get()->toArray();
  64. $box_insert = [];
  65. foreach ($product_list as $v) {
  66. $num_list = $key_list[$v['id']];
  67. $total = $num_list['total'];
  68. $detail = $num_list['detail'];
  69. $team_id = $num_list['team_id'];
  70. $un_box_num = $v['dispatch_complete_quantity'] - $v['box_num'];
  71. if ($total > $un_box_num) return [false, $v['product_title'] . '数量不足'];
  72. $ext_1 = $v['product_no'];//产品编号
  73. $ext_2 = $v['technology_material']; //工艺材质 废弃
  74. $ext_3 = $v['technology_name'];//工艺名称 改为颜色
  75. $ext_4 = $v['wood_name'];//木皮 废弃
  76. $ext_5 = $v['process_mark'];//工艺备注 废弃
  77. $out_order_no = $insert['out_order_no'] = $v['out_order_no'];
  78. $top_id = $v['sale_orders_product_id'];
  79. foreach ($detail as $vv){
  80. $box_insert[] = [
  81. 'out_order_no' => $out_order_no,
  82. 'top_id' => $top_id,
  83. 'ext_1' => $ext_1,
  84. 'ext_2' => $ext_2,
  85. 'ext_3' => $ext_3,
  86. 'ext_4' => $ext_4,
  87. 'ext_5' => $ext_5,
  88. 'num' => $vv,
  89. 'price' => $v['price'],
  90. 'box_type' => 1,
  91. 'team_id' => $team_id,
  92. 'shipment_order_no' => $transport_no,
  93. ];
  94. }
  95. SaleOrdersProduct::where('id',$v['sale_orders_product_id'])->update([
  96. 'box_num' => DB::raw('box_num + '.$total),
  97. ]);
  98. OrdersProduct::where('id',$v['id'])->update([
  99. 'box_num' => DB::raw('box_num + '.$total),
  100. ]);
  101. }
  102. foreach ($sale_product_list as $v) {
  103. $box_type = 0;
  104. if($v['id'] < 0) {
  105. $v['id'] = -$v['id'];
  106. $box_type = 1;
  107. }
  108. $num_list = $key_list[$v['id']];
  109. $total = $num_list['total'];
  110. $detail = $num_list['detail'];
  111. $team_id = $num_list['team_id'];
  112. $box_detail = new BoxDetail(['channel'=>$top_order_no]);
  113. $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');
  114. if ($total > $un_box_num) return [false, $v['product_title'] . '数量不足'];
  115. $ext_1 = $v['product_no'];//产品编号
  116. $ext_2 = $v['technology_material']; //工艺材质 废弃
  117. $ext_3 = $v['technology_name'];//工艺名称 改为颜色
  118. $ext_4 = $v['wood_name'];//木皮 废弃
  119. $ext_5 = $v['process_mark'];//工艺备注 废弃
  120. $out_order_no = $insert['out_order_no'] = $v['out_order_no'];
  121. $top_id = $v['id'];
  122. foreach ($detail as $vv){
  123. $box_insert[] = [
  124. 'out_order_no' => $out_order_no,
  125. 'top_id' => $top_id,
  126. 'ext_1' => $ext_1,
  127. 'ext_2' => $ext_2,
  128. 'ext_3' => $ext_3,
  129. 'ext_4' => $ext_4,
  130. 'ext_5' => $ext_5,
  131. 'num' => $vv,
  132. 'price' => $v['price'],
  133. 'box_type' => $box_type,
  134. 'team_id' => $team_id,
  135. 'shipment_order_no' => $transport_no,
  136. ];
  137. }
  138. SaleOrdersProduct::where('id',$v['id'])->update([
  139. 'box_num' => DB::raw('box_num + '.$total),
  140. ]);
  141. }
  142. //客户名称
  143. $ext_1 = "";
  144. if(empty($ext_1) && isset($sale_product_list[0]['customer_name'])) $ext_1 = $sale_product_list[0]['customer_name'];
  145. if(empty($ext_1) && isset($product_list[0]['customer_name'])) $ext_1 = $product_list[0]['customer_name'];
  146. $insert['ext_1'] = $ext_1;
  147. $insert['detail'] = $box_insert;
  148. $insert['top_order_no'] = $top_order_no;
  149. $insert['order_no'] = $box_no;
  150. $insert['shipment_order_no'] = $transport_no;
  151. list($status,$msg) = self::$box_hook->boxInsert($insert);
  152. if(!$status) {
  153. $this->delLock($key);
  154. DB::rollBack();
  155. return [false,$msg];
  156. }
  157. $this->delLock($key);
  158. DB::commit();
  159. return [true, ['package_data' => $msg->toArray()]];
  160. }catch (\Exception $e){
  161. DB::rollBack();
  162. return [false,$e->getLine().':'.$e->getMessage()];
  163. }
  164. }
  165. /**
  166. * 根据发货单包装
  167. * @param $data
  168. * @return array
  169. */
  170. public function transportBoxIn($data)
  171. {
  172. // $param = [
  173. // [
  174. // 'order_no' => 'XD202309000155',
  175. // 'product_no' => '0301011816',
  176. // 'technology_material' => '多层板,单贴,新木纹钢板',
  177. // 'technology_name' => '',
  178. // 'wood_name' => '',
  179. // 'process_mark' => '',
  180. // 'num' => '5',
  181. // 'team_id' => '1',
  182. // ],[
  183. // 'order_no' => 'XD202309000155',
  184. // 'product_no' => '0104010753',
  185. // 'technology_material' => '多层线条',
  186. // 'technology_name' => '',
  187. // 'wood_name' => '',
  188. // 'process_mark' => '',
  189. // 'num' => '4',
  190. // 'team_id' => '1',
  191. // ],[
  192. // 'order_no' => 'XD202309000156',
  193. // 'product_no' => '0301011712',
  194. // 'technology_material' => '多层板,双贴,雨丝钢板',
  195. // 'technology_name' => '',
  196. // 'wood_name' => '',
  197. // 'process_mark' => '',
  198. // 'num' => '3',
  199. // ],
  200. // ];
  201. // dd(json_encode($param));
  202. // $params = [
  203. // 'params' => $param,
  204. // 'transport_no' => '123443212',
  205. // ];
  206. $param = $data['params'];
  207. $shipment_order_no = $data['transport_no'];
  208. $sale_order_nos = [];
  209. $key_list = [];
  210. foreach ($param as $v){
  211. if(!in_array($v['order_no'],$sale_order_nos)) $sale_order_nos[] = $v['order_no'];
  212. $key = $this->getKey($v);
  213. $key_list[$key] = [
  214. 'num' => $v['num'],
  215. 'order_no' => $v['order_no'],
  216. 'team_id' => isset($v['team_id']) ? $v['team_id'] : 0,
  217. ];
  218. }
  219. $sale_order_product_list = SaleOrdersProduct::wherein('out_order_no',$sale_order_nos)->get()->toArray();
  220. $sale_order_product_key_list = [];
  221. foreach ($sale_order_product_list as $v){
  222. $key = $this->getKey($v);
  223. $sale_order_product_key_list[$key] = $v['id'];
  224. }
  225. $param = [];
  226. // var_dump($key_list);
  227. // var_dump($sale_order_product_key_list);die;
  228. foreach ($key_list as $k=>$v){
  229. if(!isset($sale_order_product_key_list[$k])) return [false,$k.' 不存在!'];
  230. $param[$v['order_no']][] = [
  231. 'id' => -(intval($sale_order_product_key_list[$k])),
  232. 'team_id' => $v['team_id'],
  233. 'params' => [$v['num']]
  234. ];
  235. }
  236. $box_no = self::$box_hook->setOrderNo();
  237. foreach ($param as $k=>$v){
  238. $top_order_no = SaleOrdersProduct::where('out_order_no',$k)->value('order_no');
  239. $postParam = [
  240. 'order_no' => $top_order_no,
  241. 'param' => $v,
  242. 'box_no' => $box_no,
  243. 'transport_no' => $shipment_order_no,
  244. ];
  245. $this->boxIn($postParam);
  246. // var_dump($postParam);die;
  247. }
  248. return [true,'保存成功'];
  249. }
  250. protected function getKey($data){
  251. return $data['product_no'].'_'.$data['technology_material'].'_'.$data['technology_name'].'_'.$data['wood_name'].'_'.$data['process_mark'];
  252. }
  253. /**
  254. * 包装详情1用于包装前
  255. * @param $data
  256. * @return array
  257. */
  258. public function boxDetail($data)
  259. {
  260. list($status, $data) = self::$box_hook->boxDetail($data);
  261. if (!$status) return [false, $data];
  262. $sale_orders_product_ids = [];
  263. foreach ($data as $v){
  264. $sale_orders_product_ids[] = $v['top_id'];
  265. }
  266. $list = SaleOrdersProduct::wherein('id',$sale_orders_product_ids)->get()->toArray();
  267. $key_list = [];
  268. foreach ($list as $v){
  269. $key_list[$v['id']] = $v;
  270. }
  271. foreach ($data as &$v){
  272. $detail = $key_list[$v['top_id']];
  273. $v['customer_no'] = $detail['customer_no'];
  274. $v['customer_name'] = $detail['customer_name'];
  275. }
  276. return [true, $data];
  277. }
  278. public function boxProductList($data){
  279. if(!isset($data['id'])) return [false,'id not found'];
  280. $sale_order_ids = $data['id'];
  281. $model = SaleOrdersProduct::where('del_time',0)->wherein('id',$sale_order_ids)
  282. ->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')
  283. ->orderBy('id','desc')->get()->toArray();
  284. $product_list = ordersProduct::where('del_time',0)->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','dispatch_complete_quantity','box_num','technology_name','wood_name','crt_time',DB::raw('(production_quantity - scrapp_num) as production_quantity'),DB::raw('finished_num as dispatch_complete_quantity'),'technology_material','technology_name','wood_name','process_mark')->get()->toArray();
  285. $model_key_list = [];
  286. foreach ($model as $v){
  287. $model_key_list[$v['id']] = $v;
  288. }
  289. $product_key_num_list = [];
  290. foreach ($product_list as $v){
  291. if(!isset($product_key_num_list[$v['sale_orders_product_id']][$v['id']]))$product_key_num_list[$v['sale_orders_product_id']][$v['id']] = [
  292. 'product_num' => 0 ,
  293. 'box_num' => 0 ,
  294. ];
  295. $product_key_num_list[$v['sale_orders_product_id']][$v['id']]['product_num'] += $v['production_quantity'];
  296. $product_key_num_list[$v['sale_orders_product_id']][$v['id']]['box_num'] += $v['box_num'];
  297. $detail = $model_key_list[$v['sale_orders_product_id']];
  298. $detail['box_type'] = 1;
  299. $detail['id'] = $v['id'];
  300. $detail['box_num'] = $v['box_num'];
  301. $detail['un_box_num'] = $v['dispatch_complete_quantity'] - $v['box_num'];
  302. $detail['type'] = 1;
  303. $model[] = $detail;
  304. }
  305. $return = [];
  306. $product_key_list = [];
  307. foreach ($model as $v){
  308. if(!isset($v['box_type'])) {
  309. $product_num = 0;
  310. $box_num = 0;
  311. if(isset($product_key_num_list[$v['id']])){
  312. foreach ($product_key_num_list[$v['id']] as $vv){
  313. $product_num += $vv['product_num'];
  314. $box_num += $vv['box_num'];
  315. }
  316. }
  317. if(($v['order_quantity'] - $product_num) === 0) continue;
  318. $product_key_list[$v['sale_orders_product_id']] = [
  319. 'out_order_no' => $v['out_order_no'],
  320. 'order_no' => $v['order_no'],
  321. 'production_time' => '未下生产',
  322. 'customer_no' => $v['customer_no'],
  323. 'customer_name' => $v['customer_name'],
  324. 'product_no' => $v['product_no'],
  325. 'product_title' => $v['product_title'],
  326. 'product_size' => $v['product_size'],
  327. 'id' => -$v['sale_orders_product_id'],
  328. 'technology_material' => $v['technology_material'],
  329. 'technology_name' => $v['technology_name'],
  330. 'wood_name' => $v['wood_name'],
  331. 'process_mark' => $v['process_mark'],
  332. 'type' => '2',
  333. 'is_box_num' => $v['box_num'] - $box_num,
  334. 'un_box_num' => $v['order_quantity'] - ($v['box_num'] - $box_num) - $product_num,
  335. 'sale_num' => $v['order_quantity'],
  336. ];
  337. }else{
  338. $return[] = [
  339. 'id' => $v['id'],
  340. 'technology_material' => $v['technology_material'],
  341. 'technology_name' => $v['technology_name'],
  342. 'wood_name' => $v['wood_name'],
  343. 'order_no' => $v['order_no'],
  344. 'process_mark' => $v['process_mark'],
  345. 'out_order_no' => $v['out_order_no'],
  346. 'production_time' => date('Y-m-d',$v['crt_time']),
  347. 'customer_no' => $v['customer_no'],
  348. 'customer_name' => $v['customer_name'],
  349. 'product_no' => $v['product_no'],
  350. 'product_title' => $v['product_title'],
  351. 'product_size' => $v['product_size'],
  352. 'type' => '1',
  353. 'is_box_num' => $v['box_num'],
  354. 'un_box_num' => $v['un_box_num'],
  355. 'sale_num' => $v['order_quantity'],
  356. ];
  357. }
  358. }
  359. foreach ($product_key_list as $v){
  360. $return[] = $v;
  361. }
  362. return [true,$return];
  363. }
  364. /**
  365. * 包装详情2用于包装后
  366. * @param $data
  367. * @return array
  368. */
  369. public function boxOrderDetail($data)
  370. {
  371. list($status, $data) = self::$box_hook->boxDetail($data);
  372. // var_dump($data);die;
  373. $sale_orders_product_ids = [];
  374. foreach ($data as $v){
  375. $sale_orders_product_ids[] = $v['top_id'];
  376. }
  377. $list = SaleOrdersProduct::wherein('id',$sale_orders_product_ids)->get()->toArray();
  378. $key_list = [];
  379. foreach ($list as $v){
  380. $key_list[$v['id']] = $v;
  381. }
  382. foreach ($data as &$v){
  383. $v['ext_3'] = $key_list[$v['top_id']]['product_no'];
  384. $v['wood_name'] = $key_list[$v['top_id']]['wood_name'];
  385. $v['technology_name'] = $key_list[$v['top_id']]['technology_name'];
  386. $v['process_mark'] = $key_list[$v['top_id']]['process_mark'];
  387. $v['technology_material'] = $key_list[$v['top_id']]['technology_material'];
  388. }
  389. if (!$status) return [false, $data];
  390. return [true, $data];
  391. }
  392. /**
  393. * 通过销售单号获取包装单
  394. * @param $data
  395. * @return array
  396. */
  397. public function boxOrderDetailByTop($data){
  398. $list = new Box();
  399. if(isset($data['top_order_no'])&&!empty($data['top_order_no'])) $list = $list->wherein('top_order_no',$data['top_order_no']);
  400. if(isset($data['transport_no'])&&!empty($data['transport_no'])) $list = $list->wherein('shipment_order_no',$data['transport_no']);
  401. // if(isset($data['top_order_no'])) $list = $list->wherein('top_order_no',$data['top_order_no']);
  402. // if(isset($data['transport_no'])) $list = $list->wherein('shipment_order_no',$data['transport_no']);
  403. $list = $list->select('top_order_no','order_no','crt_time')->where('del_time',0)->groupBy('order_no')->get()->toArray();
  404. return [true,$list];
  405. }
  406. /**
  407. * 通过包装单获取包装详情
  408. * @param $data
  409. * @return array
  410. */
  411. public function boxOrderDetailByOrderNo($data){
  412. $order_nos = $data['order_nos'];
  413. $order_nos = array_unique($order_nos);
  414. $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();
  415. $detail_list = [];
  416. foreach ($list as $v){
  417. $model = new BoxDetail(['channel'=>$v['top_order_no']]);
  418. $detail_list = array_merge($detail_list,$model->where('order_no',$v['order_no'])->where('top_order_no',$v['top_order_no'])->get()->toArray());
  419. }
  420. $list = $detail_list;
  421. $ids = [];
  422. foreach ($list as $v){
  423. $ids[] = $v['top_id'];
  424. }
  425. $sale_orders_product = SaleOrdersProduct::wherein('id',$ids)->get()->toArray();
  426. $sale_orders_key_product = [];
  427. foreach ($sale_orders_product as $v){
  428. $sale_orders_key_product[$v['id']] = $v;
  429. }
  430. $team_key_list = Team::pluck('title','id')->toArray();
  431. foreach ($list as &$v){
  432. $detail = $sale_orders_key_product[$v['top_id']];
  433. // var_dump($detail);die;
  434. $v['customer_name'] = $detail['customer_name'];
  435. $v['table_body_mark'] = $detail['table_body_mark'];
  436. $v['ext_4'] = $detail['product_title'];
  437. $v['ext_5'] = $detail['product_size'];
  438. $v['customer_name'] = $detail['customer_name'];
  439. $v['technology_material'] = $detail['technology_material'];
  440. $v['transport_no'] = $v['shipment_order_no'];
  441. $v['wood_name'] = $detail['wood_name'];
  442. $v['team_name'] = isset($team_key_list[$v['team_id']]) ? $team_key_list[$v['team_id']] : '' ;
  443. }
  444. return [true,$list];
  445. }
  446. public function boxOrderGroup($data){
  447. $list = new Box();
  448. if(empty($data['top_order_no'])&&empty($data['transport_no'])) return [false,'销售单或发货单必选一个'];
  449. if(isset($data['top_order_no'])&&!empty($data['top_order_no'])) $list = $list->wherein('top_order_no',$data['top_order_no']);
  450. if(!empty($data['transport_no'])) {
  451. if(is_array($data['transport_no'])){
  452. $list = $list->wherein('shipment_order_no',$data['transport_no']);
  453. }else{
  454. $list = $list->where('shipment_order_no','Like','%'. $data['transport_no'] . '%');
  455. }
  456. }
  457. $list = $list->select('top_order_no','order_no','crt_time','shipment_order_no')->where('del_time',0)->get()->toArray();
  458. return [true,$list];
  459. }
  460. public function transportNo(){
  461. $list = Box::where('del_time',0)->where('shipment_order_no','<>','')->groupBy('shipment_order_no')->pluck('shipment_order_no')->toArray();
  462. return [true,$list];
  463. }
  464. public function delBoxDetail($data){
  465. $order_nos = $data['order_nos'];
  466. foreach ($order_nos as $v){
  467. $list = self::$box_hook->delBox($v);
  468. foreach ($list as $vv){
  469. SaleOrdersProduct::where('id',$vv['top_id'])->update([
  470. 'box_num' => DB::raw('box_num - '.$vv['num'])
  471. ]);
  472. if($vv['box_type'] == 1){
  473. // $ext_1 = $v['product_no'];//产品编号
  474. // $ext_2 = $v['technology_material']; //工艺材质
  475. // $ext_3 = $v['technology_name'];//工艺名称
  476. // $ext_4 = $v['wood_name'];//木皮
  477. // $ext_5 = $v['process_mark'];//工艺备注
  478. // toDO 有问题
  479. OrdersProduct::where('product_no',$vv['ext_1'])->where('technology_material',$vv['ext_2'])->where('technology_name',$vv['ext_3'])->where('wood_name',$vv['ext_4'])->where('process_mark',$vv['ext_5'])->where('sale_orders_product_id',$vv['top_id'])
  480. ->update([
  481. 'box_num' => DB::raw('box_num - '.$vv['num'])
  482. ]);
  483. }
  484. }
  485. }
  486. return [true,'删除成功'];
  487. }
  488. public function boxAdd($data)
  489. {
  490. list($status,$msg) = $this->boxAddRule($data);
  491. if(! $status) return [false,$msg];
  492. try{
  493. DB::beginTransaction();
  494. $box = new Box();
  495. $box->order_no = $msg['order_no'];
  496. $box->save();
  497. DB::table('box_detail')->insert($msg['detail']);
  498. DB::commit();
  499. return [true,''];
  500. }catch (\Exception $e){
  501. DB::rollBack();
  502. return [false,$e->getLine().':'.$e->getMessage()];
  503. }
  504. }
  505. public function boxAddRule($data)
  506. {
  507. if(empty($data['param'])) return [false,'请选择包装数据'];
  508. $order_no = (new BoxHookService())->setOrderNo();
  509. $detail = [];
  510. foreach ($data['param'] as $value) {
  511. $key = $this->lock_key.'_'.$value['idlsid'];
  512. list($status,$msg) = $this->limitingSendRequestBackg($key);
  513. if(! $status) return [false,$msg];
  514. // if(empty($value['submit_quantity']) || ! is_numeric($value['submit_quantity']) || $value['submit_quantity'] > $value['quantity']) return [false,'包装数量错误'];
  515. if(empty($value['team_id'])) return [false,'班组必须选择'];
  516. $tmp = $value;
  517. $tmp['iquantity'] = $value['submit_quantity'];
  518. $detail[] = [
  519. 'order_no' => $order_no,
  520. 'out_order_no' => $value['csocode']??'',
  521. 'crt_time' => time(),
  522. 'upd_time' => time(),
  523. 'type' => 1,
  524. 'ext_1' => $value['cinvcode'],
  525. 'ext_2' => $value['technology_material'],
  526. 'ext_3' => $value['cfree1'] ?? "",
  527. 'ext_4' => $value['cfree2'] ?? "",
  528. 'ext_5' => $value['process_mark'],
  529. 'ext_6' => $value['customer_name'] ?? "",
  530. 'ext_7' => $value['cuscode'] ?? "",
  531. 'ext_8' => $value['product_title'],
  532. 'ext_9' => $value['product_size'],
  533. 'ext_10' => $value['table_header_mark'],
  534. 'ext_11' => $value['table_body_mark'],
  535. 'top_id' => $value['idlsid'],
  536. 'state' => 0,
  537. 'num' => $value['submit_quantity'],
  538. 'box_type' => 2,
  539. 'team_id' => $value['team_id'],
  540. 'shipment_order_no' => $value['cdlcode'],
  541. 'post' => json_encode($tmp),
  542. ];
  543. }
  544. return [true,['order_no' => $order_no, 'detail' => $detail]];
  545. }
  546. public function boxFhDetail($data){
  547. if(empty($data['idlsid'])) return [false,'请选择数据'];
  548. $result = DB::table('box_detail')->where('del_time',0)
  549. ->where('top_id',$data['idlsid'])
  550. ->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')
  551. ->get()->toArray();
  552. if(! empty($result)){
  553. foreach ($result as $key => $value){
  554. $result[$key] = (array)$value;
  555. }
  556. }
  557. return [true,$result];
  558. }
  559. public function boxFhDel($data){
  560. if(empty($data['order_nos'])) return [false,'包装单号不能为空'];
  561. $box = Box::whereIn('order_no',$data['order_nos'])->update(['del_time' => time()]);
  562. DB::table('box_detail')->whereIn('order_no',$data['order_nos'])->where('del_time',0)->update([
  563. 'del_time' => time()
  564. ]);
  565. return [true,''];
  566. }
  567. public function transportDetail($data){
  568. if(empty($data['order_nos'])) return [false,'包装单号不能为空'];
  569. $order_nos = $data['order_nos'];
  570. $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();
  571. foreach ($list as &$v){
  572. $v['product_no'] = $v['ext_1'];
  573. $v['technology_material'] = $v['ext_2'];
  574. $v['technology_name'] = $v['ext_3'];
  575. $v['wood_name'] = $v['ext_4'];
  576. $v['process_mark'] = $v['ext_5'];
  577. $v['customer_no'] = $v['ext_6'];
  578. $v['customer_name'] = $v['ext_7'];
  579. $v['product_title'] = $v['ext_8'];
  580. $v['product_size'] = $v['ext_9'];
  581. $v['post'] = json_decode($v['post'],true);
  582. }
  583. return [200,$list];
  584. }
  585. public function boxFhBzDetail($data){
  586. if(empty($data['order_no'])) return [false,'请选择包装单数据'];
  587. $result = DB::table('box_detail')->where('del_time',0)
  588. ->whereIn('order_no',$data['order_no'])
  589. ->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')
  590. ->get()->toArray();
  591. if(! empty($result)){
  592. foreach ($result as $key => $value){
  593. $result[$key] = (array)$value;
  594. }
  595. $map = Team::where('id',array_unique(array_column($result,'team_id')))->pluck('title','id')->toArray();
  596. foreach ($result as $key => $value){
  597. $result[$key]['team_name'] = $map[$value['team_id']] ?? '';
  598. }
  599. }
  600. return [true,$result];
  601. }
  602. public function boxFhBzList($data){
  603. if(empty($data['shipment_order_no'])) return [false, '请输入发货单号'];
  604. $model = DB::table('box_detail')->where('del_time',0)
  605. ->where('shipment_order_no','LIKE', '%'.$data['shipment_order_no'].'%')
  606. ->select('order_no','crt_time','shipment_order_no');
  607. $return = [];
  608. $result = $model->get()->toArray();
  609. if(! empty($result)){
  610. foreach ($result as $value){
  611. $return[$value->order_no] = [
  612. 'order_no' => $value->order_no,
  613. 'shipment_order_no' => $value->shipment_order_no,
  614. 'crt_time' => date("Y-m-d H:i:s",$value->crt_time)
  615. ];
  616. }
  617. }
  618. return [true,array_values($return)];
  619. }
  620. }