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.
paopao-ce/internal/model/model.go

38 lines
917 B

3 years ago
package model
import (
"time"
"github.com/rocboss/paopao-ce/pkg/types"
3 years ago
"gorm.io/gorm"
"gorm.io/plugin/soft_delete"
)
// Model 公共Model
3 years ago
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]interface{}
type Predicates map[string]types.AnySlice
3 years ago
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
}