lrf 2 anos atrás
pai
commit
ddd702e5dd
2 arquivos alterados com 36 adições e 19 exclusões
  1. 15 6
      app/service/trade/order.js
  2. 21 13
      app/service/util/order.js

+ 15 - 6
app/service/trade/order.js

@@ -220,11 +220,6 @@ class OrderService extends CrudService {
     const customer = _.get(user, '_id');
     if (!customer) throw new BusinessError(ErrorCode.NOT_LOGIN, '未找到用户信息');
     const pageData = {};
-    // 商品总价,各店铺的价格明细
-    specsData = this.ctx.service.util.order.makeOrder_computedShopTotal(specsData);
-    const shopTotalDetail = this.ctx.service.util.order.makerOrder_computedOrderTotal(specsData);
-    pageData.goodsData = specsData;
-    pageData.orderTotal = shopTotalDetail;
     // 找到默认地址
     const address = await this.addressModel.findOne({ customer, is_default: '1' });
     pageData.address = address;
@@ -235,8 +230,22 @@ class OrderService extends CrudService {
     // 返现部分:添加推荐人信息
     const inviter = data.find(f => ObjectId.isValid(f.inviter));
     pageData.inviter = inviter;
+
+    // 商品总价,各店铺的价格明细
+    specsData = this.ctx.service.util.order.makeOrder_computedShopTotal(specsData);
+    const shopTotalDetail = this.ctx.service.util.order.makerOrder_computedOrderTotal(specsData);
     // 活动部分
-    pageData.actList = actList.filter(f => ![ '2', '3' ].includes(f.platform_act_type));
+    // 将加价购拿出来,给前端,需要特殊处理
+    pageData.actList = actList.filter(f => f.platform_act_type === '4');
+    // 满减/折 直接放在orderTotal中,作为明细,反正后面也不用
+    const daList = actList.filter(f => f.platform_act_type === '5' || f.platform_act_type === '6');
+    for (const da of daList) {
+      const obj = { zh: da.title, key: da.platform_act, money: da.discount };
+      shopTotalDetail.push(obj);
+    }
+    pageData.goodsData = specsData;
+    pageData.orderTotal = shopTotalDetail;
+
     return pageData;
   }
   /**

+ 21 - 13
app/service/util/order.js

@@ -22,14 +22,20 @@ class OrderService extends CrudService {
   makeOrder_computedShopTotal(list) {
     for (const i of list) {
       let goods_total = 0,
-        freight_total = 0;
+        freight_total = 0,
+        discount = 0;
       for (const g of i.goods) {
         // 如果有特价,那就使用特价,没有特价就是用正常销售价
         goods_total = this.ctx.plus(goods_total, _.get(g, 'price'));
         freight_total = this.ctx.plus(freight_total, _.get(g, 'freight'));
+        if (_.isArray(g.act)) {
+          const actDiscount = g.act.reduce((p, n) => this.ctx.plus(p, n.discount), 0);
+          discount = this.ctx.plus(discount, actDiscount);
+        }
       }
       i.goods_total = goods_total;
       i.freight_total = freight_total;
+      i.discount = discount;
     }
     return list;
   }
@@ -39,11 +45,10 @@ class OrderService extends CrudService {
    * list是经过 getPageData 处理过的数据
    */
   makerOrder_computedOrderTotal(list) {
-    const obj = {
-      goods_total: list.reduce((p, n) => this.ctx.plus(p, n.goods_total), 0),
-      freight_total: list.reduce((p, n) => this.ctx.plus(p, n.freight_total), 0),
-    };
-    return obj;
+    const arr = [];
+    arr.push({ key: 'goods_total', zh: '商品总价', money: list.reduce((p, n) => this.ctx.plus(p, n.goods_total), 0) });
+    arr.push({ key: 'freight_total', zh: '运费总价', money: list.reduce((p, n) => this.ctx.plus(p, n.freight_total), 0) });
+    return arr;
   }
 
   // #endregion
@@ -205,13 +210,16 @@ class OrderService extends CrudService {
    */
   dealAct_sp(goodsList, actList) {
     for (const act of actList) {
-      const { spec, sp_price } = act;
+      const { spec, sp_price, platform_act_type, platform_act } = act;
       if (!spec) continue;
       const goods = goodsList.find(f => f.goodsSpec_id === spec);
       if (goods) {
         // 默认特价为商品金额
         goods.sp_price = sp_price;
         goods.price = sp_price;
+        const { act = [] } = goods;
+        act.push({ platform_act_type, platform_act, sp_price });
+        goods.act = act;
       }
     }
   }
@@ -260,11 +268,11 @@ class OrderService extends CrudService {
               const rp = this.getGoodsPayAfterAct(gia);
               const percent = this.ctx.divide(rp, total);
               const money = this.ctx.multiply(percent, discountTotal);
-              actResult.push({ platform_act, money, goodsSpec_id });
+              actResult.push({ platform_act, platform_act_type, discount: money, goodsSpec_id });
             } else {
               const allready = actResult.reduce((p, n) => this.ctx.plus(p, n.money), 0);
               const el = this.ctx.minus(discountTotal, allready);
-              actResult.push({ platform_act, money: el, goodsSpec_id });
+              actResult.push({ platform_act, platform_act_type, discount: el, goodsSpec_id });
             }
           }
           // 修改数据
@@ -281,7 +289,7 @@ class OrderService extends CrudService {
           const text = `满${platform_act_type === '6' ? '折' : '减'}活动`;
           const actData = await this.platformActModel.findById(platform_act);
           act.title = _.get(actData, 'act_time.title', text);
-          act.discount = actResult.reduce((p, n) => this.ctx.plus(p, n.money), 0);
+          act.discount = actResult.reduce((p, n) => this.ctx.plus(p, n.discount), 0);
           break;
         }
       }
@@ -295,12 +303,12 @@ class OrderService extends CrudService {
    */
   async dealAct_gift(goodsList, actList) {
     for (const act of actList) {
-      const { spec, gift, platform_act } = act;
+      const { spec, gift, platform_act, platform_act_type } = act;
       const goodsInAct = await this.getGoodsInAct(goodsList, platform_act);
       const actResult = [];
       for (const goods of goodsInAct) {
         const { goodsSpec_id } = goods;
-        if (spec === goodsSpec_id) actResult.push({ platform_act, gift, goodsSpec_id });
+        if (spec === goodsSpec_id) actResult.push({ platform_act, platform_act_type, gift, goodsSpec_id });
       }
       for (const i of actResult) {
         const { goodsSpec_id, ...others } = i;
@@ -338,7 +346,7 @@ class OrderService extends CrudService {
    */
   getGoodsPayAfterAct(goods) {
     const { act = [], price } = goods;
-    const actDiscount = act.reduce((p, n) => this.ctx.plus(p, n.money), 0);
+    const actDiscount = act.reduce((p, n) => this.ctx.plus(p, n.discount), 0);
     const rp = this.ctx.minus(price, actDiscount);
     return rp;
   }