抽奖新增500刀过滤处理
This commit is contained in:
parent
84732434fe
commit
dc47209d4a
@ -291,7 +291,7 @@ public class LotteryDrawExe {
|
|||||||
prizes = filterAlreadyWonBadgePrizes(prizes, progress.getUserId(), activityId);
|
prizes = filterAlreadyWonBadgePrizes(prizes, progress.getUserId(), activityId);
|
||||||
|
|
||||||
// 4. 过滤美元奖励(充值金额为0的用户不能抽到)
|
// 4. 过滤美元奖励(充值金额为0的用户不能抽到)
|
||||||
prizes = filterMoneyPrizes(prizes, userRechargeAmount);
|
prizes = filterMoneyPrizes(activityId, prizes, userRechargeAmount);
|
||||||
|
|
||||||
// 5. 过滤会超过提现门槛的大奖
|
// 5. 过滤会超过提现门槛的大奖
|
||||||
prizes = filterOverThresholdPrizes(prizes, progress, activity.getWithdrawThreshold());
|
prizes = filterOverThresholdPrizes(prizes, progress, activity.getWithdrawThreshold());
|
||||||
@ -332,7 +332,7 @@ public class LotteryDrawExe {
|
|||||||
prizes = filterAlreadyWonBadgePrizes(prizes, userId, activityId);
|
prizes = filterAlreadyWonBadgePrizes(prizes, userId, activityId);
|
||||||
|
|
||||||
// 过滤美元奖励(充值金额为0的用户不能抽到)
|
// 过滤美元奖励(充值金额为0的用户不能抽到)
|
||||||
prizes = filterMoneyPrizes(prizes, userRechargeAmount);
|
prizes = filterMoneyPrizes(activityId, prizes, userRechargeAmount);
|
||||||
|
|
||||||
if (prizes.isEmpty()) {
|
if (prizes.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
@ -658,7 +658,7 @@ public class LotteryDrawExe {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 过滤用户已中过的BADGE类型奖品.
|
* 过滤用户已中过的BADGE类型奖品.
|
||||||
*
|
*
|
||||||
* @param prizes 奖品列表
|
* @param prizes 奖品列表
|
||||||
* @param userId 用户ID
|
* @param userId 用户ID
|
||||||
* @return 过滤后的奖品列表
|
* @return 过滤后的奖品列表
|
||||||
@ -674,55 +674,52 @@ public class LotteryDrawExe {
|
|||||||
if (!"BADGE".equals(prize.getPrizeType())) {
|
if (!"BADGE".equals(prize.getPrizeType())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查用户是否已经中过这个BADGE
|
// 检查用户是否已经中过这个BADGE
|
||||||
String redisKey = "lottery:badge:won:" + userId + ":" + activityId;
|
String redisKey = "lottery:badge:won:" + userId + ":" + activityId;
|
||||||
String won = redisService.getString(redisKey);
|
String won = redisService.getString(redisKey);
|
||||||
|
|
||||||
if (won != null) {
|
if (won != null) {
|
||||||
log.info("User already won this BADGE prize, filtering it out. userId: {}, prizeId: {}, prizeName: {}",
|
log.info("User already won this BADGE prize, filtering it out. userId: {}, prizeId: {}, prizeName: {}",
|
||||||
userId, prize.getId(), prize.getPrizeName());
|
userId, prize.getId(), prize.getPrizeName());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
})
|
})
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 过滤美元奖励(充值金额为0的用户不能抽到).
|
* 过滤美元奖励(根据充值金额过滤不同档位的奖品)
|
||||||
*
|
|
||||||
* @param prizes 奖品列表
|
|
||||||
* @param userRechargeAmount 用户充值金额
|
|
||||||
* @return 过滤后的奖品列表
|
|
||||||
*/
|
*/
|
||||||
private List<LotteryPrize> filterMoneyPrizes(List<LotteryPrize> prizes, BigDecimal userRechargeAmount) {
|
private List<LotteryPrize> filterMoneyPrizes(Long activityId, List<LotteryPrize> prizes, BigDecimal userRechargeAmount) {
|
||||||
if (prizes == null || prizes.isEmpty()) {
|
if (prizes == null || prizes.isEmpty()) {
|
||||||
return prizes;
|
return prizes;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果用户充值金额>0,不需要过滤
|
// 从Redis获取活动充值门槛,默认500
|
||||||
if (userRechargeAmount.compareTo(BigDecimal.ZERO) > 0) {
|
String thresholdKey = "lottery:recharge:threshold:" + activityId;
|
||||||
|
String thresholdStr = redisService.getString(thresholdKey);
|
||||||
|
BigDecimal rechargeThreshold = thresholdStr != null ? new BigDecimal(thresholdStr) : new BigDecimal("500");
|
||||||
|
|
||||||
|
// 如果用户充值金额 >= 门槛,不需要过滤
|
||||||
|
if (userRechargeAmount.compareTo(rechargeThreshold) >= 0) {
|
||||||
return prizes;
|
return prizes;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 充值金额为0,过滤掉MONEY类型奖品
|
// 如果用户充值金额 <= 0,过滤掉所有MONEY类型奖品
|
||||||
List<LotteryPrize> filtered = prizes.stream()
|
if (userRechargeAmount.compareTo(BigDecimal.ZERO) <= 0) {
|
||||||
.filter(prize -> {
|
return prizes.stream()
|
||||||
if ("MONEY".equals(prize.getPrizeType())) {
|
.filter(prize -> !"MONEY".equals(prize.getPrizeType()))
|
||||||
log.info("User has no recharge, filtering MONEY prize. userId: {}, prizeId: {}, prizeName: {}",
|
.collect(Collectors.toList());
|
||||||
userRechargeAmount, prize.getId(), prize.getPrizeName());
|
}
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
})
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
log.info("Filter MONEY prizes completed. userRechargeAmount: {}, beforeCount: {}, afterCount: {}",
|
// 如果用户充值金额 > 0 且 < 门槛,过滤掉 prizeValue >= 10 的MONEY奖品
|
||||||
userRechargeAmount, prizes.size(), filtered.size());
|
return prizes.stream()
|
||||||
|
.filter(prize -> !"MONEY".equals(prize.getPrizeType()) ||
|
||||||
return filtered;
|
prize.getPrizeValue().compareTo(new BigDecimal("10")) < 0)
|
||||||
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -305,7 +305,7 @@ public class LotteryMultiDrawExe {
|
|||||||
prizes = filterAlreadyWonBadgePrizes(prizes, progress.getUserId(), activityId);
|
prizes = filterAlreadyWonBadgePrizes(prizes, progress.getUserId(), activityId);
|
||||||
|
|
||||||
// 过滤美元奖励(充值金额为0的用户不能抽到)
|
// 过滤美元奖励(充值金额为0的用户不能抽到)
|
||||||
prizes = filterMoneyPrizes(prizes, userRechargeAmount);
|
prizes = filterMoneyPrizes(activityId, prizes, userRechargeAmount);
|
||||||
|
|
||||||
prizes = filterOverThresholdPrizes(prizes, progress, activity.getWithdrawThreshold());
|
prizes = filterOverThresholdPrizes(prizes, progress, activity.getWithdrawThreshold());
|
||||||
if (prizes.isEmpty()) {
|
if (prizes.isEmpty()) {
|
||||||
@ -422,7 +422,7 @@ public class LotteryMultiDrawExe {
|
|||||||
prizes = filterAlreadyWonBadgePrizes(prizes, userId, activityId);
|
prizes = filterAlreadyWonBadgePrizes(prizes, userId, activityId);
|
||||||
|
|
||||||
// 过滤美元奖励(充值金额为0的用户不能抽到)
|
// 过滤美元奖励(充值金额为0的用户不能抽到)
|
||||||
prizes = filterMoneyPrizes(prizes, userRechargeAmount);
|
prizes = filterMoneyPrizes(activityId, prizes, userRechargeAmount);
|
||||||
|
|
||||||
if (prizes.isEmpty()) {
|
if (prizes.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
@ -678,41 +678,41 @@ public class LotteryMultiDrawExe {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 过滤美元奖励(充值金额为0的用户不能抽到)
|
* 过滤美元奖励(根据充值金额过滤不同档位的奖品)
|
||||||
*/
|
*/
|
||||||
private List<LotteryPrize> filterMoneyPrizes(List<LotteryPrize> prizes, BigDecimal userRechargeAmount) {
|
private List<LotteryPrize> filterMoneyPrizes(Long activityId, List<LotteryPrize> prizes, BigDecimal userRechargeAmount) {
|
||||||
if (prizes == null || prizes.isEmpty()) {
|
if (prizes == null || prizes.isEmpty()) {
|
||||||
return prizes;
|
return prizes;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果用户充值金额>0,不需要过滤
|
// 从Redis获取活动充值门槛,默认500
|
||||||
if (userRechargeAmount.compareTo(BigDecimal.ZERO) > 0) {
|
String thresholdKey = "lottery:recharge:threshold:" + activityId;
|
||||||
|
String thresholdStr = redisService.getString(thresholdKey);
|
||||||
|
BigDecimal rechargeThreshold = thresholdStr != null ? new BigDecimal(thresholdStr) : new BigDecimal("500");
|
||||||
|
|
||||||
|
// 如果用户充值金额 >= 门槛,不需要过滤
|
||||||
|
if (userRechargeAmount.compareTo(rechargeThreshold) >= 0) {
|
||||||
return prizes;
|
return prizes;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 充值金额为0,过滤掉MONEY类型奖品
|
// 如果用户充值金额 <= 0,过滤掉所有MONEY类型奖品
|
||||||
List<LotteryPrize> filtered = prizes.stream()
|
if (userRechargeAmount.compareTo(BigDecimal.ZERO) <= 0) {
|
||||||
.filter(prize -> {
|
return prizes.stream()
|
||||||
if ("MONEY".equals(prize.getPrizeType())) {
|
.filter(prize -> !"MONEY".equals(prize.getPrizeType()))
|
||||||
log.info("User has no recharge in multi-draw, filtering MONEY prize. userRechargeAmount: {}, prizeId: {}, prizeName: {}",
|
.collect(Collectors.toList());
|
||||||
userRechargeAmount, prize.getId(), prize.getPrizeName());
|
}
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
})
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
log.info("Filter MONEY prizes completed in multi-draw. userRechargeAmount: {}, beforeCount: {}, afterCount: {}",
|
// 如果用户充值金额 > 0 且 < 门槛,过滤掉 prizeValue >= 10 的MONEY奖品
|
||||||
userRechargeAmount, prizes.size(), filtered.size());
|
return prizes.stream()
|
||||||
|
.filter(prize -> !"MONEY".equals(prize.getPrizeType()) ||
|
||||||
return filtered;
|
prize.getPrizeValue().compareTo(new BigDecimal("10")) < 0)
|
||||||
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 标记用户已中BADGE类型奖品(永久记录).
|
* 标记用户已中BADGE类型奖品(永久记录).
|
||||||
*
|
*
|
||||||
* @param userId 用户ID
|
* @param userId 用户ID
|
||||||
* @param prizeId 奖品ID
|
|
||||||
*/
|
*/
|
||||||
private void markBadgePrizeAsWon(Long userId, Long activityId) {
|
private void markBadgePrizeAsWon(Long userId, Long activityId) {
|
||||||
String redisKey = "lottery:badge:won:" + userId + ":" + activityId;
|
String redisKey = "lottery:badge:won:" + userId + ":" + activityId;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user