pull/701/head
miaowuawa 1 year ago
parent e7686d597f
commit c6c4ebb916

@ -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

@ -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=

@ -24,4 +24,4 @@ type UserLevelService interface {
// DeleteLevel 删除等级配置
DeleteLevel(level int) error
}
}

@ -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 {

@ -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),

@ -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

@ -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 {

@ -1,4 +0,0 @@
package v1
type CheckInActivitity struct {
}
Loading…
Cancel
Save