文件
xionggeshop/addons/shopro_wechat_trade/Shopro_wechat_trade.php

76 行
2.0 KiB
PHP

<?php
namespace addons\shopro_wechat_trade;
use addons\shopro_wechat_trade\library\Installer;
use app\common\library\Menu;
use think\Addons;
class Shopro_wechat_trade extends Addons
{
public function __construct()
{
$this->addonName = 'shopro_wechat_trade';
$this->addonPath = ADDON_PATH . 'shopro_wechat_trade' . DS;
$this->addons_path = $this->addonPath;
parent::__construct();
}
public function install()
{
Installer::run();
return true;
}
public function uninstall()
{
$sql = file_get_contents(__DIR__ . '/uninstall.sql');
$prefix = config('database.prefix');
$sql = str_replace('__PREFIX__', $prefix, $sql);
$statements = array_filter(array_map('trim', explode(';', $sql)));
foreach ($statements as $statement) {
if ($statement !== '') {
try {
\think\Db::execute($statement);
} catch (\Exception $e) {
// ignore
}
}
}
Menu::delete('shopro_wechat_trade');
Menu::delete('shopro_wechat_trade/config');
Menu::delete('shopro_wechat_trade/sync');
return true;
}
public function enable()
{
Menu::enable('shopro_wechat_trade/config');
Menu::enable('shopro_wechat_trade/sync');
return true;
}
public function disable()
{
Menu::disable('shopro_wechat_trade/config');
Menu::disable('shopro_wechat_trade/sync');
return true;
}
public function appInit()
{
if (!class_exists('\\addons\\shopro_wechat_trade\\library\\Bridge')) {
return;
}
if (!\addons\shopro_wechat_trade\library\Bridge::isEnabled()) {
return;
}
$hooks = require __DIR__ . '/hooks.php';
foreach ($hooks as $tag => $behaviors) {
foreach ((array) $behaviors as $behavior) {
\think\Hook::add($tag, $behavior, true);
}
}
}
}