app->request->isPost()) { $param = $this->app->request->param(); if ($param['name'] == '') { $this->error("目录名不能为空"); } try { if ($param['id'] != 0) { SysMenuModel::update([ 'pid' => $param['pid'], 'name' => $param['name'], 'url' => $param['url'] ?: null, 'type' => $param['type'], 'icon' => $param['icon'] ], ['id'=>$param['id']]); } else { SysMenuModel::create([ 'pid' => $param['pid'], 'name' => $param['name'], 'url' => $param['url'] ?: null, 'type' => $param['type'], 'icon' => $param['icon'] ]); } // 删除菜单目录缓存 \think\Facade\Cache::set('menus', null); } catch (\Exception $e) { $msg = $e->getMessage(); $this->error("错误提示:".$msg); } $this->success('操作成功', 'sys_menu/index'); } else { if ($id != 0) { $data = SysMenuModel::find($id); } else { $data = [ 'id' => 0, 'pid' => 0, 'name' => '', 'url' => '', 'type' => 0, 'icon' =>'' ]; } View::assign('data', $data); return View::fetch(); } } public function delete($id = null) { if ($this->app->request->isAjax()) { if (SysMenuModel::where('pid', $id)->value('id')) { return ['code'=>0, 'msg'=>'此权限子权限不为空, 若要删除请先清空子权限']; } if (SysMenuModel::destroy($id)) { return ['code' => 1,'msg'=>"删除成功"]; } else { return ['code' => 0,'msg'=>"删除失败"]; } } } }