Просмотр исходного кода

Merge branch 'master' of ssh://47.103.131.176:10022/var/git/bswas

 Conflicts:
	app/Http/Controllers/TestController.php
zhouzhendong 4 лет назад
Родитель
Сommit
b7abb67f22

+ 17 - 7
app/Http/ApiControllers/InventoryController.php

@@ -11,6 +11,7 @@ use App\Services\AndroidInventoryService;
 use App\Services\InventoryAccountService;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Log;
+use phpDocumentor\Reflection\Types\Object_;
 
 class InventoryController
 {
@@ -102,7 +103,11 @@ class InventoryController
         $taskId = $request->input("taskId");
         $location = $request->input("location");
         $res=app('AndroidInventoryService')->getLocInvPro($taskId,$location);
-        $this->response($res);
+        if ($res===0){
+            $this->response(null,410,"库位不存在!");
+        }else{
+            $this->response($res);
+        }
     }
 
     /**
@@ -159,6 +164,7 @@ class InventoryController
      * @apiSuccess {string} message 响应描述
      * @apiSuccess {int} status_code HTTP响应码
      * @apiSuccess {array} data 数据列表
+     * @apiSuccess {bool} isDiff 是否差异
      *
      * @apiSuccessExample {json} Success-Response:
      *     HTTP/1.1 200 OK
@@ -166,10 +172,11 @@ class InventoryController
      *       "message": "请求成功",
      *       "status_code": "200"
      *       "data":[
+     *          “isDiff”=>“是否差异",
      *          "notStocktakingList"=>[
      *                  {
-     *                        "id"=>"盘点任务明细号",
      *                        "location"=>"库位",
+     *                        "count"=>"待盘数量",
      *                  }
      *              ]
      *        ]
@@ -177,7 +184,6 @@ class InventoryController
      */
     public function stockInventory(Request $request)
     {
-        Log::error('执行开始',[now()->toDateTimeString()]);
         $task_item_id = $request->input("task_item_id");
         $verified_amount = $request->input("verified_amount");
         /**
@@ -190,16 +196,20 @@ class InventoryController
         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);
+            $stockDetail=$stockService->盘点($task_id,$verified_amount,$inventoryAccountMission);
         }else{
-            $stockService->盘点生产日期_失效日期_批号有改动任务($task_item_id, $verified_amount, $task_id,
+            $stockDetail=$stockService->盘点生产日期_失效日期_批号有改动任务($task_item_id, $verified_amount, $task_id,
                 $request->input('produced_at')??'', $request->input('valid_at')??'',
                 $request->input('batch_number')??'');
             $stockService->updateInventory($task_id);
         }
+        if ($stockDetail->difference_amount==0){
+            $isDiff=false;
+        }else{
+            $isDiff=true;
+        }
         $notStocktakingList=$service->getUnInventoryTaskList($task_id);
-        Log::error('执行结束',[now()->toDateTimeString()]);
-        $this->response($notStocktakingList);
+        $this->response(['isDiff'=>$isDiff,'notStocktakingList'=>$notStocktakingList]);
     }
 
     /**

+ 6 - 0
app/InventoryAccountMission.php

@@ -24,6 +24,12 @@ class InventoryAccountMission extends Model
         return $this->hasMany('App\Sign','signable_id','id')
             ->where('signable_type','inventory_account_missions')->where('field','盘点人');
     }
+    public function getProducedAtAttribute($value){
+        return substr($value,0,10);
+    }
+    public function getValidAtAttribute($value){
+        return substr($value,0,10);
+    }
     public function createSignStockInventoryPersons(){
         return Sign::query()->firstOrCreate([
             'signable_type'=>'inventory_account_missions',

+ 48 - 27
app/Services/AndroidInventoryService.php

@@ -17,54 +17,75 @@ class AndroidInventoryService
     //未盘任务列表
     public function getUnInventoryTaskList($taskId)
     {
-        return  InventoryAccountMission::query()
+        $stock_status = InventoryAccount::query()->where('id', $taskId)->value('status');
+        $query = InventoryAccountMission::query()
             ->select('location')->selectRaw("count(*) count")
             ->where('inventory_account_id', $taskId)
-            ->where('checked', '否')->groupBy("location")
-            ->get();
+            ->groupBy("location");
+        if ($stock_status=='待盘点'||$stock_status=='盘点中'){ //初盘
+            return $query->where('checked', '否')->get();
+        }elseif ($stock_status=='复盘中'){  //复盘
+            return $query->where('checked', '是')->whereNotNull('difference_amount')->get();
+        }else{
+            return collect();
+        }
+
     }
+
     //根据员工姓名获取当日盘点行数
     public function getStaffSameDayInvCount(): int
     {
-         return Sign::query()
+        return Sign::query()
             ->where('signable_type', 'inventory_account_missions')
             ->where('field', '盘点人')
             ->where('created_at', 'like', Carbon::now()->toDateString() . '%')
             ->where('mark', Auth::user()['name'])->count();
     }
-    public function getLocInvPro($taskId,$location): array
+
+    public function getLocInvPro($taskId, $location)
     {
-        $ins=InventoryAccountMission::query()
-            ->where('inventory_account_id',$taskId)
-            ->where('location',$location)->get();
+        $ins = InventoryAccountMission::query()
+            ->where('inventory_account_id', $taskId)
+            ->where('location', $location)->get();
         //库位盘点任务总条数
-        $total=$ins->count();
+        $total = $ins->count();
         //已盘数
-        $invCount=$ins->where('checked','<>','否')->count();
-        return ['total'=>$total,'invCount'=>$invCount];
+        $invCount = $ins->where('checked', '<>', '否')->count();
+        if ($total == 0 && $invCount == 0) {
+            return 0;//库位不存在
+        } else {
+            return ['total' => $total, 'invCount' => $invCount];
+        }
+
     }
+
     //根据盘点任务号,库位,条码 查询指定盘点任务
-    public function getInventoryDetail($taskId,$location,$barcode)
+    public function getInventoryDetail($taskId, $location, $barcode)
     {
-        return Cache::remember($taskId.'_'.$location.'_'.$barcode, 300, function ()use($taskId,$location,$barcode) {
-            return InventoryAccountMission::with(['commodity.barcodes','stockInventoryPersons'])
-                ->whereHas('commodity',function($query)use($barcode){
-                    $query->whereHas('barcodes',function($sql)use($barcode){
-                        $sql->where('code','=',$barcode);
-                    });
-                })->where('location',$location)
-                ->where('inventory_account_id',$taskId)
-                ->where('checked','否')
-                ->first();
-        });
+        $stock_status = InventoryAccount::query()->where('id', $taskId)->value('status');
+        $query = InventoryAccountMission::with(['commodity.barcodes', 'stockInventoryPersons'])
+            ->whereHas('commodity', function ($query) use ($barcode) {
+                $query->whereHas('barcodes', function ($sql) use ($barcode) {
+                    $sql->where('code', '=', $barcode);
+                });
+            })->where('location', $location)
+            ->where('inventory_account_id', $taskId);
+        if ($stock_status == '待盘点' || $stock_status == '盘点中') { //初盘
+            return $query->where('checked', '否')->first();
+        } elseif ($stock_status == '复盘中') { //复盘
+            return $query->where('checked', '是')->whereNotNull('difference_amount')->first();
+        } else {
+            return null;
+        }
     }
+
     public function skipInventory($inventoryDetailId)
     {
-        $inventoryAccountMission=InventoryAccountMission::query()->find($inventoryDetailId);
-        if (!$inventoryAccountMission)return null;
-        $inventoryAccountMission->checked='跳过';
+        $inventoryAccountMission = InventoryAccountMission::query()->find($inventoryDetailId);
+        if (!$inventoryAccountMission) return null;
+        $inventoryAccountMission->checked = '跳过';
         $inventoryAccountMission->update();
-        if ($inventoryAccountMission->checked=='跳过'){
+        if ($inventoryAccountMission->checked == '跳过') {
             /** @var InventoryAccountService $inventoryService */
             $inventoryService = app('inventoryAccountService');
             $inventoryService->updateInventory($inventoryAccountMission->inventory_account_id);