mirror of
https://gitee.com/ctexthuang/hyperf_rbac_framework_server_ctexthuang.git
synced 2025-12-25 23:57:49 +08:00
88 lines
1.7 KiB
PHP
88 lines
1.7 KiB
PHP
<?php
|
|
/**
|
|
* This service file is part of item.
|
|
*
|
|
* @author ctexthuang
|
|
* @contact ctexthuang@qq.com
|
|
*/
|
|
|
|
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;
|
|
|
|
abstract class BaseAdminService
|
|
{
|
|
use RequestScopedTokenTrait;
|
|
|
|
/**
|
|
* 请求对象注入
|
|
* @var RequestInterface
|
|
*/
|
|
#[Inject]
|
|
protected RequestInterface $request;
|
|
|
|
/**
|
|
* 返回对象注入
|
|
* @var AdminReturn
|
|
*/
|
|
#[Inject]
|
|
protected AdminReturn $adminReturn;
|
|
|
|
/**
|
|
* @param string $name
|
|
* @return \current_admin_id|mixed
|
|
*/
|
|
public function __get(string $name)
|
|
{
|
|
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);
|
|
// }
|
|
|
|
/**
|
|
* 主函数抽象类
|
|
*/
|
|
abstract public function handle();
|
|
|
|
/**
|
|
* @return int
|
|
*/
|
|
protected function getCurrentPage(): int
|
|
{
|
|
return (int) $this->request->input('page', 1);
|
|
}
|
|
|
|
/**
|
|
* @return int
|
|
*/
|
|
protected function getPageSize(): int
|
|
{
|
|
return (int) $this->request->input('page_size', 20);
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
protected function getRequestData(): array
|
|
{
|
|
return $this->request->all();
|
|
}
|
|
} |