bag.go 2.11 KB
Newer Older
hujiebin's avatar
hujiebin committed
1 2 3 4 5 6
package user_r

import (
	"git.hilo.cn/hilo-common/domain"
	"git.hilo.cn/hilo-common/mycontext"
	"github.com/gin-gonic/gin"
chenweijian's avatar
chenweijian committed
7
	"hilo-user/_const/enum/cp_e"
hujiebin's avatar
hujiebin committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
	"hilo-user/_const/enum/res_e"
	"hilo-user/cv/user_cv"
	"hilo-user/domain/model/bag_m"
	"hilo-user/domain/model/res_m"
	"hilo-user/myerr/bizerr"
	"hilo-user/req"
	"hilo-user/resp"
	"strconv"
	"time"
)

// @Tags 用户背包
// @Summary 获取用户的背包
// @Param resType path int true "类型:1 礼物"
// @Success 200 {object} []user_cv.UserBag
// @Router /v1/user/bag/{resType} [get]
func UserBag(c *gin.Context) (*mycontext.MyContext, error) {
	myCtx := mycontext.CreateMyContext(c.Keys)
	userId, err := req.GetUserId(c)
	if err != nil {
		return myCtx, err
	}
	model := domain.CreateModelContext(myCtx)
	resType, err := strconv.Atoi(c.Param("resType"))
	if err != nil {
		return myCtx, err
	}
	var results []user_cv.UserBag
	switch res_e.ResUserBag(resType) {
	case res_e.ResUserBagGift:
		userBagGifts, err := bag_m.GetUserValidUserBag(model, userId, res_e.ResUserBagGift)
		if err != nil {
			return myCtx, err
		}
hujiebin's avatar
hujiebin committed
42
		allGifts, err := res_m.FindAllResGiftsMap(model)
hujiebin's avatar
hujiebin committed
43 44 45 46
		if err != nil {
			return myCtx, err
		}
		for _, bagGift := range userBagGifts {
hujiebin's avatar
hujiebin committed
47
			if gift, ok := allGifts[bagGift.ResId]; ok {
chenweijian's avatar
chenweijian committed
48
				info := user_cv.UserBag{
hujiebin's avatar
hujiebin committed
49 50 51 52 53 54 55 56 57 58
					BagId:      bagGift.ID,
					ResType:    res_e.ResUserBagGift,
					ResId:      gift.ID,
					GiftId:     gift.ID,
					Name:       gift.Name,
					DiamondNum: gift.DiamondNum,
					IconUrl:    gift.IconUrl,
					SvgaUrl:    gift.SvagUrl,
					Count:      bagGift.Count,
					RemainDays: int(bagGift.EndTime.Sub(time.Now()).Hours() / 24),
chenweijian's avatar
chenweijian committed
59
				}
chenweijian's avatar
chenweijian committed
60
				if gift.ID == cp_e.CpConfessionGiftId { // 如果是cp告白礼物
chenweijian's avatar
chenweijian committed
61 62 63 64 65 66 67 68
					info.TextStyleList = make([]*user_cv.TextStyle, 0, 2)
					info.TextStyleList = append(info.TextStyleList,
						&user_cv.TextStyle{TextColor: "#ce0083", TextSize: 20, TextKey: "sender_name"},
						&user_cv.TextStyle{TextColor: "#ce0083", TextSize: 20, TextKey: "receiver_name"},
					)
				}

				results = append(results, info)
hujiebin's avatar
hujiebin committed
69 70 71 72 73 74 75 76
			}
		}
	default:
		return myCtx, bizerr.InvalidParameter
	}
	resp.ResponseOk(c, results)
	return myCtx, nil
}