Zhouzhendong 4 лет назад
Родитель
Сommit
12e0d06aff

+ 23 - 10
app/Http/Controllers/StorageController.php

@@ -392,6 +392,7 @@ SQL;
         if ($location->count()==0||$collection->count()==0)$this->error("没有可执行任务");
         $res = $service->fetchGroup_multiLocation($location,$collection,'','立架出至缓存架');
         if (!$res)$this->error("呼叫失败,海柔拒绝任务");
+        Cache::forget($key);
         $this->success();
     }
 
@@ -407,16 +408,28 @@ SQL;
         $box = MaterialBox::query()->where("code",$ide)->first();
         if (!$box)$this->error("未知料箱");
 
-        $task = TaskTransaction::query()->where("material_box_id",$box->id)->where("amount",">",$amount)
-            ->where("type","入库")->where("mark",1)->where("status",0)->first();
-        if (!$task)$this->error("无任务存在");
-        $task->update(["amount" => DB::raw("amount - {$amount}")]);
-        $storage = MaterialBoxCommodity::query()->where("material_box_id",$task->material_box_id)
-            ->where("commodity_id",$task->commodity_id)->first();
-        $maximum = (($storage->amount ?? 0)+$task->amount)-$amount;
-        CommodityMaterialBoxModel::query()->where("material_box_model_id",$task->materialBox->material_box_model_id)
-            ->where("commodity_id",$task->commodity_id)->update(["maximum"=>$maximum]);
-        $this->success("校正成功");
+        DB::beginTransaction();
+        try {
+            $task = TaskTransaction::query()->where("material_box_id",$box->id)->where("amount",">=",$amount)
+                ->where("type","入库")->where("mark",1)->where("status",0)->lockForUpdate()->first();
+            if (!$task)$this->error("无任务存在");
+            if ($task->amount == $amount){
+                $station = Station::query()->find($task->fm_station_id);
+                app("CacheShelfService")->lightUp($station->code);
+                $task->delete();
+            }
+            else $task->update(["amount" => DB::raw("amount - {$amount}")]);
+            $storage = MaterialBoxCommodity::query()->where("material_box_id",$task->material_box_id)
+                ->where("commodity_id",$task->commodity_id)->first();
+            $maximum = (($storage->amount ?? 0)+$task->amount)-$amount;
+            CommodityMaterialBoxModel::query()->where("material_box_model_id",$task->materialBox->material_box_model_id)
+                ->where("commodity_id",$task->commodity_id)->update(["maximum"=>$maximum]);
+            DB::commit();
+            $this->success("校正成功");
+        }catch (\Exception $e){
+            DB::rollBack();
+            $this->error("校正失败");
+        }
     }
 
     public function syncStorage()

+ 77 - 77
app/Http/Controllers/TestController.php

@@ -8,6 +8,7 @@ use App\Components\AsyncResponse;
 use App\Components\ErrorPush;
 use App\ErrorTemp;
 use App\Feature;
+use App\Jobs\CacheShelfTaskJob;
 use App\Jobs\OrderCreateWaybill;
 use App\MaterialBox;
 use App\MaterialBoxModel;
@@ -65,86 +66,85 @@ class TestController extends Controller
         $response = Http::post(config('api.haiq.storage.light'), $params);
         return json_decode($response->body());
     }
-    private function checkHaiQ(array $boxCodes)
-    {
-        $haiBoxes = DB::connection("mysql_haiRobotics")->table("ks_bin")
-            ->where("status",1)->whereIn("ks_bin_code",$boxCodes)->get();
-        if ($haiBoxes->count()==0)return array(null,null);
-        $codes = [];
-        $haiBoxes->each(function ($haiBox)use(&$codes){$codes[$haiBox->ks_bin_code] = true;});
-        $haiBoxes = DB::connection("mysql_haiRobotics_ess")->table("ks_ess_task_detail")
-            ->whereIn("bin_code",$boxCodes)
-            ->whereNotIn("status",[0,4])->get();
-        $notCodes = [];
-        $haiBoxes->each(function ($haiBox)use(&$notCodes){$notCodes[$haiBox->bin_code] = true;});
-        return array($codes,$notCodes);
-    }
-    public function getModelAvailableBox(int $modelId, bool $sqlQuery = false, array $blacklist = [])
-    {
-        $query = MaterialBox::query()->where("material_box_model_id",$modelId);
-        $boxes = $query->whereNotIn("id",MaterialBox::query()->where("material_box_model_id",$modelId)->select("id")
-            ->whereHas("performTask"));
-        if ($blacklist)$boxes = $boxes->whereNotIn("id",$blacklist);
-        $boxes = $boxes->get();
-        //筛选下海柔可用箱
-        list($codes,$notCodes) = $this->checkHaiQ(array_column($boxes->toArray(),"code"));
-        if (!$codes)$boxes = new \Illuminate\Database\Eloquent\Collection();
-        $boxes = $boxes->filter(function ($box)use($codes,$notCodes){
-            if (!isset($codes[$box->code]) || isset($notCodes[$box->code]))return false;
-            return true;
-        });
 
-        if (!$sqlQuery)return $boxes;
-        if ($boxes->count()==0)return array(null,null);
-        $boxCodes = "";
-        $map = [];
-        foreach ($boxes as $box){
-            $boxCodes .= "'".$box->code."',";
-            $map[$box->code] = $box->id;
-        }
-        return array(rtrim($boxCodes,","),$map);
-    }
     public function test()
     {
-        $a = collect(["a"]);
-        $b = collect(["b"]);
-        dd($a->merge($b));
-        $lotNum = 'LT00551703';
-        $commodity = Commodity::query()->find(593292);
-        /** @var \Illuminate\Database\Eloquent\Collection $models */
-        $models = app("MaterialBoxModelService")->getModelSortedByOwner($commodity->owner_id);
-        $models->load(["commodity"=>function($query)use($commodity){
-            $query->where("commodity_id",$commodity->id);
-        }]);
-        $models = $models->whereNotNull("commodity");
-        if ($models->count()==0)$this->success(["status"=>false,"commodityId"=>$commodity->id]);
-
-
-        $sql = <<<SQL
-SELECT LOCATIONID,QTY FROM INV_LOT_LOC_ID WHERE LOTNUM = '{$lotNum}'
-AND LOCATIONID LIKE 'IDE%' AND SKU = '{$commodity->sku}' AND TRACEID = '*' AND QTY > 0 AND QTY > 0 ORDER BY QTY
-SQL;
-        $invs = DB::connection("oracle")->select(DB::raw($sql));
-        if ($invs){
-            $map = [];
-            $codes = [];
-            foreach ($invs as $inv){
-                $map[$inv->locationid] = $inv->qty;
-                $codes[] = $inv->locationid;
-            }
-            $modelMap = [];
-            $orderBy = "CASE material_box_model_id ";
-            foreach ($models as $key=>$model){
-                $orderBy .= 'WHEN '.$model->id." THEN ".$key;
-                $modelMap[$model->id] = $model->commodity->maximum;
-            }
-            $orderBy.= " END";
-            $boxes = MaterialBox::query()->whereIn("code",$codes)->orderByRaw($orderBy)->get();
-            foreach ($boxes as $box){
-                if ($modelMap[$box->material_box_model_id]<=$map[$box->code])continue;
-                $num = $modelMap[$box->material_box_model_id]-$map[$box->code];
-                dump([$box,$num]);
-            }
+        app("CacheShelfService")->_stationCacheLightOff("HAIB1-01-01");
+        app("CacheShelfService")->_stationCacheLightOff("HAIB1-01-02");
+        app("CacheShelfService")->_stationCacheLightOff("HAIB1-02-02");
+        dd(1);
+        $stationTaskMaterialBox = StationTaskMaterialBox::query()->find(70370);
+        DB::beginTransaction();
+        try{
+            $stationTaskMaterialBox->loadMissing("station");
+            //如果为半箱位置 清理原有任务
+            if (!$stationTaskMaterialBox->station)return;
+            if (app("StationService")->isHalfBoxLocation($stationTaskMaterialBox->station)){
+                app("StationService")->locationOccupy($stationTaskMaterialBox->station->code,$stationTaskMaterialBox->material_box_id);
+                //清除海柔库位信息
+                app("StorageService")->clearTask([$stationTaskMaterialBox->station->code]);
+                $stationId = $stationTaskMaterialBox->station_id;
+                $tasks = TaskTransaction::query()->with("materialBox")->where(function ($query)use($stationId){
+                    $query->where("fm_station_id",$stationId)->orWhere("to_station_id",$stationId);
+                })->where("status",0)->get();
+                if ($tasks->count()!=0){
+                    $options = [];
+                    switch ($tasks[0]->mark){
+                        case 1:
+                            $options["title"] = '上架任务';
+                            break;
+                        case 2:
+                            $options["title"] = '出库任务';
+                            break;
+                        default:
+                            $options["title"] = '未知类型';
+                    }
+                    switch ($tasks->count()){
+                        case 1:
+                            $task = $tasks[0];
+                            $options["detail01"] = $task->materialBox->code ?? '';
+                            $options["detail02"] = $task->doc_code ?: '跟踪:‘'.$task->track_num."’ 批次:‘".$task->lot_num."’";
+                            $options["detail03"] = $task->bar_code;
+                            $options["qty01"] = $task->amount;
+                            $options["uomDesc01"] = '件';
+                            $options["qty02"] = $task->bin_number;
+                            $options["uomDesc02"] = '号';
+                            break;
+                        default:
+                            $count = count(array_unique(array_column($tasks->toArray(),"commodity_id")));
+                            if ($count==1){
+                                $options["detail01"] = $tasks[0]->bar_code;
+                                $options["detail02"] = "";
+                                $options["detail03"] = "";
+                                $amount = 0;
+                                foreach ($tasks as $task){
+                                    if (mb_strlen($options["detail02"])>20){
+                                        $options["detail03"] .= $task->bin_number."号-".$task->amount."件,";
+                                    }else $options["detail02"] .= $task->bin_number."号-".$task->amount."件,";
+                                    $amount += $task->amount;
+                                }
+                                $options["detail02"] = rtrim($options["detail02"],",");
+                                $options["detail03"] = rtrim($options["detail03"],",");
+                                $options["qty02"] = $amount;
+                                $options["uomDesc02"] = '件';
+                            }else{
+                                $task = $tasks[0];
+                                $options["detail01"] = $task->materialBox->code ?? '';
+                                $options["detail02"] = "货品过多请自行核对";
+                                $options["detail03"] = "波次:".$task->doc_code ?
+                                    (Order::query()->with("batch")->where("code",$task->doc_code)->first()->batch->code ?? '无') : '无';
+                            }
+                            break;
+                    }
+                    app("CacheShelfService")->lightUp($stationTaskMaterialBox->station->code,'2','0',$options);
+                    Cache::forget("CACHE_SHELF_OCCUPANCY_{$stationTaskMaterialBox->station->id}");//关闭无限亮灯
+                }
+            }else app("StationService")->locationFreed($stationTaskMaterialBox->station->code); //释放库位占用
+            DB::commit();
+            dd("OK");
+        }catch (\Exception $e){
+            DB::rollBack();
+            dd($e->getTrace());
         }
 
 

+ 1 - 1
app/Http/Controllers/WaybillController.php

@@ -170,7 +170,7 @@ class WaybillController extends Controller
             if ($waybill->type=='德邦物流' && !$oldBill){
                 $bill = app('DbOpenService')->getDbOrderNo($waybill);
                 if (!$bill){DB::rollBack();return "获取德邦单号失败,德邦服务异常";}
-                $waybill->update(["carrier_bill"=>$bill]);
+                $waybill->update(["carrier_bill"=>$bill,'waybill_number'=>$bill]);
                 $msg =  "【申请德邦物流单号:".$bill."】";
                 if (!app("WaybillService")->notifyFlux($waybill))$msg .= ",通知FLUX失败";
                 $stage = '发起德邦调度';

+ 4 - 4
app/Jobs/CacheShelfTaskJob.php

@@ -108,7 +108,7 @@ class CacheShelfTaskJob implements ShouldQueue
                 }else $updateTransaction[] = ["id"=>$obj->id,"to_station_id"=>$stationId,"status"=>0,"updated_at"=>$time];
             },function ($service,$toLocation,$task,$prefix){
                 return $service->fetchGroup_multiLocation($toLocation,$task,$prefix,'立架出至缓存架',20);
-            })){DB::commit();return true;}
+            },"to_station_id")){DB::commit();return true;}
             DB::rollBack();
         }catch (\Exception $e){
             DB::rollBack();
@@ -137,7 +137,7 @@ class CacheShelfTaskJob implements ShouldQueue
                 $updateTransaction[] = ["id"=>$obj->id,"fm_station_id"=>$stationId,"status"=>0,"updated_at"=>$time];
             },function ($service,$toLocation,$task,$prefix){
                 return $service->fetchGroup_multiLocation($toLocation,$task,'','立架出至缓存架');
-            })){DB::commit();return true;}
+            },"fm_station_id")){DB::commit();return true;}
             DB::rollBack();
         }catch (\Exception $e){
             DB::rollBack();
@@ -147,7 +147,7 @@ class CacheShelfTaskJob implements ShouldQueue
     }
 
     private function dispatchTask(\Illuminate\Database\Eloquent\Collection $tasks, array $available, $service,
-                                  \Closure $update, \Closure $execute):bool
+                                  \Closure $update, \Closure $execute, string $stationName):bool
     {
         if (!$tasks->count())return false;
         if ($tasks->count()>count($available))$tasks = $tasks->slice(0,count($available));//事务过多切割部分处理
@@ -156,7 +156,7 @@ class CacheShelfTaskJob implements ShouldQueue
         $availableTemp = array_keys($available);
         $map = app("StationService")->getStationMapping($availableTemp);//获取库位映射信息
         $updateTask = [["id","station_id","updated_at"]];
-        $updateTransaction = [["id","to_station_id","status","updated_at"]];
+        $updateTransaction = [["id",$stationName,"status","updated_at"]];
         $time = date("Y-m-d H:i:s");
         foreach ($tasks as $index=>$obj){
             $loc = $availableTemp[$index];

+ 1 - 0
app/Services/CacheShelfService.php

@@ -66,6 +66,7 @@ class   CacheShelfService
                 $this->lightUp($station->code);
                 return ['success' => true];
             }
+            app("StationService")->locationFreed($station->code);
         }
         try {
             $bool = $this->putBinToStore($station);                         // 推送任务

+ 3 - 2
app/Services/StationService.php

@@ -193,13 +193,14 @@ class StationService
     /**
      * 库位释放
      *
-     * @param string $location
+     * @param ?string $location
      * @param int|null $boxId
      *
      * @return int
      */
-    public function locationFreed(string $location, ?int $boxId=null):int
+    public function locationFreed(?string $location, ?int $boxId=null):int
     {
+        if (!$location)return 0;
         $update = ["status"=>0];
         if ($boxId)$update["material_box_id"]=$boxId;
         return Station::query()->where("code",$location)->update($update);

+ 0 - 1
app/Services/StationTaskMaterialBoxService.php

@@ -221,7 +221,6 @@ class StationTaskMaterialBoxService
             CacheShelfTaskJob::dispatch("CACHE_SHELF_AVAILABLE",count($available))->delay(now()->addSeconds(config("haiRou.cacheShelf.outBinAwait")));
             unset($map[$stationTaskMaterialBox->material_box_id]);
             Cache::forever("CACHE_SHELF_MAPPING",$map);
-            app("StationService")->locationFreed($stationTaskMaterialBox->station->code,$stationTaskMaterialBox->material_box_id);
         }
     }
 

+ 1 - 0
app/Services/StorageService.php

@@ -39,6 +39,7 @@ class StorageService
             //如果为半箱位置 清理原有任务
             if (!$stationTaskMaterialBox->station)return;
             if (app("StationService")->isHalfBoxLocation($stationTaskMaterialBox->station)){
+                app("StationService")->locationOccupy($stationTaskMaterialBox->station->code,$stationTaskMaterialBox->material_box_id);
                 //清除海柔库位信息
                 $this->clearTask([$stationTaskMaterialBox->station->code]);
                 $stationId = $stationTaskMaterialBox->station_id;

+ 4 - 3
resources/views/store/inStorage/halfChestStorage.blade.php

@@ -147,7 +147,7 @@
                 },
                 //提交溢出减量
                 overflowRevision(){
-                    if (!this.ov.station || !this.ov.amount){
+                    if (!this.ov.ide || !this.ov.amount){
                         window.tempTip.show("信息不完整");
                         return;
                     }
@@ -180,7 +180,7 @@
                             this.showMaximumModal();
                             return;
                         }
-                        this.info = {track:this.info.track};
+                        this.info = {track:this.info.track,call:this.info.call};
                         this.errors = {};
                         let element = document.getElementById("barCode");
                         if (element)element.focus();
@@ -291,9 +291,10 @@
                 },
                 callRobot(){
                     window.tempTip.postBasicRequest("{{url('store/inStorage/callRobot')}}",{},()=>{
-                        this.info = {};
+                        this.info = {call:this.info.call};
                         let element = document.getElementById("track");
                         if (element)element.focus();
+                        return '呼叫成功';
                     });
                 }
             },