36 lines
911 B
Go
36 lines
911 B
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// SearchLog 搜索记录模型
|
|
type SearchLog struct {
|
|
ID uint `json:"id" gorm:"primaryKey;column:id"`
|
|
Keyword string `json:"keyword" gorm:"column:keyword"`
|
|
SearchType string `json:"searchType" gorm:"column:search_type"` // category/tag/column/keyword
|
|
UserIP string `json:"userIp" gorm:"column:user_ip"`
|
|
UserLocation string `json:"userLocation" gorm:"column:user_location"`
|
|
DeletedAt int64 `json:"deletedAt" gorm:"column:deleted_at;default:0"`
|
|
CreatedAt int64 `json:"createdAt" gorm:"column:created_at"`
|
|
}
|
|
|
|
// TableName 指定表名
|
|
func (SearchLog) TableName() string {
|
|
return "search_logs"
|
|
}
|
|
|
|
// BeforeCreate 创建前钩子
|
|
func (sl *SearchLog) BeforeCreate(tx *gorm.DB) error {
|
|
now := time.Now().Unix()
|
|
if sl.CreatedAt == 0 {
|
|
sl.CreatedAt = now
|
|
}
|
|
if sl.DeletedAt == 0 {
|
|
sl.DeletedAt = 0
|
|
}
|
|
return nil
|
|
}
|