fix : update path And request

This commit is contained in:
2025-09-16 15:14:47 +08:00
parent c1d8f02491
commit be0d0913b6
42 changed files with 484 additions and 75 deletions

View 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;
}
}