|
|
@@ -15,6 +15,7 @@ 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;
|
|
|
@@ -304,4 +305,90 @@ sql;
|
|
|
{
|
|
|
return 'name';
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 库外箱绑定至库位
|
|
|
+ */
|
|
|
+ public function bindBox()
|
|
|
+ {
|
|
|
+ $location = request("location");
|
|
|
+ $box = request("ide");
|
|
|
+ if (!$location || !$box)$this->error("参数传递错误");
|
|
|
+ $task = StationTaskMaterialBox::query()->select("id")->where(function ($query)use($location,$box){
|
|
|
+ /** @var Builder $query */
|
|
|
+ $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);
|
|
|
+ });
|
|
|
+ })->whereNotIn("status",["完成","取消"])->first();
|
|
|
+ if ($task)$this->error("库位或料箱存在任务待执行,无法放置料箱");
|
|
|
+ $ks = DB::connection("mysql_haiRobotics")->table("ks_bin")->select(DB::raw("1"))
|
|
|
+ ->where("ks_bin_code",$box)->where("status",4)->first();
|
|
|
+ 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()->first();
|
|
|
+ $station = Station::query()->where("code",$location)->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("库存信息异常,料箱或库位未完全释放");
|
|
|
+ }
|
|
|
+ DB::commit();
|
|
|
+ $this->success();
|
|
|
+ }catch (\Exception $e){
|
|
|
+ DB::rollBack();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|