mirror of
https://gitee.com/ctexthuang/hyperf_rbac_framework_server_ctexthuang.git
synced 2025-12-25 17:07:49 +08:00
feat : admin aspect
This commit is contained in:
@@ -4,8 +4,10 @@ namespace App\Trait;
|
||||
|
||||
use App\Cache\Redis\RedisCache;
|
||||
use App\Cache\Redis\RedisKey;
|
||||
use App\Model\AdminUser;
|
||||
use App\Repository\AdminUserRepository;
|
||||
use Hyperf\Context\Context;
|
||||
use Hyperf\Database\Model\Model;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
trait AdminUserTrait
|
||||
@@ -24,9 +26,9 @@ trait AdminUserTrait
|
||||
|
||||
/**
|
||||
* @param int $adminId
|
||||
* @return array|null
|
||||
* @return AdminUser|Model|mixed|string|null
|
||||
*/
|
||||
public function getAdminUserInfo(int $adminId): array|null
|
||||
public function getAdminUserInfo(int $adminId): mixed
|
||||
{
|
||||
$key = RedisKey::getAdminUserInfoKey($adminId);
|
||||
if (Context::has($key)) {
|
||||
@@ -34,16 +36,16 @@ trait AdminUserTrait
|
||||
}
|
||||
|
||||
if ($this->redis->with()->exists($key)) {
|
||||
$userInfo = $this->redis->with()->get($key);
|
||||
$userInfo = unserialize($this->redis->with()->get($key));
|
||||
Context::set($key,$userInfo);
|
||||
return json_decode($userInfo,true);
|
||||
return $userInfo;
|
||||
}
|
||||
|
||||
$userInfo = $this->adminUserRepository->findById($adminId)?->toArray() ?? null;
|
||||
$userInfo = $this->adminUserRepository->findById($adminId) ?? null;
|
||||
if (!$userInfo) return null;
|
||||
|
||||
Context::set($key, $userInfo);
|
||||
$this->redis->with()->set($key, json_encode($userInfo), 3600);
|
||||
$this->redis->with()->set($key, serialize($userInfo), 3600);
|
||||
|
||||
return $userInfo;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user