优化电子凭证接口日志和结果展示

This commit is contained in:
yml2213
2026-07-09 19:00:47 +08:00
parent 32eb442b72
commit f8a1b992af
2 changed files with 83 additions and 8 deletions
@@ -49,6 +49,7 @@ import { formatAdminDateTime } from '@/utils/admin-time'
import { stringifyDisplayJson } from '@/utils/date-time'
type DateRangeValue = [Dayjs | null, Dayjs | null] | null
type IndustryTab = 'vouchers' | 'refunds' | 'result'
type VoucherFilterState = {
oid: string
@@ -74,6 +75,7 @@ type RefundListState = {
const DEFAULT_ETICKET_TYPE = 'DINING_OPEN_TICKET'
export default function AdminKuaishouIndustryPage() {
const [activeTab, setActiveTab] = useState<IndustryTab>('vouchers')
const [voucherLoading, setVoucherLoading] = useState(false)
const [actionLoading, setActionLoading] = useState('')
const [vouchers, setVouchers] = useState<AdminKuaishouIndustryVoucher[]>([])
@@ -289,6 +291,7 @@ export default function AdminKuaishouIndustryPage() {
const response = await consumeAdminKuaishouIndustryVoucher(buildVoucherToolPayload())
setLastResultTitle('手动核销')
setLastResult(response.data)
setActiveTab('result')
showSuccess('手动核销已完成')
await loadVouchers()
} catch (error) {
@@ -304,6 +307,7 @@ export default function AdminKuaishouIndustryPage() {
const response = await resendAdminKuaishouIndustryVoucherCode(buildVoucherToolPayload())
setLastResultTitle('重发发码回调')
setLastResult(response.data)
setActiveTab('result')
if (response.data.success) {
showSuccess('发码回调已重发')
} else {
@@ -361,6 +365,7 @@ export default function AdminKuaishouIndustryPage() {
const response = await action()
setLastResultTitle(title)
setLastResult(response.data)
setActiveTab('result')
afterSuccess?.(response.data)
if (response.data.success) {
showSuccess(`${title}已执行`)
@@ -407,6 +412,8 @@ export default function AdminKuaishouIndustryPage() {
<PageHeader title="快手电子凭证" description="行业电子凭证接口工具与售后处理" />
<Tabs
activeKey={activeTab}
onChange={(key) => setActiveTab(key as IndustryTab)}
items={[
{
key: 'vouchers',
@@ -768,6 +775,8 @@ export default function AdminKuaishouIndustryPage() {
}
function renderResultTab() {
const summary = resolveOpenApiResultSummary(lastResult)
return (
<Card
title={lastResultTitle}
@@ -778,7 +787,15 @@ export default function AdminKuaishouIndustryPage() {
}
>
{lastResult ? (
<pre className="json-preview">{stringifyDisplayJson(lastResult)}</pre>
<Space direction="vertical" size={12} className="full-width">
<Alert
type={summary.success ? 'success' : 'error'}
showIcon
message={summary.title}
description={summary.description}
/>
<pre className="json-preview">{stringifyDisplayJson(lastResult)}</pre>
</Space>
) : (
<Alert type="info" showIcon message="暂无接口结果" />
)}
@@ -809,6 +826,40 @@ function extractRefundRows(response: Record<string, unknown> | null): Array<Reco
: []
}
function resolveOpenApiResultSummary(value: unknown) {
const result = value && typeof value === 'object' && !Array.isArray(value)
? value as Record<string, unknown>
: {}
const response = result.response && typeof result.response === 'object' && !Array.isArray(result.response)
? result.response as Record<string, unknown>
: null
const success = Boolean(result.success)
const code = String(response?.code || response?.sub_code || '').trim()
const resultCode = String(response?.result || '').trim()
const message = String(
response?.error_msg ||
response?.msg ||
response?.sub_msg ||
response?.message ||
result.error ||
'',
).trim()
const status = Number(result.httpStatus || 0) || 0
const durationMs = Number(result.durationMs || 0) || 0
const markers = [
status ? `HTTP ${status}` : '',
resultCode ? `result=${resultCode}` : '',
code ? `code=${code}` : '',
durationMs ? `${durationMs}ms` : '',
].filter(Boolean)
return {
success,
title: success ? '接口返回成功' : '接口返回失败',
description: [markers.join(' / '), message].filter(Boolean).join('') || '请查看下方原始响应。',
}
}
function getVoucherStatusColor(status: string) {
const normalized = String(status || '').toUpperCase()
if (normalized === 'CONSUMED') return 'green'