App_Controller_PublicController.proxy.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. declare (strict_types=1);
  3. namespace App\Controller;
  4. use App\JsonRpc\PublicRpcServiceInterface;
  5. use Hyperf\Di\Annotation\Inject;
  6. use Hyperf\HttpServer\Annotation\AutoController;
  7. use App\Tools\Result;
  8. use App\Tools\CommonService;
  9. /**
  10. * Class PublicController
  11. * @package App\Controller
  12. */
  13. #[AutoController]
  14. class PublicController extends AbstractController
  15. {
  16. use \Hyperf\Di\Aop\ProxyTrait;
  17. use \Hyperf\Di\Aop\PropertyHandlerTrait;
  18. function __construct(\Hyperf\Logger\LoggerFactory $loggerFactory)
  19. {
  20. if (method_exists(parent::class, '__construct')) {
  21. parent::__construct(...func_get_args());
  22. }
  23. $this->__handlePropertyHandler(__CLASS__);
  24. }
  25. /**
  26. * @var PublicRpcServiceInterface
  27. */
  28. #[Inject]
  29. private $publicServiceClient;
  30. /**
  31. * 地区
  32. * @return array
  33. */
  34. public function getDistrictList()
  35. {
  36. $pid = $this->request->input("pid", 0);
  37. $data = ['pid' => $pid];
  38. $result = $this->publicServiceClient->getDistrictList($data);
  39. return $result ? Result::success($result['data']) : Result::error($result['message']);
  40. }
  41. /**
  42. * 获取用户等级
  43. * @return array
  44. */
  45. public function getUserLevelList()
  46. {
  47. $result = $this->publicServiceClient->getUserLevelList([]);
  48. return $result ? Result::success($result['data']) : Result::error($result['message']);
  49. }
  50. public function uploadFile()
  51. {
  52. $urlN = new CommonService();
  53. $file = $this->request->file('file');
  54. try {
  55. if ($file == null) {
  56. return Result::error("未找到上传文件");
  57. }
  58. $data = CommonService::uploadFile($file, ['png', 'jpg', 'png', 'jpeg', 'gif', 'xls', 'xlsx', 'pdf', 'xls', 'xlsx', 'doc', 'docx', 'ppt', 'zip', 'pptx', 'mp4', 'flv'], 'image');
  59. $data['imgUrl'] = $urlN->imgUrl($data['src']);
  60. return Result::success($data, '上传成功');
  61. } catch (\Exception $e) {
  62. return Result::error($e->getMessage());
  63. }
  64. }
  65. }