diff --git a/route/router.go b/route/router.go index 9ad16bc0159a3df846263b2c6c1316aaf7a9230d..5ac00b44fe9b8bfc7143b555779c4ec095ef2068 100755 --- a/route/router.go +++ b/route/router.go @@ -51,6 +51,7 @@ func InitRouter() *gin.Engine { innerUser.GET("/bag/id", wrapper(user_r.GetUserBagId)) innerUser.GET("/cp", wrapper(user_r.GetUserCp)) innerUser.GET("/cpRelation", wrapper(user_r.GetUserCpRelation)) + innerUser.GET("/cpRelations", wrapper(user_r.MGetUserCpRelation)) innerUser.GET("/cp/pair", wrapper(user_r.GetUserCpPair)) } // 道具相关 diff --git a/route/user_r/inner.go b/route/user_r/inner.go index 33c75237daa19fc291b06be5b6f52d2c105a408a..7bee448aef23a1e04be71b117bbfe3b706f59780 100644 --- a/route/user_r/inner.go +++ b/route/user_r/inner.go @@ -202,6 +202,46 @@ func GetUserCpRelation(c *gin.Context) (*mycontext.MyContext, error) { 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 { Ids []mysql.ID `form:"ids" binding:"required"` }