Commit e7ec35d7 authored by hujiebin's avatar hujiebin

Merge branch 'feature/cp-new' into feature/3.9.0

parents d05fab9e 6d699fdb
......@@ -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
......
......@@ -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")
......
......@@ -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
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment