商户微信支付设置

This commit is contained in:
马梓彭 2026-03-30 19:46:25 +08:00
parent 22dd33b8c1
commit d0e2cfd225
2 changed files with 90 additions and 61 deletions

View File

@ -26,6 +26,11 @@ export const merchantPageGet = (params) => {
* @param {string} data.accountNumber - 银行账号 * @param {string} data.accountNumber - 银行账号
* @param {string} data.businessLicenseUrl - 营业执照URL * @param {string} data.businessLicenseUrl - 营业执照URL
* @param {string} data.contactPhone - 联系电话 * @param {string} data.contactPhone - 联系电话
* @param {Object} [data.weChatPayConfig] - 微信支付配置
* @param {string} data.weChatPayConfig.merchantIdValue - 微信支付商户号
* @param {string} data.weChatPayConfig.merchantV3Secret - 微信支付APIv3密钥
* @param {string} data.weChatPayConfig.merchantCertificateSerialNumber - 微信支付商户证书序列号
* @param {string} data.weChatPayConfig.merchantCertificatePrivateKey - 微信支付商户私钥(PEM格式)
*/ */
export const merchantAddPost = (data) => { export const merchantAddPost = (data) => {
return http.post('/merchant/add', data); return http.post('/merchant/add', data);
@ -41,6 +46,11 @@ export const merchantAddPost = (data) => {
* @param {string} data.businessLicenseUrl - 营业执照URL * @param {string} data.businessLicenseUrl - 营业执照URL
* @param {string} data.contactPhone - 联系电话 * @param {string} data.contactPhone - 联系电话
* @param {number} data.id - 商户ID * @param {number} data.id - 商户ID
* @param {Object} [data.weChatPayConfig] - 微信支付配置
* @param {string} data.weChatPayConfig.merchantIdValue - 微信支付商户号
* @param {string} data.weChatPayConfig.merchantV3Secret - 微信支付APIv3密钥
* @param {string} data.weChatPayConfig.merchantCertificateSerialNumber - 微信支付商户证书序列号
* @param {string} data.weChatPayConfig.merchantCertificatePrivateKey - 微信支付商户私钥(PEM格式)
*/ */
export const merchantEditPut = (data) => { export const merchantEditPut = (data) => {
return http.put('/merchant/edit', data); return http.put('/merchant/edit', data);

View File

@ -28,9 +28,9 @@
</ProTable> </ProTable>
<!-- 弹窗 --> <!-- 弹窗 -->
<el-dialog :title="dialogTitle" v-model="isShowDialog"> <el-dialog :title="dialogTitle" v-model="isShowDialog" width="900px">
<el-form ref="formRef" :model="formData" :rules="formRules" label-width="200px" <el-form ref="formRef" :model="formData" :rules="formRules" label-width="200px"
style="max-width: 600px;margin-bottom: 30px;" v-if="isShowDialog"> style="max-width: 800px;margin-bottom: 30px;" v-if="isShowDialog">
<!-- 商户名称 --> <!-- 商户名称 -->
<el-form-item label="商户名称" prop="merchantName"> <el-form-item label="商户名称" prop="merchantName">
@ -63,11 +63,32 @@
</el-upload> </el-upload>
</el-form-item> </el-form-item>
<!-- 费用 --> <!-- 联系电话 -->
<el-form-item label="联系电话" prop="contactPhone"> <el-form-item label="联系电话" prop="contactPhone">
<el-input v-model="formData.contactPhone" placeholder="请输入联系电话" class="fee-input"> <el-input v-model="formData.contactPhone" placeholder="请输入联系电话"></el-input>
<template slot="append">元</template> </el-form-item>
</el-input>
<!-- 分隔线 -->
<el-divider content-position="left">微信支付配置</el-divider>
<!-- 微信支付商户号 -->
<el-form-item label="微信支付商户号" prop="weChatPayConfig.merchantIdValue">
<el-input v-model="formData.weChatPayConfig.merchantIdValue" placeholder="请输入微信支付商户号"></el-input>
</el-form-item>
<!-- 微信支付APIv3密钥 -->
<el-form-item label="微信支付APIv3密钥" prop="weChatPayConfig.merchantV3Secret">
<el-input v-model="formData.weChatPayConfig.merchantV3Secret" type="password" show-password placeholder="请输入微信支付APIv3密钥"></el-input>
</el-form-item>
<!-- 微信支付商户证书序列号 -->
<el-form-item label="商户证书序列号" prop="weChatPayConfig.merchantCertificateSerialNumber">
<el-input v-model="formData.weChatPayConfig.merchantCertificateSerialNumber" placeholder="请输入微信支付商户证书序列号"></el-input>
</el-form-item>
<!-- 微信支付商户私钥 -->
<el-form-item label="商户私钥(PEM格式)" prop="weChatPayConfig.merchantCertificatePrivateKey">
<el-input v-model="formData.weChatPayConfig.merchantCertificatePrivateKey" type="textarea" :rows="4" placeholder="请输入微信支付商户私钥(PEM格式)"></el-input>
</el-form-item> </el-form-item>
</el-form> </el-form>
@ -84,7 +105,8 @@
<script setup name="sysMenu"> <script setup name="sysMenu">
import { defineAsyncComponent, ref, reactive } from 'vue'; import { defineAsyncComponent, ref, reactive } from 'vue';
import { ElMessage, ElForm } from 'element-plus'; import { ElMessage, ElForm } from 'element-plus';
import { merchantPageGet, merchantAddPost ,merchantEditPut ,merchantDeleteDelete} from '/@/api/match/merchant'; import { Plus } from '@element-plus/icons-vue';
import { merchantPageGet, merchantAddPost, merchantEditPut, merchantDeletePost, merchantDetailGet } from '/@/api/match/merchant';
import { auths } from '/@/utils/authFunction'; import { auths } from '/@/utils/authFunction';
import ProTable from '/@/components/ProTable/index.vue'; import ProTable from '/@/components/ProTable/index.vue';
@ -94,22 +116,31 @@ const formRef = ref();
const initParam = ref({ const initParam = ref({
refresh: false, refresh: false,
}); });
const formData = ref({
const getDefaultFormData = () => ({
id: undefined,
merchantName: '', merchantName: '',
creditCode: '', creditCode: '',
bankName: '', bankName: '',
accountNumber: '', accountNumber: '',
businessLicenseUrl: '', businessLicenseUrl: '',
durationMinutes: '', contactPhone: '',
contactPhone: '' weChatPayConfig: {
}) merchantIdValue: '',
merchantV3Secret: '',
merchantCertificateSerialNumber: '',
merchantCertificatePrivateKey: ''
}
});
const formData = ref(getDefaultFormData());
const formRules = ref({ const formRules = ref({
merchantName: [ merchantName: [
{ required: true, message: '请输入商户名称', trigger: 'blur' } { required: true, message: '请输入商户名称', trigger: 'blur' }
], ],
creditCode: [ creditCode: [
{ required: true, message: '请选择统一社会信用代码', trigger: 'blur' } { required: true, message: '请输入统一社会信用代码', trigger: 'blur' }
], ],
bankName: [ bankName: [
{ required: true, message: '请输入开户行', trigger: 'blur' } { required: true, message: '请输入开户行', trigger: 'blur' }
@ -120,7 +151,9 @@ const formRules = ref({
businessLicenseUrl: [ businessLicenseUrl: [
{ required: true, message: '请上传营业执照', trigger: 'blur' } { required: true, message: '请上传营业执照', trigger: 'blur' }
], ],
contactPhone: [
{ required: true, message: '请输入联系电话', trigger: 'blur' }
],
}); });
const columns = ref([ const columns = ref([
@ -149,27 +182,34 @@ const columns = ref([
const isShowDialog = ref(false); const isShowDialog = ref(false);
const dialogTitle = ref('新增'); const dialogTitle = ref('新增');
const onOpenMenu = (data) => { const onOpenMenu = async (data) => {
console.log(data)
dialogTitle.value = data ? '编辑' : '新增'; dialogTitle.value = data ? '编辑' : '新增';
if (data) { formData.value = getDefaultFormData();
formData.value = data; if (data && data.id) {
} else { try {
formData.value = { const res = await merchantDetailGet({ id: data.id });
merchantName: '', if (res && res.succeeded && res.data) {
creditCode: '', formData.value = {
bankName: '', ...getDefaultFormData(),
accountNumber: '', ...res.data,
businessLicenseUrl: '', weChatPayConfig: res.data.weChatPayConfig || {
phone: '' merchantIdValue: '',
}; merchantV3Secret: '',
merchantCertificateSerialNumber: '',
merchantCertificatePrivateKey: ''
}
};
}
} catch (error) {
console.error('获取商户详情失败', error);
}
} }
isShowDialog.value = true; isShowDialog.value = true;
}; };
//删除菜单 //删除菜单
const onDeleteMenu = async (id) => { const onDeleteMenu = async (id) => {
const { succeeded, errors } = await merchantDeleteDelete({ id }); const { succeeded, errors } = await merchantDeletePost([id]);
if (succeeded) { if (succeeded) {
ElMessage.success('删除成功'); ElMessage.success('删除成功');
initParam.value.refresh = !initParam.value.refresh; initParam.value.refresh = !initParam.value.refresh;
@ -180,34 +220,34 @@ const onDeleteMenu = async (id) => {
const handleAvatarSuccess = (response, uploadFile) => { const handleAvatarSuccess = (response, uploadFile) => {
formData.value.businessLicenseUrl = response[0].url; formData.value.businessLicenseUrl = response[0].url;
console.log(response, uploadFile)
} }
const beforeAvatarUpload = () => { const beforeAvatarUpload = () => {
// if (rawFile.type !== 'image/jpeg') {
// ElMessage.error('Avatar picture must be JPG format!')
// return false
// } else if (rawFile.size / 1024 / 1024 > 2) {
// ElMessage.error('Avatar picture size can not exceed 2MB!')
// return false
// }
return true return true
} }
// 表单提交 // 表单提交
const onSubmit = () => { const onSubmit = () => {
console.log(formData.value)
if (!formRef.value) return; if (!formRef.value) return;
formRef.value.validate(async (valid) => { formRef.value.validate(async (valid) => {
if (!valid) return; if (!valid) return;
try { try {
// 处理微信支付配置 - 如果都是空的,发送null
const weChatPayConfig = formData.value.weChatPayConfig;
const hasWeChatPayConfig = weChatPayConfig.merchantIdValue || weChatPayConfig.merchantV3Secret ||
weChatPayConfig.merchantCertificateSerialNumber || weChatPayConfig.merchantCertificatePrivateKey;
const payload = {
...formData.value,
weChatPayConfig: hasWeChatPayConfig ? weChatPayConfig : null
};
let res; let res;
if (formData.value.id) { if (formData.value.id) {
res = await merchantEditPut(formData.value); res = await merchantEditPut(payload);
} else { } else {
res = await merchantAddPost(formData.value); res = await merchantAddPost(payload);
} }
if (res.succeeded) { if (res.succeeded) {
@ -233,27 +273,6 @@ const onCancel = () => {
margin-top: 80px; margin-top: 80px;
} }
/* 时长组合框样式 */
.duration-row {
display: flex;
align-items: center;
gap: 8px;
}
.duration-row .el-input {
width: 120px;
}
.duration-separator {
color: #606266;
font-size: 14px;
}
.duration-label {
color: #909399;
font-size: 14px;
}
.avatar { .avatar {
width: 350px; width: 350px;
} }