Commit 65daebad authored by hujiebin's avatar hujiebin

批量获取用户cp关系

parent baa1f37b
...@@ -51,6 +51,7 @@ func InitRouter() *gin.Engine { ...@@ -51,6 +51,7 @@ func InitRouter() *gin.Engine {
innerUser.GET("/bag/id", wrapper(user_r.GetUserBagId)) innerUser.GET("/bag/id", wrapper(user_r.GetUserBagId))
innerUser.GET("/cp", wrapper(user_r.GetUserCp)) innerUser.GET("/cp", wrapper(user_r.GetUserCp))
innerUser.GET("/cpRelation", wrapper(user_r.GetUserCpRelation)) innerUser.GET("/cpRelation", wrapper(user_r.GetUserCpRelation))
innerUser.GET("/cpRelations", wrapper(user_r.MGetUserCpRelation))
innerUser.GET("/cp/pair", wrapper(user_r.GetUserCpPair)) innerUser.GET("/cp/pair", wrapper(user_r.GetUserCpPair))
} }
// 道具相关 // 道具相关
......
...@@ -202,6 +202,46 @@ func GetUserCpRelation(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -202,6 +202,46 @@ func GetUserCpRelation(c *gin.Context) (*mycontext.MyContext, error) {
return myContext, nil return myContext, nil
} }
type MGetUserCpRelationReq struct {
Ids []mysql.ID `form:"ids" binding:"required"`
}
// @Tags 用户-内部
// @Summary 批量获取用户cp关系
// @Param ids query int true "用户ids"
// @Success 200 {object} map[uint64]cp_cv.CvCpRelation
// @Router /inner/user/cpRelations [get]
func MGetUserCpRelation(c *gin.Context) (*mycontext.MyContext, error) {
myContext := mycontext.CreateMyContext(c.Keys)
var model = domain.CreateModelContext(myContext)
var req MGetUserCpRelationReq
if err := c.ShouldBindQuery(&req); err != nil {
return myContext, err
}
cpRelations := cp_m.MGetCpRelation(model, req.Ids)
var m = make(map[uint64]cp_m.CpRelationTmp)
for i, v := range cpRelations {
m[v.UserId1] = cpRelations[i]
m[v.UserId2] = cpRelations[i]
}
var response = make(map[uint64]cp_cv.CvCpRelation)
for _, uid := range req.Ids {
if cpRelation, ok := m[uid]; ok {
cpUserId := cpRelation.UserId2
if cpUserId == uid {
cpUserId = cpRelation.UserId1
}
response[uid] = cp_cv.CvCpRelation{
CpId: cpRelation.ID,
UserId: uid,
CpUserId: cpUserId,
}
}
}
resp.ResponseOk(c, response)
return myContext, nil
}
type GetUserCpPairReq struct { type GetUserCpPairReq struct {
Ids []mysql.ID `form:"ids" binding:"required"` Ids []mysql.ID `form:"ids" binding:"required"`
} }
......
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