ArticleController.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace App\Http\Controllers\Api\v1;
  3. use App\Http\Controllers\Api\webApp;
  4. use App\Services\Api\ArticleService;
  5. use App\Services\Api\SupervisorsService;
  6. use App\Services\Common\AdService;
  7. /**
  8. * 文章管理
  9. * Class ArticleController
  10. * @package App\Http\Controllers\Api
  11. */
  12. class ArticleController extends webApp
  13. {
  14. /**
  15. * 列表
  16. * @return array
  17. */
  18. public function index()
  19. {
  20. $params =request()->post();
  21. $pageSize = request()->post('pageSize', 15);
  22. $datas = ArticleService::make()->getDataList($params, $pageSize);
  23. return message(1010, true, $datas);
  24. }
  25. /**
  26. * 行业数据
  27. * @return array
  28. */
  29. public function industry()
  30. {
  31. try {
  32. $data = [
  33. // 轮播
  34. 'banners' => AdService::make()->getListByPosition(2), // 轮播
  35. 'supervisors' => SupervisorsService::make()->getRecommendList(), // 推荐导师
  36. 'articles' => ArticleService::make()->getListByType(2), // 行业政策资讯
  37. ];
  38. return showJson(1010, true, $data);
  39. } catch (\Exception $exception) {
  40. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  41. return showJson(1046, false, $error);
  42. }
  43. }
  44. /**
  45. * 详情
  46. */
  47. public function info()
  48. {
  49. $params = request()->all();
  50. $id = isset($params['id'])? intval($params['id']) : 0;
  51. if(empty($id)){
  52. return message(1036, false);
  53. }
  54. if($info = ArticleService::make()->getInfo($id)){
  55. return message(1010, true, $info);
  56. }else{
  57. return message(1009, false);
  58. }
  59. }
  60. /**
  61. * 单页数据
  62. */
  63. public function page()
  64. {
  65. $params = request()->all();
  66. $type = isset($params['type'])? intval($params['type']) : 0;
  67. if(empty($type)){
  68. return message(1031, false);
  69. }
  70. if($info = ArticleService::make()->getInfoByType($type)){
  71. return message(1010, true, $info);
  72. }else{
  73. return message(1009, false);
  74. }
  75. }
  76. }