46 lines
2.5 KiB
Go
46 lines
2.5 KiB
Go
package model
|
||
|
||
import (
|
||
"gorm.io/gorm"
|
||
"hepa-calc-api/global"
|
||
"time"
|
||
)
|
||
|
||
// Question 问题表
|
||
type Question struct {
|
||
QuestionId int64 `gorm:"column:question_id;type:bigint(19);primary_key;comment:主键id" json:"question_id"`
|
||
QuestionTitle string `gorm:"column:question_title;type:varchar(200);comment:标题" json:"question_title"`
|
||
QuestionSubtitle string `gorm:"column:question_subtitle;type:varchar(200);comment:副标题" json:"question_subtitle"`
|
||
QuestionIden string `gorm:"column:question_iden;type:varchar(255);comment:唯一标识(用于和前端对应)" json:"question_iden"`
|
||
QuestionStatus int `gorm:"column:question_status;type:tinyint(1);default:2;comment:问题状态(1:正常 2:待发布)" json:"question_status"`
|
||
IsHide int `gorm:"column:is_hide;type:tinyint(1);default:0;comment:是否隐藏(0:否 1:是)" json:"is_hide"`
|
||
IsRecommend int `gorm:"column:is_recommend;type:tinyint(1);default:0;comment:是否推荐(0:否 1:是)" json:"is_recommend"`
|
||
ClickCount int `gorm:"column:click_count;type:int(5);default:0;comment:点击次数(点击进入详情页的人次)" json:"click_count"`
|
||
SubmitCount int `gorm:"column:submit_count;type:int(5);default:0;comment:提交次数(提交个人信息进行了算算的人次)" json:"submit_count"`
|
||
PayCount int `gorm:"column:pay_count;type:int(5);default:0;comment:支付次数(查看报告的人次)" json:"pay_count"`
|
||
Price float64 `gorm:"column:price;type:decimal(10,2) unsigned;default:0.00;comment:价格(原价)" json:"price"`
|
||
DiscountPrice *float64 `gorm:"column:discount_price;type:decimal(10,2);comment:优惠价格" json:"discount_price"`
|
||
DiscountEndTime *LocalTime `gorm:"column:discount_end_time;type:datetime;comment:优惠截止时间" json:"discount_end_time"`
|
||
QuestionBrief string `gorm:"column:question_brief;type:text;comment:问题介绍" json:"question_brief"`
|
||
QuestionExplain string `gorm:"column:question_explain;type:text;comment:问题解释/科普" json:"question_explain"`
|
||
Model
|
||
}
|
||
|
||
func (m *Question) TableName() string {
|
||
return "question"
|
||
}
|
||
|
||
func (m *Question) BeforeCreate(tx *gorm.DB) error {
|
||
if m.QuestionId == 0 {
|
||
m.QuestionId = 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
|
||
}
|