Initial commit

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-15 13:57:10 +08:00
co-authored by Claude Opus 5
commit 8679200f41
1897 changed files with 257900 additions and 0 deletions
+241
View File
@@ -0,0 +1,241 @@
package rankser
import (
"sync"
"time"
"91porn-server/app/appg"
"91porn-server/common"
"91porn-server/common/constant/redisconst"
"91porn-server/common/log"
"91porn-server/models/s/kwrankmod"
"91porn-server/models/s/statusermod"
"91porn-server/models/v/usermod"
)
const MaxCount = 30
type KWPage struct {
List []kwrankmod.Keyword `json:"list"`
Count int64 `json:"count"`
UpdatedAt string `json:"updatedAt"`
HasNext bool `json:"hasNext"`
}
// 热搜排行榜
func GetHotSearchList() (KWPage, error) {
keywords, err := kwrankmod.RecentRanking(MaxCount)
if err != nil {
log.Error("app service rank GetHotSearchList 1 FindHotSearchList err", log.E(err))
return KWPage{}, err
}
now := time.Now()
return KWPage{
List: keywords,
Count: int64(len(keywords)),
UpdatedAt: now.Format("2006-01-02 15:04"),
HasNext: false,
}, nil
}
type RankType = string
const (
UserInviteRankType RankType = "userInviteRank" //推广达人
UserIncomeRankType RankType = "userIncomeRank" //收益达人
UserUploadRankType RankType = "userUploadRank" //上传达人
//VideoTodayRankType RankType = "videoTodayRank" //今日排行(视频)
//VideoLikeRankType RankType = "videoLikeRank" //点赞榜
//VideoCmtRankType RankType = "videoCmtRank" //评论榜
//KeywordHotRankType RankType = "keywordHotRank" //热搜榜
)
const (
UserInviteRankMax = 50
UserIncomeRankMax = 50
UserUploadRankMax = 50
)
type RankMap = map[RankType]interface{}
func GetRankMap() (RankMap, error) {
rankMap := RankMap{}
wg := sync.WaitGroup{}
wg.Add(3)
var (
userInviteRank UserRank
userIncomeRank UserRank
userUploadRank UserRank
)
common.Go(func() {
defer wg.Done()
//收益达人
rank, err := redisUserIncomeRank()
if err != nil {
log.Warn("redisUserIncomeRank faild", log.E(err))
}
userIncomeRank = rank
})
//上传达人
common.Go(func() {
defer wg.Done()
rank, err := redisUserUploadRank()
if err != nil {
log.Warn("redisUserUploadRank faild", log.E(err))
}
userUploadRank = rank
})
wg.Wait()
rankMap[UserInviteRankType] = userInviteRank
rankMap[UserIncomeRankType] = userIncomeRank
rankMap[UserUploadRankType] = userUploadRank
return rankMap, nil
}
type UBaseInfo = usermod.BaseInfo
func getExcludedUIDMap() (map[uint64]byte, error) {
excludedUIDMap, err := usermod.GetLockedUIDMap()
if err != nil {
return nil, err
}
if appg.Static != nil {
sysUserList := appg.Static.SysUser
for _, uid := range sysUserList {
excludedUIDMap[uid] = 1
}
}
//历史遗留的区代不参加排行
oldAgents := []uint64{115057, 117557, 564993, 1384837, 1384879, 1855799}
for _, agent := range oldAgents {
excludedUIDMap[agent] = 1
}
return excludedUIDMap, nil
}
func GetUserIncomeRank() (UserRank, error) {
excludedUIDMap, err := getExcludedUIDMap()
if err != nil {
return UserRank{}, err
}
list, err := statusermod.ListByVidIncome(UserIncomeRankMax + int64(len(excludedUIDMap)))
if err != nil {
return UserRank{}, err
}
listLen := len(list)
uidList := make([]uint64, 0, listLen)
for _, v := range list {
if _, ok := excludedUIDMap[v.UID]; !ok {
uidList = append(uidList, v.UID)
}
}
if len(uidList) > UserIncomeRankMax {
uidList = uidList[:UserIncomeRankMax]
}
uInfos, err := usermod.GetUsersBaseInfo(uidList)
if err != nil {
return UserRank{}, err
}
uInfoMap := make(map[uint64]*UBaseInfo)
for _, info := range uInfos {
uInfoMap[info.UID] = info
}
updatedAt := time.Time{}
if listLen != 0 {
updatedAt = list[0].UpdatedAt
}
userList := make([]User, 0, listLen)
for _, v := range list {
uInfo, ok := uInfoMap[v.UID]
if !ok {
continue
}
userList = append(userList, User{
UID: uInfo.UID,
Name: uInfo.Name,
Portrait: uInfo.Portrait,
Value: v.Count,
})
}
rank := UserRank{
ItemList: userList,
Sort: 1,
Background: "",
UpdatedAt: updatedAt,
}
return rank, nil
}
func redisUserIncomeRank() (UserRank, error) {
redisKey := redisconst.RankKey(UserIncomeRankType)
var rank UserRank
if err := appg.Redis.Scan(redisKey, &rank); err != nil {
log.Warn("rankser redisUserIncomeRank redis Scan failed", log.E(err))
return GetUserIncomeRank()
}
return rank, nil
}
func GetUserUploadRank() (UserRank, error) {
excludedUIDMap, err := getExcludedUIDMap()
if err != nil {
return UserRank{}, err
}
list, err := statusermod.ListByUploadCount(UserUploadRankMax + int64(len(excludedUIDMap)))
if err != nil {
return UserRank{}, err
}
listLen := len(list)
uidList := make([]uint64, 0, listLen)
for _, v := range list {
if _, ok := excludedUIDMap[v.UID]; !ok {
uidList = append(uidList, v.UID)
}
}
if listLen > UserUploadRankMax {
uidList = uidList[:UserUploadRankMax]
}
uInfos, err := usermod.GetUsersBaseInfo(uidList)
if err != nil {
return UserRank{}, err
}
uInfoMap := make(map[uint64]*UBaseInfo)
for _, info := range uInfos {
uInfoMap[info.UID] = info
}
updatedAt := time.Time{}
if len(list) != 0 {
updatedAt = list[0].UpdatedAt
}
userList := make([]User, 0, listLen)
for _, v := range list {
uInfo, ok := uInfoMap[v.UID]
if !ok {
continue
}
userList = append(userList, User{
UID: uInfo.UID,
Name: uInfo.Name,
Portrait: uInfo.Portrait,
Value: v.Count,
})
}
rank := UserRank{
ItemList: userList,
Sort: 1,
Background: "",
UpdatedAt: updatedAt,
}
return rank, nil
}
func redisUserUploadRank() (UserRank, error) {
redisKey := redisconst.RankKey(UserUploadRankType)
var rank UserRank
if err := appg.Redis.Scan(redisKey, &rank); err != nil {
log.Warn("rankser redisUserUploadRank redis Scan faild", log.E(err))
return GetUserUploadRank()
}
return rank, nil
}