查询玩家基本信息

This commit is contained in:
yangduo 2024-06-26 20:41:26 +08:00
parent ecd609ffc0
commit 4dee75f5b2
4 changed files with 261 additions and 0 deletions

35
doc/admin/player.js Normal file
View File

@ -0,0 +1,35 @@
const common = require('../common');
module.exports = class {
constructor() {
this.apis = [
{
'method': 'POST',
'name': 'info',
'desc': '获取玩家信息',
'group': 'player',
'url': 'api/v1/player/info',
'header': [
],
'is_json_params': true,
'params': [
['name', '', '用户名字'],
['accurate_name'], false, '是否精确匹配名字',
['account_id', '', '账号id'],
['address', '', '钱包地址'],
],
'uri_params': [
['cursor', '', '游标'],
['page_size', '', '每页数量'],
],
'response': [
new common.RspHead(),
['!data', common.Player()]
]
}
];
}
// ...
}

View File

@ -0,0 +1,93 @@
package system
import (
"f5"
"fmt"
"main/common"
"main/constant"
"main/model/system"
"net/http"
"q5"
"github.com/gin-gonic/gin"
)
type PlayerApi struct {
}
func (this *PlayerApi) Info(c *gin.Context) {
type InfoForm struct {
Playername string `json:"playername"`
AccurateName bool `json:"accurate_name"`
Account_id string `json:"account_id"`
Address string `json:"address"`
}
reqJson := InfoForm{}
if err := c.ShouldBindJSON(&reqJson); err != nil {
c.JSON(http.StatusOK, gin.H{
"code": 1,
"message": err.Error(),
})
return
}
cursor := q5.ToInt64(c.DefaultQuery("cursor", ""))
filterstr := ""
if reqJson.Playername != "" {
if reqJson.AccurateName {
filterstr = " name = '" + reqJson.Playername + "' "
} else {
filterstr = " name like '%" + reqJson.Playername + "%'"
}
} else if reqJson.Account_id != "" {
filterstr = " account_id = '" + reqJson.Account_id + "'"
} else if reqJson.Address != "" {
filterstr = " address = '" + reqJson.Address + "'"
} else {
c.JSON(http.StatusOK, gin.H{
"code": 1,
"message": "input one of playername, account_id, address",
})
return
}
sql := fmt.Sprintf(`SELECT * FROM t_user WHERE idx > %d AND %s `, cursor, filterstr)
rspObj := struct {
ErrCode int32 `json:"errcode"`
ErrMsg string `json:"errmsg"`
Page common.StreamPagination `json:"page"`
Rows []system.Player `json:"rows"`
}{
Rows: []system.Player{},
}
pageSize := q5.AdjustRangeValue(q5.ToInt32(c.DefaultQuery("page_size", "")), 1, 20)
params := []string{}
subFilters := []f5.DbQueryFilter{}
orderBy := ""
f5.GetGoStyleDb().StreamPageQuery(
constant.GAME_DB,
pageSize,
cursor,
sql,
params,
f5.GetDbFilter().Comp(subFilters...),
orderBy,
func(err error, pagination *f5.StreamPagination) {
rspObj.Page.FillPage(pagination)
},
func(ds *f5.DataSet) {
p := new(system.Player)
p.LoadFromDs(ds)
rspObj.Rows = append(rspObj.Rows, *p)
})
c.JSON(200, rspObj)
}

View File

@ -0,0 +1,116 @@
package system
import (
"f5"
"q5"
"strings"
)
type Player struct {
Idx int64 `json:"idx"`
Account_id string `gorm:"uniqueIndex;comment:用户id" json:"account_id"`
Channel string `gorm:"comment:渠道id" json:"channel"`
Name string `gorm:"comment:用户名" json:"name"`
Sex int `gorm:"comment:性别" json:"sex"`
Head_id int `gorm:"comment:头像id" json:"head_id"`
Head_frame int `gorm:"comment:头像框id" json:"head_frame"`
Level int `gorm:"comment:等级" json:"level"`
Exp int `gorm:"comment:经验" json:"exp"`
Rank int `gorm:"comment:段位" json:"rank"`
History_best_rank int `gorm:"comment:历史最高段位" json:"history_best_rank"`
Score int `gorm:"comment:积分" json:"score"`
History_best_score int `gorm:"comment:历史最高积分" json:"history_best_score"`
Elo int `gorm:"comment:隐藏elo积分" json:"elo"`
Bceg int `gorm:"comment:治理代币" json:"bceg"`
Gold int `gorm:"comment:金币" json:"gold"`
Diamond int `gorm:"comment:钻石" json:"diamond"`
Hero_id int `gorm:"comment:当前上阵英雄id" json:"hero_id"`
First_fight int `gorm:"comment:是否首战" json:"first_fight"`
Last_season_id int `gorm:"comment:最后一次赛季id" json:"last_season_id"`
Activated int `gorm:"comment:是否已激活" json:"activated"`
Rename_count int `gorm:"comment:改名次数" json:"rename_count"`
Activatetime int `gorm:"comment:激活时间" json:"activatetime"`
Already_guide int `gorm:"comment:已引导" json:"already_guide"`
Pve_instance_id int `gorm:"comment:已过pve副本id" json:"pve_instance_id"`
Like_count int `gorm:"comment:被点赞次数" json:"like_count"`
Head_list []string `gorm:"comment:拥有的头像列表" json:"head_list"`
Head_frame_list []string `gorm:"comment:拥有的头像框列表" json:"head_frame_list"`
Consume_gold int64 `gorm:"comment:消费金币数" json:"consume_gold"`
Score_modifytime int `gorm:"comment:积分修改时间" json:"score_modifytime"`
Best_rank_modifytime int `gorm:"comment:积分修改次数" json:"best_rank_modifytime"`
Createtime int `gorm:"comment:创建时间" json:"createtime"`
Last_login_time int `gorm:"comment:上次登录时间" json:"last_login_time"`
Is_gain_item int `gorm:"comment:是否获取免费item道具" json:"is_gain_item"`
Guild_id string `gorm:"comment:工会id" json:"guild_id"`
Guild_job int `gorm:"comment:工会职位" json:"guild_job"`
Guild_name string `gorm:"comment:工会名称" json:"guild_name"`
Ring_id int `gorm:"comment:戒指id" json:"ring_id"`
Parachute int `gorm:"comment:降落伞id" json:"parachute"`
Star_num int `gorm:"comment:星星数(成长任务)" json:"star_num"`
Address string `gorm:"uniqueIndex;comment:钱包地址" json:"address"`
}
func (this *Player) TableName() string {
return "t_user"
}
func (this *Player) LoadFromDs(ds *f5.DataSet) {
this.Idx = q5.ToInt64(ds.GetByName("idx"))
this.Account_id = ds.GetByName("account_id")
this.Channel = ds.GetByName("channel")
this.Name = ds.GetByName("name")
this.Sex = q5.ToInt(ds.GetByName("sex"))
this.Head_id = q5.ToInt(ds.GetByName("head_id"))
this.Head_frame = q5.ToInt(ds.GetByName("head_frame"))
this.Level = q5.ToInt(ds.GetByName("level"))
this.Exp = q5.ToInt(ds.GetByName("exp"))
this.Rank = q5.ToInt(ds.GetByName("rank"))
this.History_best_rank = q5.ToInt(ds.GetByName("history_best_rank"))
this.Score = q5.ToInt(ds.GetByName("score"))
this.History_best_score = q5.ToInt(ds.GetByName("history_best_score"))
this.Elo = q5.ToInt(ds.GetByName("elo"))
this.Bceg = q5.ToInt(ds.GetByName("bceg"))
this.Gold = q5.ToInt(ds.GetByName("gold"))
this.Diamond = q5.ToInt(ds.GetByName("diamond"))
this.Hero_id = q5.ToInt(ds.GetByName("hero_id"))
this.First_fight = q5.ToInt(ds.GetByName("first_fight"))
this.Last_season_id = q5.ToInt(ds.GetByName("last_season_id"))
this.Activated = q5.ToInt(ds.GetByName("activated"))
this.Rename_count = q5.ToInt(ds.GetByName("rename_count"))
this.Activatetime = q5.ToInt(ds.GetByName("activatetime"))
this.Already_guide = q5.ToInt(ds.GetByName("already_guide"))
this.Pve_instance_id = q5.ToInt(ds.GetByName("pve_instance_id"))
this.Like_count = q5.ToInt(ds.GetByName("like_count"))
this.Head_list = this.GetPureStringSlice(ds.GetByName("head_list"))
this.Head_frame_list = this.GetPureStringSlice(ds.GetByName("head_frame_list"))
this.Consume_gold = q5.ToInt64(ds.GetByName("consume_gold"))
this.Score_modifytime = q5.ToInt(ds.GetByName("score_modifytime"))
this.Best_rank_modifytime = q5.ToInt(ds.GetByName("best_rank_modifytime"))
this.Createtime = q5.ToInt(ds.GetByName("createtime"))
this.Last_login_time = q5.ToInt(ds.GetByName("last_login_time"))
this.Is_gain_item = q5.ToInt(ds.GetByName("is_gain_item"))
this.Guild_id = ds.GetByName("guild_id")
this.Guild_job = q5.ToInt(ds.GetByName("guild_job"))
this.Guild_name = ds.GetByName("guild_name")
this.Ring_id = q5.ToInt(ds.GetByName("ring_id"))
this.Parachute = q5.ToInt(ds.GetByName("parachute"))
this.Star_num = q5.ToInt(ds.GetByName("star_num"))
this.Address = ds.GetByName("address")
}
func (this *Player) GetPureStringSlice(src string) []string {
if src == "" {
return []string{}
}
if src[0] == '[' {
src = src[1:]
}
if src[len(src)-1] == ']' {
src = src[:len(src)-1]
}
src = strings.Replace(src, "\"", "", -1)
return q5.StrSplit(src, ",")
}

View File

@ -0,0 +1,17 @@
package system
import (
v1 "main/api/v1"
"github.com/gin-gonic/gin"
)
type PlayerRouter struct{}
func (this *PlayerRouter) InitPlayerRouter(priRouter *gin.RouterGroup) {
group := priRouter.Group("player")
api := v1.ApiGroupApp.SystemApiGroup.PlayerApi
{
group.POST("info", api.Info)
}
}