Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 79417d4cd1 | |||
| b776475a21 | |||
| fdda834a71 | |||
| b7fa15ec9c | |||
| 5bec909dbd | |||
| 5d2841fc85 | |||
| ca7c3f27f0 |
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,176 @@
|
||||
# admin 比价记录「技术成功/失败」口径与缺失提示设计
|
||||
|
||||
- **日期**:2026-08-04
|
||||
- **范围**:后端 `shaguabijia-app-server`(admin 层,**方案 A**:无 schema 变更、无迁移、不碰 #209 落库与 C 端)+ 前端 `shaguabijia-admin-web`
|
||||
- **涉及文件**:
|
||||
- 后端:`app/admin/repositories/comparison_outcome.py`(**新建**:共享常量 + Python 派生 + SQL 判定)、`app/admin/repositories/queries.py`(列表派生 + 概览口径)、`app/admin/schemas/comparison.py`(新增两字段)、`app/admin/repositories/stats.py`(大盘成功率分子口径)
|
||||
- 前端:`src/app/(main)/comparison-records/page.tsx`、`src/lib/types.ts`
|
||||
- 文档:`shaguabijia-app-server/docs/guides/比价结果卡片-状态口径与交互参考.md`(补 admin 口径说明)
|
||||
|
||||
## 目标
|
||||
|
||||
比价记录页(管理员排查工具)把「流程正常跑完、只是外部原因导致结果缺失」的记录——未找到店 / 未找到菜 / 门店打烊 / 单点不配送 / 平台·场景不支持 / 未满起送——从「失败」改判为 **🟢 成功 ⚠**(hover 看具体缺失原因)。让「失败」红标签**只剩真正的技术故障**,管理员一眼定位系统问题。改动范围:**admin 后台内部统一**(比价记录页状态列 + 概览成功率 + 数据大盘),不动 C 端。
|
||||
|
||||
## 背景与现状冲突
|
||||
|
||||
- **#209** 把 `store_closed / store_not_found / items_not_found / no_delivery / unsupported` 归一化成记录级 `failed` 落库,`below_minimum` 归 `success`;成功率按此算。
|
||||
- 前端 `STATUS_LABEL` 把这些细分值 + `failed` 全显示「失败」([page.tsx:35](../../src/app/(main)/comparison-records/page.tsx))。
|
||||
- 问题:这些是「跑完流程、外部结果缺失」,不是系统故障。全归「失败」粒度太粗,管理员无法区分「系统的锅」vs「目标平台本来就没有这家店 / 这些菜」。
|
||||
- **数据来源已坐实**:原始业务结局保存在 `raw_payload["record_status"]`(优先)或 `raw_payload["status"]`(兜底),**每条记录都有**(harvest 与 POST 两条写路径都落,见 `repositories/comparison.py:810` 注释)。admin 列表用裸 `select(ComparisonRecord)`、**本就全量加载 `raw_payload`**(C 端 `list_records` 才 `defer`),故列表派生**零额外查询**。概览/大盘用 `raw_payload["record_status"].as_string()` 在 SQL 里分类(跨方言写法,#209 迁移已验证可用)。
|
||||
|
||||
## admin 口径(核心)
|
||||
|
||||
**原始结局** `original = raw_payload["record_status"] or raw_payload["status"]`。
|
||||
|
||||
| original | admin_status | outcome_hint(hover) |
|
||||
|---|---|---|
|
||||
| success | success | (无) |
|
||||
| below_minimum | success | 未满起送 |
|
||||
| store_closed | success | 门店打烊 |
|
||||
| store_not_found | success | 未找到店 |
|
||||
| items_not_found | success | 未找到菜 |
|
||||
| no_delivery | success | 单点不配送 |
|
||||
| unsupported | success | 平台·场景不支持 |
|
||||
| failed / 其他未知 | failed | (无,这才是要排查的技术故障) |
|
||||
| (cancelled 记录,status 列) | cancelled | (无) |
|
||||
| (running 记录,status 列) | running | (无) |
|
||||
|
||||
**派生规则**:
|
||||
- 记录 `status == "cancelled"` → `admin_status=cancelled`;`status == "running"` → `admin_status=running`(生命周期状态直接取 `status`,不看 original)。
|
||||
- 否则看 original:∈ **admin 成功集** `S` → `admin_status=success`,`outcome_hint=_OUTCOME_HINTS.get(original)`(`success` 本身 → `None`)。
|
||||
- original 为 `failed` 或未知非 `S` → `admin_status=failed`,`outcome_hint=None`。
|
||||
- **兜底**:`raw_payload` 缺 original(极老记录)→ 用 `status` 列(`success→success` / `failed→failed`),`outcome_hint=None`。
|
||||
|
||||
其中 `S = {success, below_minimum, store_closed, store_not_found, items_not_found, no_delivery, unsupported}`。
|
||||
|
||||
## 数据契约(新增两字段)
|
||||
|
||||
`AdminComparisonListItem`(`AdminComparisonDetail` 继承)新增:
|
||||
|
||||
```python
|
||||
admin_status: str # success / failed / cancelled / running(admin 口径)
|
||||
outcome_hint: str | None = None # 缺失提示文案;None = 无缺失
|
||||
```
|
||||
|
||||
原 `status` 字段**保留原样下发**(排查时可看后端落库原值)。前端只认 `admin_status` + `outcome_hint`,不自己算口径。
|
||||
|
||||
## 后端实现(方案 A)
|
||||
|
||||
### 1. 新模块 `app/admin/repositories/comparison_outcome.py`(供 `queries.py` 与 `stats.py` 共用,避免循环 import)
|
||||
|
||||
```python
|
||||
from sqlalchemy import func
|
||||
from app.models.comparison import ComparisonRecord
|
||||
|
||||
ADMIN_SUCCESS_OUTCOMES = frozenset({
|
||||
"success", "below_minimum", "store_closed",
|
||||
"store_not_found", "items_not_found", "no_delivery", "unsupported",
|
||||
})
|
||||
OUTCOME_HINTS = {
|
||||
"below_minimum": "未满起送", "store_closed": "门店打烊",
|
||||
"store_not_found": "未找到店", "items_not_found": "未找到菜",
|
||||
"no_delivery": "单点不配送", "unsupported": "平台·场景不支持",
|
||||
}
|
||||
|
||||
def derive_admin_outcome(raw_payload: dict | None, status: str) -> tuple[str, str | None]:
|
||||
"""Python 层派生(列表用;raw_payload 已随 ORM 加载,零额外查询)。"""
|
||||
if status in ("cancelled", "running"):
|
||||
return status, None
|
||||
raw = raw_payload or {}
|
||||
original = raw.get("record_status") or raw.get("status")
|
||||
if original is None: # 极老记录兜底
|
||||
return ("success" if status == "success" else "failed"), None
|
||||
if original in ADMIN_SUCCESS_OUTCOMES:
|
||||
return "success", OUTCOME_HINTS.get(original)
|
||||
return "failed", None
|
||||
|
||||
def _original_expr():
|
||||
return func.coalesce(
|
||||
ComparisonRecord.raw_payload["record_status"].as_string(),
|
||||
ComparisonRecord.raw_payload["status"].as_string(),
|
||||
)
|
||||
|
||||
def admin_success_sql():
|
||||
"""SQL 层 admin 成功判定(概览/大盘的 case/where 共用)。"""
|
||||
original = _original_expr()
|
||||
return original.in_(tuple(ADMIN_SUCCESS_OUTCOMES)) | (
|
||||
original.is_(None) & (ComparisonRecord.status == "success")
|
||||
)
|
||||
```
|
||||
|
||||
### 2. 列表 `list_comparison_records`
|
||||
|
||||
在现有瞬态挂载段(`_attach_*` / `ad_revenue_yuan` 之后)对每条 `record`:
|
||||
|
||||
```python
|
||||
record.admin_status, record.outcome_hint = _derive_admin_outcome(record.raw_payload, record.status)
|
||||
```
|
||||
|
||||
`raw_payload` 列表已加载,无 N+1。schema 加上述两字段(`from_attributes` 读出)。
|
||||
|
||||
### 3. 概览 `comparison_records_summary`
|
||||
|
||||
把 `success` / `completed` 的 `case` 改用 original 口径:
|
||||
|
||||
```python
|
||||
_original_expr = func.coalesce(
|
||||
ComparisonRecord.raw_payload["record_status"].as_string(),
|
||||
ComparisonRecord.raw_payload["status"].as_string(),
|
||||
)
|
||||
# admin 成功 = original ∈ S OR (original IS NULL AND status == 'success')
|
||||
# completed = admin 成功 + 纯 failed(展示字段;admin 口径)
|
||||
# success_rate = admin 成功 / (started - cancelled) # 分母不变,见 queries.py:532
|
||||
```
|
||||
|
||||
**耗时分位**(avg / p50 / p95,`_comparison_duration_aggregate*`):统计集从「`status == "success"`」改为「admin 成功集」——用户已确认**统一口径纳入**这 6 类。改动点:`_comparison_status_condition` 系的耗时过滤条件改用 `_original_expr ∈ S`(或复用一个 `_admin_success_condition()` 表达式,列表/概览/大盘共用)。
|
||||
|
||||
### 4. 大盘 `stats.py` `dashboard_overview`
|
||||
|
||||
`period_comparison_stats` 的 success 分子([stats.py:278-281](../../../shaguabijia-app-server/app/admin/repositories/stats.py) 的 `case(status=='success')`)现在**不含 below_minimum**(#209 只改了概览、没同步大盘)。改用 `admin_success_sql()`(`original ∈ S`)口径,与概览一致。
|
||||
|
||||
**范围界定**:两页成功率**分母都是 `total - cancelled`**(概览 [queries.py:532](../../src/../../../shaguabijia-app-server/app/admin/repositories/queries.py)、大盘 [stats.py:290](../../../shaguabijia-app-server/app/admin/repositories/stats.py)),口径一致、本次不动。真正的既有差异在**分子**:概览 success 含 `below_minimum`、大盘不含。本次把两处分子都统一为 `original ∈ S`,改完两页口径**完全一致**。副作用:大盘成功率因补上 `below_minimum` + 5 类而上升,概览因补上 5 类上升——均属口径调整、非数据异常。
|
||||
|
||||
## 前端实现
|
||||
|
||||
### 1. 状态列([page.tsx:416](../../src/app/(main)/comparison-records/page.tsx))
|
||||
|
||||
`render` 改用 `admin_status` 出标签(`STATUS_LABEL/COLOR`:success→绿「成功」/ failed→红「失败」/ cancelled→「中途退出」/ running→「进行中」);`outcome_hint` 非空 → 标签后跟 `<Tooltip title={outcome_hint}>` 包一个 ⚠(antd `WarningOutlined`)。
|
||||
|
||||
### 2. 详情页状态([page.tsx:627](../../src/app/(main)/comparison-records/page.tsx))
|
||||
|
||||
同步用 `admin_status` + `outcome_hint`。
|
||||
|
||||
### 3. `STATUS_LABEL` / `STATUS_COLOR`([page.tsx:35](../../src/app/(main)/comparison-records/page.tsx))
|
||||
|
||||
精简:移除把 `store_closed/store_not_found/items_not_found/no_delivery/unsupported` 直接映射「失败」的行(统一走 `admin_status`);保留 `success/failed/cancelled/running`。`below_minimum` 同理不再单列。
|
||||
|
||||
### 4. `types.ts`
|
||||
|
||||
`ComparisonRecordListItem` 加 `admin_status: string`、`outcome_hint: string | null`。
|
||||
|
||||
### 5. 概览成功率
|
||||
|
||||
前端只展示后端返回的数字,口径变化对前端透明;检查概览区有无「成功率」口径说明文案需同步。
|
||||
|
||||
## 不改 / 一致性
|
||||
|
||||
- `status` 列语义、#209 落库、完成奖励幂等、C 端「我的比价」/ 首页轮播 / 省钱战绩口径:**全不动**。
|
||||
- admin 口径(跑完即成功)**刻意宽于** C 端业务口径;因大盘也一并改,**admin 后台内部自洽**。
|
||||
- 在状态口径文档补一段「admin 记录页口径」:说明 admin 成功率是「技术完成率」,与 C 端业务口径不同,避免以后有人拿两者对不上而误判为 bug。
|
||||
|
||||
## 边界
|
||||
|
||||
- `raw_payload` 缺 `record_status/status`(极老记录):`admin_status` 取 `status` 列,`outcome_hint=None`,不加 ⚠。
|
||||
- 多平台 `platform_results`:以记录级 `record_status` 为准(pricebot 已归纳),不逐平台判。
|
||||
- 迁移未覆盖、`status` 列仍是细分值的老记录:`original` 优先,仍正确归类(细分值本身 ∈ S)。
|
||||
|
||||
## 测试
|
||||
|
||||
- 后端新增 `_derive_admin_outcome` 单测:各 original + cancelled/running + raw_payload 缺失兜底,验 `(admin_status, outcome_hint)`。
|
||||
- `tests/test_comparison_admin_summary.py`:造含 6 类 + success + failed + cancelled 的记录,验 `success` / `completed` / `success_rate` / 耗时分位按新口径。
|
||||
- `tests/test_admin_read.py`:列表返回 `admin_status` / `outcome_hint`(成功·有缺失、纯失败、纯成功各一条)。
|
||||
|
||||
## 影响面 / 风险
|
||||
|
||||
- 概览/大盘 SQL 读 JSONB(`raw_payload['record_status'].as_string()`):PG 上是 JSONB,跨方言 `.as_string()` #209 迁移已用;SQLite 测试走 JSON1。admin 低频、P0 量级,性能可忽略。
|
||||
- **admin 成功率数字会上升**(这 6 类从失败转成功):需知会运营这是**口径调整、非数据异常**。C 端 / 大盘之外的成功率不受影响。
|
||||
@@ -4,8 +4,9 @@ import { useEffect, useState } from 'react';
|
||||
import type { CSSProperties, ReactNode } from 'react';
|
||||
import {
|
||||
App, Button, Card, Col, Collapse, DatePicker, Descriptions, Divider, Drawer, Input, InputNumber,
|
||||
Row, Select, Space, Spin, Statistic, Table, Tag, Typography,
|
||||
Row, Select, Space, Spin, Statistic, Table, Tag, Tooltip, Typography,
|
||||
} from 'antd';
|
||||
import { ExclamationCircleOutlined } from '@ant-design/icons';
|
||||
import type { ColumnsType } from 'antd/es/table';
|
||||
import dayjs, { type Dayjs } from 'dayjs';
|
||||
import { api, errMsg } from '@/lib/api';
|
||||
@@ -19,18 +20,141 @@ import type {
|
||||
|
||||
const { RangePicker } = DatePicker;
|
||||
|
||||
const STATUS_COLOR: Record<string, string> = { success: 'green', failed: 'red', cancelled: 'default' };
|
||||
const STATUS_LABEL: Record<string, string> = { success: '成功', failed: '失败', cancelled: '中途退出' };
|
||||
|
||||
// 「卡在哪一步」: platform_results[*].status 翻成人话(找店/加菜/起送/读价)
|
||||
const STUCK_LABEL: Record<string, string> = {
|
||||
success: '成功',
|
||||
store_not_found: '没找到店',
|
||||
items_not_found: '菜没匹配上',
|
||||
below_minimum: '未达起送',
|
||||
unsupported: '平台不支持',
|
||||
failed: '失败',
|
||||
// admin_status 只有四个生命周期值;外部缺失由 outcome_hint(感叹号)承载。
|
||||
const STATUS_COLOR: Record<string, string> = {
|
||||
success: 'green',
|
||||
failed: 'red',
|
||||
cancelled: 'default',
|
||||
running: 'blue',
|
||||
};
|
||||
const STATUS_LABEL: Record<string, string> = {
|
||||
success: '成功',
|
||||
failed: '失败',
|
||||
cancelled: '中途退出',
|
||||
running: '进行中',
|
||||
};
|
||||
|
||||
type PlatformResultRow = Record<string, unknown> & {
|
||||
platform_id?: string;
|
||||
platform_name?: string;
|
||||
status?: string;
|
||||
reason?: string;
|
||||
};
|
||||
|
||||
function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
return value != null && typeof value === 'object' && !Array.isArray(value);
|
||||
}
|
||||
|
||||
function platformResultRows(
|
||||
platforms: Record<string, unknown>[] | null | undefined,
|
||||
rawPayload: Record<string, unknown> | null | undefined,
|
||||
): PlatformResultRow[] {
|
||||
if ((platforms?.length ?? 0) > 0) return platforms as PlatformResultRow[];
|
||||
|
||||
const rawPlatforms = rawPayload?.platforms;
|
||||
if (Array.isArray(rawPlatforms)) {
|
||||
const rows = rawPlatforms.filter(isRecord) as PlatformResultRow[];
|
||||
if (rows.length > 0) return rows;
|
||||
}
|
||||
|
||||
// 灰度期旧记录没有 platforms,才回退 platform_results。这里的 success/source 是旧枚举,
|
||||
// 展示时兼容折算为逐平台成功态 ok。
|
||||
const resultValue = rawPayload?.platform_results;
|
||||
if (Array.isArray(resultValue)) return resultValue.filter(isRecord) as PlatformResultRow[];
|
||||
if (isRecord(resultValue)) {
|
||||
return Object.entries(resultValue).flatMap(([platformId, result]) => (
|
||||
isRecord(result) ? [{ platform_id: platformId, ...result } as PlatformResultRow] : []
|
||||
));
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
function stringList(value: unknown): string[] {
|
||||
return Array.isArray(value) ? value.filter((item): item is string => typeof item === 'string') : [];
|
||||
}
|
||||
|
||||
function hasDishDiff(row: PlatformResultRow): boolean {
|
||||
if (typeof row.has_dish_diff === 'boolean') return row.has_dish_diff;
|
||||
const items = Array.isArray(row.items) ? row.items.filter(isRecord) : [];
|
||||
return items.some((item) => item.similar === true)
|
||||
|| stringList(row.approx_dish_names).length > 0
|
||||
|| stringList(row.skipped_dish_names).length > 0
|
||||
|| Number(row.skipped_dish_count || 0) > 0;
|
||||
}
|
||||
|
||||
type PlatformDisplay = {
|
||||
label: string;
|
||||
color: string;
|
||||
rawStatus: string;
|
||||
category: string;
|
||||
dishDiff: boolean;
|
||||
fallbackReason: string;
|
||||
};
|
||||
|
||||
function platformDisplay(row: PlatformResultRow): PlatformDisplay {
|
||||
const rawStatus = typeof row.status === 'string' && row.status ? row.status : 'unknown';
|
||||
const legacySource = rawStatus === 'source';
|
||||
const normalizedStatus = rawStatus === 'success' || legacySource ? 'ok' : rawStatus;
|
||||
const dishDiff = hasDishDiff(row);
|
||||
|
||||
if (normalizedStatus === 'ok') {
|
||||
const isSource = row.role === 'source' || row.is_user_original === true || legacySource;
|
||||
const isLowest = row.is_best === true && !dishDiff;
|
||||
return {
|
||||
label: '成功',
|
||||
color: 'green',
|
||||
rawStatus,
|
||||
category: isLowest ? '#1 全网最低赢家' : isSource ? '#2 原选择' : '#3 其他成功',
|
||||
dishDiff,
|
||||
fallbackReason: dishDiff ? '已比出价格,但存在菜品差异,仅供参考' : '已成功比出价格',
|
||||
};
|
||||
}
|
||||
|
||||
const known: Record<string, Omit<PlatformDisplay, 'rawStatus' | 'dishDiff'>> = {
|
||||
below_minimum: { label: '未满起送', color: 'gold', category: '#5 未满起送', fallbackReason: '购物车未达到起送门槛' },
|
||||
store_closed: { label: '门店打烊', color: 'orange', category: '#6 门店打烊', fallbackReason: '门店当前已打烊,无法比价' },
|
||||
items_not_found: { label: '商品未找到', color: 'orange', category: '#7 没有您点的商品', fallbackReason: '该店没有找到本次所选商品' },
|
||||
store_not_found: { label: '店铺未找到', color: 'orange', category: '#8 无对应商家', fallbackReason: '未找到可对应的商家' },
|
||||
failed: { label: '比价失败', color: 'red', category: '#9 失败兜底', fallbackReason: '本平台比价流程未完成' },
|
||||
unsupported: { label: '比价失败', color: 'red', category: '#9 失败兜底', fallbackReason: '当前版本暂不支持该平台' },
|
||||
no_delivery: { label: '单点不配送', color: 'orange', category: '表外 · 单点不配送', fallbackReason: '所选商品不支持单点配送' },
|
||||
not_installed: { label: '未安装', color: 'default', category: '#10 端侧本地 · 未安装', fallbackReason: '该状态仅由 App 端根据装机情况补齐' },
|
||||
not_compared_this_time: { label: '本次未比', color: 'default', category: '#11 端侧本地 · 未选择', fallbackReason: '该状态仅由 App 端根据本次勾选情况补齐' },
|
||||
};
|
||||
const mapped = known[normalizedStatus];
|
||||
if (mapped) return { ...mapped, rawStatus, dishDiff: false };
|
||||
return {
|
||||
label: '比价失败',
|
||||
color: 'red',
|
||||
rawStatus,
|
||||
category: '#9 未知状态兜底',
|
||||
dishDiff: false,
|
||||
fallbackReason: `端侧未识别状态 ${rawStatus},按比价失败兜底`,
|
||||
};
|
||||
}
|
||||
|
||||
function dishDiffSummary(row: PlatformResultRow): string | null {
|
||||
if (!hasDishDiff(row)) return null;
|
||||
const parts: string[] = [];
|
||||
const items = Array.isArray(row.items) ? row.items.filter(isRecord) : [];
|
||||
const similarPairs = items
|
||||
.filter((item) => item.similar === true && typeof item.name === 'string')
|
||||
.map((item) => (typeof item.orig === 'string' ? `${item.orig}→${item.name}` : String(item.name)));
|
||||
if (similarPairs.length) parts.push(`近似替换:${similarPairs.join('、')}`);
|
||||
const approx = stringList(row.approx_dish_names);
|
||||
if (approx.length) parts.push(`规格近似:${approx.join('、')}`);
|
||||
const skipped = stringList(row.skipped_dish_names);
|
||||
if (skipped.length) parts.push(`完全缺失:${skipped.join('、')}`);
|
||||
if (!skipped.length && Number(row.skipped_dish_count || 0) > 0) {
|
||||
parts.push(`缺少 ${Number(row.skipped_dish_count)} 个菜品`);
|
||||
}
|
||||
return parts.join(';') || '存在菜品差异';
|
||||
}
|
||||
|
||||
function complexSpecSummary(row: PlatformResultRow): string | null {
|
||||
const names = stringList(row.complex_spec_dish_names);
|
||||
return names.length > 0 ? `复杂规格需核对:${names.join('、')}` : null;
|
||||
}
|
||||
|
||||
const fmtMs = (ms: number | null) => (ms == null ? '-' : `${(ms / 1000).toFixed(1)}s`);
|
||||
const cents = (c: number | null) => (c == null ? '-' : yuan(c));
|
||||
@@ -273,12 +397,21 @@ export default function ComparisonRecordsPage() {
|
||||
width: 140,
|
||||
render: (_, r) => (
|
||||
<div style={{ color: '#1677ff' }}>
|
||||
<div>{r.phone || `#${r.user_id}`}</div>
|
||||
<div>{r.phone || (r.user_id != null ? `#${r.user_id}` : '匿名')}</div>
|
||||
{r.nickname && <div style={{ fontSize: 12 }}>{r.nickname}</div>}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{ title: '状态', dataIndex: 'status', width: 72, render: (s: string) => <Tag color={STATUS_COLOR[s]}>{STATUS_LABEL[s] || s}</Tag> },
|
||||
{ title: '状态', dataIndex: 'admin_status', width: 108, render: (_: string, r) => (
|
||||
<span>
|
||||
<Tag color={STATUS_COLOR[r.admin_status]}>{STATUS_LABEL[r.admin_status] || r.admin_status}</Tag>
|
||||
{r.outcome_hint && (
|
||||
<Tooltip title={r.outcome_hint}>
|
||||
<ExclamationCircleOutlined style={{ color: '#faad14', marginLeft: 2 }} />
|
||||
</Tooltip>
|
||||
)}
|
||||
</span>
|
||||
) },
|
||||
// 产品文档指定展示“原平台”;字段名仍沿用后端 source_platform_name。
|
||||
{ title: '原平台', dataIndex: 'source_platform_name', width: 90, render: (v) => v || '-' },
|
||||
{
|
||||
@@ -369,8 +502,7 @@ export default function ComparisonRecordsPage() {
|
||||
},
|
||||
];
|
||||
|
||||
const platformResults =
|
||||
(detail?.raw_payload?.platform_results as Record<string, unknown>[] | undefined) || [];
|
||||
const platformResults = platformResultRows(detail?.platforms, detail?.raw_payload);
|
||||
|
||||
return (
|
||||
<div>
|
||||
@@ -423,6 +555,7 @@ export default function ComparisonRecordsPage() {
|
||||
{ value: 'success', label: '成功' },
|
||||
{ value: 'failed', label: '失败' },
|
||||
{ value: 'cancelled', label: '中途退出' },
|
||||
{ value: 'running', label: '进行中' },
|
||||
]}
|
||||
/>
|
||||
<Button type="primary" onClick={search}>查询</Button>
|
||||
@@ -487,9 +620,12 @@ export default function ComparisonRecordsPage() {
|
||||
<Space direction="vertical" size="middle" style={{ width: '100%' }}>
|
||||
<Descriptions size="small" column={2} bordered>
|
||||
<Descriptions.Item label="用户">
|
||||
{detail.phone || `#${detail.user_id}`}{detail.nickname ? `(${detail.nickname})` : ''}
|
||||
{detail.phone || (detail.user_id != null ? `#${detail.user_id}` : '匿名')}{detail.nickname ? `(${detail.nickname})` : ''}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="状态">
|
||||
<Tag color={STATUS_COLOR[detail.admin_status]}>{STATUS_LABEL[detail.admin_status] || detail.admin_status}</Tag>
|
||||
{detail.outcome_hint && <Tooltip title={detail.outcome_hint}><ExclamationCircleOutlined style={{ color: '#faad14', marginLeft: 4 }} /></Tooltip>}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="状态"><Tag color={STATUS_COLOR[detail.status]}>{STATUS_LABEL[detail.status] || detail.status}</Tag></Descriptions.Item>
|
||||
<Descriptions.Item label="业务">{detail.business_type}</Descriptions.Item>
|
||||
<Descriptions.Item label="耗时">{fmtMs(detail.total_ms)}</Descriptions.Item>
|
||||
<Descriptions.Item label="步数">{detail.step_count ?? '-'}</Descriptions.Item>
|
||||
@@ -579,16 +715,67 @@ export default function ComparisonRecordsPage() {
|
||||
)}
|
||||
|
||||
{platformResults.length > 0 && (
|
||||
<Card size="small" title="逐平台结局(卡在哪一步)">
|
||||
<Card size="small" title="逐平台结果卡片判定">
|
||||
<Typography.Paragraph type="secondary" style={{ marginBottom: 12 }}>
|
||||
优先按 platforms[].status=ok 及 is_best、role、has_dish_diff 判定;#10 未安装和 #11 本次未比
|
||||
由 App 端本地补齐,正常情况下后台没有对应行。
|
||||
</Typography.Paragraph>
|
||||
<Table
|
||||
size="small"
|
||||
rowKey={(_, i) => String(i)}
|
||||
pagination={false}
|
||||
dataSource={platformResults}
|
||||
scroll={{ x: 1050 }}
|
||||
columns={[
|
||||
{ title: '平台', dataIndex: 'platform_name', render: (v, r: Record<string, unknown>) => (v as string) || (r.platform_id as string) || '-' },
|
||||
{ title: '结局', dataIndex: 'status', render: (s: string) => <Tag color={s === 'success' ? 'green' : 'orange'}>{STUCK_LABEL[s] || s || '-'}</Tag> },
|
||||
{ title: '说明', dataIndex: 'reason', render: (v) => (v as string) || '-' },
|
||||
{
|
||||
title: '平台', dataIndex: 'platform_name', width: 150,
|
||||
render: (v, r: PlatformResultRow) => (v as string) || r.platform_id || '-',
|
||||
},
|
||||
{
|
||||
title: '逐平台状态', dataIndex: 'status', width: 135,
|
||||
render: (_, r: PlatformResultRow) => {
|
||||
const display = platformDisplay(r);
|
||||
return (
|
||||
<Space direction="vertical" size={0}>
|
||||
<Tag color={display.color}>{display.label}</Tag>
|
||||
<Typography.Text type="secondary" code>{display.rawStatus}</Typography.Text>
|
||||
</Space>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '卡片分类', key: 'category', width: 210,
|
||||
render: (_, r: PlatformResultRow) => {
|
||||
const display = platformDisplay(r);
|
||||
const hasComplexSpec = complexSpecSummary(r) != null;
|
||||
return (
|
||||
<Space size={[4, 4]} wrap>
|
||||
<Tag color={display.color}>{display.category}</Tag>
|
||||
{display.dishDiff ? <Tag color="gold">#4 菜品差异</Tag> : null}
|
||||
{hasComplexSpec ? <Tag color="blue">复杂规格待核对</Tag> : null}
|
||||
</Space>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '价格', dataIndex: 'price', width: 90,
|
||||
render: (v) => (typeof v === 'number' ? `¥${v.toFixed(2)}` : '-'),
|
||||
},
|
||||
{
|
||||
title: '说明 / 判定字段', key: 'reason',
|
||||
render: (_, r: PlatformResultRow) => {
|
||||
const display = platformDisplay(r);
|
||||
const diff = dishDiffSummary(r);
|
||||
const complexSpec = complexSpecSummary(r);
|
||||
return (
|
||||
<Space direction="vertical" size={0}>
|
||||
<span>{typeof r.reason === 'string' && r.reason ? r.reason : display.fallbackReason}</span>
|
||||
{diff ? <Typography.Text type="warning">{diff}</Typography.Text> : null}
|
||||
{complexSpec ? <Typography.Text type="secondary">{complexSpec}</Typography.Text> : null}
|
||||
</Space>
|
||||
);
|
||||
},
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</Card>
|
||||
|
||||
@@ -1,7 +1,18 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Button, Card, InputNumber, 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';
|
||||
@@ -38,7 +49,9 @@ function SceneConfig({ scene }: { scene: Scene }) {
|
||||
const load = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const { data } = await api.get<GuideCfg>('/admin/api/guide-video', { params: { scene } });
|
||||
const { data } = await api.get<GuideCfg>('/admin/api/guide-video', {
|
||||
params: { scene },
|
||||
});
|
||||
sync(data);
|
||||
} catch (e) {
|
||||
message.error(errMsg(e));
|
||||
@@ -56,7 +69,11 @@ function SceneConfig({ scene }: { scene: Scene }) {
|
||||
try {
|
||||
const { data } = await api.patch<GuideCfg>(
|
||||
'/admin/api/guide-video',
|
||||
{ enabled, max_plays: maxPlays, reward_coin: rewardCoin },
|
||||
{
|
||||
enabled,
|
||||
reward_coin: rewardCoin,
|
||||
...(scene === 'comparison' ? { max_plays: maxPlays } : {}),
|
||||
},
|
||||
{ params: { scene } },
|
||||
);
|
||||
sync(data);
|
||||
@@ -121,11 +138,20 @@ function SceneConfig({ scene }: { scene: Scene }) {
|
||||
size="small"
|
||||
title={meta.title}
|
||||
style={{ marginBottom: 16 }}
|
||||
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 }}>
|
||||
Android 用户点击「{meta.action}」后,前若干次在等候浮层广告位播放本视频并奖励金币。
|
||||
次数按账号、按功能分别计算;开播即计次,播完或中途关闭均发放当次配置的金币。
|
||||
Android 用户点击「{meta.action}」后,前 {cfg?.max_plays ?? 3}{' '}
|
||||
次在等候浮层广告位播放本视频并奖励金币。次数按账号、按功能分别计算;
|
||||
开播即计次,播完或中途关闭均发放当次配置的金币。
|
||||
{scene === 'coupon' &&
|
||||
'领券引导视频的播放次数上限请在「监控审计 → 限制策略」中调整。'}
|
||||
</p>
|
||||
{loading || !cfg ? (
|
||||
<Spin style={{ display: 'block', margin: '24px 0' }} />
|
||||
@@ -137,10 +163,24 @@ function SceneConfig({ scene }: { scene: Scene }) {
|
||||
<video
|
||||
src={mediaUrl(cfg.video_url)}
|
||||
controls
|
||||
style={{ width: 240, maxHeight: 420, borderRadius: 12, background: '#000' }}
|
||||
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
|
||||
style={{
|
||||
height: 280,
|
||||
border: '1px dashed #d9d9d9',
|
||||
borderRadius: 12,
|
||||
display: 'grid',
|
||||
placeItems: 'center',
|
||||
color: '#aaa',
|
||||
}}
|
||||
>
|
||||
未上传视频
|
||||
</div>
|
||||
)}
|
||||
@@ -148,22 +188,51 @@ function SceneConfig({ scene }: { scene: Scene }) {
|
||||
<Space direction="vertical" size="middle" style={{ minWidth: 390 }}>
|
||||
<Space>
|
||||
<span>启用:</span>
|
||||
<Switch checked={enabled} disabled={!canEdit} onChange={setEnabled} />
|
||||
<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>
|
||||
{scene === 'comparison' && (
|
||||
<Space>
|
||||
<span>播放次数:</span>
|
||||
<InputNumber
|
||||
min={0}
|
||||
max={50}
|
||||
precision={0}
|
||||
value={maxPlays}
|
||||
disabled={!canEdit}
|
||||
onChange={(value) => setMaxPlays(value ?? 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)} />
|
||||
<InputNumber
|
||||
min={0}
|
||||
max={10000}
|
||||
precision={0}
|
||||
value={rewardCoin}
|
||||
disabled={!canEdit}
|
||||
onChange={(value) => setRewardCoin(value ?? 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}>
|
||||
<Upload
|
||||
accept="video/mp4,.mp4"
|
||||
showUploadList={false}
|
||||
beforeUpload={beforeUpload}
|
||||
disabled={!canEdit}
|
||||
>
|
||||
<Button
|
||||
icon={<UploadOutlined />}
|
||||
loading={uploading}
|
||||
disabled={!canEdit}
|
||||
>
|
||||
{cfg.video_url ? '更换视频' : '上传视频'}
|
||||
</Button>
|
||||
</Upload>
|
||||
@@ -174,8 +243,17 @@ function SceneConfig({ scene }: { scene: Scene }) {
|
||||
)}
|
||||
<Text type="secondary">MP4(H.264),≤100MB</Text>
|
||||
</Space>
|
||||
<Button type="primary" loading={saving} disabled={!canEdit} onClick={save}>保存配置</Button>
|
||||
<Text type="secondary">累计播放 {cfg.total_plays} 次,已发币 {cfg.granted_plays} 次</Text>
|
||||
<Button
|
||||
type="primary"
|
||||
loading={saving}
|
||||
disabled={!canEdit}
|
||||
onClick={save}
|
||||
>
|
||||
保存配置
|
||||
</Button>
|
||||
<Text type="secondary">
|
||||
累计播放 {cfg.total_plays} 次,已发币 {cfg.granted_plays} 次
|
||||
</Text>
|
||||
</Space>
|
||||
</Space>
|
||||
)}
|
||||
|
||||
@@ -76,6 +76,7 @@ interface CouponDataRow {
|
||||
claimed_count: number | null;
|
||||
point_success_count: number | null;
|
||||
point_total_count: number | null;
|
||||
point_event_count?: number;
|
||||
// 兼容旧后端的内嵌明细;新后端不再返回,改为点击后按 trace 加载。
|
||||
point_details?: CouponPointDetail[];
|
||||
trace_url: string | null;
|
||||
@@ -145,15 +146,22 @@ function PointScorePopover({ row }: { row: CouponDataRow }) {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [loadError, setLoadError] = useState<string | null>(null);
|
||||
|
||||
if (row.point_success_count == null || row.point_total_count == null || row.point_total_count <= 0) {
|
||||
const abandonedWithoutScoredResult =
|
||||
row.status === 'abandoned' && row.point_success_count === 0 && row.point_total_count === 0;
|
||||
if (
|
||||
row.point_success_count == null ||
|
||||
row.point_total_count == null ||
|
||||
(row.point_total_count <= 0 && !abandonedWithoutScoredResult)
|
||||
) {
|
||||
return <Typography.Text type="secondary">-</Typography.Text>;
|
||||
}
|
||||
const score = `${row.point_success_count}/${row.point_total_count}`;
|
||||
const scoreWithRate = `${score}(${(
|
||||
row.point_success_count / row.point_total_count * 100
|
||||
).toFixed(1)}%)`;
|
||||
const hasPointDetails = (row.point_event_count ?? 0) > 0;
|
||||
const scoreWithRate = abandonedWithoutScoredResult
|
||||
? `0.0%(${hasPointDetails ? '无有效结果' : '退出前无结果'})`
|
||||
: `${score}(${(row.point_success_count / row.point_total_count * 100).toFixed(1)}%)`;
|
||||
const scoreColor =
|
||||
row.point_success_count === row.point_total_count
|
||||
row.point_total_count > 0 && row.point_success_count === row.point_total_count
|
||||
? STATUS_TAG.completed.color
|
||||
: STATUS_TAG.abandoned.color;
|
||||
const loadDetails = async () => {
|
||||
@@ -174,6 +182,14 @@ function PointScorePopover({ row }: { row: CouponDataRow }) {
|
||||
}
|
||||
};
|
||||
|
||||
if (abandonedWithoutScoredResult && !hasPointDetails) {
|
||||
return (
|
||||
<Tooltip title="本次在第一张券产生终态前中途退出,没有可计入成功/尝试的单券结果;按运营展示口径记为 0.0%,不虚构失败券数量。">
|
||||
<Typography.Text type="warning">{scoreWithRate}</Typography.Text>
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Popover
|
||||
trigger="click"
|
||||
|
||||
@@ -550,6 +550,7 @@ export default function DashboardPage() {
|
||||
const couponPeriod = periodData?.coupon ?? null;
|
||||
const previousCouponPeriod = previousPeriodData?.coupon ?? null;
|
||||
const couponStartedDelta = percentDelta(couponPeriod?.started, previousCouponPeriod?.started);
|
||||
const couponSuccessDenominator = couponPeriod?.success_denominator ?? null;
|
||||
const couponSuccessRateValue =
|
||||
couponPeriod?.success_rate == null ? '--' : (couponPeriod.success_rate * 100).toFixed(1);
|
||||
const couponSuccessRateDelta = pointDelta(couponPeriod?.success_rate, previousCouponPeriod?.success_rate);
|
||||
@@ -875,9 +876,11 @@ export default function DashboardPage() {
|
||||
unit="%"
|
||||
delta={couponSuccessRateDelta.value}
|
||||
deltaTone={couponSuccessRateDelta.tone}
|
||||
hint={`全部点位领成功的次数 / 领券发起数;本期 ${fmtInt(couponPeriod?.all_success)} / ${fmtInt(
|
||||
couponPeriod?.started,
|
||||
)} 次。点位成功口径含「今日已领过」。`}
|
||||
hint={`全部点位领成功的次数 ÷(领券发起数-中途退出数);本期 ${fmtInt(
|
||||
couponPeriod?.all_success,
|
||||
)} ÷(${fmtInt(couponPeriod?.started)}-${fmtInt(couponPeriod?.abandoned)}),分母为 ${fmtInt(
|
||||
couponSuccessDenominator,
|
||||
)}。中途退出不计入分母,点位成功口径含「今日已领过」。`}
|
||||
/>
|
||||
<StatCard
|
||||
title="点位成功率"
|
||||
|
||||
@@ -4,6 +4,7 @@ import { useEffect, useRef, useState } from 'react';
|
||||
import { usePathname, useRouter } from 'next/navigation';
|
||||
import {
|
||||
BarChartOutlined,
|
||||
ControlOutlined,
|
||||
DashboardOutlined,
|
||||
DatabaseOutlined,
|
||||
FileSearchOutlined,
|
||||
@@ -105,6 +106,7 @@ const NAV_GROUPS: NavGroup[] = [
|
||||
{ key: '/analytics-health', icon: <LineChartOutlined />, label: '埋点成功率' },
|
||||
{ key: '/event-logs', icon: <DatabaseOutlined />, label: '埋点日志' },
|
||||
{ key: '/audit-logs', icon: <FileSearchOutlined />, label: '审计日志' },
|
||||
{ key: '/limit-whitelist', icon: <ControlOutlined />, label: '限制策略' },
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -19,10 +19,12 @@ import {
|
||||
CopyOutlined,
|
||||
DownOutlined,
|
||||
EditOutlined,
|
||||
PlusCircleOutlined,
|
||||
ReloadOutlined,
|
||||
RightOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import dayjs from 'dayjs';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { api, errMsg } from '@/lib/api';
|
||||
import { formatUtcTime, utcDayjs } from '@/lib/format';
|
||||
import type {
|
||||
@@ -69,8 +71,8 @@ type IncidentStatus = 'open' | 'blocked';
|
||||
const RULE_LIMITS: Record<RiskKind, { min: number; max: number; help: string }> = {
|
||||
sms: {
|
||||
min: 1,
|
||||
max: 5,
|
||||
help: '统计成功下发;最高5次,与现有每设备每小时发送上限一致。',
|
||||
max: 100000,
|
||||
help: '统计成功下发;告警阈值与短信硬限制分别配置。',
|
||||
},
|
||||
oneclick: {
|
||||
min: 1,
|
||||
@@ -79,8 +81,8 @@ const RULE_LIMITS: Record<RiskKind, { min: number; max: number; help: string }>
|
||||
},
|
||||
compare: {
|
||||
min: 1,
|
||||
max: 100,
|
||||
help: '同一账户按北京时间自然日累计;最高100次,与比价每日上限一致。',
|
||||
max: 100000,
|
||||
help: '同一账户按北京时间自然日累计;告警阈值与比价硬限制分别配置。',
|
||||
},
|
||||
};
|
||||
const utcTime = (value: string | null, withDate = true) =>
|
||||
@@ -271,6 +273,7 @@ function DetailTable({
|
||||
}
|
||||
|
||||
export default function RiskMonitorPage() {
|
||||
const router = useRouter();
|
||||
const { message, modal } = App.useApp();
|
||||
const [summary, setSummary] = useState<RiskMonitorSummary | null>(null);
|
||||
const [lists, setLists] = useState<Partial<Record<RiskKind, RiskIncidentPage>>>({});
|
||||
@@ -597,6 +600,40 @@ export default function RiskMonitorPage() {
|
||||
[lists, loadAll, message, modal],
|
||||
);
|
||||
|
||||
const addToWhitelist = useCallback(
|
||||
(row: RiskIncidentItem) => {
|
||||
const isCompare = row.kind === 'compare';
|
||||
const subjectValue = isCompare ? row.phone : row.subject_id;
|
||||
if (!isCompare && subjectValue?.startsWith('legacy-ip:')) {
|
||||
void message.error(
|
||||
'旧客户端未上报真实设备 ID,无法加入设备白名单,请升级客户端后重试',
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (!subjectValue) {
|
||||
void message.error(
|
||||
isCompare
|
||||
? '该风险记录没有关联手机号,暂时无法加入白名单'
|
||||
: '该风险记录没有设备 ID,暂时无法加入白名单',
|
||||
);
|
||||
return;
|
||||
}
|
||||
const ruleCode: Record<RiskKind, string> = {
|
||||
sms: 'risk.sms.hourly',
|
||||
oneclick: 'risk.oneclick.daily',
|
||||
compare: 'risk.compare.daily',
|
||||
};
|
||||
const params = new URLSearchParams({
|
||||
create: '1',
|
||||
subject_type: isCompare ? 'phone' : 'device',
|
||||
subject_value: subjectValue,
|
||||
rule_code: ruleCode[row.kind],
|
||||
});
|
||||
router.push(`/limit-whitelist?${params.toString()}`);
|
||||
},
|
||||
[message, router],
|
||||
);
|
||||
|
||||
const columns = useCallback(
|
||||
(kind: RiskKind): ColumnsType<RiskIncidentItem> => {
|
||||
const actionColumn = {
|
||||
@@ -604,9 +641,18 @@ export default function RiskMonitorPage() {
|
||||
key: 'actions',
|
||||
align: 'right' as const,
|
||||
fixed: 'right' as const,
|
||||
width: 180,
|
||||
width: 280,
|
||||
render: (_: unknown, row: RiskIncidentItem) => {
|
||||
const open = expanded.has(row.incident_id);
|
||||
const whitelistUnavailableReason =
|
||||
row.kind === 'compare'
|
||||
? row.phone
|
||||
? undefined
|
||||
: '该风险记录没有关联手机号,暂时无法加入白名单'
|
||||
: row.subject_id.startsWith('legacy-ip:')
|
||||
? '旧客户端未上报真实设备 ID,无法加入设备白名单'
|
||||
: undefined;
|
||||
const canAddToWhitelist = !whitelistUnavailableReason;
|
||||
return (
|
||||
<span className={styles.actionGroup}>
|
||||
<Button
|
||||
@@ -618,6 +664,20 @@ export default function RiskMonitorPage() {
|
||||
>
|
||||
{open ? '收起' : '展开'}
|
||||
</Button>
|
||||
<Tooltip
|
||||
title={whitelistUnavailableReason}
|
||||
>
|
||||
<span>
|
||||
<Button
|
||||
size="small"
|
||||
icon={<PlusCircleOutlined />}
|
||||
disabled={!canAddToWhitelist}
|
||||
onClick={() => addToWhitelist(row)}
|
||||
>
|
||||
加入白名单
|
||||
</Button>
|
||||
</span>
|
||||
</Tooltip>
|
||||
{row.status === 'open' && (
|
||||
<>
|
||||
<Button
|
||||
@@ -700,7 +760,16 @@ export default function RiskMonitorPage() {
|
||||
actionColumn,
|
||||
];
|
||||
},
|
||||
[acting, copy, detailLoading, expanded, revokeRestriction, runAction, toggle],
|
||||
[
|
||||
acting,
|
||||
addToWhitelist,
|
||||
copy,
|
||||
detailLoading,
|
||||
expanded,
|
||||
revokeRestriction,
|
||||
runAction,
|
||||
toggle,
|
||||
],
|
||||
);
|
||||
|
||||
const cards = useMemo(() => {
|
||||
|
||||
+85
-3
@@ -414,14 +414,14 @@ export interface FeedbackQrConfig {
|
||||
updated_at: string | null;
|
||||
}
|
||||
|
||||
/** 领券等候浮层的「新手引导视频」配置(前 3 次用它替代广告,每次固定 120 金币)。
|
||||
/** 领券等候浮层的「新手引导视频」配置(前 3 次用它替代广告,默认每次固定 100 金币)。
|
||||
* 后台只开放 enabled + 换片;下面几个字段接口仍返回,但页面不展示、也不回传。 */
|
||||
export interface GuideVideoConfig {
|
||||
scene: 'coupon' | 'comparison';
|
||||
enabled: boolean;
|
||||
video_url: string | null; // /media/guide_video/xxx.mp4;null = 未配片(浮层照旧只放广告)
|
||||
max_plays: number; // 每个账号前 N 次浮层放引导视频(服务端默认 3,后台不开放调整)
|
||||
reward_coin: number; // 每次固定金币(服务端默认 120,播完 / 中途关闭都发)
|
||||
reward_coin: number; // 每次固定金币(服务端默认 100,播完 / 中途关闭都发)
|
||||
updated_at: string | null;
|
||||
total_plays: number; // 只读统计:全站已播次数(后台不再展示)
|
||||
granted_plays: number; // 只读统计:其中已发币次数(后台不再展示)
|
||||
@@ -443,13 +443,15 @@ export interface AuditLog {
|
||||
// ===== 比价记录(admin debug 页)=====
|
||||
export interface ComparisonRecordListItem {
|
||||
id: number;
|
||||
user_id: number;
|
||||
user_id: number | null; // 软鉴权/匿名下帧0 建行时可能暂缺,admin 全看含孤儿行
|
||||
phone: string | null;
|
||||
nickname: string | null;
|
||||
business_type: string;
|
||||
trace_id: string;
|
||||
trace_url: string | null;
|
||||
status: string;
|
||||
admin_status: string; // admin 展示口径:success/failed/cancelled/running
|
||||
outcome_hint: string | null; // 有缺失的成功提示(未找到店/未满起送...);null=无缺失
|
||||
information: string | null;
|
||||
store_name: string | null;
|
||||
product_names: string | null; // 下单商品名派生串(顿号分隔),「商品」列展示
|
||||
@@ -518,6 +520,7 @@ export interface ComparisonRecordDetail extends ComparisonRecordListItem {
|
||||
skipped_dish_count: number | null;
|
||||
device_id: string | null;
|
||||
items: { name: string; qty?: number; specs?: string[] }[];
|
||||
platforms: Record<string, unknown>[];
|
||||
comparison_results: Record<string, unknown>[];
|
||||
skipped_dish_names: string[];
|
||||
device_manufacturer: string | null;
|
||||
@@ -706,6 +709,8 @@ export interface DashboardOverview {
|
||||
// 点位=一张券;成功口径 success+already_claimed;点位成功率分母=发起数×应领点位数(未跑到视为失败)。
|
||||
coupon?: {
|
||||
started: number;
|
||||
abandoned: number;
|
||||
success_denominator: number;
|
||||
all_success: number; // 全部点位领成功的完成场次数
|
||||
success_rate: number | null;
|
||||
point_success: number;
|
||||
@@ -895,3 +900,80 @@ export interface HealthTrendPoint extends HealthMetrics {
|
||||
export interface HealthBreakdownRow extends HealthMetrics {
|
||||
key: string; // 维度值(event 名 / app_ver / oem);缺失为 "(unknown)"
|
||||
}
|
||||
|
||||
// ===== 统一限制策略 / 白名单 =====
|
||||
export type LimitSubjectType = 'phone' | 'device';
|
||||
export type LimitPolicyMode =
|
||||
| 'inherit'
|
||||
| 'override'
|
||||
| 'unlimited'
|
||||
| 'suppress_alert';
|
||||
|
||||
export interface LimitRule {
|
||||
code: string;
|
||||
label: string;
|
||||
group: string;
|
||||
global_limit: number;
|
||||
default_limit: number;
|
||||
window_label: string;
|
||||
subject_types: LimitSubjectType[];
|
||||
allowed_modes: LimitPolicyMode[];
|
||||
min_value: number;
|
||||
max_value: number;
|
||||
supports_reset: boolean;
|
||||
alert_only: boolean;
|
||||
}
|
||||
|
||||
export interface LimitDeviceCandidate {
|
||||
device_id: string;
|
||||
source: string;
|
||||
source_label: string;
|
||||
user_id: number | null;
|
||||
username: string | null;
|
||||
phone: string | null;
|
||||
nickname: string | null;
|
||||
device_model: string | null;
|
||||
last_active_at: string;
|
||||
}
|
||||
|
||||
export interface LimitOverride {
|
||||
id: number;
|
||||
subject_type: LimitSubjectType;
|
||||
subject_value: string;
|
||||
rule_code: string;
|
||||
rule_label: string;
|
||||
rule_group: string;
|
||||
mode: LimitPolicyMode;
|
||||
limit_value: number | null;
|
||||
global_limit: number;
|
||||
effective_limit: number | null;
|
||||
enabled: boolean;
|
||||
starts_at: string | null;
|
||||
expires_at: string | null;
|
||||
reset_at: string | null;
|
||||
reason: string | null;
|
||||
status: 'active' | 'scheduled' | 'expired' | 'disabled';
|
||||
created_by_admin_id: number | null;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
export interface LimitOverrideList {
|
||||
items: LimitOverride[];
|
||||
total: number;
|
||||
}
|
||||
|
||||
export interface LimitSubject {
|
||||
subject_type: LimitSubjectType;
|
||||
subject_value: string;
|
||||
group_counts: Record<string, number>;
|
||||
total_rules: number;
|
||||
items: LimitOverride[];
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
export interface LimitSubjectList {
|
||||
items: LimitSubject[];
|
||||
total: number;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ export function usePagedList<T>(
|
||||
url: string,
|
||||
filters: Record<string, unknown>,
|
||||
initialPageSize = 20,
|
||||
offsetParam: 'cursor' | 'offset' = 'cursor',
|
||||
) {
|
||||
const [items, setItems] = useState<T[]>([]);
|
||||
const [total, setTotal] = useState(0);
|
||||
@@ -31,7 +32,11 @@ export function usePagedList<T>(
|
||||
requestSeq.current = seq;
|
||||
setLoading(true);
|
||||
try {
|
||||
const params = { ...JSON.parse(filtersKey), limit: ps, cursor: (p - 1) * ps };
|
||||
const params = {
|
||||
...JSON.parse(filtersKey),
|
||||
limit: ps,
|
||||
[offsetParam]: (p - 1) * ps,
|
||||
};
|
||||
const { data } = await api.get<CursorPage<T>>(url, { params });
|
||||
if (requestSeq.current !== seq) return; // 丢弃过期响应(快速切页/筛选)
|
||||
setItems(data.items);
|
||||
@@ -40,7 +45,7 @@ export function usePagedList<T>(
|
||||
if (requestSeq.current === seq) setLoading(false);
|
||||
}
|
||||
},
|
||||
[url, filtersKey],
|
||||
[url, filtersKey, offsetParam],
|
||||
);
|
||||
|
||||
// 筛选变化:回第 1 页重载
|
||||
|
||||
Reference in New Issue
Block a user