singleton('inventoryAccountService',InventoryAccountService::class); } //创建盘点任务 public function createStockInventoryMission(Request $request){ if(!Gate::allows("库存管理-盘点")){ return redirect(url('/')); } // $date_start=$request->input('formData.date_start'); // $date_end=$request->input('formData.date_end'); // $ownerId=$request->input('formData.owner_id')[0]; $date_start=$request->input('date_start'); $date_end=$request->input('date_end'); $ownerId=$request->input('owner_id'); $inventoryAccount=app('inventoryAccountService')->createMission($date_start,$date_end,$ownerId); $inventoryAccount=InventoryAccount::with('owner')->find($inventoryAccount->id); if (is_null($inventoryAccount)) return ['success'=>false,'data'=>'参数错误!']; return ['success'=>true,'data'=>$inventoryAccount]; } //删除盘点任务 public function deleteStockInventoryMission($id){ if(!Gate::allows('库存管理-盘点')){return['success'=>0,'status'=>'没有权限'];} if(is_null($id)){return ['success'=>false,'data'=>'传入id为空'];} $inventoryAccount=InventoryAccount::where('id',$id)->delete(); return ['success'=>true,'data'=>$inventoryAccount]; } //盘点-任务页面 public function mission(Request $request,OwnerService $ownerService){ if(!Gate::allows("库存管理-盘点")){ return redirect(url('/')); } $paginateParams = $request->input(); $queryParam=$request->all(); $inventoryAccounts=app('inventoryAccountService')->paginate($queryParam); $owners=$ownerService->getSelection(); return view('inventory.stockInventory.mission',compact('owners','inventoryAccounts','paginateParams')); } //进入盘点中或复盘页面 public function enterStockInventory($id,Request $request){ if($request->input('listMode') ?? false){ if (!Gate::allows('库存管理-盘点-查看')){return redirect(url('/')); } }else{ if (!Gate::allows('库存管理-盘点')){return redirect(url('/')); } } if (!$id) return ['success'=>false,'data'=>'参数错误!']; $inventoryAccount=InventoryAccount::with('owner')->find($id); $inventoryAccountMissions=InventoryAccountMission::with(['commodity.barcodes','stockInventoryPersons'])->where('inventory_account_id',$id)->orderBy('difference_amount','desc')->get(); return view('inventory.stockInventory.inventoryMission',compact('inventoryAccount','inventoryAccountMissions')); } //依据盘点任务id进行 --盘点 public function stockInventory(Request $request){ if (!Gate::allows('库存管理-盘点')){return redirect(url('/')); } $location=$request->input('location'); $barcode=$request->input('barcode'); $inventoryId=$request->input('inventoryId'); $count=$request->input('count'); if (is_null($count)) return ['success'=>false,'data'=>'盘点数不能为空!']; /** @var InventoryAccountService $inventoryAccountMission */ $inventoryAccountService=app('inventoryAccountService'); $inventoryAccountMission=$inventoryAccountService->stockInventory($location,$barcode,$count,$inventoryId); if (!$inventoryAccountMission)return ['success'=>false,'data'=>'参数错误!']; /** @var InventoryAccountService $inventoryService */ $inventoryService=app('inventoryAccountService'); $inventoryAccount=$inventoryService->updateInventory($inventoryId); $stockInventoryPersons=$inventoryAccountMission->stockInventoryPersons; return ['success'=>true,'inventoryMission'=>$inventoryAccountMission,'inventory'=>$inventoryAccount,'stockInventoryPersons'=>$stockInventoryPersons]; } //根据该库存和产品条码查询该条盘点记录 public function searchStockInventoryRecord(Request $request){ if (!Gate::allows('库存管理-盘点')){return redirect(url('/')); } $location=$request->input('location'); $barcode=$request->input('barcode'); $inventoryId=$request->input('inventoryId'); $inventoryAccountMission=app('inventoryAccountService')->searchStockInventoryRecord($location,$barcode,$inventoryId); if (!$inventoryAccountMission)return ['success'=>false,'data'=>'参数错误!']; $stockInventoryPersons=$inventoryAccountMission->stockInventoryPersons; return ['success'=>true,'data'=>$inventoryAccountMission,'stockInventoryPersons'=>$stockInventoryPersons]; } //盘点任务导出 public function stockInventoryExport(Request $request){ if (!Gate::allows('库存管理-盘点')){return redirect(url('/')); } ini_set('max_execution_time',3500); ini_set('memory_limit','3526M'); if ($request->checkAllSign){ $request->offsetUnset('checkAllSign'); $queryParam=$request->all(); $inventoryAccounts=app('inventoryAccountService')->get($queryParam); }else{ $queryParam=$request->all(); $inventoryAccounts=app('inventoryAccountService')->some($queryParam); } $row=[[ 'id'=>'盘点编号', 'status'=>'盘点状态', 'created_at'=>'创建时间', 'owner_id'=>'货主', 'type'=>'任务类型', 'start_at'=>'起始时间', 'end_at'=>'结束时间', 'total'=>'记录数', 'processed'=>'已盘数', 'surplus'=>'剩余数', 'difference'=>'复盘差异', 'returned'=>'复盘归位', ]]; $list=[]; for ($i=0; $iisset($inventoryAccount->id)?$inventoryAccount->id:'', 'status'=>isset($inventoryAccount->status)?$inventoryAccount->status:'', 'created_at'=>isset($inventoryAccount->created_at)?$inventoryAccount->created_at:'', 'owner_id'=>isset($inventoryAccount->owner->name)?$inventoryAccount->owner->name:'', 'type'=>isset($inventoryAccount->type)?$inventoryAccount->type:'', 'start_at'=>isset($inventoryAccount->start_at)?$inventoryAccount->start_at:'', 'end_at'=>isset($inventoryAccount->end_at)?$inventoryAccount->end_at:'', 'total'=>isset($inventoryAccount->total)?$inventoryAccount->total:'', 'processed'=>isset($inventoryAccount->processed)?$inventoryAccount->processed:'', 'surplus'=>isset($inventoryAccount->surplus)?$inventoryAccount->surplus:'', 'difference'=>isset($inventoryAccount->difference)?$inventoryAccount->difference:'', 'returned'=>isset($inventoryAccount->returned)?$inventoryAccount->returned:'', ]; $list[$i]=$w; } return Excel::download(new Export($row,$list),date('YmdHis', time()).'-盘点任务记录单.xlsx'); } public function stockInventoryEnd(Request $request){ if (!Gate::allows('库存管理-盘点')){return redirect(url('/')); } $id=$request->input('id'); if (!$id) return ['success'=>false,'data'=>'参数错误!']; $inventoryAccount=InventoryAccount::query()->where('id',$id)->update(['status'=>'复盘中']); $this->log(__METHOD__,'结束初盘任务'.__FUNCTION__,json_encode($request->toArray()),Auth::user()['id']); if ($inventoryAccount>0) return ['success'=>true,'data'=>'复盘中']; return ['success'=>false,'data'=>'参数错误!']; } public function syncOwners(OwnerService $ownerService){ if (!Gate::allows('库存管理-盘点')){return redirect(url('/')); } $owners=$ownerService->syncOwnersData(); if (!$owners)return ['success'=>false,'data'=>'同步货主失败!']; return ['success'=>true,'data'=>$owners]; } public function 修改质量状态(Request $request){ if (!Gate::allows('库存管理-盘点')){return redirect(url('/')); } $id=$request->input('id'); $location=$request->location; $sku=$request->sku; $quality=$request->quality; $ownerCode=$request->ownerCode; $inventoryAccountMission=app('inventoryAccountService')->修改质量状态($id,$location,$sku,$quality,$ownerCode); $this->log(__METHOD__,__FUNCTION__,json_encode($request->toArray()),Auth::user()['id']); if ($inventoryAccountMission==null) return ['success'=>false,'data'=>'WMS中不存在该条记录!']; return ['success'=>true,'data'=>'质量状态修改成功']; } public function 完结盘点任务($id){ if(!Gate::allows('库存管理-盘点-完结')){return['success'=>false,'status'=>'没有权限'];} if (!$id)return['success'=>false,'status'=>'参数错误!']; $inventoryAccount=app('inventoryAccountService')->完结盘点任务($id); if (!$inventoryAccount)return['success'=>false,'status'=>'修改完结状态失败!']; return['success'=>true,'data'=>$inventoryAccount]; } public function 增加系统之外的库位记录(Request $request){ if(!Gate::allows('库存管理-盘点')){return['success'=>false,'data'=>'没有权限'];} $location=$request->input('location'); $barcode=$request->input('barcode'); $inventoryId=$request->input('inventoryId'); $count=$request->input('count'); $inventoryAccountMission=app('inventoryAccountService')->增加系统之外的库位记录($location,$barcode,$inventoryId,$count); if (!$inventoryAccountMission)return ['success'=>false,'data'=>'添加系统之外的库位记录失败!']; $inventoryAccountMission=InventoryAccountMission::with(['commodity.barcodes','stockInventoryPersons'])->where('id',$inventoryAccountMission->id)->first(); $stockInventoryPersons=$inventoryAccountMission->stockInventoryPersons; return ['success'=>true,'inventoryAccountMission'=>$inventoryAccountMission,'stockInventoryPersons'=>$stockInventoryPersons]; } public function 盘点选中任务(Request $request){ if(!Gate::allows('库存管理-盘点')){return['success'=>false,'data'=>'没有权限'];} $id=$request->input('id'); $count=$request->count; $inventoryId=$request->input('inventoryId'); $produced_at=$request->input('produced_at'); $valid_at=$request->input('valid_at'); $batch_number=$request->input('batch_number'); if (is_null($count)) return ['success'=>false,'data'=>'盘点数不能为空!']; if ($produced_at||$valid_at||$batch_number){ /** @var InventoryAccountService $inventoryAccountMission */ $inventoryAccountService=app('inventoryAccountService'); $inventoryAccountMission=$inventoryAccountService ->盘点生产日期_失效日期_批号有改动任务($id,$count,$inventoryId,$produced_at,$valid_at,$batch_number); if (!$inventoryAccountMission)return ['success'=>false,'data'=>'参数错误!']; /** @var InventoryAccountService $inventoryService */ $inventoryService=app('inventoryAccountService'); $inventoryAccount=$inventoryService->updateInventory($inventoryId); return ['success'=>true,'inventoryMission'=>$inventoryAccountMission,'inventory'=>$inventoryAccount]; }else{ /** @var InventoryAccountService $inventoryAccountMission */ $inventoryAccountService=app('inventoryAccountService'); $inventoryAccountMission=$inventoryAccountService ->盘点选中任务($id,$count,$inventoryId); if (!$inventoryAccountMission)return ['success'=>false,'data'=>'参数错误!']; /** @var InventoryAccountService $inventoryService */ $inventoryService=app('inventoryAccountService'); $inventoryAccount=$inventoryService->updateInventory($inventoryId); $stockInventoryPersons=$inventoryAccountMission->stockInventoryPersons; return ['success'=>true,'inventoryMission'=>$inventoryAccountMission,'inventory'=>$inventoryAccount,'stockInventoryPersons'=>$stockInventoryPersons]; } } public function 删除盘点记录(Request $request){ if(!Gate::allows('库存管理-盘点-删除')){return['success'=>false,'data'=>'没有权限'];} $inventoryAccountMissionId=$request->input('inventoryAccountMissionId'); $inventoryAccountId=$request->input('inventoryAccountId'); if(is_null($inventoryAccountMissionId)){return ['success'=>false,'data'=>'传入id为空'];} $inventoryAccountMission=InventoryAccountMission::query()->where('id',$inventoryAccountMissionId)->delete(); $this->log(__METHOD__,__FUNCTION__,json_encode($request->toArray()),Auth::user()['id']); if ($inventoryAccountMission>0){ $inventoryAccount=InventoryAccount::query()->find($inventoryAccountId); $inventoryAccount->total=$inventoryAccount->total-1; $inventoryAccount->processed=$inventoryAccount->getProcessedAmount();//已盘点数 $inventoryAccount->difference=$inventoryAccount->getDifferenceAmount();//盘点差异数 $inventoryAccount->returned=$inventoryAccount->getReturnedAmount(); //复盘归位数 $inventoryAccount->update(); $this->log(__METHOD__,'删除盘点记录时修改盘点任务信息'.__FUNCTION__,json_encode($request->toArray()),Auth::user()['id']); } return ['success'=>true,'data'=>$inventoryAccountMission]; } }