feat(payment): 增加支付配置测试支付与全链路报文
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
import { apiClient } from '@/shared/api/client'
|
||||
import type { ApiResponse } from '@/shared/types/types'
|
||||
|
||||
export interface ConfigTestPayment {
|
||||
id: number
|
||||
tenant_id: number
|
||||
payment_config_id: number
|
||||
config_name: string
|
||||
provider: string
|
||||
merchant_id: string
|
||||
pay_way: string
|
||||
environment: string
|
||||
config_status: string
|
||||
test_no: string
|
||||
third_order_id: string
|
||||
provider_order_id: string
|
||||
amount_cent: number
|
||||
status: string
|
||||
td_code?: string
|
||||
jspay_url?: string
|
||||
jspay_info?: string
|
||||
error_message: string
|
||||
raw_request?: Record<string, unknown> | null
|
||||
raw_response?: Record<string, unknown> | null
|
||||
create_request?: Record<string, unknown> | null
|
||||
create_response?: Record<string, unknown> | null
|
||||
query_request?: Record<string, unknown> | null
|
||||
query_response?: Record<string, unknown> | null
|
||||
notify_request?: Record<string, unknown> | null
|
||||
notify_result?: Record<string, unknown> | null
|
||||
notify_ack?: string
|
||||
query_count: number
|
||||
last_queried_at?: string
|
||||
paid_at?: string
|
||||
notified_at?: string
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
export interface ConfigTestPaymentList {
|
||||
items: ConfigTestPayment[]
|
||||
total: number
|
||||
page: number
|
||||
page_size: number
|
||||
}
|
||||
|
||||
export interface ConfigTestPaymentQuery {
|
||||
payment_config_id?: number
|
||||
provider?: string
|
||||
pay_way?: string
|
||||
status?: string
|
||||
test_no?: string
|
||||
page?: number
|
||||
page_size?: number
|
||||
}
|
||||
|
||||
export async function createConfigTestPayment(configId: number, amountCent: number) {
|
||||
const { data } = await apiClient.post<ApiResponse<ConfigTestPayment>>(
|
||||
`/admin/payment-configs/${configId}/test-orders`,
|
||||
{ amount_cent: amountCent }
|
||||
)
|
||||
return data.data
|
||||
}
|
||||
|
||||
export async function fetchConfigTestPayments(query: ConfigTestPaymentQuery = {}) {
|
||||
const params = Object.fromEntries(
|
||||
Object.entries(query).filter(([, value]) => value !== '' && value !== undefined)
|
||||
)
|
||||
const { data } = await apiClient.get<ApiResponse<ConfigTestPaymentList>>(
|
||||
'/admin/payment-config-test-orders',
|
||||
{ params }
|
||||
)
|
||||
const result = data.data
|
||||
return {
|
||||
items: Array.isArray(result?.items) ? result.items : [],
|
||||
total: Number(result?.total ?? 0),
|
||||
page: Number(result?.page ?? query.page ?? 1),
|
||||
page_size: Number(result?.page_size ?? query.page_size ?? 20),
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchConfigTestPayment(id: number) {
|
||||
const { data } = await apiClient.get<ApiResponse<ConfigTestPayment>>(
|
||||
`/admin/payment-config-test-orders/${id}`
|
||||
)
|
||||
return data.data
|
||||
}
|
||||
|
||||
export async function refreshConfigTestPayment(id: number, silent = false) {
|
||||
const { data } = await apiClient.post<ApiResponse<ConfigTestPayment>>(
|
||||
`/admin/payment-config-test-orders/${id}/refresh`,
|
||||
undefined,
|
||||
{ silent }
|
||||
)
|
||||
return data.data
|
||||
}
|
||||
@@ -0,0 +1,478 @@
|
||||
<script setup lang="ts">
|
||||
import { Loading, Refresh, VideoPlay, WarningFilled } from '@element-plus/icons-vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import QRCode from 'qrcode'
|
||||
import { computed, onBeforeUnmount, ref, watch } from 'vue'
|
||||
|
||||
import {
|
||||
createConfigTestPayment,
|
||||
refreshConfigTestPayment,
|
||||
type ConfigTestPayment,
|
||||
} from '@/features/admin/api/paymentConfigTest'
|
||||
import type { PaymentConfig } from '@/features/admin/api/paymentConfig'
|
||||
import { readError } from '@/shared/utils/error'
|
||||
|
||||
const props = defineProps<{
|
||||
modelValue: boolean
|
||||
config: PaymentConfig | null
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:modelValue': [value: boolean]
|
||||
changed: []
|
||||
}>()
|
||||
|
||||
const visible = computed({
|
||||
get: () => props.modelValue,
|
||||
set: value => emit('update:modelValue', value),
|
||||
})
|
||||
|
||||
const amountYuan = ref(0.01)
|
||||
const creating = ref(false)
|
||||
const refreshing = ref(false)
|
||||
const qrGenerating = ref(false)
|
||||
const qrDataUrl = ref('')
|
||||
const payment = ref<ConfigTestPayment | null>(null)
|
||||
let pollingTimer: number | undefined
|
||||
|
||||
const payUrl = computed(
|
||||
() => payment.value?.jspay_url || payment.value?.td_code || payment.value?.jspay_info || ''
|
||||
)
|
||||
const hasRenderablePayURL = computed(() => /^https?:\/\//i.test(payUrl.value))
|
||||
const terminal = computed(() =>
|
||||
payment.value ? ['paid', 'closed', 'failed'].includes(payment.value.status) : false
|
||||
)
|
||||
const statusLabel = computed(() => {
|
||||
const map: Record<string, string> = {
|
||||
created: '创建中',
|
||||
paying: '待扫码支付',
|
||||
paid: '已支付',
|
||||
failed: '失败',
|
||||
closed: '已关闭',
|
||||
}
|
||||
return map[payment.value?.status || ''] || payment.value?.status || ''
|
||||
})
|
||||
const statusType = computed(() => {
|
||||
if (payment.value?.status === 'paid') return 'success'
|
||||
if (payment.value?.status === 'failed') return 'danger'
|
||||
if (payment.value?.status === 'closed') return 'info'
|
||||
return 'warning'
|
||||
})
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
value => {
|
||||
if (value) {
|
||||
reset()
|
||||
} else {
|
||||
stopPolling()
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
watch(
|
||||
() => props.config?.id,
|
||||
() => {
|
||||
if (props.modelValue) reset()
|
||||
}
|
||||
)
|
||||
|
||||
onBeforeUnmount(stopPolling)
|
||||
|
||||
function reset() {
|
||||
stopPolling()
|
||||
amountYuan.value = 0.01
|
||||
payment.value = null
|
||||
qrDataUrl.value = ''
|
||||
qrGenerating.value = false
|
||||
creating.value = false
|
||||
refreshing.value = false
|
||||
}
|
||||
|
||||
async function startTestPayment() {
|
||||
if (!props.config) return
|
||||
const amountCent = Math.round(Number(amountYuan.value) * 100)
|
||||
if (!Number.isFinite(amountCent) || amountCent <= 0) {
|
||||
ElMessage.warning('测试金额必须大于 0')
|
||||
return
|
||||
}
|
||||
creating.value = true
|
||||
stopPolling()
|
||||
try {
|
||||
payment.value = await createConfigTestPayment(props.config.id, amountCent)
|
||||
await renderQRCode()
|
||||
emit('changed')
|
||||
if (!terminal.value) startPolling()
|
||||
} catch (error) {
|
||||
ElMessage.error(readError(error, '创建测试支付失败'))
|
||||
} finally {
|
||||
creating.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function refreshStatus(silent = false) {
|
||||
if (!payment.value || refreshing.value) return
|
||||
refreshing.value = true
|
||||
try {
|
||||
payment.value = await refreshConfigTestPayment(payment.value.id, silent)
|
||||
if (payment.value.status === 'paid') {
|
||||
stopPolling()
|
||||
if (!silent) ElMessage.success('测试支付已到账')
|
||||
} else if (payment.value.status === 'failed') {
|
||||
stopPolling()
|
||||
if (!silent) ElMessage.error(payment.value.error_message || '测试支付失败')
|
||||
} else if (payment.value.status === 'closed') {
|
||||
stopPolling()
|
||||
} else if (payment.value.status === 'paying' && payment.value.error_message && !silent) {
|
||||
ElMessage.warning(payment.value.error_message)
|
||||
}
|
||||
emit('changed')
|
||||
} catch (error) {
|
||||
if (!silent) ElMessage.error(readError(error, '查询测试支付状态失败'))
|
||||
} finally {
|
||||
refreshing.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function renderQRCode() {
|
||||
qrDataUrl.value = ''
|
||||
const url = payUrl.value
|
||||
if (!url || !/^https?:\/\//i.test(url)) return
|
||||
qrGenerating.value = true
|
||||
try {
|
||||
qrDataUrl.value = await QRCode.toDataURL(url, {
|
||||
width: 280,
|
||||
margin: 1,
|
||||
errorCorrectionLevel: 'M',
|
||||
color: { dark: '#111827', light: '#ffffff' },
|
||||
})
|
||||
} catch {
|
||||
ElMessage.error('二维码生成失败')
|
||||
} finally {
|
||||
qrGenerating.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function startPolling() {
|
||||
stopPolling()
|
||||
pollingTimer = window.setInterval(() => {
|
||||
void refreshStatus(true)
|
||||
}, 3000)
|
||||
}
|
||||
|
||||
function stopPolling() {
|
||||
if (pollingTimer === undefined) return
|
||||
window.clearInterval(pollingTimer)
|
||||
pollingTimer = undefined
|
||||
}
|
||||
|
||||
function formatAmount(cent: number) {
|
||||
return (Number(cent || 0) / 100).toFixed(2)
|
||||
}
|
||||
|
||||
function formatPayWay(value?: string) {
|
||||
return value === 'WXZF' ? '微信' : value === 'ZFBZF' ? '支付宝' : value || '-'
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<el-dialog
|
||||
v-model="visible"
|
||||
title="支付配置测试"
|
||||
width="720px"
|
||||
class="config-test-dialog"
|
||||
destroy-on-close
|
||||
@closed="stopPolling"
|
||||
>
|
||||
<div v-if="config" class="test-shell">
|
||||
<div class="config-summary">
|
||||
<div>
|
||||
<span class="summary-label">配置</span>
|
||||
<strong>{{ config.name }}</strong>
|
||||
</div>
|
||||
<div>
|
||||
<span class="summary-label">服务商</span>
|
||||
<strong>{{ config.provider }}</strong>
|
||||
</div>
|
||||
<div>
|
||||
<span class="summary-label">商户号</span>
|
||||
<strong>{{ config.merchant_id }}</strong>
|
||||
</div>
|
||||
<div>
|
||||
<span class="summary-label">支付方式</span>
|
||||
<strong>{{ formatPayWay(config.pay_way) }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<el-alert
|
||||
v-if="config.environment === 'production' || config.status !== 'active'"
|
||||
type="warning"
|
||||
:closable="false"
|
||||
show-icon
|
||||
class="test-warning"
|
||||
>
|
||||
当前为{{
|
||||
config.environment === 'production' ? '生产环境' : '非启用状态'
|
||||
}}配置,本次测试会产生真实渠道订单。
|
||||
</el-alert>
|
||||
|
||||
<div class="amount-row">
|
||||
<div>
|
||||
<span class="summary-label">测试金额(元)</span>
|
||||
<p class="amount-tip">默认 0.01 元,可修改;真实扫码支付会实际扣款。</p>
|
||||
</div>
|
||||
<el-input-number
|
||||
v-model="amountYuan"
|
||||
:min="0.01"
|
||||
:step="0.01"
|
||||
:precision="2"
|
||||
size="large"
|
||||
controls-position="right"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="test-actions">
|
||||
<el-button
|
||||
type="primary"
|
||||
size="large"
|
||||
:icon="VideoPlay"
|
||||
:loading="creating"
|
||||
@click="startTestPayment"
|
||||
>
|
||||
{{ payment ? '重新生成测试支付' : '生成支付二维码' }}
|
||||
</el-button>
|
||||
<el-button
|
||||
v-if="payment"
|
||||
:icon="Refresh"
|
||||
size="large"
|
||||
:loading="refreshing"
|
||||
@click="refreshStatus(false)"
|
||||
>
|
||||
刷新状态
|
||||
</el-button>
|
||||
</div>
|
||||
|
||||
<div v-if="payment" class="payment-result">
|
||||
<div class="result-head">
|
||||
<div>
|
||||
<span class="summary-label">测试单号</span>
|
||||
<strong class="mono">{{ payment.test_no }}</strong>
|
||||
</div>
|
||||
<el-tag :type="statusType" effect="light">{{ statusLabel }}</el-tag>
|
||||
</div>
|
||||
|
||||
<div v-if="payment.status === 'paying'" class="qr-area">
|
||||
<div class="qr-box">
|
||||
<el-icon v-if="qrGenerating" class="is-loading" :size="32"><Loading /></el-icon>
|
||||
<img v-else-if="qrDataUrl" :src="qrDataUrl" alt="测试支付二维码" />
|
||||
<el-icon v-else :size="42"><WarningFilled /></el-icon>
|
||||
</div>
|
||||
<div class="qr-copy">
|
||||
<h3>
|
||||
请使用{{ formatPayWay(payment.pay_way) }}扫码支付 ¥{{
|
||||
formatAmount(payment.amount_cent)
|
||||
}}
|
||||
</h3>
|
||||
<p>支付完成后系统会自动查单;也可以点击“刷新状态”立即查询。</p>
|
||||
<p class="mono">渠道单号:{{ payment.provider_order_id || '等待渠道返回' }}</p>
|
||||
<el-alert
|
||||
v-if="!hasRenderablePayURL"
|
||||
type="warning"
|
||||
:closable="false"
|
||||
show-icon
|
||||
title="渠道未返回可识别的支付链接,请查看测试记录或稍后刷新状态"
|
||||
/>
|
||||
<el-alert
|
||||
v-else-if="payment.error_message"
|
||||
type="warning"
|
||||
:closable="false"
|
||||
show-icon
|
||||
:title="payment.error_message"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<el-alert
|
||||
v-if="payment.status === 'paid'"
|
||||
type="success"
|
||||
:closable="false"
|
||||
show-icon
|
||||
title="测试支付已成功"
|
||||
:description="`支付时间:${payment.paid_at || payment.updated_at}`"
|
||||
/>
|
||||
<el-alert
|
||||
v-else-if="payment.status === 'failed'"
|
||||
type="error"
|
||||
:closable="false"
|
||||
show-icon
|
||||
title="测试支付失败"
|
||||
:description="payment.error_message || '请查看测试支付记录中的渠道报文'"
|
||||
/>
|
||||
<el-alert
|
||||
v-else-if="payment.status === 'closed'"
|
||||
type="info"
|
||||
:closable="false"
|
||||
show-icon
|
||||
title="测试支付已关闭"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
<el-button @click="visible = false">关闭</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.test-shell {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 18px;
|
||||
}
|
||||
|
||||
.config-summary {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
gap: 12px;
|
||||
padding: 16px;
|
||||
border: 1px solid #e2e8f0;
|
||||
border-radius: 12px;
|
||||
background: #f8fafc;
|
||||
}
|
||||
|
||||
.config-summary > div,
|
||||
.result-head > div {
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.summary-label {
|
||||
color: #64748b;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.config-summary strong,
|
||||
.result-head strong {
|
||||
overflow: hidden;
|
||||
color: #0f172a;
|
||||
font-size: 13px;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.test-warning {
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
.amount-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 24px;
|
||||
padding: 16px 18px;
|
||||
border: 1px solid #e2e8f0;
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
.amount-row :deep(.el-input-number) {
|
||||
width: 180px;
|
||||
}
|
||||
|
||||
.amount-tip {
|
||||
margin: 5px 0 0;
|
||||
color: #94a3b8;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.test-actions {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.payment-result {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
padding-top: 4px;
|
||||
}
|
||||
|
||||
.result-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.mono {
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
||||
}
|
||||
|
||||
.qr-area {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 24px;
|
||||
padding: 18px;
|
||||
border: 1px solid #dbeafe;
|
||||
border-radius: 14px;
|
||||
background: linear-gradient(135deg, #eff6ff, #ffffff);
|
||||
}
|
||||
|
||||
.qr-box {
|
||||
display: grid;
|
||||
width: 240px;
|
||||
height: 240px;
|
||||
flex: 0 0 240px;
|
||||
place-items: center;
|
||||
border: 1px solid #e2e8f0;
|
||||
border-radius: 12px;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.qr-box img {
|
||||
width: 224px;
|
||||
height: 224px;
|
||||
}
|
||||
|
||||
.qr-copy h3 {
|
||||
margin: 0 0 10px;
|
||||
color: #0f172a;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.qr-copy p {
|
||||
margin: 6px 0;
|
||||
color: #64748b;
|
||||
font-size: 12.5px;
|
||||
line-height: 1.6;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
@media (max-width: 720px) {
|
||||
.config-summary {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.amount-row,
|
||||
.qr-area {
|
||||
align-items: stretch;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.qr-box {
|
||||
width: 220px;
|
||||
height: 220px;
|
||||
flex-basis: 220px;
|
||||
align-self: center;
|
||||
}
|
||||
|
||||
.qr-box img {
|
||||
width: 204px;
|
||||
height: 204px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,508 @@
|
||||
<script setup lang="ts">
|
||||
import { Refresh, Search, View } from '@element-plus/icons-vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { computed, reactive, ref, watch } from 'vue'
|
||||
|
||||
import {
|
||||
fetchConfigTestPayment,
|
||||
fetchConfigTestPayments,
|
||||
refreshConfigTestPayment,
|
||||
type ConfigTestPayment,
|
||||
} from '@/features/admin/api/paymentConfigTest'
|
||||
import { fetchPaymentConfigs, type PaymentConfig } from '@/features/admin/api/paymentConfig'
|
||||
import { readError } from '@/shared/utils/error'
|
||||
import { formatDateTime } from '@/shared/utils/time'
|
||||
|
||||
const props = defineProps<{
|
||||
modelValue: boolean
|
||||
configs: PaymentConfig[]
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:modelValue': [value: boolean]
|
||||
}>()
|
||||
|
||||
const visible = computed({
|
||||
get: () => props.modelValue,
|
||||
set: value => emit('update:modelValue', value),
|
||||
})
|
||||
|
||||
const loading = ref(false)
|
||||
const refreshingID = ref(0)
|
||||
const records = ref<ConfigTestPayment[]>([])
|
||||
const total = ref(0)
|
||||
const page = ref(1)
|
||||
const pageSize = ref(20)
|
||||
const detailVisible = ref(false)
|
||||
const detailLoading = ref(false)
|
||||
const activeRecord = ref<ConfigTestPayment | null>(null)
|
||||
const configOptions = ref<PaymentConfig[]>([])
|
||||
const hasChainPayloads = computed(() =>
|
||||
Boolean(
|
||||
activeRecord.value &&
|
||||
(activeRecord.value.create_request ||
|
||||
activeRecord.value.create_response ||
|
||||
activeRecord.value.query_request ||
|
||||
activeRecord.value.query_response ||
|
||||
activeRecord.value.notify_request ||
|
||||
activeRecord.value.notify_result ||
|
||||
activeRecord.value.notify_ack)
|
||||
)
|
||||
)
|
||||
|
||||
const filters = reactive({
|
||||
payment_config_id: '',
|
||||
provider: '',
|
||||
status: '',
|
||||
test_no: '',
|
||||
})
|
||||
|
||||
const providerOptions = [
|
||||
{ label: '全部服务商', value: '' },
|
||||
{ label: '乐刷支付', value: 'leshua' },
|
||||
{ label: '拉卡拉支付', value: 'lakala' },
|
||||
{ label: '顺成支付', value: 'shuncheng' },
|
||||
{ label: '扫呗支付', value: 'saobei' },
|
||||
{ label: '模拟支付', value: 'mock' },
|
||||
]
|
||||
|
||||
const statusOptions = [
|
||||
{ label: '全部状态', value: '' },
|
||||
{ label: '创建中', value: 'created' },
|
||||
{ label: '待扫码支付', value: 'paying' },
|
||||
{ label: '已支付', value: 'paid' },
|
||||
{ label: '失败', value: 'failed' },
|
||||
{ label: '已关闭', value: 'closed' },
|
||||
]
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
value => {
|
||||
if (value) {
|
||||
configOptions.value = props.configs
|
||||
page.value = 1
|
||||
void loadConfigOptions()
|
||||
void loadRecords()
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
async function loadConfigOptions() {
|
||||
try {
|
||||
const result = await fetchPaymentConfigs({ page: 1, page_size: 100 })
|
||||
configOptions.value = result.items
|
||||
} catch {
|
||||
configOptions.value = props.configs
|
||||
}
|
||||
}
|
||||
|
||||
async function loadRecords() {
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await fetchConfigTestPayments({
|
||||
payment_config_id: filters.payment_config_id ? Number(filters.payment_config_id) : undefined,
|
||||
provider: filters.provider || undefined,
|
||||
status: filters.status || undefined,
|
||||
test_no: filters.test_no.trim() || undefined,
|
||||
page: page.value,
|
||||
page_size: pageSize.value,
|
||||
})
|
||||
records.value = result.items
|
||||
total.value = result.total
|
||||
} catch (error) {
|
||||
records.value = []
|
||||
total.value = 0
|
||||
ElMessage.error(readError(error, '加载测试支付记录失败'))
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function resetFilters() {
|
||||
filters.payment_config_id = ''
|
||||
filters.provider = ''
|
||||
filters.status = ''
|
||||
filters.test_no = ''
|
||||
page.value = 1
|
||||
void loadRecords()
|
||||
}
|
||||
|
||||
async function refreshRecord(row: ConfigTestPayment) {
|
||||
refreshingID.value = row.id
|
||||
try {
|
||||
const latest = await refreshConfigTestPayment(row.id)
|
||||
const index = records.value.findIndex(item => item.id === latest.id)
|
||||
if (index >= 0) records.value[index] = latest
|
||||
if (activeRecord.value?.id === latest.id) activeRecord.value = latest
|
||||
ElMessage.success(latest.status === 'paid' ? '已确认支付成功' : '状态已刷新')
|
||||
} catch (error) {
|
||||
ElMessage.error(readError(error, '刷新测试支付状态失败'))
|
||||
} finally {
|
||||
refreshingID.value = 0
|
||||
}
|
||||
}
|
||||
|
||||
async function openDetail(row: ConfigTestPayment) {
|
||||
activeRecord.value = row
|
||||
detailVisible.value = true
|
||||
detailLoading.value = true
|
||||
try {
|
||||
activeRecord.value = await fetchConfigTestPayment(row.id)
|
||||
} catch (error) {
|
||||
ElMessage.error(readError(error, '加载测试支付详情失败'))
|
||||
} finally {
|
||||
detailLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function statusLabel(status: string) {
|
||||
const map: Record<string, string> = {
|
||||
created: '创建中',
|
||||
paying: '待扫码支付',
|
||||
paid: '已支付',
|
||||
failed: '失败',
|
||||
closed: '已关闭',
|
||||
}
|
||||
return map[status] || status
|
||||
}
|
||||
|
||||
function statusType(status: string): 'success' | 'danger' | 'warning' | 'info' {
|
||||
if (status === 'paid') return 'success'
|
||||
if (status === 'failed') return 'danger'
|
||||
if (status === 'closed') return 'info'
|
||||
return 'warning'
|
||||
}
|
||||
|
||||
function environmentLabel(value: string) {
|
||||
if (value === 'production') return '生产环境'
|
||||
if (value === 'sandbox') return '测试环境'
|
||||
return value || '-'
|
||||
}
|
||||
|
||||
function providerLabel(provider: string) {
|
||||
const map: Record<string, string> = {
|
||||
leshua: '乐刷支付',
|
||||
lakala: '拉卡拉支付',
|
||||
shuncheng: '顺成支付',
|
||||
saobei: '扫呗支付',
|
||||
mock: '模拟支付',
|
||||
}
|
||||
return map[provider] || provider
|
||||
}
|
||||
|
||||
function payWayLabel(value: string) {
|
||||
return value === 'WXZF' ? '微信' : value === 'ZFBZF' ? '支付宝' : value || '-'
|
||||
}
|
||||
|
||||
function money(cent: number) {
|
||||
return `¥${(Number(cent || 0) / 100).toFixed(2)}`
|
||||
}
|
||||
|
||||
function jsonText(value: unknown) {
|
||||
if (!value) return '{}'
|
||||
try {
|
||||
return JSON.stringify(value, null, 2)
|
||||
} catch {
|
||||
return String(value)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<el-drawer v-model="visible" title="测试支付记录" size="76%" destroy-on-close>
|
||||
<div class="records-shell">
|
||||
<div class="filter-bar">
|
||||
<el-select
|
||||
v-model="filters.payment_config_id"
|
||||
placeholder="支付配置"
|
||||
clearable
|
||||
class="filter-select"
|
||||
>
|
||||
<el-option
|
||||
v-for="config in configOptions"
|
||||
:key="config.id"
|
||||
:label="config.name"
|
||||
:value="String(config.id)"
|
||||
/>
|
||||
</el-select>
|
||||
<el-select v-model="filters.provider" placeholder="服务商" class="filter-select">
|
||||
<el-option
|
||||
v-for="item in providerOptions"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value"
|
||||
/>
|
||||
</el-select>
|
||||
<el-select v-model="filters.status" placeholder="状态" class="filter-select">
|
||||
<el-option
|
||||
v-for="item in statusOptions"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value"
|
||||
/>
|
||||
</el-select>
|
||||
<el-input
|
||||
v-model="filters.test_no"
|
||||
placeholder="测试单号"
|
||||
clearable
|
||||
class="filter-input"
|
||||
@keyup.enter="loadRecords"
|
||||
/>
|
||||
<el-button :icon="Search" type="primary" @click="loadRecords">查询</el-button>
|
||||
<el-button :icon="Refresh" @click="resetFilters">重置</el-button>
|
||||
</div>
|
||||
|
||||
<el-table v-loading="loading" :data="records" stripe class="records-table">
|
||||
<el-table-column prop="test_no" label="测试单号" min-width="230">
|
||||
<template #default="{ row }">
|
||||
<span class="mono">{{ row.test_no }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
prop="config_name"
|
||||
label="支付配置"
|
||||
min-width="180"
|
||||
show-overflow-tooltip
|
||||
/>
|
||||
<el-table-column label="服务商 / 方式" min-width="150">
|
||||
<template #default="{ row }">
|
||||
<div class="provider-cell">
|
||||
<span>{{ providerLabel(row.provider) }}</span>
|
||||
<small>{{ payWayLabel(row.pay_way) }}</small>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="金额" width="110" align="right">
|
||||
<template #default="{ row }">
|
||||
<strong>{{ money(row.amount_cent) }}</strong>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="状态" width="110" align="center">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="statusType(row.status)" effect="light">{{
|
||||
statusLabel(row.status)
|
||||
}}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="渠道单号" min-width="170" show-overflow-tooltip>
|
||||
<template #default="{ row }">
|
||||
<span class="mono muted">{{ row.provider_order_id || '-' }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="创建时间" width="170">
|
||||
<template #default="{ row }">{{ formatDateTime(row.created_at) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="150" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button link type="primary" :icon="View" @click="openDetail(row)">详情</el-button>
|
||||
<el-button
|
||||
v-if="!['paid', 'failed', 'closed'].includes(row.status)"
|
||||
link
|
||||
type="success"
|
||||
:icon="Refresh"
|
||||
:loading="refreshingID === row.id"
|
||||
@click="refreshRecord(row)"
|
||||
>
|
||||
刷状态
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<div class="pagination-row">
|
||||
<el-pagination
|
||||
v-model:current-page="page"
|
||||
v-model:page-size="pageSize"
|
||||
:total="total"
|
||||
:page-sizes="[10, 20, 50, 100]"
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
@current-change="loadRecords"
|
||||
@size-change="loadRecords"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<el-dialog v-model="detailVisible" title="测试支付详情" width="720px" append-to-body>
|
||||
<div v-if="activeRecord" v-loading="detailLoading" class="detail-shell">
|
||||
<el-descriptions :column="2" border>
|
||||
<el-descriptions-item label="测试单号">{{ activeRecord.test_no }}</el-descriptions-item>
|
||||
<el-descriptions-item label="状态">
|
||||
<el-tag :type="statusType(activeRecord.status)">{{
|
||||
statusLabel(activeRecord.status)
|
||||
}}</el-tag>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="支付配置">{{
|
||||
activeRecord.config_name
|
||||
}}</el-descriptions-item>
|
||||
<el-descriptions-item label="服务商">{{
|
||||
providerLabel(activeRecord.provider)
|
||||
}}</el-descriptions-item>
|
||||
<el-descriptions-item label="商户号">{{ activeRecord.merchant_id }}</el-descriptions-item>
|
||||
<el-descriptions-item label="支付方式">{{
|
||||
payWayLabel(activeRecord.pay_way)
|
||||
}}</el-descriptions-item>
|
||||
<el-descriptions-item label="测试金额">{{
|
||||
money(activeRecord.amount_cent)
|
||||
}}</el-descriptions-item>
|
||||
<el-descriptions-item label="环境">{{
|
||||
environmentLabel(activeRecord.environment)
|
||||
}}</el-descriptions-item>
|
||||
<el-descriptions-item label="渠道订单号" :span="2">
|
||||
{{ activeRecord.provider_order_id || '-' }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="错误信息" :span="2">
|
||||
{{ activeRecord.error_message || '-' }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="创建时间">{{
|
||||
formatDateTime(activeRecord.created_at)
|
||||
}}</el-descriptions-item>
|
||||
<el-descriptions-item label="支付时间">
|
||||
{{ activeRecord.paid_at ? formatDateTime(activeRecord.paid_at) : '-' }}
|
||||
</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
|
||||
<div v-if="hasChainPayloads" class="payload-grid">
|
||||
<div v-if="activeRecord.create_request" class="payload-item">
|
||||
<h4>下单请求</h4>
|
||||
<pre class="payload-code">{{ jsonText(activeRecord.create_request) }}</pre>
|
||||
</div>
|
||||
<div v-if="activeRecord.create_response" class="payload-item">
|
||||
<h4>下单响应</h4>
|
||||
<pre class="payload-code">{{ jsonText(activeRecord.create_response) }}</pre>
|
||||
</div>
|
||||
<div v-if="activeRecord.query_request" class="payload-item">
|
||||
<h4>最近一次查单请求</h4>
|
||||
<pre class="payload-code">{{ jsonText(activeRecord.query_request) }}</pre>
|
||||
</div>
|
||||
<div v-if="activeRecord.query_response" class="payload-item">
|
||||
<h4>最近一次查单响应</h4>
|
||||
<pre class="payload-code">{{ jsonText(activeRecord.query_response) }}</pre>
|
||||
</div>
|
||||
<div v-if="activeRecord.notify_request" class="payload-item">
|
||||
<h4>支付回调请求</h4>
|
||||
<pre class="payload-code">{{ jsonText(activeRecord.notify_request) }}</pre>
|
||||
</div>
|
||||
<div v-if="activeRecord.notify_result" class="payload-item">
|
||||
<h4>回调处理结果</h4>
|
||||
<pre class="payload-code">{{ jsonText(activeRecord.notify_result) }}</pre>
|
||||
</div>
|
||||
<div v-if="activeRecord.notify_ack" class="payload-item">
|
||||
<h4>返回渠道应答</h4>
|
||||
<pre class="payload-code">{{ activeRecord.notify_ack }}</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else-if="activeRecord.raw_request || activeRecord.raw_response" class="payload-grid">
|
||||
<div v-if="activeRecord.raw_request" class="payload-item">
|
||||
<h4>历史下单请求</h4>
|
||||
<pre class="payload-code">{{ jsonText(activeRecord.raw_request) }}</pre>
|
||||
</div>
|
||||
<div v-if="activeRecord.raw_response" class="payload-item">
|
||||
<h4>历史渠道响应</h4>
|
||||
<pre class="payload-code">{{ jsonText(activeRecord.raw_response) }}</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="payload-empty">暂无报文</div>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</el-drawer>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.records-shell {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.filter-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.filter-select {
|
||||
width: 160px;
|
||||
}
|
||||
|
||||
.filter-input {
|
||||
width: 210px;
|
||||
}
|
||||
|
||||
.records-table {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.mono {
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.muted {
|
||||
color: #64748b;
|
||||
}
|
||||
|
||||
.provider-cell {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.provider-cell small {
|
||||
color: #94a3b8;
|
||||
}
|
||||
|
||||
.pagination-row {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.detail-shell {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 18px;
|
||||
}
|
||||
|
||||
.payload-item {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.payload-empty {
|
||||
padding: 24px;
|
||||
border: 1px dashed #cbd5e1;
|
||||
border-radius: 10px;
|
||||
color: #94a3b8;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.payload-grid {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
gap: 14px;
|
||||
}
|
||||
|
||||
.payload-grid h4 {
|
||||
margin: 0 0 8px;
|
||||
color: #475569;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.payload-grid pre.payload-code {
|
||||
box-sizing: border-box;
|
||||
min-width: 0;
|
||||
min-height: 180px;
|
||||
max-height: 320px;
|
||||
margin: 0;
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-all;
|
||||
overflow-wrap: anywhere;
|
||||
border-radius: 10px;
|
||||
background: #0f172a !important;
|
||||
color: #e2e8f0 !important;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
||||
font-size: 12px;
|
||||
padding: 12px;
|
||||
}
|
||||
</style>
|
||||
@@ -10,6 +10,8 @@ import {
|
||||
Download,
|
||||
Upload,
|
||||
StarFilled,
|
||||
Tickets,
|
||||
VideoPlay,
|
||||
} from '@element-plus/icons-vue'
|
||||
|
||||
import {
|
||||
@@ -21,6 +23,8 @@ import {
|
||||
} from '@/features/admin/api/paymentConfig'
|
||||
import { readError } from '@/shared/utils/error'
|
||||
import PaymentConfigDialog from '../components/PaymentConfigDialog.vue'
|
||||
import PaymentConfigTestDialog from '../components/PaymentConfigTestDialog.vue'
|
||||
import PaymentConfigTestRecordsDrawer from '../components/PaymentConfigTestRecordsDrawer.vue'
|
||||
|
||||
const loading = ref(false)
|
||||
const configs = ref<PaymentConfig[]>([])
|
||||
@@ -34,6 +38,9 @@ const backupFileInput = ref<HTMLInputElement | null>(null)
|
||||
const dialogVisible = ref(false)
|
||||
const dialogMode = ref<'create' | 'edit' | 'view'>('create')
|
||||
const currentConfig = ref<PaymentConfig | null>(null)
|
||||
const testDialogVisible = ref(false)
|
||||
const testConfig = ref<PaymentConfig | null>(null)
|
||||
const testRecordsVisible = ref(false)
|
||||
|
||||
const filterProvider = ref('')
|
||||
const filterPayWay = ref('')
|
||||
@@ -110,6 +117,11 @@ function handleEdit(row: PaymentConfig) {
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
function handleTest(row: PaymentConfig) {
|
||||
testConfig.value = row
|
||||
testDialogVisible.value = true
|
||||
}
|
||||
|
||||
async function handleDelete(row: PaymentConfig) {
|
||||
if (!canDeleteConfig(row)) {
|
||||
ElMessage.warning('该配置已有交易记录,需要保留用于退款、查询和回调验签')
|
||||
@@ -315,6 +327,7 @@ function deleteDisabledReason(row: PaymentConfig) {
|
||||
</div>
|
||||
|
||||
<div class="toolbar-actions">
|
||||
<el-button :icon="Tickets" @click="testRecordsVisible = true">测试支付记录</el-button>
|
||||
<el-button :icon="Upload" :loading="importing" @click="handleImportBackup">
|
||||
导入备份
|
||||
</el-button>
|
||||
@@ -448,9 +461,17 @@ function deleteDisabledReason(row: PaymentConfig) {
|
||||
<span v-else class="standby-badge">备用</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="226" class-name="operation-column">
|
||||
<el-table-column label="操作" width="286" class-name="operation-column">
|
||||
<template #default="{ row }">
|
||||
<div class="action-buttons">
|
||||
<el-button
|
||||
class="action-button test"
|
||||
size="small"
|
||||
:icon="VideoPlay"
|
||||
@click="handleTest(row)"
|
||||
>
|
||||
测试
|
||||
</el-button>
|
||||
<el-button
|
||||
class="action-button view"
|
||||
size="small"
|
||||
@@ -506,6 +527,9 @@ function deleteDisabledReason(row: PaymentConfig) {
|
||||
@close="handleDialogClose"
|
||||
@saved="handleSaved"
|
||||
/>
|
||||
|
||||
<PaymentConfigTestDialog v-model="testDialogVisible" :config="testConfig" />
|
||||
<PaymentConfigTestRecordsDrawer v-model="testRecordsVisible" :configs="configs" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -783,6 +807,18 @@ function deleteDisabledReason(row: PaymentConfig) {
|
||||
padding: 0 10px;
|
||||
}
|
||||
|
||||
.action-button.test {
|
||||
color: #7c3aed;
|
||||
background: #f5f3ff;
|
||||
border-color: #ddd6fe;
|
||||
}
|
||||
|
||||
.action-button.test:hover {
|
||||
color: #ffffff;
|
||||
background: #7c3aed;
|
||||
border-color: #7c3aed;
|
||||
}
|
||||
|
||||
.action-button.view {
|
||||
color: #1d4ed8;
|
||||
background: #eff6ff;
|
||||
|
||||
Reference in New Issue
Block a user