mirror of
https://gitee.com/ctexthuang/hyperf_rbac_framework_server_ctexthuang.git
synced 2025-12-25 18:17:49 +08:00
fix : update path And request
This commit is contained in:
52
app/Common/Trait/AdminUserTrait.php
Normal file
52
app/Common/Trait/AdminUserTrait.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Common\Trait;
|
||||
|
||||
use App\Cache\Redis\RedisCache;
|
||||
use App\Cache\Redis\RedisKey;
|
||||
use App\Common\Repository\AdminUserRepository;
|
||||
use App\Model\AdminUser;
|
||||
use Hyperf\Context\Context;
|
||||
use Hyperf\Database\Model\Model;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
trait AdminUserTrait
|
||||
{
|
||||
/**
|
||||
* @var RedisCache
|
||||
*/
|
||||
#[Inject]
|
||||
protected RedisCache $redis;
|
||||
|
||||
/**
|
||||
* @var AdminUserRepository
|
||||
*/
|
||||
#[Inject]
|
||||
protected AdminUserRepository $adminUserRepository;
|
||||
|
||||
/**
|
||||
* @param int $adminId
|
||||
* @return AdminUser|Model|mixed|string|null
|
||||
*/
|
||||
public function getAdminUserInfo(int $adminId): mixed
|
||||
{
|
||||
$key = RedisKey::getAdminUserInfoKey($adminId);
|
||||
if (Context::has($key)) {
|
||||
return Context::get($key,false);
|
||||
}
|
||||
|
||||
if ($this->redis->with()->exists($key)) {
|
||||
$userInfo = unserialize($this->redis->with()->get($key));
|
||||
Context::set($key,$userInfo);
|
||||
return $userInfo;
|
||||
}
|
||||
|
||||
$userInfo = $this->adminUserRepository->findById($adminId) ?? null;
|
||||
if (!$userInfo) return null;
|
||||
|
||||
Context::set($key, $userInfo);
|
||||
$this->redis->with()->set($key, serialize($userInfo), 3600);
|
||||
|
||||
return $userInfo;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user