lrf 2 سال پیش
والد
کامیت
82203e52a6

+ 4 - 0
app/controller/trade/config/.orderDetail.js

@@ -44,4 +44,8 @@ module.exports = {
       count: true,
       count: true,
     },
     },
   },
   },
+  sot: {
+    params: ['!id'],
+    service: 'searchOrderTransport',
+  },
 };
 };

+ 4 - 1
app/model/trade/orderDetail.js

@@ -1,7 +1,10 @@
 'use strict';
 'use strict';
 const Schema = require('mongoose').Schema;
 const Schema = require('mongoose').Schema;
 const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
 const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
-
+const transport = {
+  shop_transport_no: '运单号',
+  shop_transport_type: '快递公司类型',
+};
 // 订单详情
 // 订单详情
 const orderDetail = {
 const orderDetail = {
   order: { type: String, required: false, zh: '总订单', ref: 'Trade.order' }, //
   order: { type: String, required: false, zh: '总订单', ref: 'Trade.order' }, //

+ 10 - 0
app/service/trade/orderDetail.js

@@ -15,6 +15,16 @@ class OrderDetailService extends CrudService {
     this.userCouponModel = this.ctx.model.User.UserCoupon;
     this.userCouponModel = this.ctx.model.User.UserCoupon;
     this.tran = new Transaction();
     this.tran = new Transaction();
   }
   }
+  async searchOrderTransport({ id }) {
+    const orderDetail = await this.model.findById(id);
+    if (!id) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到订单信息');
+    const { transport = {} } = orderDetail;
+    const { shop_transport_no: no, shop_transport_type: type } = transport;
+    if (!no || !type) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '缺少快递信息');
+    const res = await this.ctx.service.util.kd100.search({ no, type });
+    return res;
+  }
+
 
 
   /**
   /**
    * 创建:用户支付完成后的订单
    * 创建:用户支付完成后的订单

+ 38 - 0
app/service/util/kd100.js

@@ -0,0 +1,38 @@
+'use strict';
+const { CrudService } = require('naf-framework-mongoose-free/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+const _ = require('lodash');
+const assert = require('assert');
+const crypto = require('crypto');
+
+class Kd100Service extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'kd100');
+    this.httpUtil = this.ctx.service.util.httpUtil;
+    this.kd100Api = 'https://poll.kuaidi100.com/poll/query.do';
+  }
+
+  async search({ no, type }) {
+    const customer = '5EC65D1966B410C333013563B7156AEE';
+    const key = 'jrwohIUD2299';
+    const param = { com: type, num: no };
+    const md5Str = `${JSON.stringify(param)}${key}${customer}`;
+    const sign = _.toUpper(await this.getSign(md5Str));
+    const body = { customer, sign, param: JSON.stringify(param) };
+    console.log(body);
+    const res = await this.ctx.curl(this.kd100Api, {
+      method: 'POST',
+      data: body,
+      dataType: 'json',
+      contentType: 'application/x-www-form-urlencoded',
+    });
+    if (res.status === 200) return res.data;
+  }
+
+  async getSign(data) {
+    const md5 = crypto.createHash('md5');
+    return md5.update(data).digest('hex');
+  }
+}
+
+module.exports = Kd100Service;

+ 1 - 0
app/z_router/trade/orderDetail.js

@@ -7,6 +7,7 @@ const rkey = 'orderDetail';
 const ckey = 'trade.orderDetail';
 const ckey = 'trade.orderDetail';
 const keyZh = '订单详情';
 const keyZh = '订单详情';
 const routes = [
 const routes = [
+  { method: 'get', path: `${rkey}/sot/:id`, controller: `${ckey}.sot`, name: `${ckey}sot`, zh: `${keyZh}查询物流` },
   { method: 'get', path: `${rkey}`, controller: `${ckey}.index`, name: `${ckey}Query`, zh: `${keyZh}列表查询` },
   { method: 'get', path: `${rkey}`, controller: `${ckey}.index`, name: `${ckey}Query`, zh: `${keyZh}列表查询` },
   { method: 'get', path: `${rkey}/:id`, controller: `${ckey}.show`, name: `${ckey}Show`, zh: `${keyZh}查询` },
   { method: 'get', path: `${rkey}/:id`, controller: `${ckey}.show`, name: `${ckey}Show`, zh: `${keyZh}查询` },
   { method: 'post', path: `${rkey}`, controller: `${ckey}.create`, name: `${ckey}Create`, zh: `创建${keyZh}` },
   { method: 'post', path: `${rkey}`, controller: `${ckey}.create`, name: `${ckey}Create`, zh: `创建${keyZh}` },