207 行
5.6 KiB
PHP
可执行文件
207 行
5.6 KiB
PHP
可执行文件
<?php
|
|
|
|
namespace addons\shopro;
|
|
|
|
use think\Addons;
|
|
use app\common\library\Menu;
|
|
use app\admin\model\AuthRule;
|
|
use addons\shopro\library\Hook;
|
|
|
|
/**
|
|
* Shopro插件 v3.0.0
|
|
*/
|
|
class Shopro extends Addons
|
|
{
|
|
|
|
/**
|
|
* 插件安装方法
|
|
* @return bool
|
|
*/
|
|
public function install()
|
|
{
|
|
// 创建菜单
|
|
$menu = self::getMenu();
|
|
Menu::create($menu['new']);
|
|
self::flattenShoproMenus();
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* 插件卸载方法
|
|
* @return bool
|
|
*/
|
|
public function uninstall()
|
|
{
|
|
// 删除菜单
|
|
$ids = AuthRule::where('name', 'like', 'shopro%')->column('id');
|
|
if ($ids) {
|
|
AuthRule::destroy($ids);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* 插件启用方法
|
|
*/
|
|
public function enable()
|
|
{
|
|
// 启用菜单
|
|
AuthRule::where('name', 'like', 'shopro%')->update(['status' => 'normal']);
|
|
self::flattenShoproMenus();
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* 插件更新方法
|
|
*/
|
|
public function upgrade()
|
|
{
|
|
// 更新菜单
|
|
$menu = self::getMenu();
|
|
Menu::upgrade('shopro', $menu['new']);
|
|
self::flattenShoproMenus();
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* 插件禁用方法
|
|
*/
|
|
public function disable()
|
|
{
|
|
// 禁用菜单
|
|
AuthRule::where('name', 'like', 'shopro%')->update(['status' => 'hidden']);
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
/**
|
|
* 应用初始化
|
|
*/
|
|
public function appInit()
|
|
{
|
|
// 公共方法
|
|
require_once __DIR__ . '/helper/helper.php';
|
|
|
|
// 覆盖队列 redis 参数
|
|
$queue = \think\Config::get('queue');
|
|
$redis = \think\Config::get('redis');
|
|
if ($queue && strtolower($queue['connector']) == 'redis' && $redis) {
|
|
$queue = array_merge($redis, $queue); // queue.php 中的配置,覆盖 redis.php 中的配置
|
|
\think\Config::set('queue', $queue);
|
|
}
|
|
|
|
// database 增加断线重连参数
|
|
$database = \think\Config::get('database');
|
|
$database['break_reconnect'] = true; // 断线重连
|
|
\think\Config::set('database', $database);
|
|
|
|
// 全局注册行为事件
|
|
Hook::register();
|
|
|
|
if (request()->isCli()) {
|
|
\think\Console::addDefaultCommands([
|
|
'addons\shopro\console\ShoproChat',
|
|
'addons\shopro\console\ShoproHelp',
|
|
'addons\shopro\console\PartnerSettle',
|
|
'addons\shopro\console\PartnerInstall',
|
|
'addons\shopro\console\PartnerDemo',
|
|
'addons\shopro\console\PartnerAccept',
|
|
'addons\shopro\console\PartnerClean',
|
|
'addons\shopro\console\PartnerTransferCommission',
|
|
]);
|
|
}
|
|
|
|
// 全局共享 暗色类型 变量
|
|
\think\View::share('DARK_TYPE', $this->getDarkType());
|
|
}
|
|
|
|
|
|
|
|
public function configInit(&$config)
|
|
{
|
|
// 全局 js共享 暗色类型 变量
|
|
$config['dark_type'] = $this->getDarkType();
|
|
}
|
|
|
|
|
|
private static function getMenu()
|
|
{
|
|
$newMenu = [];
|
|
$config_file = ADDON_PATH . "shopro" . DS . 'config' . DS . "menu.php";
|
|
if (is_file($config_file)) {
|
|
$newMenu = include $config_file;
|
|
}
|
|
$oldMenu = AuthRule::where('name', 'like', "shopro%")->select();
|
|
$oldMenu = array_column($oldMenu, null, 'name');
|
|
return ['new' => $newMenu, 'old' => $oldMenu];
|
|
}
|
|
|
|
/**
|
|
* 业务菜单提到一级侧栏,shopro 只作插件根节点(不显示)
|
|
*/
|
|
public static function flattenShoproMenus()
|
|
{
|
|
$root = AuthRule::getByName('shopro');
|
|
if (!$root) {
|
|
return;
|
|
}
|
|
|
|
AuthRule::where('id', $root['id'])->update([
|
|
'ismenu' => 0,
|
|
'title' => 'Shopro',
|
|
]);
|
|
|
|
AuthRule::where('pid', $root['id'])->where('ismenu', 1)->update(['pid' => 0]);
|
|
|
|
$weighs = [
|
|
'shopro/dashboard' => 300,
|
|
'shopro/order' => 290,
|
|
'shopro/goods' => 280,
|
|
'shopro/user/user' => 270,
|
|
'shopro/commission' => 260,
|
|
'shopro/withdraw' => 250,
|
|
'shopro/activity/activity' => 240,
|
|
'shopro/decorate' => 230,
|
|
'shopro/chat' => 220,
|
|
'shopro/wechat' => 210,
|
|
'shopro/feedback' => 200,
|
|
'shopro/config' => 190,
|
|
'shopro/dispatch/dispatch' => 180,
|
|
'shopro/notification/config' => 170,
|
|
'shopro/data' => 160,
|
|
];
|
|
foreach ($weighs as $name => $weigh) {
|
|
AuthRule::where('name', $name)->update(['weigh' => $weigh]);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* 获取暗黑类型
|
|
*
|
|
* @return string
|
|
*/
|
|
private function getDarkType()
|
|
{
|
|
$dark_type = 'none';
|
|
if (in_array('darktheme', get_addonnames())) {
|
|
// 有暗黑主题
|
|
$darkthemeConfig = get_addon_config('darktheme');
|
|
$dark_type = $darkthemeConfig['mode'] ?? 'none';
|
|
|
|
$thememode = cookie("thememode");
|
|
if ($thememode && in_array($thememode, ['dark', 'light'])) {
|
|
$dark_type = $thememode;
|
|
}
|
|
}
|
|
|
|
return $dark_type;
|
|
}
|
|
}
|