|
@@ -93,8 +93,6 @@ class StorageController extends Controller
|
|
|
*/
|
|
*/
|
|
|
public function checkMaximum()
|
|
public function checkMaximum()
|
|
|
{
|
|
{
|
|
|
- $track = request("track");
|
|
|
|
|
- $barCode = request("barCode");
|
|
|
|
|
$lotNum = request("lotNum");
|
|
$lotNum = request("lotNum");
|
|
|
$sql = <<<SQL
|
|
$sql = <<<SQL
|
|
|
SELECT * FROM INV_LOT_ATT WHERE LOTNUM = '{$lotNum}'
|
|
SELECT * FROM INV_LOT_ATT WHERE LOTNUM = '{$lotNum}'
|
|
@@ -106,7 +104,7 @@ SQL;
|
|
|
})->where("sku",$lot->sku)->first();
|
|
})->where("sku",$lot->sku)->first();
|
|
|
if (!$commodity)$this->error("WAS无此商品信息");
|
|
if (!$commodity)$this->error("WAS无此商品信息");
|
|
|
$models = CommodityMaterialBoxModel::query()->where("commodity_id",$commodity->id)->get();
|
|
$models = CommodityMaterialBoxModel::query()->where("commodity_id",$commodity->id)->get();
|
|
|
- if ($models->count()==0)$this->success(["material_box_model_id"=>null]);
|
|
|
|
|
|
|
+ if ($models->count()==0)$this->success(["material_box_model_id"=>null,"commodity_id"=>$commodity->id]);
|
|
|
$map = [];
|
|
$map = [];
|
|
|
foreach ($models as $model)$map[$model->material_box_model_id] = $model;
|
|
foreach ($models as $model)$map[$model->material_box_model_id] = $model;
|
|
|
$models = app("MaterialBoxModelService")->getModelSortedByOwner($commodity->owner_id);
|
|
$models = app("MaterialBoxModelService")->getModelSortedByOwner($commodity->owner_id);
|
|
@@ -114,14 +112,9 @@ SQL;
|
|
|
foreach ($models as $model){
|
|
foreach ($models as $model){
|
|
|
if (!isset($map[$model->id]))continue;
|
|
if (!isset($map[$model->id]))continue;
|
|
|
$model->maximum = $map[$model->id]->maximum;
|
|
$model->maximum = $map[$model->id]->maximum;
|
|
|
- $boxes = app("MaterialBoxService")->getModelAvailableBox($model->id);
|
|
|
|
|
- if ($boxes->count()==0)continue;
|
|
|
|
|
|
|
+ $boxCodes = app("MaterialBoxService")->getModelAvailableBox($model->id,true);
|
|
|
|
|
+ if (!$boxCodes)continue;
|
|
|
if (!$m)$m = $model;
|
|
if (!$m)$m = $model;
|
|
|
- $boxCodes = "";
|
|
|
|
|
- foreach ($boxes as $box){
|
|
|
|
|
- $boxCodes .= "'".$box->code."',";
|
|
|
|
|
- }
|
|
|
|
|
- $boxCodes = rtrim($boxCodes,",");
|
|
|
|
|
$sql = <<<SQL
|
|
$sql = <<<SQL
|
|
|
SELECT LOCATIONID,({$model->maximum}-QTY) AS QTY FROM INV_LOT_LOC_ID WHERE LOTNUM = '{$lotNum}'
|
|
SELECT LOCATIONID,({$model->maximum}-QTY) AS QTY FROM INV_LOT_LOC_ID WHERE LOTNUM = '{$lotNum}'
|
|
|
AND LOCATIONID IN ({$boxCodes}) AND TRACEID = '*' AND {$model->maximum}-QTY > 0 ORDER BY (CASE QTY WHEN 0 THEN 1 ELSE 0 END),{$model->maximum}-QTY
|
|
AND LOCATIONID IN ({$boxCodes}) AND TRACEID = '*' AND {$model->maximum}-QTY > 0 ORDER BY (CASE QTY WHEN 0 THEN 1 ELSE 0 END),{$model->maximum}-QTY
|
|
@@ -130,11 +123,12 @@ SQL;
|
|
|
if ($res){
|
|
if ($res){
|
|
|
$m = $model;
|
|
$m = $model;
|
|
|
$m->maximum = $res->qty;
|
|
$m->maximum = $res->qty;
|
|
|
|
|
+ $m->location = $res->locationid;
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
if (!$m)$this->error("没有可用料箱");
|
|
if (!$m)$this->error("没有可用料箱");
|
|
|
- $this->success(["need"=>$m->maximum,"material_box_model_id"=>$m->id,"commodity_id"=>$commodity->id]);
|
|
|
|
|
|
|
+ $this->success(["need"=>$m->maximum,"material_box_model_id"=>$m->id,"commodity_id"=>$commodity->id,"location"=>$m->locationid]);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -204,49 +198,59 @@ sql;
|
|
|
if (!$station)$this->error("未知库位");
|
|
if (!$station)$this->error("未知库位");
|
|
|
$isAvailable = app("StationService")->isAvailable($station);
|
|
$isAvailable = app("StationService")->isAvailable($station);
|
|
|
if (!$isAvailable)$this->error("库存被占用或存在任务未处理");
|
|
if (!$isAvailable)$this->error("库存被占用或存在任务未处理");
|
|
|
- $amount = app("StorageService")->checkPutAmount(request("asn"),request("barCode"));
|
|
|
|
|
|
|
+ $amount = app("StorageService")->checkPutAmount(request("track"),request("barCode"),request("lotNum"));
|
|
|
if ($amount<request("amount"))$this->error("待上架数量不足,最大可上数量为{$amount}");
|
|
if ($amount<request("amount"))$this->error("待上架数量不足,最大可上数量为{$amount}");
|
|
|
|
|
|
|
|
//发起取箱任务
|
|
//发起取箱任务
|
|
|
- $exe = function ($boxId)use($station){
|
|
|
|
|
|
|
+ $exe = function ($boxId)use($station,$amount){
|
|
|
DB::beginTransaction();
|
|
DB::beginTransaction();
|
|
|
- $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
|
|
|
|
|
- ]);
|
|
|
|
|
- DB::commit();
|
|
|
|
|
- //亮灯
|
|
|
|
|
- app("CacheShelfService")->lightUp($station->code,'3','2');
|
|
|
|
|
- app("StationService")->locationOccupy($station->code);//占用库位
|
|
|
|
|
- Cache::forever("CACHE_SHELF_OCCUPANCY_{$station->id}",true);
|
|
|
|
|
|
|
+ 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','2');
|
|
|
|
|
+ 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($exe($boxId));
|
|
|
|
|
- $item = app("StoreItemService")->getMaxAvailableDetail(request("asn"),request("barCode"));
|
|
|
|
|
- if (!$item)$this->error("无此单据记录");
|
|
|
|
|
- $models = app("MaterialBoxModelService")->getModelSortedByOwner($item->store->owner_id);
|
|
|
|
|
- $models->load(["commodity"=>function($query)use($item){
|
|
|
|
|
- $query->where("commodity_id",$item->commodity_id);
|
|
|
|
|
|
|
+ //检查获取的料箱仍然可用
|
|
|
|
|
+ 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){
|
|
if ($boxId){
|
|
@@ -254,18 +258,18 @@ sql;
|
|
|
$boxId = null;
|
|
$boxId = null;
|
|
|
//料箱存在且不可用
|
|
//料箱存在且不可用
|
|
|
/** @var \Illuminate\Database\Eloquent\Collection $models */
|
|
/** @var \Illuminate\Database\Eloquent\Collection $models */
|
|
|
-
|
|
|
|
|
foreach ($models as $model){
|
|
foreach ($models as $model){
|
|
|
if (!$model->commodity)continue;
|
|
if (!$model->commodity)continue;
|
|
|
//料箱不可用寻找新料箱
|
|
//料箱不可用寻找新料箱
|
|
|
- $result = app("StorageService")->getHalfBoxLocation($model->commodity,$item,request("asn"),$blacklist);
|
|
|
|
|
|
|
+ $result = app("StorageService")->getMaxAvailableHalfBoxLocation($model->commodity, request("lotNum"), $blacklist);
|
|
|
while ($result){
|
|
while ($result){
|
|
|
|
|
+ $materialBox = MaterialBox::query()->where("code",$result->locationid)->first();
|
|
|
//料箱可用并且数量符合本次半箱数量 跳出
|
|
//料箱可用并且数量符合本次半箱数量 跳出
|
|
|
- if (app("MaterialBoxService")->checkUsableBox($result->material_box_id)
|
|
|
|
|
- && $model->maximum-$result->amount>=request("amount"))$this->success($exe($result->material_box_id));
|
|
|
|
|
- else $blacklist[] = $result->material_box_id;
|
|
|
|
|
|
|
+ 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")->getHalfBoxLocation($model->commodity,$item,request("asn"),$blacklist);
|
|
|
|
|
|
|
+ $result = app("StorageService")->getMaxAvailableHalfBoxLocation($model->commodity, request("lotNum"), $blacklist);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -279,7 +283,7 @@ sql;
|
|
|
}
|
|
}
|
|
|
}else $box = app("MaterialBoxService")->getAnEmptyBox(MaterialBoxModel::query()->find($modelId));
|
|
}else $box = app("MaterialBoxService")->getAnEmptyBox(MaterialBoxModel::query()->find($modelId));
|
|
|
if (!$box)$this->error("无可用料箱");
|
|
if (!$box)$this->error("无可用料箱");
|
|
|
- $this->success($exe($box->id));
|
|
|
|
|
|
|
+ $this->success(["status"=>$exe($box->id),"amount"=>$amount-request("amount")]);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -432,7 +436,6 @@ sql;
|
|
|
{
|
|
{
|
|
|
$insert = function ($commodityId){
|
|
$insert = function ($commodityId){
|
|
|
$in = [];
|
|
$in = [];
|
|
|
- $map = [];
|
|
|
|
|
$ids = [];
|
|
$ids = [];
|
|
|
foreach (request("models") as $model){
|
|
foreach (request("models") as $model){
|
|
|
$in[] = [
|
|
$in[] = [
|
|
@@ -440,59 +443,30 @@ sql;
|
|
|
"material_box_model_id" => $model["id"],
|
|
"material_box_model_id" => $model["id"],
|
|
|
"maximum" => $model["maximum"]
|
|
"maximum" => $model["maximum"]
|
|
|
];
|
|
];
|
|
|
- $map[$model["id"]] = $model;
|
|
|
|
|
$ids[] = $model["id"];
|
|
$ids[] = $model["id"];
|
|
|
}
|
|
}
|
|
|
- return array($in,$map,$ids);
|
|
|
|
|
|
|
+ return array($in,$ids);
|
|
|
};
|
|
};
|
|
|
- if (request("commodityId")){
|
|
|
|
|
- list($in,$map,$ids) = $insert(request("commodityId"));
|
|
|
|
|
- if ($ids){
|
|
|
|
|
- $map = array_flip($ids);
|
|
|
|
|
- foreach (CommodityMaterialBoxModel::query()->where("commodity_id",request("commodityId"))
|
|
|
|
|
- ->lockForUpdate()->get() as $model){
|
|
|
|
|
- $index = $map[$model->material_box_model_id];
|
|
|
|
|
- if ($model->maximum != $in[$index]["maximum"]){
|
|
|
|
|
- CommodityMaterialBoxModel::query()->where("commodity_id",request("commodityId"))
|
|
|
|
|
- ->where("material_box_model_id",$model->material_box_model_id)
|
|
|
|
|
- ->update(["maximum"=>$in[$index]["maximum"]]);
|
|
|
|
|
- }
|
|
|
|
|
- unset($in[$index]);
|
|
|
|
|
|
|
+ list($in,$ids) = $insert(request("commodityId"));
|
|
|
|
|
+ if ($ids){
|
|
|
|
|
+ $map = array_flip($ids);
|
|
|
|
|
+ foreach (CommodityMaterialBoxModel::query()->where("commodity_id",request("commodityId"))
|
|
|
|
|
+ ->lockForUpdate()->get() as $model){
|
|
|
|
|
+ $index = $map[$model->material_box_model_id];
|
|
|
|
|
+ if ($model->maximum != $in[$index]["maximum"]){
|
|
|
|
|
+ CommodityMaterialBoxModel::query()->where("commodity_id",request("commodityId"))
|
|
|
|
|
+ ->where("material_box_model_id",$model->material_box_model_id)
|
|
|
|
|
+ ->update(["maximum"=>$in[$index]["maximum"]]);
|
|
|
}
|
|
}
|
|
|
- $in = array_values($in);
|
|
|
|
|
- }
|
|
|
|
|
- if ($in){
|
|
|
|
|
- LogService::log(__CLASS__,__METHOD__,json_encode($in));
|
|
|
|
|
- CommodityMaterialBoxModel::query()->insert($in);
|
|
|
|
|
|
|
+ unset($in[$index]);
|
|
|
}
|
|
}
|
|
|
- $this->success();
|
|
|
|
|
|
|
+ $in = array_values($in);
|
|
|
}
|
|
}
|
|
|
- $item = StoreItem::query()->whereHas("store",function (Builder $query){
|
|
|
|
|
- $query->where("asn_code",request("asn"));
|
|
|
|
|
- })->whereHas("commodity",function (Builder $query){
|
|
|
|
|
- $query->whereHas("barcodes",function (Builder $query){
|
|
|
|
|
- $query->where("code",request("barCode"));
|
|
|
|
|
- });
|
|
|
|
|
- })->first();
|
|
|
|
|
- if (!$item)$this->error("商品不存在");
|
|
|
|
|
- list($in,$map,$ids) = $insert($item->store->commodity_id);
|
|
|
|
|
- LogService::log(__CLASS__,__METHOD__,json_encode($in));
|
|
|
|
|
- CommodityMaterialBoxModel::query()->insert($in);
|
|
|
|
|
- $this->getMaterBoxModel($item,$map);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private function getMaterBoxModel($commodity,$map)
|
|
|
|
|
- {
|
|
|
|
|
- $models = app("MaterialBoxModelService")->getModelSortedByOwner($commodity->owner_id);
|
|
|
|
|
- foreach ($models as $model){
|
|
|
|
|
- if (!isset($map[$model->id]))continue;
|
|
|
|
|
- //$result = app("StorageService")->getHalfBoxLocation($map[$model->id],$item,$item->store->asn_code);
|
|
|
|
|
- $result = app("StorageService")->getMaxAvailableHalfBoxLocation($map[$model->id],$item,$item->store->asn_code);
|
|
|
|
|
- if (!$result)continue;
|
|
|
|
|
- $result->maximum = $model->maximum-$result->amount;
|
|
|
|
|
- $this->success($result);
|
|
|
|
|
|
|
+ if ($in){
|
|
|
|
|
+ LogService::log(__CLASS__,__METHOD__,json_encode($in));
|
|
|
|
|
+ CommodityMaterialBoxModel::query()->insert($in);
|
|
|
}
|
|
}
|
|
|
- $this->success(["need"=>$models[0]->maximum,"material_box_model_id"=>$models[0]->material_box_model_id,"commodity_id"=>$commodity->id]);
|
|
|
|
|
|
|
+ $this->success();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|