From 8341bd2b7d005a22d3f3b182c8796ce2fd23797b Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Mon, 12 Jan 2026 17:08:22 +0800 Subject: [PATCH] =?UTF-8?q?game=20vipLevel=20=E9=80=BB=E8=BE=91=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../other/inner/enums/game/VipLevelRule.java | 4 +- .../app/service/game/HotGameServiceImpl.java | 67 +++++++++++++------ 2 files changed, 50 insertions(+), 21 deletions(-) diff --git a/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/enums/game/VipLevelRule.java b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/enums/game/VipLevelRule.java index 5a620acd..4726cb65 100644 --- a/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/enums/game/VipLevelRule.java +++ b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/enums/game/VipLevelRule.java @@ -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")), diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/game/HotGameServiceImpl.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/game/HotGameServiceImpl.java index 04586643..a85b67cb 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/game/HotGameServiceImpl.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/game/HotGameServiceImpl.java @@ -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 updateUserCoin(HotGameUserCoinUpdate param) {