148 lines
2.8 KiB
Go
148 lines
2.8 KiB
Go
package controller
|
|
|
|
import (
|
|
"backend/model"
|
|
"backend/store"
|
|
"backend/util"
|
|
"fmt"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func UserInfo(c *gin.Context) {
|
|
Token := util.GetToken(c)
|
|
Info, _ := store.GetTokenInfo(Token)
|
|
c.JSON(200, gin.H{
|
|
"code": 0,
|
|
"data": map[string]interface{}{
|
|
"id": 0,
|
|
"realName": Info.UserName,
|
|
"roles": []string{Info.Role},
|
|
"username": Info.UserName,
|
|
},
|
|
"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 UserHeat(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 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)
|
|
log := model.Log{
|
|
Uid: request.Uid,
|
|
}
|
|
heat, _ := log.Heat()
|
|
if err != nil {
|
|
fmt.Print(err)
|
|
failed(c, err.Error())
|
|
return
|
|
}
|
|
user["Heatmap"] = heat
|
|
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)
|
|
}
|
|
|
|
func UserBan(c *gin.Context) {
|
|
var request struct {
|
|
AppId int `json:"AppId"`
|
|
ServerId int `json:"ServerId"`
|
|
Uid int `json:"Uid"`
|
|
Day int `json:"Day"`
|
|
Reason string `json:"Reason"`
|
|
}
|
|
err := c.BindJSON(&request)
|
|
if err != nil {
|
|
fmt.Print(err)
|
|
failed(c, err.Error())
|
|
return
|
|
}
|
|
|
|
r, err := model.UserBan(request.AppId, request.ServerId, request.Uid, request.Day, request.Reason)
|
|
if err != nil {
|
|
fmt.Print(err)
|
|
failed(c, err.Error())
|
|
return
|
|
}
|
|
|
|
success(c, r)
|
|
}
|