diff --git a/domain/model/group_m/groupTop.go b/domain/model/group_m/groupTop.go index 0429a81e19fb2b7eb8d3f8ee88d4f03625b0534e..5cbf439078ddd5ad018ee58360372af0c0653ad0 100644 --- a/domain/model/group_m/groupTop.go +++ b/domain/model/group_m/groupTop.go @@ -23,9 +23,13 @@ func (g *GroupTop) Delete(model *domain.Model) error { return model.Db.Where(g).Delete(&GroupTop{}).Error } -func GroupTopGetAll(model *domain.Model) ([]string, error) { +func GroupTopGetAll(model *domain.Model, area int) ([]string, error) { rows := make([]GroupTop, 0) - err := model.Db.Order("id").Find(&rows).Error + err := model.DB().Table("group_top"). + Joins("left join group_info gi on group_top.im_group_id = gi.im_group_id "+ + "left join res_country rc on gi.country = rc.name"). + Where("rc.area = ?", area). + Order("group_top.id").Find(&rows).Error if err != nil { return nil, err } diff --git a/route/group_r/group_list.go b/route/group_r/group_list.go index b8fafb35348923e231a943bbc3532a05057fc725..e9d97f2fc8383fd6f6a42020f1e09bb36585292c 100644 --- a/route/group_r/group_list.go +++ b/route/group_r/group_list.go @@ -72,6 +72,12 @@ func GetPopularGroups(c *gin.Context) (*mycontext.MyContext, error) { } model := domain.CreateModelContext(myContext) + // 获取国家信息 + _, area, err := user_m.GetUserCountryArea(model, myUserId) + if err != nil { + model.Log.Errorf("GetUserCountryArea 获取国家资源错误 userId:%d, err:%v", myUserId, err) + return myContext, err + } /* 2022-06-30 老板说先不分区 regions, err := res_m.GetAllLangRegion(model) if err != nil { @@ -120,7 +126,7 @@ func GetPopularGroups(c *gin.Context) (*mycontext.MyContext, error) { model.Log.Infof("GetPopularGroups, micGroupNum: %v, banned %d, hidden %d,cost:%v", micGroupNum, banCount, hiddenCount, time.Now().Sub(start)) // 3. 处理置顶群 - topGroupIds, err := getTopGroups(model, bannedGroups, hiddenGroups) + topGroupIds, err := getTopGroups(model, bannedGroups, hiddenGroups, area) if err != nil { return myContext, err } @@ -165,12 +171,6 @@ func GetPopularGroups(c *gin.Context) (*mycontext.MyContext, error) { //} //logstr += " |" - // 获取国家信息 - _, area, err := user_m.GetUserCountryArea(model, myUserId) - if err != nil { - model.Log.Errorf("GetUserCountryArea 获取国家资源错误 userId:%d, err:%v", myUserId, err) - return myContext, err - } myArea := fmt.Sprintf("%d", area) // 国家区域信息 resAreaMap, err := res_c.GetCountryAreaMap(model) @@ -402,8 +402,8 @@ func GetPopularGroups(c *gin.Context) (*mycontext.MyContext, error) { return myContext, nil } -func getTopGroups(model *domain.Model, bannedGroups map[string]uint64, hiddenGroups map[string]struct{}) ([]string, error) { - topGroups, err := group_m.GroupTopGetAll(model) +func getTopGroups(model *domain.Model, bannedGroups map[string]uint64, hiddenGroups map[string]struct{}, area int) ([]string, error) { + topGroups, err := group_m.GroupTopGetAll(model, area) if err != nil { return nil, err }