Files
nl-game-api/internal/model/user.go
2026-08-14 17:50:37 +08:00

52 lines
2.7 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Package model 定义与数据库表一一对应的 GORM 模型
// 约定created_at/updated_at/deleted_at 统一为 int 时间戳(秒),
// 由 GORM 的 autoCreateTime/autoUpdateTime 与 soft_delete 插件自动维护
package model
import "gorm.io/plugin/soft_delete"
// 用户角色常量
const (
RoleAdmin = 1 // 超级管理员
RoleNormal = 2 // 普通用户
)
// 用户状态常量
const (
UserStatusNormal = 1 // 正常
UserStatusBanned = 2 // 禁用
)
// User 用户表:平台所有账号(超管与普通用户共用,靠 Role 区分)
type User struct {
ID int `gorm:"primaryKey" json:"id"` // 用户ID
Username string `gorm:"size:32;uniqueIndex" json:"username"` // 登录用户名(唯一)
Password string `gorm:"size:100" json:"-"` // bcrypt 密文(不下发给前端)
Nickname string `gorm:"size:32" json:"nickname"` // 昵称
Avatar string `gorm:"size:16" json:"avatar"` // 头像(像素编码 px:01~px:32
Role int `gorm:"default:2" json:"role"` // 角色1超管 2普通
Points int `gorm:"default:0" json:"points"` // 当前积分余额
TotalPoints int `gorm:"default:0" json:"total_points"` // 历史累计积分(排行榜依据)
VipLevel int `gorm:"default:0" json:"vip_level"` // VIP等级0=非VIP1~5
VipExpire int64 `gorm:"default:0" json:"vip_expire"` // VIP到期时间戳0=未开通)
Status int `gorm:"default:1" json:"status"` // 状态1正常 2禁用
CreatedAt int64 `gorm:"autoCreateTime" json:"created_at"` // 创建时间int 时间戳)
UpdatedAt int64 `gorm:"autoUpdateTime" json:"updated_at"` // 更新时间int 时间戳)
DeletedAt soft_delete.DeletedAt `gorm:"default:0" json:"-"` // 软删除时间0=未删除)
}
// TableName 指定表名
func (User) TableName() string { return "users" }
// LoginLog 登录记录表:每次登录成功写一条
type LoginLog struct {
ID int `gorm:"primaryKey" json:"id"` // 记录ID
UserID int `gorm:"index" json:"user_id"` // 登录用户ID
IP string `gorm:"size:64" json:"ip"` // 登录IP
UserAgent string `gorm:"size:255" json:"user_agent"` // 浏览器UA
CreatedAt int64 `gorm:"autoCreateTime" json:"created_at"` // 登录时间int 时间戳)
}
// TableName 指定表名
func (LoginLog) TableName() string { return "login_logs" }