Compare commits

..

1 Commits

Author SHA1 Message Date
linkeyu 7e79c99625 fix(admin): 使用后端常规任务金币汇总 2026-07-22 11:40:41 +08:00
8 changed files with 57 additions and 614 deletions
+25 -112
View File
@@ -66,101 +66,21 @@ const APP_TAG: Record<string, { color: string; label: string }> = {
test: { color: 'default', label: '测试应用' },
};
const REWARD_STATUS_HINT: Record<string, string> = {
granted: '已完成金币发放',
capped: '次数超限,未发金币',
ecpm_missing: '缺少有效 eCPM,未发金币',
too_short: '播放时长未达到发奖条件,未发金币',
closed_early: '用户提前关闭广告,未发金币',
};
const PLAYBACK_STATUS_TAG: Record<string, { color: string; label: string }> = {
completed: { color: 'green', label: '已完成' },
too_short: { color: 'gold', label: '观看时长不足' },
// 发奖状态 → 颜色 + 中文(含「不发金币的原因」:提前关闭/未满10秒/缺eCPM/次数超限)
const STATUS_TAG: Record<string, { color: string; label: string }> = {
granted: { color: 'green', label: '已发' },
capped: { color: 'orange', label: '次数超限' },
ecpm_missing: { color: 'red', label: '缺 eCPM' },
too_short: { color: 'gold', label: '未满10秒' },
closed_early: { color: 'default', label: '提前关闭' },
unknown: { color: 'default', label: '未知' },
};
const ZERO_REVENUE_REWARD_VIDEO_STATUSES = new Set(['closed_early', 'too_short']);
function rewardStatuses(row: AdRevenueRow): string[] {
if (row.sub_rewards?.length) return row.sub_rewards.map((reward) => reward.status);
return row.status ? [row.status] : [];
}
function effectiveRevenueYuan(row: AdRevenueRow): number {
if (
row.ad_type === 'reward_video'
&& rewardStatuses(row).some((status) => ZERO_REVENUE_REWARD_VIDEO_STATUSES.has(status))
) {
return 0;
}
return row.row_revenue_yuan ?? row.revenue_yuan;
}
function rewardStatusTag(row: AdRevenueRow) {
const statuses = rewardStatuses(row);
if (!row.has_reward || statuses.length === 0) {
return { color: 'default', label: '无记录', hint: '仅记录到广告展示,没有对应发奖记录。' };
}
const grantedCount = statuses.filter((status) => status === 'granted').length;
const reasonSummary = Object.entries(
statuses
.filter((status) => status !== 'granted')
.reduce<Record<string, number>>((counts, status) => {
counts[status] = (counts[status] ?? 0) + 1;
return counts;
}, {}),
)
.map(([status, count]) => `${REWARD_STATUS_HINT[status] ?? status} ${count}`)
.join('');
if (grantedCount === statuses.length) {
return { color: 'green', label: '已发', hint: `已完成金币发放${statuses.length > 1 ? ` ${statuses.length}` : ''}` };
}
if (grantedCount > 0) {
return {
color: 'blue',
label: '部分已发',
hint: `已发 ${grantedCount} 条,未发 ${statuses.length - grantedCount}${reasonSummary ? `${reasonSummary}` : ''}`,
};
}
return { color: 'default', label: '未发', hint: reasonSummary ? `${reasonSummary}` : '未发放金币。' };
}
function playbackStatusTag(row: AdRevenueRow) {
const statuses = rewardStatuses(row);
if (statuses.length === 0) {
return row.has_impression
? { color: 'blue', label: '仅展示', hint: '记录到广告展示,但没有对应的播放结果。' }
: { color: 'default', label: '无记录', hint: '没有可用的广告播放记录。' };
}
const playbackCounts = statuses.reduce<Record<string, number>>((counts, status) => {
const playbackStatus =
status === 'too_short' || status === 'closed_early'
? status
: status === 'granted' || status === 'capped' || status === 'ecpm_missing'
? 'completed'
: 'unknown';
counts[playbackStatus] = (counts[playbackStatus] ?? 0) + 1;
return counts;
}, {});
const entries = Object.entries(playbackCounts);
if (entries.length === 1) {
const [status, count] = entries[0];
const tag = PLAYBACK_STATUS_TAG[status];
return {
...tag,
hint: `${tag.label}${count > 1 ? ` ${count}` : ''}`,
};
}
const hint = entries
.map(([status, count]) => `${PLAYBACK_STATUS_TAG[status].label} ${count}`)
.join('');
return { color: 'purple', label: '部分完成', hint: `${hint}` };
}
const STATUS_HINT: Record<string, string> = {
granted: '已满足当前客户端发奖条件并完成金币发放。',
too_short: '旧版 Draw 信息流观看不足 10 秒,不发金币;新版按观看比例发放时会记为已发。',
closed_early: '用户在达到发奖条件前主动关闭,不发金币。',
capped: '已达到次数上限,不再发金币。',
ecpm_missing: '缺少有效 eCPM,无法计算金币。',
};
const fmtFactorRange = (a: number | null, b: number | null) => {
if (a == null) return '-';
@@ -558,25 +478,19 @@ export default function AdRevenueReportPage() {
width: 110,
align: 'right',
// 一次比价/领券聚合行用 row_revenue_yuan(该次发奖广告 eCPM 折算之和),其它行用展示侧 revenue_yuan
// 激励视频提前关闭/时长不足时防御性显示 0,与后端有效收益口径一致。
render: (_v: number, r: AdRevenueRow) => effectiveRevenueYuan(r).toFixed(4),
},
{
title: '发奖状态',
key: 'reward_status',
width: 100,
render: (_: unknown, row: AdRevenueRow) => {
const tag = rewardStatusTag(row);
return <Tooltip title={tag.hint}><Tag color={tag.color}>{tag.label}</Tag></Tooltip>;
render: (v: number, r: AdRevenueRow) => {
const rev = r.row_revenue_yuan ?? v;
return rev.toFixed(4);
},
},
{
title: '广告播放状态',
key: 'playback_status',
width: 120,
render: (_: unknown, row: AdRevenueRow) => {
const tag = playbackStatusTag(row);
return <Tooltip title={tag.hint}><Tag color={tag.color}>{tag.label}</Tag></Tooltip>;
title: '发奖状态',
dataIndex: 'status',
width: 100,
render: (s: string | null) => {
if (!s) return <Tooltip title="仅记录广告展示,没有对应发奖事件。"><Tag></Tag></Tooltip>;
const t = STATUS_TAG[s] ?? { color: 'default', label: s };
return <Tooltip title={STATUS_HINT[s]}><Tag color={t.color}>{t.label}</Tag></Tooltip>;
},
},
{
@@ -618,8 +532,7 @@ export default function AdRevenueReportPage() {
'ecpm_yuan',
'revenue_yuan',
'actual_coin',
'reward_status',
'playback_status',
'status',
'ad_type',
'app_env',
'our_code_id',
@@ -705,7 +618,7 @@ export default function AdRevenueReportPage() {
<br />
<br />
广(onAdShow) eCPM ( ÷1000
);<b> 0 </b>, eCPM 穿,
),<b>广</b>;穿/,,
<b>穿</b> 0广ID / ,
<br />
<br />
+13 -116
View File
@@ -10,11 +10,9 @@ import {
DatePicker,
Divider,
Input,
Popover,
Row,
Select,
Space,
Spin,
Statistic,
Table,
Tag,
@@ -74,23 +72,9 @@ interface CouponDataRow {
app_env: string | null;
started_at: string;
claimed_count: number | null;
point_success_count: number | null;
point_total_count: number | null;
// 兼容旧后端的内嵌明细;新后端不再返回,改为点击后按 trace 加载。
point_details?: CouponPointDetail[];
trace_url: string | null;
ad_revenue_yuan: number | null; // 本次领券看的信息流广告预估收益(元);未填充为 null
}
interface CouponPointDetail {
coupon_id: string;
coupon_name: string | null;
status: string;
reason: string | null;
}
interface CouponPointDetailsOut {
trace_id: string;
items: CouponPointDetail[];
}
interface CouponDataReport {
date_from: string;
date_to: string;
@@ -132,103 +116,6 @@ const STATUS_TAG: Record<string, { color: string; label: string }> = {
abandoned: { color: 'orange', label: '中途退出' },
};
const POINT_STATUS_TAG: Record<string, { color: string; label: string }> = {
success: { color: 'success', label: '成功' },
already_claimed: { color: 'processing', label: '已领' },
failed: { color: 'error', label: '失败' },
skipped: { color: 'default', label: '跳过' },
};
function PointScorePopover({ row }: { row: CouponDataRow }) {
const { message } = App.useApp();
const [details, setDetails] = useState<CouponPointDetail[] | null>(row.point_details ?? null);
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) {
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 scoreColor =
row.point_success_count === row.point_total_count
? STATUS_TAG.completed.color
: STATUS_TAG.abandoned.color;
const loadDetails = async () => {
if (details !== null || loading) return;
setLoading(true);
setLoadError(null);
try {
const response = await api.get<CouponPointDetailsOut>('/admin/api/coupon-data/point-details', {
params: { trace_id: row.trace_id },
});
setDetails(response.data.items);
} catch (error) {
const errorMessage = errMsg(error);
setLoadError(errorMessage);
message.error(errorMessage);
} finally {
setLoading(false);
}
};
return (
<Popover
trigger="click"
placement="bottomLeft"
title={`点位明细(${score}`}
onOpenChange={(open) => {
if (open) void loadDetails();
}}
content={(
<div style={{ width: 380, maxHeight: 360, overflowY: 'auto' }}>
{loading || (details === null && loadError === null) ? (
<Spin size="small" style={{ display: 'block', margin: '24px auto' }} />
) : loadError ? (
<Typography.Text type="danger"></Typography.Text>
) : details && details.length > 0 ? details.map((point, index) => {
const status = POINT_STATUS_TAG[point.status] ?? {
color: 'default', label: point.status,
};
return (
<div
key={`${point.coupon_id}-${index}`}
style={{
padding: '8px 0',
borderBottom: index < details.length - 1 ? '1px solid #f0f0f0' : undefined,
}}
>
<div style={{ display: 'flex', alignItems: 'flex-start', gap: 12 }}>
<div style={{ flex: 1, minWidth: 0 }}>
<Typography.Text>{point.coupon_name || point.coupon_id}</Typography.Text>
{point.coupon_name ? (
<div><Typography.Text type="secondary">{point.coupon_id}</Typography.Text></div>
) : null}
</div>
<Tag color={status.color} style={{ marginInlineEnd: 0 }}>{status.label}</Tag>
</div>
{point.reason ? (
<div style={{ marginTop: 4 }}>
<Typography.Text type="danger">{point.reason}</Typography.Text>
</div>
) : null}
</div>
);
}) : (
<Typography.Text type="secondary"></Typography.Text>
)}
</div>
)}
>
<Button type="link" size="small" style={{ height: 'auto', padding: 0, color: scoreColor }}>
{scoreWithRate}
</Button>
</Popover>
);
}
// ms → "1.5s"(空值显示 -)
const fmtSec = (ms: number | null | undefined): string =>
ms == null ? '-' : `${(ms / 1000).toFixed(1)}s`;
@@ -605,10 +492,20 @@ export default function CouponDataPage() {
render: (v: number | null) => fmtSec(v),
},
{
title: '单券成功率',
title: '点位成功率',
key: 'point_success_rate',
width: 150,
render: (_: unknown, r: CouponDataRow) => <PointScorePopover row={r} />,
width: 110,
render: (_: unknown, r: CouponDataRow) => (
<Tooltip title="当前接口未返回本场应领点位及逐点结果,前端不使用全局均值冒充本场成功率。">
{r.trace_url ? (
<a href={r.trace_url} target="_blank" rel="noreferrer">
</a>
) : (
<Typography.Text type="secondary"></Typography.Text>
)}
</Tooltip>
),
},
{
title: '广告收益',
+2 -2
View File
@@ -1065,14 +1065,14 @@ export default function DashboardPage() {
value={fmtInt(periodData?.coins.reward_video_coin_total)}
delta={rewardVideoCoinRatio.value}
deltaTone={rewardVideoCoinRatio.tone}
hint="普通看视频与历史签到膨胀的实发金币之和,不再重复计入领券奖励或常规任务。"
hint="独立统计看视频发放,不再重复计入领券奖励。"
/>
<StatCard
title="常规任务金币"
value={fmtInt(regularTaskCoinTotal)}
delta={regularTaskCoinRatio.value}
deltaTone={regularTaskCoinRatio.tone}
hint="每日签到、通知/其他任务、上报更低价和反馈采纳的实发金币之和。"
hint="每日签到、历史签到膨胀、通知/其他任务、上报更低价和反馈采纳的实发金币之和。"
/>
<StatCard
title="本期提现金额"
+1 -202
View File
@@ -4,15 +4,11 @@ import { useEffect, useState } from 'react';
import type { ColumnsType } from 'antd/es/table';
import type { SorterResult } from 'antd/es/table/interface';
import {
App,
Button,
Card,
DatePicker,
Form,
Image,
Input,
InputNumber,
Modal,
Select,
Space,
Statistic,
@@ -21,12 +17,10 @@ import {
Typography,
} from 'antd';
import type { Dayjs } from 'dayjs';
import { api, errMsg } from '@/lib/api';
import { api } from '@/lib/api';
import { canDo } from '@/lib/auth';
import { formatWallTime } from '@/lib/format';
import { refreshReviewBadge } from '@/lib/reviewBadge';
import { BULK_REVIEW_MAX, bulkFailureReasonText, failedReviewIds } from '@/lib/bulkAction';
import type { BulkReviewResult } from '@/lib/bulkAction';
import { usePagedList } from '@/lib/usePagedList';
import type { Feedback, FeedbackSummary } from '@/lib/types';
import FeedbackHandleDrawer from './FeedbackHandleDrawer';
@@ -34,7 +28,6 @@ import UserRecordsDrawer from '@/components/UserRecordsDrawer';
const { Text, Paragraph } = Typography;
const { RangePicker } = DatePicker;
const REWARD_MAX = 10000;
// 截图是 app-server 的 /media 相对路径,本地由 :8770 提供(NEXT_PUBLIC_MEDIA_BASE);生产同域走 nginx 代理。
const MEDIA_BASE = process.env.NEXT_PUBLIC_MEDIA_BASE || '';
@@ -162,8 +155,6 @@ const RECORD_COLUMNS: ColumnsType<Feedback> = [
];
export default function FeedbacksPage() {
const { message } = App.useApp();
const [bulkForm] = Form.useForm();
// 筛选草稿:点「查询」才应用(避免输入即刷新)
const [status, setStatus] = useState<string | undefined>();
const [source, setSource] = useState<string | undefined>();
@@ -180,19 +171,6 @@ export default function FeedbacksPage() {
usePagedList<Feedback>('/admin/api/feedbacks', filters);
const canReview = canDo(['operator']);
const [selectedRowKeys, setSelectedRowKeys] = useState<number[]>([]);
const [bulkAction, setBulkAction] = useState<'approve' | 'reject' | null>(null);
const [bulkSubmitting, setBulkSubmitting] = useState(false);
const selectedFeedbacks = items.filter(
(item) => selectedRowKeys.includes(item.id) && isPending(item.status),
);
useEffect(() => {
const visiblePendingIds = new Set(
items.filter((item) => isPending(item.status)).map((item) => item.id),
);
setSelectedRowKeys((keys) => keys.filter((id) => visiblePendingIds.has(id)));
}, [items]);
const [summary, setSummary] = useState<FeedbackSummary | null>(null);
const loadSummary = async () => {
@@ -258,61 +236,6 @@ export default function FeedbacksPage() {
const sortOrderOf = (field: SortField) =>
sortBy === field ? (sortOrder === 'asc' ? 'ascend' : 'descend') : null;
const openBulkModal = (action: 'approve' | 'reject') => {
if (!selectedFeedbacks.length) return;
if (selectedFeedbacks.length > BULK_REVIEW_MAX) {
message.warning(`单次最多审核 ${BULK_REVIEW_MAX} 条反馈`);
return;
}
bulkForm.resetFields();
setBulkAction(action);
};
const submitBulkReview = async () => {
if (!bulkAction || !selectedFeedbacks.length) return;
const values = await bulkForm.validateFields();
const targets = selectedFeedbacks;
setBulkSubmitting(true);
try {
const { data } = await api.post<BulkReviewResult>(
`/admin/api/feedbacks/bulk/${bulkAction}`,
bulkAction === 'approve'
? {
ids: targets.map((item) => item.id),
reward_coins: values.reward_coins,
note: values.note?.trim() || null,
reply: values.reply?.trim() || null,
}
: {
ids: targets.map((item) => item.id),
reason: values.reason.trim(),
note: values.note?.trim() || null,
reply: values.reply?.trim() || null,
},
);
const failedIds = failedReviewIds(data);
setSelectedRowKeys(failedIds);
setBulkAction(null);
bulkForm.resetFields();
if (failedIds.length) reload();
else onPageChange(1, pageSize);
loadSummary();
refreshReviewBadge('/feedbacks');
const label = bulkAction === 'approve' ? '批量采纳' : '批量拒绝';
if (failedIds.length) {
message.warning(
`${label}完成:成功 ${data.success} 条,失败 ${failedIds.length} 条;失败项已保留勾选${bulkFailureReasonText(data)}`,
);
} else {
message.success(`${label}完成:成功 ${data.success}`);
}
} catch (e) {
message.error(errMsg(e));
} finally {
setBulkSubmitting(false);
}
};
const columns: ColumnsType<Feedback> = [
{
title: '用户ID',
@@ -488,58 +411,16 @@ export default function FeedbacksPage() {
<Button onClick={resetFilters}></Button>
</Space>
{canReview && (
<Space wrap style={{ display: 'flex', marginBottom: 12 }}>
<Text> <Text strong>{selectedFeedbacks.length}</Text> </Text>
<Button
type="primary"
disabled={!selectedFeedbacks.length || selectedFeedbacks.length > BULK_REVIEW_MAX}
onClick={() => openBulkModal('approve')}
>
</Button>
<Button
danger
disabled={!selectedFeedbacks.length || selectedFeedbacks.length > BULK_REVIEW_MAX}
onClick={() => openBulkModal('reject')}
>
</Button>
{!!selectedFeedbacks.length && (
<Button onClick={() => setSelectedRowKeys([])}></Button>
)}
</Space>
)}
<Table
rowKey="id"
columns={columns}
dataSource={items}
rowSelection={
canReview
? {
selectedRowKeys,
onChange: (keys) => {
const ids = keys as number[];
if (ids.length > BULK_REVIEW_MAX) {
message.warning(`单次最多选择 ${BULK_REVIEW_MAX} 条待审核反馈`);
}
setSelectedRowKeys(ids.slice(0, BULK_REVIEW_MAX));
},
getCheckboxProps: (record) => ({
disabled: !isPending(record.status),
name: `选择反馈 #${record.id}`,
}),
}
: undefined
}
loading={loading}
pagination={{
current: page,
pageSize,
total,
showSizeChanger: true,
pageSizeOptions: [10, 20, 50],
showTotal: (t) => `${t} 条反馈`,
onChange: onPageChange,
}}
@@ -547,88 +428,6 @@ export default function FeedbacksPage() {
scroll={{ x: 1720 }}
/>
<Modal
title={
bulkAction === 'approve'
? `批量采纳 ${selectedFeedbacks.length} 条反馈`
: `批量拒绝 ${selectedFeedbacks.length} 条反馈`
}
open={bulkAction != null}
okText={bulkAction === 'approve' ? '批量采纳并发金币' : '确认批量拒绝'}
okButtonProps={{ danger: bulkAction === 'reject' }}
confirmLoading={bulkSubmitting}
onOk={submitBulkReview}
onCancel={() => {
if (bulkSubmitting) return;
setBulkAction(null);
bulkForm.resetFields();
}}
destroyOnHidden
>
<Text type="secondary">
{selectedFeedbacks.length}
</Text>
<Form form={bulkForm} layout="vertical" preserve={false} style={{ marginTop: 16 }}>
{bulkAction === 'approve' ? (
<Form.Item
name="reward_coins"
label={`每条奖励金币(必填,1 ~ ${REWARD_MAX}`}
rules={[
{ required: true, message: '请输入每条反馈的奖励金币' },
{ type: 'number', min: 1, max: REWARD_MAX, message: `请输入 1 ~ ${REWARD_MAX}` },
]}
>
<InputNumber
min={1}
max={REWARD_MAX}
style={{ width: '100%' }}
placeholder="每条反馈发放相同金币"
/>
</Form.Item>
) : (
<Form.Item
name="reason"
label="未采纳原因(必填,用户可见)"
rules={[
{ required: true, whitespace: true, message: '请填写未采纳原因' },
{ max: 256, message: '最多 256 字' },
]}
>
<Input.TextArea
rows={3}
maxLength={256}
showCount
placeholder="同一原因将发送给全部已选用户"
/>
</Form.Item>
)}
<Form.Item
name="note"
label={
bulkAction === 'approve'
? '采纳要点 / 审核备注(选填,内部)'
: '内部备注(选填)'
}
rules={[{ max: 256, message: '最多 256 字' }]}
>
<Input.TextArea rows={2} maxLength={256} showCount />
</Form.Item>
<Form.Item
name="reply"
label="给用户的回复(选填,用户可见)"
rules={[{ max: 256, message: '最多 256 字' }]}
>
<Input.TextArea
rows={2}
maxLength={256}
showCount
placeholder="同一回复将发送给全部已选用户"
/>
</Form.Item>
</Form>
</Modal>
<FeedbackHandleDrawer
feedback={drawerFb}
open={drawerOpen}
+4 -11
View File
@@ -67,6 +67,8 @@ const NAV_GROUPS: NavGroup[] = [
{ key: '/comparison-records', icon: <ProfileOutlined />, label: '比价记录' },
{ key: '/coupon-data', icon: <GiftOutlined />, label: '领券记录' },
{ key: '/cps', icon: <ShareAltOutlined />, label: 'CPS收益' },
{ key: '/device-liveness', icon: <HeartOutlined />, label: '设备存活' },
{ key: '/analytics-health', icon: <LineChartOutlined />, label: '埋点成功率' },
],
},
{
@@ -90,18 +92,9 @@ const NAV_GROUPS: NavGroup[] = [
{ key: '/users', icon: <UserOutlined />, label: '用户管理' },
],
},
{
key: 'monitoring-audit',
icon: <FileSearchOutlined />,
label: '监控审计',
children: [
{ key: '/device-liveness', icon: <HeartOutlined />, label: '设备存活' },
{ key: '/analytics-health', icon: <LineChartOutlined />, label: '埋点成功率' },
{ key: '/event-logs', icon: <DatabaseOutlined />, label: '埋点日志' },
{ key: '/audit-logs', icon: <FileSearchOutlined />, label: '审计日志' },
],
},
{ key: '/admins', icon: <TeamOutlined />, label: '权限管理' },
{ key: '/event-logs', icon: <DatabaseOutlined />, label: '埋点日志' },
{ key: '/audit-logs', icon: <FileSearchOutlined />, label: '审计日志' },
];
// 导航项 key(/dashboard)→ 权限页 key(dashboard),与后端 permissions.py 目录对齐
+11 -137
View File
@@ -23,8 +23,6 @@ import { api, errMsg } from '@/lib/api';
import { canDo } from '@/lib/auth';
import { mediaUrl } from '@/lib/media';
import { refreshReviewBadge } from '@/lib/reviewBadge';
import { BULK_REVIEW_MAX, bulkFailureReasonText, failedReviewIds } from '@/lib/bulkAction';
import type { BulkReviewResult } from '@/lib/bulkAction';
import { usePagedList } from '@/lib/usePagedList';
import type { PriceReport, PriceReportSummary } from '@/lib/types';
import UserRecordsDrawer from '@/components/UserRecordsDrawer';
@@ -134,10 +132,7 @@ export default function PriceReportsPage() {
const [activeStatus, setActiveStatus] = useState('pending');
const [summary, setSummary] = useState<PriceReportSummary | null>(null);
const [rejecting, setRejecting] = useState<PriceReport | null>(null);
const [bulkRejecting, setBulkRejecting] = useState<PriceReport[]>([]);
const [rejectReason, setRejectReason] = useState('');
const [rejectSubmitting, setRejectSubmitting] = useState(false);
const [selectedRowKeys, setSelectedRowKeys] = useState<number[]>([]);
// 提交时间列服务端排序(默认按提交时间倒序,最新在前)
const [sortBy, setSortBy] = useState<SortField>('created_at');
const [sortOrder, setSortOrder] = useState<'asc' | 'desc'>('desc');
@@ -170,16 +165,6 @@ export default function PriceReportsPage() {
};
const canReview = canDo(['operator']);
const selectedReports = items.filter(
(item) => selectedRowKeys.includes(item.id) && item.status === 'pending',
);
useEffect(() => {
const visiblePendingIds = new Set(
items.filter((item) => item.status === 'pending').map((item) => item.id),
);
setSelectedRowKeys((keys) => keys.filter((id) => visiblePendingIds.has(id)));
}, [items]);
const loadSummary = async () => {
try {
@@ -198,49 +183,6 @@ export default function PriceReportsPage() {
loadSummary();
};
const reportBulkResult = (label: string, result: BulkReviewResult) => {
const failedIds = failedReviewIds(result);
setSelectedRowKeys(failedIds);
refreshReviewBadge('/price-reports');
loadSummary();
if (failedIds.length) reload();
else onPageChange(1, pageSize);
if (failedIds.length) {
message.warning(
`${label}完成:成功 ${result.success} 条,失败 ${failedIds.length} 条;失败项已保留勾选${bulkFailureReasonText(result)}`,
);
} else {
message.success(`${label}完成:成功 ${result.success}`);
}
};
const bulkApprove = () => {
const targets = selectedReports;
if (!targets.length) return;
if (targets.length > BULK_REVIEW_MAX) {
message.warning(`单次最多审核 ${BULK_REVIEW_MAX} 条记录`);
return;
}
modal.confirm({
title: `确认批量通过 ${targets.length} 条低价上报?`,
icon: <CheckCircleOutlined style={{ color: '#52c41a' }} />,
content: `通过后将向每位用户发放 1000 金币,共发放 ${targets.length * 1000} 金币。请确认已逐条核实截图。`,
okText: '批量通过并发金币',
onOk: async () => {
try {
const { data } = await api.post<BulkReviewResult>(
'/admin/api/price-reports/bulk/approve',
{ ids: targets.map((item) => item.id) },
);
reportBulkResult('批量通过', data);
} catch (e) {
message.error(errMsg(e));
throw e;
}
},
});
};
const approve = (r: PriceReport) => {
modal.confirm({
title: '确认通过该上报?',
@@ -272,38 +214,21 @@ export default function PriceReportsPage() {
};
const confirmReject = async () => {
const targets = bulkRejecting.length ? bulkRejecting : rejecting ? [rejecting] : [];
if (!targets.length) return;
if (targets.length > BULK_REVIEW_MAX) {
message.warning(`单次最多审核 ${BULK_REVIEW_MAX} 条记录`);
return;
}
if (!rejecting) return;
const reason = rejectReason.trim();
if (!reason) {
message.warning('请填写拒绝理由');
return;
}
setRejectSubmitting(true);
try {
if (bulkRejecting.length) {
const { data } = await api.post<BulkReviewResult>(
'/admin/api/price-reports/bulk/reject',
{ ids: targets.map((item) => item.id), reason },
);
reportBulkResult('批量拒绝', data);
} else {
await api.post(`/admin/api/price-reports/${targets[0].id}/reject`, { reason });
refreshReviewBadge('/price-reports');
message.success('已拒绝');
refreshAfterChange();
}
await api.post(`/admin/api/price-reports/${rejecting.id}/reject`, { reason });
refreshReviewBadge('/price-reports');
message.success('已拒绝');
setRejecting(null);
setBulkRejecting([]);
setRejectReason('');
refreshAfterChange();
} catch (e) {
message.error(errMsg(e));
} finally {
setRejectSubmitting(false);
}
};
@@ -468,56 +393,10 @@ export default function PriceReportsPage() {
onChange={setActiveStatus}
items={STATUS_TABS.map((t) => ({ key: t.key, label: t.label }))}
/>
{canReview && (
<Space wrap style={{ marginBottom: 16 }}>
<Text> <Text strong>{selectedReports.length}</Text> </Text>
<Button
type="primary"
icon={<CheckCircleOutlined />}
disabled={!selectedReports.length || selectedReports.length > BULK_REVIEW_MAX}
onClick={bulkApprove}
>
</Button>
<Button
danger
icon={<CloseCircleOutlined />}
disabled={!selectedReports.length || selectedReports.length > BULK_REVIEW_MAX}
onClick={() => {
setRejecting(null);
setBulkRejecting(selectedReports);
setRejectReason('');
}}
>
</Button>
{!!selectedReports.length && (
<Button onClick={() => setSelectedRowKeys([])}></Button>
)}
</Space>
)}
<Table
rowKey="id"
columns={columns}
dataSource={items}
rowSelection={
canReview
? {
selectedRowKeys,
onChange: (keys) => {
const ids = keys as number[];
if (ids.length > BULK_REVIEW_MAX) {
message.warning(`单次最多选择 ${BULK_REVIEW_MAX} 条待审核记录`);
}
setSelectedRowKeys(ids.slice(0, BULK_REVIEW_MAX));
},
getCheckboxProps: (record) => ({
disabled: record.status !== 'pending',
name: `选择低价上报 #${record.id}`,
}),
}
: undefined
}
loading={loading}
onChange={onTableChange}
pagination={{
@@ -525,7 +404,6 @@ export default function PriceReportsPage() {
pageSize,
total,
showSizeChanger: true,
pageSizeOptions: [10, 20, 50],
showTotal: (t) => `${t}`,
onChange: onPageChange,
}}
@@ -534,25 +412,21 @@ export default function PriceReportsPage() {
</Card>
<Modal
title={bulkRejecting.length ? `批量拒绝 ${bulkRejecting.length} 条低价上报` : '拒绝上报'}
open={!!(rejecting || bulkRejecting.length)}
title="拒绝上报"
open={!!rejecting}
okText="确认拒绝"
confirmLoading={rejectSubmitting}
okButtonProps={{ danger: true, icon: <CloseCircleOutlined /> }}
onOk={confirmReject}
onCancel={() => {
setRejecting(null);
setBulkRejecting([]);
setRejectReason('');
}}
>
{(rejecting || bulkRejecting.length > 0) && (
{rejecting && (
<Space direction="vertical" style={{ width: '100%' }}>
{bulkRejecting.length ? (
<Text type="secondary"> {bulkRejecting.length} </Text>
) : rejecting ? (
<Text> #{rejecting.user_id} · {rejecting.store_name || '-'}</Text>
) : null}
<Text>
#{rejecting.user_id} · {rejecting.store_name || '-'}
</Text>
<Space wrap>
{REJECT_TEMPLATES.map((tpl) => (
<Button size="small" key={tpl} onClick={() => setRejectReason(tpl)}>
-33
View File
@@ -1,33 +0,0 @@
export interface BulkReviewItemResult {
id: number;
ok: boolean;
status: string | null;
error: string | null;
}
export interface BulkReviewResult {
total: number;
success: number;
failed: number;
items: BulkReviewItemResult[];
}
export const BULK_REVIEW_MAX = 50;
export function failedReviewIds(result: BulkReviewResult): number[] {
return result.items.filter((item) => !item.ok).map((item) => item.id);
}
export function bulkFailureReasonText(result: BulkReviewResult): string {
const reasons = Array.from(
new Set(
result.items
.filter((item) => !item.ok)
.map((item) => item.error?.trim())
.filter((reason): reason is string => Boolean(reason)),
),
);
if (!reasons.length) return '';
const visible = reasons.slice(0, 3);
return `;原因:${visible.join('')}${reasons.length > visible.length ? ';…' : ''}`;
}
+1 -1
View File
@@ -488,7 +488,7 @@ export interface AdRevenueRow {
has_impression: boolean; // 是否有广告展示(信息流逐条展示=true,纯发奖行=false)
impressions: number; // 本行展示条数 1/0(供日汇总、趋势图复用)
ecpm: string | null; // 分/千次;展示行取展示值,纯发奖行取发奖采用值
revenue_yuan: number; // 本次有效展示预估收益(元);纯发奖、激励视频提前关闭/时长不足=0
revenue_yuan: number; // 本次展示预估收益(元);纯发奖=0
row_revenue_yuan?: number | null; // 主表逐行显示用:一次比价/领券聚合行=该次发奖广告 eCPM 折算之和;其它行空(回退 revenue_yuan)
adn: string | null; // 实际填充 ADN;纯发奖行为空
slot_id: string | null; // 底层 mediation rit;纯发奖行为空