From c6c4ebb916876e3f5095a2e8b52dc3632672aba3 Mon Sep 17 00:00:00 2001 From: miaowuawa <2484667023@qq.com> Date: Tue, 5 Aug 2025 20:45:54 +0800 Subject: [PATCH] fix bugs --- go.mod | 8 ++--- go.sum | 8 +++++ internal/core/level.go | 2 +- internal/dao/jinzhu/dbr/user.go | 21 ++++++++++++- internal/dao/jinzhu/jinzhu.go | 4 +-- internal/dao/jinzhu/user.go | 52 +++++++++++++-------------------- internal/model/web/loose.go | 2 ++ mirc/web/v1/activities.go | 4 --- 8 files changed, 56 insertions(+), 45 deletions(-) delete mode 100644 mirc/web/v1/activities.go diff --git a/go.mod b/go.mod index 63127509..7fbfea1a 100644 --- a/go.mod +++ b/go.mod @@ -6,13 +6,13 @@ require ( github.com/Masterminds/semver/v3 v3.2.1 github.com/RoaringBitmap/roaring v1.9.4 github.com/afocus/captcha v0.0.0-20191010092841-4bd1f21c8868 - github.com/alimy/mir/v5 v5.2.2 + github.com/alimy/mir/v5 v5.2.3 github.com/alimy/tryst v1.1.0 github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible github.com/allegro/bigcache/v3 v3.1.0 github.com/bytedance/sonic v1.12.6 github.com/cockroachdb/errors v1.11.3 - github.com/disintegration/imaging v1.6.2 + github.com/disintegration/imaging v1.6.3-0.20200122095911-d8633a436aab github.com/fatih/color v1.18.0 github.com/getsentry/sentry-go v0.33.0 github.com/getsentry/sentry-go/gin v0.33.0 @@ -61,7 +61,7 @@ require ( gorm.io/driver/mysql v1.5.7 gorm.io/driver/postgres v1.6.0 gorm.io/driver/sqlite v1.5.7 - gorm.io/gorm v1.30.0 + gorm.io/gorm v1.30.1 gorm.io/plugin/dbresolver v1.6.0 gorm.io/plugin/soft_delete v1.2.1 modernc.org/sqlite v1.37.1 @@ -92,7 +92,7 @@ require ( github.com/go-playground/validator/v10 v10.20.0 // indirect github.com/go-sql-driver/mysql v1.7.0 // indirect github.com/go-task/slim-sprig/v3 v3.0.0 // indirect - github.com/go-viper/mapstructure/v2 v2.2.1 // indirect + github.com/go-viper/mapstructure/v2 v2.3.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang-jwt/jwt/v4 v4.5.2 // indirect github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect diff --git a/go.sum b/go.sum index 07297b77..a5f831b1 100644 --- a/go.sum +++ b/go.sum @@ -11,6 +11,8 @@ github.com/afocus/captcha v0.0.0-20191010092841-4bd1f21c8868 h1:uFrPOl1VBt/Abfl2 github.com/afocus/captcha v0.0.0-20191010092841-4bd1f21c8868/go.mod h1:srphKZ1i+yGXxl/LpBS7ZIECTjCTPzZzAMtJWoG3sLo= github.com/alimy/mir/v5 v5.2.2 h1:q66hf1xLFjP7nRcSPTOiPg9Fv2e0bNzw95YadoxadFI= github.com/alimy/mir/v5 v5.2.2/go.mod h1:R76XQiU3K7T4V0aOcd4r5OeO7Gf8yTIVtnLbt1LLf2U= +github.com/alimy/mir/v5 v5.2.3 h1:Bks3tBc5+m/xkalMHAzJ734KcGzkSgPk0yzWGo1yie4= +github.com/alimy/mir/v5 v5.2.3/go.mod h1:R76XQiU3K7T4V0aOcd4r5OeO7Gf8yTIVtnLbt1LLf2U= github.com/alimy/tryst v1.1.0 h1:EiGiTLLw9n6bfg1WwnqoZTb1gnDHDHxozjfE/cuVjlI= github.com/alimy/tryst v1.1.0/go.mod h1:t/Ocn3Qd2P8Sg5VIL11s1H7cBCYZcDy+VNwiFHix+lI= github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible h1:8psS8a+wKfiLt1iVDX79F7Y6wUM49Lcha2FMXt4UM8g= @@ -56,6 +58,8 @@ github.com/dhui/dktest v0.4.5 h1:uUfYBIVREmj/Rw6MvgmqNAYzTiKOHJak+enB5Di73MM= github.com/dhui/dktest v0.4.5/go.mod h1:tmcyeHDKagvlDrz7gDKq4UAJOLIfVZYkfD5OnHDwcCo= github.com/disintegration/imaging v1.6.2 h1:w1LecBlG2Lnp8B3jk5zSuNqd7b4DXhcjwek1ei82L+c= github.com/disintegration/imaging v1.6.2/go.mod h1:44/5580QXChDfwIclfc/PCwrr44amcmDAg8hxG0Ewe4= +github.com/disintegration/imaging v1.6.3-0.20200122095911-d8633a436aab h1:UC9eDbYJ8CTo7lmekCfL92FPFV761EL/QNPmjHnXYDM= +github.com/disintegration/imaging v1.6.3-0.20200122095911-d8633a436aab/go.mod h1:44/5580QXChDfwIclfc/PCwrr44amcmDAg8hxG0Ewe4= github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk= github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E= github.com/docker/docker v27.2.0+incompatible h1:Rk9nIVdfH3+Vz4cyI/uhbINhEZ/oLmc+CBXmH6fbNk4= @@ -113,6 +117,8 @@ github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1v github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8= github.com/go-viper/mapstructure/v2 v2.2.1 h1:ZAaOCxANMuZx5RCeg0mBdEZk7DZasvvZIxtHqx8aGss= github.com/go-viper/mapstructure/v2 v2.2.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= +github.com/go-viper/mapstructure/v2 v2.3.0 h1:27XbWsHIqhbdR5TIC911OfYvgSaW93HM+dX7970Q7jk= +github.com/go-viper/mapstructure/v2 v2.3.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4= github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= github.com/gofrs/uuid/v5 v5.3.2 h1:2jfO8j3XgSwlz/wHqemAEugfnTlikAYHhnqQ8Xh4fE0= @@ -469,6 +475,8 @@ gorm.io/gorm v1.23.0/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk= gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8= gorm.io/gorm v1.30.0 h1:qbT5aPv1UH8gI99OsRlvDToLxW5zR7FzS9acZDOZcgs= gorm.io/gorm v1.30.0/go.mod h1:8Z33v652h4//uMA76KjeDH8mJXPm1QNCYrMeatR0DOE= +gorm.io/gorm v1.30.1 h1:lSHg33jJTBxs2mgJRfRZeLDG+WZaHYCk3Wtfl6Ngzo4= +gorm.io/gorm v1.30.1/go.mod h1:8Z33v652h4//uMA76KjeDH8mJXPm1QNCYrMeatR0DOE= gorm.io/plugin/dbresolver v1.6.0 h1:XvKDeOtTn1EIX6s4SrKpEH82q0gXVemhYjbYZFGFVcw= gorm.io/plugin/dbresolver v1.6.0/go.mod h1:tctw63jdrOezFR9HmrKnPkmig3m5Edem9fdxk9bQSzM= gorm.io/plugin/soft_delete v1.2.1 h1:qx9D/c4Xu6w5KT8LviX8DgLcB9hkKl6JC9f44Tj7cGU= diff --git a/internal/core/level.go b/internal/core/level.go index 527e067e..598e745a 100644 --- a/internal/core/level.go +++ b/internal/core/level.go @@ -24,4 +24,4 @@ type UserLevelService interface { // DeleteLevel 删除等级配置 DeleteLevel(level int) error -} +} \ No newline at end of file diff --git a/internal/dao/jinzhu/dbr/user.go b/internal/dao/jinzhu/dbr/user.go index b216733f..83347231 100644 --- a/internal/dao/jinzhu/dbr/user.go +++ b/internal/dao/jinzhu/dbr/user.go @@ -52,13 +52,32 @@ func (u *User) Format() *UserFormated { Avatar: u.Avatar, IsAdmin: u.IsAdmin, Experience: u.Experience, - Level: u.Level, + Level: calculateLevel(u.Experience), } } return nil } +func calculateLevel(experience int) int { + // 简单的等级计算逻辑,可根据实际需求调整 + level := 1 + if experience >= 100 { + level = 2 + } + if experience >= 500 { + level = 3 + } + if experience >= 1000 { + level = 4 + } + if experience >= 2000 { + level = 5 + } + // 可以根据需要添加更多等级 + return level +} + func (u *User) Get(db *gorm.DB) (*User, error) { var user User if u.Model != nil && u.Model.ID > 0 { diff --git a/internal/dao/jinzhu/jinzhu.go b/internal/dao/jinzhu/jinzhu.go index 0e6ea6cc..c5822614 100644 --- a/internal/dao/jinzhu/jinzhu.go +++ b/internal/dao/jinzhu/jinzhu.go @@ -42,7 +42,6 @@ type dataSrv struct { core.TrendsManageServantA core.UserManageService core.UserMetricServantA - core.UserLevelService core.ContactManageService core.FollowingManageService core.UserRelationService @@ -63,14 +62,13 @@ func NewDataService() (core.DataService, core.VersionInfo) { pvs := security.NewPhoneVerifyService() tms := newTweetMetricServentA(db) ums := newUserMetricServentA(db) - uls := newUserLevelService(db) cms := newCommentMetricServentA(db) + uls := newUserLevelService(db) cis := cache.NewEventCacheIndexSrv(tms) ds := &dataSrv{ TweetMetricServantA: tms, CommentMetricServantA: cms, UserMetricServantA: ums, - UserLevelService: uls, WalletService: newWalletService(db), MessageService: newMessageService(db), TopicService: newTopicService(db), diff --git a/internal/dao/jinzhu/user.go b/internal/dao/jinzhu/user.go index 380a01ef..f5292d8f 100644 --- a/internal/dao/jinzhu/user.go +++ b/internal/dao/jinzhu/user.go @@ -35,24 +35,24 @@ type userRelationSrv struct { func newUserManageService(db *gorm.DB, ums core.UserMetricServantA, uls core.UserLevelService) core.UserManageService { return &userManageSrv{ - db: db, - ums: ums, - uls: uls, - _userProfileJoins: fmt.Sprintf("LEFT JOIN %s m ON %s.id=m.user_id", _userMetric_, _user_), - _userProfileWhere: fmt.Sprintf("%s.username=? AND %s.is_del=0", _user_, _user_), - _userProfileColumns: []string{ - fmt.Sprintf("%s.id", _user_), - fmt.Sprintf("%s.username", _user_), - fmt.Sprintf("%s.nickname", _user_), - fmt.Sprintf("%s.phone", _user_), - fmt.Sprintf("%s.status", _user_), - fmt.Sprintf("%s.avatar", _user_), - fmt.Sprintf("%s.balance", _user_), - fmt.Sprintf("%s.is_admin", _user_), - fmt.Sprintf("%s.created_on", _user_), - "m.tweets_count", - "m.experience", - }, + db: db, + ums: ums, + uls: uls, + _userProfileJoins: fmt.Sprintf("LEFT JOIN %s m ON %s.id=m.user_id", _userMetric_, _user_), + _userProfileWhere: fmt.Sprintf("%s.username=? AND %s.is_del=0", _user_, _user_), + _userProfileColumns: []string{ + fmt.Sprintf("%s.id", _user_), + fmt.Sprintf("%s.username", _user_), + fmt.Sprintf("%s.nickname", _user_), + fmt.Sprintf("%s.phone", _user_), + fmt.Sprintf("%s.status", _user_), + fmt.Sprintf("%s.avatar", _user_), + fmt.Sprintf("%s.balance", _user_), + fmt.Sprintf("%s.is_admin", _user_), + fmt.Sprintf("%s.created_on", _user_), + "m.tweets_count", + "m.experience", + }, } } @@ -119,18 +119,6 @@ func (s *userManageSrv) UserProfileByName(username string) (res *cs.UserProfile, Where(s._userProfileWhere, username). Select(s._userProfileColumns). First(&res).Error - - if err == nil && res != nil { - // 获取用户等级 - level, err := s.uls.GetLevelByExperience(res.Experience) - if err == nil { - res.Level = level.Level - } else { - // 默认等级为1 - res.Level = 1 - } - } - return } @@ -188,7 +176,7 @@ func (s *userManageSrv) GetUsersByIDs(ids []int64) ([]*ms.User, error) { // 默认等级为1 u.Level = 1 } - } + } } return users, nil @@ -227,7 +215,7 @@ func (s *userManageSrv) GetUsersByKeyword(keyword string) ([]*ms.User, error) { // 默认等级为1 u.Level = 1 } - } + } } return users, nil diff --git a/internal/model/web/loose.go b/internal/model/web/loose.go index 4e9dae62..cebece57 100644 --- a/internal/model/web/loose.go +++ b/internal/model/web/loose.go @@ -95,6 +95,8 @@ type GetUserProfileResp struct { Follows int64 `json:"follows"` Followings int64 `json:"followings"` TweetsCount int `json:"tweets_count"` + Experience int `json:"experience"` + Level int `json:"level"` } type TopicListReq struct { diff --git a/mirc/web/v1/activities.go b/mirc/web/v1/activities.go deleted file mode 100644 index 378a3b22..00000000 --- a/mirc/web/v1/activities.go +++ /dev/null @@ -1,4 +0,0 @@ -package v1 - -type CheckInActivitity struct { -}