171 lines
3.8 KiB
Go
171 lines
3.8 KiB
Go
package controller
|
|
|
|
import (
|
|
"backend/Type"
|
|
"backend/model"
|
|
"backend/store"
|
|
"backend/util"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func UserInfo(c *gin.Context) {
|
|
Token := util.GetToken(c)
|
|
Info, _ := store.GetTokenInfo(Token)
|
|
homePath := "/dashboard"
|
|
if Info.Role == "wb_transfer" {
|
|
homePath = "/language"
|
|
}
|
|
c.JSON(200, gin.H{
|
|
"code": 0,
|
|
"data": map[string]interface{}{
|
|
"id": 0,
|
|
"realName": Info.UserName,
|
|
"roles": []string{Info.Role},
|
|
"username": Info.UserName,
|
|
"homePath": homePath,
|
|
},
|
|
"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"`
|
|
StartTime int `json:"StartTime"`
|
|
EndTime int `json:"EndTime"`
|
|
Nickname string `json:"Nickname"`
|
|
Username string `json:"Username"`
|
|
DeviceId string `json:"DeviceId"`
|
|
}
|
|
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, request.StartTime, request.EndTime, request.Nickname, request.Username, request.DeviceId)
|
|
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"`
|
|
Node int `json:"Node"`
|
|
AppId int `json:"AppId"`
|
|
}
|
|
err := c.BindJSON(&request)
|
|
if err != nil {
|
|
fmt.Print(err)
|
|
failed(c, err.Error())
|
|
return
|
|
}
|
|
user, err := model.UserDetail(request.AppId, request.Uid, request.Node)
|
|
if user["Order"] != nil {
|
|
order := user["Order"].(map[string]interface{})
|
|
for k, v := range order {
|
|
info := v.(map[string]interface{})
|
|
chess_id := info["ChessId"].(string)
|
|
chess_list := strings.Split(chess_id, " ")
|
|
chess_arr := []Type.ChessData{}
|
|
for _, cid := range chess_list {
|
|
if cid == "" {
|
|
continue
|
|
}
|
|
chess_url := util.GetChessURL(cid)
|
|
chess_arr = append(chess_arr, Type.ChessData{
|
|
Id: cid,
|
|
Icon: chess_url,
|
|
})
|
|
}
|
|
info["ChessId"] = chess_arr
|
|
order[k] = info
|
|
}
|
|
}
|
|
|
|
if user["FriendList"] != nil {
|
|
friendList := user["FriendList"].([]interface{})
|
|
for k, v := range friendList {
|
|
info := v.(map[string]interface{})
|
|
face_url := util.GetFaceURL(util.Int(info["Avatar"]))
|
|
info["avatarUrl"] = face_url
|
|
friendList[k] = info
|
|
info["onlineStatus"] = util.Int(info["LoginTime"]) > util.Int(info["LogoutTime"])
|
|
}
|
|
user["FriendList"] = friendList
|
|
}
|
|
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)
|
|
}
|
|
|
|
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)
|
|
}
|