一波更新
This commit is contained in:
@@ -10,13 +10,20 @@ root:
|
||||
es_urls: "http://10.252.0.70:18099"
|
||||
|
||||
# RabbitMQ 配置
|
||||
rabbitmq_config: "amqp://guest:guest@localhost:5672/"
|
||||
rabbitmq_address: "amqp://admin:admin@192.168.50.85:5672/"
|
||||
|
||||
# mq队列名称
|
||||
mq_queue_name: "admin_center"
|
||||
|
||||
# 是否通过mq执行sql
|
||||
sql_use_mq: true
|
||||
|
||||
# 数据库配置
|
||||
db_config:
|
||||
|
||||
# 实时更新数据库数量{玩家库/用户库}
|
||||
db_num: [0]
|
||||
|
||||
admin_db:
|
||||
# 最大处于开启状态的连接数
|
||||
max_open_conns: 0
|
||||
|
||||
@@ -29,10 +29,11 @@ require (
|
||||
github.com/jinzhu/now v1.1.5 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.17 // indirect
|
||||
github.com/streadway/amqp v1.1.0 // indirect
|
||||
golang.org/x/net v0.0.0-20210916014120-12bc252f5db8 // indirect
|
||||
golang.org/x/sys v0.6.0 // indirect
|
||||
golang.org/x/text v0.21.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
gorm.io/driver/mysql v1.5.7 // indirect
|
||||
gorm.io/gorm v1.25.12 // indirect
|
||||
)
|
||||
|
||||
@@ -53,6 +53,8 @@ github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
|
||||
github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/streadway/amqp v1.1.0 h1:py12iX8XSyI7aN/3dUT8DFIDJazNJsVJdxNVEpnQTZM=
|
||||
github.com/streadway/amqp v1.1.0/go.mod h1:WYSrTEYHOXHd0nwFeUXAe2G2hRnQT+deZJJf88uS9Bg=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
|
||||
@@ -80,8 +82,9 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkep
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gorm.io/driver/mysql v1.5.7 h1:MndhOPYOfEp2rHKgkZIhJ16eVUIRf2HmzgoPmh7FCWo=
|
||||
gorm.io/driver/mysql v1.5.7/go.mod h1:sEtPWMiqiN1N1cMXoXmBbd8C6/l+TESwriotuRRpkDM=
|
||||
gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
|
||||
|
||||
@@ -2,11 +2,14 @@ package admin
|
||||
|
||||
import (
|
||||
"common/connection"
|
||||
"time"
|
||||
)
|
||||
|
||||
func init() {
|
||||
//注册数据库
|
||||
connection.RegisterDBModel(&Admin{})
|
||||
connection.RegisterDBModel(&RecordLoginOfWxUser{})
|
||||
connection.RegisterDBModel(&RecordWatchADOfWxUser{})
|
||||
}
|
||||
|
||||
type Admin struct {
|
||||
@@ -29,6 +32,32 @@ type Admin struct {
|
||||
Describe string `gorm:"column:describe;comment:备注" json:"describe"`
|
||||
}
|
||||
|
||||
// 登录相关的记录
|
||||
type RecordLoginOfWxUser struct {
|
||||
ID int64 `gorm:"column:id;primary_key;comment:自增索引;autoIncrementIncrement" json:"id"`
|
||||
Uid int64 `gorm:"column:uid;comment:用户唯一Id" json:"uid"`
|
||||
LoginInTime int64 `gorm:"column:loginintime;comment:登录时间" json:"loginintime"`
|
||||
LoginOutTime int64 `gorm:"column:loginouttime;comment:登出时间" json:"loginouttime"`
|
||||
PlayTimes int64 `gorm:"column:playtimes;comment:游玩时长" json:"playtimes"`
|
||||
}
|
||||
|
||||
// 看广告相关记录
|
||||
// 记录日期便于按天统计
|
||||
type RecordWatchADOfWxUser struct {
|
||||
ID int64 `gorm:"column:id;primary_key;comment:自增索引;autoIncrementIncrement" json:"id"`
|
||||
RecordDate time.Time `gorm:"column:recorddate;type:date;comment:记录日期" json:"recorddate"`
|
||||
Uid int64 `gorm:"column:uid;comment:用户唯一Id" json:"uid"`
|
||||
WatchADNum int32 `gorm:"column:watchadnum;comment:看广告次数" json:"watchadnum"`
|
||||
}
|
||||
|
||||
func (Admin) TableName() string {
|
||||
return "admin"
|
||||
}
|
||||
|
||||
func (RecordLoginOfWxUser) TableName() string {
|
||||
return "recordloginofwxuser"
|
||||
}
|
||||
|
||||
func (RecordWatchADOfWxUser) TableName() string {
|
||||
return "recordwatchadofwxuser"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"common/mytime"
|
||||
"common/remark"
|
||||
"common/resultStatus"
|
||||
"common/webServer"
|
||||
@@ -201,3 +202,56 @@ func (a *AdminApi) Login(account string, password string) (responseObj *webServe
|
||||
responseObj.SetData(resultMap)
|
||||
return
|
||||
}
|
||||
|
||||
// 查询玩家登录相关记录
|
||||
func init() {
|
||||
moduleName := "AdminApi"
|
||||
methodName := "QueryloginRecord"
|
||||
skipVerifyTokenPage := true
|
||||
methodDesc := "查询玩家登录相关记录"
|
||||
methodAuthor := "youjinlan"
|
||||
methodMendor := ""
|
||||
methodDate := "2025-01-21 16:00:00"
|
||||
methodInParam := []string{"int64:uid"}
|
||||
methodOutParam := `
|
||||
{
|
||||
"Code '类型:int'": "响应结果的状态值",
|
||||
"Message '类型:string'": "响应结果的状态值所对应的描述信息",
|
||||
"Data '类型:interface{}'": "响应结果的数据"
|
||||
{
|
||||
"FirstLoginTime '类型:int64'": "首次登录时间",
|
||||
"PlayDayNum '类型:int32'": "生命周期",
|
||||
"PlayTimes '类型:int64'": "在线时长",
|
||||
}
|
||||
}`
|
||||
|
||||
remark.RegisterMethodRemark(moduleName, methodName, methodDesc, methodAuthor, methodMendor, methodDate, methodInParam, methodOutParam, skipVerifyTokenPage)
|
||||
}
|
||||
|
||||
func (a *AdminApi) QueryloginRecord(uid int64) (responseObj *webServer.ResponseObject) {
|
||||
responseObj = webServer.GetInitResponseObj()
|
||||
//验证参数
|
||||
if uid == 0 {
|
||||
responseObj.SetResultStatus(resultStatus.APIDataError)
|
||||
return
|
||||
}
|
||||
var userfirstRecord *RecordLoginOfWxUser
|
||||
if userfirstRecord, _ = GetUserFirstRecord(uid); userfirstRecord == nil {
|
||||
responseObj.SetResultStatus(resultStatus.PlayerNotExist)
|
||||
return
|
||||
}
|
||||
userLastRecord, _ := GetUserLastRecord(uid)
|
||||
firstLoginInTime := userfirstRecord.LoginInTime
|
||||
var lastLoginOutTime int64
|
||||
if userLastRecord.LoginOutTime == 0 {
|
||||
lastLoginOutTime = userLastRecord.LoginInTime
|
||||
}
|
||||
lastLoginOutTime = userLastRecord.LoginOutTime
|
||||
playDayNum := mytime.DiffDays(lastLoginOutTime, firstLoginInTime)
|
||||
resultMap := make(map[string]any)
|
||||
resultMap["FirstLoginTime"] = firstLoginInTime
|
||||
resultMap["PlayDayNum"] = playDayNum
|
||||
resultMap["PlayTimes"] = GetUserTotalPlayTime(uid)
|
||||
responseObj.SetData(resultMap)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ func AddAdmin(admin *Admin) (int64, error) {
|
||||
//处理一些验证
|
||||
|
||||
// 写入到数据库
|
||||
result := connection.GetAdminDB().Create(&admin) // 通过数据的指针来创建
|
||||
result := connection.Create(connection.GetAdminDB(), &admin, 0) // 通过数据的指针来创建
|
||||
|
||||
if result.Error != nil {
|
||||
logUtilPlus.ErrorLog("添加管理员失败 错误信息:", result.Error.Error())
|
||||
@@ -41,3 +41,29 @@ func Login(account string, password string) (*Admin, error) {
|
||||
}
|
||||
return &admin, nil
|
||||
}
|
||||
|
||||
// 查询玩家首次登录登出记录
|
||||
func GetUserFirstRecord(uid int64) (*RecordLoginOfWxUser, error) {
|
||||
var userRecord *RecordLoginOfWxUser
|
||||
result := connection.GetUserDB().Where("uid = ?", uid).First(&userRecord)
|
||||
if result.Error != nil {
|
||||
return nil, result.Error
|
||||
}
|
||||
return userRecord, nil
|
||||
}
|
||||
|
||||
// 查询玩家最新登录登出记录
|
||||
func GetUserLastRecord(uid int64) (*RecordLoginOfWxUser, error) {
|
||||
var userRecord *RecordLoginOfWxUser
|
||||
result := connection.GetUserDB().Where("uid = ?", uid).Last(&userRecord)
|
||||
if result.Error != nil {
|
||||
return nil, result.Error
|
||||
}
|
||||
return userRecord, nil
|
||||
}
|
||||
|
||||
func GetUserTotalPlayTime(uid int64) int64 {
|
||||
var totalPlayTime int64
|
||||
connection.GetUserDB().Table("recordloginofwxuser").Where("uid = ?", uid).Select("SUM(playtimes)").Scan(&totalPlayTime)
|
||||
return totalPlayTime
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ func loadConfig() {
|
||||
|
||||
//设置数据类型
|
||||
connection.SetModelDB(connection.GetAdminDB())
|
||||
connection.SetModelDB(connection.GetUserDB())
|
||||
|
||||
//构建数据库
|
||||
connection.BuildDB()
|
||||
|
||||
Reference in New Issue
Block a user