Merge branch 'develop'
This commit is contained in:
@@ -118,6 +118,12 @@ class AuthLogic
|
||||
}
|
||||
// 是否登陆
|
||||
$user->isLogin = false;
|
||||
|
||||
$options = [
|
||||
'corp_id' => $user->corp_id,
|
||||
'user_id' => $user->id
|
||||
];
|
||||
\Webman\RedisQueue\Redis::send('perm-agt', $options);
|
||||
} else {
|
||||
$updated = [
|
||||
'union_id' => $feishuUserInfo['union_id'],
|
||||
|
||||
@@ -2,11 +2,18 @@
|
||||
|
||||
namespace app\common\logic;
|
||||
|
||||
use app\common\traits\crud\CrudLogicTrait;
|
||||
use app\common\model\CorpFeishuApp;
|
||||
|
||||
class CorpFeishuAppLogic
|
||||
{
|
||||
|
||||
use CrudLogicTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = CorpFeishuApp::class;
|
||||
|
||||
|
||||
public function getFeishuApp($corpId, $systemId)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\logic;
|
||||
|
||||
use app\common\traits\crud\CrudLogicTrait;
|
||||
use app\common\model\CorpFeishuApp;
|
||||
|
||||
class CountryLogic
|
||||
{
|
||||
use CrudLogicTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = CorpFeishuApp::class;
|
||||
|
||||
}
|
||||
@@ -23,13 +23,16 @@ class PermLogic
|
||||
}
|
||||
|
||||
$all = collect();
|
||||
|
||||
// 合并角色资源,排除不需要权限认证的资源
|
||||
// 遍历用户的所有角色,合并每个角色所拥有的资源
|
||||
foreach ($user->roles as $role) {
|
||||
$all = $all->merge(
|
||||
// 过滤当前角色的资源列表
|
||||
$role->resources->filter(function ($resource) use($system) {
|
||||
// var_dump($resource->toArray());
|
||||
// 只保留需要权限认证的资源(或公共资源)
|
||||
// 资源过滤条件:
|
||||
// 1. !$resource->no_auth:资源需要权限认证(排除公共资源)
|
||||
// 2. 系统匹配条件:
|
||||
// - $system->id == $resource->system_id:资源属于当前系统
|
||||
// - $resource->system_id == 0:资源为全局公共资源(所有系统可用)
|
||||
return !$resource->no_auth && ($system->id == $resource->system_id || $resource->system_id == 0);
|
||||
})
|
||||
);
|
||||
@@ -64,151 +67,6 @@ class PermLogic
|
||||
* @param string $parentPath 父级完整路径(用于递归)
|
||||
* @return array
|
||||
*/
|
||||
public function buildTree_bak($resources, int $parentId = 0, string $parentPath = ''): array
|
||||
{
|
||||
$tree = [];
|
||||
|
||||
foreach ($resources as $node) {
|
||||
// 只处理目录和菜单,不把 permission 当作菜单节点
|
||||
if ($node->parent_id !== $parentId || $node->type === 'permission') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// —— 拼接当前节点的完整路径 ——
|
||||
$currentPath = rtrim($parentPath, '/');
|
||||
if (!empty($node->url)) {
|
||||
$urlSegment = ltrim($node->url, '/');
|
||||
$currentPath = $currentPath === ''
|
||||
? $urlSegment
|
||||
: "{$currentPath}/{$urlSegment}";
|
||||
}
|
||||
|
||||
// —— 递归构建子节点 ——
|
||||
// 这里只会继续收目录和菜单,permission 永远不会进入此方法
|
||||
$children = $this->buildTree($resources, $node->id, $currentPath);
|
||||
|
||||
// —— 本级权限列表 ——
|
||||
$authList = $resources
|
||||
->filter(fn($r) => $r->type === 'permission' && $r->parent_id === $node->id)
|
||||
->map(fn($r) => [
|
||||
'id' => $r->id,
|
||||
'title' => $r->name,
|
||||
'auth_mark' => $r->code,
|
||||
])
|
||||
->values()
|
||||
->all();
|
||||
|
||||
// —— 判断是否有子目录或子菜单 ——
|
||||
$hasChildrenMenu = ! empty($children);
|
||||
|
||||
// —— 计算 component 字段 ——
|
||||
if ($hasChildrenMenu) {
|
||||
if ($node->type === 'menu' && !empty($node->url)) {
|
||||
// menu 类型且自身有 url,用自身 url(加前导 slash)
|
||||
$componentValue = '/' . ltrim($node->url, '/');
|
||||
} else {
|
||||
// 其它含子项的节点,固定 Layout 组件
|
||||
$componentValue = '/index/index';
|
||||
}
|
||||
} else {
|
||||
// 叶子节点:拼接路径,确保以 slash 开头
|
||||
$componentValue = $currentPath !== ''
|
||||
? '/' . ltrim($currentPath, '/')
|
||||
: '';
|
||||
}
|
||||
|
||||
$tree[] = [
|
||||
'id' => $node->id,
|
||||
'name' => $node->name,
|
||||
'path' => $node->url,
|
||||
'component' => $componentValue,
|
||||
'meta' => [
|
||||
'title' => $node->name,
|
||||
'icon' => $node->icon,
|
||||
'keepAlive' => true,
|
||||
'authList' => $authList,
|
||||
'openType' => $node->open_type,
|
||||
'isHide' => $node->is_hide == 0 ? false : true,
|
||||
'isHideTab' => $node->is_hide_tab == 0 ? false : true
|
||||
],
|
||||
'children' => $children
|
||||
];
|
||||
}
|
||||
|
||||
return $tree;
|
||||
}
|
||||
public function buildTree_bak2($resources, int $parentId = 0, string $parentPath = ''): array
|
||||
{
|
||||
$tree = [];
|
||||
|
||||
foreach ($resources as $node) {
|
||||
if ($node->parent_id !== $parentId) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// —— 拼接当前节点的完整路径 ——
|
||||
$currentPath = $parentPath;
|
||||
// 去掉末尾多余 slash
|
||||
$currentPath = rtrim($currentPath, '/');
|
||||
|
||||
if (!empty($node->url)) {
|
||||
// 如果当前节点有 url,则拼接
|
||||
$urlSegment = ltrim($node->url, '/');
|
||||
$currentPath = $currentPath === ''
|
||||
? $urlSegment
|
||||
: "{$currentPath}/{$urlSegment}";
|
||||
}
|
||||
|
||||
// —— 递归构建子节点 ——
|
||||
$children = [];
|
||||
if ($node->type === 'directory') {
|
||||
$children = $this->buildTree($resources, $node->id, $currentPath);
|
||||
}
|
||||
|
||||
// —— 收集本级的 permission 权限列表 ——
|
||||
$authList = $resources
|
||||
->filter(fn($r) => $r->type === 'permission' && $r->parent_id === $node->id)
|
||||
->map(fn($r) => [
|
||||
'id' => $r->id,
|
||||
'title' => $r->name,
|
||||
'auth_mark' => $r->code,
|
||||
])
|
||||
->values()
|
||||
->all();
|
||||
|
||||
// —— 判断是否有子菜单/目录 ——
|
||||
$hasChildrenMenu = $resources
|
||||
->where('parent_id', $node->id)
|
||||
->whereIn('type', ['directory', 'menu'])
|
||||
->isNotEmpty();
|
||||
|
||||
// —— 计算 component 字段 ——
|
||||
if ($hasChildrenMenu) {
|
||||
// 只要有子项,就一律显示顶层 Layout 组件
|
||||
$componentValue = '/index/index';
|
||||
} else {
|
||||
// 叶子节点:如果定义了 url,就使用拼接后的路径;否则用占位符(这里用空串,你可替换)
|
||||
$componentValue = $currentPath !== '' ? $currentPath : '';
|
||||
}
|
||||
|
||||
$tree[] = [
|
||||
'id' => $node->id,
|
||||
'name' => $node->name,
|
||||
'path' => $node->url,
|
||||
'component' => $componentValue,
|
||||
'meta' => [
|
||||
'title' => $node->name,
|
||||
'icon' => $node->icon,
|
||||
'keepAlive' => true,
|
||||
'authList' => $authList,
|
||||
'openType' => $node->open_type,
|
||||
],
|
||||
'children' => $children,
|
||||
];
|
||||
}
|
||||
|
||||
return $tree;
|
||||
}
|
||||
public function buildTree($resources, int $parentId = 0, string $parentPath = ''): array
|
||||
{
|
||||
$tree = [];
|
||||
@@ -258,7 +116,7 @@ class PermLogic
|
||||
'meta' => [
|
||||
'title' => $node->name,
|
||||
'icon' => $node->icon,
|
||||
'keepAlive' => true,
|
||||
'keepAlive' => $node->keep_alive == 1 ? true : false,
|
||||
'authList' => $authList,
|
||||
'openType' => $node->open_type,
|
||||
'isHide' => $node->is_hide == 0 ? false : true,
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\logic;
|
||||
|
||||
use app\common\traits\crud\CrudLogicTrait;
|
||||
use app\common\model\Resource;
|
||||
use support\Request;
|
||||
|
||||
class ResourceLogic
|
||||
{
|
||||
use CrudLogicTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = Resource::class;
|
||||
|
||||
|
||||
public function logicListAllResources(Request $request, array $config)
|
||||
{
|
||||
$data = $this->logicListAll($config);
|
||||
|
||||
if ($request->get('role_id')) {
|
||||
$selected = (new RoleLogic())->getRoleResources($request->get('role_id'));
|
||||
} else if ($request->get('user_id')) {
|
||||
$selected = (new RoleLogic())->getUserResources($request->get('user_id'));
|
||||
} else {
|
||||
$selected = [];
|
||||
}
|
||||
|
||||
foreach ($data as &$item) {
|
||||
$item['selected'] = in_array($item['id'], $selected) ? true : false;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -2,13 +2,84 @@
|
||||
|
||||
namespace app\common\logic;
|
||||
|
||||
use app\common\model\Role;
|
||||
use support\exception\BusinessException;
|
||||
use support\Log;
|
||||
use support\Db;
|
||||
|
||||
class RoleLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* 更新角色资源权限
|
||||
*
|
||||
* @param array $data 包含 role_id 和 resources 的数据
|
||||
* @return bool 操作是否成功
|
||||
*/
|
||||
public function updateRoleResources(array $data): bool
|
||||
{
|
||||
$roleId = $data['role_id'] ?? 0;
|
||||
$resources = $data['resources'] ?? [];
|
||||
|
||||
if (empty($roleId)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
// 删除原有角色资源关联
|
||||
Db::table('role_resources')->where('role_id', $roleId)->delete();
|
||||
|
||||
// 批量插入新角色资源关联
|
||||
if (!empty($resources)) {
|
||||
$insertData = [];
|
||||
foreach ($resources as $resourceId) {
|
||||
$insertData[] = [
|
||||
'role_id' => $roleId,
|
||||
'resource_id' => $resourceId
|
||||
];
|
||||
}
|
||||
Db::table('role_resources')->insert($insertData);
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $exception) {
|
||||
Db::rollBack();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取角色资源
|
||||
*
|
||||
* @param int $roleId 角色ID
|
||||
* @return array 资源ID列表
|
||||
*/
|
||||
public function getRoleResources(int $roleId): array
|
||||
{
|
||||
if (empty($roleId)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Db::table('role_resources')
|
||||
->where('role_id', $roleId)
|
||||
->pluck('resource_id')
|
||||
->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户资源
|
||||
*
|
||||
* @param int $userId 用户ID
|
||||
* @return array 资源ID列表
|
||||
*/
|
||||
public function getUserResources(int $userId): array
|
||||
{
|
||||
if (empty($userId)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Db::table('user_resources')
|
||||
->where('user_id', $userId)
|
||||
->pluck('resource_id')
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,18 @@
|
||||
namespace app\common\logic;
|
||||
|
||||
use app\common\model\User;
|
||||
use app\common\traits\crud\CrudLogicTrait;
|
||||
use support\exception\BusinessException;
|
||||
|
||||
class UserLogic
|
||||
{
|
||||
use CrudLogicTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = User::class;
|
||||
|
||||
/**
|
||||
* 用户信息
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user