43 lines
1.7 KiB
Go
43 lines
1.7 KiB
Go
package model
|
||
|
||
import (
|
||
"gorm.io/gorm"
|
||
"knowledge/global"
|
||
"time"
|
||
)
|
||
|
||
// AdminUser 后台-用户表
|
||
type AdminUser struct {
|
||
UserId int64 `gorm:"column:user_id;type:bigint(20);primary_key;comment:主键id" json:"user_id"`
|
||
Access string `gorm:"column:access;type:varchar(64);comment:账号;NOT NULL" json:"access"`
|
||
Password string `gorm:"column:password;type:varchar(128);comment:密码;NOT NULL" json:"password"`
|
||
Salt string `gorm:"column:salt;type:varchar(255);comment:密码掩码;NOT NULL" json:"salt"`
|
||
NickName string `gorm:"column:nick_name;type:varchar(255);comment:昵称" json:"nick_name"`
|
||
Status int `gorm:"column:status;type:tinyint(1);default:2;comment:状态(1:正常 2:审核中 3:审核失败)" json:"status"`
|
||
IsDeleted int `gorm:"column:is_deleted;type:tinyint(1);default:0;comment:是否被删除(0:否 1:是)" json:"is_deleted"`
|
||
IsDisabled int `gorm:"column:is_disabled;type:tinyint(1);default:0;comment:是否被禁用(0:否 1:是)" json:"is_disabled"`
|
||
Phone string `gorm:"column:phone;type:varchar(11);comment:手机号" json:"phone"`
|
||
Avatar string `gorm:"column:avatar;type:varchar(255);comment:头像" json:"avatar"`
|
||
Sex int `gorm:"column:sex;type:tinyint(1);comment:性别(1:男 2:女)" json:"sex"`
|
||
Email string `gorm:"column:email;type:varchar(100);comment:邮箱" json:"email"`
|
||
Model
|
||
}
|
||
|
||
func (m *AdminUser) TableName() string {
|
||
return "kb_admin_user"
|
||
}
|
||
|
||
func (m *AdminUser) BeforeCreate(tx *gorm.DB) error {
|
||
if m.UserId == 0 {
|
||
m.UserId = global.Snowflake.Generate().Int64()
|
||
}
|
||
|
||
m.CreatedAt = LocalTime(time.Now())
|
||
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
|
||
|
||
m.UpdatedAt = LocalTime(time.Now())
|
||
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
|
||
|
||
return nil
|
||
}
|