Some checks failed
Build docker and publish / linux (1.24.5) (push) Failing after 25s
feat(admin): 新增工会管理功能 feat(activity): 添加活动管理相关服务 feat(user): 实现用户道具卡和积分管理 feat(guild): 新增工会成员管理功能 fix: 修复数据库连接配置 fix: 修正jwtoken导入路径 fix: 解决端口冲突问题 style: 统一代码格式和注释风格 style: 更新项目常量命名 docs: 添加项目框架和开发规范文档 docs: 更新接口文档注释 chore: 移除无用代码和文件 chore: 更新Makefile和配置文件 chore: 清理日志文件 test: 添加道具卡测试脚本
76 lines
2.1 KiB
Go
76 lines
2.1 KiB
Go
package admin
|
||
|
||
import (
|
||
"strconv"
|
||
|
||
"bindbox-game/internal/pkg/core"
|
||
"bindbox-game/internal/service/user"
|
||
|
||
"go.uber.org/zap"
|
||
)
|
||
|
||
// GrantRewardRequest 奖励发放请求(复用service层的结构体)
|
||
type GrantRewardRequest = user.GrantRewardRequest
|
||
|
||
// GrantRewardResponse 奖励发放响应(复用service层的结构体)
|
||
type GrantRewardResponse = user.GrantRewardResponse
|
||
|
||
// GrantReward 给用户发放奖励
|
||
// @Summary 给用户发放奖励
|
||
// @Description 管理员给用户发放奖励,支持实物和虚拟奖品,可选择关联活动和奖励配置
|
||
// @Tags 管理端.用户
|
||
// @Accept json
|
||
// @Produce json
|
||
// @Param user_id path integer true "用户ID"
|
||
// @Param RequestBody body GrantRewardRequest true "请求参数"
|
||
// @Success 200 {object} GrantRewardResponse
|
||
// @Failure 400 {object} code.Failure
|
||
// @Failure 401 {object} code.Failure
|
||
// @Failure 403 {object} code.Failure
|
||
// @Failure 500 {object} code.Failure
|
||
// @Router /api/admin/users/{user_id}/rewards/grant [post]
|
||
func (h *handler) GrantReward() core.HandlerFunc {
|
||
return func(ctx core.Context) {
|
||
userIDStr := ctx.Param("user_id")
|
||
if userIDStr == "" {
|
||
ctx.AbortWithError(core.Error(400, 40001, "用户ID不能为空"))
|
||
return
|
||
}
|
||
|
||
// 解析用户ID
|
||
userID, err := strconv.ParseInt(userIDStr, 10, 64)
|
||
if err != nil {
|
||
ctx.AbortWithError(core.Error(400, 40001, "用户ID格式错误"))
|
||
return
|
||
}
|
||
|
||
// 权限检查 - 仅超管可以发放奖励
|
||
if ctx.SessionUserInfo().IsSuper != 1 {
|
||
ctx.AbortWithError(core.Error(403, 40301, "无权限发放奖励"))
|
||
return
|
||
}
|
||
|
||
// 解析请求参数
|
||
var req GrantRewardRequest
|
||
if err := ctx.ShouldBindJSON(&req); err != nil {
|
||
zap.L().Error("解析奖励发放请求失败", zap.Error(err))
|
||
ctx.AbortWithError(core.Error(400, 40001, "参数格式错误"))
|
||
return
|
||
}
|
||
|
||
// 调用服务层发放奖励
|
||
resp, err := h.user.GrantReward(ctx.RequestContext(), userID, user.GrantRewardRequest(req))
|
||
if err != nil {
|
||
zap.L().Error("发放奖励失败",
|
||
zap.Int64("user_id", userID),
|
||
zap.Error(err),
|
||
)
|
||
ctx.AbortWithError(core.Error(500, 50001, err.Error()))
|
||
return
|
||
}
|
||
|
||
// 返回成功响应
|
||
ctx.Payload(resp)
|
||
}
|
||
}
|