Ver código fonte

即时账单新需求,增加新单位等

Zhouzhendong 4 anos atrás
pai
commit
d5f1e0da85

+ 20 - 51
app/Http/Controllers/PriceModelController.php

@@ -55,8 +55,7 @@ class PriceModelController extends Controller
         $this->storageValidator($request->input())->validate();
         /** @var OwnerStoragePriceModel $model */
         $model = app('OwnerStoragePriceModelService')->create($request->input());
-        $result = $model->owners()->sync(explode(",",$request->input("owner_id")));
-        app("OwnerService")->refreshRelevance($result["attached"],0);
+        $model->owners()->sync(explode(",",$request->input("owner_id")));
         LogService::log(__METHOD__,"计费模型-创建仓储计费",json_encode($request->input(),JSON_UNESCAPED_UNICODE));
         return response()->redirectTo('maintenance/priceModel/storage')->with('successTip',"创建成功!");
     }
@@ -92,9 +91,7 @@ class PriceModelController extends Controller
             $service->update(["id"=>$id],$values);
             $model = new OwnerStoragePriceModel();
             $model->id = $id;
-            $result = $model->owners()->sync(explode(",",request("owner_id")));
-            app("OwnerService")->refreshRelevance($result["attached"],0);
-            app("OwnerService")->refreshRelevance($result["detached"],0,true);
+            $model->owners()->sync(explode(",",request("owner_id")));
         }else $service->copy($model,$values,explode(",",request("owner_id")));
         return response()->redirectTo('maintenance/priceModel/storage')->with('successTip',"更新成功!");
     }
@@ -321,11 +318,7 @@ class PriceModelController extends Controller
         }
         //录入中间表
         /** @var OwnerPriceOperation $ownerPriceOperation */
-        if ($request->input("owner_id")){
-            $result = $ownerPriceOperation->owners()->sync($request->input("owner_id"));
-            app("OwnerService")->refreshRelevance($result["attached"],1);
-            app("OwnerService")->refreshRelevance($result["detached"],1,true);
-        }
+        if ($request->input("owner_id"))$ownerPriceOperation->owners()->sync($request->input("owner_id"));
         LogService::log(__METHOD__,"计费模型-录入作业计费",json_encode($request->input(),JSON_UNESCAPED_UNICODE));
         return response()->redirectTo("maintenance/priceModel/operation")->with("successTip","创建“".$request->input("name")."”成功");
     }
@@ -381,11 +374,7 @@ class PriceModelController extends Controller
             }
             //录入中间表
             /** @var OwnerPriceOperation $model */
-            if ($request->input("owner_id")){
-                $result = $model->owners()->sync(request("owner_id"));
-                app("OwnerService")->refreshRelevance($result["attached"],1);
-                app("OwnerService")->refreshRelevance($result["detached"],1,true);
-            }
+            if ($request->input("owner_id"))$model->owners()->sync(request("owner_id"));
         }else $service->copy($model,$obj,request("owner_id"),request("items"),false);
         LogService::log(__METHOD__,"计费模型-修改作业计费",json_encode($request->input(),JSON_UNESCAPED_UNICODE));
         return response()->redirectTo("maintenance/priceModel/operation")->with("successTip","修改“".$request->input("name")."”成功");
@@ -516,9 +505,7 @@ class PriceModelController extends Controller
             "initial_weight" => $request->input("initial_weight"),
             "additional_weight" => $request->input("additional_weight"),
         ]);
-        $result = $model->owners()->sync($request->input("owner_id"));
-        app("OwnerService")->refreshRelevance($result["attached"],2);
-        app("OwnerService")->refreshRelevance($result["detached"],2,true);
+        $model->owners()->sync($request->input("owner_id"));
         $model->logistics()->sync($request->input("logistic_id"));
         LogService::log(__METHOD__,"计费模型-录入快递计费",json_encode($request->input(),JSON_UNESCAPED_UNICODE));
         return response()->redirectTo("maintenance/priceModel/express")->with("successTip","录入“".$request->input("name")."”成功");
@@ -550,9 +537,7 @@ class PriceModelController extends Controller
             app("OwnerPriceExpressService")->update(["id"=>$id],$values);
             $model = new OwnerPriceExpress();
             $model->id = $id;
-            $result = $model->owners()->sync($request->input("owner_id"));
-            app("OwnerService")->refreshRelevance($result["attached"],2);
-            app("OwnerService")->refreshRelevance($result["detached"],2,true);
+            $model->owners()->sync($request->input("owner_id"));
             $model->logistics()->sync($request->input("logistic_id"));
         }else app("OwnerPriceExpressService")->copy($model,$values,$request->input("owner_id"),$request->input("logistic_id"));
         LogService::log(__METHOD__,"计费模型-修改快递计费",json_encode($request->input(),JSON_UNESCAPED_UNICODE));
@@ -637,9 +622,7 @@ class PriceModelController extends Controller
             "other_unit_id" => $request->input("other_unit_id"),
             "other_unit_range" => $request->input("other_unit_range"),
         ]);
-        $result = $model->owners()->sync($request->input("owner_id"));
-        app("OwnerService")->refreshRelevance($result["attached"],3);
-        app("OwnerService")->refreshRelevance($result["detached"],3,true);
+        $model->owners()->sync($request->input("owner_id"));
         $model->logistics()->sync($request->input("logistic_id"));
         LogService::log(__METHOD__,"计费模型-录入物流计费",json_encode($request->input(),JSON_UNESCAPED_UNICODE));
         return response()->redirectTo("maintenance/priceModel/logistic")->with("successTip","创建“".$request->input("name")."”成功");
@@ -675,9 +658,7 @@ class PriceModelController extends Controller
             app("OwnerPriceLogisticService")->update(["id"=>$id],$values);
             $model = new OwnerPriceLogistic();
             $model->id = $id;
-            $result = $model->owners()->sync($request->input("owner_id"));
-            app("OwnerService")->refreshRelevance($result["attached"],3);
-            app("OwnerService")->refreshRelevance($result["detached"],3,true);
+            $model->owners()->sync($request->input("owner_id"));
             $model->logistics()->sync($request->input("logistic_id"));
         }else app("OwnerPriceLogisticService")->copy($model,$values,$request->input("owner_id"),$request->input("logistic_id"));
 
@@ -954,9 +935,7 @@ class PriceModelController extends Controller
             "name" => $request->input("name"),
             "base_km" => $request->input("base_km"),
         ]);
-        $result = $model->owners()->sync($request->input("owner_id"));
-        app("OwnerService")->refreshRelevance($result["attached"],4);
-        app("OwnerService")->refreshRelevance($result["detached"],4,true);
+        $model->owners()->sync($request->input("owner_id"));
         LogService::log(__METHOD__,"计费模型-录入直发车计费",json_encode($request->input(),JSON_UNESCAPED_UNICODE));
         return response()->redirectTo("maintenance/priceModel/directLogistic")->with("successTip","创建“".$request->input("name")."”成功");
     }
@@ -995,9 +974,7 @@ class PriceModelController extends Controller
             app("OwnerPriceDirectLogisticService")->update(["id"=>$id],$values);
             $model = new OwnerPriceDirectLogistic();
             $model->id = $id;
-            $result = $model->owners()->sync($request->input("owner_id"));
-            app("OwnerService")->refreshRelevance($result["attached"],4);
-            app("OwnerService")->refreshRelevance($result["detached"],4,true);
+            $model->owners()->sync($request->input("owner_id"));
         }else app("OwnerPriceDirectLogisticService")->copy($model,$values,request("owner_id"));
         LogService::log(__METHOD__,"计费模型-修改直发车计费",json_encode($request->input(),JSON_UNESCAPED_UNICODE));
         return response()->redirectTo("maintenance/priceModel/directLogistic")->with("successTip","修改“".$request->input("name")."”成功");
@@ -1146,7 +1123,6 @@ class PriceModelController extends Controller
         }else{
             $model = app('OwnerStoragePriceModelService')->create($values);
             DB::insert(DB::raw("INSERT INTO owner_storage_price_model_owner VALUES(?,?)"),[$model->id,request("owner_id")]);
-            app("OwnerService")->refreshRelevance(request("owner_id"),0);
             $this->success($model->id);
         }
     }
@@ -1225,7 +1201,6 @@ class PriceModelController extends Controller
                 }
                 app("OwnerPriceOperationItemService")->insert($params["items"]);
                 DB::insert(DB::raw("INSERT INTO owner_price_operation_owner(owner_price_operation_id,owner_id) VALUES(?,?)"),[$model->id,request("owner_id")]);
-                app("OwnerService")->refreshRelevance(request("owner_id"),1);
                 DB::commit();
             });
         }
@@ -1300,7 +1275,6 @@ class PriceModelController extends Controller
                 }
                 OwnerPriceExpressProvince::query()->insert($params["items"]);
                 DB::insert(DB::raw("INSERT INTO owner_price_express_owner VALUES(?,?)"),[$model->id,request("owner_id")]);
-                app("OwnerService")->refreshRelevance(request("owner_id"),2);
                 /** @var OwnerPriceExpress $model */
                 $model->logistics()->syncWithoutDetaching(request("logistics"));
                 DB::commit();
@@ -1382,7 +1356,6 @@ class PriceModelController extends Controller
                 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")]);
-                app("OwnerService")->refreshRelevance(request("owner_id"),3);
                 /** @var OwnerPriceLogistic $model */
                 $model->logistics()->syncWithoutDetaching(request("logistics"));
                 DB::commit();
@@ -1447,7 +1420,6 @@ class PriceModelController extends Controller
                 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")]);
-                app("OwnerService")->refreshRelevance(request("owner_id"),4);
                 DB::commit();
             });
         }
@@ -1807,11 +1779,12 @@ class PriceModelController extends Controller
         /** @var \stdClass|Owner $owner */
         $owner = new Owner();
         $owner->id = $ownerId;
+        $response = null;
         switch (request("type")){
             case "storage":
                 app("OwnerStoragePriceModelService")->auditOrRecover(request("isAudit"),$ownerId);//priceModelAuditOrRecoverQuery
                 $owner->load("ownerStoragePriceModels");
-                $this->success($owner->ownerStoragePriceModels);
+                $response = $owner->ownerStoragePriceModels;
                 break;
             case "operation":
                 app("OwnerPriceOperationService")->auditOrRecover(request("isAudit"),$ownerId);
@@ -1834,7 +1807,7 @@ class PriceModelController extends Controller
                         }
                     }
                 }
-                $this->success($owner->ownerPriceOperations);
+                $response = $owner->ownerPriceOperations;
                 break;
             case "express":
                 app("OwnerPriceExpressService")->auditOrRecover(request("isAudit"),$ownerId);
@@ -1842,7 +1815,7 @@ class PriceModelController extends Controller
                     /** @var Builder $query */
                     $query->with(["details","logistics"]);
                 }]);
-                $this->success($owner->ownerPriceExpresses);
+                $response = $owner->ownerPriceExpresses;
                 break;
             case "logistic":
                 app("OwnerPriceLogisticService")->auditOrRecover(request("isAudit"),$ownerId);
@@ -1850,7 +1823,7 @@ class PriceModelController extends Controller
                     /** @var Builder $query */
                     $query->with(["details","logistics"]);
                 }]);
-                $this->success($owner->ownerPriceLogistics);
+                $response = $owner->ownerPriceLogistics;
                 break;
             case "directLogistic":
                 app("OwnerPriceDirectLogisticService")->auditOrRecover(request("isAudit"),$ownerId);
@@ -1859,18 +1832,14 @@ class PriceModelController extends Controller
                 break;
             case "system":
                 $result = app(QueryService::class)->priceModelAuditOrRecoverQuery(request("isAudit"),OwnerPriceSystem::query(),$ownerId,null,true);
-                if ($result["delete"]){
-                    OwnerPriceSystem::destroy($result["delete"]);
-                    app("OwnerService")->refreshRelevance($ownerId,5,true);
-                }
-                if ($result["update"]){
-                    OwnerPriceSystem::query()->whereIn("id",$result["update"])->update(["operation"=>null,"target_id"=>null]);
-                    app("OwnerService")->refreshRelevance($ownerId,5);
-                }
+                if ($result["delete"])OwnerPriceSystem::destroy($result["delete"]);
+                if ($result["update"])OwnerPriceSystem::query()->whereIn("id",$result["update"])->update(["operation"=>null,"target_id"=>null]);
                 $owner->load("ownerPriceSystem");
-                $this->success($owner->ownerPriceSystem);
+                $response = $owner->ownerPriceSystem;
                 break;
         }
+        app("OwnerService")->refreshRelevance($ownerId);
+        $this->success($response);
     }
 
     /**

+ 3 - 2
app/Http/Controllers/WeighController.php

@@ -2,6 +2,7 @@
 
 namespace App\Http\Controllers;
 
+use App\MeasuringMachine;
 use App\OrderPackage;
 use App\PaperBox;
 use App\Services\OrderPackageService;
@@ -13,7 +14,6 @@ use Exception;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Auth;
 use Illuminate\Support\Facades\Gate;
-use Illuminate\Support\Facades\Http;
 use Illuminate\Support\Facades\Validator;
 use Oursdreams\Export\Export;
 
@@ -27,7 +27,8 @@ class WeighController extends Controller
         /** @var PackageService $application */
         $application = app('PackageService');
         $packages = $application->paginate($request);
-        return view('package.weigh.index',['packages'=>$packages,'owners'=>$ownerService->getIntersectPermitting(),'paginateParams'=>$paginateParams]);
+        $measuringMachines = MeasuringMachine::query()->get();
+        return view('package.weigh.index',['packages'=>$packages,"measuringMachines"=>$measuringMachines,'owners'=>$ownerService->getIntersectPermitting(),'paginateParams'=>$paginateParams]);
     }
 
     public function create()

+ 0 - 7
app/Services/OwnerPriceDirectLogisticService.php

@@ -106,14 +106,7 @@ class OwnerPriceDirectLogisticService
         if (!is_array($id))$id = [$id];
         OwnerPriceDirectLogisticCar::query()->whereIn("owner_price_direct_logistic_id",$id)->delete();
 
-        $query = "IN (";
-        for ($i=0;$i<count($id)-1;$i++)$query .= "{$id[$i]},";
-        $query .= "{$id[count($id)-1]})";
-
-        $sql = "SELECT * FROM owner_price_direct_logistic_owner WHERE owner_price_direct_logistic_id {$query}";
-        $owners = array_column(DB::select(DB::raw($sql)),"owner_id");
         DB::table("owner_price_direct_logistic_owner")->whereIn("owner_price_direct_logistic_id",$id)->delete();
-        app("OwnerService")->refreshRelevance($owners,4,true);
         return OwnerPriceDirectLogistic::destroy($id);
     }
 

+ 0 - 8
app/Services/OwnerPriceExpressService.php

@@ -193,15 +193,7 @@ class OwnerPriceExpressService
         if (!$id)return 0;
         if (!is_array($id))$id = [$id];
         OwnerPriceExpressProvince::query()->whereIn("owner_price_express_id",$id)->delete();
-
-        $query = "IN (";
-        for ($i=0;$i<count($id)-1;$i++)$query .= "{$id[$i]},";
-        $query .= "{$id[count($id)-1]})";
-
-        $sql = "SELECT * FROM owner_price_express_owner WHERE owner_price_express_id {$query}";
-        $owners = array_column(DB::select(DB::raw($sql)),"owner_id");
         DB::table("owner_price_express_owner")->whereIn("owner_price_express_id",$id)->delete();
-        app("OwnerService")->refreshRelevance($owners,2,true);
         DB::table("owner_price_express_logistic")->whereIn("owner_price_express_id",$id)->delete();
         return OwnerPriceExpress::destroy($id);
     }

+ 0 - 7
app/Services/OwnerPriceLogisticService.php

@@ -125,14 +125,7 @@ class OwnerPriceLogisticService
         if (!is_array($id))$id = [$id];
         OwnerPriceLogisticDetail::query()->whereIn("owner_price_logistic_id",$id)->delete();
 
-        $query = "IN (";
-        for ($i=0;$i<count($id)-1;$i++)$query .= "{$id[$i]},";
-        $query .= "{$id[count($id)-1]})";
-
-        $sql = "SELECT * FROM owner_price_logistic_owner WHERE owner_price_logistic_id {$query}";
-        $owners = array_column(DB::select(DB::raw($sql)),"owner_id");
         DB::table("owner_price_logistic_owner")->whereIn("owner_price_logistic_id",$id)->delete();
-        app("OwnerService")->refreshRelevance($owners,3,true);
         DB::table("owner_price_logistic_logistic")->whereIn("owner_price_logistic_id",$id)->delete();
 
         return OwnerPriceLogistic::destroy($id);

+ 26 - 18
app/Services/OwnerPriceOperationService.php

@@ -141,14 +141,7 @@ class OwnerPriceOperationService
         if (!is_array($id))$id = [$id];
         OwnerPriceOperationItem::query()->whereIn("owner_price_operation_id",$id)->delete();
 
-        $query = "IN (";
-        for ($i=0;$i<count($id)-1;$i++)$query .= "{$id[$i]},";
-        $query .= "{$id[count($id)-1]})";
-
-        $sql = "SELECT * FROM owner_price_operation_owner WHERE owner_price_operation_id {$query}";
-        $owners = array_column(DB::select(DB::raw($sql)),"owner_id");
         DB::table("owner_price_operation_owner")->whereIn("owner_price_operation_id",$id)->delete();
-        app("OwnerService")->refreshRelevance($owners,1,true);
 
         return OwnerPriceOperation::destroy($id);
     }
@@ -319,7 +312,7 @@ class OwnerPriceOperationService
      */
     public function matching($matchObject, $columnMapping, $ownerId, $type = '出库', $typeMark = null)
     {
-        $units = app("UnitService")->getUnitMapping(["件","箱"]); //获取单位映射集
+        $units = app("UnitService")->getUnitMapping(["件","箱","m³","T","kg"]); //获取单位映射集
         $rules = $this->getOwnerPriceOperation($ownerId,$type,$typeMark);//货主下的全部规则
         if (!$rules)return -2;  //规则不存在跳出
 
@@ -331,6 +324,9 @@ class OwnerPriceOperationService
         if ($type == '出库'){
             $total = app("OrderService")->getOrderQuantity($ownerId)+1;//获取该货主本月C端单量
             $matchObject->packages->each(function ($package)use(&$orderTotal){
+                if($package->commodities->count()==0)return;
+                $package->commodities[0]->bulk = $package->bulk/1000000;
+                $package->commodities[0]->weight = $package->weight;
                 $package->commodities->each(function ($commodity)use(&$orderTotal){
                     $orderTotal += (int)$commodity->amount;
                 });
@@ -468,17 +464,29 @@ class OwnerPriceOperationService
                 }
                 $package["price"] = $rule->unit_price;
             }
-            if ($units[$rule->unit_id] == '箱'){ //为箱时同步商品寻找箱规
-                $amount = 0;
-                foreach ($matchObject as $commodity){
-                    $pack = $this->changeUnit($ownerId,$commodity[$columnMapping[9]]);
-                    if ($rule->odd_price){
-                        $amount += floor($amount/$pack);
-                        $surcharge += $rule->odd_price * ($amount%$pack); //零头附加费
-                    }else$amount += ceil($amount/$pack);
+            if ($units[$rule->unit_id] != '件'){ //非件时改变商品数量 此时数量可能为小数
+                foreach ($matchObject as &$commodity){
+                    switch ($units[$rule->unit_id]){
+                        case "箱"://为箱时同步商品寻找箱规并改变商品数量
+                            $pack = $this->changeUnit($ownerId,$commodity[$columnMapping[9]]);
+                            if ($rule->odd_price){
+                                $amount = floor($commodity[$columnMapping[8]]/$pack);
+                                $surcharge += $rule->odd_price * ($amount%$pack); //零头附加费
+                            }else$amount = ceil($commodity[$columnMapping[8]]/$pack);
+                            if ($amount<0)return $amount;
+                            $commodity[$columnMapping[8]] = $amount;
+                            break;
+                        case "m³":
+                            $commodity[$columnMapping[8]] = $commodity["bulk"] ?? 0;
+                            break;
+                        case "kg":
+                            $commodity[$columnMapping[8]] = $commodity["weight"] ?? 0;
+                            break;
+                        case "T":
+                            $commodity[$columnMapping[8]] = ($commodity["weight"]/1000) ?? 0;
+                            break;
+                    }
                 }
-                if ($amount<0)return $amount;
-                $package[$columnMapping[8]] = $amount;
             }
         }
         if ($matchObject){

+ 44 - 49
app/Services/OwnerService.php

@@ -380,58 +380,53 @@ sql
     /**
      * 计费模型变动时更新货主中关联属性
      *
-     * @param integer|array $owner
-     * @param integer $type
-     * @param bool $isDestroy
+     * @param integer $ownerId
      *
      */
-    public function refreshRelevance($owner, $type, $isDestroy = false)
+    public function refreshRelevance($ownerId)
     {
-        if (!$owner)return;
-        if (!is_array($owner))$owner = [$owner];
-        $owners = Owner::query()->select("id","relevance")->whereIn("id",$owner)->get();
-        $update = [["id","relevance"]];
-        foreach ($owners as $ow){
-            $relevance = $ow->relevance ?? [];
-            $index = array_search($type,$relevance);
-            $exist = $index===false ? false : true;
-            if ($exist && $isDestroy && !$this->isExistModel($ow->id,$type)){
-                array_splice($relevance,$index,1);
-                $update[] = [
-                    "id"=>$ow->id,
-                    "relevance"=>$relevance,
-                ];
-            }
-            if (!$exist && !$isDestroy){
-                array_push($relevance,$type);
-                $update[] = [
-                    "id"=>$ow->id,
-                    "relevance"=>$relevance,
-                ];
-            }
-        }
-        if (count($update)>1)app(BatchUpdateService::class)->batchUpdate("owners",$update);
-    }
-
-    private function isExistModel($owner, $type):bool
-    {
-        switch ($type){
-            case 0:
-                $table = "owner_storage_price_model_owner";
-                break;
-            case 1:
-                $table = "owner_price_operation_owner";
-                break;
-            case 2:
-                $table = "owner_price_logistic_owner";
-                break;
-            case 3:
-                $table = "owner_price_express_owner";
-                break;
-            default:
-                $table = "owner_price_direct_logistic_owner";
-        }
-        return DB::selectOne(DB::raw("SELECT 1 FROM {$table} WHERE owner_id = ? LIMIT 1"),[$owner]) ? true : false;
+        $relevance = [];
+        $sql = <<<sql
+SELECT 1 FROM owner_storage_price_models a 
+LEFT JOIN owner_storage_price_model_owner b ON a.id =  b.owner_storage_price_model_id 
+LEFT JOIN owners c ON b.owner_id = c.id 
+WHERE (a.operation IS NULL OR a.operation = '') AND c.id = ? LIMIT 1
+sql;
+        if (DB::selectOne(DB::raw($sql),[$ownerId]))$relevance[] = 0;
+        $sql = <<<sql
+SELECT 1 FROM owner_price_operations a 
+LEFT JOIN owner_price_operation_owner b ON a.id =  b.owner_price_operation_id 
+LEFT JOIN owners c ON b.owner_id = c.id 
+WHERE (a.operation IS NULL OR a.operation = '') AND c.id = ? LIMIT 1
+sql;
+        if (DB::selectOne(DB::raw($sql),[$ownerId]))$relevance[] = 1;
+        $sql = <<<sql
+SELECT 1 FROM owner_price_expresses a 
+LEFT JOIN owner_price_express_owner b ON a.id =  b.owner_price_express_id 
+LEFT JOIN owners c ON b.owner_id = c.id 
+WHERE (a.operation IS NULL OR a.operation = '') AND c.id = ? LIMIT 1
+sql;
+        if (DB::selectOne(DB::raw($sql),[$ownerId]))$relevance[] = 2;
+        $sql = <<<sql
+SELECT 1 FROM owner_price_logistics a 
+LEFT JOIN owner_price_logistic_owner b ON a.id =  b.owner_price_logistic_id 
+LEFT JOIN owners c ON b.owner_id = c.id 
+WHERE (a.operation IS NULL OR a.operation = '') AND c.id = ? LIMIT 1
+sql;
+        if (DB::selectOne(DB::raw($sql),[$ownerId]))$relevance[] = 3;
+        $sql = <<<sql
+SELECT 1 FROM owner_price_direct_logistics a 
+LEFT JOIN owner_price_direct_logistic_owner b ON a.id =  b.owner_price_direct_logistic_id 
+LEFT JOIN owners c ON b.owner_id = c.id 
+WHERE (a.operation IS NULL OR a.operation = '') AND c.id = ? LIMIT 1
+sql;
+        if (DB::selectOne(DB::raw($sql),[$ownerId]))$relevance[] = 4;
+        $sql = <<<sql
+SELECT 1 FROM owner_price_systems a LEFT JOIN owners b ON a.owner_id = b.id
+WHERE b.id = ? LIMIT 1
+sql;
+        if (DB::selectOne(DB::raw($sql),[$ownerId]))$relevance[] = 5;
+        Owner::query()->where("id",$ownerId)->update(["relevance"=>$relevance]);
     }
 
     /**

+ 0 - 4
app/Services/OwnerStoragePriceModelService.php

@@ -92,7 +92,6 @@ class OwnerStoragePriceModelService
     }
     public function destroy($id)
     {
-        $sql = "SELECT * FROM owner_storage_price_model_owner WHERE owner_storage_price_model_id ";
         if (is_array($id)){
             $query = "IN (";
             for ($i=0;$i<count($id)-1;$i++)$query .= "?,";
@@ -101,10 +100,7 @@ class OwnerStoragePriceModelService
             $query = "= ?";
             $id = [$id];
         }
-        $owners = array_column(DB::select(DB::raw($sql.$query),$id),"owner_id");
         DB::delete(DB::raw("DELETE FROM owner_storage_price_model_owner WHERE owner_storage_price_model_id ".$query),$id);
-        app("OwnerService")->refreshRelevance($owners,0,true);
-
         return OwnerStoragePriceModel::destroy($id);
     }
 

+ 9 - 1
resources/views/customer/project/create.blade.php

@@ -892,6 +892,13 @@
                         this.$set(this.errors,"surcharge_unit_id",["耗材附加费未填写"]);
                         return;
                     }
+                    let unit = this.model.operation.items[0].unit_id;
+                    for (let i=1;i<this.model.operation.items.length;i++){
+                        if (this.model.operation.items[i]!==unit){
+                            this.$set(this.errors,'items.'+i+'.unit_id',["所有子项单位必须一致"]);
+                            return;
+                        }
+                    }
                     if (!this.model.operation.isSingle){
                         for (let i=0;i<this.model.operation.items.length;i++){
                             if (this._verifyOperationItem(i))return;
@@ -1915,7 +1922,8 @@
                 //开启满减
                 onDiscount(type){
                   if (!type)return;
-                  if (this.model.operation.discount_count.length===0) this.model.operation.discount_count = [""];
+                  if (this.model.operation.discount_count.length===1) this.model.operation.discount_count = ["0"];
+                  if (this.model.operation.discount_count.length===0) this.model.operation.discount_count = ["0"];
                 },
                 //删除阶梯满减阈值
                 delDiscount(index){

+ 4 - 1
resources/views/customer/project/part/_auditComparison.blade.php

@@ -61,10 +61,13 @@
                                     <td>@{{ s.unit_id }}</td>
                                     <td>@{{ s.time_unit_id }}</td>
                                     <td>
-                                        <div class="float-left small">
+                                        <div class="float-left small" v-if="s.amount_interval">
                                             <span v-for="(a,i) in s.amount_interval" v-if="i!=s.amount_interval.length-1">@{{ a }}-@{{ s.amount_interval[i+1] }}(@{{ s.price[i] }}元)<br></span>
                                             <span>@{{ s.amount_interval[s.amount_interval.length-1] }}&nbsp;+(@{{ s.price[s.amount_interval.length-1] }}元)<br></span>
                                         </div>
+                                        <div v-else>
+                                            @{{ s.price[0] }}元
+                                        </div>
                                     </td>
                                     <td>@{{ s.tax_rate_id }}</td>
                                 </tr>

+ 6 - 6
resources/views/customer/project/part/_operation.blade.php

@@ -45,7 +45,7 @@
     <div class="col-8 row" v-if="model.operation.isDiscount">
         <div class="col-1 cursor-pointer"><span class="fa fa-plus" @click="addDiscount(model.operation.discount_count)"></span></div>
         <label class="col-2" for="discount">满减阈值</label>
-        <input id="discount" v-model="model.operation.discount_count[0]" :class="errors['discount_count_0'] ? 'is-invalid' : ''"
+        <input disabled id="discount" :value="model.operation.discount_count[0]" :class="errors['discount_count_0'] ? 'is-invalid' : ''"
                class="form-control form-control-sm col-6" step="1" type="number" min="0">
     </div>
 </div>
@@ -76,7 +76,7 @@
         <label class="col-3" for="total_discount_price">满减价</label>
         <input id="total_discount_price" v-model="model.operation.total_discount_price[i]"
                class="form-control form-control-sm col-5" :class="errors.total_discount_price ? 'is-invalid' : ''" step="0.01" type="number" min="0">
-        <label class="col-4 text-secondary">@{{ value ? (model.operation.discount_count[i+1] ? value+'-'+(model.operation.discount_count[i+1]-1)+' 单' : value+'+ 单') : '' }}</label>
+        <label class="col-4 text-secondary">@{{ value ? (model.operation.discount_count[i+1] ? value+'-'+(model.operation.discount_count[i+1]-1)+' '+(model.operation.operation_type=='入库' ? '件' : '')+'/月' : value+'+ '+(model.operation.operation_type=='入库' ? '件' : '')+'/月') : '' }}</label>
     </div>
 </div>
 <div class="row mt-3">
@@ -125,7 +125,7 @@
             <div class="row mt-2" v-if="item.strategy!='起步' || (item.strategy=='起步' && item.type==0)">
                 <label class="col-3">单位</label>
                 <label class="col-3 mb-0"><select v-model="item.unit_id" class="form-control" :class="errors['items.'+i+'.unit_id'] ? 'is-invalid' : ''">
-                    <option v-for="unit in pool.units" :value="unit.id" v-if="unit.name=='件' || unit.name=='箱'">@{{ unit.name }}</option>
+                    <option v-for="unit in pool.units" :value="unit.id" v-if="unit.name=='件' || unit.name=='箱' || unit.name=='m³' || unit.name=='T' || unit.name=='kg'">@{{ unit.name }}</option>
                 </select></label>
                 <label class="col-2 text-right" v-if="poolMapping.units[item.unit_id]=='箱'">零头价</label>
                 <label class="col-3 mb-0" v-if="poolMapping.units[item.unit_id]=='箱'">
@@ -133,9 +133,9 @@
                 </label>
             </div>
             <div class="row mt-0" v-if="errors['items.'+i+'.unit_id']">
-                <div class="offset-3"><small class="text-danger font-weight-bold ml-3">单位为必选项</small></div>
+                <div class="offset-3"><small class="text-danger font-weight-bold ml-3">@{{ errors['items.'+i+'.unit_id'][0] }}</small></div>
             </div>
-            <div class="row mt-2" v-if="item.strategy!='起步' || (item.strategy=='起步' && item.type==0)">
+            <div class="row mt-2" v-if="item.strategy!='起步' || (item.strategy=='起步' && item.type==0)" v-show="!model.operation.isDiscount">
                 <label class="col-3"><span v-if="item.strategy=='起步'">起步费</span><span v-else>单价</span></label>
                 <label class="col-6 mb-0 input-group">
                     <input type="number" min="0" step="0.01" class="form-control" v-model="item.unit_price"
@@ -157,7 +157,7 @@
                           <span class="input-group-text">元</span>
                     </span>
                 </label>
-                <label class="col-4">@{{ value ? (model.operation.discount_count[i+1] ? value+'-'+(model.operation.discount_count[i+1]-1)+' 单' : value+'+ 单') : '' }}</label>
+                <label class="col-4">@{{ value ? (model.operation.discount_count[i+1] ? value+'-'+(model.operation.discount_count[i+1]-1)+' '+(model.operation.operation_type=='入库' ? '件' : '')+'/月' : value+'+ '+(model.operation.operation_type=='入库' ? '件' : '')+'/月') : '' }}</label>
             </div>
             <div class="row mt-2" v-if="item.strategy=='特征'">
                 <label class="col-3">特征:</label>

+ 4 - 4
resources/views/package/measureMonitor/index.blade.php

@@ -125,7 +125,7 @@
                         if (package.id ===_this.package.id){
                             _this.package.measuringMachine_status=package.measuring_machine.status;
                             _this.measuringMachinesIndex[package.measuring_machine.name].status=package.measuring_machine.status;
-                            tempTip.setDuration(4000);
+                            tempTip.setDuration(2000);
                             tempTip.showSuccess('暂无新数据');
                             return;
                         }
@@ -135,7 +135,7 @@
                             audio.src=_this.logisticAudioURL[logistic_name];
                             setTimeout(()=>{
                                 audio.play();
-                            },10);
+                            },0);
                         }else {
                             window.tempTip.setDuration(3000);
                             window.axios.post("{{url('package/weigh/measureMonitor/speech')}}",{logistic:logistic_name})
@@ -145,7 +145,7 @@
                                         audio.src=response.data;
                                         setTimeout(()=>{
                                             audio.play();
-                                        },10);
+                                        },0);
                                     }else window.tempTip.show('没有对应快递名称!');
                                 }).catch(function (err) {
                                     window.tempTip.show('语音合成发生错误:'+err);
@@ -165,7 +165,7 @@
                                 let orderPackage=response.data;
                                 _this.updateData(_this,orderPackage);
                                 _this.package.measuringMachine=orderPackage.measuring_machine ? orderPackage.measuring_machine.name : '';                            }else {
-                                tempTip.setDuration(4000);
+                                tempTip.setDuration(3000);
                                 tempTip.showSuccess('暂无数据!');
                             }
                         })

+ 7 - 1
resources/views/package/weigh/index.blade.php

@@ -86,6 +86,11 @@
                     {name:'{{$owner->id}}',value:'{{$owner->name}}'},
                     @endforeach
                 ],
+                measuringMachines:[
+                    @foreach($measuringMachines as $measuringMachine)
+                    {name:'{{$measuringMachine->id}}',value:'{{$measuringMachine->name}}'},
+                    @endforeach
+                ],
                 form:'',
                 sum:{!! $packages->total() !!},
                 selectTr:0
@@ -102,7 +107,8 @@
                     {name:'is_weighed',type:'checkbox',tip:'是否已称重', data: [{name: 'true', value: '是否已称重'}]}
                 ],[
                     {name:'weighed_at_end',type:'time',tip:['选择显示称重日期的结束时间','选择显示称重日期的结束时间']},
-                    {name:'batch_number',type:'input',tip:'可支持多波次号,糊模查找需要在右边打上%符号',placeholder:'波次号'}
+                    {name:'batch_number',type:'input',tip:'可支持多波次号,糊模查找需要在右边打上%符号',placeholder:'波次号'},
+                    {name:'measuring_machine_id',type:'select',placeholder:'设备',data:this.measuringMachines},
                 ]];
 
                 _this.form = new query({