feat: 迁移渠道画像累计指标和玩家付费分层
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user