diff --git a/cv/user_cv/user.go b/cv/user_cv/user.go index 8ac46fd8d8af759ec6e29af92cd814c0721ba760..6e09de77dc321ee9a5bb0d8b90751cb0ac04299f 100644 --- a/cv/user_cv/user.go +++ b/cv/user_cv/user.go @@ -151,11 +151,15 @@ func GetUserBases(userIds []mysql.ID, myUserId mysql.ID) ([]*CvUserBase, error) //rp := res_m.ResProperty{} //properties, err := rp.GetAll(mysql.Db) - _, myArea, err := user_m.GetUserCountryArea(domain.CreateModelNil(), myUserId) - if err != nil { - return nil, err + propertiesArea := make(map[int]map[uint64]property_cv.CvProperty) + for _, v := range []int{1, 2} { + properties, err := GetPropertyAll(mysql.Db, v) + if err != nil { + return nil, err + } + propertiesArea[v] = properties } - properties, err := GetPropertyAll(mysql.Db, myArea) + areaMap, err := user_m.GetUserAreaMap(domain.CreateModelNil(), userIds) if err != nil { return nil, err } @@ -173,6 +177,7 @@ func GetUserBases(userIds []mysql.ID, myUserId mysql.ID) ([]*CvUserBase, error) cvUserBases := []*CvUserBase{} for i := 0; i < len(users); i++ { user := users[i] + properties := propertiesArea[areaMap[user.ID]] invisible := IfLogout(user.LogoutTime) invisibleAvatar := "" invisibleNick := user.Code diff --git a/domain/model/user_m/user.go b/domain/model/user_m/user.go index 15ee7d8d4428e36e28f1425d3784897da24204da..a9863ca6b8fb8f8a37d1fb5c88534eb9ac64b101 100755 --- a/domain/model/user_m/user.go +++ b/domain/model/user_m/user.go @@ -157,3 +157,21 @@ func GetUserCountryArea(model *domain.Model, userId mysql.ID) (string, int, erro } return res.Name, res.Area, nil } + +//获取用户的国家所属的区域(是否阿语区) +func GetUserAreaMap(model *domain.Model, userIds []mysql.ID) (map[mysql.ID]int, error) { + type info struct { + Id mysql.ID + Area int + } + rows := make([]*info, 0) + sql := "select user.id, rc.area from user left join res_country rc on user.country = rc.name where user.id in (?);" + if err := model.DB().Raw(sql, userIds).Scan(&rows).Error; err != nil { + return nil, myerr.WrapErr(err) + } + res := make(map[mysql.ID]int) + for _, v := range rows { + res[v.Id] = v.Area + } + return res, nil +}