bindbox-game/internal/api/admin/admin_list.go
邹方成 1ab39d2f5a
Some checks failed
Build docker and publish / linux (1.24.5) (push) Failing after 25s
refactor: 重构项目结构并重命名模块
feat(admin): 新增工会管理功能
feat(activity): 添加活动管理相关服务
feat(user): 实现用户道具卡和积分管理
feat(guild): 新增工会成员管理功能

fix: 修复数据库连接配置
fix: 修正jwtoken导入路径
fix: 解决端口冲突问题

style: 统一代码格式和注释风格
style: 更新项目常量命名

docs: 添加项目框架和开发规范文档
docs: 更新接口文档注释

chore: 移除无用代码和文件
chore: 更新Makefile和配置文件
chore: 清理日志文件

test: 添加道具卡测试脚本
2025-11-14 21:10:00 +08:00

127 lines
3.3 KiB
Go
Executable File
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 admin
import (
"fmt"
"net/http"
"bindbox-game/internal/code"
"bindbox-game/internal/pkg/core"
"bindbox-game/internal/pkg/timeutil"
"bindbox-game/internal/pkg/validation"
adminsvc "bindbox-game/internal/service/admin"
)
type listRequest struct {
Username string `form:"username"` // 用户名
Nickname string `form:"nickname"` // 昵称
Page int `form:"page"` // 当前页码,默认为第一页
PageSize int `form:"page_size"` // 每页返回的数据量
}
type listData struct {
ID int32 `json:"id"` // 编号
UserName string `json:"username"` // 用户名
NickName string `json:"nickname"` // 昵称
Mobile string `json:"mobile"` // 手机号
Avatar string `json:"avatar"` // 头像
CreatedAt string `json:"created_at"` // 创建时间
UpdatedAt string `json:"updated_at"` // 更新时间
}
type listResponse struct {
Page int `json:"page"` // 当前页码
PageSize int `json:"page_size"` // 每页返回的数据量
Total int64 `json:"total"` // 符合查询条件的总记录数
List []listData `json:"list"`
}
// PageList 客服列表
// @Summary 客服列表
// @Description 客服列表
// @Tags 管理端.客服管理
// @Accept json
// @Produce json
// @Param username query string false "用户名"
// @Param nickname query string false "昵称"
// @Param page query int true "当前页码" default(1)
// @Param page_size query int true "每页返回的数据量,最多 100 条" default(20)
// @Success 200 {object} listResponse
// @Failure 400 {object} code.Failure
// @Router /api/admin/list [get]
// @Security LoginVerifyToken
func (h *handler) PageList() core.HandlerFunc {
return func(ctx core.Context) {
req := new(listRequest)
res := new(listResponse)
if err := ctx.ShouldBindForm(req); err != nil {
ctx.AbortWithError(core.Error(
http.StatusBadRequest,
code.ParamBindError,
validation.Error(err)),
)
return
}
if req.Page == 0 {
req.Page = 1
}
if req.PageSize == 0 {
req.PageSize = 20
}
if req.PageSize > 100 {
ctx.AbortWithError(core.Error(
http.StatusBadRequest,
code.ListAdminError,
fmt.Sprintf("%s: 一次最多只能查询 100 条", code.Text(code.ListAdminError)),
))
return
}
if ctx.SessionUserInfo().IsSuper != 1 {
ctx.AbortWithError(core.Error(
http.StatusBadRequest,
code.ListAdminError,
fmt.Sprintf("%s: %s", code.Text(code.ListAdminError), "禁止操作")),
)
return
}
items, total, err := h.svc.List(ctx.RequestContext(), adminsvc.ListInput{
Username: req.Username,
Nickname: req.Nickname,
Page: req.Page,
PageSize: req.PageSize,
})
if err != nil {
ctx.AbortWithError(core.Error(
http.StatusBadRequest,
code.ListAdminError,
fmt.Sprintf("%s%s", code.Text(code.ListAdminError), err.Error())),
)
return
}
res.Page = req.Page
res.PageSize = req.PageSize
res.Total = total
res.List = make([]listData, len(items))
for k, v := range items {
res.List[k] = listData{
ID: v.ID,
UserName: v.Username,
NickName: v.Nickname,
Mobile: v.Mobile,
Avatar: v.Avatar,
CreatedAt: timeutil.FriendlyTime(v.CreatedAt),
UpdatedAt: timeutil.FriendlyTime(v.CreatedAt),
}
}
ctx.Payload(res)
}
}