ソースを参照

入库逻辑变更,废弃Storage表 删除无用方法 缩减Service

Zhouzhendong 4 年 前
コミット
c68d8afa05

+ 87 - 130
app/Http/Controllers/StorageController.php

@@ -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){

+ 2 - 6
app/Http/Controllers/StoreController.php

@@ -7,7 +7,6 @@ use App\Owner;
 use App\Services\common\BatchUpdateService;
 use App\Services\StoreService;
 use App\Station;
-use App\Storage;
 use App\Store;
 use App\StoreItem;
 use App\Warehouse;
@@ -440,11 +439,8 @@ class StoreController extends Controller
      */
     public function cacheRackStorage()
     {
-        $stations = Station::query()->select("id")->where("parent_id",6);
-        $storages = Storage::query()->with("station:id,code")->whereIn("station_id",$stations)->where(function (Builder $query){
-            $query->whereNotNull("material_box_id")->orWhere("status",1);
-        })->get();
-        return \view("store.inStorage.cacheRackStorage",compact("storages"));
+        $stations = Station::query()->select("id")->where("parent_id",6)->get();
+        return \view("store.inStorage.cacheRackStorage",compact("stations"));
     }
 
     /**

+ 2 - 25
app/Http/Controllers/TestController.php

@@ -149,14 +149,8 @@ class TestController extends Controller
     }
     public function test()
     {
-        dd(DB::connection("mysql_haiRobotics")->table("ks_bin")->where("ks_bin_code","IDE0000700")
-            ->update([
-                "ks_bin_space_code" => null,"ks_bin_space_id"=>null,"orig_ks_bin_space_code"=>null,"orig_ks_bin_space_id"=>null,
-                "status"=>4,
-            ]));
-        $task = DB::connection("oracle")->selectOne(DB::raw("select * from TSK_TASKLISTS where taskid = 'TS32563988' and TASKID_SEQUENCE = 2"));
-        $ide = "IDE0000696";
-        dd(app("StorageService")->fluxPA($task,$ide));
+        $a = MaterialBoxModel::query()->withCount("commodities")->get();
+        dd($a);
     }
     public function orderCreateBill()
     {
@@ -165,23 +159,6 @@ class TestController extends Controller
         $ser->createInstantBill($order);
         dd("order create bill success");
     }
-    function mp(){
-        $stationTaskCommodities=StationTaskCommodity::query()->where('id',19942)->get();
-        StationTaskCommodity::query()
-            ->whereIn('id',data_get($stationTaskCommodities,'*.id')??[])
-            ->update(['status'=>'完成']);
-        $stationTaskMaterialBoxes=StationTaskMaterialBox::query()
-            ->whereIn('id', data_get($stationTaskCommodities, '*.station_task_material_box_id') ?? [])
-            ->get('material_box_id');
-        $storages= \App\Storage::query()->whereIn('commodity_id',data_get($stationTaskCommodities,'*.commodity_id')??[])
-            ->whereIn('material_box_id',data_get($stationTaskMaterialBoxes,'*.material_box_id')??[])
-            ->get();
-        foreach($storages as $storage){
-            $amountReducing=$stationTaskCommodities->where('material_box_id',$storage['material_box_id'])->first()['amount']??0;
-            $storage['amount']-=$amountReducing;
-            $storage->update();
-        }
-    }
 
     public function supplementMarchOwnerReport()
     {

+ 5 - 0
app/MaterialBox.php

@@ -5,6 +5,7 @@ namespace App;
 use Illuminate\Database\Eloquent\Model;
 
 use App\Traits\ModelLogChanging;
+use Illuminate\Database\Eloquent\Relations\HasOne;
 
 class MaterialBox extends Model
 {
@@ -33,6 +34,10 @@ class MaterialBox extends Model
         parent::__construct($attributes);
     }
 
+    public function station():HasOne
+    {
+        return $this->hasOne(Station::class);
+    }
     public function getStatusAttribute($value)
     {
         if(!$value)return '';

+ 22 - 0
app/MaterialBoxCommodity.php

@@ -0,0 +1,22 @@
+<?php
+
+namespace App;
+
+use Illuminate\Database\Eloquent\Model;
+
+use App\Traits\ModelLogChanging;
+use Illuminate\Database\Eloquent\Relations\BelongsTo;
+
+class MaterialBoxCommodity extends Model
+{
+    use ModelLogChanging;
+
+    protected $fillable=[
+        "material_box_id","commodity_id","amount"
+    ];
+
+    public function materialBox():BelongsTo
+    {
+        return $this->belongsTo(MaterialBox::class);
+    }
+}

+ 6 - 0
app/MaterialBoxModel.php

@@ -5,6 +5,7 @@ namespace App;
 use Illuminate\Database\Eloquent\Model;
 
 use App\Traits\ModelLogChanging;
+use Illuminate\Database\Eloquent\Relations\HasOne;
 
 class MaterialBoxModel extends Model
 {
@@ -13,4 +14,9 @@ class MaterialBoxModel extends Model
     protected $fillable=[
         "code","description","maximum_kind"
     ];
+
+    public function commodity():HasOne
+    {
+        return $this->hasOne(CommodityMaterialBoxModel::class);
+    }
 }

+ 3 - 110
app/Services/CacheShelfService.php

@@ -7,13 +7,9 @@ use App\Exceptions\ErrorException;
 use App\MaterialBox;
 use App\Station;
 use App\StationTask;
-use App\StationTaskChild;
 use App\StationTaskChildren;
 use App\StationTaskMaterialBox;
-use App\StationType;
-use App\Storage;
 use App\Traits\ServiceAppAop;
-use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Http;
 use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Database\Eloquent\Collection;
@@ -60,7 +56,6 @@ class   CacheShelfService
         }])->where('code', $locCode)->first();
         //站存在 站为缓存架2 站为蓝灯状态
         if (app("StationService")->isHalfBoxLocation($station)){
-            if (!Storage::query()->where("station_id",$station->id)->whereNotNull("material_box_id")->first())return ['success' => false, 'errMsg' => "任务执行中,不允许灭灯"];
             if (!app("StorageService")->checkStorage($station)){
                 $this->lightUp($station->code,'0','1',["title"=>"上架失败,联系管理员"]);
                 return ['success' => false,'errMsg' => '上架任务失败'];
@@ -126,94 +121,7 @@ class   CacheShelfService
      */
     public function bindMaterialBox($stationCode, $materialBoxCode): array
     {
-        $station = Station::query()->with('storage')->where('code', $stationCode)->first();
-
-        if (!$station) {
-            $arr = [];
-            preg_match('/^HAI([\w]+)/', $stationCode, $arr);
-            $parentCode = $arr[1] ?? '';
-            $stationType = StationType::query()->where('name', '缓存架')->first();
-            $parentStation = Station::query()->firstOrCreate(['code' => $parentCode], ['station_type_id' => $stationType['id']]);
-            $station = Station::query()->firstOrCreate(['code' => $stationCode, 'parent_id' => $parentStation['id']], ['name' => $stationCode, 'station_type_id' => $stationType['id']]);
-        }
-
-        $materialBox = MaterialBox::query()->firstOrCreate(['code' => $materialBoxCode]);
-
-        $storage = $station->storage ?? Storage::query()->firstOrCreate(['station_id' => $station['id']]);
-
-        $result = $this->_stationCacheLightOn($station['code'],$materialBoxCode);
-        if($result['code'] == 200){
-            $storage->update(['material_box_id' => $materialBox['id'],'status' => 1]);
-            return ['success' => true];
-        }
-        return ['success' => false,'message' => $result['errMsg']];
-    }
-
-
-    /**
-     * 控制格口亮灯
-     * @param $locCode
-     * @param null $materialCode
-     * @param string $title
-     * @param string $color
-     * @return mixed
-     */
-    public function _stationCacheLightOn($locCode, $materialCode = null, $title = 'title', string $color = '1')
-    {
-        $params = [
-            "areaCode" => "1004",
-            'locCode' => $locCode,
-            'PTLAction' => 1,
-            'PTLSettings' => ['color' => $color, 'frequency' => 1],
-            "displayInfo" => [
-                "detail01" => $materialCode,
-                "detail02" => "detail02",
-                "detail03" => "detail03",
-                "qrCode" => "qrCode",
-                "qty00" => "11",
-                "qty01" => 1,
-                "qty02" => 2,
-                "title" => $title,
-                "uomDesc01" => "uo",
-                "uomDesc02" => "uo"
-            ],
-        ];
-        $response = Http::post(config('api.haiq.storage.light'), $params);
-        return json_decode($response->body());
-    }
-
-    /**
-     * 站亮灯
-     *
-     * @param string $stationCode
-     * @param string|null $materialCode
-     * @param string $color             explain: 0-red 1-green 2-blue 3-yellow
-     * @param string $frequency         explain: 0-常亮 1-一次 2-两次 3-三次 4-四次 5-五次 (均为/秒)
-     * @param string $title
-     * @return mixed
-     */
-    public function stationLightUp(string $stationCode,?string $materialCode = null, string $color = '1', string $frequency = '0', $title = '')
-    {
-        $params = [
-            "areaCode" => "1004",
-            'locCode' => $stationCode,
-            'PTLAction' => 1,
-            'PTLSettings' => ['color' => $color, 'frequency'  => $frequency],
-            "displayInfo" => [
-                "detail01" => $materialCode,
-                "detail02" => "detail02",
-                "detail03" => "detail03",
-                "qrCode" => "qrCode",
-                "qty00" => "11",
-                "qty01" => 1,
-                "qty02" => 2,
-                "title" => $title,
-                "uomDesc01" => "uo",
-                "uomDesc02" => "uo"
-            ],
-        ];
-        $response = Http::post(config('api.haiq.storage.light'), $params);
-        return json_decode($response->body());
+        return ['success' => false,'message' => "接口废弃"];
     }
 
     /**
@@ -293,21 +201,6 @@ class   CacheShelfService
         }
     }
 
-    /**
-     * 根据立库任务完成对storage进行修改
-     * @param StationTaskMaterialBox $stationTaskMaterial
-     */
-    public function putStationTaskMaterialBoxProcess(StationTaskMaterialBox $stationTaskMaterial)
-    {
-        $this->instant($this->stationTaskMaterialBoxService, 'StationTaskMaterialBoxService');
-
-        $storage = Storage::query()->where('material_box_id', $stationTaskMaterial['material_box_id'])->where('status',1)->first();
-        if($storage)$storage->update(['status' => 0, 'material_box_id' => null]);
-
-        $this->_stationCacheLightOff($stationTaskMaterial->station->code ?? null);  //海柔格口灭灯
-        $this->_stationCacheBroadCast($stationTaskMaterial->station->code ?? null, 0);    //通知缓存架任务完成
-    }
-
     /**
      * 取消任务
      * @param $stationCode
@@ -320,7 +213,7 @@ class   CacheShelfService
 
         if (!$station) return ['success' => false, 'message' => '传入参数异常,找不到对应的缓存架记录'];
 
-        $stationTaskMaterialBox = StationTaskMaterialBox::query()->where('material_box_id',$station['storage']['material_box_id'])->first();
+        $stationTaskMaterialBox = StationTaskMaterialBox::query()->where('material_box_id',$station['material_box_id'])->first();
         if($stationTaskMaterialBox ){
             if($stationTaskMaterialBox->status == '处理中')
                 return ['success' => false, 'message' => '当前缓存架任务正在处理中'];
@@ -329,7 +222,7 @@ class   CacheShelfService
             }
         }
 
-        $station->storage->update(['status' => 0,'material_box_id' => null]);
+        $station->update(['status' => 0,'material_box_id' => null]);
 
         return ['success' => true];
     }

+ 5 - 6
app/Services/CommodityMaterialBoxModelService.php

@@ -1,4 +1,4 @@
-<?php 
+<?php
 
 namespace App\Services;
 
@@ -14,14 +14,13 @@ class CommodityMaterialBoxModelService
     /**
      * 获取最大限值
      *
-     * @param integer|null $modelId
-     * @param integer|null $commodityId
+     * @param integer $modelId
+     * @param integer $commodityId
      *
      * @return int|null
      */
-    public function getMaximum($modelId, $commodityId):?int
+    public function getMaximum(int $modelId, int $commodityId):?int
     {
-        if (!$modelId || !$commodityId)return null;
         $model = CommodityMaterialBoxModel::query()->select("maximum")->where("commodity_id",$commodityId)
             ->where("material_box_model_id",$modelId)->first();
         return (int)$model->maximum ?? null;
@@ -48,4 +47,4 @@ class CommodityMaterialBoxModelService
         ]);else $model->update(["maximum" => $maximum]);
         return true;
     }
-}
+}

+ 1 - 1
app/Services/ForeignHaiRoboticsService.php

@@ -510,7 +510,7 @@ class ForeignHaiRoboticsService
      *
      * @throws
      */
-    public function paddingCacheShelf($stations):?bool
+    public function paddingCacheShelf(Collection $stations):?bool
     {
         $collection = new Collection();
         $stationCollection = new Collection();

+ 0 - 19
app/Services/MaterialBoxService.php

@@ -7,8 +7,6 @@ namespace App\Services;
 use App\MaterialBox;
 use App\MaterialBoxModel;
 use App\StationTaskMaterialBox;
-use App\Storage;
-use Illuminate\Database\Eloquent\Builder;
 use App\Traits\ServiceAppAop;
 use Illuminate\Support\Facades\DB;
 
@@ -92,21 +90,6 @@ sql;
         return null;
     }
 
-    /**
-     * 获取料箱所在库区
-     *
-     * @param string $ide
-     *
-     * @return string|null
-     */
-    public function getBoxLocation(string $ide):?string
-    {
-        $storage = Storage::query()->with("station")->whereHas("materialBox",function (Builder $box)use($ide){
-            $box->where("code",$ide);
-        })->whereNotNull("station_id")->first();
-        return $storage->station->code ?? null;
-    }
-
     /**
      * 检查可用料箱
      *
@@ -117,8 +100,6 @@ sql;
     public function checkUsableBox(int $boxId):bool
     {
         /** @var MaterialBox|\stdClass $box */
-        //$box = MaterialBox::query()->find($boxId);
-        //if (!$this->getBoxLocation($box->code))return false;
         if (StationTaskMaterialBox::query()->select(DB::raw(1))->whereNotIn("status",['完成','取消'])->where("material_box_id",$boxId)->first())return false;
         return true;
     }

+ 11 - 0
app/Services/StationService.php

@@ -116,4 +116,15 @@ class StationService
         return $station->parent_id==7;
     }
 
+    /**
+     * 是否为缓存架位置
+     *
+     * @param Station|\stdClass $station
+     *
+     * @return bool
+     */
+    public function isCacheShelfLocation(Station $station):bool
+    {
+        return $station->station_type_id == 5;
+    }
 }

+ 16 - 23
app/Services/StationTaskCommodityService.php

@@ -5,15 +5,14 @@ namespace App\Services;
 
 
 use App\Batch;
+use App\MaterialBoxCommodity;
 use App\OrderCommodity;
-use App\StationTask;
-use App\StationTaskBatch;
 use App\StationTaskCommodity;
 use App\StationTaskMaterialBox;
-use App\Storage;
 use Illuminate\Support\Collection;
 use Illuminate\Support\Facades\Cache;
 use App\Traits\ServiceAppAop;
+use Illuminate\Support\Facades\DB;
 
 
 class StationTaskCommodityService
@@ -195,26 +194,20 @@ class StationTaskCommodityService
         $stationTaskMaterialBoxes=StationTaskMaterialBox::query()
             ->whereIn('id', data_get($stationTaskCommodities, '*.station_task_material_box_id') ?? [])
             ->get('material_box_id');
-        $storages=Storage::query()->whereIn('commodity_id',data_get($stationTaskCommodities,'*.commodity_id')??[])
-            ->whereIn('material_box_id',data_get($stationTaskMaterialBoxes,'*.material_box_id')??[])
-            ->get();
-        foreach($storages as $storage){
-            $amountReducing=$stationTaskCommodities->where('material_box_id',$storage['material_box_id'])->first()['amount']??0;
-            $storage['amount']-=$amountReducing;
-            $storage->update();
+        $boxes = data_get($stationTaskMaterialBoxes,'*.material_box_id')??[];
+        $commodities = data_get($stationTaskCommodities,'*.commodity_id')??[];
+        $map = [];
+        foreach ($stationTaskCommodities as $commodity){
+            $map[$commodity->material_box_id."-".$commodity->commodity_id] = $commodity->amount;
         }
-//        $station_id=$stationTaskCommodities[0]['station_id'];
-//        $stationTaskCommodities_next=StationTaskCommodity::query()
-//            ->where('station_id',$station_id)
-//            ->where('status','处理队列')
-//            ->orderBy('updated_at')
-//            ->get();
-//        if($stationTaskCommodities_next->isNotEmpty()){
-//            $stationTaskCommodities_toUpdate=$stationTaskCommodities_next->where(
-//                'material_box_id', $stationTaskCommodities_next->first()['material_box_id']);
-//            StationTaskCommodity::query()
-//                ->whereIn('id',data_get($stationTaskCommodities_toUpdate,'*.id'))
-//                ->update(['status'=>'处理中']);
-//        }
+        MaterialBoxCommodity::query()->whereIn('commodity_id',$commodities)
+            ->whereIn('material_box_id',$boxes)->lockForUpdate()
+            ->get()->each(function ($boxC)use($map){
+                $key = $boxC->material_box_id."-".$boxC->commodity_id;
+                if (!isset($map[$key]))return false;
+                if ($boxC->amount>$map[$key])$boxC->update(["amount"=>DB::raw("amount-{$map[$key]}")]);
+                if ($boxC->amount==$map[$key])$boxC->delete();
+                return true;
+            });
     }
 }

+ 0 - 1
app/Services/StationTaskMaterialBoxService.php

@@ -172,7 +172,6 @@ class StationTaskMaterialBoxService
                     $stationTaskMaterialBox->materialBox->update();
                     break;
                 case '入立库':
-                    $this->cacheShelfService->putStationTaskMaterialBoxProcess($stationTaskMaterialBox);
                     $stationTaskMaterialBox->materialBox['status']='在立库';
                     $stationTaskMaterialBox->materialBox->update();
                     $stationTaskMaterialBox->loadMissing("station");    //提前加载站,后续都需要站信息来处理

+ 27 - 114
app/Services/StorageService.php

@@ -3,17 +3,16 @@
 namespace App\Services;
 
 use App\CommodityMaterialBoxModel;
+use App\MaterialBoxCommodity;
 use App\Station;
 use App\StationTask;
 use App\StationTaskMaterialBox;
 use App\StoreItem;
 use App\TaskTransaction;
 use App\Traits\ServiceAppAop;
-use App\Storage;
 use App\ValueStore;
 use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Database\Eloquent\Model;
-use Illuminate\Support\Collection;
 use Illuminate\Support\Facades\Auth;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Str;
@@ -21,7 +20,6 @@ use Illuminate\Support\Str;
 class StorageService
 {
     use ServiceAppAop;
-    protected $modelClass=Storage::class;
 
     /**
      * 缓存架放置记录
@@ -32,16 +30,8 @@ class StorageService
     {
         DB::beginTransaction();
         try{
-            $storage = Storage::query()->where("material_box_id",$stationTaskMaterialBox->material_box_id)->lockForUpdate()->first();
-            Storage::query()->where("station_id",$stationTaskMaterialBox->station_id)->where("status",0)
-                ->whereNotNull("material_box_id")->update(["station_id"=>null]);
-            Storage::query()->where("station_id",$stationTaskMaterialBox->station_id)->where("status",0)
-                ->whereNull("material_box_id")->delete();
-            if ($storage)$storage->update(["station_id"=>$stationTaskMaterialBox->station_id,'status'=>0]);
-            else Storage::query()->create([
-                "station_id" => $stationTaskMaterialBox->station_id,
-                "material_box_id" => $stationTaskMaterialBox->material_box_id,
-            ]);
+            Station::query()->where("id",$stationTaskMaterialBox->station_id)
+                ->update(["material_box_id"=>$stationTaskMaterialBox->material_box_id,"status"=>0]);
             $stationTaskMaterialBox->loadMissing("station");
             //清理原有任务
             if ($stationTaskMaterialBox->station){
@@ -74,13 +64,11 @@ class StorageService
      */
     public function releaseOccupation($stationTaskMaterialBox)
     {
-        if ($stationTaskMaterialBox->station->station_type_id != 5)return;
-        $storage = Storage::query()->where("material_box_id",$stationTaskMaterialBox->material_box_id)->first();
-        if (!$storage)return;
-        $update = [];
-        if ($storage->status == 1)$update["status"] = 0;
-        if ($storage->station_id)$update["station_id"] = null;
-        if ($update)$storage->update($update);
+        if (!app("StationService")->isCacheShelfLocation($stationTaskMaterialBox->station))return;
+        $stationTaskMaterialBox->station->update([
+            "material_box_id" => null,
+            "status" => 0,
+        ]);
     }
 
     /**
@@ -130,7 +118,7 @@ class StorageService
                     return false;
                 }
                 $taskMaterialBox = $this->createWarehousingTask($station->id,$task->material_box_id);//建立入库任务
-                if (!$this->enterWarehouse($station->id,$task->material_box_id,$task->commodity_id,$task->amount))throw new \Exception("库存异常"); //处理库存
+                if (!$this->enterWarehouse($task->material_box_id,$task->commodity_id,$task->amount))throw new \Exception("库存异常"); //处理库存
                 $task->update([
                     "task_id" => $taskMaterialBox->id,
                     "status" => 1,
@@ -156,7 +144,7 @@ class StorageService
      *
      * @return StationTaskMaterialBox|\stdClass|Model
      */
-    public function createWarehousingTask($stationId,$boxId)
+    public function createWarehousingTask($stationId,$boxId):StationTaskMaterialBox
     {
         /** @var StationTask|\stdClass $task */
         $task = StationTask::query()->create([
@@ -175,32 +163,28 @@ class StorageService
     /**
      * 库存入库
      *
-     * @param integer $stationId
      * @param integer $boxId
      * @param integer $commodityId
      * @param integer $amount
-     * @param integer $modelId
+     * @param integer|null $modelId
      *
      * @return bool
      */
-    public function enterWarehouse($stationId, $boxId, $commodityId, $amount, $modelId = null)
+    public function enterWarehouse(int $boxId,int $commodityId,int $amount,?int $modelId = null):bool
     {
         DB::beginTransaction();
         try{
-            $storage = Storage::query()->where("material_box_id",$boxId)->lockForUpdate()->first();
-            $obj = [
-                "station_id" => $stationId,
-                "material_box_id" => $boxId,
-                "commodity_id" => $commodityId,
-                "amount" => $amount,
-                "status" => 1,
-            ];
+            $storage = MaterialBoxCommodity::query()->where("material_box_id",$boxId)
+                ->where("commodity_id",$commodityId)->lockForUpdate()->first();
             if ($storage){
                 $amountTemp = (int)$storage->amount + (int)$amount;
-                $obj["amount"] = DB::raw("amount+{$amount}");
-                $storage->update($obj);
+                $storage->update(["amount"=>DB::raw("amount+{$amount}")]);
                 $amount = $amountTemp;
-            } else Storage::query()->create($obj);
+            } else MaterialBoxCommodity::query()->create([
+                "amount" => $amount,
+                "material_box_id" => $boxId,
+                "commodity_id" => $commodityId,
+            ]);
             if ($commodityId && $modelId){
                 //维护料箱最大上限 用于半箱补货
                 $model = CommodityMaterialBoxModel::query()->select("maximum")->where("commodity_id",$commodityId)
@@ -210,7 +194,7 @@ class StorageService
                     ->where("material_box_model_id",$modelId)->update(["maximum"=>$amount]);
             }
             DB::commit();
-            LogService::log(__CLASS__,"库存增加",$storage->toJson()."  |  ".json_encode([$stationId, $boxId, $commodityId, $amount, $modelId]));
+            LogService::log(__CLASS__,"库存增加",$storage->toJson()."  |  ".json_encode([$boxId, $commodityId, $amount, $modelId]));
             return true;
         }catch(\Exception $e){
             DB::rollBack();
@@ -261,6 +245,7 @@ sql;
      * @param int $amount
      *
      * @return array
+     * @throws
      */
     private function splitTask($tasks,$maxIndex,$amount):array
     {
@@ -511,75 +496,6 @@ SQL;
         ValueStore::query()->select("value")->where("name","flux_tr_number")->update(["value"=>(string)((int)$max+1)]);
     }
 
-    /**
-     * 入库
-     *
-     * @param integer $boxId
-     * @param integer $amount
-     * @param integer $commodityId
-     *
-     * @return bool
-     */
-    public function warehousing($boxId, $amount, $commodityId = null):bool
-    {
-        DB::beginTransaction();
-        try{
-            $storage = Storage::query()->where("material_box_id",$boxId)->lockForUpdate()->first();
-            if (!$storage && !$commodityId)return false;
-            if (!$storage){
-                Storage::query()->create([
-                    "station_id" => null,
-                    "material_box_id" => $boxId,
-                    "commodity_id" => $commodityId,
-                    "amount" => $amount,
-                ]);
-                return true;
-            }
-            if ($commodityId && $storage->commodity_id && $storage->commodity_id!=$commodityId)return false;
-            $obj = [
-                "station_id" => null,
-                "amount" => DB::raw("amount + {$amount}"),
-            ];
-            if (!$storage->commodity_id && $commodityId)$obj["commodity_id"] = $commodityId;
-            $storage->update($obj);
-            DB::commit();
-            return true;
-        }catch (\Exception $e){
-            DB::rollBack();
-            return false;
-        }
-    }
-
-    /**
-     * 出库
-     *
-     * @param integer $boxId
-     * @param integer $amount
-     * @param integer $commodityId
-     *
-     * @return bool
-     */
-    public function outWarehousing($boxId, $amount, $commodityId = null):bool
-    {
-        DB::beginTransaction();
-        try{
-            $storage = Storage::query()->where("material_box_id",$boxId)->lockForUpdate()->first();
-            if (!$storage)return false;
-            if ($commodityId && $storage->commodity_id && $storage->commodity_id!=$commodityId)return false;
-            $obj = [
-                "station_id" => null,
-                "amount" => DB::raw("amount - {$amount}"),
-            ];
-            if (!$storage->commodity_id && $commodityId)$obj["commodity_id"] = $commodityId;
-            $storage->update($obj);
-            DB::commit();
-            return true;
-        }catch (\Exception $e){
-            DB::rollBack();
-            return false;
-        }
-    }
-
     /**
      * 清除任务
      *
@@ -612,21 +528,18 @@ SQL;
      * @param StoreItem|\stdClass $item
      * @param string|null $asn
      *
-     * @return ?Storage
+     * @return ?MaterialBoxCommodity
      */
-    public function getHalfBoxLocation(CommodityMaterialBoxModel $model,StoreItem $item,?string $asn = null,array $blacklist = []):?Storage
+    public function getHalfBoxLocation(CommodityMaterialBoxModel $model,StoreItem $item,?string $asn = null,array $blacklist = []):?MaterialBoxCommodity
     {
         if (!$asn){$item->loadMissing("store");$asn = $item->store->asn_code;}
         $boxCodes = '';//拼接料箱编码
         $map = [];//库位与库存映射
         //查询填充
-        $query = Storage::query()->with("materialBox")->whereHas("materialBox",function (Builder $query)use($model){
+        $query = MaterialBoxCommodity::query()->with("materialBox")->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"),">",0);
-        if ($blacklist)$query->whereHas("materialBox",function (Builder $query)use($blacklist){
-           $query->whereNotIn("id",$blacklist);
-        });
+        })->where("commodity_id",$model->commodity_id)->where("amount","<",$model->maximum);
+        if ($blacklist)$query->whereNotIn("material_box_id",$blacklist);
         $query->get()->each(function ($storage)use(&$boxCodes,&$map){
             $boxCodes .= "'".$storage->materialBox->code."',";
             $map[$storage->materialBox->code] = $storage;

+ 11 - 2
app/Station.php

@@ -3,8 +3,8 @@
 namespace App;
 
 use App\Traits\ModelTimeFormat;
-use Carbon\Carbon;
 use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\Relations\BelongsTo;
 use Illuminate\Database\Eloquent\Relations\HasOne;
 use App\Traits\ModelLogChanging;
 
@@ -13,8 +13,17 @@ class Station extends Model
     use ModelLogChanging;
     use ModelTimeFormat;
 
-    protected $fillable=['name', 'code', 'station_type_id','sequence','parent_id'];
+    protected $fillable=['name', 'code', 'station_type_id','sequence','parent_id',"material_box_id","status"];
 
+    const STATUS=[
+        0 => "正常",
+        1 => "占用",
+    ];
+
+    public function materialBox():BelongsTo
+    {
+        return $this->belongsTo(MaterialBox::class);
+    }
     public function stationType(){
         return $this->belongsTo(StationType::class);
     }

+ 34 - 0
database/migrations/2021_07_19_113938_create_material_box_commodities_table.php

@@ -0,0 +1,34 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateMaterialBoxCommoditiesTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('material_box_commodities', function (Blueprint $table) {
+            $table->id();
+            $table->bigInteger("material_box_id")->index()->comment("料箱ID");
+            $table->bigInteger("commodity_id")->index()->comment("商品ID");
+            $table->integer("amount")->default(0)->comment("数量");
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('material_box_commodities');
+    }
+}

+ 34 - 0
database/migrations/2021_07_19_115331_change_stations_add_material_box_id.php

@@ -0,0 +1,34 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class ChangeStationsAddMaterialBoxId extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('stations', function (Blueprint $table) {
+            $table->bigInteger("material_box_id")->index()->comment("料箱ID");
+            $table->tinyInteger("status")->default(0)->comment("状态");
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('stations', function (Blueprint $table) {
+            $table->dropColumn("material_box_id");
+            $table->dropColumn("status");
+        });
+    }
+}

+ 2 - 1
resources/views/store/inStorage/cacheRackStorage.blade.php

@@ -115,7 +115,7 @@
             },
             mounted(){
                 if (navigator.userAgent.indexOf("Android")!==-1)this.isAndroid = true;
-                @foreach($storages as $storage)this.$set(this.shelfOccupy,"{{$storage->station->code}}",true);@endforeach
+                @foreach($stations as $station)this.$set(this.shelfOccupy,"{{$station->code}}",!!{{$station->material_box_id}});@endforeach
                 //this.codeFocus();
                 //this.globalClick();
                 this.createBefore();
@@ -153,6 +153,7 @@
                         for (let key in this.selectedBox)if (this.selectedBox[key]) boxes.push(key);
                         window.tempTip.postBasicRequest("{{url('store/inStorage/resetCacheShelf')}}",{boxes:boxes},res=>{
                             window.tempTip.cancelWaitingTip();
+                            window.tempTip.setDuration(3000);
                             for (let i=0;i<res.boxes.length;i++){
                                 this.$set(this.shelfOccupy,res.boxes[i],true);
                                 this.$set(this.selectedBox,res.boxes[i],true);

+ 39 - 41
resources/views/transport/waybill/edit.blade.php

@@ -38,43 +38,7 @@
                                     <input name="type" id="type" :value="waybill.type" hidden>
                                 </div>
                             </div>
-                            <div class="form-group row">
-                                <label for="charge" class="col-2 col-form-label text-right text-secondary">运输收费(元)</label>
-                                <div class="col-3">
-                                    <input type="number" step="0.01" min="0" class="form-control @error('charge') is-invalid @enderror"
-                                           id="charge" name="charge" v-model="waybill.charge" >
-                                </div>
-                                <label for="mileage" class="col-2 col-form-label text-right text-muted">里程数</label>
-                                <div class="input-group col-4">
-                                    <input type="number" step="0.01" class="form-control @error('mileage') is-invalid @enderror"
-                                           name="mileage" autocomplete="off" v-model="waybill.mileage" id="mileage" >
-                                    <div class="input-group-append">
-                                        <span class="input-group-text">KM</span>
-                                    </div>
-                                </div>
-                                @error('charge')
-                                <span class="invalid-feedback" role="alert">
-                                    <strong>{{ $message }}</strong>
-                                </span>
-                                @enderror
-                            </div>
-                            <div class="form-group row">
-                                <label for="other_charge" class="col-2 col-form-label text-right text-muted">其他收费(元)</label>
-                                <div class="col-3">
-                                    <input id="other_charge" type="number" step="0.01" class="form-control @error('other_charge') is-invalid @enderror"
-                                           name="other_charge" autocomplete="off" value="@if(old('other_charge')){{ old('other_charge') }}@else{{$waybill->other_charge}}@endif"  >
-                                </div>
-                                <label for="other_charge_remark" class="col-2 col-form-label text-right text-muted">其他收费备注</label>
-                                <div class="col-4">
-                                    <input type="text" class="form-control" id="other_charge_remark"
-                                           name="other_charge_remark" autocomplete="off" value="@if(old('other_charge_remark')){{ old('other_charge_remark') }}@else{{$waybill->other_charge_remark}}@endif"  >
-                                </div>
-                                @error('other_charge')
-                                <span class="invalid-feedback" role="alert">
-                                    <strong>{{ $message }}</strong>
-                                </span>
-                                @enderror
-                            </div>
+
                             <div class="form-group row" style="margin-bottom: 20px">
                                 <label for="logistic_id" class="col-2 col-form-label text-right text-primary">承运商 *</label>
                                 <div class="col-3" style="position: relative">
@@ -238,13 +202,10 @@
                             </div>
                             <div class="form-group row">
                                 <label for="amount" class="col-2 col-form-label text-right text-primary">计数</label>
-                                <div class="col-5">
+                                <div class="col-4 form-inline">
                                     <input type="number" class="form-control @error('amount') is-invalid @enderror"
                                            name="amount" autocomplete="off" v-model="waybill.amount" id="amount">
                                     @error('amount')<span class="invalid-feedback" role="alert"><strong>{{ $message }}</strong></span>@enderror
-                                </div>
-                                <label for="amount_unit_id" class=" col-form-label text-right ">单位:</label>
-                                <div class="col-1.5 form-inline">
                                     <label for="amount_unit_id" class="ml-1  @error('amount_unit_id') text-danger @enderror"  >件</label>
                                     <input id="amount_unit_id" type="radio" value="4" class="form-control form-control-sm ml-1"
                                            name="amount_unit_id" v-model="waybill.amount_unit_id">
@@ -252,6 +213,14 @@
                                     <input id="amount_unit_id1" type="radio" value="5" class="form-control form-control-sm ml-1"
                                            :class="errors['amount_unit_id'] ? 'is-invalid' :''" name="amount_unit_id" v-model="waybill.amount_unit_id">
                                 </div>
+                                <label for="mileage" class="col-2 col-form-label text-right text-muted" v-if="waybill.type=='直发车'">里程数</label>
+                                <div class="input-group col-3" v-if="waybill.type=='直发车'">
+                                    <input type="number" step="0.01" class="form-control @error('mileage') is-invalid @enderror"
+                                           name="mileage" autocomplete="off" v-model="waybill.mileage" id="mileage" >
+                                    <div class="input-group-append">
+                                        <span class="input-group-text">KM</span>
+                                    </div>
+                                </div>
                                 @error('amount_unit_id')
                                 <div class="col-2 form-inline">
                                     <label class="form-control-static text-danger small font-weight-bold">{{$message}}</label>
@@ -385,6 +354,35 @@
                                     <input type="text" class="form-control" disabled="disabled" :value="waybill.recipient_mobile" >
                                 </div>
                             </div>
+                            <div class="form-group row">
+                                <label for="charge" class="col-2 col-form-label text-right text-secondary">运输收费(元)</label>
+                                <div class="col-3">
+                                    <input type="number" step="0.01" min="0" class="form-control @error('charge') is-invalid @enderror"
+                                           id="charge" name="charge" v-model="waybill.charge" >
+                                </div>
+                                <label for="other_charge" class="col-2 col-form-label text-right text-muted">其他收费(元)</label>
+                                <div class="col-3">
+                                    <input id="other_charge" type="number" step="0.01" class="form-control @error('other_charge') is-invalid @enderror"
+                                           name="other_charge" autocomplete="off" value="@if(old('other_charge')){{ old('other_charge') }}@else{{$waybill->other_charge}}@endif"  >
+                                </div>
+                                @error('charge')
+                                <span class="invalid-feedback" role="alert">
+                                    <strong>{{ $message }}</strong>
+                                </span>
+                                @enderror
+                                @error('other_charge')
+                                <span class="invalid-feedback" role="alert">
+                                    <strong>{{ $message }}</strong>
+                                </span>
+                                @enderror
+                            </div>
+                            <div class="form-group row">
+                                <label for="other_charge_remark" class="col-2 col-form-label text-right text-muted">其他收费备注</label>
+                                <div class="col-8">
+                                    <input type="text" class="form-control" id="other_charge_remark"
+                                           name="other_charge_remark" autocomplete="off" value="@if(old('other_charge_remark')){{ old('other_charge_remark') }}@else{{$waybill->other_charge_remark}}@endif"  >
+                                </div>
+                            </div>
                             <div class="form-group row" id="ordering_remark">
                                 <label class="col-2 col-form-label text-right text-secondary">下单备注</label>
                                 <div class="col-8">