feat(finance): refine daily sales statistics
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user