1. fix bug
This commit is contained in:
2026-04-11 10:24:15 +08:00
parent a6f328b4df
commit 84965901af
2 changed files with 18 additions and 17 deletions

View File

@@ -12,4 +12,7 @@ public class LotteryDrawRequest implements Serializable {
@NotNull(message = "无效积分")
private BigDecimal amount;
@NotNull(message = "无效次数")
private Integer times;
}

View File

@@ -116,24 +116,22 @@ public class CommonLotteryPrizeServiceImpl extends BaseServiceImpl<CommonLottery
@Transactional(rollbackFor = Exception.class)
public CommonLotteryPrizeApiVO draw(LotteryDrawRequest request) {
Long userId = AuthUtil.getUserId();
String key = "lottery:" + userId;
if (debounceClient.tryDebounce(key, 3, TimeUnit.SECONDS)) {
Assert.isTrue(request.getAmount().compareTo(BigDecimal.valueOf(100)) == 0 || request.getAmount().compareTo(BigDecimal.valueOf(1000)) == 0, "无效积分");
userPointService.spendPointsForLottery(request.getAmount(), userId);
Boolean addCashCoupon = cashCouponService.addCashCoupon(new MarketCashCouponApiDTO().setAmount(request.getAmount()).setUserId(userId).setSourceType(MarketBusinessModule.LOTTERY));
if (!addCashCoupon) {
log.error("新增现金券失败");
throw new ServiceException("操作失败");
}
Boolean addedRecord = lotteryRecordService.addRecord(userId, request.getAmount());
if (!addedRecord) {
log.error("新增抽奖记录失败");
throw new ServiceException("操作失败");
}
} else {
long remaining = debounceClient.getRemainingTime(key, TimeUnit.SECONDS);
throw new ServiceException("操作过于频繁,请" + remaining + "秒后重试");
if (request.getAmount().compareTo(BigDecimal.valueOf(20)) != 0 || request.getTimes() < 1) {
throw new ServiceException("无效积分值");
}
BigDecimal total = request.getAmount().multiply(BigDecimal.valueOf(request.getTimes()));
userPointService.spendPointsForLottery(total, userId);
Boolean addCashCoupon = cashCouponService.addCashCoupon(new MarketCashCouponApiDTO().setAmount(total).setUserId(userId).setSourceType(MarketBusinessModule.LOTTERY));
if (!addCashCoupon) {
log.error("新增现金券失败");
throw new ServiceException("操作失败");
}
Boolean addedRecord = lotteryRecordService.addRecord(userId, total);
if (!addedRecord) {
log.error("新增抽奖记录失败");
throw new ServiceException("操作失败");
}
return PRIZE;
}