41 lines
1.6 KiB
Go
41 lines
1.6 KiB
Go
package model
|
||
|
||
import (
|
||
"case-api/global"
|
||
"gorm.io/gorm"
|
||
"time"
|
||
)
|
||
|
||
// RecordScore 积分发放记录
|
||
type RecordScore struct {
|
||
ScoreId int64 `gorm:"column:score_id;type:bigint(19);primary_key;comment:主键id" json:"score_id"`
|
||
ProjectId int64 `gorm:"column:project_id;type:bigint(19);comment:所属项目id;NOT NULL" json:"project_id"`
|
||
CaseId int64 `gorm:"column:case_id;type:bigint(19);comment:所属病例id" json:"case_id"`
|
||
PlatformId int64 `gorm:"column:platform_id;type:bigint(19);comment:用户所属平台id" json:"platform_id"`
|
||
UserId int64 `gorm:"column:user_id;type:bigint(10);comment:用户id" json:"user_id"`
|
||
UserName string `gorm:"column:user_name;type:varchar(100);comment:用户名称" json:"user_name"`
|
||
Type int `gorm:"column:type;type:tinyint(1);default:1;comment:积分类型(1:完成阅读 2:阅读时间满足 3:优质留言 4:再次优质留言 )" json:"type"`
|
||
NodeName string `gorm:"column:node_name;type:varchar(50);comment:获取积分节点名称(如:阅读时间足够)" json:"node_name"`
|
||
Score int `gorm:"column:score;type:int(5);comment:积分" json:"score"`
|
||
Model
|
||
Case *Case `gorm:"foreignKey:CaseId;references:case_id" json:"case"`
|
||
}
|
||
|
||
func (m *RecordScore) TableName() string {
|
||
return "record_score"
|
||
}
|
||
|
||
func (m *RecordScore) BeforeCreate(tx *gorm.DB) error {
|
||
if m.ScoreId == 0 {
|
||
m.ScoreId = 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
|
||
}
|