123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- declare (strict_types=1);
- namespace App\Controller;
- use App\JsonRpc\AdServiceInterface;
- //use Hyperf\Contract\StdoutLoggerInterface;
- use Hyperf\Di\Annotation\Inject;
- use Hyperf\HttpServer\Annotation\AutoController;
- use App\Tools\Result;
- use App\Constants\ErrorCode;
- use Hyperf\Logger;
- /**
- * Class AdController
- * @package App\Controller
- */
- #[AutoController]
- class AdController extends AbstractController
- {
- use \Hyperf\Di\Aop\ProxyTrait;
- use \Hyperf\Di\Aop\PropertyHandlerTrait;
- function __construct(\Hyperf\Logger\LoggerFactory $loggerFactory)
- {
- if (method_exists(parent::class, '__construct')) {
- parent::__construct(...func_get_args());
- }
- $this->__handlePropertyHandler(__CLASS__);
- }
- /**
- * @var AdServiceInterface
- */
- #[Inject]
- private $adServiceInterface;
- public function createAd()
- {
- $name = (string) $this->request->input('name', '');
- $gender = (string) $this->request->input('url', 0);
- $result = $this->adServiceInterface->createAd($name, $gender);
- return $result ? Result::success($result['data']) : Result::error($result['message']);
- }
- /**
- * @return array|void
- */
- public function getAdInfo()
- {
- $id = (int) $this->request->input('id');
- $result = $this->adServiceInterface->getAdInfo($id);
- // $this->logger->info("ceshi--");
- if ($result['code'] != ErrorCode::SUCCESS) {
- return Result::error($result['message'], 0);
- }
- return Result::success($result['data']);
- }
- }
|