AndroidInventoryService.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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)
  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. if ($total==0&&$invCount==0){
  41. return 0;//库位不存在
  42. }else{
  43. return ['total'=>$total,'invCount'=>$invCount];
  44. }
  45. }
  46. //根据盘点任务号,库位,条码 查询指定盘点任务
  47. public function getInventoryDetail($taskId,$location,$barcode)
  48. {
  49. return Cache::remember($taskId.'_'.$location.'_'.$barcode, 300, function ()use($taskId,$location,$barcode) {
  50. return InventoryAccountMission::with(['commodity.barcodes','stockInventoryPersons'])
  51. ->whereHas('commodity',function($query)use($barcode){
  52. $query->whereHas('barcodes',function($sql)use($barcode){
  53. $sql->where('code','=',$barcode);
  54. });
  55. })->where('location',$location)
  56. ->where('inventory_account_id',$taskId)
  57. ->whereIn('checked',['是','否'])
  58. ->first();
  59. });
  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. /** @var InventoryAccountService $inventoryService */
  69. $inventoryService = app('inventoryAccountService');
  70. $inventoryService->updateInventory($inventoryAccountMission->inventory_account_id);
  71. }
  72. return $inventoryAccountMission;
  73. }
  74. }