Просмотр исходного кода

客户管理第一次完整上传,计费逻辑完善在service中

Zhouzhendong 5 лет назад
Родитель
Сommit
f78cbde21f
35 измененных файлов с 582 добавлено и 124 удалено
  1. 1 1
      app/Commodity.php
  2. 11 7
      app/Console/Commands/CreateOwnerAreaReport.php
  3. 21 3
      app/Console/Commands/CreateOwnerBillReport.php
  4. 14 9
      app/Console/Commands/CreateOwnerReport.php
  5. 7 3
      app/Http/Controllers/CommodityController.php
  6. 22 24
      app/Http/Controllers/PriceModelController.php
  7. 14 2
      app/Http/Controllers/TestController.php
  8. 18 13
      app/Http/Controllers/api/thirdPart/haiq/StorageController.php
  9. 5 0
      app/OwnerAreaReport.php
  10. 3 11
      app/OwnerPriceExpress.php
  11. 1 0
      app/OwnerReport.php
  12. 22 0
      app/Services/CommodityService.php
  13. 41 1
      app/Services/FeatureService.php
  14. 30 2
      app/Services/OwnerPriceDirectLogisticService.php
  15. 34 3
      app/Services/OwnerPriceExpressService.php
  16. 54 2
      app/Services/OwnerPriceLogisticService.php
  17. 158 0
      app/Services/OwnerPriceOperationService.php
  18. 27 2
      app/Services/OwnerStoragePriceModelService.php
  19. 0 5
      app/User.php
  20. 1 0
      database/migrations/2020_10_20_143953_create_owner_reports_table.php
  21. 1 0
      database/migrations/2020_10_26_142753_create_owner_area_reports_table.php
  22. 1 0
      database/migrations/2020_10_27_103741_create_owner_bill_reports_table.php
  23. 2 2
      database/migrations/2020_10_28_162458_create_owner_price_expresses_table.php
  24. 32 0
      database/migrations/2020_11_17_170541_add_column_pack_commodities_table.php
  25. 1 0
      resources/views/customer/finance/billConfirmation.blade.php
  26. 1 0
      resources/views/customer/finance/instantBill.blade.php
  27. 1 0
      resources/views/customer/project/area.blade.php
  28. 29 3
      resources/views/customer/project/index.blade.php
  29. 2 1
      resources/views/customer/project/report.blade.php
  30. 1 1
      resources/views/maintenance/priceModel/directLogistic/create.blade.php
  31. 12 21
      resources/views/maintenance/priceModel/express/create.blade.php
  32. 6 6
      resources/views/maintenance/priceModel/express/index.blade.php
  33. 7 1
      resources/views/maintenance/priceModel/storage/create.blade.php
  34. 1 0
      resources/views/maintenance/priceModel/storage/menu.blade.php
  35. 1 1
      tests/Unit/WaybillPriceModelTest.php

+ 1 - 1
app/Commodity.php

@@ -9,7 +9,7 @@ use App\Traits\ModelTimeFormat;
 class Commodity extends Model
 {
     use ModelTimeFormat;
-    protected $fillable=['name','sku','owner_id','created_at','length','width','height','volumn',"type"];
+    protected $fillable=['name','sku','owner_id','created_at','length','width','height','volumn',"type","pack"];
     protected $appends=['barcode'];
 //    protected $appends=['barcode','owner_name','owner_code'];
 

+ 11 - 7
app/Console/Commands/CreateOwnerAreaReport.php

@@ -42,18 +42,22 @@ class CreateOwnerAreaReport extends Command
     {
         /** @var OwnerService $ownerService */
         $ownerService = app('OwnerService');
-        $chunks = ($ownerService->get([],null,false,true))->chunk(50);
+        $chunks = ($ownerService->get([],["ownerStoragePriceModels"],false,true))->chunk(50);
         $month = date('Y-m-d');
         foreach ($chunks as $owners){
             $date = date('Y-m-d H:i:s');
             $createOwnerAreaReport = [];
             foreach ($owners as $owner){
-                $createOwnerAreaReport[] = [
-                    "owner_id"              => $owner->id,
-                    "counting_month"        => $month,
-                    "user_owner_group_id"   => $owner->user_owner_group_id,
-                    "created_at"            => $date,
-                ];
+                if (!$owner->ownerStoragePriceModels)continue;
+                foreach ($owner->ownerStoragePriceModels as $model){
+                    $createOwnerAreaReport[] = [
+                        "owner_id"              => $owner->id,
+                        "counting_month"        => $month,
+                        "user_owner_group_id"   => $owner->user_owner_group_id,
+                        "created_at"            => $date,
+                        "owner_storage_price_model_id"  => $model->id,
+                    ];
+                }
             }
             DB::table("owner_area_reports")->insert($createOwnerAreaReport);
         }

+ 21 - 3
app/Console/Commands/CreateOwnerBillReport.php

@@ -2,7 +2,7 @@
 
 namespace App\Console\Commands;
 
-use App\Services\OwnerService;
+use App\OwnerAreaReport;
 use Illuminate\Console\Command;
 use Illuminate\Support\Facades\DB;
 
@@ -33,7 +33,7 @@ class CreateOwnerBillReport extends Command
     }
 
     /**
-     * 1号生成账单确认,确认金额由人工填写
+     * 1号生成账单确认,确认金额由人工填写 原始金额默认为:即时账单月记录金额+仓储计费与面积计算金额
      *
      * @return void
      */
@@ -46,15 +46,33 @@ class CreateOwnerBillReport extends Command
             $lastMonth = '12';
         }else $lastMonth = ($month-1) < 10 ? "0".($month-1) : ($month-1);
         $bills = DB::select(DB::raw("select owner_id,SUM(work_fee)+SUM(logistic_fee) as total from owner_fee_details where worked_at like ? GROUP BY owner_id"),[$year."-".$lastMonth."%"]);
+
+        $areas = OwnerAreaReport::query()->with("ownerStoragePriceModel")->where("counting_month","like",$year."-".$lastMonth."%")->get();
+        $map = [];
+        foreach($areas as $area){
+            if (isset($map[$area->owner_id."_".$area->counting_month])){
+                if (!$area->ownerStoragePriceModel)continue;
+                $map[$area->owner_id."_".$area->counting_month] += app('OwnerStoragePriceModelService')
+                    ->calculationAmount($area->ownerStoragePriceModel,$area->accounting_area,$area->owner_id,$area->counting_month);
+            }else{
+                if (!$area->ownerStoragePriceModel)continue;
+                $map[$area->owner_id."_".$area->counting_month] = app('OwnerStoragePriceModelService')
+                    ->calculationAmount($area->ownerStoragePriceModel,$area->accounting_area,$area->owner_id,$area->counting_month);
+            }
+        }
+
         $chunks = array_chunk($bills,50);
         foreach ($chunks as $bills){
             $date = date('Y-m-d H:i:s');
             $createOwnerBillReport = [];
             foreach ($bills as $bill){
+                $key = $bill->owner_id."_".$year."-".$lastMonth;
+                $total = $bill->total;
+                if (isset($map[$key]))$total += $map[$key];
                 $createOwnerBillReport[] = [
                     "owner_id"          => $bill->owner_id,       //项目ID
                     "counting_month"    => $year."-".$lastMonth."-01", //结算月
-                    "initial_fee"       => $bill->total,    //原始账单金额
+                    "initial_fee"       => $total,    //原始账单金额
                     "created_at"        => $date,
                 ];
             }

+ 14 - 9
app/Console/Commands/CreateOwnerReport.php

@@ -58,18 +58,20 @@ class CreateOwnerReport extends Command
         $lastDay = date("d",strtotime("$year-$lastMonth +1 month -1 day"));
 
         //获取上月面积与报表
-        $areas = OwnerAreaReport::query()->with(['owner'=>function($query){
-            $query->select('id',"code");
-        }])->where("counting_month","like",$year."-".$lastMonth."%")->get();
+        $areas = OwnerAreaReport::query()->select("id","owner_id","counting_month",DB::raw("SUM(accounting_area) total,YEAR(counting_month) y,MONTH(counting_month) m"))
+            ->with(['owner'=>function($query){
+                $query->select('id',"code");
+            }])->where("counting_month","like",$year."-".$lastMonth."%")
+            ->groupBy("y","m","owner_id")->get();
         $reports = OwnerReport::query()->where("counting_month","like",$year."-".$lastMonth."%")->orWhere("counting_month","like",$historyYear."-".$historyMonth."%")->get();
         $bills = OwnerBillReport::query()->where("counting_month","like",$year."-".$lastMonth."%")->get();
 
         //日均单量统计
-        $query = DB::raw("select  count(*) c,CUSTOMERID from DOC_ORDER_HEADER where EDITTIME >= to_date('$year-$lastMonth-01 00:00:00','yyyy-mm-dd hh24:mi:ss') and EDITTIME <= to_date('$year-$lastMonth-$lastDay 23:59:59','yyyy-mm-dd hh24:mi:ss') group by CUSTOMERID");
+        $query = DB::raw("select  count(*) c,CUSTOMERID from DOC_ORDER_HEADER where EDITTIME >= to_date('".$year."-".$lastMonth."-01 00:00:00','yyyy-mm-dd hh24:mi:ss') and EDITTIME <= to_date('".$year."-".$lastMonth."-".$lastDay." 23:59:59','yyyy-mm-dd hh24:mi:ss') group by CUSTOMERID");
         $orderStatistic = DB::connection("oracle")->select($query);
         $map = [];
         foreach ($orderStatistic as $item){
-            $map[$item->customerid] = round($item->c / $lastDay,2);
+            $map[$item->customerid] = $item->c;
         }
 
         //已存在的报表记录
@@ -95,18 +97,21 @@ class CreateOwnerReport extends Command
         ]];
         $createReports = [];
         foreach ($areas as $area){
+            $total = $area->owner ? ($map[$area->owner->code] ?? 0) : 0;
             if ($reportMap[$area->owner_id."_".$area->counting_month] ?? false){
                 $updateReports[] = [
                     "id"=>$reportMap[$area->owner_id."_".$area->counting_month],
-                    "daily_average_order_amount"=>$area->owner ? ($map[$area->owner->code] ?? 0) : 0,
-                    "current_month_counting_area"=>$area->accounting_area ?? 0,
+                    "total" =>$total,
+                    "daily_average_order_amount"=>round($total / $lastDay,2),
+                    "current_month_counting_area"=>$area->total ?? 0,
                     "owner_bill_report_id" => $billMap[$area->owner_id."_".$area->counting_month] ?? 0,
                 ];
             }else $createReports[] = [
                 "owner_id"=>$area->owner_id,
                 "counting_month"=>$area->counting_month."-01",
-                "daily_average_order_amount"=>$area->owner ? ($map[$area->owner->code] ?? 0) : 0,
-                "current_month_counting_area"=>$area->accounting_area ?? 0,
+                "total" =>$total,
+                "daily_average_order_amount"=>round($total / $lastDay,2),
+                "current_month_counting_area"=>$area->total ?? 0,
                 "owner_bill_report_id" => $billMap[$area->owner_id."_".$area->counting_month] ?? 0,
                 "last_month_counting_area" => $historyReportMap[$area->owner_id."_".($historyYear."-".$historyMonth)] ?? 0,
             ];

+ 7 - 3
app/Http/Controllers/CommodityController.php

@@ -217,7 +217,7 @@ class CommodityController extends Controller
         $commodities = $commodityService->getOwnerCommodities(['owner_id' => $owner_id, 'sku'=>$skus]);
         $updateCommodities = [];
         $updateCommodities[] = [
-            'id', 'sku', 'name', 'length', 'width', 'height', 'volumn',
+            'id', 'sku', 'name', 'length', 'width', 'height', 'volumn',"pack"
         ];
         $barcodeMap = [];
         $commoditiesId = [];
@@ -228,7 +228,8 @@ class CommodityController extends Controller
             $trimSku = rtrim($wms->sku,"*");
             if (($commodity->sku != $trimSku) || ($commodity->length != $wms->skulength)
                 || ($commodity->width != $wms->skuwidth) || ($commodity->name != $wms->descr_c)
-                || ($commodity->height != $wms->skuhigh) || ($commodity->volumn != $wms->cube)){
+                || ($commodity->height != $wms->skuhigh) || ($commodity->volumn != $wms->cube)
+                || ($commodity->pack === null)){
                 $updateCommodities[] = [
                     'id'=>$commodity->id,
                     'sku'=>$trimSku,
@@ -236,7 +237,8 @@ class CommodityController extends Controller
                     'length' => $wms->skulength,
                     'width' => $wms->skuwidth,
                     'height' => $wms->skuhigh,
-                    'volumn' => $wms->cube
+                    'volumn' => $wms->cube,
+                    "pack"  => $wms->packid == 'STANDARD' ? 0 : explode("/",$wms->packid)[1],
                 ];
             }
             if ($wms->alternate_sku1){
@@ -298,6 +300,7 @@ class CommodityController extends Controller
                 'width' => $wms->skuwidth,
                 'height' => $wms->skuhigh,
                 'volumn' => $wms->cube,
+                "pack"  => $wms->packid == 'STANDARD' ? 0 : explode("/",$wms->packid)[1],
                 "created_at" => $today,
             ];
             $barcodeMap[$wms->sku] = [];
@@ -337,6 +340,7 @@ class CommodityController extends Controller
                             'width' => $goods['width'],
                             'height' => $goods['height'],
                             'volumn' => $goods['volumn'],
+                            "pack" => $goods["pack"],
                         ];
                         unset($createCommodities[$barcodeIndex[$code->code]]);
                         break;

+ 22 - 24
app/Http/Controllers/PriceModelController.php

@@ -24,10 +24,10 @@ use Maatwebsite\Excel\Facades\Excel;
 
 class PriceModelController extends Controller
 {
-    public function storageIndex()
+    public function storageIndex(Request $request)
     {
         if(!Gate::allows('计费模型-仓储')){ return redirect('denied');  }
-        $models = app('OwnerStoragePriceModelService')->paginate(["unit"]);
+        $models = app('OwnerStoragePriceModelService')->paginate($request->input("id"),["unit"]);
         return response()->view('maintenance.priceModel.storage.index',compact("models"));
     }
 
@@ -358,9 +358,9 @@ class PriceModelController extends Controller
         ]);
     }
 
-    public function expressIndex(){
+    public function expressIndex(Request $request){
         if(!Gate::allows('计费模型-快递-查询')){ return redirect('denied');  }
-        $models = app('OwnerPriceExpressService')->paginate();
+        $models = app('OwnerPriceExpressService')->paginate($request->input("id"));
         return response()->view('maintenance.priceModel.express.index',compact("models"));
     }
 
@@ -426,8 +426,7 @@ class PriceModelController extends Controller
         if(!Gate::allows('计费模型-快递-录入')){ return redirect('denied');  }
         $logistics = app("LogisticService")->getSelection();
         $owners = app("OwnerService")->getSelection();
-        $units = app("UnitService")->getSelection();
-        return response()->view('maintenance.priceModel.express.create',compact("logistics","owners","units"));
+        return response()->view('maintenance.priceModel.express.create',compact("logistics","owners"));
     }
 
     public function expressStore(Request $request)
@@ -439,8 +438,8 @@ class PriceModelController extends Controller
         /** @var OwnerPriceExpress $model */
         $model = app("OwnerPriceExpressService")->create([
             "name" => $request->input("name"),
-            "initial_weight_unit_id" => $request->input("initial_weight_unit_id"),
-            "additional_weight_unit_id" => $request->input("additional_weight_unit_id"),
+            "initial_weight" => $request->input("initial_weight"),
+            "additional_weight" => $request->input("additional_weight"),
         ]);
         $model->owners()->sync($request->input("owner_id"));
         $model->logistics()->sync($request->input("logistic_id"));
@@ -454,8 +453,7 @@ class PriceModelController extends Controller
         $model = app('OwnerPriceExpressService')->find($id)->append(["owner_id","logistic_id"]);
         $owners = app("OwnerService")->getSelection();
         $logistics = app('LogisticService')->getSelection();
-        $units = app('UnitService')->getSelection();
-        return response()->view('maintenance.priceModel.express.create',compact("owners","logistics","model","units"));
+        return response()->view('maintenance.priceModel.express.create',compact("owners","logistics","model"));
     }
 
     public function expressUpdate($id,Request $request)
@@ -467,8 +465,8 @@ class PriceModelController extends Controller
         /** @var OwnerPriceExpress $model */
         app("OwnerPriceExpressService")->update(["id"=>$id],[
             "name" => $request->input("name"),
-            "initial_weight_unit_id" => $request->input("initial_weight_unit_id"),
-            "additional_weight_unit_id" => $request->input("additional_weight_unit_id"),
+            "initial_weight" => $request->input("initial_weight"),
+            "additional_weight" => $request->input("additional_weight"),
         ]);
         $model = new OwnerPriceExpress();
         $model->id = $id;
@@ -481,8 +479,8 @@ class PriceModelController extends Controller
     {
         return Validator::make($params,[
             'name'=>['required',$id?"unique:owner_price_expresses,name,$id":'unique:owner_price_expresses,name'],
-            'initial_weight_unit_id'=>['required'],
-            'additional_weight_unit_id'=>['required'],
+            'initial_weight'=>['required','numeric','min:0'],
+            'additional_weight'=>['required','numeric','min:0'],
             'owner_id'=>[function ($attribute, $value, $fail)use($id) {
                 $owners = app("OwnerPriceExpressService")->getExistOwnerName($value,$id);
                 if ($owners)$fail("(".implode(',',$owners).') 已经绑定计费模型');
@@ -496,8 +494,8 @@ class PriceModelController extends Controller
             'unique' => ':attribute 已存在',
         ],[
             'name' =>"名称",
-            'initial_weight_unit_id'  =>"首重单位",
-            'additional_weight_unit_id'  =>"续重单位",
+            'initial_weight'  =>"首重",
+            'additional_weight'  =>"续重",
         ]);
     }
 
@@ -508,10 +506,10 @@ class PriceModelController extends Controller
         return ["success"=>true];
     }
 
-    public function logisticIndex()
+    public function logisticIndex(Request $request)
     {
         if(!Gate::allows('计费模型-物流-查询')){ return redirect('denied');  }
-        $models = app("OwnerPriceLogisticService")->paginate()->append(["unit_range_json","other_unit_range_json"]);
+        $models = app("OwnerPriceLogisticService")->paginate($request->input("id"))->append(["unit_range_json","other_unit_range_json"]);
         return response()->view('maintenance.priceModel.logistic.index',compact("models"));
     }
 
@@ -595,15 +593,15 @@ class PriceModelController extends Controller
     {
         if(!Gate::allows('计费模型-快递-查询')){ return ["success"=>false,"data"=>"无权操作"];  }
         $model = app("OwnerPriceExpressService")->find($id,[
-            "owners","logistics","initialWeightUnit","additionalWeightUnit","details"=>function($query){
+            "owners","logistics","details"=>function($query){
                 /** @var Builder $query */
                 $query->with("province");
             }]);
-        $row = ["客户","首重单位","续重单位","承运商"];
+        $row = ["客户","首重","续重","承运商"];
         $list = [[
             implode(",",array_column($model->owners->toArray(),"name")),
-            $model->initialWeightUnit ? $model->initialWeightUnit->name : '',
-            $model->additionalWeightUnit ? $model->additionalWeightUnit->name : '',
+            $model->initial_weight,
+            $model->additional_weight,
             implode(",",array_column($model->logistics->toArray(),"name")),
         ],[
             "价格名称","省","首重价格","续重价格",
@@ -767,9 +765,9 @@ class PriceModelController extends Controller
         ]);
     }
 
-    public function directLogisticIndex(){
+    public function directLogisticIndex(Request $request){
         if(!Gate::allows('计费模型-直发-查询')){ return redirect('denied');  }
-        $models = app("OwnerPriceDirectLogisticService")->paginate();
+        $models = app("OwnerPriceDirectLogisticService")->paginate($request->input("id"));
         return response()->view('maintenance.priceModel.directLogistic.index',compact("models"));
     }
 

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

@@ -31,6 +31,8 @@ use App\OrderPackageCommodities;
 use App\OrderTracking;
 use App\OrderTrackingOwner;
 use App\Owner;
+use App\OwnerAreaReport;
+use App\OwnerPriceOperation;
 use App\Package;
 use App\Process;
 use App\ProcessDaily;
@@ -45,6 +47,7 @@ use App\Services\CommodityService;
 use App\Services\common\BatchUpdateService;
 use App\Services\common\DataHandlerService;
 use App\Services\common\ExportService;
+use App\Services\FeatureService;
 use App\Services\InventoryCompareService;
 use App\Services\LogService;
 use App\Services\OracleActAllocationDetailService;
@@ -57,6 +60,7 @@ use App\Services\OrderPackageService;
 use App\Services\OrderService;
 use App\Services\OrderTrackingOwnerService;
 use App\Services\OrderTrackingService;
+use App\Services\OwnerPriceOperationService;
 use App\Services\WarehouseService;
 use App\StoreCheckingReceive;
 use App\StoreCheckingReceiveItem;
@@ -93,8 +97,16 @@ class TestController extends Controller
     }
 
     public function test4(){
-        dd(mb_strpos("续费(KM)","续1费"));
-
+        $a = new OwnerPriceOperationService();
+        $object = [
+            "a" => "衣服",
+            "b" => "TST454878"
+        ];
+        $mapping = [
+            "商品名称" => "a",
+            "订单类型" => "b"
+        ];
+        dd($a->matchRule(125,$object,$mapping,9,"8013108620706"));
     }
 
     public function test2(){

+ 18 - 13
app/Http/Controllers/api/thirdPart/haiq/StorageController.php

@@ -21,33 +21,38 @@ class StorageController
         $bin = [
             "taskCode" => "TEST-BS2010100001",//任务编号 全局唯一
             "binCode" => "TEST-BIN01",//料箱编码
-            //"toWorkStation" => "TEST-HQ01",//出库工作站
-            //"fromWorkStation" => "TEST-HQ01",//回库工作站
             "fromLocCode" => "HAIB1-02-01",//源库位编码
             "toLocCode" => "HAIB1-02-01",//目标库位编码 出库填多个,表示这些库位都可以支持
             "sequence" => -1,//出库顺序 -1表示没有顺序,只有移库出库时需要指定顺序,其他可为-1
             "stockInfo" => [$stockInfo],//商品信息
         ];
-        $this->request = [[
+        /*$this->request = [[
             "groupCode" => 1,//组号/波次号 一组任务需要一起完成,再开始下一组任务;没有组任务的限制默认传-1或空
             "taskMode" => 3,//任务模式 值 1 (输送线入库)值 2 (输送线出库)值 3(货架到缓存货架)值4(货架到流利货架)
             "priority" => 99,//优先级 1-2147483647 1最低
             "sequenceFlag" => -1,//是否需要有序 1:需要有序 0:不需要有序
             "bins" => [$bin],//可执行货箱任务
+        ]];*/
+        $this->request = [[
+            "taskMode"      => 8,
+            "bins"=>[[
+                "taskCode"  =>"TEST-BS2011160004",
+                "binCode"   => "TESTBINCODE-0",
+                "fromLocCode" => "BIN-IN1",
+                //"toLocCode" => "BIN-OUT1",
+            ]],
+            "groupCode"     => 4,
+            "priority"      => 20,
+            "sequenceFlag"  => -1,
         ]];
     }
 
     public function relocate(Request $request){
-        $req = [[
-            "groupCode"=> "test_code2",
-            "priority"=> 1,
-            "taskMode"=> 1,
-            "bins"=> [[
-                "binCode"=> "test_bin_1",
-                "fromLocCode"=> "HAIB1-02-01"
-            ]],
-        ]];
-        $response = Http::post(config('api.haiq.storage.relocate'),$req);
+        $response = Http::post(config('api.haiq.storage.relocate'),$this->request);return $response;
+        if (!$response->ok()){
+            app('LogService')->log(__METHOD__,"haiq-请求失败,路径异常","REQUEST:".json_encode($this->request)." | RESPONSE:".$response);
+            return ['success'=>false,"data"=>"接口异常"];
+        }
         if (($response["code"] ?? false) && $response["code"] != 200){
             app('LogService')->log(__METHOD__,"haiq-料箱出库失败","REQUEST:".json_encode($this->request)." | RESPONSE:".$response);
             return ['success'=>false,"data"=>$response["errMsg"]];

+ 5 - 0
app/OwnerAreaReport.php

@@ -9,6 +9,7 @@ class OwnerAreaReport extends Model
     protected $fillable = [
         "owner_id",             //货主ID
         "counting_month",       //结算月
+        "owner_storage_price_model_id", //仓储计费ID
         "user_owner_group_id",  //项目组ID
         "area_on_tray",         //货物整托
         "area_on_half_tray",    //货物半托
@@ -25,6 +26,10 @@ class OwnerAreaReport extends Model
     {   //项目组
         return $this->hasOne(UserOwnerGroup::class,"id","user_owner_group_id");
     }
+    public function ownerStoragePriceModel()
+    {   //仓储计费
+        return $this->hasOne(OwnerStoragePriceModel::class,"id","owner_storage_price_model_id");
+    }
 
     /* 结算月格式转换,仅截取至月
      * 引用:CreateOwnerReport

+ 3 - 11
app/OwnerPriceExpress.php

@@ -8,9 +8,9 @@ use Illuminate\Support\Facades\DB;
 class OwnerPriceExpress extends Model
 {
     protected $fillable = [
-        "name",                     //名称
-        "initial_weight_unit_id",   //首重单位
-        "additional_weight_unit_id",//续重单位
+        "name",             //名称
+        "initial_weight",   //首重
+        "additional_weight",//续重
     ];
 
     public function owners()
@@ -21,14 +21,6 @@ class OwnerPriceExpress extends Model
     {   //物流
         return $this->belongsToMany(Logistic::class,"owner_price_express_logistic","owner_price_express_id","logistic_id");
     }
-    public function initialWeightUnit()
-    {   //首重单位
-        return $this->hasOne(Unit::class,"id","initial_weight_unit_id");
-    }
-    public function additionalWeightUnit()
-    {   //续重单位
-        return $this->hasOne(Unit::class,"id","additional_weight_unit_id");
-    }
     public function details()
     {   //计费详情
         return $this->hasMany(OwnerPriceExpressProvince::class,"owner_price_express_id","id");

+ 1 - 0
app/OwnerReport.php

@@ -13,6 +13,7 @@ class OwnerReport extends Model
         "owner_id",                     //货主ID
         "counting_month",               //结算月
         "daily_average_order_amount",   //日均单量
+        "total",                        //总单量
         "current_month_counting_area",  //结算月盘点面积
         "last_month_counting_area",     //结算月上月盘点面积
         "owner_bill_report_id"          //账单ID

+ 22 - 0
app/Services/CommodityService.php

@@ -3,6 +3,7 @@
 namespace App\Services;
 
 use App\Commodity;
+use App\Http\Controllers\CommodityController;
 use App\OracleBasSKU;
 use App\Owner;
 use App\Services\common\BatchUpdateService;
@@ -214,4 +215,25 @@ Class CommodityService
         $params["type"] = "临时";
         return Commodity::query()->create($params);
     }
+
+    //获取箱规
+    public function getPack($owner_id, $sku)
+    {
+        $that = $this;
+        return app("CacheService")->getOrExecute("pack_{$owner_id}_{$sku}",function ()use($owner_id,$sku,$that){
+            $commodity = $that->first([
+                "owner_id" => $owner_id,
+                "sku" => $sku
+            ]);
+            if (!$commodity || $commodity->pack === null){
+                $owner = app("OwnerService")->find($owner_id);
+                $action = new CommodityController();
+                $action->syncOwnerCommodities($owner->id,$owner->code,$sku);
+            }
+            return $that->first([
+                "owner_id" => $owner_id,
+                "sku" => $sku
+            ])->pack;
+        });
+    }
 }

+ 41 - 1
app/Services/FeatureService.php

@@ -109,7 +109,6 @@ Class FeatureService
     public function formatFeature(array $features, $value, $columnMapping = null)
     {
         if (!$features)return $value;
-        $result = [];
         preg_match_all('/\d+|[\&\|\(\)]/',$value,$result);
         foreach ($result[0] as &$str){
             if (is_numeric($str) && isset($features[$str])){
@@ -146,4 +145,45 @@ Class FeatureService
         return implode("",$result[0]);
     }
 
+    public function matchFeature($value, $columnMapping, $matchObject) :bool
+    {
+        preg_match_all('/\d+/',$value,$ids);
+        if ($ids[0])$fs = Feature::query()->whereIn("id",$ids[0])->get();
+        else return false;
+        $features = [];
+        foreach ($fs as $f){
+            $features[$f->id] = $f;
+        }
+        preg_match_all('/\d+|[\&\|\(\)]/',$value,$result);
+        foreach ($result[0] as &$str) {
+            if (is_numeric($str) && isset($features[$str])) {
+                $column = $features[$str]["type"];
+                $logic = $features[$str]["logic"];
+                $describe = $features[$str]["describe"];
+                $value = isset($columnMapping[$column]) ? $matchObject[$columnMapping[$column]] : '';
+                switch ($logic) {
+                    case "包含":
+                        $str = mb_strpos($value,$describe) === false ? 'false' : 'true';
+                        break;
+                    case "不包含":
+                        $str = mb_strpos($value,$describe) === false ? 'true' : 'false';
+                        break;
+                    case "等于":
+                        $str = $value == $describe ? 'true' : 'false';
+                        break;
+                }
+                continue;
+            }
+            if ($str == "&") {
+                $str = '&&';
+                continue;
+            }
+            if ($str == "|") {
+                $str = '||';
+            }
+        }
+        $is = implode("",$result[0]);
+        return eval("return $is;");
+    }
+
 }

+ 30 - 2
app/Services/OwnerPriceDirectLogisticService.php

@@ -5,13 +5,16 @@ namespace App\Services;
 use App\Owner;
 use App\OwnerPriceDirectLogistic;
 use App\OwnerPriceDirectLogisticCar;
+use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Support\Facades\DB;
 
 Class OwnerPriceDirectLogisticService
 { 
-    public function paginate()
+    public function paginate($id = null)
     {
-        return OwnerPriceDirectLogistic::query()->with("owners")->paginate(50);
+        $query = OwnerPriceDirectLogistic::query()->with("owners");
+        if($id)$query->where("id",$id);
+        return $query->paginate(50);
     }
 
     public function create(array $params)
@@ -80,4 +83,29 @@ Class OwnerPriceDirectLogisticService
         }
         return $arr;
     }
+
+
+    /**
+     * CODE: -1:未找到计费模型
+     *
+     * @param double $amount
+     * @param integer $owner_id
+     * @param integer $car_id
+     * @return double
+     */
+    public function matching($amount, $owner_id, $car_id)
+    {
+        $model = OwnerPriceDirectLogistic::query()->with(["details"=>function($query)use($car_id){
+            /** @var Builder $query */
+            $query->where("car_type_id",$car_id);
+        }])->whereHas("owners",function ($query)use($owner_id){
+            /** @var Builder $query */
+            $query->where("id",$owner_id);
+        })->first();
+        if (!$model || !$model->details)return -1;
+        if ($amount < $model->base_km)$amount = $model->base_km;
+        $initialMoney = $model->base_km*$model->details[0]->base_fee;
+        $amount -= $model->base_km;
+        return ($amount*$model->details[0]->additional_fee)+$initialMoney;
+    }
 }

+ 34 - 3
app/Services/OwnerPriceExpressService.php

@@ -6,15 +6,18 @@ use App\Logistic;
 use App\Owner;
 use App\OwnerPriceExpress;
 use App\OwnerPriceExpressProvince;
+use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Support\Facades\DB;
 
 Class OwnerPriceExpressService
 { 
 
-    public function paginate()
+    public function paginate($id = null)
     {
-        return OwnerPriceExpress::query()->with(["initialWeightUnit","additionalWeightUnit","owners","logistics"])
-            ->orderByDesc("id")->paginate(50);
+        $query = OwnerPriceExpress::query()->with(["owners","logistics"])
+            ->orderByDesc("id");
+        if ($id)$query->where("id",$id);
+        return $query->paginate(50);
     }
 
     public function find($id, $withs = [])
@@ -96,4 +99,32 @@ Class OwnerPriceExpressService
         }
         return $query->update($values);
     }
+
+    /**
+     * CODE: -1:未找到计费模型
+     *
+     * @param double $weight
+     * @param integer $owner_id
+     * @param integer $logistic_id
+     * @param integer $province_id
+     * @return double
+     */
+    public function matching($weight, $owner_id, $logistic_id, $province_id)
+    {
+        $model = OwnerPriceExpress::query()->with(["details"=>function($query)use($province_id){
+            /** @var Builder $query */
+            $query->where("province_id",$province_id);
+        }])->whereHas("owners",function ($query)use($owner_id){
+            /** @var Builder $query */
+           $query->where("id",$owner_id);
+        })->whereHas("logistics",function ($query)use($logistic_id){
+            /** @var Builder $query */
+            $query->where("id",$logistic_id);
+        })->first();
+        if (!$model || !$model->details)return -1;
+        if ($weight < $model->initial_weight)$weight = $model->initial_weight;
+        $initialMoney = $model->initial_weight*$model->details[0]->initial_weight_price;
+        $weight -= $model->initial_weight;
+        return ($weight*$model->details[0]->additional_weight_price)+$initialMoney;
+    }
 }

+ 54 - 2
app/Services/OwnerPriceLogisticService.php

@@ -4,12 +4,15 @@ namespace App\Services;
 
 use App\OwnerPriceLogistic;
 use App\OwnerPriceLogisticDetail;
+use Illuminate\Database\Eloquent\Builder;
 
 Class OwnerPriceLogisticService
 { 
-    public function paginate()
+    public function paginate($id = null)
     {
-        return OwnerPriceLogistic::query()->with(["owners","logistics","unit","otherUnit"])->paginate(50);
+        $query = OwnerPriceLogistic::query()->with(["owners","logistics","unit","otherUnit"]);
+        if ($id)$query->where("id",$id);
+        return $query->paginate(50);
     }
 
     public function create(array $params)
@@ -84,4 +87,53 @@ Class OwnerPriceLogisticService
         }
         return true;
     }
+
+    /**
+     * CODE: -1:未找到计费模型
+     *
+     * @param double $amount
+     * @param integer $owner_id
+     * @param integer $logistic_id
+     * @param integer $unit_id
+     * @param integer $province_id
+     * @param integer $city_id
+     * @return double
+     */
+    public function matching($amount, $owner_id, $logistic_id, $unit_id, $province_id, $city_id)
+    {
+        $model = OwnerPriceLogistic::query()->with(["details"=>function($query)use($province_id,$city_id){
+            /** @var Builder $query */
+            $query->where("province_id",$province_id)->where("city_id",$city_id);
+        }])->where(function ($query)use($unit_id){
+            /** @var Builder $query */
+            $query->where("unit_id",$unit_id)->orWhere("other_unit_id",$unit_id);
+        })->whereHas("owners",function ($query)use($owner_id){
+            /** @var Builder $query */
+            $query->where("id",$owner_id);
+        })->whereHas("logistics",function ($query)use($logistic_id){
+            /** @var Builder $query */
+            $query->where("id",$logistic_id);
+        })->first();
+        if (!$model || !$model->details)return -1;
+        $fee = $model->pick_up_price + $model->fuel_price + $model->service_price; //服务费
+        foreach ($model->details as $detail){
+            if ($unit_id != $detail->unit_id)continue;
+            $arr = explode("-",$detail->range);
+            if (count($arr) < 2){
+                if ($amount >= $arr[0])return $this->calculation($amount,$detail,$fee);
+            }else{
+                if ($amount >= $arr[0] && $amount < $arr[1])return $this->calculation($amount,$detail,$fee);
+            }
+        }
+        return -1;
+    }
+
+    private function calculation($amount, $detail, $fee)
+    {
+        if ($amount < $detail->initial_amount)$amount = $detail->initial_amount; //小于起始数以起始数为准
+        $initialMoney = $detail->initial_amount*$detail->unit_price; //起始数计费
+        $amount -= $detail->initial_amount; //减起始数为续数
+        if ($initialMoney < $detail->initial_fee)$initialMoney = $detail->initial_fee; //小于起始计费以起始计费为准
+        return ($amount*$detail->unit_price)+$initialMoney+$detail->delivery_fee+$fee;
+    }
 }

+ 158 - 0
app/Services/OwnerPriceOperationService.php

@@ -6,6 +6,7 @@ use App\OwnerInStorageRule;
 use App\OwnerOutStorageRule;
 use App\OwnerPriceOperation;
 use App\Services\common\QueryService;
+use App\Unit;
 use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Database\Eloquent\Model;
 use Illuminate\Support\Facades\DB;
@@ -92,4 +93,161 @@ Class OwnerPriceOperationService
     {
         return $model->update($params);
     }
+
+    /** 参数顺序: 数量 匹配对象 列映射 货主ID 单位ID 类型 SKU .
+     *  匹配顺序: 类型 货主 策略 单位 特征                    ..多对多匹配规则废弃,1对1,设单位必定为件,对应规则必然只有一项存在
+     *  单位匹配: 件,箱,单 由小到大,依次换算匹配           .
+     * @param int $amount
+     * @param array|object $matchObject  key-val
+     * @param array $columnMapping       key-val
+     * @param string $owner_id
+     * @param string $type
+     * @param string $sku
+     * @return double
+     * 错误代码: -1:非法数量 -2:无计费模型 -3:未知单位 -4:sku为空 -5:货主未找到 -6:无箱规 -7:未匹配到计费模型
+     */
+    public function matchRule($amount, $matchObject, $columnMapping, $owner_id, $sku = null, $type = '出库')
+    {
+        if ($amount <= 0 )return -1;
+
+        $unitModels = Unit::query()->whereIn("name",["件","箱","单"])->get();
+        $units = [];
+        foreach ($unitModels as $unitModel)$units[$unitModel->id] = $unitModel->name;
+
+        $withs = $type=='出库' ? ['ownerOutStorageRules'=>function($query){
+            /** @var Builder $query */
+            $query->orderByRaw("CASE strategy  WHEN '默认' THEN 1 WHEN '特征' THEN 2 WHEN '起步' THEN 3 END DESC,priority DESC");
+        }] : ['ownerInStorageRule'] ;
+        $rules = OwnerPriceOperation::query()->with($withs)
+            ->where("operation_type","出库")
+            ->whereHas("ownerPriceOperationOwners",function ($query)use($owner_id){
+                /** @var Builder $query */
+                $query->where("id",$owner_id);
+            })
+            ->orderByRaw("strategy desc,priority desc")->get(); //货主下的全部规则
+        if (!$rules)return -2;
+
+        if ($type == '入库'){
+            foreach ($rules as $rule){
+                if (!$rule->ownerInStorageRule)continue;
+                if ($rule->strategy == '特征'){
+                    $bool = app("FeatureService")->matchFeature($rule->feature,$columnMapping,$matchObject);
+                    if ($bool === true){
+                        if (!isset($units[$rule->ownerInStorageRule->unit_id])) return -3;
+                        if ($units[$rule->ownerInStorageRule->unit_id] == '箱'){ //为箱时同步商品寻找箱规
+                            $amount = $this->changeUnit($amount,$owner_id,$sku);
+                            if ($amount<0) return $amount;
+                        }
+                        if ($units[$rule->ownerInStorageRule->unit_id] == '单')$amount = 1; //为单时数量设为1;
+                        return ceil($amount/$rule->ownerInStorageRule->amount)*$rule->ownerInStorageRule->unit_price;
+                    };
+                }else{
+                    if (!isset($units[$rule->ownerInStorageRule->unit_id])) return -3;
+                    if ($units[$rule->ownerInStorageRule->unit_id] == '箱'){ //为箱时同步商品寻找箱规
+                        $amount = $this->changeUnit($amount,$owner_id,$sku);
+                        if ($amount<0) return $amount;
+                    }
+                    if ($units[$rule->ownerInStorageRule->unit_id] == '单')$amount = 1; //为单时数量设为1;
+                    return ceil($amount/$rule->ownerInStorageRule->amount)*$rule->ownerInStorageRule->unit_price;
+                };
+            }
+            return -7;
+        }
+        //出库
+        foreach ($rules as $rule){
+            if (!$rule->ownerOutStorageRules)continue;
+            if ($rule->strategy == '特征'){
+                $bool = app("FeatureService")->matchFeature($rule->feature,$columnMapping,$matchObject);//匹配特征
+                if ($bool === true){
+                    $money = $this->matchOutStorage($amount,$rule->ownerOutStorageRules,$columnMapping,$matchObject,$units,$owner_id,$sku);
+                    if ($money>0)return $money;
+                };
+            }else{
+                $money = $this->matchOutStorage($amount,$rule->ownerOutStorageRules,$columnMapping,$matchObject,$units,$owner_id,$sku);
+                if ($money>0)return $money;
+            };
+        }
+        return -7;
+    }
+    private function changeUnit($amount,$owner_id,$sku)
+    {
+        if (!$sku)return -4;
+        $pack = app("CommodityService")->getPack($owner_id,$sku);
+        if (!$pack)return -6;
+        return ceil($amount/$pack);
+    }
+    private function matchOutStorage($amount, $rules, $columnMapping, $matchObject, $units, $owner_id, $sku)
+    {
+        $money = 0;
+        foreach ($rules as $rule){
+            switch ($rule->strategy){
+                case "起步":
+                    $money = $rule->amount * $rule->unit_price;
+                    if ($units[$rule->unit_id] == '箱') { //为箱时同步商品寻找箱规
+                        if (!$sku)return -4;
+                        $pack = app("CommodityService")->getPack($owner_id,$sku);
+                        if (!$pack)return -6;
+                        $rule->amount *= $pack;
+                    }
+
+                    if ($amount < $rule->amount)$amount = $rule->amount;
+                    else $amount -= $rule->amount;
+                    break;
+                case "特征":
+                    if (app("FeatureService")->matchFeature($rule->feature,$columnMapping,$matchObject)){
+                        if (!isset($units[$rule->unit_id]) || $units[$rule->unit_id] == '单') return -3;
+                        if ($units[$rule->unit_id] == '箱'){ //为箱时同步商品寻找箱规
+                            $amount = $this->changeUnit($amount,$owner_id,$sku);
+                        }
+                        return (ceil($amount/$rule->amount)*$rule->unit_price)+$money;
+                    };
+                    break;
+                case "默认":
+                    if (!isset($units[$rule->unit_id]) || $units[$rule->unit_id] == '单') return -3;
+                    if ($units[$rule->unit_id] == '箱'){ //为箱时同步商品寻找箱规
+                        $amount = $this->changeUnit($amount,$owner_id,$sku);
+                    }
+                    return (ceil($amount/$rule->amount)*$rule->unit_price)+$money;
+                    break;
+            }
+        }
+        return -7;
+    }
+
+    private function matchInStorage($amount, $matchObject, $columnMapping, $owner_id, $unit_id, $rules, $sku, $units = null, $isMatch = false)
+    {
+        /*foreach ($rules as $rule){
+            if ($unit_id != $rule->ownerInStorageRule->unit_id)continue;
+            else{
+                if ($rule->strategy == '特征'){
+                    $bool = app("FeatureService")->matchFeature($rule->feature,$columnMapping,$matchObject);
+                    if ($bool === true){
+                        return ceil($amount/$rule->ownerInStorageRule->amount)*$rule->ownerInStorageRule->unit_price;
+                    };
+                }else{
+                    return ceil($amount/$rule->ownerInStorageRule->amount)*$rule->ownerInStorageRule->unit_price;
+                };
+            }
+        }
+        //单位换算
+        if (!$units){
+            $unitModels = Unit::query()->whereIn("name",["件","箱","单"])->get();
+            if (!$unitModels) return null;
+            foreach ($unitModels as $unitModel)$units[$unitModel->name] = $unitModel->id;
+        }
+        $name = array_search($unit_id,$units);
+        //递归匹配
+        switch ($name){
+            case "件"://布尔值校验是否匹配过件来确保箱只匹配一次件
+                return $this->matchInStorage($amount, $matchObject, $columnMapping, $owner_id, $units["箱"], $rules, $sku, $units, true);
+            case "箱"://箱存在向下向上转换
+                if ($isMatch){
+                    return $this->matchInStorage($amount, $matchObject, $columnMapping, $owner_id, $units["单"], $rules, $sku, $units);
+                }else{
+                    return $this->matchInStorage($amount, $matchObject, $columnMapping, $owner_id, $units["件"], $rules, $sku, $units);
+                }
+            case "单"://三次匹配皆无,返回null
+                return null;
+        }*/
+    }
 }

+ 27 - 2
app/Services/OwnerStoragePriceModelService.php

@@ -2,6 +2,7 @@
 
 namespace App\Services; 
 
+use App\OwnerReport;
 use App\OwnerStoragePriceModel;
 
 Class OwnerStoragePriceModelService
@@ -11,9 +12,11 @@ Class OwnerStoragePriceModelService
         return OwnerStoragePriceModel::query()->select($columns)->with($withs)->get();
     }
 
-    public function paginate(array $withs = [])
+    public function paginate($id = null,array $withs = [])
     {
-        return OwnerStoragePriceModel::query()->orderByDesc('id')->with($withs)->paginate($params["paginate"] ?? 50);
+        $query = OwnerStoragePriceModel::query()->orderByDesc('id')->with($withs);
+        if ($id)$query->where("id",$id);
+        return $query->paginate($params["paginate"] ?? 50);
     }
 
     public function create(array $params)
@@ -38,4 +41,26 @@ Class OwnerStoragePriceModelService
     {
         return OwnerStoragePriceModel::destroy($id);
     }
+
+    //暂时不考虑单位换算问题:后期可能存在多单位换算,此处仅视为单位为 m²
+    public function calculationAmount(OwnerStoragePriceModel $model, int $area, $owner_id = null, $month = null) :int
+    {
+        if (!$model || !$area) return 0;
+        if ((int)$area < $model->minimum_area) $area = (int)$model->minimum_area;
+        $money = $area*$model->price;
+        switch ($model->discount_type){
+            case "按单减免":
+                if ($owner_id && $month){
+                    $report = OwnerReport::query()->select("id","total")
+                        ->where("owner_id",$owner_id)
+                        ->where("counting_month","like",$month."%")->first();
+                    $money -= $report ? ($report->total)*($model->discount_value) : 0;
+                }
+                break;
+            case "固定减免":
+                $money -= (int)$model->discount_value;
+                break;
+        }
+        return $money;
+    }
 }

+ 0 - 5
app/User.php

@@ -2,16 +2,11 @@
 
 namespace App;
 
-use App\Services\UserService;
-use Carbon\Carbon;
 use Illuminate\Notifications\Notifiable;
-use Illuminate\Contracts\Auth\MustVerifyEmail;
 use Illuminate\Foundation\Auth\User as Authenticatable;
 use Illuminate\Support\Collection;
-use Illuminate\Support\Facades\Auth;
 use Illuminate\Support\Facades\Cache;
 use Illuminate\Support\Facades\Gate;
-use Illuminate\Database\Eloquent\SoftDeletes;
 use App\Traits\ModelTimeFormat;
 
 class User extends Authenticatable

+ 1 - 0
database/migrations/2020_10_20_143953_create_owner_reports_table.php

@@ -18,6 +18,7 @@ class CreateOwnerReportsTable extends Migration
             $table->bigInteger('owner_id')->index()->comment('外键货主');
             $table->date('counting_month')->nullable()->comment('结算月');
             $table->decimal('daily_average_order_amount',11,2)->nullable()->comment('日均单量');
+            $table->integer('total')->nullable()->comment("结算月总单量");
             $table->decimal('current_month_counting_area',11,2)->nullable()->comment('结算月盘点面积');
             $table->decimal('last_month_counting_area',11,2)->nullable()->comment('结算月上月盘点面积');
             $table->bigInteger('owner_bill_report_id')->nullable()->index()->comment('账单');

+ 1 - 0
database/migrations/2020_10_26_142753_create_owner_area_reports_table.php

@@ -23,6 +23,7 @@ class CreateOwnerAreaReportsTable extends Migration
             $table->decimal('area_on_flat',8,2)->nullable()->comment('平面区面积');
             $table->decimal('accounting_area',8,2)->nullable()->comment('结算面积');
             $table->enum('status',['编辑中','已完成'])->default('编辑中')->comment('状态');
+            $table->bigInteger("owner_storage_price_model_id")->index()->comment("关联仓储计费标准");
             $table->timestamps();
         });
     }

+ 1 - 0
database/migrations/2020_10_27_103741_create_owner_bill_reports_table.php

@@ -14,6 +14,7 @@ class CreateOwnerBillReportsTable extends Migration
     public function up()
     {
         Schema::create('owner_bill_reports', function (Blueprint $table) {
+            $table->engine = 'InnoDB';
             $table->id();
             $table->bigInteger('owner_id')->index()->comment('外键项目');
             $table->date('counting_month')->index()->comment('结算月');

+ 2 - 2
database/migrations/2020_10_28_162458_create_owner_price_expresses_table.php

@@ -16,8 +16,8 @@ class CreateOwnerPriceExpressesTable extends Migration
         Schema::create('owner_price_expresses', function (Blueprint $table) {
             $table->id();
             $table->string("name")->comment("价格名称");
-            $table->bigInteger("initial_weight_unit_id")->index()->comment("首重单位");
-            $table->bigInteger("additional_weight_unit_id")->index()->comment("续重单位");
+            $table->decimal("initial_weight")->comment("首重");
+            $table->decimal("additional_weight")->comment("续重");
             $table->timestamps();
         });
     }

+ 32 - 0
database/migrations/2020_11_17_170541_add_column_pack_commodities_table.php

@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class AddColumnPackCommoditiesTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('commodities', function (Blueprint $table) {
+            $table->integer("pack")->nullable()->comment("包装规格");
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('commodities', function (Blueprint $table) {
+            $table->dropColumn("pack");
+        });
+    }
+}

+ 1 - 0
resources/views/customer/finance/billConfirmation.blade.php

@@ -108,6 +108,7 @@
                 }
             },
             mounted(){
+                $('#container').removeClass('d-none');
                 let data=[
                     [
                         {name:'owner_group_id',type:'select',tip:'项目小组',placeholder: '项目小组',data:this.ownerGroups},

+ 1 - 0
resources/views/customer/finance/instantBill.blade.php

@@ -113,6 +113,7 @@
                 sum : Number("{{ $details->total() }}"),
             },
             mounted(){
+                $('#container').removeClass('d-none');
                 let data=[
                     [
                         {name:'shop_id',type:'select',tip:'店铺',placeholder: '店铺',data:this.shops},

+ 1 - 0
resources/views/customer/project/area.blade.php

@@ -134,6 +134,7 @@
                 }
             },
             mounted(){
+                $('#container').removeClass('d-none');
                 let data=[
                     [
                         {name:'owner_group_id',type:'select',tip:'项目小组',placeholder: '项目小组',data:this.ownerGroups},

+ 29 - 3
resources/views/customer/project/index.blade.php

@@ -8,7 +8,32 @@
             <div class="modal-dialog modal-dialog-scrollable modal-dialog-centered">
                 <div class="modal-content">
                     <div class="modal-body">
-                        <p>Modal body text goes here.</p>
+                        <div class="container-fluid" v-if="priceModel[thisClickIndex]">
+                            <div class="row" v-for="(model,i) in priceModel[thisClickIndex]['ownerStoragePriceModels']">
+                                <label class="text-dark font-weight-bold col-3"><span v-if="i==0">仓储:</span></label>
+                                <a target="_blank" :href="'{{url('maintenance/priceModel/storage')}}?id='+model.id" class="text-decoration-none">@{{ model.counting_type }}-@{{ model.using_type }}</a>
+                            </div>
+                            <hr class="m-1">
+                            <div class="row" v-for="(model,i) in priceModel[thisClickIndex]['ownerPriceOperations']">
+                                <label class="text-dark font-weight-bold col-3"><span v-if="i==0">作业:</span></label>
+                                <a target="_blank" :href="'{{url('maintenance/priceModel/operation')}}?id='+model.id" class="text-decoration-none">@{{ model.name }}</a>
+                            </div>
+                            <hr class="m-1">
+                            <div class="row" v-for="(model,i) in priceModel[thisClickIndex]['ownerPriceExpresses']">
+                                <label class="text-dark font-weight-bold col-3"><span v-if="i==0">快递:</span></label>
+                                <a target="_blank" :href="'{{url('maintenance/priceModel/express')}}?id='+model.id" class="text-decoration-none">@{{ model.name }}</a>
+                            </div>
+                            <hr class="m-1">
+                            <div class="row" v-for="(model,i) in priceModel[thisClickIndex]['ownerPriceLogistics']">
+                                <label class="text-dark font-weight-bold col-3"><span v-if="i==0">物流:</span></label>
+                                <a target="_blank" :href="'{{url('maintenance/priceModel/logistic')}}?id='+model.id" class="text-decoration-none">@{{ model.name }}</a>
+                            </div>
+                            <hr class="m-1">
+                            <div class="row" v-for="(model,i) in priceModel[thisClickIndex]['ownerPriceDirectLogistics']">
+                                <label class="text-dark font-weight-bold col-3"><span v-if="i==0">直发车:</span></label>
+                                <a target="_blank" :href="'{{url('maintenance/priceModel/directLogistic')}}?id='+model.id" class="text-decoration-none">@{{ model.name }}</a>
+                            </div>
+                        </div>
                     </div>
                     <div class="modal-footer">
                         <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
@@ -44,7 +69,7 @@
                         <a :href="'{{url('customer/project')}}/'+owner.id+'/edit'"><button class="btn btn0sm btn-outline-info">编辑</button></a>
                     </td>
                     <td>@{{ owner.customer_name }}</td>
-                    <td>@{{ owner.tax_rate }}</td>
+                    <td>@{{ owner.tax_rate ? owner.tax_rate+'%' : '' }}</td>
                     <td>@{{ owner.name }}</td>
                     <td>@{{ owner.code }}</td>
                     <td>@{{ owner.contract_number }}</td>
@@ -104,12 +129,13 @@
                 thisClickIndex : "",
             },
             mounted(){
+                $('#container').removeClass('d-none');
                 let column = [
                     {name:'cloneCheckAll',customization:true,type:'checkAll',column:'id',
                         dom:$('#cloneCheckAll').removeClass('d-none'), neglect: true},
                     {name:'operating',value: '操作', neglect: true},
                     {name:'customer',value: '客户'},
-                    {name:'tax_rate',value: '税率', neglect: true},
+                    {name:'tax_rate',value: '税率%', neglect: true},
                     {name:'name',value: '项目'},
                     {name:'code',value: '货主代码'},
                     {name:'contract_number',value: '合同号'},

+ 2 - 1
resources/views/customer/project/report.blade.php

@@ -4,7 +4,7 @@
 @endsection
 @section('content')
     @component('customer.project.menu')@endcomponent
-    <div class="container-fluid card" id="container">
+    <div class="container-fluid card d-none" id="container">
         <div id="form_div"></div>
         <div>
             <button type="button" class="btn btn-outline-dark btn-sm form-control-sm dropdown-toggle tooltipTarget" :class="[checkData.length>0?'btn-dark text-light':'']"
@@ -106,6 +106,7 @@
                 sum : Number("{{ $reports->total() }}"),
             },
             mounted(){
+                $('#container').removeClass('d-none');
                 let data=[
                     [
                         {name:'owner_group_id',type:'select',tip:'项目小组',placeholder: '项目小组',data:this.workgroup},

+ 1 - 1
resources/views/maintenance/priceModel/directLogistic/create.blade.php

@@ -25,7 +25,7 @@
             </div>
             <div class="row mt-3">
                 <label for="base_km" class="col-2"><b class="text-danger">* </b>起步公里数</label>
-                <input id="base_km" v-model="model.base_km" type="number" min="0" step="1.00" name="base_km" class="col-3 form-control" required
+                <input id="base_km" v-model="model.base_km" type="number" min="0" step="0.01" name="base_km" class="col-3 form-control" required
                        :class="errors.base_km ? 'is-invalid' : ''">
                 <span class="invalid-feedback mt-0 offset-2" role="alert" v-if="errors.base_km">
                     <strong>@{{ errors.base_km[0] }}</strong>

+ 12 - 21
resources/views/maintenance/priceModel/express/create.blade.php

@@ -24,23 +24,19 @@
                 </span>
             </div>
             <div class="row mt-3">
-                <label for="initial_weight_unit_id" class="col-2"><b class="text-danger">* </b>首重单位</label>
-                <select id="initial_weight_unit_id" name="initial_weight_unit_id" class="col-3 form-control" required
-                        v-model="model.initial_weight_unit_id" :class="errors.initial_weight_unit_id ? 'is-invalid' : ''">
-                    <option v-for="unit in units" :value="unit.id">@{{ unit.name }}</option>
-                </select>
-                <span class="invalid-feedback mt-0 offset-2" role="alert" v-if="errors.initial_weight_unit_id">
-                    <strong>@{{ errors.initial_weight_unit_id[0] }}</strong>
+                <label for="initial_weight" class="col-2"><b class="text-danger">* </b>首重单位</label>
+                <input type="number" min="0" step="0.01" id="initial_weight" name="initial_weight" class="col-3 form-control" required
+                        v-model="model.initial_weight" :class="errors.initial_weight ? 'is-invalid' : ''">
+                <span class="invalid-feedback mt-0 offset-2" role="alert" v-if="errors.initial_weight">
+                    <strong>@{{ errors.initial_weight[0] }}</strong>
                 </span>
             </div>
             <div class="row mt-3">
-                <label for="additional_weight_unit_id" class="col-2"><b class="text-danger">* </b>续重单位</label>
-                <select id="additional_weight_unit_id" name="additional_weight_unit_id" class="col-3 form-control" required
-                        v-model="model.additional_weight_unit_id" :class="errors.additional_weight_unit_id ? 'is-invalid' : ''">
-                    <option v-for="unit in units" :value="unit.id">@{{ unit.name }}</option>
-                </select>
-                <span class="invalid-feedback mt-0 offset-2" role="alert" v-if="errors.additional_weight_unit_id">
-                    <strong>@{{ errors.additional_weight_unit_id[0] }}</strong>
+                <label for="additional_weight" class="col-2"><b class="text-danger">* </b>续重单位</label>
+                <input type="number" min="0" step="0.01" id="additional_weight" name="additional_weight" class="col-3 form-control" required
+                       v-model="model.additional_weight" :class="errors.additional_weight ? 'is-invalid' : ''">
+                <span class="invalid-feedback mt-0 offset-2" role="alert" v-if="errors.additional_weight">
+                    <strong>@{{ errors.additional_weight[0] }}</strong>
                 </span>
             </div>
             <div class="row mt-3">
@@ -82,14 +78,9 @@
                     owner_id:{!! old('owner_id') ? json_encode(old('owner_id')) : (isset($model) ? json_encode($model->owner_id) : '[]') !!},
                     logistic_id:{!! old('logistic_id') ? json_encode(old('logistic_id')) : (isset($model) ? json_encode($model->logistic_id) : '[]') !!},
                     name:"{{old('name') ?? (isset($model) ? $model->name : '')}}",
-                    initial_weight_unit_id:"{{old('initial_weight_unit_id') ?? (isset($model) ? $model->initial_weight_unit_id : '')}}",
-                    additional_weight_unit_id:"{{old('additional_weight_unit_id') ?? (isset($model) ? $model->additional_weight_unit_id : '')}}",
+                    initial_weight:"{{old('initial_weight') ?? (isset($model) ? $model->initial_weight : '')}}",
+                    additional_weight:"{{old('additional_weight') ?? (isset($model) ? $model->additional_weight : '')}}",
                 },
-                units : [
-                    @foreach($units as $unit)
-                    {id:"{{$unit->id}}",name:"{{$unit->name}}"},
-                    @endforeach
-                ],
                 owners : [
                     @foreach($owners as $owner)
                     {id:"{{$owner->id}}",name:"{{$owner->name}}"},

+ 6 - 6
resources/views/maintenance/priceModel/express/index.blade.php

@@ -16,8 +16,8 @@
                 <th>序号</th>
                 <th>价格名称</th>
                 <th>操作</th>
-                <th>首重单位</th>
-                <th>续重单位</th>
+                <th>首重(KG)</th>
+                <th>续重(KG)</th>
                 <th>项目</th>
                 <th>承运商</th>
                 <th>录入时间</th>
@@ -29,8 +29,8 @@
                 <td>
                     <button type="button" class="btn btn-sm btn-primary" @click="showDetailModal(model)">维护详情</button>
                 </td>
-                <td>@{{ model.initialWeightUnitName }}</td>
-                <td>@{{ model.additionalWeightUnitName }}</td>
+                <td>@{{ model.initialWeight }}</td>
+                <td>@{{ model.additionalWeight }}</td>
                 <td>
                     <small v-for="owner in model.owners" class="font-weight-bold">@{{ owner.name }}<br></small>
                 </td>
@@ -57,8 +57,8 @@
                     {
                         id:"{{$model->id}}",
                         name:"{{$model->name}}",
-                        initialWeightUnitName:"{{$model->initialWeightUnit ? $model->initialWeightUnit->name : ''}}",
-                        additionalWeightUnitName:"{{$model->additionalWeightUnit ? $model->additionalWeightUnit->name : ''}}",
+                        initialWeight:"{{$model->initial_weight }}",
+                        additionalWeight:"{{$model->additional_weight }}",
                         createdAt:"{{$model->created_at}}",
                         owners:{!! $model->owners !!},
                         logistics:{!! $model->logistics !!},

+ 7 - 1
resources/views/maintenance/priceModel/storage/create.blade.php

@@ -4,7 +4,13 @@
 @section('content')
     <div id="nav2">
         @component('maintenance.menu')@endcomponent
-        @component('maintenance.priceModel.storage.menu')@endcomponent
+        @component('maintenance.priceModel.storage.menu')
+            @if(isset($model))
+            <li class="nav-item">
+                <a class="nav-link" href="{{URL::current()}}" :class="{active:isActive('edit',5)}">编辑</a>
+            </li>
+            @endif
+        @endcomponent
     </div>
     <div class="container-fluid mt-2 card" id="container">
         <form method="POST" :action="model.id ? '{{url('maintenance/priceModel/storage/update')}}' : '{{url('maintenance/priceModel/storage/store')}}'" class="card-body offset-3">

+ 1 - 0
resources/views/maintenance/priceModel/storage/menu.blade.php

@@ -10,6 +10,7 @@
             <li class="nav-item">
                 <a class="nav-link" href="{{url('maintenance/priceModel/storage/create')}}" :class="{active:isActive('create',4)}">录入</a>
             </li> @endcan
+            {{$slot}}
         </ul>
     </div>
 </div>

+ 1 - 1
tests/Unit/WaybillPriceModelTest.php

@@ -115,7 +115,7 @@ class WaybillPriceModelTest extends TestCase
         ]]);
         $responseMark->assertStatus(302)->assertRedirect('/');
         $waybillPriceModel=WaybillPriceModel::whereRaw('carrier_id = ? and province_id = ? and city_id=? and unit_id=? and range_min=? and range_max=? and unit_price=? and initial_weight=?',[
-            12,4,1,1,0.00,1000.00,1.00,10.00
+            12,4,1,1,0.00,1000.00,0.01,10.00
         ])->first();
         $result=$waybillPriceModel->delete();
         $this->assertTrue($result);