修复财务仪表盘日明细
This commit is contained in:
@@ -118,8 +118,9 @@ func (r *Repository) dailyItems(ctx context.Context, query DashboardQuery) ([]Fi
|
|||||||
itemsByDate[date] = FinanceDailyDTO{Date: date}
|
itemsByDate[date] = FinanceDailyDTO{Date: date}
|
||||||
}
|
}
|
||||||
for _, row := range payments {
|
for _, row := range payments {
|
||||||
item := itemsByDate[row.Date]
|
date := dailyDateKey(row.Date)
|
||||||
item.Date = row.Date
|
item := itemsByDate[date]
|
||||||
|
item.Date = date
|
||||||
item.TotalFlowAmountCent = row.TotalFlowAmountCent
|
item.TotalFlowAmountCent = row.TotalFlowAmountCent
|
||||||
item.TotalRefundAmountCent = row.TotalRefundAmountCent
|
item.TotalRefundAmountCent = row.TotalRefundAmountCent
|
||||||
item.PendingRefundAmountCent = row.PendingRefundAmountCent
|
item.PendingRefundAmountCent = row.PendingRefundAmountCent
|
||||||
@@ -127,17 +128,18 @@ func (r *Repository) dailyItems(ctx context.Context, query DashboardQuery) ([]Fi
|
|||||||
item.SuccessfulPayCount = row.SuccessfulPayCount
|
item.SuccessfulPayCount = row.SuccessfulPayCount
|
||||||
item.SuccessfulRefundCount = row.SuccessfulRefundCount
|
item.SuccessfulRefundCount = row.SuccessfulRefundCount
|
||||||
item.PendingRefundCount = row.PendingRefundCount
|
item.PendingRefundCount = row.PendingRefundCount
|
||||||
itemsByDate[row.Date] = item
|
itemsByDate[date] = item
|
||||||
}
|
}
|
||||||
for _, row := range settlements {
|
for _, row := range settlements {
|
||||||
item := itemsByDate[row.Date]
|
date := dailyDateKey(row.Date)
|
||||||
item.Date = row.Date
|
item := itemsByDate[date]
|
||||||
|
item.Date = date
|
||||||
item.PlatformIncomeAmountCent = row.PlatformIncomeAmountCent
|
item.PlatformIncomeAmountCent = row.PlatformIncomeAmountCent
|
||||||
item.OwnerShouldIncomeAmountCent = row.OwnerShouldIncomeAmountCent
|
item.OwnerShouldIncomeAmountCent = row.OwnerShouldIncomeAmountCent
|
||||||
item.OwnerWalletIncomeAmountCent = row.OwnerWalletIncomeAmountCent
|
item.OwnerWalletIncomeAmountCent = row.OwnerWalletIncomeAmountCent
|
||||||
item.SettlementDiffAmountCent = row.OwnerShouldIncomeAmountCent - row.OwnerWalletIncomeAmountCent
|
item.SettlementDiffAmountCent = row.OwnerShouldIncomeAmountCent - row.OwnerWalletIncomeAmountCent
|
||||||
item.SettledOrderCount = row.SettledOrderCount
|
item.SettledOrderCount = row.SettledOrderCount
|
||||||
itemsByDate[row.Date] = item
|
itemsByDate[date] = item
|
||||||
}
|
}
|
||||||
|
|
||||||
items := make([]FinanceDailyDTO, 0, len(itemsByDate))
|
items := make([]FinanceDailyDTO, 0, len(itemsByDate))
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package adminfinance
|
package adminfinance
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"hfb_sys/backend/internal/timeutil"
|
"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)
|
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 {
|
func absCent(value int64) int64 {
|
||||||
if value < 0 {
|
if value < 0 {
|
||||||
return -value
|
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)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user