feat: deepen report metrics

This commit is contained in:
2026-01-15 17:50:37 +08:00
parent ba1d120c84
commit 914df9edf2
10 changed files with 1163 additions and 52 deletions

View File

@@ -394,6 +394,8 @@ func (s *CreatorTestSuite) Test_ReportOverview() {
models.TableNameUser,
models.TableNameContent,
models.TableNameOrder,
models.TableNameUserContentAction,
models.TableNameComment,
)
owner := &models.User{Username: "owner_r", Phone: "13900001011"}
@@ -405,18 +407,23 @@ func (s *CreatorTestSuite) Test_ReportOverview() {
}
models.TenantQuery.WithContext(ctx).Create(tenant)
models.ContentQuery.WithContext(ctx).Create(&models.Content{
content := &models.Content{
TenantID: tenant.ID,
UserID: owner.ID,
Title: "Content A",
Status: consts.ContentStatusPublished,
Views: 100,
})
}
models.ContentQuery.WithContext(ctx).Create(content)
now := time.Now()
inRangePaidAt := now.Add(-12 * time.Hour)
outRangePaidAt := now.Add(-10 * 24 * time.Hour)
likeAt := now.Add(-2 * time.Hour)
favoriteAt := now.Add(-3 * time.Hour)
commentAt := now.Add(-4 * time.Hour)
models.OrderQuery.WithContext(ctx).Create(
&models.Order{
TenantID: tenant.ID,
@@ -442,8 +449,55 @@ func (s *CreatorTestSuite) Test_ReportOverview() {
AmountPaid: 500,
UpdatedAt: now.Add(-6 * time.Hour),
},
&models.Order{
TenantID: tenant.ID,
UserID: owner.ID,
Type: consts.OrderTypeWithdrawal,
Status: consts.OrderStatusCreated,
AmountPaid: 300,
CreatedAt: now.Add(-5 * time.Hour),
},
&models.Order{
TenantID: tenant.ID,
UserID: owner.ID,
Type: consts.OrderTypeWithdrawal,
Status: consts.OrderStatusPaid,
AmountPaid: 800,
PaidAt: now.Add(-3 * time.Hour),
},
&models.Order{
TenantID: tenant.ID,
UserID: owner.ID,
Type: consts.OrderTypeWithdrawal,
Status: consts.OrderStatusFailed,
AmountPaid: 500,
UpdatedAt: now.Add(-2 * time.Hour),
},
)
models.UserContentActionQuery.WithContext(ctx).Create(
&models.UserContentAction{
UserID: owner.ID,
ContentID: content.ID,
Type: string(consts.UserContentActionTypeLike),
CreatedAt: likeAt,
},
&models.UserContentAction{
UserID: owner.ID,
ContentID: content.ID,
Type: string(consts.UserContentActionTypeFavorite),
CreatedAt: favoriteAt,
},
)
models.CommentQuery.WithContext(ctx).Create(&models.Comment{
TenantID: tenant.ID,
UserID: owner.ID,
ContentID: content.ID,
Content: "Nice",
CreatedAt: commentAt,
})
start := now.Add(-24 * time.Hour).Format(time.RFC3339)
end := now.Format(time.RFC3339)
report, err := Creator.ReportOverview(ctx, tenant.ID, owner.ID, &creator_dto.ReportOverviewFilter{
@@ -452,10 +506,21 @@ func (s *CreatorTestSuite) Test_ReportOverview() {
})
So(err, ShouldBeNil)
So(report.Summary.TotalViews, ShouldEqual, 100)
So(report.Summary.ContentCount, ShouldEqual, 1)
So(report.Summary.ContentCreated, ShouldEqual, 1)
So(report.Summary.LikeActions, ShouldEqual, 1)
So(report.Summary.FavoriteActions, ShouldEqual, 1)
So(report.Summary.CommentCount, ShouldEqual, 1)
So(report.Summary.PaidOrders, ShouldEqual, 1)
So(report.Summary.PaidAmount, ShouldEqual, 10.0)
So(report.Summary.RefundOrders, ShouldEqual, 1)
So(report.Summary.RefundAmount, ShouldEqual, 5.0)
So(report.Summary.WithdrawalApplyOrders, ShouldEqual, 1)
So(report.Summary.WithdrawalApplyAmount, ShouldEqual, 3.0)
So(report.Summary.WithdrawalPaidOrders, ShouldEqual, 1)
So(report.Summary.WithdrawalPaidAmount, ShouldEqual, 8.0)
So(report.Summary.WithdrawalFailedOrders, ShouldEqual, 1)
So(report.Summary.WithdrawalFailedAmount, ShouldEqual, 5.0)
var paidSum, refundSum int64
for _, item := range report.Items {
@@ -475,6 +540,8 @@ func (s *CreatorTestSuite) Test_ExportReport() {
models.TableNameUser,
models.TableNameContent,
models.TableNameOrder,
models.TableNameUserContentAction,
models.TableNameComment,
)
owner := &models.User{Username: "owner_e", Phone: "13900001012"}
@@ -507,6 +574,6 @@ func (s *CreatorTestSuite) Test_ExportReport() {
resp, err := Creator.ExportReport(ctx, tenant.ID, owner.ID, form)
So(err, ShouldBeNil)
So(resp.Filename, ShouldNotBeBlank)
So(resp.Content, ShouldContainSubstring, "date,paid_orders,paid_amount,refund_orders,refund_amount")
So(resp.Content, ShouldContainSubstring, "date,paid_orders,paid_amount,refund_orders,refund_amount,withdrawal_apply_orders,withdrawal_apply_amount,withdrawal_paid_orders,withdrawal_paid_amount,withdrawal_failed_orders,withdrawal_failed_amount,content_created,like_actions,favorite_actions,comment_count")
})
}