ReplenishmentController.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Components\AsyncResponse;
  4. use App\Services\ReplenishmentService;
  5. use Illuminate\Http\Request;
  6. class ReplenishmentController extends Controller
  7. {
  8. use AsyncResponse;
  9. public function getReplenishmentInfoByCustomer(Request $request)
  10. {
  11. $this->gate("库存管理-补货列表");
  12. $customer=$request->input('customer');
  13. if (!$customer)$this->error('请选择指定货主!');
  14. /** @var ReplenishmentService $service */
  15. $service = app('ReplenishmentService');
  16. $orders=$service->getOrderInfoRecentMonthByCustomer($customer);
  17. $skuArr=array_diff(array_unique(data_get($orders, '*.sku')), ['', '*', null]);
  18. $info=$service->getEaInventoryByCustomerAndSku($customer,$skuArr);
  19. $rsInfo=$service->getRsInventoryByCustomerAndSku($customer,$skuArr);
  20. //将整合后拣货位信息 结合订单汇总
  21. foreach ($orders as &$order){
  22. if(isset($info[$order['sku']])){
  23. $item = $info[$order['sku']];
  24. $order['amount']=($order['amount']-$item['qty']);
  25. $order['eaLocation']=$item['locationid'];
  26. }else{
  27. $order['eaLocation']=[];
  28. }
  29. if(isset($rsInfo[$order['sku']])){
  30. $rsItem = $rsInfo[$order['sku']];
  31. $order['rsLocation']=$rsItem['locationid'];
  32. }else{
  33. $order['rsLocation']=[];
  34. }
  35. }
  36. if (count($orders)>0)$this->success($orders);
  37. else $this->error('未查询到相应信息!');
  38. }
  39. }