ArticleController.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace App\Http\Controllers\Api\v1;
  3. use App\Http\Controllers\Api\webApp;
  4. use App\Http\Validator\ConsultValidator;
  5. use App\Services\Api\ArticleService;
  6. use App\Services\Api\SupervisorsService;
  7. use App\Services\Common\AdService;
  8. /**
  9. * 文章管理
  10. * Class ArticleController
  11. * @package App\Http\Controllers\Api
  12. */
  13. class ArticleController extends webApp
  14. {
  15. /**
  16. * 列表
  17. * @return array
  18. */
  19. public function index()
  20. {
  21. $params =request()->post();
  22. $pageSize = request()->post('pageSize', 15);
  23. $datas = ArticleService::make()->getDataList($params, $pageSize);
  24. return message(1010, true, $datas);
  25. }
  26. /**
  27. * 详情
  28. */
  29. public function info()
  30. {
  31. $params = request()->all();
  32. $id = isset($params['id'])? intval($params['id']) : 0;
  33. if(empty($id)){
  34. return message(1036, false);
  35. }
  36. if($info = ArticleService::make()->getInfo($id)){
  37. return message(1010, true, $info);
  38. }else{
  39. return message(1009, false);
  40. }
  41. }
  42. /**
  43. * 分类
  44. * @return array
  45. */
  46. public function categorys()
  47. {
  48. $type = request()->post('type', 1);
  49. $datas = ArticleService::make()->getCateList($type);
  50. return message(1010, true, $datas);
  51. }
  52. /**
  53. * 单页数据
  54. */
  55. public function page()
  56. {
  57. $params = request()->all();
  58. $type = isset($params['type'])? intval($params['type']) : 0;
  59. if(empty($type)){
  60. return message(1031, false);
  61. }
  62. if($info = ArticleService::make()->getInfoByType($type)){
  63. return message(1010, true, $info);
  64. }else{
  65. return message(1009, false);
  66. }
  67. }
  68. /**
  69. * 咨询提交
  70. */
  71. public function consult(ConsultValidator $validator)
  72. {
  73. $params = request()->post();
  74. $params = $validator->check($params, 'submit');
  75. if (!is_array($params)) {
  76. return showJson($params, false);
  77. }
  78. try {
  79. if (ArticleService::make()->consultSubmit($this->userId, $params)) {
  80. return showJson(ArticleService::make()->getError(), true);
  81. } else {
  82. return showJson(ArticleService::make()->getError(), false);
  83. }
  84. } catch (\Exception $exception) {
  85. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  86. return showJson(1046, false, $error);
  87. }
  88. }
  89. }