diff --git a/domain/model/bag_m/user_bag.go b/domain/model/bag_m/user_bag.go index 5025b7bde13e92c0943703cc032fa28f77283c53..543c0062c089621deb8c5ff721c6e4095766141f 100644 --- a/domain/model/bag_m/user_bag.go +++ b/domain/model/bag_m/user_bag.go @@ -34,3 +34,13 @@ func GetUserValidUserBag(model *domain.Model, userId mysql.ID, resType res_e.Res } return res, nil } + +// 获取指定背包 +func GetUserBag(model *domain.Model, bagId mysql.ID) (*UserBag, error) { + res := new(UserBag) + if err := model.DB().Model(UserBag{}). + Where("id = ?", bagId).First(res).Error; err != nil { + return nil, err + } + return res, nil +} diff --git a/domain/model/res_m/gift.go b/domain/model/res_m/gift.go index 7c62fe88e59085f3425f4e5af5b6174dafbb39dc..5c540d0ae06343bd0f5268435951943d10713af9 100644 --- a/domain/model/res_m/gift.go +++ b/domain/model/res_m/gift.go @@ -36,3 +36,12 @@ func FindValidResGiftsMap(model *domain.Model) (map[mysql.ID]ResGift, error) { } return res, nil } + +// 获取礼物 +func FindResGift(model *domain.Model, giftId mysql.ID) (*ResGift, error) { + res := new(ResGift) + if err := model.DB().Model(ResGift{}).Where("id = ?", giftId).First(res).Error; err != nil { + return nil, err + } + return res, nil +} diff --git a/route/router.go b/route/router.go index 601d1f7c958387fcc635e619c054782b066ff28f..092b91aedadb050013d328bac2037272a541d682 100755 --- a/route/router.go +++ b/route/router.go @@ -26,6 +26,7 @@ func InitRouter() *gin.Engine { innerUser := inner.Group("/user") { innerUser.GET("/levels", wrapper(user_r.MGetUserLevels)) + innerUser.GET("/bag", wrapper(user_r.GetUserBag)) } return r } diff --git a/route/user_r/inner.go b/route/user_r/inner.go index 42d4de7ce89cb9380a1c2b555e34d6a4de5b4fac..da49122a92a798c4208fb91557d60252c0ca6ab3 100644 --- a/route/user_r/inner.go +++ b/route/user_r/inner.go @@ -6,8 +6,11 @@ import ( "git.hilo.cn/hilo-common/resource/mysql" "github.com/gin-gonic/gin" "hilo-user/cv/user_cv" + "hilo-user/domain/model/bag_m" + "hilo-user/domain/model/res_m" "hilo-user/domain/model/user_m" "hilo-user/resp" + "time" ) type MGetUserLevelReq struct { @@ -43,3 +46,41 @@ func MGetUserLevels(c *gin.Context) (*mycontext.MyContext, error) { resp.ResponseOk(c, response) return myCtx, nil } + +type GetUserBagReq struct { + BagId mysql.ID `form:"bagId" binding:"required"` +} + +// @Tags 用户-内部 +// @Summary 获取单个背包 +// @Param bagId query int true "背包id" +// @Success 200 {object} user_cv.UserBag +// @Router /inner/user/bag [get] +func GetUserBag(c *gin.Context) (*mycontext.MyContext, error) { + myCtx := mycontext.CreateMyContext(c.Keys) + var model = domain.CreateModelContext(myCtx) + var req GetUserBagReq + if err := c.ShouldBindQuery(&req); err != nil { + return myCtx, err + } + bag, err := bag_m.GetUserBag(model, req.BagId) + if err != nil { + return myCtx, err + } + gift, err := res_m.FindResGift(model, bag.ResId) + if err != nil { + return myCtx, err + } + resp.ResponseOk(c, user_cv.UserBag{ + BagId: bag.ID, + ResType: bag.ResType, + ResId: bag.ResId, + Name: gift.Name, + DiamondNum: gift.DiamondNum, + IconUrl: gift.IconUrl, + SvgaUrl: gift.SvagUrl, + Count: bag.Count, + RemainDays: int(bag.EndTime.Sub(time.Now()).Hours() / 24), + }) + return myCtx, nil +}