vote-api/api/model/User.go
2024-08-27 14:51:15 +08:00

37 lines
1.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package model
import (
"gorm.io/gorm"
"time"
"vote-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
}