Files
medical-mall/services/analytics/couponAnalysisService.uts
2026-01-30 16:11:23 +08:00

42 lines
1.2 KiB
Plaintext

import { computeDateRange } from './dateRange.uts'
import { rpcOrEmptyArray, rpcOrNull } from './rpc.uts'
export type CouponAnalysisData = {
overviewRow: UTSJSONObject | null
typeList: Array<UTSJSONObject>
channelList: Array<UTSJSONObject>
trendList: Array<UTSJSONObject>
conversionList: Array<UTSJSONObject>
}
export async function fetchCouponAnalysis(period: string): Promise<CouponAnalysisData> {
const { startIso, endIso } = computeDateRange(period)
const overviewRow = await rpcOrNull('rpc_coupon_effectiveness_overview', {
p_start: startIso,
p_end: endIso
} as UTSJSONObject)
const typeList = await rpcOrEmptyArray('rpc_coupon_type_stats', {
p_start: startIso,
p_end: endIso
} as UTSJSONObject)
const channelList = await rpcOrEmptyArray('rpc_coupon_channel_stats', {
p_start: startIso,
p_end: endIso
} as UTSJSONObject)
const trendList = await rpcOrEmptyArray('rpc_coupon_trend_daily', {
p_start: startIso,
p_end: endIso
} as UTSJSONObject)
const conversionList = await rpcOrEmptyArray('rpc_coupon_conversion_effect', {
p_start: startIso,
p_end: endIso
} as UTSJSONObject)
return { overviewRow, typeList, channelList, trendList, conversionList }
}