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.

68 lines
1.5 KiB

package topic
import (
"live/app/lib"
"live/app/lib/config"
"live/app/model/topic"
)
type Topic struct {
}
// @Title 根据关键字获取话题列表
func (t *Topic) List(keyword string, page lib.Page) (result *[]topic.Topic, count int64) {
result = &[]topic.Topic{}
topicModel := &topic.Topic{}
start := (page.GetPage() - 1) * page.GetLimit()
count = topicModel.GetlistCount(keyword)
if count <= int64(start) {
// 没有数据,不需要查库
return
}
*result = topicModel.Getlist(keyword, start, page.GetLimit())
return
}
// @Title 获取热门话题
func (t *Topic) Hot() []topic.Topic {
topicModel := &topic.Topic{}
return topicModel.GetHotlist(config.Config.Section("topic").Key("hotCount").MustInt(10))
}
// @Title 根据ids获取列表
func (t *Topic) GetListByIds(topicIds []uint) (result *[]topic.Topic) {
result = &[]topic.Topic{}
if len(topicIds) == 0 {
return
}
topicModel := &topic.Topic{}
*result = topicModel.GetlistByIds(topicIds)
return
}
type replyTopicInfo struct {
topic.Topic
IsFollow int `json:"isFollow"`
}
// @Title 根据id获取单条信息
func (t *Topic) GetInfo(userId, topicId uint) (result *replyTopicInfo) {
result = &replyTopicInfo{}
if topicId <= 0 {
return
}
topicModel := &topic.Topic{}
result.Topic = topicModel.GetById(topicId)
if result.Id > 0 {
// 获取关注相关
topicFollow := &topic.TopicFollow{}
followInfo := topicFollow.GetByUserIdAndTopicId(userId, topicId)
if followInfo.Id > 0 && followInfo.IsDel == 0 {
result.IsFollow = 1
}
}
return
}