ArticleController.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. * @return array
  29. */
  30. public function industry()
  31. {
  32. try {
  33. $data = [
  34. // 轮播
  35. 'banners' => AdService::make()->getListByPosition(2), // 轮播
  36. 'supervisors' => SupervisorsService::make()->getRecommendList(), // 推荐导师
  37. 'articles' => ArticleService::make()->getListByType(2), // 行业政策资讯
  38. ];
  39. return showJson(1010, true, $data);
  40. } catch (\Exception $exception) {
  41. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  42. return showJson(1046, false, $error);
  43. }
  44. }
  45. /**
  46. * 详情
  47. */
  48. public function info()
  49. {
  50. $params = request()->all();
  51. $id = isset($params['id'])? intval($params['id']) : 0;
  52. if(empty($id)){
  53. return message(1036, false);
  54. }
  55. if($info = ArticleService::make()->getInfo($id)){
  56. return message(1010, true, $info);
  57. }else{
  58. return message(1009, false);
  59. }
  60. }
  61. /**
  62. * 分类
  63. * @return array
  64. */
  65. public function categorys()
  66. {
  67. $type = request()->post('type', 1);
  68. $datas = ArticleService::make()->getCateList($type);
  69. return message(1010, true, $datas);
  70. }
  71. /**
  72. * 单页数据
  73. */
  74. public function page()
  75. {
  76. $params = request()->all();
  77. $type = isset($params['type'])? intval($params['type']) : 0;
  78. if(empty($type)){
  79. return message(1031, false);
  80. }
  81. if($info = ArticleService::make()->getInfoByType($type)){
  82. return message(1010, true, $info);
  83. }else{
  84. return message(1009, false);
  85. }
  86. }
  87. /**
  88. * 咨询提交
  89. */
  90. public function consult(ConsultValidator $validator)
  91. {
  92. $params = request()->post();
  93. $params = $validator->check($params, 'submit');
  94. if (!is_array($params)) {
  95. return showJson($params, false);
  96. }
  97. try {
  98. if (ArticleService::make()->consultSubmit($this->userId, $params)) {
  99. return showJson(ArticleService::make()->getError(), true);
  100. } else {
  101. return showJson(ArticleService::make()->getError(), false);
  102. }
  103. } catch (\Exception $exception) {
  104. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  105. return showJson(1046, false, $error);
  106. }
  107. }
  108. }