游戏接入抽奖券完善
This commit is contained in:
parent
3510e63e41
commit
ecb7a83c46
@ -27,11 +27,10 @@ import com.red.circle.other.app.convertor.user.UserProfileAppConvertor;
|
||||
import com.red.circle.other.app.dto.cmd.activity.RankingDataUpdateCmd;
|
||||
import com.red.circle.other.app.dto.cmd.game.GameLxwlUpdateBalanceCmd;
|
||||
import com.red.circle.other.app.dto.cmd.game.GameLxwlUserInfoCmd;
|
||||
import com.red.circle.other.app.dto.cmd.SpinsTaskProgressUpdateCmd;
|
||||
import com.red.circle.other.app.enums.violation.GameOriginEnum;
|
||||
import com.red.circle.other.app.enums.violation.ViolationTypeEnum;
|
||||
import com.red.circle.other.app.service.activity.RankingActivityService;
|
||||
import com.red.circle.other.app.service.SpinsUserTaskProgressService;
|
||||
import com.red.circle.other.app.service.game.GameActivityService;
|
||||
import com.red.circle.other.app.util.DateTimeAsiaRiyadhUtils;
|
||||
import com.red.circle.other.app.util.OfficialNoticeUtils;
|
||||
import com.red.circle.other.domain.game.GameRankingIncrementCmd;
|
||||
@ -90,7 +89,7 @@ public class GameHkysRestController {
|
||||
private final GameRankingGateway gameRankingGateway;
|
||||
private final GameListCacheService gameListCacheService;
|
||||
private final RankingActivityService rankingActivityService;
|
||||
private final SpinsUserTaskProgressService spinsUserTaskProgressService;
|
||||
private final GameActivityService gameActivityService;
|
||||
private final RedisService redisService;
|
||||
|
||||
@IgnoreResultResponse
|
||||
@ -191,7 +190,9 @@ public class GameHkysRestController {
|
||||
incGameRankingRecord(cmd, gameListConfig);
|
||||
|
||||
//处理游戏消费任务
|
||||
handleGameSpendTask(userId, cmd.getType(), cmd.getCoin());
|
||||
if (cmd.getType() == 1) {
|
||||
gameActivityService.handleGameSpendTask(userId, cmd.getCoin());
|
||||
}
|
||||
|
||||
|
||||
return new HkysResponse<JSONObject>()
|
||||
@ -233,66 +234,6 @@ public class GameHkysRestController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理游戏消费任务
|
||||
*/
|
||||
private void handleGameSpendTask(Long userId, Integer type, Long amount) {
|
||||
try {
|
||||
if (type != 1 || amount <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 累计每日游戏消费金额
|
||||
String redisKey = "spins:daily:game:spend:" + userId;
|
||||
String totalStr = redisService.getString(redisKey);
|
||||
long totalSpend;
|
||||
|
||||
if (StringUtils.isBlank(totalStr)) {
|
||||
totalSpend = amount;
|
||||
long expireSeconds = DateTimeAsiaRiyadhUtils.getSecondsUntilMidnight();
|
||||
redisService.setString(redisKey, String.valueOf(totalSpend), expireSeconds, TimeUnit.SECONDS);
|
||||
} else {
|
||||
long currentTotal = Long.parseLong(totalStr);
|
||||
// 如果已经超过50000,不再处理
|
||||
if (currentTotal >= 50000) {
|
||||
log.info("Spins游戏消费任务已达上限, userId={}, totalSpend={}", userId, currentTotal);
|
||||
return;
|
||||
}
|
||||
totalSpend = currentTotal + amount;
|
||||
long expireSeconds = DateTimeAsiaRiyadhUtils.getSecondsUntilMidnight();
|
||||
redisService.setString(redisKey, String.valueOf(totalSpend), expireSeconds, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
log.info("Spins游戏消费任务, userId={}, spendAmount={}, totalSpend={}", userId, amount, totalSpend);
|
||||
|
||||
int progressValue = Integer.parseInt(String.valueOf(totalSpend));
|
||||
spinsUserTaskProgressService.updateTaskProgress(
|
||||
new SpinsTaskProgressUpdateCmd()
|
||||
.setUserId(userId)
|
||||
.setTaskCode("SPINS_SPEND_5000")
|
||||
.setProgressValue(progressValue)
|
||||
);
|
||||
|
||||
spinsUserTaskProgressService.updateTaskProgress(
|
||||
new SpinsTaskProgressUpdateCmd()
|
||||
.setUserId(userId)
|
||||
.setTaskCode("SPINS_SPEND_10000")
|
||||
.setProgressValue(progressValue)
|
||||
);
|
||||
|
||||
spinsUserTaskProgressService.updateTaskProgress(
|
||||
new SpinsTaskProgressUpdateCmd()
|
||||
.setUserId(userId)
|
||||
.setTaskCode("SPINS_SPEND_50000")
|
||||
.setProgressValue(progressValue)
|
||||
);
|
||||
|
||||
log.info("Spins游戏消费任务处理成功, userId={}, totalSpend={}", userId, totalSpend);
|
||||
} catch (Exception e) {
|
||||
log.error("处理Spins游戏消费任务失败, userId={}, amount={}", userId, amount, e);
|
||||
}
|
||||
}
|
||||
|
||||
@IgnoreResultResponse
|
||||
@PostMapping("/orderCompensation")
|
||||
public HkysResponse<JSONObject> orderCompensation(@RequestBody JSONObject object) {
|
||||
|
||||
@ -50,6 +50,7 @@ public class SpinsTaskProgressUpdateExe {
|
||||
new LambdaQueryWrapper<SpinsTaskConfig>()
|
||||
.eq(SpinsTaskConfig::getTaskCode, taskCode)
|
||||
.eq(SpinsTaskConfig::getStatus, 1)
|
||||
.last("limit 1")
|
||||
);
|
||||
|
||||
if (taskConfigs.isEmpty()) {
|
||||
|
||||
@ -0,0 +1,91 @@
|
||||
package com.red.circle.other.app.service.game;
|
||||
|
||||
import com.red.circle.component.redis.service.RedisService;
|
||||
import com.red.circle.other.app.dto.cmd.SpinsTaskProgressUpdateCmd;
|
||||
import com.red.circle.other.app.service.SpinsUserTaskProgressService;
|
||||
import com.red.circle.other.app.util.DateTimeAsiaRiyadhUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 游戏活动服务
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class GameActivityService {
|
||||
|
||||
private static final long MAX_DAILY_SPEND = 50000L;
|
||||
private static final String REDIS_KEY_PREFIX = "spins:daily:game:spend:";
|
||||
|
||||
private final RedisService redisService;
|
||||
private final SpinsUserTaskProgressService spinsUserTaskProgressService;
|
||||
|
||||
/**
|
||||
* 处理游戏消费任务
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param spendAmount 本次消费金额
|
||||
*/
|
||||
public void handleGameSpendTask(Long userId, Long spendAmount) {
|
||||
try {
|
||||
if (spendAmount <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
String redisKey = REDIS_KEY_PREFIX + userId;
|
||||
|
||||
Long totalSpend = redisService.increment(redisKey, spendAmount);
|
||||
|
||||
// 首次创建时设置过期时间
|
||||
if (totalSpend.equals(spendAmount)) {
|
||||
long expireSeconds = DateTimeAsiaRiyadhUtils.getSecondsUntilMidnight();
|
||||
redisService.expire(redisKey, expireSeconds, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
// 如果累计已经超过50000,不再处理任务
|
||||
if (totalSpend - spendAmount >= MAX_DAILY_SPEND) {
|
||||
log.info("Spins游戏消费任务已达上限, userId={}, totalSpend={}", userId, totalSpend);
|
||||
return;
|
||||
}
|
||||
|
||||
log.info("Spins游戏消费任务, userId={}, spendAmount={}, totalSpend={}", userId, spendAmount, totalSpend);
|
||||
|
||||
int progressValue = totalSpend.intValue();
|
||||
updateGameSpendProgress(userId, progressValue);
|
||||
|
||||
log.info("Spins游戏消费任务处理成功, userId={}, totalSpend={}", userId, totalSpend);
|
||||
} catch (Exception e) {
|
||||
log.error("处理Spins游戏消费任务失败, userId={}, spendAmount={}", userId, spendAmount, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新游戏消费进度
|
||||
*/
|
||||
private void updateGameSpendProgress(Long userId, int progressValue) {
|
||||
spinsUserTaskProgressService.updateTaskProgress(
|
||||
new SpinsTaskProgressUpdateCmd()
|
||||
.setUserId(userId)
|
||||
.setTaskCode("SPINS_SPEND_5000")
|
||||
.setProgressValue(progressValue)
|
||||
);
|
||||
|
||||
spinsUserTaskProgressService.updateTaskProgress(
|
||||
new SpinsTaskProgressUpdateCmd()
|
||||
.setUserId(userId)
|
||||
.setTaskCode("SPINS_SPEND_10000")
|
||||
.setProgressValue(progressValue)
|
||||
);
|
||||
|
||||
spinsUserTaskProgressService.updateTaskProgress(
|
||||
new SpinsTaskProgressUpdateCmd()
|
||||
.setUserId(userId)
|
||||
.setTaskCode("SPINS_SPEND_50000")
|
||||
.setProgressValue(progressValue)
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -88,7 +88,7 @@ public class GameBaishunServiceImpl implements GameBaishunService {
|
||||
private final GameRankingGateway gameRankingGateway;
|
||||
private final GameListCacheService gameListCacheService;
|
||||
private final TaskService taskService;
|
||||
private final SpinsUserTaskProgressService spinsUserTaskProgressService;
|
||||
private final GameActivityService gameActivityService;
|
||||
@Value("${red-circle.game-rank.gameid}")
|
||||
private String gameId;
|
||||
|
||||
@ -219,7 +219,9 @@ public class GameBaishunServiceImpl implements GameBaishunService {
|
||||
incGameRankingRecord(request, gameListConfig);
|
||||
|
||||
//处理游戏消费任务
|
||||
handleGameSpendTask(userId, request.getCurrencyDiff());
|
||||
if (request.getCurrencyDiff() < 0) {
|
||||
gameActivityService.handleGameSpendTask(userId, Math.abs(request.getCurrencyDiff()));
|
||||
}
|
||||
}
|
||||
|
||||
log.warn("{} 发送游戏获奖通知--金币数量{}", GoldOrigin.BAISHUN_GAME.name(), request.getCurrencyDiff());
|
||||
@ -303,66 +305,6 @@ public class GameBaishunServiceImpl implements GameBaishunService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理游戏消费任务
|
||||
*/
|
||||
private void handleGameSpendTask(Long userId, Long amount) {
|
||||
try {
|
||||
if (amount >= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
long spendAmount = Math.abs(amount);
|
||||
|
||||
// 累计每日游戏消费金额
|
||||
String redisKey = "spins:daily:game:spend:" + userId;
|
||||
String totalStr = redisService.getString(redisKey);
|
||||
long totalSpend;
|
||||
|
||||
if (StringUtils.isBlank(totalStr)) {
|
||||
totalSpend = spendAmount;
|
||||
long expireSeconds = DateTimeAsiaRiyadhUtils.getSecondsUntilMidnight();
|
||||
redisService.setString(redisKey, String.valueOf(totalSpend), expireSeconds, TimeUnit.SECONDS);
|
||||
} else {
|
||||
long currentTotal = Long.parseLong(totalStr);
|
||||
// 如果已经超过50000,不再处理
|
||||
if (currentTotal >= 50000) {
|
||||
log.info("Spins游戏消费任务已达上限, userId={}, totalSpend={}", userId, currentTotal);
|
||||
return;
|
||||
}
|
||||
totalSpend = currentTotal + spendAmount;
|
||||
long expireSeconds = DateTimeAsiaRiyadhUtils.getSecondsUntilMidnight();
|
||||
redisService.setString(redisKey, String.valueOf(totalSpend), expireSeconds, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
int progressValue = Integer.parseInt(String.valueOf(totalSpend));
|
||||
spinsUserTaskProgressService.updateTaskProgress(
|
||||
new SpinsTaskProgressUpdateCmd()
|
||||
.setUserId(userId)
|
||||
.setTaskCode("SPINS_SPEND_5000")
|
||||
.setProgressValue(progressValue)
|
||||
);
|
||||
|
||||
spinsUserTaskProgressService.updateTaskProgress(
|
||||
new SpinsTaskProgressUpdateCmd()
|
||||
.setUserId(userId)
|
||||
.setTaskCode("SPINS_SPEND_10000")
|
||||
.setProgressValue(progressValue)
|
||||
);
|
||||
|
||||
spinsUserTaskProgressService.updateTaskProgress(
|
||||
new SpinsTaskProgressUpdateCmd()
|
||||
.setUserId(userId)
|
||||
.setTaskCode("SPINS_SPEND_50000")
|
||||
.setProgressValue(progressValue)
|
||||
);
|
||||
|
||||
log.info("Spins游戏消费任务处理成功, userId={}, totalSpend={}", userId, totalSpend);
|
||||
} catch (Exception e) {
|
||||
log.error("处理Spins游戏消费任务失败, userId={}, amount={}", userId, amount, e);
|
||||
}
|
||||
}
|
||||
|
||||
private GoldReceiptCmd createReceipt(BaishunChangeCurrencyRequest param) {
|
||||
UserCredential userCredential = UserCredential.parseToken(param.getToken());
|
||||
return createGoldReceiptCmdBuilder(param.getCurrencyDiff())
|
||||
|
||||
@ -23,12 +23,11 @@ import com.red.circle.other.app.convertor.user.UserProfileAppConvertor;
|
||||
import com.red.circle.other.app.dto.clientobject.game.HotGameUpdateRequest;
|
||||
import com.red.circle.other.app.dto.cmd.activity.RankingDataUpdateCmd;
|
||||
import com.red.circle.other.app.dto.cmd.game.GameLxwlUpdateBalanceCmd;
|
||||
import com.red.circle.other.app.dto.cmd.SpinsTaskProgressUpdateCmd;
|
||||
import com.red.circle.other.app.enums.violation.GameOriginEnum;
|
||||
import com.red.circle.other.app.service.activity.RankingActivityService;
|
||||
import com.red.circle.other.app.service.game.GameActivityService;
|
||||
import com.red.circle.other.app.service.game.override.domain.HotGameUserProfile;
|
||||
import com.red.circle.other.app.service.game.override.service.HotGameService;
|
||||
import com.red.circle.other.app.service.SpinsUserTaskProgressService;
|
||||
import com.red.circle.other.app.util.DateTimeAsiaRiyadhUtils;
|
||||
import com.red.circle.other.app.util.OfficialNoticeUtils;
|
||||
import com.red.circle.other.domain.game.GameRankingIncrementCmd;
|
||||
@ -95,7 +94,7 @@ public class HotGameServiceImpl implements HotGameService {
|
||||
private final GameRankingGateway gameRankingGateway;
|
||||
private final GameListCacheService gameListCacheService;
|
||||
private final RankingActivityService rankingActivityService;
|
||||
private final SpinsUserTaskProgressService spinsUserTaskProgressService;
|
||||
private final GameActivityService gameActivityService;
|
||||
@Value("${red-circle.game-rank.gameid}")
|
||||
private String gameId;
|
||||
@Value("${red-circle.game-rank.endTime}")
|
||||
@ -241,7 +240,9 @@ public class HotGameServiceImpl implements HotGameService {
|
||||
incGameRankingTmpActivity(param);
|
||||
|
||||
//处理游戏消费任务
|
||||
handleGameSpendTask(userId, param.getType(), param.getCoin());
|
||||
if (param.getType() == 1) {
|
||||
gameActivityService.handleGameSpendTask(userId, param.getCoin());
|
||||
}
|
||||
|
||||
return new HotGameResponse<HotGameCoin>()
|
||||
.setData(new HotGameCoin()
|
||||
@ -376,64 +377,4 @@ public class HotGameServiceImpl implements HotGameService {
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理游戏消费任务
|
||||
*/
|
||||
private void handleGameSpendTask(Long userId, Integer type, Long amount) {
|
||||
try {
|
||||
if (type != 1 || amount <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 累计每日游戏消费金额
|
||||
String redisKey = "spins:daily:game:spend:" + userId;
|
||||
String totalStr = redisService.getString(redisKey);
|
||||
long totalSpend;
|
||||
|
||||
if (StringUtils.isBlank(totalStr)) {
|
||||
totalSpend = amount;
|
||||
long expireSeconds = DateTimeAsiaRiyadhUtils.getSecondsUntilMidnight();
|
||||
redisService.setString(redisKey, String.valueOf(totalSpend), expireSeconds, TimeUnit.SECONDS);
|
||||
} else {
|
||||
long currentTotal = Long.parseLong(totalStr);
|
||||
// 如果已经超过50000,不再处理
|
||||
if (currentTotal >= 50000) {
|
||||
log.info("Spins游戏消费任务已达上限, userId={}, totalSpend={}", userId, currentTotal);
|
||||
return;
|
||||
}
|
||||
totalSpend = currentTotal + amount;
|
||||
long expireSeconds = DateTimeAsiaRiyadhUtils.getSecondsUntilMidnight();
|
||||
redisService.setString(redisKey, String.valueOf(totalSpend), expireSeconds, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
log.info("Spins游戏消费任务, userId={}, spendAmount={}, totalSpend={}", userId, amount, totalSpend);
|
||||
|
||||
int progressValue = Integer.parseInt(String.valueOf(totalSpend));
|
||||
spinsUserTaskProgressService.updateTaskProgress(
|
||||
new SpinsTaskProgressUpdateCmd()
|
||||
.setUserId(userId)
|
||||
.setTaskCode("SPINS_SPEND_5000")
|
||||
.setProgressValue(progressValue)
|
||||
);
|
||||
|
||||
spinsUserTaskProgressService.updateTaskProgress(
|
||||
new SpinsTaskProgressUpdateCmd()
|
||||
.setUserId(userId)
|
||||
.setTaskCode("SPINS_SPEND_10000")
|
||||
.setProgressValue(progressValue)
|
||||
);
|
||||
|
||||
spinsUserTaskProgressService.updateTaskProgress(
|
||||
new SpinsTaskProgressUpdateCmd()
|
||||
.setUserId(userId)
|
||||
.setTaskCode("SPINS_SPEND_50000")
|
||||
.setProgressValue(progressValue)
|
||||
);
|
||||
|
||||
log.info("Spins游戏消费任务处理成功, userId={}, totalSpend={}", userId, totalSpend);
|
||||
} catch (Exception e) {
|
||||
log.error("处理Spins游戏消费任务失败, userId={}, amount={}", userId, amount, e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user