bindbox-game/internal/api/admin/guild_applications.go
邹方成 6ee627139c
Some checks failed
Build docker and publish / linux (1.24.5) (push) Failing after 40s
feat: 新增支付测试小程序与微信支付集成
feat(pay): 添加支付API基础结构
feat(miniapp): 创建支付测试小程序页面与配置
feat(wechatpay): 配置微信支付参数与证书
fix(guild): 修复成员列表查询条件
docs: 更新代码规范文档与需求文档
style: 统一前后端枚举显示与注释格式
refactor(admin): 重构用户奖励发放接口参数处理
test(title): 添加称号效果参数验证测试
2025-11-17 00:42:08 +08:00

112 lines
4.2 KiB
Go

package admin
import (
"net/http"
"strconv"
"bindbox-game/internal/code"
"bindbox-game/internal/pkg/core"
"bindbox-game/internal/pkg/validation"
)
type listGuildApplicationsRequest struct {
Page int `form:"page"`
PageSize int `form:"page_size"`
}
type applicationItem struct {
ID int64 `json:"id"`
UserID int64 `json:"user_id"`
Role string `json:"role"`
ApplyTime string `json:"apply_time"`
}
type listGuildApplicationsResponse struct {
Page int `json:"page"`
PageSize int `json:"page_size"`
Total int64 `json:"total"`
List []applicationItem `json:"list"`
}
func (h *handler) ListGuildApplications() core.HandlerFunc {
return func(ctx core.Context) {
req := new(listGuildApplicationsRequest)
res := new(listGuildApplicationsResponse)
if err := ctx.ShouldBindForm(req); err != nil {
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, validation.Error(err)))
return
}
if ctx.SessionUserInfo().IsSuper != 1 {
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ListGuildMembersError, "禁止操作"))
return
}
id, err := strconv.ParseInt(ctx.Param("guild_id"), 10, 64)
if err != nil {
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, "未传递工会ID"))
return
}
items, total, err := h.guild.ListApplications(ctx.RequestContext(), id, req.Page, req.PageSize)
if err != nil {
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ListGuildMembersError, err.Error()))
return
}
res.Page = req.Page
res.PageSize = req.PageSize
res.Total = total
res.List = make([]applicationItem, len(items))
for i, v := range items {
res.List[i] = applicationItem{ID: v.ID, UserID: v.UserID, Role: v.Role, ApplyTime: v.CreatedAt.Format("2006-01-02 15:04:05")}
}
ctx.Payload(res)
}
}
func (h *handler) ApproveGuildApplication() core.HandlerFunc {
return func(ctx core.Context) {
res := new(simpleMessageResponse)
if ctx.SessionUserInfo().IsSuper != 1 {
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ModifyGuildError, "禁止操作"))
return
}
guildID, err := strconv.ParseInt(ctx.Param("guild_id"), 10, 64)
if err != nil {
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, "未传递工会ID"))
return
}
memberID, err := strconv.ParseInt(ctx.Param("member_id"), 10, 64)
if err != nil {
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, "未传递成员记录ID"))
return
}
if err := h.guild.ApproveApplication(ctx.RequestContext(), guildID, memberID); err != nil {
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ModifyGuildError, err.Error()))
return
}
res.Message = "操作成功"
ctx.Payload(res)
}
}
func (h *handler) RejectGuildApplication() core.HandlerFunc {
return func(ctx core.Context) {
res := new(simpleMessageResponse)
if ctx.SessionUserInfo().IsSuper != 1 {
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ModifyGuildError, "禁止操作"))
return
}
guildID, err := strconv.ParseInt(ctx.Param("guild_id"), 10, 64)
if err != nil {
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, "未传递工会ID"))
return
}
memberID, err := strconv.ParseInt(ctx.Param("member_id"), 10, 64)
if err != nil {
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, "未传递成员记录ID"))
return
}
if err := h.guild.RejectApplication(ctx.RequestContext(), guildID, memberID); err != nil {
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ModifyGuildError, err.Error()))
return
}
res.Message = "操作成功"
ctx.Payload(res)
}
}