AndroidInventoryService.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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('location')->selectRaw("count(*) count")
  18. ->where('inventory_account_id', $taskId)
  19. ->where('checked', '否')->groupBy("location")
  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)
  52. ->where('inventory_account_id',$taskId)
  53. ->where('checked','否')
  54. ->first();
  55. });
  56. }
  57. public function skipInventory($inventoryDetailId)
  58. {
  59. $inventoryAccountMission=InventoryAccountMission::query()->find($inventoryDetailId);
  60. if (!$inventoryAccountMission)return null;
  61. $inventoryAccountMission->checked='跳过';
  62. $inventoryAccountMission->update();
  63. if ($inventoryAccountMission->checked=='跳过'){
  64. /** @var InventoryAccountService $inventoryService */
  65. $inventoryService = app('inventoryAccountService');
  66. $inventoryService->updateInventory($inventoryAccountMission->inventory_account_id);
  67. }
  68. return $inventoryAccountMission;
  69. }
  70. }