| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300 |
- <?php
- namespace App\Http\Controllers;
- use App\Exports\Export;
- use App\InventoryAccount;
- use App\InventoryAccountMission;
- use App\Services\InventoryAccountService;
- use App\Services\OwnerService;
- use Exception;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Auth;
- use Illuminate\Support\Facades\Gate;
- use Illuminate\Support\Facades\Http;
- use Maatwebsite\Excel\Facades\Excel;
- class InventoryAccountController extends Controller
- {
- public function __construct()
- {
- app()->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');
- $location=$request->input('location');
- $barcode=$request->input('barcode');
- $inventoryAccount=app('inventoryAccountService')->createMission($date_start,$date_end,$ownerId,$location,$barcode);
- $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 (!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'));
- }
- public function enterBlindReceive($id){
- if (!Gate::allows('库存管理-盘点')){return redirect(url('/')); }
- if (!$id) return ['success'=>false,'data'=>'参数错误!'];
- $inventoryAccount=InventoryAccount::with('owner')->find($id);
- return view('inventory.stockInventory.blindReceive',compact('inventoryAccount'));
- }
- //依据盘点任务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');
- $id=$request->input('id');
- if (is_null($count)) return ['success'=>false,'data'=>'盘点数不能为空!'];
- /** @var InventoryAccountService $inventoryAccountMission */
- $inventoryAccountService=app('inventoryAccountService');
- $inventoryAccountMission=$inventoryAccountService->stockInventory($id,$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 baseOnBlindReceive(Request $request){
- if (!Gate::allows('库存管理-盘点')){return redirect(url('/')); }
- $location=$request->input('location');
- $inventoryId=$request->input('inventoryId');
- $owner_code=$request->input('owner_code');
- $goodses=$request->input('goodses');
- if (!$location) return ['success'=>false,'fail_info'=>'盘点库位不存在!'];
- if (count($goodses)<1) return ['success'=>false,'fail_info'=>'盘点商品不存在!'];
- //dd($location,$owner_code,$goodses,$inventoryId,$owner_id);
- /** @var InventoryAccountService $inventoryAccountMission */
- $inventoryAccountService=app('inventoryAccountService');
- $inventoryAccountMissions=$inventoryAccountService->baseOnBlindReceive($location,$owner_code,$goodses,$inventoryId);
- if (count($inventoryAccountMissions)<0)return ['success'=>false,'fail_info'=>'盲收盘点失败!'];
- /** @var InventoryAccountService $inventoryService */
- $inventoryService=app('inventoryAccountService');
- $inventoryAccount=$inventoryService->updateInventory($inventoryId);
- if ($inventoryAccountMissions&&$inventoryAccount)
- $stockInventoryPersons=$inventoryAccountMissions[0]->stockInventoryPersons;
- return ['success'=>true,'inventoryMissions'=>$inventoryAccountMissions,'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');
- /** @var InventoryAccountService $application */
- $application = app('inventoryAccountService');
- $inventoryAccountMissions= $application->searchStockInventoryRecord($location,$barcode,$inventoryId);
- if ($inventoryAccountMissions->isEmpty())return ['success'=>false,'data'=>'没有找到相应记录!'];
- // $stockInventoryPersons=$inventoryAccountMissions->stockInventoryPersons;
- // return ['success'=>true,'data'=>$inventoryAccountMissions,'stockInventoryPersons'=>$stockInventoryPersons];
- return ['success'=>true,'data'=>$inventoryAccountMissions];
- }
- //盘点任务导出
- 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; $i<count($inventoryAccounts);$i++){
- $inventoryAccount=$inventoryAccounts[$i];
- $w=[
- 'id'=>isset($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 ['success'=>false,'data'=>'没有权限']; }
- $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');
- $owner_code=$request->input('owner_code');
- $param=$request->input('param');
- if (is_null($count)) return ['success'=>false,'data'=>'盘点数不能为空!'];
- $inventoryAccountMission=app('inventoryAccountService')->增加系统之外的盘点记录($location,$barcode,$inventoryId,$count,$owner_code,$param);
- 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);
- $stockInventoryPersons=$inventoryAccountMission[0]->stockInventoryPersons;
- return ['success'=>true,'inventoryMission'=>$inventoryAccountMission,'inventory'=>$inventoryAccount,'stockInventoryPersons'=>$stockInventoryPersons];
- }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为空'];}
- /** @var InventoryAccountService $inventoryService */
- $inventoryService=app('inventoryAccountService');
- $inventoryAccountMission=$inventoryService->删除盘点记录($inventoryAccountMissionId,$inventoryAccountId);
- return ['success'=>true,'data'=>$inventoryAccountMission];
- }
- public function 跳过盘点记录(Request $request){
- if(!Gate::allows('库存管理-盘点')){return['success'=>false,'data'=>'没有权限'];}
- $inventoryAccountMissionId=$request->inventoryAccountMissionId;
- $inventoryAccountId=$request->input('inventoryAccountId');
- if(is_null($inventoryAccountMissionId)){return ['success'=>false,'data'=>'传入id为空'];}
- /** @var InventoryAccountService $inventoryService */
- $inventoryService=app('inventoryAccountService');
- $inventoryAccountMission=$inventoryService->跳过盘点记录($inventoryAccountMissionId,$inventoryAccountId);
- return ['success'=>true,'inventoryAccountMission'=>$inventoryAccountMission];
- }
- public function exportInventoryAccountMission(Request $request){
- if(!Gate::allows("库存管理-盘点")){ return redirect(url('/')); }
- $post = Http::post(config('go.export.url'),['type'=>'inventoryAccountMission','data'=>$request->data]);
- if ($post->status() == 500){
- throw new Exception($post->header("Msg"));
- }
- return response($post,200, [
- "Content-type"=>"application/octet-stream",
- "Content-Disposition"=>"attachment; filename=库存盘点记录-".date('ymdHis').'.xlsx',
- ]);
- }
- public function searchCommodityByBarcode(Request $request){
- if(!Gate::allows('库存管理-盘点')){return['success'=>false,'data'=>'没有权限'];}
- $barcode=$request->input('barcode');
- $owner_code=$request->input('owner_code');
- /** @var InventoryAccountService $inventoryService */
- $inventoryService=app('inventoryAccountService');
- $commodity=$inventoryService->searchCommodityByBarcode($barcode,$owner_code);
- if ($commodity){
- return ['success'=>true,'data'=>$commodity];
- }else{
- return ['success'=>false,'data'=>'输入的条码没有对应商品!'];
- }
- }
- }
|