18 lines
396 B
Go
18 lines
396 B
Go
package model
|
|
|
|
import "gorm.io/gorm"
|
|
|
|
// BaseModel 基础模型,包含通用字段
|
|
type BaseModel struct {
|
|
Creator uint `gorm:"not null" json:"creator"`
|
|
Updater uint `gorm:"not null" json:"updater"`
|
|
}
|
|
|
|
func (b *BaseModel) BeforeCreate(tx *gorm.DB) error {
|
|
if userID, ok := tx.Statement.Context.Value("current_user_id").(uint); ok {
|
|
b.Creator = userID
|
|
b.Updater = userID
|
|
}
|
|
return nil
|
|
}
|