修复财务仪表盘日明细

This commit is contained in:
yml2213
2026-06-21 09:44:19 +08:00
parent a5165d17e9
commit 5c67f5c411
3 changed files with 42 additions and 6 deletions
@@ -118,8 +118,9 @@ func (r *Repository) dailyItems(ctx context.Context, query DashboardQuery) ([]Fi
itemsByDate[date] = FinanceDailyDTO{Date: date}
}
for _, row := range payments {
item := itemsByDate[row.Date]
item.Date = row.Date
date := dailyDateKey(row.Date)
item := itemsByDate[date]
item.Date = date
item.TotalFlowAmountCent = row.TotalFlowAmountCent
item.TotalRefundAmountCent = row.TotalRefundAmountCent
item.PendingRefundAmountCent = row.PendingRefundAmountCent
@@ -127,17 +128,18 @@ func (r *Repository) dailyItems(ctx context.Context, query DashboardQuery) ([]Fi
item.SuccessfulPayCount = row.SuccessfulPayCount
item.SuccessfulRefundCount = row.SuccessfulRefundCount
item.PendingRefundCount = row.PendingRefundCount
itemsByDate[row.Date] = item
itemsByDate[date] = item
}
for _, row := range settlements {
item := itemsByDate[row.Date]
item.Date = row.Date
date := dailyDateKey(row.Date)
item := itemsByDate[date]
item.Date = date
item.PlatformIncomeAmountCent = row.PlatformIncomeAmountCent
item.OwnerShouldIncomeAmountCent = row.OwnerShouldIncomeAmountCent
item.OwnerWalletIncomeAmountCent = row.OwnerWalletIncomeAmountCent
item.SettlementDiffAmountCent = row.OwnerShouldIncomeAmountCent - row.OwnerWalletIncomeAmountCent
item.SettledOrderCount = row.SettledOrderCount
itemsByDate[row.Date] = item
itemsByDate[date] = item
}
items := make([]FinanceDailyDTO, 0, len(itemsByDate))
@@ -1,6 +1,7 @@
package adminfinance
import (
"strings"
"time"
"hfb_sys/backend/internal/timeutil"
@@ -24,6 +25,14 @@ func dayStart(value time.Time) time.Time {
return time.Date(local.Year(), local.Month(), local.Day(), 0, 0, 0, 0, loc)
}
func dailyDateKey(value string) string {
value = strings.TrimSpace(value)
if len(value) >= len("2006-01-02") {
return value[:len("2006-01-02")]
}
return value
}
func absCent(value int64) int64 {
if value < 0 {
return -value
@@ -0,0 +1,25 @@
package adminfinance
import "testing"
func TestDailyDateKey(t *testing.T) {
tests := []struct {
name string
in string
want string
}{
{name: "date only", in: "2026-06-15", want: "2026-06-15"},
{name: "datetime", in: "2026-06-15 00:00:00", want: "2026-06-15"},
{name: "rfc3339", in: "2026-06-15T00:00:00+08:00", want: "2026-06-15"},
{name: "trim spaces", in: " 2026-06-15T00:00:00Z ", want: "2026-06-15"},
{name: "short value", in: "2026-06", want: "2026-06"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := dailyDateKey(tt.in); got != tt.want {
t.Fatalf("dailyDateKey(%q) = %q, want %q", tt.in, got, tt.want)
}
})
}
}