初始化-安装依赖
This commit is contained in:
94
server/plugin/saiadmin/app/cache/ConfigCache.php
vendored
Normal file
94
server/plugin/saiadmin/app/cache/ConfigCache.php
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: sai <1430792918@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace plugin\saiadmin\app\cache;
|
||||
|
||||
use plugin\saiadmin\app\logic\system\SystemConfigLogic;
|
||||
use support\think\Cache;
|
||||
|
||||
/**
|
||||
* 配置缓存
|
||||
*/
|
||||
class ConfigCache
|
||||
{
|
||||
/**
|
||||
* 读取缓存配置
|
||||
* @return array
|
||||
*/
|
||||
public static function cacheConfig(): array
|
||||
{
|
||||
return config('plugin.saiadmin.saithink.config_cache', [
|
||||
'expire' => 60 * 60 * 24 * 365,
|
||||
'prefix' => 'saiadmin:config_cache:config_',
|
||||
'tag' => 'saiadmin:config_cache'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取配置信息
|
||||
*/
|
||||
public static function getConfig(string $code = ''): array
|
||||
{
|
||||
if (empty($code)) {
|
||||
return [];
|
||||
}
|
||||
$cache = static::cacheConfig();
|
||||
// 直接从缓存获取
|
||||
$config = Cache::get($cache['prefix'] . md5($code));
|
||||
if ($config) {
|
||||
return $config;
|
||||
}
|
||||
|
||||
// 设置配置并获取
|
||||
$config = static::setConfig($code);
|
||||
if ($config) {
|
||||
return $config;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置配置数据
|
||||
*/
|
||||
public static function setConfig(string $code): array
|
||||
{
|
||||
$cache = static::cacheConfig();
|
||||
|
||||
$data = (new SystemConfigLogic())->getData($code);
|
||||
if (empty($data)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$tag = [];
|
||||
$tag[] = $cache['tag'];
|
||||
|
||||
// 保存到缓存
|
||||
Cache::tag($tag)->set($cache['prefix'] . md5($code), $data, $cache['expire']);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理单个配置缓存
|
||||
*/
|
||||
public static function clearConfig(string $code): bool
|
||||
{
|
||||
$cache = static::cacheConfig();
|
||||
return Cache::delete($cache['prefix'] . md5($code));
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理全部配置缓存
|
||||
* @return bool
|
||||
*/
|
||||
public static function clear(): bool
|
||||
{
|
||||
$cache = static::cacheConfig();
|
||||
return Cache::tag($cache['tag'])->clear();
|
||||
}
|
||||
}
|
||||
86
server/plugin/saiadmin/app/cache/DictCache.php
vendored
Normal file
86
server/plugin/saiadmin/app/cache/DictCache.php
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: sai <1430792918@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace plugin\saiadmin\app\cache;
|
||||
|
||||
use plugin\saiadmin\app\logic\system\SystemDictTypeLogic;
|
||||
use plugin\saiadmin\app\model\system\SystemDictType;
|
||||
use support\think\Cache;
|
||||
|
||||
/**
|
||||
* 字典信息缓存
|
||||
*/
|
||||
class DictCache
|
||||
{
|
||||
/**
|
||||
* 读取缓存配置
|
||||
* @return array
|
||||
*/
|
||||
public static function cacheConfig(): array
|
||||
{
|
||||
return config('plugin.saiadmin.saithink.dict_cache', [
|
||||
'expire' => 60 * 60 * 24 * 365,
|
||||
'tag' => 'saiadmin:dict_cache',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取全部字典
|
||||
*/
|
||||
public static function getDictAll(): array
|
||||
{
|
||||
$cache = static::cacheConfig();
|
||||
// 直接从缓存获取
|
||||
$data = Cache::get($cache['tag']);
|
||||
if ($data) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
// 获取信息并返回
|
||||
$data = static::setDictAll();
|
||||
if ($data) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单个字典
|
||||
*/
|
||||
public static function getDict($code): array
|
||||
{
|
||||
$data = static::getDictAll();
|
||||
if (isset($data[$code])) {
|
||||
return $data[$code];
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置全部字典
|
||||
*/
|
||||
public static function setDictAll(): array
|
||||
{
|
||||
$cache = static::cacheConfig();
|
||||
$data = (new SystemDictTypeLogic)->getDictAll();
|
||||
|
||||
Cache::set($cache['tag'], $data, $cache['expire']);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除全部字典信息
|
||||
*/
|
||||
public static function clear(): bool
|
||||
{
|
||||
$cache = static::cacheConfig();
|
||||
return Cache::delete($cache['tag']);
|
||||
}
|
||||
}
|
||||
104
server/plugin/saiadmin/app/cache/ReflectionCache.php
vendored
Normal file
104
server/plugin/saiadmin/app/cache/ReflectionCache.php
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: sai <1430792918@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace plugin\saiadmin\app\cache;
|
||||
|
||||
use ReflectionClass;
|
||||
use ReflectionMethod;
|
||||
use plugin\saiadmin\service\Permission;
|
||||
use support\think\Cache;
|
||||
|
||||
/**
|
||||
* 反射文件缓存
|
||||
*/
|
||||
class ReflectionCache
|
||||
{
|
||||
/**
|
||||
* 读取缓存配置
|
||||
* @return array
|
||||
*/
|
||||
public static function cacheConfig(): array
|
||||
{
|
||||
return config('plugin.saiadmin.saithink.reflection_cache', [
|
||||
'tag' => 'saiadmin:reflection',
|
||||
'expire' => 60 * 60 * 24 * 365,
|
||||
'no_need' => 'saiadmin:reflection_cache:no_need_',
|
||||
'attr' => 'saiadmin:reflection_cache:attr_',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取控制器中无需登录的方法列表
|
||||
*/
|
||||
public static function getNoNeedLogin(string $controller): array
|
||||
{
|
||||
$cache = static::cacheConfig();
|
||||
$tag = [];
|
||||
$tag[] = $cache['tag'];
|
||||
$key = $cache['no_need'] . md5($controller);
|
||||
|
||||
$data = Cache::get($key);
|
||||
if ($data !== null) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
// 反射逻辑
|
||||
if (class_exists($controller)) {
|
||||
$ref = new ReflectionClass($controller);
|
||||
$data = $ref->getDefaultProperties()['noNeedLogin'] ?? [];
|
||||
} else {
|
||||
$data = [];
|
||||
}
|
||||
|
||||
Cache::tag($tag)->set($key, $data, $cache['expire']);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取方法上的权限属性
|
||||
*/
|
||||
public static function getPermissionAttributes(string $controller, string $action): array
|
||||
{
|
||||
$cache = static::cacheConfig();
|
||||
$tag = [];
|
||||
$tag[] = $cache['tag'];
|
||||
$key = $cache['attr'] . md5($controller . '::' . $action);
|
||||
|
||||
$data = Cache::get($key);
|
||||
if ($data) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
$data = [];
|
||||
if (method_exists($controller, $action)) {
|
||||
$refMethod = new ReflectionMethod($controller, $action);
|
||||
$attributes = $refMethod->getAttributes(Permission::class);
|
||||
if (!empty($attributes)) {
|
||||
$attr = $attributes[0]->newInstance();
|
||||
$data = [
|
||||
'title' => $attr->getTitle(),
|
||||
'slug' => $attr->getSlug(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Cache::tag($tag)->set($key, $data, $cache['expire']);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理所有反射缓存
|
||||
* @return bool
|
||||
*/
|
||||
public static function clear(): bool
|
||||
{
|
||||
$cache = static::cacheConfig();
|
||||
return Cache::tag($cache['tag'])->clear();
|
||||
}
|
||||
|
||||
}
|
||||
143
server/plugin/saiadmin/app/cache/UserAuthCache.php
vendored
Normal file
143
server/plugin/saiadmin/app/cache/UserAuthCache.php
vendored
Normal file
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: sai <1430792918@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace plugin\saiadmin\app\cache;
|
||||
|
||||
use plugin\saiadmin\app\logic\system\SystemMenuLogic;
|
||||
use plugin\saiadmin\app\model\system\SystemUserRole;
|
||||
use support\think\Cache;
|
||||
|
||||
/**
|
||||
* 用户权限缓存
|
||||
*/
|
||||
class UserAuthCache
|
||||
{
|
||||
/**
|
||||
* 读取缓存配置
|
||||
* @return array
|
||||
*/
|
||||
public static function cacheConfig(): array
|
||||
{
|
||||
return config('plugin.saiadmin.saithink.button_cache', [
|
||||
'prefix' => 'saiadmin:button_cache:user_',
|
||||
'expire' => 60 * 60 * 2,
|
||||
'all' => 'saiadmin:button_cache:all',
|
||||
'role' => 'saiadmin:button_cache:role_',
|
||||
'tag' => 'saiadmin:button_cache',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户的权限
|
||||
*/
|
||||
public static function getUserAuth($uid): array
|
||||
{
|
||||
if (empty($uid)) {
|
||||
return [];
|
||||
}
|
||||
$cache = static::cacheConfig();
|
||||
// 直接从缓存获取
|
||||
$auth = Cache::get($cache['prefix'] . $uid);
|
||||
if ($auth) {
|
||||
return $auth;
|
||||
}
|
||||
|
||||
// 设置权限并返回
|
||||
$auth = static::setUserAuth($uid);
|
||||
if ($auth) {
|
||||
return $auth;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置用户的权限
|
||||
*/
|
||||
public static function setUserAuth($uid): array
|
||||
{
|
||||
// 从缓存获取,直接返回
|
||||
$roleIds = SystemUserRole::getRoleIds($uid);
|
||||
|
||||
// 获取角色关联的菜单权限
|
||||
$data = (new SystemMenuLogic())->getAuthByRole($roleIds);
|
||||
if (empty($data)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$cache = static::cacheConfig();
|
||||
|
||||
$tag = [];
|
||||
$tag[] = $cache['tag'];
|
||||
if (!empty($roleIds)) {
|
||||
foreach ($roleIds as $role) {
|
||||
$tag[] = $cache['role'] . $role;
|
||||
}
|
||||
}
|
||||
|
||||
// 保存到缓存
|
||||
Cache::tag($tag)->set($cache['prefix'] . $uid, $data, $cache['expire']);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取全部权限
|
||||
*/
|
||||
public static function getAllAuth(): array
|
||||
{
|
||||
$cache = static::cacheConfig();
|
||||
// 直接从缓存获取
|
||||
$auth = Cache::get($cache['all']);
|
||||
if ($auth) {
|
||||
return $auth;
|
||||
}
|
||||
|
||||
$all = (new SystemMenuLogic())->getAllAuth();
|
||||
|
||||
// 设置权限并返回
|
||||
Cache::tag($cache['tag'])->set($cache['all'], $all, $cache['expire']);
|
||||
|
||||
return $all;
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理缓存
|
||||
*/
|
||||
public static function clearUserAuth($uid): bool
|
||||
{
|
||||
$cache = static::cacheConfig();
|
||||
return Cache::delete($cache['prefix'] . $uid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理角色缓存
|
||||
*/
|
||||
public static function clearUserAuthByRoleId($role_id): bool
|
||||
{
|
||||
$cache = static::cacheConfig();
|
||||
if (is_array($role_id)) {
|
||||
$tags = [];
|
||||
foreach ($role_id as $id) {
|
||||
$tags[] = $cache['role'] . $id;
|
||||
}
|
||||
} else {
|
||||
$tags = $cache['role'] . $role_id;
|
||||
}
|
||||
return Cache::tag($tags)->clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理所有用户缓存
|
||||
* @return bool
|
||||
*/
|
||||
public static function clear(): bool
|
||||
{
|
||||
$cache = static::cacheConfig();
|
||||
return Cache::tag($cache['tag'])->clear();
|
||||
}
|
||||
}
|
||||
145
server/plugin/saiadmin/app/cache/UserInfoCache.php
vendored
Normal file
145
server/plugin/saiadmin/app/cache/UserInfoCache.php
vendored
Normal file
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: sai <1430792918@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace plugin\saiadmin\app\cache;
|
||||
|
||||
use plugin\saiadmin\app\logic\system\SystemUserLogic;
|
||||
use support\think\Cache;
|
||||
|
||||
/**
|
||||
* 用户信息缓存
|
||||
*/
|
||||
class UserInfoCache
|
||||
{
|
||||
/**
|
||||
* 读取缓存配置
|
||||
* @return array
|
||||
*/
|
||||
public static function cacheConfig(): array
|
||||
{
|
||||
return config('plugin.saiadmin.saithink.user_cache', [
|
||||
'prefix' => 'saiadmin:user_cache:info_',
|
||||
'expire' => 60 * 60 * 4,
|
||||
'dept' => 'saiadmin:user_cache:dept_',
|
||||
'role' => 'saiadmin:user_cache:role_',
|
||||
'post' => 'saiadmin:user_cache:post_',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id获取缓存管理员信息
|
||||
*/
|
||||
public static function getUserInfo($uid): array
|
||||
{
|
||||
if (empty($uid)) {
|
||||
return [];
|
||||
}
|
||||
$cache = static::cacheConfig();
|
||||
// 直接从缓存获取
|
||||
$adminInfo = Cache::get($cache['prefix'] . $uid);
|
||||
|
||||
if ($adminInfo) {
|
||||
return $adminInfo;
|
||||
}
|
||||
|
||||
// 获取缓存信息并返回
|
||||
$adminInfo = static::setUserInfo($uid);
|
||||
if ($adminInfo) {
|
||||
return $adminInfo;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置管理员信息
|
||||
*/
|
||||
public static function setUserInfo($uid): array
|
||||
{
|
||||
$data = (new SystemUserLogic())->getUser($uid);
|
||||
$cache = static::cacheConfig();
|
||||
|
||||
$tags = [];
|
||||
if (!empty($data['deptList'])) {
|
||||
$tags[] = $cache['dept'] . $data['deptList']['id'];
|
||||
}
|
||||
if (!empty($data['roleList'])) {
|
||||
foreach ($data['roleList'] as $role) {
|
||||
$tags[] = $cache['role'] . $role['id'];
|
||||
}
|
||||
}
|
||||
if (!empty($data['postList'])) {
|
||||
foreach ($data['postList'] as $post) {
|
||||
$tags[] = $cache['post'] . $post['id'];
|
||||
}
|
||||
}
|
||||
Cache::tag($tags)->set($cache['prefix'] . $uid, $data, $cache['expire']);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理管理员信息缓存
|
||||
*/
|
||||
public static function clearUserInfo($uid): bool
|
||||
{
|
||||
$cache = static::cacheConfig();
|
||||
return Cache::delete($cache['prefix'] . $uid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理部门下所有用户缓存
|
||||
*/
|
||||
public static function clearUserInfoByDeptId($dept_id): bool
|
||||
{
|
||||
$cache = static::cacheConfig();
|
||||
if (is_array($dept_id)) {
|
||||
$tags = [];
|
||||
foreach ($dept_id as $id) {
|
||||
$tags[] = $cache['dept'] . $id;
|
||||
}
|
||||
} else {
|
||||
$tags = $cache['dept'] . $dept_id;
|
||||
}
|
||||
return Cache::tag($tags)->clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理角色下所有用户缓存
|
||||
*/
|
||||
public static function clearUserInfoByRoleId($role_id): bool
|
||||
{
|
||||
$cache = static::cacheConfig();
|
||||
if (is_array($role_id)) {
|
||||
$tags = [];
|
||||
foreach ($role_id as $id) {
|
||||
$tags[] = $cache['role'] . $id;
|
||||
}
|
||||
} else {
|
||||
$tags = $cache['role'] . $role_id;
|
||||
}
|
||||
return Cache::tag($tags)->clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理岗位下所有用户缓存
|
||||
*/
|
||||
public static function clearUserInfoByPostId($post_id): bool
|
||||
{
|
||||
$cache = static::cacheConfig();
|
||||
if (is_array($post_id)) {
|
||||
$tags = [];
|
||||
foreach ($post_id as $id) {
|
||||
$tags[] = $cache['post'] . $id;
|
||||
}
|
||||
} else {
|
||||
$tags = $cache['post'] . $post_id;
|
||||
}
|
||||
return Cache::tag($tags)->clear();
|
||||
}
|
||||
|
||||
}
|
||||
100
server/plugin/saiadmin/app/cache/UserMenuCache.php
vendored
Normal file
100
server/plugin/saiadmin/app/cache/UserMenuCache.php
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: sai <1430792918@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace plugin\saiadmin\app\cache;
|
||||
|
||||
use plugin\saiadmin\app\logic\system\SystemMenuLogic;
|
||||
use plugin\saiadmin\app\model\system\SystemUserRole;
|
||||
use support\think\Cache;
|
||||
|
||||
/**
|
||||
* 用户菜单缓存
|
||||
*/
|
||||
class UserMenuCache
|
||||
{
|
||||
/**
|
||||
* 读取缓存配置
|
||||
* @return array
|
||||
*/
|
||||
public static function cacheConfig(): array
|
||||
{
|
||||
return config('plugin.saiadmin.saithink.menu_cache', [
|
||||
'prefix' => 'saiadmin:menu_cache:user_',
|
||||
'expire' => 60 * 60 * 24 * 7,
|
||||
'tag' => 'saiadmin:menu_cache',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户的菜单
|
||||
*/
|
||||
public static function getUserMenu($uid): array
|
||||
{
|
||||
if (empty($uid)) {
|
||||
return [];
|
||||
}
|
||||
$cache = static::cacheConfig();
|
||||
// 直接从缓存获取
|
||||
$menu = Cache::get($cache['prefix'] . $uid);
|
||||
if ($menu) {
|
||||
return $menu;
|
||||
}
|
||||
|
||||
// 设置用户菜单并获取
|
||||
$menu = static::setUserMenu($uid);
|
||||
if ($menu) {
|
||||
return $menu;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置用户菜单
|
||||
*/
|
||||
public static function setUserMenu($uid): array
|
||||
{
|
||||
$cache = static::cacheConfig();
|
||||
$tag = [];
|
||||
$tag[] = $cache['tag'];
|
||||
$logic = new SystemMenuLogic();
|
||||
if ($uid == 1) {
|
||||
$data = $logic->getAllMenus();
|
||||
} else {
|
||||
$roleIds = SystemUserRole::getRoleIds($uid);
|
||||
$data = $logic->getMenuByRole($roleIds);
|
||||
if (empty($data)) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
// 保存到缓存
|
||||
Cache::tag($tag)->set($cache['prefix'] . $uid, $data, $cache['expire']);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理用户缓存
|
||||
*/
|
||||
public static function clearUserMenu($uid): bool
|
||||
{
|
||||
$cache = static::cacheConfig();
|
||||
return Cache::delete($cache['prefix'] . $uid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理所有菜单缓存
|
||||
* @return bool
|
||||
*/
|
||||
public static function clearMenuCache(): bool
|
||||
{
|
||||
$cache = static::cacheConfig();
|
||||
return Cache::tag($cache['tag'])->clear();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user