| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?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);
- $bill = app('DbOpenService')->getDbOrderNo($waybill);
- if (!$bill || $bill["result"]=="false"){
- Log::error("德邦单号获取失败",["no"=>$waybill->waybill_number,"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){
- $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;
- }
- }
|