Files
duolamaojiazhen/application/admin/server/AuthServer.php
2025-12-22 13:59:40 +08:00

100 lines
2.7 KiB
PHP
Raw 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
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
namespace app\admin\server;
use think\Db;
class AuthServer
{
/**
* 获取角色没有的权限id
* @param int $role_id
* @return array
*/
public static function getRoleNoneAuthIds($role_id)
{
if ($role_id == 0) {
return [];
}
$role_auth = self::getRoleAuth($role_id);
$all_auth = self::getAllAuth();
return array_diff($all_auth, $role_auth);
}
/**
* 获取角色没有的uri
* @param $role_id
*/
public static function getRoleNoneAuthUris($role_id)
{
$ids = self::getRoleNoneAuthIds($role_id);
$result = Db::name('dev_auth')
->where('id', 'in', $ids)
->column('uri');
$data = [];
foreach ($result as $k => $v) {
if (empty($v)) {
continue;
}
$data[] = strtolower($v);
}
return $data;
}
/**
* 获取角色权限
* @param $role_id
* @return array
*/
private static function getRoleAuth($role_id)
{
return Db::name('role_dev_auth_index')
->where(['role_id' => $role_id])
->column('menu_auth_id');
}
/**
* 获取系统所有权限
* @return array
*/
private static function getAllAuth()
{
return Db::name('dev_auth')
->where(['del' => 0, 'disable' => 0])
->column('id');
}
/**
* 获取用户没有权限uri
* @param $role_id
* @return array
*/
public static function getRoleNoneAuthArr($role_id)
{
return Db::name('dev_auth')
->where('id', 'in', self::getRoleNoneAuthIds($role_id))
->column('uri');
}
}