package model import ( "gorm.io/gorm" "time" "vote-admin-api/global" ) // ArticleVoteDay 文章-每日投票 type ArticleVoteDay struct { VoteDayId int64 `gorm:"column:vote_day_id;type:bigint(19);primary_key;comment:主键id" json:"vote_day_id"` ArticleId int64 `gorm:"column:article_id;type:bigint(19);comment:文章id;NOT NULL" json:"article_id"` UserId int64 `gorm:"column:user_id;type:bigint(19);comment:用户id;NOT NULL" json:"user_id"` VotedAt *LocalTime `gorm:"column:voted_at;type:date;comment:投票时间(日)" json:"voted_at"` Model } func (m *ArticleVoteDay) TableName() string { return "article_vote_day" } func (m *ArticleVoteDay) BeforeCreate(tx *gorm.DB) error { if m.VoteDayId == 0 { m.VoteDayId = global.Snowflake.Generate().Int64() } m.CreatedAt = LocalTime(time.Now()) tx.Statement.SetColumn("CreatedAt", m.CreatedAt) m.UpdatedAt = LocalTime(time.Now()) tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt) return nil }