diff --git a/app/admin/controller/merchant/system/merchant/auth/Menu.php b/app/admin/controller/merchant/system/merchant/auth/Menu.php index 1c4efe0..7e0398a 100644 --- a/app/admin/controller/merchant/system/merchant/auth/Menu.php +++ b/app/admin/controller/merchant/system/merchant/auth/Menu.php @@ -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()); + } } } \ No newline at end of file diff --git a/app/admin/route/menu.php b/app/admin/route/menu.php index 7465915..5b15ac9 100644 --- a/app/admin/route/menu.php +++ b/app/admin/route/menu.php @@ -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([ diff --git a/app/admin/view/merchant/system/auth/add.html b/app/admin/view/merchant/system/auth/add.html index 49d2fca..2b494c5 100644 --- a/app/admin/view/merchant/system/auth/add.html +++ b/app/admin/view/merchant/system/auth/add.html @@ -11,7 +11,7 @@