Files
IUQT/acquaintances/biz/model/user.go
2025-07-14 17:49:33 +08:00

43 lines
2.3 KiB
Go

package model
import (
"acquaintances/biz/model/user"
"acquaintances/biz/utils"
"encoding/json"
"gorm.io/gorm"
"time"
)
type User struct {
gorm.Model
UserID string `gorm:"column:user_id;type:varchar(32);uniqueIndex:idx_user_id;not null;comment:'用户唯一标识'"`
UserName string `gorm:"column:user_name;type:varchar(50);uniqueIndex:idx_user_name;not null;comment:'用户昵称'"`
Gender user.Gender `gorm:"column:gender;type:tinyint unsigned;default:0;comment:'性别;0:保密,1:男,2:女'"`
Age uint8 `gorm:"column:age;type:tinyint unsigned;default:0;comment:'年龄(岁)'"`
Introduce string `gorm:"column:introduce;type:varchar(200);default:'';comment:'个性签名'"`
AvatarImageURL string `gorm:"column:avatar_image_url;type:varchar(255);default:'';comment:'头像URL'"`
Birthday *time.Time `gorm:"column:birthday;type:date;comment:'出生日期'"`
Area uint8 `gorm:"column:area;type:tinyint;comment:'国家/地区编码(ISO 3166-1)'"`
Mobile string `gorm:"column:mobile;type:char(11);uniqueIndex:idx_mobile;not null;unique;comment:'手机号码'"`
UserPassword string `gorm:"column:password;type:varchar(100);not null;comment:'加密密码'"`
UserStatus user.UserStatus `gorm:"column:user_status;type:tinyint unsigned;default:1;comment:'用户状态;0:禁用,1:正常,2:注销'"`
UserEmail string `gorm:"column:email;type:varchar(100);comment:'用户邮箱'"`
Alias string `gorm:"column:alias;type:varchar(50);comment:'用户别名'"`
Address string `gorm:"column:address;type:text;comment:'用户详细地址'"`
LastLoginIP string `gorm:"column:last_login_ip;type:varchar(15);comment:'上次登录IP(IPv4)'"`
LastLoginTime *time.Time `gorm:"column:last_login_time;type:datetime;comment:'上次登录时间'"`
UserSalt string `gorm:"column:user_salt;type:varchar(16);not null;comment:'密码加密盐'"`
// 扩展字段(预留)
ExtraInfo json.RawMessage `gorm:"column:extra_info;type:json;comment:'预留'"`
}
func (u *User) TableName() string {
return "user"
}
func (u *User) BeforeSave(tx *gorm.DB) error {
u.UpdatedAt = time.Now()
u.UserPassword, u.UserSalt = utils.ScryptPw(u.UserPassword)
return nil
}