This commit is contained in:
2026-06-26 18:14:26 +08:00
parent f604791c69
commit 1baa6d87cf
10 changed files with 404 additions and 30 deletions

3
.gitignore vendored
View File

@@ -27,3 +27,6 @@ npminstall-debug.log
# ai # ai
.agents .agents
#build
one-pipe-system-dist.zip

View File

@@ -13,3 +13,9 @@ This context captures the business language used by the admin system for orders,
**Operational batch task**: An asynchronous admin task created from an uploaded batch import file and tracked through task status, counts, operator identity, and failure details. _Avoid_: Inline order operation, synchronous import **Operational batch task**: An asynchronous admin task created from an uploaded batch import file and tracked through task status, counts, operator identity, and failure details. _Avoid_: Inline order operation, synchronous import
**Operational remark**: A note captured when an admin creates a financial or operational record. Operational remarks are retained for later review and are not edited after creation. _Avoid_: Editable comment, processing note **Operational remark**: A note captured when an admin creates a financial or operational record. Operational remarks are retained for later review and are not edited after creation. _Avoid_: Editable comment, processing note
**Recharge order**: A C-side asset recharge order created when a user recharges an IoT card or device asset wallet. It is identified by `recharge_order_no`, is associated with `resource_type` and `resource_id`, and may be rejected while pending payment. _Avoid_: Agent recharge order
**Rejected recharge order**: A recharge order that an admin has rejected before payment because the recharge request should not proceed. Rejection is an irreversible terminal state and does not involve refunds. _Avoid_: Refunded recharge, closed recharge
**Agent recharge order**: A financial recharge record for an agent/shop wallet in the admin finance module. It uses a different API contract and status model from C-side recharge orders. _Avoid_: Recharge order

View File

@@ -0,0 +1,110 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import { mkdtemp, rm, stat } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { pathToFileURL } from 'node:url'
import * as esbuild from 'esbuild'
async function resolveSrcAlias(path) {
const resolvedPath = join(process.cwd(), 'src', path.slice(2))
try {
if ((await stat(resolvedPath)).isDirectory()) {
return join(resolvedPath, 'index.ts')
}
} catch {
// Let esbuild report the original resolution failure.
}
return resolvedPath
}
async function importBundledActions() {
const tempDir = await mkdtemp(join(tmpdir(), 'agent-recharge-actions-'))
const bundlePath = join(tempDir, 'agentRechargeActions.mjs')
await esbuild.build({
entryPoints: ['src/views/finance/agent-recharge/agentRechargeActions.ts'],
bundle: true,
outfile: bundlePath,
format: 'esm',
platform: 'node',
absWorkingDir: process.cwd(),
plugins: [
{
name: 'alias-src',
setup(build) {
build.onResolve({ filter: /^@\// }, async (args) => ({
path: await resolveSrcAlias(args.path)
}))
}
}
]
})
const module = await import(pathToFileURL(bundlePath).href)
return {
module,
cleanup: () => rm(tempDir, { recursive: true, force: true })
}
}
test('pending agent recharge exposes reject action for admins with rejection permission', async () => {
const { module, cleanup } = await importBundledActions()
const { buildAgentRechargeActions } = module
const row = {
id: 42,
status: 1,
payment_method: 'wechat',
payment_voucher_key: []
}
const handledRows = []
try {
const actions = buildAgentRechargeActions(row, {
hasAuth: (permission) => permission === 'agent_recharge:reject',
onViewPaymentVoucher: () => {},
onConfirmPayment: () => {},
onReject: (recharge) => handledRows.push(recharge)
})
assert.deepEqual(
actions.map((action) => action.label),
['拒绝']
)
actions[0].handler()
assert.deepEqual(handledRows, [row])
} finally {
await cleanup()
}
})
test('non-pending agent recharge does not expose reject action', async () => {
const { module, cleanup } = await importBundledActions()
const { buildAgentRechargeActions } = module
const row = {
id: 42,
status: 2,
payment_method: 'wechat',
payment_voucher_key: []
}
try {
const actions = buildAgentRechargeActions(row, {
hasAuth: (permission) => permission === 'agent_recharge:reject',
onViewPaymentVoucher: () => {},
onConfirmPayment: () => {},
onReject: () => {}
})
assert.deepEqual(
actions.map((action) => action.label),
[]
)
} finally {
await cleanup()
}
})

View File

@@ -0,0 +1,49 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import { mkdtemp, rm } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { pathToFileURL } from 'node:url'
import * as esbuild from 'esbuild'
async function importBundledDisplay() {
const tempDir = await mkdtemp(join(tmpdir(), 'agent-recharge-display-'))
const bundlePath = join(tempDir, 'agentRechargeDisplay.mjs')
await esbuild.build({
entryPoints: ['src/views/finance/agent-recharge/agentRechargeDisplay.ts'],
bundle: true,
outfile: bundlePath,
format: 'esm',
platform: 'node',
absWorkingDir: process.cwd()
})
const module = await import(pathToFileURL(bundlePath).href)
return {
module,
cleanup: () => rm(tempDir, { recursive: true, force: true })
}
}
test('agent recharge rejection reason display uses backend rejection_reason when present', async () => {
const { module, cleanup } = await importBundledDisplay()
try {
assert.equal(module.formatRejectionReason('凭证不清晰'), '凭证不清晰')
} finally {
await cleanup()
}
})
test('agent recharge rejection reason display falls back to dash when absent', async () => {
const { module, cleanup } = await importBundledDisplay()
try {
assert.equal(module.formatRejectionReason(''), '-')
assert.equal(module.formatRejectionReason(null), '-')
assert.equal(module.formatRejectionReason(undefined), '-')
} finally {
await cleanup()
}
})

View File

@@ -0,0 +1,69 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import { mkdtemp, rm, writeFile } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { pathToFileURL } from 'node:url'
import * as esbuild from 'esbuild'
test('agent recharge rejection posts the rejection reason to the order rejection endpoint', async () => {
const calls = []
const tempDir = await mkdtemp(join(tmpdir(), 'agent-recharge-service-'))
const bundlePath = join(tempDir, 'agentRechargeService.mjs')
const httpMockPath = join(tempDir, 'httpMock.mjs')
await writeFile(
httpMockPath,
`
export const calls = globalThis.__agentRechargeHttpCalls
export default {
post(options) {
calls.push(options)
return Promise.resolve({ code: 0, data: undefined })
}
}
`,
'utf8'
)
globalThis.__agentRechargeHttpCalls = calls
try {
await esbuild.build({
entryPoints: ['src/api/modules/agentRecharge.ts'],
bundle: true,
outfile: bundlePath,
format: 'esm',
platform: 'node',
absWorkingDir: process.cwd(),
plugins: [
{
name: 'mock-http-boundary',
setup(build) {
build.onResolve({ filter: /^@\/utils\/http$/ }, () => ({
path: httpMockPath
}))
}
}
]
})
const { AgentRechargeService } = await import(pathToFileURL(bundlePath).href)
await AgentRechargeService.rejectAgentRecharge(42, {
reject_reason: '支付凭证不符合要求'
})
assert.deepEqual(calls, [
{
url: '/api/admin/agent-recharges/42/reject',
data: {
reject_reason: '支付凭证不符合要求'
}
}
])
} finally {
delete globalThis.__agentRechargeHttpCalls
await rm(tempDir, { recursive: true, force: true })
}
})

View File

@@ -9,6 +9,7 @@ import type {
AgentRechargeListResponse, AgentRechargeListResponse,
CreateAgentRechargeRequest, CreateAgentRechargeRequest,
ConfirmOfflinePaymentRequest, ConfirmOfflinePaymentRequest,
RejectAgentRechargeRequest,
BaseResponse BaseResponse
} from '@/types/api' } from '@/types/api'
@@ -55,4 +56,16 @@ export class AgentRechargeService extends BaseService {
data data
) )
} }
/**
* 拒绝代理充值订单
* @param id 充值订单ID
* @param data 拒绝请求参数
*/
static rejectAgentRecharge(
id: number,
data: RejectAgentRechargeRequest
): Promise<BaseResponse<void>> {
return this.post<BaseResponse<void>>(`/api/admin/agent-recharges/${id}/reject`, data)
}
} }

View File

@@ -72,3 +72,8 @@ export interface CreateAgentRechargeRequest {
export interface ConfirmOfflinePaymentRequest { export interface ConfirmOfflinePaymentRequest {
operation_password: string operation_password: string
} }
// 拒绝代理充值订单请求
export interface RejectAgentRechargeRequest {
reject_reason: string
}

View File

@@ -0,0 +1,56 @@
import { AgentRechargeStatus, type AgentRecharge } from '@/types/api'
import { hasVoucherKeys } from '@/utils/business'
export interface AgentRechargeAction {
label: string
handler: () => void
type: 'primary' | 'danger'
}
interface BuildAgentRechargeActionsOptions {
hasAuth: (permission: string) => boolean
onViewPaymentVoucher: (row: AgentRecharge) => void
onConfirmPayment: (row: AgentRecharge) => void
onReject: (row: AgentRecharge) => void
}
export const buildAgentRechargeActions = (
row: AgentRecharge,
options: BuildAgentRechargeActionsOptions
): AgentRechargeAction[] => {
const actions: AgentRechargeAction[] = []
if (
row.payment_method === 'offline' &&
hasVoucherKeys(row.payment_voucher_key) &&
options.hasAuth('agent_recharge:view_payment_voucher')
) {
actions.push({
label: '查看支付凭证',
handler: () => options.onViewPaymentVoucher(row),
type: 'primary'
})
}
if (
row.status === AgentRechargeStatus.PENDING &&
row.payment_method === 'offline' &&
options.hasAuth('agent_recharge:confirm_payment')
) {
actions.push({
label: '确认支付',
handler: () => options.onConfirmPayment(row),
type: 'primary'
})
}
if (row.status === AgentRechargeStatus.PENDING && options.hasAuth('agent_recharge:reject')) {
actions.push({
label: '拒绝',
handler: () => options.onReject(row),
type: 'danger'
})
}
return actions
}

View File

@@ -0,0 +1,3 @@
export const formatRejectionReason = (reason?: string | null): string => {
return reason || '-'
}

View File

@@ -167,6 +167,38 @@
</template> </template>
</ElDialog> </ElDialog>
<!-- 拒绝充值订单对话框 -->
<ElDialog
v-model="rejectDialogVisible"
title="拒绝充值订单"
width="500px"
@closed="handleRejectDialogClosed"
>
<ElForm ref="rejectFormRef" :model="rejectForm" :rules="rejectRules" label-width="100px">
<ElFormItem label="充值单号">
<span>{{ currentRecharge?.recharge_no }}</span>
</ElFormItem>
<ElFormItem label="拒绝原因" prop="reject_reason">
<ElInput
v-model="rejectForm.reject_reason"
type="textarea"
:rows="3"
maxlength="500"
show-word-limit
placeholder="请输入拒绝原因"
/>
</ElFormItem>
</ElForm>
<template #footer>
<div class="dialog-footer">
<ElButton @click="rejectDialogVisible = false">取消</ElButton>
<ElButton type="danger" @click="handleRejectRecharge" :loading="rejectLoading">
确认拒绝
</ElButton>
</div>
</template>
</ElDialog>
<!-- 支付凭证预览 --> <!-- 支付凭证预览 -->
<PaymentVoucherDialog <PaymentVoucherDialog
:file-keys="paymentVoucherFileKeys" :file-keys="paymentVoucherFileKeys"
@@ -198,7 +230,8 @@
AgentRechargeStatus, AgentRechargeStatus,
AgentRechargePaymentMethod, AgentRechargePaymentMethod,
CreateAgentRechargeRequest, CreateAgentRechargeRequest,
ConfirmOfflinePaymentRequest ConfirmOfflinePaymentRequest,
RejectAgentRechargeRequest
} from '@/types/api' } from '@/types/api'
import type { SearchFormItem } from '@/types' import type { SearchFormItem } from '@/types'
import { useCheckedColumns } from '@/composables/useCheckedColumns' import { useCheckedColumns } from '@/composables/useCheckedColumns'
@@ -207,6 +240,7 @@
import { useAuth } from '@/composables/useAuth' import { useAuth } from '@/composables/useAuth'
import PaymentVoucherDialog from '@/components/business/PaymentVoucherDialog.vue' import PaymentVoucherDialog from '@/components/business/PaymentVoucherDialog.vue'
import VoucherUpload from '@/components/business/VoucherUpload.vue' import VoucherUpload from '@/components/business/VoucherUpload.vue'
import { buildAgentRechargeActions } from './agentRechargeActions'
defineOptions({ name: 'AgentRechargeList' }) defineOptions({ name: 'AgentRechargeList' })
@@ -217,9 +251,11 @@
const createLoading = ref(false) const createLoading = ref(false)
const voucherUploading = ref(false) const voucherUploading = ref(false)
const confirmPayLoading = ref(false) const confirmPayLoading = ref(false)
const rejectLoading = ref(false)
const tableRef = ref() const tableRef = ref()
const createDialogVisible = ref(false) const createDialogVisible = ref(false)
const confirmPayDialogVisible = ref(false) const confirmPayDialogVisible = ref(false)
const rejectDialogVisible = ref(false)
const currentRecharge = ref<AgentRecharge | null>(null) const currentRecharge = ref<AgentRecharge | null>(null)
const paymentVoucherFileKeys = ref<string[]>([]) const paymentVoucherFileKeys = ref<string[]>([])
@@ -337,6 +373,7 @@
const createFormRef = ref<FormInstance>() const createFormRef = ref<FormInstance>()
const confirmPayFormRef = ref<FormInstance>() const confirmPayFormRef = ref<FormInstance>()
const rejectFormRef = ref<FormInstance>()
const uploadRef = ref<InstanceType<typeof VoucherUpload>>() const uploadRef = ref<InstanceType<typeof VoucherUpload>>()
const MIN_RECHARGE_AMOUNT = 0.01 const MIN_RECHARGE_AMOUNT = 0.01
@@ -374,6 +411,10 @@
] ]
}) })
const rejectRules = reactive<FormRules>({
reject_reason: [{ required: true, message: '请输入拒绝原因', trigger: 'blur' }]
})
const createForm = reactive<{ const createForm = reactive<{
amount: number amount: number
payment_method: string payment_method: string
@@ -392,6 +433,10 @@
operation_password: '' operation_password: ''
}) })
const rejectForm = reactive<RejectAgentRechargeRequest>({
reject_reason: ''
})
const rechargeList = ref<AgentRecharge[]>([]) const rechargeList = ref<AgentRecharge[]>([])
// 格式化货币 - 将分转换为元 // 格式化货币 - 将分转换为元
@@ -735,6 +780,44 @@
}) })
} }
// 显示拒绝对话框
const handleShowReject = (row: AgentRecharge) => {
currentRecharge.value = row
rejectDialogVisible.value = true
}
// 拒绝对话框关闭后的清理
const handleRejectDialogClosed = () => {
rejectFormRef.value?.resetFields()
rejectForm.reject_reason = ''
currentRecharge.value = null
}
// 拒绝代理充值订单
const handleRejectRecharge = async () => {
const formRef = rejectFormRef.value
const recharge = currentRecharge.value
if (!formRef || !recharge) return
await formRef.validate(async (valid) => {
if (valid) {
rejectLoading.value = true
try {
await AgentRechargeService.rejectAgentRecharge(recharge.id, {
reject_reason: rejectForm.reject_reason
})
ElMessage.success('拒绝成功')
rejectDialogVisible.value = false
await getTableData()
} catch (error) {
console.error(error)
} finally {
rejectLoading.value = false
}
}
})
}
// 处理名称点击 // 处理名称点击
const handleNameClick = (row: AgentRecharge) => { const handleNameClick = (row: AgentRecharge) => {
if (hasAuth('agent_recharge:detail_page')) { if (hasAuth('agent_recharge:detail_page')) {
@@ -754,35 +837,12 @@
// 获取操作按钮 // 获取操作按钮
const getActions = (row: AgentRecharge) => { const getActions = (row: AgentRecharge) => {
const actions: any[] = [] return buildAgentRechargeActions(row, {
hasAuth,
// 线下支付且有凭证可以查看 onViewPaymentVoucher: handleViewPaymentVoucher,
if ( onConfirmPayment: handleShowConfirmPay,
row.payment_method === 'offline' && onReject: handleShowReject
hasVoucherKeys(row.payment_voucher_key) && })
hasAuth('agent_recharge:view_payment_voucher')
) {
actions.push({
label: '查看支付凭证',
handler: () => handleViewPaymentVoucher(row),
type: 'primary'
})
}
// 待支付且线下转账的订单可以确认支付
if (
row.status === 1 &&
row.payment_method === 'offline' &&
hasAuth('agent_recharge:confirm_payment')
) {
actions.push({
label: '确认支付',
handler: () => handleShowConfirmPay(row),
type: 'primary'
})
}
return actions
} }
// 查看支付凭证 // 查看支付凭证