feat: 添加段位系统。

main
NorthLan 2 years ago
parent 2af5c212d3
commit bc66e55bf0

@ -2,7 +2,7 @@
chcp 65001 chcp 65001
@echo 开始代码生成 @echo 开始代码生成
set tables=user_title set tables=user_grade
set targetDir=.\model set targetDir=.\model
set templateDir=..\..\doc\template set templateDir=..\..\doc\template

@ -0,0 +1,65 @@
package model
import (
"context"
"git.noahlan.cn/northlan/ntools-go/gorm-zero/gormx"
"gorm.io/gorm"
)
var _ UserGradeModel = (*customUserGradeModel)(nil)
const (
DefaultUserGrade = 1
DefaultUserGradeLevel = 1
DefaultUserGradeStar = 0
DefaultUserGradeBravePoint = 0
MaxUserGrade = 9
MaxUserGradeLevel = 4
MaxUserGradeStar = 5
MaxUserGradeBravePoint = 3000
)
type (
// UserGradeModel is an interface to be customized, add more methods here,
// and implement the added methods in customUserGradeModel.
UserGradeModel interface {
userGradeModel
UpdateOptimistic(ctx context.Context, tx *gorm.DB, data *UserGrade) error
}
customUserGradeModel struct {
*defaultUserGradeModel
}
)
// NewUserGradeModel returns a model for the database table.
func NewUserGradeModel(conn *gorm.DB) UserGradeModel {
return &customUserGradeModel{
defaultUserGradeModel: newUserGradeModel(conn),
}
}
func (m *customUserGradeModel) UpdateOptimistic(ctx context.Context, tx *gorm.DB, data *UserGrade) error {
if data.Grade < DefaultUserGrade {
data.Grade = DefaultUserGrade
}
if data.Level < DefaultUserGradeLevel {
data.Level = DefaultUserGradeLevel
}
if data.Star < DefaultUserGradeStar {
data.Star = DefaultUserGradeStar
}
if data.BravePoint < DefaultUserGradeBravePoint {
data.BravePoint = DefaultUserGradeBravePoint
}
db := gormx.WithTx(ctx, m.DB, tx)
result := db.Model(&data).
Updates(map[string]interface{}{
"grade": data.Grade,
"level": data.Level,
"star": data.Star,
"brave_point": data.BravePoint,
})
return gormx.WrapUpdateErr(result.Error, result.RowsAffected)
}

@ -0,0 +1,92 @@
// Code generated by goctl. DO NOT EDIT!
package model
import (
"context"
"gorm.io/plugin/optimisticlock"
"strings"
"time"
"git.noahlan.cn/northlan/ntools-go/gorm-zero/gormx"
"github.com/zeromicro/go-zero/core/stores/builder"
"github.com/zeromicro/go-zero/core/stringx"
"gorm.io/gorm"
)
var (
userGradeFieldNames = builder.RawFieldNames(&UserGrade{})
userGradeRows = strings.Join(userGradeFieldNames, ",")
userGradeRowsExpectAutoSet = strings.Join(stringx.Remove(userGradeFieldNames, "`create_time`", "`update_time`"), ",")
userGradeRowsWithPlaceHolder = strings.Join(stringx.Remove(userGradeFieldNames, "`user_id`", "`create_time`", "`update_time`"), "=?,") + "=?"
)
type (
userGradeModel interface {
gormx.TxModel
Insert(ctx context.Context, tx *gorm.DB, data *UserGrade) error
FindOne(ctx context.Context, tx *gorm.DB, userId int64) (*UserGrade, error)
Update(ctx context.Context, tx *gorm.DB, data *UserGrade) error
Delete(ctx context.Context, tx *gorm.DB, userId int64) error
}
defaultUserGradeModel struct {
gormx.GormConn
table string
}
UserGrade struct {
UserId int64 `gorm:"column:user_id;primaryKey"` // 用户ID
Grade int64 `gorm:"column:grade"` // 段位
Level int64 `gorm:"column:level"` // 段位等级
Star int64 `gorm:"column:star"` // 等级星级
BravePoint int64 `gorm:"column:brave_point"` // 骁勇分
Version optimisticlock.Version `gorm:"column:version"` // 乐观锁
CreateTime time.Time `gorm:"column:create_time;default:null"` // 创建时间
UpdateTime time.Time `gorm:"column:update_time;default:null"` // 更新时间
}
)
var UserGradeTableName = "`user_grade`"
func newUserGradeModel(conn *gorm.DB) *defaultUserGradeModel {
return &defaultUserGradeModel{
GormConn: gormx.NewConn(conn),
table: UserGradeTableName,
}
}
func (m *defaultUserGradeModel) Insert(ctx context.Context, tx *gorm.DB, data *UserGrade) error {
err := gormx.WithTx(ctx, m.DB, tx).Create(&data).Error
return err
}
func (m *defaultUserGradeModel) FindOne(ctx context.Context, tx *gorm.DB, userId int64) (*UserGrade, error) {
var resp UserGrade
err := gormx.WithTx(ctx, m.DB, tx).Model(&UserGrade{}).Where("`user_id` = ?", userId).Take(&resp).Error
if err = gormx.WrapSelectErr(err); err != nil {
return nil, err
}
return &resp, nil
}
func (m *defaultUserGradeModel) Update(ctx context.Context, tx *gorm.DB, data *UserGrade) error {
result := gormx.WithTx(ctx, m.DB, tx).Save(data)
return gormx.WrapUpdateErr(result.Error, result.RowsAffected)
}
func (m *defaultUserGradeModel) Delete(ctx context.Context, tx *gorm.DB, userId int64) error {
err := gormx.WithTx(ctx, m.DB, tx).Delete(&UserGrade{}, userId).Error
return err
}
func (m *defaultUserGradeModel) tableName() string {
return m.table
}
func (UserGrade) TableName() string {
return UserGradeTableName
}

@ -20,7 +20,7 @@ Kafka:
Topic: "notify-user-coin-dev" Topic: "notify-user-coin-dev"
RankUpdate: RankUpdate:
Addr: [ "127.0.0.1:9093" ] Addr: [ "127.0.0.1:9093" ]
Topic: "rank-update-dev" Topic: "grade-update-dev"
RewardPool: RewardPool:
Addr: [ "127.0.0.1:9093" ] Addr: [ "127.0.0.1:9093" ]
Topic: "rewardPool-dev" Topic: "rewardPool-dev"
@ -37,7 +37,7 @@ UserRetriever:
RoomShortInfoApi: https://api.live.bilibili.com/room/v1/Room/room_init RoomShortInfoApi: https://api.live.bilibili.com/room/v1/Room/room_init
TopListApi: https://api.live.bilibili.com/guard/topList TopListApi: https://api.live.bilibili.com/guard/topList
Rank: Rank:
Enabled: true Enabled: false
Cron: Cron:
Update: "@every 10s" # 10s一次 Update: "@every 10s" # 10s一次
Persistence: "@every 10m" # 10min一次 Persistence: "@every 10m" # 10min一次
@ -87,7 +87,7 @@ Coin:
# 签到 一周 0(周日) 1 2 3 4 5 6 # 签到 一周 0(周日) 1 2 3 4 5 6
Points: [ 60,10,15,20,25,30,50 ] Points: [ 60,10,15,20,25,30,50 ]
Critical: 0.08 # 签到暴击率 Critical: 0.08 # 签到暴击率
CriticalRadio: [ 1.2, 1.3, 1.5 ] # 暴击倍率 CriticalRadio: [ 1.2, 1.3, 1.5, 1.8 ] # 暴击倍率
# RMB到弹币的转换 # RMB到弹币的转换
RMBToCoin: 10 RMBToCoin: 10
# 平台礼物到RMB的转换 # 平台礼物到RMB的转换
@ -96,8 +96,13 @@ Coin:
# 平台免费礼物到弹币的转换 # 平台免费礼物到弹币的转换
FreeToCoin: FreeToCoin:
bilibili: 0.01 # 价值1毛 bilibili: 0.01 # 价值1毛
Grade:
BravePointCost: [0,300,320,350,400,450,500,600,800,1000]
MaxBravePoint: 3000
WinScoreThreshold: 32
MinUserCount: 8
Elite: Elite:
LiveDict: { "1": "0", "2": "1001", "3": "1002" } LiveDict: { "1": "0", "2": "1001", "3": "1002", "4": "1003" }
DefaultId: 0 DefaultId: 0
Items: Items:
- Id: 1001 - Id: 1001
@ -108,6 +113,10 @@ Elite:
Sort: 3 Sort: 3
PriceDay: 60 PriceDay: 60
PriceForever: 18888 PriceForever: 18888
- Id: 1003
Sort: 4
PriceDay: 65
PriceForever: 18888
Title: Title:
LiveDict: { "1": "2000" } LiveDict: { "1": "2000" }
Items: Items:
@ -132,29 +141,32 @@ Title:
- Id: 6 - Id: 6
Name: 群萌新 Name: 群萌新
Type: custom Type: custom
- Id: 7
Name: 白马义从
Type: custom
- Id: 1000 - Id: 1000
Name: 军神 # 名将榜首 Name: 军神 # 名将榜首
Type: rank Type: grade
RankType: 3 RankType: 3
- Id: 1001 - Id: 1001
Name: 人屠 # 小兵击杀榜首 Name: 人屠 # 小兵击杀榜首
Type: rank Type: grade
RankType: 5 RankType: 5
- Id: 1002 - Id: 1002
Name: 破营 # 拆迁榜首 Name: 破营 # 拆迁榜首
Type: rank Type: grade
RankType: 7 RankType: 7
- Id: 1003 - Id: 1003
Name: 不败 # 常胜榜首 Name: 不败 # 常胜榜首
Type: rank Type: grade
RankType: 9 RankType: 9
- Id: 1004 - Id: 1004
Name: 勇冠三军 # 一血榜首 Name: 勇冠三军 # 一血榜首
Type: rank Type: grade
RankType: 11 RankType: 11
- Id: 1005 - Id: 1005
Name: 求放过 # 被一血榜首 Name: 求放过 # 被一血榜首
Type: rank Type: grade
RankType: 12 RankType: 12
- Id: 2000 - Id: 2000
Name: 无用之人 Name: 无用之人

@ -21,7 +21,7 @@ Kafka:
Topic: "notify-user-coin" Topic: "notify-user-coin"
RankUpdate: RankUpdate:
Addr: [ "127.0.0.1:9093" ] Addr: [ "127.0.0.1:9093" ]
Topic: "rank-update" Topic: "grade-update"
RewardPool: RewardPool:
Addr: [ "127.0.0.1:9093" ] Addr: [ "127.0.0.1:9093" ]
Topic: "rewardPool" Topic: "rewardPool"
@ -135,27 +135,27 @@ Title:
Type: custom Type: custom
- Id: 1000 - Id: 1000
Name: 军神 # 名将榜首 Name: 军神 # 名将榜首
Type: rank Type: grade
RankType: 3 RankType: 3
- Id: 1001 - Id: 1001
Name: 人屠 # 小兵击杀榜首 Name: 人屠 # 小兵击杀榜首
Type: rank Type: grade
RankType: 5 RankType: 5
- Id: 1002 - Id: 1002
Name: 破营 # 拆迁榜首 Name: 破营 # 拆迁榜首
Type: rank Type: grade
RankType: 7 RankType: 7
- Id: 1003 - Id: 1003
Name: 不败 # 常胜榜首 Name: 不败 # 常胜榜首
Type: rank Type: grade
RankType: 9 RankType: 9
- Id: 1004 - Id: 1004
Name: 勇冠三军 # 一血榜首 Name: 勇冠三军 # 一血榜首
Type: rank Type: grade
RankType: 11 RankType: 11
- Id: 1005 - Id: 1005
Name: 求放过 # 被一血榜首 Name: 求放过 # 被一血榜首
Type: rank Type: grade
RankType: 12 RankType: 12
- Id: 2000 - Id: 2000
Name: 无用之人 Name: 无用之人

@ -0,0 +1,253 @@
package grade
import (
"context"
"git.noahlan.cn/northlan/ntools-go/gorm-zero/gormx"
"github.com/pkg/errors"
"gorm.io/gorm"
"live-service/app/user_center/model"
"live-service/app/user_center/rpc/internal/config"
"live-service/app/user_center/rpc/pb"
)
// Manager 排位管理器
// 段/二级星/星等级(5) 二级段顶级后开始晋级赛1次获胜后升段。
// 战斗积分(累计),抵扣掉段,每个大段抵扣值不同。
// 获胜+星,失败-星
type (
Manager struct {
config *config.GameConfig
userGradeModel model.UserGradeModel
}
ReportReq struct {
UserId int64
Username string
Position int32
Score float32
}
ReportResp struct {
ReportReq
*pb.Grade
Result pb.StatPvPReportResp_GradeResult
Reason pb.StatPvPReportResp_GradeReason
}
)
func NewUserGradeManager(config *config.GameConfig, userGradeModel model.UserGradeModel) *Manager {
return &Manager{
config: config,
userGradeModel: userGradeModel,
}
}
// QueryUser 查询用户段位
func (m *Manager) QueryUser(ctx context.Context, userId int64) (*model.UserGrade, error) {
var resp *model.UserGrade
if err := m.userGradeModel.TransactCtx(ctx, nil, func(tx *gorm.DB) error {
dbModel, err := m.userGradeModel.FindOne(ctx, nil, userId)
if err != nil {
if errors.Is(err, gormx.ErrNotFound) {
dbModel = &model.UserGrade{
UserId: userId,
Grade: model.DefaultUserGrade,
Level: model.DefaultUserGradeLevel,
Star: model.DefaultUserGradeStar,
BravePoint: 0,
}
if err = m.userGradeModel.Insert(ctx, tx, dbModel); err != nil {
return err
}
resp = dbModel
}
return err
}
resp = dbModel
return nil
}); err != nil {
return nil, err
}
return resp, nil
}
// Report 战斗记录
func (m *Manager) Report(ctx context.Context, winItems, lostItems []ReportReq) ([]ReportResp, error) {
// 1. 查询现有段位信息
// 2. 计算段位结果
// 3. 更新并返回
userCountSatisfied := len(winItems)+len(lostItems) >= m.config.Grade.MinUserCount
resp := make([]ReportResp, 0, len(winItems)+len(lostItems))
if err := m.userGradeModel.TransactCtx(ctx, nil, func(tx *gorm.DB) error {
for _, item := range winItems {
if itemResp, err := m.reportItem(ctx, tx, item, true, userCountSatisfied); err != nil {
return err
} else {
resp = append(resp, *itemResp)
}
}
for _, item := range lostItems {
if itemResp, err := m.reportItem(ctx, tx, item, false, userCountSatisfied); err != nil {
return err
} else {
resp = append(resp, *itemResp)
}
}
return nil
}); err != nil {
return nil, err
}
return resp, nil
}
func (m *Manager) reportItem(ctx context.Context, tx *gorm.DB, item ReportReq, win bool, userCountSatisfied bool) (*ReportResp, error) {
var resp *ReportResp
dbModel, err := m.userGradeModel.FindOne(ctx, tx, item.UserId)
if err != nil {
if !errors.Is(err, gormx.ErrNotFound) {
return nil, err
}
}
if dbModel == nil {
// insert
dbModel = &model.UserGrade{
UserId: item.UserId,
}
grade, result, reason := m.calcRank(win, userCountSatisfied,
model.DefaultUserGrade,
model.DefaultUserGradeLevel,
model.DefaultUserGradeStar,
0,
item.Score)
dbModel.Grade = int64(grade.Grade)
dbModel.Level = int64(grade.Level)
dbModel.Star = int64(grade.Star)
dbModel.BravePoint = grade.BravePoint
if err = m.userGradeModel.Insert(ctx, tx, dbModel); err != nil {
return nil, err
}
resp = &ReportResp{
ReportReq: ReportReq{
UserId: dbModel.UserId,
Username: item.Username,
Position: item.Position,
Score: item.Score,
},
Grade: &grade,
Result: result,
Reason: reason,
}
return resp, nil
}
grade, result, reason := m.calcRank(win, userCountSatisfied,
dbModel.Grade,
dbModel.Level,
dbModel.Star,
dbModel.BravePoint,
item.Score)
dbModel.Grade = int64(grade.Grade)
dbModel.Level = int64(grade.Level)
dbModel.Star = int64(grade.Star)
dbModel.BravePoint = grade.BravePoint
if err = m.userGradeModel.UpdateOptimistic(ctx, tx, dbModel); err != nil {
return nil, err
}
resp = &ReportResp{
ReportReq: ReportReq{
UserId: dbModel.UserId,
Username: item.Username,
Position: item.Position,
Score: item.Score,
},
Grade: &grade,
Result: result,
Reason: reason,
}
return resp, nil
}
func (m *Manager) calcRank(win bool, userCountSatisfied bool, grade, level, star, bravePoint int64, score float32) (g pb.Grade, result pb.StatPvPReportResp_GradeResult, reason pb.StatPvPReportResp_GradeReason) {
g.Grade = int32(grade)
g.Level = int32(level)
g.Star = int32(star)
g.BravePoint = bravePoint + int64(score)
if g.BravePoint > m.config.Grade.MaxBravePoint {
g.BravePoint = m.config.Grade.MaxBravePoint
}
if score < m.config.Grade.WinScoreThreshold {
result = pb.StatPvPReportResp_Keep
reason = pb.StatPvPReportResp_Win
return
}
if !userCountSatisfied {
result = pb.StatPvPReportResp_Keep
reason = pb.StatPvPReportResp_Win
return
}
if win {
reason = pb.StatPvPReportResp_Win // 获胜
if grade != model.MaxUserGrade || level != model.MaxUserGradeLevel-1 || star != model.MaxUserGradeStar {
// 非最高段位
if star == model.MaxUserGradeStar {
g.Star = model.DefaultUserGradeStar
if level == model.MaxUserGradeLevel {
g.Level = model.DefaultUserGradeLevel
// grade
if grade == model.MaxUserGrade {
g.Grade = int32(grade)
result = pb.StatPvPReportResp_Keep
} else {
g.Grade = int32(grade + 1)
result = pb.StatPvPReportResp_GradeUp
}
} else {
g.Level = int32(level + 1)
result = pb.StatPvPReportResp_LevelUp
}
} else {
g.Star = int32(star + 1)
result = pb.StatPvPReportResp_StarUp // 升星
}
}
} else {
// 段位的骁勇分减扣规则
bravePointCost := m.config.Grade.BravePointCost[grade]
if bravePoint >= bravePointCost {
g.Grade = int32(grade)
g.Level = int32(level)
g.Star = int32(star)
g.BravePoint = bravePoint - bravePointCost
if g.BravePoint < 0 {
g.BravePoint = 0
}
reason = pb.StatPvPReportResp_BravePoint
result = pb.StatPvPReportResp_Keep
return
}
reason = pb.StatPvPReportResp_Lost
if star != model.DefaultUserGradeStar || level != model.DefaultUserGradeLevel || grade != model.DefaultUserGrade {
if star == model.DefaultUserGradeStar {
g.Star = model.MaxUserGradeStar - 1 // 掉小段或掉大段,星星变 max-1
if level == model.DefaultUserGradeLevel {
g.Level = model.MaxUserGradeLevel
if grade == model.DefaultUserGrade {
g.Grade = model.DefaultUserGrade
result = pb.StatPvPReportResp_Keep
} else {
g.Grade = int32(grade - 1)
result = pb.StatPvPReportResp_GradeDown
}
} else {
g.Level = int32(level - 1)
result = pb.StatPvPReportResp_LevelDown
}
} else {
g.Star = int32(star - 1)
result = pb.StatPvPReportResp_StarDown
}
}
}
g.BravePoint = bravePoint + int64(score)
if g.BravePoint > m.config.Grade.MaxBravePoint {
g.BravePoint = m.config.Grade.MaxBravePoint
}
return
}

@ -99,6 +99,13 @@ type (
GiftToRMB map[string]float64 // 平台礼物到RMB的转换 GiftToRMB map[string]float64 // 平台礼物到RMB的转换
FreeToCoin map[string]float64 // 平台免费礼物到弹币的转换 FreeToCoin map[string]float64 // 平台免费礼物到弹币的转换
} }
// 段位
Grade struct {
BravePointCost []int64 // 骁勇分抵扣规则对于grade等级
MaxBravePoint int64 // 最大骁勇分
WinScoreThreshold float32 // 获胜升段分数阈值
MinUserCount int // 最小段位计算用户量
}
// 精英单位 // 精英单位
Elite Elite Elite Elite
// 称号 // 称号

@ -8,6 +8,7 @@ import (
"github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/core/logx"
"gorm.io/gorm" "gorm.io/gorm"
"live-service/app/user_center/model" "live-service/app/user_center/model"
"live-service/app/user_center/rpc/internal/common/grade"
"live-service/app/user_center/rpc/internal/svc" "live-service/app/user_center/rpc/internal/svc"
"live-service/app/user_center/rpc/pb" "live-service/app/user_center/rpc/pb"
"sort" "sort"
@ -82,6 +83,46 @@ func (l *StatPvpReportLogic) StatPvpReport(in *pb.StatPvPReportReq) (*pb.StatPvP
l.Logger.Errorf("战败PvP记录失败, err:%+v", err) l.Logger.Errorf("战败PvP记录失败, err:%+v", err)
} }
// 4. 段位
winGradeItems := make([]grade.ReportReq, 0, len(winItems))
lostGradeItems := make([]grade.ReportReq, 0, len(lostItems))
for _, item := range winItems {
winGradeItems = append(winGradeItems, grade.ReportReq{
UserId: item.uid,
Username: item.uname,
Position: item.respItem.Position,
Score: item.respItem.Score,
})
}
for _, item := range lostItems {
lostGradeItems = append(lostGradeItems, grade.ReportReq{
UserId: item.uid,
Username: item.uname,
Position: item.respItem.Position,
Score: item.respItem.Score,
})
}
if gradeReported, err := l.svcCtx.GradeManager.Report(l.ctx, winGradeItems, lostGradeItems); err != nil {
l.Logger.Errorf("计算段位时发生错误", err)
} else {
for _, reportResp := range gradeReported {
for _, item := range winItems {
if item.uid == reportResp.UserId {
item.respItem.Grade = reportResp.Grade
item.respItem.GradeResult = reportResp.Result
item.respItem.GradeReason = reportResp.Reason
}
}
for _, item := range lostItems {
if item.uid == reportResp.UserId {
item.respItem.Grade = reportResp.Grade
item.respItem.GradeResult = reportResp.Result
item.respItem.GradeReason = reportResp.Reason
}
}
}
}
// resp // resp
resp.WinItems = make([]*pb.StatPvPReportResp_Item, 0, len(winItems)) resp.WinItems = make([]*pb.StatPvPReportResp_Item, 0, len(winItems))
resp.LostItems = make([]*pb.StatPvPReportResp_Item, 0, len(lostItems)) resp.LostItems = make([]*pb.StatPvPReportResp_Item, 0, len(lostItems))
@ -126,6 +167,7 @@ func (l *StatPvpReportLogic) calcScoreResponse(sum sumType, items []*statPvPRepo
Uid: item.uid, Uid: item.uid,
Uname: item.uname, Uname: item.uname,
Score: 0, Score: 0,
Grade: &pb.Grade{},
} }
var tmpScore float64 var tmpScore float64
if sum.damage != 0 { if sum.damage != 0 {
@ -182,7 +224,7 @@ func (l *StatPvpReportLogic) calcScoreResponse(sum sumType, items []*statPvPRepo
itemResp.Score = 0 itemResp.Score = 0
} }
// 最终进行四舍五入 // 最终进行四舍五入
tmp, _ := decimal.NewFromFloat32(itemResp.Score).Round(1).Float64() tmp, _ := decimal.NewFromFloat32(itemResp.Score).Round(0).Float64()
itemResp.Score = float32(tmp) itemResp.Score = float32(tmp)
item.respItem = itemResp item.respItem = itemResp

@ -0,0 +1,44 @@
package user
import (
"context"
"github.com/pkg/errors"
"live-service/common/nerr"
"live-service/app/user_center/rpc/internal/svc"
"live-service/app/user_center/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type GetUserGradeLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetUserGradeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserGradeLogic {
return &GetUserGradeLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// @ZeroGroup: grade
func (l *GetUserGradeLogic) GetUserGrade(in *pb.UserIdReq) (*pb.UserGradeResp, error) {
gradeResp, err := l.svcCtx.GradeManager.QueryUser(l.ctx, in.UserId)
if err != nil {
return nil, errors.Wrapf(nerr.NewWithErr(err), "获取用户段位信息失败, err:%v", err)
}
return &pb.UserGradeResp{
UserId: in.UserId,
Grade: &pb.Grade{
Grade: int32(gradeResp.Grade),
Level: int32(gradeResp.Level),
Star: int32(gradeResp.Star),
BravePoint: gradeResp.BravePoint,
},
}, nil
}

@ -74,7 +74,10 @@ func (l *RetrievePlatformUserLogic) RetrievePlatformUser(in *pb.PlatformUserReq)
return nerr.NewWithCode(nerr.DBError) return nerr.NewWithCode(nerr.DBError)
} }
displayUser = &model.UserForDisplay{ displayUser = &model.UserForDisplay{
Id: dbPlatformUser.Id,
UserId: newId, UserId: newId,
PUname: in.PUname,
PAvatar: in.PAvatar,
} }
return nil return nil
}); err != nil { }); err != nil {

@ -7,7 +7,6 @@ import (
"context" "context"
"live-service/app/user_center/rpc/internal/logic/coin" "live-service/app/user_center/rpc/internal/logic/coin"
"live-service/app/user_center/rpc/internal/logic/gift" "live-service/app/user_center/rpc/internal/logic/gift"
"live-service/app/user_center/rpc/internal/logic/rank"
"live-service/app/user_center/rpc/internal/logic/statistics" "live-service/app/user_center/rpc/internal/logic/statistics"
"live-service/app/user_center/rpc/internal/logic/user" "live-service/app/user_center/rpc/internal/logic/user"
"live-service/app/user_center/rpc/internal/logic/zhg" "live-service/app/user_center/rpc/internal/logic/zhg"
@ -90,19 +89,25 @@ func (s *UserCenterServer) DrawGiftPack(ctx context.Context, in *pb.DrawGiftPack
return l.DrawGiftPack(in) return l.DrawGiftPack(in)
} }
// @ZeroGroup: grade
func (s *UserCenterServer) GetUserGrade(ctx context.Context, in *pb.UserIdReq) (*pb.UserGradeResp, error) {
l := user.NewGetUserGradeLogic(ctx, s.svcCtx)
return l.GetUserGrade(in)
}
// rankPvp pvp排行 // rankPvp pvp排行
func (s *UserCenterServer) RankPvp(ctx context.Context, in *pb.RankPvpReq) (*pb.RankPvpResp, error) { func (s *UserCenterServer) RankPvp(ctx context.Context, in *pb.RankPvpReq) (*pb.RankPvpResp, error) {
l := rank.NewRankPvpLogic(ctx, s.svcCtx) l := statistics.NewRankPvpLogic(ctx, s.svcCtx)
return l.RankPvp(in) return l.RankPvp(in)
} }
func (s *UserCenterServer) RankPvpSubmit(ctx context.Context, in *pb.RankPvpSubmitReq) (*pb.RankPvpSubmitResp, error) { func (s *UserCenterServer) RankPvpSubmit(ctx context.Context, in *pb.RankPvpSubmitReq) (*pb.RankPvpSubmitResp, error) {
l := rank.NewRankPvpSubmitLogic(ctx, s.svcCtx) l := statistics.NewRankPvpSubmitLogic(ctx, s.svcCtx)
return l.RankPvpSubmit(in) return l.RankPvpSubmit(in)
} }
func (s *UserCenterServer) UserRankPvp(ctx context.Context, in *pb.UserRankReq) (*pb.UserRankResp, error) { func (s *UserCenterServer) UserRankPvp(ctx context.Context, in *pb.UserRankReq) (*pb.UserRankResp, error) {
l := rank.NewUserRankPvpLogic(ctx, s.svcCtx) l := statistics.NewUserRankPvpLogic(ctx, s.svcCtx)
return l.UserRankPvp(in) return l.UserRankPvp(in)
} }

@ -6,6 +6,7 @@ import (
"gorm.io/gorm/logger" "gorm.io/gorm/logger"
"live-service/app/user_center/model" "live-service/app/user_center/model"
"live-service/app/user_center/rpc/internal/common/coin_manager" "live-service/app/user_center/rpc/internal/common/coin_manager"
"live-service/app/user_center/rpc/internal/common/grade"
"live-service/app/user_center/rpc/internal/config" "live-service/app/user_center/rpc/internal/config"
"live-service/app/user_center/rpc/internal/mq" "live-service/app/user_center/rpc/internal/mq"
"log" "log"
@ -25,6 +26,7 @@ type ServiceContext struct {
UserCoinModel model.UserCoinModel UserCoinModel model.UserCoinModel
UserNobilityModel model.UserNobilityModel UserNobilityModel model.UserNobilityModel
UserCheckInModel model.UserCheckInModel UserCheckInModel model.UserCheckInModel
UserGradeModel model.UserGradeModel
UserEliteModel model.UserEliteModel UserEliteModel model.UserEliteModel
UserTitleModel model.UserTitleModel UserTitleModel model.UserTitleModel
@ -40,6 +42,7 @@ type ServiceContext struct {
//RewardPoolManager *reward_pool.PoolManager //RewardPoolManager *reward_pool.PoolManager
CoinManager *coin_manager.Manager CoinManager *coin_manager.Manager
GradeManager *grade.Manager
} }
func NewServiceContext(c *config.Config, cg *config.GameConfig) *ServiceContext { func NewServiceContext(c *config.Config, cg *config.GameConfig) *ServiceContext {
@ -66,10 +69,10 @@ func NewServiceContext(c *config.Config, cg *config.GameConfig) *ServiceContext
userPlatformModel := model.NewUserPlatformModel(gormDb) userPlatformModel := model.NewUserPlatformModel(gormDb)
userIntegralModel := model.NewUserIntegralModel(gormDb) userIntegralModel := model.NewUserIntegralModel(gormDb)
userCoinModel := model.NewUserCoinModel(gormDb) userCoinModel := model.NewUserCoinModel(gormDb)
userGradeModel := model.NewUserGradeModel(gormDb)
userMq := mq.NewUserMq(userPlatformModel, c.Kafka) userMq := mq.NewUserMq(userPlatformModel, c.Kafka)
rewardPoolMq := mq.NewRewardPoolMq(c.Kafka) rewardPoolMq := mq.NewRewardPoolMq(c.Kafka)
//rewardPoolManager := reward_pool.NewRewardPoolManager( //rewardPoolManager := reward_pool.NewRewardPoolManager(
// c.Integral.RewardPool.InitReward, // c.Integral.RewardPool.InitReward,
// reward_pool.Ratio{ // reward_pool.Ratio{
@ -93,6 +96,7 @@ func NewServiceContext(c *config.Config, cg *config.GameConfig) *ServiceContext
UserCoinModel: userCoinModel, UserCoinModel: userCoinModel,
UserNobilityModel: model.NewUserNobilityModel(gormDb), UserNobilityModel: model.NewUserNobilityModel(gormDb),
UserCheckInModel: model.NewUserCheckInModel(gormDb), UserCheckInModel: model.NewUserCheckInModel(gormDb),
UserGradeModel: userGradeModel,
UserEliteModel: model.NewUserEliteModel(gormDb), UserEliteModel: model.NewUserEliteModel(gormDb),
UserTitleModel: model.NewUserTitleModel(gormDb), UserTitleModel: model.NewUserTitleModel(gormDb),
@ -106,5 +110,6 @@ func NewServiceContext(c *config.Config, cg *config.GameConfig) *ServiceContext
//RewardPoolManager: rewardPoolManager, //RewardPoolManager: rewardPoolManager,
CoinManager: coin_manager.NewCoinManager(userCoinModel, userMq), CoinManager: coin_manager.NewCoinManager(userCoinModel, userMq),
GradeManager: grade.NewUserGradeManager(cg, userGradeModel),
} }
} }

File diff suppressed because it is too large Load Diff

@ -139,6 +139,18 @@ message UserBuyNobilityReq {
int64 endTime = 12; // int64 endTime = 12; //
} }
message Grade {
int32 grade = 1; //
int32 level = 2; //
int32 star = 3; //
int64 bravePoint = 4; // ()
}
message UserGradeResp {
int64 userId = 1;
Grade grade = 2;
}
// -PvP statistics.pvp.report // -PvP statistics.pvp.report
message StatPvPReportReq { message StatPvPReportReq {
message Item { message Item {
@ -162,11 +174,29 @@ message StatPvPReportReq {
// -PvP // -PvP
message StatPvPReportResp { message StatPvPReportResp {
enum GradeResult {
Keep = 0; // ()
GradeUp = 1; //
LevelUp = 2; //
StarUp = 3; //
GradeDown = 4; //
LevelDown = 5; //
StarDown = 6; //
}
enum GradeReason {
Win = 0; //
Lost = 1; //
BravePoint = 2; //
}
message Item { message Item {
int64 uid = 1; // ID int64 uid = 1; // ID
string uname = 2; // string uname = 2; //
int32 position = 3; // int32 position = 3; //
float score = 4; // float score = 4; //
// grade
Grade grade = 5;
GradeResult gradeResult = 6; //
GradeReason gradeReason = 7; //
} }
int32 winCamp = 1; // 1- 2- int32 winCamp = 1; // 1- 2-
int64 battleId = 2; // ID int64 battleId = 2; // ID
@ -359,6 +389,9 @@ service userCenter {
// rpc increaseWelfare(IncreaseWelfareReq) returns (Empty); // rpc increaseWelfare(IncreaseWelfareReq) returns (Empty);
/// @ZeroGroup: grade
rpc getUserGrade(UserIdReq) returns (UserGradeResp);
/// @ZeroGroup: rank /// @ZeroGroup: rank
// rankPvp pvp // rankPvp pvp

@ -41,6 +41,8 @@ type UserCenterClient interface {
UserBuyNobility(ctx context.Context, in *UserBuyNobilityReq, opts ...grpc.CallOption) (*Empty, error) UserBuyNobility(ctx context.Context, in *UserBuyNobilityReq, opts ...grpc.CallOption) (*Empty, error)
StatPvpReport(ctx context.Context, in *StatPvPReportReq, opts ...grpc.CallOption) (*StatPvPReportResp, error) StatPvpReport(ctx context.Context, in *StatPvPReportReq, opts ...grpc.CallOption) (*StatPvPReportResp, error)
DrawGiftPack(ctx context.Context, in *DrawGiftPackReq, opts ...grpc.CallOption) (*DrawGiftPackResp, error) DrawGiftPack(ctx context.Context, in *DrawGiftPackReq, opts ...grpc.CallOption) (*DrawGiftPackResp, error)
/// @ZeroGroup: grade
GetUserGrade(ctx context.Context, in *UserIdReq, opts ...grpc.CallOption) (*UserGradeResp, error)
// rankPvp pvp排行 // rankPvp pvp排行
RankPvp(ctx context.Context, in *RankPvpReq, opts ...grpc.CallOption) (*RankPvpResp, error) RankPvp(ctx context.Context, in *RankPvpReq, opts ...grpc.CallOption) (*RankPvpResp, error)
RankPvpSubmit(ctx context.Context, in *RankPvpSubmitReq, opts ...grpc.CallOption) (*RankPvpSubmitResp, error) RankPvpSubmit(ctx context.Context, in *RankPvpSubmitReq, opts ...grpc.CallOption) (*RankPvpSubmitResp, error)
@ -160,6 +162,15 @@ func (c *userCenterClient) DrawGiftPack(ctx context.Context, in *DrawGiftPackReq
return out, nil return out, nil
} }
func (c *userCenterClient) GetUserGrade(ctx context.Context, in *UserIdReq, opts ...grpc.CallOption) (*UserGradeResp, error) {
out := new(UserGradeResp)
err := c.cc.Invoke(ctx, "/pb.userCenter/getUserGrade", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *userCenterClient) RankPvp(ctx context.Context, in *RankPvpReq, opts ...grpc.CallOption) (*RankPvpResp, error) { func (c *userCenterClient) RankPvp(ctx context.Context, in *RankPvpReq, opts ...grpc.CallOption) (*RankPvpResp, error) {
out := new(RankPvpResp) out := new(RankPvpResp)
err := c.cc.Invoke(ctx, "/pb.userCenter/rankPvp", in, out, opts...) err := c.cc.Invoke(ctx, "/pb.userCenter/rankPvp", in, out, opts...)
@ -264,6 +275,8 @@ type UserCenterServer interface {
UserBuyNobility(context.Context, *UserBuyNobilityReq) (*Empty, error) UserBuyNobility(context.Context, *UserBuyNobilityReq) (*Empty, error)
StatPvpReport(context.Context, *StatPvPReportReq) (*StatPvPReportResp, error) StatPvpReport(context.Context, *StatPvPReportReq) (*StatPvPReportResp, error)
DrawGiftPack(context.Context, *DrawGiftPackReq) (*DrawGiftPackResp, error) DrawGiftPack(context.Context, *DrawGiftPackReq) (*DrawGiftPackResp, error)
/// @ZeroGroup: grade
GetUserGrade(context.Context, *UserIdReq) (*UserGradeResp, error)
// rankPvp pvp排行 // rankPvp pvp排行
RankPvp(context.Context, *RankPvpReq) (*RankPvpResp, error) RankPvp(context.Context, *RankPvpReq) (*RankPvpResp, error)
RankPvpSubmit(context.Context, *RankPvpSubmitReq) (*RankPvpSubmitResp, error) RankPvpSubmit(context.Context, *RankPvpSubmitReq) (*RankPvpSubmitResp, error)
@ -314,6 +327,9 @@ func (UnimplementedUserCenterServer) StatPvpReport(context.Context, *StatPvPRepo
func (UnimplementedUserCenterServer) DrawGiftPack(context.Context, *DrawGiftPackReq) (*DrawGiftPackResp, error) { func (UnimplementedUserCenterServer) DrawGiftPack(context.Context, *DrawGiftPackReq) (*DrawGiftPackResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method DrawGiftPack not implemented") return nil, status.Errorf(codes.Unimplemented, "method DrawGiftPack not implemented")
} }
func (UnimplementedUserCenterServer) GetUserGrade(context.Context, *UserIdReq) (*UserGradeResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetUserGrade not implemented")
}
func (UnimplementedUserCenterServer) RankPvp(context.Context, *RankPvpReq) (*RankPvpResp, error) { func (UnimplementedUserCenterServer) RankPvp(context.Context, *RankPvpReq) (*RankPvpResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method RankPvp not implemented") return nil, status.Errorf(codes.Unimplemented, "method RankPvp not implemented")
} }
@ -552,6 +568,24 @@ func _UserCenter_DrawGiftPack_Handler(srv interface{}, ctx context.Context, dec
return interceptor(ctx, in, info, handler) return interceptor(ctx, in, info, handler)
} }
func _UserCenter_GetUserGrade_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UserIdReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(UserCenterServer).GetUserGrade(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/pb.userCenter/getUserGrade",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(UserCenterServer).GetUserGrade(ctx, req.(*UserIdReq))
}
return interceptor(ctx, in, info, handler)
}
func _UserCenter_RankPvp_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { func _UserCenter_RankPvp_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(RankPvpReq) in := new(RankPvpReq)
if err := dec(in); err != nil { if err := dec(in); err != nil {
@ -765,6 +799,10 @@ var UserCenter_ServiceDesc = grpc.ServiceDesc{
MethodName: "drawGiftPack", MethodName: "drawGiftPack",
Handler: _UserCenter_DrawGiftPack_Handler, Handler: _UserCenter_DrawGiftPack_Handler,
}, },
{
MethodName: "getUserGrade",
Handler: _UserCenter_GetUserGrade_Handler,
},
{ {
MethodName: "rankPvp", MethodName: "rankPvp",
Handler: _UserCenter_RankPvp_Handler, Handler: _UserCenter_RankPvp_Handler,

@ -7,7 +7,7 @@ import (
"live-service/app/user_center/rpc/internal/config" "live-service/app/user_center/rpc/internal/config"
"live-service/app/user_center/rpc/internal/logic/gift_collect" "live-service/app/user_center/rpc/internal/logic/gift_collect"
"live-service/app/user_center/rpc/internal/logic/platform_user" "live-service/app/user_center/rpc/internal/logic/platform_user"
"live-service/app/user_center/rpc/internal/logic/rank" "live-service/app/user_center/rpc/internal/logic/statistics"
"live-service/app/user_center/rpc/internal/server" "live-service/app/user_center/rpc/internal/server"
"live-service/app/user_center/rpc/internal/svc" "live-service/app/user_center/rpc/internal/svc"
"live-service/app/user_center/rpc/pb" "live-service/app/user_center/rpc/pb"
@ -34,7 +34,7 @@ func main() {
svr := server.NewUserCenterServer(ctx) svr := server.NewUserCenterServer(ctx)
platform_user.InitUserRetriever(ctx) platform_user.InitUserRetriever(ctx)
rank.InitRankJob(ctx) statistics.InitRankJob(ctx)
gift_collect.InitCollector(ctx) gift_collect.InitCollector(ctx)
s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) { s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {

@ -26,6 +26,7 @@ type (
GiftPackItem = pb.GiftPackItem GiftPackItem = pb.GiftPackItem
GiveEliteReq = pb.GiveEliteReq GiveEliteReq = pb.GiveEliteReq
GiveTitleReq = pb.GiveTitleReq GiveTitleReq = pb.GiveTitleReq
Grade = pb.Grade
IncreaseWelfareReq = pb.IncreaseWelfareReq IncreaseWelfareReq = pb.IncreaseWelfareReq
PlatformUserReq = pb.PlatformUserReq PlatformUserReq = pb.PlatformUserReq
PlatformUserResp = pb.PlatformUserResp PlatformUserResp = pb.PlatformUserResp
@ -49,6 +50,7 @@ type (
UserDetailsResp = pb.UserDetailsResp UserDetailsResp = pb.UserDetailsResp
UserDetailsResp_EliteItem = pb.UserDetailsResp_EliteItem UserDetailsResp_EliteItem = pb.UserDetailsResp_EliteItem
UserDetailsResp_TitleItem = pb.UserDetailsResp_TitleItem UserDetailsResp_TitleItem = pb.UserDetailsResp_TitleItem
UserGradeResp = pb.UserGradeResp
UserIdReq = pb.UserIdReq UserIdReq = pb.UserIdReq
UserIdResp = pb.UserIdResp UserIdResp = pb.UserIdResp
UserRankReq = pb.UserRankReq UserRankReq = pb.UserRankReq
@ -76,6 +78,8 @@ type (
UserBuyNobility(ctx context.Context, in *UserBuyNobilityReq, opts ...grpc.CallOption) (*Empty, error) UserBuyNobility(ctx context.Context, in *UserBuyNobilityReq, opts ...grpc.CallOption) (*Empty, error)
StatPvpReport(ctx context.Context, in *StatPvPReportReq, opts ...grpc.CallOption) (*StatPvPReportResp, error) StatPvpReport(ctx context.Context, in *StatPvPReportReq, opts ...grpc.CallOption) (*StatPvPReportResp, error)
DrawGiftPack(ctx context.Context, in *DrawGiftPackReq, opts ...grpc.CallOption) (*DrawGiftPackResp, error) DrawGiftPack(ctx context.Context, in *DrawGiftPackReq, opts ...grpc.CallOption) (*DrawGiftPackResp, error)
// @ZeroGroup: grade
GetUserGrade(ctx context.Context, in *UserIdReq, opts ...grpc.CallOption) (*UserGradeResp, error)
// rankPvp pvp排行 // rankPvp pvp排行
RankPvp(ctx context.Context, in *RankPvpReq, opts ...grpc.CallOption) (*RankPvpResp, error) RankPvp(ctx context.Context, in *RankPvpReq, opts ...grpc.CallOption) (*RankPvpResp, error)
RankPvpSubmit(ctx context.Context, in *RankPvpSubmitReq, opts ...grpc.CallOption) (*RankPvpSubmitResp, error) RankPvpSubmit(ctx context.Context, in *RankPvpSubmitReq, opts ...grpc.CallOption) (*RankPvpSubmitResp, error)
@ -162,6 +166,12 @@ func (m *defaultUserCenter) DrawGiftPack(ctx context.Context, in *DrawGiftPackRe
return client.DrawGiftPack(ctx, in, opts...) return client.DrawGiftPack(ctx, in, opts...)
} }
// @ZeroGroup: grade
func (m *defaultUserCenter) GetUserGrade(ctx context.Context, in *UserIdReq, opts ...grpc.CallOption) (*UserGradeResp, error) {
client := pb.NewUserCenterClient(m.cli.Conn())
return client.GetUserGrade(ctx, in, opts...)
}
// rankPvp pvp排行 // rankPvp pvp排行
func (m *defaultUserCenter) RankPvp(ctx context.Context, in *RankPvpReq, opts ...grpc.CallOption) (*RankPvpResp, error) { func (m *defaultUserCenter) RankPvp(ctx context.Context, in *RankPvpReq, opts ...grpc.CallOption) (*RankPvpResp, error) {
client := pb.NewUserCenterClient(m.cli.Conn()) client := pb.NewUserCenterClient(m.cli.Conn())

Loading…
Cancel
Save