admin_backend/controller/user.go
2025-05-06 10:07:31 +08:00

96 lines
1.8 KiB
Go

package controller
import (
"backend/model"
"fmt"
"github.com/gin-gonic/gin"
)
func UserInfo(c *gin.Context) {
c.JSON(200, gin.H{
"code": 0,
"data": map[string]interface{}{
"id": 0,
"realName": "Vben",
"roles": []string{"super"},
"username": "vben",
},
"message": "Hello, world!",
})
}
// 获取玩家列表
func UserList(c *gin.Context) {
var request struct {
Id int `json:"Id"`
Uid int `json:"Uid"`
ServerId int `json:"ServerId"`
PageSize int `json:"pageSize"`
CurrentPage int `json:"currentPage"`
}
err := c.BindJSON(&request)
if err != nil {
fmt.Print(err)
failed(c, err.Error())
return
}
user, total, err := model.GetUserList(request.Id, request.ServerId, request.PageSize, request.CurrentPage, request.Uid)
if err != nil {
fmt.Print(err)
failed(c, err.Error())
return
}
success(c, map[string]interface{}{
"total": total,
"data": user,
})
}
func UserDetail(c *gin.Context) {
var request struct {
Uid int `json:"Id"`
}
err := c.BindJSON(&request)
if err != nil {
fmt.Print(err)
failed(c, err.Error())
return
}
user, err := model.UserDetail(request.Uid)
if err != nil {
fmt.Print(err)
failed(c, err.Error())
return
}
success(c, user)
}
func UserGM(c *gin.Context) {
var request struct {
AppId int `json:"AppId"`
ServerId int `json:"ServerId"`
Uid int `json:"Uid"`
Command string `json:"Command"`
}
err := c.BindJSON(&request)
if err != nil {
fmt.Print(err)
failed(c, err.Error())
return
}
if request.Command == "" || request.AppId == 0 || request.AppId == 3 {
failed(c, "参数错误")
}
r, err := model.UserGM(request.AppId, request.ServerId, request.Uid, request.Command)
if err != nil {
fmt.Print(err)
failed(c, err.Error())
return
}
success(c, r)
}