大盘领券和比价广告收益卡改读服务端全量场景小计,激励视频卡改读类型小计

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
陈世睿
2026-07-05 15:03:29 +08:00
parent b620948a71
commit fd91335745
2 changed files with 11 additions and 3 deletions
+7 -3
View File
@@ -131,19 +131,23 @@ function avgEcpm(report: AdRevenueReport | null) {
function adTypeSummary(report: AdRevenueReport | null, adType: string) {
if (!report) return null;
if (report.by_ad_type?.[adType]) return report.by_ad_type[adType];
// 优先用后端全量小计 type_stats(items 受 limit 分页截断,>1000 行的区间按 items 现算会漏旧数据)
const stat = report.type_stats?.[adType];
if (stat) return { impressions: stat.impressions, revenue_yuan: stat.revenue_yuan };
const matched = report.items.filter((it) => it.ad_type === adType);
if (matched.length === 0) return null;
return {
ad_type: adType,
impressions: matched.reduce((sum, it) => sum + it.impressions, 0),
revenue_yuan: matched.reduce((sum, it) => sum + it.revenue_yuan, 0),
expected_coin: matched.reduce((sum, it) => sum + it.expected_coin, 0),
actual_coin: matched.reduce((sum, it) => sum + it.actual_coin, 0),
};
}
function adSceneSummary(report: AdRevenueReport | null, feedScene: 'coupon' | 'comparison') {
if (!report) return null;
// 优先用后端全量小计 scene_stats:2026-07-02 起 items 不再含信息流逐条展示行(唯一带收益+场景的行),
// 按 items 现算恒为 0;scene_stats 在全量 events 上聚合且不受分页截断。旧后端无此字段时回退 items 现算。
const stat = report.scene_stats?.[feedScene];
if (stat) return { impressions: stat.impressions, revenue_yuan: stat.revenue_yuan };
const matched = report.items.filter((it) => it.feed_scene === feedScene);
if (matched.length === 0) return null;
return {
+4
View File
@@ -474,6 +474,10 @@ export interface AdRevenueReport {
daily: AdRevenueDaily[]; // 按日期汇总序列(全量,供按天趋势图)
hourly: AdRevenueHourly[]; // 按小时汇总序列(全量,供按小时趋势图;按天查询时为空)
type_stats: Record<string, AdRevenueTypeStat>; // 按广告类型小计;前端取 draw / reward_video
// 按信息流场景小计(comparison/coupon/welfare;全量,不受分页截断)。数据大盘「领券广告/比价广告」卡
// 优先读它:2026-07-02 后端起 items 不再含信息流逐条展示行(唯一带收益+场景的行),按 items 现算恒 0。
// 可选(`?.` 探测)以兼容未升级后端,缺失时回退 items 现算。
scene_stats?: Record<string, AdRevenueTypeStat>;
// 可选:后端预聚合的「按广告类型」富小计(含发放金币明细)。当前后端未下发 → 数据大盘页
// (dashboard adTypeSummary)用 `?.` 探测、缺失时按 items 现算兜底;后端补上即自动启用。
by_ad_type?: Record<