数据分析ui补充完善,接入数据库
This commit is contained in:
@@ -23,8 +23,8 @@ function safeNumber(v: any): number {
|
||||
export async function fetchProductOverview(period: string): Promise<ProductOverview> {
|
||||
const { startIso, endIso } = computeDateRange(period)
|
||||
const row = await rpcOrNull('rpc_product_insights_overview', {
|
||||
p_start: startIso,
|
||||
p_end: endIso
|
||||
p_start: toDateOnly(startIso),
|
||||
p_end: toDateOnly(endIso)
|
||||
} as any)
|
||||
|
||||
const obj: any = row != null ? row : ({} as any)
|
||||
@@ -44,8 +44,7 @@ export async function fetchTopProducts(period: string, limit: number = 10): Prom
|
||||
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> = []
|
||||
@@ -55,8 +54,8 @@ export async function fetchTopProducts(period: string, limit: number = 10): Prom
|
||||
id: `${r.getAny?.('id') ?? i}`,
|
||||
rank: i + 1,
|
||||
name: `${r.getAny?.('name') ?? '未知商品'}`,
|
||||
sales: safeNumber(r.getAny?.('sales') ?? r.getAny?.('total_amount') ?? 0),
|
||||
growth: safeNumber(r.getAny?.('growth') ?? r.getAny?.('growth_rate') ?? 0)
|
||||
sales: safeNumber(r.getAny?.('sales') ?? 0),
|
||||
growth: safeNumber(r.getAny?.('growth') ?? 0)
|
||||
})
|
||||
}
|
||||
return list
|
||||
@@ -73,12 +72,12 @@ export async function fetchProductTrend(period: string, productId: string): Prom
|
||||
const out: Array<ProductTrendRow> = []
|
||||
for (let i = 0; i < rows.length; i++) {
|
||||
const r: any = rows[i]
|
||||
const date = `${r.getAny?.('date') ?? r.getAny?.('day') ?? r.getAny?.('date_key') ?? ''}`
|
||||
const date = `${r.getAny?.('date') ?? ''}`
|
||||
out.push({
|
||||
date,
|
||||
gmv: safeNumber(r.getAny?.('gmv') ?? r.getAny?.('total_amount') ?? 0),
|
||||
qty: safeNumber(r.getAny?.('qty') ?? r.getAny?.('sales_qty') ?? 0),
|
||||
orders: safeNumber(r.getAny?.('orders') ?? r.getAny?.('order_count') ?? 0)
|
||||
gmv: safeNumber(r.getAny?.('gmv') ?? 0),
|
||||
qty: safeNumber(r.getAny?.('qty') ?? 0),
|
||||
orders: safeNumber(r.getAny?.('orders') ?? 0)
|
||||
})
|
||||
}
|
||||
return out
|
||||
@@ -93,11 +92,7 @@ export async function fetchCategorySales(period: string): Promise<Array<UTSJSONO
|
||||
}
|
||||
|
||||
export async function fetchStockInsights(period: string): Promise<Array<UTSJSONObject>> {
|
||||
const { startIso, endIso } = computeDateRange(period)
|
||||
return await rpcOrEmptyArray('rpc_product_insights_stock', {
|
||||
p_start: startIso,
|
||||
p_end: endIso
|
||||
} as any)
|
||||
return await rpcOrEmptyArray('rpc_product_insights_stock', {} as any)
|
||||
}
|
||||
|
||||
export async function fetchPriceTrend(period: string): Promise<Array<UTSJSONObject>> {
|
||||
|
||||
Reference in New Issue
Block a user