Item.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. namespace app\data\controller\news;
  3. use app\data\model\DataNewsItem;
  4. use app\data\model\DataNewsMark;
  5. use app\data\service\NewsService;
  6. use think\admin\Controller;
  7. use think\admin\extend\CodeExtend;
  8. use think\admin\helper\QueryHelper;
  9. /**
  10. * 文章内容管理
  11. * Class Item
  12. * @package app\data\controller\news
  13. */
  14. class Item extends Controller
  15. {
  16. /**
  17. * 文章内容管理
  18. * @auth true
  19. * @menu true
  20. * @throws \think\db\exception\DataNotFoundException
  21. * @throws \think\db\exception\DbException
  22. * @throws \think\db\exception\ModelNotFoundException
  23. */
  24. public function index()
  25. {
  26. $this->type = input('get.type', 'index');
  27. DataNewsItem::mQuery($this->get)->layTable(function () {
  28. $this->title = '文章内容管理';
  29. $this->marks = DataNewsMark::items();
  30. }, function (QueryHelper $query) {
  31. $query->like('code,name')->like('mark', ',')->dateBetween('create_at');
  32. $query->where(['status' => intval($this->type === 'index'), 'deleted' => 0]);
  33. });
  34. }
  35. /**
  36. * 列表数据处理
  37. * @param array $data
  38. */
  39. protected function _page_filter(array &$data)
  40. {
  41. NewsService::buildData($data);
  42. }
  43. /**
  44. * 添加文章内容
  45. * @auth true
  46. */
  47. public function add()
  48. {
  49. $this->title = '添加文章内容';
  50. DataNewsItem::mForm('form');
  51. }
  52. /**
  53. * 编辑文章内容
  54. * @auth true
  55. */
  56. public function edit()
  57. {
  58. $this->title = '编辑文章内容';
  59. DataNewsItem::mForm('form');
  60. }
  61. /**
  62. * 表单数据处理
  63. * @param array $data
  64. * @throws \think\db\exception\DataNotFoundException
  65. * @throws \think\db\exception\DbException
  66. * @throws \think\db\exception\ModelNotFoundException
  67. */
  68. protected function _form_filter(array &$data)
  69. {
  70. if (empty($data['code'])) {
  71. $data['code'] = CodeExtend::uniqidNumber(20, 'A');
  72. }
  73. if ($this->request->isGet()) {
  74. $model = DataNewsMark::mk()->where(['status' => 1, 'deleted' => 0]);
  75. $this->marks = $model->order('sort desc,id desc')->select()->toArray();
  76. $data['mark'] = str2arr($data['mark'] ?? '');
  77. } else {
  78. $data['mark'] = arr2str($data['mark'] ?? []);
  79. }
  80. }
  81. /**
  82. * 表单结果处理
  83. * @param boolean $state
  84. */
  85. protected function _form_result(bool $state)
  86. {
  87. if ($state) {
  88. $this->success('文章保存成功!', 'javascript:history.back()');
  89. }
  90. }
  91. /**
  92. * 修改文章状态
  93. * @auth true
  94. */
  95. public function state()
  96. {
  97. DataNewsItem::mSave($this->_vali([
  98. 'status.in:0,1' => '状态值范围异常!',
  99. 'status.require' => '状态值不能为空!',
  100. ]));
  101. }
  102. /**
  103. * 删除文章内容
  104. * @auth true
  105. */
  106. public function remove()
  107. {
  108. DataNewsItem::mDelete();
  109. }
  110. /**
  111. * 文章内容选择
  112. * @login true
  113. * @throws \think\db\exception\DataNotFoundException
  114. * @throws \think\db\exception\DbException
  115. * @throws \think\db\exception\ModelNotFoundException
  116. */
  117. public function select()
  118. {
  119. $this->get['status'] = 1;
  120. $this->index();
  121. }
  122. }