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.
71 lines
1.7 KiB
71 lines
1.7 KiB
5 years ago
|
package user
|
||
|
|
||
|
import (
|
||
|
"github.com/gin-gonic/gin"
|
||
|
"live/app/lib"
|
||
|
"live/app/lib/back"
|
||
|
"live/app/lib/tools"
|
||
|
live2 "live/app/model/live"
|
||
|
)
|
||
|
|
||
|
type Live struct {
|
||
|
}
|
||
|
type argsUserList struct {
|
||
|
UserId uint `json:"userId" form:"userId"`
|
||
|
lib.Page
|
||
|
}
|
||
|
|
||
|
type replyItem struct {
|
||
|
Id uint `json:"id"`
|
||
|
GoodsCount uint `json:"goodsCount"`
|
||
|
Cover string `json:"cover"`
|
||
|
Look int `json:"look"`
|
||
|
Title string `json:"title"`
|
||
|
IsLive int `json:"isLive"`
|
||
|
StartAt int64 `json:"startAt"`
|
||
|
}
|
||
|
|
||
|
// @Title 用户直播场次列表
|
||
|
func (l *Live) UserList(c *gin.Context) {
|
||
|
args := argsUserList{}
|
||
|
if err := tools.ParseParams(&args, c); err != nil {
|
||
|
back.Fail(c, err.Error())
|
||
|
return
|
||
|
}
|
||
|
if args.UserId <= 0 {
|
||
|
back.Fail(c, "参数错误")
|
||
|
return
|
||
|
}
|
||
|
liveItemModel := &live2.LiveItem{}
|
||
|
start := args.GetStart()
|
||
|
total := int(liveItemModel.GetUserListTotal(args.UserId))
|
||
|
resultList := []replyItem{}
|
||
|
if total > start {
|
||
|
lists := liveItemModel.GetUserList(args.UserId, args.GetStart(), args.GetLimit())
|
||
|
liveItemIds := []uint{}
|
||
|
for _, list := range lists {
|
||
|
liveItemIds = append(liveItemIds, list.Id)
|
||
|
}
|
||
|
liveDatas := (&live2.LiveData{}).GetByLiveItemIds(liveItemIds)
|
||
|
liveDataMap := map[uint]live2.LiveData{}
|
||
|
for _, data := range liveDatas {
|
||
|
liveDataMap[data.LiveItemId] = data
|
||
|
}
|
||
|
for _, list := range lists {
|
||
|
resultList = append(resultList, replyItem{
|
||
|
Id: list.Id,
|
||
|
Title: list.Title,
|
||
|
IsLive: list.Status,
|
||
|
Look: liveDataMap[list.Id].Look,
|
||
|
GoodsCount: list.GoodsCount,
|
||
|
Cover: list.Cover,
|
||
|
StartAt: list.StartAt.Time.Unix(),
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
back.Suc(c, "操作成功", gin.H{
|
||
|
"total": total,
|
||
|
"lists": resultList,
|
||
|
})
|
||
|
}
|