mirror of
https://gitee.com/ctexthuang/hyperf_rbac_framework_server_ctexthuang.git
synced 2025-12-25 17:07:49 +08:00
fix : first finish
This commit is contained in:
@@ -40,9 +40,10 @@ class MenuService extends BaseAdminService
|
||||
*/
|
||||
public function create(): array
|
||||
{
|
||||
$data = array($this->getRequestData(),[
|
||||
$data = array_merge($this->getRequestData(),[
|
||||
'created_by' => $this->adminId
|
||||
]);
|
||||
if (empty($data['parent_id'])) $data['parent_id'] = 0;
|
||||
/**
|
||||
* @var AdminMenu $model
|
||||
*/
|
||||
@@ -75,7 +76,7 @@ class MenuService extends BaseAdminService
|
||||
*/
|
||||
public function update(int $id): array
|
||||
{
|
||||
$data = array($this->getRequestData(),[
|
||||
$data = array_merge($this->getRequestData(),[
|
||||
'updated_by' => $this->adminId
|
||||
]);
|
||||
|
||||
|
||||
@@ -96,6 +96,7 @@ class RoleService extends BaseAdminService
|
||||
public function getRole(int $id): array
|
||||
{
|
||||
return $this->adminReturn->success(
|
||||
'success',
|
||||
$this->adminRoleRepository
|
||||
->findById($id)
|
||||
->adminMenus()
|
||||
|
||||
@@ -44,17 +44,11 @@ class UserService extends BaseAdminService
|
||||
#[Inject]
|
||||
protected AdminRoleRepository $adminRoleRepository;
|
||||
|
||||
#[Inject]
|
||||
protected RedisCache $redisCache;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function handle(): array
|
||||
{
|
||||
$this->redisCache->with()->set('123',1);
|
||||
$this->redisCache->with()->lua(RateLimit::class)->check('user:123', 10, 60);
|
||||
|
||||
return $this->adminReturn->success(
|
||||
'success',
|
||||
Arr::only(
|
||||
@@ -188,7 +182,7 @@ class UserService extends BaseAdminService
|
||||
'code' => $this->request->input('role_codes')
|
||||
])->map(static function(AdminRole $adminRole) {
|
||||
return $adminRole->id;
|
||||
})->all()
|
||||
})
|
||||
);
|
||||
|
||||
return $this->adminReturn->success();
|
||||
|
||||
@@ -10,12 +10,12 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Admin;
|
||||
|
||||
use App\Exception\ErrException;
|
||||
use App\Lib\Jwt\RequestScopedTokenTrait;
|
||||
use App\Lib\Return\AdminReturn;
|
||||
use Hyperf\Context\Context;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Hyperf\HttpServer\Contract\RequestInterface;
|
||||
use Lcobucci\JWT\Token\RegisteredClaims;
|
||||
|
||||
abstract class BaseAdminService
|
||||
{
|
||||
@@ -36,20 +36,27 @@ abstract class BaseAdminService
|
||||
protected AdminReturn $adminReturn;
|
||||
|
||||
/**
|
||||
* 管理员 id
|
||||
* @var int
|
||||
* @param string $name
|
||||
* @return \current_admin_id|mixed
|
||||
*/
|
||||
protected int $adminId = 0;
|
||||
|
||||
/**
|
||||
* 主构造函数
|
||||
*/
|
||||
public function __construct()
|
||||
public function __get(string $name)
|
||||
{
|
||||
$this->adminId = (int) $this->getToken()?->claims()?->get(RegisteredClaims::ID) ?? 0;
|
||||
if ($this->adminId > 0) Context::set('current_admin_id', $this->adminId);
|
||||
if ($name === 'adminId') return Context::get('current_admin_id',0);
|
||||
|
||||
if (!property_exists($this, $name)) throw new ErrException('属性未定义');
|
||||
|
||||
return $this->$name;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 主构造函数
|
||||
// */
|
||||
// public function __construct()
|
||||
// {
|
||||
// $this->adminId = Context::get('current_admin_id',0);
|
||||
// var_dump('BaseAdminService获取到的'.$this->adminId);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 主函数抽象类
|
||||
*/
|
||||
|
||||
@@ -46,7 +46,6 @@ class LoginService extends BaseAdminService
|
||||
}
|
||||
|
||||
if ($adminInfo->status == AdminUserStatusCode::DISABLE) throw new ErrException('用户已禁用');
|
||||
|
||||
$jwtHandle = $this->tokenService->setJwt('admin')->getJwt();
|
||||
|
||||
return $this->adminReturn->success('success',[
|
||||
|
||||
Reference in New Issue
Block a user