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

修改 缓存架和格口的service

ajun 5 лет назад
Родитель
Сommit
56fd2a6b58

+ 24 - 3
app/Services/StationCacheShelfGridService.php

@@ -1,4 +1,4 @@
-<?php 
+<?php
 
 namespace App\Services;
 
@@ -8,6 +8,27 @@ use App\StationCacheShelfGrid;
 class StationCacheShelfGridService
 {
     use ServiceAppAop;
-    protected $modelClass=StationCacheShelfGrid::class;
 
-}
+    protected $modelClass = StationCacheShelfGrid::class;
+
+    /**
+     * 修改格口的状态
+     * @param $stationCacheShelfGrid
+     * @param $station
+     * @param $materialBox
+     */
+    public function processGrid($stationCacheShelfGrid, $station, $materialBox)
+    {
+        $stationCacheShelfGrid->update(['station_id' => $station['id'], 'material_box_id' => $materialBox['id'], 'status' => 1]);
+    }
+
+    /**
+     * 清空任务
+     * @param $grids
+     * @return bool
+     */
+    public function cancelTask($grids): bool
+    {
+        return $grids->update(['material_box_id' => null, 'status' => 0]) > 0;
+    }
+}

+ 33 - 1
app/Services/StationTaskMaterialBoxService.php

@@ -5,10 +5,12 @@ namespace App\Services;
 
 
 use App\Batch;
+use App\Events\BroadcastToStation;
 use App\Exceptions\ErrorException;
 use App\Exceptions\Exception;
 use App\MaterialBox;
 use App\OrderCommodity;
+use App\StationCacheShelfGrid;
 use App\StationTask;
 use App\StationTaskBatch;
 use App\StationTaskMaterialBox;
@@ -33,6 +35,8 @@ class StationTaskMaterialBoxService
     private $stationTaskCommodityService;
     /** @var MaterialBoxService $materialBoxService */
     private $materialBoxService;
+    /** @var StationCacheShelfGridService $stationCacheShelfGridService */
+    private $stationCacheShelfGridService;
     public function __construct(){
         $this->stationService=null;
         $this->stationTypeService=null;
@@ -42,6 +46,15 @@ class StationTaskMaterialBoxService
         $this->stationTaskCommodityService=null;
     }
 
+    function createByStationMaterialBox($station,$materialBox)
+    {
+        return StationTaskMaterialBox::query()->create([
+            'station_id' => $station['id'],
+            'material_box_id' => $materialBox['id'],
+            'status' => '待处理'
+        ]);
+    }
+
     function createByBatches(Collection $batches,Collection $stationTasks_toAttach): Collection
     {
         $this->instant($this->stationTaskService,'StationTaskService');
@@ -136,9 +149,28 @@ class StationTaskMaterialBoxService
         }
     }
 
-    function markHasTaken($stationTaskMaterialBox){
+    function markHasTaken($stationTaskMaterialBox)
+    {
         //TODO: 标记 料箱位置(需要其字段存在)$stationTaskMaterialBox['materialBox']['position']
+
+        $this->instant($this->stationCacheShelfGridService,'StationCacheShelfGridService');
+
+        // 料箱从缓存架上拿走
+        if($stationTaskMaterialBox['station']['stationType']['name']=='缓存架'){
+            $stationTaskMaterialBox['status'] = '完成';
+
+            $json = json_encode([
+                'station_id'=>$stationTaskMaterialBox['station_id'],
+                'code' => $stationTaskMaterialBox['materialBox']['code'],
+                'status' => '完成'
+            ]);
+            $grids = StationCacheShelfGrid::query()->where(['station_id'=>$stationTaskMaterialBox['station_id'],'material_box_id'=>$stationTaskMaterialBox['material_box_id']])->get();
+            $this->stationCacheShelfGridService->cancelTask($grids);
+            broadcast(new BroadcastToStation($stationTaskMaterialBox['station_id'], $json));
+            $this->markProcessed($stationTaskMaterialBox);
+        }
     }
+
     function processNextQueued(StationTaskMaterialBox $stationTaskMaterialBox_lastProcessed){
         $station_id=$stationTaskMaterialBox_lastProcessed['station_id'];
         $stationTaskMaterialBox_next=StationTaskMaterialBox::query()