ArticleController.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. namespace App\Http\Controllers\Api\v1;
  3. use App\Http\Controllers\Api\webApp;
  4. use App\Services\Api\ArticleService;
  5. /**
  6. * 文章管理
  7. * Class ArticleController
  8. * @package App\Http\Controllers\Api
  9. */
  10. class ArticleController 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 = ArticleService::make()->getDataList($params, $pageSize);
  21. return message(1010, true, $datas);
  22. }
  23. /**
  24. * 咨询问答主页数据
  25. * @return array
  26. */
  27. public function datas()
  28. {
  29. $datas = [
  30. 'hotList' => ArticleService::make()->getHotList($this->userId),
  31. 'recList' => ArticleService::make()->getRecommendList(),
  32. ];
  33. return message(1010, true, $datas);
  34. }
  35. /**
  36. * 资料分类
  37. * @return array
  38. */
  39. public function cates()
  40. {
  41. $params = request()->all();
  42. $type = isset($params['type'])? $params['type'] : 2;
  43. $sc = isset($params['sc'])? $params['sc'] : 0;
  44. $datas = ArticleService::make()->getCateList($type, $sc);
  45. return message(1010, true, $datas);
  46. }
  47. /**
  48. * 热门咨询
  49. * @return array
  50. */
  51. public function hots()
  52. {
  53. $params = request()->all();
  54. $refresh = isset($params['refresh'])? $params['refresh'] : false;
  55. $datas = ArticleService::make()->getHotList($this->userId, $refresh);
  56. return message(1010, true, $datas);
  57. }
  58. /**
  59. * 详情
  60. */
  61. public function info()
  62. {
  63. $params = request()->all();
  64. $id = isset($params['id']) ? intval($params['id']) : 0;
  65. if (empty($id)) {
  66. return message(1036, false);
  67. }
  68. if ($info = ArticleService::make()->getInfo($id)) {
  69. return message(1010, true, $info);
  70. } else {
  71. return message(1009, false);
  72. }
  73. }
  74. /**
  75. * 问题咨询
  76. */
  77. public function search()
  78. {
  79. $params = request()->all();
  80. if ($info = ArticleService::make()->search($params)) {
  81. return message(1010, true, $info);
  82. } else {
  83. return message('抱歉,没有找到您要的答案', false);
  84. }
  85. }
  86. /**
  87. * 单页数据
  88. */
  89. public function page()
  90. {
  91. $params = request()->all();
  92. $type = isset($params['type']) ? intval($params['type']) : 0;
  93. if (empty($type)) {
  94. return message(1031, false);
  95. }
  96. if ($info = ArticleService::make()->getInfoByType($type)) {
  97. return message(1010, true, $info);
  98. } else {
  99. return message(1009, false);
  100. }
  101. }
  102. }