商户菜单修改,移动商户model到commom
This commit is contained in:
parent
b74ab2b198
commit
842e365f8b
@ -9,8 +9,10 @@
|
||||
namespace app\admin\controller\merchant\system\merchant\auth;
|
||||
|
||||
use app\admin\BaseController;
|
||||
use app\admin\model\system\auth\Menu as MenuModel;
|
||||
use app\common\model\merchant\system\auth\Menu as MenuModel;
|
||||
use think\facade\View;
|
||||
use app\common\controller\FormatList;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
/**
|
||||
* class Menu
|
||||
@ -18,38 +20,114 @@ use app\common\controller\FormatList;
|
||||
class Menu extends BaseController
|
||||
{
|
||||
protected $menu;
|
||||
protected $is_mer;
|
||||
protected $url;
|
||||
protected $category_id;
|
||||
protected $params;
|
||||
|
||||
function __construct(MenuModel $menu) {
|
||||
// $this->adminInfo = get_login_admin();
|
||||
|
||||
$this->menu = $menu;
|
||||
|
||||
// 模块,0 平台, 1商户
|
||||
$this->is_mer = get_params('is_m', 0) == 0 ? 2 : 2;
|
||||
$this->category_id=354;
|
||||
$this->url=[
|
||||
'/admin/nk.classroom/index?category_id='.$this->category_id,
|
||||
'/admin/nk.classroom/add',
|
||||
'/admin/nk.classroom/edit',
|
||||
'/admin/nk.classroom/del',
|
||||
'/admin/nk.classroom/read',
|
||||
];
|
||||
$this->params = get_params() ;
|
||||
}
|
||||
|
||||
/**
|
||||
* 空白菜单页,由前端 ajax 获取数据
|
||||
*/
|
||||
function Index() {
|
||||
return view('merchant/system/auth/index',['url'=>$this->url]);
|
||||
return view('merchant/system/auth/index');
|
||||
}
|
||||
|
||||
function Lst(FormatList $formatList){
|
||||
/**
|
||||
* 菜单列表
|
||||
*/
|
||||
function Lst(){
|
||||
// 查出商户所有菜单数据
|
||||
$list = $this->menu->Search([], 1);
|
||||
$data = $this->menu->Search([], 1);
|
||||
|
||||
// 格式化成多维数组
|
||||
// $data = $formatList->FormatCategory($list['list'], "menu_id");
|
||||
to_assign(0,'操作成功',$list);
|
||||
// return view('merchant/system/auth/index',['url'=>$this->url]);
|
||||
to_assign(0,'',$data['list']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 表单页
|
||||
* TODO: 操作日志要另建表做关联
|
||||
* 操作日志待开发
|
||||
*
|
||||
*/
|
||||
function AddForm(FormatList $format){
|
||||
$id = isset($this->params['id']) ? $this->params['id'] : 0;
|
||||
$pid = isset($this->params['pid']) ? $this->params['pid'] : 0;
|
||||
if($id>0){
|
||||
$detail = $this->menu->Find($id);
|
||||
$detail['name'] = $detail['title'];
|
||||
View::assign('detail', $detail);
|
||||
}
|
||||
// 查出商户所有菜单数据
|
||||
$data = $this->menu->Search([], 1);
|
||||
$menus = $format->DropDownMenu($data['list']);
|
||||
|
||||
View::assign('id', $id);
|
||||
View::assign('pid', $pid);
|
||||
View::assign('menus',$menus);
|
||||
|
||||
return view('merchant/system/auth/add');
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加菜单
|
||||
*/
|
||||
function Add(){
|
||||
echo 'add';
|
||||
$this->params['src'] = preg_replace('# #','',$this->params['src']);
|
||||
// if ($param['id'] == 0) {
|
||||
try {
|
||||
validate(RuleCheck::class)->scene('add')->check($this->params);
|
||||
} catch (ValidateException $e) {
|
||||
// 验证失败 输出错误信息
|
||||
return to_assign(1, $e->getError());
|
||||
}
|
||||
$this->params['create_time'] = time();
|
||||
$rid = Db::name('AdminRule')->strict(false)->field(true)->insertGetId($this->params);
|
||||
//自动为系统所有者管理组分配新增的节点
|
||||
$group = Db::name('AdminGroup')->find(1);
|
||||
if (!empty($group)) {
|
||||
$newGroup['id'] = 1;
|
||||
$newGroup['rules'] = $group['rules'] . ',' . $rid;
|
||||
Db::name('AdminGroup')->strict(false)->field(true)->update($newGroup);
|
||||
add_log('add', $rid, $this->params);
|
||||
}
|
||||
// }
|
||||
// 删除后台节点缓存
|
||||
clear_cache('adminRules');
|
||||
return to_assign();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑菜单
|
||||
*/
|
||||
function Edit(){
|
||||
echo 'edit';
|
||||
if ($this->params['id'] > 0) {
|
||||
try {
|
||||
validate(RuleCheck::class)->scene('edit')->check($this->params);
|
||||
} catch (ValidateException $e) {
|
||||
// 验证失败 输出错误信息
|
||||
return to_assign(1, $e->getError());
|
||||
}
|
||||
Db::name('AdminRule')->strict(false)->field(true)->update($this->params);
|
||||
add_log('edit', $this->params['id'], $this->params);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除菜单
|
||||
*/
|
||||
function Del(){
|
||||
$id = get_params("id");
|
||||
try{
|
||||
$this->menu->Del($id);
|
||||
return to_assign(0, "删除节点成功");
|
||||
}catch(ValidateException $e){
|
||||
return to_assign(1, $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
@ -17,35 +17,6 @@ use app\common\middleware\LogMiddleware;
|
||||
|
||||
Route::group(function () {
|
||||
|
||||
//权限管理
|
||||
// Route::group('system/menu', function () {
|
||||
// Route::get('lst', '/getList')->name('systemMenuGetLst')->option([
|
||||
// '_alias' => '平台菜单/权限列表',
|
||||
// ]);
|
||||
// Route::get('create/form', '/createForm')->name('systemMenuCreateForm')->option([
|
||||
// '_alias' => '平台菜单/权限添加表单',
|
||||
// '_auth' => false,
|
||||
// '_form' => 'systemMenuCreate',
|
||||
// ]);
|
||||
// Route::get('update/form/:id', '/updateForm')->name('systemMenuUpdateForm')->option([
|
||||
// '_alias' => '平台菜单/权限编辑表单',
|
||||
// '_auth' => false,
|
||||
// '_form' => 'systemMenuUpdate',
|
||||
// ]);
|
||||
// Route::post('create', '/create')->name('systemMenuCreate')->option([
|
||||
// '_alias' => '平台菜单/权限添加',
|
||||
// ]);
|
||||
// Route::post('update/:id', '/update')->name('systemMenuUpdate')->option([
|
||||
// '_alias' => '平台菜单/权限编辑',
|
||||
// ]);
|
||||
// Route::delete('delete/:id', '/delete')->name('systemMenuDelete')->option([
|
||||
// '_alias' => '平台菜单/权限删除',
|
||||
// ]);
|
||||
// })->prefix('admin.system.auth.Menu')->option([
|
||||
// '_path' => '/setting/menu',
|
||||
// '_auth' => true,
|
||||
// ]);
|
||||
|
||||
//商户权限管理
|
||||
Route::group('merchant/menu', function () {
|
||||
Route::get('index', '/index')->name('systemMerchantMenuIndex')->option([
|
||||
@ -56,23 +27,24 @@ Route::group(function () {
|
||||
Route::get('lst', '/lst')->name('systemMerchantMenuGetLst')->append(['merchant' => 1])->option([
|
||||
'_alias' => '商户菜单/权限列表',
|
||||
]);
|
||||
Route::get('create/form', '/createForm')->name('systemMerchantMenuCreateForm')->append(['merchant' => 1])->option([
|
||||
|
||||
Route::post('add', '/add')->name('systemMerchantMenuCreate')->append(['merchant' => 1])->option([
|
||||
'_alias' => '商户菜单/权限添加',
|
||||
]);
|
||||
Route::post('edit/:id', '/edit')->name('systemMerchantMenuUpdate')->append(['merchant' => 1])->option([
|
||||
'_alias' => '商户菜单/权限编辑',
|
||||
]);
|
||||
Route::get('addform', '/AddForm')->name('systemMerchantMenuCreateForm')->append(['merchant' => 1])->option([
|
||||
'_alias' => '商户菜单/权限添加表单',
|
||||
'_auth' => false,
|
||||
'_form' => 'systemMerchantMenuCreate',
|
||||
]);
|
||||
Route::get('update/form/:id', '/updateForm')->name('systemMerchantMenuUpdateForm')->append(['merchant' => 1])->option([
|
||||
Route::get('editform', '/editform')->name('systemMerchantMenuUpdateForm')->append(['merchant' => 1])->option([
|
||||
'_alias' => '商户菜单/权限编辑表单',
|
||||
'_auth' => false,
|
||||
'_form' => 'systemMerchantMenuUpdate',
|
||||
]);
|
||||
Route::post('create', '/create')->name('systemMerchantMenuCreate')->append(['merchant' => 1])->option([
|
||||
'_alias' => '商户菜单/权限添加',
|
||||
]);
|
||||
Route::post('update/:id', '/update')->name('systemMerchantMenuUpdate')->append(['merchant' => 1])->option([
|
||||
'_alias' => '商户菜单/权限编辑',
|
||||
]);
|
||||
Route::delete('delete/:id', '/delete')->name('systemMerchantMenuDelete')->append(['merchant' => 1])->option([
|
||||
Route::delete('del/:id', '/del')->name('systemMerchantMenuDelete')->append(['merchant' => 1])->option([
|
||||
'_alias' => '商户菜单/权限删除',
|
||||
]);
|
||||
})->prefix('merchant.system.merchant.auth.Menu')->option([
|
||||
|
@ -11,7 +11,7 @@
|
||||
<td>
|
||||
<select name="pid" lay-verify="required" lay-reqText="请选择父级菜单/节点">
|
||||
<option value="0">作为顶级菜单/节点</option>
|
||||
{volist name=":set_recursion(get_admin_rule())" id="v"}
|
||||
{volist name="$menus" id="v"}
|
||||
<option value="{$v.id}" {eq name="pid" value="$v.id" }selected="" {/eq}>{$v.title} </option>
|
||||
{/volist}
|
||||
</select>
|
||||
@ -65,8 +65,8 @@
|
||||
<td>
|
||||
<select name="pid" lay-verify="required" lay-reqText="请选择父级菜单/节点">
|
||||
<option value="0">作为顶级节点</option>
|
||||
{volist name=":set_recursion(get_admin_rule())" id="v"}
|
||||
<option value="{$v.id}" {eq name="$detail.pid" value="$v.id" }selected="" {/eq}>{$v.title} </option>
|
||||
{volist name="$menus" id="v"}
|
||||
<option value="{$v.id}" {eq name="$detail.pid" value="$v.id" }selected="" {/eq}>{$v.title}</option>
|
||||
{/volist}
|
||||
</select>
|
||||
</td>
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author:刘孝全
|
||||
* @email:q8197264@126.com
|
||||
* @date :2023年03月2日
|
||||
* @date :2023年03月3日
|
||||
*/
|
||||
namespace app\common\controller;
|
||||
|
||||
@ -19,7 +19,7 @@ class FormatList
|
||||
* @param string $childrenKey 子级字段名
|
||||
* @return array
|
||||
*
|
||||
* @date 2020-03-27
|
||||
* @date 2023-03-3
|
||||
*/
|
||||
function FormatCategory(array $data, string $idName = "id", string $fieldName = 'pid', $childrenKey = 'children')
|
||||
{
|
||||
@ -37,4 +37,34 @@ class FormatList
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归排序,用于下拉分类选择菜单
|
||||
*
|
||||
* @param array $data 数据源
|
||||
* @param string $idName 主键
|
||||
* @param string $fieldName 父级字段
|
||||
* @param string $childrenKey 子级字段名
|
||||
* @return array
|
||||
*
|
||||
* @date 2023-03-3
|
||||
*/
|
||||
function DropDownMenu($result, $pid = 0, $level=-1)
|
||||
{
|
||||
/*记录排序后的类别数组*/
|
||||
static $list = array();
|
||||
static $space = ['','├─','§§├─','§§§§├─','§§§§§§├─'];
|
||||
$level++;
|
||||
foreach ($result as $k => $v) {
|
||||
if ($v['pid'] == $pid) {
|
||||
if ($pid != 0) {
|
||||
$v['title'] = $space[$level] . $v['title'];
|
||||
}
|
||||
/*将该类别的数据放入list中*/
|
||||
$list[] = $v;
|
||||
self::DropDownMenu($result, $v['id'],$level);
|
||||
}
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
}
|
51
app/common/model/merchant/system/Merchant.php
Normal file
51
app/common/model/merchant/system/Merchant.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* @usage 商户管理
|
||||
* @
|
||||
* @author 刘孝全
|
||||
*/
|
||||
namespace app\common\model\merchant\system;
|
||||
use think\model;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 商户管理model
|
||||
*/
|
||||
class Merchant extends Model
|
||||
{
|
||||
/**
|
||||
* 店铺类型.
|
||||
*
|
||||
*@param int $page 当前页数
|
||||
*@param int $limit 获取记录行数
|
||||
*
|
||||
*@return Array $list
|
||||
*/
|
||||
public function GetType($offset,$limit){
|
||||
$rows = empty($limit) ? get_config('app . page_size') : $limit;
|
||||
|
||||
$where = [];
|
||||
$list = self::where($where)
|
||||
->field('id,user_id,title,content,create_time,status,is_read,read_time')
|
||||
->page($offset)
|
||||
->limit($limit)
|
||||
->select();
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ 店铺类型说明
|
||||
*
|
||||
* return string
|
||||
*/
|
||||
public function GetDescription(){}
|
||||
|
||||
/**
|
||||
* @ 店铺保证金
|
||||
*
|
||||
* return list
|
||||
*/
|
||||
public function Getdeposit(){}
|
||||
|
||||
}
|
22
app/common/model/merchant/system/MerchantApplyments.php
Normal file
22
app/common/model/merchant/system/MerchantApplyments.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\common\model\merchant\system;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class MerchantApplyments extends Model
|
||||
{
|
||||
protected $table = "eb_merchant_intention";
|
||||
|
||||
function __construct(){}
|
||||
|
||||
function GetList(){
|
||||
$list = self::where()->select();
|
||||
|
||||
return $list;
|
||||
}
|
||||
}
|
108
app/common/model/merchant/system/auth/Menu.php
Normal file
108
app/common/model/merchant/system/auth/Menu.php
Normal file
@ -0,0 +1,108 @@
|
||||
<?php
|
||||
/**
|
||||
* 商户菜单 model
|
||||
*
|
||||
* @author:刘孝全
|
||||
* @email:q8197264@126.com
|
||||
* @date :2023年03月3日
|
||||
*/
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\common\model\merchant\system\auth;
|
||||
|
||||
use think\Model;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
/**
|
||||
* Class Menu
|
||||
*/
|
||||
class Menu extends Model
|
||||
{
|
||||
// 指定连接到商城库
|
||||
protected $connection = 'shop';
|
||||
|
||||
// 指定此model关联表
|
||||
protected $table = 'eb_system_menu';
|
||||
|
||||
/**
|
||||
* 按条件获取商户菜单数据
|
||||
*
|
||||
* @param array $where 过滤字段条件
|
||||
* @param int $is_mer 菜单类型: 0商城平台菜单 1商户菜单
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function Search(array $where=[], int $is_mer=2)
|
||||
{
|
||||
// 按条件 拼接 select 前sql
|
||||
$query = self::where('is_mer', $is_mer)
|
||||
->field('menu_id as id,pid, sort, route as src,icon,menu_name as title,is_show as status, is_menu as menu')
|
||||
->order('sort DESC,menu_id ASC');
|
||||
if (isset($where['pid'])) $query->where('pid', (int)$where['pid']);
|
||||
if (isset($where['keyword'])) $query->whereLike('menu_name|route', "%{$where['keyword']}%");
|
||||
if (isset($where['is_menu'])) $query->where('is_menu', (int)$where['is_menu']);
|
||||
|
||||
// 查询记录总行数
|
||||
$count = $query->count();
|
||||
|
||||
if (isset($where['offset'])) $query->page($where['offset'])->limit($where['limit']);
|
||||
|
||||
// 隐藏指定字段
|
||||
$list = $query->hidden(['update_time', 'path'])->select()->toArray();
|
||||
// 合并为一个数组并返回
|
||||
$data = compact('count', 'list');
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定行数据
|
||||
*
|
||||
* @return array $row
|
||||
*/
|
||||
function Find($id) {
|
||||
$row = self::where('menu_id', $id)
|
||||
->field('menu_id as id,pid, sort, route as src,icon,menu_name as title,is_show as status, is_menu as menu')
|
||||
->find();
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*/
|
||||
function Add() {}
|
||||
|
||||
/**
|
||||
* 更新
|
||||
*/
|
||||
function modify()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定菜单项
|
||||
* 由于有三种结果,建议用 try{}catch() 捕获
|
||||
*
|
||||
* @return bool||throw Exception
|
||||
*/
|
||||
function Del($id)
|
||||
{
|
||||
$count = self::where(["pid" => $id])->count();
|
||||
if ($count > 0) {
|
||||
throw new ValidateException('该节点下还有子节点,无法删除');
|
||||
return false;
|
||||
}
|
||||
if (self::delete($id) !== false) {
|
||||
clear_cache('adminRules');
|
||||
add_log('delete', $id, []);
|
||||
throw new ValidateException('删除节点成功');
|
||||
} else {
|
||||
throw new ValidateException('删除失败');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
14
app/common/model/merchant/system/auth/Role.php
Normal file
14
app/common/model/merchant/system/auth/Role.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace aapp\common\model\merchant\system\auth;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class Role extends Model
|
||||
{
|
||||
//
|
||||
}
|
14
app/common/model/merchant/system/merchant/MerchantType.php
Normal file
14
app/common/model/merchant/system/merchant/MerchantType.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\common\model\merchant\system\merchant;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class MerchantType extends Model
|
||||
{
|
||||
//
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user