GameRound status 调整

This commit is contained in:
wells
2026-08-08 22:00:39 +08:00
parent 52061b9d59
commit cfb5b4f2a8
11 changed files with 171 additions and 103 deletions
@@ -17,8 +17,14 @@ import java.util.List;
public interface IGameService {
// 局状态常量
int STATUS_ONGOING = 0;
int STATUS_ENDED = 1;
int STATUS_BETTING = 0; // 开始下注
int STATUS_BET_CLOSED = 1; // 结束下注,等待发红包
int STATUS_RP_SENDING = 2; // 开始发红包,等待红包领完
int STATUS_FINISHED = 3; // 已结束
// 向后兼容别名
int STATUS_ONGOING = STATUS_BETTING;
int STATUS_ENDED = STATUS_FINISHED;
// 玩法赔率
BigDecimal ODDS_SINGLE_DOUBLE = new BigDecimal("1");
@@ -32,6 +38,11 @@ public interface IGameService {
*/
GameRound getOngoingRound(Long groupId);
/**
* 获取群当前正在下注的局
*/
GameRound getBettingRound(Long groupId);
/**
* 生成期号
*/
@@ -61,12 +61,12 @@ public class BetServiceImpl implements IBetService {
return null;
}
// 检查进行中的局
// 检查进行中的局(下注中)
GameRound round = gameRoundMapper.selectOne(new LambdaQueryWrapper<GameRound>()
.eq(GameRound::getGroupId, groupId)
.eq(GameRound::getStatus, 0));
.eq(GameRound::getStatus, IGameService.STATUS_BETTING));
if (round == null) {
throw new RuntimeException("当前没有进行中的局");
throw new RuntimeException("当前不在下注阶段");
}
// 检查余额
@@ -143,10 +143,10 @@ public class FakeUserServiceImpl implements IFakeUserService {
String fakeIdStr = fakeList.get(RANDOM.nextInt(fakeList.size()));
Long fakeId = Long.parseLong(fakeIdStr);
// 检查是否有进行中的局
// 检查是否有下注中的局
GameRound round = gameRoundMapper.selectOne(new LambdaQueryWrapper<GameRound>()
.eq(GameRound::getGroupId, groupId)
.eq(GameRound::getStatus, 0));
.eq(GameRound::getStatus, com.tailbet.service.IGameService.STATUS_BETTING));
if (round == null) {
return;
@@ -44,13 +44,27 @@ public class GameServiceImpl implements IGameService {
private final IAuditService auditService;
/**
* 获取群当前进行中的局
* 获取群当前未结束的局(包含下注中、已封盘、发红包中)
*/
@Override
public GameRound getOngoingRound(Long groupId) {
return gameRoundMapper.selectOne(new LambdaQueryWrapper<GameRound>()
.eq(GameRound::getGroupId, groupId)
.eq(GameRound::getStatus, STATUS_ONGOING));
.lt(GameRound::getStatus, STATUS_FINISHED)
.orderByDesc(GameRound::getCreateTime)
.last("LIMIT 1"));
}
/**
* 获取群当前正在下注中的局
*/
@Override
public GameRound getBettingRound(Long groupId) {
return gameRoundMapper.selectOne(new LambdaQueryWrapper<GameRound>()
.eq(GameRound::getGroupId, groupId)
.eq(GameRound::getStatus, STATUS_BETTING)
.orderByDesc(GameRound::getCreateTime)
.last("LIMIT 1"));
}
/**
@@ -97,7 +111,7 @@ public class GameServiceImpl implements IGameService {
GameRound round = new GameRound();
round.setGroupId(groupId);
round.setRoundNo(generateRoundNo(groupId));
round.setStatus(STATUS_ONGOING);
round.setStatus(STATUS_BETTING);
round.setStartTime(LocalDateTime.now());
round.setDigitStrategy("random");
round.setAutoNext(1);
@@ -116,18 +130,20 @@ public class GameServiceImpl implements IGameService {
@Override
@Transactional
public GameRound endBet(Long groupId, Long userId) {
GameRound round = getOngoingRound(groupId);
GameRound round = getBettingRound(groupId);
if (round == null) {
throw new RuntimeException("没有进行中的局");
throw new RuntimeException("当前没有下注中的局");
}
// 校验群主权限
Group group = groupMapper.selectById(groupId);
if (!group.getOwnerUserId().equals(userId)) {
throw new RuntimeException("只有群主可以结束接注");
// 校验群主权限(系统调用时userId=0L跳过校验)
if (!Long.valueOf(0L).equals(userId)) {
Group group = groupMapper.selectById(groupId);
if (!group.getOwnerUserId().equals(userId)) {
throw new RuntimeException("只有群主可以结束接注");
}
}
round.setStatus(STATUS_ENDED);
round.setStatus(STATUS_BET_CLOSED);
round.setEndBetTime(LocalDateTime.now());
gameRoundMapper.updateById(round);
@@ -165,9 +181,9 @@ public class GameServiceImpl implements IGameService {
@Override
@Transactional
public void setTargetDigit(Long groupId, Integer digit, Long userId) {
GameRound round = getOngoingRound(groupId);
GameRound round = getBettingRound(groupId);
if (round == null) {
throw new RuntimeException("没有进行中的局");
throw new RuntimeException("当前没有下注中的局");
}
round.setTargetDigit(digit);
@@ -315,7 +331,7 @@ public class GameServiceImpl implements IGameService {
// 更新局状态
round.setFinishTime(LocalDateTime.now());
round.setStatus(STATUS_ENDED);
round.setStatus(STATUS_FINISHED);
gameRoundMapper.updateById(round);
// 审计日志
@@ -348,7 +364,7 @@ public class GameServiceImpl implements IGameService {
List<GameRound> allRounds = gameRoundMapper.selectList(new LambdaQueryWrapper<GameRound>()
.eq(GameRound::getGroupId, groupId));
stat.setTotalRounds(allRounds.size());
stat.setOngoingRounds((int) allRounds.stream().filter(r -> r.getStatus() == STATUS_ONGOING).count());
stat.setOngoingRounds((int) allRounds.stream().filter(r -> r.getStatus() != null && r.getStatus() < STATUS_FINISHED).count());
// 统计注单
List<BetOrder> allBets = betOrderMapper.selectList(new LambdaQueryWrapper<BetOrder>()