Explorar el Código

Merge branch 'Haozi'

zhouzhendong hace 4 años
padre
commit
f191ecbe96

+ 29 - 10
app/Http/ApiControllers/InventoryController.php

@@ -6,7 +6,9 @@ namespace App\Http\ApiControllers;
 
 use App\Components\ApiResponse;
 use App\InventoryAccount;
+use App\InventoryAccountMission;
 use App\Services\AndroidInventoryService;
+use App\Services\InventoryAccountService;
 use Illuminate\Http\Request;
 
 class InventoryController
@@ -56,7 +58,12 @@ class InventoryController
         $taskId = $request->input("taskId");
         /** @var AndroidInventoryService $service */
         $service=app('AndroidInventoryService');
-        $stocktakingTask = InventoryAccount::query()->find($taskId);
+        if (!$taskId) $this->response(null,410,"未获取到任务号");
+        $stocktakingTask = InventoryAccount::query()
+            ->whereIn('status',['待盘点','盘点中','复盘中'])
+            ->where('id',$taskId)
+            ->first();
+        if (!$stocktakingTask) $this->response(null,410,"未查询到盘点任务");
         $notStocktakingList=$service->getUnInventoryTaskList($taskId);
         $sameDayInventoryCount=$service->getStaffSameDayInvCount();
         $this->response(['stocktakingTask' => $stocktakingTask,
@@ -135,7 +142,7 @@ class InventoryController
         if ($inventoryDetail) {
             $this->response($inventoryDetail);
         }else{
-            $this->response(null,403,'未检测到指定盘点任务');
+            $this->response(null,410,'未检测到指定盘点任务');
         }
     }
     /**
@@ -169,14 +176,26 @@ class InventoryController
      */
     public function stockInventory(Request $request)
     {
-        $taskId = $request->input("taskId");
-        $location = $request->input("location");
-        $barcode = $request->input("barcode");
-        $amount = $request->input("amount");
-        /** @var AndroidInventoryService $service */
+        $task_item_id = $request->input("task_item_id");
+        $verified_amount = $request->input("verified_amount");
+        /**
+         * @var AndroidInventoryService $service
+         *@var InventoryAccountService $stockService
+         */
         $service=app('AndroidInventoryService');
-        $service->stockInventory($taskId,$location,$barcode,$amount);
-        $notStocktakingList=$service->getUnInventoryTaskList($taskId);
+        $stockService=app('InventoryAccountService');
+        $inventoryAccountMission=InventoryAccountMission::query()->find($task_item_id);
+        if (!$inventoryAccountMission)$this->response(null,410,'未查询到盘点明细');
+        $task_id=$inventoryAccountMission->inventory_account_id;
+        if (!$request->has('produced_at')&&!$request->has('valid_at')&&!$request->has('batch_number')){
+            $stockService->盘点($task_id,$verified_amount,$inventoryAccountMission);
+        }else{
+            $stockService->盘点生产日期_失效日期_批号有改动任务($task_item_id, $verified_amount, $task_id,
+                $request->input('produced_at')??'', $request->input('valid_at')??'',
+                $request->input('batch_number')??'');
+            $stockService->updateInventory($task_id);
+        }
+        $notStocktakingList=$service->getUnInventoryTaskList($task_id);
         $this->response([
             "notStocktakingList" => $notStocktakingList,
         ]);
@@ -222,7 +241,7 @@ class InventoryController
                 'inventoryTaskDetails' => $inventoryTaskDetails, 'sameDayInventoryCount'=>$sameDayInventoryCount
             ]);
         }else{
-            $this->response(null,403,'跳过失败!');
+            $this->response(null,410,'跳过失败!');
         }
 
     }

+ 7 - 16
app/Services/AndroidInventoryService.php

@@ -52,18 +52,12 @@ class AndroidInventoryService
                     $query->whereHas('barcodes',function($sql)use($barcode){
                         $sql->where('code','=',$barcode);
                     });
-                })->where('location',$location)->where('inventory_account_id',$taskId)->first();
+                })->where('location',$location)
+                ->where('inventory_account_id',$taskId)
+                ->where('checked','否')
+                ->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);
@@ -71,12 +65,9 @@ class AndroidInventoryService
         $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();
+            /** @var InventoryAccountService $inventoryService */
+            $inventoryService = app('inventoryAccountService');
+            $inventoryService->updateInventory($inventoryAccountMission->inventory_account_id);
         }
         return $inventoryAccountMission;
     }