game vipLevel 逻辑调整

This commit is contained in:
tianfeng 2026-01-12 17:08:22 +08:00
parent 5952097305
commit 8341bd2b7d
2 changed files with 50 additions and 21 deletions

View File

@ -16,8 +16,8 @@ import java.util.Random;
public enum VipLevelRule {
WEEK1_V3(1, 3, new BigDecimal("500"), null),
WEEK1_V2(1, 2, new BigDecimal("100"), new BigDecimal("499")),
WEEK1_V1(1, 1, new BigDecimal("0.99"), new BigDecimal("99.99")),
WEEK1_V2(1, 2, new BigDecimal("50"), new BigDecimal("499")),
WEEK1_V1(1, 1, new BigDecimal("0.99"), new BigDecimal("49.99")),
WEEK2_V3(2, 3, new BigDecimal("700"), null),
WEEK2_V2(2, 2, new BigDecimal("500"), new BigDecimal("699")),

View File

@ -69,10 +69,7 @@ import java.time.ZonedDateTime;
import java.time.chrono.ChronoZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.*;
import java.util.concurrent.TimeUnit;
import lombok.RequiredArgsConstructor;
@ -191,29 +188,22 @@ public class HotGameServiceImpl implements HotGameService {
LocalDate cycleStartDate = firstRechargeDate.plusDays(completedCycles * 21);
LocalDate cycleEndDate = cycleStartDate.plusDays(20);
BigDecimal cycleTotalRecharge = userActivityRechargeService.getRechargeAmountByDateRange(
userId, VIP_ACTIVITY_ID, cycleStartDate, cycleEndDate
);
BigDecimal effectiveAmount = cycleTotalRecharge
.divide(new BigDecimal(weekInCycle), 2, RoundingMode.HALF_UP);
WeeklyVipInfo lastWeekInfo = gameVipLevelWeeklyService.getLastWeekInfo(userId, VIP_ACTIVITY_ID, weekStartDate);
BigDecimal lastWeekInherited = (lastWeekInfo != null && lastWeekInfo.getInheritedAmount() != null)
? lastWeekInfo.getInheritedAmount()
: BigDecimal.ZERO;
int displayLevel = VipLevelRule.calculateVipLevelWithInheritance(
normalizedWeek, effectiveAmount, lastWeekInherited
);
BigDecimal lastWeekInherited = calculateLastWeekInherited(lastWeekInfo, weekInCycle, completedCycles);
BigDecimal thisWeekRecharge = userActivityRechargeService.getRechargeAmountByDateRange(
userId, VIP_ACTIVITY_ID, weekStartDate, weekEndDate
);
BigDecimal thisWeekInherited = VipLevelRule.calculateThisWeekInheritance(
normalizedWeek, displayLevel, thisWeekRecharge
int displayLevel = VipLevelRule.calculateVipLevelWithInheritance(
normalizedWeek, thisWeekRecharge, lastWeekInherited
);
// 应用保底逻辑
int startLevel = calculateStartLevel(lastWeekInfo, weekInCycle, completedCycles);
displayLevel = Math.max(displayLevel, startLevel);
BigDecimal thisWeekInherited = thisWeekRecharge.add(lastWeekInherited);
gameVipLevelWeeklyService.saveOrUpdateWeeklyLevel(
userId, VIP_ACTIVITY_ID, (int) (completedCycles * 3 + normalizedWeek),
@ -232,6 +222,45 @@ public class HotGameServiceImpl implements HotGameService {
}
private BigDecimal calculateLastWeekInherited(WeeklyVipInfo lastWeekInfo, int weekInCycle, long completedCycles) {
BigDecimal lastWeekInherited = Optional.ofNullable(lastWeekInfo)
.map(WeeklyVipInfo::getInheritedAmount)
.orElse(BigDecimal.ZERO);
// 第二个周期及以后第一周需要除3再除2
if (completedCycles > 0 && weekInCycle == 1) {
return lastWeekInherited
.divide(new BigDecimal("3"), 2, RoundingMode.HALF_UP)
.divide(new BigDecimal("2"), 2, RoundingMode.HALF_UP);
}
if (completedCycles > 0 && weekInCycle == 2) {
BigDecimal lastCycleInherited = lastWeekInherited.subtract(Optional.ofNullable(lastWeekInfo).map(WeeklyVipInfo::getRechargeAmount).orElse(BigDecimal.ZERO)).max(BigDecimal.ZERO);
return lastWeekInherited.subtract(lastCycleInherited).divide(new BigDecimal("2"), 2, RoundingMode.HALF_UP);
}
// 原有逻辑第二周除2第三周除2再除2
if (weekInCycle == 2) {
return lastWeekInherited.divide(new BigDecimal("2"), 2, RoundingMode.HALF_UP);
} else if (weekInCycle == 3) {
return lastWeekInherited.divide(new BigDecimal("2"), 2, RoundingMode.HALF_UP)
.divide(new BigDecimal("2"), 2, RoundingMode.HALF_UP);
}
return lastWeekInherited;
}
private Integer calculateStartLevel(WeeklyVipInfo lastWeekInfo, int weekInCycle, long completedCycles) {
// 只在新周期的第一周判断
if (completedCycles > 0 && weekInCycle == 1 && lastWeekInfo != null) {
// 检查上周期是否达到过V3
if (lastWeekInfo.getFinalLevel() != null && lastWeekInfo.getFinalLevel() >= 3) {
return 2; // 保底V2
}
}
return 0; // 默认无保底
}
@Override
public HotGameResponse<HotGameCoin> updateUserCoin(HotGameUserCoinUpdate param) {