lrf 2 years ago
parent
commit
854008e88a
2 changed files with 11 additions and 1 deletions
  1. 1 0
      app/controller/trade/config/.cart.js
  2. 10 1
      app/service/trade/cart.js

+ 1 - 0
app/controller/trade/config/.cart.js

@@ -53,6 +53,7 @@ module.exports = {
         cartId: 'cartId',
         goodsSpecId: 'goodsSpecId',
         num: 'num',
+        set_id: 'set_id',
       },
     },
   },

+ 10 - 1
app/service/trade/cart.js

@@ -164,9 +164,16 @@ class CartService extends CrudService {
    * @param {String} cartId 购物车id
    * @param {Number} num 需要的库存数量
    * @param {Boolean} update 修改购物车
+   * @param {String} set_id 套装id
    * @return {Boolean} true:库存满足购物车条件;false:库存不满足条件
    */
-  async checkGoodsNum({ cartId, goodsSpecId, num }, update = true) {
+  async checkGoodsNum({ cartId, goodsSpecId, num, set_id }, update = true) {
+    if (set_id) {
+      // 套装查询库存
+      const cartData = await this.model.findById(cartId);
+      const res = await this.checkSetGoodsNum(cartData, num);
+      return res;
+    }
     const { populate } = this.ctx.service.shop.goodsSpec.getRefMods();
     const goodsSpec = await this.goodsSpecModel.findById(goodsSpecId).populate(populate);
     if (!goodsSpec) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到商品的规格数据');
@@ -185,6 +192,8 @@ class CartService extends CrudService {
       await this.model.updateOne({ _id: cartId }, { num });
     }
     return { enough: true, total: gsnum };
+
+
   }
 }