新增斋月活动发放奖励
This commit is contained in:
parent
b9a446ae4c
commit
77a11aa393
@ -764,6 +764,11 @@ public enum GoldOrigin {
|
||||
* cp抽奖
|
||||
*/
|
||||
CP_LOTTERY("CP lottery"),
|
||||
|
||||
/**
|
||||
* 斋月活动
|
||||
*/
|
||||
RAMADAN("RAMadan"),
|
||||
;
|
||||
|
||||
private final String desc;
|
||||
|
||||
@ -59,6 +59,10 @@ import com.red.circle.tool.core.collection.CollectionUtils;
|
||||
import com.red.circle.tool.core.date.DateFormatConstant;
|
||||
import com.red.circle.tool.core.date.LocalDateTimeUtils;
|
||||
import com.red.circle.tool.core.date.ZonedDateTimeAsiaRiyadhUtils;
|
||||
import com.red.circle.tool.core.tuple.PennyAmount;
|
||||
import com.red.circle.wallet.inner.endpoint.wallet.WalletGoldClient;
|
||||
import com.red.circle.wallet.inner.model.cmd.GoldReceiptCmd;
|
||||
import com.red.circle.wallet.inner.model.enums.GoldOrigin;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -103,6 +107,7 @@ public class WeeklyRewardsSentManager {
|
||||
private final WeekKingQueenClient weekKingQueenClient;
|
||||
private final PropsActivityClient propsActivityClient;
|
||||
private final RankingActivityGateway rankingActivityGateway;
|
||||
private final WalletGoldClient walletGoldClient;
|
||||
|
||||
/**
|
||||
* 每周一发送奖励业务.
|
||||
@ -223,7 +228,13 @@ public class WeeklyRewardsSentManager {
|
||||
// 发放活动奖励
|
||||
if (isKingGames(activityConfigDTO)) {
|
||||
sendCustomRankingActivityRewards(SysOriginPlatformEnum.LIKEI, activityId, records, kingRewardList);
|
||||
} else {
|
||||
}
|
||||
|
||||
if (isRamadan(activityConfigDTO)) {
|
||||
sendRamadanRankingActivityRewards(SysOriginPlatformEnum.LIKEI, activityId, records, kingRewardList);
|
||||
}
|
||||
|
||||
else {
|
||||
sendRankingActivityRewards(SysOriginPlatformEnum.LIKEI, activityId, records, kingRewardList);
|
||||
}
|
||||
|
||||
@ -319,10 +330,93 @@ public class WeeklyRewardsSentManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 斋月活动奖励
|
||||
*/
|
||||
private void sendRamadanRankingActivityRewards(SysOriginPlatformEnum sysOriginPlatformEnum, Long activityId,
|
||||
List<RankingActivityRecord> topUsers,
|
||||
List<ActivityConfigRewardsDTO> rewardsDTOList) {
|
||||
if (CollectionUtils.isEmpty(topUsers) || CollectionUtils.isEmpty(rewardsDTOList)) {
|
||||
log.warn("活动奖励为空, 跳过奖励发放");
|
||||
return;
|
||||
}
|
||||
|
||||
// 定义排名区间:第1名、2-4名、5-7名、8-10名
|
||||
int[][] rankingRanges = {
|
||||
{0, 1}, // 第1名 (索引0)
|
||||
{1, 2}, // 第2名 (索引1)
|
||||
{2, 3}, // 第3名 (索引2)
|
||||
{3, 10} // 4-10名 (索引7-9)
|
||||
};
|
||||
|
||||
// 计算金币奖励
|
||||
double[] percentages = {0.10, 0.08, 0.06, 0.04};
|
||||
|
||||
for (int rewardIndex = 0; rewardIndex < Math.min(rewardsDTOList.size(), rankingRanges.length); rewardIndex++) {
|
||||
ActivityConfigRewardsDTO reward = rewardsDTOList.get(rewardIndex);
|
||||
int[] range = rankingRanges[rewardIndex];
|
||||
int startIndex = range[0];
|
||||
int endIndex = Math.min(range[1], topUsers.size());
|
||||
|
||||
for (int userIndex = startIndex; userIndex < endIndex; userIndex++) {
|
||||
try {
|
||||
RankingActivityRecord user = topUsers.get(userIndex);
|
||||
|
||||
// 判断金额是否达到100K,如果没有则跳过不发奖励
|
||||
if (user.getQuantity() == null || user.getQuantity() < 100000) {
|
||||
continue;
|
||||
}
|
||||
|
||||
double percentage = percentages[Math.min(rewardIndex, percentages.length)];
|
||||
long goldReward = (long) (user.getQuantity() * percentage);
|
||||
|
||||
// 发送金币
|
||||
addUserGold(user.getUserId(), user.getSysOrigin(), GoldOrigin.RAMADAN, goldReward, user.getId());
|
||||
|
||||
// 发送奖励
|
||||
sendRewardToUser(sysOriginPlatformEnum, activityId, user.getUserId(), reward.getResourceGroupId(), SendPropsOrigin.RANKING_ACTIVITY);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("活动奖励发放失败 - 排名: {}, 用户ID: {}, 错误信息: {}",
|
||||
userIndex + 1, topUsers.get(userIndex).getUserId(), e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 增加用户金币
|
||||
*/
|
||||
private void addUserGold(Long userId, String sysOrigin, GoldOrigin goldOrigin, Long amount, String eventId) {
|
||||
GoldReceiptCmd build = GoldReceiptCmd.builder()
|
||||
.appIncome()
|
||||
.userId(userId)
|
||||
.amount(PennyAmount.ofDollar(amount))
|
||||
.eventId(eventId)
|
||||
.sysOrigin(sysOrigin)
|
||||
.origin(goldOrigin)
|
||||
.build();
|
||||
|
||||
try {
|
||||
walletGoldClient.changeBalance(build);
|
||||
} catch (Exception e) {
|
||||
log.error("增加金币失败 userId={} amount={} eventId={}", userId, amount, eventId, e);
|
||||
throw new RuntimeException("Failed to increase gold coins");
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isKingGames(ActivityConfigDTO activityConfigDTO) {
|
||||
return RankingActivityType.KING_GAMES.name().equals(activityConfigDTO.getActivityType());
|
||||
}
|
||||
|
||||
/**
|
||||
* 斋月活动
|
||||
*/
|
||||
private static boolean isRamadan(ActivityConfigDTO activityConfigDTO) {
|
||||
return RankingActivityType.RAMADAN.name().equals(activityConfigDTO.getActivityType());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取排名区间描述
|
||||
*/
|
||||
|
||||
@ -50,6 +50,8 @@ public enum RankingActivityType {
|
||||
FRUIT_PARTY(11, "FruitParty", "统计游戏数据排行"),
|
||||
|
||||
CHRISTMAS(12, "圣诞节活动", "统计送礼物消费排行"),
|
||||
|
||||
RAMADAN(13, "'斋月活动'", "'统计送礼物消费排行'"),
|
||||
;
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user