| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- <?php
- namespace addons\fastchat;
- use app\admin\model\Admin;
- use app\common\library\Menu;
- use think\Addons;
- use think\Cookie;
- /**
- * 插件
- */
- class Fastchat extends Addons
- {
- /**
- * 插件安装方法
- * @return bool
- */
- public function install()
- {
- // 创建菜单
- $menu = [
- [
- 'name' => 'fastchat',
- 'title' => '即时通信管理',
- 'icon' => 'fa fa-comments',
- 'sublist' => [
- [
- 'name' => 'fastchat/pushmessage',
- 'title' => '推送消息',
- 'icon' => 'fa fa-circle-o',
- 'sublist' => [
- ['name' => 'fastchat/pushmessage/index', 'title' => '推送消息']
- ]
- ],
- [
- 'name' => 'fastchat/serviceuser',
- 'title' => '服务账号管理',
- 'icon' => 'fa fa-circle-o',
- 'sublist' => [
- ['name' => 'fastchat/serviceuser/index', 'title' => '查看'],
- ['name' => 'fastchat/serviceuser/add', 'title' => '添加'],
- ['name' => 'fastchat/serviceuser/edit', 'title' => '编辑'],
- ['name' => 'fastchat/serviceuser/del', 'title' => '删除'],
- ['name' => 'fastchat/serviceuser/multi', 'title' => '批量更新'],
- ['name' => 'fastchat/serviceuser/recyclebin', 'title' => '回收站'],
- ['name' => 'fastchat/serviceuser/destroy', 'title' => '真实删除'],
- ['name' => 'fastchat/serviceuser/restore', 'title' => '还原'],
- ]
- ],
- ]
- ]
- ];
- Menu::create($menu);
- return true;
- }
- /**
- * 插件卸载方法
- * @return bool
- */
- public function uninstall()
- {
- // 删除命令
- $command_file = APP_PATH . 'command.php';
- $command_item = 'addons\fastchat\library\GatewayWorker\start';
- if (is_file($command_file)) {
- $fullConfigArr = include $command_file;
- }
- $command_existing = false;
- foreach ($fullConfigArr as $key => $value) {
- if ($value == $command_item) {
- $command_existing = true;
- unset($fullConfigArr[$key]);
- }
- }
- if ($command_existing) {
- if (is_really_writable($command_file)) {
- if ($handle = fopen($command_file, 'w')) {
- fwrite($handle, "<?php\n\n" . "return " . var_export($fullConfigArr, TRUE) . ";\n");
- fclose($handle);
- }
- }
- }
- Menu::delete('fastchat');
- return true;
- }
- /**
- * 注册命令
- */
- public function appInit()
- {
- if (request()->isCli()) {
- \think\Console::addDefaultCommands([
- 'addons\fastchat\library\GatewayWorker\start'
- ]);
- }
- }
- /**
- * 插件启用方法
- * @return bool
- */
- public function enable()
- {
- return true;
- }
- /**
- * 插件禁用方法
- * @return bool
- */
- public function disable()
- {
- return true;
- }
- /*
- * 管理员登陆时的行为事件
- */
- public function adminLoginAfter($admin_request)
- {
- try {
- $username = $admin_request->post('username');
- if ($username) {
- $admin = Admin::get(['username' => $username]);
- if ($admin) {
- $keeptime = 864000;
- $expiretime = time() + $keeptime;
- $key = md5(md5($admin->id) . md5($keeptime) . md5($expiretime) . $admin->token);
- $data = [$admin->id, $keeptime, $expiretime, $key];
- Cookie::set('fastchat_admin', implode('|', $data), $keeptime);
- }
- }
- } catch (\think\exception\PDOException $e) {
- } catch (\think\Exception $e) {
- // 防止出现异常造成管理员无法登录
- }
- }
- }
|