diff --git a/domain/model/cp_m/level.go b/domain/model/cp_m/level.go index 3abd0fb314c39e74e73d4c80e64c167bd0a4ec7d..c96a5c9b43855c3d8dbba822c83e09644278822e 100644 --- a/domain/model/cp_m/level.go +++ b/domain/model/cp_m/level.go @@ -83,7 +83,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 { @@ -119,6 +119,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 1e83d49001a0ff7e87cf42fe87fa3eabd4170d0b..8c6b5d02c638c8dd2eaab905d219b58d0a5ad66d 100755 --- a/route/router.go +++ b/route/router.go @@ -57,6 +57,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 +}