工会管理接口修改
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,3 +3,4 @@
|
|||||||
.idea
|
.idea
|
||||||
*.log
|
*.log
|
||||||
.env
|
.env
|
||||||
|
.node_modules
|
||||||
@@ -92,6 +92,24 @@ class Admin extends GuildAdmin
|
|||||||
$this->grouplist = $groupList;
|
$this->grouplist = $groupList;
|
||||||
$this->groupdata = $groupName;
|
$this->groupdata = $groupName;
|
||||||
$this->assignconfig("admin", ['id' => $this->auth->id, 'group_ids' => $this->auth->getGroupIds()]);
|
$this->assignconfig("admin", ['id' => $this->auth->id, 'group_ids' => $this->auth->getGroupIds()]);
|
||||||
|
|
||||||
|
$ruleList = db::name("vs_guild_admin_auth")->field('type,condition,remark,createtime,updatetime', true)->order('weigh DESC,id ASC')->select();
|
||||||
|
foreach ($ruleList as $k => &$v) {
|
||||||
|
$v['title'] = __($v['title']);
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($v);
|
||||||
|
Tree::instance()->init($ruleList);
|
||||||
|
$this->rulelist = Tree::instance()->getTreeArray(0);
|
||||||
|
$ruledata = [0 => __('None')];
|
||||||
|
foreach ($this->rulelist as $k => &$v) {
|
||||||
|
if (!$v['ismenu']) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$ruledata[$v['id']] = $v['title'];
|
||||||
|
unset($v['spacer']);
|
||||||
|
}
|
||||||
|
unset($v);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -217,6 +235,30 @@ class Admin extends GuildAdmin
|
|||||||
return V(1,"系统菜单接口", $ruleList);
|
return V(1,"系统菜单接口", $ruleList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getTree($ruleList,$fieldData=[]){
|
||||||
|
$ruledata = [];
|
||||||
|
$i= 0;
|
||||||
|
foreach ($ruleList as $k => &$v) {
|
||||||
|
if (!$v['ismenu']) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(!$this->auth->check($v['name'])){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
foreach ($fieldData as $key => $value) {
|
||||||
|
$ruledata[$i][$value] = $v[$value];
|
||||||
|
}
|
||||||
|
if(!empty($v['childlist'])){
|
||||||
|
$ruledata[$i]['childlist'] = $this->getTree($v['childlist'],$fieldData);
|
||||||
|
if(empty($ruledata[$i]['childlist'])){
|
||||||
|
unset($ruledata[$i]['childlist']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
return $ruledata;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 角色列表
|
* 角色列表
|
||||||
|
|||||||
142
application/guildAdmin/controller/Statistical.php
Normal file
142
application/guildAdmin/controller/Statistical.php
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\guildAdmin\controller;
|
||||||
|
|
||||||
|
use app\admin\command\Menu;
|
||||||
|
use app\GuildAdmin\model\AuthGroup;
|
||||||
|
use app\GuildAdmin\model\AuthGroupAccess;
|
||||||
|
use app\GuildAdmin\model\AuthRule;
|
||||||
|
use app\common\controller\GuildAdmin;
|
||||||
|
use fast\Random;
|
||||||
|
use fast\Tree;
|
||||||
|
use think\Cache;
|
||||||
|
use think\Db;
|
||||||
|
use think\Exception;
|
||||||
|
use think\Hook;
|
||||||
|
use think\Session;
|
||||||
|
use think\Validate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 管理员管理
|
||||||
|
*
|
||||||
|
* @icon fa fa-users
|
||||||
|
* @remark 一个管理员可以有多个角色组,左侧的菜单根据管理员所拥有的权限进行生成
|
||||||
|
*/
|
||||||
|
class Statistical extends GuildAdmin
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $noNeedLogin = [];
|
||||||
|
protected $noNeedRight = [];
|
||||||
|
protected $layout = '';
|
||||||
|
protected $table_guild_subsidy_config = 'vs_guild_subsidy_config';
|
||||||
|
protected $table_guild_subsidy = 'vs_guild_subsidy';
|
||||||
|
protected $table_guild_user = 'vs_guild_user';
|
||||||
|
protected $table_guild_data = 'vs_guild_data';
|
||||||
|
protected $table_guild = 'vs_guild';
|
||||||
|
public function _initialize()
|
||||||
|
{
|
||||||
|
parent::_initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
//用户申请列表
|
||||||
|
public function user_lists(){
|
||||||
|
$guild_id = $this->guildId;
|
||||||
|
$page = input('page', 1);
|
||||||
|
$page_limit = input('page_limit', 30);
|
||||||
|
$search_user_id = input('user_id', '');
|
||||||
|
$stime = input('stime', '');
|
||||||
|
$etime = input('etime', '');
|
||||||
|
$where = [];
|
||||||
|
$where['a.guild_id'] = $guild_id;
|
||||||
|
if ($search_user_id) {
|
||||||
|
$user_id = db::name('user')->where('user_code', $search_user_id)->value('id');
|
||||||
|
$where['a.user_id'] = $user_id;
|
||||||
|
}
|
||||||
|
if ($stime) {
|
||||||
|
$where['a.create_time'] = ['>=', $stime];
|
||||||
|
}
|
||||||
|
if ($etime) {
|
||||||
|
$where['a.create_time'] = ['<=', $etime];
|
||||||
|
}
|
||||||
|
$count = Db::name($this->table_guild_user)->alias('a')
|
||||||
|
->join('user b', 'a.user_id = b.id')
|
||||||
|
->where($where)
|
||||||
|
->where('a.status', 1)->count();
|
||||||
|
$lists = Db::name($this->table_guild_user)->alias('a')
|
||||||
|
->join('user b', 'a.user_id = b.id')
|
||||||
|
->field('a.id,a.user_id,a.status,a.createtime,a.apply_time,b.user_code,b.nickname')
|
||||||
|
->where($where)
|
||||||
|
->where('a.status', 1)
|
||||||
|
->order('a.id desc')
|
||||||
|
->page($page, $page_limit)
|
||||||
|
->select();
|
||||||
|
$lists_data = [];
|
||||||
|
foreach ($lists as $key => $value) {
|
||||||
|
$lists_data[$key] = $value;
|
||||||
|
$lists_data[$key]['createtime'] = date('Y-m-d H:i:s', $value['createtime']);
|
||||||
|
}
|
||||||
|
$return_data = [
|
||||||
|
'page' =>$page,
|
||||||
|
'page_limit' => $page_limit,
|
||||||
|
'count' => $count,
|
||||||
|
'lists' => $lists_data
|
||||||
|
];
|
||||||
|
return V(1,"成功", $return_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
//房间数据统计
|
||||||
|
public function room_lists(){
|
||||||
|
$guild_id = $this->guildId;
|
||||||
|
$page = input('page', 1);
|
||||||
|
$page_limit = input('page_limit', 30);
|
||||||
|
$search_room_id = input('room_id', '');
|
||||||
|
$stime = input('stime', '');
|
||||||
|
$etime = input('etime', '');
|
||||||
|
$where = [];
|
||||||
|
$where['a.guild_id'] = $guild_id;
|
||||||
|
if ($search_room_id) {
|
||||||
|
$where['b.room_number'] = $search_room_id;
|
||||||
|
}
|
||||||
|
$search_stime = '';
|
||||||
|
$search_etime = '';
|
||||||
|
if ($stime) {
|
||||||
|
$where['a.create_time'] = ['>=', $stime];
|
||||||
|
$search_stime = strtotime($stime);
|
||||||
|
}
|
||||||
|
if ($etime) {
|
||||||
|
$where['a.create_time'] = ['<=', $etime];
|
||||||
|
$search_etime = strtotime($etime);
|
||||||
|
}
|
||||||
|
$count = Db::name($this->table_guild_user)->alias('a')
|
||||||
|
->join('vs_room b', 'a.room_id = b.id')
|
||||||
|
->where($where)
|
||||||
|
->where('a.status', 1)->count();
|
||||||
|
$lists = Db::name($this->table_guild_user)->alias('a')
|
||||||
|
->join('vs_room b', 'a.room_id = b.id')
|
||||||
|
->field('a.id,a.room_id,a.status,a.createtime,a.apply_time,b.room_number,b.room_name')
|
||||||
|
->where($where)
|
||||||
|
->where('a.status', 1)
|
||||||
|
->order('a.id desc')
|
||||||
|
->page($page, $page_limit)
|
||||||
|
->select();
|
||||||
|
$lists_data = [];
|
||||||
|
foreach ($lists as $key => $value) {
|
||||||
|
$lists_data[$key]['room_number'] = $value['room_number'];
|
||||||
|
$lists_data[$key]['room_name'] = $value['room_name'];
|
||||||
|
//送礼流水
|
||||||
|
$lists_data[$key]['consumption']= model('adminapi/Room')->getRoomFlow($value['room_id'],$search_stime,$search_etime);
|
||||||
|
//绩效流水
|
||||||
|
|
||||||
|
//送礼人数
|
||||||
|
$lists_data[$key]['gift_num'] = db::name('vs_give_gift')->where(['from_id'=>$value['room_id'],'from'=>2])->count();
|
||||||
|
$lists_data[$key]['createtime'] = date('Y-m-d H:i:s', $value['createtime']);
|
||||||
|
}
|
||||||
|
$return_data = [
|
||||||
|
'page' =>$page,
|
||||||
|
'page_limit' => $page_limit,
|
||||||
|
'count' => $count,
|
||||||
|
'lists' => $lists_data
|
||||||
|
];
|
||||||
|
return V(1,"成功", $return_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
70
application/guildAdmin/controller/SystemMessage.php
Normal file
70
application/guildAdmin/controller/SystemMessage.php
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\guildAdmin\controller;
|
||||||
|
|
||||||
|
use app\admin\command\Menu;
|
||||||
|
use app\GuildAdmin\model\AuthGroup;
|
||||||
|
use app\GuildAdmin\model\AuthGroupAccess;
|
||||||
|
use app\GuildAdmin\model\AuthRule;
|
||||||
|
use app\common\controller\GuildAdmin;
|
||||||
|
use fast\Random;
|
||||||
|
use fast\Tree;
|
||||||
|
use think\Cache;
|
||||||
|
use think\Db;
|
||||||
|
use think\Exception;
|
||||||
|
use think\Hook;
|
||||||
|
use think\Session;
|
||||||
|
use think\Validate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 管理员管理
|
||||||
|
*
|
||||||
|
* @icon fa fa-users
|
||||||
|
* @remark 一个管理员可以有多个角色组,左侧的菜单根据管理员所拥有的权限进行生成
|
||||||
|
*/
|
||||||
|
class SystemMessage extends GuildAdmin
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $noNeedLogin = [];
|
||||||
|
protected $noNeedRight = [];
|
||||||
|
protected $layout = '';
|
||||||
|
protected $table_guild_subsidy_config = 'vs_guild_subsidy_config';
|
||||||
|
protected $table_guild_subsidy = 'vs_guild_subsidy';
|
||||||
|
protected $table_guild_user = 'vs_guild_user';
|
||||||
|
protected $table_guild_data = 'vs_guild_data';
|
||||||
|
protected $table_guild = 'vs_guild';
|
||||||
|
public function _initialize()
|
||||||
|
{
|
||||||
|
parent::_initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
//用户申请列表
|
||||||
|
public function message_lists(){
|
||||||
|
$guild_id = $this->guildId;
|
||||||
|
$page = input('page', 1);
|
||||||
|
$page_limit = input('page_limit', 30);
|
||||||
|
$where['delete_time'] = 0;
|
||||||
|
$where['receiving_id'] = $guild_id;
|
||||||
|
$count = db::name('system_message')->where($where)->count();
|
||||||
|
$lists = db::name('system_message')->where($where)->page($page, $page_limit)->select();
|
||||||
|
|
||||||
|
$lists_data =[];
|
||||||
|
foreach ($lists as $key => $value) {
|
||||||
|
$lists_data[$key]['title'] = $value['title'];
|
||||||
|
$lists_data[$key]['content'] = $value['content'];
|
||||||
|
$lists_data[$key]['createtime'] = date('Y-m-d H:i:s', $value['createtime']);
|
||||||
|
$lists_data[$key]['type_name'] = $value['type'] == 1 ? '系统消息' : '官方公告';
|
||||||
|
$lists_data[$key]['admin_name'] = db::name('admin')->where('id', $value['admin_id'])->value('nickname');
|
||||||
|
//提醒方式:1 站内 2短信
|
||||||
|
$lists_data[$key]['remind_type_str'] = $value['remind_type'] == 1 ? '站内' : '短信';
|
||||||
|
|
||||||
|
}
|
||||||
|
$return_data = [
|
||||||
|
'page' =>$page,
|
||||||
|
'page_limit' => $page_limit,
|
||||||
|
'count' => $count,
|
||||||
|
'lists' => $lists_data
|
||||||
|
];
|
||||||
|
return V(1,"成功", $return_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,7 +13,7 @@ use think\Hook;
|
|||||||
use think\Request;
|
use think\Request;
|
||||||
use think\Session;
|
use think\Session;
|
||||||
|
|
||||||
class Auth extends \fast\Auth
|
class Auth extends \fast\GuildaAuth
|
||||||
{
|
{
|
||||||
protected $_error = '';
|
protected $_error = '';
|
||||||
protected $requestUri = '';
|
protected $requestUri = '';
|
||||||
@@ -320,8 +320,10 @@ class Auth extends \fast\Auth
|
|||||||
public function getRuleIds($uid = null)
|
public function getRuleIds($uid = null)
|
||||||
{
|
{
|
||||||
$uid = is_null($uid) ? $this->id : $uid;
|
$uid = is_null($uid) ? $this->id : $uid;
|
||||||
// return parent::getRuleIds($uid);
|
|
||||||
// 执行查询
|
// 执行查询
|
||||||
|
if($uid==1){
|
||||||
|
return parent::getRuleIds($uid);
|
||||||
|
}else{
|
||||||
$user_groups = Db::name('vs_guild_admin_auth_group_access')
|
$user_groups = Db::name('vs_guild_admin_auth_group_access')
|
||||||
->alias('aga')
|
->alias('aga')
|
||||||
->join('fa_vs_guild_admin_auth_group ag', 'aga.group_id = ag.id', 'LEFT')
|
->join('fa_vs_guild_admin_auth_group ag', 'aga.group_id = ag.id', 'LEFT')
|
||||||
@@ -337,6 +339,7 @@ class Auth extends \fast\Auth
|
|||||||
$ids = array_unique($ids);
|
$ids = array_unique($ids);
|
||||||
return $ids;
|
return $ids;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function isSuperAdmin()
|
public function isSuperAdmin()
|
||||||
{
|
{
|
||||||
|
|||||||
265
extend/fast/GuildaAuth.php
Normal file
265
extend/fast/GuildaAuth.php
Normal file
@@ -0,0 +1,265 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Copyright (c) 2011 http://thinkphp.cn All rights reserved.
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: luofei614 <weibo.com/luofei614>
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | 修改者: anuo (本权限类在原3.2.3的基础上修改过来的)
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace fast;
|
||||||
|
|
||||||
|
use think\Db;
|
||||||
|
use think\Config;
|
||||||
|
use think\Session;
|
||||||
|
use think\Request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 权限认证类
|
||||||
|
* 功能特性:
|
||||||
|
* 1,是对规则进行认证,不是对节点进行认证。用户可以把节点当作规则名称实现对节点进行认证。
|
||||||
|
* $auth=new Auth(); $auth->check('规则名称','用户id')
|
||||||
|
* 2,可以同时对多条规则进行认证,并设置多条规则的关系(or或者and)
|
||||||
|
* $auth=new Auth(); $auth->check('规则1,规则2','用户id','and')
|
||||||
|
* 第三个参数为and时表示,用户需要同时具有规则1和规则2的权限。 当第三个参数为or时,表示用户值需要具备其中一个条件即可。默认为or
|
||||||
|
* 3,一个用户可以属于多个用户组(think_auth_group_access表 定义了用户所属用户组)。我们需要设置每个用户组拥有哪些规则(think_auth_group 定义了用户组权限)
|
||||||
|
* 4,支持规则表达式。
|
||||||
|
* 在think_auth_rule 表中定义一条规则,condition字段就可以定义规则表达式。 如定义{score}>5 and {score}<100
|
||||||
|
* 表示用户的分数在5-100之间时这条规则才会通过。
|
||||||
|
*/
|
||||||
|
class GuildaAuth
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var object 对象实例
|
||||||
|
*/
|
||||||
|
protected static $instance;
|
||||||
|
protected $rules = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前请求实例
|
||||||
|
* @var Request
|
||||||
|
*/
|
||||||
|
protected $request;
|
||||||
|
//默认配置
|
||||||
|
protected $config = [
|
||||||
|
'auth_on' => 1, // 权限开关
|
||||||
|
'auth_type' => 1, // 认证方式,1为实时认证;2为登录认证。
|
||||||
|
'auth_group' => 'vs_guild_auth_group', // 用户组数据表名
|
||||||
|
'auth_group_access' => 'vs_guild_auth_group_access', // 用户-用户组关系表
|
||||||
|
'auth_rule' => 'vs_guild_auth_rule', // 权限规则表
|
||||||
|
'auth_user' => 'user', // 用户信息表
|
||||||
|
];
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
if ($auth = Config::get('auth')) {
|
||||||
|
$this->config = array_merge($this->config, $auth);
|
||||||
|
}
|
||||||
|
// 初始化request
|
||||||
|
$this->request = Request::instance();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化
|
||||||
|
* @access public
|
||||||
|
* @param array $options 参数
|
||||||
|
* @return Auth
|
||||||
|
*/
|
||||||
|
public static function instance($options = [])
|
||||||
|
{
|
||||||
|
if (is_null(self::$instance)) {
|
||||||
|
self::$instance = new static($options);
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::$instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查权限
|
||||||
|
* @param string|array $name 需要验证的规则列表,支持逗号分隔的权限规则或索引数组
|
||||||
|
* @param int $uid 认证用户的id
|
||||||
|
* @param string $relation 如果为 'or' 表示满足任一条规则即通过验证;如果为 'and'则表示需满足所有规则才能通过验证
|
||||||
|
* @param string $mode 执行验证的模式,可分为url,normal
|
||||||
|
* @return bool 通过验证返回true;失败返回false
|
||||||
|
*/
|
||||||
|
public function check($name, $uid, $relation = 'or', $mode = 'url')
|
||||||
|
{
|
||||||
|
if (!$this->config['auth_on']) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// 获取用户需要验证的所有有效规则列表
|
||||||
|
$rulelist = $this->getRuleList($uid);
|
||||||
|
if (in_array('*', $rulelist)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_string($name)) {
|
||||||
|
$name = strtolower($name);
|
||||||
|
if (strpos($name, ',') !== false) {
|
||||||
|
$name = explode(',', $name);
|
||||||
|
} else {
|
||||||
|
$name = [$name];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$list = []; //保存验证通过的规则名
|
||||||
|
if ('url' == $mode) {
|
||||||
|
$REQUEST = unserialize(strtolower(serialize($this->request->param())));
|
||||||
|
}
|
||||||
|
foreach ($rulelist as $rule) {
|
||||||
|
$query = preg_replace('/^.+\?/U', '', $rule);
|
||||||
|
if ('url' == $mode && $query != $rule) {
|
||||||
|
parse_str($query, $param); //解析规则中的param
|
||||||
|
$intersect = array_intersect_assoc($REQUEST, $param);
|
||||||
|
$rule = preg_replace('/\?.*$/U', '', $rule);
|
||||||
|
if (in_array($rule, $name) && $intersect == $param) {
|
||||||
|
//如果节点相符且url参数满足
|
||||||
|
$list[] = $rule;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (in_array($rule, $name)) {
|
||||||
|
$list[] = $rule;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ('or' == $relation && !empty($list)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
$diff = array_diff($name, $list);
|
||||||
|
if ('and' == $relation && empty($diff)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据用户id获取用户组,返回值为数组
|
||||||
|
* @param int $uid 用户id
|
||||||
|
* @return array 用户所属的用户组 array(
|
||||||
|
* array('uid'=>'用户id','group_id'=>'用户组id','name'=>'用户组名称','rules'=>'用户组拥有的规则id,多个,号隔开'),
|
||||||
|
* ...)
|
||||||
|
*/
|
||||||
|
public function getGroups($uid)
|
||||||
|
{
|
||||||
|
static $groups = [];
|
||||||
|
if (isset($groups[$uid])) {
|
||||||
|
return $groups[$uid];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 执行查询
|
||||||
|
$user_groups = Db::name('vs_guild_admin_auth_group_access')
|
||||||
|
->alias('aga')
|
||||||
|
->join('__' . 'vs_guild_admin_auth_group' . '__ ag', 'aga.group_id = ag.id', 'LEFT')
|
||||||
|
->field('aga.uid,aga.group_id,ag.id,ag.pid,ag.name,ag.rules')
|
||||||
|
->where("aga.uid='{$uid}' and ag.status='normal'")
|
||||||
|
->select();
|
||||||
|
$groups[$uid] = $user_groups ?: [];
|
||||||
|
return $groups[$uid];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得权限规则列表
|
||||||
|
* @param int $uid 用户id
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getRuleList($uid)
|
||||||
|
{
|
||||||
|
static $_rulelist = []; //保存用户验证通过的权限列表
|
||||||
|
if (isset($_rulelist[$uid])) {
|
||||||
|
return $_rulelist[$uid];
|
||||||
|
}
|
||||||
|
if (2 == $this->config['auth_type'] && Session::has('_guild_rule_list_' . $uid)) {
|
||||||
|
return Session::get('_guild_rule_list_' . $uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 读取用户规则节点
|
||||||
|
$ids = $this->getRuleIds($uid);
|
||||||
|
if (empty($ids)) {
|
||||||
|
$_rulelist[$uid] = [];
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 筛选条件
|
||||||
|
$where = [
|
||||||
|
'status' => 'normal'
|
||||||
|
];
|
||||||
|
if (!in_array('*', $ids)) {
|
||||||
|
$where['id'] = ['in', $ids];
|
||||||
|
}
|
||||||
|
//读取用户组所有权限规则
|
||||||
|
$this->rules = Db::name("vs_guild_admin_auth")->where($where)->field('id,pid,condition,icon,name,title,ismenu')->select();
|
||||||
|
|
||||||
|
//循环规则,判断结果。
|
||||||
|
$rulelist = []; //
|
||||||
|
if (in_array('*', $ids)) {
|
||||||
|
$rulelist[] = "*";
|
||||||
|
}
|
||||||
|
foreach ($this->rules as $rule) {
|
||||||
|
//超级管理员无需验证condition
|
||||||
|
if (!empty($rule['condition']) && !in_array('*', $ids)) {
|
||||||
|
//根据condition进行验证
|
||||||
|
$user = $this->getUserInfo($uid); //获取用户信息,一维数组
|
||||||
|
$nums = 0;
|
||||||
|
$condition = str_replace(['&&', '||'], "\r\n", $rule['condition']);
|
||||||
|
$condition = preg_replace('/\{(\w*?)\}/', '\\1', $condition);
|
||||||
|
$conditionArr = explode("\r\n", $condition);
|
||||||
|
foreach ($conditionArr as $index => $item) {
|
||||||
|
preg_match("/^(\w+)\s?([\>\<\=]+)\s?(.*)$/", trim($item), $matches);
|
||||||
|
if ($matches && isset($user[$matches[1]]) && version_compare($user[$matches[1]], $matches[3], $matches[2])) {
|
||||||
|
$nums++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($conditionArr && ((stripos($rule['condition'], "||") !== false && $nums > 0) || count($conditionArr) == $nums)) {
|
||||||
|
$rulelist[$rule['id']] = strtolower($rule['name']);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//只要存在就记录
|
||||||
|
$rulelist[$rule['id']] = strtolower($rule['name']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$_rulelist[$uid] = $rulelist;
|
||||||
|
//登录验证则需要保存规则列表
|
||||||
|
if (2 == $this->config['auth_type']) {
|
||||||
|
//规则列表结果保存到session
|
||||||
|
Session::set('_guild_rule_list_' . $uid, $rulelist);
|
||||||
|
}
|
||||||
|
return array_unique($rulelist);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRuleIds($uid)
|
||||||
|
{
|
||||||
|
//读取用户所属用户组
|
||||||
|
$groups = $this->getGroups($uid);
|
||||||
|
$ids = []; //保存用户所属用户组设置的所有权限规则id
|
||||||
|
foreach ($groups as $g) {
|
||||||
|
$ids = array_merge($ids, explode(',', trim($g['rules'], ',')));
|
||||||
|
}
|
||||||
|
$ids = array_unique($ids);
|
||||||
|
return $ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得用户资料
|
||||||
|
* @param int $uid 用户id
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
protected function getUserInfo($uid)
|
||||||
|
{
|
||||||
|
static $user_info = [];
|
||||||
|
|
||||||
|
$user = Db::name($this->config['auth_user']);
|
||||||
|
// 获取用户表主键
|
||||||
|
$_pk = is_string($user->getPk()) ? $user->getPk() : 'uid';
|
||||||
|
if (!isset($user_info[$uid])) {
|
||||||
|
$user_info[$uid] = $user->where($_pk, $uid)->find();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $user_info[$uid];
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user