Sfoglia il codice sorgente

BUG修复:称重管理,子项显示屏蔽主项无效

Zhouzhendong 5 anni fa
parent
commit
71ac1c0e47

+ 1 - 1
app/Http/Controllers/CitiesController.php

@@ -83,6 +83,6 @@ class CitiesController extends Controller
     }
 
     public function get(){
-        return ["success"=>true,"data"=>City::query()->select("id","name","province_id")->get()];
+        return ["success"=>true,"data"=>City::query()->select("id","name","province_id")->with("province")->get()];
     }
 }

+ 144 - 42
app/Http/Controllers/PriceModelController.php

@@ -1096,7 +1096,7 @@ class PriceModelController extends Controller
         $this->gate("客户管理-项目-录入");
         $params = request()->input();
         $params["logistic_id"] = $params["logistics"];
-        $errors = $this->expressValidator($params)->errors();
+        $errors = $this->expressValidator($params,request("id"))->errors();
         $exist = [];
         foreach ($params["items"] as $index => $item){
             if (isset($exist[$item["province_id"]]))$errors["items.".$index.".province_id"] = ["已存在"];
@@ -1104,19 +1104,51 @@ class PriceModelController extends Controller
         }
         if (count($errors)>0)$this->success(["errors"=>$errors]);
 
-        DB::transaction(function ()use(&$model,$params){
-            $model = app('OwnerPriceExpressService')->create([
-                "name"              => request("name"),
-                "initial_weight"    => request("initial_weight"),
-                "additional_weight" => request("additional_weight"),
-            ]);
-            foreach ($params["items"] as &$item)$item["owner_price_express_id"] = $model->id;
-            OwnerPriceExpressProvince::query()->insert($params["items"]);
-            DB::insert(DB::raw("INSERT INTO owner_price_express_owner VALUES(?,?)"),[$model->id,request("owner_id")]);
+        $obj = [
+            "name"              => request("name"),
+            "initial_weight"    => request("initial_weight"),
+            "additional_weight" => request("additional_weight"),
+        ];
+        if (request("id")){
             /** @var OwnerPriceExpress $model */
-            $model->logistics()->syncWithoutDetaching(request("logistics"));
-            DB::commit();
-        });
+            $model = app('OwnerPriceExpressService')->find(request("id"),["details"]);
+            app('OwnerPriceExpressService')->update(["id"=>request("id")],$obj);
+
+            $delete = [];//需要删除子项
+            $update = [["id","province_id","initial_weight_price","additional_weight_price"]];//需要更新子项
+            $insert = [];//需要新增子项
+            foreach ($params["items"] as $item){
+                $obj = [
+                    "province_id"               => $item["province_id"],
+                    "initial_weight_price"      => $item["initial_weight_price"],
+                    "additional_weight_price"   => $item["additional_weight_price"],
+                ];
+                if (isset($item["id"])){
+                    $obj["id"] = $item["id"];
+                    $update[] = $obj;
+                    $delete[] = $item["id"];
+                } else{
+                    $obj["owner_price_express_id"] = $model->id;
+                    $insert[] = $obj;
+                }
+            }
+            $ids = array_column($model->details->toArray(),"id");
+            $delete = array_diff($ids,$delete);
+            if ($delete)OwnerPriceExpressProvince::destroy($delete);
+            if (count($update) > 1)app(BatchUpdateService::class)->batchUpdate("owner_price_express_provinces",$update);
+            if ($insert)OwnerPriceExpressProvince::query()->insert($insert);
+            $model->logistics()->sync(request("logistics"));
+        }else{
+            DB::transaction(function ()use(&$model,$params,$obj){
+                $model = app('OwnerPriceExpressService')->create($obj);
+                foreach ($params["items"] as &$item)$item["owner_price_express_id"] = $model->id;
+                OwnerPriceExpressProvince::query()->insert($params["items"]);
+                DB::insert(DB::raw("INSERT INTO owner_price_express_owner VALUES(?,?)"),[$model->id,request("owner_id")]);
+                /** @var OwnerPriceExpress $model */
+                $model->logistics()->syncWithoutDetaching(request("logistics"));
+                DB::commit();
+            });
+        }
         $model->load("details");
         $this->success($model);
     }
@@ -1127,7 +1159,7 @@ class PriceModelController extends Controller
         $params = request()->input();
         $params["owner_id"] = [$params["owner_id"]];
         $params["logistic_id"] = $params["logistics"];
-        $errors = $this->logisticValidator($params)->errors();
+        $errors = $this->logisticValidator($params,request("id"))->errors();
         $exist = [];
         foreach ($params["items"] as $index => $item){
             $key = $item["unit_id"]."-".$item["range"]."-".$item["province_id"]."-".$item["city_id"];
@@ -1135,24 +1167,63 @@ class PriceModelController extends Controller
             else $exist[$key] = true;
         }
         if (count($errors)>0)$this->success(["errors"=>$errors]);
-        DB::transaction(function ()use(&$model,$params){
-            $model = app("OwnerPriceLogisticService")->create([
-                "name"              => request('name'),
-                "unit_range"        => request('unit_range'),
-                "unit_id"           => request('unit_id'),
-                "other_unit_range"  => request('other_unit_range'),
-                "other_unit_id"     => request('other_unit_id'),
-                "pick_up_price"     => request('pick_up_price'),
-                "fuel_price"        => request('fuel_price'),
-                "service_price"     => request('service_price'),
-            ]);
-            foreach ($params["items"] as &$param)$param["owner_price_logistic_id"] = $model->id;
-            OwnerPriceLogisticDetail::query()->insert($params["items"]);
-            DB::insert(DB::raw("INSERT INTO owner_price_logistic_owner VALUES(?,?)"),[$model->id,request("owner_id")]);
+
+        $obj = [
+            "name"              => request('name'),
+            "unit_range"        => request('unit_range'),
+            "unit_id"           => request('unit_id'),
+            "other_unit_range"  => request('other_unit_range'),
+            "other_unit_id"     => request('other_unit_id'),
+            "pick_up_price"     => request('pick_up_price'),
+            "fuel_price"        => request('fuel_price'),
+            "service_price"     => request('service_price'),
+        ];
+        if (request("id")){
+            $model = app("OwnerPriceLogisticService")->find(request("id"),["details"]);
+            app("OwnerPriceLogisticService")->update(["id"=>request("id")],$obj);
+
+            $delete = [];//需要删除子项
+            $update = [["id","unit_id","range","province_id","city_id","unit_price","delivery_fee","initial_fee","initial_amount","rate"]];//需要更新子项
+            $insert = [];//需要新增子项
+            foreach ($params["items"] as $item){
+                $obj = [
+                    "unit_id"        => $item["unit_id"],
+                    "range"          => $item["range"],
+                    "province_id"    => $item["province_id"],
+                    "city_id"        => $item["city_id"],
+                    "unit_price"     => $item["unit_price"],
+                    "delivery_fee"   => $item["delivery_fee"],
+                    "initial_fee"    => $item["initial_fee"],
+                    "initial_amount" => $item["initial_amount"],
+                    "rate"           => $item["rate"],
+                ];
+                if (isset($item["id"])){
+                    $obj["id"] = $item["id"];
+                    $update[] = $obj;
+                    $delete[] = $item["id"];
+                } else{
+                    $obj["owner_price_logistic_id"] = $model->id;
+                    $insert[] = $obj;
+                }
+            }
+            $ids = array_column($model->details->toArray(),"id");
+            $delete = array_diff($ids,$delete);
+            if ($delete)OwnerPriceLogisticDetail::destroy($delete);
+            if (count($update) > 1)app(BatchUpdateService::class)->batchUpdate("owner_price_logistic_details",$update);
+            if ($insert)OwnerPriceLogisticDetail::query()->insert($insert);
             /** @var OwnerPriceLogistic $model */
-            $model->logistics()->syncWithoutDetaching(request("logistics"));
-            DB::commit();
-        });
+            $model->logistics()->sync(request("logistics"));
+        }else{
+            DB::transaction(function ()use(&$model,$params,$obj){
+                $model = app("OwnerPriceLogisticService")->create($obj);
+                foreach ($params["items"] as &$param)$param["owner_price_logistic_id"] = $model->id;
+                OwnerPriceLogisticDetail::query()->insert($params["items"]);
+                DB::insert(DB::raw("INSERT INTO owner_price_logistic_owner VALUES(?,?)"),[$model->id,request("owner_id")]);
+                /** @var OwnerPriceLogistic $model */
+                $model->logistics()->syncWithoutDetaching(request("logistics"));
+                DB::commit();
+            });
+        }
         $model->load("details");
         $this->success($model);
     }
@@ -1160,7 +1231,7 @@ class PriceModelController extends Controller
     public function apiStoreDirectLogistic()
     {
         $this->gate("客户管理-项目-录入");
-        $errors = $this->directLogisticValidator(request()->input())->errors();
+        $errors = $this->directLogisticValidator(request()->input(),request("id"))->errors();
         $exist = [];
         foreach (request("items") as $index=>$item){
             if (isset($exist[$item['car_type_id']]))$errors["items.".$index.".car_type_id"] = ["已存在"];
@@ -1169,16 +1240,47 @@ class PriceModelController extends Controller
         if (count($errors)>0)$this->success(["errors"=>$errors]);
 
         $items = request()->input("items");
-        DB::transaction(function ()use(&$model,$items){
-            $model = app("OwnerPriceDirectLogisticService")->create([
-                "name"      => request("name"),
-                "base_km"   => request("base_km"),
-            ]);
-            foreach ($items as &$item)$item["owner_price_direct_logistic_id"] = $model->id;
-            OwnerPriceDirectLogisticCar::query()->insert($items);
-            DB::insert(DB::raw("INSERT INTO owner_price_direct_logistic_owner VALUES(?,?)"),[$model->id,request("owner_id")]);
-            DB::commit();
-        });
+        $obj = [
+            "name"      => request("name"),
+            "base_km"   => request("base_km"),
+        ];
+        if (request("id")){
+            $model = app("OwnerPriceDirectLogisticService")->find(request("id"),["details"]);
+            app("OwnerPriceDirectLogisticService")->update(["id"=>request("id")],$obj);
+
+            $delete = [];//需要删除子项
+            $update = [["id","car_type_id","base_fee","additional_fee"]];//需要更新子项
+            $insert = [];//需要新增子项
+            foreach ($items as $item){
+                $obj = [
+                    "car_type_id"       => $item["car_type_id"],
+                    "base_fee"          => $item["base_fee"],
+                    "additional_fee"    => $item["additional_fee"],
+                ];
+                if (isset($item["id"])){
+                    $obj["id"] = $item["id"];
+                    $update[] = $obj;
+                    $delete[] = $item["id"];
+                } else{
+                    $obj["owner_price_direct_logistic_id"] = $model->id;
+                    $insert[] = $obj;
+                }
+            }
+            $ids = array_column($model->details->toArray(),"id");
+            $delete = array_diff($ids,$delete);
+            if ($delete)OwnerPriceDirectLogisticCar::destroy($delete);
+            if (count($update) > 1)app(BatchUpdateService::class)->batchUpdate("owner_price_direct_logistic_cars",$update);
+            if ($insert)OwnerPriceDirectLogisticCar::query()->insert($insert);
+        }else{
+            DB::transaction(function ()use(&$model,$items,$obj){
+                $model = app("OwnerPriceDirectLogisticService")->create($obj);
+                foreach ($items as &$item)$item["owner_price_direct_logistic_id"] = $model->id;
+                OwnerPriceDirectLogisticCar::query()->insert($items);
+                DB::insert(DB::raw("INSERT INTO owner_price_direct_logistic_owner VALUES(?,?)"),[$model->id,request("owner_id")]);
+                DB::commit();
+            });
+        }
+        /** @var OwnerPriceDirectLogistic $model */
         $model->load("details");
         $this->success($model);
     }

+ 3 - 2
app/Services/PackageService.php

@@ -13,11 +13,12 @@ const TABLE = "order_packages.";
 Class PackageService
 {
     private function conditionQuery($params){
-        $packages = OrderPackage::query()->with(['order'=>function($query){
+        $packages = OrderPackage::query()->with(['order','paperBox','measuringMachine'])
+        ->whereHas("order",function ($query){
             /** @var Builder $query */
             $ownerIds=app('UserService')->getPermittingOwnerIds(Auth::user());
             $query->with('owner','logistic')->whereIn("owner_id",$ownerIds ?? []);
-        },'paperBox','measuringMachine'])->orderBy(TABLE.'id','DESC');
+        })->orderBy(TABLE.'id','DESC');
         if ($params['owner_id'] ?? false){
             $owner_id = explode(',',$params['owner_id']);
             $packages->whereHas('order',function ($query)use($owner_id){

+ 27 - 7
resources/views/customer/project/create.blade.php

@@ -695,11 +695,14 @@
                             if (res.errors.owner_id)window.tempTip.show(res.errors.owner_id[0]);
                             return;
                         }
-                        this.model.express.id = res.id;
                         this.model.express.items.forEach((item,i)=>{
                             item.id = res.details[i].id;
                         });
-                        this.selectedModel.express.unshift(this.model.express);
+                        if (this.model.express.id) this.selectedModel.express[this.model.express.index] = this.model.express;
+                        else{
+                            this.model.express.id = res.id;
+                            this.selectedModel.express.unshift(this.model.express);
+                        }
                         this.model.express = {
                             name:"",
                             logistics:[],
@@ -732,11 +735,15 @@
                             this.errors = res.errors;
                             return;
                         }
-                        this.model.logistic.id = res.id;
                         this.model.logistic.items.forEach((item,i)=>{
                             item.id = res.details[i].id;
                         });
-                        this.selectedModel.logistic.unshift(this.model.logistic);
+                        console.log(this.model.logistic);
+                        if (this.model.logistic.id) this.selectedModel.logistic[this.model.logistic.index] = this.model.logistic;
+                        else {
+                            this.model.logistic.id = res.id;
+                            this.selectedModel.logistic.unshift(this.model.logistic);
+                        }
                         this.model.logistic = {
                             items:[],
                             other_ranges:[],
@@ -765,10 +772,10 @@
                             this.errors = res.errors;
                             return;
                         }
-                        this.model.directLogistic.id = res.id;
                         this.model.directLogistic.items.forEach((item,i)=>{
                             item.id = res.details[i].id;
                         });
+                        this.model.directLogistic.id = res.id;
                         this.selectedModel.directLogistic = this.model.directLogistic;
                         this.model.directLogistic = {
                             items:[],
@@ -1400,8 +1407,21 @@
                     this.model.operation.index = index;
                 },
                 //编辑快递
-                editExpress(){
-
+                editExpress(index){
+                    this.switchType("express");
+                    this.model.express = JSON.parse(JSON.stringify(this.selectedModel.express[index]));
+                    this.model.express.index = index;
+                },
+                //编辑物流
+                editLogistic(index){
+                    this.switchType("logistic");
+                    this.model.logistic = JSON.parse(JSON.stringify(this.selectedModel.logistic[index]));
+                    this.model.logistic.index = index;
+                },
+                //编辑直发车
+                editDirectLogistic(){
+                    this.switchType("directLogistic");
+                    this.model.directLogistic = JSON.parse(JSON.stringify(this.selectedModel.directLogistic));
                 },
             },
         });

+ 12 - 12
resources/views/customer/project/part/_three.blade.php

@@ -138,7 +138,7 @@
                         <th>详情</th>
                         <th></th>
                     </tr>
-                    <tbody v-for="(express,i) in selectedModel.express" @click="editExpress()">
+                    <tbody v-for="(express,i) in selectedModel.express" @dblclick="editExpress(i)" style="cursor: pointer">
                         <tr>
                             <td>
                                 <div class="text-overflow-warp-100 small">
@@ -148,11 +148,11 @@
                             <td>@{{ express.name }}</td>
                             <td>@{{ express.initial_weight }}</td>
                             <td>@{{ express.additional_weight }}</td>
-                            <td @click="show('express-item-'+i)" class="cursor-pointer">
+                            <td @click.stop="show('express-item-'+i)" class="cursor-pointer">
                                 <span class="fa" :class="upList['express-item-'+i] ? 'fa-angle-double-right' : 'fa-angle-double-down'"></span>
                                 &nbsp;@{{ express.items.length }} 省份</td>
                             <td>
-                                <span class="cursor-pointer text-danger font-weight-bold" @click="delExpress(express,i)">&times;</span>
+                                <span class="cursor-pointer text-danger font-weight-bold" @click.stop="delExpress(express,i)">&times;</span>
                             </td>
                         </tr>
                         <tr>
@@ -170,7 +170,7 @@
                                             <td>@{{ item.initial_weight_price }}</td>
                                             <td>@{{ item.additional_weight_price }}</td>
                                             <td>
-                                                <span class="cursor-pointer text-danger font-weight-bold" @click="deleteExpressItem(item,j,i)">&times;</span>
+                                                <span class="cursor-pointer text-danger font-weight-bold" @click.stop="deleteExpressItem(item,j,i)">&times;</span>
                                             </td>
                                         </tr>
                                     </table>
@@ -200,7 +200,7 @@
                         <th>详情</th>
                         <th></th>
                     </tr>
-                    <tbody v-for="(logistic,i) in selectedModel.logistic">
+                    <tbody v-for="(logistic,i) in selectedModel.logistic" @dblclick="editLogistic(i)">
                         <tr>
                             <td>
                                 <div class="text-overflow-warp-100 small">
@@ -215,12 +215,12 @@
                             <td>@{{ logistic.pick_up_price }}</td>
                             <td>@{{ logistic.fuel_price }}</td>
                             <td>@{{ logistic.service_price }}</td>
-                            <td @click="show('logistic-item-'+i)" class="cursor-pointer">
+                            <td @click.stop="show('logistic-item-'+i)" class="cursor-pointer">
                                 <span class="fa" :class="upList['logistic-item-'+i] ? 'fa-angle-double-right' : 'fa-angle-double-down'"></span>
                                 &nbsp;@{{ logistic.items.length }} 地区
                             </td>
                             <td>
-                                <span class="cursor-pointer text-danger font-weight-bold" @click="delLogistic(logistic,i)">&times;</span>
+                                <span class="cursor-pointer text-danger font-weight-bold" @click.stop="delLogistic(logistic,i)">&times;</span>
                             </td>
                         </tr>
                         <tr>
@@ -250,7 +250,7 @@
                                             <td>@{{ item.initial_amount }}</td>
                                             <td>@{{ item.rate }}<span v-if="item.rate" class="font-weight-bold">&nbsp;%</span></td>
                                             <td>
-                                                <span class="cursor-pointer text-danger font-weight-bold" @click="deleteLogisticItem(item,j,i)">&times;</span>
+                                                <span class="cursor-pointer text-danger font-weight-bold" @click.stop="deleteLogisticItem(item,j,i)">&times;</span>
                                             </td>
                                         </tr>
                                     </table>
@@ -265,16 +265,16 @@
             <div class="card-header bg-light-info">
                 <span class="pull-left font-weight-bold cursor-pointer" @click="show('directLogistic')"><span class="fa fa-rocket"></span>&nbsp;直发</span>
             </div>
-            <div class="card-body" id="directLogistic">
+            <div class="card-body" id="directLogistic" @dblclick="editDirectLogistic()" style="cursor: pointer">
                 <div class="row">
                     <label class="col-4">名称:<b>@{{ selectedModel.directLogistic.name }}</b></label>
                     <label class="col-4">起步数(KM):<b>@{{ selectedModel.directLogistic.base_km }}</b></label>
                     <label class="col-1 offset-3" v-if="selectedModel.directLogistic.name">
-                        <span class="cursor-pointer text-danger font-weight-bold" @click="delDirectLogistic(selectedModel.directLogistic)">&times;</span>
+                        <span class="cursor-pointer text-danger font-weight-bold" @click.stop="delDirectLogistic(selectedModel.directLogistic)">&times;</span>
                     </label>
                 </div>
                 <div class="row">
-                    <div class="cursor-pointer text-primary col-2" @click="show('directLogistic-item')">
+                    <div class="cursor-pointer text-primary col-2" @click.stop="show('directLogistic-item')">
                         <span class="fa" :class="upList['directLogistic-item'] ? 'fa-angle-double-right' : 'fa-angle-double-down'"></span>&nbsp;详情</div>
                     <div class="col-10" id="directLogistic-item">
                         <table class="table table-sm">
@@ -289,7 +289,7 @@
                                 <td>@{{ item.base_fee }}</td>
                                 <td>@{{ item.additional_fee }}</td>
                                 <td>
-                                    <span class="cursor-pointer text-danger font-weight-bold" @click="deleteDirectLogisticItem(item,i)">&times;</span>
+                                    <span class="cursor-pointer text-danger font-weight-bold" @click.stop="deleteDirectLogisticItem(item,i)">&times;</span>
                                 </td>
                             </tr>
                         </table>