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.
59 lines
1.6 KiB
59 lines
1.6 KiB
5 years ago
|
package user
|
||
|
|
||
|
import (
|
||
|
"live/app/lib"
|
||
|
"live/app/lib/recook"
|
||
|
"live/app/model/short"
|
||
|
)
|
||
|
|
||
|
const (
|
||
|
TREND_TYPE_message = 1 // 图文消息
|
||
|
TREND_TYPE_short = 2 // 短视频
|
||
|
)
|
||
|
|
||
|
type Trend struct {
|
||
|
}
|
||
|
|
||
|
// @Title 获取动态列表
|
||
|
func (t *Trend) GetList(userId uint, page lib.Page) *recook.TrendList {
|
||
|
// 获取动态列表及图文消息
|
||
|
list := recook.Trend.GetList(userId, page.GetPage(), page.GetLimit())
|
||
|
shortIds := []uint{}
|
||
|
trendMap := map[uint]*recook.TrendItem{}
|
||
|
// 处理短视频消息
|
||
|
for i, item := range list.List {
|
||
|
if item.TrendType == TREND_TYPE_short {
|
||
|
shortIds = append(shortIds, item.OriginID)
|
||
|
trendMap[item.OriginID] = &list.List[i]
|
||
|
}
|
||
|
}
|
||
|
if len(shortIds) > 0 {
|
||
|
shortModel := &short.Short{}
|
||
|
shortList := shortModel.GetByUserIdAndIds(userId, shortIds)
|
||
|
goodsIds := []uint{}
|
||
|
for _, shortItem := range shortList {
|
||
|
goodsIds = append(goodsIds, shortItem.GoodsId)
|
||
|
}
|
||
|
goodsInfos := recook.Trend.GetGoods(goodsIds)
|
||
|
|
||
|
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
|
||
|
}
|
||
|
}
|
||
|
return list
|
||
|
}
|
||
|
|
||
|
// @Title 添加会员动态信息
|
||
|
func (t *Trend) AddTrend(userId, originId uint, trendType, isShow int) error {
|
||
|
return recook.Trend.AddTrend(userId, originId, trendType, isShow)
|
||
|
}
|
||
|
|
||
|
// @Title 更改会员动态信息
|
||
|
func (t *Trend) Change(userId, originId uint, trendType, isShow int) error {
|
||
|
return recook.Trend.Change(userId, originId, trendType, isShow)
|
||
|
}
|