diff --git a/route/router.go b/route/router.go index 58c016978bccbfb37e3527e79ae031318a371aec..1c7b3ec2dedcd9aca1bd0745b57f729c4ace0060 100755 --- a/route/router.go +++ b/route/router.go @@ -58,6 +58,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 d251c21a13df1e5fd6a014424ba0b9bdd23ce97c..1b1a5e479341c47e28c8b7983b7dfcf64611e2d4 100644 --- a/route/user_r/inner.go +++ b/route/user_r/inner.go @@ -204,6 +204,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"` }