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

完善了计费模型,解决了页面布局不合理,增加了新表:异常报表,财务计费模型增加模糊查询,计费模型增加导入excel

Zhouzhendong 6 лет назад
Родитель
Сommit
d0bee96ff6
39 измененных файлов с 1390 добавлено и 208 удалено
  1. 1 1
      app/BillingModel.php
  2. 34 0
      app/Events/WaybillPriceModelEvent.php
  3. 95 13
      app/Http/Controllers/BillingModelsController.php
  4. 1 1
      app/Http/Controllers/CarTypesController.php
  5. 3 3
      app/Http/Controllers/CarriersController.php
  6. 1 1
      app/Http/Controllers/CitiesController.php
  7. 1 1
      app/Http/Controllers/ProvincesController.php
  8. 1 1
      app/Http/Controllers/UnitsController.php
  9. 33 0
      app/Http/Controllers/WaybillFinancialExceptedController.php
  10. 18 3
      app/Http/Controllers/WaybillFinancialSnapshotsController.php
  11. 65 28
      app/Http/Controllers/WaybillsController.php
  12. 166 0
      app/Imports/BillingModelsImport.php
  13. 112 0
      app/Listeners/WaybillPriceModelListener.php
  14. 3 0
      app/Providers/EventServiceProvider.php
  15. 1 1
      app/Waybill.php
  16. 16 0
      app/WaybillFinancialExcepted.php
  17. 2 1
      database/migrations/2019_11_22_094024_create_waybills_table.php
  18. 0 4
      database/migrations/2019_11_22_094128_create_waybill_financial_snapshots_table.php
  19. 6 0
      database/migrations/2019_11_22_094213_create_units_table.php
  20. 9 1
      database/migrations/2019_11_22_094241_create_provinces_table.php
  21. 306 1
      database/migrations/2019_11_22_094253_create_cities_table.php
  22. 6 5
      database/migrations/2019_11_22_094311_create_billing_models_table.php
  23. 1 0
      database/migrations/2019_12_03_174626_add_data_authorities_waybill.php
  24. 33 0
      database/migrations/2019_12_17_144623_create_waybill_financial_excepteds_table.php
  25. 31 8
      resources/views/waybill/billingModel/create.blade.php
  26. 31 8
      resources/views/waybill/billingModel/edit.blade.php
  27. 57 0
      resources/views/waybill/billingModel/import.blade.php
  28. 73 5
      resources/views/waybill/billingModel/index.blade.php
  29. 8 4
      resources/views/waybill/billingModel/menu.blade.php
  30. 16 6
      resources/views/waybill/create.blade.php
  31. 119 41
      resources/views/waybill/edit.blade.php
  32. 27 28
      resources/views/waybill/index.blade.php
  33. 10 3
      resources/views/waybill/menu.blade.php
  34. 24 11
      resources/views/waybill/waybillEdit.blade.php
  35. 51 7
      resources/views/waybill/waybillFinancialSnapshot/index.blade.php
  36. 9 2
      routes/web.php
  37. 9 9
      tests/Unit/CityTest.php
  38. 8 8
      tests/Unit/ProvinceTest.php
  39. 3 3
      tests/Unit/UnitTest.php

+ 1 - 1
app/BillingModel.php

@@ -8,7 +8,7 @@ class BillingModel extends Model
 {
 
     protected $fillable=[
-        'carrier_id','province_id','city_id','unit_id','range_min','range_max','unit_price','initial_weight'
+        'carrier_id','province_id','city_id','unit_id','range_min','range_max','unit_price','base_fee','initial_weight'
     ];
 
     protected $appends=[

+ 34 - 0
app/Events/WaybillPriceModelEvent.php

@@ -0,0 +1,34 @@
+<?php
+
+namespace App\Events;
+
+use App\BillingModel;
+use Illuminate\Queue\SerializesModels;
+use Illuminate\Broadcasting\PrivateChannel;
+
+class WaybillPriceModelEvent
+{
+    use  SerializesModels;
+
+    public $waybillPriceModel;
+
+    /**
+     * Create a new event instance.
+     *
+     * @return void
+     */
+    public function __construct(BillingModel $waybillPriceModel)
+    {
+        $this->waybillPriceModel=$waybillPriceModel;
+    }
+
+    /**
+     * Get the channels the event should broadcast on.
+     *
+     * @return \Illuminate\Broadcasting\Channel|array
+     */
+    public function broadcastOn()
+    {
+        return new PrivateChannel('channel-name');
+    }
+}

+ 95 - 13
app/Http/Controllers/BillingModelsController.php

@@ -4,20 +4,41 @@ namespace App\Http\Controllers;
 
 use App\BillingModel;
 use App\Carrier;
+use App\City;
+use App\Events\WaybillPriceModelEvent;
+use App\Imports\BillingModelsImport;
 use App\Province;
 use App\Unit;
+use function GuzzleHttp\Psr7\str;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Auth;
+use Illuminate\Support\Facades\Cache;
 use Illuminate\Support\Facades\Gate;
 use Illuminate\Support\Facades\Validator;
+use Maatwebsite\Excel\Facades\Excel;
 
 class BillingModelsController extends Controller
 {
-    public function index()
+    public function index(Request $request)
     {
         if(!Gate::allows('计费模型-查询')){ return redirect(url('/'));  }
-        $billingModels= BillingModel::paginate(50);
-        return view('waybill.billingModel.index',['billingModels'=>$billingModels]);
+        $carriers=Carrier::get();
+        $provinces=Province::get();
+        $data=$request->input();
+        if ($data){
+            $billingModels= BillingModel::orderBy('id', 'DESC');
+            if ($request->input('carrier_id')){
+                $billingModels=$billingModels->where('carrier_id',$request->input('carrier_id'));
+            }
+            if ($request->input('province_id')){
+                $billingModels=$billingModels->where('province_id',$request->input('province_id'));
+            }
+            $billingModels=$billingModels->paginate($request->input('paginate')?$request->input('paginate'):50);
+            return view('waybill.billingModel.index',['billingModels'=>$billingModels,'carriers'=>$carriers,'provinces'=>$provinces,'filterData'=>$data]);
+        }else{
+            $billingModels= BillingModel::paginate(50);
+            return view('waybill.billingModel.index',['billingModels'=>$billingModels,'carriers'=>$carriers,'provinces'=>$provinces,'filterData'=>$data]);
+        }
     }
 
 
@@ -25,20 +46,52 @@ class BillingModelsController extends Controller
     {
         if(!Gate::allows('计费模型-录入')){ return redirect(url('/'));  }
         $carriers=Carrier::get();
-        $provinces=Province::with('cities')->get();
+        $provinces=Province::get();
         $units=Unit::get();
         return view('waybill.billingModel.create',['carriers'=>$carriers,'provinces'=>$provinces,'units'=>$units]);
     }
 
+    public function getCities($province_id){
+        $cities=City::where('province_id',$province_id)->get();
+        return ['cities'=>$cities];
+    }
+
 
     public function store(Request $request)
     {
         if(!Gate::allows('计费模型-录入')){ return redirect(url('/'));  }
         $this->validateBillingModel($request)->validate();
         $billingModel=$request->input('BillingModel');
-        BillingModel::create($billingModel);
-        $this->log(__METHOD__,__FUNCTION__,json_encode($request->toArray()),Auth::user()['id']);
-        return redirect('billingModel')->with('successTip','新计费模型录入成功');
+        $billingModelIs=BillingModel::where('carrier_id',$billingModel['carrier_id'])->where('province_id',$billingModel['province_id'])->where('unit_id',$billingModel['unit_id']);
+        if (isset($billingModel['city_id'])){
+            $billingModelIs=$billingModelIs->where('city_id',$billingModel['city_id']);
+        }
+        if (isset($billingModel['range_min'])){
+            $billingModelIs=$billingModelIs->where('range_min',$billingModel['range_min']);
+        }
+        if (isset($billingModel['range_max'])){
+            $billingModelIs=$billingModelIs->where('range_max',$billingModel['range_max']);
+        }
+        $billingModelIs=$billingModelIs->first();
+        if (!$billingModelIs){
+            if (isset($billingModel['city_id'])){
+                $billingModelProvince=BillingModel::whereRaw('carrier_id = ? AND province_id = ? AND city_id IS NULL',[$billingModel['carrier_id'],$billingModel['province_id']])->first();
+                if ($billingModelProvince){
+                    return redirect()->back()->with('successTip','已存在省份模型,无需录入城市模型');
+                }
+            }else{
+                $billingModelProvince=BillingModel::whereRaw('carrier_id = ? AND province_id = ? AND city_id IS NOT NULL',[$billingModel['carrier_id'],$billingModel['province_id']])->first();
+                if ($billingModelProvince){
+                    return redirect()->back()->with('successTip','已存在城市模型,无法录入省份模型');
+                }
+            }
+            $waybillPriceModel=BillingModel::create($billingModel);
+            event(new WaybillPriceModelEvent($waybillPriceModel));
+            $this->log(__METHOD__,__FUNCTION__,json_encode($request->toArray()),Auth::user()['id']);
+            return redirect('billingModel')->with('successTip','新计费模型录入成功');
+        }else{
+            return redirect()->back()->with('successTip','该计费模型已存在');
+        }
     }
 
 
@@ -48,9 +101,10 @@ class BillingModelsController extends Controller
         if(!Gate::allows('计费模型-编辑')){ return redirect(url('/'));  }
         $billingModel=BillingModel::find($id);
         $carriers=Carrier::get();
-        $provinces=Province::with('cities')->get();
+        $provinces=Province::get();
+        $cities=City::where('province_id',$billingModel->province_id)->get();
         $units=Unit::get();
-        return view('waybill.billingModel.edit',['billingModel'=>$billingModel,'carriers'=>$carriers,'provinces'=>$provinces,'units'=>$units]);
+        return view('waybill.billingModel.edit',['billingModel'=>$billingModel,'carriers'=>$carriers,'provinces'=>$provinces,'units'=>$units,'cities'=>$cities]);
     }
 
 
@@ -61,6 +115,7 @@ class BillingModelsController extends Controller
         $billingModel=BillingModel::find($id);
         $billingModel->fill($request->input('BillingModel'));
         if ($billingModel->save()){
+            event(new WaybillPriceModelEvent($billingModel));
             $this->log(__METHOD__,__FUNCTION__,json_encode($request->toArray()),Auth::user()['id']);
             return redirect('billingModel')->with('successTip','新计费模型修改成功');
         }
@@ -75,17 +130,43 @@ class BillingModelsController extends Controller
         return ['success'=>$result];
     }
 
+
+    public function import(Request $request){
+        if(!Gate::allows('计费模型-录入')){ return redirect(url('/'));  }
+        $fileSuffix=$request->file('file')->getClientOriginalExtension();
+        if ($fileSuffix=='xlsx'||$fileSuffix=='xlsm'||$fileSuffix=='xltx'||$fileSuffix=='xltm'||$fileSuffix=='xls'||$fileSuffix=='xlt'||$fileSuffix=='ods'||$fileSuffix=='ots'||$fileSuffix=='slk'
+            ||$fileSuffix=='xml'||$fileSuffix=='gnumeric'||$fileSuffix=='htm'||$fileSuffix=='html'||$fileSuffix=='csv'||$fileSuffix=='tsv'){
+            $isOverride = $request->input('isOverride');
+            ini_set('max_execution_time',2100);
+            ini_set('memory_limit','512M');
+            $extension=$request->file()['file']->getClientOriginalExtension();
+            $extension[0] = strtoupper($extension[0]);
+            Excel::import(new BillingModelsImport($isOverride),$request->file()['file']->path(),null,$extension);
+            if (Cache::has('error')){
+                return '<h1 class="text-danger">导入Excel失败<br><p style="color: red">'.Cache::pull('error').'</p></h1>';
+            }else{
+                $exception=Cache::get('exception');
+                $a='';
+                for ($i=0;$i<count($exception);$i++){$a.=implode(',',$exception[$i]).'&#10'; };
+                return '<h1 class="text-danger">导入Excel成功<br><textarea style="width: 50%;height: 50%">'.$a.'</textarea></h1>';
+            }
+        }else{
+            return '<h1 class="text-danger">失败<br><p style="color: red">不支持该文件类型</p></h1>';
+        }
+    }
+
     protected function validateBillingModel(Request $request){
         $min = $request->input('BillingModel.range_min');
         $validator= Validator::make($request->input(),[
             'BillingModel.province_id'=>'required|integer',
             'BillingModel.carrier_id'=>'required|integer',
             'BillingModel.unit_id'=>'required|integer',
-            'BillingModel.city_id'=>'required|Integer',
-            'BillingModel.range_min'=> 'required|min:0|numeric',
-            'BillingModel.range_max'=> "required|min:{$min}|numeric",
+            'BillingModel.city_id'=>'nullable|Integer',
+            'BillingModel.range_min'=> 'nullable|min:0|numeric',
+            'BillingModel.range_max'=> "nullable|min:{$min}|numeric",
             'BillingModel.unit_price'=>'required|min:0|numeric',
-            'BillingModel.initial_weight'=>'required|min:0|numeric',
+            'BillingModel.base_fee'=>'nullable|min:0|numeric',
+            'BillingModel.initial_weight'=>'nullable|min:0|numeric',
         ],[
             'required'=>':attribute 为必填项',
             'min'     =>':attribute 数值过小',
@@ -100,6 +181,7 @@ class BillingModelsController extends Controller
             'BillingModel.range_min'=>'价格区间最小值',
             'BillingModel.range_max'=>'价格区间最大值',
             'BillingModel.unit_price'=>'单价',
+            'BillingModel.base_fee'=>'起步费',
             'BillingModel.initial_weight'=>'始重',
         ]);
         return $validator;

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

@@ -14,7 +14,7 @@ class CarTypesController extends Controller
     public function index()
     {
         if(!Gate::allows('车型-查询')){ return redirect(url('/'));  }
-        $carTypes=CarType::paginate(10);
+        $carTypes=CarType::paginate(50);
         return view('maintenance.carType.index',['carTypes'=>$carTypes]);
     }
 

+ 3 - 3
app/Http/Controllers/CarriersController.php

@@ -14,7 +14,7 @@ class CarriersController extends Controller
     public function index()
     {
         if(!Gate::allows('承运商-查询')){ return redirect(url('/'));  }
-            $carriers=Carrier::paginate(10);
+            $carriers=Carrier::paginate(50);
             return view('maintenance.carrier.index',['carriers'=>$carriers]);
     }
 
@@ -68,11 +68,11 @@ class CarriersController extends Controller
     protected function validatorCarrier(Request $request){
         $validator=Validator::make($request->input(),[
             'Carrier.name'=>'max:50|required',
-            'Carrier.mobile'=>'digits:11|required|integer',
+            'Carrier.mobile'=>['required','integer','regex:/^(0\d{6,10})|(1[3|4|5|7|8][0-9]\d{4,8})$/'],
         ],[
             'digits_between'=>':attribute 最小一位,最大五十位',
             'required'=>':attribute 不应为空',
-            'digits'=>':attribute 联系方式应为11位',
+            'regex'=>':attribute 输入有误',
             'integer'=>':attribute 应为数值',
         ],[
             'Carrier.name'=>'承运商名称',

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

@@ -14,7 +14,7 @@ class CitiesController extends Controller
     public function index()
     {
         if(!Gate::allows('城市-查询')){ return redirect(url('/'));  }
-        $cities=City::paginate(10);
+        $cities=City::paginate(50);
         return view('maintenance.city.index',['cities'=>$cities]);
     }
 

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

@@ -13,7 +13,7 @@ class ProvincesController extends Controller
     public function index()
     {
         if(!Gate::allows('省份-查询')){ return redirect(url('/'));  }
-        $provinces=Province::paginate(10);
+        $provinces=Province::paginate(50);
         return view('maintenance.province.index',['provinces'=>$provinces]);
     }
 

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

@@ -14,7 +14,7 @@ class UnitsController extends Controller
     public function index()
     {
         if(!Gate::allows('计量单位-查询')){ return redirect(url('/'));  }
-        $units=Unit::paginate(10);
+        $units=Unit::paginate(50);
         return view('maintenance.unit.index',['units'=>$units]);
     }
 

+ 33 - 0
app/Http/Controllers/WaybillFinancialExceptedController.php

@@ -0,0 +1,33 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use App\BillingModel;
+use App\Events\WaybillPriceModelEvent;
+use App\WaybillFinancialExcepted;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Event;
+use Illuminate\Support\Facades\Gate;
+
+class WaybillFinancialExceptedController extends Controller
+{
+    public function index(Request $request)
+    {
+        if(!Gate::allows('财务报表-查询')){ return redirect(url('/'));  }
+        $waybillFinancialSnapshots=WaybillFinancialExcepted::orderBy('id', 'DESC');
+        if ($request->input('type')=='直发'){
+            $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('json_content','like','%直发%');
+        }
+        if($request->input('type')=='专线'){
+            $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('json_content','like','%专线%');
+        }
+        if ($request->input('created_at_start')){
+            $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('created_at','>',$request->input('created_at_start'));
+        }
+        if ($request->input('created_at_end')){
+            $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('created_at','<',$request->input('created_at_end'));
+        }
+        $waybillFinancialSnapshots=$waybillFinancialSnapshots->paginate(50);
+        return view('waybill.waybillFinancialSnapshot.index',['waybillFinancialSnapshots'=>$waybillFinancialSnapshots,'filterData'=>$request->input(),'type'=>$request->input('type'),'excepted'=>true]);
+    }
+}

+ 18 - 3
app/Http/Controllers/WaybillFinancialSnapshotsController.php

@@ -4,16 +4,31 @@ namespace App\Http\Controllers;
 
 use App\Exports\WaybillExport;
 use App\WaybillFinancialSnapshot;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Auth;
 use Illuminate\Support\Facades\Gate;
 use Maatwebsite\Excel\Facades\Excel;
 
 class WaybillFinancialSnapshotsController extends Controller
 {
-    public function index()
+    public function index(Request $request)
     {
         if(!Gate::allows('财务报表-查询')){ return redirect(url('/'));  }
-        $waybillFinancialSnapshots=WaybillFinancialSnapshot::paginate(10);
-        return view('waybill.waybillFinancialSnapshot.index',['waybillFinancialSnapshots'=>$waybillFinancialSnapshots]);
+        $waybillFinancialSnapshots=WaybillFinancialSnapshot::orderBy('id', 'DESC');
+        if ($request->input('type')=='直发'){
+            $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('json_content','like','%直发%');
+        }
+        if($request->input('type')=='专线'){
+            $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('json_content','like','%专线%');
+        }
+        if ($request->input('created_at_start')){
+            $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('created_at','>',$request->input('created_at_start'));
+        }
+        if ($request->input('created_at_end')){
+            $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('created_at','<',$request->input('created_at_end'));
+        }
+        $waybillFinancialSnapshots=$waybillFinancialSnapshots->paginate(50);
+        return view('waybill.waybillFinancialSnapshot.index',['waybillFinancialSnapshots'=>$waybillFinancialSnapshots,'filterData'=>$request->input(),'type'=>$request->input('type')]);
     }
 
     public function export($id){

+ 65 - 28
app/Http/Controllers/WaybillsController.php

@@ -12,6 +12,7 @@ use App\Owner;
 use App\Unit;
 use App\Waybill;
 use App\WaybillCalculate;
+use App\WaybillFinancialExcepted;
 use App\WaybillFinancialSnapshot;
 use Carbon\Carbon;
 use Illuminate\Http\Request;
@@ -32,7 +33,7 @@ class WaybillsController extends Controller
             $today=Carbon::now()->subDays(15);
             $waybills=Waybill::with(['owner', 'auditLogs' => function ($query) {
                 return $query->with('user');
-            }]);
+            }])->orderBy('id','DESC');
             if ($request->input('waybill_number')){
                 $waybills =$waybills->where('waybill_number','like','%'.$request->input('waybill_number').'%')->where('created_at','>',$today->format('Y-m-d'));
             }
@@ -95,6 +96,7 @@ class WaybillsController extends Controller
             'recipient'=>$data['recipient'],
             'recipient_mobile'=>$data['recipient_mobile'],
             'charge'=>$data['charge'],
+            'collect_fee'=>$data['charge'],
             'ordering_remark'=>$data['ordering_remark']
         ]);
         $waybill->save();
@@ -129,30 +131,24 @@ class WaybillsController extends Controller
         $this->validatorWaybillDispatch($request)->validate();
         $data=$request->input();
         $waybill=Waybill::find($id);
-
-        if ($waybill->type=="专线"){
-            $carrier_weight=$request->input('carrier_weight');
-            $isBillingModel=BillingModel::whereRaw('carrier_id = ? and city_id = ? and unit_id = ? and range_min < ? and range_max >= ?',[
-                    $request->input('carrier_id'),$request->input('destination_city_id'),
-                    $request->input('warehouse_weight_unit_id'),$carrier_weight,
-                    $carrier_weight
-            ])->first();
-            if ($isBillingModel==null){
-                return redirect()->back()->with('notBillingModel','计费模型未定义')->withInput();
-            }
-        }
         $waybill->fill($data);
         if ($waybill->save()){
             if ($waybill->type=="直发"){
                 $total_receivable=($waybill->charge);
                 $total_expense=($waybill->fee)+($waybill->other_fee)-($waybill->collect_fee);
             }else if ($waybill->type=="专线"){
-                if ($carrier_weight<$isBillingModel->initial_weight){
-                    $fee=($isBillingModel->unit_price)*($isBillingModel->initial_weight);
-                }else{
-                    $fee=($isBillingModel->unit_price)*$carrier_weight;
+                $billingModel_id=$request->input('billingModel');
+                if ($billingModel_id){
+                    $carrier_weight=$request->input('carrier_weight');
+                    $billingModel=BillingModel::find($billingModel_id);
+                    if ($carrier_weight<$billingModel->initial_weight){
+                        $fee=($billingModel->unit_price)*($billingModel->initial_weight);
+                    }else{
+                        $fee=($billingModel->unit_price)*$carrier_weight;
+                    }
+                    $waybill->fee=$fee;
+                    $waybill->waybill_price_model_id=$billingModel_id;
                 }
-                $waybill->fee=$fee;
                 $waybill->save();
                 $total_receivable=($waybill->charge);
                 $total_expense=($waybill->pick_up_fee)+($waybill->other_fee)+($waybill->fee);
@@ -179,6 +175,32 @@ class WaybillsController extends Controller
         }
     }
 
+    public function isBillingModel(Request $request){
+        $carrier_id=$request->input('carrier_id');
+        $destination_city_id=$request->input('destination_city_id');
+        $carrier_weight=$request->input('carrier_weight');
+        $carrier_weight_unit_id=$request->input('carrier_weight_unit_id');
+        if(!$carrier_id)return['success'=>false];
+        if(!$destination_city_id)return['success'=>false];
+        if(!$carrier_weight)return['success'=>false];
+        if(!$carrier_weight_unit_id)return['success'=>false];
+        $billingModel=BillingModel::where('carrier_id',$carrier_id)->where('city_id',$destination_city_id)
+            ->where('range_min','<',$carrier_weight)->where('range_max','>=',$carrier_weight)
+            ->where('unit_id',$carrier_weight_unit_id)->first();
+        if($billingModel)return['success'=>$billingModel->id];
+        $billingModelRange=BillingModel::whereRaw('carrier_id = ? and city_id = ? and unit_id = ? and range_max is null',[$carrier_id,$destination_city_id,$carrier_weight_unit_id])->first();
+        if ($billingModelRange){ return ['success'=>$billingModelRange->id];}
+        $city=City::where('id',$destination_city_id)->select('province_id')->first();
+        $billingModelProvince=BillingModel::whereRaw('carrier_id = ? and province_id = ? and unit_id = ? and range_max >= ? and range_min < ? and city_id is null',
+            [$carrier_id,$city->province_id,$carrier_weight_unit_id,$carrier_weight,$carrier_weight])->first();
+        if ($billingModelProvince){return ['success'=>$billingModelProvince->id];}
+        $billingModelProvinceRange=BillingModel::whereRaw('carrier_id = ? and province_id = ? and unit_id = ? and range_max is null and city_id is null',
+            [$carrier_id,$city->province_id,$carrier_weight_unit_id])->first();
+        if ($billingModelProvinceRange){return ['success'=>$billingModelProvinceRange->id];}else{
+            return ['success'=>false];
+        }
+    }
+
     public function waybillUpdate(Request $request, $id){
         if(!Gate::allows('运单管理-编辑')){ return redirect(url('/'));  }
         $this->validatorWaybill($request)->validate();
@@ -209,7 +231,7 @@ class WaybillsController extends Controller
             $this->log(__METHOD__,__FUNCTION__,json_encode($waybill),Auth::user()['id']);
             return ['success'=>$result,'state'=>$waybill->state,'auditLog'=>$auditLog];
         }
-            return ['exception'=>'请勿重复审核!'];
+        return ['exception'=>'请勿重复审核!'];
     }
 
     public function waybillEdit($id){
@@ -246,11 +268,20 @@ class WaybillsController extends Controller
             $waybillCalculate->waybill->load(["owner","carrier","origination_city","destination_city","warehouse_weight_unit","carrier_weight_unit","carType","auditLogs"]);
             $waybillCalculate->waybill->auditLogs->load(["user"]);
             $waybillCalculateJson=json_encode($waybillCalculate,JSON_UNESCAPED_UNICODE);
-            WaybillFinancialSnapshot::create([
-                'waybill_id'=>$id,
-                'json_content'=>$waybillCalculateJson,
-            ]);
-            $waybill->state='完结';
+            if ($waybill->waybill_price_model_id){
+                WaybillFinancialSnapshot::create([
+                    'waybill_id'=>$id,
+                    'json_content'=>$waybillCalculateJson,
+                ]);
+                $waybill->state='完结';
+            }else{
+                WaybillFinancialExcepted::create([
+                    'waybill_id'=>$id,
+                    'json_content'=>$waybillCalculateJson,
+                ]);
+                $waybill->state='未定义计费模型';
+            }
+
             $result=$waybill->save();
             $this->log(__METHOD__,__FUNCTION__,$waybillCalculateJson,Auth::user()['id']);
             return ['success'=>$result,'state'=>$waybill->state,'auditLog'=>$auditLog];
@@ -347,13 +378,14 @@ class WaybillsController extends Controller
             'origination'=>'required|max:255',
             'destination'=>'required|max:255',
             'recipient'=>'required|max:50',
-            'recipient_mobile'=>'required|digits:11|integer',
+            'recipient_mobile'=>['required','integer','regex:/^(0\d{6,10})|(1[3|4|5|7|8][0-9]\d{4,8})$/'],
             'charge'=>'required|min:0|numeric',
+            'collect_fee'=>'nullable|min:0|numeric',
         ],[
             'required'=>':attribute 为必填项',
             'alpha_num'=>':attribute 应为字母或数字',
             'max'=>':attribute 字符过多',
-            'digits'=>':attribute 应为11位',
+            'regex'=>':attribute 输入有误',
             'integer'=>':attribute 应为整数',
             'min'=>':attribute 不得为负',
             'numeric'=>':attribute 应为数字',
@@ -364,6 +396,7 @@ class WaybillsController extends Controller
             'recipient'=>'收件人',
             'recipient_mobile'=>'收件人电话',
             'charge'=>'收费',
+            'collect_fee'=>'到付金额',
         ]);
         return $validator;
     }
@@ -373,7 +406,6 @@ class WaybillsController extends Controller
                 'carrier_bill'=>'required|alpha_num|max:50',
                 'fee'=>'required|min:0|numeric',
                 'other_fee'=>'nullable|min:0|numeric',
-                'collect_fee'=>'nullable|min:0|numeric',
             ],[
                 'required'=>':attribute 为必填项',
                 'alpha_num'=>':attribute 应为字母或数字',
@@ -384,7 +416,6 @@ class WaybillsController extends Controller
                 'carrier_bill'=>'承运商单号',
                 'fee'=>'运费',
                 'other_fee'=>'其他费用',
-                'collect_fee'=>'到付金额',
             ]);
             return $validator;
         }else if ($request->input('type')=='专线'){
@@ -394,6 +425,9 @@ class WaybillsController extends Controller
                 'carrier_weight'=>'required|min:0|numeric',
                 'pick_up_fee'=>'required|min:0|numeric',
                 'other_fee'=>'nullable|min:0|numeric',
+                'carrier_id'=>'required|integer',
+                'destination_city_id'=>'required|integer',
+                'carrier_weight_unit_id'=>'required|integer',
             ],[
                 'required'=>':attribute 为必填项',
                 'alpha_num'=>':attribute 应为字母或数字',
@@ -406,6 +440,9 @@ class WaybillsController extends Controller
                 'carrier_weight'=>'承运商计重(抛)',
                 'pick_up_fee'=>'提货费',
                 'other_fee'=>'其他费用',
+                'carrier_id'=>'承运商',
+                'destination_city_id'=>'目的市',
+                'carrier_weight_unit_id'=>'承运商计重单位',
             ]);
             return $validator;
         }else{

+ 166 - 0
app/Imports/BillingModelsImport.php

@@ -0,0 +1,166 @@
+<?php
+
+namespace App\Imports;
+
+use App\BillingModel;
+use App\Carrier;
+use App\City;
+use App\Events\WaybillPriceModelEvent;
+use App\Province;
+use App\Unit;
+use Illuminate\Support\Collection;
+use Illuminate\Support\Facades\Cache;
+use Maatwebsite\Excel\Concerns\ToCollection;
+use Maatwebsite\Excel\Concerns\WithHeadingRow;
+use Maatwebsite\Excel\Imports\HeadingRowFormatter;
+
+HeadingRowFormatter::default('none');
+class BillingModelsImport implements ToCollection,WithHeadingRow
+{
+    protected $isOverride;
+    public function __construct($isOverride)
+    {
+        if ($isOverride==1){
+            $this->isOverride=true;
+        }
+    }
+
+
+    /**
+     * @param Collection $collection
+     */
+    public function Collection(Collection $collection)
+    {
+        $endIs=false;
+        $cityIs=true;
+        if (isset($collection->toArray()[0]['承运商'])&&isset($collection->toArray()[0]['计数单位'])&&isset($collection->toArray()[0]['省份'])
+            &&isset($collection->toArray()[0]['单价'])&&isset($collection->toArray()[0]['市'])&&isset($collection->toArray()[0]['计数区间'])&&
+            isset($collection->toArray()[0]['起步费'])&&isset($collection->toArray()[0]['最低计数'])){
+                $endIs=true;
+        }else{
+                Cache::put('error','请检查您第一行标题是否存在承运商,计数单位,省份,单价,市,计数区间,起步费,最低计数',86400);
+                $endIs=false;
+        }
+        $exception=[];
+        $sum=2;
+        if ($endIs) {
+            foreach ($collection as $row) {
+                if ($row['承运商'] && $row['计数单位'] && $row['省份'] && $row['单价']) {
+                    $carrier = Carrier::where('name', $row['承运商'])->first();
+                    $unit = Unit::where('name', $row['计数单位'])->first();
+                    $province = Province::where('name', $row['省份'])->first();
+                    $city = City::where('name', $row['市'])->first();
+                    if ($carrier && $unit && $province) {
+                        $billing = BillingModel::where('carrier_id', $carrier->id);
+                        $billing = $billing->where('unit_id', $unit->id);
+                        $billing = $billing->where('province_id', $province->id);
+                        if ($row['市']) {
+                            $billing = $billing->where('city_id', $city->id);
+                        }
+                        if ($row['计数区间'] && !strstr($row['计数区间'], '∞')) {
+                            $str = explode('-', $row['计数区间']);
+                            if (count($str) == 2) {
+                                $billing = $billing->where('range_min', $str[0]);
+                                $billing = $billing->where('range_max', $str[1]);
+                            }
+                        }
+                        $billing = $billing->first();
+                        if (!$billing) {
+                            if (isset($billingModel['city_id'])){
+                                $billingModelProvince=BillingModel::whereRaw('carrier_id = ? AND province_id = ? AND city_id IS NULL',[$carrier->id,$province->id])->first();
+                                if ($billingModelProvince){
+                                    $cityIs=false;
+                                    array_push($exception, ['第' . $sum . '行数据已存在省份模型,无需录入城市模型']);
+                                }
+                            }else{
+                                $billingModelProvince=BillingModel::whereRaw('carrier_id = ? AND province_id = ? AND city_id IS NOT NULL',[$carrier->id,$province->id])->first();
+                                if ($billingModelProvince){
+                                    $cityIs=false;
+                                    array_push($exception, ['第' . $sum . '行数据已存在城市模型,无法录入省份模型']);
+                                }
+                            }
+                            if ($cityIs){
+                                $billingModel = ['carrier_id' => $carrier->id, 'unit_id' => $unit->id, 'province_id' => $province->id, 'unit_price' => $row['单价']];
+                                if ($row['计数区间']) {
+                                    $str = explode('-', $row['计数区间']);
+                                    if (preg_match('/^([0-9]\d*(\.\d*[1-9])?)|(0\.\d*[1-9])$/', $str[0]) > 0
+                                        && preg_match('/^([0-9]\d*(\.\d*[1-9])?)|(0\.\d*[1-9])$/', $str[1]) > 0
+                                        && $str[0] < $str[1] && count($str) == 2
+                                    ) {
+                                        $billingModel = array_merge($billingModel, ['range_min' => $str[0], 'range_max' => $str[1]]);
+                                    } else {
+                                        array_push($exception, ['第' . $sum . '行数据计数区间数据有误,应为:最小值-最大值']);
+                                    }
+                                }
+                                if ($row['市']) {
+                                    if ($city) {
+                                        $billingModel = array_merge($billingModel, ['city_id' => $city->id]);
+                                    }
+                                }
+                                if ($row['起步费'] && preg_match('/^([0-9]\d*(\.\d*[1-9])?)|(0\.\d*[1-9])$/', $row['起步费']) > 0) {
+                                    $billingModel = array_merge($billingModel, ['base_fee' => $row['起步费']]);
+                                } else {
+                                    $billingModel = array_merge($billingModel, ['base_fee' => 0]);
+                                    array_push($exception, ['第' . $sum . '行数据起步费为空,或为负,已默认设为0']);
+                                }
+                                if ($row['最低计数'] && preg_match('/^([0-9]\d*(\.\d*[1-9])?)|(0\.\d*[1-9])$/', $row['最低计数']) > 0) {
+                                    $billingModel = array_merge($billingModel, ['initial_weight' => $row['最低计数']]);
+                                } else {
+                                    $billingModel = array_merge($billingModel, ['initial_weight' => 0]);
+                                    array_push($exception, ['第' . $sum . '行数据最低计数为空,或为负,已默认设为0']);
+                                }
+                                $waybillPriceModel=BillingModel::create($billingModel);
+                                event(new WaybillPriceModelEvent($waybillPriceModel));
+                            }
+                        } else {
+                            if ($this->isOverride) {
+                                $billingModel = ['carrier_id' => $carrier->id, 'unit_id' => $unit->id, 'province_id' => $province->id, 'unit_price' => $row['单价']];
+                                if ($row['计数区间']&& !strstr($row['计数区间'], '∞')) {
+                                    $str = explode('-', $row['计数区间']);
+                                    if (preg_match('/^([0-9]\d*(\.\d*[1-9])?)|(0\.\d*[1-9])$/', $str[0]) > 0
+                                        && preg_match('/^([0-9]\d*(\.\d*[1-9])?)|(0\.\d*[1-9])$/', $str[1]) > 0
+                                        && $str[0] < $str[1] && count($str) == 2
+                                    ) {
+                                        $billingModel = array_merge($billingModel, ['range_min' => $str[0], 'range_max' => $str[1]]);
+                                    } else {
+                                        array_push($exception, ['第' . $sum . '行数据计数区间数据有误,应为:最小值-最大值']);
+                                    }
+                                }
+                                if ($row['市']) {
+                                    if ($city) {
+                                        $billingModel = array_merge($billingModel, ['city_id' => $city->id]);
+                                    }
+                                }
+                                if ($row['起步费'] && preg_match('/^([0-9]\d*(\.\d*[1-9])?)|(0\.\d*[1-9])$/', $row['起步费']) > 0) {
+                                    $billingModel = array_merge($billingModel, ['base_fee' => $row['起步费']]);
+                                } else {
+                                    $billingModel = array_merge($billingModel, ['base_fee' => 0]);
+                                    array_push($exception, ['第' . $sum . '行数据起步费为空,或为负,已默认设为0']);
+                                }
+                                if ($row['最低计数'] && preg_match('/^([0-9]\d*(\.\d*[1-9])?)|(0\.\d*[1-9])$/', $row['最低计数']) > 0) {
+                                    $billingModel = array_merge($billingModel, ['initial_weight' => $row['最低计数']]);
+                                } else {
+                                    $billingModel = array_merge($billingModel, ['initial_weight' => 0]);
+                                    array_push($exception, ['第' . $sum . '行数据最低计数为空,或为负,已默认设为0']);
+                                }
+                                $billing->fill($billingModel);
+                                if ($billing->save()) {
+                                    event(new WaybillPriceModelEvent($billing));
+                                    array_push($exception, ['第' . $sum . '行数据已覆盖原计费模型']);
+                                }
+                            } else {
+                                array_push($exception, ['第' . $sum . '行数据在计费模型中已存在']);
+                            }
+                        }
+                    } else {
+                        array_push($exception, ['第' . $sum . '行数据承运商,单位,省在基础数据中未定义']);
+                    }
+                } else {
+                    array_push($exception, ['第' . $sum . '行数据必填项为空']);
+                }
+                $sum++;
+            }
+            Cache::put('exception', $exception, 86400);
+        }
+    }
+}

+ 112 - 0
app/Listeners/WaybillPriceModelListener.php

@@ -0,0 +1,112 @@
+<?php
+
+namespace App\Listeners;
+
+use App\City;
+use App\Events\WaybillPriceModelEvent;
+use App\Waybill;
+use App\WaybillCalculate;
+use App\WaybillFinancialExcepted;
+use Illuminate\Queue\InteractsWithQueue;
+use Illuminate\Contracts\Queue\ShouldQueue;
+
+class WaybillPriceModelListener
+{
+    /**
+     * Create the event listener.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        //
+    }
+
+    /**
+     * Handle the event.
+     *
+     * @param  WaybillPriceModelEvent  $event
+     * @return void
+     */
+    public function handle(WaybillPriceModelEvent $event)
+    {
+        $waybillPriceModel=$event->waybillPriceModel;
+        $cityIds=[$waybillPriceModel->city_id];
+        //取省下所有市
+        if(!$waybillPriceModel->city_id){
+            $cities=City::select('id')->where('province_id',$waybillPriceModel['province_id'])->get();
+            $cityIds=$cities->map(function ($city){
+                return $city['id'];
+            });
+            //市不存在,价格区间不存在
+            if (!$waybillPriceModel->range_max){
+                $waybills=Waybill::where('carrier_id',$waybillPriceModel->carrier_id)->whereIn('destination_city_id',$cityIds)
+                    ->where('carrier_weight_unit_id',$waybillPriceModel->unit_id)
+                    ->where('type','专线')->where('state','!=','完结')->get();
+            }
+            //市不存在,价格区间存在
+            if ($waybillPriceModel->range_max){
+                $waybills=Waybill::where('carrier_id',$waybillPriceModel->carrier_id)->whereIn('destination_city_id',$cityIds)
+                    ->where('carrier_weight','<=',$waybillPriceModel->range_max)->where('carrier_weight','>',$waybillPriceModel->range_min)
+                    ->where('carrier_weight_unit_id',$waybillPriceModel->unit_id)
+                    ->where('type','专线')->where('state','!=','完结')->get();
+            }
+        }
+
+        //市存在,价格区间存在
+        if ($waybillPriceModel->city_id&&$waybillPriceModel->range_max){
+            $waybills=Waybill::where('carrier_id',$waybillPriceModel->carrier_id)->where('destination_city_id',$waybillPriceModel->city_id)
+                ->where('carrier_weight','<=',$waybillPriceModel->range_max)->where('carrier_weight','>',$waybillPriceModel->range_min)
+                ->where('carrier_weight_unit_id',$waybillPriceModel->unit_id)
+                ->where('type','专线')->where('state','!=','完结')->get();
+        }
+
+        //市存在,价格区间不存在
+        if ($waybillPriceModel->city_id&&!$waybillPriceModel->range_max){
+            $waybills=Waybill::where('carrier_id',$waybillPriceModel->carrier_id)->where('destination_city_id',$waybillPriceModel->city_id)
+                ->where('carrier_weight_unit_id',$waybillPriceModel->unit_id)
+                ->where('type','专线')->where('state','!=','完结')->get();
+        }
+        if ($waybills){
+            foreach ($waybills as $waybill){
+                //修改运单表运费
+                if ($waybill->carrier_weight<$waybillPriceModel->initial_weight){
+                    $fee=($waybillPriceModel->unit_price)*($waybillPriceModel->initial_weight);
+                }else{
+                    $fee=($waybillPriceModel->unit_price)*$waybill->carrier_weight;
+                }
+                $waybill->fee=$fee;
+                $waybill->save();
+                $total_receivable=($waybill->charge);
+                $total_expense=($waybill->pick_up_fee)+($waybill->other_fee)+($waybill->fee);
+
+                //修改财务表信息
+                $waybillCalculate=WaybillCalculate::where('waybill_id','=',$waybill->id)->first();
+                if ($waybillCalculate){
+                    $waybillCalculate->total_expense=$total_expense;
+                    $waybillCalculate->total_receivable=$total_receivable;
+                    $waybillCalculate->gross_margin=$total_receivable-$total_expense;
+                    $waybillCalculate->gross_profit_rate=(($total_receivable-$total_expense)/$total_receivable);
+                    $waybillCalculate->save();
+                }else{
+                    WaybillCalculate::create([
+                        'waybill_id'=>$waybill->id,
+                        'total_expense'=>$total_expense,
+                        'total_receivable'=>$total_receivable,
+                        'gross_margin'=>$total_receivable-$total_expense,
+                        'gross_profit_rate'=>(($total_receivable-$total_expense)/$total_receivable),
+                    ]);
+                };
+                $waybillFinancialExcepted=WaybillFinancialExcepted::where('waybill_id',$waybill->id)->first();
+                if ($waybillFinancialExcepted){
+                    $waybillFinancialExcepted->delete();
+                    $waybill->state='完结';
+                }
+                if ($waybill->waybill_price_model_id!=$waybillPriceModel->id){
+                    $waybill->waybill_price_model_id=$waybillPriceModel->id;
+                }
+                $waybill->save();
+            }
+        }
+    }
+}

+ 3 - 0
app/Providers/EventServiceProvider.php

@@ -21,6 +21,9 @@ class EventServiceProvider extends ServiceProvider
 //        \App\Events\CancelOrder::class => [
 //            \App\Listeners\BroadcastCancelOrder::class,
 //        ],
+        'App\Events\WaybillPriceModelEvent' => [
+            'App\Listeners\WaybillPriceModelListener',
+        ],
     ];
 
     /**

+ 1 - 1
app/Waybill.php

@@ -10,7 +10,7 @@ class Waybill extends Model
     protected $fillable=[
         'state','type','waybill_number','owner_id','wms_bill_number','origination','destination','recipient','recipient_mobile','charge','ordering_remark',
         'carrier_id','carrier_bill','origination_city_id','destination_city_id','warehouse_weight','warehouse_weight_unit_id','carrier_weight','carrier_weight_unit_id','carType_id',
-        'fee','pick_up_fee','other_fee','collect_fee','dispatch_remark'
+        'fee','pick_up_fee','other_fee','collect_fee','dispatch_remark','waybill_price_model_id'
     ];
     protected $appends=[
         'origination_city_name',

+ 16 - 0
app/WaybillFinancialExcepted.php

@@ -0,0 +1,16 @@
+<?php
+
+namespace App;
+
+use Illuminate\Database\Eloquent\Model;
+
+class WaybillFinancialExcepted extends Model
+{
+    protected $fillable=[
+        'waybill_id','json_content'
+    ];
+
+    public function waybill(){
+        return $this->belongsTo('App\Waybill','waybill_id','id');
+    }
+}

+ 2 - 1
database/migrations/2019_11_22_094024_create_waybills_table.php

@@ -26,6 +26,7 @@ class CreateWaybillsTable extends Migration
             $table->string('recipient',50)->comment('收件人');
             $table->string('recipient_mobile',50)->comment('收件人电话');
             $table->decimal('charge')->comment('收费(元)');
+            $table->decimal('collect_fee')->nullable()->comment('到付金额');
             $table->text('ordering_remark')->nullable()->comment('下单备注');
             $table->bigInteger('carrier_id')->nullable()->index()->comment('承运商');
             $table->string('carrier_bill')->nullable()->comment('承运商单号');
@@ -39,8 +40,8 @@ class CreateWaybillsTable extends Migration
             $table->decimal('fee')->nullable()->comment('运费');
             $table->decimal('pick_up_fee')->nullable()->comment('提货费');
             $table->decimal('other_fee')->nullable()->comment('其他费用');
-            $table->decimal('collect_fee')->nullable()->comment('到付金额');
             $table->text('dispatch_remark')->nullable()->comment('调度备注');
+            $table->bigInteger('waybill_price_model_id')->nullable()->index()->comment('外联计费模型');
 
             //外键
             /* $table->foreign('owner_id')->references('id')->on('owners');            //货主

+ 0 - 4
database/migrations/2019_11_22_094128_create_waybill_financial_snapshots_table.php

@@ -18,10 +18,6 @@ class CreateWaybillFinancialSnapshotsTable extends Migration
             $table->timestamps();
             $table->bigInteger('waybill_id')->unique()->index()->comment('运单ID');
             $table->longText('json_content')->comment('快照json');
-
-            //外键
-            $table->foreign('waybill_id')->references('id')->on('waybills');        //运单
-
         });
     }
 

+ 6 - 0
database/migrations/2019_11_22_094213_create_units_table.php

@@ -18,6 +18,12 @@ class CreateUnitsTable extends Migration
             $table->timestamps();
             $table->string('name',50)->unique()->comment('名称');
         });
+        $units=['kg','m³','T'];
+        for ($i=0;$i<count($units);$i++){
+            \App\Unit::create([
+                'name'=>$units[$i],
+            ]);
+        }
     }
 
     /**

+ 9 - 1
database/migrations/2019_11_22_094241_create_provinces_table.php

@@ -15,9 +15,17 @@ class CreateProvincesTable extends Migration
     {
         Schema::create('provinces', function (Blueprint $table) {
             $table->bigIncrements('id');
-            $table->timestamps();
             $table->string('name',50)->unique()->comment('名称');
+            $table->timestamps();
         });
+        $provinces=['陕西','甘肃','宁夏','青海','新疆','江苏','淅江','安徽','江西','福建','重庆','四川','云南',
+            '贵州','西藏','黑龙江','吉林','辽宁','山东','北京','天津','广西','广东','河北','山西','内蒙古',
+            '湖北','湖南','河南','海南','香港','澳门','台湾','上海'];
+        for ($i=0;$i<count($provinces);$i++){
+            \App\Province::create([
+                'name'=>$provinces[$i]
+            ]);
+        }
     }
 
     /**

+ 306 - 1
database/migrations/2019_11_22_094253_create_cities_table.php

@@ -15,13 +15,318 @@ class CreateCitiesTable extends Migration
     {
         Schema::create('cities', function (Blueprint $table) {
             $table->bigIncrements('id');
-            $table->timestamps();
             $table->bigInteger('province_id')->index()->comment('省份');
             $table->string('name',50)->unique()->comment('名称');
+            $table->timestamps();
 
             //外键
             $table->foreign('province_id')->references('id')->on('provinces');      //省份
         });
+        $Shanxi=['西安','宝鸡','咸阳','铜川','渭南','延安','榆林','汉中','安康','商洛'];
+        $Gansu=['兰州','嘉峪关','金昌','白银','天水','武威','张掖','平凉','酒泉','庆阳','定西','陇南','临夏','合作'];
+        $Ningxia=['银川','石嘴山','吴忠','固原','中卫'];
+        $Qinghai=['西宁','平安县','门源县','同仁县','共和县','玛訫县','玉树县','格尔木'];
+        $Xinjiang=['乌鲁木齐','克拉玛依','吐鲁番','哈密','昌吉州','博乐市','库尔勒','阿克苏市','阿图什市','喀什市','和田市','伊宁市','塔城市','阿尔泰市'];
+        $Jiangsu=['南京','常熟','无锡','徐州','常州','苏州','南通','连云港','淮安','盐城','扬州','镇江','泰州','宿迁'];
+        $ZheJiang=['杭州','宁波','温州','嘉兴','湖州','绍兴','金华','衢州','舟山','台州','丽水'];
+        $Anhui=['合肥','芜湖','蚌埠','淮南','马鞍山','淮北','铜陵','安庆','黄山','滁州','阜阳','宿州','巢湖','六安','亳州','池州','宣城'];
+        $Jiangxi=['南昌','景德镇','萍乡','九江','新余','鹰潭','赣州','吉安','宜春','抚州','上饶'];
+        $Fujian=['福州','厦门','莆田','三明','泉州','漳州','南平','龙岩','宁德'];
+        $Chongqing=['重庆','万州','涪陵','黔江','綦江','潼南','酉阳','巫溪'];
+        $Sichuan=['自贡','攀枝花','泸州','德阳','绵阳','广元','遂宁','内江','乐山','南充','眉山','宜宾','广安','达州','雅安','巴中','资阳','马尔康','西昌','成都'];
+        $Yunnan=['昆明','曲靖','玉溪','保山','昭通','丽江','普洱','临沧','楚雄','蒙自','文山','景洪','大理','芒市','泸水','香格里拉'];
+        $Guizhou=['贵阳','六盘水','遵义','安顺','铜仁','兴义','毕节','凯里','都匀'];
+        $Xizang=['拉萨','昌都','山南','日喀则','那曲','普兰','林芝'];
+        $Heilongjiang=['哈尔滨','齐齐哈尔','鸡西','鹤岗','双鸭山','大庆','伊春','佳木斯','七台河','牡丹江','黑河','绥化','呼玛县'];
+        $Jilin=['长春','吉林','四平','辽源','通化','白山','松原','白城','延吉'];
+        $Liaoning=['沈阳','大连','鞍山','抚顺','本溪','丹东','锦州','营口','阜新','辽阳','盘锦','铁岭','朝阳','葫芦岛'];
+        $Shandong=['青岛','济南','济宁','威海','临清','淄博','德州','莱芜','莱阳','潍坊','高密','文登','济阳','烟台','聊城','兖州','菏泽','东营','日照','临沂'];
+        $Beijing=['北京'];
+        $Tianjin=['天津'];
+        $Guangxi=['柳州','南宁','桂林','梧州','北海','防城港','钦州','贵港','玉林','百色','贺州','河池','来宾','崇左'];
+        $Guangdong=['广州','深圳','韶关','珠海','汕头','佛山','江门','湛江','茂名','肇庆','惠州','梅州','汕头/汕尾','阳江','清远','东莞','中山','潮州','揭阳'];
+        $Hebei=['石家庄','唐山','秦皇岛','邯郸','邢台','保定','张家口','承德','沧州','廊坊','衡水'];
+        $ShanXi=['太原','大同','阳泉','长治','晋城','朔州','晋中','运城','忻州','临汾','吕梁'];
+        $Neimenggu=['呼和浩特','包头','乌海','赤峰','通辽','鄂尔多斯','呼伦贝尔','巴彦淖尔','乌兰察布','乌兰浩特','锡林浩特','阿拉善'];
+        $Hubei=['武汉','黄石','十堰','宜昌','襄樊','鄂州','荆门','孝感','荆州','黄冈','咸宁','随州','恩施'];
+        $Hunan=['长沙','株洲','湘潭','衡阳','邵阳','岳阳','常德','张家界','益阳','郴州','永州','怀化','娄底','吉首'];
+        $Henan=['郑州','开封','洛阳','平顶山','安阳','鹤壁','新乡','焦作','濮阳','许昌','漯河','三门峡','商丘','周口','驻马店','南阳','信阳','济源'];
+        $Hainan=['海口','三亚'];
+        $provinces=['陕西','甘肃','宁夏','青海','新疆','江苏','淅江','安徽','江西','福建','重庆','四川','云南',
+            '贵州','西藏','黑龙江','吉林','辽宁','山东','北京','天津','广西','广东','河北','山西','内蒙古',
+            '湖北','湖南','河南','海南','香港','澳门','台湾','上海'];
+        for ($i=0;$i<count($provinces);$i++){
+            if ($provinces[$i]=="陕西"){
+                $province=\App\Province::where('name','=',$provinces[$i])->first();
+                for ($j=0;$j<count($Shanxi);$j++){
+                    \App\City::create([
+                        'province_id'=>$province->id,
+                        'name'=>$Shanxi[$j],
+                    ]);
+                }
+            }
+            if ($provinces[$i]=="甘肃"){
+                $province=\App\Province::where('name','=',$provinces[$i])->first();
+                for ($j=0;$j<count($Gansu);$j++){
+                    \App\City::create([
+                        'province_id'=>$province->id,
+                        'name'=>$Gansu[$j],
+                    ]);
+                }
+            }
+            if ($provinces[$i]=="宁夏"){
+                $province=\App\Province::where('name','=',$provinces[$i])->first();
+                for ($j=0;$j<count($Ningxia);$j++){
+                    \App\City::create([
+                        'province_id'=>$province->id,
+                        'name'=>$Ningxia[$j],
+                    ]);
+                }
+            }
+            if ($provinces[$i]=="青海"){
+                $province=\App\Province::where('name','=',$provinces[$i])->first();
+                for ($j=0;$j<count($Qinghai);$j++){
+                    \App\City::create([
+                        'province_id'=>$province->id,
+                        'name'=>$Qinghai[$j],
+                    ]);
+                }
+            }
+            if ($provinces[$i]=="新疆"){
+                $province=\App\Province::where('name','=',$provinces[$i])->first();
+                for ($j=0;$j<count($Xinjiang);$j++){
+                    \App\City::create([
+                        'province_id'=>$province->id,
+                        'name'=>$Xinjiang[$j],
+                    ]);
+                }
+            }
+            if ($provinces[$i]=="江苏"){
+                $province=\App\Province::where('name','=',$provinces[$i])->first();
+                for ($j=0;$j<count($Jiangsu);$j++){
+                    \App\City::create([
+                        'province_id'=>$province->id,
+                        'name'=>$Jiangsu[$j],
+                    ]);
+                }
+            }
+            if ($provinces[$i]=="淅江"){
+                $province=\App\Province::where('name','=',$provinces[$i])->first();
+                for ($j=0;$j<count($ZheJiang);$j++){
+                    \App\City::create([
+                        'province_id'=>$province->id,
+                        'name'=>$ZheJiang[$j],
+                    ]);
+                }
+            }
+            if ($provinces[$i]=="安徽"){
+                $province=\App\Province::where('name','=',$provinces[$i])->first();
+                for ($j=0;$j<count($Anhui);$j++){
+                    \App\City::create([
+                        'province_id'=>$province->id,
+                        'name'=>$Anhui[$j],
+                    ]);
+                }
+            }
+            if ($provinces[$i]=="江西"){
+                $province=\App\Province::where('name','=',$provinces[$i])->first();
+                for ($j=0;$j<count($Jiangxi);$j++){
+                    \App\City::create([
+                        'province_id'=>$province->id,
+                        'name'=>$Jiangxi[$j],
+                    ]);
+                }
+            }
+            if ($provinces[$i]=="福建"){
+                $province=\App\Province::where('name','=',$provinces[$i])->first();
+                for ($j=0;$j<count($Fujian);$j++){
+                    \App\City::create([
+                        'province_id'=>$province->id,
+                        'name'=>$Fujian[$j],
+                    ]);
+                }
+            }
+           if ($provinces[$i]=="重庆"){
+               $province=\App\Province::where('name','=',$provinces[$i])->first();
+                for ($j=0;$j<count($Chongqing);$j++){
+                    \App\City::create([
+                        'province_id'=>$province->id,
+                        'name'=>$Chongqing[$j],
+                    ]);
+                }
+            }
+            if ($provinces[$i]=="四川"){
+                $province=\App\Province::where('name','=',$provinces[$i])->first();
+                for ($j=0;$j<count($Sichuan);$j++){
+                    \App\City::create([
+                        'province_id'=>$province->id,
+                        'name'=>$Sichuan[$j],
+                    ]);
+                }
+            }
+            if ($provinces[$i]=="云南"){
+                $province=\App\Province::where('name','=',$provinces[$i])->first();
+                for ($j=0;$j<count($Yunnan);$j++){
+                    \App\City::create([
+                        'province_id'=>$province->id,
+                        'name'=>$Yunnan[$j],
+                    ]);
+                }
+            }
+            if ($provinces[$i]=="贵州"){
+                $province=\App\Province::where('name','=',$provinces[$i])->first();
+                for ($j=0;$j<count($Guizhou);$j++){
+                    \App\City::create([
+                        'province_id'=>$province->id,
+                        'name'=>$Guizhou[$j],
+                    ]);
+                }
+            }
+            if ($provinces[$i]=="西藏"){
+                $province=\App\Province::where('name','=',$provinces[$i])->first();
+                for ($j=0;$j<count($Xizang);$j++){
+                    \App\City::create([
+                        'province_id'=>$province->id,
+                        'name'=>$Xizang[$j],
+                    ]);
+                }
+            }
+            if ($provinces[$i]=="黑龙江"){
+                $province=\App\Province::where('name','=',$provinces[$i])->first();
+                for ($j=0;$j<count($Heilongjiang);$j++){
+                    \App\City::create([
+                        'province_id'=>$province->id,
+                        'name'=>$Heilongjiang[$j],
+                    ]);
+                }
+            }
+            if ($provinces[$i]=="吉林"){
+                $province=\App\Province::where('name','=',$provinces[$i])->first();
+                for ($j=0;$j<count($Jilin);$j++){
+                    \App\City::create([
+                        'province_id'=>$province->id,
+                        'name'=>$Jilin[$j],
+                    ]);
+                }
+            }
+            if ($provinces[$i]=="辽宁"){
+                $province=\App\Province::where('name','=',$provinces[$i])->first();
+                for ($j=0;$j<count($Liaoning);$j++){
+                    \App\City::create([
+                        'province_id'=>$province->id,
+                        'name'=>$Liaoning[$j],
+                    ]);
+                }
+            }
+            if ($provinces[$i]=="山东"){
+                $province=\App\Province::where('name','=',$provinces[$i])->first();
+                for ($j=0;$j<count($Shandong);$j++){
+                    \App\City::create([
+                        'province_id'=>$province->id,
+                        'name'=>$Shandong[$j],
+                    ]);
+                }
+            }
+            if ($provinces[$i]=="北京"){
+                $province=\App\Province::where('name','=',$provinces[$i])->first();
+                for ($j=0;$j<count($Beijing);$j++){
+                    \App\City::create([
+                        'province_id'=>$province->id,
+                        'name'=>$Beijing[$j],
+                    ]);
+                }
+            }
+            if ($provinces[$i]=="天津"){
+                $province=\App\Province::where('name','=',$provinces[$i])->first();
+                for ($j=0;$j<count($Tianjin);$j++){
+                    \App\City::create([
+                        'province_id'=>$province->id,
+                        'name'=>$Tianjin[$j],
+                    ]);
+                }
+            }
+            if ($provinces[$i]=="广西"){
+                $province=\App\Province::where('name','=',$provinces[$i])->first();
+                for ($j=0;$j<count($Guangxi);$j++){
+                    \App\City::create([
+                        'province_id'=>$province->id,
+                        'name'=>$Guangxi[$j],
+                    ]);
+                }
+            }
+            if ($provinces[$i]=="广东"){
+                $province=\App\Province::where('name','=',$provinces[$i])->first();
+                for ($j=0;$j<count($Guangdong);$j++){
+                    \App\City::create([
+                        'province_id'=>$province->id,
+                        'name'=>$Guangdong[$j],
+                    ]);
+                }
+            }
+            if ($provinces[$i]=="河北"){
+                $province=\App\Province::where('name','=',$provinces[$i])->first();
+                for ($j=0;$j<count($Hebei);$j++){
+                    \App\City::create([
+                        'province_id'=>$province->id,
+                        'name'=>$Hebei[$j],
+                    ]);
+                }
+            }
+            if ($provinces[$i]=="山西"){
+                $province=\App\Province::where('name','=',$provinces[$i])->first();
+                for ($j=0;$j<count($ShanXi);$j++){
+                    \App\City::create([
+                        'province_id'=>$province->id,
+                        'name'=>$ShanXi[$j],
+                    ]);
+                }
+            }
+            if ($provinces[$i]=="内蒙古"){
+                $province=\App\Province::where('name','=',$provinces[$i])->first();
+                for ($j=0;$j<count($Neimenggu);$j++){
+                    \App\City::create([
+                        'province_id'=>$province->id,
+                        'name'=>$Neimenggu[$j],
+                    ]);
+                }
+            }
+            if ($provinces[$i]=="湖北"){
+                $province=\App\Province::where('name','=',$provinces[$i])->first();
+                for ($j=0;$j<count($Hubei);$j++){
+                    \App\City::create([
+                        'province_id'=>$province->id,
+                        'name'=>$Hubei[$j],
+                    ]);
+                }
+            }
+            if ($provinces[$i]=="湖南"){
+                $province=\App\Province::where('name','=',$provinces[$i])->first();
+                for ($j=0;$j<count($Hunan);$j++){
+                    \App\City::create([
+                        'province_id'=>$province->id,
+                        'name'=>$Hunan[$j],
+                    ]);
+                }
+            }
+            if ($provinces[$i]=="河南"){
+                $province=\App\Province::where('name','=',$provinces[$i])->first();
+                for ($j=0;$j<count($Henan);$j++){
+                    \App\City::create([
+                        'province_id'=>$province->id,
+                        'name'=>$Henan[$j],
+                    ]);
+                }
+            }
+            if ($provinces[$i]=="海南"){
+                $province=\App\Province::where('name','=',$provinces[$i])->first();
+                for ($j=0;$j<count($Hainan);$j++){
+                    \App\City::create([
+                        'province_id'=>$province->id,
+                        'name'=>$Hainan[$j],
+                    ]);
+                }
+            }
+        }
     }
 
     /**

+ 6 - 5
database/migrations/2019_11_22_094311_create_billing_models_table.php

@@ -20,16 +20,17 @@ class CreateBillingModelsTable extends Migration
             $table->bigInteger('province_id')->index()->comment('省份');
             $table->bigInteger('city_id')->index()->comment('城市');
             $table->bigInteger('unit_id')->index()->comment('货物单位');
-            $table->decimal('range_min')->comment('区间最小值');
-            $table->decimal('range_max')->comment('区间最大值');
+            $table->decimal('range_min')->index()->nullable()->comment('区间最小值');
+            $table->decimal('range_max')->index()->nullable()->comment('区间最大值');
             $table->decimal('unit_price')->comment('单价(元)');
-            $table->decimal('initial_weight')->comment('始重');
+            $table->decimal('base_fee')->default(0)->comment('起步费');
+            $table->decimal('initial_weight')->default(0)->comment('始重');
 
-            //外键
+/*            //外键
             $table->foreign('carrier_id')->references('id')->on('carrier');    //承运商
             $table->foreign('province_id')->references('id')->on('provinces');  //省份
             $table->foreign('city_id')->references('id')->on('citys');         //城市
-            $table->foreign('unit_id')->references('id')->on('units');          //单位
+            $table->foreign('unit_id')->references('id')->on('units');          //单位*/
         });
     }
 

+ 1 - 0
database/migrations/2019_12_03_174626_add_data_authorities_waybill.php

@@ -49,6 +49,7 @@ class AddDataAuthoritiesWaybill extends Migration
         (new Authority(['name'=>'运单管理-删除','alias_name'=>'运单管理-删除']))->save();
         (new Authority(['name'=>'运单管理-运单审核','alias_name'=>'运单管理-运单审核']))->save();
         (new Authority(['name'=>'运单管理-调度审核','alias_name'=>'运单管理-调度审核']))->save();
+        (new Authority(['name'=>'运单管理-可见费用项','alias_name'=>'运单管理-调度审核']))->save();
         (new Authority(['name'=>'计量单位','alias_name'=>'计量单位']))->save();
         (new Authority(['name'=>'计量单位-查询','alias_name'=>'计量单位-查询']))->save();
         (new Authority(['name'=>'计量单位-录入','alias_name'=>'计量单位-录入']))->save();

+ 33 - 0
database/migrations/2019_12_17_144623_create_waybill_financial_excepteds_table.php

@@ -0,0 +1,33 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateWaybillFinancialExceptedsTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('waybill_financial_excepteds', function (Blueprint $table) {
+            $table->bigIncrements('id');
+            $table->bigInteger('waybill_id')->index()->comment('外联运单表');
+            $table->longText('json_content')->comment('记录');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('waybill_financial_excepteds');
+    }
+}

+ 31 - 8
resources/views/waybill/billingModel/create.blade.php

@@ -2,17 +2,21 @@
 
 @section('content')
     <div id="nav2">
+        @component('waybill.menu')@endcomponent
         @component('waybill.billingModel.menu')@endcomponent
     </div>
     <div class="container mt-3" id="list">
         <div class="card col-md-8 offset-md-2">
             <div class="card-body">
                 <form method="POST" action="{{ url('billingModel') }}">
+                    @if(Session::has('successTip'))
+                        <div class="alert alert-success h1">{{Session::get('successTip')}}</div>
+                    @endif
                     @csrf
                     <div class="form-group row">
                         <label for="carrier_id" class="col-2 col-form-label text-right">承运商</label>
                         <div class="col-8">
-                            <select name="BillingModel[carrier_id]" style="width: 30%;height: 30px" v-model="inputting.BillingModel.carrier_id">
+                            <select class="form-control" name="BillingModel[carrier_id]" style="width: 30%;height: 30px" v-model="inputting.BillingModel.carrier_id">
                                     <option v-for="carrier in carriers" :value="carrier.id">@{{carrier.name}}</option>
                             </select>
                             <div class="col-sm-5">
@@ -23,7 +27,7 @@
                     <div class="form-group row">
                         <label for="province_id"  class="col-2 col-form-label text-right">选择省份</label>
                         <div class="col-8" >
-                            <select name="BillingModel[province_id]" style="width: 30%;height: 30px" v-model="inputting.BillingModel.province_id" @change="changeProvince($event)">
+                            <select class="form-control" name="BillingModel[province_id]" style="width: 30%;height: 30px" v-model="inputting.BillingModel.province_id" @change="changeProvince($event)">
                                 <option v-for="province in provinces" :value="province.id">@{{province.name}}</option>
                             </select>
                             <div class="col-sm-5">
@@ -34,7 +38,7 @@
                     <div class="form-group row">
                         <label for="city_id"  class="col-2 col-form-label text-right">选择城市</label>
                         <div class="col-8" >
-                            <select name="BillingModel[city_id]" style="width: 30%;height: 30px" v-model="inputting.BillingModel.city_id">
+                            <select class="form-control" name="BillingModel[city_id]" style="width: 30%;height: 30px" v-model="inputting.BillingModel.city_id">
                                 <option v-for="city in cities" :value="city.id">@{{city.name}}</option>
                             </select>
 
@@ -46,7 +50,7 @@
                     <div class="form-group row">
                         <label for="unit_id"  class="col-2 col-form-label text-right">货物单位</label>
                         <div class="col-8" >
-                            <select name="BillingModel[unit_id]" style="width: 30%;height: 30px" v-model="inputting.BillingModel.unit_id">
+                            <select class="form-control" name="BillingModel[unit_id]" style="width: 30%;height: 30px" v-model="inputting.BillingModel.unit_id">
                                 <option v-for="unit in units" :value="unit.id">@{{unit.name}}</option>
                             </select>
                             <div class="col-sm-5">
@@ -86,7 +90,19 @@
                         </div>
                     </div>
                     <div class="form-group row">
-                        <label for="initial_weight" class="col-2 col-form-label text-right">始重</label>
+                        <label for="base_fee" class="col-2 col-form-label text-right">起步费(元)</label>
+                        <div class="col-8">
+                            <input type="text" class="form-control @error('BillingModel.base_fee') is-invalid @enderror"
+                                   name="BillingModel[base_fee]" autocomplete="off" value="{{ old('BillingModel')['base_fee'] }}" >
+                            @error('BillingModel.base_fee')
+                            <span class="invalid-feedback" role="alert">
+                                        <strong>{{ $message }}</strong>
+                                    </span>
+                            @enderror
+                        </div>
+                    </div>
+                    <div class="form-group row">
+                        <label for="initial_weight" class="col-2 col-form-label text-right">最低计数</label>
                         <div class="col-8">
                             <input type="text" class="form-control @error('BillingModel.initial_weight') is-invalid @enderror"
                                    name="BillingModel[initial_weight]" autocomplete="off" value="{{ old('BillingModel')['initial_weight'] }}" >
@@ -131,7 +147,7 @@
                 },
                 provinces:[
                     @foreach($provinces as $province)
-                        {id:'{{$province->id}}',name:'{{$province->name}}',cities:{!! $province->cities !!} },
+                        {id:'{{$province->id}}',name:'{{$province->name}}' },
                     @endforeach
                 ],
                 cities:[
@@ -148,8 +164,15 @@
                 ],
             },
            methods:{
-               changeProvince(){
+               changeProvince(e){
                    let _this=this;
+                   let val=e.target.value;
+                   axios.get('cities/'+val).then(
+                        function (response) {
+                            _this.cities=response.data.cities;
+                        }
+                   );
+                   /*let _this=this;
                    let province_id=this.inputting.BillingModel.province_id;
                    this.provinces.forEach(function (province) {
                        if(province.id+''===province_id+''){
@@ -157,7 +180,7 @@
                            return
                        }
                        return null
-                   })
+                   })*/
                }
            },
         });

+ 31 - 8
resources/views/waybill/billingModel/edit.blade.php

@@ -53,8 +53,8 @@
                     <div class="form-group row">
                         <label for="unit_id"  class="col-2 col-form-label text-right">货物单位</label>
                         <div class="col-8" >
-                            <select name="BillingModel[unit_id]" style="width: 30%;height: 30px">
-                                <option v-for="unit in units" :value="unit.id" v-model="inputting.BillingModel.unit_id">@{{unit.name}}</option>
+                            <select name="BillingModel[unit_id]" v-model="inputting.BillingModel.unit_id" style="width: 30%;height: 30px">
+                                <option v-for="unit in units" :value="unit.id" >@{{unit.name}}</option>
                             </select>
 
                             <div class="col-sm-5">
@@ -94,7 +94,19 @@
                         </div>
                     </div>
                     <div class="form-group row">
-                        <label for="initial_weight" class="col-2 col-form-label text-right">始重</label>
+                        <label for="base_fee" class="col-2 col-form-label text-right">起步费(元)</label>
+                        <div class="col-8">
+                            <input type="text" class="form-control @error('BillingModel.base_fee') is-invalid @enderror"
+                                   name="BillingModel[base_fee]" autocomplete="off" value="{{old('BillingModel')['base_fee']?old('BillingModel')['base_fee']:$billingModel->base_fee}}" >
+                            @error('BillingModel.base_fee')
+                            <span class="invalid-feedback" role="alert">
+                                        <strong>{{ $message }}</strong>
+                                    </span>
+                            @enderror
+                        </div>
+                    </div>
+                    <div class="form-group row">
+                        <label for="initial_weight" class="col-2 col-form-label text-right">最低计数</label>
                         <div class="col-8">
                             <input type="text" class="form-control @error('BillingModel.initial_weight') is-invalid @enderror"
                                    name="BillingModel[initial_weight]" autocomplete="off" value="{{old('BillingModel')['initial_weight']?old('BillingModel')['initial_weight']:$billingModel->initial_weight}}" >
@@ -131,10 +143,13 @@
                 },
                 provinces:[
                     @foreach($provinces as $province)
-                    {id:'{{$province->id}}',name:'{{$province->name}}',cities:{!! $province->cities !!} },
+                    {id:'{{$province->id}}',name:'{{$province->name}}' },
                     @endforeach
                 ],
                 cities:[
+                    @foreach($cities as $city)
+                    {id:'{{$city->id}}',name:'{{$city->name}}'},
+                    @endforeach
                 ],
                 carriers:[
                      @foreach($carriers as $carrier)
@@ -154,11 +169,20 @@
                 ]
             },
             mounted:function(){
-                this.changeProvince();
                 this.inputting.BillingModel.city_id='{{$billingModel->city_id}}';
             },
             methods:{
-                changeProvince(){
+                changeProvince(e){
+                    let _this=this;
+                    let val=e.target.value;
+                    axios.get('../cities/'+val).then(
+                        function (response) {
+                            _this.cities=response.data.cities;
+                        }
+                    );
+                }
+            },
+/*                changeProvince(){
                     let _this=this;
                     let province_id=this.inputting.BillingModel.province_id;
                     this.provinces.forEach(function (province) {
@@ -168,8 +192,7 @@
                         }
                         return null
                     })
-                }
-            },
+                }*/
         });
 
     </script>

+ 57 - 0
resources/views/waybill/billingModel/import.blade.php

@@ -0,0 +1,57 @@
+@extends('layouts.app')
+
+@section('content')
+    <div id="nav2">
+        @component('waybill.menu')@endcomponent
+        @component('waybill.billingModel.menu')@endcomponent
+    </div>
+    <div class="container mt-3">
+        <div class="card col-md-8 offset-md-2">
+            <div class="card-body">
+                <form method="POST" action="{{ url('billingModel/excel/import') }}" enctype="multipart/form-data" target="_blank">
+                    @csrf
+                    <div class="form-group row text-center">
+                        <div class="col-12 text-danger">
+
+                            注意:请保证表第一行有以下对应的字段名<br>(可不按顺序,承运商,计数单位,省份,单价为必填项,其余字段不填或填入错误数据则导入默认值0):<br>
+                            承运商,计数单位,计数区间,省份,单价,市,起步费,最低计数<br>
+                        </div>
+                        <div class="col-12 text-info ">
+                            导入时间随文件大小可能达数十分钟以上,请耐心等候
+                            <hr>
+                        </div>
+                    </div>
+                    <div class="form-group row">
+                        <label for="sku" class="col-2 col-form-label text-right">选择EXCEL</label>
+                        <div class="col-8">
+                            <div class="form-control">
+                                <input type="file" class="form-control-file @error('file') is-invalid @enderror"
+                                       name="file" value="{{ old('file') }}" required>
+                                @error('file')
+                                <span class="invalid-feedback" role="alert">
+                                <strong>{{ $message }}</strong>
+                            </span>
+                                @enderror
+                            </div>
+                        </div>
+                    </div>
+                    <div class="form-group row">
+                        <label for="sku" class="col-2 col-form-label text-right">是否覆盖</label>
+                        <div class="col-8">
+                            <select name="isOverride" id="isOverride" class="form-control" >
+                                <option value="0">仅新增</option>
+                                <option value="1">新增且覆盖</option>
+                            </select>
+                            <p class="text-muted">覆盖会以承运商,计数单位,计数区间,省份为依据,覆盖其余字段</p>
+                        </div>
+                    </div>
+                    <div class="form-group row">
+                        <div class="col-8 offset-2">
+                            <input type="submit" class="btn btn-success form-control" value="执行导入">
+                        </div>
+                    </div>
+                </form>
+            </div>
+        </div>
+    </div>
+@endsection

+ 73 - 5
resources/views/waybill/billingModel/index.blade.php

@@ -6,13 +6,44 @@
         @component('waybill.menu')@endcomponent
         @component('waybill.billingModel.menu')@endcomponent
     </span>
+    <div id="list">
     <div class="container mt-3">
         <div class="card">
+            <div>
+                <form  method="GET" action="{{url('billingModel')}}" style="margin-top: 1%" id="optionSubmit">
+                    <table class="table  table-sm table-bordered table-hover text-nowrap ">
+                        <tr>
+                            <td  > <label style="margin-left: 2%" class="form-inline">页显示条数:
+                                <select name="paginate" v-model="filterData.paginate" class="form-control" @change="setPaginate" style="height: 30px;width: 80px">
+                                    <option value="50">50行</option>
+                                    <option value="100">100行</option>
+                                    <option value="200">200行</option>
+                                    <option value="500">500行</option>
+                                    <option value="1000">1000行</option>
+                                </select></label></td>
+                            <td > <label class="form-inline" style="margin-left: 2%">承运商:
+                                <select name="carrier_id" v-model="filterData.carrier_id" class="form-control"  @change="setCarrier" style="height: 30px;width: 80px">
+                                    <option >    </option>
+                                    @foreach($carriers as $carrier)
+                                        <option value="{{$carrier->id}}">{{$carrier->name}}</option>
+                                    @endforeach
+                                </select></label></td>
+                            <td><label class="form-inline" style="margin-left: 2%">省份:
+                                <select name="province_id" v-model="filterData.province_id" class="form-control" @change="setProvince" style="height: 30px;width: 80px">
+                                    <option>    </option>
+                                    @foreach($provinces as $province)
+                                        <option value="{{$province->id}}">{{$province->name}}</option>
+                                    @endforeach
+                                </select><input hidden type="submit" value="kk"></label></td>
+                        </tr>
+                    </table>
+                </form>
+            </div>
             <div class="card-body">
                 @if(Session::has('successTip'))
                     <div class="alert alert-success h1">{{Session::get('successTip')}}</div>
                 @endif
-                <table class="table table-striped table-sm" id="list">
+                <table class="table table-striped table-sm">
                     <tr>
                         <th>代码</th>
                         <th>承运商名称</th>
@@ -21,7 +52,8 @@
                         <th>计重单位</th>
                         <th>区间</th>
                         <th>单价(元)</th>
-                        <th>始重</th>
+                        <th>起步费(元)</th>
+                        <th>最低计数</th>
                         <th>录入时间</th>
                     </tr>
                     <tr v-for="billingModel in billingModels">
@@ -30,8 +62,9 @@
                         <td>@{{billingModel.province}}</td>
                         <td>@{{billingModel.city}}</td>
                         <td>@{{billingModel.unit}}</td>
-                        <td>@{{billingModel.range_min}} -- @{{billingModel.range_max}}</td>
+                        <td>@{{billingModel.range_min}}<a v-if="billingModel.range_min&&billingModel.range_max">&nbsp;&nbsp;--&nbsp;&nbsp;</a> @{{billingModel.range_max}}</td>
                         <td>@{{billingModel.unit_price}}</td>
+                        <td>@{{billingModel.base_fee}}</td>
                         <td>@{{billingModel.initial_weight}}</td>
                         <td class="text-muted">@{{billingModel.created_at}}</td>
                         <td>
@@ -42,10 +75,11 @@
                         </td>
                     </tr>
                 </table>
-                {{$billingModels->links()}}
+                {{$billingModels->appends($filterData)->links()}}
             </div>
         </div>
     </div>
+    </div>
 @endsection
 
 @section('lastScript')
@@ -58,10 +92,15 @@
                         {id:'{{$billingModel->id}}',carrier:'{{$billingModel->carrier_name}}',
                         province:'{{$billingModel->province_name}}',city:'{{$billingModel->city_name}}',
                         unit:'{{$billingModel->unit_name}}',range_min:'{{$billingModel->range_min}}',range_max:'{{$billingModel->range_max}}',
-                        unit_price:'{{$billingModel->unit_price}}',initial_weight:'{{$billingModel->initial_weight}}',
+                        unit_price:'{{$billingModel->unit_price}}',base_fee:'{{$billingModel->base_fee}}',initial_weight:'{{$billingModel->initial_weight}}',
                         created_at:'{{$billingModel->created_at}}'},
                     @endforeach
                 ],
+                filterData:
+                    {paginate:'50',carrier_id:'',province_id: ''},
+            },
+            mounted:function(){
+                this.initInputs();
             },
             methods:{
                 edit:function(id){
@@ -93,6 +132,35 @@
                             console.log(err);
                         });
                 },
+                initInputs:function(){
+                    let data=this;
+                    let uriParts =decodeURI(location.href).split("?");
+                    if(uriParts.length>1){
+                        let params = uriParts[1].split('&');
+                        params.forEach(function(paramPair){
+                            let pair=paramPair.split('=');
+                            let key = pair[0], val = pair[1];
+                            $('input[name="'+key+'"]').val(val);
+                            $('select[name="'+key+'"]').val(val);
+                            decodeURI(data.filterData[key]=val);
+                        });
+                    }
+                },
+                setPaginate:function(e){
+                    this.filterData.paginate=e.target.value;
+                    var form = document.getElementById("optionSubmit");
+                    form.submit();
+                },
+                setCarrier:function (e){
+                    this.filterData.carrier_id=e.target.value;
+                    var form = document.getElementById("optionSubmit");
+                    form.submit();
+                },
+                setProvince:function (e){
+                    this.filterData.province_id=e.target.value;
+                    var form = document.getElementById("optionSubmit");
+                    form.submit();
+                },
             }
         });
     </script>

+ 8 - 4
resources/views/waybill/billingModel/menu.blade.php

@@ -1,14 +1,18 @@
 
-<div class="container mt-3" id="nav2">
-    <div class="card">
+<div style="background: #f9f0f0;transform: scale(0.85)" id="nav2">
+    <div >
         <ul class="nav nav-pills">
             @can('计费模型-查询')
             <li class="nav-item">
-                <a class="nav-link" href="{{url('billingModel')}}" :class="{active:isActive('',2)}">查询</a>
+                <a class="nav-link" href="{{url('waybill/billingModel')}}" :class="{active:isActive('',3)}">查询</a>
             </li> @endcan
             @can('计费模型-录入')
             <li class="nav-item">
-                <a class="nav-link" href="{{url('billingModel/create')}}" :class="{active:isActive('create',2)}">录入</a>
+                <a class="nav-link" href="{{url('waybill/billingModel/create')}}" :class="{active:isActive('create',3)}">录入</a>
+            </li> @endcan
+            @can('计费模型-录入')
+            <li class="nav-item">
+                <a class="nav-link" href="{{url('waybill/billingModel/excel/goImport')}}" :class="{active:isActive('goImport',4)}">导入</a>
             </li> @endcan
             {{$slot}}
         </ul>

+ 16 - 6
resources/views/waybill/create.blade.php

@@ -11,17 +11,15 @@
                     @csrf
                     <div class="form-group row">
                         <label for="type" class="col-2 col-form-label text-right text-primary">运单类型 *</label>
-                        <div class="col-8">
-                            <select name="type" style="width: 30%;height: 30px">
-                                    <option value="直发">直发</option>
-                                    <option value="专线">专线</option>
-                            </select>
+                        <div class="col-8" style="padding-top: 1%">
+                            <label class="radio-inline"><input type="radio" name="type" value="直发" checked>直发</label>
+                            <label class="radio-inline" style="margin-left: 5%"><input type="radio" name="type" value="专线">专线</label>
                         </div>
                     </div>
                     <div class="form-group row">
                         <label for="owner_id" class="col-2 col-form-label text-right text-primary">货主 *</label>
                         <div class="col-8">
-                            <select name="owner_id" style="width: 30%;height: 30px">
+                            <select name="owner_id" class="form-control" style="width: 30%;height: 30px">
                                 @foreach($owners as $owner)
                                     <option value="{{$owner->id}}">{{$owner->name}}</option>
                                 @endforeach
@@ -100,6 +98,18 @@
                             @enderror
                         </div>
                     </div>
+                    <div class="form-group row">
+                        <label for="collect_fee" class="col-2 col-form-label text-right text-muted">到付金额(元)</label>
+                        <div class="col-8">
+                            <input type="text" class="form-control @error('collect_fee') is-invalid @enderror"
+                                   name="collect_fee" autocomplete="off" value="{{ old('collect_fee') }}"  >
+                            @error('collect_fee')
+                            <span class="invalid-feedback" role="alert">
+                                <strong>{{ $message }}</strong>
+                            </span>
+                            @enderror
+                        </div>
+                    </div>
                     <div class="form-group row">
                         <label for="ordering_remark" class="col-2 col-form-label text-right text-muted">下单备注</label>
                         <div class="col-8">

+ 119 - 41
resources/views/waybill/edit.blade.php

@@ -8,7 +8,7 @@
             </li>
         @endcomponent
     </div>
-    <div class="container mt-3">
+    <div class="container mt-3" id="list">
         <div class="card">
             <div class="card-body">
                 <form method="POST" action='{{url("waybill/{$waybill->id}")}}'>
@@ -80,18 +80,16 @@
                     <div class="form-group row">
                         <label for="carrier_id" class="col-2 col-form-label text-right text-primary">承运商 *</label>
                         <div class="col-8">
-                            <select name="carrier_id" style="width: 30%;height: 30px">
+                            <select name="carrier_id" id="carrier_id" v-model="billingModel.carrier_id" style="width: 30%;height: 30px" @change="isCarrier($event)">
                                 @foreach($carriers as $carrier)
-                                    @if($carrier->id==$waybill->carrier_id)
-                                        <option value="{{$carrier->id}}" selected>{{$carrier->name}}</option>
-                                    @else
-                                        <option value="{{$carrier->id}}">{{$carrier->name}}</option>
-                                    @endif
+                                    <option value="{{$carrier->id}}">{{$carrier->name}}</option>
                                 @endforeach
                             </select>
-                            <div class="col-sm-5">
-                                <p class="form-control-static text-danger small font-weight-bold">@if(session('notBillingModel')){{session('notBillingModel')}},<a href="{{url('/billingModel/create')}}">点此前去添加</a>@endif</p>
-                            </div>
+                            @error('carrier_id')
+                            <span class="invalid-feedback" role="alert">
+                                        <strong>{{ $message }}</strong>
+                                    </span>
+                            @enderror
                         </div>
                     </div>
                     <div class="form-group row">
@@ -124,21 +122,22 @@
                     <div class="form-group row">
                         <label for="destination_city_id" class="col-2 col-form-label text-right text-primary">目的市 *</label>
                         <div class="col-8">
-                            <select name="destination_city_id" style="width: 30%;height: 30px">
+                            <select name="destination_city_id" id="destination_city_id" v-model="billingModel.destination_city_id" style="width: 30%;height: 30px" @change="isDestination_city($event)">
                                 @foreach($cities as $city)
-                                    @if($city->id==$waybill->destination_city_id)
-                                        <option value="{{$city->id}}" selected>{{$city->name}}</option>
-                                    @else
-                                        <option value="{{$city->id}}">{{$city->name}}</option>
-                                    @endif
+                                    <option value="{{$city->id}}">{{$city->name}}</option>
                                 @endforeach
                             </select>
+                            @error('destination_city_id')
+                            <span class="invalid-feedback" role="alert">
+                                        <strong>{{ $message }}</strong>
+                                    </span>
+                            @enderror
                         </div>
                     </div>
                     <div class="form-group row">
                         <label for="warehouse_weight" class="col-2 col-form-label text-right text-primary">仓库计重(抛) *</label>
                         <div class="col-8">
-                            <input type="text" class="form-control @error('warehouse_weight') is-invalid @enderror"
+                            <input type="text"  class="form-control @error('warehouse_weight') is-invalid @enderror"
                                    name="warehouse_weight" autocomplete="off" value="@if(old('warehouse_weight')){{ old('warehouse_weight') }}@else{{$waybill->warehouse_weight}}@endif"  >
                             @error('warehouse_weight')
                             <span class="invalid-feedback" role="alert">
@@ -164,9 +163,9 @@
                     <div class="form-group row">
                         <label for="carrier_weight" class="col-2 col-form-label text-right text-primary">承运商计重(抛) *</label>
                         <div class="col-8">
-                            <input type="text" class="form-control @error('carrier_weight') is-invalid @enderror"
-                                   name="carrier_weight" autocomplete="off" value="@if(old('carrier_weight')){{ old('carrier_weight') }}@else{{$waybill->carrier_weight}}@endif"  >
-                            @error('warehouse_weight')
+                            <input type="text" id="carrier_weight" class="form-control @error('carrier_weight') is-invalid @enderror"
+                                   name="carrier_weight" autocomplete="off" v-model="billingModel.carrier_weight" @blur="isCarrier_weight($event)">
+                            @error('carrier_weight')
                             <span class="invalid-feedback" role="alert">
                                         <strong>{{ $message }}</strong>
                                     </span>
@@ -176,15 +175,16 @@
                     <div class="form-group row">
                         <label for="carrier_weight_unit_id" class="col-2 col-form-label text-right text-primary">承运商计重单位 *</label>
                         <div class="col-8">
-                            <select name="carrier_weight_unit_id" style="width: 30%;height: 30px">
+                            <select name="carrier_weight_unit_id" id="carrier_weight_unit_id" v-model="billingModel.carrier_weight_unit_id" style="width: 30%;height: 30px" @change="isCarrier_weight_unit($event)">
                                 @foreach($units as $unit)
-                                    @if($unit->id==$waybill->carrier_weight_unit_id)
-                                        <option value="{{$unit->id}}" selected>{{$unit->name}}</option>
-                                    @else
-                                        <option value="{{$unit->id}}" selected>{{$unit->name}}</option>
-                                    @endif
+                                    <option value="{{$unit->id}}">{{$unit->name}}</option>
                                 @endforeach
                             </select>
+                            @error('carrier_weight_unit_id')
+                            <span class="invalid-feedback" role="alert">
+                                        <strong>{{ $message }}</strong>
+                                    </span>
+                            @enderror
                         </div>
                     </div>
                     @endif
@@ -244,20 +244,6 @@
                             @enderror
                         </div>
                     </div>
-                    @if($waybill->type=="直发")
-                    <div class="form-group row">
-                        <label for="collect_fee" class="col-2 col-form-label text-right text-muted">到付金额(元)</label>
-                        <div class="col-8">
-                            <input type="text" class="form-control @error('collect_fee') is-invalid @enderror"
-                                   name="collect_fee" autocomplete="off" value="@if(old('collect_fee')){{ old('collect_fee') }}@else{{$waybill->collect_fee}}@endif"  >
-                            @error('collect_fee')
-                            <span class="invalid-feedback" role="alert">
-                                        <strong>{{ $message }}</strong>
-                                    </span>
-                            @enderror
-                        </div>
-                    </div>
-                    @endif
                     <div class="form-group row">
                         <label for="dispatch_remark" class="col-2 col-form-label text-right text-muted">调度备注</label>
                         <div class="col-8">
@@ -271,7 +257,7 @@
                         </div>
                     </div>
                     <input type="hidden" name="state" value="待终审">
-
+                    <input type="hidden" name="billingModel" id="billingModel">
                     <div class="form-group row">
                         <div class="col-8 offset-2">
                             <input type="submit" class="btn btn-outline-dark form-control">
@@ -282,3 +268,95 @@
         </div>
     </div>
 @endsection
+
+@section('lastScript')
+    <script>
+        let vueList=new Vue({
+            el:'#list',
+            data:{
+                billingModel: {
+                    carrier_id:'{{$waybill->carrier_id}}',destination_city_id:'{{$waybill->destination_city_id}}',
+                    carrier_weight:'{{old('carrier_weight')?old('carrier_weight'):$waybill->carrier_weight}}',carrier_weight_unit_id:'{{$waybill->carrier_weight_unit_id}}'
+                }
+            },
+            methods:{
+                isCarrier(e){
+                    let  carrier_id=e.target.value;
+                    let carrier_weight=document.getElementById('carrier_weight').value;
+                    let carrier_weight_unit_id=document.getElementById('carrier_weight_unit_id').value;
+                    let destination_city_id=document.getElementById('destination_city_id').value;
+                    if (carrier_weight&&carrier_weight_unit_id&&destination_city_id) {
+                        axios.post('../is/billingModel',{carrier_id:carrier_id,carrier_weight:carrier_weight,carrier_weight_unit_id:carrier_weight_unit_id,destination_city_id:destination_city_id})
+                        .then(
+                            function (response) {
+                                if (!response.data.success) {
+                                    tempTip.okWindow('该计费模型不存在,是否仍要录入, @can('计费模型-录入') <a href="{{url('/billingModel/create')}}">点此前去添加</a> @endcan ');
+                                    document.getElementById('billingModel').value='';
+                                }else{
+                                    document.getElementById('billingModel').value=response.data.success;
+                                }
+                            }
+                        );
+                    }
+                },
+                isDestination_city(e){
+                    let  carrier_id=document.getElementById('carrier_id').value;
+                    let carrier_weight=document.getElementById('carrier_weight').value;
+                    let carrier_weight_unit_id=document.getElementById('carrier_weight_unit_id').value;
+                    let destination_city_id=e.target.value;
+                    if (carrier_weight&&carrier_weight_unit_id&&destination_city_id) {
+                        axios.post('../is/billingModel',{carrier_id:carrier_id,carrier_weight:carrier_weight,carrier_weight_unit_id:carrier_weight_unit_id,destination_city_id:destination_city_id})
+                            .then(
+                                function (response) {
+                                    if (!response.data.success) {
+                                        tempTip.okWindow('该计费模型不存在,是否仍要录入, @can('计费模型-录入') <a href="{{url('/billingModel/create')}}">点此前去添加</a> @endcan ');
+                                        document.getElementById('billingModel').value='';
+                                    }else{
+                                        document.getElementById('billingModel').value=response.data.success;
+                                    }
+                                }
+                            );
+                    }
+                },
+                isCarrier_weight_unit(e){
+                    let  carrier_id=document.getElementById('carrier_id').value;
+                    let carrier_weight=document.getElementById('carrier_weight').value;
+                    let carrier_weight_unit_id=e.target.value;
+                    let destination_city_id=document.getElementById('destination_city_id').value;
+                    if (carrier_weight&&carrier_weight_unit_id&&destination_city_id) {
+                        axios.post('../is/billingModel',{carrier_id:carrier_id,carrier_weight:carrier_weight,carrier_weight_unit_id:carrier_weight_unit_id,destination_city_id:destination_city_id})
+                            .then(
+                                function (response) {
+                                    if (!response.data.success) {
+                                        tempTip.okWindow('该计费模型不存在,是否仍要录入, @can('计费模型-录入') <a href="{{url('/billingModel/create')}}">点此前去添加</a> @endcan ');
+                                        document.getElementById('billingModel').value='';
+                                    }else{
+                                        document.getElementById('billingModel').value=response.data.success;
+                                    }
+                                }
+                            );
+                    }
+                },
+                isCarrier_weight(e){
+                    let  carrier_id=document.getElementById('carrier_id').value;
+                    let carrier_weight=e.target.value;
+                    let carrier_weight_unit_id=document.getElementById('carrier_weight_unit_id').value;
+                    let destination_city_id=document.getElementById('destination_city_id').value;
+                    if (carrier_weight&&carrier_weight_unit_id&&destination_city_id) {
+                        axios.post('../is/billingModel',{carrier_id:carrier_id,carrier_weight:carrier_weight,carrier_weight_unit_id:carrier_weight_unit_id,destination_city_id:destination_city_id})
+                            .then(
+                                function (response) {
+                                    if (!response.data.success) {
+                                        tempTip.okWindow('该计费模型不存在,是否仍要录入, @can('计费模型-录入') <a href="{{url('/billingModel/create')}}">点此前去添加</a> @endcan ');
+                                        document.getElementById('billingModel').value='';
+                                    }else{
+                                        document.getElementById('billingModel').value=response.data.success;
+                                    }
+                                }
+                            );
+                    }
+                },
+            },
+        });
+    </script>
+@endsection

+ 27 - 28
resources/views/waybill/index.blade.php

@@ -3,12 +3,9 @@
 @section('content')
     <div id="nav2">
         @component('waybill.menu')
-            <li class="nav-item">
-                <a class="nav-link" href="{{URL::current()}}" :class="{active:isActive('',2)}">查询</a>
-            </li>
         @endcomponent
     </div>
-    <div id="list" class="table-responsive">
+    <div id="list">
         <div class="card">
             <div class="card-body">
                 <form  method="GET" action="{{url('waybill')}}" style="margin-top: 1%" id="optionSubmit">
@@ -21,18 +18,17 @@
                     <tr>
                         <td> <label style="margin-left: 2%">页显示条数:</label>
                             <select name="paginate" v-model="filterData.paginate" @change="setPaginate" class="rounded  " style="height: 30px;width: 80px">
-                                <option value="50">50</option>
-                                <option value="100">100</option>
-                                <option value="200">200</option>
-                                <option value="500">500</option>
-                                <option value="1000">1000</option>
+                                <option value="50">50</option>
+                                <option value="100">100</option>
+                                <option value="200">200</option>
+                                <option value="500">500</option>
+                                <option value="1000">1000</option>
                             </select></td>
-                        <td><label style="margin-left: 2%">承运商:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
-                            <select name="carrier_id" v-model="filterData.carrier_id" class="rounded  " @change="setCarrier" style="height: 30px;width: 80px">
-                                <option >    </option>
-                                @foreach($carriers as $carrier)
-                                    <option value="{{$carrier->id}}">{{$carrier->name}}</option>
-                                @endforeach
+                        <td><label style="margin-left: 2%">类型:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
+                            <select name="type" v-model="filterData.type" class="rounded  " @change="setType" style="height: 30px;width: 80px">
+                                <option></option>
+                                <option value="专线">专线</option>
+                                <option value="直发">直发车</option>
                             </select></td>
                         <td><label style="margin-left: 2%">货主:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
                             <select name="owner_id" v-model="filterData.owner_id" class="rounded  " @change="setOwner" style="height: 30px;width: 80px">
@@ -41,12 +37,14 @@
                                     <option value="{{$owner->id}}">{{$owner->name}}</option>
                                 @endforeach
                             </select></td>
-                        <td><label style="margin-left: 2%">类型:&nbsp;&nbsp;&nbsp;</label>
-                            <select name="type" v-model="filterData.type" class="rounded  " @change="setType" style="height: 30px;width: 80px">
-                                <option></option>
-                                <option value="专线">专线</option>
-                                <option value="直发">直发</option>
+                        <td><label style="margin-left: 2%">承运商:</label>
+                            <select name="carrier_id" v-model="filterData.carrier_id" class="rounded  " @change="setCarrier" style="height: 30px;width: 80px">
+                                <option >    </option>
+                                @foreach($carriers as $carrier)
+                                    <option value="{{$carrier->id}}">{{$carrier->name}}</option>
+                                @endforeach
                             </select></td>
+
                     </tr>
                     <tr>
                         <td><label style="margin-left: 2%">运单号:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
@@ -62,7 +60,7 @@
                         <td><label style="margin-left: 2%"> 目的地:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
                             <input type="text"  name="destination" class="rounded  " v-model="filterData.destination"><br></td>
                         <td colspan="3"><div><label style="margin-left: 1%"> 开始日期:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label><input type="date" name="created_at_start" class="rounded"  v-model="filterData.created_at_start"></div>
-                       <div><label style="margin-left: 1%"> 截至日期:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label><input type="date" class="rounded" name="Waybill[created_at_end]" v-model="filterData.created_at_end"></div></td>
+                       <div><label style="margin-left: 1%"> 截至日期:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label><input type="date" class="rounded" name="created_at_end" v-model="filterData.created_at_end"></div></td>
                     </tr>
                     <tr>
                         <td colspan="5">
@@ -98,6 +96,7 @@
                 <th>收件人</th>
                 <th>收件人电话</th>
                 <th>收费(元)</th>
+                <th>到付金额(元)</th>
                 <th>下单备注</th>
                 <th>运单审核人</th>
                 @can('运单管理-编辑','运单管理-运单审核','运单管理-调度')
@@ -115,7 +114,6 @@
                 <th>运费(元)</th>
                 <th>提货费(元)</th>
                 <th>其他费用(元)</th>
-                <th>到付金额(元)</th>
                 <th>调度备注</th>
                 <th>创建时间</th>
                 <th>调度审核人</th>
@@ -138,6 +136,7 @@
                 <td>@{{waybill.recipient}}</td>
                 <td>@{{waybill.recipient_mobile}}</td>
                 <td>@{{waybill.charge}}</td>
+                <td>@{{waybill.collect_fee}}</td>
                 <td>@{{waybill.ordering_remark}}</td>
                 <td><p v-for="auditLog in waybill.auditLogs" v-if=auditLog.audit_stage==="运单阶段">@{{auditLog.user.name}}</p></td>
                 <td>
@@ -151,7 +150,7 @@
                     </div>
                     <div v-if=waybill.state==="已审核">
                         @can('运单管理-调度')
-                            <button class="btn btn-outline-warning" @click="waybillRetreatAudit(waybill.id,waybill.waybill_number)">反审核</button>
+                            <button class="btn btn-outline-secondary" @click="waybillRetreatAudit(waybill.id,waybill.waybill_number)">反审核</button>
                             <button class="btn btn-outline-secondary" @click="job(waybill.id)">调度</button>
                         @endcan
                     </div>                                                                                                                                                                     
@@ -165,10 +164,11 @@
                 <td>@{{waybill.carrier_weight}}</td>
                 <td>@{{waybill.carrier_weight_unit}}</td>
                 <td><p v-if="waybill.carType">@{{ waybill.carType.name }}(@{{waybill.carType.length}}米)</p></td>
-                <td>@{{waybill.fee}}</td>
+                @can('运单管理-可见费用项')
+                    <td><p v-if="waybill.type=='专线'">***</p><p v-else>@{{waybill.fee}}</p></td>
                 <td>@{{waybill.pick_up_fee}}</td>
                 <td>@{{waybill.other_fee}}</td>
-                <td>@{{waybill.collect_fee}}</td>
+                @endcan
                 <td>@{{waybill.dispatch_remark}}</td>
                 <td>@{{waybill.created_at}}</td>
                 <td><p v-for="auditLog in waybill.auditLogs" v-if=auditLog.audit_stage==="调度阶段">@{{auditLog.user.name}}</p></td>
@@ -205,9 +205,9 @@
                         carrier_bill:'{{$waybill->carrier_bill}}',origination_city:'{{$waybill->origination_city_name}}',
                         destination_city:'{{$waybill->destination_city_name}}',warehouse_weight:'{{$waybill->warehouse_weight}}',
                         warehouse_weight_unit:'{{$waybill->warehouse_weight_unit_name}}',carrier_weight:'{{$waybill->carrier_weight}}',
-                        carrier_weight_unit:'{{$waybill->carrier_weight_unit_name}}',@if($waybill->carType)carType:{!! $waybill->carType !!},@endif fee:'{{$waybill->fee}}',
+                        carrier_weight_unit:'{{$waybill->carrier_weight_unit_name}}',@if($waybill->carType)carType:{!! $waybill->carType !!},@endif @can('运单管理-可见费用项') fee:'{{$waybill->fee}}',
                         pick_up_fee:'{{$waybill->pick_up_fee}}',other_fee:'{{$waybill->other_fee}}',
-                        collect_fee:'{{$waybill->collect_fee}}',dispatch_remark:'{{$waybill->dispatch_remark}}',
+                        collect_fee:'{{$waybill->collect_fee}}', @endif dispatch_remark:'{{$waybill->dispatch_remark}}',
                         auditLogs:{!! $waybill->auditLogs !!}
                     },
                     @endforeach
@@ -227,7 +227,6 @@
                     for(let key in this.filterData){
                         if(this.filterData[key]){
                             if(key==='paginate')continue;
-                            console.log(this.filterData);
                             return true
                         }
                     }

+ 10 - 3
resources/views/waybill/menu.blade.php

@@ -2,18 +2,25 @@
 <div class="container mt-3" id="nav2">
     <div class="card">
         <ul class="nav nav-pills">
+            @can('运单管理-查询')
+            <li class="nav-item">
+                <a class="nav-link" href="{{url('waybill')}}" :class="{active:isActive('',2)}">运单查询</a>
+            </li> @endcan
             @can('运单管理-录入')
             <li class="nav-item">
                 <a class="nav-link" href="{{url('waybill/create')}}" :class="{active:isActive('create',2)}">运单录入</a>
             </li> @endcan
             @can('计费模型')
             <li class="nav-item">
-                <a class="nav-link text-dark" href="{{url('billingModel')}}" :class="{active:isActive('billingModel',1)}">计费模型</a>
+                <a class="nav-link text-dark" href="{{url('waybill/billingModel')}}" :class="{active:isActive('billingModel',2)}">计费模型</a>
             </li> @endcan
             @can('财务报表')
             <li class="nav-item">
-                <a class="nav-link text-dark" href="{{url('waybillFinancialSnapshot')}}" :class="{active:isActive('waybillFinancialSnapshot',1)}">财务报表</a>
-            </li> @endcan
+                <a class="nav-link text-dark" href="{{url('waybill/waybillFinancialSnapshot')}}" :class="{active:isActive('waybillFinancialSnapshot',2)}">财务报表</a>
+            </li>
+            <li class="nav-item">
+                <a class="nav-link text-dark" href="{{url('waybill/waybillFinancialExcepted')}}" :class="{active:isActive('waybillFinancialExcepted',2)}">异常报表</a>
+            </li>@endcan
             {{$slot}}
         </ul>
     </div>

+ 24 - 11
resources/views/waybill/waybillEdit.blade.php

@@ -15,22 +15,23 @@
                     @csrf
                     <div class="form-group row">
                         <label for="type" class="col-2 col-form-label text-right text-primary">运单类型 *</label>
-                        <div class="col-8">
-                            <select name="type" style="width: 30%;height: 30px">
-                                @if($waybill->type=="直发")
-                                    <option value="直发" selected>直发</option>
-                                    <option value="专线">专线</option>
-                                @else
-                                    <option value="直发" >直发</option>
-                                    <option value="专线" selected>专线</option>
-                                @endif
-                            </select>
+                            @if($waybill->type=="直发")
+                                <div class="col-8" style="padding-top: 1%">
+                                    <label class="radio-inline"><input type="radio" name="type" value="直发" checked>直发</label>
+                                    <label class="radio-inline" style="margin-left: 5%"><input type="radio" name="type" value="专线">专线</label>
+                                </div>
+                            @else
+                                <div class="col-8" style="padding-top: 1%">
+                                    <label class="radio-inline"><input type="radio" name="type" value="直发" >直发</label>
+                                    <label class="radio-inline" style="margin-left: 5%"><input type="radio" name="type" value="专线" checked>专线</label>
+                                </div>
+                            @endif
                         </div>
                     </div>
                     <div class="form-group row">
                         <label for="province_id" class="col-2 col-form-label text-right text-primary">货主 *</label>
                         <div class="col-8">
-                            <select name="owner_id" style="width: 30%;height: 30px">
+                            <select name="owner_id" class="form-control" style="width: 30%;height: 30px">
                                 @foreach($owners as $owner)
                                     @if($owner->id==$waybill->owner_id)
                                         <option value="{{$owner->id}}" selected>{{$owner->name}}</option>
@@ -113,6 +114,18 @@
                             @enderror
                         </div>
                     </div>
+                    <div class="form-group row">
+                        <label for="collect_fee" class="col-2 col-form-label text-right text-muted">到付金额(元)</label>
+                        <div class="col-8">
+                            <input type="text" class="form-control @error('collect_fee') is-invalid @enderror"
+                                   name="collect_fee" autocomplete="off" value="@if(old('collect_fee')){{ old('collect_fee') }}@else{{$waybill->collect_fee}}@endif"  >
+                            @error('collect_fee')
+                            <span class="invalid-feedback" role="alert">
+                                <strong>{{ $message }}</strong>
+                            </span>
+                            @enderror
+                        </div>
+                    </div>
                     <div class="form-group row">
                         <label for="ordering_remark" class="col-2 col-form-label text-right text-muted">下单备注</label>
                         <div class="col-8">

+ 51 - 7
resources/views/waybill/waybillFinancialSnapshot/index.blade.php

@@ -1,24 +1,44 @@
 @extends('layouts.app')
 
 @section('content')
-    <div id="nav2">
+<div id="editingPanel">
+    <form  method="get" action="@if(!isset($excepted)) {{url('waybillFinancialSnapshot')}} @else {{url('waybillFinancialExcepted')}} @endif ">
+    <div  class="card" id="nav2">
         @component('waybill.menu')@endcomponent
-    </div>
 
+            <div  style="background: #f9f0f0;transform: scale(0.85)">
+
+                    <div class="btn-group">
+                        <input type="submit" class="btn @if($type=='全部') btn-info @endif" name="type" value="全部"/>
+                        <input type="submit" class="btn @if($type=='直发') btn-info @endif" name="type" value="直发"/>
+                        <input type="submit" class="btn @if($type=='专线') btn-info @endif" name="type" value="专线"/>
+                    </div>
+            </div>
+    </div>
+    <div class="card-header">
+        <label style="margin-left: 1%"> 开始日期:</label><input type="date" name="created_at_start" class="rounded"  v-model="filterData.created_at_start">
+        <label style="margin-left: 1%"> 截至日期:</label><input type="date" class="rounded" name="created_at_end" v-model="filterData.created_at_end">
+        <input hidden type="submit" value="kk">
+    </div>
+    </form>
 <!-- 自定义内容区域 -->
-<div class="card table-responsive "  id="editingPanel">
+<div class="card " >
+    @if(!isset($excepted))
     <div class="card-header">
-        <label>操作选定记录:</label>
-        <button @click="waybillExport" class="btn btn-outline-dark">导出Excel</button>
+    <label>操作选定记录:</label>
+    <button @click="waybillExport" class="btn btn-outline-dark">导出Excel</button>
     </div>
+    @endif
     <table class="table  table-hover table-bordered text-nowrap " style="width: 1500px;height: auto">
         <thead>
-        <tr style="background: #E8E8E8">
+        <tr style="background: #E8E8E8;@if(isset($excepted)) color: red; @endif">
+            @if(!isset($excepted))
             <th>
                 <label for="all">
                     <input id="all" type="checkbox" @click="checkAll($event)">全选
                 </label>
             </th>
+            @endif
             <th>运单ID</th>
             <th>运单类型</th>
             <th>运单号</th>
@@ -56,9 +76,11 @@
         <tbody>
 
         <tr v-for="json_content in json_contents" :style="{background:json_content.waybill.type=='直发'?'#F8F8F8':''}">
+            @if(!isset($excepted))
             <td>
                 <input class="checkItem" type="checkbox" :value="json_content.waybill_id" v-model="checkData">
             </td>
+            @endif
             <td>@{{json_content.waybill_id}}</td>
             <td>@{{json_content.waybill.type}}</td>
             <td>@{{json_content.waybill.waybill_number}}</td>
@@ -112,6 +134,7 @@
         {{$waybillFinancialSnapshots->render()}}
     </div>
 </div>
+</div>
 @stop
 
 @section('lastScript')
@@ -127,6 +150,9 @@
             ],
             @endif
             checkData:[],
+            filterData:{
+                created_at_start:'',created_at_end:'',
+            },
         },
         watch:{
             checkData:{
@@ -138,9 +164,27 @@
                     }
                 },
                 deep:true
-            }
+            },
+        },
+        mounted:function(){
+            this.initInputs();
         },
         methods:{
+            initInputs:function(){
+                let data=this;
+                let uriParts =decodeURI(location.href).split("?");
+                if(uriParts.length>1){
+                    let params = uriParts[1].split('&');
+                    params.forEach(function(paramPair){
+                        let pair=paramPair.split('=');
+                        let key = pair[0], val = pair[1];
+                        if(key==='type')return;
+                        console.log(uriParts);
+                        $('input[name="'+key+'"]').val(val);
+                        decodeURI(data.filterData[key]=val);
+                    });
+                }
+            },
             checkAll(e){
                 if (e.target.checked){
                     this.json_contents.forEach((el,i)=>{

+ 9 - 2
routes/web.php

@@ -39,8 +39,14 @@ Route::resource('maintenance/province','ProvincesController');
 Route::resource('maintenance/city','CitiesController');
 Route::resource('maintenance/commodity', 'CommodityController');
 
+Route::resource('waybill/billingModel','BillingModelsController');
+Route::get('waybill/billingModel/excel/goImport',function (){return view('waybill.billingModel.import');});
+
+Route::resource('waybill/waybillFinancialSnapshot','WaybillFinancialSnapshotsController');
+Route::resource('waybill/waybillFinancialExcepted','WaybillFinancialExceptedController');
 
 Route::resource('waybill','WaybillsController');
+Route::post('waybill/is/billingModel','WaybillsController@isBillingModel');
 Route::any('waybill/waybillAudit','WaybillsController@waybillAudit');
 Route::any('waybill/waybillEdit/{id}','WaybillsController@waybillEdit');
 Route::any('waybill/waybillRetreatAudit','WaybillsController@waybillRetreatAudit');
@@ -48,10 +54,11 @@ Route::any('waybill/waybillEndAudit','WaybillsController@waybillEndAudit');
 Route::any('waybillExport/{id}','WaybillsController@waybillExport');
 Route::any('waybill/waybillUpdate/{id}','WaybillsController@waybillUpdate');
 
-Route::resource('waybillFinancialSnapshot','WaybillFinancialSnapshotsController');
+
 Route::any('waybillFinancialSnapshot/export/{id}','WaybillFinancialSnapshotsController@export');
 
-Route::resource('billingModel','BillingModelsController');
+Route::get('billingModel/cities/{province_id}','BillingModelsController@getCities');
+Route::post('billingModel/excel/import','BillingModelsController@import');
 
 
 

+ 9 - 9
tests/Unit/CityTest.php

@@ -43,7 +43,7 @@ class CityTest extends TestCase
 
     public function testAddCity(){
         $city=new City([
-            'name'=>'商丘',
+            'name'=>'测试',
             'province_id'=>1,
         ]);
         $result=$city->save();
@@ -59,10 +59,10 @@ class CityTest extends TestCase
      */
     public function testIndex(City $city,User $user,User $userMark){
         $response=$this->actingAs($user)->get('maintenance/city');
-        $response->assertOk()->assertSee('商丘');
+        $response->assertOk();
         $responseMark=$this->actingAs($userMark)->get('maintenance/city');
         $responseMark->assertStatus(302)->assertRedirect('/');
-        $city=City::paginate(10);
+        $city=City::paginate(50);
         $this->assertNotEmpty($city);
     }
 
@@ -83,16 +83,16 @@ class CityTest extends TestCase
      * */
     public function testStore(User $user,User $userMark){
         $response=$this->actingAs($user)->post('maintenance/city',['City'=>[
-            'name'=>'驻马店',
+            'name'=>'测试Two',
             'province_id'=>1,
         ]]);
         $response->assertStatus(302)->assertRedirect('maintenance/city')->assertSessionHas('successTip');
         $responseMark=$this->actingAs($userMark)->post('maintenance/city',['City'=>[
-            'name'=>'驻马店',
+            'name'=>'测试Two',
             'province_id'=>1,
         ]]);
         $responseMark->assertStatus(302)->assertRedirect('/');
-        $city=City::where('name','=','驻马店')->first();
+        $city=City::where('name','=','测试Two')->first();
         $result=$city->delete();
         $this->assertTrue($result);
     }
@@ -104,7 +104,7 @@ class CityTest extends TestCase
      */
     public function testEdit(City $city,User $user,User $userMark){
         $response=$this->actingAs($user)->get("maintenance/city/$city->id/edit");
-        $response->assertOk()->assertSee('商丘');
+        $response->assertOk()->assertSee('测试');
         $responseMark=$this->actingAs($userMark)->get("maintenance/city/$city->id/edit");
         $responseMark->assertStatus(302)->assertRedirect('/');
     }
@@ -116,12 +116,12 @@ class CityTest extends TestCase
      */
     public function testUpdate(City $city,User $user,User $userMark){
         $response=$this->actingAs($user)->put("maintenance/city/$city->id",['City'=>[
-            'name'=>'郑州',
+            'name'=>'测试Update',
             'province_id'=>1,
         ]]);
         $response->assertStatus(302)->assertRedirect('maintenance/city')->assertSessionHas('successTip');
         $responseMark=$this->actingAs($userMark)->put("maintenance/city/$city->id",['City'=>[
-            'name'=>'郑州',
+            'name'=>'测试Update',
             'province_id'=>1,
         ]]);
         $responseMark->assertStatus(302)->assertRedirect('/');

+ 8 - 8
tests/Unit/ProvinceTest.php

@@ -43,7 +43,7 @@ class ProvinceTest extends TestCase
 
     public function testAddProvince(){
         $province=new Province([
-            'name'=>'河南',
+            'name'=>'汉城',
         ]);
         $result=$province->save();
         $this->assertTrue($result);
@@ -58,7 +58,7 @@ class ProvinceTest extends TestCase
      */
     public function testIndex(Province $province,User $user,User $userMark){
         $response=$this->actingAs($user)->get('maintenance/province');
-        $response->assertOk()->assertSee('河南');
+        $response->assertOk()->assertSee('汉城');
         $responseMark=$this->actingAs($userMark)->get('maintenance/province');
         $responseMark->assertStatus(302)->assertRedirect('/');
         $province=Province::paginate(10);
@@ -82,14 +82,14 @@ class ProvinceTest extends TestCase
      */
     public function testStore(User $user,User $userMark){
         $response=$this->actingAs($user)->post('maintenance/province',['Province'=>[
-            'name'=>'山东',
+            'name'=>'帝都',
         ]]);
         $response->assertStatus(302)->assertRedirect('maintenance/province')->assertSessionHas('successTip');
         $responseMark=$this->actingAs($userMark)->post('maintenance/province',['Province'=>[
-            'name'=>'山东',
+            'name'=>'帝都',
         ]]);
         $responseMark->assertStatus(302)->assertRedirect('/');
-        $province=Province::where('name','=','山东')->first();
+        $province=Province::where('name','=','帝都')->first();
         $result=$province->delete();
         $this->assertTrue($result);
     }
@@ -101,7 +101,7 @@ class ProvinceTest extends TestCase
      */
     public function testEdit(Province $province,User $user,User $userMark){
         $response=$this->actingAs($user)->get("maintenance/province/$province->id/edit");
-        $response->assertOk()->assertSee('河南');
+        $response->assertOk()->assertSee('汉城');
         $responseMark=$this->actingAs($userMark)->get("maintenance/province/$province->id/edit");
         $responseMark->assertStatus(302)->assertRedirect('/');
     }
@@ -113,11 +113,11 @@ class ProvinceTest extends TestCase
      */
     public function testUpdate(Province $province,User $user,User $userMark){
         $response=$this->actingAs($user)->put("maintenance/province/$province->id",['Province'=>[
-            'name'=>'北京'
+            'name'=>'圣都'
         ]]);
         $response->assertStatus(302)->assertRedirect('maintenance/province')->assertSessionHas('successTip');
         $responseMark=$this->actingAs($userMark)->put("maintenance/province/$province->id",['Province'=>[
-            'name'=>'北京'
+            'name'=>'圣都'
         ]]);
         $responseMark->assertStatus(302)->assertRedirect('/');
     }

+ 3 - 3
tests/Unit/UnitTest.php

@@ -43,7 +43,7 @@ class UnitTest extends TestCase
 
     public function testAddUnit(){
         $unit=new Unit([
-            'name'=>'kg',
+            'name'=>'cm',
         ]);
         $result=$unit->save();
         $this->assertTrue($result);
@@ -58,7 +58,7 @@ class UnitTest extends TestCase
      */
     public function testIndex(Unit $unit,User $user,User $userMark){
         $response=$this->actingAs($user)->get('maintenance/unit');
-        $response->assertOk()->assertSee('kg');
+        $response->assertOk()->assertSee('cm');
         $responseMark=$this->actingAs($userMark)->get('maintenance/unit');
         $responseMark->assertStatus(302)->assertRedirect('/');
         $unit=Unit::paginate(10);
@@ -101,7 +101,7 @@ class UnitTest extends TestCase
      */
     public function testEdit(Unit $unit,User $user,User $userMark){
         $response=$this->actingAs($user)->get("maintenance/unit/$unit->id/edit");
-        $response->assertOk()->assertSee('kg');
+        $response->assertOk()->assertSee('cm');
         $responseMark=$this->actingAs($userMark)->get("maintenance/unit/$unit->id/edit");
         $responseMark->assertStatus(302)->assertRedirect('/');
     }