You've already forked FrameTour-BE
refactor(voucher): 移除券码领取接口中的景区ID参数验证
- 删除 VoucherClaimReq 中的 scenicId 字段 - 移除券码领取接口中对景区ID的空值检查 - 更新查询条件,不再按景区ID过滤券码 - 修改错误提示信息为"券码不存在" - 调整领券权限校验逻辑,使用券码关联的景区ID进行验证
This commit is contained in:
@@ -4,6 +4,5 @@ import lombok.Data;
|
|||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class VoucherClaimReq {
|
public class VoucherClaimReq {
|
||||||
private Long scenicId;
|
|
||||||
private String code;
|
private String code;
|
||||||
}
|
}
|
||||||
@@ -74,9 +74,6 @@ public void generateVoucherCodes(Long batchId, Long scenicId, Integer count) {
|
|||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public VoucherCodeResp claimVoucher(VoucherClaimReq req) {
|
public VoucherCodeResp claimVoucher(VoucherClaimReq req) {
|
||||||
if (req.getScenicId() == null) {
|
|
||||||
throw new BizException(400, "景区ID不能为空");
|
|
||||||
}
|
|
||||||
if (!StringUtils.hasText(req.getCode())) {
|
if (!StringUtils.hasText(req.getCode())) {
|
||||||
throw new BizException(400, "券码不能为空");
|
throw new BizException(400, "券码不能为空");
|
||||||
}
|
}
|
||||||
@@ -86,19 +83,18 @@ public VoucherCodeResp claimVoucher(VoucherClaimReq req) {
|
|||||||
// 验证券码是否存在且未被领取
|
// 验证券码是否存在且未被领取
|
||||||
LambdaQueryWrapper<PriceVoucherCode> wrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<PriceVoucherCode> wrapper = new LambdaQueryWrapper<>();
|
||||||
wrapper.eq(PriceVoucherCode::getCode, req.getCode())
|
wrapper.eq(PriceVoucherCode::getCode, req.getCode())
|
||||||
.eq(PriceVoucherCode::getScenicId, req.getScenicId())
|
|
||||||
.eq(PriceVoucherCode::getDeleted, 0);
|
.eq(PriceVoucherCode::getDeleted, 0);
|
||||||
|
|
||||||
PriceVoucherCode voucherCode = voucherCodeMapper.selectOne(wrapper);
|
PriceVoucherCode voucherCode = voucherCodeMapper.selectOne(wrapper);
|
||||||
if (voucherCode == null) {
|
if (voucherCode == null) {
|
||||||
throw new BizException(400, "券码不存在或不属于该景区");
|
throw new BizException(400, "券码不存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Objects.equals(voucherCode.getStatus(), VoucherCodeStatus.UNCLAIMED.getCode())) {
|
if (!Objects.equals(voucherCode.getStatus(), VoucherCodeStatus.UNCLAIMED.getCode())) {
|
||||||
throw new BizException(400, "券码已被领取或已使用");
|
throw new BizException(400, "券码已被领取或已使用");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!canClaimVoucher(userId, req.getScenicId())) {
|
if (!canClaimVoucher(userId, voucherCode.getScenicId())) {
|
||||||
throw new BizException(400, "该用户在此景区已领取过券码");
|
throw new BizException(400, "该用户在此景区已领取过券码");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user