数据分析ui补充完善,接入数据库
This commit is contained in:
@@ -24,22 +24,9 @@ function safeNumber(v: any): number {
|
||||
|
||||
export async function fetchSalesKpis(period: string): Promise<SalesKpis> {
|
||||
const { startIso, endIso } = computeDateRange(period)
|
||||
const days = period === '7d' ? 7 : period === '30d' ? 30 : period === '90d' ? 90 : 365
|
||||
|
||||
const startDateObj = new Date(startIso)
|
||||
const endDateObj = new Date(endIso)
|
||||
|
||||
const periodStart = new Date(startDateObj.getFullYear(), startDateObj.getMonth(), startDateObj.getDate())
|
||||
const periodEnd = new Date(endDateObj.getFullYear(), endDateObj.getMonth(), endDateObj.getDate() + 1)
|
||||
const prevStart = new Date(periodStart.getTime() - days * 24 * 60 * 60 * 1000)
|
||||
const prevEnd = new Date(periodStart.getTime())
|
||||
|
||||
const row = await rpcOrNull('rpc_analytics_realtime_kpis', {
|
||||
p_start: periodStart.toISOString(),
|
||||
p_end: periodEnd.toISOString(),
|
||||
p_compare_start: prevStart.toISOString(),
|
||||
p_compare_end: prevEnd.toISOString(),
|
||||
p_merchant_id: null
|
||||
const row = await rpcOrNull('rpc_analytics_sales_kpis', {
|
||||
p_start_date: toDateOnly(startIso),
|
||||
p_end_date: toDateOnly(endIso)
|
||||
} as any)
|
||||
|
||||
const obj: any = row != null ? row : ({} as any)
|
||||
@@ -61,10 +48,9 @@ export async function fetchSalesKpis(period: string): Promise<SalesKpis> {
|
||||
|
||||
export async function fetchSalesTrend(period: string): Promise<TrendData> {
|
||||
const { startIso, endIso } = computeDateRange(period)
|
||||
const rows = await rpcOrEmptyArray('rpc_analytics_trend_data', {
|
||||
const rows = await rpcOrEmptyArray('rpc_analytics_sales_trend', {
|
||||
p_start_date: toDateOnly(startIso),
|
||||
p_end_date: toDateOnly(endIso),
|
||||
p_merchant_id: null
|
||||
p_end_date: toDateOnly(endIso)
|
||||
} as any)
|
||||
|
||||
const x: Array<string> = []
|
||||
@@ -87,8 +73,7 @@ export async function fetchSalesTopProducts(period: string, limit: number = 50):
|
||||
const rows = await rpcOrEmptyArray('rpc_analytics_top_products', {
|
||||
p_start_date: toDateOnly(startIso),
|
||||
p_end_date: toDateOnly(endIso),
|
||||
p_limit: limit,
|
||||
p_merchant_id: null
|
||||
p_limit: limit
|
||||
} as any)
|
||||
|
||||
const list: Array<ProductRank> = []
|
||||
|
||||
Reference in New Issue
Block a user