|
|
@@ -3,8 +3,10 @@
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
use App\Components\AsyncResponse;
|
|
|
+use App\Owner;
|
|
|
use App\Services\ReplenishmentService;
|
|
|
use Illuminate\Http\Request;
|
|
|
+use Oursdreams\Export\Export;
|
|
|
|
|
|
class ReplenishmentController extends Controller
|
|
|
{
|
|
|
@@ -13,34 +15,97 @@ class ReplenishmentController extends Controller
|
|
|
public function getReplenishmentInfoByCustomer(Request $request)
|
|
|
{
|
|
|
$this->gate("库存管理-补货列表");
|
|
|
- $customer=$request->input('customer');
|
|
|
- if (!$customer)$this->error('请选择指定货主!');
|
|
|
+ $customer = $request->input('customer');
|
|
|
+ if (!$customer) $this->error('请选择指定货主!');
|
|
|
+ $orders = $this->getOrders($customer);
|
|
|
+ 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 = '';
|
|
|
+ foreach ($order['eaLocation'] as $v) {
|
|
|
+ $eaLocation .= $v . ",\r\n";
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($order['rsLocation'] as $v) {
|
|
|
+ $rsLocation .= $v . ",\r\n";
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = [
|
|
|
+ $order['customerid'],
|
|
|
+ $order['sku'],
|
|
|
+ $order['alternate_sku1'],
|
|
|
+ $eaLocation,
|
|
|
+ $order['amount'],
|
|
|
+ $rsLocation,
|
|
|
+ ];
|
|
|
+ $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);
|
|
|
+ $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']])){
|
|
|
+ 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']=[];
|
|
|
+ $order['amount'] = ($order['amount'] - $item['qty']);
|
|
|
+ $order['eaLocation'] = $item['locationid'];
|
|
|
+ } else {
|
|
|
+ $order['eaLocation'] = [];
|
|
|
}
|
|
|
- if(isset($rsInfo[$order['sku']])){
|
|
|
+ if (isset($rsInfo[$order['sku']])) {
|
|
|
$rsItem = $rsInfo[$order['sku']];
|
|
|
- $order['rsLocation']=$rsItem['locationid'];
|
|
|
- }else{
|
|
|
- $order['rsLocation']=[];
|
|
|
+ $order['rsLocation'] = $rsItem['locationid'];
|
|
|
+ } else {
|
|
|
+ $order['rsLocation'] = [];
|
|
|
}
|
|
|
}
|
|
|
- if (count($orders)>0)$this->success($orders);
|
|
|
- else $this->error('未查询到相应信息!');
|
|
|
-
|
|
|
-
|
|
|
+ return $orders;
|
|
|
}
|
|
|
}
|