AgentController.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace App\Http\Controllers\Api\v1;
  3. use App\Http\Controllers\Api\webApp;
  4. use App\Http\Validator\AgentValidator;
  5. use App\Services\Api\AgentService;
  6. /**
  7. * 代理
  8. * @package App\Http\Controllers\Api
  9. */
  10. class AgentController extends webApp
  11. {
  12. /**
  13. * 列表
  14. * @return array
  15. */
  16. public function index()
  17. {
  18. $params =request()->post();
  19. $pageSize = request()->post('pageSize', 15);
  20. $datas = AgentService::make()->getDataList($params, $pageSize);
  21. return showJson(1010, true, $datas);
  22. }
  23. /**
  24. * 详情
  25. * @return array
  26. */
  27. public function info()
  28. {
  29. try {
  30. if(!$result = AgentService::make()->getInfo($this->userId)){
  31. return showJson(1009, false);
  32. }else{
  33. return showJson(1010, true, $result);
  34. }
  35. } catch (\Exception $exception) {
  36. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  37. return showJson(1046, false, $error);
  38. }
  39. }
  40. /**
  41. * 入驻
  42. * @param AgentValidator $validator
  43. * @return array
  44. */
  45. public function apply(AgentValidator $validator)
  46. {
  47. $params = request()->all();
  48. $params = $validator->check($params, 'apply');
  49. if (!is_array($params)) {
  50. return showJson($params, false);
  51. }
  52. try {
  53. if(!$result = AgentService::make()->apply($this->userId, $params)){
  54. return showJson(AgentService::make()->getError(), false);
  55. }else{
  56. return showJson(AgentService::make()->getError(), true, $result);
  57. }
  58. } catch (\Exception $exception) {
  59. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  60. return showJson(1046, false, $error);
  61. }
  62. }
  63. }