Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c6a8cb2cf0 | |||
| 2727eaa929 | |||
| af74ecf9d3 | |||
| 3102a96bd3 | |||
| 7f5dde5c2f | |||
| c8293d57b3 | |||
| 6a3ce5d340 | |||
| 98cea13d51 | |||
| d7129186c5 | |||
| a1d9923f33 | |||
| 510ce349f7 | |||
| 03ef222b71 |
@@ -0,0 +1,84 @@
|
||||
'use client';
|
||||
|
||||
// 点收益报表里的用户手机号 → 半屏抽屉展示该用户的广告收益详情(统计卡 + 金币记录)。
|
||||
// 复用「提现详情」里的 UserRewardPanel(数据走 /users/{id}/reward-stats + /coin-records);
|
||||
// 用户基本信息(昵称/注册时间/钱包)取自 /users/{id} 概览。抽屉样式(width 50% 半屏)与提现详情一致。
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Drawer } from 'antd';
|
||||
import { api } from '@/lib/api';
|
||||
import type { WithdrawUserSnapshot } from '@/lib/types';
|
||||
import UserRewardPanel from '../withdraws/UserRewardPanel';
|
||||
|
||||
// GET /admin/api/users/{id} 概览里我们要用到的子集(前端未单独定义 AdminUserOverview 类型)。
|
||||
interface UserOverviewResp {
|
||||
user: {
|
||||
id: number;
|
||||
phone: string;
|
||||
nickname: string | null;
|
||||
status: string;
|
||||
wechat_nickname: string | null;
|
||||
created_at: string;
|
||||
last_login_at: string;
|
||||
};
|
||||
cash_balance_cents: number;
|
||||
withdraw_total: number;
|
||||
withdraw_success_cents: number;
|
||||
}
|
||||
|
||||
interface Props {
|
||||
open: boolean;
|
||||
onClose: () => void;
|
||||
userId: number | null;
|
||||
phone: string | null; // 报表行已有的手机号:概览拉取失败时兜底展示
|
||||
}
|
||||
|
||||
export default function UserAdRevenueDrawer({ open, onClose, userId, phone }: Props) {
|
||||
// UserRewardPanel 的 user 快照:它只读 phone/nickname/wechat_nickname/created_at,其余按 snapshot 形状补齐。
|
||||
const [user, setUser] = useState<WithdrawUserSnapshot | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!open || userId == null) return;
|
||||
let alive = true;
|
||||
setUser(null);
|
||||
api
|
||||
.get<UserOverviewResp>(`/admin/api/users/${userId}`)
|
||||
.then((r) => {
|
||||
if (!alive) return;
|
||||
const o = r.data;
|
||||
setUser({
|
||||
id: o.user.id,
|
||||
phone: o.user.phone,
|
||||
nickname: o.user.nickname,
|
||||
status: o.user.status,
|
||||
wechat_nickname: o.user.wechat_nickname, // 概览接口已返回微信昵称
|
||||
wechat_avatar_url: null,
|
||||
created_at: o.user.created_at,
|
||||
last_login_at: o.user.last_login_at,
|
||||
cash_balance_cents: o.cash_balance_cents,
|
||||
withdraw_total: o.withdraw_total,
|
||||
withdraw_success_cents: o.withdraw_success_cents,
|
||||
});
|
||||
})
|
||||
.catch(() => {
|
||||
// 概览失败:退回只带手机号,昵称/注册天数显示「-」,不阻塞统计/金币记录(它们由 userId 独立拉)
|
||||
if (alive) setUser(phone ? ({ phone } as WithdrawUserSnapshot) : null);
|
||||
});
|
||||
return () => {
|
||||
alive = false;
|
||||
};
|
||||
}, [open, userId, phone]);
|
||||
|
||||
return (
|
||||
<Drawer
|
||||
title={`用户广告收益详情${phone ? ` · ${phone}` : ''}`}
|
||||
width="50%"
|
||||
open={open}
|
||||
onClose={onClose}
|
||||
destroyOnHidden
|
||||
>
|
||||
{/* userId 就绪即渲染;UserRewardPanel 内部按 userId 自行拉统计与金币记录,user 基本信息随后补上。
|
||||
statsVariant="ad":统计区只显示 6 项看广告统计(累计提现/现金余额/激励视频观看数+eCPM/draw观看数+eCPM) */}
|
||||
{userId != null && <UserRewardPanel userId={userId} user={user} statsVariant="ad" />}
|
||||
</Drawer>
|
||||
);
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
Card,
|
||||
Col,
|
||||
DatePicker,
|
||||
Descriptions,
|
||||
Divider,
|
||||
InputNumber,
|
||||
Modal,
|
||||
@@ -19,6 +20,7 @@ import {
|
||||
Statistic,
|
||||
Table,
|
||||
Tag,
|
||||
Tooltip,
|
||||
Typography,
|
||||
} from 'antd';
|
||||
import {
|
||||
@@ -32,17 +34,21 @@ import { api, errMsg } from '@/lib/api';
|
||||
import { formatUtcTime } from '@/lib/format';
|
||||
import type {
|
||||
AdRevenueDaily,
|
||||
AdRevenueHourly,
|
||||
AdRevenueRecord,
|
||||
AdRevenueReport,
|
||||
AdRevenueRow,
|
||||
AdRevenueTypeStat,
|
||||
} from '@/lib/types';
|
||||
import UserAdRevenueDrawer from './UserAdRevenueDrawer';
|
||||
|
||||
const { RangePicker } = DatePicker;
|
||||
|
||||
// 广告类型标签
|
||||
const TYPE_TAG: Record<string, { color: string; label: string }> = {
|
||||
reward_video: { color: 'blue', label: '激励视频' },
|
||||
feed: { color: 'purple', label: '信息流' },
|
||||
// 历史误标 feed(领券/比价广告修 adType 之前上报)一律按 Draw 信息流显示——业务已全切 Draw
|
||||
feed: { color: 'geekblue', label: 'Draw 信息流' },
|
||||
draw: { color: 'geekblue', label: 'Draw 信息流' },
|
||||
withdrawal_video: { color: 'gold', label: '提现激励视频' },
|
||||
};
|
||||
@@ -127,27 +133,24 @@ const DETAIL_COLUMNS: ColumnsType<AdRevenueRecord> = [
|
||||
},
|
||||
{ title: '应发金币', dataIndex: 'expected_coin', width: 100, render: (v: number) => <b>{v}</b> },
|
||||
{ title: '实发金币', dataIndex: 'actual_coin', width: 100 },
|
||||
{
|
||||
title: '一致',
|
||||
dataIndex: 'matched',
|
||||
width: 80,
|
||||
render: (m: boolean) => (m ? <Tag color="green">✓</Tag> : <Tag color="red">✗ 不符</Tag>),
|
||||
},
|
||||
];
|
||||
|
||||
// 趋势图(纯 SVG,零依赖):柱=展示条数(左轴),线=预估收益元(右轴)。x 轴按传入点序。
|
||||
// 趋势图(纯 SVG,零依赖):柱=展示条数(左轴),橙线=客户端预估收益元(右轴),
|
||||
// 绿线=穿山甲后台预估收益元(右轴,仅按天且有数据时出现)。x 轴按传入点序。
|
||||
const CHART_BAR = '#69b1ff';
|
||||
const CHART_LINE = '#fa8c16';
|
||||
const CHART_LINE2 = '#52c41a'; // 穿山甲后台收益线
|
||||
|
||||
interface TrendPoint {
|
||||
label: string; // x 轴刻度文案(小时数 / MM-DD)
|
||||
tip: string; // hover 原生 tooltip 全文
|
||||
impressions: number;
|
||||
revenue: number;
|
||||
pangleRevenue: number | null; // 穿山甲后台预估收益(元);无则 null(不画绿线点)
|
||||
}
|
||||
|
||||
// 按小时聚合(0–23),数据源是 items(被 limit 截断时会偏少,调用处给警告)
|
||||
function aggregateHourly(rows: AdRevenueRow[]): TrendPoint[] {
|
||||
// 按小时聚合(0–23),数据源是 hourly(后端全量聚合,不受分页影响)。穿山甲为天级,小时视图无该线。
|
||||
function aggregateHourly(rows: AdRevenueHourly[]): TrendPoint[] {
|
||||
const byHour = Array.from({ length: 24 }, (_, h) => ({ hour: h, impressions: 0, revenue: 0 }));
|
||||
for (const r of rows) {
|
||||
if (r.hour == null || r.hour < 0 || r.hour > 23) continue;
|
||||
@@ -159,10 +162,12 @@ function aggregateHourly(rows: AdRevenueRow[]): TrendPoint[] {
|
||||
tip: `${String(b.hour).padStart(2, '0')}:00 展示 ${b.impressions} 条 · 预估收益 ${b.revenue.toFixed(4)} 元`,
|
||||
impressions: b.impressions,
|
||||
revenue: b.revenue,
|
||||
pangleRevenue: null,
|
||||
}));
|
||||
}
|
||||
|
||||
// 按天聚合,数据源是 daily(全量,不受 limit 影响);用 from..to 补齐空缺日为 0,轴连续
|
||||
// 按天聚合,数据源是 daily(全量,不受 limit 影响);用 from..to 补齐空缺日为 0,轴连续。
|
||||
// 穿山甲收益(pangle_revenue_yuan)为 null 时该日不画绿线点(T+1 未出/非全量视图)。
|
||||
function aggregateDaily(dateFrom: string, dateTo: string, daily: AdRevenueDaily[]): TrendPoint[] {
|
||||
const map = new Map(daily.map((d) => [d.date, d]));
|
||||
const out: TrendPoint[] = [];
|
||||
@@ -173,11 +178,14 @@ function aggregateDaily(dateFrom: string, dateTo: string, daily: AdRevenueDaily[
|
||||
const d = map.get(ds);
|
||||
const impressions = d?.impressions ?? 0;
|
||||
const revenue = d?.revenue_yuan ?? 0;
|
||||
const pangleRevenue = d?.pangle_revenue_yuan ?? null;
|
||||
const pangleTip = pangleRevenue != null ? ` · 穿山甲收益 ${pangleRevenue.toFixed(4)} 元` : '';
|
||||
out.push({
|
||||
label: ds.slice(5),
|
||||
tip: `${ds} 展示 ${impressions} 条 · 预估收益 ${revenue.toFixed(4)} 元`,
|
||||
tip: `${ds} 展示 ${impressions} 条 · 预估收益 ${revenue.toFixed(4)} 元${pangleTip}`,
|
||||
impressions,
|
||||
revenue,
|
||||
pangleRevenue,
|
||||
});
|
||||
cur = cur.add(1, 'day');
|
||||
guard += 1;
|
||||
@@ -188,7 +196,11 @@ function aggregateDaily(dateFrom: string, dateTo: string, daily: AdRevenueDaily[
|
||||
function TrendChart({ points }: { points: TrendPoint[] }) {
|
||||
const n = points.length;
|
||||
const maxImp = Math.max(1, ...points.map((p) => p.impressions));
|
||||
const maxRev = Math.max(1e-9, ...points.map((p) => p.revenue));
|
||||
const maxRev = Math.max(
|
||||
1e-9,
|
||||
...points.map((p) => p.revenue),
|
||||
...points.map((p) => p.pangleRevenue ?? 0),
|
||||
);
|
||||
|
||||
const W = 960;
|
||||
const H = 280;
|
||||
@@ -244,6 +256,24 @@ function TrendChart({ points }: { points: TrendPoint[] }) {
|
||||
<title>{p.tip}</title>
|
||||
</circle>
|
||||
))}
|
||||
{/* 穿山甲后台收益线(绿,仅非 null 的天画;按天且已同步 T+1 数据时出现) */}
|
||||
{(() => {
|
||||
const pp = points
|
||||
.map((p, i) => ({ i, v: p.pangleRevenue, tip: p.tip }))
|
||||
.filter((x): x is { i: number; v: number; tip: string } => x.v != null);
|
||||
if (pp.length === 0) return null;
|
||||
const pangleLine = pp.map((x) => `${cx(x.i)},${revY(x.v)}`).join(' ');
|
||||
return (
|
||||
<g>
|
||||
<polyline points={pangleLine} fill="none" stroke={CHART_LINE2} strokeWidth={2} />
|
||||
{pp.map((x) => (
|
||||
<circle key={`p-${x.i}`} cx={cx(x.i)} cy={revY(x.v)} r={2.5} fill={CHART_LINE2}>
|
||||
<title>{x.tip}</title>
|
||||
</circle>
|
||||
))}
|
||||
</g>
|
||||
);
|
||||
})()}
|
||||
{points.map((p, i) =>
|
||||
i % labelEvery === 0 || i === n - 1 ? (
|
||||
<text key={i} x={cx(i)} y={H - 14} textAnchor="middle" fontSize={11} fill="#999">
|
||||
@@ -263,47 +293,59 @@ export default function AdRevenueReportPage() {
|
||||
const [range, setRange] = useState<[Dayjs, Dayjs]>([dayjs(), dayjs()]);
|
||||
const [userId, setUserId] = useState<number | null>(null);
|
||||
const [adType, setAdType] = useState<string | undefined>();
|
||||
// 「场景」为纯前端过滤(后端 query 暂不支持 feed_scene),只作用于下方明细表,不重新请求、不影响趋势/日汇总。
|
||||
// 「场景」作为后端全局筛选(feed_scene):同时影响明细 / 合计 / 趋势,与「用户 / 类型」一致,点「查询」生效。
|
||||
const [scene, setScene] = useState<string | undefined>();
|
||||
const [granularity, setGranularity] = useState<'day' | 'hour'>('day');
|
||||
const [limit, setLimit] = useState<number>(500);
|
||||
const [sortBy, setSortBy] = useState<'time' | 'ecpm'>('time'); // 明细排序:time=时间倒序 / ecpm=eCPM 倒序
|
||||
const [limit, setLimit] = useState<number>(500); // 每页条数(分页大小)
|
||||
const [page, setPage] = useState<number>(1); // 当前页码(后端分页;1 起)
|
||||
const [queriedGranularity, setQueriedGranularity] = useState<'day' | 'hour'>('day'); // 本次结果对应的粒度,决定是否显示「小时」列
|
||||
const [queriedMultiDay, setQueriedMultiDay] = useState(false); // 本次结果是否跨多天,决定显示「日期」列 + 按天/按小时图
|
||||
const [data, setData] = useState<AdRevenueReport | null>(null);
|
||||
const [queriedLimit, setQueriedLimit] = useState<number>(500);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [formulaOpen, setFormulaOpen] = useState(false);
|
||||
// 点用户手机号弹出的「用户广告收益详情」半屏抽屉(userId + 手机号;null=关闭)
|
||||
const [userDrawer, setUserDrawer] = useState<{ userId: number; phone: string | null } | null>(null);
|
||||
|
||||
// 当前选择是否跨多天:跨多天时「按小时」无意义,粒度强制按天
|
||||
const rangeMultiDay = range[0].format('YYYY-MM-DD') !== range[1].format('YYYY-MM-DD');
|
||||
|
||||
const load = useCallback(async () => {
|
||||
const from = range[0].format('YYYY-MM-DD');
|
||||
const to = range[1].format('YYYY-MM-DD');
|
||||
const multiDay = from !== to;
|
||||
const gran = multiDay ? 'day' : granularity; // 跨多天强制按天
|
||||
setLoading(true);
|
||||
try {
|
||||
const res = await api.get<AdRevenueReport>('/admin/api/ad-revenue-report', {
|
||||
params: {
|
||||
date_from: from,
|
||||
date_to: to,
|
||||
user_id: userId ?? undefined,
|
||||
ad_type: adType ?? undefined,
|
||||
granularity: gran,
|
||||
limit,
|
||||
},
|
||||
});
|
||||
setData(res.data);
|
||||
setQueriedLimit(limit);
|
||||
setQueriedGranularity(gran);
|
||||
setQueriedMultiDay(multiDay);
|
||||
} catch (e) {
|
||||
message.error(errMsg(e));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [range, userId, adType, granularity, limit]);
|
||||
// load(目标页, 每页条数):分页与筛选都经它。offset 由 页码×每页 算;场景(feed_scene)随筛选下推后端。
|
||||
const load = useCallback(
|
||||
async (targetPage = 1, targetLimit = limit, targetSort = sortBy) => {
|
||||
const from = range[0].format('YYYY-MM-DD');
|
||||
const to = range[1].format('YYYY-MM-DD');
|
||||
const multiDay = from !== to;
|
||||
const gran = multiDay ? 'day' : granularity; // 跨多天强制按天
|
||||
setLoading(true);
|
||||
try {
|
||||
const res = await api.get<AdRevenueReport>('/admin/api/ad-revenue-report', {
|
||||
params: {
|
||||
date_from: from,
|
||||
date_to: to,
|
||||
user_id: userId ?? undefined,
|
||||
ad_type: adType ?? undefined,
|
||||
feed_scene: scene ?? undefined,
|
||||
granularity: gran,
|
||||
limit: targetLimit,
|
||||
offset: (targetPage - 1) * targetLimit,
|
||||
sort: targetSort,
|
||||
},
|
||||
});
|
||||
setData(res.data);
|
||||
setPage(targetPage);
|
||||
setQueriedLimit(targetLimit);
|
||||
setQueriedGranularity(gran);
|
||||
setQueriedMultiDay(multiDay);
|
||||
} catch (e) {
|
||||
message.error(errMsg(e));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
},
|
||||
[range, userId, adType, scene, granularity, limit, sortBy],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
load();
|
||||
@@ -320,25 +362,39 @@ export default function AdRevenueReportPage() {
|
||||
title: '用户',
|
||||
dataIndex: 'user_phone',
|
||||
width: 150,
|
||||
render: (phone: string | null, r: AdRevenueRow) =>
|
||||
phone ? (
|
||||
<span>
|
||||
{phone}
|
||||
<Typography.Text type="secondary" style={{ fontSize: 11, marginLeft: 6 }}>
|
||||
#{r.user_id}
|
||||
</Typography.Text>
|
||||
</span>
|
||||
) : (
|
||||
<Typography.Text type="secondary">#{r.user_id}(无手机号)</Typography.Text>
|
||||
),
|
||||
render: (phone: string | null, r: AdRevenueRow) => (
|
||||
// 点手机号/用户 → 打开该用户「广告收益详情」半屏抽屉(统计卡 + 金币记录)
|
||||
<a onClick={() => setUserDrawer({ userId: r.user_id, phone })}>
|
||||
{phone ? (
|
||||
<span>
|
||||
{phone}
|
||||
<Typography.Text type="secondary" style={{ fontSize: 11, marginLeft: 6 }}>
|
||||
#{r.user_id}
|
||||
</Typography.Text>
|
||||
</span>
|
||||
) : (
|
||||
<span>#{r.user_id}(无手机号)</span>
|
||||
)}
|
||||
</a>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '广告类型',
|
||||
dataIndex: 'ad_type',
|
||||
width: 110,
|
||||
render: (s: string) => {
|
||||
width: 130,
|
||||
render: (s: string, r: AdRevenueRow) => {
|
||||
const t = TYPE_TAG[s] ?? { color: 'default', label: s };
|
||||
return <Tag color={t.color}>{t.label}</Tag>;
|
||||
return (
|
||||
<span>
|
||||
<Tag color={t.color}>{t.label}</Tag>
|
||||
{/* 一次比价/领券聚合了多条广告时标出条数,点「+」展开看逐条 */}
|
||||
{r.sub_count && r.sub_count > 1 ? (
|
||||
<Typography.Text type="secondary" style={{ fontSize: 11 }}>
|
||||
{r.sub_count} 条
|
||||
</Typography.Text>
|
||||
) : null}
|
||||
</span>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -361,13 +417,6 @@ export default function AdRevenueReportPage() {
|
||||
return <Tag color={t.color}>{t.label}</Tag>;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '广告位ID',
|
||||
dataIndex: 'our_code_id',
|
||||
width: 110,
|
||||
render: (v: string | null) =>
|
||||
v ? <Typography.Text code>{v}</Typography.Text> : <Typography.Text type="secondary">-</Typography.Text>,
|
||||
},
|
||||
{
|
||||
title: 'eCPM(分)',
|
||||
dataIndex: 'ecpm',
|
||||
@@ -375,12 +424,27 @@ export default function AdRevenueReportPage() {
|
||||
align: 'right',
|
||||
render: (v: string | null) => v ?? '-',
|
||||
},
|
||||
{
|
||||
title: 'eCPM(元)',
|
||||
key: 'ecpm_yuan',
|
||||
width: 100,
|
||||
align: 'right',
|
||||
render: (_: unknown, r: AdRevenueRow) => {
|
||||
// eCPM 原始值单位「分/千次」,÷100 转「元/千次」(块);非数字 / 空显示 -。
|
||||
const cents = r.ecpm == null ? null : Number(r.ecpm);
|
||||
return cents == null || Number.isNaN(cents) ? '-' : (cents / 100).toFixed(2);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '预估收益(元)',
|
||||
dataIndex: 'revenue_yuan',
|
||||
width: 110,
|
||||
align: 'right',
|
||||
render: (v: number, r: AdRevenueRow) => (r.has_impression ? v.toFixed(4) : '-'),
|
||||
// 一次比价/领券聚合行用 row_revenue_yuan(该次发奖广告 eCPM 折算之和),其它行用展示侧 revenue_yuan
|
||||
render: (v: number, r: AdRevenueRow) => {
|
||||
const rev = r.row_revenue_yuan ?? v;
|
||||
return r.has_impression || rev > 0 ? rev.toFixed(4) : '-';
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '发奖状态',
|
||||
@@ -409,16 +473,11 @@ export default function AdRevenueReportPage() {
|
||||
r.has_reward ? v : <Typography.Text type="secondary">-</Typography.Text>,
|
||||
},
|
||||
{
|
||||
title: '一致',
|
||||
dataIndex: 'matched',
|
||||
width: 70,
|
||||
align: 'center',
|
||||
render: (m: boolean, r: AdRevenueRow) =>
|
||||
r.has_reward ? (
|
||||
m ? <Tag color="green">✓</Tag> : <Tag color="red">✗ 不符</Tag>
|
||||
) : (
|
||||
<Typography.Text type="secondary">-</Typography.Text>
|
||||
),
|
||||
title: '广告位ID',
|
||||
dataIndex: 'our_code_id',
|
||||
width: 110,
|
||||
render: (v: string | null) =>
|
||||
v ? <Typography.Text code>{v}</Typography.Text> : <Typography.Text type="secondary">-</Typography.Text>,
|
||||
},
|
||||
{
|
||||
title: '底层 ADN',
|
||||
@@ -429,14 +488,11 @@ export default function AdRevenueReportPage() {
|
||||
},
|
||||
];
|
||||
|
||||
// 派生指标(全部基于全量 total_* 字段,不受 limit 截断影响,准):
|
||||
// 平均 eCPM = 收益÷展示×1000;发奖成本(元)= 实发金币÷汇率;预估毛利 = 收益−发奖成本;
|
||||
// 发奖占收益比 = 发奖成本÷收益;应发实发差额(金币)= 应发−实发(正=少发/负=多发)。
|
||||
// 派生指标(全部基于全量 total_* 字段,不受分页影响,准):
|
||||
// 发奖成本(元)= 实发金币÷汇率;预估毛利 = 收益−发奖成本;发奖占收益比 = 发奖成本÷收益;
|
||||
// 应发实发差额(金币)= 应发−实发(正=少发/负=多发);ARPU = 预估收益÷今日DAU(仅今日)。
|
||||
const derived = data
|
||||
? {
|
||||
avgEcpm: data.total_impressions
|
||||
? (data.total_revenue_yuan / data.total_impressions) * 1000
|
||||
: 0,
|
||||
payoutYuan: data.total_actual_coin / COIN_PER_YUAN,
|
||||
grossProfit: data.total_revenue_yuan - data.total_actual_coin / COIN_PER_YUAN,
|
||||
payoutRatioPct:
|
||||
@@ -444,18 +500,19 @@ export default function AdRevenueReportPage() {
|
||||
? (data.total_actual_coin / COIN_PER_YUAN / data.total_revenue_yuan) * 100
|
||||
: null,
|
||||
coinGap: data.total_expected_coin - data.total_actual_coin,
|
||||
// ARPU(今日)= 预估广告收益 ÷ 今日 DAU;dau 为 null(历史/多天)或 0 时不可算 → null,前端显示「-」。
|
||||
arpu: data.dau && data.dau > 0 ? data.total_revenue_yuan / data.dau : null,
|
||||
}
|
||||
: null;
|
||||
|
||||
// 「场景」纯前端过滤:只对已加载的明细 items 生效(后端 query 暂不支持 feed_scene);趋势图/日汇总仍用全量 daily/total_*。
|
||||
const allItems = data?.items ?? [];
|
||||
const filteredItems = scene ? allItems.filter((r) => r.feed_scene === scene) : allItems;
|
||||
// 第二行大盘「分广告类型」:draw / 激励视频 各自 收益 / eCPM / 展示条数;eCPM = 收益÷展示×1000。
|
||||
const drawStat = data?.type_stats?.draw;
|
||||
const rvStat = data?.type_stats?.reward_video;
|
||||
const ecpmOf = (s?: AdRevenueTypeStat) =>
|
||||
s && s.impressions > 0 ? (s.revenue_yuan / s.impressions) * 1000 : 0;
|
||||
|
||||
// 选中比价/领券且类型=draw 时,给出该场景在已加载明细内的实发金币小计(仅明细口径,可能受 limit 截断)。
|
||||
const sceneCoinSubtotal =
|
||||
adType === 'draw' && (scene === 'comparison' || scene === 'coupon')
|
||||
? filteredItems.reduce((s, r) => s + (r.has_reward ? r.actual_coin : 0), 0)
|
||||
: null;
|
||||
// 明细直接用后端返回的当前页 items(「场景」已由后端 feed_scene 全局过滤,前端不再二次筛)。
|
||||
const items = data?.items ?? [];
|
||||
|
||||
return (
|
||||
<div>
|
||||
@@ -474,9 +531,18 @@ export default function AdRevenueReportPage() {
|
||||
title="收益口径说明"
|
||||
content={
|
||||
<div style={{ maxWidth: 360, fontSize: 13, lineHeight: 1.7 }}>
|
||||
<b>主表每行 = 一次广告行为</b>(激励视频一次观看 / 一次比价 / 一次领券);比价·领券的 Draw
|
||||
逐条展示不单独占行(其展示数 / eCPM / 预估收益已计入上方合计与大盘),点行左侧「+」展开看该次金币复算。
|
||||
<br />
|
||||
<br />
|
||||
「预估收益」为客户端在广告展示(onAdShow)时上报 eCPM 折算的预估值(每千次展示 ÷1000
|
||||
累加),<b>只要广告展示就计入、不论是否看完发奖</b>;穿山甲会过滤无效/过短曝光,故预估值可能偏高,
|
||||
<b>实际收益一律以穿山甲后台结算为准</b>。测试应用多为 0。「广告位ID / 来源应用」为本期新增,历史记录留空。
|
||||
<br />
|
||||
<br />
|
||||
核心指标里的<b>「穿山甲后台收益(T+1)」</b>来自穿山甲 GroMore 数据 API(后台结算口径,次日出数):
|
||||
<b>穿山甲预估收益</b>=接口 revenue、<b>收益API</b>=各 ADN 回传更接近结算。穿山甲不提供分用户/类型/场景维度,
|
||||
故仅在<b>全量视图</b>(未按用户/类型/场景筛选)展示;逐条事件行仍是客户端预估,不受其影响。
|
||||
</div>
|
||||
}
|
||||
>
|
||||
@@ -520,7 +586,6 @@ export default function AdRevenueReportPage() {
|
||||
style={{ width: 150 }}
|
||||
options={[
|
||||
{ value: 'reward_video', label: '激励视频' },
|
||||
{ value: 'feed', label: '信息流' },
|
||||
{ value: 'draw', label: 'Draw 信息流' },
|
||||
{ value: 'withdrawal_video', label: '提现激励视频' },
|
||||
]}
|
||||
@@ -534,7 +599,6 @@ export default function AdRevenueReportPage() {
|
||||
onChange={setScene}
|
||||
allowClear
|
||||
style={{ width: 130 }}
|
||||
title="仅前端过滤下方明细,不影响趋势图/汇总"
|
||||
options={[
|
||||
{ value: 'comparison', label: '比价' },
|
||||
{ value: 'coupon', label: '领券' },
|
||||
@@ -557,15 +621,33 @@ export default function AdRevenueReportPage() {
|
||||
/>
|
||||
</Space>
|
||||
<Space size={6}>
|
||||
<Typography.Text type="secondary">条数</Typography.Text>
|
||||
<Typography.Text type="secondary">排序</Typography.Text>
|
||||
<Select
|
||||
value={limit}
|
||||
onChange={setLimit}
|
||||
style={{ width: 110 }}
|
||||
options={[100, 200, 500, 1000].map((n) => ({ value: n, label: `${n} 条` }))}
|
||||
value={sortBy}
|
||||
onChange={(v) => {
|
||||
setSortBy(v);
|
||||
load(1, limit, v); // 改排序:回第 1 页并重查
|
||||
}}
|
||||
style={{ width: 130 }}
|
||||
options={[
|
||||
{ value: 'time', label: '时间倒序' },
|
||||
{ value: 'ecpm', label: 'eCPM 倒序' },
|
||||
]}
|
||||
/>
|
||||
</Space>
|
||||
<Button type="primary" onClick={load} loading={loading}>
|
||||
<Space size={6}>
|
||||
<Typography.Text type="secondary">每页</Typography.Text>
|
||||
<Select
|
||||
value={limit}
|
||||
onChange={(v) => {
|
||||
setLimit(v);
|
||||
load(1, v); // 改每页大小:回到第 1 页并重查
|
||||
}}
|
||||
style={{ width: 120 }}
|
||||
options={[20, 50, 100, 200, 500, 1000].map((n) => ({ value: n, label: `${n} 条/页` }))}
|
||||
/>
|
||||
</Space>
|
||||
<Button type="primary" onClick={() => load(1)} loading={loading}>
|
||||
查询
|
||||
</Button>
|
||||
</Space>
|
||||
@@ -575,41 +657,46 @@ export default function AdRevenueReportPage() {
|
||||
<Card size="small" style={{ marginBottom: 16 }}>
|
||||
<Divider orientation="left" plain style={{ marginTop: 0, marginBottom: 16 }}>
|
||||
<Typography.Text type="secondary" style={{ fontSize: 12 }}>
|
||||
广告展示与收益
|
||||
核心指标
|
||||
</Typography.Text>
|
||||
</Divider>
|
||||
<Row gutter={[16, 12]}>
|
||||
<Col span={6}>
|
||||
<Statistic title="展示条数合计" value={data.total_impressions} />
|
||||
</Col>
|
||||
<Col span={6}>
|
||||
<Statistic title="平均 eCPM(元/千次)" value={derived.avgEcpm} precision={2} />
|
||||
</Col>
|
||||
<Col span={6}>
|
||||
<Col flex="1 1 0">
|
||||
<Statistic title="预估收益合计(元)" value={data.total_revenue_yuan} precision={4} />
|
||||
</Col>
|
||||
<Col span={6}>
|
||||
<Statistic title="广告事件数" value={data.total} />
|
||||
</Col>
|
||||
</Row>
|
||||
<Divider orientation="left" plain style={{ marginTop: 20, marginBottom: 16 }}>
|
||||
<Typography.Text type="secondary" style={{ fontSize: 12 }}>
|
||||
发奖与对账
|
||||
</Typography.Text>
|
||||
</Divider>
|
||||
<Row gutter={[16, 12]}>
|
||||
<Col span={6}>
|
||||
<Statistic title="应发金币合计" value={data.total_expected_coin} />
|
||||
</Col>
|
||||
<Col span={6}>
|
||||
<Statistic title="实发金币合计" value={data.total_actual_coin} />
|
||||
</Col>
|
||||
<Col span={6}>
|
||||
<Statistic title="发奖成本(元)" value={derived.payoutYuan} precision={4} />
|
||||
</Col>
|
||||
<Col span={6}>
|
||||
<Col flex="1 1 0">
|
||||
<Statistic
|
||||
title="预估毛利(元)"
|
||||
title={
|
||||
<Tooltip title="每活跃用户广告预估收入 = 预估收益 ÷ 今日 DAU;DAU 仅今日口径,历史/多天显示 -">
|
||||
<span>
|
||||
ARPU(今日)
|
||||
<InfoCircleOutlined style={{ marginLeft: 4 }} />
|
||||
</span>
|
||||
</Tooltip>
|
||||
}
|
||||
value={derived.arpu ?? '-'}
|
||||
precision={4}
|
||||
/>
|
||||
</Col>
|
||||
<Col flex="1 1 0">
|
||||
<Statistic
|
||||
title={
|
||||
<Tooltip title="今日活跃用户(复用大盘口径 last_login_at = 今日登录过);仅查询=今日时有值,历史/多天显示 -">
|
||||
<span>
|
||||
今日活跃 DAU
|
||||
<InfoCircleOutlined style={{ marginLeft: 4 }} />
|
||||
</span>
|
||||
</Tooltip>
|
||||
}
|
||||
value={data.dau ?? '-'}
|
||||
/>
|
||||
</Col>
|
||||
<Col flex="1 1 0">
|
||||
<Statistic title="发放金币合计(元)" value={derived.payoutYuan} precision={4} />
|
||||
</Col>
|
||||
<Col flex="1 1 0">
|
||||
<Statistic
|
||||
title="预估广告毛利(元)"
|
||||
value={derived.grossProfit}
|
||||
precision={4}
|
||||
prefix={derived.grossProfit >= 0 ? <RiseOutlined /> : <FallOutlined />}
|
||||
@@ -621,52 +708,101 @@ export default function AdRevenueReportPage() {
|
||||
</Typography.Text>
|
||||
</Col>
|
||||
</Row>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{data && (
|
||||
<Space direction="vertical" style={{ width: '100%', marginBottom: 12 }}>
|
||||
{data.mismatch_count > 0 ? (
|
||||
<Alert
|
||||
type="error"
|
||||
showIcon
|
||||
message={`共 ${data.total} 条广告事件,其中 ${data.mismatch_count} 条应发≠实发(✗);应发−实发 合计 ${
|
||||
derived && derived.coinGap >= 0 ? '+' : ''
|
||||
}${derived?.coinGap ?? 0} 金币(正=少发/负=多发)——公式可能未生效或发奖有问题。定位到具体记录可用后端逐条审计接口。`}
|
||||
/>
|
||||
<Divider orientation="left" plain style={{ marginTop: 20, marginBottom: 16 }}>
|
||||
<Tooltip title="来自穿山甲 GroMore 数据 API(后台结算口径,T+1 次日出数)。穿山甲不提供分用户/类型/场景维度,故仅在「全量视图」(未按用户/类型/场景筛选)展示;按代码位×应用×日期汇总。revenue=预估收益、收益API=各 ADN 回传更接近结算。">
|
||||
<Typography.Text type="secondary" style={{ fontSize: 12 }}>
|
||||
穿山甲后台收益(T+1)
|
||||
<InfoCircleOutlined style={{ marginLeft: 4 }} />
|
||||
</Typography.Text>
|
||||
</Tooltip>
|
||||
</Divider>
|
||||
{data.pangle_revenue_available ? (
|
||||
<Row gutter={[16, 12]}>
|
||||
<Col flex="1 1 0">
|
||||
<Statistic
|
||||
title="穿山甲预估收益(元)"
|
||||
value={data.total_pangle_revenue_yuan ?? 0}
|
||||
precision={4}
|
||||
/>
|
||||
</Col>
|
||||
<Col flex="1 1 0">
|
||||
<Statistic
|
||||
title="穿山甲收益API(元)"
|
||||
value={data.total_pangle_api_revenue_yuan ?? '-'}
|
||||
precision={data.total_pangle_api_revenue_yuan == null ? undefined : 4}
|
||||
/>
|
||||
{data.total_pangle_api_revenue_yuan == null && (
|
||||
<Typography.Text type="secondary" style={{ fontSize: 12 }}>
|
||||
未配 Reporting / 当天无
|
||||
</Typography.Text>
|
||||
)}
|
||||
</Col>
|
||||
<Col flex="1 1 0">
|
||||
<Statistic
|
||||
title={
|
||||
<Tooltip title="客户端预估相对穿山甲预估的高估幅度 =(客户端预估 − 穿山甲预估)÷ 穿山甲预估;客户端按 onAdShow 计、不滤无效曝光,通常偏高">
|
||||
<span>
|
||||
客户端预估偏差
|
||||
<InfoCircleOutlined style={{ marginLeft: 4 }} />
|
||||
</span>
|
||||
</Tooltip>
|
||||
}
|
||||
value={
|
||||
data.total_pangle_revenue_yuan && data.total_pangle_revenue_yuan > 0
|
||||
? ((data.total_revenue_yuan - data.total_pangle_revenue_yuan) /
|
||||
data.total_pangle_revenue_yuan) *
|
||||
100
|
||||
: '-'
|
||||
}
|
||||
precision={
|
||||
data.total_pangle_revenue_yuan && data.total_pangle_revenue_yuan > 0
|
||||
? 1
|
||||
: undefined
|
||||
}
|
||||
suffix={
|
||||
data.total_pangle_revenue_yuan && data.total_pangle_revenue_yuan > 0 ? '%' : ''
|
||||
}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
) : (
|
||||
<Alert type="success" showIcon message={`共 ${data.total} 条广告事件,应发与实发全部一致。`} />
|
||||
<Typography.Text type="secondary" style={{ fontSize: 13 }}>
|
||||
本视图无穿山甲后台收益:仅「全量视图」(未按用户/类型/场景筛选)且对应日期已同步到数据时展示。
|
||||
穿山甲 T+1 出数,可由 <Typography.Text code>scripts/sync_pangle_revenue</Typography.Text> 每日拉取入库。
|
||||
</Typography.Text>
|
||||
)}
|
||||
{data.truncated && (
|
||||
<Alert
|
||||
type="warning"
|
||||
showIcon
|
||||
message={`明细已截断到 ${queriedLimit} 条,还有更多未显示——请按用户/类型/日期缩小范围,或调大「条数」。合计数字不受影响。`}
|
||||
/>
|
||||
)}
|
||||
{sceneCoinSubtotal != null && (
|
||||
<Alert
|
||||
type="info"
|
||||
showIcon
|
||||
message={
|
||||
<span>
|
||||
当前已加载明细中,
|
||||
<Tag color={SCENE_TAG[scene!].color} style={{ marginInline: 4 }}>
|
||||
{SCENE_TAG[scene!].text}
|
||||
</Tag>
|
||||
Draw 信息流 实发金币小计 <b>{sceneCoinSubtotal}</b>(共 {filteredItems.length} 条;
|
||||
仅明细口径,若已截断可能偏少;上方汇总/趋势仍为全量)。
|
||||
</span>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
</Space>
|
||||
<Divider orientation="left" plain style={{ marginTop: 20, marginBottom: 16 }}>
|
||||
<Typography.Text type="secondary" style={{ fontSize: 12 }}>
|
||||
分广告类型
|
||||
</Typography.Text>
|
||||
</Divider>
|
||||
<Row gutter={[16, 12]}>
|
||||
<Col span={4}>
|
||||
<Statistic title="Draw 信息流收益(元)" value={drawStat?.revenue_yuan ?? 0} precision={4} />
|
||||
</Col>
|
||||
<Col span={4}>
|
||||
<Statistic title="Draw 信息流 eCPM(元/千次)" value={ecpmOf(drawStat)} precision={2} />
|
||||
</Col>
|
||||
<Col span={4}>
|
||||
<Statistic title="Draw 信息流条数" value={drawStat?.impressions ?? 0} />
|
||||
</Col>
|
||||
<Col span={4}>
|
||||
<Statistic title="激励视频收益(元)" value={rvStat?.revenue_yuan ?? 0} precision={4} />
|
||||
</Col>
|
||||
<Col span={4}>
|
||||
<Statistic title="激励视频 eCPM(元/千次)" value={ecpmOf(rvStat)} precision={2} />
|
||||
</Col>
|
||||
<Col span={4}>
|
||||
<Statistic title="激励视频条数" value={rvStat?.impressions ?? 0} />
|
||||
</Col>
|
||||
</Row>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{data &&
|
||||
(queriedMultiDay
|
||||
? (data.daily?.length ?? 0) > 0
|
||||
: queriedGranularity === 'hour' && (data.items?.length ?? 0) > 0) && (
|
||||
: queriedGranularity === 'hour' && (data.hourly?.length ?? 0) > 0) && (
|
||||
<Card
|
||||
size="small"
|
||||
title={queriedMultiDay ? '按天趋势' : '按小时趋势'}
|
||||
@@ -696,32 +832,30 @@ export default function AdRevenueReportPage() {
|
||||
verticalAlign: 'middle',
|
||||
}}
|
||||
/>
|
||||
预估收益(元)
|
||||
客户端预估收益(元)
|
||||
</span>
|
||||
{queriedMultiDay && (
|
||||
<span style={{ fontSize: 12, color: '#666' }}>
|
||||
<span
|
||||
style={{
|
||||
display: 'inline-block',
|
||||
width: 14,
|
||||
borderTop: `2px solid ${CHART_LINE2}`,
|
||||
marginRight: 4,
|
||||
verticalAlign: 'middle',
|
||||
}}
|
||||
/>
|
||||
穿山甲后台收益(元)
|
||||
</span>
|
||||
)}
|
||||
</Space>
|
||||
}
|
||||
>
|
||||
{/* 趋势图与日汇总恒为全量:按天图用 daily(全量),按小时图用全量 items;「场景」前端过滤只作用于下方明细表,不影响此图。 */}
|
||||
{!queriedMultiDay && data.truncated && (
|
||||
<Alert
|
||||
type="warning"
|
||||
showIcon
|
||||
style={{ marginBottom: 12 }}
|
||||
message={`图表按小时聚合的是已截断到 ${queriedLimit} 组的明细,可能少算——调大「条数」或缩小筛选可还原真实趋势。`}
|
||||
/>
|
||||
)}
|
||||
{scene && (
|
||||
<Alert
|
||||
type="info"
|
||||
showIcon
|
||||
style={{ marginBottom: 12 }}
|
||||
message="趋势图为全量数据,不随「场景」筛选变化;场景过滤仅作用于下方明细表与其金币小计。"
|
||||
/>
|
||||
)}
|
||||
{/* 趋势图恒为全量(不受分页影响):按天图用 daily,按小时图用 hourly;「场景」已下推后端,趋势随场景筛选一并变化。 */}
|
||||
{queriedMultiDay ? (
|
||||
<TrendChart points={aggregateDaily(data.date_from, data.date_to, data.daily)} />
|
||||
) : (
|
||||
<TrendChart points={aggregateHourly(data.items)} />
|
||||
<TrendChart points={aggregateHourly(data.hourly)} />
|
||||
)}
|
||||
</Card>
|
||||
)}
|
||||
@@ -729,17 +863,39 @@ export default function AdRevenueReportPage() {
|
||||
<Table
|
||||
rowKey="event_key"
|
||||
columns={columns}
|
||||
dataSource={filteredItems}
|
||||
dataSource={items}
|
||||
loading={loading}
|
||||
pagination={false}
|
||||
pagination={{
|
||||
current: page,
|
||||
pageSize: queriedLimit,
|
||||
total: data?.total ?? 0,
|
||||
showSizeChanger: false,
|
||||
showTotal: (t) => `共 ${t} 条`,
|
||||
onChange: (p) => load(p, queriedLimit),
|
||||
}}
|
||||
size="small"
|
||||
scroll={{ x: 1280 }}
|
||||
rowClassName={(r) => (r.has_reward && !r.matched ? 'row-mismatch' : '')}
|
||||
scroll={{ x: 1380 }}
|
||||
expandable={{
|
||||
// 只有发了奖的事件可展开,看「这条广告金币怎么算的」;纯展示行无复算、不可展开。
|
||||
rowExpandable: (r) => r.reward_detail != null,
|
||||
// 每行都可展开(左侧恒有 + 号):有发奖看「金币复算因子」;纯展示看「展示明细」。
|
||||
rowExpandable: () => true,
|
||||
expandedRowRender: (r) =>
|
||||
r.reward_detail ? (
|
||||
r.sub_rewards && r.sub_rewards.length > 0 ? (
|
||||
<div>
|
||||
<Typography.Text strong>本次广告逐条明细</Typography.Text>{' '}
|
||||
<Typography.Text type="secondary">
|
||||
(共 {r.sub_count ?? r.sub_rewards.length} 条 · 应发 {r.expected_coin} / 实发 {r.actual_coin})
|
||||
</Typography.Text>
|
||||
<Table<AdRevenueRecord>
|
||||
style={{ marginTop: 8 }}
|
||||
rowKey="record_id"
|
||||
columns={DETAIL_COLUMNS}
|
||||
dataSource={r.sub_rewards}
|
||||
pagination={false}
|
||||
size="small"
|
||||
scroll={{ x: 900 }}
|
||||
/>
|
||||
</div>
|
||||
) : r.reward_detail ? (
|
||||
<div>
|
||||
<Typography.Text strong>金币复算明细</Typography.Text>{' '}
|
||||
<Typography.Text type="secondary">
|
||||
@@ -753,10 +909,30 @@ export default function AdRevenueReportPage() {
|
||||
pagination={false}
|
||||
size="small"
|
||||
scroll={{ x: 900 }}
|
||||
rowClassName={(d) => (d.matched ? '' : 'row-mismatch')}
|
||||
/>
|
||||
</div>
|
||||
) : null,
|
||||
) : (
|
||||
<div>
|
||||
<Typography.Text strong>展示明细</Typography.Text>{' '}
|
||||
<Typography.Text type="secondary">(纯展示事件,未单独发奖,无金币复算)</Typography.Text>
|
||||
<Descriptions size="small" column={3} bordered style={{ marginTop: 8 }}>
|
||||
<Descriptions.Item label="时间">{formatUtcTime(r.created_at)}</Descriptions.Item>
|
||||
<Descriptions.Item label="eCPM(分)">{r.ecpm ?? '-'}</Descriptions.Item>
|
||||
<Descriptions.Item label="eCPM(元)">
|
||||
{r.ecpm != null && !Number.isNaN(Number(r.ecpm))
|
||||
? (Number(r.ecpm) / 100).toFixed(2)
|
||||
: '-'}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="预估收益(元)">
|
||||
{r.has_impression ? r.revenue_yuan.toFixed(4) : '-'}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="底层 ADN">{r.adn ?? '-'}</Descriptions.Item>
|
||||
<Descriptions.Item label="底层代码位(rit)">{r.slot_id ?? '-'}</Descriptions.Item>
|
||||
<Descriptions.Item label="我方代码位">{r.our_code_id ?? '-'}</Descriptions.Item>
|
||||
<Descriptions.Item label="来源应用">{r.app_env ?? '-'}</Descriptions.Item>
|
||||
</Descriptions>
|
||||
</div>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
<Modal
|
||||
@@ -772,7 +948,7 @@ export default function AdRevenueReportPage() {
|
||||
<Typography.Paragraph type="secondary" style={{ fontSize: 13 }}>
|
||||
· eCPM 取自穿山甲 SDK <Typography.Text code>getEcpm()</Typography.Text> 原值,单位「分/千次展示」,计算时 ÷100 转元;单次收益按「每千次 ÷1000」折到每次。
|
||||
<br />· 金币汇率:<b>1 元 = {COIN_PER_YUAN.toLocaleString()} 金币</b>,最终四舍五入取整。
|
||||
<br />· 因子2「LT 累计条数」按该账号累计第几条计(不按天重置);激励视频每次 1 条,信息流每满 10 秒折 1 条。
|
||||
<br />· 因子2「LT 累计条数」按该账号累计第几条计(不按天重置);<b>一条广告 = 1 条</b>(激励视频每次 1 条;信息流看满 10 秒即发该条满额,不按时长折多份)。
|
||||
<br />· 本表与发奖后端同源,本页「应发金币」即按此复算并与「实发金币」对账。
|
||||
</Typography.Paragraph>
|
||||
<Row gutter={16}>
|
||||
@@ -808,11 +984,12 @@ export default function AdRevenueReportPage() {
|
||||
</Typography.Paragraph>
|
||||
</Modal>
|
||||
|
||||
<style jsx global>{`
|
||||
.row-mismatch > td {
|
||||
background: #fff1f0 !important;
|
||||
}
|
||||
`}</style>
|
||||
<UserAdRevenueDrawer
|
||||
open={!!userDrawer}
|
||||
userId={userDrawer?.userId ?? null}
|
||||
phone={userDrawer?.phone ?? null}
|
||||
onClose={() => setUserDrawer(null)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ const { Text } = Typography;
|
||||
|
||||
const ACCEPT = ['image/jpeg', 'image/png', 'image/webp'];
|
||||
|
||||
/** 反馈页「加群二维码」卡配置。改完 App 意见反馈页下次进入即同步。「反馈工单」页的一个区块。 */
|
||||
/** 反馈页「加群二维码」卡配置。改完 App 意见反馈页下次进入即同步。「系统配置 → 反馈二维码」tab 的一个区块。 */
|
||||
export default function FeedbackQrConfig() {
|
||||
const [cfg, setCfg] = useState<QrConfig | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
+1
-1
@@ -49,7 +49,7 @@ interface PreviewItem {
|
||||
|
||||
const yuan = (cents: number) => (cents / 100).toFixed(2);
|
||||
|
||||
/** 首页轮播「种子」管理(真实记录不足时的兜底假数据,现为「生成规则」)。「数据大盘」页的一个区块。 */
|
||||
/** 首页轮播「种子」管理(真实记录不足时的兜底假数据,现为「生成规则」)。「系统配置 / 首页」里的一个区块。 */
|
||||
export default function HomeMarqueeSeeds() {
|
||||
const { message } = App.useApp();
|
||||
const [seeds, setSeeds] = useState<Seed[]>([]);
|
||||
+1
-1
@@ -246,7 +246,7 @@ function buildBody(metric: string, e: Edit, immediate: boolean): Record<string,
|
||||
return body;
|
||||
}
|
||||
|
||||
/** 首页三门面数字(帮助用户/完成比价/累计节省)的展示模式配置。作为「数据大盘」页的一个区块。 */
|
||||
/** 首页三门面数字(帮助用户/完成比价/累计节省)的展示模式配置。「系统配置 / 首页」里的一个区块。 */
|
||||
export default function HomeStatsConfig() {
|
||||
const { message, modal } = App.useApp();
|
||||
const [items, setItems] = useState<StatItem[]>([]);
|
||||
@@ -1,8 +1,11 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useState } from 'react';
|
||||
import { App, Button, Card, Input, InputNumber, Space, Spin, Switch, Tag, Tooltip } from 'antd';
|
||||
import { App, Button, Card, Input, InputNumber, Space, Spin, Switch, Tabs, Tag, Tooltip } from 'antd';
|
||||
import { api, errMsg } from '@/lib/api';
|
||||
import HomeMarqueeSeeds from './HomeMarqueeSeeds';
|
||||
import HomeStatsConfig from './HomeStatsConfig';
|
||||
import FeedbackQrConfig from './FeedbackQrConfig';
|
||||
|
||||
interface ConfigItem {
|
||||
key: string;
|
||||
@@ -80,9 +83,66 @@ export default function ConfigPage() {
|
||||
}
|
||||
};
|
||||
|
||||
if (loading) return <Spin style={{ display: 'block', marginTop: 80 }} />;
|
||||
|
||||
const groups = [...new Set(items.map((i) => i.group))];
|
||||
const welfareConfig = loading ? (
|
||||
<Spin style={{ display: 'block', marginTop: 24 }} />
|
||||
) : (
|
||||
groups.map((g) => (
|
||||
<Card key={g} title={g} size="small" style={{ marginBottom: 16 }}>
|
||||
{items
|
||||
.filter((i) => i.group === g)
|
||||
.map((item) => (
|
||||
<div
|
||||
key={item.key}
|
||||
style={{ marginBottom: 12, paddingBottom: 12, borderBottom: '1px solid #f0f0f0' }}
|
||||
>
|
||||
<div style={{ marginBottom: 4 }}>
|
||||
<b>{item.label}</b> {item.overridden ? <Tag color="blue">已改</Tag> : <Tag>默认</Tag>}
|
||||
{item.help && (
|
||||
<Tooltip title={item.help}>
|
||||
<span style={{ color: '#999', marginLeft: 6, fontSize: 12, cursor: 'help' }}>
|
||||
ⓘ
|
||||
</span>
|
||||
</Tooltip>
|
||||
)}
|
||||
</div>
|
||||
<Space wrap>
|
||||
{item.type === 'bool' ? (
|
||||
<Switch
|
||||
checked={!!edits[item.key]}
|
||||
onChange={(v) => setEdits({ ...edits, [item.key]: v })}
|
||||
/>
|
||||
) : item.type === 'int' ? (
|
||||
<InputNumber
|
||||
value={edits[item.key]}
|
||||
onChange={(v) => setEdits({ ...edits, [item.key]: v })}
|
||||
style={{ width: 180 }}
|
||||
/>
|
||||
) : (
|
||||
<Input
|
||||
value={edits[item.key]}
|
||||
onChange={(e) => setEdits({ ...edits, [item.key]: e.target.value })}
|
||||
style={{ width: 380 }}
|
||||
placeholder={
|
||||
item.type === 'int_list' ? '逗号分隔,如 10, 20, 30' : 'JSON,如 {"key": 100}'
|
||||
}
|
||||
/>
|
||||
)}
|
||||
<Button
|
||||
type="primary"
|
||||
size="small"
|
||||
loading={saving === item.key}
|
||||
onClick={() => save(item)}
|
||||
>
|
||||
保存
|
||||
</Button>
|
||||
<span style={{ color: '#bbb', fontSize: 12 }}>默认 {JSON.stringify(item.default)}</span>
|
||||
</Space>
|
||||
</div>
|
||||
))}
|
||||
</Card>
|
||||
))
|
||||
);
|
||||
|
||||
return (
|
||||
<div>
|
||||
@@ -90,64 +150,22 @@ export default function ConfigPage() {
|
||||
<p style={{ color: '#999' }}>
|
||||
改完即生效(业务下次读取用新值)。涉及金额 / 上限,改前请确认。每次改动都进审计日志。
|
||||
</p>
|
||||
{groups.map((g) => (
|
||||
<Card key={g} title={g} size="small" style={{ marginBottom: 16 }}>
|
||||
{items
|
||||
.filter((i) => i.group === g)
|
||||
.map((item) => (
|
||||
<div
|
||||
key={item.key}
|
||||
style={{ marginBottom: 12, paddingBottom: 12, borderBottom: '1px solid #f0f0f0' }}
|
||||
>
|
||||
<div style={{ marginBottom: 4 }}>
|
||||
<b>{item.label}</b>{' '}
|
||||
{item.overridden ? <Tag color="blue">已改</Tag> : <Tag>默认</Tag>}
|
||||
{item.help && (
|
||||
<Tooltip title={item.help}>
|
||||
<span style={{ color: '#999', marginLeft: 6, fontSize: 12, cursor: 'help' }}>
|
||||
ⓘ
|
||||
</span>
|
||||
</Tooltip>
|
||||
)}
|
||||
</div>
|
||||
<Space wrap>
|
||||
{item.type === 'bool' ? (
|
||||
<Switch
|
||||
checked={!!edits[item.key]}
|
||||
onChange={(v) => setEdits({ ...edits, [item.key]: v })}
|
||||
/>
|
||||
) : item.type === 'int' ? (
|
||||
<InputNumber
|
||||
value={edits[item.key]}
|
||||
onChange={(v) => setEdits({ ...edits, [item.key]: v })}
|
||||
style={{ width: 180 }}
|
||||
/>
|
||||
) : (
|
||||
<Input
|
||||
value={edits[item.key]}
|
||||
onChange={(e) => setEdits({ ...edits, [item.key]: e.target.value })}
|
||||
style={{ width: 380 }}
|
||||
placeholder={
|
||||
item.type === 'int_list' ? '逗号分隔,如 10, 20, 30' : 'JSON,如 {"key": 100}'
|
||||
}
|
||||
/>
|
||||
)}
|
||||
<Button
|
||||
type="primary"
|
||||
size="small"
|
||||
loading={saving === item.key}
|
||||
onClick={() => save(item)}
|
||||
>
|
||||
保存
|
||||
</Button>
|
||||
<span style={{ color: '#bbb', fontSize: 12 }}>
|
||||
默认 {JSON.stringify(item.default)}
|
||||
</span>
|
||||
</Space>
|
||||
</div>
|
||||
))}
|
||||
</Card>
|
||||
))}
|
||||
<Tabs
|
||||
items={[
|
||||
{
|
||||
key: 'home',
|
||||
label: '首页',
|
||||
children: (
|
||||
<>
|
||||
<HomeStatsConfig />
|
||||
<HomeMarqueeSeeds />
|
||||
</>
|
||||
),
|
||||
},
|
||||
{ key: 'welfare', label: '福利页', children: welfareConfig },
|
||||
{ key: 'feedback-qr', label: '反馈二维码', children: <FeedbackQrConfig /> },
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,677 @@
|
||||
'use client';
|
||||
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import type { ColumnsType } from 'antd/es/table';
|
||||
import {
|
||||
App,
|
||||
Button,
|
||||
Card,
|
||||
Col,
|
||||
DatePicker,
|
||||
Divider,
|
||||
Input,
|
||||
Row,
|
||||
Select,
|
||||
Space,
|
||||
Statistic,
|
||||
Table,
|
||||
Tag,
|
||||
Typography,
|
||||
} from 'antd';
|
||||
import dayjs, { type Dayjs } from 'dayjs';
|
||||
import { api, errMsg } from '@/lib/api';
|
||||
import { formatUtcTime } from '@/lib/format';
|
||||
import UserRecordsDrawer from '@/components/UserRecordsDrawer';
|
||||
|
||||
const { RangePicker } = DatePicker;
|
||||
|
||||
// ── 领券数据看板类型(仅本页用,内联定义)──
|
||||
interface CouponDataSummary {
|
||||
started_count: number;
|
||||
completed_count: number;
|
||||
avg_elapsed_ms: number | null;
|
||||
p5_ms: number | null;
|
||||
p50_ms: number | null;
|
||||
p95_ms: number | null;
|
||||
p99_ms: number | null;
|
||||
}
|
||||
interface CouponDataDaily {
|
||||
date: string;
|
||||
started_count: number;
|
||||
completed_count: number;
|
||||
avg_elapsed_ms: number | null;
|
||||
}
|
||||
interface CouponDataHourly {
|
||||
hour: number;
|
||||
started_count: number;
|
||||
completed_count: number;
|
||||
avg_elapsed_ms: number | null;
|
||||
}
|
||||
interface CouponDataRow {
|
||||
id: number;
|
||||
trace_id: string;
|
||||
user_id: number | null;
|
||||
user_phone: string | null;
|
||||
user_nickname: string | null;
|
||||
status: string;
|
||||
platforms: string[] | null;
|
||||
origin_package: string | null;
|
||||
elapsed_ms: number | null;
|
||||
platform_elapsed: Record<string, number> | null;
|
||||
device_model: string | null;
|
||||
rom: string | null;
|
||||
app_env: string | null;
|
||||
started_at: string;
|
||||
claimed_count: number | null;
|
||||
trace_url: string | null;
|
||||
}
|
||||
interface CouponDataReport {
|
||||
date_from: string;
|
||||
date_to: string;
|
||||
summary: CouponDataSummary;
|
||||
daily: CouponDataDaily[];
|
||||
hourly: CouponDataHourly[];
|
||||
total: number;
|
||||
items: CouponDataRow[];
|
||||
}
|
||||
|
||||
// 发起来源 App 包名 → 中文(「发起平台」列):空=傻瓜比价首页发起,外卖 App 包名→对应平台。
|
||||
function originLabel(pkg: string | null): string {
|
||||
if (!pkg) return '傻瓜比价';
|
||||
if (pkg.includes('meituan') || pkg.includes('sankuai')) return '美团';
|
||||
if (pkg.includes('taobao') || pkg.includes('ele')) return '淘宝';
|
||||
if (pkg.includes('jingdong') || pkg.includes('jd')) return '京东';
|
||||
return pkg;
|
||||
}
|
||||
|
||||
// 领券状态 → 颜色 + 中文(started 无终态 = 中途流失)
|
||||
const STATUS_TAG: Record<string, { color: string; label: string }> = {
|
||||
started: { color: 'default', label: '未完成' },
|
||||
completed: { color: 'green', label: '完成' },
|
||||
failed: { color: 'red', label: '失败' },
|
||||
abandoned: { color: 'orange', label: '中途退出' },
|
||||
};
|
||||
|
||||
// ms → "1.5s"(空值显示 -)
|
||||
const fmtSec = (ms: number | null | undefined): string =>
|
||||
ms == null ? '-' : `${(ms / 1000).toFixed(1)}s`;
|
||||
|
||||
// 点手机号弹出的「该用户全部领券」抽屉列(精简版:单用户,不含用户/手机号列)。
|
||||
const RECORD_COLUMNS: ColumnsType<CouponDataRow> = [
|
||||
{ title: '时间', dataIndex: 'started_at', width: 160, render: (v: string) => formatUtcTime(v) },
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
width: 80,
|
||||
render: (s: string) => {
|
||||
const t = STATUS_TAG[s] ?? { color: 'default', label: s };
|
||||
return <Tag color={t.color}>{t.label}</Tag>;
|
||||
},
|
||||
},
|
||||
{ title: '发起平台', dataIndex: 'origin_package', width: 90, render: (pkg: string | null) => originLabel(pkg) },
|
||||
{ title: '耗时', dataIndex: 'elapsed_ms', width: 80, align: 'right', render: (v: number | null) => fmtSec(v) },
|
||||
{ title: '美团', key: 'mt', width: 70, align: 'right', render: (_: unknown, r: CouponDataRow) => fmtSec(r.platform_elapsed?.['meituan-waimai']) },
|
||||
{ title: '淘宝', key: 'tb', width: 70, align: 'right', render: (_: unknown, r: CouponDataRow) => fmtSec(r.platform_elapsed?.['taobao-shanguang']) },
|
||||
{ title: '京东', key: 'jd', width: 70, align: 'right', render: (_: unknown, r: CouponDataRow) => fmtSec(r.platform_elapsed?.['jd-waimai']) },
|
||||
{
|
||||
title: 'trace',
|
||||
dataIndex: 'trace_id',
|
||||
width: 90,
|
||||
render: (v: string, r: CouponDataRow) =>
|
||||
r.trace_url ? (
|
||||
<a href={r.trace_url} target="_blank" rel="noreferrer" title={v}>trace</a>
|
||||
) : (
|
||||
<Typography.Text type="secondary" style={{ fontSize: 12 }}>{v.slice(0, 6)}…</Typography.Text>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
// ── 趋势图(纯 SVG,零依赖,复用广告报表同款):浅蓝柱=发起数、深蓝柱=完成数(左轴 次数),橙线=平均耗时(右轴 秒)──
|
||||
const CHART_BAR_STARTED = '#bae0ff';
|
||||
const CHART_BAR_COMPLETED = '#1677ff';
|
||||
const CHART_LINE = '#fa8c16';
|
||||
|
||||
interface TrendPoint {
|
||||
label: string; // x 轴刻度(小时数 / MM-DD)
|
||||
tip: string; // hover 原生 tooltip
|
||||
started: number;
|
||||
completed: number;
|
||||
avgSec: number | null; // 平均耗时(秒);该桶无完成为 null(不画线点)
|
||||
}
|
||||
|
||||
// 按天聚合:用 from..to 补齐空缺日为 0,轴连续。
|
||||
function aggregateDaily(dateFrom: string, dateTo: string, daily: CouponDataDaily[]): TrendPoint[] {
|
||||
const map = new Map(daily.map((d) => [d.date, d]));
|
||||
const out: TrendPoint[] = [];
|
||||
let cur = dayjs(dateFrom);
|
||||
let guard = 0;
|
||||
while (cur.format('YYYY-MM-DD') <= dateTo && guard < 400) {
|
||||
const ds = cur.format('YYYY-MM-DD');
|
||||
const d = map.get(ds);
|
||||
const started = d?.started_count ?? 0;
|
||||
const completed = d?.completed_count ?? 0;
|
||||
const avgSec = d?.avg_elapsed_ms != null ? d.avg_elapsed_ms / 1000 : null;
|
||||
out.push({
|
||||
label: ds.slice(5),
|
||||
tip: `${ds} 发起 ${started} · 完成 ${completed} · 平均耗时 ${avgSec == null ? '-' : avgSec.toFixed(1) + 's'}`,
|
||||
started,
|
||||
completed,
|
||||
avgSec,
|
||||
});
|
||||
cur = cur.add(1, 'day');
|
||||
guard += 1;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// 按小时聚合(0–23)。
|
||||
function aggregateHourly(rows: CouponDataHourly[]): TrendPoint[] {
|
||||
const byHour = new Map(rows.map((r) => [r.hour, r]));
|
||||
return Array.from({ length: 24 }, (_, h) => {
|
||||
const r = byHour.get(h);
|
||||
const started = r?.started_count ?? 0;
|
||||
const completed = r?.completed_count ?? 0;
|
||||
const avgSec = r?.avg_elapsed_ms != null ? r.avg_elapsed_ms / 1000 : null;
|
||||
return {
|
||||
label: String(h),
|
||||
tip: `${String(h).padStart(2, '0')}:00 发起 ${started} · 完成 ${completed} · 平均耗时 ${avgSec == null ? '-' : avgSec.toFixed(1) + 's'}`,
|
||||
started,
|
||||
completed,
|
||||
avgSec,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function TrendChart({ points }: { points: TrendPoint[] }) {
|
||||
const n = points.length;
|
||||
const maxBar = Math.max(1, ...points.map((p) => p.started));
|
||||
const maxSec = Math.max(1e-9, ...points.map((p) => p.avgSec ?? 0));
|
||||
|
||||
const W = 960;
|
||||
const H = 280;
|
||||
const padL = 48;
|
||||
const padR = 56;
|
||||
const padT = 16;
|
||||
const padB = 32;
|
||||
const plotW = W - padL - padR;
|
||||
const plotH = H - padT - padB;
|
||||
const step = plotW / Math.max(1, n);
|
||||
const barW = Math.min(24, step * 0.5);
|
||||
const yBase = padT + plotH;
|
||||
|
||||
const barX = (i: number) => padL + i * step + (step - barW) / 2;
|
||||
const cx = (i: number) => padL + i * step + step / 2;
|
||||
const barH = (v: number) => (v / maxBar) * plotH;
|
||||
const secY = (v: number) => yBase - (v / maxSec) * plotH;
|
||||
// X 轴刻度按天/按小时尽量每格都标(≤31 个点每个都标,超出才抽稀),避免跨度稍大就隔天显示。
|
||||
const labelEvery = Math.max(1, Math.ceil(n / 31));
|
||||
|
||||
// 平均耗时线:仅 avgSec 非 null 的点连线(无完成的桶断开)。
|
||||
const linePts = points
|
||||
.map((p, i) => (p.avgSec == null ? null : `${cx(i)},${secY(p.avgSec)}`))
|
||||
.filter((x): x is string => x !== null)
|
||||
.join(' ');
|
||||
|
||||
return (
|
||||
<svg viewBox={`0 0 ${W} ${H}`} width="100%" style={{ display: 'block' }} role="img" aria-label="趋势图">
|
||||
{[0, 0.25, 0.5, 0.75, 1].map((t) => {
|
||||
const y = yBase - t * plotH;
|
||||
return (
|
||||
<g key={t}>
|
||||
<line x1={padL} y1={y} x2={W - padR} y2={y} stroke="#f0f0f0" />
|
||||
<text x={padL - 8} y={y + 4} textAnchor="end" fontSize={11} fill={CHART_BAR_COMPLETED}>
|
||||
{Math.round(maxBar * t)}
|
||||
</text>
|
||||
<text x={W - padR + 8} y={y + 4} textAnchor="start" fontSize={11} fill={CHART_LINE}>
|
||||
{(maxSec * t).toFixed(1)}
|
||||
</text>
|
||||
</g>
|
||||
);
|
||||
})}
|
||||
{/* 发起数柱(浅) */}
|
||||
{points.map((p, i) => (
|
||||
<rect
|
||||
key={`s-${i}`}
|
||||
x={barX(i)}
|
||||
y={yBase - barH(p.started)}
|
||||
width={barW}
|
||||
height={barH(p.started)}
|
||||
fill={CHART_BAR_STARTED}
|
||||
rx={2}
|
||||
>
|
||||
<title>{p.tip}</title>
|
||||
</rect>
|
||||
))}
|
||||
{/* 完成数柱(深,窄,叠中间) */}
|
||||
{points.map((p, i) => {
|
||||
const cw = barW * 0.55;
|
||||
return (
|
||||
<rect
|
||||
key={`c-${i}`}
|
||||
x={cx(i) - cw / 2}
|
||||
y={yBase - barH(p.completed)}
|
||||
width={cw}
|
||||
height={barH(p.completed)}
|
||||
fill={CHART_BAR_COMPLETED}
|
||||
rx={1}
|
||||
>
|
||||
<title>{p.tip}</title>
|
||||
</rect>
|
||||
);
|
||||
})}
|
||||
{/* 平均耗时线(橙,右轴) */}
|
||||
<polyline points={linePts} fill="none" stroke={CHART_LINE} strokeWidth={2} />
|
||||
{points.map((p, i) =>
|
||||
p.avgSec == null ? null : (
|
||||
<circle key={`p-${i}`} cx={cx(i)} cy={secY(p.avgSec)} r={2.5} fill={CHART_LINE}>
|
||||
<title>{p.tip}</title>
|
||||
</circle>
|
||||
),
|
||||
)}
|
||||
{points.map((p, i) =>
|
||||
i % labelEvery === 0 || i === n - 1 ? (
|
||||
<text key={`x-${i}`} x={cx(i)} y={H - 14} textAnchor="middle" fontSize={11} fill="#999">
|
||||
{p.label}
|
||||
</text>
|
||||
) : null,
|
||||
)}
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
|
||||
// 领券数据看板:上半汇总卡 + 按天/小时趋势(参考广告收益大盘),下半逐条领券明细。
|
||||
// 数据源 coupon_session(客户端 /api/v1/coupon/session 两段上报);耗时统计只算 completed。
|
||||
export default function CouponDataPage() {
|
||||
const { message } = App.useApp();
|
||||
const [range, setRange] = useState<[Dayjs, Dayjs]>([dayjs().subtract(6, 'day'), dayjs()]);
|
||||
const [user, setUser] = useState<string>('');
|
||||
const [appEnv, setAppEnv] = useState<string>('prod');
|
||||
const [granularity, setGranularity] = useState<'day' | 'hour'>('day');
|
||||
const [sortBy, setSortBy] = useState<'time' | 'elapsed'>('time');
|
||||
const [limit, setLimit] = useState<number>(100);
|
||||
const [page, setPage] = useState<number>(1);
|
||||
const [queriedGranularity, setQueriedGranularity] = useState<'day' | 'hour'>('day');
|
||||
const [queriedMultiDay, setQueriedMultiDay] = useState(false);
|
||||
const [queriedLimit, setQueriedLimit] = useState<number>(100);
|
||||
const [data, setData] = useState<CouponDataReport | null>(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
// 点手机号:抽屉看该用户全部领券(总次数 + 记录)
|
||||
const [recordsUser, setRecordsUser] = useState<{ userId: number; phone: string | null } | null>(null);
|
||||
const openUserRecords = (r: CouponDataRow) => {
|
||||
if (r.user_id != null) setRecordsUser({ userId: r.user_id, phone: r.user_phone });
|
||||
};
|
||||
|
||||
// 跨多天时「按小时」无意义,粒度强制按天(同广告报表)。
|
||||
const rangeMultiDay = range[0].format('YYYY-MM-DD') !== range[1].format('YYYY-MM-DD');
|
||||
|
||||
const load = useCallback(
|
||||
async (targetPage = 1, targetLimit = limit, targetSort = sortBy) => {
|
||||
const from = range[0].format('YYYY-MM-DD');
|
||||
const to = range[1].format('YYYY-MM-DD');
|
||||
const multiDay = from !== to;
|
||||
const gran = multiDay ? 'day' : granularity;
|
||||
setLoading(true);
|
||||
try {
|
||||
const res = await api.get<CouponDataReport>('/admin/api/coupon-data', {
|
||||
params: {
|
||||
date_from: from,
|
||||
date_to: to,
|
||||
user: user.trim() || undefined,
|
||||
app_env: appEnv,
|
||||
granularity: gran,
|
||||
limit: targetLimit,
|
||||
offset: (targetPage - 1) * targetLimit,
|
||||
sort: targetSort,
|
||||
},
|
||||
});
|
||||
setData(res.data);
|
||||
setPage(targetPage);
|
||||
setQueriedLimit(targetLimit);
|
||||
setQueriedGranularity(gran);
|
||||
setQueriedMultiDay(multiDay);
|
||||
} catch (e) {
|
||||
message.error(errMsg(e));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
},
|
||||
[range, user, appEnv, granularity, limit, sortBy, message],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
load();
|
||||
// 仅首次自动拉近 7 天;之后由「查询」按钮触发
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
const columns: ColumnsType<CouponDataRow> = [
|
||||
{
|
||||
title: '用户',
|
||||
dataIndex: 'user_nickname',
|
||||
width: 140,
|
||||
render: (_: unknown, r: CouponDataRow) => {
|
||||
if (r.user_nickname) {
|
||||
return (
|
||||
<span>
|
||||
{r.user_nickname}
|
||||
{r.user_id != null && (
|
||||
<Typography.Text type="secondary" style={{ fontSize: 11, marginLeft: 6 }}>
|
||||
#{r.user_id}
|
||||
</Typography.Text>
|
||||
)}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
if (r.user_id != null) return <Typography.Text type="secondary">#{r.user_id}</Typography.Text>;
|
||||
return <Typography.Text type="secondary">游客</Typography.Text>;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '手机号',
|
||||
dataIndex: 'user_phone',
|
||||
width: 130,
|
||||
// 点手机号 → 抽屉看该用户全部领券(参考低价审核/反馈页)。游客(无 user_id)不可点。
|
||||
render: (phone: string | null, r: CouponDataRow) =>
|
||||
r.user_id != null ? (
|
||||
<a onClick={() => openUserRecords(r)}>{phone || `#${r.user_id}`}</a>
|
||||
) : (
|
||||
<Typography.Text type="secondary">游客</Typography.Text>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
width: 90,
|
||||
render: (s: string) => {
|
||||
const t = STATUS_TAG[s] ?? { color: 'default', label: s };
|
||||
return <Tag color={t.color}>{t.label}</Tag>;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '发起平台',
|
||||
dataIndex: 'origin_package',
|
||||
width: 110,
|
||||
render: (pkg: string | null) => originLabel(pkg),
|
||||
},
|
||||
{
|
||||
title: '耗时',
|
||||
dataIndex: 'elapsed_ms',
|
||||
width: 90,
|
||||
align: 'right',
|
||||
render: (v: number | null) => fmtSec(v),
|
||||
},
|
||||
{
|
||||
title: '美团耗时',
|
||||
key: 'mt_elapsed',
|
||||
width: 90,
|
||||
align: 'right',
|
||||
render: (_: unknown, r: CouponDataRow) => fmtSec(r.platform_elapsed?.['meituan-waimai']),
|
||||
},
|
||||
{
|
||||
title: '淘宝耗时',
|
||||
key: 'tb_elapsed',
|
||||
width: 90,
|
||||
align: 'right',
|
||||
render: (_: unknown, r: CouponDataRow) => fmtSec(r.platform_elapsed?.['taobao-shanguang']),
|
||||
},
|
||||
{
|
||||
title: '京东耗时',
|
||||
key: 'jd_elapsed',
|
||||
width: 90,
|
||||
align: 'right',
|
||||
render: (_: unknown, r: CouponDataRow) => fmtSec(r.platform_elapsed?.['jd-waimai']),
|
||||
},
|
||||
{
|
||||
title: '机型/ROM',
|
||||
key: 'device',
|
||||
width: 200,
|
||||
render: (_: unknown, r: CouponDataRow) => {
|
||||
const parts = [r.device_model, r.rom].filter(Boolean);
|
||||
return parts.length ? parts.join(' / ') : <Typography.Text type="secondary">-</Typography.Text>;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '时间',
|
||||
dataIndex: 'started_at',
|
||||
width: 165,
|
||||
render: (v: string) => formatUtcTime(v),
|
||||
},
|
||||
{
|
||||
title: '领券 trace',
|
||||
dataIndex: 'trace_id',
|
||||
width: 150,
|
||||
// 有 trace_url(pricebot 上云,仅 completed)→ 可点链接打开完整现场;否则降级为可复制 trace_id。
|
||||
render: (v: string, r: CouponDataRow) =>
|
||||
r.trace_url ? (
|
||||
<a href={r.trace_url} target="_blank" rel="noreferrer" title={v}>
|
||||
trace({v.slice(0, 8)}…)
|
||||
</a>
|
||||
) : (
|
||||
<Typography.Text copyable={{ text: v }} style={{ fontSize: 12 }}>
|
||||
{v.slice(0, 8)}…
|
||||
</Typography.Text>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
const summary = data?.summary;
|
||||
const items = data?.items ?? [];
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Space align="center" style={{ display: 'flex', marginBottom: 16 }}>
|
||||
<h2 style={{ margin: 0 }}>领券数据</h2>
|
||||
<Typography.Text type="secondary" style={{ fontSize: 12 }}>
|
||||
发起→完成耗时口径为客户端全程计时;均值/分位仅统计「完成」的领券
|
||||
</Typography.Text>
|
||||
</Space>
|
||||
|
||||
<Card size="small" style={{ marginBottom: 16 }}>
|
||||
<Space wrap size="middle" align="center">
|
||||
<Space size={6}>
|
||||
<Typography.Text type="secondary">日期</Typography.Text>
|
||||
<RangePicker
|
||||
value={range}
|
||||
onChange={(v) => v && v[0] && v[1] && setRange([v[0], v[1]])}
|
||||
allowClear={false}
|
||||
presets={[
|
||||
{ label: '今天', value: [dayjs(), dayjs()] },
|
||||
{ label: '近 7 天', value: [dayjs().subtract(6, 'day'), dayjs()] },
|
||||
{ label: '近 30 天', value: [dayjs().subtract(29, 'day'), dayjs()] },
|
||||
]}
|
||||
/>
|
||||
</Space>
|
||||
<Space size={6}>
|
||||
<Typography.Text type="secondary">用户</Typography.Text>
|
||||
<Input
|
||||
placeholder="手机号/昵称"
|
||||
value={user}
|
||||
onChange={(e) => setUser(e.target.value)}
|
||||
onPressEnter={() => load(1)}
|
||||
allowClear
|
||||
style={{ width: 150 }}
|
||||
/>
|
||||
</Space>
|
||||
<Space size={6}>
|
||||
<Typography.Text type="secondary">环境</Typography.Text>
|
||||
<Select
|
||||
value={appEnv}
|
||||
onChange={setAppEnv}
|
||||
style={{ width: 120 }}
|
||||
options={[
|
||||
{ value: 'prod', label: '正式(prod)' },
|
||||
{ value: 'dev', label: '测试(dev)' },
|
||||
{ value: 'all', label: '全部' },
|
||||
]}
|
||||
/>
|
||||
</Space>
|
||||
<Space size={6}>
|
||||
<Typography.Text type="secondary">粒度</Typography.Text>
|
||||
<Select
|
||||
value={rangeMultiDay ? 'day' : granularity}
|
||||
onChange={setGranularity}
|
||||
disabled={rangeMultiDay}
|
||||
style={{ width: 110 }}
|
||||
title={rangeMultiDay ? '跨多天仅支持按天' : undefined}
|
||||
options={[
|
||||
{ value: 'day', label: '按天' },
|
||||
{ value: 'hour', label: '按小时' },
|
||||
]}
|
||||
/>
|
||||
</Space>
|
||||
<Space size={6}>
|
||||
<Typography.Text type="secondary">排序</Typography.Text>
|
||||
<Select
|
||||
value={sortBy}
|
||||
onChange={(v) => {
|
||||
setSortBy(v);
|
||||
load(1, limit, v);
|
||||
}}
|
||||
style={{ width: 130 }}
|
||||
options={[
|
||||
{ value: 'time', label: '时间倒序' },
|
||||
{ value: 'elapsed', label: '耗时倒序' },
|
||||
]}
|
||||
/>
|
||||
</Space>
|
||||
<Space size={6}>
|
||||
<Typography.Text type="secondary">每页</Typography.Text>
|
||||
<Select
|
||||
value={limit}
|
||||
onChange={(v) => {
|
||||
setLimit(v);
|
||||
load(1, v);
|
||||
}}
|
||||
style={{ width: 120 }}
|
||||
options={[20, 50, 100, 200, 500].map((nn) => ({ value: nn, label: `${nn} 条/页` }))}
|
||||
/>
|
||||
</Space>
|
||||
<Button type="primary" onClick={() => load(1)} loading={loading}>
|
||||
查询
|
||||
</Button>
|
||||
</Space>
|
||||
</Card>
|
||||
|
||||
{summary && (
|
||||
<Card size="small" style={{ marginBottom: 16 }}>
|
||||
<Row gutter={[16, 12]}>
|
||||
<Col flex="1 1 0">
|
||||
<Statistic title="领券发起数" value={summary.started_count} />
|
||||
</Col>
|
||||
<Col flex="1 1 0">
|
||||
<Statistic title="领券完成数" value={summary.completed_count} />
|
||||
</Col>
|
||||
<Col flex="1 1 0">
|
||||
<Statistic title="平均耗时" value={fmtSec(summary.avg_elapsed_ms)} />
|
||||
</Col>
|
||||
</Row>
|
||||
<Divider style={{ marginTop: 16, marginBottom: 16 }} />
|
||||
<Row gutter={[16, 12]}>
|
||||
<Col flex="1 1 0">
|
||||
<Statistic title="耗时 5 分位" value={fmtSec(summary.p5_ms)} />
|
||||
</Col>
|
||||
<Col flex="1 1 0">
|
||||
<Statistic title="耗时 50 分位" value={fmtSec(summary.p50_ms)} />
|
||||
</Col>
|
||||
<Col flex="1 1 0">
|
||||
<Statistic title="耗时 95 分位" value={fmtSec(summary.p95_ms)} />
|
||||
</Col>
|
||||
<Col flex="1 1 0">
|
||||
<Statistic title="耗时 99 分位" value={fmtSec(summary.p99_ms)} />
|
||||
</Col>
|
||||
</Row>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{data &&
|
||||
(queriedMultiDay
|
||||
? (data.daily?.length ?? 0) > 0
|
||||
: queriedGranularity === 'hour' && (data.hourly?.length ?? 0) > 0) && (
|
||||
<Card
|
||||
size="small"
|
||||
title={queriedMultiDay ? '按天趋势' : '按小时趋势'}
|
||||
style={{ marginBottom: 16 }}
|
||||
extra={
|
||||
<Space size={16}>
|
||||
<span style={{ fontSize: 12, color: '#666' }}>
|
||||
<span
|
||||
style={{
|
||||
display: 'inline-block',
|
||||
width: 10,
|
||||
height: 10,
|
||||
background: CHART_BAR_STARTED,
|
||||
borderRadius: 2,
|
||||
marginRight: 4,
|
||||
}}
|
||||
/>
|
||||
发起数
|
||||
</span>
|
||||
<span style={{ fontSize: 12, color: '#666' }}>
|
||||
<span
|
||||
style={{
|
||||
display: 'inline-block',
|
||||
width: 10,
|
||||
height: 10,
|
||||
background: CHART_BAR_COMPLETED,
|
||||
borderRadius: 2,
|
||||
marginRight: 4,
|
||||
}}
|
||||
/>
|
||||
完成数
|
||||
</span>
|
||||
<span style={{ fontSize: 12, color: '#666' }}>
|
||||
<span
|
||||
style={{
|
||||
display: 'inline-block',
|
||||
width: 14,
|
||||
borderTop: `2px solid ${CHART_LINE}`,
|
||||
marginRight: 4,
|
||||
verticalAlign: 'middle',
|
||||
}}
|
||||
/>
|
||||
平均耗时(秒)
|
||||
</span>
|
||||
</Space>
|
||||
}
|
||||
>
|
||||
{queriedMultiDay ? (
|
||||
<TrendChart points={aggregateDaily(data.date_from, data.date_to, data.daily)} />
|
||||
) : (
|
||||
<TrendChart points={aggregateHourly(data.hourly)} />
|
||||
)}
|
||||
</Card>
|
||||
)}
|
||||
|
||||
<Table
|
||||
rowKey="trace_id"
|
||||
columns={columns}
|
||||
dataSource={items}
|
||||
loading={loading}
|
||||
pagination={{
|
||||
current: page,
|
||||
pageSize: queriedLimit,
|
||||
total: data?.total ?? 0,
|
||||
showSizeChanger: false,
|
||||
showTotal: (t) => `共 ${t} 条`,
|
||||
onChange: (p) => load(p, queriedLimit),
|
||||
}}
|
||||
size="small"
|
||||
scroll={{ x: 1450 }}
|
||||
/>
|
||||
|
||||
<UserRecordsDrawer<CouponDataRow>
|
||||
open={recordsUser != null}
|
||||
onClose={() => setRecordsUser(null)}
|
||||
userId={recordsUser?.userId ?? null}
|
||||
phone={recordsUser?.phone ?? null}
|
||||
endpoint="/admin/api/coupon-data/user-records"
|
||||
columns={RECORD_COLUMNS}
|
||||
recordLabel="领券"
|
||||
countLabel="领券次数"
|
||||
rewardLabel="领到券张数"
|
||||
rewardSuffix="张"
|
||||
rewardOf={(r) => r.claimed_count ?? 0}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+1502
-49
File diff suppressed because it is too large
Load Diff
@@ -19,7 +19,7 @@ import {
|
||||
} from 'antd';
|
||||
import { api, errMsg } from '@/lib/api';
|
||||
import { canDo } from '@/lib/auth';
|
||||
import { formatUtcTime } from '@/lib/format';
|
||||
import { formatWallTime } from '@/lib/format';
|
||||
import { mediaUrl } from '@/lib/media';
|
||||
import type { CursorPage, Feedback } from '@/lib/types';
|
||||
|
||||
@@ -49,6 +49,17 @@ const statusTag = (s: string) => {
|
||||
return <Tag color={m.color}>{m.label}</Tag>;
|
||||
};
|
||||
|
||||
// 反馈类型:comparison=比价反馈 / profile(及旧数据)=普通反馈
|
||||
const SOURCE_META: Record<string, { label: string; color: string }> = {
|
||||
comparison: { label: '比价反馈', color: 'geekblue' },
|
||||
profile: { label: '普通反馈', color: 'default' },
|
||||
};
|
||||
|
||||
const sourceTag = (s: string) => {
|
||||
const m = SOURCE_META[s] ?? { label: '普通反馈', color: 'default' };
|
||||
return <Tag color={m.color}>{m.label}</Tag>;
|
||||
};
|
||||
|
||||
function FeedbackImages({ images }: { images: string[] | null }) {
|
||||
if (!images || !images.length) return <Text type="secondary">无截图</Text>;
|
||||
return (
|
||||
@@ -113,12 +124,14 @@ export default function FeedbackHandleDrawer({ feedback, open, onClose, onDone }
|
||||
await api.post(`/admin/api/feedbacks/${feedback.id}/approve`, {
|
||||
reward_coins: v.reward_coins,
|
||||
note: v.note?.trim() || null,
|
||||
reply: v.reply?.trim() || null,
|
||||
});
|
||||
message.success(`已采纳,发放 ${v.reward_coins} 金币`);
|
||||
} else {
|
||||
await api.post(`/admin/api/feedbacks/${feedback.id}/reject`, {
|
||||
reason: v.reason.trim(),
|
||||
note: v.note?.trim() || null,
|
||||
reply: v.reply?.trim() || null,
|
||||
});
|
||||
message.success('已拒绝');
|
||||
}
|
||||
@@ -153,8 +166,16 @@ export default function FeedbackHandleDrawer({ feedback, open, onClose, onDone }
|
||||
{/* 本条反馈 */}
|
||||
<div>
|
||||
<Text type="secondary">
|
||||
用户 {feedback.user_id} · {formatUtcTime(feedback.created_at)}
|
||||
用户 {feedback.user_id} · {formatWallTime(feedback.created_at)}
|
||||
</Text>
|
||||
<div style={{ marginTop: 6 }}>
|
||||
{sourceTag(feedback.source)}
|
||||
{feedback.scene ? (
|
||||
<Text type="secondary" style={{ marginLeft: 6 }}>
|
||||
场景:{feedback.scene}
|
||||
</Text>
|
||||
) : null}
|
||||
</div>
|
||||
<Paragraph style={{ whiteSpace: 'pre-wrap', marginTop: 8, marginBottom: 8 }}>
|
||||
{feedback.content || '-'}
|
||||
</Paragraph>
|
||||
@@ -185,7 +206,7 @@ export default function FeedbackHandleDrawer({ feedback, open, onClose, onDone }
|
||||
<div>
|
||||
状态:{statusTag(feedback.status)}
|
||||
{feedback.reviewed_at ? (
|
||||
<Text type="secondary"> · {formatUtcTime(feedback.reviewed_at)}</Text>
|
||||
<Text type="secondary"> · {formatWallTime(feedback.reviewed_at)}</Text>
|
||||
) : null}
|
||||
</div>
|
||||
{feedback.status === 'adopted' && (
|
||||
@@ -200,7 +221,11 @@ export default function FeedbackHandleDrawer({ feedback, open, onClose, onDone }
|
||||
</div>
|
||||
)}
|
||||
<div style={{ marginTop: 6 }}>
|
||||
审核备注:{feedback.review_note || <Text type="secondary">(无)</Text>}
|
||||
审核备注(内部):{feedback.review_note || <Text type="secondary">(无)</Text>}
|
||||
</div>
|
||||
<div style={{ marginTop: 6 }}>
|
||||
给用户的回复(用户可见):
|
||||
{feedback.admin_reply || <Text type="secondary">(无)</Text>}
|
||||
</div>
|
||||
{isPending(feedback.status) && (
|
||||
<div style={{ marginTop: 6 }}>
|
||||
@@ -243,11 +268,23 @@ export default function FeedbackHandleDrawer({ feedback, open, onClose, onDone }
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="note"
|
||||
label="采纳要点 / 审核备注(选填)"
|
||||
label="采纳要点 / 审核备注(选填,内部)"
|
||||
rules={[{ max: 256, message: '最多 256 字' }]}
|
||||
>
|
||||
<Input.TextArea rows={3} maxLength={256} showCount placeholder="如:建议已采纳,将在下个版本上线" />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="reply"
|
||||
label="给用户的回复(选填,用户端可见)"
|
||||
rules={[{ max: 256, message: '最多 256 字' }]}
|
||||
>
|
||||
<Input.TextArea
|
||||
rows={2}
|
||||
maxLength={256}
|
||||
showCount
|
||||
placeholder="将展示在用户的「我的反馈」里,如:感谢反馈,已收到~"
|
||||
/>
|
||||
</Form.Item>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
@@ -268,6 +305,18 @@ export default function FeedbackHandleDrawer({ feedback, open, onClose, onDone }
|
||||
>
|
||||
<Input.TextArea rows={2} maxLength={256} showCount placeholder="运营内部备注" />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="reply"
|
||||
label="给用户的回复(选填,用户端可见)"
|
||||
rules={[{ max: 256, message: '最多 256 字' }]}
|
||||
>
|
||||
<Input.TextArea
|
||||
rows={2}
|
||||
maxLength={256}
|
||||
showCount
|
||||
placeholder="除未采纳原因外,想额外对用户说的话(选填)"
|
||||
/>
|
||||
</Form.Item>
|
||||
</>
|
||||
)}
|
||||
</Form>
|
||||
@@ -292,9 +341,12 @@ export default function FeedbackHandleDrawer({ feedback, open, onClose, onDone }
|
||||
>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
|
||||
<Text type="secondary">
|
||||
#{h.id} · {formatUtcTime(h.created_at)}
|
||||
#{h.id} · {formatWallTime(h.created_at)}
|
||||
</Text>
|
||||
{statusTag(h.status)}
|
||||
<Space size={4}>
|
||||
{sourceTag(h.source)}
|
||||
{statusTag(h.status)}
|
||||
</Space>
|
||||
</div>
|
||||
<Paragraph
|
||||
style={{ whiteSpace: 'pre-wrap', margin: '6px 0 0' }}
|
||||
@@ -313,6 +365,9 @@ export default function FeedbackHandleDrawer({ feedback, open, onClose, onDone }
|
||||
未采纳:{h.reject_reason || '-'}
|
||||
</Text>
|
||||
)}
|
||||
{h.admin_reply ? (
|
||||
<div style={{ fontSize: 12, marginTop: 2 }}>回复:{h.admin_reply}</div>
|
||||
) : null}
|
||||
</div>
|
||||
))}
|
||||
</Space>
|
||||
|
||||
@@ -1,26 +1,29 @@
|
||||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import type { ColumnsType } from 'antd/es/table';
|
||||
import type { SorterResult } from 'antd/es/table/interface';
|
||||
import {
|
||||
Button,
|
||||
Card,
|
||||
DatePicker,
|
||||
Image,
|
||||
Input,
|
||||
Select,
|
||||
Space,
|
||||
Statistic,
|
||||
Table,
|
||||
Tag,
|
||||
Typography,
|
||||
} from 'antd';
|
||||
import type { Dayjs } from 'dayjs';
|
||||
import { api } from '@/lib/api';
|
||||
import { canDo } from '@/lib/auth';
|
||||
import { formatUtcTime } from '@/lib/format';
|
||||
import { formatWallTime } from '@/lib/format';
|
||||
import { usePagedList } from '@/lib/usePagedList';
|
||||
import type { Feedback } from '@/lib/types';
|
||||
import FeedbackQrConfig from './FeedbackQrConfig';
|
||||
import type { Feedback, FeedbackSummary } from '@/lib/types';
|
||||
import FeedbackHandleDrawer from './FeedbackHandleDrawer';
|
||||
import UserRecordsDrawer from '@/components/UserRecordsDrawer';
|
||||
|
||||
const { Text, Paragraph } = Typography;
|
||||
const { RangePicker } = DatePicker;
|
||||
@@ -41,9 +44,119 @@ const STATUS_META: Record<string, { label: string; color: string }> = {
|
||||
rejected: { label: '未采纳', color: 'red' },
|
||||
};
|
||||
|
||||
const statusTag = (s: string) => {
|
||||
const m = STATUS_META[s] ?? { label: s, color: 'default' };
|
||||
return <Tag color={m.color}>{m.label}</Tag>;
|
||||
};
|
||||
|
||||
// 反馈类型:comparison=比价反馈(比价结果页入口) / profile=普通反馈(「我的」页入口)。
|
||||
// 旧数据与未识别来源按普通反馈展示。
|
||||
const SOURCE_META: Record<string, { label: string; color: string }> = {
|
||||
comparison: { label: '比价反馈', color: 'geekblue' },
|
||||
profile: { label: '普通反馈', color: 'default' },
|
||||
};
|
||||
|
||||
const SOURCE_OPTIONS = [
|
||||
{ value: 'comparison', label: '比价反馈' },
|
||||
{ value: 'profile', label: '普通反馈' },
|
||||
];
|
||||
|
||||
// 反馈类型标签 +(比价反馈时)问题场景副标题
|
||||
const renderSource = (f: Feedback) => {
|
||||
const m = SOURCE_META[f.source] ?? { label: '普通反馈', color: 'default' };
|
||||
return (
|
||||
<Space direction="vertical" size={0}>
|
||||
<Tag color={m.color}>{m.label}</Tag>
|
||||
{f.scene ? (
|
||||
<Text type="secondary" style={{ fontSize: 12 }}>
|
||||
{f.scene}
|
||||
</Text>
|
||||
) : null}
|
||||
</Space>
|
||||
);
|
||||
};
|
||||
|
||||
// 用户可见的运营回复留言(采纳/未采纳都可能有)
|
||||
const replyLine = (f: Feedback) =>
|
||||
f.admin_reply ? (
|
||||
<Text style={{ fontSize: 12 }} ellipsis>
|
||||
回复:{f.admin_reply}
|
||||
</Text>
|
||||
) : null;
|
||||
|
||||
// 审核结果展示(采纳=金币+批注 / 未采纳=原因 / 回复留言 / 待审核=-),主表与「该用户全部反馈」抽屉共用
|
||||
const renderReview = (f: Feedback) => {
|
||||
if (f.status === 'adopted') {
|
||||
return (
|
||||
<Space direction="vertical" size={0}>
|
||||
<Tag color="gold">+{f.reward_coins ?? 0} 金币</Tag>
|
||||
{f.review_note ? (
|
||||
<Text type="secondary" style={{ fontSize: 12 }} ellipsis>
|
||||
{f.review_note}
|
||||
</Text>
|
||||
) : null}
|
||||
{replyLine(f)}
|
||||
</Space>
|
||||
);
|
||||
}
|
||||
if (f.status === 'rejected') {
|
||||
return (
|
||||
<Space direction="vertical" size={0}>
|
||||
<Text type="secondary" style={{ fontSize: 12 }} ellipsis>
|
||||
未采纳:{f.reject_reason || '-'}
|
||||
</Text>
|
||||
{replyLine(f)}
|
||||
</Space>
|
||||
);
|
||||
}
|
||||
return <Text type="secondary">-</Text>;
|
||||
};
|
||||
|
||||
// 机型 / OS版本(提交反馈时的端环境;改版前历史反馈无 → -)
|
||||
const renderDeviceOs = (f: Feedback) => {
|
||||
const os = [f.android_version ? `Android ${f.android_version}` : null, f.rom_name]
|
||||
.filter(Boolean)
|
||||
.join(' · ');
|
||||
if (!f.device_model && !os) return <Text type="secondary">-</Text>;
|
||||
return (
|
||||
<Space direction="vertical" size={0}>
|
||||
<Text>{f.device_model || '-'}</Text>
|
||||
{os ? (
|
||||
<Text type="secondary" style={{ fontSize: 12 }}>
|
||||
{os}
|
||||
</Text>
|
||||
) : null}
|
||||
</Space>
|
||||
);
|
||||
};
|
||||
|
||||
// 点手机号弹出的「该用户全部反馈」抽屉列(精简版:不含操作/手机号,避免抽屉里再套抽屉)
|
||||
const RECORD_COLUMNS: ColumnsType<Feedback> = [
|
||||
{ title: '提交时间', dataIndex: 'created_at', width: 150, render: (v: string) => formatWallTime(v) },
|
||||
{ title: '状态', dataIndex: 'status', width: 80, render: statusTag },
|
||||
{ title: '反馈类型', key: 'source', width: 100, render: (_: unknown, f: Feedback) => renderSource(f) },
|
||||
{
|
||||
title: '内容',
|
||||
dataIndex: 'content',
|
||||
render: (v: string) =>
|
||||
v ? (
|
||||
<Paragraph
|
||||
style={{ marginBottom: 0, whiteSpace: 'pre-wrap', wordBreak: 'break-word' }}
|
||||
ellipsis={{ rows: 2, expandable: true, symbol: '展开' }}
|
||||
>
|
||||
{v}
|
||||
</Paragraph>
|
||||
) : (
|
||||
<Text type="secondary">-</Text>
|
||||
),
|
||||
},
|
||||
{ title: '审核结果', key: 'review', width: 160, render: (_: unknown, f: Feedback) => renderReview(f) },
|
||||
];
|
||||
|
||||
export default function FeedbacksPage() {
|
||||
// 筛选草稿:点「查询」才应用(避免输入即刷新)
|
||||
const [status, setStatus] = useState<string | undefined>();
|
||||
const [source, setSource] = useState<string | undefined>();
|
||||
const [userId, setUserId] = useState('');
|
||||
const [content, setContent] = useState('');
|
||||
const [createdRange, setCreatedRange] = useState<[Dayjs, Dayjs] | null>(null);
|
||||
@@ -58,6 +171,19 @@ export default function FeedbacksPage() {
|
||||
|
||||
const canReview = canDo(['operator']);
|
||||
|
||||
const [summary, setSummary] = useState<FeedbackSummary | null>(null);
|
||||
const loadSummary = async () => {
|
||||
try {
|
||||
const { data } = await api.get<FeedbackSummary>('/admin/api/feedbacks/summary');
|
||||
setSummary(data);
|
||||
} catch {
|
||||
/* 统计失败不阻塞列表 */
|
||||
}
|
||||
};
|
||||
useEffect(() => {
|
||||
loadSummary();
|
||||
}, []);
|
||||
|
||||
// 审核/查看抽屉(采纳发金币 / 拒绝填原因 + 看该用户历史反馈)
|
||||
const [drawerFb, setDrawerFb] = useState<Feedback | null>(null);
|
||||
const [drawerOpen, setDrawerOpen] = useState(false);
|
||||
@@ -66,9 +192,14 @@ export default function FeedbacksPage() {
|
||||
setDrawerOpen(true);
|
||||
};
|
||||
|
||||
// 点手机号:看该用户全部反馈
|
||||
const [recordsUser, setRecordsUser] = useState<{ userId: number; phone: string | null } | null>(null);
|
||||
const openUserRecords = (f: Feedback) => setRecordsUser({ userId: f.user_id, phone: f.phone });
|
||||
|
||||
const search = () =>
|
||||
setApplied({
|
||||
status,
|
||||
source,
|
||||
user_id: userId.trim() ? Number(userId.trim()) : undefined,
|
||||
content: content.trim() || undefined,
|
||||
created_from: createdRange?.[0] ? createdRange[0].startOf('day').toISOString() : undefined,
|
||||
@@ -77,6 +208,7 @@ export default function FeedbacksPage() {
|
||||
|
||||
const resetFilters = () => {
|
||||
setStatus(undefined);
|
||||
setSource(undefined);
|
||||
setUserId('');
|
||||
setContent('');
|
||||
setCreatedRange(null);
|
||||
@@ -104,8 +236,47 @@ export default function FeedbacksPage() {
|
||||
sortBy === field ? (sortOrder === 'asc' ? 'ascend' : 'descend') : null;
|
||||
|
||||
const columns: ColumnsType<Feedback> = [
|
||||
{ title: 'ID', dataIndex: 'id', width: 70, sorter: true, sortOrder: sortOrderOf('id') },
|
||||
{ title: '用户', dataIndex: 'user_id', width: 80 },
|
||||
{
|
||||
title: '用户ID',
|
||||
dataIndex: 'user_id',
|
||||
width: 80,
|
||||
render: (v: number) => <Text strong>#{v}</Text>,
|
||||
},
|
||||
{
|
||||
title: '手机号',
|
||||
dataIndex: 'phone',
|
||||
width: 130,
|
||||
render: (_: unknown, f: Feedback) =>
|
||||
f.phone ? (
|
||||
<a onClick={() => openUserRecords(f)}>{f.phone}</a>
|
||||
) : (
|
||||
<Text type="secondary">无手机号</Text>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '用户昵称',
|
||||
dataIndex: 'nickname',
|
||||
width: 120,
|
||||
render: (v: string | null) => v || <Text type="secondary">无昵称</Text>,
|
||||
},
|
||||
{
|
||||
title: '反馈类型',
|
||||
key: 'source',
|
||||
width: 110,
|
||||
render: (_: unknown, f: Feedback) => renderSource(f),
|
||||
},
|
||||
{
|
||||
title: '提交版本号',
|
||||
dataIndex: 'app_version',
|
||||
width: 100,
|
||||
render: (v: string | null) => v || <Text type="secondary">-</Text>,
|
||||
},
|
||||
{
|
||||
title: '机型 / OS版本',
|
||||
key: 'device',
|
||||
width: 150,
|
||||
render: (_: unknown, f: Feedback) => renderDeviceOs(f),
|
||||
},
|
||||
{
|
||||
title: '内容',
|
||||
dataIndex: 'content',
|
||||
@@ -145,49 +316,20 @@ export default function FeedbacksPage() {
|
||||
<Text type="secondary">无</Text>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
width: 90,
|
||||
render: (s: string) => {
|
||||
const m = STATUS_META[s] ?? { label: s, color: 'default' };
|
||||
return <Tag color={m.color}>{m.label}</Tag>;
|
||||
},
|
||||
},
|
||||
{ title: '状态', dataIndex: 'status', width: 90, render: statusTag },
|
||||
{
|
||||
title: '审核结果',
|
||||
key: 'review',
|
||||
width: 170,
|
||||
render: (_: unknown, f: Feedback) => {
|
||||
if (f.status === 'adopted') {
|
||||
return (
|
||||
<Space direction="vertical" size={0}>
|
||||
<Tag color="gold">+{f.reward_coins ?? 0} 金币</Tag>
|
||||
{f.review_note ? (
|
||||
<Text type="secondary" style={{ fontSize: 12 }} ellipsis>
|
||||
{f.review_note}
|
||||
</Text>
|
||||
) : null}
|
||||
</Space>
|
||||
);
|
||||
}
|
||||
if (f.status === 'rejected') {
|
||||
return (
|
||||
<Text type="secondary" style={{ fontSize: 12 }} ellipsis>
|
||||
未采纳:{f.reject_reason || '-'}
|
||||
</Text>
|
||||
);
|
||||
}
|
||||
return <Text type="secondary">-</Text>;
|
||||
},
|
||||
render: (_: unknown, f: Feedback) => renderReview(f),
|
||||
},
|
||||
{
|
||||
title: '时间',
|
||||
title: '提交时间',
|
||||
dataIndex: 'created_at',
|
||||
width: 170,
|
||||
sorter: true,
|
||||
sortOrder: sortOrderOf('created_at'),
|
||||
render: (v: string) => formatUtcTime(v),
|
||||
render: (v: string) => formatWallTime(v),
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
@@ -204,8 +346,21 @@ export default function FeedbacksPage() {
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h2>反馈工单</h2>
|
||||
<FeedbackQrConfig />
|
||||
<h2>用户反馈</h2>
|
||||
<div style={{ display: 'flex', gap: 16, marginBottom: 16, flexWrap: 'wrap' }}>
|
||||
<Card size="small" style={{ minWidth: 120 }}>
|
||||
<Statistic title="待审核" value={summary?.pending ?? 0} valueStyle={{ color: '#fa8c16' }} />
|
||||
</Card>
|
||||
<Card size="small" style={{ minWidth: 120 }}>
|
||||
<Statistic title="已采纳" value={summary?.adopted ?? 0} valueStyle={{ color: '#52c41a' }} />
|
||||
</Card>
|
||||
<Card size="small" style={{ minWidth: 120 }}>
|
||||
<Statistic title="未采纳" value={summary?.rejected ?? 0} valueStyle={{ color: '#8c8c8c' }} />
|
||||
</Card>
|
||||
<Card size="small" style={{ minWidth: 120 }}>
|
||||
<Statistic title="合计" value={summary?.total ?? 0} />
|
||||
</Card>
|
||||
</div>
|
||||
<Space style={{ marginBottom: 16 }} wrap>
|
||||
<Select
|
||||
placeholder="状态"
|
||||
@@ -219,6 +374,14 @@ export default function FeedbacksPage() {
|
||||
{ value: 'rejected', label: '未采纳' },
|
||||
]}
|
||||
/>
|
||||
<Select
|
||||
placeholder="反馈类型"
|
||||
value={source}
|
||||
onChange={setSource}
|
||||
allowClear
|
||||
style={{ width: 130 }}
|
||||
options={SOURCE_OPTIONS}
|
||||
/>
|
||||
<Input
|
||||
placeholder="用户ID"
|
||||
value={userId}
|
||||
@@ -261,13 +424,27 @@ export default function FeedbacksPage() {
|
||||
onChange: onPageChange,
|
||||
}}
|
||||
onChange={onTableChange}
|
||||
scroll={{ x: 1720 }}
|
||||
/>
|
||||
|
||||
<FeedbackHandleDrawer
|
||||
feedback={drawerFb}
|
||||
open={drawerOpen}
|
||||
onClose={() => setDrawerOpen(false)}
|
||||
onDone={reload}
|
||||
onDone={() => { reload(); loadSummary(); }}
|
||||
/>
|
||||
|
||||
<UserRecordsDrawer<Feedback>
|
||||
open={recordsUser != null}
|
||||
onClose={() => setRecordsUser(null)}
|
||||
userId={recordsUser?.userId ?? null}
|
||||
phone={recordsUser?.phone ?? null}
|
||||
endpoint="/admin/api/feedbacks"
|
||||
columns={RECORD_COLUMNS}
|
||||
recordLabel="反馈"
|
||||
countLabel="提交总计"
|
||||
rewardLabel="提交奖励总计"
|
||||
rewardOf={(f) => (f.status === 'adopted' ? (f.reward_coins ?? 0) : 0)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
+246
-30
@@ -8,10 +8,10 @@ import {
|
||||
DatabaseOutlined,
|
||||
FileSearchOutlined,
|
||||
FlagOutlined,
|
||||
GiftOutlined,
|
||||
HeartOutlined,
|
||||
LogoutOutlined,
|
||||
MessageOutlined,
|
||||
MobileOutlined,
|
||||
MoneyCollectOutlined,
|
||||
NotificationOutlined,
|
||||
ProfileOutlined,
|
||||
@@ -20,25 +20,66 @@ import {
|
||||
TeamOutlined,
|
||||
UserOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import { Avatar, Dropdown, Layout, Menu } from 'antd';
|
||||
import { Avatar, Dropdown, Layout, Tooltip } from 'antd';
|
||||
import { clearAuth, getAdmin, getToken } from '@/lib/auth';
|
||||
import type { AdminInfo } from '@/lib/types';
|
||||
|
||||
const { Sider, Header, Content } = Layout;
|
||||
|
||||
const MENU = [
|
||||
{ key: '/dashboard', icon: <DashboardOutlined />, label: '数据大盘' },
|
||||
{ key: '/users', icon: <UserOutlined />, label: '用户管理' },
|
||||
{ key: '/devices', icon: <MobileOutlined />, label: '设备管理' },
|
||||
{ key: '/device-liveness', icon: <HeartOutlined />, label: '设备存活' },
|
||||
{ key: '/withdraws', icon: <MoneyCollectOutlined />, label: '提现管理' },
|
||||
{ key: '/price-reports', icon: <FlagOutlined />, label: '上报审核' },
|
||||
{ key: '/comparison-records', icon: <ProfileOutlined />, label: '比价记录' },
|
||||
{ key: '/feedbacks', icon: <MessageOutlined />, label: '反馈工单' },
|
||||
{ key: '/ad-revenue', icon: <NotificationOutlined />, label: '广告配置' },
|
||||
{ key: '/ad-revenue-report', icon: <BarChartOutlined />, label: '广告收益' },
|
||||
{ key: '/cps', icon: <ShareAltOutlined />, label: 'CPS 分发' },
|
||||
{ key: '/config', icon: <SettingOutlined />, label: '系统配置' },
|
||||
type NavItem = {
|
||||
key: string;
|
||||
icon: React.ReactNode;
|
||||
label: string;
|
||||
superOnly?: boolean;
|
||||
};
|
||||
|
||||
type NavGroup =
|
||||
| (NavItem & { children?: never })
|
||||
| {
|
||||
key: string;
|
||||
icon: React.ReactNode;
|
||||
label: string;
|
||||
children: NavItem[];
|
||||
superOnly?: boolean;
|
||||
};
|
||||
|
||||
const hasChildren = (group: NavGroup): group is NavGroup & { children: NavItem[] } =>
|
||||
Array.isArray(group.children);
|
||||
|
||||
const NAV_GROUPS: NavGroup[] = [
|
||||
{
|
||||
key: 'dashboard',
|
||||
icon: <DashboardOutlined />,
|
||||
label: '看板',
|
||||
children: [
|
||||
{ key: '/dashboard', icon: <DashboardOutlined />, label: '数据大盘' },
|
||||
{ key: '/coupon-data', icon: <GiftOutlined />, label: '领券数据' },
|
||||
{ key: '/ad-revenue-report', icon: <BarChartOutlined />, label: '广告收益' },
|
||||
{ key: '/comparison-records', icon: <ProfileOutlined />, label: '比价记录' },
|
||||
{ key: '/cps', icon: <ShareAltOutlined />, label: 'CPS收益' },
|
||||
{ key: '/device-liveness', icon: <HeartOutlined />, label: '设备存活' },
|
||||
],
|
||||
},
|
||||
{
|
||||
key: 'reward-review',
|
||||
icon: <MoneyCollectOutlined />,
|
||||
label: '奖励审核',
|
||||
children: [
|
||||
{ key: '/withdraws', icon: <MoneyCollectOutlined />, label: '提现审核' },
|
||||
{ key: '/price-reports', icon: <FlagOutlined />, label: '低价审核' },
|
||||
{ key: '/feedbacks', icon: <MessageOutlined />, label: '用户反馈' },
|
||||
],
|
||||
},
|
||||
{
|
||||
key: 'data-config',
|
||||
icon: <SettingOutlined />,
|
||||
label: '数据配置',
|
||||
children: [
|
||||
{ key: '/config', icon: <SettingOutlined />, label: '系统配置' },
|
||||
{ key: '/ad-revenue', icon: <NotificationOutlined />, label: '广告配置' },
|
||||
{ key: '/users', icon: <UserOutlined />, label: '用户管理' },
|
||||
],
|
||||
},
|
||||
{ key: '/admins', icon: <TeamOutlined />, label: '管理员', superOnly: true },
|
||||
{ key: '/event-logs', icon: <DatabaseOutlined />, label: '埋点日志' },
|
||||
{ key: '/audit-logs', icon: <FileSearchOutlined />, label: '审计日志' },
|
||||
@@ -48,6 +89,7 @@ export default function MainLayout({ children }: { children: React.ReactNode })
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const [admin, setAdmin] = useState<AdminInfo | null>(null);
|
||||
const [collapsed, setCollapsed] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (!getToken()) {
|
||||
@@ -59,14 +101,19 @@ export default function MainLayout({ children }: { children: React.ReactNode })
|
||||
|
||||
if (!admin) return null; // 守卫期间不闪烁内容
|
||||
|
||||
const items = MENU.filter((m) => !m.superOnly || admin.role === 'super_admin').map((m) => ({
|
||||
key: m.key,
|
||||
icon: m.icon,
|
||||
label: m.label,
|
||||
}));
|
||||
|
||||
// 选中态:取路径一级(/users/123 → /users)
|
||||
// 选中态:取路径一级(/users/123 -> /users)
|
||||
const selectedKey = '/' + (pathname.split('/')[1] || 'dashboard');
|
||||
const canShow = (item: { superOnly?: boolean }) => !item.superOnly || admin.role === 'super_admin';
|
||||
const visibleGroups = NAV_GROUPS
|
||||
.filter(canShow)
|
||||
.map((group) => {
|
||||
if (!hasChildren(group)) return group;
|
||||
return { ...group, children: group.children.filter(canShow) };
|
||||
})
|
||||
.filter((group) => !hasChildren(group) || group.children.length > 0);
|
||||
const flatNavItems = visibleGroups.flatMap((group) =>
|
||||
hasChildren(group) ? group.children : [group],
|
||||
);
|
||||
|
||||
const logout = () => {
|
||||
clearAuth();
|
||||
@@ -75,7 +122,15 @@ export default function MainLayout({ children }: { children: React.ReactNode })
|
||||
|
||||
return (
|
||||
<Layout style={{ minHeight: '100vh' }}>
|
||||
<Sider theme="dark" breakpoint="lg" collapsible>
|
||||
<Sider
|
||||
theme="dark"
|
||||
breakpoint="lg"
|
||||
collapsible
|
||||
collapsed={collapsed}
|
||||
collapsedWidth={72}
|
||||
width={220}
|
||||
onCollapse={setCollapsed}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
height: 48,
|
||||
@@ -88,13 +143,61 @@ export default function MainLayout({ children }: { children: React.ReactNode })
|
||||
>
|
||||
运营后台
|
||||
</div>
|
||||
<Menu
|
||||
theme="dark"
|
||||
mode="inline"
|
||||
selectedKeys={[selectedKey]}
|
||||
items={items}
|
||||
onClick={({ key }) => router.push(key)}
|
||||
/>
|
||||
<nav className={`side-nav${collapsed ? ' side-nav-collapsed' : ''}`} aria-label="后台导航">
|
||||
{collapsed
|
||||
? flatNavItems.map((item) => (
|
||||
<Tooltip key={item.key} title={item.label} placement="right">
|
||||
<button
|
||||
type="button"
|
||||
className={`nav-icon-button${selectedKey === item.key ? ' is-selected' : ''}`}
|
||||
onClick={() => router.push(item.key)}
|
||||
aria-label={item.label}
|
||||
>
|
||||
{item.icon}
|
||||
</button>
|
||||
</Tooltip>
|
||||
))
|
||||
: visibleGroups.map((group) => {
|
||||
const isGroup = hasChildren(group);
|
||||
const groupSelected = isGroup
|
||||
? group.children.some((child) => child.key === selectedKey)
|
||||
: selectedKey === group.key;
|
||||
if (!isGroup) {
|
||||
return (
|
||||
<button
|
||||
key={group.key}
|
||||
type="button"
|
||||
className={`nav-primary nav-direct${groupSelected ? ' is-selected' : ''}`}
|
||||
onClick={() => router.push(group.key)}
|
||||
>
|
||||
<span className="nav-primary-icon">{group.icon}</span>
|
||||
<span>{group.label}</span>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<section key={group.key} className={`nav-group${groupSelected ? ' is-active' : ''}`}>
|
||||
<div className="nav-primary">
|
||||
<span className="nav-primary-icon">{group.icon}</span>
|
||||
<span>{group.label}</span>
|
||||
</div>
|
||||
<div className="nav-children">
|
||||
{group.children.map((child) => (
|
||||
<button
|
||||
key={child.key}
|
||||
type="button"
|
||||
className={`nav-child${selectedKey === child.key ? ' is-selected' : ''}`}
|
||||
onClick={() => router.push(child.key)}
|
||||
>
|
||||
<span className="nav-child-icon">{child.icon}</span>
|
||||
<span>{child.label}</span>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
</Sider>
|
||||
<Layout>
|
||||
<Header
|
||||
@@ -120,6 +223,119 @@ export default function MainLayout({ children }: { children: React.ReactNode })
|
||||
</Header>
|
||||
<Content style={{ margin: 24 }}>{children}</Content>
|
||||
</Layout>
|
||||
<style jsx global>{`
|
||||
.side-nav {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
padding: 0 10px 14px;
|
||||
}
|
||||
.nav-group {
|
||||
padding: 6px 0 8px;
|
||||
}
|
||||
.nav-group + .nav-group,
|
||||
.nav-group + .nav-direct,
|
||||
.nav-direct + .nav-direct {
|
||||
margin-top: 4px;
|
||||
}
|
||||
.nav-primary {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
min-height: 36px;
|
||||
padding: 0 12px;
|
||||
color: rgba(255, 255, 255, 0.88);
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0;
|
||||
}
|
||||
.nav-primary-icon,
|
||||
.nav-child-icon {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: rgba(255, 255, 255, 0.72);
|
||||
font-size: 16px;
|
||||
}
|
||||
.nav-direct,
|
||||
.nav-child,
|
||||
.nav-icon-button {
|
||||
border: 0;
|
||||
cursor: pointer;
|
||||
font: inherit;
|
||||
text-align: left;
|
||||
}
|
||||
.nav-direct {
|
||||
width: 100%;
|
||||
border-radius: 8px;
|
||||
background: transparent;
|
||||
}
|
||||
.nav-direct:hover,
|
||||
.nav-direct.is-selected {
|
||||
background: #1677ff;
|
||||
color: #fff;
|
||||
}
|
||||
.nav-direct:hover .nav-primary-icon,
|
||||
.nav-direct.is-selected .nav-primary-icon {
|
||||
color: #fff;
|
||||
}
|
||||
.nav-children {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
margin-left: 34px;
|
||||
margin-top: -2px;
|
||||
padding-right: 2px;
|
||||
}
|
||||
.nav-child {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
width: 100%;
|
||||
min-height: 34px;
|
||||
border-radius: 8px;
|
||||
background: transparent;
|
||||
color: rgba(255, 255, 255, 0.72);
|
||||
font-size: 13px;
|
||||
padding: 0 10px;
|
||||
}
|
||||
.nav-child:hover {
|
||||
background: rgba(255, 255, 255, 0.08);
|
||||
color: #fff;
|
||||
}
|
||||
.nav-child.is-selected {
|
||||
background: #1677ff;
|
||||
color: #fff;
|
||||
font-weight: 600;
|
||||
}
|
||||
.nav-child.is-selected .nav-child-icon {
|
||||
color: #fff;
|
||||
}
|
||||
.nav-group.is-active .nav-primary {
|
||||
color: #fff;
|
||||
}
|
||||
.side-nav-collapsed {
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 0 8px 14px;
|
||||
}
|
||||
.nav-icon-button {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 8px;
|
||||
background: transparent;
|
||||
color: rgba(255, 255, 255, 0.72);
|
||||
font-size: 17px;
|
||||
}
|
||||
.nav-icon-button:hover,
|
||||
.nav-icon-button.is-selected {
|
||||
background: #1677ff;
|
||||
color: #fff;
|
||||
}
|
||||
`}</style>
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
Typography,
|
||||
} from 'antd';
|
||||
import type { ColumnsType } from 'antd/es/table';
|
||||
import type { SorterResult } from 'antd/es/table/interface';
|
||||
import { CheckCircleOutlined, CloseCircleOutlined } from '@ant-design/icons';
|
||||
import dayjs from 'dayjs';
|
||||
import { api, errMsg } from '@/lib/api';
|
||||
@@ -23,6 +24,7 @@ import { canDo } from '@/lib/auth';
|
||||
import { mediaUrl } from '@/lib/media';
|
||||
import { usePagedList } from '@/lib/usePagedList';
|
||||
import type { PriceReport, PriceReportSummary } from '@/lib/types';
|
||||
import UserRecordsDrawer from '@/components/UserRecordsDrawer';
|
||||
|
||||
const { Text } = Typography;
|
||||
|
||||
@@ -55,19 +57,112 @@ function statusTag(status: string) {
|
||||
return <Tag color={STATUS_COLOR[status]}>{STATUS_LABEL[status] || status}</Tag>;
|
||||
}
|
||||
|
||||
type SortField = 'id' | 'created_at';
|
||||
|
||||
// 门店/菜品、原价→上报价、审核结果:主表与「该用户全部上报」抽屉共用
|
||||
const renderStore = (r: PriceReport) => (
|
||||
<Space direction="vertical" size={0}>
|
||||
<Text>{r.store_name || '-'}</Text>
|
||||
<Text type="secondary" style={{ fontSize: 12 }}>
|
||||
{r.dish_summary || '-'}
|
||||
</Text>
|
||||
</Space>
|
||||
);
|
||||
|
||||
const renderPrice = (r: PriceReport) => (
|
||||
<Space direction="vertical" size={0}>
|
||||
<Text type="secondary" style={{ fontSize: 12 }}>
|
||||
{r.original_platform_name || '原'}: {yuan(r.original_price_cents)}
|
||||
</Text>
|
||||
<Text strong style={{ color: '#fa541c' }}>
|
||||
{r.reported_platform_name}: {yuan(r.reported_price_cents)}
|
||||
</Text>
|
||||
</Space>
|
||||
);
|
||||
|
||||
// 只读审核结果(「审核结果」列 + 抽屉共用,不带操作按钮;待审核在「状态」列已显示,这里给 -)
|
||||
const renderResult = (r: PriceReport) => {
|
||||
if (r.status === 'approved') return <Text type="success">已发 {r.reward_coins ?? 0} 金币</Text>;
|
||||
if (r.status === 'rejected') return <Text type="secondary">拒绝: {r.reject_reason || '-'}</Text>;
|
||||
return <Text type="secondary">-</Text>;
|
||||
};
|
||||
|
||||
// Trace:与「比价记录」页一致 —— 有 trace_url(本地比价=localhost debug viewer,线上=公网)
|
||||
// 就给可点的「trace」链接,否则 -。
|
||||
const traceLink = (r: PriceReport) =>
|
||||
r.trace_url ? (
|
||||
<a href={r.trace_url} target="_blank" rel="noreferrer">
|
||||
trace
|
||||
</a>
|
||||
) : (
|
||||
<Text type="secondary">-</Text>
|
||||
);
|
||||
|
||||
// 机型 / OS版本(取自关联比价记录;无关联记录时为 -)
|
||||
const renderDeviceOs = (r: PriceReport) => {
|
||||
const os = [r.android_version ? `Android ${r.android_version}` : null, r.rom_name]
|
||||
.filter(Boolean)
|
||||
.join(' · ');
|
||||
if (!r.device_model && !os) return <Text type="secondary">-</Text>;
|
||||
return (
|
||||
<Space direction="vertical" size={0}>
|
||||
<Text>{r.device_model || '-'}</Text>
|
||||
{os ? (
|
||||
<Text type="secondary" style={{ fontSize: 12 }}>
|
||||
{os}
|
||||
</Text>
|
||||
) : null}
|
||||
</Space>
|
||||
);
|
||||
};
|
||||
|
||||
// 点手机号弹出的「该用户全部低价上报」抽屉列(精简版:不含操作/手机号)
|
||||
const RECORD_COLUMNS: ColumnsType<PriceReport> = [
|
||||
{ title: '提交时间', dataIndex: 'created_at', width: 150, render: (v: string) => dt(v) },
|
||||
{ title: '门店 / 菜品', key: 'store', width: 180, render: (_: unknown, r: PriceReport) => renderStore(r) },
|
||||
{ title: '原价 → 上报价', key: 'price', width: 200, render: (_: unknown, r: PriceReport) => renderPrice(r) },
|
||||
{ title: '状态', dataIndex: 'status', width: 90, render: statusTag },
|
||||
{ title: 'Trace', key: 'trace', width: 80, render: (_: unknown, r: PriceReport) => traceLink(r) },
|
||||
{ title: '结果', key: 'result', width: 150, render: (_: unknown, r: PriceReport) => renderResult(r) },
|
||||
];
|
||||
|
||||
export default function PriceReportsPage() {
|
||||
const { message, modal } = App.useApp();
|
||||
const [activeStatus, setActiveStatus] = useState('pending');
|
||||
const [summary, setSummary] = useState<PriceReportSummary | null>(null);
|
||||
const [rejecting, setRejecting] = useState<PriceReport | null>(null);
|
||||
const [rejectReason, setRejectReason] = useState('');
|
||||
// 提交时间列服务端排序(默认按提交时间倒序,最新在前)
|
||||
const [sortBy, setSortBy] = useState<SortField>('created_at');
|
||||
const [sortOrder, setSortOrder] = useState<'asc' | 'desc'>('desc');
|
||||
// 点手机号:看该用户全部低价上报
|
||||
const [recordsUser, setRecordsUser] = useState<{ userId: number; phone: string | null } | null>(null);
|
||||
const openUserRecords = (r: PriceReport) => setRecordsUser({ userId: r.user_id, phone: r.phone });
|
||||
|
||||
const filters: Record<string, unknown> = {};
|
||||
const filters: Record<string, unknown> = { sort_by: sortBy, sort_order: sortOrder };
|
||||
if (activeStatus !== 'all') filters.status = activeStatus;
|
||||
|
||||
const { items, total, page, pageSize, loading, onChange: onPageChange, reload } =
|
||||
usePagedList<PriceReport>('/admin/api/price-reports', filters);
|
||||
|
||||
const sortOrderOf = (field: SortField) =>
|
||||
sortBy === field ? (sortOrder === 'asc' ? 'ascend' : 'descend') : null;
|
||||
|
||||
const onTableChange = (
|
||||
_pagination: unknown,
|
||||
_filters: unknown,
|
||||
sorter: SorterResult<PriceReport> | SorterResult<PriceReport>[],
|
||||
) => {
|
||||
const s = Array.isArray(sorter) ? sorter[0] : sorter;
|
||||
if (s && s.order && s.field) {
|
||||
setSortBy(s.field as SortField);
|
||||
setSortOrder(s.order === 'ascend' ? 'asc' : 'desc');
|
||||
} else {
|
||||
setSortBy('created_at');
|
||||
setSortOrder('desc');
|
||||
}
|
||||
};
|
||||
|
||||
const canReview = canDo(['operator']);
|
||||
|
||||
const loadSummary = async () => {
|
||||
@@ -136,38 +231,51 @@ export default function PriceReportsPage() {
|
||||
|
||||
const columns: ColumnsType<PriceReport> = [
|
||||
{
|
||||
title: '用户',
|
||||
title: '用户ID',
|
||||
dataIndex: 'user_id',
|
||||
width: 90,
|
||||
width: 80,
|
||||
render: (v: number) => <Text strong>#{v}</Text>,
|
||||
},
|
||||
{
|
||||
title: '手机号',
|
||||
dataIndex: 'phone',
|
||||
width: 130,
|
||||
render: (_: unknown, r: PriceReport) =>
|
||||
r.phone ? (
|
||||
<a onClick={() => openUserRecords(r)}>{r.phone}</a>
|
||||
) : (
|
||||
<Text type="secondary">无手机号</Text>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '用户昵称',
|
||||
dataIndex: 'nickname',
|
||||
width: 120,
|
||||
render: (v: string | null) => v || <Text type="secondary">无昵称</Text>,
|
||||
},
|
||||
{
|
||||
title: '提交版本号',
|
||||
dataIndex: 'app_version',
|
||||
width: 100,
|
||||
render: (v: string | null) => v || <Text type="secondary">-</Text>,
|
||||
},
|
||||
{
|
||||
title: '机型 / OS版本',
|
||||
key: 'device',
|
||||
width: 150,
|
||||
render: (_: unknown, r: PriceReport) => renderDeviceOs(r),
|
||||
},
|
||||
{
|
||||
title: '门店 / 菜品',
|
||||
key: 'store',
|
||||
width: 200,
|
||||
render: (_: unknown, r: PriceReport) => (
|
||||
<Space direction="vertical" size={0}>
|
||||
<Text>{r.store_name || '-'}</Text>
|
||||
<Text type="secondary" style={{ fontSize: 12 }}>
|
||||
{r.dish_summary || '-'}
|
||||
</Text>
|
||||
</Space>
|
||||
),
|
||||
render: (_: unknown, r: PriceReport) => renderStore(r),
|
||||
},
|
||||
{
|
||||
title: '原最低价 → 上报价',
|
||||
key: 'price',
|
||||
width: 220,
|
||||
render: (_: unknown, r: PriceReport) => (
|
||||
<Space direction="vertical" size={0}>
|
||||
<Text type="secondary" style={{ fontSize: 12 }}>
|
||||
{r.original_platform_name || '原'}: {yuan(r.original_price_cents)}
|
||||
</Text>
|
||||
<Text strong style={{ color: '#fa541c' }}>
|
||||
{r.reported_platform_name}: {yuan(r.reported_price_cents)}
|
||||
</Text>
|
||||
</Space>
|
||||
),
|
||||
render: (_: unknown, r: PriceReport) => renderPrice(r),
|
||||
},
|
||||
{
|
||||
title: '截图证明',
|
||||
@@ -193,52 +301,58 @@ export default function PriceReportsPage() {
|
||||
),
|
||||
},
|
||||
{ title: '状态', dataIndex: 'status', width: 90, render: statusTag },
|
||||
{
|
||||
title: '审核结果',
|
||||
key: 'review',
|
||||
width: 160,
|
||||
render: (_: unknown, r: PriceReport) => renderResult(r),
|
||||
},
|
||||
{
|
||||
title: '提交时间',
|
||||
dataIndex: 'created_at',
|
||||
width: 150,
|
||||
sorter: true,
|
||||
sortOrder: sortOrderOf('created_at'),
|
||||
render: (v: string) => dt(v),
|
||||
},
|
||||
{
|
||||
title: '操作 / 结果',
|
||||
title: 'Trace',
|
||||
key: 'trace',
|
||||
width: 80,
|
||||
render: (_: unknown, r: PriceReport) => traceLink(r),
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'op',
|
||||
fixed: 'right',
|
||||
width: 200,
|
||||
width: 150,
|
||||
render: (_: unknown, r: PriceReport) => {
|
||||
if (r.status === 'pending') {
|
||||
if (!canReview) return <Text type="secondary">无审核权限</Text>;
|
||||
return (
|
||||
<Space>
|
||||
<Button
|
||||
size="small"
|
||||
type="link"
|
||||
icon={<CheckCircleOutlined />}
|
||||
onClick={() => approve(r)}
|
||||
>
|
||||
通过
|
||||
</Button>
|
||||
<Button
|
||||
size="small"
|
||||
type="link"
|
||||
danger
|
||||
icon={<CloseCircleOutlined />}
|
||||
onClick={() => {
|
||||
setRejecting(r);
|
||||
setRejectReason('');
|
||||
}}
|
||||
>
|
||||
拒绝
|
||||
</Button>
|
||||
</Space>
|
||||
);
|
||||
}
|
||||
if (r.status === 'approved') {
|
||||
return <Text type="success">已发 {r.reward_coins ?? 0} 金币</Text>;
|
||||
}
|
||||
if (r.status === 'rejected') {
|
||||
return <Text type="secondary">拒绝: {r.reject_reason || '-'}</Text>;
|
||||
}
|
||||
return <Text type="secondary">-</Text>;
|
||||
if (r.status !== 'pending') return <Text type="secondary">-</Text>;
|
||||
if (!canReview) return <Text type="secondary">无审核权限</Text>;
|
||||
return (
|
||||
<Space>
|
||||
<Button
|
||||
size="small"
|
||||
type="link"
|
||||
icon={<CheckCircleOutlined />}
|
||||
onClick={() => approve(r)}
|
||||
>
|
||||
通过
|
||||
</Button>
|
||||
<Button
|
||||
size="small"
|
||||
type="link"
|
||||
danger
|
||||
icon={<CloseCircleOutlined />}
|
||||
onClick={() => {
|
||||
setRejecting(r);
|
||||
setRejectReason('');
|
||||
}}
|
||||
>
|
||||
拒绝
|
||||
</Button>
|
||||
</Space>
|
||||
);
|
||||
},
|
||||
},
|
||||
];
|
||||
@@ -247,7 +361,7 @@ export default function PriceReportsPage() {
|
||||
<div>
|
||||
<Space direction="vertical" style={{ marginBottom: 16 }}>
|
||||
<Typography.Title level={4} style={{ margin: 0 }}>
|
||||
上报审核
|
||||
低价审核
|
||||
</Typography.Title>
|
||||
<Text type="secondary">
|
||||
用户上报「某平台更低价」+ 截图,人工核实后通过发放 1000 金币奖励、拒绝需填理由。用户在 app
|
||||
@@ -255,14 +369,20 @@ export default function PriceReportsPage() {
|
||||
</Text>
|
||||
</Space>
|
||||
|
||||
{summary && (
|
||||
<Space size="large" style={{ marginBottom: 16 }}>
|
||||
<Statistic title="待审核" value={summary.pending} valueStyle={{ color: '#faad14' }} />
|
||||
<Statistic title="已通过" value={summary.approved} valueStyle={{ color: '#52c41a' }} />
|
||||
<Statistic title="已拒绝" value={summary.rejected} />
|
||||
<Statistic title="合计" value={summary.total} />
|
||||
</Space>
|
||||
)}
|
||||
<div style={{ display: 'flex', gap: 16, marginBottom: 16, flexWrap: 'wrap' }}>
|
||||
<Card size="small" style={{ minWidth: 120 }}>
|
||||
<Statistic title="待审核" value={summary?.pending ?? 0} valueStyle={{ color: '#fa8c16' }} />
|
||||
</Card>
|
||||
<Card size="small" style={{ minWidth: 120 }}>
|
||||
<Statistic title="已通过" value={summary?.approved ?? 0} valueStyle={{ color: '#52c41a' }} />
|
||||
</Card>
|
||||
<Card size="small" style={{ minWidth: 120 }}>
|
||||
<Statistic title="已拒绝" value={summary?.rejected ?? 0} valueStyle={{ color: '#8c8c8c' }} />
|
||||
</Card>
|
||||
<Card size="small" style={{ minWidth: 120 }}>
|
||||
<Statistic title="合计" value={summary?.total ?? 0} />
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<Tabs
|
||||
@@ -275,6 +395,7 @@ export default function PriceReportsPage() {
|
||||
columns={columns}
|
||||
dataSource={items}
|
||||
loading={loading}
|
||||
onChange={onTableChange}
|
||||
pagination={{
|
||||
current: page,
|
||||
pageSize,
|
||||
@@ -283,7 +404,7 @@ export default function PriceReportsPage() {
|
||||
showTotal: (t) => `共 ${t} 条`,
|
||||
onChange: onPageChange,
|
||||
}}
|
||||
scroll={{ x: 1100 }}
|
||||
scroll={{ x: 1790 }}
|
||||
/>
|
||||
</Card>
|
||||
|
||||
@@ -320,6 +441,19 @@ export default function PriceReportsPage() {
|
||||
</Space>
|
||||
)}
|
||||
</Modal>
|
||||
|
||||
<UserRecordsDrawer<PriceReport>
|
||||
open={recordsUser != null}
|
||||
onClose={() => setRecordsUser(null)}
|
||||
userId={recordsUser?.userId ?? null}
|
||||
phone={recordsUser?.phone ?? null}
|
||||
endpoint="/admin/api/price-reports"
|
||||
columns={RECORD_COLUMNS}
|
||||
recordLabel="低价上报"
|
||||
countLabel="上报总计"
|
||||
rewardLabel="上报奖励总计"
|
||||
rewardOf={(r) => (r.status === 'approved' ? (r.reward_coins ?? 0) : 0)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -39,10 +39,12 @@ const PAGE_SIZE = 10; // 金币记录每页条数
|
||||
interface Props {
|
||||
userId: number;
|
||||
user: WithdrawUserSnapshot | null;
|
||||
// 统计区字段集:withdraw(默认,提现详情:含提现细分) / ad(广告收益详情:只看看广告观看统计,对齐参考图 6 项)
|
||||
statsVariant?: 'withdraw' | 'ad';
|
||||
}
|
||||
|
||||
/** 提现详情抽屉:用户基本信息 + 互斥时间筛选 + 看广告/提现统计区 + 金币发放记录表。 */
|
||||
export default function UserRewardPanel({ userId, user }: Props) {
|
||||
/** 用户看广告/提现详情:基本信息 + 互斥时间筛选 + 统计区(按 statsVariant 取字段集)+ 金币发放记录表。 */
|
||||
export default function UserRewardPanel({ userId, user, statsVariant = 'withdraw' }: Props) {
|
||||
const [mode, setMode] = useState<'all' | 'range'>('all'); // all=注册至今 / range=自定义区间
|
||||
const [range, setRange] = useState<[Dayjs, Dayjs] | null>(null);
|
||||
const [stats, setStats] = useState<UserRewardStats | null>(null);
|
||||
@@ -164,7 +166,7 @@ export default function UserRewardPanel({ userId, user }: Props) {
|
||||
</Space>
|
||||
</Space>
|
||||
|
||||
{/* 统计区(受时间筛选;现金余额为当前快照) */}
|
||||
{/* 统计区(受时间筛选;现金余额为当前快照)。ad 视图只保留看广告观看统计(对齐参考图 6 项) */}
|
||||
<Descriptions bordered size="small" column={2} style={{ marginBottom: 8 }}>
|
||||
<Descriptions.Item label="累计提现">
|
||||
{stats ? yuan(stats.withdraw_success_cents) : '-'}
|
||||
@@ -172,29 +174,51 @@ export default function UserRewardPanel({ userId, user }: Props) {
|
||||
<Descriptions.Item label="现金余额">
|
||||
{stats ? yuan(stats.cash_balance_cents) : '-'}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="提现总次数">{stats?.withdraw_total ?? '-'}</Descriptions.Item>
|
||||
<Descriptions.Item label="传统任务提现">
|
||||
{stats ? yuan(stats.traditional_task_cash_cents) : '-'}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="累计激励视频数">
|
||||
{stats?.reward_video_count ?? '-'}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="平均激励视频ECPM">
|
||||
{stats ? `${stats.reward_video_avg_ecpm} 分/千` : '-'}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="激励视频提现">
|
||||
{stats ? yuan(stats.reward_video_cash_cents) : '-'}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="累计信息流广告数">{stats?.feed_count ?? '-'}</Descriptions.Item>
|
||||
<Descriptions.Item label="平均信息流广告ECPM">
|
||||
{stats ? `${stats.feed_avg_ecpm} 分/千` : '-'}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="信息流广告提现">
|
||||
{stats ? yuan(stats.feed_cash_cents) : '-'}
|
||||
</Descriptions.Item>
|
||||
{statsVariant === 'ad' ? (
|
||||
<>
|
||||
<Descriptions.Item label="激励视频观看数">
|
||||
{stats?.reward_video_count ?? '-'}
|
||||
</Descriptions.Item>
|
||||
{/* eCPM 均按元展示(reward_video / feed avg_ecpm 原始为分/千次,÷100 转元) */}
|
||||
<Descriptions.Item label="平均激励视频ECPM">
|
||||
{stats ? `${(stats.reward_video_avg_ecpm / 100).toFixed(2)} 元/千` : '-'}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="draw信息流视频观看数">
|
||||
{stats?.feed_count ?? '-'}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="平均draw信息流ECPM">
|
||||
{stats ? `${(stats.feed_avg_ecpm / 100).toFixed(2)} 元/千` : '-'}
|
||||
</Descriptions.Item>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Descriptions.Item label="提现总次数">{stats?.withdraw_total ?? '-'}</Descriptions.Item>
|
||||
<Descriptions.Item label="传统任务提现">
|
||||
{stats ? yuan(stats.traditional_task_cash_cents) : '-'}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="累计激励视频数">
|
||||
{stats?.reward_video_count ?? '-'}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="平均激励视频ECPM">
|
||||
{stats ? `${stats.reward_video_avg_ecpm} 分/千` : '-'}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="激励视频提现">
|
||||
{stats ? yuan(stats.reward_video_cash_cents) : '-'}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="累计信息流广告数">{stats?.feed_count ?? '-'}</Descriptions.Item>
|
||||
<Descriptions.Item label="平均信息流广告ECPM">
|
||||
{stats ? `${stats.feed_avg_ecpm} 分/千` : '-'}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="信息流广告提现">
|
||||
{stats ? yuan(stats.feed_cash_cents) : '-'}
|
||||
</Descriptions.Item>
|
||||
</>
|
||||
)}
|
||||
</Descriptions>
|
||||
<Text type="secondary" style={{ fontSize: 12 }}>
|
||||
统计随上方时间筛选(现金余额除外,为当前快照);eCPM 单位分/千次,同金币审计。
|
||||
{statsVariant === 'ad'
|
||||
? '统计随上方时间筛选(现金余额除外,为当前快照);eCPM 均按元展示(原始分/千次 ÷100)。'
|
||||
: '统计随上方时间筛选(现金余额除外,为当前快照);eCPM 单位分/千次,同金币审计。'}
|
||||
</Text>
|
||||
|
||||
{/* 金币记录 */}
|
||||
|
||||
@@ -104,6 +104,19 @@ const SORT_OPTIONS = [
|
||||
{ value: 'created_at', label: '申请时间' },
|
||||
{ value: 'amount_cents', label: '提现金额' },
|
||||
];
|
||||
// 提现类型:coin_cash=福利页提现(金币兑换现金) / invite_cash=邀请提现(邀请奖励金)
|
||||
const SOURCE_LABEL: Record<string, string> = {
|
||||
coin_cash: '福利页提现',
|
||||
invite_cash: '邀请提现',
|
||||
};
|
||||
const SOURCE_COLOR: Record<string, string> = {
|
||||
coin_cash: 'blue',
|
||||
invite_cash: 'purple',
|
||||
};
|
||||
const SOURCE_OPTIONS = [
|
||||
{ value: 'coin_cash', label: '福利页提现' },
|
||||
{ value: 'invite_cash', label: '邀请提现' },
|
||||
];
|
||||
const DATE_FIELD_OPTIONS = [
|
||||
{ value: 'created_at', label: '申请时间' },
|
||||
{ value: 'updated_at', label: '更新时间' },
|
||||
@@ -184,9 +197,11 @@ export default function WithdrawsPage() {
|
||||
const [sortBy, setSortBy] = useState<'created_at' | 'amount_cents'>('created_at');
|
||||
const [sortOrder, setSortOrder] = useState<'asc' | 'desc'>('desc');
|
||||
const [quickFilter, setQuickFilter] = useState<string | undefined>(undefined);
|
||||
const [source, setSource] = useState<string | undefined>(undefined);
|
||||
|
||||
const filters: Record<string, unknown> = {};
|
||||
if (activeStatus !== 'all') filters.status = activeStatus;
|
||||
if (source) filters.source = source;
|
||||
if (keyword.trim()) filters.keyword = keyword.trim();
|
||||
if (dateRange?.[0]) filters.date_from = dateRange[0].startOf('day').toISOString();
|
||||
if (dateRange?.[1]) filters.date_to = dateRange[1].endOf('day').toISOString();
|
||||
@@ -211,6 +226,7 @@ export default function WithdrawsPage() {
|
||||
setSortBy('created_at');
|
||||
setSortOrder('desc');
|
||||
setQuickFilter(undefined);
|
||||
setSource(undefined);
|
||||
};
|
||||
|
||||
const applyQuickFilter = (value?: string) => {
|
||||
@@ -481,6 +497,12 @@ export default function WithdrawsPage() {
|
||||
width: 120,
|
||||
render: (v: number) => <Text strong>{yuan(v)}</Text>,
|
||||
},
|
||||
{
|
||||
title: '提现类型',
|
||||
dataIndex: 'source',
|
||||
width: 110,
|
||||
render: (v: string) => <Tag color={SOURCE_COLOR[v] || 'default'}>{SOURCE_LABEL[v] || v}</Tag>,
|
||||
},
|
||||
{
|
||||
title: '累计提现',
|
||||
dataIndex: 'cumulative_success_cents',
|
||||
@@ -724,6 +746,14 @@ export default function WithdrawsPage() {
|
||||
}}
|
||||
onSearch={(value) => setKeyword(value.trim())}
|
||||
/>
|
||||
<Select
|
||||
value={source}
|
||||
allowClear
|
||||
placeholder="提现类型"
|
||||
style={{ width: 140 }}
|
||||
options={SOURCE_OPTIONS}
|
||||
onChange={(value?: string) => setSource(value)}
|
||||
/>
|
||||
<Select
|
||||
value={quickFilter}
|
||||
allowClear
|
||||
@@ -849,7 +879,7 @@ export default function WithdrawsPage() {
|
||||
showTotal: (t) => `共 ${t} 条`,
|
||||
onChange: onPageChange,
|
||||
}}
|
||||
scroll={{ x: 1350 }}
|
||||
scroll={{ x: 1460 }}
|
||||
onRow={(record) => ({
|
||||
onClick: () => openDetail(record),
|
||||
style: { cursor: 'pointer' },
|
||||
@@ -881,6 +911,11 @@ export default function WithdrawsPage() {
|
||||
<Descriptions.Item label="金额">
|
||||
<Text strong>{yuan(detail.order.amount_cents)}</Text>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="提现类型">
|
||||
<Tag color={SOURCE_COLOR[detail.order.source] || 'default'}>
|
||||
{SOURCE_LABEL[detail.order.source] || detail.order.source}
|
||||
</Tag>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="提现实名">
|
||||
{detail.order.user_name || '-'}
|
||||
</Descriptions.Item>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// 调金币 / 调现金弹窗(受控)。列表页与用户详情页共用,避免两处各写一套。
|
||||
// 每个弹窗自带「增减 / 设为指定值」两种模式;打开时拉一次 360 概览展示当前余额。
|
||||
import { useEffect, useState } from 'react';
|
||||
import { App, Form, Input, InputNumber, Modal, Segmented } from 'antd';
|
||||
import { App, Form, Input, InputNumber, Modal, Radio, Segmented } from 'antd';
|
||||
import { api, errMsg } from '@/lib/api';
|
||||
import { yuan } from '@/lib/format';
|
||||
import type { UserOverview } from '@/lib/types';
|
||||
@@ -17,15 +17,19 @@ interface ModalProps {
|
||||
onDone?: () => void; // 调整成功后回调(刷新余额/列表)
|
||||
}
|
||||
|
||||
const balanceLine = (balances: { coin: number; cashCents: number } | null) => (
|
||||
type Balances = { coin: number; cashCents: number; inviteCashCents: number };
|
||||
|
||||
const balanceLine = (balances: Balances | null) => (
|
||||
<p style={{ color: '#888', marginBottom: 12 }}>
|
||||
当前余额:金币 {balances ? balances.coin : '…'} | 现金 {balances ? yuan(balances.cashCents) : '…'}
|
||||
当前余额:金币 {balances ? balances.coin : '…'} | 现金(金币兑现金){' '}
|
||||
{balances ? yuan(balances.cashCents) : '…'} | 邀请奖励金{' '}
|
||||
{balances ? yuan(balances.inviteCashCents) : '…'}
|
||||
</p>
|
||||
);
|
||||
|
||||
// 弹窗打开时拉一次该用户余额;用户切换/关闭时丢弃过期响应(alive 标记防竞态)。
|
||||
function useBalances(userId: number | undefined, open: boolean) {
|
||||
const [balances, setBalances] = useState<{ coin: number; cashCents: number } | null>(null);
|
||||
const [balances, setBalances] = useState<Balances | null>(null);
|
||||
useEffect(() => {
|
||||
if (!open || userId == null) {
|
||||
setBalances(null);
|
||||
@@ -36,7 +40,12 @@ function useBalances(userId: number | undefined, open: boolean) {
|
||||
api
|
||||
.get<UserOverview>(`/admin/api/users/${userId}`)
|
||||
.then((r) => {
|
||||
if (alive) setBalances({ coin: r.data.coin_balance, cashCents: r.data.cash_balance_cents });
|
||||
if (alive)
|
||||
setBalances({
|
||||
coin: r.data.coin_balance,
|
||||
cashCents: r.data.cash_balance_cents,
|
||||
inviteCashCents: r.data.invite_cash_balance_cents,
|
||||
});
|
||||
})
|
||||
.catch(() => {});
|
||||
return () => {
|
||||
@@ -113,39 +122,39 @@ export function AdjustCoinModal({ user, open, onClose, onDone }: ModalProps) {
|
||||
export function AdjustCashModal({ user, open, onClose, onDone }: ModalProps) {
|
||||
const { message } = App.useApp();
|
||||
const [form] = Form.useForm();
|
||||
const [mode, setMode] = useState<'delta' | 'set'>('delta');
|
||||
// 操作方式改为表单必选项(无默认、手动选);用 watch 驱动金额栏文案/最小值
|
||||
const mode = Form.useWatch('mode', form) as 'delta' | 'set' | undefined;
|
||||
const balances = useBalances(user?.id, open);
|
||||
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
setMode('delta');
|
||||
form.resetFields();
|
||||
}
|
||||
if (open) form.resetFields(); // 目标账户 / 操作方式 都重置为「未选」
|
||||
}, [open, form]);
|
||||
|
||||
// 输入元,×100 转分后调后端(主要给无现金用户发钱直接测试提现)
|
||||
const submit = async () => {
|
||||
if (!user) return;
|
||||
const v = await form.validateFields();
|
||||
const v = await form.validateFields(); // 任一必填/必选缺失 → 该项下方红字 + 阻断提交
|
||||
const amountCents = Math.round(Number(v.amount_yuan) * 100);
|
||||
if (mode === 'delta' && amountCents === 0) {
|
||||
if (v.mode === 'delta' && amountCents === 0) {
|
||||
message.warning('金额不能为 0(且不小于 1 分)');
|
||||
return;
|
||||
}
|
||||
if (mode === 'set' && amountCents < 0) {
|
||||
if (v.mode === 'set' && amountCents < 0) {
|
||||
message.warning('目标金额不能为负');
|
||||
return;
|
||||
}
|
||||
const acctName = v.account === 'invite_cash' ? '邀请奖励金' : '现金';
|
||||
try {
|
||||
await api.post(`/admin/api/users/${user.id}/cash`, {
|
||||
mode,
|
||||
account: v.account,
|
||||
mode: v.mode,
|
||||
amount_cents: amountCents,
|
||||
reason: v.reason,
|
||||
});
|
||||
message.success(
|
||||
mode === 'set'
|
||||
? `已设为 ¥${(amountCents / 100).toFixed(2)} 现金`
|
||||
: `已${amountCents > 0 ? '发放' : '扣减'} ¥${(Math.abs(amountCents) / 100).toFixed(2)} 现金`,
|
||||
v.mode === 'set'
|
||||
? `已设为 ¥${(amountCents / 100).toFixed(2)} ${acctName}`
|
||||
: `已${amountCents > 0 ? '发放' : '扣减'} ¥${(Math.abs(amountCents) / 100).toFixed(2)} ${acctName}`,
|
||||
);
|
||||
onClose();
|
||||
onDone?.();
|
||||
@@ -164,10 +173,20 @@ export function AdjustCashModal({ user, open, onClose, onDone }: ModalProps) {
|
||||
>
|
||||
{balanceLine(balances)}
|
||||
<Form form={form} layout="vertical">
|
||||
<Form.Item label="操作方式">
|
||||
<Segmented
|
||||
value={mode}
|
||||
onChange={(v) => setMode(v as 'delta' | 'set')}
|
||||
<Form.Item name="account" label="目标账户" rules={[{ required: true, message: '请选择目标账户' }]}>
|
||||
<Radio.Group
|
||||
optionType="button"
|
||||
buttonStyle="solid"
|
||||
options={[
|
||||
{ label: '金币兑现金账户', value: 'coin_cash' },
|
||||
{ label: '邀请账户', value: 'invite_cash' },
|
||||
]}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item name="mode" label="操作方式" rules={[{ required: true, message: '请选择操作方式' }]}>
|
||||
<Radio.Group
|
||||
optionType="button"
|
||||
buttonStyle="solid"
|
||||
options={[
|
||||
{ label: '增减', value: 'delta' },
|
||||
{ label: '设为指定值', value: 'set' },
|
||||
@@ -182,7 +201,7 @@ export function AdjustCashModal({ user, open, onClose, onDone }: ModalProps) {
|
||||
: '现金变动(元,正=发放,负=扣减;不可扣成负)'
|
||||
}
|
||||
rules={[
|
||||
{ required: true },
|
||||
{ required: true, message: '请输入现金变动金额' },
|
||||
...(mode === 'set' ? [{ type: 'number' as const, min: 0, message: '目标值不能为负' }] : []),
|
||||
]}
|
||||
>
|
||||
@@ -194,7 +213,7 @@ export function AdjustCashModal({ user, open, onClose, onDone }: ModalProps) {
|
||||
min={mode === 'set' ? 0 : undefined}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item name="reason" label="原因(入审计)" rules={[{ required: true }]}>
|
||||
<Form.Item name="reason" label="原因(入审计)" rules={[{ required: true, message: '请填写原因' }]}>
|
||||
<Input.TextArea rows={2} />
|
||||
</Form.Item>
|
||||
</Form>
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
'use client';
|
||||
|
||||
// 点列表里的手机号 → 抽屉列出该用户「同类型」的全部记录(反馈页=全部反馈;低价审核页=全部上报)。
|
||||
// 顶部汇总该用户的「提交/上报总计」+「奖励总计」;复用各自的 list 接口按 user_id 过滤(无需新后端接口)。
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Drawer, Empty, Space, Spin, Statistic, Table, Typography } from 'antd';
|
||||
import type { ColumnsType } from 'antd/es/table';
|
||||
import { api } from '@/lib/api';
|
||||
import type { CursorPage } from '@/lib/types';
|
||||
|
||||
const { Text } = Typography;
|
||||
|
||||
interface Props<T> {
|
||||
open: boolean;
|
||||
onClose: () => void;
|
||||
userId: number | null;
|
||||
phone: string | null;
|
||||
endpoint: string; // 列表接口,按 user_id 过滤,如 /admin/api/feedbacks
|
||||
columns: ColumnsType<T>;
|
||||
recordLabel: string; // 「反馈」/「低价上报」,用于标题与空态文案
|
||||
countLabel: string; // 顶部计数卡标题,如「提交总计」/「上报总计」
|
||||
rewardLabel: string; // 顶部奖励卡标题,如「提交奖励总计」/「上报奖励总计」
|
||||
rewardOf: (item: T) => number; // 单条已发奖励金币(未采纳/未通过返回 0)
|
||||
rewardSuffix?: string; // 第二个汇总卡单位,默认「金币」;领券场景可传「张」(领到券张数)等
|
||||
}
|
||||
|
||||
export default function UserRecordsDrawer<T extends { id: number }>({
|
||||
open,
|
||||
onClose,
|
||||
userId,
|
||||
phone,
|
||||
endpoint,
|
||||
columns,
|
||||
recordLabel,
|
||||
countLabel,
|
||||
rewardLabel,
|
||||
rewardOf,
|
||||
rewardSuffix = '金币',
|
||||
}: Props<T>) {
|
||||
const [items, setItems] = useState<T[]>([]);
|
||||
const [total, setTotal] = useState(0);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (!open || userId == null) return;
|
||||
let alive = true;
|
||||
setLoading(true);
|
||||
api
|
||||
.get<CursorPage<T>>(endpoint, {
|
||||
params: { user_id: userId, limit: 100, sort_by: 'created_at', sort_order: 'desc' },
|
||||
})
|
||||
.then((r) => {
|
||||
if (!alive) return;
|
||||
setItems(r.data.items);
|
||||
setTotal(r.data.total ?? r.data.items.length);
|
||||
})
|
||||
.catch(() => {
|
||||
if (!alive) return;
|
||||
setItems([]);
|
||||
setTotal(0);
|
||||
})
|
||||
.finally(() => {
|
||||
if (alive) setLoading(false);
|
||||
});
|
||||
return () => {
|
||||
alive = false;
|
||||
};
|
||||
}, [open, userId, endpoint]);
|
||||
|
||||
// 奖励总计在已加载记录上累加(单用户记录数远小于 100 上限,够用)
|
||||
const rewardTotal = items.reduce((sum, it) => sum + rewardOf(it), 0);
|
||||
|
||||
return (
|
||||
<Drawer
|
||||
title={
|
||||
<span>
|
||||
用户 #{userId ?? '-'} 的全部{recordLabel}
|
||||
{phone ? (
|
||||
<Text type="secondary" style={{ fontSize: 13, marginLeft: 8 }}>
|
||||
{phone}
|
||||
</Text>
|
||||
) : null}
|
||||
</span>
|
||||
}
|
||||
width={760}
|
||||
open={open}
|
||||
onClose={onClose}
|
||||
destroyOnHidden
|
||||
>
|
||||
{loading ? (
|
||||
<Spin style={{ display: 'block', margin: '40px auto' }} />
|
||||
) : (
|
||||
<>
|
||||
<Space size={48} style={{ marginBottom: 20 }}>
|
||||
<Statistic title={countLabel} value={total} />
|
||||
<Statistic title={rewardLabel} value={rewardTotal} suffix={rewardSuffix} />
|
||||
</Space>
|
||||
{items.length === 0 ? (
|
||||
<Empty description={`该用户暂无${recordLabel}`} style={{ marginTop: 24 }} />
|
||||
) : (
|
||||
<Table<T>
|
||||
rowKey="id"
|
||||
size="small"
|
||||
columns={columns}
|
||||
dataSource={items}
|
||||
pagination={false}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</Drawer>
|
||||
);
|
||||
}
|
||||
+135
-7
@@ -81,6 +81,7 @@ export interface UserOverview {
|
||||
user: UserListItem;
|
||||
coin_balance: number;
|
||||
cash_balance_cents: number;
|
||||
invite_cash_balance_cents: number; // 邀请奖励金余额(与 cash_balance_cents 物理隔离)
|
||||
total_coin_earned: number;
|
||||
comparison_total: number;
|
||||
comparison_success: number;
|
||||
@@ -116,6 +117,8 @@ export interface WithdrawOrder {
|
||||
user_id: number;
|
||||
out_bill_no: string;
|
||||
amount_cents: number;
|
||||
// 提现类型:coin_cash(福利页提现,金币兑换现金) / invite_cash(邀请提现,邀请奖励金)
|
||||
source: string;
|
||||
user_name: string | null;
|
||||
status: string; // reviewing / pending / success / failed / rejected
|
||||
wechat_state: string | null;
|
||||
@@ -238,15 +241,36 @@ export interface Feedback {
|
||||
user_id: number;
|
||||
content: string;
|
||||
contact: string;
|
||||
// 反馈来源入口:profile(「我的」页=普通反馈) / comparison(比价结果页=比价反馈)
|
||||
source: string;
|
||||
// 比价反馈的问题场景(找错商品/优惠不对…);普通反馈为 null
|
||||
scene: string | null;
|
||||
images: string[] | null;
|
||||
// pending(审核中) / adopted(已采纳) / rejected(未采纳);历史数据可能为 new
|
||||
status: string;
|
||||
reject_reason: string | null; // 未采纳原因(用户端可见)
|
||||
reward_coins: number | null; // 采纳后发放金币
|
||||
review_note: string | null; // 审核批注(采纳要点 / 内部备注)
|
||||
review_note: string | null; // 审核批注(采纳要点 / 内部备注,用户不可见)
|
||||
admin_reply: string | null; // 运营给用户的回复留言(用户端可见)
|
||||
reviewed_by_admin_id: number | null;
|
||||
reviewed_at: string | null;
|
||||
created_at: string;
|
||||
// 提交端环境快照:提交版本号 / 机型OS版本;改版前的历史反馈为 null
|
||||
app_version: string | null;
|
||||
device_model: string | null;
|
||||
rom_name: string | null;
|
||||
android_version: string | null;
|
||||
// 联表瞬态:展示完整手机号(点手机号查该用户全部反馈)
|
||||
phone: string | null;
|
||||
nickname: string | null;
|
||||
}
|
||||
|
||||
// 反馈审核台顶部各状态计数(pending 含历史 new 态)。后端 GET /admin/api/feedbacks/summary。
|
||||
export interface FeedbackSummary {
|
||||
pending: number;
|
||||
adopted: number;
|
||||
rejected: number;
|
||||
total: number;
|
||||
}
|
||||
|
||||
// 反馈页「加群二维码」卡配置(运营后台改 → App 意见反馈页同步)。
|
||||
@@ -365,15 +389,32 @@ export interface AdRevenueRecord {
|
||||
matched: boolean;
|
||||
}
|
||||
|
||||
// 广告收益报表:按日期汇总的一天(按天趋势图用;全量,不受 limit 影响)
|
||||
// 广告收益报表:按日期汇总的一天(按天趋势图用;全量,不受分页影响)
|
||||
export interface AdRevenueDaily {
|
||||
date: string; // 北京时间 YYYY-MM-DD
|
||||
impressions: number;
|
||||
revenue_yuan: number; // 客户端预估收益(eCPM 折算)
|
||||
pangle_revenue_yuan: number | null; // 穿山甲后台预估收益(GroMore revenue);非全量视图/无数据为 null
|
||||
pangle_api_revenue_yuan: number | null; // 穿山甲收益API(更接近结算);未配/当天/无数据为 null
|
||||
expected_coin: number;
|
||||
actual_coin: number;
|
||||
}
|
||||
|
||||
// 广告收益报表:按北京小时(0–23)汇总的一小时(按小时趋势图用;全量,不受分页影响;按天查询时为空)
|
||||
export interface AdRevenueHourly {
|
||||
hour: number; // 北京时间小时 0–23
|
||||
impressions: number;
|
||||
revenue_yuan: number;
|
||||
expected_coin: number;
|
||||
actual_coin: number;
|
||||
}
|
||||
|
||||
// 广告收益报表:按广告类型(ad_type)的小计(展示条数 + 预估收益;eCPM 前端用 收益÷展示×1000 算)
|
||||
export interface AdRevenueTypeStat {
|
||||
impressions: number; // 该类型展示条数合计
|
||||
revenue_yuan: number; // 该类型预估收益合计(元)
|
||||
}
|
||||
|
||||
// 广告收益报表:一次广告事件(逐条一行)。激励视频展示+发奖按 ad_session_id 合并;信息流展示/发奖各自成行。
|
||||
export interface AdRevenueRow {
|
||||
event_key: string; // 事件稳定唯一键(前端 rowKey)
|
||||
@@ -391,6 +432,7 @@ export interface AdRevenueRow {
|
||||
impressions: number; // 本行展示条数 1/0(供日汇总、趋势图复用)
|
||||
ecpm: string | null; // 分/千次;展示行取展示值,纯发奖行取发奖采用值
|
||||
revenue_yuan: number; // 本次展示预估收益(元);纯发奖行=0
|
||||
row_revenue_yuan?: number | null; // 主表逐行显示用:一次比价/领券聚合行=该次发奖广告 eCPM 折算之和;其它行空(回退 revenue_yuan)
|
||||
adn: string | null; // 实际填充 ADN;纯发奖行为空
|
||||
slot_id: string | null; // 底层 mediation rit;纯发奖行为空
|
||||
// ── 发奖侧 ──
|
||||
@@ -400,16 +442,30 @@ export interface AdRevenueRow {
|
||||
actual_coin: number; // 实发金币;纯展示=0
|
||||
matched: boolean; // 本条应发==实发;纯展示恒 true(不计对账)
|
||||
reward_detail: AdRevenueRecord | null; // 发奖复算明细(点行展开下钻);纯展示为空
|
||||
sub_rewards?: AdRevenueRecord[]; // 一次比价/领券聚合行的组内逐条明细(同整场 ad_session_id 的多条广告);展开渲染多行
|
||||
sub_count?: number; // 本行聚合的发奖条数:一次比价/领券=该次广告条数(≥1);激励视频/纯展示=1
|
||||
}
|
||||
|
||||
export interface AdRevenueReport {
|
||||
date_from: string; // 起始日 北京时间 YYYY-MM-DD
|
||||
date_to: string; // 结束日 北京时间 YYYY-MM-DD(闭区间;单日时与 date_from 相同)
|
||||
daily: AdRevenueDaily[]; // 按日期汇总序列(全量,供按天趋势图)
|
||||
total: number; // 广告事件总数(全量,不受 limit 影响)
|
||||
truncated: boolean;
|
||||
hourly: AdRevenueHourly[]; // 按小时汇总序列(全量,供按小时趋势图;按天查询时为空)
|
||||
type_stats: Record<string, AdRevenueTypeStat>; // 按广告类型小计;前端取 draw / reward_video
|
||||
// 可选:后端预聚合的「按广告类型」富小计(含发放金币明细)。当前后端未下发 → 数据大盘页
|
||||
// (dashboard adTypeSummary)用 `?.` 探测、缺失时按 items 现算兜底;后端补上即自动启用。
|
||||
by_ad_type?: Record<
|
||||
string,
|
||||
{ ad_type: string; impressions: number; revenue_yuan: number; expected_coin: number; actual_coin: number }
|
||||
>;
|
||||
dau: number | null; // 今日活跃(复用大盘 last_login_at);仅查询=今日时有值,否则 null
|
||||
total: number; // 当前筛选下的分页总条数(全量,不受分页影响)
|
||||
truncated: boolean; // 当前页之后是否还有更多事件(分页后前端不再据此报警)
|
||||
total_impressions: number;
|
||||
total_revenue_yuan: number;
|
||||
total_revenue_yuan: number; // 客户端预估收益合计(eCPM 折算)
|
||||
total_pangle_revenue_yuan: number | null; // 穿山甲后台预估收益合计(GroMore revenue);非全量视图/无数据为 null
|
||||
total_pangle_api_revenue_yuan: number | null; // 穿山甲收益API合计(更接近结算);未配/当天/非全量视图为 null
|
||||
pangle_revenue_available: boolean; // 本次结果是否带穿山甲后台收益(全量视图且已同步到数据)
|
||||
total_expected_coin: number;
|
||||
total_actual_coin: number;
|
||||
mismatch_count: number; // 应发≠实发的发奖条数
|
||||
@@ -425,7 +481,17 @@ export interface DashboardOverview {
|
||||
new_today: number;
|
||||
dau: number;
|
||||
};
|
||||
coins: { granted_total: number };
|
||||
coins: {
|
||||
reward_video_coin_total: number;
|
||||
reward_video_watch_count: number;
|
||||
feed_ad_coin_total: number;
|
||||
feed_ad_watch_count: number;
|
||||
signin_coin_total: number;
|
||||
signin_count: number;
|
||||
signin_boost_coin_total: number;
|
||||
signin_boost_watch_count: number;
|
||||
granted_total: number;
|
||||
};
|
||||
cash: {
|
||||
withdraw_success_cents: number;
|
||||
withdraw_pending_count: number;
|
||||
@@ -433,8 +499,60 @@ export interface DashboardOverview {
|
||||
withdraw_failed_count: number;
|
||||
};
|
||||
comparison: { total: number; success: number; success_rate: number };
|
||||
// 时段大盘(对应后端 app/admin/schemas/dashboard.py DashboardPeriod);新版数据大盘页用
|
||||
period: {
|
||||
date_from: string;
|
||||
date_to: string;
|
||||
users: {
|
||||
new: number;
|
||||
active: number;
|
||||
retained_new_users: number;
|
||||
retention_rate: number | null;
|
||||
retention_note: string;
|
||||
};
|
||||
comparison: {
|
||||
total: number;
|
||||
success: number;
|
||||
success_rate: number;
|
||||
ordered: number;
|
||||
average_duration_ms: number | null;
|
||||
average_saved_cents: number | null;
|
||||
};
|
||||
coins: {
|
||||
granted_total: number;
|
||||
reward_video_coin_total: number;
|
||||
feed_ad_coin_total: number;
|
||||
signin_coin_total: number;
|
||||
signin_boost_coin_total: number;
|
||||
task_coin_total: number;
|
||||
coupon_reward_coin_total: number;
|
||||
comparison_reward_coin_total: number;
|
||||
regular_task_coin_total: number;
|
||||
};
|
||||
cash: { withdraw_success_cents: number };
|
||||
trend: {
|
||||
date: string;
|
||||
active_users: number;
|
||||
new_users: number;
|
||||
comparisons: number;
|
||||
}[];
|
||||
};
|
||||
feedback: { new: number };
|
||||
cps: { available: boolean; note: string };
|
||||
cps: {
|
||||
available: boolean;
|
||||
note: string;
|
||||
meituan_order_count: number;
|
||||
meituan_commission_cents: number;
|
||||
meituan_hit_count: number;
|
||||
meituan_miss_count: number;
|
||||
meituan_unknown_rate_count: number;
|
||||
meituan_hit_rate: number | null;
|
||||
jd_order_count?: number;
|
||||
jd_commission_cents?: number;
|
||||
jd_actual_commission_cents?: number;
|
||||
jd_estimated_commission_cents?: number;
|
||||
jd_invalid_count?: number;
|
||||
};
|
||||
}
|
||||
|
||||
export interface PriceReport {
|
||||
@@ -455,6 +573,16 @@ export interface PriceReport {
|
||||
reward_coins: number | null;
|
||||
reviewed_at: string | null;
|
||||
created_at: string;
|
||||
// 联表瞬态:phone/nickname 展示完整手机号(点手机号查该用户全部上报);
|
||||
// 其余取自关联比价记录(无关联记录时为 null):trace 调试链接、机型OS版本、提交版本号
|
||||
phone: string | null;
|
||||
nickname: string | null;
|
||||
trace_id: string | null;
|
||||
trace_url: string | null;
|
||||
device_model: string | null; // 机型,如 PEEM00
|
||||
rom_name: string | null; // ROM/OS 名,如 ColorOS / MIUI / HarmonyOS
|
||||
android_version: string | null; // Android 版本号,如 13
|
||||
app_version: string | null; // 提交时我们 app 的 versionName,如 1.2.3
|
||||
}
|
||||
|
||||
export interface PriceReportSummary {
|
||||
|
||||
Reference in New Issue
Block a user