133 lines
3.8 KiB
PHP
133 lines
3.8 KiB
PHP
<?php
|
||
/**
|
||
* 商户菜单管理
|
||
*
|
||
* @author:刘孝全
|
||
* @email:q8197264@126.com
|
||
* @date :2023年03月3日
|
||
*/
|
||
namespace app\admin\controller\merchant\system\auth;
|
||
|
||
use app\admin\BaseController;
|
||
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
|
||
*/
|
||
class Menu extends BaseController
|
||
{
|
||
protected $menu;
|
||
protected $params;
|
||
|
||
function __construct(MenuModel $menu) {
|
||
// $this->adminInfo = get_login_admin();
|
||
|
||
$this->menu = $menu;
|
||
|
||
$this->params = get_params() ;
|
||
}
|
||
|
||
/**
|
||
* 空白菜单页,由前端 ajax 获取数据
|
||
*/
|
||
function Index() {
|
||
return view('merchant/system/auth/menu/index');
|
||
}
|
||
|
||
/**
|
||
* 菜单列表
|
||
*/
|
||
function Lst(){
|
||
// 查出商户所有菜单数据
|
||
$data = $this->menu->getList([], 1);
|
||
|
||
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->getList([], 1);
|
||
$menus = $format->DropDownMenu($data['list']);
|
||
|
||
View::assign('id', $id);
|
||
View::assign('pid', $pid);
|
||
View::assign('menus',$menus);
|
||
|
||
return view('merchant/system/auth/menu/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());
|
||
}
|
||
}
|
||
} |