| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- <?php
- namespace App\Services;
- use App\Components\ErrorPush;
- use App\Traits\ServiceAppAop;
- use Illuminate\Database\Eloquent\Model;
- class DbOpenService
- {
- use ServiceAppAop, ErrorPush;
- protected $modelClass = DbOpenService::class;
- /**
- * 创建德邦订单,生成快递单号
- * @param Model|\stdClass $waybill
- *
- * @return string|null
- * @throws \Throwable
- */
- public function getDbOrderNo($waybill):?array
- {
- return null;
- $header = [
- 'Content-Type' => 'application/x-www-form-urlencoded;charset=utf-8',
- "Accept" => "application/json"
- ];
- $body = $this->formatWaybillData($waybill);
- try {
- $response = httpPost(config('api_logistic.DB.prod.uri')['create_order'], $body, $header);
- if (!$response["result"]) {
- return null;
- }
- return $response ?? '';
- }catch (\Exception $e){
- $this->push(__METHOD__."->".__LINE__,"德邦接口请求失败",$e->getMessage() . ' | '.json_encode($response ?? ''));
- return null;
- }
- }
- /**
- * 根据 德邦运单号 获取 订单物流轨迹
- * @param array $params
- * @return array
- */
- public function getOrderStatus(array $params = []):array
- {
- if ( ($params['mailNo']??'') == '') return ['code' => 0 , 'msg' => '德邦运单号不能为空'];
- $header = [
- 'Content-Type' => 'application/x-www-form-urlencoded;charset=utf-8',
- "Accept" => "application/json"
- ];
- $data = [
- 'mailNo' => $params['mailNo']??''
- ];
- $param = json_encode($data, 1);
- $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(config('api_logistic.DB.prod.uri')['order_locus'], $dd, $header);
- if (array_key_exists('result', $return) && $return['result'] == 'true' && array_key_exists('resultCode', $return) && $return['resultCode'] == '1000'){
- return ['code'=> 1, 'msg'=> '正在加载中。。。', 'data' => $return['responseParam']];
- }
- return ['code' => 0, 'msg' => '暂无物流信息'];
- }
- /**
- * @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')];
- }
- }
|