This commit is contained in:
wells
2026-08-05 13:48:48 +08:00
commit 1303bf37dc
80 changed files with 5154 additions and 0 deletions
@@ -0,0 +1,122 @@
package com.tailbet.controller;
import com.tailbet.model.dto.BetDTO;
import com.tailbet.model.dto.GameOperateDTO;
import com.tailbet.model.dto.HistoryQueryDTO;
import com.tailbet.model.dto.SetDigitDTO;
import com.tailbet.model.vo.R;
import com.tailbet.model.vo.UserContext;
import com.tailbet.service.IBetService;
import com.tailbet.service.IGameService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 游戏Controller
*/
@RestController
@RequestMapping("/api/game")
@RequiredArgsConstructor
public class GameController {
private final IGameService gameService;
private final IBetService betService;
/**
* 开始游戏(群主)
*/
@PostMapping("/start")
public R<?> startGame(@RequestBody GameOperateDTO dto) {
try {
Long userId = UserContext.getUserId();
var round = gameService.startGame(dto.getGroupId(), userId);
return R.ok(round);
} catch (RuntimeException e) {
return R.fail(e.getMessage());
}
}
/**
* 结束接注(群主)
*/
@PostMapping("/end")
public R<?> endBet(@RequestBody GameOperateDTO dto) {
try {
Long userId = UserContext.getUserId();
var round = gameService.endBet(dto.getGroupId(), userId);
return R.ok(round);
} catch (RuntimeException e) {
return R.fail(e.getMessage());
}
}
/**
* 停止自动连开
*/
@PostMapping("/stop")
public R<?> stopAutoNext(@RequestBody GameOperateDTO dto) {
try {
Long userId = UserContext.getUserId();
gameService.stopAutoNext(dto.getGroupId(), userId);
return R.ok("已停止自动连开");
} catch (RuntimeException e) {
return R.fail(e.getMessage());
}
}
/**
* 下注
*/
@PostMapping("/bet")
public R<?> bet(@RequestBody BetDTO dto) {
try {
Long userId = UserContext.getUserId();
var bet = betService.placeBet(userId, dto.getGroupId(),
dto.getClientMsgId(), dto.getPlayType(), dto.getBetAmount());
if (bet == null) {
return R.ok("假人下注已记录");
}
return R.ok(bet);
} catch (RuntimeException e) {
return R.fail(e.getMessage());
}
}
/**
* 尾数试算
*/
@GetMapping("/bet/trial")
public R<?> trialDigit(Long groupId, Long roundId) {
try {
List<GameService.DigitTrial> trials = gameService.trialDigit(groupId, roundId);
return R.ok(trials);
} catch (RuntimeException e) {
return R.fail(e.getMessage());
}
}
/**
* 开奖历史
*/
@GetMapping("/history")
public R<?> history(HistoryQueryDTO query) {
var page = gameService.getHistory(query.getGroupId(), query.getPageNum(), query.getPageSize());
return R.ok(page);
}
/**
* 设置尾数(白名单用户)
*/
@PostMapping("/digit/set")
public R<?> setDigit(@RequestBody SetDigitDTO dto) {
try {
Long userId = UserContext.getUserId();
gameService.setTargetDigit(dto.getGroupId(), dto.getDigit(), userId);
return R.ok("尾数已设置");
} catch (RuntimeException e) {
return R.fail(e.getMessage());
}
}
}