lrf 2 years ago
parent
commit
74cf0616d3
2 changed files with 19 additions and 32 deletions
  1. 19 3
      app/service/group/group.js
  2. 0 29
      app/service/trade/pay.js

+ 19 - 3
app/service/group/group.js

@@ -12,6 +12,7 @@ class GroupService extends CrudService {
     this.model = this.ctx.model.Group.Group;
     this.model = this.ctx.model.Group.Group;
     this.goodsModel = this.ctx.model.Shop.Goods;
     this.goodsModel = this.ctx.model.Shop.Goods;
     this.goodsSpecModel = this.ctx.model.Shop.GoodsSpec;
     this.goodsSpecModel = this.ctx.model.Shop.GoodsSpec;
+    this.userModel = this.ctx.model.User.User;
   }
   }
 
 
   /**
   /**
@@ -20,10 +21,11 @@ class GroupService extends CrudService {
    * @param {Transaction} tran 数据库事务实例
    * @param {Transaction} tran 数据库事务实例
    */
    */
   async create(orderDetail, tran) {
   async create(orderDetail, tran) {
-    const { goods: goodsInfo, customer, shop } = orderDetail;
-    const goods_id = _.get(goodsInfo, 'goods._id');
+    const { goods: goodsInfos, customer, shop } = orderDetail;
+    const g = _.head(goodsInfos);
+    const goods_id = _.get(g, 'goods._id');
     const goods = await this.goodsModel.findById(goods_id);
     const goods = await this.goodsModel.findById(goods_id);
-    const goodsSpec_id = _.get(goodsInfo, '_id');
+    const goodsSpec_id = _.get(g, '_id');
     const goodsSpec = await this.goodsSpecModel.findById(goodsSpec_id);
     const goodsSpec = await this.goodsSpecModel.findById(goodsSpec_id);
     const person_limit = _.get(goodsSpec, 'group_config.need_person');
     const person_limit = _.get(goodsSpec, 'group_config.need_person');
     const leader = customer;
     const leader = customer;
@@ -96,6 +98,20 @@ class GroupService extends CrudService {
     }
     }
     tran.update('Group', group, updateData);
     tran.update('Group', group, updateData);
   }
   }
+
+
+  async afterQuery(filter, data) {
+    data = JSON.parse(JSON.stringify(data));
+    for (const i of data) {
+      const { persons = [] } = i;
+      for (const p of persons) {
+        const user = await this.userModel.findById(p.customer, { name: 1 });
+        p.name = _.get(user, 'name');
+      }
+    }
+
+    return data;
+  }
 }
 }
 
 
 module.exports = GroupService;
 module.exports = GroupService;

+ 0 - 29
app/service/trade/pay.js

@@ -188,35 +188,6 @@ class PayService extends CrudService {
     return data;
     return data;
   }
   }
 
 
-  /**
-   * 计算订单需支付的金额
-   * @param {Object} order 要支付的订单数据
-   */
-  getOrderNeedPay(order) {
-    let total = 0;
-    const { total_detail = {} } = order;
-    const { discount_detail, ...others } = total_detail;
-    for (const key in others) {
-      total = this.ctx.plus(total_detail[key], total);
-    }
-    // 优惠券部分
-    if (discount_detail) {
-      let totalDiscount = 0;
-      for (const uc in discount_detail) {
-        // uc:用户领取的优惠券id
-        // detail: 该优惠券下的明细
-        const detail = discount_detail[uc];
-        if (!detail) continue;
-        totalDiscount = this.ctx.plus(totalDiscount, Object.values(detail).reduce((p, n) => this.ctx.plus(p, n), 0));
-      }
-      console.log(total, totalDiscount);
-      total = this.ctx.minus(total, totalDiscount);
-      console.log(total);
-      if (total <= 0) total = 0;
-    }
-    return total;
-  }
-
   /**
   /**
    * 查询订单
    * 查询订单
    * @param {String} order_no 订单号
    * @param {String} order_no 订单号