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.
41 lines
1005 B
41 lines
1005 B
2 years ago
|
// Copyright 2022 ROC. All rights reserved.
|
||
|
// Use of this source code is governed by a MIT style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
|
package dbr
|
||
3 years ago
|
|
||
|
import (
|
||
|
"time"
|
||
|
|
||
|
"gorm.io/gorm"
|
||
|
"gorm.io/plugin/soft_delete"
|
||
|
)
|
||
|
|
||
3 years ago
|
// 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"`
|
||
|
}
|
||
|
|
||
2 years ago
|
type ConditionsT map[string]any
|
||
|
type Predicates map[string][]any
|
||
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
|
||
|
}
|