add 微信支付-子商户管理

This commit is contained in:
chenbo 2023-11-10 09:57:51 +08:00
parent 66b42fadfa
commit 23cffad7c0
8 changed files with 755 additions and 1 deletions

View File

@ -0,0 +1,26 @@
import request from '@/utils/request'
// 微信支付子商户表列表
export function apiSubMerchantLists(params: any) {
return request.get({ url: '/sub_merchant/lists', params })
}
// 添加微信支付子商户表
export function apiSubMerchantAdd(params: any) {
return request.post({ url: '/sub_merchant/add', params })
}
// 编辑微信支付子商户表
export function apiSubMerchantEdit(params: any) {
return request.post({ url: '/sub_merchant/edit', params })
}
// 删除微信支付子商户表
export function apiSubMerchantDelete(params: any) {
return request.post({ url: '/sub_merchant/delete', params })
}
// 微信支付子商户表详情
export function apiSubMerchantDetail(params: any) {
return request.get({ url: '/sub_merchant/detail', params })
}

View File

@ -0,0 +1,163 @@
<template>
<div class="edit-popup">
<popup
ref="popupRef"
:title="popupTitle"
:async="true"
width="550px"
@confirm="handleSubmit"
@close="handleClose"
>
<el-form ref="formRef" :model="formData" label-width="90px" :rules="formRules">
<el-form-item label="子商户名" prop="sub_merchant_name">
<el-input v-model="formData.sub_merchant_name" clearable placeholder="请输入子商户名" />
</el-form-item>
<el-form-item label="子商户号" prop="sub_mch_id">
<el-input v-model="formData.sub_mch_id" clearable placeholder="请输入子商户号" />
</el-form-item>
<el-form-item label="省" prop="province">
<el-input v-model="formData.province" clearable placeholder="请输入省" />
</el-form-item>
<el-form-item label="市" prop="city">
<el-input v-model="formData.city" clearable placeholder="请输入市" />
</el-form-item>
<el-form-item label="区/县" prop="area">
<el-input v-model="formData.area" clearable placeholder="请输入区/县" />
</el-form-item>
<el-form-item label="镇" prop="street">
<el-input v-model="formData.street" clearable placeholder="请输入镇" />
</el-form-item>
<el-form-item label="村" prop="village">
<el-input v-model="formData.village" clearable placeholder="请输入村" />
</el-form-item>
</el-form>
</popup>
</div>
</template>
<script lang="ts" setup name="subMerchantEdit">
import type { FormInstance } from 'element-plus'
import Popup from '@/components/popup/index.vue'
import { apiSubMerchantAdd, apiSubMerchantEdit, apiSubMerchantDetail } from '@/api/sub_merchant'
import { timeFormat } from '@/utils/util'
import type { PropType } from 'vue'
defineProps({
dictData: {
type: Object as PropType<Record<string, any[]>>,
default: () => ({})
}
})
const emit = defineEmits(['success', 'close'])
const formRef = shallowRef<FormInstance>()
const popupRef = shallowRef<InstanceType<typeof Popup>>()
const mode = ref('add')
//
const popupTitle = computed(() => {
return mode.value == 'edit' ? '编辑微信支付子商户表' : '新增微信支付子商户表'
})
//
const formData = reactive({
id: '',
sub_merchant_name: '',
sub_mch_id: '',
province: '',
city: '',
area: '',
street: '',
village: '',
})
//
const formRules = reactive<any>({
sub_merchant_name: [{
required: true,
message: '请输入子商户名',
trigger: ['blur']
}],
sub_mch_id: [{
required: true,
message: '请输入子商户号',
trigger: ['blur']
}],
province: [{
required: true,
message: '请输入省',
trigger: ['blur']
}],
city: [{
required: true,
message: '请输入市',
trigger: ['blur']
}],
area: [{
required: true,
message: '请输入区/县',
trigger: ['blur']
}],
street: [{
required: true,
message: '请输入镇',
trigger: ['blur']
}],
village: [{
required: true,
message: '请输入村',
trigger: ['blur']
}],
})
//
const setFormData = async (data: Record<any, any>) => {
for (const key in formData) {
if (data[key] != null && data[key] != undefined) {
//@ts-ignore
formData[key] = data[key]
}
}
}
const getDetail = async (row: Record<string, any>) => {
const data = await apiSubMerchantDetail({
id: row.id
})
setFormData(data)
}
//
const handleSubmit = async () => {
await formRef.value?.validate()
const data = { ...formData, }
mode.value == 'edit'
? await apiSubMerchantEdit(data)
: await apiSubMerchantAdd(data)
popupRef.value?.close()
emit('success')
}
//
const open = (type = 'add') => {
mode.value = type
popupRef.value?.open()
}
//
const handleClose = () => {
emit('close')
}
defineExpose({
open,
setFormData,
getDetail
})
</script>

View File

@ -0,0 +1,155 @@
<template>
<div>
<el-card class="!border-none mb-4" shadow="never">
<el-form
class="mb-[-16px]"
:model="queryParams"
inline
>
<el-form-item label="子商户名" prop="sub_merchant_name">
<el-input class="w-[280px]" v-model="queryParams.sub_merchant_name" clearable placeholder="请输入子商户名" />
</el-form-item>
<el-form-item label="子商户号" prop="sub_mch_id">
<el-input class="w-[280px]" v-model="queryParams.sub_mch_id" clearable placeholder="请输入子商户号" />
</el-form-item>
<el-form-item label="省" prop="province">
<el-input class="w-[280px]" v-model="queryParams.province" clearable placeholder="请输入省" />
</el-form-item>
<el-form-item label="市" prop="city">
<el-input class="w-[280px]" v-model="queryParams.city" clearable placeholder="请输入市" />
</el-form-item>
<el-form-item label="区/县" prop="area">
<el-input class="w-[280px]" v-model="queryParams.area" clearable placeholder="请输入区/县" />
</el-form-item>
<el-form-item label="镇" prop="street">
<el-input class="w-[280px]" v-model="queryParams.street" clearable placeholder="请输入镇" />
</el-form-item>
<el-form-item label="村" prop="village">
<el-input class="w-[280px]" v-model="queryParams.village" clearable placeholder="请输入村" />
</el-form-item>
<el-form-item>
<el-button type="primary" @click="resetPage">查询</el-button>
<el-button @click="resetParams">重置</el-button>
</el-form-item>
</el-form>
</el-card>
<el-card class="!border-none" v-loading="pager.loading" shadow="never">
<el-button v-perms="['sub_merchant/add']" type="primary" @click="handleAdd">
<template #icon>
<icon name="el-icon-Plus" />
</template>
新增
</el-button>
<el-button
v-perms="['sub_merchant/delete']"
:disabled="!selectData.length"
@click="handleDelete(selectData)"
>
删除
</el-button>
<div class="mt-4">
<el-table :data="pager.lists" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" />
<el-table-column label="子商户名" prop="sub_merchant_name" show-overflow-tooltip />
<el-table-column label="子商户号" prop="sub_mch_id" show-overflow-tooltip />
<el-table-column label="省" prop="province" show-overflow-tooltip />
<el-table-column label="市" prop="city" show-overflow-tooltip />
<el-table-column label="区/县" prop="area" show-overflow-tooltip />
<el-table-column label="镇" prop="street" show-overflow-tooltip />
<el-table-column label="村" prop="village" show-overflow-tooltip />
<el-table-column label="操作" width="120" fixed="right">
<template #default="{ row }">
<el-button
v-perms="['sub_merchant/edit']"
type="primary"
link
@click="handleEdit(row)"
>
编辑
</el-button>
<el-button
v-perms="['sub_merchant/delete']"
type="danger"
link
@click="handleDelete(row.id)"
>
删除
</el-button>
</template>
</el-table-column>
</el-table>
</div>
<div class="flex mt-4 justify-end">
<pagination v-model="pager" @change="getLists" />
</div>
</el-card>
<edit-popup v-if="showEdit" ref="editRef" :dict-data="dictData" @success="getLists" @close="showEdit = false" />
</div>
</template>
<script lang="ts" setup name="subMerchantLists">
import { usePaging } from '@/hooks/usePaging'
import { useDictData } from '@/hooks/useDictOptions'
import { apiSubMerchantLists, apiSubMerchantDelete } from '@/api/sub_merchant'
import { timeFormat } from '@/utils/util'
import feedback from '@/utils/feedback'
import EditPopup from './edit.vue'
const editRef = shallowRef<InstanceType<typeof EditPopup>>()
//
const showEdit = ref(false)
//
const queryParams = reactive({
sub_merchant_name: '',
sub_mch_id: '',
province: '',
city: '',
area: '',
street: '',
village: '',
})
//
const selectData = ref<any[]>([])
//
const handleSelectionChange = (val: any[]) => {
selectData.value = val.map(({ id }) => id)
}
//
const { dictData } = useDictData('')
//
const { pager, getLists, resetParams, resetPage } = usePaging({
fetchFun: apiSubMerchantLists,
params: queryParams
})
//
const handleAdd = async () => {
showEdit.value = true
await nextTick()
editRef.value?.open('add')
}
//
const handleEdit = async (data: any) => {
showEdit.value = true
await nextTick()
editRef.value?.open('edit')
editRef.value?.setFormData(data)
}
//
const handleDelete = async (id: number | any[]) => {
await feedback.confirm('确定要删除?')
await apiSubMerchantDelete({ id })
getLists()
}
getLists()
</script>

View File

@ -1 +0,0 @@
APP_DEBUG = true [APP] DEFAULT_TIMEZONE = Asia/Shanghai [DATABASE] TYPE = mysql HOSTNAME = 127.0.0.1 DATABASE = test USERNAME = username PASSWORD = password HOSTPORT = 3306 CHARSET = utf8 DEBUG = true PREFIX = la_ [LANG] default_lang = zh-cn [PROJECT] UNIQUE_IDENTIFICATION = likeadmin # 演示环境 DEMO_ENV = false

View File

@ -0,0 +1,108 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\controller;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\SubMerchantLists;
use app\adminapi\logic\SubMerchantLogic;
use app\adminapi\validate\SubMerchantValidate;
/**
* SubMerchant控制器
* Class SubMerchantController
* @package app\adminapi\controller
*/
class SubMerchantController extends BaseAdminController
{
/**
* @notes 获取列表
* @return \think\response\Json
* @author likeadmin
* @date 2023/11/10 09:54
*/
public function lists()
{
return $this->dataLists(new SubMerchantLists());
}
/**
* @notes 添加
* @return \think\response\Json
* @author likeadmin
* @date 2023/11/10 09:54
*/
public function add()
{
$params = (new SubMerchantValidate())->post()->goCheck('add');
$result = SubMerchantLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(SubMerchantLogic::getError());
}
/**
* @notes 编辑
* @return \think\response\Json
* @author likeadmin
* @date 2023/11/10 09:54
*/
public function edit()
{
$params = (new SubMerchantValidate())->post()->goCheck('edit');
$result = SubMerchantLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(SubMerchantLogic::getError());
}
/**
* @notes 删除
* @return \think\response\Json
* @author likeadmin
* @date 2023/11/10 09:54
*/
public function delete()
{
$params = (new SubMerchantValidate())->post()->goCheck('delete');
SubMerchantLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取详情
* @return \think\response\Json
* @author likeadmin
* @date 2023/11/10 09:54
*/
public function detail()
{
$params = (new SubMerchantValidate())->goCheck('detail');
$result = SubMerchantLogic::detail($params);
return $this->data($result);
}
}

View File

@ -0,0 +1,77 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\lists;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\SubMerchant;
use app\common\lists\ListsSearchInterface;
/**
* SubMerchant列表
* Class SubMerchantLists
* @package app\adminapi\lists
*/
class SubMerchantLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2023/11/10 09:54
*/
public function setSearch(): array
{
return [
'=' => ['sub_merchant_name', 'sub_mch_id', 'province', 'city', 'area', 'street', 'village'],
];
}
/**
* @notes 获取列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2023/11/10 09:54
*/
public function lists(): array
{
return SubMerchant::where($this->searchWhere)
->field(['id', 'sub_merchant_name', 'sub_mch_id', 'province', 'city', 'area', 'street', 'village'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->toArray();
}
/**
* @notes 获取数量
* @return int
* @author likeadmin
* @date 2023/11/10 09:54
*/
public function count(): int
{
return SubMerchant::where($this->searchWhere)->count();
}
}

View File

@ -0,0 +1,118 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\logic;
use app\common\model\SubMerchant;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* SubMerchant逻辑
* Class SubMerchantLogic
* @package app\adminapi\logic
*/
class SubMerchantLogic extends BaseLogic
{
/**
* @notes 添加
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/11/10 09:54
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
SubMerchant::create([
'sub_merchant_name' => $params['sub_merchant_name'],
'sub_mch_id' => $params['sub_mch_id'],
'province' => $params['province'],
'city' => $params['city'],
'area' => $params['area'],
'street' => $params['street'],
'village' => $params['village'],
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/11/10 09:54
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
SubMerchant::where('id', $params['id'])->update([
'sub_merchant_name' => $params['sub_merchant_name'],
'sub_mch_id' => $params['sub_mch_id'],
'province' => $params['province'],
'city' => $params['city'],
'area' => $params['area'],
'street' => $params['street'],
'village' => $params['village'],
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/11/10 09:54
*/
public static function delete(array $params): bool
{
return SubMerchant::destroy($params['id']);
}
/**
* @notes 获取详情
* @param $params
* @return array
* @author likeadmin
* @date 2023/11/10 09:54
*/
public static function detail($params): array
{
return SubMerchant::findOrEmpty($params['id'])->toArray();
}
}

View File

@ -0,0 +1,108 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate;
use app\common\validate\BaseValidate;
/**
* SubMerchant验证器
* Class SubMerchantValidate
* @package app\adminapi\validate
*/
class SubMerchantValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
'sub_merchant_name' => 'require',
'sub_mch_id' => 'require',
'province' => 'require',
'city' => 'require',
'area' => 'require',
'street' => 'require',
'village' => 'require',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'sub_merchant_name' => '子商户名',
'sub_mch_id' => '子商户号',
'province' => '省',
'city' => '市',
'area' => '区/县',
'street' => '镇',
'village' => '村',
];
/**
* @notes 添加场景
* @return SubMerchantValidate
* @author likeadmin
* @date 2023/11/10 09:54
*/
public function sceneAdd()
{
return $this->only(['sub_merchant_name','sub_mch_id','province','city','area','street','village']);
}
/**
* @notes 编辑场景
* @return SubMerchantValidate
* @author likeadmin
* @date 2023/11/10 09:54
*/
public function sceneEdit()
{
return $this->only(['id','sub_merchant_name','sub_mch_id','province','city','area','street','village']);
}
/**
* @notes 删除场景
* @return SubMerchantValidate
* @author likeadmin
* @date 2023/11/10 09:54
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return SubMerchantValidate
* @author likeadmin
* @date 2023/11/10 09:54
*/
public function sceneDetail()
{
return $this->only(['id']);
}
}