错误消息完善

This commit is contained in:
Chopper 2021-06-25 10:17:58 +08:00
parent e4dd156ae7
commit 54320499e5
3 changed files with 8 additions and 7 deletions

View File

@ -51,7 +51,7 @@ public enum ResultCode {
/** /**
* 商品 * 商品
*/ */
GOODS_ERROR(11010, "读取商品异常"), GOODS_ERROR(11001, "商品异常,请稍后重试"),
GOODS_NOT_EXIST(11001, "商品已下架"), GOODS_NOT_EXIST(11001, "商品已下架"),
GOODS_NAME_ERROR(11002, "商品名称不正确名称应为2-50字符"), GOODS_NAME_ERROR(11002, "商品名称不正确名称应为2-50字符"),
GOODS_UNDER_ERROR(11003, "商品下架失败"), GOODS_UNDER_ERROR(11003, "商品下架失败"),
@ -63,6 +63,7 @@ public enum ResultCode {
GOODS_SKU_COST_ERROR(11009, "商品SKU成本价不能小于等于0"), GOODS_SKU_COST_ERROR(11009, "商品SKU成本价不能小于等于0"),
GOODS_SKU_WEIGHT_ERROR(11010, "商品重量不能为负数"), GOODS_SKU_WEIGHT_ERROR(11010, "商品重量不能为负数"),
GOODS_SKU_QUANTITY_ERROR(11011, "商品库存数量不能为负数"), GOODS_SKU_QUANTITY_ERROR(11011, "商品库存数量不能为负数"),
GOODS_SKU_QUANTITY_NOT_ENOUGH(11011, "商品库存不足"),
/** /**
* 参数 * 参数

View File

@ -360,17 +360,17 @@ public class CartServiceImpl implements CartService {
private GoodsSku checkGoods(String skuId, Integer num) { private GoodsSku checkGoods(String skuId, Integer num) {
GoodsSku dataSku = this.goodsSkuService.getGoodsSkuByIdFromCache(skuId); GoodsSku dataSku = this.goodsSkuService.getGoodsSkuByIdFromCache(skuId);
if (dataSku == null) { if (dataSku == null) {
throw new ServiceException("商品已失效,请重新选购!"); throw new ServiceException(ResultCode.GOODS_NOT_EXIST);
} }
if (!GoodsAuthEnum.PASS.name().equals(dataSku.getIsAuth()) || !GoodsStatusEnum.UPPER.name().equals(dataSku.getMarketEnable())) { if (!GoodsAuthEnum.PASS.name().equals(dataSku.getIsAuth()) || !GoodsStatusEnum.UPPER.name().equals(dataSku.getMarketEnable())) {
throw new ServiceException("商品已下架,请重新选购!"); throw new ServiceException(ResultCode.GOODS_NOT_EXIST);
} }
//读取sku的可用库存 //读取sku的可用库存
Integer enableQuantity = goodsSkuService.getStock(skuId); Integer enableQuantity = goodsSkuService.getStock(skuId);
//如果sku的可用库存小于等于0或者小于用户购买的数量则不允许购买 //如果sku的可用库存小于等于0或者小于用户购买的数量则不允许购买
if (enableQuantity <= 0 || enableQuantity < num) { if (enableQuantity <= 0 || enableQuantity < num) {
throw new ServiceException("商品库存已不足,请选购其他商品。"); throw new ServiceException(ResultCode.GOODS_SKU_QUANTITY_NOT_ENOUGH);
} }
return dataSku; return dataSku;
} }