邹方成 c8b04e2bc6 feat(活动): 新增抽奖记录等级筛选功能并优化展示信息
refactor(抽奖记录): 重构抽奖记录列表接口,支持按等级筛选
新增用户昵称、头像及奖品名称、图片等展示字段
优化分页逻辑,默认返回最新100条记录

feat(游戏): 添加扫雷游戏验证和结算接口
新增游戏票据验证和结算相关接口定义及Swagger文档

docs(API): 更新Swagger文档
更新抽奖记录和游戏相关接口的文档描述

style(路由): 添加游戏路由注释
添加扫雷游戏接口路由的占位注释
2025-12-21 23:45:01 +08:00

120 lines
2.7 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package minesweeper
import (
"bindbox-game/internal/pkg/core"
"bindbox-game/internal/repository/mysql"
"go.uber.org/zap"
)
type Handler struct {
logger *zap.Logger
db mysql.Repo
}
func New(logger *zap.Logger, db mysql.Repo) *Handler {
return &Handler{
logger: logger,
db: db,
}
}
// i() 辅助函数
func (h *Handler) i() {}
// VerifyTicket 验证游戏票据
// @Summary 验证游戏票据
// @Description 验证游戏票据是否有效
// @Tags Internal
// @Accept json
// @Produce json
// @Param ticket body VerifyTicketRequest true "票据信息"
// @Success 200 {object} VerifyTicketResponse
// @Router /internal/game/verify [post]
func (h *Handler) VerifyTicket() core.HandlerFunc {
return func(c core.Context) {
req := new(VerifyTicketRequest)
if err := c.ShouldBindJSON(req); err != nil {
c.AbortWithError(core.Error(
400,
10001,
"参数错误",
))
return
}
// TODO: 实际验证逻辑这里先Mock通过
// 实际应该检查Redis中ticket是否存在且对应正确的user_id
c.Payload(VerifyTicketResponse{
Valid: true,
UserID: req.UserID,
RemainingTimes: 1, // Mock
})
}
}
// SettleGame 结算游戏
// @Summary 结算游戏
// @Description 游戏结束后结算并发放奖励
// @Tags Internal
// @Accept json
// @Produce json
// @Param result body SettleGameRequest true "结算信息"
// @Success 200 {object} SettleGameResponse
// @Router /internal/game/settle [post]
func (h *Handler) SettleGame() core.HandlerFunc {
return func(c core.Context) {
req := new(SettleGameRequest)
if err := c.ShouldBindJSON(req); err != nil {
c.AbortWithError(core.Error(
400,
10001,
"参数错误",
))
return
}
// TODO: 实际结算逻辑
// 1. 验证 ticket 状态为“进行中”
// 2. 如果 Win=true发放奖励
// 3. 标记 ticket 为“已完成”
h.logger.Info("Game Settled",
zap.String("user_id", req.UserID),
zap.Bool("win", req.Win),
zap.Int("score", req.Score),
)
c.Payload(SettleGameResponse{
Success: true,
Reward: "100积分", // Mock
})
}
}
type VerifyTicketRequest struct {
UserID string `json:"user_id"`
Ticket string `json:"ticket"`
}
type VerifyTicketResponse struct {
Valid bool `json:"valid"`
UserID string `json:"user_id"`
RemainingTimes int `json:"remaining_times"`
}
type SettleGameRequest struct {
UserID string `json:"user_id"`
Ticket string `json:"ticket"`
MatchID string `json:"match_id"`
Win bool `json:"win"`
Score int `json:"score"`
Metadata string `json:"metadata"`
}
type SettleGameResponse struct {
Success bool `json:"success"`
Reward string `json:"reward"`
}