addonName = 'shopro_huifu'; $this->addonPath = ADDON_PATH . 'shopro_huifu' . DS; $this->addons_path = $this->addonPath; parent::__construct(); } public function install() { Installer::run(); return true; } public function uninstall() { $pending = Db::name('shopro_order') ->where('pay_type', 'huifu_wechat') ->where('status', 'in', [0, 1, 2]) ->count(); if ($pending > 0) { throw new \Exception('存在未完结的汇付订单,请先处理后再卸载'); } $sql = file_get_contents(__DIR__ . '/uninstall.sql'); $prefix = config('database.prefix'); $sql = str_replace('fa_', $prefix, $sql); $statements = array_filter(array_map('trim', explode(';', $sql))); foreach ($statements as $statement) { if ($statement !== '') { try { Db::execute($statement); } catch (\Exception $e) { // ignore cleanup errors } } } Menu::delete('shopro_huifu'); Menu::delete('shopro_huifu/config'); return true; } public function enable() { Menu::enable('shopro_huifu/config'); return true; } public function disable() { Menu::disable('shopro_huifu/config'); Db::name('shopro_huifu_config')->where('name', 'miniprogram_channel')->update(['value' => 'yansongda']); return true; } public function appInit() { if (!defined('DEBUG')) { define('DEBUG', false); } elseif (DEBUG !== false) { define('HUIFU_DEBUG_BLOCKED', true); } $hooks = require __DIR__ . '/hooks.php'; foreach ($hooks as $tag => $behaviors) { foreach ((array) $behaviors as $behavior) { \think\Hook::add($tag, $behavior, true); } } } public function installMenu() { return Installer::installMenu(); } protected function runUpgradeSql() { $prefix = config('database.prefix'); $file = __DIR__ . '/upgrade_huifu_split.sql'; if (!is_file($file)) { return; } $sql = str_replace('fa_', $prefix, file_get_contents($file)); $statements = array_filter(array_map('trim', explode(';', $sql))); foreach ($statements as $statement) { if ($statement !== '') { try { Db::execute($statement); } catch (\Exception $e) { // column may already exist } } } } }