| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- declare (strict_types=1);
- namespace Modules\Api\Controllers;
- use App\Constants\CommonConstant;
- use App\Controller\CoreController;
- use App\Repositories\UserLogRepository;
- use App\Repositories\Utils\JwtRepository;
- use Hyperf\Di\Annotation\Inject;
- use Hyperf\HttpServer\Contract\RequestInterface;
- use Hyperf\HttpServer\Contract\ResponseInterface;
- use Modules\Api\Services\AuthService;
- use Psr\Container\ContainerInterface;
- class BaseController extends CoreController
- {
- use \Hyperf\Di\Aop\ProxyTrait;
- use \Hyperf\Di\Aop\PropertyHandlerTrait;
- function __construct()
- {
- if (method_exists(parent::class, '__construct')) {
- parent::__construct(...func_get_args());
- }
- $this->__handlePropertyHandler(__CLASS__);
- }
- /**
- * 容器接口.
- *
- * @Inject
- * @var ContainerInterface
- */
- protected $container;
- /**
- * 请求接口.
- *
- * @Inject
- * @var RequestInterface
- */
- protected $request;
- /**
- * 相应接口.
- *
- * @Inject
- * @var ResponseInterface
- */
- protected $response;
- /**
- * 获取用户Id.
- * @return string
- */
- public function getUserId()
- {
- return (new AuthService())->getUserId();
- }
- /**
- * 记录操作日志.
- * @param string $subject 主题.
- * @param string $svalue 关联数据.
- * @return bool
- */
- protected function log(string $subject, $svalue = '')
- {
- list($module, $action) = $this->getModuleAndAction();
- $inputs = ['user_id' => $this->getUserId(), 'subject' => mb_strcut((string) $subject, 0, 700), 'module' => $module, 'action' => $action, 'svalue' => !empty($svalue) ? mb_strcut((string) $svalue, 0, 700) : ''];
- make(UserLogRepository::class)->createOne($inputs);
- return true;
- }
- }
|