ConstructionService.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. <?php
  2. namespace App\Service;
  3. use App\Model\BasicType;
  4. use App\Model\Construction;
  5. use App\Model\ConstructionInfo;
  6. use App\Model\ConstructionProductInfo;
  7. use App\Model\Customer;
  8. use App\Model\Employee;
  9. use App\Model\SalesOrder;
  10. use App\Model\SalesOrderInfo;
  11. use App\Model\SalesOrderProductInfo;
  12. use App\Model\Storehouse;
  13. use Illuminate\Support\Facades\DB;
  14. /**
  15. * 施工订单
  16. */
  17. class ConstructionService extends Service
  18. {
  19. /**
  20. * 施工订单编辑
  21. * @param $data
  22. * @param $user
  23. * @return array
  24. */
  25. public function constructionEdit($data,$user){
  26. list($status,$msg) = $this->constructionRule($data, $user, false);
  27. if(!$status) return [$status,$msg];
  28. try {
  29. DB::beginTransaction();
  30. $model = Construction::where('id', $data['id'])->first();
  31. $model->model_type = $data['model_type'];
  32. $model->order_number = $data['order_number'];
  33. $model->title = $data['title'] ?? '';
  34. $model->customer_id = $data['customer_id'] ?? 0;
  35. $model->customer_contact_id = $data['customer_contact_id'] ?? 0;
  36. $model->install_method = $data['install_method'] ?? 0;
  37. $model->install_position = $data['install_position'] ?? '';
  38. $model->sales_order_id = $data['sales_order_id'] ?? 0;
  39. $model->construction_fee = $data['construction_fee'] ?? 0;
  40. $model->service_price = $data['service_price'] ?? 0;
  41. $model->construction_time = $data['construction_time'] ?? 0;
  42. $model->handover_time = $data['handover_time'] ?? 0;
  43. $model->urgency = $data['urgency'] ?? 0;
  44. $model->mark = $data['mark'] ?? '';
  45. $model->address1 = ! empty($data['address1']) ? json_encode($data['address1']) : '';
  46. $model->address2 = $data['address2'] ?? '';
  47. $model->introduction = $data['introduction'] ?? '';
  48. $model->storehouse_id = $data['storehouse_id'] ?? 0;
  49. $model->save();
  50. $time = time();
  51. ConstructionInfo::where('del_time',0)
  52. ->where('construction_id',$data['id'])
  53. ->update(['del_time' => $time]);
  54. ConstructionProductInfo::where('del_time',0)
  55. ->where('construction_id',$data['id'])
  56. ->update(['del_time' => $time]);
  57. if(! empty($data['construction_contact'])){
  58. $insert = [];
  59. foreach ($data['construction_contact'] as $value){
  60. $insert[] = [
  61. 'construction_id' => $model->id,
  62. 'contact_type' => $value['id'],
  63. 'contact_info' => $value['info'],
  64. 'type' => ConstructionInfo::type_one,
  65. 'crt_time' => $time,
  66. ];
  67. }
  68. ConstructionInfo::insert($insert);
  69. }
  70. if(! empty($data['employee_one'])){
  71. $insert = [];
  72. foreach ($data['employee_one'] as $value){
  73. $insert[] = [
  74. 'construction_id' => $model->id,
  75. 'employee_id' => $value,
  76. 'type' => ConstructionInfo::type_two,
  77. 'crt_time' => $time,
  78. ];
  79. }
  80. ConstructionInfo::insert($insert);
  81. }
  82. if(! empty($data['product'])){
  83. $insert = [];
  84. foreach ($data['product'] as $value){
  85. $insert[] = [
  86. 'construction_id' => $model->id,
  87. 'product_id' => $value['product_id'],
  88. 'number' => $value['number'],
  89. 'cost' => $value['cost'] ?? 0,
  90. 'retail_price' => $value['retail_price'] ?? 0,
  91. 'mark' => $value['mark'] ?? '',
  92. 'crt_time' => $time,
  93. 'storehouse_id' => $data['storehouse_id'] ?? 0,
  94. 'basic_type_id' => $value['basic_type_id'],
  95. 'price' => $value['price'],
  96. 'final_amount' => $value['final_amount'] ?? 0,
  97. ];
  98. }
  99. ConstructionProductInfo::insert($insert);
  100. //锁定库存
  101. ProductInventoryService::changeLockNumber($user,$msg[0],$msg[1]);
  102. }
  103. DB::commit();
  104. }catch (\Exception $exception){
  105. DB::rollBack();
  106. return [false,$exception->getMessage()];
  107. }
  108. return [true,''];
  109. }
  110. /**
  111. * 施工订单新增
  112. * @param $data
  113. * @param $user
  114. * @return array
  115. */
  116. public function constructionAdd($data,$user){
  117. list($status,$msg) = $this->constructionRule($data,$user);
  118. if(!$status) return [$status,$msg];
  119. try {
  120. DB::beginTransaction();
  121. $model = new Construction();
  122. $model->model_type = $data['model_type'];
  123. $model->order_number = $data['order_number'];
  124. $model->title = $data['title'] ?? '';
  125. $model->customer_id = $data['customer_id'] ?? 0;
  126. $model->customer_contact_id = $data['customer_contact_id'] ?? 0;
  127. $model->install_method = $data['install_method'] ?? 0;
  128. $model->install_position = $data['install_position'] ?? '';
  129. $model->sales_order_id = $data['sales_order_id'] ?? 0;
  130. $model->construction_fee = $data['construction_fee'] ?? 0;
  131. $model->service_price = $data['service_price'] ?? 0;
  132. $model->construction_time = $data['construction_time'] ?? 0;
  133. $model->handover_time = $data['handover_time'] ?? 0;
  134. $model->urgency = $data['urgency'] ?? 0;
  135. $model->mark = $data['mark'] ?? '';
  136. $model->address1 = ! empty($data['address1']) ? json_encode($data['address1']) : '';
  137. $model->address2 = $data['address2'] ?? '';
  138. $model->introduction = $data['introduction'] ?? '';
  139. $model->crt_id = $user['id'];
  140. $model->depart_id = $data['depart_id'] ?? 0;
  141. $model->top_depart_id = $data['top_depart_id'] ?? 0;
  142. $model->storehouse_id = $data['storehouse_id'] ?? 0;
  143. $model->save();
  144. $time = time();
  145. if(! empty($data['construction_contact'])){
  146. $insert = [];
  147. foreach ($data['construction_contact'] as $value){
  148. $insert[] = [
  149. 'construction_id' => $model->id,
  150. 'contact_type' => $value['id'],
  151. 'contact_info' => $value['info'],
  152. 'type' => ConstructionInfo::type_one,
  153. 'crt_time' => $time,
  154. ];
  155. }
  156. ConstructionInfo::insert($insert);
  157. }
  158. if(! empty($data['employee_one'])){
  159. $insert = [];
  160. foreach ($data['employee_one'] as $value){
  161. $insert[] = [
  162. 'construction_id' => $model->id,
  163. 'employee_id' => $value,
  164. 'type' => ConstructionInfo::type_two,
  165. 'crt_time' => $time,
  166. ];
  167. }
  168. ConstructionInfo::insert($insert);
  169. }
  170. if(! empty($data['product'])){
  171. $insert = [];
  172. foreach ($data['product'] as $value){
  173. $insert[] = [
  174. 'construction_id' => $model->id,
  175. 'product_id' => $value['product_id'],
  176. 'number' => $value['number'],
  177. 'cost' => $value['cost'] ?? 0,
  178. 'retail_price' => $value['retail_price'] ?? 0,
  179. 'mark' => $value['mark'] ?? '',
  180. 'crt_time' => $time,
  181. 'storehouse_id' => $data['storehouse_id'] ?? 0,
  182. 'basic_type_id' => $value['basic_type_id'],
  183. 'price' => $value['price'],
  184. 'final_amount' => $value['final_amount'] ?? 0,
  185. ];
  186. }
  187. ConstructionProductInfo::insert($insert);
  188. //锁定库存
  189. ProductInventoryService::changeLockNumber($user,$msg[0],[]);
  190. }
  191. DB::commit();
  192. }catch (\Exception $exception){
  193. DB::rollBack();
  194. return [false,$exception->getMessage()];
  195. }
  196. return [true,''];
  197. }
  198. /**
  199. * 施工订单删除
  200. * @param $data
  201. * @return array
  202. */
  203. public function constructionDel($data,$user){
  204. if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
  205. $construction = Construction::where('del_time',0)->where('id',$data['id'])->first();
  206. if(empty($construction)) return [false,'施工单不存在或已被删除'];
  207. $construction = $construction->toArray();
  208. if($construction['state'] > Construction::STATE_ZERO) return [false,'请确认施工单状态,操作失败'];
  209. $product_save = $this->getSaveDetail($data['id']);
  210. try {
  211. DB::beginTransaction();
  212. Construction::where('id',$data['id'])->update([
  213. 'del_time'=> time()
  214. ]);
  215. ConstructionInfo::where('del_time',0)
  216. ->where('construction_id',$data['id'])
  217. ->update(['del_time' => time()]);
  218. ConstructionProductInfo::where('del_time',0)
  219. ->where('construction_id',$data['id'])
  220. ->update(['del_time' => time()]);
  221. //锁定库存释放
  222. ProductInventoryService::changeLockNumber($user,[],$product_save);
  223. DB::commit();
  224. }catch (\Exception $exception){
  225. DB::rollBack();
  226. return [false,$exception->getMessage()];
  227. }
  228. return [true,''];
  229. }
  230. /**
  231. * 施工订单详情
  232. * @param $data
  233. * @return array
  234. */
  235. public function constructionDetail($data){
  236. if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
  237. $construction = Construction::where('del_time',0)
  238. ->where('id',$data['id'])
  239. ->first();
  240. if(empty($construction)) return [false,'施工订单不存在或已被删除'];
  241. $construction = $construction->toArray();
  242. $address = '';
  243. if(! empty($construction['address1'])) {
  244. $tmp = json_decode($construction['address1'],true);
  245. $construction['address1'] = $tmp;
  246. $tmp = implode(' ',$tmp);
  247. $tmp .= ' ' . $construction['address2'];
  248. $address = $tmp;
  249. }
  250. $construction['address'] = $address;
  251. $sales = SalesOrder::where('id',$construction['sales_order_id'])->value('order_number');
  252. $construction['sales_order_number'] = $sales;
  253. $customer_title = Customer::where('id',$construction['customer_id'])->value('title');
  254. $construction['customer_title'] = $customer_title;
  255. $construction['storehouse_title'] = Storehouse::where('id',$construction['storehouse_id'])->value('title');
  256. $emp_title = Employee::where('id',$construction['customer_contact_id'])->value('emp_name');
  257. $construction['customer_contact_title'] = $emp_title;
  258. $construction['employee_one'] = $construction['construction_contact'] = $construction['product'] = [];
  259. $array = [
  260. $construction['install_method'],
  261. $construction['urgency'],
  262. ];
  263. $basic_map = BasicType::whereIn('id',$array)
  264. ->pluck('title','id')
  265. ->toArray();
  266. $construction = [$construction];
  267. foreach ($construction as $key => $value){
  268. $construction[$key]['install_method_title'] = $basic_map[$value['install_method']] ?? '';
  269. $construction[$key]['urgency_title'] = $basic_map[$value['urgency']] ?? '';
  270. }
  271. $construction = $construction[0];
  272. $construction_info = ConstructionInfo::where('del_time',0)
  273. ->where('construction_id',$construction['id'])
  274. ->select('id','construction_id','employee_id','type','contact_type','contact_info')
  275. ->get()->toArray();
  276. $emp_map = Employee::whereIn('id',array_unique(array_merge_recursive([$construction['crt_id']],array_column($construction_info,'employee_id'))))
  277. ->pluck('emp_name','id')
  278. ->toArray();
  279. $basic_map2 = BasicType::whereIn('id',array_unique(array_column($construction_info,'contact_type')))
  280. ->pluck('title','id')
  281. ->toArray();
  282. foreach ($construction_info as $value){
  283. if($value['type'] == ConstructionInfo::type_one){
  284. $tmp = [
  285. 'id' => $value['contact_type'],
  286. 'title' => $basic_map2[$value['contact_type']] ?? '',
  287. 'info' => $value['contact_info']
  288. ];
  289. $construction['construction_contact'][] = $tmp;
  290. }elseif ($value['type'] == ConstructionInfo::type_two){
  291. $tmp = [
  292. 'id' => $value['employee_id'],
  293. 'name' => $emp_map[$value['employee_id']] ?? '',
  294. ];
  295. $construction['employee_one'][] = $tmp;
  296. }
  297. }
  298. $p_info = ConstructionProductInfo::where('del_time',0)
  299. ->where('construction_id',$construction['id'])
  300. ->get()->toArray();
  301. $basic_price = BasicType::whereIn('id',array_unique(array_column($p_info,'basic_type_id')))->pluck('title','id')->toArray();
  302. $map = (new ProductService())->getProductDetail(array_column($p_info,'product_id'));
  303. foreach ($p_info as $value){
  304. $tmp = $map[$value['product_id']] ?? [];
  305. $value['title'] = $tmp['title'] ?? "";
  306. $value['code'] = $tmp['code'] ?? "";
  307. $value['size'] = $tmp['size'] ?? "";
  308. $value['unit'] = $tmp['unit'] ?? "";
  309. $value['bar_code'] = $tmp['bar_code'] ?? "";
  310. $value['basic_type_title'] = $basic_price[$value['basic_type_id']] ?? "";
  311. $construction['product'][] = $value;
  312. }
  313. $construction['crt_name'] = $emp_map[$construction['crt_id']] ?? '';
  314. $construction['crt_time'] = $construction['crt_time'] ? date("Y-m-d H:i:s",$construction['crt_time']): '';
  315. return [true, $construction];
  316. }
  317. /**
  318. * 施工订单列表
  319. * @param $data
  320. * @param $user
  321. * @return array
  322. */
  323. public function constructionList($data,$user){
  324. $model = new Construction(['userData' => $user, 'search' => $data]);
  325. $model = $model->where('del_time',0)
  326. ->select('title','id','model_type','order_number','customer_id','customer_contact_id','install_method','install_position','sales_order_id','construction_fee','construction_time','handover_time','urgency','crt_id','crt_time','mark','state','address1','address2','introduction','service_price','storehouse_id')
  327. ->orderby('id', 'desc');
  328. if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
  329. if(! empty($data['model_type'])) $model->where('model_type',$data['model_type']);
  330. if(! empty($data['time_type'])) {
  331. if($data['time_type'] == 1) {
  332. $start = strtotime('today');
  333. $end = strtotime('tomorrow') - 1;
  334. }elseif ($data['time_type'] == 2){
  335. $start = strtotime('this week',strtotime('today'));
  336. $end = strtotime('this week +6 days 23:59:59', strtotime('today'));
  337. }
  338. if(! empty($start) && ! empty($end)) {
  339. $model->where('crt_time','>=',$start);
  340. $model->where('crt_time','<=',$end);
  341. }
  342. }
  343. $list = $this->limit($model,'',$data);
  344. $list = $this->fillData($list);
  345. return [true, $list];
  346. }
  347. /**
  348. * 参数规则
  349. * @param $data
  350. * @param $user
  351. * @param $is_add
  352. * @return array
  353. */
  354. public function constructionRule(&$data, $user, $is_add = true){
  355. if(empty($data['model_type'])) return [false,'工单模板类型不能为空'];
  356. if(! in_array($data['model_type'],Construction::$model_type)) return [false,'工单模板类型错误'];
  357. if(empty($data['order_number'])) return [false,'工单编号不能为空'];
  358. if(empty($data['storehouse_id'])) return [false,'请选择仓库'];
  359. if(empty($data['sales_order_id'])) return [false,'请选择合同'];
  360. $sale = SalesOrder::where('del_time',0)->where('id',$data['sales_order_id'])->first();
  361. if(empty($sale)) return [false,'合同不存在或已被删除'];
  362. if($sale['state'] < SalesOrder::State_two) return [false,'合同未派单,不允许新建施工单'];
  363. if(empty($data['product'])) return [false,'请选择产品'];
  364. if(! empty($data['construction_fee'])){
  365. $res = $this->checkNumber($data['construction_fee']);
  366. if(! $res) return [false,'施工费用请输入不超过两位小数并且大于0的数值'];
  367. }
  368. if(! empty($data['service_price'])){
  369. $res = $this->checkNumber($data['service_price']);
  370. if(! $res) return [false,'服务价格请输入不超过两位小数并且大于0的数值'];
  371. }
  372. if(! empty($data['construction_time'])) $data['construction_time'] = $this->changeDateToDateMin($data['construction_time']);
  373. if(! empty($data['handover_time'])) $data['handover_time'] = $this->changeDateToDateMin($data['handover_time']);
  374. if($data['model_type'] == Construction::Model_type_one){
  375. if(empty($data['install_method'])) return [false,'安装方式不能为空'];
  376. if(empty($data['install_position'])) return [false,'安装地点不能为空'];
  377. }else{
  378. if(empty($data['construction_contact'])) return [false,'联系方式不能为空'];
  379. if(empty($data['address1']) || empty($data['address2'])) return [false,'地址不能为空'];
  380. }
  381. //所属部门 以及 顶级部门
  382. if(empty($data['depart_id'])) $data['depart_id'] = $this->getDepart($user);
  383. $data['top_depart_id'] = $user['depart_map'][$data['depart_id']] ?? 0;
  384. $product_submit = $product_id = [];
  385. foreach ($data['product'] as $value){
  386. if(empty($value['number'])) return [false,'产品数量不能为空'];
  387. $res = $this->checkNumber($value['number']);
  388. if(! $res) return [false,'请输入正确的产品数量'];
  389. $key = $value['product_id'] . ',' .$data['storehouse_id'];
  390. if(isset($product_submit[$key])){
  391. $product_submit[$key] += $value['number'];
  392. }else{
  393. $product_submit[$key] = $value['number'];
  394. }
  395. $product_id[] = $value['product_id'];
  396. }
  397. //剩余能施工
  398. $id = $data['id'] ?? 0;
  399. $s_product = $this->getSaveReturnCompareMessage($id, $data['sales_order_id']);
  400. //比较
  401. foreach ($product_submit as $pro => $number){
  402. $tmp = explode(',',$pro);
  403. $p = $tmp[0];
  404. if(! isset($s_product[$p])) return [false,'施工产品错误,合同中不存在该产品'];
  405. $s_number = $s_product[$p];
  406. if($number > $s_number) return [false,'施工产品数量不能超过合同产品数据'];
  407. }
  408. $id = $data['id'] ?? 0;
  409. $product_save = $this->getSaveDetail($id);
  410. list($status,$msg) = (new ProductInventoryService())->compareStock($user,$product_id, $product_submit, $product_save);
  411. if(! $status) return [false, $msg];
  412. if($is_add){
  413. $bool = Construction::where('del_time',0)->where('order_number',$data['order_number'])->exists();
  414. if($bool) return [false,'工单编号已存在,请重新获取'];
  415. }else{
  416. if(empty($data['id'])) return [false,'ID不能为空'];
  417. }
  418. return [true, [$product_submit, $product_save]];
  419. }
  420. /**
  421. * 数据拼接
  422. * @param $data
  423. * @return array
  424. */
  425. public function fillData($data){
  426. if(empty($data['data'])) return $data;
  427. $array = array_unique(array_merge_recursive(array_column($data['data'],'install_method'),array_column($data['data'],'urgency')));
  428. $basic_map = BasicType::whereIn('id',$array)
  429. ->pluck('title','id')
  430. ->toArray();
  431. $emp = Employee::whereIn('id',array_unique(array_merge_recursive(array_column($data['data'],'crt_id'),array_column($data['data'],'customer_contact_id'))))
  432. ->pluck('emp_name','id')
  433. ->toArray();
  434. $customer = Customer::whereIn('id',array_unique(array_column($data['data'],'customer_id')))
  435. ->pluck('title','id')
  436. ->toArray();
  437. $sales = SalesOrder::whereIn('id',array_unique(array_column($data['data'],'sales_order_id')))->pluck('order_number','id')->toArray();
  438. $storehouse = Storehouse::whereIn('id',array_unique(array_column($data['data'],'storehouse_id')))
  439. ->pluck('title','id')
  440. ->toArray();
  441. foreach ($data['data'] as $key => $value){
  442. $address = '';
  443. if(! empty($value['address1'])) {
  444. $tmp = json_decode($value['address1'],true);
  445. $tmp = implode(' ',$tmp);
  446. $tmp .= ' ' . $value['address2'];
  447. $address = $tmp;
  448. }
  449. $data['data'][$key]['address'] = $address;
  450. $data['data'][$key]['install_method_title'] = $basic_map[$value['install_method']] ?? '';
  451. $data['data'][$key]['urgency_title'] = $basic_map[$value['urgency']] ?? '';
  452. $data['data'][$key]['customer_title'] = $customer[$value['customer_id']] ?? '';
  453. $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d H:i:s',$value['crt_time']) : '';
  454. $data['data'][$key]['crt_name'] = $emp[$value['crt_id']] ?? '';
  455. $data['data'][$key]['customer_contact_title'] = $emp[$value['customer_contact_id']] ?? '';
  456. $data['data'][$key]['state_title'] = Construction::$name[$value['state']] ?? '';
  457. $data['data'][$key]['sales_order_number'] = $sales[$value['sales_order_id']] ?? '';
  458. $data['data'][$key]['storehouse_title'] = $storehouse[$value['storehouse_id']] ?? '';
  459. }
  460. return $data;
  461. }
  462. /**
  463. * 获取施工单号
  464. * @param $data
  465. * @return array
  466. */
  467. public function constructionGet($data){
  468. if(empty($data['model_type'])) return [false,'工单模板类型不能为空'];
  469. if(! isset(Construction::$prefix[$data['model_type']])) return [false,'工单模板类型错误'];
  470. $prefix = Construction::$prefix[$data['model_type']];
  471. $order_number = OrderNoService::createConstructionOrderNumber($prefix);
  472. if(! $order_number) return [false,'工单编号生成失败!'];
  473. return [true,['order_number' => $order_number]];
  474. }
  475. /**
  476. * 获取保存详情
  477. * @param $id
  478. * @return array
  479. */
  480. public function getSaveDetail($id){
  481. $product_save = [];
  482. if(empty($id)) return $product_save;
  483. $sub = ConstructionProductInfo::where('construction_id',$id)
  484. ->where('del_time',0)
  485. ->get()->toArray();
  486. foreach ($sub as $value){
  487. $key = $value['product_id'] . ',' . $value['storehouse_id'];
  488. if(isset($product_save[$key])){
  489. $product_save[$key] += $value['number'];
  490. }else{
  491. $product_save[$key] = $value['number'];
  492. }
  493. }
  494. return $product_save;
  495. }
  496. public function getSaveReturnCompareMessage($id = 0, $sales_order_id = 0){
  497. $product_save = [];
  498. $sub = ConstructionProductInfo::where('del_time',0)
  499. ->when(! empty($id), function ($query) use ($id) {
  500. return $query->where('construction_id', '<>',$id);
  501. })
  502. ->get()->toArray();
  503. foreach ($sub as $value){
  504. if(isset($product_save[$value['product_id']])){
  505. $product_save[$value['product_id']] += $value['number'];
  506. }else{
  507. $product_save[$value['product_id']] = $value['number'];
  508. }
  509. }
  510. $sales_order_product = [];
  511. $sales_product = SalesOrderProductInfo::where('del_time',0)
  512. ->where('sales_order_id',$sales_order_id)
  513. ->get()->toArray();
  514. foreach ($sales_product as $value){
  515. $product_save_tmp = $product_save[$value['product_id']] ?? 0;
  516. if(isset($sales_order_product[$value['product_id']])){
  517. $sales_order_product[$value['product_id']] += $value['number'];
  518. }else{
  519. $sales_order_product[$value['product_id']] = $value['number'] - $product_save_tmp;
  520. }
  521. }
  522. return $sales_order_product;
  523. }
  524. }