mirror of https://github.com/rocboss/paopao-ce
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
858 B
37 lines
858 B
2 years ago
|
package model
|
||
|
|
||
|
import (
|
||
|
"time"
|
||
|
|
||
|
"gorm.io/gorm"
|
||
|
"gorm.io/plugin/soft_delete"
|
||
|
)
|
||
|
|
||
|
// Model 公共Model
|
||
|
type Model struct {
|
||
|
ID int64 `gorm:"primary_key" json:"id"`
|
||
|
CreatedOn int64 `json:"created_on"`
|
||
|
ModifiedOn int64 `json:"modified_on"`
|
||
|
DeletedOn int64 `json:"deleted_on"`
|
||
|
IsDel soft_delete.DeletedAt `gorm:"softDelete:flag" json:"is_del"`
|
||
|
}
|
||
|
|
||
|
type ConditionsT map[string]any
|
||
|
type Predicates map[string][]any
|
||
|
|
||
|
func (m *Model) BeforeCreate(tx *gorm.DB) (err error) {
|
||
|
nowTime := time.Now().Unix()
|
||
|
|
||
|
tx.Statement.SetColumn("created_on", nowTime)
|
||
|
tx.Statement.SetColumn("modified_on", nowTime)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func (m *Model) BeforeUpdate(tx *gorm.DB) (err error) {
|
||
|
if !tx.Statement.Changed("modified_on") {
|
||
|
tx.Statement.SetColumn("modified_on", time.Now().Unix())
|
||
|
}
|
||
|
|
||
|
return
|
||
|
}
|