Browse Source

修复多框多商品的状态标记问题

LD 5 years ago
parent
commit
54fcbfd2d7

+ 14 - 11
app/Services/BatchService.php

@@ -10,6 +10,7 @@ use App\OrderCommodity;
 use App\Owner;
 use Exception;
 use Illuminate\Support\Collection;
+use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Http;
 use App\Traits\ServiceAppAop;
 
@@ -70,18 +71,20 @@ class BatchService
             $this->instant($this->stationTaskCommodityService,'StationTaskCommodityService');
             $this->instant($this->stationTaskMaterialBoxService,'StationTaskMaterialBoxService');
 
-            $batches_shouldProcess = $this->stationRuleBatchService->getBatches_shouldProcess($batches); //按规则过滤需要的波次
-            if($batches_shouldProcess->isEmpty()) return;
-            LogService::log(__METHOD__,'assignTasks','波次任务分配2:'.json_encode($batches));
+            DB::transaction(function ()use($batches){
+                $batches_shouldProcess = $this->stationRuleBatchService->getBatches_shouldProcess($batches); //按规则过滤需要的波次
+                if($batches_shouldProcess->isEmpty()) return;
+                LogService::log(__METHOD__,'assignTasks','波次任务分配2:'.json_encode($batches));
 
-            $stationTasks =  $this->stationTaskService->create($batches_shouldProcess->count()); //生成总任务
-            LogService::log(__METHOD__,'assignTasks','波次任务分配3:'.json_encode($batches));
-            $stationTaskBatches=$this->stationTaskBatchService->createByBatches($batches_shouldProcess,$stationTasks); //注册波次任务
-            LogService::log(__METHOD__,'assignTasks','波次任务分配4:'.json_encode($batches));
-            $stationTaskMaterialBoxes=$this->stationTaskMaterialBoxService->createByBatches($batches_shouldProcess,$stationTasks); //注册料箱任务
-            LogService::log(__METHOD__,'assignTasks','波次任务分配5:'.json_encode($stationTaskMaterialBoxes).json_encode($batches));
-            $stationTaskCommodities=$this->stationTaskCommodityService->createByBatches($batches_shouldProcess,$stationTasks); //注册商品任务
-            LogService::log(__METHOD__,'assignTasks','波次任务分配6:'.json_encode($batches));
+                $stationTasks =  $this->stationTaskService->create($batches_shouldProcess->count()); //生成总任务
+                LogService::log(__METHOD__,'assignTasks','波次任务分配3:'.json_encode($batches));
+                $stationTaskBatches=$this->stationTaskBatchService->createByBatches($batches_shouldProcess,$stationTasks); //注册波次任务
+                LogService::log(__METHOD__,'assignTasks','波次任务分配4:'.json_encode($batches));
+                $stationTaskMaterialBoxes=$this->stationTaskMaterialBoxService->createByBatches($batches_shouldProcess,$stationTasks); //注册料箱任务
+                LogService::log(__METHOD__,'assignTasks','波次任务分配5:'.json_encode($stationTaskMaterialBoxes).json_encode($batches));
+                $stationTaskCommodities=$this->stationTaskCommodityService->createByBatches($batches_shouldProcess,$stationTasks); //注册商品任务
+                LogService::log(__METHOD__,'assignTasks','波次任务分配6:'.json_encode($batches));
+            });
 
             $ran=$this->stationTaskBatchService->runMany($stationTaskBatches);//执行波次任务
             LogService::log(__METHOD__,'assignTasks','波次任务分配7:'.json_encode($batches));

+ 1 - 0
app/Services/StationRuleBatchService.php

@@ -68,6 +68,7 @@ class StationRuleBatchService
             if(!$stationRuleBatch)continue;
             if(Cache::get('波次防重叠'.$batch['id']))continue;
             $batches_toProcess->push($batch);
+            Cache::tags(['people', 'artists'])->put('John', $john, $seconds);
             Cache::add('波次防重叠'.$batch['id'],true,config('haiRou.波次防重叠时间_秒'));
         }
         LogService::log(__METHOD__,'shouldProcess','波次任务分配1.3:'.json_encode($batches_inTask));

+ 3 - 0
app/Services/StationTaskMaterialBoxService.php

@@ -92,15 +92,18 @@ class StationTaskMaterialBoxService
         if($orderCommodities->isEmpty())return $stationMaterialBoxes_toCreate;
         $stationType=$this->stationTypeService->getForMaterialBox_onBatchProcess();
         $stationTaskBatch=$this->stationTaskBatchService->get(['batch_id'=>$batch['id']])->first();
+        $materialBoxIds_used=[];
         foreach ($orderCommodities as $orderCommodity){
             $station=$this->stationService->getStation_byType($stationType['name']);
             $materialBox=$this->materialBoxService->firstOrCreate(['code' => $orderCommodity['location']]);
+            if(in_array($materialBox['id'],$materialBoxIds_used))continue;
             $stationMaterialBoxes_toCreate->push([
                 'station_id'=>$station['id'],
                 'material_box_id'=>$materialBox['id'],
                 'station_task_batch_id'=>$stationTaskBatch['id'],
                 'status'=>'待处理'
             ]);
+            $materialBoxIds_used[]=$materialBox['id'];
         }
         return $this->insert($stationMaterialBoxes_toCreate->toArray(),true);
     }