ArticleContent.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. namespace app\data\controller;
  3. use think\admin\Controller;
  4. /**
  5. * 文章内容管理
  6. * Class ArticleContent
  7. * @package app\data\controller
  8. */
  9. class ArticleContent extends Controller
  10. {
  11. /**
  12. * 绑定数据表
  13. * @var string
  14. */
  15. private $table = 'DataArticleContent';
  16. /**
  17. * 平台标签配置
  18. * @var array
  19. */
  20. protected $types = ['video' => '视频', 'article' => '文章', 'audio' => '音频'];
  21. /**
  22. * 文章内容管理
  23. * @auth true
  24. * @menu true
  25. * @throws \think\db\exception\DataNotFoundException
  26. * @throws \think\db\exception\DbException
  27. * @throws \think\db\exception\ModelNotFoundException
  28. */
  29. public function index()
  30. {
  31. $this->title = '文章内容管理';
  32. $query = $this->_query($this->table);
  33. $query->like('title,tags')->dateBetween('create_at');
  34. $query->where(['deleted' => 0])->order('sort desc,id desc')->page();
  35. }
  36. /**
  37. * 文章内容管理
  38. * @throws \think\db\exception\DataNotFoundException
  39. * @throws \think\db\exception\DbException
  40. * @throws \think\db\exception\ModelNotFoundException
  41. */
  42. public function select()
  43. {
  44. $query = $this->_query($this->table)->equal('status')->like('title');
  45. $query->where(['deleted' => '0'])->dateBetween('create_at')->order('sort desc,id desc')->page();
  46. }
  47. /**
  48. * 列表数据处理
  49. * @param array $data
  50. */
  51. protected function _page_filter(&$data)
  52. {
  53. foreach ($data as &$vo) {
  54. $vo['tags'] = explode(',', trim($vo['tags'], ','));
  55. }
  56. }
  57. /**
  58. * 添加文章内容
  59. * @auth true
  60. * @throws \think\db\exception\DataNotFoundException
  61. * @throws \think\db\exception\DbException
  62. * @throws \think\db\exception\ModelNotFoundException
  63. */
  64. public function add()
  65. {
  66. $this->title = '添加文章内容';
  67. $this->_form($this->table, 'form');
  68. }
  69. /**
  70. * 编辑文章内容
  71. * @auth true
  72. * @throws \think\db\exception\DataNotFoundException
  73. * @throws \think\db\exception\DbException
  74. * @throws \think\db\exception\ModelNotFoundException
  75. */
  76. public function edit()
  77. {
  78. $this->title = '编辑文章内容';
  79. $this->_form($this->table, 'form');
  80. }
  81. /**
  82. * 表单数据处理
  83. * @param array $data
  84. * @throws \think\db\exception\DataNotFoundException
  85. * @throws \think\db\exception\DbException
  86. * @throws \think\db\exception\ModelNotFoundException
  87. */
  88. protected function _form_filter(&$data)
  89. {
  90. if ($this->request->isGet()) {
  91. [$map, $sort] = [['deleted' => 0, 'status' => 1], 'sort desc,id desc'];
  92. $this->tags = $this->app->db->name('DataArticleTags')->where($map)->order($sort)->select()->toArray();
  93. $data['tags'] = isset($data['tags']) && $data['tags'] ? explode(',', trim($data['tags'], ',')) : [];
  94. } else {
  95. $data['tags'] = ',' . join(',', isset($data['tags']) && is_array($data['tags']) ? $data['tags'] : []) . ',';
  96. }
  97. }
  98. /**
  99. * 表单结果处理
  100. * @param boolean $state
  101. */
  102. protected function _form_result($state)
  103. {
  104. if ($state) {
  105. $this->success('文章内容保存成功!', 'javascript:history.back()');
  106. }
  107. }
  108. /**
  109. * 修改文章状态
  110. * @auth true
  111. * @throws \think\db\exception\DbException
  112. */
  113. public function state()
  114. {
  115. $this->_save($this->table, $this->_vali([
  116. 'status.in:0,1' => '状态值范围异常!',
  117. 'status.require' => '状态值不能为空!',
  118. ]));
  119. }
  120. /**
  121. * 删除文章内容
  122. * @auth true
  123. * @throws \think\db\exception\DbException
  124. */
  125. public function remove()
  126. {
  127. $this->_delete($this->table);
  128. }
  129. }