协程版仓库后端项目
Some checks failed
Build Docker / build (push) Has been cancelled

This commit is contained in:
2025-07-08 14:59:47 +08:00
commit 0b2299c427
134 changed files with 19277 additions and 0 deletions

View File

@ -0,0 +1,86 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace App\Controller;
use App\Context\UserContext;
use App\Service\OpLogsService;
use App\Utils\ApiResponse;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Contract\ResponseInterface;
use Psr\Container\ContainerInterface;
abstract class AbstractController
{
#[Inject]
protected ContainerInterface $container;
#[Inject]
protected RequestInterface $request;
#[Inject]
protected ResponseInterface $response;
#[Inject]
protected ApiResponse $apiResponse;
#[Inject]
protected OpLogsService $opLogsService;
/**
* 获取默认分页参数.
* @return array
*/
protected function getPage(): array
{
$params = $this->request->all();
return [$params['page'] ?? 1, $params['pageSize'] ?? 100];
}
/**
* 获取当前用户令牌
* @return string|null
*/
public function token(): ?string
{
return UserContext::getCurrentToken();
}
/**
* 获取当前用户信息
* @return array
*/
public function user(): array
{
return UserContext::getCurrentUser() ?? [];
}
/**
* 获取当前公司信息
* @return array
*/
public function company(): array
{
return $this->user()['company'] ?? [];
}
/**
* 操作日志.
* @param string $log
* @param int $source
*/
protected function opLogs(string $log, int $source = 0): void
{
$this->opLogsService->operatorLogs($log, $source);
}
}