123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- <?php
- namespace addons\notice;
- use addons\notice\library\GatewayTool;
- use addons\notice\library\NoticeClient;
- use app\common\library\Menu;
- use think\Addons;
- use think\Request;
- /**
- * 插件
- */
- class Notice extends Addons
- {
- /**
- * 应用初始化
- */
- public function appInit()
- {
- // 公共方法
- require_once __DIR__ . '/library/common/helper.php';
- if ($this->getConfig()['admin_real'] == 2 || $this->getConfig()['user_real'] == 2) {
- require_once __DIR__ . '/library/libs/GatewayClient/Gateway.php';
- GatewayTool::init();
- }
- if (request()->isCli()) {
- \think\Console::addDefaultCommands([
- 'addons\notice\library\libs\GatewayWorker\server'
- ]);
- }
- }
- /**
- * @param $params
- */
- public function configInit(&$params)
- {
- $config = $this->getConfig();
- if ($config['wss_switch'] == 1) {
- $protocol = 'wss://';
- } else {
- $protocol = 'ws://';
- }
- $wsurl = $protocol .\request()->host() . ':' . $config['websocket_port'];
- $params['notice'] = [
- 'admin_real' => $config['admin_real'],
- 'wsurl' => $wsurl,
- 'user_real_url' => $config['user_real_url'],
- 'user_real' => $config['user_real']
- ];
- }
- /**
- * 插件安装方法
- *
- * @return bool
- */
- public function install()
- {
- $config_file = ADDON_PATH . "notice" . DS . 'config' . DS . "menu.php";
- $menu = include $config_file;
- Menu::create($menu);
- return true;
- }
- /**
- * 插件卸载方法
- *
- * @return bool
- */
- public function uninstall()
- {
- Menu::delete("notice");
- Menu::delete("notice/admin");
- return true;
- }
- /**
- * 插件启用方法
- *
- * @return bool
- */
- public function enable()
- {
- Menu::enable("notice");
- Menu::enable("notice/admin");
- return true;
- }
- /**
- * 插件禁用方法
- *
- * @return bool
- */
- public function disable()
- {
- Menu::disable("notice");
- Menu::disable("notice/admin");
- return true;
- }
- /**
- * 会员中心边栏后
- *
- * @return mixed
- * @throws \Exception
- */
- public function userSidenavAfter()
- {
- $request = Request::instance();
- $actionname = strtolower($request->action());
- $data = [
- 'actionname' => $actionname,
- ];
- return $this->fetch('view/hook/user_sidenav_after', $data);
- }
- /**
- * 发送消息
- */
- public function sendNotice($params)
- {
- return NoticeClient::instance()->trigger($params['event'], $params['params']);
- }
- }
|