Compare commits

..

2 Commits

Author SHA1 Message Date
exinglang b74bfcbf64 feat(config): 增加两套引导视频奖励配置 2026-07-27 15:14:47 +08:00
linkeyu 8d7f36ddac 修复:展示收益明细广告网络来源 (#81)
## 本次改动

- 展开聚合收益记录时优先展示每条明细自身的 ADN
- 单条发奖明细同样读取明细级来源
- 无唯一来源证据的历史记录明确显示“未上报”

## 验证

TypeScript `--noEmit` 检查通过。

依赖服务端 PR:WonderableAI/shaguabijia-app-server#179。

---------

Co-authored-by: linkeyu <798648091@qq.com>
Reviewed-on: #81
Co-authored-by: linkeyu <linkeyu@wonderable.ai>
Co-committed-by: linkeyu <linkeyu@wonderable.ai>
2026-07-27 10:24:12 +08:00
4 changed files with 117 additions and 127 deletions
+19 -3
View File
@@ -194,7 +194,16 @@ type AdRevenueDetailRow = AdRevenueRecord & { source_adn?: string | null };
// 展开行(逐条事件展开)- 该条的发奖复算明细(还原金币审计的 eCPM/因子1/份数/LT/因子2 等列)
const DETAIL_COLUMNS: ColumnsType<AdRevenueDetailRow> = [
{ title: '来源广告网络', dataIndex: 'source_adn', width: 110, render: (value: string | null) => value || '-' },
{
title: '来源广告网络',
dataIndex: 'source_adn',
width: 110,
render: (value: string | null) => value?.trim() || (
<Tooltip title="该历史记录没有可唯一确认的 SDK 广告来源,未猜测填充。">
<span></span>
</Tooltip>
),
},
{
title: 'eCPM(元)',
dataIndex: 'ecpm',
@@ -1102,7 +1111,11 @@ export default function AdRevenueReportPage() {
style={{ marginTop: 8 }}
rowKey="record_id"
columns={DETAIL_COLUMNS}
dataSource={r.sub_rewards.map((detail) => ({ ...detail, source_adn: r.adn }))}
dataSource={r.sub_rewards.map((detail) => ({
...detail,
// 一次比价/领券可能由不同 ADN 连续填充,优先显示本条发奖记录的来源。
source_adn: detail.adn ?? r.adn,
}))}
pagination={false}
size="small"
scroll={{ x: 900 }}
@@ -1118,7 +1131,10 @@ export default function AdRevenueReportPage() {
style={{ marginTop: 8 }}
rowKey="record_id"
columns={DETAIL_COLUMNS}
dataSource={[{ ...r.reward_detail, source_adn: r.adn }]}
dataSource={[{
...r.reward_detail,
source_adn: r.reward_detail.adn ?? r.adn,
}]}
pagination={false}
size="small"
scroll={{ x: 900 }}
+94 -123
View File
@@ -1,7 +1,7 @@
'use client';
import { useEffect, useState } from 'react';
import { Button, Card, Space, Spin, Switch, Tag, Typography, Upload, message } from 'antd';
import { Button, Card, InputNumber, Space, Spin, Switch, Tag, Typography, Upload, message } from 'antd';
import { DeleteOutlined, UploadOutlined } from '@ant-design/icons';
import { api, errMsg } from '@/lib/api';
import { canDo } from '@/lib/auth';
@@ -9,55 +9,58 @@ import { mediaUrl } from '@/lib/media';
import type { GuideVideoConfig as GuideCfg } from '@/lib/types';
const { Text } = Typography;
/** 后端 media.save_guide_video 只认 MP4 魔数;这里先在浏览器挡一道,省得白传 100MB。 */
const MAX_BYTES = 100 * 1024 * 1024;
type Scene = 'coupon' | 'comparison';
/**
* 领券等候浮层的「新手引导视频」配置。
*
* 用户点首页「一键自动领取」→ 出等候浮层,浮层下方那块位置**前 3 次**放这支引导视频
* (而不是广告),每次固定发 120 金币;播完若浮层还开着,自动接着放广告(原逻辑)。
* 「系统配置 → 领券引导视频」tab 的一个区块。
*
* 后台只管两件事:**开关** 和 **换片**。次数(3)/ 金币(120)走服务端默认值,产品已拍板不再
* 开放配置,所以这里不渲染输入框、PATCH 也不带这两个字段(后端仍保留字段与默认值)。
*/
export default function GuideVideoConfig() {
const META: Record<Scene, { title: string; action: string }> = {
coupon: { title: '一键自动领取引导视频', action: '一键自动领取' },
comparison: { title: '开始比价引导视频', action: '开始比价' },
};
function SceneConfig({ scene }: { scene: Scene }) {
const meta = META[scene];
const [cfg, setCfg] = useState<GuideCfg | null>(null);
const [loading, setLoading] = useState(true);
const [saving, setSaving] = useState(false);
const [uploading, setUploading] = useState(false);
// 本地编辑态,保存时一次性 PATCH
const [enabled, setEnabled] = useState(true);
const [maxPlays, setMaxPlays] = useState(3);
const [rewardCoin, setRewardCoin] = useState(100);
const canEdit = canDo(['operator']);
const sync = (c: GuideCfg) => {
setCfg(c);
setEnabled(c.enabled);
const sync = (value: GuideCfg) => {
setCfg(value);
setEnabled(value.enabled);
setMaxPlays(value.max_plays);
setRewardCoin(value.reward_coin);
};
const load = async () => {
setLoading(true);
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);
} catch (e) {
message.error(errMsg(e));
} finally {
setLoading(false);
}
};
useEffect(() => {
load();
}, []);
void load();
}, [scene]);
const save = async () => {
setSaving(true);
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);
message.success('已保存,用户下一次进入领券浮层即生效');
message.success(`${meta.title}配置已保存,下次触发即生效`);
} catch (e) {
message.error(errMsg(e));
} finally {
@@ -65,11 +68,27 @@ 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) => {
// 有些系统给 .mp4 的 type 是空串,不能只看 type,再兜一层扩展名。
const looksMp4 = file.type === 'video/mp4' || /\.mp4$/i.test(file.name);
if (!looksMp4) {
if (file.type !== 'video/mp4' && !/\.mp4$/i.test(file.name)) {
message.error('仅支持 MP4 视频(H.264 编码)');
return Upload.LIST_IGNORE;
}
@@ -81,27 +100,15 @@ export default function GuideVideoConfig() {
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 () => {
setUploading(true);
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);
message.success('已移除引导视频,领券浮层恢复为只放广告');
message.success(`已移除${meta.title}`);
} catch (e) {
message.error(errMsg(e));
} finally {
@@ -112,82 +119,48 @@ export default function GuideVideoConfig() {
return (
<Card
size="small"
title="领券引导视频(App 领券等候浮层,前 3 次替代广告)"
title={meta.title}
style={{ marginBottom: 16 }}
extra={
cfg?.updated_at ? (
<Text type="secondary" style={{ fontSize: 12 }}>
{new Date(cfg.updated_at).toLocaleString('zh-CN')}
</Text>
) : null
}
extra={cfg?.updated_at ? <Text type="secondary"> {new Date(cfg.updated_at).toLocaleString('zh-CN')}</Text> : null}
>
<p style={{ color: '#999', marginTop: 0 }}>
广<b> 3 </b>
<b></b> <b>120 </b>广
<b></b><b></b>
<b></b><b></b>
<p style={{ color: '#777', marginTop: 0 }}>
Android {meta.action}广
</p>
{loading || !cfg ? (
<Spin style={{ display: 'block', margin: '24px 0' }} />
) : (
<Space align="start" size={32} wrap>
{/* 左:视频预览 */}
<div>
<Text type="secondary" style={{ fontSize: 12 }}>
</Text>
<div style={{ marginTop: 8, width: 240 }}>
{cfg.video_url ? (
// eslint-disable-next-line jsx-a11y/media-has-caption
<video
src={mediaUrl(cfg.video_url)}
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 style={{ width: 240 }}>
{cfg.video_url ? (
// eslint-disable-next-line jsx-a11y/media-has-caption
<video
src={mediaUrl(cfg.video_url)}
controls
style={{ width: 240, maxHeight: 420, borderRadius: 12, background: '#000' }}
/>
) : (
<div style={{ height: 280, border: '1px dashed #d9d9d9', borderRadius: 12, display: 'grid', placeItems: 'center', color: '#aaa' }}>
</div>
)}
</div>
{/* 右:编辑控件 */}
<Space direction="vertical" size="middle" style={{ minWidth: 360 }}>
<Space direction="vertical" size="middle" style={{ minWidth: 390 }}>
<Space>
<span></span>
<span></span>
<Switch checked={enabled} disabled={!canEdit} onChange={setEnabled} />
{!enabled && <Tag color="orange"></Tag>}
</Space>
<Space>
<span></span>
<InputNumber min={0} max={50} precision={0} value={maxPlays} disabled={!canEdit} onChange={(v) => setMaxPlays(v ?? 0)} />
<Text type="secondary"> N 3</Text>
</Space>
<Space>
<span></span>
<InputNumber min={0} max={10000} precision={0} value={rewardCoin} disabled={!canEdit} onChange={(v) => setRewardCoin(v ?? 0)} />
<Text type="secondary"> 100</Text>
</Space>
<Space wrap>
<Upload accept="video/mp4,.mp4" showUploadList={false} beforeUpload={beforeUpload} disabled={!canEdit}>
<Button icon={<UploadOutlined />} loading={uploading} disabled={!canEdit}>
@@ -195,28 +168,26 @@ export default function GuideVideoConfig() {
</Button>
</Upload>
{cfg.video_url && (
<Button
icon={<DeleteOutlined />}
danger
loading={uploading}
disabled={!canEdit}
onClick={removeVideo}
>
<Button icon={<DeleteOutlined />} danger loading={uploading} disabled={!canEdit} onClick={removeVideo}>
</Button>
)}
<Text type="secondary" style={{ fontSize: 12 }}>
MP4H.264100MB
</Text>
<Text type="secondary">MP4H.264100MB</Text>
</Space>
<Button type="primary" loading={saving} disabled={!canEdit} onClick={save}>
</Button>
{!canEdit && <Text type="secondary"> operator / super_admin </Text>}
<Button type="primary" loading={saving} disabled={!canEdit} onClick={save}></Button>
<Text type="secondary"> {cfg.total_plays} {cfg.granted_plays} </Text>
</Space>
</Space>
)}
</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: 'feedback-qr', label: '反馈二维码', children: <FeedbackQrConfig /> },
{ key: 'guide-video', label: '领券引导视频', children: <GuideVideoConfig /> },
{ key: 'guide-video', label: '引导视频奖励', children: <GuideVideoConfig /> },
]}
/>
</div>
+3
View File
@@ -406,6 +406,7 @@ export interface FeedbackQrConfig {
/** 领券等候浮层的「新手引导视频」配置(前 3 次用它替代广告,每次固定 120 金币)。
* 后台只开放 enabled + 换片;下面几个字段接口仍返回,但页面不展示、也不回传。 */
export interface GuideVideoConfig {
scene: 'coupon' | 'comparison';
enabled: boolean;
video_url: string | null; // /media/guide_video/xxx.mp4;null = 未配片(浮层照旧只放广告)
max_plays: number; // 每个账号前 N 次浮层放引导视频(服务端默认 3,后台不开放调整)
@@ -542,6 +543,8 @@ export interface AdRevenueRecord {
expected_coin: number;
actual_coin: number;
matched: boolean;
adn: string | null; // 本条发奖对应的实际填充 ADN
slot_id: string | null; // 本条发奖对应的底层 mediation rit
}
// 广告收益报表:按日期汇总的一天(按天趋势图用;全量,不受分页影响)