Article.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Niucloud-admin 企业快速开发的多应用管理平台
  4. // +----------------------------------------------------------------------
  5. // | 官方网址:https://www.niucloud.com
  6. // +----------------------------------------------------------------------
  7. // | niucloud团队 版权所有 开源版本可自由商用
  8. // +----------------------------------------------------------------------
  9. // | Author: Niucloud Team
  10. // +----------------------------------------------------------------------
  11. namespace app\adminapi\controller\article;
  12. use app\service\admin\article\ArticleService;
  13. use core\base\BaseAdminController;
  14. use think\Response;
  15. /**
  16. * 文章控制器
  17. * Class Article
  18. * @package app\adminapi\controller\article
  19. */
  20. class Article extends BaseAdminController
  21. {
  22. /**
  23. * 文章列表
  24. * @return Response
  25. */
  26. public function lists()
  27. {
  28. $data = $this->request->params( [
  29. [ 'title', '' ],
  30. [ 'category_id', '' ],
  31. [ 'sort', '' ],
  32. [ 'is_show', '' ],
  33. ] );
  34. return success( ( new ArticleService() )->getPage( $data ) );
  35. }
  36. /**
  37. * 文章详情
  38. * @param int $id
  39. * @return Response
  40. */
  41. public function info(int $id)
  42. {
  43. return success( ( new ArticleService() )->getInfo( $id ) );
  44. }
  45. /**
  46. * 添加文章
  47. * @return Response
  48. */
  49. public function add()
  50. {
  51. $data = $this->request->params( [
  52. [ 'title', '' ],
  53. [ 'category_id', '' ],
  54. [ 'intro', '' ],
  55. [ 'summary', '' ],
  56. [ 'image', '' ],
  57. [ 'author', '' ],
  58. [ 'content', '', false ],
  59. [ 'visit_virtual', 0 ],
  60. [ 'is_show', 1 ],
  61. [ 'sort', 0 ],
  62. ] );
  63. $this->validate( $data, 'app\validate\article\Article.add' );
  64. $id = ( new ArticleService() )->add( $data );
  65. return success( 'ADD_SUCCESS', [ 'id' => $id ] );
  66. }
  67. /**
  68. * 文章编辑
  69. * @param int $id
  70. * @return Response
  71. */
  72. public function edit(int $id)
  73. {
  74. $data = $this->request->params( [
  75. [ 'title', '' ],
  76. [ 'category_id', '' ],
  77. [ 'intro', '' ],
  78. [ 'summary', '' ],
  79. [ 'image', '' ],
  80. [ 'author', '' ],
  81. [ 'content', '', false ],
  82. [ 'visit_virtual', 0 ],
  83. [ 'is_show', 1 ],
  84. [ 'sort', 0 ],
  85. ] );
  86. $this->validate( $data, 'app\validate\article\Article.edit' );
  87. ( new ArticleService() )->edit( $id, $data );
  88. return success( 'EDIT_SUCCESS' );
  89. }
  90. /**
  91. * 文章删除
  92. * @param int $id
  93. * @return Response
  94. */
  95. public function del(int $id)
  96. {
  97. ( new ArticleService() )->del( $id );
  98. return success( 'DELETE_SUCCESS' );
  99. }
  100. }