feat(adminfinance): 新增预计收入指标并优化明细查询性能
- 财务看板增加预计收入与待结算订单数统计 - 明细列表 COUNT 改为仅扫描 rental_orders 主表,避免 5-JOIN 子查询 - 统一前后端结算差异判定阈值为常量 5 分 - 修复日期选择器使用 UTC 日期导致东八区凌晨偏移前一天的问题
This commit is contained in:
@@ -62,6 +62,18 @@ func (r *Repository) summary(ctx context.Context, query DashboardQuery) (*Financ
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 预计收入:尚未结算订单的下单预估平台手续费之和,按下单时间落在查询区间内统计。
|
||||||
|
var estimated estimatedIncomeRow
|
||||||
|
if err := db.Table("rental_orders").
|
||||||
|
Select(`COALESCE(SUM(platform_fee_cent), 0) AS estimated_income_amount_cent,
|
||||||
|
COUNT(id) AS pending_settle_order_count`).
|
||||||
|
Where("settlement_status NOT IN ?", settledSettlementStatuses()).
|
||||||
|
Where("status NOT IN ?", nonBillableOrderStatuses()).
|
||||||
|
Where("created_at >= ? AND created_at <= ?", query.StartDate, query.EndDate).
|
||||||
|
Scan(&estimated).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return &FinanceSummaryDTO{
|
return &FinanceSummaryDTO{
|
||||||
TotalFlowAmountCent: payment.TotalFlowAmountCent,
|
TotalFlowAmountCent: payment.TotalFlowAmountCent,
|
||||||
TotalRefundAmountCent: payment.TotalRefundAmountCent,
|
TotalRefundAmountCent: payment.TotalRefundAmountCent,
|
||||||
@@ -71,10 +83,12 @@ func (r *Repository) summary(ctx context.Context, query DashboardQuery) (*Financ
|
|||||||
OwnerShouldIncomeAmountCent: settlement.OwnerShouldIncomeAmountCent,
|
OwnerShouldIncomeAmountCent: settlement.OwnerShouldIncomeAmountCent,
|
||||||
OwnerWalletIncomeAmountCent: settlement.OwnerWalletIncomeAmountCent,
|
OwnerWalletIncomeAmountCent: settlement.OwnerWalletIncomeAmountCent,
|
||||||
SettlementDiffAmountCent: settlement.OwnerShouldIncomeAmountCent - settlement.OwnerWalletIncomeAmountCent,
|
SettlementDiffAmountCent: settlement.OwnerShouldIncomeAmountCent - settlement.OwnerWalletIncomeAmountCent,
|
||||||
|
EstimatedIncomeAmountCent: estimated.EstimatedIncomeAmountCent,
|
||||||
SuccessfulPayCount: payment.SuccessfulPayCount,
|
SuccessfulPayCount: payment.SuccessfulPayCount,
|
||||||
SuccessfulRefundCount: payment.SuccessfulRefundCount,
|
SuccessfulRefundCount: payment.SuccessfulRefundCount,
|
||||||
PendingRefundCount: payment.PendingRefundCount,
|
PendingRefundCount: payment.PendingRefundCount,
|
||||||
SettledOrderCount: settlement.SettledOrderCount,
|
SettledOrderCount: settlement.SettledOrderCount,
|
||||||
|
PendingSettleOrderCount: estimated.PendingSettleOrderCount,
|
||||||
FinancialExceptionCount: exceptionCount,
|
FinancialExceptionCount: exceptionCount,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
@@ -112,6 +126,19 @@ func (r *Repository) dailyItems(ctx context.Context, query DashboardQuery) ([]Fi
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 每日预计收入:尚未结算订单的下单预估平台手续费,按下单日期归集,口径与 summary 一致。
|
||||||
|
estimates := make([]dailyEstimatedRow, 0)
|
||||||
|
if err := db.Table("rental_orders").
|
||||||
|
Select(`DATE(created_at) AS date,
|
||||||
|
COALESCE(SUM(platform_fee_cent), 0) AS estimated_income_amount_cent`).
|
||||||
|
Where("settlement_status NOT IN ?", settledSettlementStatuses()).
|
||||||
|
Where("status NOT IN ?", nonBillableOrderStatuses()).
|
||||||
|
Where("created_at >= ? AND created_at <= ?", query.StartDate, query.EndDate).
|
||||||
|
Group("DATE(created_at)").
|
||||||
|
Scan(&estimates).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
itemsByDate := make(map[string]FinanceDailyDTO)
|
itemsByDate := make(map[string]FinanceDailyDTO)
|
||||||
for day := dayStart(query.StartDate); !day.After(query.EndDate); day = day.AddDate(0, 0, 1) {
|
for day := dayStart(query.StartDate); !day.After(query.EndDate); day = day.AddDate(0, 0, 1) {
|
||||||
date := day.Format("2006-01-02")
|
date := day.Format("2006-01-02")
|
||||||
@@ -141,6 +168,13 @@ func (r *Repository) dailyItems(ctx context.Context, query DashboardQuery) ([]Fi
|
|||||||
item.SettledOrderCount = row.SettledOrderCount
|
item.SettledOrderCount = row.SettledOrderCount
|
||||||
itemsByDate[date] = item
|
itemsByDate[date] = item
|
||||||
}
|
}
|
||||||
|
for _, row := range estimates {
|
||||||
|
date := dailyDateKey(row.Date)
|
||||||
|
item := itemsByDate[date]
|
||||||
|
item.Date = date
|
||||||
|
item.EstimatedIncomeAmountCent = row.EstimatedIncomeAmountCent
|
||||||
|
itemsByDate[date] = item
|
||||||
|
}
|
||||||
|
|
||||||
items := make([]FinanceDailyDTO, 0, len(itemsByDate))
|
items := make([]FinanceDailyDTO, 0, len(itemsByDate))
|
||||||
for day := dayStart(query.StartDate); !day.After(query.EndDate); day = day.AddDate(0, 0, 1) {
|
for day := dayStart(query.StartDate); !day.After(query.EndDate); day = day.AddDate(0, 0, 1) {
|
||||||
@@ -165,6 +199,11 @@ type settlementSummaryRow struct {
|
|||||||
SettledOrderCount int64
|
SettledOrderCount int64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type estimatedIncomeRow struct {
|
||||||
|
EstimatedIncomeAmountCent int64
|
||||||
|
PendingSettleOrderCount int64
|
||||||
|
}
|
||||||
|
|
||||||
type dailyPaymentRow struct {
|
type dailyPaymentRow struct {
|
||||||
Date string
|
Date string
|
||||||
TotalFlowAmountCent int64
|
TotalFlowAmountCent int64
|
||||||
@@ -182,3 +221,8 @@ type dailySettlementRow struct {
|
|||||||
OwnerWalletIncomeAmountCent int64
|
OwnerWalletIncomeAmountCent int64
|
||||||
SettledOrderCount int64
|
SettledOrderCount int64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type dailyEstimatedRow struct {
|
||||||
|
Date string
|
||||||
|
EstimatedIncomeAmountCent int64
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,14 +7,20 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (r *Repository) Details(ctx context.Context, query DetailQuery) (*PaginatedResult, error) {
|
func (r *Repository) Details(ctx context.Context, query DetailQuery) (*PaginatedResult, error) {
|
||||||
baseDB := r.db.WithContext(ctx)
|
// COUNT 只扫描 rental_orders 主表(过滤条件全部落在 ro.* 上,可命中
|
||||||
db := r.financeDetailBaseQuery(ctx, query)
|
// idx_rental_orders_settled_at_id / created_at_id 索引),不再套完整 5-JOIN
|
||||||
|
// 子查询,避免大数据量翻页时 COUNT 拖慢。
|
||||||
|
countDB := r.applyDetailFilters(r.db.WithContext(ctx).Table("rental_orders AS ro"), query)
|
||||||
var total int64
|
var total int64
|
||||||
countDB := baseDB.Table("(?) AS finance_rows", db)
|
|
||||||
if err := countDB.Count(&total).Error; err != nil {
|
if err := countDB.Count(&total).Error; err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if total == 0 {
|
||||||
|
return &PaginatedResult{Items: []FinanceDetailDTO{}, Total: 0, Page: query.Page, PageSize: query.PageSize}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 明细行查询保留完整 JOIN,仅对当前分页命中的订单做金额聚合。
|
||||||
|
db := r.financeDetailBaseQuery(ctx, query)
|
||||||
offset := (query.Page - 1) * query.PageSize
|
offset := (query.Page - 1) * query.PageSize
|
||||||
rows := make([]financeDetailRow, 0, query.PageSize)
|
rows := make([]financeDetailRow, 0, query.PageSize)
|
||||||
if err := db.Order("ro.id DESC").Offset(offset).Limit(query.PageSize).Scan(&rows).Error; err != nil {
|
if err := db.Order("ro.id DESC").Offset(offset).Limit(query.PageSize).Scan(&rows).Error; err != nil {
|
||||||
@@ -27,6 +33,31 @@ func (r *Repository) Details(ctx context.Context, query DetailQuery) (*Paginated
|
|||||||
return &PaginatedResult{Items: items, Total: total, Page: query.Page, PageSize: query.PageSize}, nil
|
return &PaginatedResult{Items: items, Total: total, Page: query.Page, PageSize: query.PageSize}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// applyDetailFilters 把仅依赖 rental_orders 主表字段的过滤条件挂到查询上,
|
||||||
|
// COUNT 与明细行查询共用,保证两者口径一致。
|
||||||
|
func (r *Repository) applyDetailFilters(db *gorm.DB, query DetailQuery) *gorm.DB {
|
||||||
|
if query.OrderNo != "" {
|
||||||
|
db = db.Where("ro.order_no = ?", query.OrderNo)
|
||||||
|
}
|
||||||
|
if query.UserID > 0 {
|
||||||
|
db = db.Where("(ro.renter_id = ? OR ro.owner_id = ?)", query.UserID, query.UserID)
|
||||||
|
}
|
||||||
|
if query.OrderStatus != "" {
|
||||||
|
db = db.Where("ro.status = ?", query.OrderStatus)
|
||||||
|
}
|
||||||
|
if query.SettlementStatus != "" {
|
||||||
|
db = db.Where("ro.settlement_status = ?", query.SettlementStatus)
|
||||||
|
}
|
||||||
|
if !query.StartDate.IsZero() && !query.EndDate.IsZero() {
|
||||||
|
if query.DateType == "created" {
|
||||||
|
db = db.Where("ro.created_at >= ? AND ro.created_at <= ?", query.StartDate, query.EndDate)
|
||||||
|
} else {
|
||||||
|
db = db.Where("ro.settled_at >= ? AND ro.settled_at <= ?", query.StartDate, query.EndDate)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return db
|
||||||
|
}
|
||||||
|
|
||||||
func (r *Repository) financeDetailBaseQuery(ctx context.Context, query DetailQuery) *gorm.DB {
|
func (r *Repository) financeDetailBaseQuery(ctx context.Context, query DetailQuery) *gorm.DB {
|
||||||
db := r.db.WithContext(ctx).Table("rental_orders AS ro").
|
db := r.db.WithContext(ctx).Table("rental_orders AS ro").
|
||||||
Select(`ro.id AS order_id, ro.order_no, ro.status AS order_status, ro.settlement_status, ro.refund_status,
|
Select(`ro.id AS order_id, ro.order_no, ro.status AS order_status, ro.settlement_status, ro.refund_status,
|
||||||
@@ -48,34 +79,15 @@ func (r *Repository) financeDetailBaseQuery(ctx context.Context, query DetailQue
|
|||||||
CASE
|
CASE
|
||||||
WHEN COALESCE(p.failed_refund_amount_cent, 0) > 0 THEN 'refund_failed'
|
WHEN COALESCE(p.failed_refund_amount_cent, 0) > 0 THEN 'refund_failed'
|
||||||
WHEN COALESCE(p.refunding_amount_cent, 0) > 0 OR ro.refund_status = 'refunding' THEN 'refund_pending'
|
WHEN COALESCE(p.refunding_amount_cent, 0) > 0 OR ro.refund_status = 'refunding' THEN 'refund_pending'
|
||||||
WHEN ABS(COALESCE(oc.owner_income_amount_cent, 0) - COALESCE(w.owner_wallet_income_amount_cent, 0)) >= 5 THEN 'settlement_diff'
|
WHEN ABS(COALESCE(oc.owner_income_amount_cent, 0) - COALESCE(w.owner_wallet_income_amount_cent, 0)) >= ? THEN 'settlement_diff'
|
||||||
ELSE 'normal'
|
ELSE 'normal'
|
||||||
END AS finance_status,
|
END AS finance_status,
|
||||||
ro.created_at, ro.settled_at`).
|
ro.created_at, ro.settled_at`, settlementDiffThresholdCent).
|
||||||
Joins("LEFT JOIN users AS ru ON ru.id = ro.renter_id").
|
Joins("LEFT JOIN users AS ru ON ru.id = ro.renter_id").
|
||||||
Joins("LEFT JOIN users AS ou ON ou.id = ro.owner_id").
|
Joins("LEFT JOIN users AS ou ON ou.id = ro.owner_id").
|
||||||
Joins("LEFT JOIN (?) AS oc ON oc.order_id = ro.id", acceptedCheckoutSubquery(r.db.WithContext(ctx))).
|
Joins("LEFT JOIN (?) AS oc ON oc.order_id = ro.id", acceptedCheckoutSubquery(r.db.WithContext(ctx))).
|
||||||
Joins("LEFT JOIN (?) AS p ON p.order_id = ro.id", orderPaymentSubquery(r.db.WithContext(ctx))).
|
Joins("LEFT JOIN (?) AS p ON p.order_id = ro.id", orderPaymentSubquery(r.db.WithContext(ctx))).
|
||||||
Joins("LEFT JOIN (?) AS w ON w.order_id = ro.id", ownerWalletIncomeSubquery(r.db.WithContext(ctx)))
|
Joins("LEFT JOIN (?) AS w ON w.order_id = ro.id", ownerWalletIncomeSubquery(r.db.WithContext(ctx)))
|
||||||
|
|
||||||
if query.OrderNo != "" {
|
return r.applyDetailFilters(db, query)
|
||||||
db = db.Where("ro.order_no = ?", query.OrderNo)
|
|
||||||
}
|
|
||||||
if query.UserID > 0 {
|
|
||||||
db = db.Where("(ro.renter_id = ? OR ro.owner_id = ?)", query.UserID, query.UserID)
|
|
||||||
}
|
|
||||||
if query.OrderStatus != "" {
|
|
||||||
db = db.Where("ro.status = ?", query.OrderStatus)
|
|
||||||
}
|
|
||||||
if query.SettlementStatus != "" {
|
|
||||||
db = db.Where("ro.settlement_status = ?", query.SettlementStatus)
|
|
||||||
}
|
|
||||||
if !query.StartDate.IsZero() && !query.EndDate.IsZero() {
|
|
||||||
if query.DateType == "created" {
|
|
||||||
db = db.Where("ro.created_at >= ? AND ro.created_at <= ?", query.StartDate, query.EndDate)
|
|
||||||
} else {
|
|
||||||
db = db.Where("ro.settled_at >= ? AND ro.settled_at <= ?", query.StartDate, query.EndDate)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return db
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,10 +34,12 @@ type FinanceSummaryDTO struct {
|
|||||||
OwnerShouldIncomeAmountCent int64 `json:"owner_should_income_amount_cent"`
|
OwnerShouldIncomeAmountCent int64 `json:"owner_should_income_amount_cent"`
|
||||||
OwnerWalletIncomeAmountCent int64 `json:"owner_wallet_income_amount_cent"`
|
OwnerWalletIncomeAmountCent int64 `json:"owner_wallet_income_amount_cent"`
|
||||||
SettlementDiffAmountCent int64 `json:"settlement_diff_amount_cent"`
|
SettlementDiffAmountCent int64 `json:"settlement_diff_amount_cent"`
|
||||||
|
EstimatedIncomeAmountCent int64 `json:"estimated_income_amount_cent"`
|
||||||
SuccessfulPayCount int64 `json:"successful_pay_count"`
|
SuccessfulPayCount int64 `json:"successful_pay_count"`
|
||||||
SuccessfulRefundCount int64 `json:"successful_refund_count"`
|
SuccessfulRefundCount int64 `json:"successful_refund_count"`
|
||||||
PendingRefundCount int64 `json:"pending_refund_count"`
|
PendingRefundCount int64 `json:"pending_refund_count"`
|
||||||
SettledOrderCount int64 `json:"settled_order_count"`
|
SettledOrderCount int64 `json:"settled_order_count"`
|
||||||
|
PendingSettleOrderCount int64 `json:"pending_settle_order_count"`
|
||||||
FinancialExceptionCount int64 `json:"financial_exception_count"`
|
FinancialExceptionCount int64 `json:"financial_exception_count"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,6 +53,7 @@ type FinanceDailyDTO struct {
|
|||||||
OwnerShouldIncomeAmountCent int64 `json:"owner_should_income_amount_cent"`
|
OwnerShouldIncomeAmountCent int64 `json:"owner_should_income_amount_cent"`
|
||||||
OwnerWalletIncomeAmountCent int64 `json:"owner_wallet_income_amount_cent"`
|
OwnerWalletIncomeAmountCent int64 `json:"owner_wallet_income_amount_cent"`
|
||||||
SettlementDiffAmountCent int64 `json:"settlement_diff_amount_cent"`
|
SettlementDiffAmountCent int64 `json:"settlement_diff_amount_cent"`
|
||||||
|
EstimatedIncomeAmountCent int64 `json:"estimated_income_amount_cent"`
|
||||||
SuccessfulPayCount int64 `json:"successful_pay_count"`
|
SuccessfulPayCount int64 `json:"successful_pay_count"`
|
||||||
SuccessfulRefundCount int64 `json:"successful_refund_count"`
|
SuccessfulRefundCount int64 `json:"successful_refund_count"`
|
||||||
PendingRefundCount int64 `json:"pending_refund_count"`
|
PendingRefundCount int64 `json:"pending_refund_count"`
|
||||||
|
|||||||
@@ -7,6 +7,11 @@ import (
|
|||||||
"hfb_sys/backend/internal/timeutil"
|
"hfb_sys/backend/internal/timeutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// settlementDiffThresholdCent 是判定"结算差异"的最小绝对金额(分)。
|
||||||
|
// 号主应得与实际入账的差额绝对值达到此阈值,才视为财务异常。
|
||||||
|
// SQL、presenter、前端展示统一引用此口径,避免多处硬编码不一致。
|
||||||
|
const settlementDiffThresholdCent = 5
|
||||||
|
|
||||||
func refundBizTypes() []string {
|
func refundBizTypes() []string {
|
||||||
return []string{
|
return []string{
|
||||||
"cancel_refund",
|
"cancel_refund",
|
||||||
@@ -19,6 +24,18 @@ func refundBizTypes() []string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// settledSettlementStatuses 是视为"已完成结算"的结算状态集合。
|
||||||
|
// 预计收入只统计尚未结算的订单,这些状态需从预计口径中排除。
|
||||||
|
func settledSettlementStatuses() []string {
|
||||||
|
return []string{"settled", "closed"}
|
||||||
|
}
|
||||||
|
|
||||||
|
// nonBillableOrderStatuses 是不产生平台收入的订单状态集合(待支付、已取消、已关闭)。
|
||||||
|
// 预计收入排除这些状态,只保留进行中/待结算且未来会产生手续费的订单。
|
||||||
|
func nonBillableOrderStatuses() []string {
|
||||||
|
return []string{"pending_payment", "cancelled", "closed"}
|
||||||
|
}
|
||||||
|
|
||||||
func dayStart(value time.Time) time.Time {
|
func dayStart(value time.Time) time.Time {
|
||||||
loc := timeutil.ShanghaiLocation()
|
loc := timeutil.ShanghaiLocation()
|
||||||
local := value.In(loc)
|
local := value.In(loc)
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ func (r financeDetailRow) toDTO() FinanceDetailDTO {
|
|||||||
if status == "" {
|
if status == "" {
|
||||||
status = "normal"
|
status = "normal"
|
||||||
}
|
}
|
||||||
if absCent(diff) < 5 && status == "settlement_diff" {
|
if absCent(diff) < settlementDiffThresholdCent && status == "settlement_diff" {
|
||||||
status = "normal"
|
status = "normal"
|
||||||
}
|
}
|
||||||
return FinanceDetailDTO{
|
return FinanceDetailDTO{
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
import { apiClient } from '@/shared/api/client'
|
import { apiClient } from '@/shared/api/client'
|
||||||
import type { ApiResponse, PaginatedResult } from '@/shared/types/types'
|
import type { ApiResponse, PaginatedResult } from '@/shared/types/types'
|
||||||
|
|
||||||
|
// 结算差异判定阈值(分)。号主应得与实际入账差额绝对值达到此值即标红。
|
||||||
|
// 与后端 settlementDiffThresholdCent 保持一致,改口径时两端同步。
|
||||||
|
export const SETTLEMENT_DIFF_THRESHOLD_CENT = 5
|
||||||
|
|
||||||
export interface FinanceSummary {
|
export interface FinanceSummary {
|
||||||
total_flow_amount_cent: number
|
total_flow_amount_cent: number
|
||||||
total_refund_amount_cent: number
|
total_refund_amount_cent: number
|
||||||
@@ -10,10 +14,12 @@ export interface FinanceSummary {
|
|||||||
owner_should_income_amount_cent: number
|
owner_should_income_amount_cent: number
|
||||||
owner_wallet_income_amount_cent: number
|
owner_wallet_income_amount_cent: number
|
||||||
settlement_diff_amount_cent: number
|
settlement_diff_amount_cent: number
|
||||||
|
estimated_income_amount_cent: number
|
||||||
successful_pay_count: number
|
successful_pay_count: number
|
||||||
successful_refund_count: number
|
successful_refund_count: number
|
||||||
pending_refund_count: number
|
pending_refund_count: number
|
||||||
settled_order_count: number
|
settled_order_count: number
|
||||||
|
pending_settle_order_count: number
|
||||||
financial_exception_count: number
|
financial_exception_count: number
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,6 +33,7 @@ export interface FinanceDailyItem {
|
|||||||
owner_should_income_amount_cent: number
|
owner_should_income_amount_cent: number
|
||||||
owner_wallet_income_amount_cent: number
|
owner_wallet_income_amount_cent: number
|
||||||
settlement_diff_amount_cent: number
|
settlement_diff_amount_cent: number
|
||||||
|
estimated_income_amount_cent: number
|
||||||
successful_pay_count: number
|
successful_pay_count: number
|
||||||
successful_refund_count: number
|
successful_refund_count: number
|
||||||
pending_refund_count: number
|
pending_refund_count: number
|
||||||
|
|||||||
@@ -4,11 +4,12 @@ import { computed, onMounted, reactive, ref } from 'vue'
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
fetchFinanceDashboard,
|
fetchFinanceDashboard,
|
||||||
|
SETTLEMENT_DIFF_THRESHOLD_CENT,
|
||||||
type FinanceDashboard,
|
type FinanceDashboard,
|
||||||
type FinanceDailyItem,
|
type FinanceDailyItem,
|
||||||
} from '@/features/admin/api/adminFinance'
|
} from '@/features/admin/api/adminFinance'
|
||||||
import { formatCentWithSymbol } from '@/shared/utils/money'
|
import { formatCentWithSymbol } from '@/shared/utils/money'
|
||||||
import { formatDateTime } from '@/shared/utils/time'
|
import { formatDateTime, formatInputDate } from '@/shared/utils/time'
|
||||||
|
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const dashboard = ref<FinanceDashboard | null>(null)
|
const dashboard = ref<FinanceDashboard | null>(null)
|
||||||
@@ -44,16 +45,14 @@ function defaultEndDate() {
|
|||||||
return formatInputDate(new Date())
|
return formatInputDate(new Date())
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatInputDate(date: Date) {
|
|
||||||
return date.toISOString().slice(0, 10)
|
|
||||||
}
|
|
||||||
|
|
||||||
function diffType(value: number) {
|
function diffType(value: number) {
|
||||||
return Math.abs(Number(value || 0)) >= 5 ? 'danger' : 'success'
|
return Math.abs(Number(value || 0)) >= SETTLEMENT_DIFF_THRESHOLD_CENT ? 'danger' : 'success'
|
||||||
}
|
}
|
||||||
|
|
||||||
function rowDiffClass(row: FinanceDailyItem) {
|
function rowDiffClass(row: FinanceDailyItem) {
|
||||||
return Math.abs(Number(row.settlement_diff_amount_cent || 0)) >= 5 ? 'amount-danger' : ''
|
return Math.abs(Number(row.settlement_diff_amount_cent || 0)) >= SETTLEMENT_DIFF_THRESHOLD_CENT
|
||||||
|
? 'amount-danger'
|
||||||
|
: ''
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -130,6 +129,11 @@ function rowDiffClass(row: FinanceDailyItem) {
|
|||||||
</strong>
|
</strong>
|
||||||
<small>{{ dashboard.summary.financial_exception_count }} 个异常订单</small>
|
<small>{{ dashboard.summary.financial_exception_count }} 个异常订单</small>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="metric-card">
|
||||||
|
<span>预计收入</span>
|
||||||
|
<strong>{{ moneyCent(dashboard.summary.estimated_income_amount_cent) }}</strong>
|
||||||
|
<small>{{ dashboard.summary.pending_settle_order_count }} 个待结算订单</small>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<el-table v-loading="loading" class="table-panel" :data="dailyItems">
|
<el-table v-loading="loading" class="table-panel" :data="dailyItems">
|
||||||
@@ -157,11 +161,17 @@ function rowDiffClass(row: FinanceDailyItem) {
|
|||||||
<span :class="rowDiffClass(row)">{{ moneyCent(row.settlement_diff_amount_cent) }}</span>
|
<span :class="rowDiffClass(row)">{{ moneyCent(row.settlement_diff_amount_cent) }}</span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="收款/退款/结算" min-width="170">
|
<el-table-column label="预计收入" width="130">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">{{ moneyCent(row.estimated_income_amount_cent) }}</template>
|
||||||
{{ row.successful_pay_count }} / {{ row.successful_refund_count }} /
|
</el-table-column>
|
||||||
{{ row.settled_order_count }}
|
<el-table-column label="销售数量" width="110">
|
||||||
</template>
|
<template #default="{ row }">{{ row.successful_pay_count }}</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="退款数量" width="110">
|
||||||
|
<template #default="{ row }">{{ row.successful_refund_count }}</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="结算数量" width="110">
|
||||||
|
<template #default="{ row }">{{ row.settled_order_count }}</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
</el-table>
|
</el-table>
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,15 @@
|
|||||||
import { Search } from '@element-plus/icons-vue'
|
import { Search } from '@element-plus/icons-vue'
|
||||||
import { onMounted, reactive, ref } from 'vue'
|
import { onMounted, reactive, ref } from 'vue'
|
||||||
|
|
||||||
import { fetchFinanceDetails, type FinanceDetail } from '@/features/admin/api/adminFinance'
|
import {
|
||||||
|
fetchFinanceDetails,
|
||||||
|
SETTLEMENT_DIFF_THRESHOLD_CENT,
|
||||||
|
type FinanceDetail,
|
||||||
|
} from '@/features/admin/api/adminFinance'
|
||||||
import { adminPath } from '@/shared/utils/adminPath'
|
import { adminPath } from '@/shared/utils/adminPath'
|
||||||
import { formatCentWithSymbol } from '@/shared/utils/money'
|
import { formatCentWithSymbol } from '@/shared/utils/money'
|
||||||
import { orderStatusLabel } from '@/shared/utils/statusLabels'
|
import { orderStatusLabel } from '@/shared/utils/statusLabels'
|
||||||
import { formatDateTime } from '@/shared/utils/time'
|
import { formatDateTime, formatInputDate } from '@/shared/utils/time'
|
||||||
import AdminTablePagination from '../components/AdminTablePagination.vue'
|
import AdminTablePagination from '../components/AdminTablePagination.vue'
|
||||||
|
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
@@ -102,10 +106,6 @@ function defaultStartDate() {
|
|||||||
function defaultEndDate() {
|
function defaultEndDate() {
|
||||||
return formatInputDate(new Date())
|
return formatInputDate(new Date())
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatInputDate(date: Date) {
|
|
||||||
return date.toISOString().slice(0, 10)
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -236,7 +236,10 @@ function formatInputDate(date: Date) {
|
|||||||
}}</span>
|
}}</span>
|
||||||
<span
|
<span
|
||||||
class="amount-text amount-cell"
|
class="amount-text amount-cell"
|
||||||
:class="{ 'amount-danger': Math.abs(row.settlement_diff_amount_cent) >= 5 }"
|
:class="{
|
||||||
|
'amount-danger':
|
||||||
|
Math.abs(row.settlement_diff_amount_cent) >= SETTLEMENT_DIFF_THRESHOLD_CENT,
|
||||||
|
}"
|
||||||
>
|
>
|
||||||
{{ moneyCent(row.settlement_diff_amount_cent) }}
|
{{ moneyCent(row.settlement_diff_amount_cent) }}
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -17,6 +17,12 @@ export function formatDateMinute(value: DateInput, fallback = '-') {
|
|||||||
return formatted === fallback ? fallback : formatted.slice(0, 16)
|
return formatted === fallback ? fallback : formatted.slice(0, 16)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// formatInputDate 按本地时区输出 YYYY-MM-DD,供日期选择器 value-format 使用。
|
||||||
|
// 不能用 toISOString().slice(0,10),那是 UTC 日期,东八区凌晨 0-8 点会偏成前一天。
|
||||||
|
export function formatInputDate(value: Date = new Date()) {
|
||||||
|
return [value.getFullYear(), pad(value.getMonth() + 1), pad(value.getDate())].join('-')
|
||||||
|
}
|
||||||
|
|
||||||
function pad(value: number) {
|
function pad(value: number) {
|
||||||
return String(value).padStart(2, '0')
|
return String(value).padStart(2, '0')
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user