// +---------------------------------------------------------------------- // +---------------------------------------------------------------------- // | 表单插件 // +---------------------------------------------------------------------- namespace addons\formguide; use app\common\library\Menu; use think\Addons; use think\Db; use think\facade\Config; class Formguide extends Addons { //后台菜单 public $menu = [ [ "name" => "formguide", "title" => "表单管理", "icon" => "iconfont icon-file-list-3-line", "sublist" => [ [ "name" => "formguide.formguide", "title" => "表单管理", "icon" => "iconfont icon-file-list-3-line", "sublist" => [ ["name" => "formguide.formguide/index", "title" => "查看"], ["name" => "formguide.formguide/add", "title" => "新增"], ["name" => "formguide.formguide/edit", "title" => "编辑"], ["name" => "formguide.formguide/del", "title" => "删除"], ], ], [ "name" => "formguide.field", "title" => "字段管理", "ismenu" => 0, "sublist" => [ ["name" => "formguide.field/index", "title" => "查看"], ["name" => "formguide.field/add", "title" => "新增"], ["name" => "formguide.field/edit", "title" => "编辑"], ["name" => "formguide.field/del", "title" => "删除"], ["name" => "formguide.info/index", "title" => "信息列表"], ["name" => "formguide.info/public_view", "title" => "信息查看"], ["name" => "formguide.info/del", "title" => "信息删除"], ], ], ], ], ]; //安装 public function install() { $info = get_addon_info('cms'); if (!$info || $info['status'] != 1) { throw new \think\Exception("请在后台插件管理中安装《内容管理系统》并启用后再尝试"); } Menu::create($this->menu); return true; } /** * 插件卸载方法 * @return bool */ public function uninstall() { $droptables = request()->param("droptables"); $auth = \app\admin\service\User::instance(); //只有开启调试且为超级管理员才允许删除相关数据库 if ($droptables && Config::get("app_debug") && $auth->isAdministrator()) { //删除模型中建的表 $table_list = Db::name('model')->where('module', 'formguide')->field('tablename,id')->select(); if ($table_list) { foreach ($table_list as $val) { $tablename = Config::get('database.prefix') . $val['tablename']; Db::execute("DROP TABLE IF EXISTS `{$tablename}`;"); Db::name('model_field')->where('modelid', $val['id'])->delete(); } } } //删除模型中的表 Db::name('model')->where('module', 'formguide')->delete(); Menu::delete("formguide"); return true; } /** * 插件启用方法 * @return bool */ public function enable() { Menu::enable("formguide"); return true; } /** * 插件禁用方法 * @return bool */ public function disable() { Menu::disable("formguide"); return true; } }