|
|
@@ -6,16 +6,15 @@ use App\Commodity;
|
|
|
use App\CommodityMaterialBoxModel;
|
|
|
use App\Components\AsyncResponse;
|
|
|
use App\MaterialBox;
|
|
|
+use App\MaterialBoxCommodity;
|
|
|
use App\MaterialBoxModel;
|
|
|
use App\Owner;
|
|
|
use App\Station;
|
|
|
use App\StationTask;
|
|
|
use App\StationTaskMaterialBox;
|
|
|
-use App\Storage;
|
|
|
use App\StoreItem;
|
|
|
use App\TaskTransaction;
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
-use Illuminate\Database\Eloquent\Model;
|
|
|
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
|
|
use Illuminate\Support\Collection;
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
@@ -37,16 +36,12 @@ class StorageController extends Controller
|
|
|
$amount = (int)\request("amount");
|
|
|
//check info
|
|
|
if (!$asn || !$ide || !$barCode || !$amount)$this->error("信息不完整");
|
|
|
- $fromLocation = app("MaterialBoxService")->getBoxLocation($ide);
|
|
|
- if (!$fromLocation)$this->error("WAS无此库位信息");
|
|
|
- $box = MaterialBox::query()->where("code",$ide)->first();
|
|
|
+ $box = MaterialBox::query()->with("station")->where("code",$ide)->first();
|
|
|
if (!$box)$this->error("WAS无此料箱");
|
|
|
+ if (!$box->station)$this->error("WAS无此库位信息");
|
|
|
+ if (!app("StationService")->isCacheShelfLocation($box->station))$this->error("非缓存架库位");
|
|
|
+ $fromLocation = $box->station->code; //源库位
|
|
|
|
|
|
- //库存相关信息
|
|
|
- /** @var Station|\stdClass $station */
|
|
|
- $station = Station::query()->firstOrCreate(["code"=>$fromLocation],[
|
|
|
- 'name' => $fromLocation, 'code' => $fromLocation, 'station_type_id' => 5
|
|
|
- ]);
|
|
|
$item = StoreItem::query()->whereHas("store",function (Builder $query){
|
|
|
$query->where("asn_code",request("asn"));
|
|
|
})->whereHas("commodity",function (Builder $query)use($barCode){
|
|
|
@@ -54,6 +49,7 @@ class StorageController extends Controller
|
|
|
$query->where("code",$barCode);
|
|
|
});
|
|
|
})->first();
|
|
|
+ if (!$item)$this->error("WAS无此ASN单信息");
|
|
|
//get flux
|
|
|
$tasks = app("StorageService")->getFluxTask($asn,$barCode,$amount);
|
|
|
if (!$tasks)$this->error("该单无上架任务或不存在");
|
|
|
@@ -61,7 +57,7 @@ class StorageController extends Controller
|
|
|
DB::beginTransaction(); //总体事务 回滚WAS错误操作
|
|
|
try{
|
|
|
//库存记录
|
|
|
- if (!app("StorageService")->enterWarehouse($station->id, $box->id, $item->commodity_id ?? null, $amount, $box->material_box_model_id))$this->error("库存异常");
|
|
|
+ if (!app("StorageService")->enterWarehouse( $box->id, $item->commodity_id, $amount, $box->material_box_model_id))$this->error("库存异常");
|
|
|
|
|
|
DB::connection("oracle")->transaction(function ()use($tasks,$ide){ //单体嵌套事务 回滚FLUX失败任务
|
|
|
foreach ($tasks as $task)if (!app("StorageService")->fluxPA($task,$ide)){
|
|
|
@@ -75,11 +71,10 @@ class StorageController extends Controller
|
|
|
$this->error($e->getMessage());
|
|
|
}
|
|
|
//亮灯
|
|
|
- app("CacheShelfService")->_stationCacheLightOn($fromLocation,$ide);
|
|
|
+ app("CacheShelfService")->lightUp($fromLocation,'1','0',["detail01"=>$ide]);
|
|
|
|
|
|
- $maximum = app("CommodityMaterialBoxModelService")->getMaximum($box->material_box_model_id,$item->commodity_id ?? null);
|
|
|
- if ($maximum && $maximum<$amount)app("CommodityMaterialBoxModelService")->setMaximum($box->material_box_model_id,$item->commodity_id ?? null,$amount);
|
|
|
- $this->success(["model" => $box->material_box_model_id,"commodity" => $item->commodity_id ?? null, "maximum" => $maximum]);
|
|
|
+ $maximum = app("CommodityMaterialBoxModelService")->getMaximum($box->material_box_model_id,$item->commodity_id);
|
|
|
+ $this->success(["model" => $box->material_box_model_id,"commodity" => $item->commodity_id, "maximum" => $maximum]);
|
|
|
}
|
|
|
|
|
|
public function setMaximum()
|
|
|
@@ -89,7 +84,7 @@ class StorageController extends Controller
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 检查最大限值并返回
|
|
|
+ * 检查最大限值并返回 TODO
|
|
|
*
|
|
|
*/
|
|
|
public function checkMaximum()
|
|
|
@@ -98,12 +93,15 @@ class StorageController extends Controller
|
|
|
if (!$item)$this->error("无此单据记录");
|
|
|
$models = CommodityMaterialBoxModel::query()->where("commodity_id",$item->commodity_id)->get();
|
|
|
if ($models->count()==0)$this->error("商品首入,请使用缓存架空箱入库");
|
|
|
+ $map = [];
|
|
|
+ foreach ($models as $model)$map[$model->material_box_model_id] = $model;
|
|
|
+ $models = app("MaterialBoxModelService")->getModelSortedByOwner($item->store->owner_id);
|
|
|
foreach ($models as $model){
|
|
|
- $result = app("StorageService")->getHalfBoxLocation($model,$item,request("asn"));
|
|
|
- if ($result){
|
|
|
- $result->maximum = $model->maximum-$result->amount;
|
|
|
- $this->success($result);
|
|
|
- }
|
|
|
+ if (!isset($map[$model->id]))continue;
|
|
|
+ $result = app("StorageService")->getHalfBoxLocation($map[$model->id],$item,request("asn"));
|
|
|
+ if (!$result)continue;
|
|
|
+ $result->maximum = $model->maximum-$result->amount;
|
|
|
+ $this->success($result);
|
|
|
}
|
|
|
$this->success(["need"=>$models[0]->maximum,"material_box_model_id"=>$models[0]->material_box_model_id,"commodity_id"=>$item->commodity_id]);
|
|
|
}
|
|
|
@@ -132,15 +130,17 @@ sql;
|
|
|
$boxes = request("boxes");
|
|
|
//清理任务
|
|
|
$data = '';
|
|
|
- $occupy = Storage::query()->with("station:id,code")->whereIn("station_id",Station::query()->select("id")->whereIn("code",$boxes))->where("status",1)->get();
|
|
|
+ //剔除准备执行任务但没有真正开始执行的待定库位
|
|
|
+ $occupy = Station::query()->select("id")->whereIn("code",$boxes)->where("status",1)->get();
|
|
|
foreach ($occupy as $item){
|
|
|
- unset($boxes[array_search($item->station->code,$boxes)]);
|
|
|
- $data .= '“'.$item->station->code.'”,';
|
|
|
+ unset($boxes[array_search($item->code,$boxes)]);
|
|
|
+ $data .= '“'.$item->code.'”,';
|
|
|
}
|
|
|
if ($occupy->count()>0){
|
|
|
$data .= "存在任务待处理,无法调取 ";
|
|
|
$boxes = array_values($boxes);
|
|
|
}
|
|
|
+ //剔除存在任务的库位
|
|
|
$tasks = StationTaskMaterialBox::query()->with("station:id,code")
|
|
|
->whereIn("station_id",Station::query()->select("id")->whereIn("code",$boxes))
|
|
|
->whereNotIn("status",["完成","取消"])->get();
|
|
|
@@ -174,72 +174,78 @@ sql;
|
|
|
if ($occupyTask)$this->error("库位存在任务未处理完成");
|
|
|
$amount = app("StorageService")->checkPutAmount(request("asn"),request("barCode"));
|
|
|
if ($amount<request("amount"))$this->error("待上架数量不足,最大可上数量为{$amount}");
|
|
|
+
|
|
|
+ //发起取箱任务
|
|
|
+ $exe = function ($boxId)use($station){
|
|
|
+ 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,'2','1');
|
|
|
+ };
|
|
|
+ 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)){
|
|
|
+ if ($boxId){
|
|
|
$blacklist = [$boxId];
|
|
|
$boxId = null;
|
|
|
//料箱存在且不可用
|
|
|
- $models = CommodityMaterialBoxModel::query()->where("commodity_id",request("commodity_id"))->get();
|
|
|
- $item = app("StoreItemService")->getMaxAvailableDetail(request("asn"),request("barCode"));
|
|
|
- if (!$item)$this->error("无此单据记录");
|
|
|
+ /** @var \Illuminate\Database\Eloquent\Collection $models */
|
|
|
+
|
|
|
foreach ($models as $model){
|
|
|
+ if (!$model->commodity)continue;
|
|
|
//料箱不可用寻找新料箱
|
|
|
- $result = app("StorageService")->getHalfBoxLocation($model,$item,request("asn"),$blacklist);
|
|
|
+ $result = app("StorageService")->getHalfBoxLocation($model->commodity,$item,request("asn"),$blacklist);
|
|
|
while ($result){
|
|
|
//料箱可用并且数量符合本次半箱数量 跳出
|
|
|
if (app("MaterialBoxService")->checkUsableBox($result->material_box_id)
|
|
|
- && $model->maximum-$result->amount>=request("amount")){$boxId = $result->material_box_id;break;}
|
|
|
+ && $model->maximum-$result->amount>=request("amount"))$this->success($exe($result->material_box_id));
|
|
|
else $blacklist[] = $result->material_box_id;
|
|
|
//否则黑名单此料箱继续查找 直至料箱为空
|
|
|
- $result = app("StorageService")->getHalfBoxLocation($model,$item,request("asn"),$blacklist);
|
|
|
+ $result = app("StorageService")->getHalfBoxLocation($model->commodity,$item,request("asn"),$blacklist);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//料箱不存在且该商品有过入库记录 拿取空箱
|
|
|
- if (!$boxId){
|
|
|
- if (!$modelId){
|
|
|
- $box = null;
|
|
|
- $models = CommodityMaterialBoxModel::query()->with("materialBoxModel")->where("commodity_id",request("commodity_id"))->get();
|
|
|
- foreach ($models as $model){
|
|
|
- if (!$model->materialBoxModel)continue;
|
|
|
- $box = app("MaterialBoxService")->getAnEmptyBox($model->materialBoxModel);
|
|
|
- if($box)break;
|
|
|
- }
|
|
|
- }else $box = app("MaterialBoxService")->getAnEmptyBox(MaterialBoxModel::query()->find($modelId));
|
|
|
- if (!$box)$this->error("无可用料箱");
|
|
|
- $boxId = $box->id;
|
|
|
- }
|
|
|
- //发起取箱任务
|
|
|
- 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")->stationLightUp($station->code,null,'2');
|
|
|
- $this->success();
|
|
|
+ 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($exe($box->id));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -257,7 +263,8 @@ sql;
|
|
|
->where("type","入库")->where("mark",1)->where("status",0)->first();
|
|
|
if (!$task)$this->error("无任务存在");
|
|
|
$task->update(["amount" => DB::raw("amount - {$amount}")]);
|
|
|
- $storage = Storage::query()->where("material_box_id",$task->material_box_id)->first();
|
|
|
+ $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]);
|
|
|
@@ -286,9 +293,9 @@ sql;
|
|
|
"name" => $inv->customerid,
|
|
|
]);
|
|
|
$commodity = Commodity::query()->where("owner_id",$owner->id)->where("sku",$inv->sku)->first();
|
|
|
- $s = \App\Storage::query()->where("material_box_id",$materialBox->id)
|
|
|
+ $s = MaterialBoxCommodity::query()->where("material_box_id",$materialBox->id)
|
|
|
->where("commodity_id",$commodity->id)->first();
|
|
|
- if (!$s)\App\Storage::query()->create([
|
|
|
+ if (!$s)MaterialBoxCommodity::query()->create([
|
|
|
"material_box_id" => $materialBox->id,
|
|
|
"commodity_id" => $commodity->id,
|
|
|
"amount" => $inv->qty,
|
|
|
@@ -342,60 +349,10 @@ sql;
|
|
|
if (!$ks)$this->error("海柔料箱状态异常");
|
|
|
DB::beginTransaction();
|
|
|
try {
|
|
|
- $storages = Storage::query()->whereHas("station",function ($query)use($location){
|
|
|
- /** @var Builder $query */
|
|
|
- $query->where("code",$location);
|
|
|
- })->orWhereHas("materialBox",function ($query)use($box){
|
|
|
- /** @var Builder $query */
|
|
|
- $query->where("code",$box);
|
|
|
- })->lockForUpdate()->get();
|
|
|
- $station = Station::query()->where("code",$location)->first();
|
|
|
+ $station = Station::query()->where("code",$location)->where("status",0)->first();
|
|
|
$box = MaterialBox::query()->where("code",$box)->first();
|
|
|
if (!$station || !$box)$this->error("库位或料箱未在WAS记录");
|
|
|
- switch ($storages->count()){
|
|
|
- case 0:
|
|
|
- Storage::query()->create([
|
|
|
- "station_id" => $station->id,
|
|
|
- "material_box_id" => $box->id,
|
|
|
- ]);
|
|
|
- break;
|
|
|
- case 1:
|
|
|
- $storage = $storages->first();
|
|
|
- if ($storage->status==1)$this->error("库存占用中");
|
|
|
- //已经映射库位 跳出
|
|
|
- if ($storage->station_id==$station->id && $storage->material_box_id==$box->id)break;
|
|
|
- //库存中 仅有库位信息
|
|
|
- if ($storage->station_id==$station->id){
|
|
|
- //料箱信息存在且有库存-》新建库位映射,将此料箱库位清空
|
|
|
- if ($storage->material_box_id && $storage->amount){
|
|
|
- Storage::query()->create([
|
|
|
- "station_id" => $station->id,
|
|
|
- "material_box_id" => $box->id,
|
|
|
- ]);
|
|
|
- $storage->update(["station_id"=>null]);
|
|
|
- //料箱信息不存在或没有库存信息 映射到当前库位
|
|
|
- }else $storage->update(["material_box_id"=>$box->id,"commodity_id"=>null,"amount"=>0]);
|
|
|
- }else $storage->update(["station_id"=>$station->id]);
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- //ls:库位库存 bs:料箱库存
|
|
|
- $ls = null;
|
|
|
- $bs = null;
|
|
|
- foreach ($storages as $storage){
|
|
|
- if ($storage->station_id==$station->id)$ls = $storage;
|
|
|
- else $bs = $storage;
|
|
|
- }
|
|
|
- //其一不存在说明库存中重复记录 需要人工筛查
|
|
|
- if (!$ls || !$bs)$this->error("库存中重复库位记录或料箱记录");
|
|
|
- //库位库存存在有效库存 库位置空 否则删除库存记录
|
|
|
- if ($ls->material_box_id && $ls->amount)$ls->update(["station_id"=>null]);
|
|
|
- else $ls->delete();
|
|
|
- //料箱映射库位改至当前库位
|
|
|
- $bs->update(["station_id"=>$station->id]);
|
|
|
- break;
|
|
|
- default:
|
|
|
- $this->error("库存信息异常,料箱或库位未完全释放");
|
|
|
- }
|
|
|
+ $station->update(["material_box_id"=>$box->id]);
|
|
|
DB::commit();
|
|
|
$this->success();
|
|
|
}catch (\Exception $e){
|