lrf 2 yıl önce
ebeveyn
işleme
c62785e038
2 değiştirilmiş dosya ile 20 ekleme ve 0 silme
  1. 10 0
      app/service/trade/order.js
  2. 10 0
      app/service/trade/orderDetail.js

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

@@ -107,6 +107,16 @@ 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 参数体

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

@@ -89,6 +89,16 @@ class OrderDetailService extends CrudService {
     res = await this.afterFetch(filter, res);
     return res;
   }
+
+  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.buy_num), 0);
+      i.buy_num_total = buy_num_total;
+    }
+    return data;
+  }
 }
 
 module.exports = OrderDetailService;