|
|
@@ -2,155 +2,45 @@
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
|
-use App\Log;
|
|
|
-use App\OracleDOCOrderHeader;
|
|
|
-use App\OrderLogistic;
|
|
|
+use App\Components\ErrorPush;
|
|
|
use App\Traits\ServiceAppAop;
|
|
|
-use App\Waybill;
|
|
|
-use Illuminate\Support\Carbon;
|
|
|
-use Illuminate\Support\Facades\DB;
|
|
|
+use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
|
|
|
class DbOpenService
|
|
|
{
|
|
|
- use ServiceAppAop;
|
|
|
+ use ServiceAppAop, ErrorPush;
|
|
|
|
|
|
protected $modelClass = DbOpenService::class;
|
|
|
|
|
|
/**
|
|
|
* 创建德邦订单,生成快递单号
|
|
|
- * @param array $params
|
|
|
+ * @param Model|\stdClass $waybill
|
|
|
+ *
|
|
|
+ * @return string|null
|
|
|
+ * @throws \Throwable
|
|
|
*/
|
|
|
- public function getDbOrderNo(array $params = []):array
|
|
|
+ public function getDbOrderNo($waybill):?string
|
|
|
{
|
|
|
- //获取系统无快递单号订单信息
|
|
|
- $order_info = Waybill::query()
|
|
|
- ->with(['owner:id,name,phone_number', 'order', 'order.shop:id,name',
|
|
|
- 'order.warehouse:id,province_id,city_id,county_id,address',
|
|
|
- 'order.warehouse.province:id,name', 'order.warehouse.city:id,name',
|
|
|
- 'order.warehouse.county:id,name', 'deliveryType:id,name'])
|
|
|
- ->where('id', '=', $params['id'])
|
|
|
- ->first();
|
|
|
- //请求德邦API 生成新订单
|
|
|
- $model = new OrderLogistic();
|
|
|
+ $waybill->loadCount(["waybillAuditLogs"=>function($query){
|
|
|
+ $query->where("audit_stage","发起德邦调度");
|
|
|
+ }]);
|
|
|
+ if ($waybill->waybill_audit_logs_count>0)return null;
|
|
|
$header = [
|
|
|
'Content-Type' => 'application/x-www-form-urlencoded;charset=utf-8',
|
|
|
"Accept" => "application/json"
|
|
|
];
|
|
|
- if ($order_info) {
|
|
|
- if (empty($order_info->order) || empty($order_info->owner) || empty($order_info->order->shop)) return ['code' => 0, 'msg' => '订单关联信息错误,请核实'];
|
|
|
- $res = $model->isExist($order_info->order->id);
|
|
|
- if (!$res || $res->status == 0 ?? 0) {
|
|
|
- $data = [
|
|
|
- 'logisticID' => config('api_logistic.DB.prod.sign') . date("YmdHis") . mt_rand(1000, 9999) . $order_info->order->id,
|
|
|
- 'custOrderNo' => $order_info->order->client_code ?? '',
|
|
|
- // 'mailNo' => '', // 不传会创建新的 运单号
|
|
|
- 'needTraceInfo' => config('api_logistic.DB.prod.needTraceInfo'),
|
|
|
- 'companyCode' => config('api_logistic.DB.prod.company_code'),
|
|
|
- 'orderType' => $order_info->order_type,
|
|
|
- 'transportType' => $order_info->transport_type,
|
|
|
- 'customerCode' => config('api_logistic.DB.prod.customer_Code'),
|
|
|
- 'sender' => [
|
|
|
- 'companyName' => $order_info->order->shop->name ?? '',
|
|
|
- 'businessNetworkNo' => '',
|
|
|
- 'name' => $order_info->owner->name ?? '',
|
|
|
- 'mobile' => $order_info->owner->phone_number ?? '',
|
|
|
- 'phone' => $order_info->owner->phone_number ?? '',
|
|
|
- 'province' => $order_info->order->warehouse->province->name ?? '',
|
|
|
- 'city' => $order_info->order->warehouse->city->name ?? '',
|
|
|
- 'country' => $order_info->order->warehouse->county->name ?? '',
|
|
|
- 'town' => '',
|
|
|
- 'address' => $order_info->order->warehouse->address ?? '',
|
|
|
- ],
|
|
|
- 'receiver' => [
|
|
|
- 'toNetworkNo' => '',
|
|
|
- 'name' => $order_info->order->consignee_name ?? '',
|
|
|
- 'phone' => $order_info->order->consignee_phone ?? '',
|
|
|
- 'mobile' => $order_info->order->consignee_phone ?? '',
|
|
|
- 'province' => $order_info->order->province ?? '',
|
|
|
- 'city' => $order_info->order->city ?? "",
|
|
|
- 'county' => $order_info->order->district ?? '',
|
|
|
- 'town' => '',
|
|
|
- 'address' => $order_info->order->address ?? '',
|
|
|
- 'companyName' => ''
|
|
|
- ],
|
|
|
- 'packageInfo' => [
|
|
|
- 'cargoName' => $order_info->cargo_name ?? '',
|
|
|
- 'totalNumber' => $order_info->total_number ?? '',
|
|
|
- 'totalWeight' => $order_info->total_weight ?? '',
|
|
|
- 'totalVolume' => '',
|
|
|
- 'packageService' => $order_info->package_service ?? '',
|
|
|
- 'deliveryType' => $order_info->deliveryType->name ?? '',
|
|
|
- ],
|
|
|
- 'gmtCommit' => date('Y-m-d H:i:s'),
|
|
|
- 'payType' => $order_info->pay_type,
|
|
|
- 'addServices' => [
|
|
|
- 'insuranceValue' => '',
|
|
|
- 'codType' => '',
|
|
|
- 'reciveLoanAccount' => '',
|
|
|
- 'accountName' => '',
|
|
|
- 'codValue' => '',
|
|
|
- 'backSignBill' => $order_info->back_sign_bill
|
|
|
- ],
|
|
|
- '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' => 'N',
|
|
|
- 'passwordSigning' => config('api_logistic.DB.prod.passwordSigning'),
|
|
|
- 'isdispatched' => '',
|
|
|
- 'ispresaleorder' => '',
|
|
|
- 'isCenterDelivery' => '',
|
|
|
- 'orderExtendFields' => [
|
|
|
- 'value' => '',
|
|
|
- 'key' => ''
|
|
|
- ]
|
|
|
- ];
|
|
|
- $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')['create_order'], $dd, $header);
|
|
|
- unset($data);
|
|
|
- $id = $params['id'];
|
|
|
- $order_no = $order_info->wms_bill_number;
|
|
|
- if (array_key_exists('result', $return)) {
|
|
|
- //请求成功 快递单号 $return['mailNo'] 请求编号 $return['uniquerRequestNumber']
|
|
|
- //返回日志记录
|
|
|
- $mail_no = $return['mailNo']??'';
|
|
|
- $add_data = [
|
|
|
- 'order_id' => $order_info->order->id,
|
|
|
- 'status' => $return['result'] == 'true' ? 1 : 0,
|
|
|
- 'code' => $mail_no ?? '',
|
|
|
- 'uniquer_request_number' => $return['uniquerRequestNumber'],
|
|
|
- 'reason' => $return['reason'] ?? '',
|
|
|
- 'created_at' => date('Y-m-d H:i:s')
|
|
|
- ];
|
|
|
- $roe = OrderLogistic::query()->insertGetId($add_data);
|
|
|
- if ($roe && $return['result'] == 'true') {
|
|
|
- DB::connection('mysql')->transaction(function () use ($id, $order_no, $mail_no) {
|
|
|
- $update_data = [
|
|
|
- 'type' => '德邦物流',
|
|
|
- 'waybill_number' => $mail_no,
|
|
|
- 'updated_at' => date('Y-m-d H:i:s')
|
|
|
- ];
|
|
|
- Waybill::query()->where('id', '=', $id)->update($update_data);
|
|
|
- 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')]);
|
|
|
- });
|
|
|
- return ['code' => 1, 'msg' => '申请德邦物流单号成功'];
|
|
|
- }
|
|
|
- }
|
|
|
- LogService::log(__METHOD__, "申请快递单号回传WMS", ['orderno' => $order_no, 'content'=> $return]);
|
|
|
- return ['code' => 0, 'msg' => $return['reason']];
|
|
|
- }
|
|
|
- elseif($res->status == 1 ?? 0 ) return ['code' => 1, 'msg'=> '德邦快递单号已存在'];
|
|
|
+ $body = $this->formatWaybillData($waybill);
|
|
|
+
|
|
|
+ try {
|
|
|
+ $response = httpPost(config('api_logistic.DB.prod.uri')['create_order'], $body, $header);
|
|
|
+ if (!$response["result"])return null;
|
|
|
+ return $response['mailNo'] ?? '';
|
|
|
+ //OracleDOCOrderHeader::query()->where('orderno', $order_no)->update(['edittime' => Carbon::now(), 'soreference5' => $mail_no]);
|
|
|
+ }catch (\Exception $e){
|
|
|
+ $this->push(__METHOD__."->".__LINE__,"德邦接口请求失败",$e->getMessage() . ' | '.json_encode($response ?? ''));
|
|
|
+ return null;
|
|
|
}
|
|
|
- return ['code' => 0, 'msg' => '订单信息错误,请核实'];
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -179,4 +69,85 @@ class DbOpenService
|
|
|
}
|
|
|
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","deliveryType"
|
|
|
+ ]);
|
|
|
+ $date = date('Y-m-d H:i:s');
|
|
|
+ $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' => $waybill->order->shop->name ?? '',
|
|
|
+ 'businessNetworkNo' => '',
|
|
|
+ 'name' => $waybill->owner->name ?? '',
|
|
|
+ 'mobile' => $waybill->owner->phone_number ?? '',
|
|
|
+ 'phone' => $waybill->owner->phone_number ?? '',
|
|
|
+ '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->name ?? '',
|
|
|
+ ],
|
|
|
+ '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' => $waybill->deliver_at ?? date("Y-m-d H:i:s", strtotime('+1 day')),
|
|
|
+ '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,1);
|
|
|
+ $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')];
|
|
|
+ }
|
|
|
}
|