feat(platform-ops): 增加用户商品交易资金分类统计
This commit is contained in:
@@ -2,6 +2,7 @@ package platformops
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"hfb_sys/backend/internal/database"
|
||||
"hfb_sys/backend/internal/model"
|
||||
@@ -78,6 +79,24 @@ func TestOverviewAggregatesAllTenantsAndSites(t *testing.T) {
|
||||
if err := db.Create(&orders).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
now := time.Now()
|
||||
ledgers := []model.WalletLedger{
|
||||
{LedgerNo: "OPS-WL-A-IN", TenantID: tenants[0].ID, UserID: users[0].ID, Direction: "in", AmountCent: 1000, BalanceType: "available", BizType: "owner_income", BizNo: "OPS-ORDER-1", CreatedAt: now},
|
||||
{LedgerNo: "OPS-WL-A-OUT", TenantID: tenants[0].ID, UserID: users[0].ID, Direction: "out", AmountCent: 200, BalanceType: "available", BizType: "withdrawal", BizNo: "OPS-WD-A", CreatedAt: now.AddDate(0, 0, -1)},
|
||||
{LedgerNo: "OPS-WL-B-IN", TenantID: tenants[1].ID, UserID: users[2].ID, Direction: "in", AmountCent: 300, BalanceType: "available", BizType: "owner_income", BizNo: "OPS-ORDER-2", CreatedAt: now},
|
||||
{LedgerNo: "OPS-WL-B-OUT", TenantID: tenants[1].ID, UserID: users[2].ID, Direction: "out", AmountCent: 100, BalanceType: "available", BizType: "withdrawal", BizNo: "OPS-WD-B", CreatedAt: now},
|
||||
}
|
||||
if err := db.Create(&ledgers).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
withdrawals := []model.WithdrawalRequest{
|
||||
{WithdrawNo: "OPS-WD-A", TenantID: tenants[0].ID, UserID: users[0].ID, AmountCent: 100, ActualAmountCent: 100, AccountType: "bank", AccountName: "A站用户", AccountNo: "****0001", Status: "pending"},
|
||||
{WithdrawNo: "OPS-WD-B", TenantID: tenants[1].ID, UserID: users[2].ID, AmountCent: 100, ActualAmountCent: 100, AccountType: "bank", AccountName: "B站用户", AccountNo: "****0002", Status: "processing"},
|
||||
{WithdrawNo: "OPS-WD-DONE", TenantID: tenants[1].ID, UserID: users[3].ID, AmountCent: 100, ActualAmountCent: 100, AccountType: "bank", AccountName: "B站用户", AccountNo: "****0003", Status: "completed"},
|
||||
}
|
||||
if err := db.Create(&withdrawals).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var userCount int64
|
||||
if err := db.Model(&model.User{}).Count(&userCount).Error; err != nil || userCount != 4 {
|
||||
t.Fatalf("seeded users = %d, err=%v", userCount, err)
|
||||
@@ -95,15 +114,31 @@ func TestOverviewAggregatesAllTenantsAndSites(t *testing.T) {
|
||||
overview.Totals.PaidGMVCent != 1000 {
|
||||
t.Fatalf("overview order totals = %+v", overview.Totals)
|
||||
}
|
||||
if overview.Totals.WalletInflowCent != 1300 || overview.Totals.WalletOutflowCent != 300 ||
|
||||
overview.Totals.TodayWalletInflowCent != 1300 || overview.Totals.TodayWalletOutflowCent != 100 ||
|
||||
overview.Totals.PendingWithdrawals != 2 {
|
||||
t.Fatalf("overview wallet totals = %+v", overview.Totals)
|
||||
}
|
||||
if len(overview.Sites) != 2 || len(overview.Trend) != 7 {
|
||||
t.Fatalf("sites=%d trend=%d", len(overview.Sites), len(overview.Trend))
|
||||
}
|
||||
if overview.Sites[0].UserCount != 2 || overview.Sites[0].BuyerOrders != 1 ||
|
||||
overview.Sites[0].SourceOrders != 0 {
|
||||
overview.Sites[0].SourceOrders != 0 || overview.Sites[0].TodayNewListings != 1 ||
|
||||
overview.Sites[0].WalletInflowCent != 1000 || overview.Sites[0].WalletOutflowCent != 200 ||
|
||||
overview.Sites[0].PendingWithdrawals != 1 {
|
||||
t.Fatalf("site A stats = %+v", overview.Sites[0])
|
||||
}
|
||||
if overview.Sites[1].UserCount != 2 || overview.Sites[1].BuyerOrders != 0 ||
|
||||
overview.Sites[1].SourceOrders != 1 {
|
||||
overview.Sites[1].SourceOrders != 1 || overview.Sites[1].TodayNewListings != 1 ||
|
||||
overview.Sites[1].WalletInflowCent != 300 || overview.Sites[1].WalletOutflowCent != 100 ||
|
||||
overview.Sites[1].TodayWalletInflowCent != 300 || overview.Sites[1].TodayWalletOutflowCent != 100 ||
|
||||
overview.Sites[1].PendingWithdrawals != 1 {
|
||||
t.Fatalf("site B stats = %+v", overview.Sites[1])
|
||||
}
|
||||
todayTrend := overview.Trend[6]
|
||||
if todayTrend.NewUsers != 4 || todayTrend.NewListings != 2 ||
|
||||
todayTrend.Orders != 1 || todayTrend.PaidGMVCent != 1000 ||
|
||||
todayTrend.WalletInflowCent != 1300 || todayTrend.WalletOutflowCent != 100 {
|
||||
t.Fatalf("today trend = %+v", todayTrend)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user