|
|
@@ -13,6 +13,7 @@ use App\Services\LogService;
|
|
|
use App\Station;
|
|
|
use App\StationTask;
|
|
|
use App\StationTaskMaterialBox;
|
|
|
+use App\Store;
|
|
|
use App\StoreItem;
|
|
|
use App\TaskTransaction;
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
@@ -92,13 +93,42 @@ class StorageController extends Controller
|
|
|
*/
|
|
|
public function checkMaximum()
|
|
|
{
|
|
|
- $item = app("StoreItemService")->getMaxAvailableDetail(request("asn"),request("barCode"));
|
|
|
- if (!$item)$this->error("无此单据记录");
|
|
|
- $models = CommodityMaterialBoxModel::query()->where("commodity_id",$item->commodity_id)->get();
|
|
|
- if ($models->count()==0)$this->success(["material_box_model_id"=>null]);
|
|
|
+ $lotNum = request("lotNum");
|
|
|
+ $sql = <<<SQL
|
|
|
+SELECT * FROM INV_LOT_ATT WHERE LOTNUM = '{$lotNum}'
|
|
|
+SQL;
|
|
|
+ $lot = DB::connection("oracle")->selectOne(DB::raw($sql));
|
|
|
+ if (!$lot)$this->error("批次丢失");
|
|
|
+ $commodity = Commodity::query()->whereHas("owner",function ($query)use($lot){
|
|
|
+ $query->where("code",$lot->customerid);
|
|
|
+ })->where("sku",$lot->sku)->first();
|
|
|
+ if (!$commodity)$this->error("WAS无此商品信息");
|
|
|
+ $models = CommodityMaterialBoxModel::query()->where("commodity_id",$commodity->id)->get();
|
|
|
+ if ($models->count()==0)$this->success(["material_box_model_id"=>null,"commodity_id"=>$commodity->id]);
|
|
|
$map = [];
|
|
|
foreach ($models as $model)$map[$model->material_box_model_id] = $model;
|
|
|
- $this->getMaterBoxModel($item,$map);
|
|
|
+ $models = app("MaterialBoxModelService")->getModelSortedByOwner($commodity->owner_id);
|
|
|
+ $m = null;
|
|
|
+ foreach ($models as $model){
|
|
|
+ if (!isset($map[$model->id]))continue;
|
|
|
+ $model->maximum = $map[$model->id]->maximum;
|
|
|
+ $boxCodes = app("MaterialBoxService")->getModelAvailableBox($model->id,true);
|
|
|
+ if (!$boxCodes)continue;
|
|
|
+ if (!$m)$m = $model;
|
|
|
+ $sql = <<<SQL
|
|
|
+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
|
|
|
+SQL;
|
|
|
+ $res = DB::connection("oracle")->selectOne(DB::raw($sql));
|
|
|
+ if ($res){
|
|
|
+ $m = $model;
|
|
|
+ $m->maximum = $res->qty;
|
|
|
+ $m->location = $res->locationid;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!$m)$this->error("没有可用料箱");
|
|
|
+ $this->success(["need"=>$m->maximum,"material_box_model_id"=>$m->id,"commodity_id"=>$commodity->id,"location"=>$m->locationid]);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -168,49 +198,59 @@ sql;
|
|
|
if (!$station)$this->error("未知库位");
|
|
|
$isAvailable = app("StationService")->isAvailable($station);
|
|
|
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}");
|
|
|
|
|
|
//发起取箱任务
|
|
|
- $exe = function ($boxId)use($station){
|
|
|
+ $exe = function ($boxId)use($station,$amount){
|
|
|
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){
|
|
|
@@ -218,18 +258,18 @@ sql;
|
|
|
$boxId = null;
|
|
|
//料箱存在且不可用
|
|
|
/** @var \Illuminate\Database\Eloquent\Collection $models */
|
|
|
-
|
|
|
foreach ($models as $model){
|
|
|
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){
|
|
|
+ $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);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -243,7 +283,7 @@ sql;
|
|
|
}
|
|
|
}else $box = app("MaterialBoxService")->getAnEmptyBox(MaterialBoxModel::query()->find($modelId));
|
|
|
if (!$box)$this->error("无可用料箱");
|
|
|
- $this->success($exe($box->id));
|
|
|
+ $this->success(["status"=>$exe($box->id),"amount"=>$amount-request("amount")]);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -396,61 +436,37 @@ sql;
|
|
|
{
|
|
|
$insert = function ($commodityId){
|
|
|
$in = [];
|
|
|
- $map = [];
|
|
|
$ids = [];
|
|
|
foreach (request("models") as $model){
|
|
|
- $insert[] = [
|
|
|
+ $in[] = [
|
|
|
"commodity_id" => $commodityId,
|
|
|
"material_box_model_id" => $model["id"],
|
|
|
"maximum" => $model["maximum"]
|
|
|
];
|
|
|
- $map[$model["id"]] = $model;
|
|
|
$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()->whereIn("id",$ids)->lockForUpdate()->get() as $model){
|
|
|
- $index = $map[$model->id];
|
|
|
- if ($model->maximum != $in[$index]["maximum"])$model->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($item,$map)
|
|
|
- {
|
|
|
- $models = app("MaterialBoxModelService")->getModelSortedByOwner($item->store->owner_id);
|
|
|
- foreach ($models as $model){
|
|
|
- if (!isset($map[$model->id]))continue;
|
|
|
- $result = app("StorageService")->getHalfBoxLocation($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"=>$item->commodity_id]);
|
|
|
+ $this->success();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -458,11 +474,95 @@ sql;
|
|
|
*/
|
|
|
public function searchBarCode()
|
|
|
{
|
|
|
- $commodities = Commodity::query()->whereHas("barcodes",function (Builder $query){
|
|
|
+ $commodities = Commodity::query()->with("owner")->whereHas("barcodes",function (Builder $query){
|
|
|
$query->where("code",request("barCode"));
|
|
|
})->get();
|
|
|
if (!$commodities->count())$this->error("库内无此商品信息");
|
|
|
if ($commodities->count()>1)$commodities->load("owner");
|
|
|
$this->success($commodities);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据商品ID检索已存在的上限设定
|
|
|
+ */
|
|
|
+ public function searchModel()
|
|
|
+ {
|
|
|
+ $mapping = [];
|
|
|
+ foreach (CommodityMaterialBoxModel::query()->where("commodity_id",request("id"))->get() as $model){
|
|
|
+ $mapping[$model->material_box_model_id] = $model->maximum;
|
|
|
+ }
|
|
|
+ $this->success($mapping);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据ASN号检索未设定商品型号上限的信息
|
|
|
+ */
|
|
|
+ public function searchAsn()
|
|
|
+ {
|
|
|
+ $sql = <<<SQL
|
|
|
+SELECT CUSTOMERID,SKU FROM TSK_TASKLISTS WHERE DOCNO = ? AND TASKPROCESS = '00' AND TASKTYPE = 'PA' GROUP BY CUSTOMERID,SKU
|
|
|
+SQL;
|
|
|
+ $store = Store::query()->select("owner_id")->where("asn_code",request("asn"))->first();
|
|
|
+ if (!$store || !$store->owner_id)$this->error("WAS内无此ASN单信息");
|
|
|
+
|
|
|
+ $tasks = DB::connection("oracle")->select(DB::raw($sql),[request("asn")]);
|
|
|
+ $codes = array_column($tasks,"sku");
|
|
|
+ $model = MaterialBoxModel::query()->where("maximum_kind",1)->first();
|
|
|
+ if (!$model)$this->error("单品型号缺失");
|
|
|
+ $commodities = Commodity::query()->with("model")->where("owner_id",$store->owner_id)
|
|
|
+ ->whereIn("sku",$codes)->get()->toArray();
|
|
|
+ if (count($codes)!=count($commodities))$this->error("WAS商品信息不全");
|
|
|
+ foreach ($commodities as $index=>$commodity){
|
|
|
+ if ($commodity->model)unset($commodities[$index]);
|
|
|
+ }
|
|
|
+ $this->success(["commodities"=>array_values($commodities),"model"=>$model]);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置商品上限
|
|
|
+ */
|
|
|
+ public function settingCommodityMaximum()
|
|
|
+ {
|
|
|
+ $modelId = request("modelId");
|
|
|
+ $insert = [];
|
|
|
+ $date = date("Y-m-d H:i:s");
|
|
|
+ foreach (request("commodities") as $commodity){
|
|
|
+ $insert[] = [
|
|
|
+ "commodity_id" => $commodity["id"],
|
|
|
+ "material_box_model_id" => $modelId,
|
|
|
+ "maximum" => $commodity->maximum,
|
|
|
+ "created_at" => $date,
|
|
|
+ "updated_at" => $date,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ $this->success(CommodityMaterialBoxModel::query()->insert($insert));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检查任务获取多批次
|
|
|
+ */
|
|
|
+ public function checkTask()
|
|
|
+ {
|
|
|
+ $track = request("track");
|
|
|
+ $barCode = request("barCode");
|
|
|
+ $sql = <<<SQL
|
|
|
+SELECT TSK_TASKLISTS.FMLOTNUM FROM TSK_TASKLISTS LEFT JOIN BAS_SKU ON TSK_TASKLISTS.CUSTOMERID = BAS_SKU.CUSTOMERID
|
|
|
+AND TSK_TASKLISTS.SKU = BAS_SKU.SKU
|
|
|
+WHERE FMID = ? AND (ALTERNATE_SKU1 = ? OR ALTERNATE_SKU2 = ? OR ALTERNATE_SKU3 = ?)
|
|
|
+AND TASKPROCESS = '00' AND TASKTYPE = 'PA' GROUP BY FMID,FMLOTNUM
|
|
|
+SQL;
|
|
|
+ $tasks = DB::connection("oracle")->select(DB::raw($sql),[$track,$barCode,$barCode,$barCode]);
|
|
|
+ $result = ["count"=>count($tasks)];
|
|
|
+ if (count($tasks)>1){
|
|
|
+ $lotNums = "";
|
|
|
+ foreach ($tasks as $task)$lotNums .= "'".$task->fmlotnum."',";
|
|
|
+ $lotNums = rtrim($lotNums,",");
|
|
|
+ $sql = <<<SQL
|
|
|
+SELECT * FROM INV_LOT_ATT WHERE LOTNUM IN ({$lotNums});
|
|
|
+SQL;
|
|
|
+ $result["lots"] = DB::connection("oracle")->select(DB::raw($sql));
|
|
|
+ }
|
|
|
+ if (count($tasks)==1)$result["lots"] = $tasks[0]->fmlotnum;
|
|
|
+ $this->success($result);
|
|
|
+ }
|
|
|
}
|