Browse Source

bug:数量没进入计算

lrf 2 years ago
parent
commit
ecb6349815
1 changed files with 17 additions and 21 deletions
  1. 17 21
      app/service/util/order.js

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

@@ -26,8 +26,8 @@ class OrderService extends CrudService {
         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'));
+        goods_total = this.ctx.plus(goods_total, this.ctx.multiply(_.get(g, 'price'), _.get(g, 'num')));
+        freight_total = this.ctx.plus(freight_total, this.ctx.multiply(_.get(g, 'freight'), _.get(g, 'num')));
         if (_.isArray(g.act)) {
           const actDiscount = g.act.reduce((p, n) => this.ctx.plus(p, n.discount), 0);
           discount = this.ctx.plus(discount, actDiscount);
@@ -59,7 +59,7 @@ class OrderService extends CrudService {
    * @return {Number} 订单实付金额
    */
   payOrder_RealPay(order) {
-    const priceKey = 'price';
+    const priceKey = 'grp';
     const detail = this.moneyDetail(order);
     // 解除店铺层
     const sd = Object.values(detail);
@@ -137,9 +137,10 @@ class OrderService extends CrudService {
    **      dt: 优惠总价(d_detail的value之和)
    **      ad: [{
    **         money:活动优惠金额(负数),
-   **         platform_act:
+   **         platform_act:活动金额
    **      }]
-   **      grp:商品实际支付价格(goods_real_pay: gt - dt)
+   **      at: 活动优惠总金额
+   **      grp:商品实际支付价格(goods_real_pay: gt - dt - at)
    **      gsm:规格团购销售价格(group_sell_money)
    **      gst: 规格团购销售总价(group_sell_total: gsm * bn)
    **      ggt: 商品团购支付原价(goods_group_total: gst + ft)
@@ -152,8 +153,6 @@ class OrderService extends CrudService {
     if (!data) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到订单信息');
     // 优惠部分
     const ddt = _.get(data, 'total_detail.discount_detail', {});
-    // 活动部分
-    const act = _.get(data, 'total_detail.act', []);
     // 店铺规格商品数据
     const shopGoods = _.get(data, 'goods', []);
     const result = {};
@@ -161,12 +160,13 @@ class OrderService extends CrudService {
       const { goods, shop } = s;
       const shopResult = {};
       for (const g of goods) {
-        const { sell_money, freight: f, buy_num: bn, group_config, _id } = g;
+        const { sell_money, freight: f, buy_num: bn, _id, act: ad = [] } = g;
         // 优先获取price字段,没有再取sell_money
         const sm = _.get(g, 'price', sell_money);
         const st = this.ctx.multiply(sm, bn);
         const ft = this.ctx.multiply(f, bn);
         const gt = this.ctx.plus(st, ft);
+        // 优惠券部分
         const dd = {};
         for (const uc_id in ddt) {
           const detail = _.get(ddt, uc_id, {});
@@ -174,15 +174,10 @@ class OrderService extends CrudService {
           if (value) dd[uc_id] = value;
         }
         const dt = Object.values(dd).reduce((p, n) => this.ctx.plus(p, n), 0);
-        const grp = this.ctx.minus(gt, dt);
-        let obj = { sm, f, bn, st, ft, gt, dd, dt, grp };
-        const gsm = _.get(group_config, 'money');
-        if (gsm) {
-          const gst = this.ctx.multiply(gsm, bn);
-          const ggt = this.ctx.plus(gst, ft);
-          const ggrp = this.ctx.minus(ggt, dt);
-          obj = { ...obj, gsm, gst, ggt, ggrp };
-        }
+        // 活动部分
+        const at = ad.reduce((p, n) => this.ctx.plus(p, n.discount), 0);
+        const grp = this.ctx.minus(this.ctx.minus(gt, dt), at);
+        const obj = { sm, f, bn, st, ft, gt, dd, dt, grp };
         shopResult[_id] = obj;
       }
       result[shop] = shopResult;
@@ -319,13 +314,13 @@ class OrderService extends CrudService {
         }
       }
       for (const i of actResult) {
-        const { goodsSpec_id, gift, ...others } = i;
+        const { goodsSpec_id, ...others } = i;
         const r = goodsList.find(f => f.goodsSpec_id === goodsSpec_id);
         if (r) {
           const { act = [] } = r;
           act.push(others);
           r.act = act;
-          r.gift = gift;
+          r.gift = _.get(i, 'gift');
         }
       }
     }
@@ -354,9 +349,10 @@ class OrderService extends CrudService {
    * @param {Object} goods 平铺的商品数据
    */
   getGoodsPayAfterAct(goods) {
-    const { act = [], price } = goods;
+    const { act = [], price, num } = goods;
     const actDiscount = act.reduce((p, n) => this.ctx.plus(p, n.discount), 0);
-    const rp = this.ctx.minus(price, actDiscount);
+    const sp = this.ctx.multiply(price, num);
+    const rp = this.ctx.minus(sp, actDiscount);
     return rp;
   }