diff --git a/backend/internal/modules/adminfinance/dashboard.go b/backend/internal/modules/adminfinance/dashboard.go index de81166..d68da2f 100644 --- a/backend/internal/modules/adminfinance/dashboard.go +++ b/backend/internal/modules/adminfinance/dashboard.go @@ -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)) diff --git a/backend/internal/modules/adminfinance/helper.go b/backend/internal/modules/adminfinance/helper.go index 6eed500..27a2ef2 100644 --- a/backend/internal/modules/adminfinance/helper.go +++ b/backend/internal/modules/adminfinance/helper.go @@ -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 diff --git a/backend/internal/modules/adminfinance/helper_test.go b/backend/internal/modules/adminfinance/helper_test.go new file mode 100644 index 0000000..e736f56 --- /dev/null +++ b/backend/internal/modules/adminfinance/helper_test.go @@ -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) + } + }) + } +}