|
@@ -192,8 +192,12 @@ sql;
|
|
|
public function acquireBox()
|
|
public function acquireBox()
|
|
|
{
|
|
{
|
|
|
$this->gate("入库管理-入库-半箱补货入库");
|
|
$this->gate("入库管理-入库-半箱补货入库");
|
|
|
-
|
|
|
|
|
- list($track, $barCode, $lotNum, $amount) = request()->only(["track","barCode","lotNum","amount"]);
|
|
|
|
|
|
|
+ $param = request()->only(["track","barCode","lotNum","amount","call"]);
|
|
|
|
|
+ $track = $param["track"] ?? null;
|
|
|
|
|
+ $barCode = $param["barCode"] ?? null;
|
|
|
|
|
+ $lotNum = $param["lotNum"] ?? null;
|
|
|
|
|
+ $amount = $param["amount"] ?? null;
|
|
|
|
|
+ $manualCall = $param["call"] ?? false;
|
|
|
if (!$track || !$barCode || !$lotNum || !$amount)$this->error("提交信息不完整");
|
|
if (!$track || !$barCode || !$lotNum || !$amount)$this->error("提交信息不完整");
|
|
|
|
|
|
|
|
$sql = <<<SQL
|
|
$sql = <<<SQL
|
|
@@ -206,7 +210,7 @@ WHERE FMID = ? AND FMLOTNUM = ? AND
|
|
|
AND TASKPROCESS = '00' AND TASKTYPE = 'PA'
|
|
AND TASKPROCESS = '00' AND TASKTYPE = 'PA'
|
|
|
GROUP BY FMID,FMLOTNUM,TSK_TASKLISTS.SKU,TSK_TASKLISTS.CUSTOMERID
|
|
GROUP BY FMID,FMLOTNUM,TSK_TASKLISTS.SKU,TSK_TASKLISTS.CUSTOMERID
|
|
|
SQL;
|
|
SQL;
|
|
|
- $task = DB::connection("oracle")->selectOne(DB::raw($sql));
|
|
|
|
|
|
|
+ $task = DB::connection("oracle")->selectOne(DB::raw($sql),[$track,$lotNum,$barCode,$barCode,$barCode]);
|
|
|
if (!$task || $task->qty<$amount)$this->error("待上架数量不足");
|
|
if (!$task || $task->qty<$amount)$this->error("待上架数量不足");
|
|
|
$commodity = Commodity::query()->whereHas("owner",function ($query)use($task){
|
|
$commodity = Commodity::query()->whereHas("owner",function ($query)use($task){
|
|
|
$query->where("code",$task->customerid);
|
|
$query->where("code",$task->customerid);
|
|
@@ -219,7 +223,7 @@ SQL;
|
|
|
$query->where("commodity_id",$commodity->id);
|
|
$query->where("commodity_id",$commodity->id);
|
|
|
}]);
|
|
}]);
|
|
|
$models = $models->whereNotNull("commodity");
|
|
$models = $models->whereNotNull("commodity");
|
|
|
- if ($models->count()==0)$this->success(["status"=>false]);
|
|
|
|
|
|
|
+ if ($models->count()==0)$this->success(["status"=>false,"commodityId"=>$commodity->id]);
|
|
|
|
|
|
|
|
//设定一个默认缓存架 仅用于任务占位 没有实际作用
|
|
//设定一个默认缓存架 仅用于任务占位 没有实际作用
|
|
|
$defaultStation = Station::query()->where("station_type_id",5)
|
|
$defaultStation = Station::query()->where("station_type_id",5)
|
|
@@ -259,19 +263,44 @@ SQL;
|
|
|
return $task;
|
|
return $task;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- $stations = app("StationService")->getCacheShelf(true);
|
|
|
|
|
|
|
+ $stations = app("StationService")->getCacheShelf(true,true);
|
|
|
$collection = collect();
|
|
$collection = collect();
|
|
|
$location = collect();
|
|
$location = collect();
|
|
|
$ids = [];
|
|
$ids = [];
|
|
|
//寻找半箱
|
|
//寻找半箱
|
|
|
- foreach ($models as $model){
|
|
|
|
|
- list($invs,$map) = app("StorageService")->getMaxAvailableHalfBoxLocation($model->commodity, request("lotNum"));
|
|
|
|
|
- if (!$invs)continue;
|
|
|
|
|
|
|
+ $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){
|
|
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)->lockForUpdate()->get();
|
|
|
|
|
+ //筛选下海柔可用箱
|
|
|
|
|
+ list($codes,$notCodes) = app("MaterialBoxService")->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;
|
|
|
|
|
+ });
|
|
|
|
|
+ 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];
|
|
|
$station = $stations->last();
|
|
$station = $stations->last();
|
|
|
- $boxId = $map[$inv->locationid];
|
|
|
|
|
- $number = $amount >= $inv->qty ? $amount-$inv->qty : $amount;
|
|
|
|
|
- $task = $exe($station, $boxId, $number);
|
|
|
|
|
|
|
+ $number = $amount >= $num ? $amount-$num : $amount;
|
|
|
|
|
+ $task = $exe($station, $box->id, $number);
|
|
|
if ($station){
|
|
if ($station){
|
|
|
$stations->offsetUnset($stations->count()-1);
|
|
$stations->offsetUnset($stations->count()-1);
|
|
|
$collection->push($task);
|
|
$collection->push($task);
|
|
@@ -281,8 +310,8 @@ SQL;
|
|
|
$amount -= $number;
|
|
$amount -= $number;
|
|
|
if ($amount==0)break;
|
|
if ($amount==0)break;
|
|
|
}
|
|
}
|
|
|
- if ($amount==0)break;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
if ($amount){
|
|
if ($amount){
|
|
|
//寻找空箱
|
|
//寻找空箱
|
|
|
$blacklist = [];//空箱逐一寻找需要列队黑名单
|
|
$blacklist = [];//空箱逐一寻找需要列队黑名单
|
|
@@ -308,7 +337,8 @@ SQL;
|
|
|
if ($location->count()){
|
|
if ($location->count()){
|
|
|
/** @var ForeignHaiRoboticsService $service */
|
|
/** @var ForeignHaiRoboticsService $service */
|
|
|
$service = app("ForeignHaiRoboticsService");
|
|
$service = app("ForeignHaiRoboticsService");
|
|
|
- $result = $service->fetchGroup_multiLocation($location,$collection,'','立架出至缓存架');
|
|
|
|
|
|
|
+ if ($manualCall)$result = $this->mergeIntoCache($location,$collection);
|
|
|
|
|
+ else $result = $service->fetchGroup_multiLocation($location,$collection,'','立架出至缓存架');
|
|
|
if (!$result){
|
|
if (!$result){
|
|
|
DB::rollBack();
|
|
DB::rollBack();
|
|
|
$this->error("机器人呼叫失败,海柔任务错误");
|
|
$this->error("机器人呼叫失败,海柔任务错误");
|
|
@@ -335,105 +365,35 @@ SQL;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 取得料箱 废弃
|
|
|
|
|
|
|
+ * 并入缓存 等待呼叫
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param Collection $location
|
|
|
|
|
+ * @param Collection $collection
|
|
|
|
|
+ *
|
|
|
|
|
+ * @return bool
|
|
|
*/
|
|
*/
|
|
|
- public function acquireBoxTemp()
|
|
|
|
|
|
|
+ public function mergeIntoCache(Collection $location,Collection $collection):bool
|
|
|
{
|
|
{
|
|
|
- $this->gate("入库管理-入库-半箱补货入库");
|
|
|
|
|
- $boxId = request("material_box_id");
|
|
|
|
|
- $modelId = request("material_box_model_id");
|
|
|
|
|
- if (!$modelId)$this->error("商品未设定库存上限");
|
|
|
|
|
- //获取目标库位
|
|
|
|
|
- $station = app("StationService")->getMirrorMappingLocation(request("station"));
|
|
|
|
|
- if (!$station)$this->error("未知库位");
|
|
|
|
|
- $isAvailable = app("StationService")->isAvailable($station);
|
|
|
|
|
- if (!$isAvailable)$this->error("库存被占用或存在任务未处理");
|
|
|
|
|
- $amount = app("StorageService")->checkPutAmount(request("track"),request("barCode"),request("lotNum"));
|
|
|
|
|
- if ($amount<request("amount"))$this->error("待上架数量不足,最大可上数量为{$amount}");
|
|
|
|
|
-
|
|
|
|
|
- //发起取箱任务
|
|
|
|
|
- $exe = function ($boxId)use($station,$amount){
|
|
|
|
|
- DB::beginTransaction();
|
|
|
|
|
- try{
|
|
|
|
|
- $collection = new Collection();
|
|
|
|
|
- $task = StationTask::query()->create([
|
|
|
|
|
- 'status' => "待处理",
|
|
|
|
|
- 'station_id' => $station->id,
|
|
|
|
|
- ]);
|
|
|
|
|
- $collection->add(StationTaskMaterialBox::query()->create([
|
|
|
|
|
- 'station_id' => $station->id,
|
|
|
|
|
- 'material_box_id'=>$boxId,
|
|
|
|
|
- 'status'=>"待处理",
|
|
|
|
|
- 'type' => '取',
|
|
|
|
|
- 'station_task_id' => $task->id,
|
|
|
|
|
- ]));
|
|
|
|
|
- if (!app("ForeignHaiRoboticsService")->fetchGroup($station->code,$collection,'','立架出至缓存架'))$this->error("呼叫机器人失败");
|
|
|
|
|
- //生成临时任务事务
|
|
|
|
|
- TaskTransaction::query()->create([
|
|
|
|
|
- //"doc_code" => request("asn"),
|
|
|
|
|
- "bar_code" => request("barCode"),
|
|
|
|
|
- "fm_station_id" => $station->id,
|
|
|
|
|
- "material_box_id" => $boxId,
|
|
|
|
|
- "commodity_id" => request("commodity_id"),
|
|
|
|
|
- "amount" => request("amount"),
|
|
|
|
|
- "type" => "入库",
|
|
|
|
|
- "user_id" => Auth::id(),
|
|
|
|
|
- "mark" => 1,
|
|
|
|
|
- "lot_num" => request("lotNum"),
|
|
|
|
|
- "track_num" => request("track"),
|
|
|
|
|
- ]);
|
|
|
|
|
- //亮灯
|
|
|
|
|
- app("CacheShelfService")->lightUp($station->code,'3','0');
|
|
|
|
|
- app("StationService")->locationOccupy($station->code);//占用库位
|
|
|
|
|
- Cache::forever("CACHE_SHELF_OCCUPANCY_{$station->id}",true);
|
|
|
|
|
- DB::commit();
|
|
|
|
|
- return true;
|
|
|
|
|
- }catch (\Exception $e){
|
|
|
|
|
- DB::rollBack();
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
- };
|
|
|
|
|
- //检查获取的料箱仍然可用
|
|
|
|
|
- if ($boxId && app("MaterialBoxService")->checkUsableBox($boxId))$this->success(["status"=>$exe($boxId),"amount"=>$amount-request("amount")]);
|
|
|
|
|
-
|
|
|
|
|
- $commodity = Commodity::query()->find(request("commodity_id"));
|
|
|
|
|
- if (!$commodity)$this->error("商品在WAS丢失");
|
|
|
|
|
- $models = app("MaterialBoxModelService")->getModelSortedByOwner($commodity->owner_id);
|
|
|
|
|
- $models->load(["commodity"=>function($query)use($commodity){
|
|
|
|
|
- $query->where("commodity_id",$commodity->id);
|
|
|
|
|
- }]);
|
|
|
|
|
- //获取料箱
|
|
|
|
|
- if ($boxId){
|
|
|
|
|
- $blacklist = [$boxId];
|
|
|
|
|
- $boxId = null;
|
|
|
|
|
- //料箱存在且不可用
|
|
|
|
|
- /** @var \Illuminate\Database\Eloquent\Collection $models */
|
|
|
|
|
- foreach ($models as $model){
|
|
|
|
|
- if (!$model->commodity)continue;
|
|
|
|
|
- //料箱不可用寻找新料箱
|
|
|
|
|
- $result = app("StorageService")->getMaxAvailableHalfBoxLocation($model->commodity, request("lotNum"), $blacklist);
|
|
|
|
|
- while ($result){
|
|
|
|
|
- $materialBox = MaterialBox::query()->where("code",$result->locationid)->first();
|
|
|
|
|
- //料箱可用并且数量符合本次半箱数量 跳出
|
|
|
|
|
- if ($materialBox && app("MaterialBoxService")->checkUsableBox($materialBox->id)
|
|
|
|
|
- && $result->qty>=request("amount"))$this->success(["status"=>$exe($materialBox->id),"amount"=>$amount-request("amount")]);
|
|
|
|
|
- else if ($materialBox)$blacklist[] = $materialBox->id;
|
|
|
|
|
- //否则黑名单此料箱继续查找 直至料箱为空
|
|
|
|
|
- $result = app("StorageService")->getMaxAvailableHalfBoxLocation($model->commodity, request("lotNum"), $blacklist);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ $key = "CACHE_SHELF_CALL_".Auth::id();
|
|
|
|
|
+ if (Cache::has($key)){
|
|
|
|
|
+ list($locationAdd,$collectionAdd) = Cache::get($key);
|
|
|
|
|
+ $location = $locationAdd->merge($location);
|
|
|
|
|
+ $collection = $collectionAdd->merge($collection);
|
|
|
}
|
|
}
|
|
|
- //料箱不存在且该商品有过入库记录 拿取空箱
|
|
|
|
|
- if (!$modelId){
|
|
|
|
|
- $box = null;
|
|
|
|
|
- foreach ($models as $model){
|
|
|
|
|
- if (!$model->commodity)continue;
|
|
|
|
|
- $box = app("MaterialBoxService")->getAnEmptyBox($model);
|
|
|
|
|
- if($box)break;
|
|
|
|
|
- }
|
|
|
|
|
- }else $box = app("MaterialBoxService")->getAnEmptyBox(MaterialBoxModel::query()->find($modelId));
|
|
|
|
|
- if (!$box)$this->error("无可用料箱");
|
|
|
|
|
- $this->success(["status"=>$exe($box->id),"amount"=>$amount-request("amount")]);
|
|
|
|
|
|
|
+ return Cache::forever($key,[$location,$collection]);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function callRobot()
|
|
|
|
|
+ {
|
|
|
|
|
+ /** @var ForeignHaiRoboticsService $service */
|
|
|
|
|
+ $service = app("ForeignHaiRoboticsService");
|
|
|
|
|
+ $key = "CACHE_SHELF_CALL_".Auth::id();
|
|
|
|
|
+ list($location,$collection) = Cache::get($key);
|
|
|
|
|
+ if ($location->count()==0||$collection->count()==0)$this->error("没有可执行任务");
|
|
|
|
|
+ $res = $service->fetchGroup_multiLocation($location,$collection,'','立架出至缓存架');
|
|
|
|
|
+ if (!$res)$this->error("呼叫失败,海柔拒绝任务");
|
|
|
|
|
+ Cache::forget($key);
|
|
|
|
|
+ $this->success();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -448,16 +408,28 @@ SQL;
|
|
|
$box = MaterialBox::query()->where("code",$ide)->first();
|
|
$box = MaterialBox::query()->where("code",$ide)->first();
|
|
|
if (!$box)$this->error("未知料箱");
|
|
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()
|
|
public function syncStorage()
|
|
@@ -588,6 +560,7 @@ sql;
|
|
|
*/
|
|
*/
|
|
|
public function settingModelMaximum()
|
|
public function settingModelMaximum()
|
|
|
{
|
|
{
|
|
|
|
|
+ if (!request("commodityId"))$this->error("未获取商品");
|
|
|
$insert = function ($commodityId){
|
|
$insert = function ($commodityId){
|
|
|
$in = [];
|
|
$in = [];
|
|
|
$ids = [];
|
|
$ids = [];
|