LD vor 5 Jahren
Ursprung
Commit
7f3abebe97

+ 13 - 4
app/Services/ForeignHaiRoboticsService.php

@@ -15,7 +15,7 @@ use Ramsey\Collection\Collection;
 
 class ForeignHaiRoboticsService
 {
-    /** @var StationTaskMaterialBoxService $stationTaskMaterialBoxService  */
+    /** @var  $stationTaskMaterialBoxService StationTaskMaterialBoxService */
     private $stationTaskMaterialBoxService;
     public function __construct()
     {
@@ -124,16 +124,25 @@ class ForeignHaiRoboticsService
                     =$status)==1){
                 throw new ErrorException('海柔任务失败');
             }
+            if($stationTaskMaterialBox
+                =(function()use($taskCode,$binCode){
+                $stationTaskMaterialBox=StationTaskMaterialBox::query()->find($taskCode);
+                if($stationTaskMaterialBox['code']==$binCode)return $stationTaskMaterialBox;
+                return null;
+            })()){
+                throw new ErrorException('发回的料箱和任务号(ID)不匹配');
+            };
+
             if(($isPut
                     =$updateEventType)==0){
-                $this->stationTaskMaterialBoxService->markHasPut($taskCode,$binCode);
+                $this->stationTaskMaterialBoxService->markHasPut($stationTaskMaterialBox);
             }
             if(($isGet
                     =$updateEventType)==1){
-                $this->stationTaskMaterialBoxService->markHasTaken($taskCode,$binCode);
+                $this->stationTaskMaterialBoxService->markHasTaken($stationTaskMaterialBox);
             }
         }catch (\Exception $e){
-            $this->excepted($taskCode,$binCode);
+            $this->excepted($taskCode, $binCode);
             return false;
         }
         return true;

+ 28 - 17
app/Services/StationTaskMaterialBoxService.php

@@ -28,18 +28,20 @@ class StationTaskMaterialBoxService
     }
     function createByBatches(array $batches,Collection $stationTasks_toAttach): Collection
     {
-        return $this->stationTaskService
+        $stationTaskMaterialBoxes = (function () use ($batches) {
+            $stationTaskMaterialBoxes_listByBatch = new Collection();
+            foreach ($batches as $batch) {
+                $stationTaskMaterialBoxes_listByBatch->push(
+                    $this->createByBatch($batch)
+                );
+            }
+            return $stationTaskMaterialBoxes_listByBatch;
+        })();
+         $this->stationTaskService
             ->registerSubTasks(
                 $stationTasks_toAttach,
-                (function()use($batches){
-                    $stationTaskMaterialBoxes_listByBatch=new Collection();
-                    foreach ($batches as $batch){
-                        $stationTaskMaterialBoxes_listByBatch->push(
-                            $this->createByBatch($batch)
-                        );
-                    }
-                    return $stationTaskMaterialBoxes_listByBatch;
-                })());
+                $stationTaskMaterialBoxes);
+        return $stationTaskMaterialBoxes;
 
     }
 
@@ -48,11 +50,13 @@ class StationTaskMaterialBoxService
         $this->materialBoxService=app('MaterialBoxService');
         $this->stationTypeService=app('StationTypeService');
         $this->stationService=app('StationService');
+
         $stationMaterialBoxes_toCreate=new Collection();
         $order_ids=data_get($batch['orders'],'*.id');
         $orderCommodities=OrderCommodity::query()->with('orderBin')->whereIn('order_id',$order_ids)->get();
+        if($orderCommodities->isEmpty())return ;
+        $stationType=$this->stationTypeService->getForMaterialBox_onBatchProcess();
         foreach ($orderCommodities as $orderCommodity){
-            $stationType=$this->stationTypeService->getForMaterialBox();
             $station=$this->stationService->getStation_byType($stationType['name']);
             $materialBox=$this->materialBoxService->firstOrCreate(['code' => $orderCommodity['location']]);
             $stationMaterialBoxes_toCreate->push([
@@ -84,14 +88,21 @@ class StationTaskMaterialBoxService
         return $inserted;
     }
 
-    function markHasPut($taskCode,$binCode){
-        //如果
-        //标记箱子任务处理中
-        //标记箱子关联的商品任务处理中
-        //标记波次处理中
+    function markHasPut($stationTaskMaterialBox){
+        //如果任务属于服务波次的
+            //交给波次服务处理
+    }
+
+    function markHasTaken($stationTaskMaterialBox){
+
     }
 
-    function markHasTaken($taskCode,$binCode){
+    function getServingTaskType(StationTaskMaterialBox $stationTaskMaterialBox){
+//        $isBatch;
+//        $isStoring;
+        if($stationTaskMaterialBox['station_task_batch_id']){
 
+        }
+        $stationTaskMaterialBox->task();
     }
 }

+ 2 - 2
app/Services/StationTaskService.php

@@ -56,8 +56,8 @@ class StationTaskService
                     'station_task_table_type' => $tableName,
                     'station_task_table_id' => $subTask['id'],
                 ];
-                $taskChild=$this->stationTaskChildService->get($paramToInsert)->frist();
-                if(!$taskChild)
+                $taskChild_existed=$this->stationTaskChildService->get($paramToInsert)->frist();
+                if(!$taskChild_existed)
                     $taskChildren_toInsert->push($paramToInsert);
             }
         }

+ 1 - 1
app/Services/StationTypeService.php

@@ -29,7 +29,7 @@ class StationTypeService
         $stationType= StationType::query()->firstOrCreate(['name'=>'料箱监视器']);
         return $stationType;
     }
-    function getForMaterialBox(): StationType
+    function getForMaterialBox_onBatchProcess(): StationType
     {
         /** @var StationType $stationType */
         $stationType= StationType::query()->firstOrCreate(['name'=>'料箱监视器']);

+ 5 - 1
app/StationTaskMaterialBox.php

@@ -12,7 +12,11 @@ class StationTaskMaterialBox extends ModelExtended
     {   //料箱
         return $this->hasOne(MaterialBox::class,"id","material_box_id");
     }
-    function parentTask(){
+    public function station()
+    {   //料箱
+        return $this->belongsTo(Station::class,"id","station_id");
+    }
+    function task(){
         return $this->morphOne(StationTask::class,'station_taskable');
     }
 }

+ 6 - 2
database/migrations/2020_12_24_155647_add_column_material_task_type_drop_station_mission_tables.php

@@ -17,8 +17,9 @@ class AddColumnMaterialTaskTypeDropStationMissionTables extends Migration
         Schema::dropIfExists('station_mission_batches');
         Schema::dropIfExists('station_mission_commodities');
         Schema::dropIfExists('station_mission_material_boxes');
-        Schema::table('station_task_material_boxes',function($table){
+        Schema::table('station_task_material_boxes',function(Blueprint $table){
             $table->enum('type',['取','放','移动']);
+            $table->bigInteger('station_task_batch_id')->index()->nullable();
         });
     }
 
@@ -29,6 +30,9 @@ class AddColumnMaterialTaskTypeDropStationMissionTables extends Migration
      */
     public function down()
     {
-        //
+        Schema::table('station_task_material_boxes',function(Blueprint $table){
+            $table->dropColumn('type');
+            $table->dropColumn('station_task_batch_id');
+        });
     }
 }