ArticleController.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. $params = request()->all();
  30. $answerType = isset($params['answer_type'])?$params['answer_type']:1;
  31. $datas = [
  32. 'hotList' => ArticleService::make()->getHotList($this->userId,$answerType),
  33. 'recList' => ArticleService::make()->getRecommendList($answerType),
  34. ];
  35. return message(1010, true, $datas);
  36. }
  37. /**
  38. * 资料分类
  39. * @return array
  40. */
  41. public function cates()
  42. {
  43. $params = request()->all();
  44. $type = isset($params['type'])? $params['type'] : 2;
  45. $sc = isset($params['sc'])? $params['sc'] : 0;
  46. $datas = ArticleService::make()->getCateList($type, $sc);
  47. return message(1010, true, $datas);
  48. }
  49. /**
  50. * 热门咨询
  51. * @return array
  52. */
  53. public function hots()
  54. {
  55. $params = request()->all();
  56. $answerType = isset($params['answer_type'])? $params['answer_type'] : 1;
  57. $refresh = isset($params['refresh'])? $params['refresh'] : false;
  58. $datas = ArticleService::make()->getHotList($this->userId,$answerType, $refresh);
  59. return message(1010, true, $datas);
  60. }
  61. /**
  62. * 详情
  63. */
  64. public function info()
  65. {
  66. $params = request()->all();
  67. $id = isset($params['id']) ? intval($params['id']) : 0;
  68. if (empty($id)) {
  69. return message(1036, false);
  70. }
  71. if ($info = ArticleService::make()->getInfo($id)) {
  72. return message(1010, true, $info);
  73. } else {
  74. return message(1009, false);
  75. }
  76. }
  77. /**
  78. * 问题咨询
  79. */
  80. public function search()
  81. {
  82. $params = request()->all();
  83. if ($info = ArticleService::make()->search($params)) {
  84. return message(1010, true, $info);
  85. } else {
  86. return message('抱歉,没有找到您要的答案', false);
  87. }
  88. }
  89. /**
  90. * 单页数据
  91. */
  92. public function page()
  93. {
  94. $params = request()->all();
  95. $type = isset($params['type']) ? intval($params['type']) : 0;
  96. if (empty($type)) {
  97. return message(1031, false);
  98. }
  99. if ($info = ArticleService::make()->getInfoByType($type)) {
  100. return message(1010, true, $info);
  101. } else {
  102. return message(1009, false);
  103. }
  104. }
  105. /**
  106. * 预览
  107. */
  108. public function doc()
  109. {
  110. $url = request()->get('url');
  111. echo file_get_contents('https://view.officeapps.live.com/op/view.aspx?src='.$url);
  112. }
  113. }