update:
1. fix bug
This commit is contained in:
@@ -12,4 +12,7 @@ public class LotteryDrawRequest implements Serializable {
|
|||||||
@NotNull(message = "无效积分")
|
@NotNull(message = "无效积分")
|
||||||
private BigDecimal amount;
|
private BigDecimal amount;
|
||||||
|
|
||||||
|
@NotNull(message = "无效次数")
|
||||||
|
private Integer times;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,24 +116,22 @@ public class CommonLotteryPrizeServiceImpl extends BaseServiceImpl<CommonLottery
|
|||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public CommonLotteryPrizeApiVO draw(LotteryDrawRequest request) {
|
public CommonLotteryPrizeApiVO draw(LotteryDrawRequest request) {
|
||||||
Long userId = AuthUtil.getUserId();
|
Long userId = AuthUtil.getUserId();
|
||||||
String key = "lottery:" + userId;
|
if (request.getAmount().compareTo(BigDecimal.valueOf(20)) != 0 || request.getTimes() < 1) {
|
||||||
if (debounceClient.tryDebounce(key, 3, TimeUnit.SECONDS)) {
|
throw new ServiceException("无效积分值");
|
||||||
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 + "秒后重试");
|
|
||||||
}
|
}
|
||||||
|
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;
|
return PRIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user