2025-01-06 16:01:02 +08:00
|
|
|
package admin
|
|
|
|
|
|
|
|
|
|
import (
|
2025-01-23 16:12:49 +08:00
|
|
|
"common/mytime"
|
2025-01-06 16:01:02 +08:00
|
|
|
"common/remark"
|
|
|
|
|
"common/resultStatus"
|
|
|
|
|
"common/webServer"
|
|
|
|
|
"goutil/intUtil"
|
|
|
|
|
"goutil/securityUtil"
|
|
|
|
|
"strconv"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
|
|
|
|
|
//注册接口
|
|
|
|
|
webServer.RegisterFunction(new(AdminApi))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
moduleName := "AdminApi"
|
|
|
|
|
desc := "管理员接口"
|
|
|
|
|
author := "tangping"
|
|
|
|
|
mendor := ""
|
|
|
|
|
date := "2024-12-25"
|
|
|
|
|
remark.RegisterModuleRemark(moduleName, desc, author, mendor, date)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// AdminApi 管理员接口
|
|
|
|
|
type AdminApi struct {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------- 接口 --------------------------------------------------
|
|
|
|
|
func init() {
|
|
|
|
|
moduleName := "AdminApi"
|
|
|
|
|
methodName := "Add"
|
2025-01-07 16:43:33 +08:00
|
|
|
skipVerifyTokenPage := true
|
2025-01-06 16:01:02 +08:00
|
|
|
methodDesc := "添加管理员用户"
|
|
|
|
|
methodAuthor := "tangping"
|
|
|
|
|
methodMendor := ""
|
|
|
|
|
methodDate := "2024-12-25 15:55:00"
|
|
|
|
|
methodInParam := []string{"string 账号,string:管理员名称,string:管理员密码,string:管理员性别,string:管理员生日,int64:管理员手机号,string:管理员邮箱,string:管理员微信群,string:管理员备注"}
|
|
|
|
|
methodOutParam := `
|
|
|
|
|
{
|
|
|
|
|
"Code '类型:int'": "响应结果的状态值",
|
|
|
|
|
"Message '类型:string'": "响应结果的状态值所对应的描述信息",
|
|
|
|
|
"Data '类型:interface{}'": "响应结果的数据"
|
|
|
|
|
{
|
|
|
|
|
"id '类型:int'": "管理员id",
|
|
|
|
|
}
|
|
|
|
|
}`
|
2025-01-07 16:43:33 +08:00
|
|
|
remark.RegisterMethodRemark(moduleName, methodName, methodDesc, methodAuthor, methodMendor, methodDate, methodInParam, methodOutParam, skipVerifyTokenPage)
|
2025-01-06 16:01:02 +08:00
|
|
|
}
|
|
|
|
|
func (a *AdminApi) Add(account string, name string, password string, sex int32, birthday string, phone int64, email string, wechatGroup string, describe string) (responseObj *webServer.ResponseObject) {
|
|
|
|
|
responseObj = webServer.GetInitResponseObj()
|
|
|
|
|
|
|
|
|
|
//校验参数
|
|
|
|
|
if account == "" || name == "" || password == "" || sex == 0 || birthday == "" || phone == 0 || email == "" || wechatGroup == "" {
|
|
|
|
|
responseObj.SetResultStatus(resultStatus.APIDataError)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//密码md5加密
|
|
|
|
|
password = securityUtil.Md5String(password, true)
|
|
|
|
|
|
|
|
|
|
//处理数据
|
|
|
|
|
adminModel := &Admin{
|
|
|
|
|
Account: account,
|
|
|
|
|
Name: name,
|
|
|
|
|
Password: password,
|
|
|
|
|
Sex: sex,
|
|
|
|
|
Birthday: birthday,
|
|
|
|
|
Phone: phone,
|
|
|
|
|
Email: email,
|
|
|
|
|
WechatGroup: wechatGroup,
|
|
|
|
|
Describe: describe,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//添加到数据库
|
|
|
|
|
AddAdmin(adminModel)
|
|
|
|
|
|
|
|
|
|
resultMap := make(map[string]any)
|
|
|
|
|
resultMap["id"] = adminModel.ID
|
|
|
|
|
responseObj.SetData(resultMap)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
moduleName := "AdminApi"
|
|
|
|
|
methodName := "Get"
|
2025-01-07 16:43:33 +08:00
|
|
|
skipVerifyTokenPage := false
|
2025-01-06 16:01:02 +08:00
|
|
|
methodDesc := "获取管理员用户"
|
|
|
|
|
methodAuthor := "tangping"
|
|
|
|
|
methodMendor := ""
|
|
|
|
|
methodDate := "2024-12-25 15:55:00"
|
|
|
|
|
methodInParam := []string{"int64:管理员id"}
|
|
|
|
|
methodOutParam := `
|
|
|
|
|
{
|
|
|
|
|
"Code '类型:int'": "响应结果的状态值",
|
|
|
|
|
"Message '类型:string'": "响应结果的状态值所对应的描述信息",
|
|
|
|
|
"Data '类型:interface{}'": "响应结果的数据"
|
|
|
|
|
{
|
|
|
|
|
"account '类型:string'": "管理员账号",
|
|
|
|
|
"name '类型:string'": "管理员名称",
|
|
|
|
|
"sex '类型:int32'": "管理员性别",
|
|
|
|
|
"birthday '类型:string'": "管理员生日",
|
|
|
|
|
"phone '类型:int64'": "管理员手机号",
|
|
|
|
|
"email '类型:string'": "管理员邮箱",
|
|
|
|
|
"wechatGroup '类型:string'": "管理员微信群",
|
|
|
|
|
"describe '类型:string'": "管理员备注",
|
|
|
|
|
}
|
|
|
|
|
}`
|
|
|
|
|
|
2025-01-07 16:43:33 +08:00
|
|
|
remark.RegisterMethodRemark(moduleName, methodName, methodDesc, methodAuthor, methodMendor, methodDate, methodInParam, methodOutParam, skipVerifyTokenPage)
|
2025-01-06 16:01:02 +08:00
|
|
|
}
|
2025-01-07 16:43:33 +08:00
|
|
|
func (a *AdminApi) Get(useAdmin *Admin, adminId int64) (responseObj *webServer.ResponseObject) {
|
2025-01-06 16:01:02 +08:00
|
|
|
|
|
|
|
|
responseObj = webServer.GetInitResponseObj()
|
|
|
|
|
|
2025-01-07 16:43:33 +08:00
|
|
|
//获取当前登录用户信息
|
|
|
|
|
|
2025-01-06 16:01:02 +08:00
|
|
|
//验证参数
|
|
|
|
|
if adminId == 0 {
|
|
|
|
|
responseObj.SetResultStatus(resultStatus.APIDataError)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
adminData, err := GetAdminByID(adminId)
|
|
|
|
|
if err != nil {
|
|
|
|
|
responseObj.SetResultStatus(resultStatus.DataError)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//adminData映射成map
|
|
|
|
|
resultMap := make(map[string]any)
|
|
|
|
|
resultMap["account"] = adminData.Account
|
|
|
|
|
resultMap["name"] = adminData.Name
|
|
|
|
|
resultMap["sex"] = adminData.Sex
|
|
|
|
|
resultMap["birthday"] = adminData.Birthday
|
|
|
|
|
resultMap["phone"] = adminData.Phone
|
|
|
|
|
resultMap["email"] = adminData.Email
|
|
|
|
|
resultMap["wechatGroup"] = adminData.WechatGroup
|
|
|
|
|
resultMap["describe"] = adminData.Describe
|
|
|
|
|
|
|
|
|
|
responseObj.SetData(resultMap)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 管理员登录
|
|
|
|
|
func init() {
|
|
|
|
|
moduleName := "AdminApi"
|
|
|
|
|
methodName := "Login"
|
2025-01-07 16:43:33 +08:00
|
|
|
skipVerifyTokenPage := true
|
2025-01-06 16:01:02 +08:00
|
|
|
methodDesc := "管理员登录"
|
|
|
|
|
methodAuthor := "tangping"
|
|
|
|
|
methodMendor := ""
|
|
|
|
|
methodDate := "2024-12-26 15:55:00"
|
|
|
|
|
methodInParam := []string{"string:账号,string:密码"}
|
|
|
|
|
methodOutParam := `
|
|
|
|
|
{
|
|
|
|
|
"Code '类型:int'": "响应结果的状态值",
|
|
|
|
|
"Message '类型:string'": "响应结果的状态值所对应的描述信息",
|
|
|
|
|
"Data '类型:interface{}'": "响应结果的数据"
|
|
|
|
|
{
|
|
|
|
|
"Token '类型:string'": "登录令牌",
|
|
|
|
|
}
|
|
|
|
|
}`
|
|
|
|
|
|
2025-01-07 16:43:33 +08:00
|
|
|
remark.RegisterMethodRemark(moduleName, methodName, methodDesc, methodAuthor, methodMendor, methodDate, methodInParam, methodOutParam, skipVerifyTokenPage)
|
2025-01-06 16:01:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *AdminApi) Login(account string, password string) (responseObj *webServer.ResponseObject) {
|
|
|
|
|
|
|
|
|
|
responseObj = webServer.GetInitResponseObj()
|
|
|
|
|
|
|
|
|
|
//验证参数
|
|
|
|
|
if account == "" || password == "" {
|
|
|
|
|
responseObj.SetResultStatus(resultStatus.APIDataError)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
adminData, err := Login(account, securityUtil.Md5String(password, true))
|
|
|
|
|
if err != nil {
|
|
|
|
|
responseObj.SetResultStatus(resultStatus.DataError)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//生成一个随机token
|
|
|
|
|
token, err := intUtil.ShuffleIntDigits(time.Now().UnixNano())
|
|
|
|
|
if err != nil {
|
|
|
|
|
responseObj.SetResultStatus(resultStatus.DataError)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//添加登录用户
|
2025-01-07 16:43:33 +08:00
|
|
|
webServer.AddLoginUserToken(token, &webServer.TokenInfo{Id: adminData.ID, Account: account, UserInfo: adminData})
|
2025-01-06 16:01:02 +08:00
|
|
|
|
|
|
|
|
//adminData映射成map
|
|
|
|
|
resultMap := make(map[string]any)
|
|
|
|
|
resultMap["Token"] = strconv.FormatInt(token, 10)
|
|
|
|
|
|
|
|
|
|
responseObj.SetData(resultMap)
|
|
|
|
|
return
|
|
|
|
|
}
|
2025-01-23 16:12:49 +08:00
|
|
|
|
|
|
|
|
// 查询玩家登录相关记录
|
|
|
|
|
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
|
|
|
|
|
}
|