App_Controller_AdController.proxy.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. declare (strict_types=1);
  3. namespace App\Controller;
  4. use App\JsonRpc\AdServiceInterface;
  5. //use Hyperf\Contract\StdoutLoggerInterface;
  6. use Hyperf\Di\Annotation\Inject;
  7. use Hyperf\HttpServer\Annotation\AutoController;
  8. use App\Tools\Result;
  9. use App\Constants\ErrorCode;
  10. use Hyperf\Logger;
  11. /**
  12. * Class AdController
  13. * @package App\Controller
  14. */
  15. #[AutoController]
  16. class AdController extends AbstractController
  17. {
  18. use \Hyperf\Di\Aop\ProxyTrait;
  19. use \Hyperf\Di\Aop\PropertyHandlerTrait;
  20. function __construct(\Hyperf\Logger\LoggerFactory $loggerFactory)
  21. {
  22. if (method_exists(parent::class, '__construct')) {
  23. parent::__construct(...func_get_args());
  24. }
  25. $this->__handlePropertyHandler(__CLASS__);
  26. }
  27. // public function __construct(protected StdoutLoggerInterface $logger)
  28. // {
  29. // }
  30. /**
  31. * @var AdServiceInterface
  32. */
  33. #[Inject]
  34. private $adServiceInterface;
  35. public function createAd()
  36. {
  37. $name = (string) $this->request->input('name', '');
  38. $gender = (string) $this->request->input('url', 0);
  39. $result = $this->adServiceInterface->createAd($name, $gender);
  40. return $result ? Result::success($result['data']) : Result::error($result['message']);
  41. }
  42. /**
  43. * @return array|void
  44. */
  45. public function getAdInfo()
  46. {
  47. $id = (int) $this->request->input('id');
  48. $result = $this->adServiceInterface->getAdInfo($id);
  49. // $this->logger->info("ceshi--");
  50. if ($result['code'] != ErrorCode::SUCCESS) {
  51. return Result::error($result['message'], 0);
  52. }
  53. return Result::success($result['data']);
  54. }
  55. }