Przeglądaj źródła

运输管理 德邦物流 申请 德邦快递单号

king 4 lat temu
rodzic
commit
ef46d92145

+ 16 - 0
app/DeliveryType.php

@@ -0,0 +1,16 @@
+<?php
+
+namespace App;
+
+use App\Traits\ModelTimeFormat;
+use Illuminate\Database\Eloquent\Model;
+
+use App\Traits\ModelLogChanging;
+
+class DeliveryType extends Model
+{
+    use ModelLogChanging;
+    use ModelTimeFormat;
+
+    protected $fillable = ['id', 'name', 'status'];
+}

+ 25 - 2
app/Http/Controllers/WaybillController.php

@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
 
 use App\CarType;
 use App\Components\AsyncResponse;
+use App\Logistic;
 use App\Region;
 use App\Services\CarTypeService;
 use App\Services\LogisticService;
@@ -105,7 +106,8 @@ class WaybillController extends Controller
         $cities=app("RegionService")->getSelection(2);
         $units=$unitService->getSelection();
         $carTypes=$carTypeService->getSelection();
-        return view('transport.waybill.edit',['waybill'=>$waybill,'logistics'=>$logisticService->getSelection(["id","name"],"物流"),'cities'=>$cities,'units'=>$units,'carTypes'=>$carTypes]);
+        $deliveryType = app('DeliveryTypeService')->getSelection();
+        return view('transport.waybill.edit',['waybill'=>$waybill,'logistics'=>$logisticService->getSelection(["id","name"],"物流"),'cities'=>$cities,'units'=>$units,'carTypes'=>$carTypes,'deliveryTypes'=>$deliveryType]);
     }
 
     public function update(Request $request, $id,WaybillPriceModelService $waybillPriceModelService,
@@ -169,7 +171,13 @@ class WaybillController extends Controller
             'audit_stage'=>'发起调度',
             'user_id'=>Auth::id(),
         ]);
-        return redirect('transport/waybill/index')->with('successTip','运单“'.$waybill->waybill_number.'”调度成功');
+        //todo 若是德邦物流 请求API创建快递单号
+        $logistic_ids = Logistic::query()->where('name','like', '德邦%')->pluck('id')->toArray();
+        if (in_array($request['logistic_id'], $logistic_ids)){
+            $row = app('DbOpenService')->getDbOrderNo(['id' => $id]);
+            if ($row == 'false') $msg = '-- 生成德邦快递单号失败,请核实参数重新调度';
+        }
+        return redirect('transport/waybill/index')->with('successTip','运单“'.$waybill->waybill_number.'”调度成功 '. ($msg??''));
     }
 
     public function checkWaybillPriceModel($logistic_id,$destination_city_id,$carrier_weight,$carrier_weight_unit_id){
@@ -283,6 +291,13 @@ class WaybillController extends Controller
         $validatorData=["logistic_id"=>$logistic_id,"destination_city_id"=>$destination_city_id,
             'carrier_weight'=>$carrier_weight[0],"carrier_weight_unit_id"=>$carrier_weight_unit_id[0],
             "carrier_weight_other"=>$carrier_weight[1],"carrier_weight_unit_id_other"=>$carrier_weight_unit_id[1]];
+        if (in_array($logistic_id,[14,15,28,29])){
+            $flag = 1;
+            $validatorData['cargo_name'] = $request->input('cargo_name');
+            $validatorData['total_number'] = $request->input('total_number');
+            $validatorData['total_weight'] = $request->input('total_weight');
+            $validatorData['deliveryType_id'] = $request->input('deliveryType_id');
+        }else $flag = 0;
         $errors=Validator::make($validatorData,[
             'logistic_id'=>'required|integer',
             'destination_city_id'=>'required|integer',
@@ -290,6 +305,10 @@ class WaybillController extends Controller
             'carrier_weight_unit_id'=>'required_with:carrier_weight',
             'carrier_weight_other'=>'nullable|min:0|numeric|max:999999',
             'carrier_weight_unit_id_other'=>'required_with:carrier_weight_other',
+            'cargo_name' => $flag ? 'required' : '',
+            'total_number' => $flag ? 'required|min:0|numeric|max:999999' : '',
+            'total_weight' => $flag ? 'required|min:0|numeric|max:999999' : '',
+            'deliveryType_id' => $flag ? 'required' : '',
         ],[
             'required'=>':attribute 为必填项',
             'max'=>':attribute 字符过多或输入值过大',
@@ -305,6 +324,10 @@ class WaybillController extends Controller
             'carrier_weight_unit_id'=>'承运商计数单位',
             'carrier_weight_other'=>'承运商计数二',
             'carrier_weight_unit_id_other'=>'承运商计数单位二',
+            'cargo_name' =>  '货物名称',
+            'total_number' =>  '总包裹数',
+            'total_weight' =>  '总重量',
+            'deliveryType_id' => '送货方式',
         ])->errors();
         if (count($errors)>0)return ['error'=>$errors];
         $result=$this->checkWaybillPriceModel($logistic_id,$destination_city_id,$carrier_weight,$carrier_weight_unit_id);

+ 32 - 0
app/OrderLogistic.php

@@ -0,0 +1,32 @@
+<?php
+
+namespace App;
+
+use App\Services\DbOpenService;
+use App\Traits\ModelTimeFormat;
+use Illuminate\Database\Eloquent\Model;
+
+use App\Traits\ModelLogChanging;
+use Illuminate\Support\Facades\DB;
+
+class OrderLogistic extends Model
+{
+    use ModelLogChanging;
+    use ModelTimeFormat;
+
+    protected $fillable = [
+        'id',
+        'order_id',
+        'order_package_id',
+        'status',
+        'code',
+        'created_at'
+    ];
+
+
+    public function isExist($id= 0)
+    {
+        if (empty($id)) return false;
+        return OrderLogistic::query()->selectRaw('id,status')->where('order_id','=',$id)->orderByDesc('id')->first();
+    }
+}

+ 4 - 0
app/Providers/AppServiceProvider.php

@@ -148,6 +148,8 @@ use App\Services\OwnerLogisticFeeReportService;
 use App\Services\LogisticSyncRecordService;
 use App\Services\OwnerBillReportArchiveService;
 use App\Services\SettlementBillsAreaFeeService;
+use App\Services\DbOpenService;
+use App\Services\DeliveryTypeService;
 
 class AppServiceProvider extends ServiceProvider
 {
@@ -230,7 +232,9 @@ class AppServiceProvider extends ServiceProvider
         app()->singleton('CustomerLogStatusService',CustomerLogStatusService::class);
         app()->singleton('CustomerService',CustomerService::class);
         app()->singleton('DataHandlerService',DataHandlerService::class);
+        app()->singleton('DbOpenService',DbOpenService::class);
         app()->singleton('DeliveryAppointmentService',DeliveryAppointmentService::class);
+        app()->singleton('DeliveryTypeService',DeliveryTypeService::class);
         app()->singleton('DemandProcessService',DemandProcessService::class);
         app()->singleton('DemandService',DemandService::class);
         app()->singleton('DepositoryService',DepositoryService::class);

+ 143 - 0
app/Services/DbOpenService.php

@@ -0,0 +1,143 @@
+<?php
+
+namespace App\Services;
+
+use App\OracleDOCOrderHeader;
+use App\OrderLogistic;
+use App\Traits\ServiceAppAop;
+use App\Waybill;
+use Illuminate\Support\Carbon;
+use Illuminate\Support\Facades\DB;
+
+
+class DbOpenService
+{
+    use ServiceAppAop;
+
+    protected $modelClass = DbOpenService::class;
+
+    /**
+     * 创建德邦订单,生成快递单号
+     * @param array $params
+     */
+    public function getDbOrderNo($params = [])
+    {
+        //获取系统无快递单号订单信息
+        $order_info = Waybill::query()
+            ->with(['owner:id,name,phone_number', 'orderByCode', 'orderByCode.shop:id,name',
+                'orderByCode.warehouse:id,province_id,city_id,county_id,address',
+                'orderByCode.warehouse.province:id,name', 'orderByCode.warehouse.city:id,name',
+                'orderByCode.warehouse.county:id,name', 'deliveryType:id,name'])
+            ->where('id', '=', $params['id'])
+            ->first();
+        //请求德邦API 生成新订单
+        $model = new OrderLogistic();
+        $uri = "http://dpsanbox.deppon.com/sandbox-web/dop-standard-ewborder/createOrderNotify.action";
+        $header = [
+            'Content-Type' => 'application/x-www-form-urlencoded;charset=utf-8',
+            "Accept" => "application/json"
+        ];
+        if ($order_info) {
+            if (empty($order_info->orderByCode)) return false;
+            $res = $model->isExist($order_info->orderByCode->id);
+            if (!$res || $res->status == 0 ?? 0) {
+                $data = [
+                    'logisticID' => config('api_logistic.DB.prod.sign') . date("YmdHis") . mt_rand(1000, 9999) . $order_info->orderByCode->id,
+                    'custOrderNo' => $order_info->orderByCode->client_code ?? '',
+                    // 'mailNo' => '',  // 不传会创建新的 运单号
+                    'needTraceInfo' => config('api_logistic.DB.prod.needTraceInfo'),
+                    'companyCode' => config('api_logistic.DB.prod.company_code'),
+                    'orderType' => config('api_logistic.DB.prod.orderType'),
+                    'transportType' => config('api_logistic.DB.prod.transportType'),
+                    'customerCode' => config('api_logistic.DB.prod.customer_Code'),
+                    'sender' => [
+                        'companyName' => $order_info->orderByCode->shop->name ?? '',
+                        'businessNetworkNo' => '',
+                        'name' => $order_info->owner->name ?? '',
+                        'mobile' => $order_info->owner->phone_number ?? '',
+                        'phone' => $order_info->owner->phone_number ?? '',
+                        'province' => $order_info->orderByCode->warehouse->province->name ?? '',
+                        'city' => $order_info->orderByCode->warehouse->city->name ?? '',
+                        'country' => $order_info->orderByCode->warehouse->county->name ?? '',
+                        'town' => '',
+                        'address' => $order_info->orderByCode->warehouse->address ?? '',
+                    ],
+                    'receiver' => [
+                        'toNetworkNo' => '',
+                        'name' => $order_info->orderByCode->consignee_name ?? '',
+                        'phone' => $order_info->orderByCode->consignee_phone ?? '',
+                        'mobile' => $order_info->orderByCode->consignee_phone ?? '',
+                        'province' => $order_info->orderByCode->province ?? '',
+                        'city' => $order_info->orderByCode->city ?? "",
+                        'county' => $order_info->orderByCode->district ?? '',
+                        'town' => '',
+                        'address' => $order_info->orderByCode->address ?? '',
+                        'companyName' => ''
+                    ],
+                    'packageInfo' => [
+                        'cargoName' => $order_info->cargo_name ?? '',
+                        'totalNumber' => $order_info->total_number ?? '',
+                        'totalWeight' => $order_info->total_weight ?? '',
+                        'totalVolume' => '',
+                        'packageService' => '',
+                        'deliveryType' => $order_info->deliveryType->name ?? '',
+                    ],
+                    'gmtCommit' => date('Y-m-d H:i:s'),
+                    'payType' => config('api_logistic.DB.prod.payType'),
+                    'addServices' => [
+                        'insuranceValue' => '',
+                        'codType' => '',
+                        'reciveLoanAccount' => '',
+                        'accountName' => '',
+                        'codValue' => '',
+                        'backSignBill' => config('api_logistic.DB.prod.backSignBill')
+                    ],
+                    'smsNotify' => config('api_logistic.DB.prod.smsNotify'),
+                    'sendStartTime' => date("Y-m-d H:i:s"),
+                    'sendEndTime' => $order_info->deliver_at ?? date("Y-m-d H:i:s", strtotime('+1 day')),
+                    'originalWaybillNumber' => $order_info->wms_bill_number ?? '',
+                    'remark' => $order_info->dispatch_remark ?? '',
+                    'isOut' => '',
+                    'passwordSigning' => config('api_logistic.DB.prod.passwordSigning'),
+                    'isdispatched' => '',
+                    'ispresaleorder' => '',
+                    'isCenterDelivery' => '',
+                    'orderExtendFields' => [
+                        'value' => '',
+                        'key' => ''
+                    ]
+                ];
+                $param = json_encode($data, true);
+                $dd["params"] = $param;
+                $dd["timestamp"] = (integer)getMillisecond();
+                $dd["digest"] = base64_encode(md5($param . config('api_logistic.DB.prod.app_key') . $dd['timestamp']));
+                $dd["companyCode"] = config('api_logistic.DB.prod.company_code');
+                $return = httpPost($uri, $dd, $header);
+                unset($data);
+                if (array_key_exists('result', $return)) {
+                    //请求成功  快递单号 $return['mailNo']   请求编号 $return['uniquerRequestNumber']
+                    $add_data = [
+                        'order_id' => $order_info->orderByCode->id,
+                        'status' => $return['result'] == 'true' ? 1 : 0,
+                        'code' => $return['mailNo'] ?? '',
+                        'uniquer_request_number' => $return['uniquerRequestNumber'],
+                        'reason' => $return['reason'] ?? '',
+                        'created_at' => date('Y-m-d H:i:s')
+                    ];
+                    $roe = OrderLogistic::query()->insertGetId($add_data);
+                    //成功
+                    if ($return['result'] == 'true' && $roe) {
+                        $order_no = $order_info->wms_bill_number;
+                        $mail_no = $return['mailNo'];
+                        $row = DB::connection('oracle')->transaction(function () use ($order_no, $mail_no) {
+                            OracleDOCOrderHeader::query()->where('orderno', $order_no)->update(['edittime' => Carbon::now(), 'soreference5' => $mail_no]);
+                            LogService::log(__METHOD__, "申请快递单号回传WMS", ['orderno' => $order_no, 'soreference5' => $mail_no, 'edittime' => date('Y-m-d H:i:s')]);
+                        });
+                        if ($row) return true;
+                    }
+                }
+            }
+        }
+        return false;
+    }
+}

+ 18 - 0
app/Services/DeliveryTypeService.php

@@ -0,0 +1,18 @@
+<?php
+
+namespace App\Services;
+
+use App\Traits\ServiceAppAop;
+use App\DeliveryType;
+
+class DeliveryTypeService
+{
+    use ServiceAppAop;
+    protected $modelClass=DeliveryType::class;
+
+    public function getSelection($column = ['id', 'name'])
+    {
+        if (!is_array($column)) $column = [$column];
+        return DeliveryType::query()->select($column)->where('status', '=', 0)->get();
+    }
+}

+ 20 - 0
app/Utils/helpers.php

@@ -58,3 +58,23 @@ function diff($array1,$array2,string $identification,array $mapping,bool $intact
     }
     return $changes;
 }
+
+//**官方的时间戳是13位的而php一般都是11位的所以需要进行处理一下**
+function getMillisecond():string
+{
+    list($t1, $t2) = explode(' ', microtime());
+    return (float)sprintf('%.0f',(floatval($t1)+floatval($t2))*1000);
+}
+
+function httpPost($uri = '', $body = '', $header = ''):array
+{
+    $client = new \GuzzleHttp\Client([
+        'base_uri' => $uri
+    ]);
+    $res = $client->post($uri, [
+        'header' => $header,
+        'form_params' => $body
+    ]);
+    $data = $res->getBody()->getContents();
+    return json_decode($data,  true);
+}

+ 14 - 1
app/Warehouse.php

@@ -12,9 +12,22 @@ class Warehouse extends Model
     use ModelLogChanging;
 
     use ModelTimeFormat;
-    protected $fillable=['name','code',"production_capacity","reduced_production_capacity_coefficient","address","principal","phone"];
+    protected $fillable=['name','code',"production_capacity","reduced_production_capacity_coefficient","address","principal","phone","province_id","city_id","county_id"];
 
     public function userWorkgroups(){
         return $this->hasMany('App\UserWorkgroup');
     }
+
+    public function province()
+    {   //省
+        return $this->belongsTo(Region::class)->where("type",1);
+    }
+    public function city()
+    {   //市
+        return $this->belongsTo(Region::class)->where("type",2);
+    }
+    public function county()
+    {   //区县
+        return $this->belongsTo(Region::class)->where("type",3);
+    }
 }

+ 13 - 1
app/Waybill.php

@@ -59,7 +59,11 @@ class Waybill extends Model
         'deliver_at',
         "district_id",
         "order_id",
-        "is_to_pay" //0否 1是
+        "is_to_pay", //0否 1是
+        'cargo_name',
+        'total_number',
+        'total_weight',
+        'deliveryType_id'
     ];
 
     public function district()
@@ -114,6 +118,14 @@ class Waybill extends Model
     {   //订单
         return $this->belongsTo(Order::class);
     }
+    public function orderByCode()
+    {   //订单
+        return $this->hasOne(Order::class,'code','wms_bill_number');
+    }
+    public function deliveryType()
+    {   //订单
+        return $this->hasOne(DeliveryType::class,'id','deliveryType_id');
+    }
 
 
 

+ 34 - 0
config/api_logistic.php

@@ -167,4 +167,38 @@ return [
     ],
     'init_date' => '2021-05-17 23:59:59',
     'querying_days' => 15,
+    'DB' => [
+        'test'=>[
+            'app_key' => 'bb4e6c0b24794795c306b3461f5470d3',
+            'company_code' => 'EWBSHBSGYLGLYXGS',
+            'customer_Code' => 'F2015082279473065',
+            'sign' => 'IYKO',
+            'needTraceInfo' => 0, //是否需要订阅轨迹 1:是 2:否
+            'orderType' => 2, //下单模式 1:散客模式 2:大客户模式 3:同步筛单下单
+            'transportType' => 'JJDJ', //运输方式/产品类型 快递运输方式 : RCP:大件快递360; NZBRH:重包入户; ZBTH:重包特惠; WXJTH:微小件特惠; JJDJ:经济大件; PACKAGE:标准快递; DEAP:特准快件;HKDJC:航空大件次日达; HKDJG:航空大件隔日达; TZKJC:特快专递; 零担运输方式: JZKY:精准空运(仅散客模式支持该运输方式); JZQY_LONG:精准汽运; JZKH:精准卡航; 整车运输方式 1.整车配送 ZCPS 2.精准专车 JZZHC
+            'payType' => 2, //支付方式  0、发货人付款(现付)(大客户模式不支持寄付) 1、收货人付款(到付) 2、发货人付款(月结)
+            'backSignBill' => 2, //运输方式/产品类型 1:散客模式 2:大客户模式 3:同步筛单下单
+            'smsNotify' => 'N', //短信通知  Y:需要 N: 不需要
+            'passwordSigning' => 'N', //是否口令签收 仅适用于快递,Y:需要 N: 不需要;若为Y,必须收货人提供验证码给快递员才能签收,该服务是有偿的,具体费用请让我司收货营业部联系张宁(491407),请慎重使用!
+            'uri' => [
+                'create_order' => 'http://dpsanbox.deppon.com/sandbox-web/dop-standard-ewborder/createOrderNotify.action',
+            ]
+        ],
+        'prod'=>[
+            'app_key' => 'bb4e6c0b24794795c306b3461f5470d3',
+            'company_code' => 'EWBSHBSGYLGLYXGS',
+            'customer_Code' => 'F2015082279473065',
+            'sign' => 'IYKO',
+            'needTraceInfo' => 0, //是否需要订阅轨迹 1:是 2:否
+            'orderType' => 2, //下单模式 1:散客模式 2:大客户模式 3:同步筛单下单
+            'transportType' => 'JJDJ', //运输方式/产品类型 快递运输方式 : RCP:大件快递360; NZBRH:重包入户; ZBTH:重包特惠; WXJTH:微小件特惠; JJDJ:经济大件; PACKAGE:标准快递; DEAP:特准快件;HKDJC:航空大件次日达; HKDJG:航空大件隔日达; TZKJC:特快专递; 零担运输方式: JZKY:精准空运(仅散客模式支持该运输方式); JZQY_LONG:精准汽运; JZKH:精准卡航; 整车运输方式 1.整车配送 ZCPS 2.精准专车 JZZHC
+            'payType' => 2, //支付方式  0、发货人付款(现付)(大客户模式不支持寄付) 1、收货人付款(到付) 2、发货人付款(月结)
+            'backSignBill' => 2, //运输方式/产品类型 1:散客模式 2:大客户模式 3:同步筛单下单
+            'smsNotify' => 'N', //短信通知  Y:需要 N: 不需要
+            'passwordSigning' => 'N', //是否口令签收 仅适用于快递,Y:需要 N: 不需要;若为Y,必须收货人提供验证码给快递员才能签收,该服务是有偿的,具体费用请让我司收货营业部联系张宁(491407),请慎重使用!
+            'uri' => [
+                'create_order' => 'http://dpsanbox.deppon.com/sandbox-web/dop-standard-ewborder/createOrderNotify.action',
+            ]
+        ]
+    ],
 ];

+ 1 - 1
config/users.php

@@ -3,7 +3,7 @@
 return [
 
 
-    'superAdmin' => ['ldaaww','baoshi56','周亚萍','shiyao','zhouzhendong','胡浩','zengjun','阿珺','huhao','yang'],
+    'superAdmin' => ['ldaaww','baoshi56','周亚萍','shiyao','zhouzhendong','胡浩','zengjun','阿珺','huhao','yang','king'],
     'token_expire_minutes'=>7200,
     'token_check_in_expire_minutes'=>432000, //打卡过期时间,单位为秒
     'cookie_expire_minutes'=>7200,//cookie过期时间,单位分钟

+ 37 - 0
database/migrations/2021_07_06_163708_create_order_logistics_table.php

@@ -0,0 +1,37 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateOrderLogisticsTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('order_logistics', function (Blueprint $table) {
+            $table->id()->comment('订单order 申请 快递单号 记录表');
+            $table->unsignedBigInteger('order_id')->index()->comment('orders id');
+            $table->unsignedBigInteger('order_package_id')->index()->nullable()->comment('order_package id');
+            $table->unsignedTinyInteger('status')->comment('是否请求快递API:  0:否  1:是');
+            $table->string('code')->nullable()->comment('快递单号');
+            $table->string('uniquer_request_number')->nullable()->comment('请求唯一编号');
+            $table->string('reason', 500)->nullable()->comment('错误原因');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('order_logistics');
+    }
+}

+ 34 - 0
database/migrations/2021_07_07_103716_change_warehouses_table.php

@@ -0,0 +1,34 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class ChangeWarehousesTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('warehouses', function (Blueprint $table) {
+            $table->addColumn('bigInteger','province_id')->nullable();
+            $table->addColumn('bigInteger','city_id')->nullable();
+            $table->addColumn('bigInteger','county_id')->nullable();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('warehouses', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 34 - 0
database/migrations/2021_07_07_144202_create_delivery_types_table.php

@@ -0,0 +1,34 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateDeliveryTypeTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('delivery_types', function (Blueprint $table) {
+            $table->id()->comment('送货方式 表');
+            $table->string('name')->comment('送货方式');
+            $table->unsignedTinyInteger('status')->default(0)->comment('是否删除:  0:否  1:是');
+            $table->softDeletes();
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('delivery_types');
+    }
+}

+ 35 - 0
database/migrations/2021_07_07_164742_change_waybills_add_db_table.php

@@ -0,0 +1,35 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class ChangeWaybillsAddDbTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('waybills', function (Blueprint $table) {
+            $table->string('cargo_name')->nullable()->comment('活动名称');
+            $table->integer('total_number')->nullable()->comment('总包裹数');
+            $table->unsignedDouble('total_weight',5,2)->nullable()->comment('总重量');
+            $table->unsignedInteger('deliveryType_id')->nullable()->comment('送货方式');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('waybills', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 77 - 10
resources/views/transport/waybill/edit.blade.php

@@ -144,6 +144,58 @@
                             <strong class="">@{{ errors['logistic_id'][0] }}</strong>
                         </div>
                     </div>
+                    <div  v-if="waybill.logistic_id == 14 ||  waybill.logistic_id == 15 || waybill.logistic_id == 28 || waybill.logistic_id == 29">
+                        <div class="form-group row">
+                            <label for="" class="col-2 col-form-label text-right text-primary">货物名称 *</label>
+                            <div class="col-2">
+                                <input type="text" class="form-control @error('cargo_name') is-invalid @enderror "
+                                       :class="errors['cargo_name'] ? 'is-invalid' :''"
+                                name="cargo_name" autocomplete="off" v-model="waybill.cargo_name" id="cargo_name">
+                                @error('cargo_name')
+                                <span class="invalid-feedback" role="alert">
+                                    <strong>{{ $message }}</strong>
+                                </span>
+                                @enderror
+                            </div>
+                            <label for="" class="col-2 col-form-label text-right text-primary">总包裹数(件) *</label>
+                            <div class="col-2">
+                                <input type="number" class="form-control @error('total_number') is-invalid @enderror "
+                                       :class="errors['total_number'] ? 'is-invalid' :''"
+                                       name="total_number" autocomplete="off" v-model="waybill.total_number" id="total_number">
+                                @error('total_number')
+                                <span class="invalid-feedback" role="alert">
+                                    <strong>{{ $message }}</strong>
+                                </span>
+                                @enderror
+                            </div>
+                        </div>
+                        <div class="form-group row">
+                            <label for="" class="col-2 col-form-label text-right text-primary">总重量(kg) *</label>
+                            <div class="col-2">
+                                <input type="number" class="form-control @error('total_weight') is-invalid @enderror "
+                                       :class="errors['total_weight'] ? 'is-invalid' :''"
+                                       name="total_weight" autocomplete="off" v-model="waybill.total_weight" id="total_weight">
+                                @error('total_weight')
+                                <span class="invalid-feedback" role="alert">
+                                    <strong>{{ $message }}</strong>
+                                </span>
+                                @enderror
+                            </div>
+                            <label for="" class="col-2 col-form-label text-right text-primary">送货方式 *</label>
+                            <div class="col-6">
+                                <select class="form-control col-4 @error('deliveryType_id') is-invalid @enderror" name="deliveryType_id"
+                                        :class="errors['deliveryType_id'] ? 'is-invalid' :''"
+                                        style="width: 30%;"   v-model="waybill.deliveryType_id" id="deliveryType_id">
+                                    <option v-for="deliveryType in deliveryTypes" :value="deliveryType.id">@{{ deliveryType.name }}</option>
+                                </select>
+                                @error('deliveryType_id')
+                                <span class="invalid-feedback" role="alert">
+                                    <strong>{{ $message }}</strong>
+                                </span>
+                                @enderror
+                            </div>
+                        </div>
+                    </div>
                     <div v-if="waybill.type=='专线'">
                         <div class="form-group row">
                             <label for="origination_city_id" class="col-2 col-form-label text-right text-primary">始发市 *</label>
@@ -383,6 +435,7 @@
                 units:[@foreach($units as $unit){id:'{{$unit->id}}',name:'{{$unit->name}}',},@endforeach],
                 logistics:[@foreach($logistics as $logistic){id:'{{$logistic->id}}',name:'{{$logistic->name}}',},@endforeach],
                 carTypes:[@foreach($carTypes as $carType){!! $carType !!},@endforeach],
+                deliveryTypes:[@foreach($deliveryTypes as $deliveryType){!! $deliveryType !!},@endforeach],
                 errors:[],
                 waybill:{
                     id:'{{$waybill->id}}',
@@ -420,6 +473,10 @@
                     carrier_weight_unit_id_other:'{{$waybill->carrier_weight_unit_id_other}}',
                     pick_up_fee:'{{$waybill->pick_up_fee}}',
                     province:"",
+                    cargo_name: '{{ old("cargo_name") ?? $waybill->cargo_name}}',
+                    total_number: '{{ old("total_number") ?? $waybill->total_number}}',
+                    total_weight: '{{ old("total_weight") ?? $waybill->total_weight}}',
+                    deliveryType_id: '{{ old("deliveryType_id") ?? $waybill->deliveryType_id}}',
                 },
                 order:{!! $waybill->order ?? '{}' !!},
                 waybillTemp:{!! $waybill !!},
@@ -522,13 +579,14 @@
             },
             methods:{
                 {{--计费模型阶段保留--}}
-                is_waybillPriceModel(logistic_id,carrier_weight,carrier_weight_unit_id,destination_city_id,carrier_weight_other,carrier_weight_unit_id_other){
+                is_waybillPriceModel(logistic_id,carrier_weight,carrier_weight_unit_id,destination_city_id,carrier_weight_other,carrier_weight_unit_id_other,cargo_name,total_number,total_weight,deliveryType_id){
                     this.errors=[];
                     let url='{{url('transport/waybill/is/waybillPriceModel')}}';
 
                     let _this=this;
                     axios.post(url,{logistic_id:logistic_id,carrier_weight:[carrier_weight,carrier_weight_other],
-                        carrier_weight_unit_id:[carrier_weight_unit_id,carrier_weight_unit_id_other],destination_city_id:destination_city_id})
+                        carrier_weight_unit_id:[carrier_weight_unit_id,carrier_weight_unit_id_other],destination_city_id:destination_city_id,
+                        cargo_name:cargo_name, total_number:total_number,total_weight:total_weight, deliveryType_id:deliveryType_id})
                         .then(
                             function (response) {
 
@@ -558,15 +616,24 @@
                 },
                 submitForm(){
                     let type=this.waybill.type;
+                    let  logistic_id=document.getElementById('logistic_id').value;
+                    let carrier_weight = '',carrier_weight_unit_id='',destination_city_id='',carrier_weight_other='',carrier_weight_unit_id_other='',
+                        cargo_name = '',total_number='',total_weight='',deliveryType_id='';
+                    if ( $.inArray(logistic_id, ['14','15','28','29']) >= 0 ){
+                        cargo_name=document.getElementById('cargo_name').value;
+                        total_number=document.getElementById('total_number').value;
+                        total_weight=document.getElementById('total_weight').value;
+                        deliveryType_id=document.getElementById('deliveryType_id').value;
+                    }
                     if (type==='专线'){
-                        let  logistic_id=document.getElementById('logistic_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=document.getElementById('destination_city_id').value;
-                        let carrier_weight_other=document.getElementById('carrier_weight_other').value;
-                        let carrier_weight_unit_id_other=document.getElementById('carrier_weight_unit_id_other').value;
-                        this.is_waybillPriceModel(logistic_id,carrier_weight,carrier_weight_unit_id,destination_city_id,carrier_weight_other,carrier_weight_unit_id_other);
-                    }else {
+                        carrier_weight=document.getElementById('carrier_weight').value;
+                        carrier_weight_unit_id=document.getElementById('carrier_weight_unit_id').value;
+                        destination_city_id=document.getElementById('destination_city_id').value;
+                        carrier_weight_other=document.getElementById('carrier_weight_other').value;
+                        carrier_weight_unit_id_other=document.getElementById('carrier_weight_unit_id_other').value;
+                        this.is_waybillPriceModel(logistic_id,carrier_weight,carrier_weight_unit_id,destination_city_id,carrier_weight_other,carrier_weight_unit_id_other,cargo_name,total_number,total_weight,deliveryType_id);
+                    } else {
+                        this.is_waybillPriceModel(logistic_id,carrier_weight,carrier_weight_unit_id,destination_city_id,carrier_weight_other,carrier_weight_unit_id_other,cargo_name,total_number,total_weight,deliveryType_id);
                         document.getElementById('deliver_at').value= document.getElementById('deliver_at_date').value+' '+ document.getElementById('deliver_at_time').value;
                         this.executeSubmit();
                     }