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