From 6d699fdbaf8d42e50ba8db1fcf02226fc5b49a85 Mon Sep 17 00:00:00 2001 From: hujiebin Date: Fri, 9 Jun 2023 19:29:16 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=99=E5=87=BA=E6=8C=87=E5=AE=9Auids?= =?UTF-8?q?=E4=B8=8B=E7=9A=84cp=E5=AF=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- domain/model/cp_m/level.go | 10 +++++++++- route/router.go | 1 + route/user_r/inner.go | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/domain/model/cp_m/level.go b/domain/model/cp_m/level.go index b9e8c0c..9f45562 100644 --- a/domain/model/cp_m/level.go +++ b/domain/model/cp_m/level.go @@ -82,7 +82,7 @@ func AddCpLevelDetail(model *domain.Model, detail CpLevelDetail) error { return model.DB().Create(&detail).Error } -// 获取cpRelation pair +// 获取cpRelation func GetCpRelation(model *domain.Model, userId mysql.ID) (cpRelation CpRelationTmp, exits bool) { if err := model.DB().Model(CpRelationTmp{}).Where("user_id1 = ? or user_id2 = ?", userId, userId).First(&cpRelation).Error; err != nil { if err != gorm.ErrRecordNotFound { @@ -118,6 +118,14 @@ func GetCpRelationPair(model *domain.Model, userId1, userId2 mysql.ID) (cpRelati return } +// 获取cpRelation pair +func MGetCpRelation(model *domain.Model, userIds []mysql.ID) (cpRelation []CpRelationTmp) { + if err := model.DB().Model(CpRelationTmp{}).Where("user_id1 in ? or user_id2 in ?", userIds, userIds).Find(&cpRelation).Error; err != nil { + model.Log.Errorf("GetCpRelation fail:%v", err) + } + return +} + // 获取是否申请解绑中 func GetApplyToUnbind(model *domain.Model, userId, cpUserId mysql.ID) bool { var total int64 diff --git a/route/router.go b/route/router.go index 3074dc2..9ad16bc 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("/cp/pair", wrapper(user_r.GetUserCpPair)) } // 道具相关 innerProp := inner.Group("/prop") diff --git a/route/user_r/inner.go b/route/user_r/inner.go index c2a5e9c..c9db321 100644 --- a/route/user_r/inner.go +++ b/route/user_r/inner.go @@ -193,3 +193,35 @@ func GetUserCpRelation(c *gin.Context) (*mycontext.MyContext, error) { resp.ResponseOk(c, response) return myContext, nil } + +type GetUserCpPairReq struct { + Ids []mysql.ID `form:"ids" binding:"required"` +} + +// @Tags 用户-内部 +// @Summary 给出指定uids下的cp对 +// @Param ids query string true "用户id,如:ids=1&ids=2&ids=3" +// @Success 200 {object} [][]uint64 +// @Router /inner/user/cpRelation [get] +func GetUserCpPair(c *gin.Context) (*mycontext.MyContext, error) { + myContext := mycontext.CreateMyContext(c.Keys) + var model = domain.CreateModelContext(myContext) + var req GetUserCpPairReq + if err := c.ShouldBindQuery(&req); err != nil { + return myContext, err + } + userIds := req.Ids + m := make(map[mysql.ID]bool) + for _, uid := range userIds { + m[uid] = true + } + pairs := cp_m.MGetCpRelation(model, userIds) + var response [][2]uint64 + for _, pair := range pairs { + if m[pair.UserId1] && m[pair.UserId2] { + response = append(response, [2]mysql.ID{pair.UserId1, pair.UserId2}) + } + } + resp.ResponseOk(c, response) + return myContext, nil +} -- 2.22.0