Browse Source

订单详情,物流查询修改;订单详情实付金额计算添加有关返现的计算

lrf 2 years ago
parent
commit
ba29afc14d

+ 1 - 1
app/controller/trade/config/.orderDetail.js

@@ -68,7 +68,7 @@ module.exports = {
     },
   },
   sot: {
-    params: ['!id'],
+    requestBody: ['!id','goods_id'],
     service: 'searchOrderTransport',
   },
 };

+ 8 - 3
app/service/trade/orderDetail.js

@@ -17,18 +17,23 @@ class OrderDetailService extends CrudService {
     this.afterSaleModel = this.ctx.model.Trade.AfterSale;
     this.tran = new Transaction();
   }
-  async searchOrderTransport({ id }) {
+  async searchOrderTransport({ id, goods_id }) {
     const orderDetail = await this.model.findById(id);
     if (!id) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到订单信息');
     const { transport = [] } = orderDetail;
+    let toSearch = [];
+    if (goods_id) {
+      toSearch = transport.filter(f => f.goods.find(fg => fg.goods_id === goods_id));
+    } else {
+      toSearch = transport;
+    }
     const result = [];
-    for (const t of transport) {
+    for (const t of toSearch) {
       const { shop_transport_no: no, shop_transport_type: type } = t;
       if (!no || !type) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '缺少快递信息');
       const res = await this.ctx.service.util.kd100.search({ no, type });
       result.push(res);
     }
-
     return result;
   }
 

+ 26 - 21
app/service/util/orderDetail.js

@@ -21,33 +21,35 @@ class OrderDetailService extends CrudService {
     else priceKey = 'grp';
     let detail = this.moneyDetail(data);
     detail = Object.values(detail);
-    const realPay = detail.reduce((p, n) => this.ctx.plus(p, _.get(n, priceKey, 0)), 0);
+    let realPay = detail.reduce((p, n) => this.ctx.plus(p, _.get(n, priceKey, 0)), 0);
+    const at = _.get(detail, 'at', 0);
+    realPay = this.ctx.minus(realPay, at);
     return realPay;
   }
   /**
    * 按商品计算该订单详情的价格明细
    * @param {Object} data 订单详情数据
    * @return {Object} 返回{
-   *  规格id:{
-   *    sm: 规格正常销售价格(sell_money),
-   *    f: 规格运费(freight),
-   *    bn: 购买数量(buy_num),
-   *    st: 规格正常销售总价(sell_total: sm * bn)
-   *    ft: 规格运费总价(freight_total: f * bn)
-   *    gt: 商品支付原价(goods_total: st + ft)
-   *    dd: {
-   *      key:优惠券id,
-   *      value:优惠价格
-   *    },
-   *    dt: 优惠总价(d_detail的value之和)
-   *    grp:商品实际支付价格(goods_real_pay: gt - dt)
-   *    gsm:规格团购销售价格(group_sell_money)
-   *    gst: 规格团购销售总价(group_sell_total: gsm * bn)
-   *    ggt: 商品团购支付原价(goods_group_total: gst + ft)
-   *    ggrp: 商品团购实际支付价格(goods_group_real_pay: ggt - dt)
-   *
-   *  }
-   * }
+   **  规格id:{
+   **    sm: 规格正常销售价格(sell_money),
+   **    f: 规格运费(freight),
+   **    bn: 购买数量(buy_num),
+   **    st: 规格正常销售总价(sell_total: sm * bn)
+   **    ft: 规格运费总价(freight_total: f * bn)
+   **    gt: 商品支付原价(goods_total: st + ft)
+   **    dd: {
+   **      key:优惠券id,
+   **      value:优惠价格
+   **    },
+   **    dt: 优惠总价(d_detail的value之和)
+   **    grp:商品实际支付价格(goods_real_pay: gt - dt)
+   **    gsm:规格团购销售价格(group_sell_money)
+   **    gst: 规格团购销售总价(group_sell_total: gsm * bn)
+   **    ggt: 商品团购支付原价(goods_group_total: gst + ft)
+   **    ggrp: 商品团购实际支付价格(goods_group_real_pay: ggt - dt)
+   **  },
+   **  at: 活动返现总价(act.reduce)
+   ** }
    */
   moneyDetail(data) {
     if (!data) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到订单信息');
@@ -78,6 +80,9 @@ class OrderDetailService extends CrudService {
       }
       result[_id] = obj;
     }
+    const act = _.get(data, 'total_detail.act', []);
+    const at = act.reduce((p, n) => this.ctx.plus(p, n.money), 0);
+    result.at = at;
     return result;
   }
 }

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

@@ -7,7 +7,7 @@ const rkey = 'orderDetail';
 const ckey = 'trade.orderDetail';
 const keyZh = '订单详情';
 const routes = [
-  { method: 'get', path: `${rkey}/sot/:id`, controller: `${ckey}.sot`, name: `${ckey}sot`, zh: `${keyZh}查询物流` },
+  { method: 'post', path: `${rkey}/sot`, controller: `${ckey}.sot`, name: `${ckey}sot`, zh: `${keyZh}查询物流` },
   { method: 'get', path: `${rkey}`, controller: `${ckey}.index`, middleware: [ 'dealQuery' ], name: `${ckey}Query`, 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}` },