package user_r import ( "git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/mycontext" "github.com/gin-gonic/gin" "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 } //weeklyStarGifts, _ := activity_m.GetWeeklyStartGift(model) //medalGifts, _ := res_m.FindMedalPublicObtainAll(model.Db) 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 } allValidGifts, err := res_m.FindValidResGiftsMap(model) if err != nil { return myCtx, err } for _, bagGift := range userBagGifts { if gift, ok := allValidGifts[bagGift.ResId]; ok { results = append(results, user_cv.UserBag{ 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), Tags: nil, // todo ShowEntry: false, // todo GroupBroadcast: gift.GroupBroadcast, }) } } default: return myCtx, bizerr.InvalidParameter } resp.ResponseOk(c, results) return myCtx, nil }