App_Controller_WebsiteController.proxy.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. declare (strict_types=1);
  3. namespace App\Controller;
  4. use App\JsonRpc\WebsiteServiceInterface;
  5. use Hyperf\Di\Annotation\Inject;
  6. use Hyperf\HttpServer\Annotation\AutoController;
  7. use App\Tools\Result;
  8. use App\Constants\ErrorCode;
  9. use Psr\Log\LoggerInterface;
  10. /**
  11. * Class WebsiteController
  12. * @package App\Controller
  13. */
  14. #[AutoController]
  15. class WebsiteController extends AbstractController
  16. {
  17. use \Hyperf\Di\Aop\ProxyTrait;
  18. use \Hyperf\Di\Aop\PropertyHandlerTrait;
  19. function __construct(\Hyperf\Logger\LoggerFactory $loggerFactory)
  20. {
  21. if (method_exists(parent::class, '__construct')) {
  22. parent::__construct(...func_get_args());
  23. }
  24. $this->__handlePropertyHandler(__CLASS__);
  25. }
  26. /**
  27. * @var WebsiteServiceInterface
  28. */
  29. #[Inject]
  30. private $websiteServiceClient;
  31. /**
  32. * 创建站点
  33. * @return array
  34. */
  35. public function createWebsite()
  36. {
  37. $data = $this->request->all();
  38. $result = $this->websiteServiceClient->createWebsite($data);
  39. return $result ? Result::success($result['data']) : Result::error($result['message']);
  40. }
  41. /**
  42. * 获取站点列表
  43. * @return void
  44. */
  45. public function getWebsitetList()
  46. {
  47. $keyword = $this->request->input("keyword", '');
  48. $page = (int) $this->request->input("page", 1);
  49. $pageSize = (int) $this->request->input("pageSize", 10);
  50. $result = $this->websiteServiceClient->getWebsitetList($keyword, $page, $pageSize);
  51. return $result ? Result::success($result['data']) : Result::error($result['message']);
  52. }
  53. /**
  54. * 更新站点
  55. * @return array
  56. */
  57. public function updateWebsite()
  58. {
  59. $id = (int) $this->request->input("id", '');
  60. $req = $this->request->all();
  61. unset($req['id']);
  62. $result = $this->websiteServiceClient->updateWebsite($id, $req);
  63. return $result ? Result::success($result['data']) : Result::error($result['message']);
  64. }
  65. /**
  66. * 删除站点
  67. * @return array
  68. */
  69. public function delWebsite()
  70. {
  71. $id = (int) $this->request->input("id", '');
  72. $result = $this->websiteServiceClient->delWebsite($id);
  73. return $result['code'] == 200 ? Result::success($result['data']) : Result::error($result['message']);
  74. }
  75. /**
  76. * 获取站点信息
  77. * @return array
  78. */
  79. public function getWebsiteInfo()
  80. {
  81. $id = (int) $this->request->input("id", '');
  82. $result = $this->websiteServiceClient->getWebsiteInfo($id);
  83. $this->logger->info('hello world', [1 => "ceshi"], ["a" => "11"]);
  84. // $this->logger->error("====@@");
  85. return $result['code'] == 200 ? Result::success($result['data']) : Result::error($result['message']);
  86. }
  87. }