zhangqian
2023-08-24 01e85245b2fbf5147554d1cfdfe9809d2e68b05d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package model
 
import (
    "gorm.io/gorm"
    "time"
)
 
// MyModel definitions from gorm.Model
//
// swagger:model
type gormModel struct {
    // The ID of the item
    // example: 1
    ID uint `json:"id"`
    // The date when the item was created
    // example: 2023-08-10 15:48:25
    CreatedAt time.Time `json:"created_at"`
    // The date when the item was last updated
    // example: 2023-08-10 15:48:25
    UpdatedAt time.Time `json:"updated_at"`
    // The date when the item was deleted
    // example: 2023-08-10 15:48:25
    DeletedAt *time.Time `json:"_"`
}
 
type CrmModel struct {
    gorm.Model  `json:"-"`
    CreatorId   int    `json:"-" gorm:"column:creator_id;type:int;comment:创建人id"`
    Creator     User   `json:"-"  gorm:"foreignKey:CreatorId"`
    CreateTime  string `json:"createTime"  gorm:"-"`
    UpdateTime  string `json:"updateTime"  gorm:"-"`
    CreatorName string `json:"creatorName" gorm:"-"`
}
 
func (slf *CrmModel) AfterFind(tx *gorm.DB) (err error) {
    slf.CreatorName = slf.Creator.Username
    slf.CreateTime = slf.CreatedAt.Format("2006-01-02 15:04")
    slf.UpdateTime = slf.UpdatedAt.Format("2006-01-02 15:04")
    return nil
}