BoxService.php 28 KB

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