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

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

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

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

60 lines
1.7 KiB
Go

package app
import (
"bindbox-game/internal/code"
"bindbox-game/internal/pkg/core"
"bindbox-game/internal/pkg/validation"
"net/http"
)
type redeemItemCardRequest struct {
CardID int64 `json:"card_id"`
Quantity int `json:"quantity"`
}
type redeemItemCardResponse struct {
Success bool `json:"success"`
CardID int64 `json:"card_id"`
LedgerID int64 `json:"ledger_id"`
Message string `json:"message"`
}
// RedeemPointsToItemCard 积分兑换道具卡
// @Summary 积分兑换道具卡
// @Description 使用积分兑换指定数量的道具卡
// @Tags APP端.用户
// @Accept json
// @Produce json
// @Security LoginVerifyToken
// @Param user_id path int true "用户ID"
// @Param request body redeemItemCardRequest true "兑换请求参数"
// @Success 200 {object} redeemItemCardResponse
// @Failure 400 {object} code.Failure
// @Router /api/app/users/{user_id}/points/redeem-item-card [post]
func (h *handler) RedeemPointsToItemCard() core.HandlerFunc {
return func(ctx core.Context) {
req := new(redeemItemCardRequest)
rsp := new(redeemItemCardResponse)
if err := ctx.ShouldBindJSON(req); err != nil {
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, validation.Error(err)))
return
}
if req.Quantity <= 0 {
req.Quantity = 1
}
userID := int64(ctx.SessionUserInfo().Id)
ledgerID, err := h.user.RedeemItemCard(ctx.RequestContext(), userID, req.CardID, req.Quantity)
if err != nil {
ctx.AbortWithError(core.Error(http.StatusBadRequest, 150201, err.Error()))
return
}
rsp.Success = true
rsp.CardID = req.CardID
rsp.LedgerID = ledgerID
rsp.Message = "ok"
ctx.Payload(rsp)
}
}