feat : section

This commit is contained in:
2024-11-07 16:17:57 +08:00
parent 7fd07c55d8
commit b6b2627129
11 changed files with 531 additions and 3 deletions

View File

@@ -0,0 +1,75 @@
<?php
namespace App\Cache\Redis\Admin;
use App\Cache\Redis\RedisCache;
use App\Model\AdminSection;
use App\Service\ServiceTrait\Admin\SectionTrait;
use Hyperf\Di\Annotation\Inject;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use RedisException;
class SectionCache
{
use SectionTrait;
/**
* @var AdminSection
*/
#[Inject]
protected AdminSection $adminSectionModel;
/**
* @var RedisCache $redis
*/
#[Inject]
protected RedisCache $redis;
/**
* 菜单
* @var string
*/
protected string $key;
/**
* 构造函数注入 key
*/
public function __construct()
{
$this->key = AdminRedisKey::adminSectionList();
}
/**
* @return array
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws RedisException
*/
public function getList(): array
{
if ($this->redis->exists($this->key,'system')) {
return json_decode($this->redis->get($this->key,'system'),true);
}
$allList = $this->adminSectionModel->getList();
$data = $this->getDbList($allList);
$this->redis->set($this->key,json_encode($data),'system');
return $data;
}
/**
* @return void
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws RedisException
*/
public function delList()
{
$this->redis->delete($this->key,'system');
}
}