game/common/model/user/userAccount.go
2025-06-15 20:06:00 +08:00

63 lines
2.6 KiB
Go

package user
import (
"time"
)
const (
// AccountNormal = 1 // 正常
AccountFrozen = 2 // 冻结
AccountBanned = 3 // 封禁
)
// 玩家账户表
type UserAccount struct {
ID int64 `gorm:"primarykey;autoIncrement" json:"id"`
Username string `gorm:"type:varchar(32);uniqueIndex;not null" json:"username"` // 用户名
Password string `gorm:"type:varchar(255);not null" json:"password"` // 密码哈希
Email string `gorm:"type:varchar(100)" json:"email"` // 邮箱(可选)
Phone string `gorm:"type:varchar(20)" json:"phone"` // 手机号(可选)
DeviceID string `gorm:"type:varchar(64);index" json:"device_id"` // 设备ID
LastLoginIP string `gorm:"type:varchar(45)" json:"last_login_ip"` // 最后登录IP(支持IPv6)
LastLoginTime time.Time `json:"last_login_time"` // 最后登录时间
Status int `gorm:"type:tinyint;default:1" json:"status"` // 账号状态 1-正常 2-冻结 3-封禁
RegisterIP string `gorm:"type:varchar(45)" json:"register_ip"` // 注册IP
RegisterTime time.Time `gorm:"type:TIMESTAMP;default:CURRENT_TIMESTAMP" json:"register_time"` // 注册时间
}
func (u UserAccount) GetId() int64 {
return u.ID
}
func (u UserAccount) TableName() string {
return "user_account"
}
// 玩家登录记录表
type UserLoginLog struct {
AccountID int64 `gorm:"type:Int64;index" json:"account_id"` // 关联帐号ID
LoginIP string `gorm:"type:String;not null" json:"login_ip"` // 登录IP
LoginTime time.Time `gorm:"type:DateTime;default:now()" json:"login_time"` // 登录或登出时间
IsLogin bool `gorm:"type:Int8" json:"is_login"` // 登录或登出 true-登录 false-登出
DeviceInfo string `gorm:"type:String" json:"device_info"` // 设备信息(JSON格式)
LoginResult bool `gorm:"type:Int8" json:"login_result"` // 登录结果 true-成功 false-失败
FailReason string `gorm:"type:String" json:"fail_reason"` // 失败原因
}
func (u UserLoginLog) GetId() int64 {
return 0
}
func (u UserLoginLog) TableName() string {
return "user_login_log"
}
func (u UserLoginLog) TableOptions() string {
// "ENGINE=MergeTree() ORDER BY tuple()"
return `ENGINE=MergeTree()
ORDER BY (account_id, login_time)
PARTITION BY toYYYYMM(login_time)
TTL login_time + INTERVAL 6 MONTH
`
}