feat: 迁移渠道画像累计指标和玩家付费分层

This commit is contained in:
Yvan
2026-11-03 23:50:05 +08:00
parent 0de822f121
commit f5b7ce21b9
38 changed files with 1424 additions and 37 deletions
@@ -19,7 +19,12 @@ func portraitMetricResponse(m *business.PortraitMetric) *dto.PortraitMetric {
if m == nil {
return nil
}
return &dto.PortraitMetric{Value: m.Value, CompareValue: m.CompareValue, ChangeRate: m.ChangeRate, ChangeDiff: m.ChangeDiff, CompareLabel: m.CompareLabel}
var label *string
if m.CompareLabel != "" {
value := m.CompareLabel
label = &value
}
return &dto.PortraitMetric{Value: m.Value, CompareValue: m.CompareValue, ChangeRate: m.ChangeRate, ChangeDiff: m.ChangeDiff, CompareLabel: label}
}
func portraitResponse(p *business.BusinessPortrait) *dto.BusinessPortraitResponse {
b := p.Basic
@@ -0,0 +1,49 @@
package business
import (
"context"
"kra/internal/biz/business"
"kra/internal/service/dto"
)
type ChannelPortraitUsecase interface {
Portrait(context.Context, business.ChannelKey, string) (*business.ChannelPortrait, error)
}
type ChannelPortraitService struct{ uc ChannelPortraitUsecase }
func NewChannelPortraitService(uc *business.ChannelPortraitUsecase) *ChannelPortraitService {
return &ChannelPortraitService{uc: uc}
}
func (s *ChannelPortraitService) Portrait(ctx context.Context, req *dto.ChannelPortraitQuery) (*dto.ChannelPortraitResponse, error) {
if req == nil || req.PromoteID == 0 {
return nil, business.ErrChannelInput
}
p, err := s.uc.Portrait(ctx, business.ChannelKey{SourceDB: req.SourceDB, ID: req.PromoteID}, req.Period)
if err != nil {
return nil, err
}
c := p.Basic.Channel
basic := &dto.ChannelPortraitBasic{PromoteID: c.ID, SourceDB: c.SourceDB, SourceDBLabel: business.PlatformName(c.SourceDB), Account: c.Account, Nickname: c.Nickname, RealName: c.RealName, PromoteLevel: c.Level, PromoteLevelLabel: business.ChannelLevelLabel(c.Level), Status: c.Status, StatusLabel: business.ChannelStatusLabel(c.Status), RegisterType: c.RegisterType, RegisterTypeLabel: business.ChannelTypeLabel(c.RegisterType), CreateTime: localTime(business.ChannelUnixTime(c.CreatedUnix)), LastLoginTime: localTime(business.ChannelUnixTime(c.LastLoginUnix)), BusierUserID: c.BusierUserID, BusierDisplayName: c.BusinessDisplayName(), GameCount: p.Basic.GameCount}
if parent := p.Basic.Parent; parent != nil {
basic.ParentPromoteID = &parent.ID
basic.ParentPromoteName = &parent.Account
basic.ParentPromoteAccount = &parent.Account
}
out := &dto.ChannelPortraitResponse{Basic: basic, Period: p.Period, Available: p.Available, UnavailableReason: p.UnavailableReason, RegisterTrend: []*dto.PortraitTrend{}, PayTrend: []*dto.PortraitTrend{}, GameDistribution: []*dto.ChannelGameResponse{}, PayTiers: []*dto.ChannelPayTier{}}
if m := p.Metrics; m != nil {
out.Metrics = &dto.ChannelPortraitMetrics{Register: portraitMetricResponse(m.Register), PayAmount: portraitMetricResponse(m.PayAmount), PayRate: portraitMetricResponse(m.PayRate), Active: portraitMetricResponse(m.Active)}
}
for _, point := range p.RegisterTrend {
out.RegisterTrend = append(out.RegisterTrend, &dto.PortraitTrend{Label: point.Label, Value: point.Value})
}
for _, point := range p.PayTrend {
out.PayTrend = append(out.PayTrend, &dto.PortraitTrend{Label: point.Label, Value: point.Value})
}
for _, game := range p.GameDistribution {
out.GameDistribution = append(out.GameDistribution, &dto.ChannelGameResponse{GameID: game.ID, GameName: game.Name, RegisterCount: game.RegisterCount, PayAmount: game.PayAmount})
}
for _, tier := range p.PayTiers {
out.PayTiers = append(out.PayTiers, &dto.ChannelPayTier{Tier: tier.Tier, TierLabel: tier.Label, Count: tier.Count, Ratio: tier.Ratio})
}
return out, nil
}
+1 -1
View File
@@ -29,7 +29,7 @@ type PortraitMetric struct {
CompareValue *string `json:"compareValue"`
ChangeRate *string `json:"changeRate"`
ChangeDiff *string `json:"changeDiff"`
CompareLabel string `json:"compareLabel"`
CompareLabel *string `json:"compareLabel"`
}
type PortraitMetrics struct {
Register *PortraitMetric `json:"register"`
+52
View File
@@ -0,0 +1,52 @@
package dto
type ChannelPortraitQuery struct {
SourceDB string `form:"sourceDb"`
PromoteID uint64 `form:"promoteId"`
Period string `form:"period"`
}
type ChannelPortraitBasic struct {
PromoteID uint64 `json:"promoteId"`
SourceDB string `json:"sourceDb"`
SourceDBLabel string `json:"sourceDbLabel"`
Account string `json:"account"`
Nickname string `json:"nickname"`
RealName string `json:"realName"`
PromoteLevel *int `json:"promoteLevel"`
PromoteLevelLabel string `json:"promoteLevelLabel"`
Status *int `json:"status"`
StatusLabel string `json:"statusLabel"`
RegisterType *int `json:"registerType"`
RegisterTypeLabel string `json:"registerTypeLabel"`
CreateTime *string `json:"createTime"`
LastLoginTime *string `json:"lastLoginTime"`
BusierUserID *uint `json:"busierUserId"`
BusierDisplayName string `json:"busierDisplayName"`
ParentPromoteID *uint64 `json:"parentPromoteId"`
ParentPromoteName *string `json:"parentPromoteName"`
ParentPromoteAccount *string `json:"parentPromoteAccount"`
GameCount *int64 `json:"gameCount"`
}
type ChannelPortraitMetrics struct {
Register *PortraitMetric `json:"register"`
PayAmount *PortraitMetric `json:"payAmount"`
PayRate *PortraitMetric `json:"payRate"`
Active *PortraitMetric `json:"active"`
}
type ChannelPayTier struct {
Tier string `json:"tier"`
TierLabel string `json:"tierLabel"`
Count int64 `json:"count"`
Ratio string `json:"ratio"`
}
type ChannelPortraitResponse struct {
Basic *ChannelPortraitBasic `json:"basic"`
Period string `json:"period"`
Metrics *ChannelPortraitMetrics `json:"metrics"`
RegisterTrend []*PortraitTrend `json:"registerTrend"`
PayTrend []*PortraitTrend `json:"payTrend"`
GameDistribution []*ChannelGameResponse `json:"gameDistribution"`
PayTiers []*ChannelPayTier `json:"payTiers"`
Available bool `json:"available"`
UnavailableReason string `json:"unavailableReason"`
}
+1
View File
@@ -22,6 +22,7 @@ var ProviderSet = wire.NewSet(
businessservice.NewActivationService,
businessservice.NewChannelService,
businessservice.NewBusinessPortraitService,
businessservice.NewChannelPortraitService,
systemservice.ProviderSet,
paymentservice.ProviderSet,
integrationservice.ProviderSet,