一波更新

This commit is contained in:
tangping
2025-01-23 16:12:49 +08:00
parent 22ac6c1fed
commit 5f3a40a50e
90 changed files with 2392 additions and 1791 deletions

View File

@@ -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"
}

View File

@@ -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
}

View File

@@ -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
}