AndroidInventoryService.php 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. $stock_status = InventoryAccount::query()->where('id', $taskId)->value('status');
  17. $query = InventoryAccountMission::query()
  18. ->select('location')->selectRaw("count(*) count")
  19. ->where('inventory_account_id', $taskId)
  20. ->groupBy("location");
  21. if ($stock_status=='待盘点'||$stock_status=='盘点中'){ //初盘
  22. return $query->where('checked', '否')->get();
  23. }elseif ($stock_status=='复盘中'){ //复盘
  24. return $query->where('checked', '是')->whereNotNull('difference_amount')->get();
  25. }else{
  26. return collect();
  27. }
  28. }
  29. //根据员工姓名获取当日盘点行数
  30. public function getStaffSameDayInvCount(): int
  31. {
  32. return Sign::query()
  33. ->where('signable_type', 'inventory_account_missions')
  34. ->where('field', '盘点人')
  35. ->where('created_at', 'like', Carbon::now()->toDateString() . '%')
  36. ->where('mark', Auth::user()['name'])->count();
  37. }
  38. public function getLocInvPro($taskId, $location)
  39. {
  40. $ins = InventoryAccountMission::query()
  41. ->where('inventory_account_id', $taskId)
  42. ->where('location', $location)->get();
  43. //库位盘点任务总条数
  44. $total = $ins->count();
  45. //已盘数
  46. $invCount = $ins->where('checked', '<>', '否')->count();
  47. if ($total == 0 && $invCount == 0) {
  48. return 0;//库位不存在
  49. } else {
  50. return ['total' => $total, 'invCount' => $invCount];
  51. }
  52. }
  53. //根据盘点任务号,库位,条码 查询指定盘点任务
  54. public function getInventoryDetail($taskId, $location, $barcode)
  55. {
  56. $stock_status = InventoryAccount::query()->where('id', $taskId)->value('status');
  57. $query = InventoryAccountMission::with(['commodity.barcodes', 'stockInventoryPersons'])
  58. ->whereHas('commodity', function ($query) use ($barcode) {
  59. $query->whereHas('barcodes', function ($sql) use ($barcode) {
  60. $sql->where('code', '=', $barcode);
  61. });
  62. })->where('location', $location)
  63. ->where('inventory_account_id', $taskId);
  64. if ($stock_status == '待盘点' || $stock_status == '盘点中') { //初盘
  65. return $query->where('checked', '否')->first();
  66. } elseif ($stock_status == '复盘中') { //复盘
  67. return $query->where('checked', '是')->whereNotNull('difference_amount')->first();
  68. } else {
  69. return null;
  70. }
  71. }
  72. public function skipInventory($inventoryDetailId)
  73. {
  74. $inventoryAccountMission = InventoryAccountMission::query()->find($inventoryDetailId);
  75. if (!$inventoryAccountMission) return null;
  76. $inventoryAccountMission->checked = '跳过';
  77. $inventoryAccountMission->update();
  78. if ($inventoryAccountMission->checked == '跳过') {
  79. /** @var InventoryAccountService $inventoryService */
  80. $inventoryService = app('inventoryAccountService');
  81. $inventoryService->updateInventory($inventoryAccountMission->inventory_account_id);
  82. }
  83. return $inventoryAccountMission;
  84. }
  85. }