Commit 45c8b1a8 authored by hujiebin's avatar hujiebin

获取背包

parent 9dee630a
...@@ -34,3 +34,13 @@ func GetUserValidUserBag(model *domain.Model, userId mysql.ID, resType res_e.Res ...@@ -34,3 +34,13 @@ func GetUserValidUserBag(model *domain.Model, userId mysql.ID, resType res_e.Res
} }
return res, nil 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
}
...@@ -36,3 +36,12 @@ func FindValidResGiftsMap(model *domain.Model) (map[mysql.ID]ResGift, error) { ...@@ -36,3 +36,12 @@ func FindValidResGiftsMap(model *domain.Model) (map[mysql.ID]ResGift, error) {
} }
return res, nil 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
}
...@@ -26,6 +26,7 @@ func InitRouter() *gin.Engine { ...@@ -26,6 +26,7 @@ func InitRouter() *gin.Engine {
innerUser := inner.Group("/user") innerUser := inner.Group("/user")
{ {
innerUser.GET("/levels", wrapper(user_r.MGetUserLevels)) innerUser.GET("/levels", wrapper(user_r.MGetUserLevels))
innerUser.GET("/bag", wrapper(user_r.GetUserBag))
} }
return r return r
} }
...@@ -6,8 +6,11 @@ import ( ...@@ -6,8 +6,11 @@ import (
"git.hilo.cn/hilo-common/resource/mysql" "git.hilo.cn/hilo-common/resource/mysql"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"hilo-user/cv/user_cv" "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/domain/model/user_m"
"hilo-user/resp" "hilo-user/resp"
"time"
) )
type MGetUserLevelReq struct { type MGetUserLevelReq struct {
...@@ -43,3 +46,41 @@ func MGetUserLevels(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -43,3 +46,41 @@ func MGetUserLevels(c *gin.Context) (*mycontext.MyContext, error) {
resp.ResponseOk(c, response) resp.ResponseOk(c, response)
return myCtx, nil 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
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment