feat(finance): refine daily sales statistics

This commit is contained in:
yml2213
2026-08-09 20:43:18 +08:00
parent 211b9f012a
commit 192f7957b8
4 changed files with 24 additions and 82 deletions
@@ -260,7 +260,8 @@ func (r *Repository) dailyItems(ctx context.Context, query DashboardQuery) ([]Fi
pickupProfits := make([]dailyPickupProfitRow, 0)
if err := db.Table("admin_pickups").
Select(`DATE(completed_at) AS date,
COALESCE(SUM(profit_amount_cent), 0) AS profit_amount_cent`).
COALESCE(SUM(profit_amount_cent), 0) AS profit_amount_cent,
COUNT(id) AS completed_count`).
Where("status = ?", "completed").
Where("completed_at >= ? AND completed_at <= ?", query.StartDate, query.EndDate).
Group("DATE(completed_at)").
@@ -318,6 +319,7 @@ func (r *Repository) dailyItems(ctx context.Context, query DashboardQuery) ([]Fi
item.OfflineSettlementPendingAmountCent = row.OfflineSettlementPendingAmountCent
item.SettlementDiffAmountCent = row.OwnerShouldIncomeAmountCent - row.OwnerEffectiveSettlementAmountCent
item.SettledOrderCount = row.SettledOrderCount
item.SalesCount = row.SettledOrderCount
item.OfflineSettlementPendingCount = row.OfflineSettlementPendingCount
itemsByDate[date] = item
}
@@ -326,6 +328,8 @@ func (r *Repository) dailyItems(ctx context.Context, query DashboardQuery) ([]Fi
item := itemsByDate[date]
item.Date = date
item.PlatformIncomeAmountCent += row.ProfitAmountCent
item.PickupCompletedCount = row.CompletedCount
item.SalesCount += row.CompletedCount
itemsByDate[date] = item
}
for _, row := range estimates {
@@ -409,6 +413,7 @@ type dailySettlementRow struct {
type dailyPickupProfitRow struct {
Date string
ProfitAmountCent int64
CompletedCount int64
}
type dailyEstimatedRow struct {
@@ -214,6 +214,8 @@ type FinanceDailyDTO struct {
PartialRefundCount int64 `json:"partial_refund_count"`
PendingRefundCount int64 `json:"pending_refund_count"`
SettledOrderCount int64 `json:"settled_order_count"`
PickupCompletedCount int64 `json:"pickup_completed_count"`
SalesCount int64 `json:"sales_count"`
OfflineSettlementPendingCount int64 `json:"offline_settlement_pending_count"`
OfflineSettlementPaidAmountCent int64 `json:"offline_settlement_paid_amount_cent"`
OfflineSettlementPaidCount int64 `json:"offline_settlement_paid_count"`