You've already forked FrameTour-BE
feat(pricing): 优惠券增加有效期时间范围功能
- 在VoucherBatchCreateReqV2、VoucherBatchResp、VoucherInfo 和 PriceVoucherBatchConfig 类中添加有效期开始时间和结束时间字段 - 实现有效期时间范围的验证和检查逻辑 - 更新 VoucherBatchServiceImpl 和 VoucherServiceImpl 以支持有效期时间范围功能
This commit is contained in:
@@ -118,6 +118,13 @@ public class VoucherBatchServiceImpl implements VoucherBatchService {
|
||||
throw new BizException(400, "使用间隔小时数不能为负数");
|
||||
}
|
||||
|
||||
// 验证时间范围参数
|
||||
if (req.getValidStartTime() != null && req.getValidEndTime() != null) {
|
||||
if (req.getValidStartTime().after(req.getValidEndTime())) {
|
||||
throw new BizException(400, "有效期开始时间不能晚于结束时间");
|
||||
}
|
||||
}
|
||||
|
||||
PriceVoucherBatchConfig batch = new PriceVoucherBatchConfig();
|
||||
BeanUtils.copyProperties(req, batch);
|
||||
|
||||
|
||||
@@ -85,13 +85,27 @@ public class VoucherServiceImpl implements IVoucherService {
|
||||
return null;
|
||||
}
|
||||
|
||||
VoucherInfo voucherInfo = buildVoucherInfo(voucherCodeEntity, batchConfig);
|
||||
|
||||
// 检查券码批次的时间范围,提供详细的时间范围信息
|
||||
if (!batchConfig.isWithinValidTimeRange()) {
|
||||
voucherInfo.setAvailable(false);
|
||||
Date now = new Date();
|
||||
if (batchConfig.getValidStartTime() != null && now.before(batchConfig.getValidStartTime())) {
|
||||
voucherInfo.setUnavailableReason("券码尚未生效");
|
||||
} else if (batchConfig.getValidEndTime() != null && now.after(batchConfig.getValidEndTime())) {
|
||||
voucherInfo.setUnavailableReason("券码已过期");
|
||||
} else {
|
||||
voucherInfo.setUnavailableReason("券码不在有效期内");
|
||||
}
|
||||
return voucherInfo;
|
||||
}
|
||||
|
||||
// 验证景区匹配
|
||||
if (scenicId != null && !scenicId.equals(voucherCodeEntity.getScenicId())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
VoucherInfo voucherInfo = buildVoucherInfo(voucherCodeEntity, batchConfig);
|
||||
|
||||
// 检查券码状态和可用性,包含完整的重复使用权限验证
|
||||
if (VoucherCodeStatus.UNCLAIMED.getCode().equals(voucherCodeEntity.getStatus())) {
|
||||
// 未领取状态,也需要检查用户的重复使用权限
|
||||
@@ -718,6 +732,10 @@ public void markVoucherAsUsed(String voucherCode, String remark, String orderId,
|
||||
voucherInfo.setUseIntervalHours(batchConfig.getUseIntervalHours());
|
||||
voucherInfo.setLastUsedTime(voucherCode.getLastUsedTime());
|
||||
|
||||
// 设置时间范围信息
|
||||
voucherInfo.setValidStartTime(batchConfig.getValidStartTime());
|
||||
voucherInfo.setValidEndTime(batchConfig.getValidEndTime());
|
||||
|
||||
// 计算剩余可使用次数
|
||||
if (batchConfig.getMaxUseCount() != null) {
|
||||
int remaining = batchConfig.getMaxUseCount() - currentUseCount;
|
||||
|
||||
Reference in New Issue
Block a user