Compare commits

...

5 Commits

Author SHA1 Message Date
exinglang 1e81bab6ea feat(新手引导): 支持十圈视频配置 2026-07-29 22:39:42 +08:00
zuochenyong c564e9df12 feat(config): 增加两套引导视频奖励配置 (#96)
Co-authored-by: guke <guke@wonderable.ai>
Co-authored-by: exinglang <exinglang@qq.com>
Reviewed-on: #96
Co-authored-by: zuochenyong <zuochenyong@wonderable.ai>
Co-committed-by: zuochenyong <zuochenyong@wonderable.ai>
2026-07-29 15:18:51 +08:00
linkeyu a286f859ee 修复:业务收益详情继承广告收益筛选口径 (#94)
## 修复

- 点击广告收益页用户后,详情默认继承已执行查询的日期范围
- 同步传递正式/测试环境、业务/全量代码位口径、领券/比价场景
- 传递的是上一次成功查询的快照,避免用户改了筛选但尚未点“查询”时详情口径漂移
- 文案明确 Draw eCPM 基于全部实际展示(含未发奖)

## 验证

- 已重放到最新 `main`,无冲突
- `npm run build` 通过(含 TypeScript 类型检查)

## 依赖/上线顺序

依赖 app-server 配套 PR 新增的 `app_env`、`revenue_scope`、`feed_scene` 查询参数;请先上线后端,再上线本 PR。

---------

Co-authored-by: linkeyu <798648091@qq.com>
Reviewed-on: #94
Co-authored-by: linkeyu <linkeyu@wonderable.ai>
Co-committed-by: linkeyu <linkeyu@wonderable.ai>
2026-07-28 17:58:04 +08:00
linkeyu 549c9bdfad 修复:统一领券与比价广告数百分位口径 (#92)
## 改动说明

- 将单次领券、比价广告数从线性插值百分位改为 nearest-rank 离散百分位
- 百分位结果始终取自真实观测样本,不再出现 13.5 条这类小数广告数
- 指标展示改为整数

## 线上数据复算

2026-07-24 正式业务口径:

- 领券 P5/P50/P95:`1/7/13.5` 修正为 `1/7/15`
- 比价 P5/P50/P95:`1/2/8.3` 修正为 `1/2/9`

## 验证

- 线上数据完整分组复算通过
- 空样本、单样本边界校验通过
- `npm run build` 通过(含 TypeScript 类型检查)

---------

Co-authored-by: guke <guke@wonderable.ai>
Co-authored-by: linkeyu <798648091@qq.com>
Reviewed-on: #92
Co-authored-by: linkeyu <linkeyu@wonderable.ai>
Co-committed-by: linkeyu <linkeyu@wonderable.ai>
2026-07-28 13:50:40 +08:00
linkeyu 26b1adb769 优化:数据大盘支持选择今日 (#93)
## 改动说明

- 数据大盘自定义日期范围放开今日选择
- 仍禁止选择明日及未来日期
- 同步修正页面日期口径文案
- 快捷窗口仍按原口径默认截至昨日

## 口径核对

后端 `stats/overview` 及广告收益查询已支持北京时间今日自然日区间,本次无需修改后端。

## 验证

- 昨日:可选
- 今日:可选
- 明日/未来日期:禁用
- `npm run build` 通过(含 TypeScript 类型检查)

---------

Co-authored-by: linkeyu <798648091@qq.com>
Reviewed-on: #93
Co-authored-by: linkeyu <linkeyu@wonderable.ai>
Co-committed-by: linkeyu <linkeyu@wonderable.ai>
2026-07-28 13:50:14 +08:00
11 changed files with 336 additions and 166 deletions
+1 -1
View File
@@ -3,7 +3,7 @@
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "next dev -p 3001", "dev": "next dev -p 3002",
"build": "next build", "build": "next build",
"start": "next start -p 3001", "start": "next start -p 3001",
"lint": "next lint" "lint": "next lint"
@@ -32,9 +32,24 @@ interface Props {
onClose: () => void; onClose: () => void;
userId: number | null; userId: number | null;
phone: string | null; // 报表行已有的手机号:概览拉取失败时兜底展示 phone: string | null; // 报表行已有的手机号:概览拉取失败时兜底展示
dateFrom: string | null;
dateTo: string | null;
appEnv?: 'prod' | 'test';
revenueScope: 'business' | 'all';
feedScene?: 'comparison' | 'coupon' | 'welfare';
} }
export default function UserAdRevenueDrawer({ open, onClose, userId, phone }: Props) { export default function UserAdRevenueDrawer({
open,
onClose,
userId,
phone,
dateFrom,
dateTo,
appEnv,
revenueScope,
feedScene,
}: Props) {
// UserRewardPanel 的 user 快照:它只读 phone/nickname/wechat_nickname/created_at,其余按 snapshot 形状补齐。 // UserRewardPanel 的 user 快照:它只读 phone/nickname/wechat_nickname/created_at,其余按 snapshot 形状补齐。
const [user, setUser] = useState<WithdrawUserSnapshot | null>(null); const [user, setUser] = useState<WithdrawUserSnapshot | null>(null);
@@ -82,7 +97,19 @@ export default function UserAdRevenueDrawer({ open, onClose, userId, phone }: Pr
> >
{/* userId 就绪即渲染;UserRewardPanel 内部按 userId 自行拉统计与金币记录,user 基本信息随后补上。 {/* userId 就绪即渲染;UserRewardPanel 内部按 userId 自行拉统计与金币记录,user 基本信息随后补上。
statsVariant="ad":统计区只显示 6 项看广告统计(累计提现/现金余额/激励视频观看数+eCPM/draw观看数+eCPM) */} statsVariant="ad":统计区只显示 6 项看广告统计(累计提现/现金余额/激励视频观看数+eCPM/draw观看数+eCPM) */}
{userId != null && <UserRewardPanel userId={userId} user={user} statsVariant="ad" />} {userId != null && (
<UserRewardPanel
key={`${userId}-${dateFrom}-${dateTo}-${appEnv}-${revenueScope}-${feedScene}`}
userId={userId}
user={user}
statsVariant="ad"
initialDateFrom={dateFrom ?? undefined}
initialDateTo={dateTo ?? undefined}
appEnv={appEnv}
revenueScope={revenueScope}
feedScene={feedScene}
/>
)}
</Drawer> </Drawer>
); );
} }
+44 -12
View File
@@ -30,7 +30,7 @@ import {
} from '@ant-design/icons'; } from '@ant-design/icons';
import dayjs, { type Dayjs } from 'dayjs'; import dayjs, { type Dayjs } from 'dayjs';
import { api, errMsg } from '@/lib/api'; import { api, errMsg } from '@/lib/api';
import { formatUtcTime, percentile } from '@/lib/format'; import { formatUtcTime, nearestRankPercentile } from '@/lib/format';
import type { import type {
AdRevenueDaily, AdRevenueDaily,
AdRevenueHourly, AdRevenueHourly,
@@ -470,7 +470,27 @@ export default function AdRevenueReportPage() {
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [formulaOpen, setFormulaOpen] = useState(false); const [formulaOpen, setFormulaOpen] = useState(false);
// 点用户手机号弹出的「用户广告收益详情」半屏抽屉(userId + 手机号;null=关闭) // 点用户手机号弹出的「用户广告收益详情」半屏抽屉(userId + 手机号;null=关闭)
const [userDrawer, setUserDrawer] = useState<{ userId: number; phone: string | null } | null>(null); const [userDrawer, setUserDrawer] = useState<{
userId: number;
phone: string | null;
dateFrom: string;
dateTo: string;
appEnv?: 'prod' | 'test';
revenueScope: 'business' | 'all';
feedScene?: 'comparison' | 'coupon' | 'welfare';
} | null>(null);
const [queriedDetailFilters, setQueriedDetailFilters] = useState<{
dateFrom: string;
dateTo: string;
appEnv?: 'prod' | 'test';
revenueScope: 'business' | 'all';
feedScene?: 'comparison' | 'coupon' | 'welfare';
}>({
dateFrom: range[0].format('YYYY-MM-DD'),
dateTo: range[1].format('YYYY-MM-DD'),
appEnv: 'prod',
revenueScope: 'business',
});
// 当前选择是否跨多天:跨多天时「按小时」无意义,粒度强制按天 // 当前选择是否跨多天:跨多天时「按小时」无意义,粒度强制按天
const rangeMultiDay = range[0].format('YYYY-MM-DD') !== range[1].format('YYYY-MM-DD'); const rangeMultiDay = range[0].format('YYYY-MM-DD') !== range[1].format('YYYY-MM-DD');
@@ -503,6 +523,13 @@ export default function AdRevenueReportPage() {
}, },
}); });
setData(res.data); setData(res.data);
setQueriedDetailFilters({
dateFrom: from,
dateTo: to,
appEnv: appEnv === 'all' ? undefined : appEnv,
revenueScope,
feedScene: scene as 'comparison' | 'coupon' | 'welfare' | undefined,
});
setPage(targetPage); setPage(targetPage);
setQueriedLimit(targetLimit); setQueriedLimit(targetLimit);
setQueriedGranularity(gran); setQueriedGranularity(gran);
@@ -551,7 +578,7 @@ export default function AdRevenueReportPage() {
width: 150, width: 150,
render: (phone: string | null, r: AdRevenueRow) => ( render: (phone: string | null, r: AdRevenueRow) => (
// 点手机号/用户 → 打开该用户「广告收益详情」半屏抽屉(统计卡 + 金币记录) // 点手机号/用户 → 打开该用户「广告收益详情」半屏抽屉(统计卡 + 金币记录)
<a onClick={() => setUserDrawer({ userId: r.user_id, phone })}> <a onClick={() => setUserDrawer({ userId: r.user_id, phone, ...queriedDetailFilters })}>
{phone ? ( {phone ? (
<span> <span>
{phone} {phone}
@@ -758,9 +785,9 @@ export default function AdRevenueReportPage() {
.filter((item) => item.feed_scene === sceneName) .filter((item) => item.feed_scene === sceneName)
.map((item) => item.sub_count ?? 1); .map((item) => item.sub_count ?? 1);
return { return {
p5: percentile(counts, 0.05, false), p5: nearestRankPercentile(counts, 0.05),
p50: percentile(counts, 0.5, false), p50: nearestRankPercentile(counts, 0.5),
p95: percentile(counts, 0.95, false), p95: nearestRankPercentile(counts, 0.95),
}; };
}; };
return { coupon: summarize('coupon'), comparison: summarize('comparison') }; return { coupon: summarize('coupon'), comparison: summarize('comparison') };
@@ -1083,12 +1110,12 @@ export default function AdRevenueReportPage() {
</Typography.Text> </Typography.Text>
</Divider> </Divider>
<Row gutter={[16, 12]}> <Row gutter={[16, 12]}>
<Col span={4}><Statistic title="单次领券广告数 P5" value={sessionAdCounts.coupon.p5 ?? '-'} precision={1} /></Col> <Col span={4}><Statistic title="单次领券广告数 P5" value={sessionAdCounts.coupon.p5 ?? '-'} precision={0} /></Col>
<Col span={4}><Statistic title="单次领券广告数 P50" value={sessionAdCounts.coupon.p50 ?? '-'} precision={1} /></Col> <Col span={4}><Statistic title="单次领券广告数 P50" value={sessionAdCounts.coupon.p50 ?? '-'} precision={0} /></Col>
<Col span={4}><Statistic title="单次领券广告数 P95" value={sessionAdCounts.coupon.p95 ?? '-'} precision={1} /></Col> <Col span={4}><Statistic title="单次领券广告数 P95" value={sessionAdCounts.coupon.p95 ?? '-'} precision={0} /></Col>
<Col span={4}><Statistic title="单次比价广告数 P5" value={sessionAdCounts.comparison.p5 ?? '-'} precision={1} /></Col> <Col span={4}><Statistic title="单次比价广告数 P5" value={sessionAdCounts.comparison.p5 ?? '-'} precision={0} /></Col>
<Col span={4}><Statistic title="单次比价广告数 P50" value={sessionAdCounts.comparison.p50 ?? '-'} precision={1} /></Col> <Col span={4}><Statistic title="单次比价广告数 P50" value={sessionAdCounts.comparison.p50 ?? '-'} precision={0} /></Col>
<Col span={4}><Statistic title="单次比价广告数 P95" value={sessionAdCounts.comparison.p95 ?? '-'} precision={1} /></Col> <Col span={4}><Statistic title="单次比价广告数 P95" value={sessionAdCounts.comparison.p95 ?? '-'} precision={0} /></Col>
</Row> </Row>
</Card> </Card>
)} )}
@@ -1284,6 +1311,11 @@ export default function AdRevenueReportPage() {
open={!!userDrawer} open={!!userDrawer}
userId={userDrawer?.userId ?? null} userId={userDrawer?.userId ?? null}
phone={userDrawer?.phone ?? null} phone={userDrawer?.phone ?? null}
dateFrom={userDrawer?.dateFrom ?? null}
dateTo={userDrawer?.dateTo ?? null}
appEnv={userDrawer?.appEnv}
revenueScope={userDrawer?.revenueScope ?? 'all'}
feedScene={userDrawer?.feedScene}
onClose={() => setUserDrawer(null)} onClose={() => setUserDrawer(null)}
/> />
</div> </div>
+201 -125
View File
@@ -1,7 +1,21 @@
'use client'; 'use client';
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { Button, Card, Space, Spin, Switch, Tag, Typography, Upload, message } from 'antd'; import {
Alert,
Button,
Card,
Descriptions,
InputNumber,
Popconfirm,
Space,
Spin,
Switch,
Tag,
Typography,
Upload,
message,
} from 'antd';
import { DeleteOutlined, UploadOutlined } from '@ant-design/icons'; import { DeleteOutlined, UploadOutlined } from '@ant-design/icons';
import { api, errMsg } from '@/lib/api'; import { api, errMsg } from '@/lib/api';
import { canDo } from '@/lib/auth'; import { canDo } from '@/lib/auth';
@@ -9,55 +23,79 @@ import { mediaUrl } from '@/lib/media';
import type { GuideVideoConfig as GuideCfg } from '@/lib/types'; import type { GuideVideoConfig as GuideCfg } from '@/lib/types';
const { Text } = Typography; const { Text } = Typography;
/** 后端 media.save_guide_video 只认 MP4 魔数;这里先在浏览器挡一道,省得白传 100MB。 */
const MAX_BYTES = 100 * 1024 * 1024; const MAX_BYTES = 100 * 1024 * 1024;
const MIN_PLAYS = 1;
const MAX_PLAYS = 50;
const MIN_REWARD_COIN = 10;
const MAX_REWARD_COIN = 10000;
type Scene = 'coupon' | 'comparison';
/** const META: Record<Scene, { title: string; action: string }> = {
* 领券等候浮层的「新手引导视频」配置。 coupon: { title: '一键自动领取引导视频', action: '一键自动领取' },
* comparison: { title: '开始比价引导视频', action: '开始比价' },
* 用户点首页「一键自动领取」→ 出等候浮层,浮层下方那块位置**前 3 次**放这支引导视频 };
* (而不是广告),每次固定发 120 金币;播完若浮层还开着,自动接着放广告(原逻辑)。
* 「系统配置 → 领券引导视频」tab 的一个区块。 function formatDuration(durationMs: number | null | undefined) {
* if (durationMs == null || !Number.isFinite(durationMs)) return '—';
* 后台只管两件事:**开关** 和 **换片**。次数(3)/ 金币(120)走服务端默认值,产品已拍板不再 return `${(durationMs / 1000).toFixed(3).replace(/\.?0+$/, '')}`;
* 开放配置,所以这里不渲染输入框、PATCH 也不带这两个字段(后端仍保留字段与默认值)。 }
*/
export default function GuideVideoConfig() { function SceneConfig({ scene }: { scene: Scene }) {
const meta = META[scene];
const [cfg, setCfg] = useState<GuideCfg | null>(null); const [cfg, setCfg] = useState<GuideCfg | null>(null);
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const [saving, setSaving] = useState(false); const [saving, setSaving] = useState(false);
const [uploading, setUploading] = useState(false); const [uploading, setUploading] = useState(false);
const [enabled, setEnabled] = useState(false);
// 本地编辑态,保存时一次性 PATCH const [maxPlays, setMaxPlays] = useState(3);
const [enabled, setEnabled] = useState(true); const [rewardCoin, setRewardCoin] = useState(100);
const canEdit = canDo(['operator']); const canEdit = canDo(['operator']);
const configValid =
Number.isInteger(maxPlays) &&
maxPlays >= MIN_PLAYS &&
maxPlays <= MAX_PLAYS &&
Number.isInteger(rewardCoin) &&
rewardCoin >= MIN_REWARD_COIN &&
rewardCoin <= MAX_REWARD_COIN &&
rewardCoin % 10 === 0;
const sync = (c: GuideCfg) => { const sync = (value: GuideCfg) => {
setCfg(c); setCfg(value);
setEnabled(c.enabled); setEnabled(value.enabled);
setMaxPlays(value.max_plays);
setRewardCoin(value.reward_coin);
}; };
const load = async () => { const load = async () => {
setLoading(true); setLoading(true);
try { try {
const { data } = await api.get<GuideCfg>('/admin/api/guide-video'); const { data } = await api.get<GuideCfg>('/admin/api/guide-video', { params: { scene } });
sync(data); sync(data);
} catch (e) {
message.error(errMsg(e));
} finally { } finally {
setLoading(false); setLoading(false);
} }
}; };
useEffect(() => { useEffect(() => {
load(); void load();
}, []); }, [scene]);
const save = async () => { const save = async () => {
if (!configValid) {
message.error('请检查配置:播放次数为 1~50,每次金币为 10~10000 且必须是 10 的倍数');
return;
}
setSaving(true); setSaving(true);
try { try {
const { data } = await api.patch<GuideCfg>('/admin/api/guide-video', { enabled }); const { data } = await api.patch<GuideCfg>(
'/admin/api/guide-video',
{ enabled, max_plays: maxPlays, reward_coin: rewardCoin },
{ params: { scene } },
);
sync(data); sync(data);
message.success('已保存,用户下一次进入领券浮层即生效'); message.success(`${meta.title}配置已保存,下次触发即生效`);
} catch (e) { } catch (e) {
message.error(errMsg(e)); message.error(errMsg(e));
} finally { } finally {
@@ -65,12 +103,28 @@ export default function GuideVideoConfig() {
} }
}; };
// antd Upload:beforeUpload 里自行 POST(multipart),返回 false 阻止其默认上传。 const uploadVideo = async (file: File) => {
const form = new FormData();
form.append('file', file);
setUploading(true);
try {
const { data } = await api.post<GuideCfg>(
'/admin/api/guide-video/video',
form,
{ params: { scene } },
);
sync(data);
message.success(`${meta.title}已更新`);
} catch (e) {
message.error(`${errMsg(e)},原视频和配置未改变`);
} finally {
setUploading(false);
}
};
const beforeUpload = (file: File) => { const beforeUpload = (file: File) => {
// 有些系统给 .mp4 的 type 是空串,不能只看 type,再兜一层扩展名。 if (file.type !== 'video/mp4' && !/\.mp4$/i.test(file.name)) {
const looksMp4 = file.type === 'video/mp4' || /\.mp4$/i.test(file.name); message.error('仅支持 MP4 视频(H.264 或 HEVC/H.265 编码)');
if (!looksMp4) {
message.error('仅支持 MP4 视频(H.264 编码)');
return Upload.LIST_IGNORE; return Upload.LIST_IGNORE;
} }
if (file.size > MAX_BYTES) { if (file.size > MAX_BYTES) {
@@ -81,27 +135,15 @@ export default function GuideVideoConfig() {
return false; return false;
}; };
const uploadVideo = async (file: File) => {
const form = new FormData();
form.append('file', file);
setUploading(true);
try {
const { data } = await api.post<GuideCfg>('/admin/api/guide-video/video', form);
sync(data);
message.success('引导视频已更新,用户下一次进入领券浮层即生效');
} catch (e) {
message.error(errMsg(e));
} finally {
setUploading(false);
}
};
const removeVideo = async () => { const removeVideo = async () => {
setUploading(true); setUploading(true);
try { try {
const { data } = await api.delete<GuideCfg>('/admin/api/guide-video/video'); const { data } = await api.delete<GuideCfg>(
'/admin/api/guide-video/video',
{ params: { scene } },
);
sync(data); sync(data);
message.success('已移除引导视频,领券浮层恢复为只放广告'); message.success(`已移除${meta.title}`);
} catch (e) { } catch (e) {
message.error(errMsg(e)); message.error(errMsg(e));
} finally { } finally {
@@ -112,82 +154,107 @@ export default function GuideVideoConfig() {
return ( return (
<Card <Card
size="small" size="small"
title="领券引导视频(App 领券等候浮层,前 3 次替代广告)" title={meta.title}
style={{ marginBottom: 16 }} style={{ marginBottom: 16 }}
extra={ extra={cfg?.updated_at ? <Text type="secondary"> {new Date(cfg.updated_at).toLocaleString('zh-CN')}</Text> : null}
cfg?.updated_at ? (
<Text type="secondary" style={{ fontSize: 12 }}>
{new Date(cfg.updated_at).toLocaleString('zh-CN')}
</Text>
) : null
}
> >
<p style={{ color: '#999', marginTop: 0 }}> <p style={{ color: '#777', marginTop: 0 }}>
广<b> 3 </b> Android {meta.action}
<b></b> <b>120 </b>广 1/10 1/10 退
<b></b><b></b>
<b></b><b></b>
</p> </p>
{loading || !cfg ? ( {loading || !cfg ? (
<Spin style={{ display: 'block', margin: '24px 0' }} /> <Spin style={{ display: 'block', margin: '24px 0' }} />
) : ( ) : (
<Space align="start" size={32} wrap> <Space align="start" size={32} wrap>
{/* 左:视频预览 */} <div style={{ width: 240 }}>
<div> {cfg.video_url ? (
<Text type="secondary" style={{ fontSize: 12 }}> // eslint-disable-next-line jsx-a11y/media-has-caption
<video
</Text> src={mediaUrl(cfg.video_url)}
<div style={{ marginTop: 8, width: 240 }}> controls
{cfg.video_url ? ( style={{ width: 240, maxHeight: 420, borderRadius: 12, background: '#000' }}
// eslint-disable-next-line jsx-a11y/media-has-caption />
<video ) : (
src={mediaUrl(cfg.video_url)} <div style={{ height: 280, border: '1px dashed #d9d9d9', borderRadius: 12, display: 'grid', placeItems: 'center', color: '#aaa' }}>
controls
style={{
width: 240,
maxHeight: 420,
borderRadius: 12,
background: '#000',
border: '1px solid #f0f0f0',
}}
/>
) : (
<div
style={{
width: 240,
height: 320,
borderRadius: 12,
border: '1px dashed #d9d9d9',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
color: '#bbb',
fontSize: 13,
textAlign: 'center',
padding: 16,
}}
>
<br />
广
</div>
)}
</div>
{!enabled && cfg.video_url && (
<div style={{ color: '#fa8c16', fontSize: 12, marginTop: 6 }}>
广
</div> </div>
)} )}
</div> </div>
<Space direction="vertical" size="middle" style={{ minWidth: 390 }}>
{/* 右:编辑控件 */} {cfg.analysis_status === 'invalid' || cfg.analysis_error ? (
<Space direction="vertical" size="middle" style={{ minWidth: 360 }}> <Alert
type="error"
showIcon
message="视频分析异常,当前场景不可启用"
description={cfg.analysis_error || '请重新上传符合要求的视频'}
/>
) : null}
<Space> <Space>
<span></span> <span></span>
<Switch checked={enabled} disabled={!canEdit} onChange={setEnabled} /> <Switch
checked={enabled}
disabled={!canEdit || (!enabled && cfg.analysis_status !== 'valid')}
onChange={setEnabled}
/>
{!enabled && <Tag color="orange"></Tag>} {!enabled && <Tag color="orange"></Tag>}
{!enabled && cfg.analysis_status !== 'valid' && <Text type="secondary"></Text>}
</Space> </Space>
<Space>
<span></span>
<InputNumber
min={MIN_PLAYS}
max={MAX_PLAYS}
precision={0}
status={maxPlays < MIN_PLAYS || maxPlays > MAX_PLAYS ? 'error' : undefined}
value={maxPlays}
disabled={!canEdit}
onChange={(v) => setMaxPlays(v ?? MIN_PLAYS)}
/>
<Text type="secondary"> 150 3</Text>
</Space>
<Space>
<span></span>
<InputNumber
min={MIN_REWARD_COIN}
max={MAX_REWARD_COIN}
step={10}
precision={0}
status={
rewardCoin < MIN_REWARD_COIN ||
rewardCoin > MAX_REWARD_COIN ||
rewardCoin % 10 !== 0
? 'error'
: undefined
}
value={rewardCoin}
disabled={!canEdit}
onChange={(v) => setRewardCoin(v ?? MIN_REWARD_COIN)}
/>
<Text type="secondary">1010000 10 100</Text>
</Space>
{cfg.video_url ? (
<Descriptions size="small" bordered column={2}>
<Descriptions.Item label="总时长">{formatDuration(cfg.duration_ms)}</Descriptions.Item>
<Descriptions.Item label="单圈时长">
{formatDuration(cfg.circle_duration_ms ?? (cfg.duration_ms == null ? null : cfg.duration_ms / 10))}
</Descriptions.Item>
<Descriptions.Item label="单圈金币">
{rewardCoin === cfg.reward_coin ? cfg.reward_per_circle : rewardCoin / cfg.circle_count}
</Descriptions.Item>
<Descriptions.Item label="编码">
{cfg.video_codec || '—'} / {cfg.audio_codec || '无'}
</Descriptions.Item>
<Descriptions.Item label="分析状态" span={2}>
<Tag color={cfg.analysis_status === 'valid' ? 'green' : 'orange'}>
{cfg.analysis_status === 'valid'
? '分析完成'
: cfg.analysis_status === 'invalid'
? '分析异常'
: '未上传'}
</Tag>
</Descriptions.Item>
</Descriptions>
) : null}
<Space wrap> <Space wrap>
<Upload accept="video/mp4,.mp4" showUploadList={false} beforeUpload={beforeUpload} disabled={!canEdit}> <Upload accept="video/mp4,.mp4" showUploadList={false} beforeUpload={beforeUpload} disabled={!canEdit}>
<Button icon={<UploadOutlined />} loading={uploading} disabled={!canEdit}> <Button icon={<UploadOutlined />} loading={uploading} disabled={!canEdit}>
@@ -195,28 +262,37 @@ export default function GuideVideoConfig() {
</Button> </Button>
</Upload> </Upload>
{cfg.video_url && ( {cfg.video_url && (
<Button <Popconfirm
icon={<DeleteOutlined />} title={`确认移除${meta.title}`}
danger description="移除后该场景的新播放将无法使用引导视频,已经开始的播放不受影响。"
loading={uploading} okText="确认移除"
cancelText="取消"
okButtonProps={{ danger: true }}
onConfirm={removeVideo}
disabled={!canEdit} disabled={!canEdit}
onClick={removeVideo}
> >
<Button icon={<DeleteOutlined />} danger loading={uploading} disabled={!canEdit}>
</Button>
</Button>
</Popconfirm>
)} )}
<Text type="secondary" style={{ fontSize: 12 }}> <Text type="secondary">MP4H.264 HEVC/H.265 AAC30180 100MB</Text>
MP4H.264100MB
</Text>
</Space> </Space>
<Button type="primary" loading={saving} disabled={!canEdit || !configValid} onClick={save}>
<Button type="primary" loading={saving} disabled={!canEdit} onClick={save}>
</Button> </Button>
{!canEdit && <Text type="secondary"> operator / super_admin </Text>}
</Space> </Space>
</Space> </Space>
)} )}
</Card> </Card>
); );
} }
export default function GuideVideoConfig() {
return (
<>
<SceneConfig scene="coupon" />
<SceneConfig scene="comparison" />
</>
);
}
+1 -1
View File
@@ -165,7 +165,7 @@ export default function ConfigPage() {
}, },
{ key: 'welfare', label: '福利页', children: welfareConfig }, { key: 'welfare', label: '福利页', children: welfareConfig },
{ key: 'feedback-qr', label: '反馈二维码', children: <FeedbackQrConfig /> }, { key: 'feedback-qr', label: '反馈二维码', children: <FeedbackQrConfig /> },
{ key: 'guide-video', label: '领券引导视频', children: <GuideVideoConfig /> }, { key: 'guide-video', label: '引导视频奖励', children: <GuideVideoConfig /> },
]} ]}
/> />
</div> </div>
+2 -2
View File
@@ -710,7 +710,7 @@ export default function DashboardPage() {
<div> <div>
<h1></h1> <h1></h1>
<p> <p>
{updatedAt ?? '--'} · · 00:00 {updatedAt ?? '--'} · · 00:00
</p> </p>
</div> </div>
<div className="controls"> <div className="controls">
@@ -734,7 +734,7 @@ export default function DashboardPage() {
format="YYYY-MM-DD" format="YYYY-MM-DD"
allowClear={false} allowClear={false}
open={datePickerOpen} open={datePickerOpen}
disabledDate={(date) => date.isAfter(dayjs().subtract(1, 'day'), 'day')} disabledDate={(date) => date.isAfter(dayjs(), 'day')}
suffixIcon={<CalendarOutlined />} suffixIcon={<CalendarOutlined />}
onClick={() => setDatePickerOpen(true)} onClick={() => setDatePickerOpen(true)}
onOpenChange={setDatePickerOpen} onOpenChange={setDatePickerOpen}
+20 -4
View File
@@ -44,6 +44,11 @@ interface Props {
withdrawSource?: 'coin_cash' | 'invite_cash'; withdrawSource?: 'coin_cash' | 'invite_cash';
// 统计区字段集:withdraw(默认,提现详情:含提现细分) / ad(广告收益详情:只看看广告观看统计,对齐参考图 6 项) // 统计区字段集:withdraw(默认,提现详情:含提现细分) / ad(广告收益详情:只看看广告观看统计,对齐参考图 6 项)
statsVariant?: 'withdraw' | 'ad'; statsVariant?: 'withdraw' | 'ad';
initialDateFrom?: string;
initialDateTo?: string;
appEnv?: 'prod' | 'test';
revenueScope?: 'business' | 'all';
feedScene?: 'comparison' | 'coupon' | 'welfare';
} }
/** 用户看广告/提现详情:基本信息 + 互斥时间筛选 + 统计区(按 statsVariant 取字段集)+ 金币发放记录表。 */ /** 用户看广告/提现详情:基本信息 + 互斥时间筛选 + 统计区(按 statsVariant 取字段集)+ 金币发放记录表。 */
@@ -52,9 +57,17 @@ export default function UserRewardPanel({
user, user,
withdrawSource, withdrawSource,
statsVariant = 'withdraw', statsVariant = 'withdraw',
initialDateFrom,
initialDateTo,
appEnv,
revenueScope = 'all',
feedScene,
}: Props) { }: Props) {
const [mode, setMode] = useState<'all' | 'range'>('all'); // all=注册至今 / range=自定义区间 const hasInitialRange = Boolean(initialDateFrom && initialDateTo);
const [range, setRange] = useState<[Dayjs, Dayjs] | null>(null); const [mode, setMode] = useState<'all' | 'range'>(hasInitialRange ? 'range' : 'all');
const [range, setRange] = useState<[Dayjs, Dayjs] | null>(() =>
hasInitialRange ? [dayjs(initialDateFrom), dayjs(initialDateTo)] : null,
);
const [stats, setStats] = useState<UserRewardStats | null>(null); const [stats, setStats] = useState<UserRewardStats | null>(null);
const [statsLoading, setStatsLoading] = useState(false); const [statsLoading, setStatsLoading] = useState(false);
@@ -80,6 +93,9 @@ export default function UserRewardPanel({
params: { params: {
...JSON.parse(paramsKey), ...JSON.parse(paramsKey),
...(withdrawSource ? { withdraw_source: withdrawSource } : {}), ...(withdrawSource ? { withdraw_source: withdrawSource } : {}),
...(appEnv ? { app_env: appEnv } : {}),
revenue_scope: revenueScope,
...(feedScene ? { feed_scene: feedScene } : {}),
}, },
}); });
setStats(data); setStats(data);
@@ -88,7 +104,7 @@ export default function UserRewardPanel({
} finally { } finally {
setStatsLoading(false); setStatsLoading(false);
} }
}, [userId, paramsKey, withdrawSource]); }, [userId, paramsKey, withdrawSource, appEnv, revenueScope, feedScene]);
const loadRecords = useCallback( const loadRecords = useCallback(
async (p: number) => { async (p: number) => {
@@ -236,7 +252,7 @@ export default function UserRewardPanel({
</Descriptions> </Descriptions>
<Text type="secondary" style={{ fontSize: 12 }}> <Text type="secondary" style={{ fontSize: 12 }}>
{statsVariant === 'ad' {statsVariant === 'ad'
? '统计随上方时间筛选(现金余额除外,为当前快照);次数仅统计成功发奖记录,信息流按奖励份数统计;eCPM 为预估值。' ? '统计继承广告收益页已查询的日期、环境、业务代码位和场景;次数仅统计成功发奖记录,信息流按奖励份数统计;Draw eCPM 按全部实际展示统计(含未发奖)。'
: '统计随上方时间筛选(现金余额除外,为当前快照);提现按申请提交时间统计;累计收益为已发金币按当前汇率折算,不代表实际已提现金额;eCPM 为预估值。'} : '统计随上方时间筛选(现金余额除外,为当前快照);提现按申请提交时间统计;累计收益为已发金币按当前汇率折算,不代表实际已提现金额;eCPM 为预估值。'}
</Text> </Text>
+12
View File
@@ -37,6 +37,18 @@ export function percentile(values: readonly number[], q: number, round = true):
return round ? Math.round(result) : result; return round ? Math.round(result) : result;
} }
/**
* 离散计数分位数(nearest-rank)。
* 广告条数等不可拆分的计数不做线性插值,结果始终取自真实样本。
*/
export function nearestRankPercentile(values: readonly number[], q: number): number | null {
if (!values.length) return null;
const sorted = [...values].sort((a, b) => a - b);
const quantile = Math.min(1, Math.max(0, q));
const rank = Math.max(1, Math.ceil(quantile * sorted.length));
return sorted[rank - 1];
}
const hasTz = (v: string) => /(?:Z|[+-]\d{2}:?\d{2})$/i.test(v); const hasTz = (v: string) => /(?:Z|[+-]\d{2}:?\d{2})$/i.test(v);
/** 把 UTC 口径字符串解析为带时区的 dayjs(无时区后缀的补 Z 当 UTC)。 */ /** 把 UTC 口径字符串解析为带时区的 dayjs(无时区后缀的补 Z 当 UTC)。 */
+15 -8
View File
@@ -233,7 +233,7 @@ export interface UserRewardStats {
reward_video_avg_ecpm: number; // 平均激励视频 eCPM(分/千次) reward_video_avg_ecpm: number; // 平均激励视频 eCPM(分/千次)
reward_video_cash_cents: number; // 激励视频提现 reward_video_cash_cents: number; // 激励视频提现
feed_count: number; // 累计信息流广告数(份) feed_count: number; // 累计信息流广告数(份)
feed_avg_ecpm: number; // 平均信息流广告 eCPM(分/千次) feed_avg_ecpm: number; // 全部 Draw/feed 实际展示的平均 eCPM(分/千次,含未发奖展示)
feed_cash_cents: number; // 信息流广告提现 feed_cash_cents: number; // 信息流广告提现
} }
@@ -414,16 +414,23 @@ export interface FeedbackQrConfig {
updated_at: string | null; updated_at: string | null;
} }
/** 领券等候浮层的「新手引导视频配置(前 3 次用它替代广告,每次固定 120 金币)。 /** 领券/比价等候浮层的引导视频配置。视频分析结果均由服务端 ffprobe 生成。 */
* 后台只开放 enabled + 换片;下面几个字段接口仍返回,但页面不展示、也不回传。 */
export interface GuideVideoConfig { export interface GuideVideoConfig {
scene: 'coupon' | 'comparison';
enabled: boolean; enabled: boolean;
video_url: string | null; // /media/guide_video/xxx.mp4;null = 未配片(浮层照旧只放广告) video_url: string | null;
max_plays: number; // 每个账号前 N 次浮层放引导视频(服务端默认 3,后台不开放调整) max_plays: number;
reward_coin: number; // 每次固定金币(服务端默认 120,播完 / 中途关闭都发) reward_coin: number;
updated_at: string | null; updated_at: string | null;
total_plays: number; // 只读统计:全站已播次数(后台不再展示) duration_ms: number | null;
granted_plays: number; // 只读统计:其中已发币次数(后台不再展示) circle_duration_ms: number | null;
circle_count: 10;
reward_per_circle: number;
video_codec: string | null;
audio_codec: string | null;
analysis_status: 'missing' | 'valid' | 'invalid';
analysis_error: string | null;
config_version: number;
} }
export interface AuditLog { export interface AuditLog {
+8 -8
View File
@@ -1,5 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# 一键启动傻瓜比价本地联调:用户侧 API(8770) + 运营后台 API(8771) + 运营后台前端(3001)。 # 一键启动傻瓜比价本地联调:用户侧 API(8772) + 运营后台 API(8773) + 运营后台前端(3002)。
# 跨平台:Windows(Git Bash)与 macOS 通用。停止用 ./stop.sh。 # 跨平台:Windows(Git Bash)与 macOS 通用。停止用 ./stop.sh。
# #
# 路径相对本脚本推导(本脚本在 shaguabijia-admin-web 内,server 是它的同级目录), # 路径相对本脚本推导(本脚本在 shaguabijia-admin-web 内,server 是它的同级目录),
@@ -93,19 +93,19 @@ start_uvicorn() {
} }
# 用户侧绑 0.0.0.0,真机/模拟器可经局域网 IP 访问;后台只本机用,绑 127.0.0.1 # 用户侧绑 0.0.0.0,真机/模拟器可经局域网 IP 访问;后台只本机用,绑 127.0.0.1
start_uvicorn "user-api" "app.main:app" 8770 "0.0.0.0" start_uvicorn "user-api" "app.main:app" 8772 "0.0.0.0"
start_uvicorn "admin-api" "app.admin.main:admin_app" 8771 "127.0.0.1" start_uvicorn "admin-api" "app.admin.main:admin_app" 8773 "127.0.0.1"
if port_in_use 3001; then if port_in_use 3002; then
echo "↺ admin-web 已在 :3001(跳过)" echo "↺ admin-web 已在 :3002(跳过)"
else else
cd "$WEB_DIR" || exit 1 cd "$WEB_DIR" || exit 1
nohup npm run dev > "$LOG_DIR/admin-web.log" 2>&1 & nohup npm run dev > "$LOG_DIR/admin-web.log" 2>&1 &
echo "$!" > "$LOG_DIR/admin-web.pid" echo "$!" > "$LOG_DIR/admin-web.pid"
echo "✅ admin-web 起在 :3001 (日志 $LOG_DIR/admin-web.log)" echo "✅ admin-web 起在 :3002 (日志 $LOG_DIR/admin-web.log)"
fi fi
echo "" echo ""
echo "⏳ 前端首次编译要几秒,然后开 👉 http://localhost:3001 (admin / admin12345)" echo "⏳ 前端首次编译要几秒,然后开 👉 http://localhost:3002 (admin / admin12345)"
echo " 用户侧 API: http://127.0.0.1:8770 | 后台 API: http://127.0.0.1:8771/admin/docs" echo " 用户侧 API: http://127.0.0.1:8772 | 后台 API: http://127.0.0.1:8773/admin/docs"
echo " 看日志: tail -f $LOG_DIR/admin-web.log | 停止: bash \"$SCRIPT_DIR/stop.sh\"" echo " 看日志: tail -f $LOG_DIR/admin-web.log | 停止: bash \"$SCRIPT_DIR/stop.sh\""
+3 -3
View File
@@ -1,5 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# 停止 start.sh 起的三个服务:用户侧 API(8770) + 后台 API(8771) + 前端(3001)。 # 停止 start.sh 起的三个服务:用户侧 API(8772) + 后台 API(8773) + 前端(3002)。
# 双保险:先按 start.sh 落的 PID 文件杀,再按端口兜底(Windows 走 PowerShell,mac 走 lsof)。 # 双保险:先按 start.sh 落的 PID 文件杀,再按端口兜底(Windows 走 PowerShell,mac 走 lsof)。
# (PG 若由 brew 自启,本脚本不停它。) # (PG 若由 brew 自启,本脚本不停它。)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
@@ -32,8 +32,8 @@ kill_port() {
fi fi
} }
for port in 8770 8771 3001; do for port in 8772 8773 3002; do
kill_port "$port" kill_port "$port"
done done
echo "✅ 已停止(用户侧 8770 / 后台 8771 / 前端 3001)。" echo "✅ 已停止(用户侧 8772 / 后台 8773 / 前端 3002)。"