|
@@ -9,6 +9,7 @@ use App\MaterialBox;
|
|
|
use App\MaterialBoxCommodity;
|
|
use App\MaterialBoxCommodity;
|
|
|
use App\MaterialBoxModel;
|
|
use App\MaterialBoxModel;
|
|
|
use App\Owner;
|
|
use App\Owner;
|
|
|
|
|
+use App\Services\LogService;
|
|
|
use App\Station;
|
|
use App\Station;
|
|
|
use App\StationTask;
|
|
use App\StationTask;
|
|
|
use App\StationTaskMaterialBox;
|
|
use App\StationTaskMaterialBox;
|
|
@@ -29,6 +30,7 @@ class StorageController extends Controller
|
|
|
|
|
|
|
|
public function putShelf()
|
|
public function putShelf()
|
|
|
{
|
|
{
|
|
|
|
|
+ $this->error("停用缓存架上架,联系管理员开启");
|
|
|
$this->gate("入库管理-入库-缓存架入库");
|
|
$this->gate("入库管理-入库-缓存架入库");
|
|
|
$asn = \request("asn");
|
|
$asn = \request("asn");
|
|
|
$ide = \request("ide");
|
|
$ide = \request("ide");
|
|
@@ -92,18 +94,10 @@ class StorageController extends Controller
|
|
|
$item = app("StoreItemService")->getMaxAvailableDetail(request("asn"),request("barCode"));
|
|
$item = app("StoreItemService")->getMaxAvailableDetail(request("asn"),request("barCode"));
|
|
|
if (!$item)$this->error("无此单据记录");
|
|
if (!$item)$this->error("无此单据记录");
|
|
|
$models = CommodityMaterialBoxModel::query()->where("commodity_id",$item->commodity_id)->get();
|
|
$models = CommodityMaterialBoxModel::query()->where("commodity_id",$item->commodity_id)->get();
|
|
|
- if ($models->count()==0)$this->error("商品首入,请使用缓存架空箱入库");
|
|
|
|
|
|
|
+ if ($models->count()==0)$this->success(["material_box_model_id"=>null]);
|
|
|
$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($item->store->owner_id);
|
|
|
|
|
- foreach ($models as $model){
|
|
|
|
|
- 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]);
|
|
|
|
|
|
|
+ $this->getMaterBoxModel($item,$map);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -167,11 +161,12 @@ sql;
|
|
|
$this->gate("入库管理-入库-半箱补货入库");
|
|
$this->gate("入库管理-入库-半箱补货入库");
|
|
|
$boxId = request("material_box_id");
|
|
$boxId = request("material_box_id");
|
|
|
$modelId = request("material_box_model_id");
|
|
$modelId = request("material_box_model_id");
|
|
|
|
|
+ if (!$modelId)$this->error("商品未设定库存上限");
|
|
|
//获取目标库位
|
|
//获取目标库位
|
|
|
$station = app("StationService")->getMirrorMappingLocation(request("station"));
|
|
$station = app("StationService")->getMirrorMappingLocation(request("station"));
|
|
|
if (!$station)$this->error("未知库位");
|
|
if (!$station)$this->error("未知库位");
|
|
|
- $occupyTask = StationTaskMaterialBox::query()->where("station_id",$station->id)->whereNotIn("status",["完成","取消"])->first();
|
|
|
|
|
- if ($occupyTask)$this->error("库位存在任务未处理完成");
|
|
|
|
|
|
|
+ $isAvailable = app("StationService")->isAvailable($station);
|
|
|
|
|
+ if (!$isAvailable)$this->error("库存被占用或存在任务未处理");
|
|
|
$amount = app("StorageService")->checkPutAmount(request("asn"),request("barCode"));
|
|
$amount = app("StorageService")->checkPutAmount(request("asn"),request("barCode"));
|
|
|
if ($amount<request("amount"))$this->error("待上架数量不足,最大可上数量为{$amount}");
|
|
if ($amount<request("amount"))$this->error("待上架数量不足,最大可上数量为{$amount}");
|
|
|
|
|
|
|
@@ -206,6 +201,7 @@ sql;
|
|
|
DB::commit();
|
|
DB::commit();
|
|
|
//亮灯
|
|
//亮灯
|
|
|
app("CacheShelfService")->lightUp($station->code,'2','1');
|
|
app("CacheShelfService")->lightUp($station->code,'2','1');
|
|
|
|
|
+ app("StationService")->locationOccupy($station->code);//占用库位
|
|
|
};
|
|
};
|
|
|
if ($boxId && app("MaterialBoxService")->checkUsableBox($boxId))$this->success($exe($boxId));
|
|
if ($boxId && app("MaterialBoxService")->checkUsableBox($boxId))$this->success($exe($boxId));
|
|
|
$item = app("StoreItemService")->getMaxAvailableDetail(request("asn"),request("barCode"));
|
|
$item = app("StoreItemService")->getMaxAvailableDetail(request("asn"),request("barCode"));
|
|
@@ -379,4 +375,92 @@ sql;
|
|
|
$this->success(MaterialBox::query()->where("code",request("ide"))
|
|
$this->success(MaterialBox::query()->where("code",request("ide"))
|
|
|
->update(["material_box_model_id"=>request("material_box_model_id")]));
|
|
->update(["material_box_model_id"=>request("material_box_model_id")]));
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ public function commodityBindModel()
|
|
|
|
|
+ {
|
|
|
|
|
+ $models = MaterialBoxModel::query()->get();
|
|
|
|
|
+ return view("store.inStorage.commodityBindModel",compact("models"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function getModels()
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->success(MaterialBoxModel::query()->select("id","code","description","maximum_kind")->get());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 设定料箱最大
|
|
|
|
|
+ */
|
|
|
|
|
+ public function settingModelMaximum()
|
|
|
|
|
+ {
|
|
|
|
|
+ $insert = function ($commodityId){
|
|
|
|
|
+ $in = [];
|
|
|
|
|
+ $map = [];
|
|
|
|
|
+ $ids = [];
|
|
|
|
|
+ foreach (request("models") as $model){
|
|
|
|
|
+ $insert[] = [
|
|
|
|
|
+ "commodity_id" => $commodityId,
|
|
|
|
|
+ "material_box_model_id" => $model["id"],
|
|
|
|
|
+ "maximum" => $model["maximum"]
|
|
|
|
|
+ ];
|
|
|
|
|
+ $map[$model["id"]] = $model;
|
|
|
|
|
+ $ids[] = $model["id"];
|
|
|
|
|
+ }
|
|
|
|
|
+ return array($in,$map,$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]);
|
|
|
|
|
+ }
|
|
|
|
|
+ $in = array_values($in);
|
|
|
|
|
+ }
|
|
|
|
|
+ if ($in){
|
|
|
|
|
+ LogService::log(__CLASS__,__METHOD__,json_encode($in));
|
|
|
|
|
+ CommodityMaterialBoxModel::query()->insert($in);
|
|
|
|
|
+ }
|
|
|
|
|
+ $this->success();
|
|
|
|
|
+ }
|
|
|
|
|
+ $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);
|
|
|
|
|
+ }
|
|
|
|
|
+ $this->success(["need"=>$models[0]->maximum,"material_box_model_id"=>$models[0]->material_box_model_id,"commodity_id"=>$item->commodity_id]);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 根据条码检索商品
|
|
|
|
|
+ */
|
|
|
|
|
+ public function searchBarCode()
|
|
|
|
|
+ {
|
|
|
|
|
+ $commodities = Commodity::query()->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);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|