| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace App\Services;
- use App\InventoryAccount;
- use App\InventoryAccountMission;
- use App\Sign;
- use App\Traits\ServiceAppAop;
- use Carbon\Carbon;
- use Illuminate\Support\Facades\Auth;
- use Illuminate\Support\Facades\Cache;
- class AndroidInventoryService
- {
- use ServiceAppAop;
- //未盘任务列表
- public function getUnInventoryTaskList($taskId)
- {
- return InventoryAccountMission::query()
- ->select('id','location')
- ->where('inventory_account_id', $taskId)
- ->where('checked', '否')
- ->get();
- }
- //根据员工姓名获取当日盘点行数
- public function getStaffSameDayInvCount(): int
- {
- return Sign::query()
- ->where('signable_type', 'inventory_account_missions')
- ->where('field', '盘点人')
- ->where('created_at', 'like', Carbon::now()->toDateString() . '%')
- ->where('mark', Auth::user()['name'])->count();
- }
- public function getLocInvPro($taskId,$location): array
- {
- $ins=InventoryAccountMission::query()
- ->where('inventory_account_id',$taskId)
- ->where('location',$location)->get();
- //库位盘点任务总条数
- $total=$ins->count();
- //已盘数
- $invCount=$ins->where('checked','<>','否')->count();
- return ['total'=>$total,'invCount'=>$invCount];
- }
- //根据盘点任务号,库位,条码 查询指定盘点任务
- public function getInventoryDetail($taskId,$location,$barcode)
- {
- return Cache::remember($taskId.'_'.$location.'_'.$barcode, 300, function ()use($taskId,$location,$barcode) {
- return InventoryAccountMission::with(['commodity.barcodes','stockInventoryPersons'])
- ->whereHas('commodity',function($query)use($barcode){
- $query->whereHas('barcodes',function($sql)use($barcode){
- $sql->where('code','=',$barcode);
- });
- })->where('location',$location)->where('inventory_account_id',$taskId)->first();
- });
- }
- public function stockInventory($taskId,$location,$barcode,$amount)
- {
- $inventoryAccountMission=$this->getInventoryDetail($taskId,$location,$barcode);
- /** @var InventoryAccountService $service */
- $service=app('InventoryAccountService');
- return $service->盘点($taskId,$amount,$inventoryAccountMission);
- }
- public function skipInventory($inventoryDetailId)
- {
- $inventoryAccountMission=InventoryAccountMission::query()->find($inventoryDetailId);
- if (!$inventoryAccountMission)return null;
- $inventoryAccountMission->checked='跳过';
- $inventoryAccountMission->update();
- if ($inventoryAccountMission->checked=='跳过'){
- $inventoryAccount=InventoryAccount::query()->find($inventoryAccountMission->inventory_account_id);
- $inventoryAccount->processed=$inventoryAccount->getProcessedAmount();//已盘点数
- $inventoryAccount->difference=$inventoryAccount->getDifferenceAmount();//盘点差异数
- $inventoryAccount->returned=$inventoryAccount->getReturnedAmount(); //复盘归位数
- $inventoryAccount->ignored=$inventoryAccount->getIgnoredAmount();
- $inventoryAccount->update();
- }
- return $inventoryAccountMission;
- }
- }
|