diff --git a/backend/internal/modules/platformops/dto.go b/backend/internal/modules/platformops/dto.go index 06bc71bf..37295586 100644 --- a/backend/internal/modules/platformops/dto.go +++ b/backend/internal/modules/platformops/dto.go @@ -10,50 +10,63 @@ type OverviewDTO struct { } type TotalsDTO struct { - TenantCount int64 `json:"tenant_count" gorm:"column:tenant_count"` - ActiveTenantCount int64 `json:"active_tenant_count" gorm:"column:active_tenant_count"` - UserCount int64 `json:"user_count" gorm:"column:user_count"` - VerifiedUsers int64 `json:"verified_users" gorm:"column:verified_users"` - TodayNewUsers int64 `json:"today_new_users" gorm:"column:today_new_users"` - TotalListings int64 `json:"total_listings" gorm:"column:total_listings"` - PublishedListings int64 `json:"published_listings" gorm:"column:published_listings"` - TodayNewListings int64 `json:"today_new_listings" gorm:"column:today_new_listings"` - PendingReviews int64 `json:"pending_reviews" gorm:"column:pending_reviews"` - TotalOrders int64 `json:"total_orders" gorm:"column:total_orders"` - PaidOrders int64 `json:"paid_orders" gorm:"column:paid_orders"` - RentingOrders int64 `json:"renting_orders" gorm:"column:renting_orders"` - TodayOrders int64 `json:"today_orders" gorm:"column:today_orders"` - TodayGMVCent int64 `json:"today_gmv_cent" gorm:"column:today_gmv_cent"` - PaidGMVCent int64 `json:"paid_gmv_cent" gorm:"column:paid_gmv_cent"` - PendingDisputes int64 `json:"pending_disputes" gorm:"column:pending_disputes"` - PendingHandoffs int64 `json:"pending_handoffs" gorm:"column:pending_handoffs"` - PendingReturns int64 `json:"pending_returns" gorm:"column:pending_returns"` + TenantCount int64 `json:"tenant_count" gorm:"column:tenant_count"` + ActiveTenantCount int64 `json:"active_tenant_count" gorm:"column:active_tenant_count"` + UserCount int64 `json:"user_count" gorm:"column:user_count"` + VerifiedUsers int64 `json:"verified_users" gorm:"column:verified_users"` + TodayNewUsers int64 `json:"today_new_users" gorm:"column:today_new_users"` + TotalListings int64 `json:"total_listings" gorm:"column:total_listings"` + PublishedListings int64 `json:"published_listings" gorm:"column:published_listings"` + TodayNewListings int64 `json:"today_new_listings" gorm:"column:today_new_listings"` + PendingReviews int64 `json:"pending_reviews" gorm:"column:pending_reviews"` + TotalOrders int64 `json:"total_orders" gorm:"column:total_orders"` + PaidOrders int64 `json:"paid_orders" gorm:"column:paid_orders"` + RentingOrders int64 `json:"renting_orders" gorm:"column:renting_orders"` + TodayOrders int64 `json:"today_orders" gorm:"column:today_orders"` + TodayGMVCent int64 `json:"today_gmv_cent" gorm:"column:today_gmv_cent"` + PaidGMVCent int64 `json:"paid_gmv_cent" gorm:"column:paid_gmv_cent"` + PendingDisputes int64 `json:"pending_disputes" gorm:"column:pending_disputes"` + PendingHandoffs int64 `json:"pending_handoffs" gorm:"column:pending_handoffs"` + PendingReturns int64 `json:"pending_returns" gorm:"column:pending_returns"` + WalletInflowCent int64 `json:"wallet_inflow_cent" gorm:"column:wallet_inflow_cent"` + WalletOutflowCent int64 `json:"wallet_outflow_cent" gorm:"column:wallet_outflow_cent"` + TodayWalletInflowCent int64 `json:"today_wallet_inflow_cent" gorm:"column:today_wallet_inflow_cent"` + TodayWalletOutflowCent int64 `json:"today_wallet_outflow_cent" gorm:"column:today_wallet_outflow_cent"` + PendingWithdrawals int64 `json:"pending_withdrawals" gorm:"column:pending_withdrawals"` } type SiteStatsDTO struct { - TenantID uint64 `json:"tenant_id" gorm:"column:tenant_id"` - TenantCode string `json:"tenant_code"` - TenantName string `json:"tenant_name"` - Status string `json:"status"` - UserCount int64 `json:"user_count" gorm:"column:user_count"` - VerifiedUsers int64 `json:"verified_users" gorm:"column:verified_users"` - TodayNewUsers int64 `json:"today_new_users" gorm:"column:today_new_users"` - TotalListings int64 `json:"total_listings" gorm:"column:total_listings"` - PublishedListings int64 `json:"published_listings" gorm:"column:published_listings"` - PendingReviews int64 `json:"pending_reviews" gorm:"column:pending_reviews"` - BuyerOrders int64 `json:"buyer_orders" gorm:"column:buyer_orders"` - BuyerGMVCent int64 `json:"buyer_gmv_cent" gorm:"column:buyer_gmv_cent"` - SourceOrders int64 `json:"source_orders" gorm:"column:source_orders"` - SourceAmountCent int64 `json:"source_amount_cent" gorm:"column:source_amount_cent"` - RentingOrders int64 `json:"renting_orders" gorm:"column:renting_orders"` - TodayOrders int64 `json:"today_orders" gorm:"column:today_orders"` - TodayGMVCent int64 `json:"today_gmv_cent" gorm:"column:today_gmv_cent"` + TenantID uint64 `json:"tenant_id" gorm:"column:tenant_id"` + TenantCode string `json:"tenant_code"` + TenantName string `json:"tenant_name"` + Status string `json:"status"` + UserCount int64 `json:"user_count" gorm:"column:user_count"` + VerifiedUsers int64 `json:"verified_users" gorm:"column:verified_users"` + TodayNewUsers int64 `json:"today_new_users" gorm:"column:today_new_users"` + TotalListings int64 `json:"total_listings" gorm:"column:total_listings"` + PublishedListings int64 `json:"published_listings" gorm:"column:published_listings"` + TodayNewListings int64 `json:"today_new_listings" gorm:"column:today_new_listings"` + PendingReviews int64 `json:"pending_reviews" gorm:"column:pending_reviews"` + BuyerOrders int64 `json:"buyer_orders" gorm:"column:buyer_orders"` + BuyerGMVCent int64 `json:"buyer_gmv_cent" gorm:"column:buyer_gmv_cent"` + SourceOrders int64 `json:"source_orders" gorm:"column:source_orders"` + SourceAmountCent int64 `json:"source_amount_cent" gorm:"column:source_amount_cent"` + RentingOrders int64 `json:"renting_orders" gorm:"column:renting_orders"` + TodayOrders int64 `json:"today_orders" gorm:"column:today_orders"` + TodayGMVCent int64 `json:"today_gmv_cent" gorm:"column:today_gmv_cent"` + WalletInflowCent int64 `json:"wallet_inflow_cent" gorm:"column:wallet_inflow_cent"` + WalletOutflowCent int64 `json:"wallet_outflow_cent" gorm:"column:wallet_outflow_cent"` + TodayWalletInflowCent int64 `json:"today_wallet_inflow_cent" gorm:"column:today_wallet_inflow_cent"` + TodayWalletOutflowCent int64 `json:"today_wallet_outflow_cent" gorm:"column:today_wallet_outflow_cent"` + PendingWithdrawals int64 `json:"pending_withdrawals" gorm:"column:pending_withdrawals"` } type TrendPointDTO struct { - Date string `json:"date"` - NewUsers int64 `json:"new_users"` - NewListings int64 `json:"new_listings"` - Orders int64 `json:"orders"` - PaidGMVCent int64 `json:"paid_gmv_cent"` + Date string `json:"date"` + NewUsers int64 `json:"new_users"` + NewListings int64 `json:"new_listings"` + Orders int64 `json:"orders"` + PaidGMVCent int64 `json:"paid_gmv_cent"` + WalletInflowCent int64 `json:"wallet_inflow_cent"` + WalletOutflowCent int64 `json:"wallet_outflow_cent"` } diff --git a/backend/internal/modules/platformops/repository.go b/backend/internal/modules/platformops/repository.go index 7c0d078c..f70cbbb4 100644 --- a/backend/internal/modules/platformops/repository.go +++ b/backend/internal/modules/platformops/repository.go @@ -117,6 +117,20 @@ func (r *Repository) totals(db *gorm.DB, today time.Time) (*TotalsDTO, error) { Count(&result.PendingReturns).Error; err != nil { return nil, err } + if err := db.Table("wallet_ledger"). + Select(`COALESCE(SUM(CASE WHEN direction = 'in' THEN amount_cent ELSE 0 END), 0) AS wallet_inflow_cent, + COALESCE(SUM(CASE WHEN direction = 'out' THEN amount_cent ELSE 0 END), 0) AS wallet_outflow_cent, + COALESCE(SUM(CASE WHEN direction = 'in' AND created_at >= ? THEN amount_cent ELSE 0 END), 0) AS today_wallet_inflow_cent, + COALESCE(SUM(CASE WHEN direction = 'out' AND created_at >= ? THEN amount_cent ELSE 0 END), 0) AS today_wallet_outflow_cent`, today, today). + Row(). + Scan(&result.WalletInflowCent, &result.WalletOutflowCent, &result.TodayWalletInflowCent, &result.TodayWalletOutflowCent); err != nil { + return nil, err + } + if err := db.Table("withdrawal_requests"). + Where("status IN ?", []string{"pending", "processing"}). + Count(&result.PendingWithdrawals).Error; err != nil { + return nil, err + } return result, nil } @@ -137,9 +151,10 @@ func (r *Repository) siteStats(db *gorm.DB, tenant model.Tenant, today time.Time if err := db.Table("rental_listings").Where("source_tenant_id = ?", tenant.ID). Select(`COUNT(*) AS total_listings, COALESCE(SUM(status = 'published' AND review_status = 'approved'), 0) AS published_listings, - COALESCE(SUM(review_status = 'pending' AND status <> 'offline'), 0) AS pending_reviews`). + COALESCE(SUM(created_at >= ?), 0) AS today_new_listings, + COALESCE(SUM(review_status = 'pending' AND status <> 'offline'), 0) AS pending_reviews`, today). Row(). - Scan(&result.TotalListings, &result.PublishedListings, &result.PendingReviews); err != nil { + Scan(&result.TotalListings, &result.PublishedListings, &result.TodayNewListings, &result.PendingReviews); err != nil { return result, err } var orderStats struct { @@ -170,6 +185,20 @@ func (r *Repository) siteStats(db *gorm.DB, tenant model.Tenant, today time.Time result.RentingOrders = orderStats.RentingOrders result.TodayOrders = orderStats.TodayOrders result.TodayGMVCent = orderStats.TodayGMVCent + if err := db.Table("wallet_ledger").Where("tenant_id = ?", tenant.ID). + Select(`COALESCE(SUM(CASE WHEN direction = 'in' THEN amount_cent ELSE 0 END), 0) AS wallet_inflow_cent, + COALESCE(SUM(CASE WHEN direction = 'out' THEN amount_cent ELSE 0 END), 0) AS wallet_outflow_cent, + COALESCE(SUM(CASE WHEN direction = 'in' AND created_at >= ? THEN amount_cent ELSE 0 END), 0) AS today_wallet_inflow_cent, + COALESCE(SUM(CASE WHEN direction = 'out' AND created_at >= ? THEN amount_cent ELSE 0 END), 0) AS today_wallet_outflow_cent`, today, today). + Row(). + Scan(&result.WalletInflowCent, &result.WalletOutflowCent, &result.TodayWalletInflowCent, &result.TodayWalletOutflowCent); err != nil { + return result, err + } + if err := db.Table("withdrawal_requests").Where("tenant_id = ?", tenant.ID). + Where("status IN ?", []string{"pending", "processing"}). + Count(&result.PendingWithdrawals).Error; err != nil { + return result, err + } return result, nil } @@ -179,9 +208,11 @@ func (r *Repository) trend(db *gorm.DB, now time.Time, days int) ([]TrendPointDT start := end.AddDate(0, 0, -days) type row struct { - Date string `gorm:"column:date"` - Value int64 `gorm:"column:value"` - AmountCent int64 `gorm:"column:amount_cent"` + Date time.Time `gorm:"column:date"` + Value int64 `gorm:"column:value"` + AmountCent int64 `gorm:"column:amount_cent"` + InflowCent int64 `gorm:"column:inflow_cent"` + OutflowCent int64 `gorm:"column:outflow_cent"` } users := map[string]int64{} var userRows []row @@ -192,7 +223,7 @@ func (r *Repository) trend(db *gorm.DB, now time.Time, days int) ([]TrendPointDT return nil, err } for _, item := range userRows { - users[item.Date] = item.Value + users[item.Date.Format("2006-01-02")] = item.Value } listings := map[string]int64{} @@ -204,7 +235,7 @@ func (r *Repository) trend(db *gorm.DB, now time.Time, days int) ([]TrendPointDT return nil, err } for _, item := range listingRows { - listings[item.Date] = item.Value + listings[item.Date.Format("2006-01-02")] = item.Value } orders := map[string]row{} @@ -218,19 +249,36 @@ func (r *Repository) trend(db *gorm.DB, now time.Time, days int) ([]TrendPointDT return nil, err } for _, item := range orderRows { - orders[item.Date] = item + orders[item.Date.Format("2006-01-02")] = item + } + + walletTrend := map[string]row{} + var walletRows []row + if err := db.Table("wallet_ledger"). + Select(`DATE(created_at) AS date, + COALESCE(SUM(CASE WHEN direction = 'in' THEN amount_cent ELSE 0 END), 0) AS inflow_cent, + COALESCE(SUM(CASE WHEN direction = 'out' THEN amount_cent ELSE 0 END), 0) AS outflow_cent`). + Where("created_at >= ? AND created_at < ?", start, end). + Group("DATE(created_at)").Scan(&walletRows).Error; err != nil { + return nil, err + } + for _, item := range walletRows { + walletTrend[item.Date.Format("2006-01-02")] = item } result := make([]TrendPointDTO, 0, days) for date := start; date.Before(end); date = date.AddDate(0, 0, 1) { key := date.Format("2006-01-02") order := orders[key] + wallet := walletTrend[key] result = append(result, TrendPointDTO{ - Date: key, - NewUsers: users[key], - NewListings: listings[key], - Orders: order.Value, - PaidGMVCent: order.AmountCent, + Date: key, + NewUsers: users[key], + NewListings: listings[key], + Orders: order.Value, + PaidGMVCent: order.AmountCent, + WalletInflowCent: wallet.InflowCent, + WalletOutflowCent: wallet.OutflowCent, }) } return result, nil diff --git a/backend/internal/modules/platformops/repository_test.go b/backend/internal/modules/platformops/repository_test.go index b298201c..a4c3db5e 100644 --- a/backend/internal/modules/platformops/repository_test.go +++ b/backend/internal/modules/platformops/repository_test.go @@ -2,6 +2,7 @@ package platformops import ( "testing" + "time" "hfb_sys/backend/internal/database" "hfb_sys/backend/internal/model" @@ -78,6 +79,24 @@ func TestOverviewAggregatesAllTenantsAndSites(t *testing.T) { if err := db.Create(&orders).Error; err != nil { t.Fatal(err) } + now := time.Now() + ledgers := []model.WalletLedger{ + {LedgerNo: "OPS-WL-A-IN", TenantID: tenants[0].ID, UserID: users[0].ID, Direction: "in", AmountCent: 1000, BalanceType: "available", BizType: "owner_income", BizNo: "OPS-ORDER-1", CreatedAt: now}, + {LedgerNo: "OPS-WL-A-OUT", TenantID: tenants[0].ID, UserID: users[0].ID, Direction: "out", AmountCent: 200, BalanceType: "available", BizType: "withdrawal", BizNo: "OPS-WD-A", CreatedAt: now.AddDate(0, 0, -1)}, + {LedgerNo: "OPS-WL-B-IN", TenantID: tenants[1].ID, UserID: users[2].ID, Direction: "in", AmountCent: 300, BalanceType: "available", BizType: "owner_income", BizNo: "OPS-ORDER-2", CreatedAt: now}, + {LedgerNo: "OPS-WL-B-OUT", TenantID: tenants[1].ID, UserID: users[2].ID, Direction: "out", AmountCent: 100, BalanceType: "available", BizType: "withdrawal", BizNo: "OPS-WD-B", CreatedAt: now}, + } + if err := db.Create(&ledgers).Error; err != nil { + t.Fatal(err) + } + withdrawals := []model.WithdrawalRequest{ + {WithdrawNo: "OPS-WD-A", TenantID: tenants[0].ID, UserID: users[0].ID, AmountCent: 100, ActualAmountCent: 100, AccountType: "bank", AccountName: "A站用户", AccountNo: "****0001", Status: "pending"}, + {WithdrawNo: "OPS-WD-B", TenantID: tenants[1].ID, UserID: users[2].ID, AmountCent: 100, ActualAmountCent: 100, AccountType: "bank", AccountName: "B站用户", AccountNo: "****0002", Status: "processing"}, + {WithdrawNo: "OPS-WD-DONE", TenantID: tenants[1].ID, UserID: users[3].ID, AmountCent: 100, ActualAmountCent: 100, AccountType: "bank", AccountName: "B站用户", AccountNo: "****0003", Status: "completed"}, + } + if err := db.Create(&withdrawals).Error; err != nil { + t.Fatal(err) + } var userCount int64 if err := db.Model(&model.User{}).Count(&userCount).Error; err != nil || userCount != 4 { t.Fatalf("seeded users = %d, err=%v", userCount, err) @@ -95,15 +114,31 @@ func TestOverviewAggregatesAllTenantsAndSites(t *testing.T) { overview.Totals.PaidGMVCent != 1000 { t.Fatalf("overview order totals = %+v", overview.Totals) } + if overview.Totals.WalletInflowCent != 1300 || overview.Totals.WalletOutflowCent != 300 || + overview.Totals.TodayWalletInflowCent != 1300 || overview.Totals.TodayWalletOutflowCent != 100 || + overview.Totals.PendingWithdrawals != 2 { + t.Fatalf("overview wallet totals = %+v", overview.Totals) + } if len(overview.Sites) != 2 || len(overview.Trend) != 7 { t.Fatalf("sites=%d trend=%d", len(overview.Sites), len(overview.Trend)) } if overview.Sites[0].UserCount != 2 || overview.Sites[0].BuyerOrders != 1 || - overview.Sites[0].SourceOrders != 0 { + overview.Sites[0].SourceOrders != 0 || overview.Sites[0].TodayNewListings != 1 || + overview.Sites[0].WalletInflowCent != 1000 || overview.Sites[0].WalletOutflowCent != 200 || + overview.Sites[0].PendingWithdrawals != 1 { t.Fatalf("site A stats = %+v", overview.Sites[0]) } if overview.Sites[1].UserCount != 2 || overview.Sites[1].BuyerOrders != 0 || - overview.Sites[1].SourceOrders != 1 { + overview.Sites[1].SourceOrders != 1 || overview.Sites[1].TodayNewListings != 1 || + overview.Sites[1].WalletInflowCent != 300 || overview.Sites[1].WalletOutflowCent != 100 || + overview.Sites[1].TodayWalletInflowCent != 300 || overview.Sites[1].TodayWalletOutflowCent != 100 || + overview.Sites[1].PendingWithdrawals != 1 { t.Fatalf("site B stats = %+v", overview.Sites[1]) } + todayTrend := overview.Trend[6] + if todayTrend.NewUsers != 4 || todayTrend.NewListings != 2 || + todayTrend.Orders != 1 || todayTrend.PaidGMVCent != 1000 || + todayTrend.WalletInflowCent != 1300 || todayTrend.WalletOutflowCent != 100 { + t.Fatalf("today trend = %+v", todayTrend) + } } diff --git a/frontend/src/features/admin/api/platformOps.ts b/frontend/src/features/admin/api/platformOps.ts index 42eae16b..4dda55c6 100644 --- a/frontend/src/features/admin/api/platformOps.ts +++ b/frontend/src/features/admin/api/platformOps.ts @@ -20,6 +20,11 @@ export interface PlatformTotals { pending_disputes: number pending_handoffs: number pending_returns: number + wallet_inflow_cent: number + wallet_outflow_cent: number + today_wallet_inflow_cent: number + today_wallet_outflow_cent: number + pending_withdrawals: number } export interface PlatformSiteStats { @@ -32,6 +37,7 @@ export interface PlatformSiteStats { today_new_users: number total_listings: number published_listings: number + today_new_listings: number pending_reviews: number buyer_orders: number buyer_gmv_cent: number @@ -40,6 +46,11 @@ export interface PlatformSiteStats { renting_orders: number today_orders: number today_gmv_cent: number + wallet_inflow_cent: number + wallet_outflow_cent: number + today_wallet_inflow_cent: number + today_wallet_outflow_cent: number + pending_withdrawals: number } export interface PlatformTrendPoint { @@ -48,6 +59,8 @@ export interface PlatformTrendPoint { new_listings: number orders: number paid_gmv_cent: number + wallet_inflow_cent: number + wallet_outflow_cent: number } export interface PlatformOverview { diff --git a/frontend/src/features/admin/views/AdminPlatformOverviewView.vue b/frontend/src/features/admin/views/AdminPlatformOverviewView.vue index bc7edf00..46b2945b 100644 --- a/frontend/src/features/admin/views/AdminPlatformOverviewView.vue +++ b/frontend/src/features/admin/views/AdminPlatformOverviewView.vue @@ -3,12 +3,16 @@ import { Calendar, Coin, DataLine, + DocumentChecked, Refresh, Shop, + Tickets, TrendCharts, User, + Wallet, Warning, } from '@element-plus/icons-vue' +import type { Component } from 'vue' import { computed, onMounted, ref } from 'vue' import { @@ -20,15 +24,278 @@ import { formatCentWithSymbol } from '@/shared/utils/money' import { formatDateTime } from '@/shared/utils/time' import { readError } from '@/shared/utils/error' +type PlatformMode = 'overview' | 'users' | 'listings' | 'trade' | 'finance' +type MetricTone = 'blue' | 'green' | 'amber' | 'red' + +interface MetricCard { + label: string + value: string + detail: string + icon: Component + tone: MetricTone +} + +const props = withDefaults(defineProps<{ mode?: PlatformMode }>(), { + mode: 'overview', +}) + const loading = ref(false) const error = ref('') const overview = ref(null) -const trendMaxOrders = computed(() => - Math.max(1, ...(overview.value?.trend || []).map(item => item.orders)) +const modeCopy: Record = { + overview: { + eyebrow: 'PLATFORM OVERVIEW', + title: '平台运营总览', + description: '汇总大锤商行、解忧商行及后续经营站点的核心经营数据,仅用于查看统计。', + }, + users: { + eyebrow: 'PLATFORM USERS', + title: '平台用户统计', + description: '按经营站点查看用户存量、实名认证和今日新增,不提供用户资料或管理操作。', + }, + listings: { + eyebrow: 'PLATFORM LISTINGS', + title: '平台商品统计', + description: '按商品的来源经营站点查看供给、在售、审核和今日新增情况。', + }, + trade: { + eyebrow: 'PLATFORM TRADE', + title: '平台交易统计', + description: '分别统计各站点的买入订单和出货订单,并汇总平台有效成交与今日交易。', + }, + finance: { + eyebrow: 'PLATFORM FINANCE', + title: '平台资金统计', + description: '按经营站点查看钱包流水与待处理提现,仅展示汇总,不展示账户和提现明细。', + }, +} + +const copy = computed(() => modeCopy[props.mode]) + +const metrics = computed(() => { + const totals = overview.value?.totals + if (!totals) return [] + + if (props.mode === 'users') { + return [ + { + label: '平台用户', + value: totals.user_count.toLocaleString(), + detail: `${totals.active_tenant_count} 个经营站点独立统计`, + icon: User, + tone: 'blue', + }, + { + label: '实名用户', + value: totals.verified_users.toLocaleString(), + detail: `实名率 ${percentage(totals.verified_users, totals.user_count)}`, + icon: DocumentChecked, + tone: 'green', + }, + { + label: '今日新增', + value: totals.today_new_users.toLocaleString(), + detail: '按北京时间自然日统计', + icon: Calendar, + tone: 'amber', + }, + { + label: '经营站点', + value: totals.active_tenant_count.toLocaleString(), + detail: `共 ${totals.tenant_count} 个站点`, + icon: Shop, + tone: 'blue', + }, + ] + } + + if (props.mode === 'listings') { + return [ + { + label: '商品总数', + value: totals.total_listings.toLocaleString(), + detail: '各经营站点商品合计', + icon: Shop, + tone: 'blue', + }, + { + label: '在售商品', + value: totals.published_listings.toLocaleString(), + detail: `在售率 ${percentage(totals.published_listings, totals.total_listings)}`, + icon: TrendCharts, + tone: 'green', + }, + { + label: '待审核', + value: totals.pending_reviews.toLocaleString(), + detail: '由商品来源站点后台处理', + icon: DocumentChecked, + tone: 'amber', + }, + { + label: '今日新增', + value: totals.today_new_listings.toLocaleString(), + detail: '按商品创建时间统计', + icon: Calendar, + tone: 'blue', + }, + ] + } + + if (props.mode === 'trade') { + return [ + { + label: '有效订单', + value: totals.paid_orders.toLocaleString(), + detail: `全部订单 ${totals.total_orders.toLocaleString()} 笔`, + icon: Tickets, + tone: 'blue', + }, + { + label: '累计成交额', + value: formatCentWithSymbol(totals.paid_gmv_cent), + detail: '按订单租金金额汇总', + icon: Coin, + tone: 'green', + }, + { + label: '今日成交额', + value: formatCentWithSymbol(totals.today_gmv_cent), + detail: `今日订单 ${totals.today_orders.toLocaleString()} 笔`, + icon: Calendar, + tone: 'amber', + }, + { + label: '租用中', + value: totals.renting_orders.toLocaleString(), + detail: '当前进行中的租用订单', + icon: TrendCharts, + tone: 'blue', + }, + { + label: '待处理事项', + value: `${totals.pending_handoffs + totals.pending_returns + totals.pending_disputes}`, + detail: `交接 ${totals.pending_handoffs} · 归还 ${totals.pending_returns} · 申诉 ${totals.pending_disputes}`, + icon: Warning, + tone: 'red', + }, + ] + } + + if (props.mode === 'finance') { + return [ + { + label: '累计钱包流入', + value: formatCentWithSymbol(totals.wallet_inflow_cent), + detail: '钱包流水 direction=in', + icon: Wallet, + tone: 'green', + }, + { + label: '累计钱包流出', + value: formatCentWithSymbol(totals.wallet_outflow_cent), + detail: '钱包流水 direction=out', + icon: Wallet, + tone: 'amber', + }, + { + label: '今日流入', + value: formatCentWithSymbol(totals.today_wallet_inflow_cent), + detail: '按北京时间自然日统计', + icon: Calendar, + tone: 'green', + }, + { + label: '今日流出', + value: formatCentWithSymbol(totals.today_wallet_outflow_cent), + detail: '按北京时间自然日统计', + icon: Calendar, + tone: 'amber', + }, + { + label: '待处理提现', + value: totals.pending_withdrawals.toLocaleString(), + detail: '待审核与待打款申请', + icon: Coin, + tone: 'red', + }, + { + label: '待处理申诉', + value: totals.pending_disputes.toLocaleString(), + detail: '可能影响资金结算', + icon: Warning, + tone: 'red', + }, + ] + } + + return [ + { + label: '经营站点', + value: totals.active_tenant_count.toLocaleString(), + detail: `共 ${totals.tenant_count} 个站点`, + icon: Shop, + tone: 'blue', + }, + { + label: '平台用户', + value: totals.user_count.toLocaleString(), + detail: `实名 ${totals.verified_users.toLocaleString()} · 今日新增 ${totals.today_new_users.toLocaleString()}`, + icon: User, + tone: 'blue', + }, + { + label: '在售商品', + value: totals.published_listings.toLocaleString(), + detail: `商品总数 ${totals.total_listings.toLocaleString()} · 待审核 ${totals.pending_reviews.toLocaleString()}`, + icon: TrendCharts, + tone: 'green', + }, + { + label: '累计成交额', + value: formatCentWithSymbol(totals.paid_gmv_cent), + detail: `有效订单 ${totals.paid_orders.toLocaleString()} 笔`, + icon: Coin, + tone: 'green', + }, + { + label: '今日成交', + value: formatCentWithSymbol(totals.today_gmv_cent), + detail: `今日订单 ${totals.today_orders.toLocaleString()} 笔`, + icon: Calendar, + tone: 'amber', + }, + ] +}) + +const trendTitle = computed(() => { + if (props.mode === 'users') return '近 7 日用户增长' + if (props.mode === 'listings') return '近 7 日商品新增' + if (props.mode === 'trade') return '近 7 日交易趋势' + if (props.mode === 'finance') return '近 7 日钱包流水' + return '近 7 日平台趋势' +}) + +const trendPrimaryLabel = computed(() => { + if (props.mode === 'users') return '新增用户' + if (props.mode === 'listings') return '新增商品' + if (props.mode === 'finance') return '钱包流入' + return '有效订单' +}) + +const trendSecondaryLabel = computed(() => { + if (props.mode === 'finance') return '钱包流出' + return '成交额' +}) + +const showSecondaryTrend = computed(() => ['overview', 'trade', 'finance'].includes(props.mode)) + +const trendMaxPrimary = computed(() => + Math.max(1, ...(overview.value?.trend || []).map(item => primaryTrendValue(item))) ) -const trendMaxGMV = computed(() => - Math.max(1, ...(overview.value?.trend || []).map(item => item.paid_gmv_cent)) +const trendMaxSecondary = computed(() => + Math.max(1, ...(overview.value?.trend || []).map(item => secondaryTrendValue(item) || 0)) ) async function loadOverview() { @@ -43,7 +310,13 @@ async function loadOverview() { } } -function barHeight(value: number, max: number) { +function percentage(part: number, total: number) { + if (total <= 0) return '0%' + return `${Math.round((part / total) * 100)}%` +} + +function barHeight(value: number | null, max: number) { + if (!value || value <= 0) return '0%' return `${Math.max(8, Math.round((value / max) * 100))}%` } @@ -51,10 +324,48 @@ function shortDate(value: string) { return value.length >= 10 ? value.slice(5) : value } -function trendOrders(row: PlatformTrendPoint) { +function primaryTrendValue(row: PlatformTrendPoint) { + if (props.mode === 'users') return row.new_users + if (props.mode === 'listings') return row.new_listings + if (props.mode === 'finance') return row.wallet_inflow_cent return row.orders } +function secondaryTrendValue(row: PlatformTrendPoint) { + if (!showSecondaryTrend.value) return null + if (props.mode === 'finance') return row.wallet_outflow_cent + return row.paid_gmv_cent +} + +function primaryTrendText(row: PlatformTrendPoint) { + const value = primaryTrendValue(row) + if (props.mode === 'finance') return `流入 ${formatCentWithSymbol(value)}` + if (props.mode === 'users') return `新增 ${value} 人` + if (props.mode === 'listings') return `新增 ${value} 个` + return `${value} 单` +} + +function secondaryTrendText(row: PlatformTrendPoint) { + const value = secondaryTrendValue(row) + if (value === null) return '' + if (props.mode === 'finance') return `流出 ${formatCentWithSymbol(value)}` + return formatCentWithSymbol(value) +} + +function trendFoot(row: PlatformTrendPoint) { + const totals = overview.value?.totals + if (!totals) return '' + if (props.mode === 'overview') { + return `用户 +${row.new_users} · 商品 +${row.new_listings}` + } + if (props.mode === 'users') return `实名存量 ${totals.verified_users}` + if (props.mode === 'listings') return `待审核 ${totals.pending_reviews}` + if (props.mode === 'trade') { + return `待交接 ${totals.pending_handoffs} · 待归还 ${totals.pending_returns}` + } + return `待提现 ${totals.pending_withdrawals}` +} + onMounted(loadOverview) @@ -64,10 +375,10 @@ onMounted(loadOverview)

- PLATFORM OVERVIEW + {{ copy.eyebrow }}

-

平台运营总览

-

汇总大锤商行、解忧商行及后续经营站点的核心经营数据,仅用于查看统计。

+

{{ copy.title }}

+

{{ copy.description }}

@@ -90,55 +401,22 @@ onMounted(loadOverview)