AndroidInventoryService.php 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace App\Services;
  3. use App\InventoryAccount;
  4. use App\InventoryAccountMission;
  5. use App\Sign;
  6. use App\Traits\ServiceAppAop;
  7. use Carbon\Carbon;
  8. use Illuminate\Support\Facades\Auth;
  9. use Illuminate\Support\Facades\Cache;
  10. class AndroidInventoryService
  11. {
  12. use ServiceAppAop;
  13. //未盘任务列表
  14. public function getUnInventoryTaskList($taskId)
  15. {
  16. return InventoryAccountMission::query()
  17. ->select('id','location')
  18. ->where('inventory_account_id', $taskId)
  19. ->where('checked', '否')
  20. ->get();
  21. }
  22. //根据员工姓名获取当日盘点行数
  23. public function getStaffSameDayInvCount(): int
  24. {
  25. return Sign::query()
  26. ->where('signable_type', 'inventory_account_missions')
  27. ->where('field', '盘点人')
  28. ->where('created_at', 'like', Carbon::now()->toDateString() . '%')
  29. ->where('mark', Auth::user()['name'])->count();
  30. }
  31. public function getLocInvPro($taskId,$location): array
  32. {
  33. $ins=InventoryAccountMission::query()
  34. ->where('inventory_account_id',$taskId)
  35. ->where('location',$location)->get();
  36. //库位盘点任务总条数
  37. $total=$ins->count();
  38. //已盘数
  39. $invCount=$ins->where('checked','<>','否')->count();
  40. return ['total'=>$total,'invCount'=>$invCount];
  41. }
  42. //根据盘点任务号,库位,条码 查询指定盘点任务
  43. public function getInventoryDetail($taskId,$location,$barcode)
  44. {
  45. return Cache::remember($taskId.'_'.$location.'_'.$barcode, 300, function ()use($taskId,$location,$barcode) {
  46. return InventoryAccountMission::with(['commodity.barcodes','stockInventoryPersons'])
  47. ->whereHas('commodity',function($query)use($barcode){
  48. $query->whereHas('barcodes',function($sql)use($barcode){
  49. $sql->where('code','=',$barcode);
  50. });
  51. })->where('location',$location)->where('inventory_account_id',$taskId)->first();
  52. });
  53. }
  54. public function stockInventory($taskId,$location,$barcode,$amount)
  55. {
  56. $inventoryAccountMission=$this->getInventoryDetail($taskId,$location,$barcode);
  57. /** @var InventoryAccountService $service */
  58. $service=app('InventoryAccountService');
  59. return $service->盘点($taskId,$amount,$inventoryAccountMission);
  60. }
  61. public function skipInventory($inventoryDetailId)
  62. {
  63. $inventoryAccountMission=InventoryAccountMission::query()->find($inventoryDetailId);
  64. if (!$inventoryAccountMission)return null;
  65. $inventoryAccountMission->checked='跳过';
  66. $inventoryAccountMission->update();
  67. if ($inventoryAccountMission->checked=='跳过'){
  68. $inventoryAccount=InventoryAccount::query()->find($inventoryAccountMission->inventory_account_id);
  69. $inventoryAccount->processed=$inventoryAccount->getProcessedAmount();//已盘点数
  70. $inventoryAccount->difference=$inventoryAccount->getDifferenceAmount();//盘点差异数
  71. $inventoryAccount->returned=$inventoryAccount->getReturnedAmount(); //复盘归位数
  72. $inventoryAccount->ignored=$inventoryAccount->getIgnoredAmount();
  73. $inventoryAccount->update();
  74. }
  75. return $inventoryAccountMission;
  76. }
  77. }