Преглед изворни кода

为承运商添加送货费字段,更新运费财务计算逻辑(单元测试待更新)

Zhouzhendong пре 6 година
родитељ
комит
ba7d0b512d

+ 1 - 1
app/Carrier.php

@@ -8,6 +8,6 @@ class Carrier extends Model
 {
 
     protected $fillable=[
-        'name','mobile','remark'
+        'name','mobile','delivery_fee','remark'
     ];
 }

+ 5 - 1
app/Http/Controllers/CarriersController.php

@@ -68,15 +68,19 @@ class CarriersController extends Controller
     protected function validatorCarrier(Request $request){
         $validator=Validator::make($request->input(),[
             'Carrier.name'=>'max:50|required',
-            'Carrier.mobile'=>['required','regex:/^(d{7,11})|(1[3|4|5|7|8][0-9]\d{4,8})$/'],
+            'Carrier.mobile'=>['required','regex:/^(\d{7,11})|(1[3|4|5|7|8][0-9]\d{4,8})$/'],
+            'Carrier.delivery_fee'=>'nullable|min:0|numeric',
         ],[
             'digits_between'=>':attribute 最小一位,最大五十位',
             'required'=>':attribute 不应为空',
             'regex'=>':attribute 输入有误',
             'integer'=>':attribute 应为数值',
+            'min'=>':attribute 不得为0或为负',
+            'numeric'=>':attribute 必须为数字',
         ],[
             'Carrier.name'=>'承运商名称',
             'Carrier.mobile'=>'承运商电话',
+            'Carrier.delivery_fee'=>'送货费',
         ]);
         return $validator;
     }

+ 11 - 2
app/Http/Controllers/WaybillsController.php

@@ -257,10 +257,11 @@ class WaybillsController extends Controller
                 if ($waybillPriceModel_id){
                     $carrier_weight=$request->input('carrier_weight');
                     $waybillPriceModel=WaybillPriceModel::find($waybillPriceModel_id);
+                    $carrier=Carrier::find($waybill->carrier_id);
                     if ($carrier_weight<$waybillPriceModel->initial_weight){
-                        $fee=($waybillPriceModel->unit_price)*($waybillPriceModel->initial_weight);
+                        $fee=(($waybillPriceModel->unit_price)*($waybillPriceModel->initial_weight))+$carrier->delivery_fee;
                     }else{
-                        $fee=($waybillPriceModel->unit_price)*$carrier_weight;
+                        $fee=(($waybillPriceModel->unit_price)*$carrier_weight)+$carrier->delivery_fee;
                     }
                     $waybill->fee=$fee;
                     $waybill->waybill_price_model_id=$waybillPriceModel_id;
@@ -443,6 +444,11 @@ class WaybillsController extends Controller
             'dispatchAuditor'=>'调度审核人',
             'created_at'=>'创建时间'
         ]];
+        $feeVisible=true;
+        if(!Gate::allows('运单管理-可见费用项')){
+            $feeVisible=false;
+            unset($row[0]['fee'],$row[0]['pick_up_fee'],$row[0]['other_fee'],$row[0]['collect_fee']);
+        }
         $list=[];
         for ($i=0; $i<count($id);$i++){
             $waybill=Waybill::with(['owner', 'waybillAuditLogs' => function ($query) {
@@ -490,6 +496,9 @@ class WaybillsController extends Controller
                 'dispatchAuditor'=>isset($dispatchAuditor)?$dispatchAuditor:'',
                 'created_at'=>isset($waybill->created_at)?$waybill->created_at:''
             ];
+            if(!$feeVisible){
+                unset($w['fee'],$w['pick_up_fee'],$w['other_fee'],$w['collect_fee']);
+            }
             $list[$i]=$w;
         }
         $this->log(__METHOD__,__FUNCTION__,json_encode($waybill),Auth::user()['id']);

+ 3 - 2
app/Listeners/WaybillPriceModelListener.php

@@ -70,10 +70,11 @@ class WaybillPriceModelListener
         if ($waybills){
             foreach ($waybills as $waybill){
                 //修改运单表运费
+                $carrier=Carrier::find($waybill->carrier_id);
                 if ($waybill->carrier_weight<$waybillPriceModel->initial_weight){
-                    $fee=($waybillPriceModel->unit_price)*($waybillPriceModel->initial_weight);
+                    $fee=(($waybillPriceModel->unit_price)*($waybillPriceModel->initial_weight))+$carrier->delivery_fee;
                 }else{
-                    $fee=($waybillPriceModel->unit_price)*$waybill->carrier_weight;
+                    $fee=(($waybillPriceModel->unit_price)*$waybill->carrier_weight)+$carrier->delivery_fee;
                 }
                 $waybill->fee=$fee;
                 $waybill->save();

+ 2 - 2
database/migrations/2019_12_19_133403_change_way_bill_field.php

@@ -13,9 +13,9 @@ class ChangeWayBillField extends Migration
      */
     public function up()
     {
-/*        Schema::table('waybills', function (Blueprint $table) {
+       Schema::table('waybills', function (Blueprint $table) {
             $table->string('car_owner_info')->nullable()->comment('车辆所有人信息');
-        });*/
+        });
         Schema::table('car_types',function (Blueprint $table){
             $table->decimal('length')->nullable()->comment('车长')->change();
         });

+ 32 - 0
database/migrations/2019_12_19_170403_change_carrier_field.php

@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class ChangeCarrierField extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('carriers',function (Blueprint $table){
+            $table->decimal('delivery_fee')->nullable()->comment('送货费');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('carriers', function (Blueprint $table) {
+            $table->dropColumn('delivery_fee');
+        });
+    }
+}

+ 1 - 1
resources/views/layouts/menu.blade.php

@@ -5,7 +5,7 @@
             <li class="nav-item"><a href="{{url("rejected/")}}" class="nav-link"
                                     :class="{active:isActive('rejected',1)}">退货管理</a></li> @endcan
         @can('运单管理')
-            <li class="nav-item"><a href="{{url("waybill/")}}" class="nav-link"
+            <li class="nav-item"><a href="{{url("waybill/index")}}" class="nav-link"
                                     :class="{active:isActive('waybill',1)}">运单管理</a></li> @endcan
         @can('基础设置')
         <li class="nav-item"><a href="{{url("maintenance/")}}" class="nav-link"

+ 12 - 0
resources/views/maintenance/carrier/create.blade.php

@@ -34,6 +34,18 @@
                             @enderror
                         </div>
                     </div>
+                    <div class="form-group row">
+                        <label for="delivery_fee" class="col-2 col-form-label text-right">送货费</label>
+                        <div class="col-8">
+                            <input type="text" class="form-control @error('Carrier.delivery_fee') is-invalid @enderror"
+                                   name="Carrier[delivery_fee]" autocomplete="off" value="{{ old('Carrier')['delivery_fee'] }}" >
+                            @error('Carrier.delivery_fee')
+                            <span class="invalid-feedback" role="alert">
+                                <strong>{{ $errors->first('Carrier.delivery_fee') }}</strong>
+                            </span>
+                            @enderror
+                        </div>
+                    </div>
                     <div class="form-group row">
                         <label for="remark" class="col-2 col-form-label text-right">备注</label>
                         <div class="col-8">

+ 12 - 0
resources/views/maintenance/carrier/edit.blade.php

@@ -40,6 +40,18 @@
                             @enderror
                         </div>
                     </div>
+                    <div class="form-group row">
+                        <label for="delivery_fee" class="col-2 col-form-label text-right">送货费</label>
+                        <div class="col-8">
+                            <input type="text" class="form-control @error('Carrier.delivery_fee') is-invalid @enderror"
+                                   name="Carrier[delivery_fee]" autocomplete="off" value="{{old('Carrier')['delivery_fee']?old('Carrier')['delivery_fee']:$carrier->delivery_fee}}">
+                            @error('Carrier.delivery_fee')
+                            <span class="invalid-feedback" role="alert">
+                                <strong>{{ $errors->first('Carrier.delivery_fee') }}</strong>
+                            </span>
+                            @enderror
+                        </div>
+                    </div>
                     <div class="form-group row">
                         <label for="remark" class="col-2 col-form-label text-right">备注</label>
                         <div class="col-8">

+ 5 - 1
resources/views/maintenance/carrier/index.blade.php

@@ -17,6 +17,7 @@
                         <th>ID</th>
                         <th>承运商名称</th>
                         <th>承运商联系方式</th>
+                        <th>送货费</th>
                         <th>备注</th>
                         <th>录入时间</th>
                         <th>操作</th>
@@ -25,6 +26,7 @@
                         <td class="text-muted">@{{carrier.id}}</td>
                         <td>@{{carrier.name}}</td>
                         <td>@{{carrier.mobile}}</td>
+                        <td>@{{carrier.delivery_fee}}</td>
                         <td>@{{carrier.remark}}</td>
                         <td class="text-muted">@{{carrier.created_at}}</td>
                         <td>
@@ -48,7 +50,9 @@
             data:{
                 carriers:[
                         @foreach( $carriers as $carrier )
-                    {id:'{{$carrier->id}}',name:'{{$carrier->name}}',mobile:'{{$carrier->mobile}}',remark:'{{$carrier->remark}}',created_at:'{{$carrier->created_at}}'},
+                    {id:'{{$carrier->id}}',name:'{{$carrier->name}}',mobile:'{{$carrier->mobile}}',
+                        delivery_fee:'{{$carrier->delivery_fee}}',
+                        remark:'{{$carrier->remark}}',created_at:'{{$carrier->created_at}}'},
                     @endforeach
                 ],
             },

+ 2 - 2
resources/views/waybill/waybillFinancialSnapshot/index.blade.php

@@ -99,7 +99,7 @@
             <td>@{{json_content.waybill_id}}</td>
             <td>@{{json_content.waybill.type}}</td>
             <td>@{{json_content.waybill.waybill_number}}</td>
-            <td>@{{json_content.waybill.owner.name}}</td>
+            <td><p v-if="json_content.waybill.owner">@{{json_content.waybill.owner.name}}</p></td>
             <td>@{{json_content.waybill.wms_bill_number}}</td>
             <td>@{{json_content.waybill.origination}}</td>
             <td>@{{json_content.waybill.destination}}</td>
@@ -107,7 +107,7 @@
             <td>@{{json_content.waybill.recipient_mobile}}</td>
             <td>@{{json_content.waybill.charge}}</td>
             <td>@{{json_content.waybill.ordering_remark}}</td>
-            <td>@{{json_content.waybill.carrier.name}}</td>
+            <td><p v-if="json_content.waybill.carrier">@{{json_content.waybill.carrier.name}}</p></td>
             <td>@{{json_content.waybill.carrier_bill}}</td>
             <td><p v-if="json_content.waybill.origination_city&&json_content.waybill.origination_city.name">@{{json_content.waybill.origination_city.name}}</p> </td>
             <td><p v-if="json_content.waybill.destination_city&&json_content.waybill.destination_city.name">@{{json_content.waybill.destination_city.name}}</p> </td>