package analytics import ( "context" biz "kra/internal/biz/analytics" "kra/internal/service/dto" "time" ) type Service struct{ uc *biz.Usecase } func NewService(uc *biz.Usecase) *Service { return &Service{uc: uc} } func (s *Service) Get(ctx context.Context, days int) (*dto.DashboardResponse, error) { if days != 0 && days != 1 && days != 7 && days != 30 { days = 1 } now := time.Now() today := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location()) from, to := today.AddDate(0, 0, -days+1), now if days == 0 { from = today.AddDate(0, 0, -1) to = today.Add(-time.Nanosecond) } v, e := s.uc.Get(ctx, from, to) if e != nil { return nil, e } out := &dto.DashboardResponse{RoomTotal: v.RoomTotal, RoomLive: v.RoomLive, RechargeCents: v.RechargeCents, PaidOrderCount: v.PaidOrderCount, GiftDiamonds: v.GiftDiamonds, GiftSendCount: v.GiftSendCount, DiamondRateCents: v.DiamondRateCents} for _, x := range v.RechargeTrend { out.RechargeTrend = append(out.RechargeTrend, dto.DashboardTrend{Date: x.Date, AmountCents: x.AmountCents}) } for _, x := range v.GiftRanking { out.GiftRanking = append(out.GiftRanking, dto.DashboardRank{RoomID: x.RoomID, RoomName: x.RoomName, AnchorName: x.AnchorName, Diamonds: x.Diamonds}) } return out, nil }