lrf 2 년 전
부모
커밋
4fc22d1c49
2개의 변경된 파일39개의 추가작업 그리고 28개의 파일을 삭제
  1. 10 8
      app/service/trade/order.js
  2. 29 20
      app/service/trade/orderDetail.js

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

@@ -496,14 +496,16 @@ class OrderService extends CrudService {
     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
-      );
+      let buy_num_total = 0;
+      for (const g of goods) {
+        const { is_set = '1' } = g;
+        if (is_set === '1') {
+          const bn = g.goods.reduce((p, n) => this.ctx.plus(p, n.buy_num), 0);
+          buy_num_total = this.ctx.plus(buy_num_total, bn);
+        } else {
+          buy_num_total = this.ctx.plus(buy_num_total, g.buy_num);
+        }
+      }
       i.buy_num_total = buy_num_total;
       i.real_pay = _.get(i, 'pay.pay_money');
     }

+ 29 - 20
app/service/trade/orderDetail.js

@@ -64,26 +64,35 @@ class OrderDetailService extends CrudService {
     // const list = [];
     const ids = [];
     for (const s of shopGoods) {
-      const shop = _.get(s, 'shop');
-      const remarks = _.get(s, 'remarks');
-      const goodsList = _.get(s, 'goods', []);
-      const detailNo = `${no}-${noTimes}`;
-      const total_detail = shopMoneyDetail[shop];
-      // 优惠部分分割
-      if (_.get(otd, 'discount_detail')) {
-        // 如果有优惠部分,那就得找,优惠里面有没有对应的商品规格
-        const discount_detail = this.getGoodsListDiscountDetail(goodsList, _.get(otd, 'discount_detail'));
-        total_detail.discount_detail = discount_detail;
+      const { is_set = '1' } = s;
+      if (is_set === '1') {
+        const shop = _.get(s, 'shop');
+        const remarks = _.get(s, 'remarks');
+        const goodsList = _.get(s, 'goods', []);
+        const detailNo = `${no}-${noTimes}`;
+        const total_detail = shopMoneyDetail[shop];
+        // 优惠部分分割
+        if (_.get(otd, 'discount_detail')) {
+          // 如果有优惠部分,那就得找,优惠里面有没有对应的商品规格
+          const discount_detail = this.getGoodsListDiscountDetail(goodsList, _.get(otd, 'discount_detail'));
+          total_detail.discount_detail = discount_detail;
+        }
+        noTimes++;
+        const obj = { ...orderDetailData, shop, goods: goodsList, no: detailNo, total_detail, remarks };
+        obj.status = '1';
+        // list.push(obj);
+        const od_id = tran.insert('OrderDetail', obj);
+        ids.push(od_id);
+      } else {
+        const shop = _.get(s, 'shop');
+        const detailNo = `${no}-${noTimes}`;
+        const total_detail = shopMoneyDetail[shop];
+        const remarks = _.get(s, 'remarks');
+        const g = _.pick(s, [ 'name', 'buy_num', 'freight', 'is_set', 'is_use', 'meta', 'sell_money', 'set_id', 'goods' ]);
+        const obj = { ...orderDetailData, shop, goods: g, no: detailNo, total_detail, remarks, status: '1' };
+        const od_id = tran.insert('OrderDetail', obj);
+        ids.push(od_id);
       }
-      noTimes++;
-      const obj = { ...orderDetailData, shop, goods: goodsList, no: detailNo, total_detail, remarks };
-      // 测试用
-      obj.status = '1';
-      // list.push(obj);
-      const od_id = tran.insert('OrderDetail', obj);
-      ids.push(od_id);
-      // 添加该商品是否和平台活动有关,做记录
-      // await this.ctx.service.trade.actOrder.create(orderDetail_id, obj, tran);
     }
     return ids;
     // await this.model.insertMany(list);
@@ -125,7 +134,7 @@ class OrderDetailService extends CrudService {
     const { _id, id } = filter;
     if (_id || id) filter = { _id: ObjectId(_id || id) };
     const { populate } = this.getRefMods();
-    let res = await this.model.findOne(filter).populate(populate).exec();
+    let res = await this.model.findOne(filter).populate(populate).lean();
     res = JSON.parse(JSON.stringify(res));
     // 找售后和评论
     const afterSale = await this.afterSaleModel.find({ order_detail: res._id });