bindbox-game/internal/api/user/points_redeem_item_card_app.go
邹方成 45815bfb7d chore: 清理无用文件与优化代码结构
refactor(utils): 修复密码哈希比较逻辑错误
feat(user): 新增按状态筛选优惠券接口
docs: 添加虚拟发货与任务中心相关文档
fix(wechat): 修正Code2Session上下文传递问题
test: 补充订单折扣与积分转换测试用例
build: 更新配置文件与构建脚本
style: 清理多余的空行与注释
2025-12-18 17:35:55 +08:00

48 lines
1.2 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"`
}
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)
}
}