| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?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
- {
- /**
- * 容器接口.
- *
- * @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;
- }
- }
|