商户分类功能

This commit is contained in:
liuxiaoquan 2023-03-16 16:19:42 +08:00
parent 0103fca160
commit d54d6bd588
10 changed files with 566 additions and 76 deletions

View File

@ -1,86 +1,163 @@
<?php
declare (strict_types = 1);
/**
* @date 2023年03月16日
* @author刘孝全
* @emailq8197264@126.com
*
* @ 商户分类管理
*/
namespace app\admin\controller\merchant\system\merchant;
use app\admin\BaseController;
use think\App;
use think\Request;
use app\validate\merchant\admin\MerchantCategoryValidate;
use app\admin\BaseController;
use app\api\controller\Validate;
use app\common\model\merchant\system\merchant\Merchant;
use app\common\model\merchant\system\merchant\MerchantCategory as MerchantCategoryModel;
use think\facade\View;
use think\exception\ValidateException;
class MerchantCategory extends BaseController
{
/**
* 显示资源列表
*
* @return \think\Response
*/
public function lst()
protected $model;
protected $path = [
'index' => 'merchant/system/merchant/category/lst',
'add'=>'merchant/system/merchant/category/add',
'edit'=>'merchant/system/merchant/category/edit',
];
public function __construct(App $app, MerchantCategoryModel $model)
{
//
parent::__construct($app);
$this->model = $model;
}
/**
* 显示创建资源表单页.
*
* @return \think\Response
* 分类列表页
*/
public function create()
public function index()
{
//
return View($this->path['index']);
}
/**
* 保存新建的资源
*
* @param \think\Request $request
* @return \think\Response
* 添加分类表单页
*/
public function save(Request $request)
public function addForm()
{
//
return View($this->path['add']);
}
/**
* 显示指定的资源
*
* @param int $id
* @return \think\Response
*/
public function read($id)
{
//
}
/**
* 显示编辑资源表单页.
*
* @param int $id
* @return \think\Response
*/
public function edit($id)
public function editForm()
{
//
$id = (int) get_params('id');
if (!$this->model->idIsExists($id))
return to_assign(1, '数据不存在');
$info = $this->model->get($id);
View::assign('info', $info);
return View($this->path['edit']);
}
/**
* 显示资源列表
*
* @return \think\Response
*/
public function list()
{
$params = get_params();
$page = empty($params['page'])? 1 : (int)$params['page'];
$limit = empty($params['limit'])? (int)get_config('app . page_size') : (int)$params['limit'];
$data = $this->model->getList([], $page, $limit);
return to_assign(0, '', $data);
}
/**
* 保存更新的资源
* 添加分类
*
* @param \think\Request $request
* @param int $id
* @return \think\Response
*/
public function update(Request $request, $id)
public function add(MerchantCategoryValidate $validate)
{
//
try{
$data = $this->checkParams($validate);
$data['commission_rate'] = bcdiv($data['commission_rate'], '100', 4);
$this->model->create($data);
}catch(ValidateException $e){
return to_assign(1, $e->getError());
}
return to_assign(0, '添加成功');
}
/**
* 编辑分类
*/
public function edit(MerchantCategoryValidate $validate)
{
$id = (int)get_params('id');
$data = get_params(['category_name','commission_rate']);
try{
$data = $this->checkParams($validate);
if (!$this->model->idIsExists($id))
return to_assign(1, '数据不存在');
$data['commission_rate'] = bcdiv($data['commission_rate'], '100', 4);
$this->model->modify($id, $data);
}catch(ValidateException $e){
return to_assign(1, $e->getError());
}
return to_assign(0, '编辑成功');
}
/**
* 删除指定资源
*
* @param int $id
* @return \think\Response
* 删除指定分类
*/
public function delete($id)
public function del(Merchant $merchant)
{
//
$id = (int) get_params('id');
try{
if (!$this->model->idIsExists($id))
return to_assign(1, '数据不存在');
if ($merchant->fieldExists('category_id', $id))
return to_assign(1, '存在商户,无法删除');
$this->model->remove($id);
}catch(ValidateException $e){
return to_assign(1, $e->getError());
}
return to_assign(0, '删除成功');
}
/** ------------------------ protected func -----------*/
/**
* 检查http传参
*/
protected function checkParams(MerchantCategoryValidate $validate)
{
$data = get_params(['category_name', 'commission_rate']);
$validate->check($data);
return $data;
}
}

View File

@ -9,28 +9,27 @@ use think\facade\Route;
Route::group(function(){
// 商户分类
Route::group('/merchant/classify', function(){
Route::get('lst', '/lst')->name('systemMerchantCategoryLst')->option([
Route::get('index', '/index')->name('systemMerchantCategoryLst')->option([
'_alias' => '商户分类列表',
]);
// Route::get('category_lst', '/lst')->option([
// '_alias' => '商户分类列表',
// '_auth' => false,
// ]);
Route::post('add', '/create')->name('systemMerchantCategoryCreate')->option([
Route::get('lst', '/list')->name('systemMerchantCategoryLst')->option([
'_alias' => '商户分类列表',
]);
Route::post('add', '/add')->name('systemMerchantCategoryCreate')->option([
'_alias' => '商户分类添加',
]);
Route::get('form', '/createForm')->name('systemMerchantCategoryCreateForm')->option([
Route::get('add', '/addForm')->name('systemMerchantCategoryCreateForm')->option([
'_alias' => '商户分类添加表单',
'_auth' => false,
'_form' => 'systemMerchantCategoryCreate',
]);
Route::delete('del/:id', '/delete')->name('systemMerchantCategoryDelete')->option([
Route::delete('del', '/del')->name('systemMerchantCategoryDelete')->option([
'_alias' => '商户分类删除',
]);
Route::post('edit/:id', '/update')->name('systemMerchantCategoryUpdate')->option([
Route::post('edit', '/edit')->name('systemMerchantCategoryUpdate')->option([
'_alias' => '商户分类编辑',
]);
Route::get('edit/form/:id', '/updateForm')->name('systemMerchantCategoryUpdateForm')->option([
Route::get('edit', '/editForm')->name('systemMerchantCategoryUpdateForm')->option([
'_alias' => '商户分类编辑表单',
'_auth' => false,
'_form' => 'systemMerchantCategoryUpdate',

View File

@ -0,0 +1,86 @@
{extend name="common/base"/}
{block name="style"}
<style type="text/css">
.editormd-code-toolbar select {
display: inline-block
}
.editormd li {
list-style: inherit;
}
</style>
{/block}
<!-- 主体 -->
{block name="body"}
<form class="layui-form p-4">
<h3 class="pb-3">添加商户分类</h3>
<table class="layui-table layui-table-form">
<tr>
<td colspan="2" class="layui-td-gray">分类名称<font>*</font></td>
<td colspan="6">
<input type="text" name="category_name" lay-verify="required" lay-reqText="请输入分类名称"
autocomplete="off" placeholder="请输入分类名称" class="layui-input" value="">
</td>
</tr>
<tr>
<td colspan="2" class="layui-td-gray">手续费(%)</td>
<td colspan="6">
<input type="number" name="commission_rate" lay-reqText="0" autocomplete="off" placeholder="0" class="layui-input" value="0">
</td>
<td colspan="5">%</td>
</tr>
</table>
<div class="pt-3">
<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform" type='button'>立即提交</button>
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
</div>
</form>
{/block}
<!-- /主体 -->
<!-- 脚本 -->
{block name="script"}
<script src="/static/assets/js/xm-select.js"></script>
<script>
var moduleInit = ['tool','treeGrid', 'tagpicker', 'tinymce', 'admin'];
var group_access = "{:session('gougu_admin')['group_access']}"
function gouguInit() {
var treeGrid = layui.treeGrid,table = layui.table
var tool = layui.tool;
var form = layui.form, tool = layui.tool, tagspicker = layui.tagpicker;
var editor = layui.tinymce;
var edit = editor.render({
selector: "#container_content",
height: 500,
});
//监听提交
form.on('submit(webform)', function (data) {
if (data.field == '') {
layer.msg('请先完善分类表单');
return false;
}
let callback = function (e) {
layer.msg(e.msg);
if (e.code == 0) {
tool.tabRefresh(71);
tool.sideClose(1000);
}
}
tool.post('/admin/merchant/classify/add', data.field, callback);
return true;
});
}
</script>
{/block}
<!-- /脚本 -->

View File

@ -0,0 +1,80 @@
{extend name="common/base"/}
{block name="style"}
<style type="text/css">
.editormd-code-toolbar select {
display: inline-block
}
.editormd li {
list-style: inherit;
}
</style>
{/block}
<!-- 主体 -->
{block name="body"}
<form class="layui-form p-4">
<h3 class="pb-3">编辑商户分类</h3>
<input type="hidden" name="id" value="{$info.merchant_category_id}">
<table class="layui-table layui-table-form">
<tr>
<td colspan="2" class="layui-td-gray">分类名称<font>*</font></td>
<td colspan="6">
<input type="text" name="category_name" lay-verify="required" lay-reqText="请输入分类名称"
autocomplete="off" placeholder="请输入分类名称" class="layui-input" value="{$info.category_name}">
</td>
</tr>
<tr>
<td colspan="2" class="layui-td-gray">手续费(%)</td>
<td colspan="6">
<input type="number" name="commission_rate" lay-reqText="0" autocomplete="off" placeholder="0" class="layui-input" value="{$info.commission_rate}">
</td>
<td colspan="5">%</td>
</tr>
</table>
<div class="pt-3">
<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform" type='button'>立即提交</button>
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
</div>
</form>
{/block}
<!-- /主体 -->
<!-- 脚本 -->
{block name="script"}
<script src="/static/assets/js/xm-select.js"></script>
<script>
var moduleInit = ['tool', 'admin'];
var group_access = "{:session('gougu_admin')['group_access']}"
function gouguInit() {
var tool = layui.tool;
var form = layui.form;
//监听提交
form.on('submit(webform)', function (data) {
if (data.field == '') {
layer.msg('请先完善分类表单');
return false;
}
let callback = function (e) {
layer.msg(e.msg);
if (e.code == 0) {
tool.tabRefresh(71);
tool.sideClose(1000);
}
}
tool.post('/admin/merchant/classify/edit', data.field, callback);
return true;
});
}
</script>
{/block}
<!-- /脚本 -->

View File

@ -0,0 +1,121 @@
{extend name="common/base"/}
<!-- 主体 -->
{block name="body"}
<div class="p-3">
<table class="layui-hide" id="store_classify" lay-filter="store_classify"></table>
</div>
<script type="text/html" id="toolbarDemo">
<div class="layui-btn-container">
<span class="layui-btn layui-btn-sm side-alert" lay-event="add" data-title="添加商品">+ 添加分类</span>
</div>
</script>
<script type="text/html" id="barDemo">
<div class="layui-btn-group">
<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</div>
</script>
{/block}
<!-- /主体 -->
<!-- 脚本 -->
{block name="script"}
<script>
const moduleInit = ['tool'];
function gouguInit() {
var table = layui.table,tool = layui.tool, form = layui.form;
layui.pageTable = table.render({
elem: '#store_classify',
title: '分类列表',
toolbar: '#toolbarDemo',
url: '/admin/merchant/classify/lst',
parseData: function(res){ //res 即为原始返回的数据
return {
"code": res.code, //解析接口状态
"msg": res.msg, //解析提示文本
"count": res.data.count, //解析数据长度
"data": res.data.list //解析数据列表
};
},
done: function (res, curr, count){
$('table').width('100%');
},
page: true,
limit: 20,
cellMinWidth: 100,
cols: [
[
{
fixed: 'ID',
field: 'merchant_category_id',
title: '编号',
align: 'center',
width: 80
},
{
field: 'category_name',
title: '分类名称',
align: 'center',
width: 180
},{
field: 'commission_rate',
title: '手续费',
align: 'center',
width: 150
},{
field: 'create_time',
title: '创建时间',
align: 'center',
width: 200
},
{
fixed: 'right',
field: 'right',
title: '操作',
toolbar: '#barDemo',
width: 180,
align: 'center'
}
]
]
});
//监听表头工具栏事件
table.on('toolbar(store_classify)', function(obj){
if (obj.event === 'add') {
tool.side("/admin/merchant/classify/add");
return false;
}
});
//监听表格行工具事件
table.on('tool(store_classify)', function(obj) {
console.log(obj)
var data = obj.data;
if (obj.event === 'edit') {
tool.side('/admin/merchant/classify/edit?id='+data.merchant_category_id);
}else if (obj.event === 'del') {
layer.confirm('确定要删除该记录吗?', {
icon: 3,
title: '提示'
}, function(index) {
let callback = function (e) {
layer.msg(e.msg);
if (e.code == 0) {
obj.del();
// tool.tabRefresh(71);
}
}
tool.delete("/admin/merchant/classify/del", { id: data.merchant_category_id }, callback);
layer.close(index);
});
}
return false;
});
}
</script>
{/block}
<!-- /脚本 -->

View File

@ -207,8 +207,9 @@
<script type="text/html" id="refundToolbar"></script>
<script type="text/html" id="refundBar">
<div class="layui-btn-group">
<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="status">审核</a>
<a class="layui-btn layui-btn-xs" lay-event="mark">备注</a>
<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="status">审核</a>
<a class="layui-btn layui-btn-xs" lay-event="record">扣费记录</a>
</div>
</script>
@ -218,6 +219,7 @@
{block name="script"}
<script>
const moduleInit = ['tool'];
function gouguInit() {
var table = layui.table, tool = layui.tool, form = layui.form;
@ -301,12 +303,24 @@
});
function refundList(data){
layui.refundTable = table.render({
layui.refundTable = table.render({
elem: '#refund_list',
title: '退回保证金列表',
toolbar: '#refundToolbar',
url: '/admin/margin/refund/lst',
parseData:(res)=>{
return {
"code": res.code, //解析接口状态
"msg": res.msg, //解析提示文本
"count": res.data.count, //解析数据长度
"data": res.data.list //解析数据列表
};
},
where: {
...data
},
page: true,
limit: 20,
cellMinWidth: 300,
@ -330,7 +344,7 @@
title: '店铺类型',
align: 'center',
width: 220,
templet: '<div>{{d.merchant.type_id}}</div>'
templet: '<div>{{d.merchant.merchantType.type_name}}</div>'
}, {
field: 'real_name',
title: '商户姓名',
@ -345,14 +359,44 @@
templet: '<div>{{d.merchant.margin}}</div>'
}, {
field: 'status',
title: '状态',
title: '保证金申请状态',
align: 'center',
width: 150
width: 150,
templet:(d)=>{
switch(d.status) {
case 0:
return '待审核';
case 1:
return '通过';
case -1:
return '未通过';
}
}
}, {
field: 'pay_time',
title: '支付时间',
field: 'create_time',
title: '申请时间',
align: 'center',
width: 150
},{
field: 'extract_money',
title: '结余保证金',
align: 'center',
width: 150
},{
field: 'financial_status',
title: '退回状态',
align: 'center',
width: 150,
templet:(d)=>{
switch(d.status) {
case 0:
return '未退';
// case 1:
// return '通过';
// case -1:
// return '未通过';
}
}
},
{
fixed: 'right',
@ -366,6 +410,8 @@
]
});
}
// 获取表单所有参数
function getformdata() {
@ -399,9 +445,10 @@
if (obj.event === 'status') {
alert("审核");
tool.post('/admin/margin/status?id=' + obj.data.mer_id, obj.data);
} else if (obj.event === 'mark') {
tool.side('/admin/margin/form?id=' + obj.data.mer_id);
} else if (obj.event === 'record') {
tool.side('/admin/margin/read?id=' + obj.data.mer_id);
}
return false;
@ -418,6 +465,8 @@
marign.style.display = "block";
refund.style.display = "none";
}else{
let data = getformdata();
refundList(data)
refund.style.display = "block";
marign.style.display = "none";
}
@ -445,7 +494,7 @@
}
,where: {
...dataRload
}
},
});
}
};
@ -480,7 +529,8 @@
if ('11'==this.getAttribute('lay-id')) {
active['reload'] ? active['reload'].call(this, othis) : '';
}else{
active['refund_reload'] ? active['refund_reload'].call(this, othis) : '';
// refundList()
// active['refund_reload'] ? active['refund_reload'].call(this, othis) : '';
}
});
@ -498,7 +548,7 @@
return false;
});
// 监听select 提交
form.on('select(searchform)', function(e) {
let data = getformdata();
layui.payTable.reload({

View File

@ -7,7 +7,7 @@ declare (strict_types = 1);
* @emailq8197264@126.com
* @date 2023年03月3日
*/
namespace aapp\common\model\merchant\system\auth;
namespace app\common\model\merchant\system\auth;
use think\Model;
@ -16,5 +16,7 @@ use think\Model;
*/
class Role extends Model
{
//
protected $connection = 'shop';
protected $table = 'eb_system_role';
protected $pk = 'role_id';
}

View File

@ -368,6 +368,9 @@ class Merchant extends Model
$merchant->save();
}
/**
* 统计字段数
*/
public function sumFieldNum(int $merId, int $num, string $field)
{
if ($num < 0) $num = -$num;
@ -378,13 +381,13 @@ class Merchant extends Model
}
/**
/**
* 判断字段是否存在
*
* @param $field
* @param $value
* @param int|null $except
* @return bool
* @author xaboy
* @day 2020-03-30
*/
public function fieldExists($field, $value, ?int $except = null): bool
{

View File

@ -1,6 +1,12 @@
<?php
declare (strict_types = 1);
/**
* @date 2023年03月16日
* @author刘孝全
* @emailq8197264@126.com
*
* @ 商户分类管理model
*/
namespace app\common\model\merchant\system\merchant;
use think\Model;
@ -14,11 +20,54 @@ class MerchantCategory extends Model
protected $table = 'eb_merchant_category';
protected $pk = 'merchant_category_id';
/**
* 获取商户的分类列表
*/
public function getList(array $where, $page, $limit)
{
$query = MerchantCategory::alias('a');
$count = $query->count($this->getPk());
$list = $query->page($page, $limit)->select()->toArray();
foreach ($list as $k => $v) {
$list[$k]['commission_rate'] = ($v['commission_rate'] > 0 ? bcmul($v['commission_rate'], '100', 2) : 0) . '%';
}
return compact('count', 'list');
}
/**
* 查询指定分类
*/
public function get($id)
{
$res = self::find($id)->toArray();
$res['commission_rate'] = $res['commission_rate'] > 0 ? bcmul($res['commission_rate'], '100', 2) : 0;
return $res;
}
/**
* 更新信息
*/
public function modify(int $id, array $data)
{
$rows = self::where($this->getPk(), $id)->update($data);
return $rows;
}
/**
* 删除
*/
public function remove(int $id)
{
return self::where($this->getPk(), $id)->delete();
}
/**
*
* @param int $id
* @return bool
* @author xaboy
* @day 2020-03-27
*/
public function idIsExists(int $id)
{
@ -30,8 +79,6 @@ class MerchantCategory extends Model
* @param $value
* @param int|null $except
* @return bool
* @author xaboy
* @day 2020-03-30
*/
public function fieldExists($field, $value, ?int $except = null): bool
{
@ -40,4 +87,7 @@ class MerchantCategory extends Model
return $query->count() > 0;
}
/** ----------------- protected func -------------- */
}

View File

@ -0,0 +1,22 @@
<?php
/**
* @date 2023年03月16日
* @author刘孝全
* @emailq8197264@126.com
*
* @ 商户分类参数验证
*/
namespace app\validate\merchant\admin;
use think\Validate;
class MerchantCategoryValidate extends Validate
{
protected $failException = true;
protected $rule = [
'category_name|分类名称' => 'require|max:32',
'commission_rate|手续费' => 'require|float|>=:0|<=:100'
];
}