37 lines
1.1 KiB
Go
37 lines
1.1 KiB
Go
package model
|
||
|
||
import (
|
||
"gorm.io/gorm"
|
||
"time"
|
||
"vote-video-api/global"
|
||
)
|
||
|
||
// User 用户表
|
||
type User struct {
|
||
UserId int64 `gorm:"column:user_id;type:bigint(19);primary_key;comment:用户id" json:"user_id"`
|
||
AppIden string `gorm:"column:app_iden;type:varchar(50);comment:app唯一标识" json:"app_iden"`
|
||
UserStatus int `gorm:"column:user_status;type:tinyint(1);default:1;comment:状态(1:正常 2:禁用)" json:"user_status"`
|
||
OpenId string `gorm:"column:open_id;type:varchar(100);comment:用户微信标识" json:"open_id"`
|
||
LoginAt *LocalTime `gorm:"column:login_at;type:datetime;comment:登陆时间" json:"login_at"`
|
||
LoginIp string `gorm:"column:login_ip;type:varchar(255);comment:登陆ip" json:"login_ip"`
|
||
Model
|
||
}
|
||
|
||
func (m *User) TableName() string {
|
||
return "user"
|
||
}
|
||
|
||
func (m *User) 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
|
||
}
|