|
|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
+use App\CommodityMaterialBoxModel;
|
|
|
use App\Components\AsyncResponse;
|
|
|
use App\MaterialBox;
|
|
|
use App\Station;
|
|
|
@@ -9,8 +10,10 @@ use App\StationTask;
|
|
|
use App\StationTaskMaterialBox;
|
|
|
use App\Storage;
|
|
|
use App\StoreItem;
|
|
|
+use App\TaskTransaction;
|
|
|
use App\ValueStore;
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
+use Illuminate\Support\Collection;
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
@@ -71,12 +74,49 @@ sql;
|
|
|
});
|
|
|
})->first();
|
|
|
//库存记录
|
|
|
- app("StorageService")->enterWarehouse($station->id, $box->id, $item->commodity_id ?? null, $amount);
|
|
|
+ app("StorageService")->enterWarehouse($station->id, $box->id, $item->commodity_id ?? null, $amount, $box->material_box_model_id);
|
|
|
//建立入库任务
|
|
|
if (!app("ForeignHaiRoboticsService")->putWareHousing($fromLocation,$box->id))$this->error("错误库位或库位已被下达任务");
|
|
|
+
|
|
|
+ $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]);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function setMaximum()
|
|
|
+ {
|
|
|
+ app("CommodityMaterialBoxModelService")->setMaximum(request("model"),request("commodity"),request("maximum"));
|
|
|
$this->success();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 检查最大限值并返回
|
|
|
+ *
|
|
|
+ */
|
|
|
+ public function checkMaximum()
|
|
|
+ {
|
|
|
+ $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("WAS无此单据记录");
|
|
|
+ $models = CommodityMaterialBoxModel::query()->where("commodity_id",$item->commodity_id)->get();
|
|
|
+ if ($models->count()==0)$this->error("商品首入,请使用缓存架空箱入库");
|
|
|
+ foreach ($models as $model){
|
|
|
+ $box = Storage::query()->select(DB::raw("MAX({$model->maximum}-amount) need"),"material_box_id")
|
|
|
+ ->whereHas("materialBox",function (Builder $query)use($model){
|
|
|
+ $query->where("material_box_model_id",$model->material_box_model_id);
|
|
|
+ })->where("commodity_id",$model->commodity_id)->where("amount","<",$model->maximum)
|
|
|
+ ->where("status",0)->first();
|
|
|
+ $box->commodity_id = $item->commodity_id;
|
|
|
+ if ($box)$this->success($box);
|
|
|
+ }
|
|
|
+ $this->success(["need"=>$models[0]->maximum,"material_box_model_id"=>$models[0]->material_box_model_id,"commodity_id"=>$item->commodity_id]);
|
|
|
+ }
|
|
|
+
|
|
|
public function fluxPA($asn,$ide,$amount)
|
|
|
{
|
|
|
if (!$asn->taskid)$this->error("ASN单无此入库信息,禁止上架");
|
|
|
@@ -230,4 +270,75 @@ sql;
|
|
|
app("ForeignHaiRoboticsService")->paddingCacheShelf($station->get());
|
|
|
$this->success(["data"=>$data,"boxes"=>$boxes]);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 取得料箱
|
|
|
+ */
|
|
|
+ public function acquireBox()
|
|
|
+ {
|
|
|
+ $boxId = request("material_box_id");
|
|
|
+ $modelId = request("material_box_model_id");
|
|
|
+ //获取目标库位
|
|
|
+ $station = app("StationService")->getMirrorMappingLocation(request("station"));
|
|
|
+ if (!$station)$this->error("未知库位");
|
|
|
+ //获取料箱
|
|
|
+ if ($boxId && !app("MaterialBoxService")->checkUsableBox($boxId)){
|
|
|
+ $boxId = null;
|
|
|
+ //料箱存在且不可用
|
|
|
+ $models = CommodityMaterialBoxModel::query()->where("commodity_id",request("commodity_id"))->get();
|
|
|
+ foreach ($models as $model){
|
|
|
+ Storage::query()->select("material_box_id")
|
|
|
+ ->whereHas("materialBox",function (Builder $query)use($model){
|
|
|
+ $query->where("material_box_model_id",$model->material_box_model_id);
|
|
|
+ })->where("commodity_id",$model->commodity_id)->where("amount","<",$model->maximum)
|
|
|
+ ->where("status",0)->where(DB::raw("{$model->maximum}-amount"),">=",request("amount"))->get()->each(function ($box)use(&$boxId){
|
|
|
+ if (app("MaterialBoxService")->checkUsableBox($box->id)){
|
|
|
+ $boxId = $box->id;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ });
|
|
|
+ if ($boxId)break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!$boxId){
|
|
|
+ if (!$modelId){
|
|
|
+ $box = null;
|
|
|
+ $models = CommodityMaterialBoxModel::query()->where("commodity_id",request("commodity_id"))->get();
|
|
|
+ foreach ($models as $model){
|
|
|
+ $box = app("MaterialBoxService")->getAnEmptyBox([],$model->material_box_model_id);
|
|
|
+ if($box)break;
|
|
|
+ }
|
|
|
+ }else $box = app("MaterialBoxService")->getAnEmptyBox([],$modelId);
|
|
|
+ if (!$box)$this->error("无可用料箱");
|
|
|
+ $boxId = $box->id;
|
|
|
+ }
|
|
|
+ //发起取箱任务
|
|
|
+ $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([
|
|
|
+ "fm_station_id" => $station->id,
|
|
|
+ "material_box_id" => $boxId,
|
|
|
+ "commodity_id" => request("commodity_id"),
|
|
|
+ "amount" => request("amount"),
|
|
|
+ "type" => "入库",
|
|
|
+ "user_id" => Auth::id(),
|
|
|
+ "mark" => 1
|
|
|
+ ]);
|
|
|
+ //亮灯
|
|
|
+ app("CacheShelfService")->stationLightUp($station->code,null,'2');
|
|
|
+ $this->success();
|
|
|
+ }
|
|
|
}
|