/** * 后台控制器初始化 */ protected function _initialize() { // 获取当前用户ID if (defined('UID')) { return; } $user = get_user(); if (!$user) { $this->redirect('Other/Public/login?type=miss_token'); } $this->_user = $user; define('UID', $user['uid']); if (!session('admin_login')) { // 缓存用户信息 session('user_auth', ['uid' => $user['uid'], 'uname' => $user['uname']]); session('admin_login', true); } // 是否是超级管理员 define('IS_ROOT', is_administrator()); // 检测系统权限 if (!IS_ROOT) { $access = $this->accessControl(); if (false === $access) { $this->error('403:禁止访问'); } elseif (null === $access) { // 检测访问权限 $rule = strtolower(MODULE_NAME . '/' . CONTROLLER_NAME . '/' . ACTION_NAME); if (!$this->checkRule($rule, array('in', '1,2'))) { $this->error('未授权用户:' . $user['uname']); } else { // 检测分类及内容有关的各项动态权限 $dynamic = $this->checkDynamic(); if (false === $dynamic) { $this->error('未授权用户:' . $user['uname']); } } } } // 初始化数据表 $this->_table = $this->_table ?: str_replace('/', '_', CONTROLLER_NAME); $this->assign('__MENU__', $this->getMenus()); $this->assign('_node_name', $this->_node_name); // 初始化通知 $notificationModel = new \Common\Model\SystemNotificationModel(); $notificationModel->updateStatus() or system_warn($notificationModel->getError()); $type = session('SYSTEM_NOTIFICATION_TYPE'); if (!is_array($type)) { $type = []; foreach (D('SystemNotification')->type_config as $key => $config) { if (check_auth($config[2])) { $type[] = $key; } } session('SYSTEM_NOTIFICATION_TYPE', $type); } $this->assign('notification_is_allow', check_auth('system/notification')); $this->assign('notification', $type ? M('SystemNotification')->where(['is_read' => 0, 'type' => ['in', $type]])->count() : 0); $this->_log(); }
public function index() { if (I('id') > 0) { $this->_action(); return; } if (I('get.type') == 'check') { $notificationModel = new \Common\Model\SystemNotificationModel(); $notificationModel->updateStatus() or system_warn($notificationModel->getError()); $where = $this->_getWhere(); $unread = M($this->_table)->where($where)->count(); $last_id = session('SYSTEM_NOTIFICATION_LAST_ID') + 0; $where['id'] = ['gt', $last_id]; $unread_new = M($this->_table)->where($where)->count(); session('SYSTEM_NOTIFICATION_LAST_ID', max($last_id, M($this->_table)->where($where)->max('id'))); ajax_success(['unread' => $unread, 'new' => $unread_new]); } parent::index(); }