You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
923 B
37 lines
923 B
package topic
|
|
|
|
import (
|
|
"github.com/golangkit/formatime"
|
|
"live/app/lib/db"
|
|
)
|
|
|
|
type TopicSubstance struct {
|
|
db.BaseModel
|
|
Id uint `gorm:"column:id" json:"id"`
|
|
UserId uint `gorm:"column:user_id" json:"userId"`
|
|
TopicId uint `gorm:"column:topic_id" json:"topicId"`
|
|
CreatedAt formatime.Second `gorm:"column:created_at" json:"createdAt"`
|
|
}
|
|
|
|
// @Title 添加参与人
|
|
func (t *TopicSubstance) AddSubstance(userId, topicId uint) uint {
|
|
if userId <= 0 || topicId <= 0 {
|
|
return 0
|
|
}
|
|
result := TopicSubstance{
|
|
UserId: userId,
|
|
TopicId: topicId,
|
|
}
|
|
t.GetDb().Create(&result)
|
|
return result.Id
|
|
}
|
|
|
|
// @Title 获取参与人信息
|
|
func (t *TopicSubstance) GetSubstanceByUserIdAndTopicId(userId, topicId uint) (result TopicSubstance) {
|
|
if userId <= 0 || topicId <= 0 {
|
|
return
|
|
}
|
|
t.GetDb().Model(t).First(&result, "user_id = ? and topic_id = ?", userId, topicId)
|
|
return
|
|
}
|