diff --git a/domain/model/cp_m/level.go b/domain/model/cp_m/level.go index b9e8c0c7ed89885651bf71046ed9c047c60392a2..9f455620c73e67e9f6c0e762227647b90b0d07fa 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 3074dc2074c440aad0c3d92d7eededf60008c913..9ad16bc0159a3df846263b2c6c1316aaf7a9230d 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 c2a5e9c559a7f5d5a3c32859cc5801cd7eef4468..c9db321ffea95ed95453f50f897719aa4f55fefe 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 +}