From 65daebada343a67c991d32a4c0a0b116f72e0f6e Mon Sep 17 00:00:00 2001 From: hujiebin Date: Wed, 14 Jun 2023 14:49:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=B9=E9=87=8F=E8=8E=B7=E5=8F=96=E7=94=A8?= =?UTF-8?q?=E6=88=B7cp=E5=85=B3=E7=B3=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- route/router.go | 1 + route/user_r/inner.go | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/route/router.go b/route/router.go index 9ad16bc..5ac00b4 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 33c7523..7bee448 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"` } -- 2.22.0