From 45c8b1a87a102c4eb15f5120cd2b95aa98855859 Mon Sep 17 00:00:00 2001 From: hujiebin Date: Tue, 21 Feb 2023 16:58:23 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E8=83=8C=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- domain/model/bag_m/user_bag.go | 10 +++++++++ domain/model/res_m/gift.go | 9 ++++++++ route/router.go | 1 + route/user_r/inner.go | 41 ++++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+) diff --git a/domain/model/bag_m/user_bag.go b/domain/model/bag_m/user_bag.go index 5025b7b..543c006 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 7c62fe8..5c540d0 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 601d1f7..092b91a 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 42d4de7..da49122 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 +} -- 2.22.0