lrf 2 gadi atpakaļ
vecāks
revīzija
cbcded4346
2 mainītis faili ar 20 papildinājumiem un 10 dzēšanām
  1. 11 10
      app/service/trade/order.js
  2. 9 0
      app/service/trade/orderDetail.js

+ 11 - 10
app/service/trade/order.js

@@ -108,16 +108,6 @@ class OrderService extends CrudService {
     }
   }
 
-  async afterQuery(filter, data) {
-    data = JSON.parse(JSON.stringify(data));
-    for (const i of data) {
-      const { goods } = i;
-      const buy_num_total = goods.reduce((p, n) => this.ctx.plus(p, n.goods.reduce((np, ng) => this.ctx.plus(np, ng.buy_num), 0)), 0);
-      i.buy_num_total = buy_num_total;
-    }
-    return data;
-  }
-
   /**
    * 取消订单(支付前)
    * @param {Object} body 参数体
@@ -309,6 +299,17 @@ class OrderService extends CrudService {
     }
     return arr;
   }
+
+  async afterQuery(filter, data) {
+    data = JSON.parse(JSON.stringify(data));
+    for (const i of data) {
+      const { goods } = i;
+      const buy_num_total = goods.reduce((p, n) => this.ctx.plus(p, n.goods.reduce((np, ng) => this.ctx.plus(np, ng.buy_num), 0)), 0);
+      i.buy_num_total = buy_num_total;
+      i.real_pay = _.get(i, 'pay.pay_money');
+    }
+    return data;
+  }
 }
 
 module.exports = OrderService;

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

@@ -97,6 +97,15 @@ class OrderDetailService extends CrudService {
       const { goods } = i;
       const buy_num_total = goods.reduce((p, n) => this.ctx.plus(p, n.buy_num), 0);
       i.buy_num_total = buy_num_total;
+      let discount = 0;
+      const dd = _.get(i, 'total_detail.discount_detail', {});
+      for (const uc_id in dd) {
+        const obj = _.get(dd, uc_id, {});
+        const values = Object.values(obj);
+        const dm = values.reduce((p, n) => this.ctx.plus(p, n), 0);
+        discount = this.ctx.plus(discount, dm);
+      }
+      i.real_pay = this.ctx.minus(_.get(i, 'total_detail.goods_total'), discount);
     }
     return data;
   }