From ae256c50c3989c73ecb66ac7bd04e3749aeca3d4 Mon Sep 17 00:00:00 2001 From: chenweijian <820961417@qq.com> Date: Mon, 26 Jun 2023 12:56:49 +0800 Subject: [PATCH] =?UTF-8?q?cp=E5=BA=A7=E9=A9=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cv/property_cv/property.go | 4 ++-- cv/user_cv/user.go | 10 +++++++--- domain/model/res_m/property.go | 1 + domain/model/user_m/user.go | 13 +++++++++++++ domain/service/user_s/user.go | 6 +++++- 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/cv/property_cv/property.go b/cv/property_cv/property.go index c6af321..6492d05 100644 --- a/cv/property_cv/property.go +++ b/cv/property_cv/property.go @@ -95,7 +95,7 @@ func GetPropertyById(resPropertyId mysql.ID) (CvProperty, error) { }, nil } -func GetPropertyAll(db *gorm.DB) (map[uint64]CvProperty, error) { +func GetPropertyAll(db *gorm.DB, area int) (map[uint64]CvProperty, error) { rp := res_m.ResProperty{} properties, err := rp.GetAll(mysql.Db) if err != nil { @@ -103,7 +103,7 @@ func GetPropertyAll(db *gorm.DB) (map[uint64]CvProperty, error) { } //获取座驾头像 - propertieAvatarMap, err := (&res_m.ResPropertyAvatar{}).GetAll(mysql.Db) + propertieAvatarMap, err := (&res_m.ResPropertyAvatar{Area: area}).GetAll(mysql.Db) userIds := []uint64{} for _, value := range propertieAvatarMap { diff --git a/cv/user_cv/user.go b/cv/user_cv/user.go index 9a51145..8ac46fd 100644 --- a/cv/user_cv/user.go +++ b/cv/user_cv/user.go @@ -151,7 +151,11 @@ func GetUserBases(userIds []mysql.ID, myUserId mysql.ID) ([]*CvUserBase, error) //rp := res_m.ResProperty{} //properties, err := rp.GetAll(mysql.Db) - properties, err := GetPropertyAll(mysql.Db) + _, myArea, err := user_m.GetUserCountryArea(domain.CreateModelNil(), myUserId) + if err != nil { + return nil, err + } + properties, err := GetPropertyAll(mysql.Db, myArea) if err != nil { return nil, err } @@ -338,7 +342,7 @@ func getMedalInfoMap(db *gorm.DB, medals map[uint64][]uint32) (map[uint64][]uint return medalIds, medalMap, nil } -func GetPropertyAll(db *gorm.DB) (map[uint64]property_cv.CvProperty, error) { +func GetPropertyAll(db *gorm.DB, area int) (map[uint64]property_cv.CvProperty, error) { rp := res_m.ResProperty{} properties, err := rp.GetAll(mysql.Db) if err != nil { @@ -346,7 +350,7 @@ func GetPropertyAll(db *gorm.DB) (map[uint64]property_cv.CvProperty, error) { } //获取座驾头像 - propertyAvatarMap, err := (&res_m.ResPropertyAvatar{}).GetAll(mysql.Db) + propertyAvatarMap, err := (&res_m.ResPropertyAvatar{Area: area}).GetAll(mysql.Db) var userIds []uint64 for _, value := range propertyAvatarMap { diff --git a/domain/model/res_m/property.go b/domain/model/res_m/property.go index d390314..0d5cbcc 100644 --- a/domain/model/res_m/property.go +++ b/domain/model/res_m/property.go @@ -33,6 +33,7 @@ type ResPropertyAvatar struct { Type res_e.ResPropertyAvatarType SendUserId mysql.ID ReceiverUserId mysql.ID + Area int } func InitResPropertyDiamond(model *domain.Model, resPropertyId mysql.ID, diamondNum mysql.Num, second mysql.Num) *ResPropertyDiamond { diff --git a/domain/model/user_m/user.go b/domain/model/user_m/user.go index d1b9f36..15ee7d8 100755 --- a/domain/model/user_m/user.go +++ b/domain/model/user_m/user.go @@ -144,3 +144,16 @@ func GetUsers(model *domain.Model, ids []mysql.ID) ([]*User, error) { } return res, nil } + +//获取用户的国家,和所属的区域(是否阿语区) +func GetUserCountryArea(model *domain.Model, userId mysql.ID) (string, int, error) { + type info struct { + Name string + Area int + } + res := new(info) + if err := model.Db.WithContext(model.Context).Raw("select name, area from res_country where name = (select country from user where id = ?)", userId).First(&res).Error; err != nil { + return "", 0, myerr.WrapErr(err) + } + return res.Name, res.Area, nil +} diff --git a/domain/service/user_s/user.go b/domain/service/user_s/user.go index be27029..71cc8c4 100644 --- a/domain/service/user_s/user.go +++ b/domain/service/user_s/user.go @@ -172,7 +172,11 @@ func (s *UserService) GetUserDetail(userId mysql.ID, myUserId mysql.ID, lang str //rp := res_m.ResProperty{} //properties, err := rp.GetAll(mysql.Db) - properties, err := property_cv.GetPropertyAll(mysql.Db) + _, myArea, err := user_m.GetUserCountryArea(model, myUserId) + if err != nil { + return nil, err + } + properties, err := property_cv.GetPropertyAll(mysql.Db, myArea) if err != nil { return nil, err } -- 2.22.0