ArticleController.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\api\controller;
  15. use app\api\lists\article\ArticleCollectLists;
  16. use app\api\lists\article\ArticleLists;
  17. use app\api\logic\ArticleLogic;
  18. /**
  19. * 文章管理
  20. * Class ArticleController
  21. * @package app\api\controller
  22. */
  23. class ArticleController extends BaseApiController
  24. {
  25. public array $notNeedLogin = ['lists', 'cate', 'detail'];
  26. /**
  27. * @notes 文章列表
  28. * @return \think\response\Json
  29. * @author 段誉
  30. * @date 2022/9/20 15:30
  31. */
  32. public function lists()
  33. {
  34. return $this->dataLists(new ArticleLists());
  35. }
  36. /**
  37. * @notes 文章分类列表
  38. * @return \think\response\Json
  39. * @author 段誉
  40. * @date 2022/9/20 15:30
  41. */
  42. public function cate()
  43. {
  44. return $this->data(ArticleLogic::cate());
  45. }
  46. /**
  47. * @notes 收藏列表
  48. * @return \think\response\Json
  49. * @author 段誉
  50. * @date 2022/9/20 16:31
  51. */
  52. public function collect()
  53. {
  54. return $this->dataLists(new ArticleCollectLists());
  55. }
  56. /**
  57. * @notes 文章详情
  58. * @return \think\response\Json
  59. * @author 段誉
  60. * @date 2022/9/20 17:09
  61. */
  62. public function detail()
  63. {
  64. $id = $this->request->get('id/d');
  65. $result = ArticleLogic::detail($id, $this->userId);
  66. return $this->data($result);
  67. }
  68. /**
  69. * @notes 加入收藏
  70. * @return \think\response\Json
  71. * @author 段誉
  72. * @date 2022/9/20 17:01
  73. */
  74. public function addCollect()
  75. {
  76. $articleId = $this->request->post('id/d');
  77. ArticleLogic::addCollect($articleId, $this->userId);
  78. return $this->success('操作成功');
  79. }
  80. /**
  81. * @notes 取消收藏
  82. * @return \think\response\Json
  83. * @author 段誉
  84. * @date 2022/9/20 17:01
  85. */
  86. public function cancelCollect()
  87. {
  88. $articleId = $this->request->post('id/d');
  89. ArticleLogic::cancelCollect($articleId, $this->userId);
  90. return $this->success('操作成功');
  91. }
  92. }