Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 70216b6fae | |||
| a286f859ee | |||
| 549c9bdfad | |||
| 26b1adb769 | |||
| 0040c5795d | |||
| 5acfb05c57 | |||
| bea35fb707 | |||
| 93c3daa784 | |||
| 63538ddee2 | |||
| d057f75b90 | |||
| 453d1981c7 |
@@ -32,9 +32,24 @@ interface Props {
|
||||
onClose: () => void;
|
||||
userId: number | null;
|
||||
phone: string | null; // 报表行已有的手机号:概览拉取失败时兜底展示
|
||||
dateFrom: string | null;
|
||||
dateTo: string | null;
|
||||
appEnv?: 'prod' | 'test';
|
||||
revenueScope: 'business' | 'all';
|
||||
feedScene?: 'comparison' | 'coupon' | 'welfare';
|
||||
}
|
||||
|
||||
export default function UserAdRevenueDrawer({ open, onClose, userId, phone }: Props) {
|
||||
export default function UserAdRevenueDrawer({
|
||||
open,
|
||||
onClose,
|
||||
userId,
|
||||
phone,
|
||||
dateFrom,
|
||||
dateTo,
|
||||
appEnv,
|
||||
revenueScope,
|
||||
feedScene,
|
||||
}: Props) {
|
||||
// UserRewardPanel 的 user 快照:它只读 phone/nickname/wechat_nickname/created_at,其余按 snapshot 形状补齐。
|
||||
const [user, setUser] = useState<WithdrawUserSnapshot | null>(null);
|
||||
|
||||
@@ -82,7 +97,19 @@ export default function UserAdRevenueDrawer({ open, onClose, userId, phone }: Pr
|
||||
>
|
||||
{/* userId 就绪即渲染;UserRewardPanel 内部按 userId 自行拉统计与金币记录,user 基本信息随后补上。
|
||||
statsVariant="ad":统计区只显示 6 项看广告统计(累计提现/现金余额/激励视频观看数+eCPM/draw观看数+eCPM) */}
|
||||
{userId != null && <UserRewardPanel userId={userId} user={user} statsVariant="ad" />}
|
||||
{userId != null && (
|
||||
<UserRewardPanel
|
||||
key={`${userId}-${dateFrom}-${dateTo}-${appEnv}-${revenueScope}-${feedScene}`}
|
||||
userId={userId}
|
||||
user={user}
|
||||
statsVariant="ad"
|
||||
initialDateFrom={dateFrom ?? undefined}
|
||||
initialDateTo={dateTo ?? undefined}
|
||||
appEnv={appEnv}
|
||||
revenueScope={revenueScope}
|
||||
feedScene={feedScene}
|
||||
/>
|
||||
)}
|
||||
</Drawer>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ import {
|
||||
} from '@ant-design/icons';
|
||||
import dayjs, { type Dayjs } from 'dayjs';
|
||||
import { api, errMsg } from '@/lib/api';
|
||||
import { formatUtcTime, percentile } from '@/lib/format';
|
||||
import { formatUtcTime, nearestRankPercentile } from '@/lib/format';
|
||||
import type {
|
||||
AdRevenueDaily,
|
||||
AdRevenueHourly,
|
||||
@@ -470,7 +470,27 @@ export default function AdRevenueReportPage() {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [formulaOpen, setFormulaOpen] = useState(false);
|
||||
// 点用户手机号弹出的「用户广告收益详情」半屏抽屉(userId + 手机号;null=关闭)
|
||||
const [userDrawer, setUserDrawer] = useState<{ userId: number; phone: string | null } | null>(null);
|
||||
const [userDrawer, setUserDrawer] = useState<{
|
||||
userId: number;
|
||||
phone: string | null;
|
||||
dateFrom: string;
|
||||
dateTo: string;
|
||||
appEnv?: 'prod' | 'test';
|
||||
revenueScope: 'business' | 'all';
|
||||
feedScene?: 'comparison' | 'coupon' | 'welfare';
|
||||
} | null>(null);
|
||||
const [queriedDetailFilters, setQueriedDetailFilters] = useState<{
|
||||
dateFrom: string;
|
||||
dateTo: string;
|
||||
appEnv?: 'prod' | 'test';
|
||||
revenueScope: 'business' | 'all';
|
||||
feedScene?: 'comparison' | 'coupon' | 'welfare';
|
||||
}>({
|
||||
dateFrom: range[0].format('YYYY-MM-DD'),
|
||||
dateTo: range[1].format('YYYY-MM-DD'),
|
||||
appEnv: 'prod',
|
||||
revenueScope: 'business',
|
||||
});
|
||||
|
||||
// 当前选择是否跨多天:跨多天时「按小时」无意义,粒度强制按天
|
||||
const rangeMultiDay = range[0].format('YYYY-MM-DD') !== range[1].format('YYYY-MM-DD');
|
||||
@@ -503,6 +523,13 @@ export default function AdRevenueReportPage() {
|
||||
},
|
||||
});
|
||||
setData(res.data);
|
||||
setQueriedDetailFilters({
|
||||
dateFrom: from,
|
||||
dateTo: to,
|
||||
appEnv: appEnv === 'all' ? undefined : appEnv,
|
||||
revenueScope,
|
||||
feedScene: scene as 'comparison' | 'coupon' | 'welfare' | undefined,
|
||||
});
|
||||
setPage(targetPage);
|
||||
setQueriedLimit(targetLimit);
|
||||
setQueriedGranularity(gran);
|
||||
@@ -551,7 +578,7 @@ export default function AdRevenueReportPage() {
|
||||
width: 150,
|
||||
render: (phone: string | null, r: AdRevenueRow) => (
|
||||
// 点手机号/用户 → 打开该用户「广告收益详情」半屏抽屉(统计卡 + 金币记录)
|
||||
<a onClick={() => setUserDrawer({ userId: r.user_id, phone })}>
|
||||
<a onClick={() => setUserDrawer({ userId: r.user_id, phone, ...queriedDetailFilters })}>
|
||||
{phone ? (
|
||||
<span>
|
||||
{phone}
|
||||
@@ -735,7 +762,7 @@ export default function AdRevenueReportPage() {
|
||||
: `${data.date_from} ~ ${data.date_to}`;
|
||||
|
||||
// 第二行大盘「分广告类型」:看视频包含福利视频与提现视频;
|
||||
// eCPM 使用合并后的总收益 ÷ 总展示数 × 1000,避免只读取 reward_video 而漏算提现视频。
|
||||
// eCPM 优先使用后端按真实展示加权的经营分类口径;兼容旧后端时才用合并收益÷展示数回退。
|
||||
const drawStat = data?.type_stats?.draw;
|
||||
const rewardVideoStat = data?.type_stats?.reward_video;
|
||||
const withdrawalVideoStat = data?.type_stats?.withdrawal_video;
|
||||
@@ -745,8 +772,10 @@ export default function AdRevenueReportPage() {
|
||||
revenue_yuan:
|
||||
(rewardVideoStat?.revenue_yuan ?? 0) + (withdrawalVideoStat?.revenue_yuan ?? 0),
|
||||
};
|
||||
const drawEcpmStat = data?.category_stats?.draw ?? drawStat;
|
||||
const videoEcpmStat = data?.category_stats?.video ?? videoStat;
|
||||
const ecpmOf = (s?: AdRevenueTypeStat) =>
|
||||
s && s.impressions > 0 ? (s.revenue_yuan / s.impressions) * 1000 : 0;
|
||||
s?.ecpm_yuan ?? (s && s.impressions > 0 ? (s.revenue_yuan / s.impressions) * 1000 : 0);
|
||||
|
||||
// 明细直接用后端返回的当前页 items(「场景」已由后端 feed_scene 全局过滤,前端不再二次筛)。
|
||||
const items = data?.items ?? [];
|
||||
@@ -756,9 +785,9 @@ export default function AdRevenueReportPage() {
|
||||
.filter((item) => item.feed_scene === sceneName)
|
||||
.map((item) => item.sub_count ?? 1);
|
||||
return {
|
||||
p5: percentile(counts, 0.05, false),
|
||||
p50: percentile(counts, 0.5, false),
|
||||
p95: percentile(counts, 0.95, false),
|
||||
p5: nearestRankPercentile(counts, 0.05),
|
||||
p50: nearestRankPercentile(counts, 0.5),
|
||||
p95: nearestRankPercentile(counts, 0.95),
|
||||
};
|
||||
};
|
||||
return { coupon: summarize('coupon'), comparison: summarize('comparison') };
|
||||
@@ -1060,7 +1089,7 @@ export default function AdRevenueReportPage() {
|
||||
<Statistic title="Draw 信息流收益(元)" value={drawStat?.revenue_yuan ?? 0} precision={4} />
|
||||
</Col>
|
||||
<Col span={4}>
|
||||
<Statistic title="Draw 信息流 eCPM(元/千次)" value={ecpmOf(drawStat)} precision={2} />
|
||||
<Statistic title="Draw 信息流 eCPM(元/千次)" value={ecpmOf(drawEcpmStat)} precision={2} />
|
||||
</Col>
|
||||
<Col span={4}>
|
||||
<Statistic title="Draw 信息流条数" value={drawStat?.impressions ?? 0} />
|
||||
@@ -1069,7 +1098,7 @@ export default function AdRevenueReportPage() {
|
||||
<Statistic title="看视频收益(元)" value={videoStat.revenue_yuan} precision={4} />
|
||||
</Col>
|
||||
<Col span={4}>
|
||||
<Statistic title="看视频 eCPM(元/千次)" value={ecpmOf(videoStat)} precision={2} />
|
||||
<Statistic title="看视频 eCPM(元/千次)" value={ecpmOf(videoEcpmStat)} precision={2} />
|
||||
</Col>
|
||||
<Col span={4}>
|
||||
<Statistic title="看视频条数" value={videoStat.impressions} />
|
||||
@@ -1081,12 +1110,12 @@ export default function AdRevenueReportPage() {
|
||||
</Typography.Text>
|
||||
</Divider>
|
||||
<Row gutter={[16, 12]}>
|
||||
<Col span={4}><Statistic title="单次领券广告数 P5" value={sessionAdCounts.coupon.p5 ?? '-'} precision={1} /></Col>
|
||||
<Col span={4}><Statistic title="单次领券广告数 P50" value={sessionAdCounts.coupon.p50 ?? '-'} precision={1} /></Col>
|
||||
<Col span={4}><Statistic title="单次领券广告数 P95" value={sessionAdCounts.coupon.p95 ?? '-'} precision={1} /></Col>
|
||||
<Col span={4}><Statistic title="单次比价广告数 P5" value={sessionAdCounts.comparison.p5 ?? '-'} precision={1} /></Col>
|
||||
<Col span={4}><Statistic title="单次比价广告数 P50" value={sessionAdCounts.comparison.p50 ?? '-'} precision={1} /></Col>
|
||||
<Col span={4}><Statistic title="单次比价广告数 P95" value={sessionAdCounts.comparison.p95 ?? '-'} precision={1} /></Col>
|
||||
<Col span={4}><Statistic title="单次领券广告数 P5" value={sessionAdCounts.coupon.p5 ?? '-'} precision={0} /></Col>
|
||||
<Col span={4}><Statistic title="单次领券广告数 P50" value={sessionAdCounts.coupon.p50 ?? '-'} precision={0} /></Col>
|
||||
<Col span={4}><Statistic title="单次领券广告数 P95" value={sessionAdCounts.coupon.p95 ?? '-'} precision={0} /></Col>
|
||||
<Col span={4}><Statistic title="单次比价广告数 P5" value={sessionAdCounts.comparison.p5 ?? '-'} precision={0} /></Col>
|
||||
<Col span={4}><Statistic title="单次比价广告数 P50" value={sessionAdCounts.comparison.p50 ?? '-'} precision={0} /></Col>
|
||||
<Col span={4}><Statistic title="单次比价广告数 P95" value={sessionAdCounts.comparison.p95 ?? '-'} precision={0} /></Col>
|
||||
</Row>
|
||||
</Card>
|
||||
)}
|
||||
@@ -1282,6 +1311,11 @@ export default function AdRevenueReportPage() {
|
||||
open={!!userDrawer}
|
||||
userId={userDrawer?.userId ?? null}
|
||||
phone={userDrawer?.phone ?? null}
|
||||
dateFrom={userDrawer?.dateFrom ?? null}
|
||||
dateTo={userDrawer?.dateTo ?? null}
|
||||
appEnv={userDrawer?.appEnv}
|
||||
revenueScope={userDrawer?.revenueScope ?? 'all'}
|
||||
feedScene={userDrawer?.feedScene}
|
||||
onClose={() => setUserDrawer(null)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -46,6 +46,41 @@ const fmtTok = (inTok: number | null, outTok: number | null) =>
|
||||
inTok == null && outTok == null ? '-' : `${inTok ?? 0}/${outTok ?? 0}`;
|
||||
const fmtRate = (value: number | null) => (value == null ? '-' : `${(value * 100).toFixed(1)}%`);
|
||||
|
||||
function deviceName(record: ComparisonRecordListItem): string {
|
||||
return record.device_model_name || record.device_model || '-';
|
||||
}
|
||||
|
||||
function romName(record: ComparisonRecordListItem): string {
|
||||
return [
|
||||
record.rom_vendor,
|
||||
record.rom_name,
|
||||
record.rom_version != null ? String(record.rom_version) : null,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(' ') || '-';
|
||||
}
|
||||
|
||||
function renderDevice(record: ComparisonRecordListItem): ReactNode {
|
||||
const readableName = deviceName(record);
|
||||
const showRawModel =
|
||||
record.device_model_name
|
||||
&& record.device_model
|
||||
&& record.device_model_name !== record.device_model;
|
||||
return (
|
||||
<Space direction="vertical" size={0}>
|
||||
<span>{readableName}</span>
|
||||
{showRawModel ? (
|
||||
<Typography.Text type="secondary" style={{ fontSize: 12 }}>
|
||||
{record.device_model}
|
||||
</Typography.Text>
|
||||
) : null}
|
||||
<Typography.Text type="secondary" style={{ fontSize: 12 }}>
|
||||
{romName(record)}
|
||||
</Typography.Text>
|
||||
</Space>
|
||||
);
|
||||
}
|
||||
|
||||
// LLM 价格快照只展示 prices 里各模型的单价(元/每百万 token),忽略 mode/_source 等元字段。
|
||||
function llmPriceRows(snapshot: Record<string, unknown> | null): string[] {
|
||||
const prices = snapshot?.prices;
|
||||
@@ -298,6 +333,14 @@ export default function ComparisonRecordsPage() {
|
||||
<b style={{ color: r.saved_amount_cents > 0 ? '#3f8600' : '#999' }}>{yuan(r.saved_amount_cents)}</b>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '是否下单',
|
||||
dataIndex: 'ordered',
|
||||
width: 84,
|
||||
render: (ordered: boolean) => (
|
||||
<Tag color={ordered ? 'green' : 'default'}>{ordered ? '已下单' : '未下单'}</Tag>
|
||||
),
|
||||
},
|
||||
{ title: 'LLM', dataIndex: 'llm_call_count', width: 56, render: (v) => v ?? '-' },
|
||||
{
|
||||
title: 'TOKEN',
|
||||
@@ -308,9 +351,9 @@ export default function ComparisonRecordsPage() {
|
||||
{
|
||||
title: '机型/ROM',
|
||||
key: 'device',
|
||||
width: 150,
|
||||
width: 180,
|
||||
ellipsis: true,
|
||||
render: (_, r) => [r.device_model, r.rom_name].filter(Boolean).join(' / ') || '-',
|
||||
render: (_, r) => renderDevice(r),
|
||||
},
|
||||
{
|
||||
title: 'traceid',
|
||||
@@ -499,8 +542,15 @@ export default function ComparisonRecordsPage() {
|
||||
|
||||
<Card size="small" title="设备环境">
|
||||
<Descriptions size="small" column={2}>
|
||||
<Descriptions.Item label="机型">{detail.device_model || '-'}({detail.device_manufacturer || '-'})</Descriptions.Item>
|
||||
<Descriptions.Item label="ROM">{[detail.rom_vendor, detail.rom_name, detail.rom_version].filter(Boolean).join(' ') || '-'}</Descriptions.Item>
|
||||
<Descriptions.Item label="机型">
|
||||
{deviceName(detail)}
|
||||
{detail.device_model_name && detail.device_model_name !== detail.device_model
|
||||
? `(${[detail.device_manufacturer, detail.device_model].filter(Boolean).join(' · ')})`
|
||||
: detail.device_manufacturer
|
||||
? `(${detail.device_manufacturer})`
|
||||
: ''}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="ROM">{romName(detail)}</Descriptions.Item>
|
||||
<Descriptions.Item label="Android">{detail.android_version || '-'}(SDK {detail.android_sdk ?? '-'})</Descriptions.Item>
|
||||
<Descriptions.Item label="App 版本">{detail.app_version || '-'}({detail.app_version_code ?? '-'})</Descriptions.Item>
|
||||
<Descriptions.Item label="源 App 版本" span={2}>{detail.source_app_version || '-'}</Descriptions.Item>
|
||||
|
||||
@@ -710,7 +710,7 @@ export default function DashboardPage() {
|
||||
<div>
|
||||
<h1>数据大盘</h1>
|
||||
<p>
|
||||
数据更新于 {updatedAt ?? '--'} · 北京时间 · 日期窗口按 00:00 自然日切分,不包含今日
|
||||
数据更新于 {updatedAt ?? '--'} · 北京时间 · 日期窗口按 00:00 自然日切分,自定义日期可选择今日
|
||||
</p>
|
||||
</div>
|
||||
<div className="controls">
|
||||
@@ -734,7 +734,7 @@ export default function DashboardPage() {
|
||||
format="YYYY-MM-DD"
|
||||
allowClear={false}
|
||||
open={datePickerOpen}
|
||||
disabledDate={(date) => date.isAfter(dayjs().subtract(1, 'day'), 'day')}
|
||||
disabledDate={(date) => date.isAfter(dayjs(), 'day')}
|
||||
suffixIcon={<CalendarOutlined />}
|
||||
onClick={() => setDatePickerOpen(true)}
|
||||
onOpenChange={setDatePickerOpen}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import type { ColumnsType } from 'antd/es/table';
|
||||
import type { SorterResult } from 'antd/es/table/interface';
|
||||
import {
|
||||
@@ -35,6 +35,7 @@ import UserRecordsDrawer from '@/components/UserRecordsDrawer';
|
||||
const { Text, Paragraph } = Typography;
|
||||
const { RangePicker } = DatePicker;
|
||||
const REWARD_MAX = 10000;
|
||||
const REVIEW_PAGE_POLL_INTERVAL_MS = 60_000;
|
||||
|
||||
// 截图是 app-server 的 /media 相对路径,本地由 :8770 提供(NEXT_PUBLIC_MEDIA_BASE);生产同域走 nginx 代理。
|
||||
const MEDIA_BASE = process.env.NEXT_PUBLIC_MEDIA_BASE || '';
|
||||
@@ -196,6 +197,10 @@ export default function FeedbacksPage() {
|
||||
const filters: Record<string, unknown> = { ...applied, sort_by: sortBy, sort_order: sortOrder };
|
||||
const { items, total, page, pageSize, loading, onChange: onPageChange, reload } =
|
||||
usePagedList<Feedback>('/admin/api/feedbacks', filters);
|
||||
const reloadRef = useRef(reload);
|
||||
useEffect(() => {
|
||||
reloadRef.current = reload;
|
||||
}, [reload]);
|
||||
|
||||
const canReview = canDo(['operator']);
|
||||
const [selectedRowKeys, setSelectedRowKeys] = useState<number[]>([]);
|
||||
@@ -213,18 +218,40 @@ export default function FeedbacksPage() {
|
||||
}, [items]);
|
||||
|
||||
const [summary, setSummary] = useState<FeedbackSummary | null>(null);
|
||||
const loadSummary = async () => {
|
||||
const loadSummary = useCallback(async () => {
|
||||
try {
|
||||
const { data } = await api.get<FeedbackSummary>('/admin/api/feedbacks/summary');
|
||||
setSummary(data);
|
||||
} catch {
|
||||
/* 统计失败不阻塞列表 */
|
||||
}
|
||||
};
|
||||
useEffect(() => {
|
||||
loadSummary();
|
||||
}, []);
|
||||
|
||||
const refreshPageData = useCallback(() => {
|
||||
void reloadRef.current();
|
||||
void loadSummary();
|
||||
}, [loadSummary]);
|
||||
|
||||
useEffect(() => {
|
||||
void loadSummary();
|
||||
|
||||
const onWindowFocus = () => refreshPageData();
|
||||
const onVisibilityChange = () => {
|
||||
if (document.visibilityState === 'visible') refreshPageData();
|
||||
};
|
||||
const pollTimer = window.setInterval(() => {
|
||||
if (document.visibilityState === 'visible') refreshPageData();
|
||||
}, REVIEW_PAGE_POLL_INTERVAL_MS);
|
||||
|
||||
window.addEventListener('focus', onWindowFocus);
|
||||
document.addEventListener('visibilitychange', onVisibilityChange);
|
||||
return () => {
|
||||
window.clearInterval(pollTimer);
|
||||
window.removeEventListener('focus', onWindowFocus);
|
||||
document.removeEventListener('visibilitychange', onVisibilityChange);
|
||||
};
|
||||
}, [loadSummary, refreshPageData]);
|
||||
|
||||
// 审核/查看抽屉(采纳发金币 / 拒绝填原因 + 看该用户历史反馈)
|
||||
const [drawerFb, setDrawerFb] = useState<Feedback | null>(null);
|
||||
const [drawerOpen, setDrawerOpen] = useState(false);
|
||||
|
||||
+29
-10
@@ -37,6 +37,8 @@ import type {
|
||||
WithdrawSummary,
|
||||
} from '@/lib/types';
|
||||
|
||||
const REVIEW_BADGE_POLL_INTERVAL_MS = 60_000;
|
||||
|
||||
const { Sider, Header, Content } = Layout;
|
||||
|
||||
type NavItem = {
|
||||
@@ -162,22 +164,39 @@ export default function MainLayout({ children }: { children: React.ReactNode })
|
||||
};
|
||||
|
||||
const refreshSafely = (key: ReviewBadgeKey) => refresh(key).catch(() => {});
|
||||
void Promise.all([
|
||||
refreshSafely('/withdraws'),
|
||||
refreshSafely('/invite-withdraws'),
|
||||
refreshSafely('/price-reports'),
|
||||
refreshSafely('/feedbacks'),
|
||||
]);
|
||||
const refreshAll = () => {
|
||||
void Promise.all([
|
||||
refreshSafely('/withdraws'),
|
||||
refreshSafely('/invite-withdraws'),
|
||||
refreshSafely('/price-reports'),
|
||||
refreshSafely('/feedbacks'),
|
||||
]);
|
||||
};
|
||||
|
||||
refreshAll();
|
||||
|
||||
const onReviewCompleted = (event: Event) => {
|
||||
const key = (event as CustomEvent<ReviewBadgeKey>).detail;
|
||||
if (key) void refreshSafely(key);
|
||||
};
|
||||
window.addEventListener(REVIEW_BADGE_REFRESH_EVENT, onReviewCompleted);
|
||||
return () => {
|
||||
window.removeEventListener(REVIEW_BADGE_REFRESH_EVENT, onReviewCompleted);
|
||||
const onWindowFocus = () => refreshAll();
|
||||
const onVisibilityChange = () => {
|
||||
if (document.visibilityState === 'visible') refreshAll();
|
||||
};
|
||||
}, [admin]);
|
||||
const pollTimer = window.setInterval(() => {
|
||||
if (document.visibilityState === 'visible') refreshAll();
|
||||
}, REVIEW_BADGE_POLL_INTERVAL_MS);
|
||||
|
||||
window.addEventListener(REVIEW_BADGE_REFRESH_EVENT, onReviewCompleted);
|
||||
window.addEventListener('focus', onWindowFocus);
|
||||
document.addEventListener('visibilitychange', onVisibilityChange);
|
||||
return () => {
|
||||
window.clearInterval(pollTimer);
|
||||
window.removeEventListener(REVIEW_BADGE_REFRESH_EVENT, onReviewCompleted);
|
||||
window.removeEventListener('focus', onWindowFocus);
|
||||
document.removeEventListener('visibilitychange', onVisibilityChange);
|
||||
};
|
||||
}, [admin, pathname]);
|
||||
|
||||
if (!admin) return null; // 守卫期间不闪烁内容
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import {
|
||||
App,
|
||||
Button,
|
||||
@@ -30,6 +30,7 @@ import type { PriceReport, PriceReportSummary } from '@/lib/types';
|
||||
import UserRecordsDrawer from '@/components/UserRecordsDrawer';
|
||||
|
||||
const { Text } = Typography;
|
||||
const REVIEW_PAGE_POLL_INTERVAL_MS = 60_000;
|
||||
|
||||
// 后端 created_at/reviewed_at 存的是北京 wall-clock(naive,同 savings/comparison),
|
||||
// 直接本地解析、不加 Z(否则会差 8h)。
|
||||
@@ -150,6 +151,10 @@ export default function PriceReportsPage() {
|
||||
|
||||
const { items, total, page, pageSize, loading, onChange: onPageChange, reload } =
|
||||
usePagedList<PriceReport>('/admin/api/price-reports', filters);
|
||||
const reloadRef = useRef(reload);
|
||||
useEffect(() => {
|
||||
reloadRef.current = reload;
|
||||
}, [reload]);
|
||||
|
||||
const sortOrderOf = (field: SortField) =>
|
||||
sortBy === field ? (sortOrder === 'asc' ? 'ascend' : 'descend') : null;
|
||||
@@ -181,18 +186,40 @@ export default function PriceReportsPage() {
|
||||
setSelectedRowKeys((keys) => keys.filter((id) => visiblePendingIds.has(id)));
|
||||
}, [items]);
|
||||
|
||||
const loadSummary = async () => {
|
||||
const loadSummary = useCallback(async () => {
|
||||
try {
|
||||
const { data } = await api.get<PriceReportSummary>('/admin/api/price-reports/summary');
|
||||
setSummary(data);
|
||||
} catch {
|
||||
/* 统计失败不阻塞列表 */
|
||||
}
|
||||
};
|
||||
useEffect(() => {
|
||||
loadSummary();
|
||||
}, []);
|
||||
|
||||
const refreshPageData = useCallback(() => {
|
||||
void reloadRef.current();
|
||||
void loadSummary();
|
||||
}, [loadSummary]);
|
||||
|
||||
useEffect(() => {
|
||||
void loadSummary();
|
||||
|
||||
const onWindowFocus = () => refreshPageData();
|
||||
const onVisibilityChange = () => {
|
||||
if (document.visibilityState === 'visible') refreshPageData();
|
||||
};
|
||||
const pollTimer = window.setInterval(() => {
|
||||
if (document.visibilityState === 'visible') refreshPageData();
|
||||
}, REVIEW_PAGE_POLL_INTERVAL_MS);
|
||||
|
||||
window.addEventListener('focus', onWindowFocus);
|
||||
document.addEventListener('visibilitychange', onVisibilityChange);
|
||||
return () => {
|
||||
window.clearInterval(pollTimer);
|
||||
window.removeEventListener('focus', onWindowFocus);
|
||||
document.removeEventListener('visibilitychange', onVisibilityChange);
|
||||
};
|
||||
}, [loadSummary, refreshPageData]);
|
||||
|
||||
const refreshAfterChange = () => {
|
||||
reload();
|
||||
loadSummary();
|
||||
|
||||
@@ -79,8 +79,8 @@ const RULE_LIMITS: Record<RiskKind, { min: number; max: number; help: string }>
|
||||
},
|
||||
compare: {
|
||||
min: 1,
|
||||
max: 100,
|
||||
help: '同一账户按北京时间自然日累计;最高100次,与比价每日上限一致。',
|
||||
max: 100000,
|
||||
help: '同一账户按北京时间自然日累计;该值同时作为每日比价业务上限和报警阈值。',
|
||||
},
|
||||
};
|
||||
const utcTime = (value: string | null, withDate = true) =>
|
||||
@@ -412,7 +412,7 @@ export default function RiskMonitorPage() {
|
||||
};
|
||||
await api.patch<RiskRuleConfig>('/admin/api/risk-monitor/rules', payload);
|
||||
setRuleOpen(false);
|
||||
void message.success('规则已保存,并已重新核算当前时段');
|
||||
void message.success('规则与比价上限已保存,并已重新核算当前时段');
|
||||
await loadAll(true);
|
||||
} catch (error) {
|
||||
void message.error(errMsg(error, '规则保存失败'));
|
||||
@@ -857,7 +857,7 @@ export default function RiskMonitorPage() {
|
||||
</>
|
||||
)}
|
||||
<Modal
|
||||
title="风控规则设置"
|
||||
title="风控规则与业务上限设置"
|
||||
open={ruleOpen}
|
||||
okText="保存并立即生效"
|
||||
cancelText="取消"
|
||||
@@ -867,7 +867,7 @@ export default function RiskMonitorPage() {
|
||||
destroyOnHidden
|
||||
>
|
||||
<p className={styles.ruleDialogIntro}>
|
||||
修改后会立即重算北京时间当前小时或当天的数据。提高阈值时,不再命中的待处理告警会自动收起;已忽略和已封禁记录不会改变。
|
||||
修改后会立即重算北京时间当前小时或当天的数据。比价阈值还会立即成为单账户每日比价上限;提高阈值时,不再命中的待处理告警会自动收起,已忽略和已封禁记录不会改变。
|
||||
</p>
|
||||
<div className={styles.ruleSettings}>
|
||||
{RISK_KINDS.map((kind) => {
|
||||
|
||||
@@ -44,6 +44,11 @@ interface Props {
|
||||
withdrawSource?: 'coin_cash' | 'invite_cash';
|
||||
// 统计区字段集:withdraw(默认,提现详情:含提现细分) / ad(广告收益详情:只看看广告观看统计,对齐参考图 6 项)
|
||||
statsVariant?: 'withdraw' | 'ad';
|
||||
initialDateFrom?: string;
|
||||
initialDateTo?: string;
|
||||
appEnv?: 'prod' | 'test';
|
||||
revenueScope?: 'business' | 'all';
|
||||
feedScene?: 'comparison' | 'coupon' | 'welfare';
|
||||
}
|
||||
|
||||
/** 用户看广告/提现详情:基本信息 + 互斥时间筛选 + 统计区(按 statsVariant 取字段集)+ 金币发放记录表。 */
|
||||
@@ -52,9 +57,17 @@ export default function UserRewardPanel({
|
||||
user,
|
||||
withdrawSource,
|
||||
statsVariant = 'withdraw',
|
||||
initialDateFrom,
|
||||
initialDateTo,
|
||||
appEnv,
|
||||
revenueScope = 'all',
|
||||
feedScene,
|
||||
}: Props) {
|
||||
const [mode, setMode] = useState<'all' | 'range'>('all'); // all=注册至今 / range=自定义区间
|
||||
const [range, setRange] = useState<[Dayjs, Dayjs] | null>(null);
|
||||
const hasInitialRange = Boolean(initialDateFrom && initialDateTo);
|
||||
const [mode, setMode] = useState<'all' | 'range'>(hasInitialRange ? 'range' : 'all');
|
||||
const [range, setRange] = useState<[Dayjs, Dayjs] | null>(() =>
|
||||
hasInitialRange ? [dayjs(initialDateFrom), dayjs(initialDateTo)] : null,
|
||||
);
|
||||
const [stats, setStats] = useState<UserRewardStats | null>(null);
|
||||
const [statsLoading, setStatsLoading] = useState(false);
|
||||
|
||||
@@ -80,6 +93,9 @@ export default function UserRewardPanel({
|
||||
params: {
|
||||
...JSON.parse(paramsKey),
|
||||
...(withdrawSource ? { withdraw_source: withdrawSource } : {}),
|
||||
...(appEnv ? { app_env: appEnv } : {}),
|
||||
revenue_scope: revenueScope,
|
||||
...(feedScene ? { feed_scene: feedScene } : {}),
|
||||
},
|
||||
});
|
||||
setStats(data);
|
||||
@@ -88,7 +104,7 @@ export default function UserRewardPanel({
|
||||
} finally {
|
||||
setStatsLoading(false);
|
||||
}
|
||||
}, [userId, paramsKey, withdrawSource]);
|
||||
}, [userId, paramsKey, withdrawSource, appEnv, revenueScope, feedScene]);
|
||||
|
||||
const loadRecords = useCallback(
|
||||
async (p: number) => {
|
||||
@@ -236,7 +252,7 @@ export default function UserRewardPanel({
|
||||
</Descriptions>
|
||||
<Text type="secondary" style={{ fontSize: 12 }}>
|
||||
{statsVariant === 'ad'
|
||||
? '统计随上方时间筛选(现金余额除外,为当前快照);次数仅统计成功发奖记录,信息流按奖励份数统计;eCPM 为预估值。'
|
||||
? '统计继承广告收益页已查询的日期、环境、业务代码位和场景;次数仅统计成功发奖记录,信息流按奖励份数统计;Draw eCPM 按全部实际展示统计(含未发奖)。'
|
||||
: '统计随上方时间筛选(现金余额除外,为当前快照);提现按申请提交时间统计;累计收益为已发金币按当前汇率折算,不代表实际已提现金额;eCPM 为预估值。'}
|
||||
</Text>
|
||||
|
||||
|
||||
@@ -124,7 +124,10 @@ function summaryCount(summary: WithdrawSummary | null, key: string) {
|
||||
if (!summary) return undefined;
|
||||
if (key === 'reviewing') return summary.reviewing_count;
|
||||
if (key === 'pending') return summary.pending_count;
|
||||
if (key === 'success') return summary.success_count;
|
||||
if (key === 'rejected') return summary.rejected_count;
|
||||
if (key === 'failed') return summary.failed_count;
|
||||
if (key === 'all') return summary.total_count;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -567,6 +570,7 @@ export function WithdrawReviewPage({ mode = 'other' }: { mode?: WithdrawReviewMo
|
||||
},
|
||||
{
|
||||
title: '失败/拒绝原因',
|
||||
key: 'fail_reason',
|
||||
dataIndex: 'fail_reason',
|
||||
ellipsis: true,
|
||||
render: (v: string | null) => v || <Text type="secondary">-</Text>,
|
||||
@@ -644,6 +648,10 @@ export function WithdrawReviewPage({ mode = 'other' }: { mode?: WithdrawReviewMo
|
||||
},
|
||||
},
|
||||
];
|
||||
const visibleColumns =
|
||||
activeStatus === 'pending' || activeStatus === 'success'
|
||||
? columns.filter((column) => column.key !== 'fail_reason')
|
||||
: columns;
|
||||
|
||||
const inviteeColumns: ColumnsType<InviteeDetail> = [
|
||||
{ title: '手机号', dataIndex: 'phone', width: 130 },
|
||||
@@ -942,7 +950,7 @@ export function WithdrawReviewPage({ mode = 'other' }: { mode?: WithdrawReviewMo
|
||||
}
|
||||
: undefined
|
||||
}
|
||||
columns={columns}
|
||||
columns={visibleColumns}
|
||||
dataSource={items}
|
||||
loading={loading}
|
||||
pagination={{
|
||||
@@ -986,12 +994,6 @@ export function WithdrawReviewPage({ mode = 'other' }: { mode?: WithdrawReviewMo
|
||||
<Descriptions.Item label="金额">
|
||||
<Text strong>{yuan(detail.order.amount_cents)}</Text>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="提现类型">
|
||||
{detail.order.source === 'invite_cash' ? '邀请奖励提现' : '福利页提现'}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="累计成功提现">
|
||||
{yuan(detail.cumulative_success_cents)}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="提交时间">
|
||||
{dt(detail.order.created_at)}
|
||||
</Descriptions.Item>
|
||||
|
||||
@@ -37,6 +37,18 @@ export function percentile(values: readonly number[], q: number, round = true):
|
||||
return round ? Math.round(result) : result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 离散计数分位数(nearest-rank)。
|
||||
* 广告条数等不可拆分的计数不做线性插值,结果始终取自真实样本。
|
||||
*/
|
||||
export function nearestRankPercentile(values: readonly number[], q: number): number | null {
|
||||
if (!values.length) return null;
|
||||
const sorted = [...values].sort((a, b) => a - b);
|
||||
const quantile = Math.min(1, Math.max(0, q));
|
||||
const rank = Math.max(1, Math.ceil(quantile * sorted.length));
|
||||
return sorted[rank - 1];
|
||||
}
|
||||
|
||||
const hasTz = (v: string) => /(?:Z|[+-]\d{2}:?\d{2})$/i.test(v);
|
||||
|
||||
/** 把 UTC 口径字符串解析为带时区的 dayjs(无时区后缀的补 Z 当 UTC)。 */
|
||||
|
||||
+9
-2
@@ -167,7 +167,10 @@ export interface WithdrawSummary {
|
||||
reviewing_count: number;
|
||||
reviewing_amount_cents: number;
|
||||
pending_count: number;
|
||||
success_count: number;
|
||||
rejected_count: number;
|
||||
failed_count: number;
|
||||
total_count: number;
|
||||
today_success_count: number;
|
||||
today_success_amount_cents: number;
|
||||
today_rejected_count: number;
|
||||
@@ -230,7 +233,7 @@ export interface UserRewardStats {
|
||||
reward_video_avg_ecpm: number; // 平均激励视频 eCPM(分/千次)
|
||||
reward_video_cash_cents: number; // 激励视频提现
|
||||
feed_count: number; // 累计信息流广告数(份)
|
||||
feed_avg_ecpm: number; // 平均信息流广告 eCPM(分/千次)
|
||||
feed_avg_ecpm: number; // 全部 Draw/feed 实际展示的平均 eCPM(分/千次,含未发奖展示)
|
||||
feed_cash_cents: number; // 信息流广告提现
|
||||
}
|
||||
|
||||
@@ -454,6 +457,7 @@ export interface ComparisonRecordListItem {
|
||||
source_price_cents: number | null;
|
||||
best_price_cents: number | null;
|
||||
saved_amount_cents: number | null;
|
||||
ordered: boolean;
|
||||
total_ms: number | null;
|
||||
step_count: number | null;
|
||||
llm_call_count: number | null;
|
||||
@@ -462,8 +466,10 @@ export interface ComparisonRecordListItem {
|
||||
output_tokens: number | null;
|
||||
llm_cost_yuan: number | null; // 后端按「当时价」冻结的实际成本(元);旧记录 null → 「成本」列回退估算
|
||||
device_model: string | null;
|
||||
device_model_name: string | null;
|
||||
rom_vendor: string | null;
|
||||
rom_name: string | null;
|
||||
rom_version: number | null;
|
||||
android_version: string | null;
|
||||
app_version: string | null;
|
||||
ad_revenue_yuan: number; // 本次比价看的信息流广告预估收益(元)
|
||||
@@ -514,7 +520,6 @@ export interface ComparisonRecordDetail extends ComparisonRecordListItem {
|
||||
comparison_results: Record<string, unknown>[];
|
||||
skipped_dish_names: string[];
|
||||
device_manufacturer: string | null;
|
||||
rom_version: number | null;
|
||||
android_sdk: number | null;
|
||||
app_version_code: number | null;
|
||||
source_app_version: string | null;
|
||||
@@ -578,6 +583,7 @@ export interface AdRevenueHourly {
|
||||
export interface AdRevenueTypeStat {
|
||||
impressions: number; // 该类型展示条数合计
|
||||
revenue_yuan: number; // 该类型预估收益合计(元)
|
||||
ecpm_yuan?: number; // 按真实展示次数加权的 SDK eCPM(元/千次)
|
||||
}
|
||||
|
||||
// 广告收益报表:一次广告事件(逐条一行)。激励视频展示+发奖按 ad_session_id 合并;信息流展示/发奖各自成行。
|
||||
@@ -617,6 +623,7 @@ export interface AdRevenueReport {
|
||||
daily: AdRevenueDaily[]; // 按日期汇总序列(全量,供按天趋势图)
|
||||
hourly: AdRevenueHourly[]; // 按小时汇总序列(全量,供按小时趋势图;按天查询时为空)
|
||||
type_stats: Record<string, AdRevenueTypeStat>; // 按广告类型小计;前端取 draw / reward_video
|
||||
category_stats?: Record<string, AdRevenueTypeStat>; // draw=draw+历史feed;video=福利视频+提现视频
|
||||
// 按信息流场景小计(comparison/coupon/welfare;全量,不受分页截断)。数据大盘「领券广告/比价广告」卡
|
||||
// 优先读它:2026-07-02 后端起 items 不再含信息流逐条展示行(唯一带收益+场景的行),按 items 现算恒 0。
|
||||
// 可选(`?.` 探测)以兼容未升级后端,缺失时回退 items 现算。
|
||||
|
||||
Reference in New Issue
Block a user