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());
}
}
}
@@ -0,0 +1,69 @@
package com.tailbet.controller;
import com.tailbet.model.dto.PointsDTO;
import com.tailbet.model.dto.PullGroupDTO;
import com.tailbet.model.vo.R;
import com.tailbet.model.vo.UserContext;
import com.tailbet.service.IPointsService;
import com.tailbet.service.IGroupService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
/**
* 运营Controller
*/
@RestController
@RequestMapping("/api/ops")
@RequiredArgsConstructor
public class OpsController {
private final IPointsService pointsService;
private final IGroupService groupService;
/**
* 加积分
*/
@PostMapping("/points/add")
public R<?> addPoints(@RequestBody PointsDTO dto) {
try {
Long operatorId = UserContext.getUserId();
pointsService.addPoints(dto.getUserId(), dto.getAmount(),
IPointsService.TYPE_OPS_ADD, null, operatorId, dto.getRemark());
return R.ok("加分成功");
} catch (RuntimeException e) {
return R.fail(e.getMessage());
}
}
/**
* 减积分
*/
@PostMapping("/points/sub")
public R<?> subPoints(@RequestBody PointsDTO dto) {
try {
Long operatorId = UserContext.getUserId();
boolean success = pointsService.subPoints(dto.getUserId(), dto.getAmount(),
IPointsService.TYPE_OPS_SUB, null, operatorId, dto.getRemark());
if (success) {
return R.ok("减分成功");
}
return R.fail("余额不足或用户不存在");
} catch (RuntimeException e) {
return R.fail(e.getMessage());
}
}
/**
* 拉入群
*/
@PostMapping("/group/pull")
public R<?> pullGroup(@RequestBody PullGroupDTO dto) {
try {
Long operatorId = UserContext.getUserId();
groupService.pullUser(dto.getGroupId(), dto.getUserId(), operatorId);
return R.ok("拉群成功");
} catch (RuntimeException e) {
return R.fail(e.getMessage());
}
}
}
@@ -0,0 +1,58 @@
package com.tailbet.controller;
import com.tailbet.model.dto.ReceiveRpDTO;
import com.tailbet.model.dto.SendRpDTO;
import com.tailbet.model.vo.R;
import com.tailbet.model.vo.UserContext;
import com.tailbet.service.IRedPacketService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
/**
* 红包Controller
*/
@RestController
@RequestMapping("/api/rp")
@RequiredArgsConstructor
public class RedPacketController {
private final IRedPacketService redPacketService;
/**
* 发红包
*/
@PostMapping("/send")
public R<?> sendRp(@RequestBody SendRpDTO dto) {
try {
Long userId = UserContext.getUserId();
var rp = redPacketService.sendRp(userId, dto.getGroupId(),
dto.getTotalAmount(), dto.getTotalCount(), dto.getRoundId());
return R.ok(rp);
} catch (RuntimeException e) {
return R.fail(e.getMessage());
}
}
/**
* 领红包
*/
@PostMapping("/receive")
public R<?> receiveRp(@RequestBody ReceiveRpDTO dto) {
try {
Long userId = UserContext.getUserId();
var recv = redPacketService.receiveRp(dto.getRpId(), userId);
return R.ok(recv);
} catch (RuntimeException e) {
return R.fail(e.getMessage());
}
}
/**
* 获取红包详情
*/
@GetMapping("/detail")
public R<?> detail(Long rpId) {
var rp = redPacketService.getById(rpId);
return R.ok(rp);
}
}
@@ -0,0 +1,80 @@
package com.tailbet.controller;
import com.tailbet.model.dto.LoginDTO;
import com.tailbet.model.dto.RegisterDTO;
import com.tailbet.model.dto.UpdateUserDTO;
import com.tailbet.model.vo.LoginUserVo;
import com.tailbet.model.vo.R;
import com.tailbet.model.vo.UserContext;
import com.tailbet.service.IUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
/**
* 用户Controller
*/
@RestController
@RequestMapping("/api/user")
@RequiredArgsConstructor
public class UserController {
private final IUserService userService;
/**
* 注册
*/
@PostMapping("/register")
public R<?> register(@RequestBody RegisterDTO dto) {
try {
userService.register(dto.getUsername(), dto.getPassword());
return R.ok("注册成功");
} catch (RuntimeException e) {
return R.fail(e.getMessage());
}
}
/**
* 登录
*/
@PostMapping("/login")
public R<?> login(@RequestBody LoginDTO dto) {
try {
String token = userService.login(dto.getUsername(), dto.getPassword());
return R.ok("登录成功", java.util.Map.of("token", token));
} catch (RuntimeException e) {
return R.fail(e.getMessage());
}
}
/**
* 获取当前用户信息
*/
@GetMapping("/info")
public R<?> getInfo() {
LoginUserVo user = UserContext.getUser();
return R.ok(user);
}
/**
* 更新用户信息
*/
@PutMapping("/update")
public R<?> update(@RequestBody UpdateUserDTO dto) {
try {
Long userId = UserContext.getUserId();
userService.updateUserInfo(userId, dto);
return R.ok("更新成功");
} catch (RuntimeException e) {
return R.fail(e.getMessage());
}
}
/**
* 退出登录
*/
@PostMapping("/logout")
public R<?> logout() {
// 可以在这里清理Redis中的token
return R.ok("退出成功");
}
}