feat:转账退款完成

This commit is contained in:
dzc committed 2025-04-01 18:29:33 +08:00
1 parent 2fab79f954
commit 8824440446
4 files changed
+162 -46

No files matched your search

+23 -3
View File
@@ -1,5 +1,13 @@
import request from "/@/utils/request"
export function refund(params?: Object) {
return request({
url: "/wallet/wallet-rule-transaction/refund",
method: "get",
params,
})
}
export function fetchList(query?: Object) {
return request({
url: "/wallet/wallet-rule-transaction/page",
@@ -8,11 +16,15 @@ export function fetchList(query?: Object) {
})
}
export function pageJoin(query?: Object) {
export function pageJoin(data: any) {
return request({
url: "/wallet/wallet-rule-transaction/page-join",
method: "get",
params: query,
method: "post",
params: {
current: data.current,
size: data.size,
},
data,
})
}
@@ -46,3 +58,11 @@ export function putObj(obj?: Object) {
data: obj,
})
}
export function transferAccounts(obj?: Object) {
return request({
url: "/wallet/wallet-rule-transaction/transfer-accounts",
method: "post",
data: obj,
})
}
@@ -14,6 +14,7 @@
@node-click="handleNodeClick"
@check="handleCheck"
@visible-change="(e) => e && getOptions()"
filterable
clearable
highlight-current
default-expand-all
@@ -1,7 +1,7 @@
<template>
<el-dialog title="转账" v-model="visible" width="60%" :close-on-click-modal="false" draggable>
<div>
<el-alert title="错误" type="error">
<el-alert v-if="errorMsg && errorMsg != ' '" title="错误" type="error">
<span>{{ errorMsg }}</span>
<span>请配置</span>
</el-alert>
@@ -14,18 +14,46 @@
<span>{{ userConfigDetail.userMobile }}</span>
</el-descriptions-item>
</el-descriptions>
<el-descriptions :column="2" border title="钱包">
<el-descriptions :column="2" border title="转账前">
<el-descriptions-item :rowspan="1" label="源钱包: ">
<span class="color-primary">{{ walletDetail.walletTypeName }}</span>
<span class="color-primary">{{ userConfigDetail.sourceWalletTypeName }}</span>
</el-descriptions-item>
<el-descriptions-item :rowspan="1" label="源余额: ">
<span class="color-success">{{ displayPrice(walletDetail.balance) }}</span>
<el-descriptions-item :rowspan="1" label="源钱包余额: ">
<span class="color-success">{{ displayPrice(userConfigDetail.sourceWalletBalance) }}</span>
</el-descriptions-item>
<el-descriptions-item :rowspan="1" label="目标钱包: ">
<span class="color-primary">{{ walletDetail.username }}</span>
<span class="color-primary">{{ userConfigDetail.targetWalletTypeName }}</span>
</el-descriptions-item>
<el-descriptions-item :rowspan="1" label="目标余额: ">
<span class="color-success">{{ walletDetail.username }}</span>
<el-descriptions-item :rowspan="1" label="目标钱包余额: ">
<span class="color-success">{{ displayPrice(userConfigDetail.targetWalletBalance) }}</span>
</el-descriptions-item>
</el-descriptions>
<el-descriptions :column="2" border title="转账后">
<el-descriptions-item :rowspan="1" label="源钱包: ">
<span class="color-primary">{{ userConfigDetail.sourceWalletTypeName }}</span>
</el-descriptions-item>
<el-descriptions-item :rowspan="1" label="源钱包余额: ">
<span class="color-success">{{ displayPrice(userConfigDetail.sourceWalletBalance - form.balance * 100) }}</span>
</el-descriptions-item>
<el-descriptions-item :rowspan="1" label="目标钱包: ">
<span class="color-primary">{{ userConfigDetail.targetWalletTypeName }}</span>
</el-descriptions-item>
<el-descriptions-item :rowspan="1" label="目标钱包余额: ">
<span class="color-success">{{ displayPrice(userConfigDetail.targetWalletBalance + form.balance * 100) }}</span>
</el-descriptions-item>
</el-descriptions>
<el-descriptions :column="3" border title="转账统计">
<el-descriptions-item :rowspan="1" label="转账百分比: ">
<span class="color-primary">{{ userConfigDetail.balanceMultiple }}%</span>
</el-descriptions-item>
<el-descriptions-item :rowspan="1" label="充值总金额: ">
<span class="color-primary">{{ displayPrice(userConfigDetail.totalTopUpBalance) }}</span>
</el-descriptions-item>
<el-descriptions-item :rowspan="1" label="最大转账金额: ">
<span class="color-primary">{{ displayPrice(userConfigDetail.maxTransferBalance) }}</span>
</el-descriptions-item>
<el-descriptions-item :rowspan="1" label="已转账金额: "
>{{ displayPrice(userConfigDetail.totalTransferBalance) }}
</el-descriptions-item>
</el-descriptions>
</div>
@@ -33,7 +61,7 @@
<span>用户</span>
<span class="color-primary">{{ walletDetail.username }}</span>
<span>将</span>
<el-input-number :disabled="errorMsg" class="mx-1" style="width: 200px" :min="1" :max="200" v-model="form.balance" placeholder="" />
<el-input-number class="mx-1" style="width: 200px" :min="1" :max="200" v-model="form.balance" placeholder="" />
<span>元从</span>
<span class="color-primary">{{ walletDetail.walletTypeName }}</span>
<span>转到</span>
@@ -61,7 +89,7 @@
import { useMessage } from "/@/hooks/message"
import * as walletApi from "/@/api/wallet/wallet-manage"
import * as walletRuleJoin from "/@/api/wallet/wallet-rule-join"
import * as walletTransactionApi from "/@/api/wallet/wallet-transaction"
import * as walletRuleTransactionApi from "/@/api/wallet/wallet-rule-transaction"
import { displayPrice } from "/@/utils/formatMoney"
import { convertToInteger } from "/@/utils/convert"
const emit = defineEmits(["refresh"])
@@ -83,7 +111,7 @@ const walletDetail = reactive<any>({})
const userConfigDetail = reactive<any>({})
const errorMsg = ref<string>("")
const errorMsg = ref<string>(" ")
/** 变动后的余额 */
const balanceResult = computed(() => displayPrice(convertToInteger(form.balance) + convertToInteger(form.changeBalance) * form.changeType))
@@ -108,28 +136,19 @@ const openDialog = (userId: string, id: string) => {
// 提交
const onSubmit = async () => {
const valid = await dataFormRef.value.validate().catch(() => {})
if (!valid) return false
if (form.changeBalance <= 0) {
useMessage().error("变动余额不能为零")
return
}
if (convertToInteger(balanceResult.value) < 0) {
useMessage().error("变动后的余额不能小于 0")
if (form.balance <= 0) {
useMessage().error("转账余额不能为0")
return
}
try {
loading.value = true
const pa = {
...form,
userId: form.id,
walletId: form.walletId,
balance: form.changeBalance * 100,
userId: userConfigDetail.userId,
sourceWalletTypeId: userConfigDetail.sourceWalletTypeId,
targetWalletTypeId: userConfigDetail.targetWalletTypeId,
balance: Math.abs(form.balance * 100),
}
if (pa.changeType == -1) {
pa.balance = -1 * pa.balance
}
await walletTransactionApi.updateBalance(pa)
await walletRuleTransactionApi.transferAccounts(pa)
useMessage().success("操作成功")
visible.value = false
emit("refresh")
@@ -168,7 +187,8 @@ const getUserConfig = async (userId: any, sourceWalletId: any, targetWalletId: a
try {
const { data } = await walletRuleJoin.userConfig(_pa)
if (!data) return
Object.assign(data, userConfigDetail)
Object.assign(userConfigDetail, data)
errorMsg.value = ""
} catch (e: any) {
errorMsg.value = e.msg
useMessage().error(e.msg)
@@ -12,6 +12,18 @@
:nodeClickable="false"
>
<el-form ref="queryRef" :inline="true" :model="state.queryForm" @keyup.enter="getDataList">
<el-form-item style="width: 250px" label="用户" prop="userId">
<select-user v-model="state.queryForm.userId" />
</el-form-item>
<el-form-item style="width: 250px" label="是否退回" prop="isRefund">
<dict-select v-model="state.queryForm.isRefund" dict-code="yes_no_type" />
</el-form-item>
<el-form-item style="width: 350px" label="转账时间" prop="createTimeList">
<el-date-picker v-model="state.queryForm.createTimeList" value-format="YYYY-MM-DD" type="daterange" />
</el-form-item>
<el-form-item style="width: 350px" label="退回时间" prop="refundTimeList">
<el-date-picker v-model="state.queryForm.refundTimeList" value-format="YYYY-MM-DD" type="daterange" />
</el-form-item>
<el-row>
<el-form-item>
<el-button icon="Search" type="primary" @click="getDataList">
@@ -46,29 +58,75 @@
>
<el-table-column type="selection" width="40" align="center" />
<el-table-column type="index" label="#" width="80" />
<el-table-column label="用户">
<el-table-column width="120" prop="username" label="姓名" />
<el-table-column width="120" prop="userMobile" label="手机号" />
<el-table-column width="120" prop="userDeptName" label="部门" />
</el-table-column>
<el-table-column label="源钱包">
<el-table-column prop="sourceWalletId" label="源钱包" />
<el-table-column prop="sourceWalletBalance" label="源钱包余额" />
<el-table-column width="100" prop="sourceWalletId" label="源钱包">
<template #default="{ row }">
<div class="flex flex-col items-center justify-center">
<div class="color-primary">{{ row.sourceWalletTypeName }}</div>
<div class="flex items-center just ml5">
<dict-tag :options="wallet_type" :value="row.sourceWalletTypeCode" />
</div>
</div>
</template>
</el-table-column>
<el-table-column width="100" prop="sourceWalletBalance" label="源钱包余额">
<template #default="{ row }">
<span class="color-primary">{{ displayPrice(row.sourceWalletBalance) }}</span>
</template>
</el-table-column>
</el-table-column>
<el-table-column label="目标钱包">
<el-table-column prop="sourceWalletId" label="源钱包" />
<el-table-column prop="sourceWalletBalance" label="源钱包余额" />
<el-table-column width="110" label="源钱包">
<template #default="{ row }">
<div class="flex flex-col items-center justify-center">
<div class="color-primary">{{ row.targetWalletTypeName }}</div>
<div class="flex items-center just ml5">
<dict-tag :options="wallet_type" :value="row.targetWalletTypeCode" />
</div>
</div>
</template>
</el-table-column>
<el-table-column width="110" prop="sourceWalletBalance" label="源钱包余额">
<template #default="{ row }">
<span class="color-success">{{ displayPrice(row.targetWalletBalance) }}</span>
</template>
</el-table-column>
</el-table-column>
<el-table-column label="转换">
<el-table-column prop="balance" label="转换金额" />
<el-table-column prop="balanceMultiple" label="百分比" />
<el-table-column prop="afterBalance" label="转换后的金额" />
<el-table-column width="110" prop="balance" label="转换金额">
<template #default="{ row }">
<span class="color-primary">{{ displayPrice(row.balance) }}</span>
</template>
</el-table-column>
<el-table-column width="110" label="转换后的金额">
<template #default="{ row }">
<span class="color-success">{{ displayPrice(row.afterBalance) }}</span>
</template>
</el-table-column>
</el-table-column>
<el-table-column prop="status" label="是否退回" />
<el-table-column label="操作" width="150">
<template #default="scope">
<el-table-column width="100" label="退回">
<el-table-column width="100" label="是否退回">
<template #default="{ row }">
<dict-tag :options="yes_no_type" :value="row.isRefund" />
</template>
</el-table-column>
<el-table-column prop="refundTime" width="170" label="退回时间" />
</el-table-column>
<el-table-column prop="createTime" width="170" label="创建时间" />
<el-table-column label="操作" fixed="right" width="80">
<template #default="{ row }">
<el-button
v-if="false"
icon="edit-pen"
v-if="row.isRefund == '0'"
icon="RefreshRight"
text
type="primary"
v-auth="'wallet_walletRuleTransaction_edit'"
@click="formDialogRef.openDialog(scope.row.id)"
@click="doRefund(row)"
>
退回
</el-button>
@@ -89,11 +147,12 @@ import { BasicTableProps, useTable } from "/@/hooks/table"
import * as walletRuleTransactionApi from "/@/api/wallet/wallet-rule-transaction"
import { useMessage, useMessageBox } from "/@/hooks/message"
import { useDict } from "/@/hooks/dict"
import { displayPrice } from "/@/utils/formatMoney"
// 引入组件
const FormDialog = defineAsyncComponent(() => import("./form.vue"))
// 定义查询字典
const { wallet_type, yes_no_type } = useDict("wallet_type", "yes_no_type")
// 定义变量内容
const formDialogRef = ref()
// 搜索变量
@@ -106,7 +165,7 @@ const multiple = ref(true)
const state: BasicTableProps = reactive<BasicTableProps>({
queryForm: {},
pageList: walletRuleTransactionApi.fetchList,
pageList: walletRuleTransactionApi.pageJoin,
})
// table hook
@@ -117,6 +176,22 @@ const exportExcel = () => {
downBlobFile("/wallet/walletRuleTransaction/export", Object.assign(state.queryForm, { ids: selectObjs }), "walletRuleTransaction.xlsx")
}
// 退款
const doRefund = async (row: any) => {
try {
await useMessageBox().confirm(`是否退回用户从${row.sourceWalletTypeName}转到${row.targetWalletTypeName}的${displayPrice(row.balance)}`)
} catch {
return
}
try {
await walletRuleTransactionApi.refund({ id: row.id })
getDataList()
useMessage().success("退回成功")
} catch (err: any) {
useMessage().error(err.msg)
}
}
// 多选事件
const selectionChangHandle = (objs: { id: string }[]) => {
selectObjs.value = objs.map(({ id }) => id)