* * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ declare(strict_types=1); namespace App\Service; use App\JsonRpc\RoleServiceInterface; use App\Repository\Company\FirstCompanyRepository; use Hyperf\Collection\Collection; use Hyperf\Di\Annotation\Inject; use function Hyperf\Collection\collect; class RelatedInfo { #[Inject] protected RoleServiceInterface $roleServiceInterface; #[Inject] protected FirstCompanyRepository $firstCompanyRepository; /** * 用户角色关联. * @param int $uid 用户ID * @return array 用户角色关联信息 */ public function userRoles(int $uid): array { $data = [ 'user_id' => $uid, ]; $rpcResult = $this->roleServiceInterface->getUserRoleInfo($data); return $rpcResult['result'] ?? []; } /** * 公司信息关联. * @param string $companyName 公司名称 * @return array|null 公司信息关联信息 */ public function companyInfo(string $companyName): ?array { return $this->firstCompanyRepository->getCompanyByFullName($companyName, false); } /** * 公司信息关联. * @param int $companyId * @return array */ public function companyInfoById(int $companyId): array { return $this->firstCompanyRepository->getCompanyById($companyId, false); } /** * 获取用户角色权限. * @param int $uid 用户ID * @return Collection 角色权限集合 */ public function getRolePermissions(int $uid): Collection { // 获取用户角色表中的 role_ids 数组 $roleIds = static::userRoles($uid)['role_ids_info'] ?? []; $userRolesIds = array_keys($roleIds); $data = [ 'role_ids' => $userRolesIds ]; // 通过数组中的 role_id 查找对应的角色权限 $rpcResult = $this->roleServiceInterface->getRolePermissionSetByRoleIds($data); $res = $rpcResult['result'] ?? []; return collect($res); } /** * 用户数据权限关联. * @param int $uid 用户ID * @return array 数据权限信息 * @return array */ public function dataPermissions(int $uid): array { $data = [ 'user_id' => $uid, ]; $rpcResult = $this->roleServiceInterface->getUserDataPermissions($data); return $rpcResult['result'] ?? []; } }