gate("库存管理-补货列表"); $customer = $request->input('customer'); if (!$customer) $this->error('请选择指定货主!'); $orders = $this->getOrders($customer); $orders = array_filter($orders,function($item){ return $item['amount'] > 0; }); if (count($orders) > 0) $this->success($orders); else $this->error('未查询到相应信息!'); } public function index(Request $request) { $this->gate("库存管理-补货列表"); /** @var UserService $userService */ $userService = app('UserService'); $owners = Owner::query()->whereIn('id', $userService->getPermittingOwnerIds(auth()->user()))->get(); return view('inventory.stockOut.index', compact('owners')); } public function export(Request $request) { $this->gate("库存管理-补货列表"); $customer = $request->input('customer'); $orders = array_filter($this->getOrders($customer),function($item){ return $item['amount'] > 0; }); $row = [ '货主', '商品名称', '商品条码', '拣货库位', '缺货数', '存储库位', '数量', '批次号' ]; $json = []; foreach ($orders as $order) { $eaLocation = ''; $rsLocation = ''; $qty = ''; $lot = ''; foreach ($order['eaLocation'] as $v) { $eaLocation .= $v . "\r\n"; } foreach ($order['rsLocation'] as $v) { $rsLocation .= $v['location'] ."\r\n"; } foreach ($order['rsLocation'] as $v) { $qty .= $v['qty'] ."\r\n"; } foreach ($order['rsLocation'] as $v) { $lot .= $v['lot'] ."\r\n"; } $data = [ $order['customerid'], $order['sku'], $order['alternate_sku1'], $eaLocation, $order['amount'], $rsLocation, $qty, $lot, ]; $json[] = $data; } return Export::make($row, $json, "库存管理-补货列表"); } /** * @param $customer * @return array */ private function getOrders($customer): array { /** @var ReplenishmentService $service */ $service = app('ReplenishmentService'); $orders = $service->getOrderInfoRecentMonthByCustomer($customer); $skuArr = array_diff(array_unique(data_get($orders, '*.sku')), ['', '*', null]); $info = $service->getEaInventoryByCustomerAndSku($customer, $skuArr); $rsInfo = $service->getRsInventoryByCustomerAndSku($customer, $skuArr); //将整合后拣货位信息 结合订单汇总 foreach ($orders as &$order) { if (isset($info[$order['sku']])) { $item = $info[$order['sku']]; $order['amount'] = ($order['amount'] - $item['qty']); $order['eaLocation'] = $item['locationid']; } else { $order['eaLocation'] = []; } if (isset($rsInfo[$order['sku']])) { $rsItem = $rsInfo[$order['sku']]; $order['rsLocation'] = $rsItem['locationid']; } else { $order['rsLocation'] = []; } } return $orders; } }