gift.go 1.87 KB
Newer Older
hujiebin's avatar
hujiebin committed
1 2 3 4 5 6 7 8
package recommend_r

import (
	"git.hilo.cn/hilo-common/domain"
	"git.hilo.cn/hilo-common/mycontext"
	"git.hilo.cn/hilo-common/resource/mysql"
	"github.com/gin-gonic/gin"
	"hilo-user/cv/user_cv"
hujiebin's avatar
hujiebin committed
9
	"hilo-user/domain/model/group_m"
hujiebin's avatar
hujiebin committed
10 11 12 13 14
	"hilo-user/domain/model/recommend_m"
	"hilo-user/domain/model/user_m"
	"hilo-user/resp"
)

hujiebin's avatar
hujiebin committed
15
type RecommendUser struct {
hujiebin's avatar
hujiebin committed
16 17
	User        *user_cv.UserTiny `json:"user"`
	CurrentRoom string            `json:"currentRoom"` // 当前用户所在房间(产品叫“群组”)
hujiebin's avatar
hujiebin committed
18 19
}

hujiebin's avatar
hujiebin committed
20 21 22
// @Tags 用户推荐
// @Summary 推荐最近送礼的50人,最近12小时赠送礼物大于100k的用户
// @Param token header string true "token"
hujiebin's avatar
hujiebin committed
23
// @Success 200 {object} []RecommendUser
hujiebin's avatar
hujiebin committed
24 25 26 27 28 29
// @Router /v1/recommend/user/gift [get]
func UserRecommendGift(c *gin.Context) (*mycontext.MyContext, error) {
	myContext := mycontext.CreateMyContext(c.Keys)
	model := domain.CreateModelContext(myContext)
	// 获取推荐
	recommendUser := recommend_m.GetPastTop50SendGiftUsers(model)
hujiebin's avatar
hujiebin committed
30
	var response = make([]RecommendUser, 0)
hujiebin's avatar
hujiebin committed
31 32 33 34 35 36 37 38 39 40 41 42
	if len(recommendUser) <= 0 {
		resp.ResponseOk(c, response)
		return myContext, nil
	}
	var userIds []mysql.ID
	for _, v := range recommendUser {
		userIds = append(userIds, v.SendUserId)
	}
	users, err := user_m.GetUserMapByIds(model, userIds)
	if err != nil {
		return myContext, err
	}
hujiebin's avatar
hujiebin committed
43 44 45
	rooms, err := group_m.RoomLivingUserIdFilter(model, userIds)
	if err != nil {
		return nil, err
hujiebin's avatar
hujiebin committed
46 47 48 49 50 51 52 53 54 55
	} else if len(rooms) > 0 {
		// to txGroupIds
		var imGroupIds []string
		for _, imGroupId := range rooms {
			imGroupIds = append(imGroupIds, imGroupId)
		}
		txGroupIdsMap, _ := group_m.ToTxGroupIdMap(model, imGroupIds)
		for uid, room := range rooms {
			rooms[uid] = txGroupIdsMap[room]
		}
hujiebin's avatar
hujiebin committed
56
	}
hujiebin's avatar
hujiebin committed
57
	for _, v := range recommendUser {
hujiebin's avatar
hujiebin committed
58
		response = append(response, RecommendUser{user_cv.UserToTiny(users[v.SendUserId]), rooms[v.SendUserId]})
hujiebin's avatar
hujiebin committed
59 60 61 62
	}
	resp.ResponseOk(c, response)
	return myContext, nil
}