lrf 2 anni fa
parent
commit
f055844f6a
1 ha cambiato i file con 27 aggiunte e 1 eliminazioni
  1. 27 1
      app/service/trade/order.js

+ 27 - 1
app/service/trade/order.js

@@ -45,9 +45,35 @@ class OrderService extends CrudService {
     const address = await this.addressModel.findOne({ customer, is_default: '1' });
     pageData.address = address;
     // 商品总价,各店铺的价格明细
+    specsData = this.computedShopTotal(specsData);
+    const shopTotalDetail = this.computedAllTotal(specsData);
     pageData.goodsData = specsData;
+    pageData.orderTotal = shopTotalDetail;
     return pageData;
   }
+  /**
+   * 计算商店的结算
+   * @param {Array} list 按店铺分组的商品列表
+   */
+  computedShopTotal(list) {
+    for (const i of list) {
+      i.goods_total = i.goods.reduce((p, n) => p + (n.money || 0), 0);
+      i.freight_total = i.goods.reduce((p, n) => p + (n.freight || 0), 0);
+    }
+    return list;
+  }
+
+  /**
+   * 计算订单的结算
+   * @param {Array} list 按店铺分组的商品列表
+   */
+  computedAllTotal(list) {
+    const obj = {
+      goods_total: list.reduce((p, n) => p + (n.goods_total || 0), 0),
+      freight_total: list.reduce((p, n) => p + (n.freight_total || 0), 0),
+    };
+    return obj;
+  }
 
   /**
    * 单商品整理数据,需要商品与规格的快照,剩下的可以简略
@@ -70,7 +96,7 @@ class OrderService extends CrudService {
       goods.money = _.get(i, 'sell_money');
       goods.num = num;
       goods.file = _.get(i.goods, 'file');
-      obj.goods = goods;
+      obj.goods = [ goods ];
       arr.push(obj);
     }
     return arr;