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.
124 lines
3.6 KiB
124 lines
3.6 KiB
package user
|
|
|
|
import (
|
|
"live/app/lib"
|
|
"live/app/lib/recook"
|
|
"live/app/model/momentscopy"
|
|
"live/app/model/short"
|
|
"live/app/model/topic"
|
|
"live/app/model/user"
|
|
)
|
|
|
|
const (
|
|
TREND_TYPE_message = 1 // 图文消息
|
|
TREND_TYPE_short = 2 // 短视频
|
|
)
|
|
|
|
type Trend struct {
|
|
}
|
|
|
|
// @Title 获取动态列表
|
|
func (t *Trend) GetList(loginUserId, userId uint, page lib.Page) *recook.TrendList {
|
|
// 获取动态列表及图文消息
|
|
list := recook.Trend.GetList(userId, page.GetPage(), page.GetLimit())
|
|
shortIds := []uint{}
|
|
trendMap := map[uint]*recook.TrendItem{}
|
|
|
|
trendIds := []uint{}
|
|
// 处理短视频消息
|
|
for i, item := range list.List {
|
|
trendIds = append(trendIds, item.ID)
|
|
if item.TrendType == TREND_TYPE_short {
|
|
shortIds = append(shortIds, item.OriginID)
|
|
trendMap[item.OriginID] = &list.List[i]
|
|
}
|
|
}
|
|
userTrendDataModel := user.UserTrendData{}
|
|
trendDataLists := userTrendDataModel.GetListByTrendIds(trendIds)
|
|
trendDataMap := map[uint]user.UserTrendData{}
|
|
for _, item := range trendDataLists {
|
|
trendDataMap[item.TrendId] = item
|
|
}
|
|
|
|
// 获取是否点赞
|
|
userTrendPraiseMap := map[uint]uint{}
|
|
if loginUserId > 0 {
|
|
userTrendPraiseModel := &user.UserTrendPraise{}
|
|
userTrendPraises := userTrendPraiseModel.GetPraiseByUserIdAndTrendIds(loginUserId, trendIds)
|
|
for _, praise := range userTrendPraises {
|
|
userTrendPraiseMap[praise.TrendId] = 1
|
|
}
|
|
}
|
|
|
|
for i, item := range list.List {
|
|
list.List[i].Praise = trendDataMap[item.ID].Praise
|
|
list.List[i].IsPraise = userTrendPraiseMap[item.ID]
|
|
}
|
|
if len(shortIds) > 0 {
|
|
shortModel := &short.Short{}
|
|
shortList := shortModel.GetByUserIdAndIds(userId, shortIds)
|
|
goodsIds := []uint{}
|
|
topicIds := []uint{}
|
|
for _, shortItem := range shortList {
|
|
goodsIds = append(goodsIds, shortItem.GoodsId)
|
|
if shortItem.TopicId > 0 {
|
|
topicIds = append(topicIds, shortItem.TopicId)
|
|
}
|
|
}
|
|
goodsInfos := recook.Trend.GetGoods(goodsIds)
|
|
|
|
// 获取话题信息
|
|
topicMap := map[uint]topic.Topic{}
|
|
if len(topicIds) > 0 {
|
|
topics := (&topic.Topic{}).GetlistByIds(topicIds)
|
|
for _, item := range topics {
|
|
topicMap[item.Id] = item
|
|
}
|
|
}
|
|
|
|
for _, shortItem := range shortList {
|
|
trendInfo := trendMap[shortItem.Id]
|
|
trendInfo.Goods = goodsInfos[shortItem.GoodsId]
|
|
trendInfo.Content = shortItem.Content
|
|
trendInfo.Short.CoverUrl = shortItem.CoverUrl
|
|
trendInfo.Short.MediaUrl = shortItem.MediaUrl
|
|
trendInfo.TopicId = shortItem.TopicId
|
|
trendInfo.TopicName = topicMap[shortItem.TopicId].Title
|
|
}
|
|
}
|
|
//根据需求,返回视频的状态,风险或安全,审核中或审核失败通过
|
|
for i, k := range list.List {
|
|
if k.Short.MediaUrl != "" {
|
|
var a short.Short
|
|
(&short.Short{}).GetDb().Where("id=?", k.OriginID).First(&a)
|
|
list.List[i].Compliance = a.Compliance
|
|
list.List[i].PassStatus = a.Pass
|
|
}
|
|
if len(k.ImgList) > 1 {
|
|
var gm momentscopy.MomentsCopy
|
|
(&momentscopy.MomentsCopy{}).GetDb().Where("id=?", k.OriginID).First(&gm)
|
|
list.List[i].Compliance = gm.Compliance
|
|
if gm.Reviewing == 0 {
|
|
list.List[i].PassStatus = 2
|
|
} else if gm.Reviewing == 1 {
|
|
list.List[i].PassStatus = 0
|
|
} else if gm.Reviewing == 2 {
|
|
list.List[i].PassStatus = 1
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
return list
|
|
}
|
|
|
|
// @Title 添加会员动态信息
|
|
func (t *Trend) AddTrend(userId, originId uint, trendType, isShow int, id, token, deviceType string) error {
|
|
return recook.Trend.AddTrend(userId, originId, trendType, isShow, id, token, deviceType)
|
|
}
|
|
|
|
// @Title 更改会员动态信息
|
|
func (t *Trend) Change(userId, originId uint, trendType, isShow int) error {
|
|
return recook.Trend.Change(userId, originId, trendType, isShow)
|
|
}
|