细节调整

master
kanade 5 years ago
parent 7a12a0fcdc
commit 083404cf7b

@ -29,7 +29,7 @@ func (d *Data) List(c *gin.Context) {
return
}
userId := common.GetUserId(c)
liveItems := (&live.LiveItem{}).GetUserList(userId, args.GetStart(), args.GetLimit())
liveItems := (&live.LiveItem{}).GetUserListFinish(userId, args.GetStart(), args.GetLimit())
reply := []replyList{}
for _, item := range liveItems {
reply = append(reply, replyList{

@ -376,6 +376,11 @@ func (l *Live) Explain(c *gin.Context) {
liveGoods := &live2.LiveGoods{}
liveGoods.UnExplain(args.LiveItemId)
liveGoods.Explain(args.LiveItemId, args.GoodsId)
live.ImLogic.SendLiveGroupMessage(liveItem.RoomId, live.LiveGroupMsgTypeExplain, gin.H{
"goodsId": args.GoodsId,
})
back.Suc(c, "操作成功", nil)
}
@ -398,6 +403,10 @@ func (l *Live) UnExplain(c *gin.Context) {
}
liveGoods := &live2.LiveGoods{}
liveGoods.UnExplain(args.LiveItemId)
live.ImLogic.SendLiveGroupMessage(liveItem.RoomId, live.LiveGroupMsgTypeUnExplain, gin.H{
"goodsId": args.GoodsId,
})
back.Suc(c, "操作成功", nil)
}

@ -0,0 +1,70 @@
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,
})
}

@ -2,6 +2,7 @@ package user
import (
"github.com/gin-gonic/gin"
"live/app/common"
"live/app/lib"
"live/app/lib/back"
"live/app/lib/tools"
@ -27,6 +28,7 @@ func (t *Trend) List(c *gin.Context) {
back.Fail(c, "参数错误")
return
}
back.Suc(c, "操作成功", (&user.Trend{}).GetList(args.UserId, args.Page))
userId := common.GetUserId(c)
back.Suc(c, "操作成功", (&user.Trend{}).GetList(userId, args.UserId, args.Page))
return
}

File diff suppressed because one or more lines are too long

@ -47,6 +47,9 @@ type TrendItem struct {
UpdatedAt string `json:"updatedAt"`
Short Short `json:"short"`
Praise uint `json:"praise"`
IsPraise uint `json:"isPraise"`
TopicId uint `json:"topicId"`
TopicName string `json:"topicName"`
}
type TrendList struct {
List []TrendItem `json:"list"`

@ -50,6 +50,13 @@ func (c *Cupboard) Delete(uid uint, ids []int) (err bool) {
// @Title 添加会员橱柜数据
// @Param uid int true "会员id"
func (c *Cupboard) Add(uid int, ids []int) (err error) {
return
func (c *Cupboard) Add(userId uint, goodsIds []uint) int64 {
data := []goods.GoodsWindow{}
for _, goodsId := range goodsIds {
data = append(data, goods.GoodsWindow{
UserId: userId,
GoodsId: goodsId,
})
}
return (&goods.GoodsWindow{}).CreateAll(&data)
}

@ -1,6 +1,7 @@
package live
import (
"encoding/json"
"errors"
"fmt"
"live/app/lib/config"
@ -13,6 +14,11 @@ import (
type im struct {
}
const (
LiveGroupMsgTypeExplain = "Explain"
LiveGroupMsgTypeUnExplain = "UnExplain"
)
var ImLogic = &im{}
type UserInfo struct {
@ -62,3 +68,15 @@ func (i *im) NoLoginUserInfo() (err error, userInfo UserInfo) {
}
}
}
type LiveGroupMessage struct {
Type string `json:"type"`
Data interface{} `json:"data"`
}
// @Title 直播群消息
func (i *im) SendLiveGroupMessage(liveRoomId uint, messageType string, data interface{}) {
liveRoom := (&live2.LiveRoom{}).GetLiveById(liveRoomId)
strData, _ := json.Marshal(LiveGroupMessage{Type: messageType, Data: data})
tencent.Im.SendLiveGroupMessage(liveRoom.GroupId, string(strData))
}

@ -9,6 +9,7 @@ import (
"live/app/lib"
"live/app/lib/recook"
"live/app/lib/tencent"
"live/app/logic/goods"
live2 "live/app/model/live"
"live/app/model/user"
"strconv"
@ -58,6 +59,7 @@ func (l live) Start(userId uint, title, cover string, topic uint, goodsIds []uin
liveItemModel.SetDb(tx)
liveItem := live2.LiveItem{
UserId: userId,
RoomId: liveRoom.Id,
MainGoodsId: goodsIds[0],
Title: title,
Cover: cover,
@ -86,6 +88,10 @@ func (l live) Start(userId uint, title, cover string, topic uint, goodsIds []uin
if row <= 0 {
return errors.New("网络异常")
}
// 加入橱窗
(&goods.Cupboard{}).Add(userId, goodsIds)
liveDataModel := &live2.LiveData{}
liveData := live2.LiveData{
UserId: userId,

@ -60,13 +60,17 @@ func (s *Short) Publish(userId, goodsId, topicId uint, fileId, content string, l
type TopicInfoItem struct {
recook.ReplyUserItem
Content string `json:"content"`
CoverUrl string `json:"coverUrl"`
TrendId uint `json:"trendId"`
OriginId uint `json:"originId"`
TrendType int `json:"trendType"`
Praise uint `json:"praise"`
IsPraise int `json:"isPraise"`
Content string `json:"content"`
CoverUrl string `json:"coverUrl"`
TrendId uint `json:"trendId"`
OriginId uint `json:"originId"`
TrendType int `json:"trendType"`
Praise uint `json:"praise"`
IsPraise int `json:"isPraise"`
Goods recook.TrendGoods `json:"goods"`
MediaUrl string `json:"mediaUrl"`
TopicId uint `json:"topicId"`
TopicName string `json:"topicName"`
}
func (s *Short) List(userId uint, page lib.Page) (result *[]TopicInfoItem, count int64, err error) {
@ -105,9 +109,15 @@ func (s *Short) ListByTopicId(userId, topicId uint, page lib.Page) (result *[]To
func (s *Short) formtList(userId uint, lists []short.Short, result *[]TopicInfoItem) (err error) {
userIds := []uint{}
shortIds := []uint{}
goodsIds := []uint{}
topicIds := []uint{}
for _, list := range lists {
userIds = append(userIds, list.UserId)
shortIds = append(shortIds, list.Id)
goodsIds = append(goodsIds, list.GoodsId)
if list.TopicId > 0 {
topicIds = append(topicIds, list.TopicId)
}
}
// 获取会员信息
@ -120,6 +130,15 @@ func (s *Short) formtList(userId uint, lists []short.Short, result *[]TopicInfoI
userMap[userItem.UserId] = userItem
}
// 获取话题信息
topicMap := map[uint]topic2.Topic{}
if len(topicIds) > 0 {
topics := (&topic2.Topic{}).GetlistByIds(topicIds)
for _, item := range topics {
topicMap[item.Id] = item
}
}
// 获取会员动态信息
trendLists := recook.Trend.Infos(shortIds, user.TREND_TYPE_short)
trendIds := []uint{}
@ -129,6 +148,9 @@ func (s *Short) formtList(userId uint, lists []short.Short, result *[]TopicInfoI
trendMap[trendInfo.OriginId] = trendInfo
}
// 获取商品信息
goodsInfos := recook.Trend.GetGoods(goodsIds)
// 获取动态统计信息
userTrendDataModel := &user2.UserTrendData{}
userTrendDataLists := userTrendDataModel.GetListByTrendIds(trendIds)
@ -162,6 +184,10 @@ func (s *Short) formtList(userId uint, lists []short.Short, result *[]TopicInfoI
TrendType: trendInfo.TrendType,
Praise: userTrendDataMap[trendInfo.Id].Praise,
IsPraise: hasPraise,
Goods: goodsInfos[list.GoodsId],
MediaUrl: list.MediaUrl,
TopicId: list.TopicId,
TopicName: topicMap[list.TopicId].Title,
})
}
return

@ -4,6 +4,7 @@ import (
"live/app/lib"
"live/app/lib/recook"
"live/app/model/short"
"live/app/model/topic"
"live/app/model/user"
)
@ -16,7 +17,7 @@ type Trend struct {
}
// @Title 获取动态列表
func (t *Trend) GetList(userId uint, page lib.Page) *recook.TrendList {
func (t *Trend) GetList(loginUserId, userId uint, page lib.Page) *recook.TrendList {
// 获取动态列表及图文消息
list := recook.Trend.GetList(userId, page.GetPage(), page.GetLimit())
shortIds := []uint{}
@ -37,25 +38,51 @@ func (t *Trend) GetList(userId uint, page lib.Page) *recook.TrendList {
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
}
}
return list

@ -2,6 +2,7 @@ package goods
import (
"github.com/golangkit/formatime"
"gorm.io/gorm/clause"
"live/app/lib/db"
)
@ -24,6 +25,14 @@ func (g *GoodsWindow) Create(goodsWindow *GoodsWindow) uint {
return 0
}
// 批量插入 忽略重复
func (g *GoodsWindow) CreateAll(goodsWindows *[]GoodsWindow) int64 {
if len(*goodsWindows) == 0 {
return 0
}
return g.GetDb().Clauses(clause.OnConflict{DoNothing: true}).Create(goodsWindows).RowsAffected
}
// @Title 通过会员id获取数据
// @Param userId uint true "会员id"
func (g *GoodsWindow) GetListByUserId(userId uint, start, limit int) *[]GoodsWindow {

@ -44,7 +44,7 @@ func (l *LiveGoods) UnExplain(liveItemId uint) int64 {
if liveItemId == 0 {
return 0
}
return l.GetDb().Model(&LiveGoods{LiveItemId: liveItemId}).Update("is_explain", 0).RowsAffected
return l.GetDb().Model(&LiveGoods{}).Where("live_item_id = ?", liveItemId).Update("is_explain", 0).RowsAffected
}
// 讲解
@ -52,5 +52,5 @@ func (l *LiveGoods) Explain(liveItemId, goodsId uint) int64 {
if liveItemId == 0 {
return 0
}
return l.GetDb().Model(&LiveGoods{LiveItemId: liveItemId, GoodsId: goodsId}).Update("is_explain", 1).RowsAffected
return l.GetDb().Model(&LiveGoods{}).Where("live_item_id = ? and goods_id = ?", liveItemId, goodsId).Update("is_explain", 1).RowsAffected
}

@ -14,7 +14,9 @@ type LiveItem struct {
db.BaseModel
Id uint `gorm:"column:id" json:"id"`
UserId uint `gorm:"column:user_id" json:"userId"`
RoomId uint `gorm:"column:room_id" json:"roomId"`
MainGoodsId uint `gorm:"column:main_goods_id" json:"mainGoodsId"`
GoodsCount uint `gorm:"column:goods_count" json:"goodsCount"`
Title string `gorm:"column:title" json:"title"`
Cover string `gorm:"column:cover" json:"cover"`
Topic uint `gorm:"column:topic" json:"topic"`
@ -61,7 +63,19 @@ func (l *LiveItem) GetListByTime(userId uint, startTime, endTime formatime.Secon
}
// @Title 当前直播场次信息
func (l *LiveItem) GetUserList(userId uint, start, limit int) (result []LiveItem) {
func (l *LiveItem) GetUserListFinish(userId uint, start, limit int) (result []LiveItem) {
l.GetDb().Model(&LiveItem{}).Find(&result, "user_id = ? and `status` = ?", userId, LIVE_STATUS_finish)
return
}
// @Title 当前直播场次信息
func (l *LiveItem) GetUserListTotal(userId uint) (result int64) {
l.GetDb().Model(&LiveItem{}).Where("user_id = ?", userId).Count(&result)
return
}
// @Title 当前直播场次信息
func (l *LiveItem) GetUserList(userId uint, start, limit int) (result []LiveItem) {
l.GetDb().Model(&LiveItem{}).Order("id desc").Find(&result, "user_id = ?", userId)
return
}

@ -27,6 +27,17 @@ func (l *LiveRoom) Create(liveRoom *LiveRoom) uint {
}
func (l *LiveRoom) GetLiveByUserId(userId uint) (result LiveRoom) {
if userId <= 0 {
return
}
l.GetDb().First(&result, "user_id = ?", userId)
return
}
func (l *LiveRoom) GetLiveById(id uint) (result LiveRoom) {
if id <= 0 {
return
}
l.GetDb().First(&result, "id = ?", id)
return
}

@ -58,7 +58,7 @@ func Router(router *gin.Engine) {
}
trendC := &user.Trend{}
userR.POST("trend/list", trendC.List) // 会员动态列表
userR.POST("trend/list", middleware.BothAuth(), trendC.List) // 会员动态列表
commentC := &trend.Comment{}
userR.POST("trend/comment/list", middleware.BothAuth(), commentC.List) // 评论列表
@ -71,6 +71,9 @@ func Router(router *gin.Engine) {
praiseC := &trend.Praise{}
userR.POST("trend/praise/add", middleware.Auth(), praiseC.Add) // 动态点赞
userR.POST("trend/praise/cancel", middleware.Auth(), praiseC.Cancel) // 动态取消点赞
liveC := user.Live{}
userR.POST("live/list", liveC.UserList) // 会员直播列表
}
// 订单
orderR := liveRouter.Group("/order")

@ -0,0 +1,29 @@
#!/usr/bin/env bash
echo "编译中"
go-bindata -o=./app/lib/asset/asset.go -pkg=asset config/...
# shellcheck disable=SC2006
DIR=`dirname "$0"`
# shellcheck disable=SC2164
# shellcheck disable=SC2086
cd $DIR
if [[ -f "./bin/recook" ]];then
echo "删除原来执行文件..."
rm ./bin/recook
fi
GOPROXY=https://goproxy.cn GOSUMDB=off GO111MODULE=on CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/recook_live
echo "🎄🎄🎄🎄🎄🎄🎄🎄编译完成🎄🎄🎄🎄🎄🎄🎄🎄🎄"
Loading…
Cancel
Save