45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package analytics
|
|
|
|
import (
|
|
"context"
|
|
bizlive "kra/internal/biz/live"
|
|
"time"
|
|
)
|
|
|
|
type TrendPoint struct {
|
|
Date string
|
|
AmountCents int64
|
|
}
|
|
type GiftRank struct {
|
|
RoomID uint
|
|
RoomName, AnchorName string
|
|
Diamonds int64
|
|
}
|
|
type Dashboard struct {
|
|
RoomTotal, RoomLive, RechargeCents, PaidOrderCount, GiftDiamonds, GiftSendCount, DiamondRateCents int64
|
|
RechargeTrend []*TrendPoint
|
|
GiftRanking []*GiftRank
|
|
}
|
|
type Repo interface {
|
|
Dashboard(context.Context, time.Time, time.Time) (*Dashboard, error)
|
|
}
|
|
type Usecase struct {
|
|
repo Repo
|
|
streams *bizlive.StreamUsecase
|
|
}
|
|
|
|
func NewUsecase(repo Repo, streams *bizlive.StreamUsecase) *Usecase {
|
|
return &Usecase{repo: repo, streams: streams}
|
|
}
|
|
func (uc *Usecase) Get(ctx context.Context, from, to time.Time) (*Dashboard, error) {
|
|
v, err := uc.repo.Dashboard(ctx, from, to)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
streams, err := uc.streams.List(ctx)
|
|
if err == nil {
|
|
v.RoomLive = int64(len(streams))
|
|
}
|
|
return v, nil
|
|
}
|