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 } else if parent := c.ParentDisplayName(); parent != "" { basic.ParentPromoteName = &parent } basic.Phone, basic.SettlementDays = c.Phone, c.SettlementDays basic.LockStatus, basic.LockStatusLabel = c.LockStatus, business.ChannelLockStatusLabel(c.LockStatus) 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 }