feat:商户管理

feature/pay-0704-ch
ch 3 years ago
parent 9279a7d6cb
commit f58303e37f

@ -2,10 +2,43 @@
* @Author: ch
* @Date: 2022-07-04 15:20:02
* @LastEditors: ch
* @LastEditTime: 2022-07-04 15:50:39
* @LastEditTime: 2022-07-06 10:09:07
* @Description: file content
*/
import request from '@/utils/request.js';
export const create = (data) => {
return request({
url: '/payCenter/mchInfo',
method: 'post',
data,
});
};
export const del = (mchPrimaryId) => {
return request({
url: `/payCenter/mchInfo/${mchPrimaryId}`,
method: 'delete',
});
};
export const detail = (mchPrimaryId) => {
return request({
url: `/payCenter/mchInfo/${mchPrimaryId}`,
method: 'get',
});
};
export const update = (data) => {
return request({
url: '/payCenter/mchInfo',
method: 'put',
data,
});
};
export const updateStatus = (params) => {
return request({
url: `/payCenter/mchInfo/updateStatus`,
method: 'put',
params,
});
};
export const getMerchantList = (params) => {
return request({
url: '/payCenter/mchInfo/page',

@ -2,11 +2,13 @@
* @Author: ch
* @Date: 2022-07-04 15:21:30
* @LastEditors: ch
* @LastEditTime: 2022-07-04 16:22:14
* @LastEditTime: 2022-07-06 11:16:50
* @Description: file content
*/
import * as api from '@/api/pay/merchant.js';
import { ElMessage, ElMessageBox } from '@/plugins/element-plus';
const state = {
code: 'PayMerchantManagement',
list: [],
detail: {},
total: 0,
@ -33,18 +35,59 @@ const mutations = {
};
const actions = {
async search({ rootGetters, commit }, params) {
let data = { ...params };
let pagingCode = params.pagingCode;
const res = await api.getMerchantList({
...rootGetters['local/page'](pagingCode),
...data,
...rootGetters['local/page'](state.code),
...params,
});
if (res) {
commit('setList', res?.records || []);
commit('setList', res?.records.map((i) => ({ ...i, isShow: !i.isDisabled })) || []);
commit('setTotal', res?.total || 0);
}
},
async getMerchantPlatform({ commit }, params) {
async save({ dispatch }, data) {
let save = data.mchPrimaryId ? api.update : api.create;
let res = await save(data);
if (res) {
ElMessage.success('保存成功');
dispatch('search');
} else {
ElMessage.error('保存失败');
}
return res;
},
detail: async (context, id) => {
let res = await api.detail(id);
if (!res) {
ElMessage.error('加载详情失败');
}
return res;
},
del: async ({ dispatch }, id) => {
try {
await ElMessageBox.confirm('数据删除后无法恢复,确定要删除吗?', '危险操作');
let res = await api.del(id);
if (res) {
ElMessage.success('删除成功');
dispatch('search');
} else {
ElMessage.error('删除失败');
}
return res;
} catch (e) {
console.info('取消删除', e);
}
},
async updateStatus({ dispatch }, data) {
let res = await api.updateStatus(data);
if (res) {
ElMessage.success('保存成功');
dispatch('search');
} else {
ElMessage.error('保存失败');
}
return res;
},
async getMerchantPlatform({ commit }) {
const res = await api.getMerchantPlatform();
if (res) {
commit('setPlatform', res || []);

@ -0,0 +1,11 @@
<!--
* @Author: ch
* @Date: 2022-07-04 16:37:25
* @LastEditors: ch
* @LastEditTime: 2022-07-04 16:38:00
* @Description: file content
-->
<template>
<div></div>
</template>
<script setup lang="jsx"></script>

@ -0,0 +1,11 @@
<!--
* @Author: ch
* @Date: 2022-07-04 16:34:07
* @LastEditors: ch
* @LastEditTime: 2022-07-04 16:34:13
* @Description: file content
-->
<template></template>
<script lang="jsx">
export default {};
</script>

@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-06-15 17:29:32
* @LastEditors: ch
* @LastEditTime: 2022-07-04 16:12:49
* @LastEditTime: 2022-07-04 16:56:20
* @Description: file content
-->
<template>
@ -13,7 +13,9 @@
:config="config"
:data="list"
:total="total"
title="商户"
@search="handleSearch"
@create="handleCreate()"
:reset="handleReset"
>
<template #search>
@ -46,20 +48,6 @@
</el-form-item>
</el-form>
</template>
<template #operation="{ selection }">
<div class="batch-show-hide" v-if="selection.length">
<el-select v-model="allShowHideVal">
<el-option
v-for="(item, idx) in opts.isShow"
:key="idx"
:label="item.label"
:value="item.value"
></el-option>
</el-select>
<el-button type="primary" @click="handleAllShowHide(selection)"></el-button>
</div>
</template>
</table-list>
</template>
<script setup lang="jsx">
@ -103,7 +91,7 @@
const handleReset = () => {
state.condition = { ..._condition };
};
const handleCreate = () => {};
const config = reactive({
columns: [
{
@ -118,10 +106,8 @@
},
{
label: '商户平台',
width: 180,
slots: {
default: ({ row }) => ({ opts }),
},
width: 120,
prop: 'mchCode',
},
{
label: '商户状态',
@ -131,7 +117,7 @@
{
label: '创建时间',
prop: 'createTime',
width: 120,
width: 160,
},
{
label: '操作',

@ -0,0 +1,126 @@
<!--
* @Author: ch
* @Date: 2022-07-04 17:57:55
* @LastEditors: ch
* @LastEditTime: 2022-07-06 10:18:14
* @Description: file content
-->
<template>
<el-form labelWidth="160px" ref="formEl" :rules="rules" :model="form">
<el-form-item label="公钥" prop="publicKey">
<el-input
type="textarea"
maxlength="400"
show-word-limit
:placeholder="modelValue.hasPublicKey"
v-model="form.publicKey"
/>
</el-form-item>
<el-form-item label="公钥证书" prop="aliPayCertUrl">
<el-upload action="none" accept=".crt" :show-file-list="false" :http-request="handleUploadCert">
<el-button type="success" v-if="modelValue.hasAliPayCert || form.aliPayCertUrl">
已上传点击重新上传
</el-button>
<el-button type="primary" v-else></el-button>
</el-upload>
</el-form-item>
<el-form-item label="根证书" prop="aliPayRootCertUrl">
<el-upload action="none" accept=".crt" :show-file-list="false" :http-request="handleUploadRootCert">
<el-button type="success" v-if="modelValue.hasAliPayRootCert || form.aliPayRootCertUrl">
已上传点击重新上传
</el-button>
<el-button type="primary" v-else></el-button>
</el-upload>
</el-form-item>
</el-form>
</template>
<script setup lang="jsx">
import { upload } from '@/api/file';
const route = useRoute();
const emits = defineEmits(['update:modelValue']);
const attrs = useAttrs();
const createRules = {
publicKey: [{ required: true, message: '公钥不能为空' }],
aliPayCertUrl: [{ required: true, message: '请上传公钥证书' }],
aliPayRootCertUrl: [{ required: true, message: '请上传根证书' }],
};
const editRules = {
publicKey: [
{
validator: (rule, val, cb) => {
if (!val && !modelValue.value.hasPublicKey) {
cb(new Error('公钥不能为空'));
} else {
cb();
}
},
},
],
aliPayCertUrl: [
{
validator: (rule, val, cb) => {
if (!val && !modelValue.value.hasAliPayCert) {
cb(new Error('请上传公钥证书'));
} else {
cb();
}
},
},
],
aliPayRootCertUrl: [
{
validator: (rule, val, cb) => {
if (!val && !modelValue.value.hasAliPayRootCert) {
cb(new Error('请上传根证书'));
} else {
cb();
}
},
},
],
};
const rules = computed(() => {
return route.name === 'UpdateMerchant' ? editRules : createRules;
});
const form = reactive({
publicKey: '',
aliPayRootCertUrl: '',
aliPayCertUrl: '',
});
const formEl = ref();
const modelValue = computed(() => attrs.modelValue);
watch(
() => toRefs(form),
() => {
emits('update:modelValue', Object.assign(unref(modelValue), form));
}
);
/**
* 上传公钥证书
*/
const handleUploadCert = async ({ file }) => {
const res = await upload('payCenter', 'merchant/', file);
form.aliPayCertUrl = res;
};
/**
* 上传根证书
*/
const handleUploadRootCert = async ({ file }) => {
const res = await upload('payCenter', 'merchant/', file);
form.aliPayRootCertUrl = res;
};
/**
* 验证方法暴露给父组件
*/
const validate = async () => {
await formEl.value.validate();
};
const resetFields = () => {
formEl.value.resetFields();
};
defineExpose({
validate,
resetFields,
});
</script>

@ -0,0 +1,124 @@
<!--
* @Author: ch
* @Date: 2022-07-04 16:42:21
* @LastEditors: ch
* @LastEditTime: 2022-07-06 11:08:35
* @Description: file content
-->
<template>
<div>
<el-form ref="formEl" label-width="160px" :model="form" :rules="rules">
<el-form-item label="商户平台" prop="mchCode">
<el-radio-group v-model="form.mchCode" :disabled="idEdit">
<el-radio v-for="item in opts.platform" :key="item.code" :label="item.code" border>
{{ item.text }}
</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="商户名称" prop="mchName">
<el-input v-model="form.mchName" maxlength="64" show-word-limit />
</el-form-item>
<el-form-item label="商户ID" prop="mchId">
<el-input v-model="form.mchId" maxlength="64" show-word-limit />
</el-form-item>
<el-form-item label="商户状态" prop="disabled">
<el-select v-model="form.isDisabled" :clearable="false">
<el-option v-for="item in opts.status" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</el-form-item>
<Ali v-if="form.mchCode === 'alipay'" ref="aliFormEl" v-model="form.aliMchData" :detai="aliMchData" />
<Wx v-if="form.mchCode === 'wxpay'" v-model="form.wxMchData" ref="wxFormEl" />
<el-form-item>
<el-button @click="handleCancel"></el-button>
<el-button :disabled="loading" :loading="submitting" type="primary" @click="handleSave"></el-button>
</el-form-item>
</el-form>
</div>
</template>
<script setup lang="jsx">
import Ali from './ali.vue';
import Wx from './wx.vue';
const store = useStore();
const router = useRouter();
const route = useRoute();
//
const opts = computed(() => store.state.merchant.opts);
const defaultForm = {
isDisabled: false,
mchCode: route.params.id ? '' : 'wxpay',
mchName: '',
mchId: '',
aliMchData: {},
wxMchData: {},
};
const form = reactive({ ...defaultForm });
const rules = reactive({
mchName: [{ required: true, message: '商户名称不能为空' }],
mchId: [{ required: true, message: '商户ID不能为空' }],
});
const idEdit = computed(() => Boolean(route.params.id));
const formEl = ref();
const aliFormEl = ref();
const wxFormEl = ref();
store.dispatch('merchant/getMerchantPlatform');
onActivated(() => {
handlelLoadData();
});
/**
* 如果是编辑需要加载初始数据加载
*/
const handlelLoadData = async () => {
let id = route.params.id;
if (id && form.id !== id) {
let res = await store.dispatch('merchant/detail', id);
if (res.mchCode === 'alipay') {
const publicKey = res.aliMchData.publicKey;
if (publicKey) {
res.aliMchData.hasPublicKey = publicKey;
delete res.aliMchData.publicKey;
}
} else {
const { apiKey, apiKeyV3, serialNo } = res.wxMchData;
res.wxMchData.hasApiKey = apiKey;
delete res.wxMchData.apiKey;
res.wxMchData.hasApiKeyV3 = apiKeyV3;
delete res.wxMchData.apiKeyV3;
res.wxMchData.hasSerialNo = serialNo;
delete res.wxMchData.serialNo;
}
Object.assign(form, res);
}
};
const handleSave = async () => {
let validate = false;
if (form.mchCode === 'wxpay') {
validate = wxFormEl.value.validate;
} else {
validate = aliFormEl.value.validate;
}
Promise.all([formEl.value.validate(), validate()])
.then(async () => {
const res = await store.dispatch('merchant/save', form);
if (res) {
handleCancel();
}
})
.catch(() => {});
};
const handleCancel = () => {
Object.assign(form, defaultForm);
wxFormEl.value && wxFormEl.value.resetFields();
aliFormEl.value && aliFormEl.value.resetFields();
formEl.value.resetFields();
router.push({ name: 'PayMerchant' });
};
</script>
<style lang="less" scoped>
.form-container {
.el-form {
// width: 100%;
}
}
</style>

@ -0,0 +1,182 @@
<!--
* @Author: ch
* @Date: 2022-07-04 17:57:45
* @LastEditors: ch
* @LastEditTime: 2022-07-06 11:18:45
* @Description: file content
-->
<template>
<el-form labelWidth="160px" ref="formEl" :rules="rules" :model="form">
<el-form-item label="API秘钥" prop="apiKey">
<el-input
maxlength="64"
show-word-limit
v-model="form.apiKey"
:placeholder="modelValue.hasApiKey || '请输入'"
/>
</el-form-item>
<el-form-item label="v3秘钥" prop="apiKeyV3">
<el-input maxlength="64" show-word-limit v-model="form.apiKeyV3" :placeholder="modelValue.hasApiKeyV3" />
</el-form-item>
<el-form-item label="证书序列号" prop="serialNo">
<el-input maxlength="64" show-word-limit v-model="form.serialNo" :placeholder="modelValue.hasSerialNo" />
</el-form-item>
<el-form-item label="私钥证书(key.pem)" prop="keyOssUrl">
<el-upload action="none" accept=".pem" :show-file-list="false" :http-request="handleUploadKeyCert">
<el-button type="success" v-if="modelValue.hasKey || form.keyOssUrl"></el-button>
<el-button type="primary" v-else></el-button>
</el-upload>
</el-form-item>
<el-form-item label="商户证书(key.pem)" prop="certOssUrl">
<el-upload action="none" accept=".pem" :show-file-list="false" :http-request="handleUploadCert">
<el-button type="success" v-if="modelValue.hasCert || form.certOssUrl"></el-button>
<el-button type="primary" v-else></el-button>
</el-upload>
</el-form-item>
<el-form-item label="p12证书(cert.p12)" prop="certP12OssUrl">
<el-upload action="none" accept=".p12" :show-file-list="false" :http-request="handleUploadCert120">
<el-button type="success" v-if="modelValue.hasCertP12 || form.certP12OssUrl">
已上传点击重新上传
</el-button>
<el-button type="primary" v-else></el-button>
</el-upload>
</el-form-item>
</el-form>
</template>
<script setup lang="jsx">
import { upload } from '@/api/file';
const route = useRoute();
const emits = defineEmits(['update:modelValue']);
const attrs = useAttrs();
const createRules = {
apiKey: [{ required: true, message: 'API秘钥不能为空' }],
apiKeyV3: [{ required: true, message: 'v3秘钥不能为空' }],
serialNo: [{ required: true, message: '证书序列号不能为空' }],
certOssUrl: [{ required: true, message: '请上传根商户证书' }],
keyOssUrl: [{ required: true, message: '请上传私钥证书' }],
certP12OssUrl: [{ required: true, message: '请上传p12证书' }],
};
const editRules = {
apiKey: [
{
validator: (rule, val, cb) => {
if (!val && !modelValue.value.hasApiKey) {
cb(new Error('API秘钥不能为空'));
} else {
cb();
}
},
},
],
apiKeyV3: [
{
validator: (rule, val, cb) => {
if (!val && !modelValue.value.hasApiKeyV3) {
cb(new Error('v3秘钥不能为空'));
} else {
cb();
}
},
},
],
serialNo: [
{
validator: (rule, val, cb) => {
if (!val && !modelValue.value.hasSerialNo) {
cb(new Error('证书序列号不能为空'));
} else {
cb();
}
},
},
],
certOssUrl: [
{
validator: (rule, val, cb) => {
if (!val && !modelValue.value.hasCert) {
cb(new Error('请上传根商户证书'));
} else {
cb();
}
},
},
],
keyOssUrl: [
{
validator: (rule, val, cb) => {
if (!val && !modelValue.value.hasKey) {
cb(new Error('请上传私钥证书'));
} else {
cb();
}
},
},
],
certP12OssUrl: [
{
validator: (rule, val, cb) => {
if (!val && !modelValue.value.hasCertP12) {
cb(new Error('请上传p12证书'));
} else {
cb();
}
},
},
],
};
const form = reactive({
apiKey: '',
apiKeyV3: '',
serialNo: '',
certOssUrl: '',
keyOssUrl: '',
certP12OssUrl: '',
});
const rules = computed(() => {
return route.name === 'UpdateMerchant' ? editRules : createRules;
});
const modelValue = computed(() => attrs.modelValue);
const formEl = ref();
watch(
() => toRefs(form),
() => {
emits('update:modelValue', Object.assign(unref(modelValue), form));
}
);
/**
* 上传公钥证书
*/
const handleUploadCert = async ({ file }) => {
const res = await upload('payCenter', 'merchant/', file);
form.certOssUrl = res;
};
/**
* 上传私钥证书
*/
const handleUploadKeyCert = async ({ file }) => {
const res = await upload('payCenter', 'merchant/', file);
form.keyOssUrl = res;
};
/**
* 上传p12证书
*/
const handleUploadCert120 = async ({ file }) => {
const res = await upload('payCenter', 'merchant/', file);
form.certP12OssUrl = res;
};
/**
* 验证方法暴露给父组件
*/
const validate = async () => {
await formEl.value.validate();
};
const resetFields = () => {
formEl.value.resetFields();
};
defineExpose({
validate,
resetFields,
});
</script>

@ -2,60 +2,53 @@
* @Author: ch
* @Date: 2022-06-15 17:29:32
* @LastEditors: ch
* @LastEditTime: 2022-07-04 11:38:11
* @LastEditTime: 2022-07-06 11:19:31
* @Description: file content
-->
<template>
<div>
<table-list
v-loading="loading"
:operation="['search']"
:code="_pagingCode"
:config="config"
:data="list"
:total="total"
@search="handleSearch"
:reset="handleReset"
>
<template #search>
<el-form inline>
<el-form-item label="商户平台" prop="productName">
<el-input v-model="state.condition.productName" />
</el-form-item>
<el-form-item label="商户名称">
<el-input v-model="state.condition.userName" />
</el-form-item>
<el-form-item label="商户ID" prop="phone">
<el-input v-model="state.condition.phone" />
</el-form-item>
<el-form-item label="商户状态" prop="status">
<el-select v-model="state.condition.isShow">
<el-option
v-for="(item, idx) in opts.isShow"
:key="idx"
:label="item.label"
:value="item.value"
></el-option>
</el-select>
</el-form-item>
</el-form>
</template>
<template #operation="{ selection }">
<div class="batch-show-hide" v-if="selection.length">
<el-select v-model="allShowHideVal">
<table-list
v-loading="loading"
:code="code"
:config="config"
:data="list"
:operation="['create', 'search']"
:reset="handleReset"
title="商户"
:total="total"
@create="handleCreate"
@search="handleSearch"
>
<template #search>
<el-form inline>
<el-form-item label="商户名称">
<el-input v-model="state.condition.mchName" />
</el-form-item>
<el-form-item label="商户ID">
<el-input v-model="state.condition.mchId" />
</el-form-item>
<el-form-item label="商户平台">
<el-select v-model="state.condition.mchCode">
<el-option
v-for="(item, idx) in opts.platform"
:key="idx"
:label="item.text"
:value="item.code"
/>
</el-select>
</el-form-item>
<el-form-item label="商户状态">
<el-select v-model="state.condition.isDisabled">
<el-option
v-for="(item, idx) in opts.isShow"
v-for="(item, idx) in opts.status"
:key="idx"
:label="item.label"
:value="item.value"
></el-option>
/>
</el-select>
<el-button type="primary" @click="handleAllShowHide(selection)"></el-button>
</div>
</template>
</table-list>
</div>
</el-form-item>
</el-form>
</template>
</table-list>
</template>
<script setup lang="jsx">
import ElButton from '@/components/extra/ElButton.vue';
@ -64,37 +57,32 @@
const store = useStore();
const loading = ref(false);
//
const opts = computed(() => store.state.comment.opts);
const opts = computed(() => store.state.merchant.opts);
//
const list = computed(() => _.cloneDeep(store.state.comment.list));
const total = computed(() => store.state.comment.total);
// code使codesotre
const _pagingCode = 'CommentManagement';
const code = computed(() => store.state.merchant.code);
const list = computed(() => _.cloneDeep(store.state.merchant.list));
const total = computed(() => store.state.merchant.total);
//
const _condition = {
productName: '',
userName: '',
phone: '',
scoreList: [],
isShow: '',
dateRange: '',
mchCode: '',
mchId: '',
mchName: '',
isDisabled: null,
};
const state = reactive({
condition: { ..._condition },
});
//
const allShowHideVal = ref(true);
// store.dispatch('comment/search', { pagingCode: _pagingCode });
/**
* 搜索
*/
const handleSearch = async () => {
loading.value = true;
await store.dispatch('comment/search', { ...state.condition, pagingCode: _pagingCode });
await store.dispatch('merchant/search', { ...state.condition });
loading.value = false;
};
store.dispatch('merchant/getMerchantPlatform');
onActivated(handleSearch);
/**
* 重置
@ -102,121 +90,68 @@
const handleReset = () => {
state.condition = { ..._condition };
};
/**
* 单行操作显示隐藏
*
*/
const handleShowHide = async (row) => {
loading.value = true;
try {
await store.dispatch('comment/updateShow', {
idList: [row.id],
isShow: row.isShow,
});
} catch (e) {
row.isShow = !row.isShow;
}
loading.value = false;
const handleCreate = () => {
router.push('./create');
};
/**
* 批量操作显示隐藏
*/
const handleAllShowHide = async (selection) => {
loading.value = true;
let val = allShowHideVal.value;
try {
await store.dispatch('comment/updateShow', {
idList: selection.map((i) => i.id),
isShow: val,
});
} catch (e) {
val = !val;
}
loading.value = false;
selection.forEach((item) => {
item.isShow = val;
const handleShowHide = (row) => {
store.dispatch('merchant/updateStatus', {
mchPrimaryId: row.mchPrimaryId,
isDisabled: !row.isShow,
});
};
const handleDetail = (id) => {
router.push({
name: 'CommentDetail',
name: 'UpdateMerchant',
params: {
id: id,
id,
},
});
};
const handleDelete = (id) => {
store.dispatch('merchant/del', id);
};
const config = reactive({
columns: [
{
type: 'selection',
fixed: 'left',
width: 60,
},
{
label: '商品名称',
width: 180,
label: '商户名称',
align: 'left',
slots: {
default: ({ row }) => <div class="row-ellipsis">{row.productName}</div>,
},
prop: 'mchName',
},
{
label: '评价内容',
label: '商户ID',
align: 'left',
slots: {
default: ({ row }) => (
<div class="row-ellipsis ctx-link" onClick={() => handleDetail(row.id)}>
{row.commentContent}
</div>
),
},
},
{
label: '评分',
prop: 'scoreName',
width: 70,
},
{
label: '用户',
width: 120,
slots: {
default: ({ row }) => (
<div>
<p class="row-ellipsis">{row.userName}</p>
<p>{row.phone}</p>
</div>
),
},
prop: 'mchId',
},
{
label: '评价时间',
prop: 'time',
label: '商户平台',
width: 120,
slots: {
default: ({ row }) => (
<div>
<p>{row.createTime.split(' ')[0]}</p>
<p>{row.createTime.split(' ')[1]}</p>
</div>
),
},
prop: 'mchCode',
},
{
label: '显示',
label: '状态',
width: 80,
slots: {
default: ({ row }) => <ElSwitch v-model={row.isShow} onChange={() => handleShowHide(row)} />,
},
},
{
label: '创建时间',
prop: 'createTime',
width: 160,
},
{
label: '操作',
width: 70,
width: 120,
slots: {
default: ({ row }) => (
<ElButton type="text" onClick={() => handleDetail(row.id)}>
查看
</ElButton>
<div>
<ElButton type="text" onClick={() => handleDetail(row.mchPrimaryId)}>
编辑
</ElButton>
<ElButton type="text" onClick={() => handleDelete(row.mchPrimaryId)}>
删除
</ElButton>
</div>
),
},
},

@ -90,7 +90,7 @@ export default (configEnv) => {
{
...eslintPlugin({
eslintOptions: {
cache: true,
cache: false,
},
shouldLint: (path) => /\/src\/[^?]*\.(vue|m?[jt]sx?)$/.test(path),
}),

Loading…
Cancel
Save