lrf 2 years ago
parent
commit
3d4ca3493d
1 changed files with 4 additions and 4 deletions
  1. 4 4
      app/service/trade/cart.js

+ 4 - 4
app/service/trade/cart.js

@@ -83,13 +83,13 @@ class CartService extends CrudService {
     const data = await this.model.findOne(query);
     if (data) {
       const buyNum = this.ctx.plus(data.num, num);
-      const { enough } = await this.checkGoodsNum({ goodsSpecId: goodsSpec, num: buyNum });
-      if (!enough) throw new BusinessError(ErrorCode.SERVICE_FAULT, '库存不足,无法添加至购物车');
+      const { enough, msg } = await this.checkGoodsNum({ goodsSpecId: goodsSpec, num: buyNum });
+      if (!enough) throw new BusinessError(ErrorCode.SERVICE_FAULT, msg);
       data.num = buyNum;
       await data.save();
     } else {
-      const { enough } = await this.checkGoodsNum({ goodsSpecId: goodsSpec, num });
-      if (!enough) throw new BusinessError(ErrorCode.SERVICE_FAULT, '库存不足,无法添加至购物车');
+      const { enough, msg } = await this.checkGoodsNum({ goodsSpecId: goodsSpec, num });
+      if (!enough) throw new BusinessError(ErrorCode.SERVICE_FAULT, msg);
       await this.model.create({ num, ...body });
     }
   }