package entity import ( "time" "gorm.io/gorm" ) type User struct { ID uint `json:"id" gorm:"primaryKey;comment:用户ID"` UserCode string `json:"user_code" gorm:"uniqueIndex;size:8;comment:用户码(8位随机字母数字)"` Username string `json:"username" gorm:"uniqueIndex;size:50;comment:用户名"` Password string `json:"-" gorm:"size:255;comment:密码(加密存储)"` Email string `json:"email" gorm:"size:100;comment:邮箱"` Phone string `json:"phone" gorm:"size:20;comment:手机号"` Nickname string `json:"nickname" gorm:"size:50;comment:昵称"` StorageUsed int64 `json:"storage_used" gorm:"default:0;comment:已使用存储空间(字节)"` StorageLimit int64 `json:"storage_limit" gorm:"default:52428800;comment:存储空间限制(字节),默认50MB"` CreatedAt time.Time `json:"created_at" gorm:"comment:创建时间"` UpdatedAt time.Time `json:"updated_at" gorm:"comment:更新时间"` DeletedAt gorm.DeletedAt `json:"-" gorm:"comment:删除时间"` } func (User) TableName() string { return "users" } func (User) TableComment() string { return "用户表" } func NewUser(username, password, userCode, nickname string) *User { if nickname == "" { nickname = username } return &User{ Username: username, Password: password, UserCode: userCode, Nickname: nickname, StorageUsed: 0, StorageLimit: 52428800, } }