Compare commits

..

2 Commits

Author SHA1 Message Date
guke 767585cafa Merge branch 'main' into fix-guideVideoFix 2026-07-29 15:18:16 +08:00
exinglang b74bfcbf64 feat(config): 增加两套引导视频奖励配置 2026-07-27 15:14:47 +08:00
5 changed files with 37 additions and 148 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 3002", "dev": "next dev -p 3001",
"build": "next build", "build": "next build",
"start": "next start -p 3001", "start": "next start -p 3001",
"lint": "next lint" "lint": "next lint"
+18 -123
View File
@@ -1,21 +1,7 @@
'use client'; 'use client';
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { import { Button, Card, InputNumber, Space, Spin, Switch, Tag, Typography, Upload, message } from 'antd';
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';
@@ -24,10 +10,6 @@ import type { GuideVideoConfig as GuideCfg } from '@/lib/types';
const { Text } = Typography; const { Text } = Typography;
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'; type Scene = 'coupon' | 'comparison';
const META: Record<Scene, { title: string; action: string }> = { const META: Record<Scene, { title: string; action: string }> = {
@@ -35,29 +17,16 @@ const META: Record<Scene, { title: string; action: string }> = {
comparison: { title: '开始比价引导视频', action: '开始比价' }, comparison: { title: '开始比价引导视频', action: '开始比价' },
}; };
function formatDuration(durationMs: number | null | undefined) {
if (durationMs == null || !Number.isFinite(durationMs)) return '—';
return `${(durationMs / 1000).toFixed(3).replace(/\.?0+$/, '')}`;
}
function SceneConfig({ scene }: { scene: Scene }) { function SceneConfig({ scene }: { scene: Scene }) {
const meta = META[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); const [enabled, setEnabled] = useState(true);
const [maxPlays, setMaxPlays] = useState(3); const [maxPlays, setMaxPlays] = useState(3);
const [rewardCoin, setRewardCoin] = useState(100); 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 = (value: GuideCfg) => { const sync = (value: GuideCfg) => {
setCfg(value); setCfg(value);
@@ -83,10 +52,6 @@ function SceneConfig({ scene }: { scene: Scene }) {
}, [scene]); }, [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>( const { data } = await api.patch<GuideCfg>(
@@ -116,7 +81,7 @@ function SceneConfig({ scene }: { scene: Scene }) {
sync(data); sync(data);
message.success(`${meta.title}已更新`); message.success(`${meta.title}已更新`);
} catch (e) { } catch (e) {
message.error(`${errMsg(e)},原视频和配置未改变`); message.error(errMsg(e));
} finally { } finally {
setUploading(false); setUploading(false);
} }
@@ -124,7 +89,7 @@ function SceneConfig({ scene }: { scene: Scene }) {
const beforeUpload = (file: File) => { const beforeUpload = (file: File) => {
if (file.type !== 'video/mp4' && !/\.mp4$/i.test(file.name)) { if (file.type !== 'video/mp4' && !/\.mp4$/i.test(file.name)) {
message.error('仅支持 MP4 视频(H.264 或 HEVC/H.265 编码)'); message.error('仅支持 MP4 视频(H.264 编码)');
return Upload.LIST_IGNORE; return Upload.LIST_IGNORE;
} }
if (file.size > MAX_BYTES) { if (file.size > MAX_BYTES) {
@@ -159,8 +124,8 @@ function SceneConfig({ scene }: { scene: Scene }) {
extra={cfg?.updated_at ? <Text type="secondary"> {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: '#777', marginTop: 0 }}> <p style={{ color: '#777', marginTop: 0 }}>
Android {meta.action} Android {meta.action}广
1/10 1/10 退
</p> </p>
{loading || !cfg ? ( {loading || !cfg ? (
<Spin style={{ display: 'block', margin: '24px 0' }} /> <Spin style={{ display: 'block', margin: '24px 0' }} />
@@ -181,80 +146,21 @@ function SceneConfig({ scene }: { scene: Scene }) {
)} )}
</div> </div>
<Space direction="vertical" size="middle" style={{ minWidth: 390 }}> <Space direction="vertical" size="middle" style={{ minWidth: 390 }}>
{cfg.analysis_status === 'invalid' || cfg.analysis_error ? (
<Alert
type="error"
showIcon
message="视频分析异常,当前场景不可启用"
description={cfg.analysis_error || '请重新上传符合要求的视频'}
/>
) : null}
<Space> <Space>
<span></span> <span></span>
<Switch <Switch checked={enabled} disabled={!canEdit} onChange={setEnabled} />
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> <Space>
<span></span> <span></span>
<InputNumber <InputNumber min={0} max={50} precision={0} value={maxPlays} disabled={!canEdit} onChange={(v) => setMaxPlays(v ?? 0)} />
min={MIN_PLAYS} <Text type="secondary"> N 3</Text>
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>
<Space> <Space>
<span></span> <span></span>
<InputNumber <InputNumber min={0} max={10000} precision={0} value={rewardCoin} disabled={!canEdit} onChange={(v) => setRewardCoin(v ?? 0)} />
min={MIN_REWARD_COIN} <Text type="secondary"> 100</Text>
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> </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}>
@@ -262,25 +168,14 @@ function SceneConfig({ scene }: { scene: Scene }) {
</Button> </Button>
</Upload> </Upload>
{cfg.video_url && ( {cfg.video_url && (
<Popconfirm <Button icon={<DeleteOutlined />} danger loading={uploading} disabled={!canEdit} onClick={removeVideo}>
title={`确认移除${meta.title}`}
description="移除后该场景的新播放将无法使用引导视频,已经开始的播放不受影响。" </Button>
okText="确认移除"
cancelText="取消"
okButtonProps={{ danger: true }}
onConfirm={removeVideo}
disabled={!canEdit}
>
<Button icon={<DeleteOutlined />} danger loading={uploading} disabled={!canEdit}>
</Button>
</Popconfirm>
)} )}
<Text type="secondary">MP4H.264 HEVC/H.265 AAC30180 100MB</Text> <Text type="secondary">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>
<Text type="secondary"> {cfg.total_plays} {cfg.granted_plays} </Text>
</Button>
</Space> </Space>
</Space> </Space>
)} )}
+7 -13
View File
@@ -414,23 +414,17 @@ export interface FeedbackQrConfig {
updated_at: string | null; updated_at: string | null;
} }
/** 领券/比价等候浮层的引导视频配置。视频分析结果均由服务端 ffprobe 生成。 */ /** 领券等候浮层的「新手引导视频配置(前 3 次用它替代广告,每次固定 120 金币)。
* 后台只开放 enabled + 换片;下面几个字段接口仍返回,但页面不展示、也不回传。 */
export interface GuideVideoConfig { export interface GuideVideoConfig {
scene: 'coupon' | 'comparison'; scene: 'coupon' | 'comparison';
enabled: boolean; enabled: boolean;
video_url: string | null; video_url: string | null; // /media/guide_video/xxx.mp4;null = 未配片(浮层照旧只放广告)
max_plays: number; max_plays: number; // 每个账号前 N 次浮层放引导视频(服务端默认 3,后台不开放调整)
reward_coin: number; reward_coin: number; // 每次固定金币(服务端默认 120,播完 / 中途关闭都发)
updated_at: string | null; updated_at: string | null;
duration_ms: number | null; total_plays: number; // 只读统计:全站已播次数(后台不再展示)
circle_duration_ms: number | null; granted_plays: number; // 只读统计:其中已发币次数(后台不再展示)
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(8772) + 运营后台 API(8773) + 运营后台前端(3002)。 # 一键启动傻瓜比价本地联调:用户侧 API(8770) + 运营后台 API(8771) + 运营后台前端(3001)。
# 跨平台: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" 8772 "0.0.0.0" start_uvicorn "user-api" "app.main:app" 8770 "0.0.0.0"
start_uvicorn "admin-api" "app.admin.main:admin_app" 8773 "127.0.0.1" start_uvicorn "admin-api" "app.admin.main:admin_app" 8771 "127.0.0.1"
if port_in_use 3002; then if port_in_use 3001; then
echo "↺ admin-web 已在 :3002(跳过)" echo "↺ admin-web 已在 :3001(跳过)"
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 起在 :3002 (日志 $LOG_DIR/admin-web.log)" echo "✅ admin-web 起在 :3001 (日志 $LOG_DIR/admin-web.log)"
fi fi
echo "" echo ""
echo "⏳ 前端首次编译要几秒,然后开 👉 http://localhost:3002 (admin / admin12345)" echo "⏳ 前端首次编译要几秒,然后开 👉 http://localhost:3001 (admin / admin12345)"
echo " 用户侧 API: http://127.0.0.1:8772 | 后台 API: http://127.0.0.1:8773/admin/docs" echo " 用户侧 API: http://127.0.0.1:8770 | 后台 API: http://127.0.0.1:8771/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(8772) + 后台 API(8773) + 前端(3002)。 # 停止 start.sh 起的三个服务:用户侧 API(8770) + 后台 API(8771) + 前端(3001)。
# 双保险:先按 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 8772 8773 3002; do for port in 8770 8771 3001; do
kill_port "$port" kill_port "$port"
done done
echo "✅ 已停止(用户侧 8772 / 后台 8773 / 前端 3002)。" echo "✅ 已停止(用户侧 8770 / 后台 8771 / 前端 3001)。"