Article.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Niucloud-admin 企业快速开发的saas管理平台
  4. // +----------------------------------------------------------------------
  5. // | 官方网址:https://www.niucloud.com
  6. // +----------------------------------------------------------------------
  7. // | niucloud团队 版权所有 开源版本可自由商用
  8. // +----------------------------------------------------------------------
  9. // | Author: Niucloud Team
  10. // +----------------------------------------------------------------------
  11. namespace app\api\controller\article;
  12. use app\service\api\article\ArticleService;
  13. use core\base\BaseApiController;
  14. use think\Response;
  15. /**
  16. * 文章控制器
  17. * Class Article
  18. * @package app\api\controller\article
  19. */
  20. class Article extends BaseApiController
  21. {
  22. /**
  23. * 文章列表
  24. * @return Response
  25. */
  26. public function lists()
  27. {
  28. $data = $this->request->params([
  29. [ 'title', '' ],
  30. [ 'category_id', '' ],
  31. ]);
  32. return success(( new ArticleService() )->getPage($data));
  33. }
  34. public function all()
  35. {
  36. $data = $this->request->params([
  37. [ 'title', '' ],
  38. [ 'category_id', '' ],
  39. [ 'ids', [] ],
  40. [ 'limit', 0 ]
  41. ]);
  42. return success(( new ArticleService() )->getAll($data, $data[ 'limit' ]));
  43. }
  44. /**
  45. * 热门资讯
  46. * @return Response
  47. */
  48. public function hot()
  49. {
  50. $data = $this->request->params([
  51. [ 'limit', 5 ]
  52. ]);
  53. return success(( new ArticleService() )->getHot($data[ 'limit' ]));
  54. }
  55. /**
  56. * 文章详情
  57. * @param int $id
  58. * @return Response
  59. */
  60. public function info(int $id)
  61. {
  62. return success(( new ArticleService() )->getInfo($id));
  63. }
  64. /**
  65. * 增加文章访问量
  66. * @param int $id
  67. * @return Response
  68. */
  69. public function incVisit()
  70. {
  71. $data = $this->request->params([
  72. [ 'id', 0 ]
  73. ]);
  74. return success(data:( new ArticleService() )->incVisit($data[ 'id' ]));
  75. }
  76. }