log = new LogModel([ 'module' => 'supplier', 'action' => $request->getMethod(), 'target_type' => 'dailyStockRecord', ]); } public function index(Request $request) { $build = DailyStockRecord::query()->filter()->with("goodsSku:id,name,title"); if (!empty($request->title)) { $build->whereHas('goodsSku', function ($query) use ($request) { $query->where('name', 'like', '%' . $request->title . '%'); }); } if (!empty($request->get('external_sku_id'))) { $build->whereHas('goodsSku', function ($query) use ($request) { $query->where('external_sku_id', '=', $request->external_sku_id); }); } $dailyStockRecord = $build->paginate($request->get('per_page')); return JsonResource::collection($dailyStockRecord); } /** * @param Request $request * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response */ public function store(Request $request) { $validator = Validator::make($request->all(), [ 'external_sku_id' => 'required|string', 'inventory' => 'required|integer', ]); if ($validator->fails()) { //校验失败返回异常 $this->setValidatorFailResponse($validator->getMessageBag()->getMessages()); return response($this->res, $this->res['httpCode']); } $goodsSku = GoodsSku::query()->with("combinationGoods")->where('external_sku_id', "=", $request->external_sku_id)->first(); if (empty($goodsSku)) { $this->res = [ 'httpCode' => 400, 'message' => '查询不到sku信息', 'errorCode' => "ERP001", 'errorMessage' => '查询不到sku信息', ]; return response($this->res, $this->res['httpCode']); } $goodsSkuWithInventory = array_merge($goodsSku->toArray(),["inventory"=>$request->inventory]); //同批量逻辑操作 $goodSkuService = new GoodSkuService(); $goodSkuService->inventory([$goodsSkuWithInventory]); return response($this->res, $this->res['httpCode']); } public function inventoryImport(Request $request) { if (!$request->hasFile('inventoryFile')) { $this->res = [ 'httpCode' => 404, 'errorCode' => 404404, 'errorMessage' => 'not found inventory file', ]; } try { $import = new InventoryImport(); $path = $request->file('inventoryFile'); Excel::import($import, $path); $this->addLog(0, 'import', 'inventory'); } catch (ValidationException $exception) { $this->setValidatorFailResponse($exception->validator->getMessageBag()->getMessages()); } return response($this->res, $this->res['httpCode']); } }