소스 검색

德邦自动获取单号

Zhouzhendong 4 년 전
부모
커밋
77d32102ef

+ 1 - 1
app/Http/ApiControllers/WaybillController.php

@@ -149,7 +149,7 @@ sql;
         if (!$deliverAt || !$fee || !is_numeric($fee) || !$fee<0)
             $this->response(false,400,"非法参数或不满足需求");
         $param=array('screenDate'=>$deliverAt,'billing'=>$fee);
-        $waybills=app('waybillService')->dailyBilling($param,true);
+        $waybills=app('WaybillService')->dailyBilling($param,true);
         if ($waybills===0 || $waybills===1 || !isset($waybills)) $this->response(false);
         $this->response(true);
     }

+ 106 - 0
app/Http/Controllers/TestController.php

@@ -133,6 +133,7 @@ use Firebase\JWT\JWT;
 use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Database\Eloquent\Collection;
 use Illuminate\Database\Eloquent\HigherOrderBuilderProxy;
+use Illuminate\Database\Eloquent\Model;
 use Illuminate\Database\QueryException;
 use Illuminate\Foundation\Http\FormRequest;
 use Illuminate\Http\Request;
@@ -211,8 +212,113 @@ class TestController extends Controller
         }
         return $update;
     }
+    /**
+     * @param Model|\stdClass $waybill
+     */
+    private function formatWaybillData($waybill):array
+    {
+        $waybill->loadMissing([
+            "order.shop","owner","order.warehouse.province","order.warehouse.city","order.warehouse.county"
+        ]);
+        $date = date('Y-m-d H:i:s', $waybill->deliver_at ? strtotime($waybill->deliver_at) : now()->getTimestamp());
+        $data =  [
+            'logisticID'    =>      config('api_logistic.DB.prod.sign').date("YmdHis").mt_rand(1000, 9999).$waybill->order->id,
+            'custOrderNo'   =>      $waybill->order->client_code ?? '',
+            'needTraceInfo' =>      config('api_logistic.DB.prod.needTraceInfo'),
+            'companyCode'   =>      config('api_logistic.DB.prod.company_code'),
+            'orderType'     =>      $waybill->order_type,
+            'transportType' =>      $waybill->transport_type,
+            'customerCode'  =>      config('api_logistic.DB.prod.customer_Code'),
+            'sender'        =>      [
+                'companyName'       => '宝时物流',
+                'businessNetworkNo' => '',
+                'name'              => '宝时物流',
+                'mobile'            => '',
+                'phone'             => '021-6316561',
+                'province'          => $waybill->order->warehouse->province->name ?? '',
+                'city'              => $waybill->order->warehouse->city->name ?? '',
+                'country'           => $waybill->order->warehouse->county->name ?? '',
+                'town'              => '',
+                'address'           => $waybill->order->warehouse->address ?? '',
+            ],
+            'receiver' => [
+                'toNetworkNo'       => '',
+                'name'              => $waybill->order->consignee_name ?? '',
+                'phone'             => $waybill->order->consignee_phone ?? '',
+                'mobile'            => $waybill->order->consignee_phone ?? '',
+                'province'          => $waybill->order->province ?? '',
+                'city'              => $waybill->order->city ?? "",
+                'county'            => $waybill->order->district ?? '',
+                'town'              => '',
+                'address'           => $waybill->order->address ?? '',
+                'companyName'       => ''
+            ],
+            'packageInfo' => [
+                'cargoName'         => $waybill->cargo_name ?? '',
+                'totalNumber'       => $waybill->total_number ?? '',
+                'totalWeight'       => $waybill->total_weight ?? '',
+                'totalVolume'       => '',
+                'packageService'    => $waybill->package_service ?? '',
+                'deliveryType'      => $waybill->deliveryType_id,
+            ],
+            'gmtCommit'     =>  $date,
+            'payType'       =>  $waybill->pay_type,
+            'addServices'   =>  [
+                'insuranceValue'    => '',
+                'codType'           => '',
+                'reciveLoanAccount' => '',
+                'accountName'       => '',
+                'codValue'          => '',
+                'backSignBill'      => $waybill->back_sign_bill
+            ],
+            'smsNotify'     => config('api_logistic.DB.prod.smsNotify'),
+            'sendStartTime' => $date,
+            'sendEndTime'   => date('Y-m-d ', $waybill->deliver_at ? strtotime($waybill->deliver_at) : now()->getTimestamp()).'23:59:59',
+            'originalWaybillNumber' => $waybill->wms_bill_number ?? '',
+            'remark'        => $waybill->dispatch_remark ?? '',
+            'isOut'         => 'N',
+            'passwordSigning' => config('api_logistic.DB.prod.passwordSigning'),
+            'isdispatched'  => '',
+            'ispresaleorder'=> '',
+            'isCenterDelivery' => '',
+//            'orderExtendFields' => [
+//                'value'     => '',
+//                'key'       => ''
+//            ]
+        ];
+        $param = json_encode($data);
+        $timestamp = (integer)getMillisecond();
+        return ["params"=>$param,"timestamp"=>$timestamp,
+            "digest"=>base64_encode(md5($param.config('api_logistic.DB.prod.app_key').$timestamp)),
+            "companyCode" => config('api_logistic.DB.prod.company_code')];
+    }
     public function test(Request $request)
     {
+        $waybill = Waybill::query()->where("waybill_number","BSDB2112284814")
+            ->first();
+        $waybill->load("order");
+        if (!$waybill->order){
+            dd("德邦单号获取失败1");
+            return;
+        }
+        $update = $this->paramDefault($waybill);
+        $waybill->update($update);
+        $bill = app('DbOpenService')->getDbOrderNo($waybill);
+        if (!$bill || $bill["result"]=="false"){
+            dd($bill);
+            return;
+        }
+        $waybill->update([
+            "carrier_bill"=>$bill['mailNo'],
+            "waybill_number"=>$bill['mailNo'],
+            "station_no"=>$bill['stationNo'],
+            "arrived_org_simple_name"=>$bill['arrivedOrgSimpleName'],
+            "much_higher_delivery"=>$bill['muchHigherDelivery'],
+        ]);
+        if (!app("WaybillService")->notifyFlux($waybill)){
+            dd("德邦单号回传FLUX失败");
+            return;
+        }
         dd(1);
         $c = "test";
         $a = function ($b)use($c){

+ 4 - 1
app/Http/Controllers/api/thirdPart/flux/WaybillController.php

@@ -102,7 +102,10 @@ class WaybillController extends Controller
                 $notes = DB::connection("oracle")->selectOne(DB::raw("SELECT notes FROM DOC_ORDER_HEADER WHERE ORDERNO = ?"),[$waybill->wms_bill_number]);
                 if ($notes)$waybill->ordering_remark = $notes->notes;
                 $order = app("OrderService")->first(["code"=>$waybill->wms_bill_number]);
-                if ($order)$waybill->order_id = $order->id;
+                if ($order){
+                    $waybill->order_id = $order->id;
+                    app("WaybillService")->autoGetDBBill($waybill);
+                }
             }
             $waybill->save();
             WaybillAuditLog::query()->create([

+ 0 - 79
app/Observers/WaybillObserver.php

@@ -1,79 +0,0 @@
-<?php
-
-namespace App\Observers;
-
-use App\Waybill;
-use Illuminate\Support\Facades\Log;
-
-class WaybillObserver
-{
-    /**
-     * 监听插入事件
-     *
-     * @param Waybill|\stdClass $waybill
-     * @return void
-     */
-    public function created(Waybill $waybill)
-    {
-        if(config('app.env')!='production')return;
-        if ($waybill->type=='德邦物流'){
-            if ($waybill->carrier_bill)return;
-            $waybill->load("order");
-            if (!$waybill->order){
-                Log::error("德邦单号获取失败",["no"=>$waybill->waybill_number,"info"=>"运单无绑定订单"]);
-                return;
-            }
-            $update = $this->paramDefault($waybill);
-            $waybill->update($update);
-            $bill = app('DbOpenService')->getDbOrderNo($waybill);
-            if (!$bill || $bill["result"]=="false"){
-                Log::error("德邦单号获取失败",["no"=>$waybill->toArray(),"info"=>$bill]);
-                return;
-            }
-            $waybill->update([
-                "carrier_bill"=>$bill['mailNo'],
-                "waybill_number"=>$bill['mailNo'],
-                "station_no"=>$bill['stationNo'],
-                "arrived_org_simple_name"=>$bill['arrivedOrgSimpleName'],
-                "much_higher_delivery"=>$bill['muchHigherDelivery'],
-            ]);
-            if (!app("WaybillService")->notifyFlux($waybill)){
-                Log::error("德邦单号回传FLUX失败",["no"=>$waybill->waybill_number,"info"=>$bill]);
-                return;
-            }
-        }
-    }
-
-    private function paramDefault(&$waybill):array
-    {
-        $update = [];
-        if (!$waybill->order_type){
-            $update["order_type"] = $waybill->order_type = Waybill::ORDER_TYPE_DEFAULT;
-        }
-        if (!$waybill->transport_type){
-            $update["transport_type"] = $waybill->transport_type = "JZKH";
-        }
-        if (!$waybill->cargo_name){
-            $update["cargo_name"] = $waybill->cargo_name = "补货";
-        }
-        if (!$waybill->total_number){
-            $update["total_number"] = $waybill->total_number = 1;
-        }
-        if (!$waybill->total_weight){
-            $update["total_weight"] = $waybill->total_weight = 1;
-        }
-        if (!$waybill->package_service){
-            $update["package_service"] = $waybill->package_service = '托膜';
-        }
-        if (!$waybill->deliveryType){
-            $update["deliveryType_id"] = $waybill->deliveryType_id = 3;
-        }
-        if (!$waybill->pay_type){
-            $update["pay_type"] = $waybill->pay_type = Waybill::PAY_TYPE_DEFAULT;
-        }
-        if (!$waybill->back_sign_bill){
-            $update["back_sign_bill"] = $waybill->back_sign_bill = Waybill::BACK_SIGN_BILL_DEFAULT;
-        }
-        return $update;
-    }
-}

+ 0 - 2
app/Providers/AppServiceProvider.php

@@ -9,7 +9,6 @@ use App\Observers\AuthorityObserver;
 use App\Observers\MenuObserver;
 use App\Observers\OwnerObserver;
 use App\Observers\UserWorkGroupObserver;
-use App\Observers\WaybillObserver;
 use App\Owner;
 use App\Services\AuthorityService;
 use App\Services\BatchService;
@@ -424,7 +423,6 @@ class AppServiceProvider extends ServiceProvider
     private function registerObserver()
     {
         Owner::observe(OwnerObserver::class);
-        Waybill::observe(WaybillObserver::class);
         UserWorkgroup::observe(UserWorkGroupObserver::class);
         Menu::observe(MenuObserver::class);
         Authority::observe(AuthorityObserver::class);

+ 2 - 2
app/Services/DbOpenService.php

@@ -75,7 +75,7 @@ class DbOpenService
     private function formatWaybillData($waybill):array
     {
         $waybill->loadMissing([
-            "order.shop","owner","order.warehouse.province","order.warehouse.city","order.warehouse.county","deliveryType"
+            "order.shop","owner","order.warehouse.province","order.warehouse.city","order.warehouse.county"
         ]);
         $date = date('Y-m-d H:i:s', $waybill->deliver_at ? strtotime($waybill->deliver_at) : now()->getTimestamp());
         $data =  [
@@ -116,7 +116,7 @@ class DbOpenService
                 'totalWeight'       => $waybill->total_weight ?? '',
                 'totalVolume'       => '',
                 'packageService'    => $waybill->package_service ?? '',
-                'deliveryType'      => $waybill->deliveryType->id ?? ''
+                'deliveryType'      => $waybill->deliveryType_id,
             ],
             'gmtCommit'     =>  $date,
             'payType'       =>  $waybill->pay_type,

+ 60 - 0
app/Services/WaybillService.php

@@ -394,4 +394,64 @@ SQL;
                ->orWhereIn("logistic_id",app("LogisticService")->getQuery());
         })->whereNotNull("deliver_at")->whereIn("status",["已审核","待终审"]);
     }
+
+    public function autoGetDBBill(Waybill $waybill){
+        if ($waybill->type=='德邦物流'){
+            if ($waybill->carrier_bill)return;
+            $waybill->load("order");
+            if (!$waybill->order){
+                Log::error("德邦单号获取失败",["no"=>$waybill->waybill_number,"info"=>"运单无绑定订单"]);
+                return;
+            }
+            list($update,$waybill) = $this->paramDefault($waybill);
+            $bill = app('DbOpenService')->getDbOrderNo($waybill);
+            if (!$bill || $bill["result"]=="false"){
+                Log::error("德邦单号获取失败",["no"=>$waybill->toArray(),"info"=>$bill]);
+                return;
+            }
+            $update["carrier_bill"] = $bill['mailNo'];
+            $update["waybill_number"] = $bill['mailNo'];
+            $update["station_no"] = $bill['stationNo'];
+            $update["arrived_org_simple_name"] = $bill['arrivedOrgSimpleName'];
+            $update["much_higher_delivery"] = $bill['muchHigherDelivery'];
+            $waybill->update($update);
+            if (!app("WaybillService")->notifyFlux($waybill)){
+                Log::error("德邦单号回传FLUX失败",["no"=>$waybill->waybill_number,"info"=>$bill]);
+                return;
+            }
+        }
+    }
+
+    private function paramDefault($waybill):array
+    {
+        $update = [];
+        if (!$waybill->order_type){
+            $update["order_type"] = $waybill->order_type = Waybill::ORDER_TYPE_DEFAULT;
+        }
+        if (!$waybill->transport_type){
+            $update["transport_type"] = $waybill->transport_type = "JZKH";
+        }
+        if (!$waybill->cargo_name){
+            $update["cargo_name"] = $waybill->cargo_name = "补货";
+        }
+        if (!$waybill->total_number){
+            $update["total_number"] = $waybill->total_number = 1;
+        }
+        if (!$waybill->total_weight){
+            $update["total_weight"] = $waybill->total_weight = 1;
+        }
+        if (!$waybill->package_service){
+            $update["package_service"] = $waybill->package_service = '托膜';
+        }
+        if (!$waybill->deliveryType_id){
+            $update["deliveryType_id"] = $waybill->deliveryType_id = 3;
+        }
+        if (!$waybill->pay_type){
+            $update["pay_type"] = $waybill->pay_type = Waybill::PAY_TYPE_DEFAULT;
+        }
+        if (!$waybill->back_sign_bill){
+            $update["back_sign_bill"] = $waybill->back_sign_bill = Waybill::BACK_SIGN_BILL_DEFAULT;
+        }
+        return array($update,$waybill);
+    }
 }