103 lines
2.5 KiB
PHP
103 lines
2.5 KiB
PHP
<?php
|
|
/**
|
|
* This service file is part of item.
|
|
*
|
|
* @author ctexthuang
|
|
* @contact ctexthuang@qq.com
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Service\Admin\User;
|
|
|
|
use App\Cache\Redis\Admin\MenuCache;
|
|
use App\Constants\Admin\AuthCode;
|
|
use App\Exception\AdminException;
|
|
use App\Model\AdminMenu;
|
|
use App\Service\Admin\BaseService;
|
|
use Hyperf\Di\Annotation\Inject;
|
|
use Psr\Container\ContainerExceptionInterface;
|
|
use Psr\Container\NotFoundExceptionInterface;
|
|
use RedisException;
|
|
|
|
class RoleMenuService extends BaseService
|
|
{
|
|
/**
|
|
* 注入缓存
|
|
* @var MenuCache $menuCache
|
|
*/
|
|
#[Inject]
|
|
protected MenuCache $menuCache;
|
|
|
|
/**
|
|
* @var AdminMenu $adminMenuModel
|
|
*/
|
|
#[Inject]
|
|
protected AdminMenu $adminMenuModel;
|
|
|
|
/**
|
|
* 列表
|
|
* @return array
|
|
* @throws ContainerExceptionInterface
|
|
* @throws NotFoundExceptionInterface
|
|
* @throws RedisException
|
|
*/
|
|
public function handle(): array
|
|
{
|
|
$data = $this->menuCache->getMenu();
|
|
|
|
return $this->return->success('success', ['list' => $data]);
|
|
}
|
|
|
|
public function add()
|
|
{
|
|
return $this->return->success();
|
|
}
|
|
|
|
public function edit()
|
|
{
|
|
return $this->return->success();
|
|
}
|
|
|
|
public function del()
|
|
{
|
|
return $this->return->success();
|
|
}
|
|
|
|
/**
|
|
* 详情
|
|
* @return array
|
|
*/
|
|
public function details(): array
|
|
{
|
|
$menuId = $this->request->input('menu_id');
|
|
$res = $this->adminMenuModel->where('id',$menuId)->first();
|
|
if (!$res) throw new AdminException('角色不存在');
|
|
$res = $res->toArray();
|
|
|
|
//闭包函数获取子集
|
|
$res = function() use($res,$menuId) {
|
|
$children = $this->adminMenuModel->where('parent_id',$menuId)->select(['type','value','title','id'])->get();
|
|
$res['permissionList'] = [];
|
|
if (!empty($children)) {
|
|
$children = $children->toArray();
|
|
if ($children[0]['type'] == AuthCode::MENU_TYPE_LIST) {
|
|
return $res;
|
|
}
|
|
|
|
foreach ($children as $one)
|
|
{
|
|
$res['permissionList'][] = [
|
|
'id' => $one['id'],
|
|
'label' => $one['title'],
|
|
'value' => $one['value'],
|
|
];
|
|
}
|
|
}
|
|
|
|
return $res;
|
|
};
|
|
|
|
return $this->return->success('success',['info' => $res]);
|
|
}
|
|
} |