1
0
Files
2020-08-06 14:58:51 +08:00

110 lines
3.4 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace app\system\controller;
use app\common\model\Auth as AuthModel;
use app\common\model\AuthUser as AuthUserModel;
use think\Config;
use think\Db;
use tools\Initialize;
class _Init extends Initialize
{
public function _initialize()
{
define('UID', self::isLogin());
if (!UID) {
$this->redirect('login/index');
}
if (!$this->checkAuth(UID, CONTROLLER_NAME . '/' . ACTION_NAME)) {
return $this->error('没有操作权限');
}
}
/**
* 操作成功跳转的快捷方法
* @access protected
* @param mixed $msg 提示信息
* @param string $url 跳转的URL地址
* @param mixed $data 返回的数据
* @param integer $wait 跳转等待时间
* @param array $header 发送的Header信息
* @return void
*/
protected function success($msg = '', $url = null, $data = '', $wait = 3, array $header = [])
{
$msg = $msg ?: '操作成功';
return parent::success($msg, $url, $data, $wait, $header);
}
/**
* 操作错误跳转的快捷方法
* @access protected
* @param mixed $msg 提示信息
* @param string $url 跳转的URL地址
* @param mixed $data 返回的数据
* @param integer $wait 跳转等待时间
* @param array $header 发送的Header信息
* @return void
*/
protected function error($msg = '', $url = null, $data = '', $wait = 3, array $header = [])
{
$msg = $msg ?: '未知错误';
return parent::error($msg, $url, $data, $wait, $header);
}
protected function back($result)
{
if ($result === true) {
return $this->success();
} else {
return $this->error($result);
}
}
/**
* 检查授权
* @param [type] $uid 用户id
* @param [type] $node 节点名 menu/index
* @return [type] [description]
*/
public function checkAuth($uid, $node)
{
//查询设置的超级管理的ids
$adminUsers = Config::get('administrator');
if (!in_array($uid, $adminUsers)) {
//获取当前页的菜单id
$nodes = Db::name('Menu')->where('url', $node)->value('id');
if ($nodes) {
//获取当前用户的授权节点
$authId = AuthUserModel::where('uid', $uid)->column('auth_id');
$rules = AuthModel::where('id', 'in', $authId)->column('rules');
if ($rules) {
$rules = implode($rules, ',');
$rules = explode(',', $rules);
$rules = array_unique($rules);
if (in_array($nodes, $rules)) {
return true;
} else {
return false;
}
} else {
return false;
}
} else {
return true;
}
} else {
return true;
}
}
}