package model import ( "time" "github.com/google/uuid" "gorm.io/gorm" ) // UserStatus 用户状态 type UserStatus string const ( UserStatusActive UserStatus = "active" UserStatusBanned UserStatus = "banned" UserStatusInactive UserStatus = "inactive" ) // User 用户实体 type User struct { ID string `json:"id" gorm:"type:varchar(36);primaryKey"` Username string `json:"username" gorm:"type:varchar(50);uniqueIndex;not null"` Nickname string `json:"nickname" gorm:"type:varchar(100);not null"` Email *string `json:"email" gorm:"type:varchar(255);uniqueIndex"` Phone *string `json:"phone" gorm:"type:varchar(20);uniqueIndex"` EmailVerified bool `json:"email_verified" gorm:"default:false"` PasswordHash string `json:"-" gorm:"type:varchar(255);not null"` Avatar string `json:"avatar" gorm:"type:text"` CoverURL string `json:"cover_url" gorm:"type:text"` // 头图URL Bio string `json:"bio" gorm:"type:text"` Website string `json:"website" gorm:"type:varchar(255)"` Location string `json:"location" gorm:"type:varchar(100)"` // 实名认证信息(可选) RealName string `json:"real_name" gorm:"type:varchar(100)"` // 真实姓名 IDCard string `json:"-" gorm:"type:varchar(18)"` // 身份证号(加密存储) IsVerified bool `json:"is_verified" gorm:"default:false"` // 是否实名认证 VerifiedAt *time.Time `json:"verified_at" gorm:"type:timestamp"` // 统计计数 PostsCount int `json:"posts_count" gorm:"default:0"` FollowersCount int `json:"followers_count" gorm:"default:0"` FollowingCount int `json:"following_count" gorm:"default:0"` // 状态 Status UserStatus `json:"status" gorm:"type:varchar(20);default:active"` LastLoginAt *time.Time `json:"last_login_at" gorm:"type:timestamp"` LastLoginIP string `json:"last_login_ip" gorm:"type:varchar(45)"` // 时间戳 CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"` UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"` DeletedAt gorm.DeletedAt `json:"-" gorm:"index"` } // BeforeCreate 创建前生成UUID func (u *User) BeforeCreate(tx *gorm.DB) error { if u.ID == "" { u.ID = uuid.New().String() } return nil } func (User) TableName() string { return "users" }