|
@@ -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 };
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|