feat(order): 添加错误信息配置并优化测试账号处理逻辑
- 在 OrderConfigProperties 中添加 ErrorMessages 类,用于配置订单相关的错误信息- 在 OrderBusinessService 中增加测试账号的判断逻辑,测试账号可跳过金额验证
This commit is contained in:
@@ -38,6 +38,11 @@ public class OrderConfigProperties {
|
||||
*/
|
||||
private AutoCancel autoCancel = new AutoCancel();
|
||||
|
||||
/**
|
||||
* 错误信息配置
|
||||
*/
|
||||
private ErrorMessages errorMessages = new ErrorMessages();
|
||||
|
||||
@Data
|
||||
public static class TestAccount {
|
||||
/**
|
||||
@@ -194,4 +199,37 @@ public class OrderConfigProperties {
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class ErrorMessages {
|
||||
/**
|
||||
* 订单金额计算错误信息
|
||||
*/
|
||||
private String amountCalculationError = "订单金额计算错误,请刷新重试";
|
||||
|
||||
/**
|
||||
* 商品不存在错误信息
|
||||
*/
|
||||
private String goodsNotFound = "商品不存在";
|
||||
|
||||
/**
|
||||
* 商品已下架错误信息
|
||||
*/
|
||||
private String goodsOffline = "商品已下架";
|
||||
|
||||
/**
|
||||
* 库存不足错误信息
|
||||
*/
|
||||
private String stockInsufficient = "商品库存不足";
|
||||
|
||||
/**
|
||||
* 购买数量超限错误信息
|
||||
*/
|
||||
private String quantityExceeded = "商品购买数量超过限制";
|
||||
|
||||
/**
|
||||
* 商品价格异常错误信息
|
||||
*/
|
||||
private String priceAbnormal = "商品价格异常";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,6 +104,18 @@ public class OrderBusinessService {
|
||||
throw new BusinessException("用户未登录");
|
||||
}
|
||||
|
||||
// 检查是否为测试账号
|
||||
boolean isTestAccount = orderConfig.isTestAccount(loginUser.getPhone());
|
||||
|
||||
if (isTestAccount) {
|
||||
// 测试账号:直接使用测试金额,跳过金额验证
|
||||
BigDecimal testAmount = orderConfig.getTestAccount().getTestPayAmount();
|
||||
request.setTotalPrice(testAmount);
|
||||
log.info("测试账号订单,用户:{},使用测试金额:{}", loginUser.getPhone(), testAmount);
|
||||
return; // 测试账号跳过后续验证
|
||||
}
|
||||
|
||||
// 非测试账号:正常验证流程
|
||||
// 验证商品信息并计算总金额
|
||||
BigDecimal calculatedTotal = validateAndCalculateTotal(request);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user