SeriesArticle.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?php
  2. namespace app\Nutrition\controller;
  3. use app\common\model\ArticleIntro;
  4. use app\common\model\SeriesArticleCate;
  5. use library\Controller;
  6. use library\tools\Data;
  7. use app\common\model\DatumCate;
  8. /**
  9. * 图文管理
  10. * Class SeriesArticle
  11. * @package app\Nutrition\controller
  12. */
  13. class SeriesArticle extends Controller
  14. {
  15. /**
  16. * 绑定数据表
  17. * @var string
  18. */
  19. protected $table = 'ArticleIntro';
  20. /**
  21. * 列表
  22. * @auth true
  23. * @menu true
  24. * @throws \think\Exception
  25. * @throws \think\db\exception\DataNotFoundException
  26. * @throws \think\db\exception\ModelNotFoundException
  27. * @throws \think\exception\DbException
  28. * @throws \think\exception\PDOException
  29. */
  30. public function index()
  31. {
  32. $this->title = '文章列表';
  33. $sel_where = [];
  34. $sel_where[] = ['is_deleted','=',0];
  35. $sel_where[] = ['type','=',2];
  36. if($title = $this->request->get('title')) $sel_where[] = ['title','like','%'.$title.'%'];
  37. if($label = $this->request->get('label')) $sel_where[] = ['label','like','%'.$label.'%'];
  38. $this->is_vip = $is_vip = $this->request->get('is_vip',-1);
  39. if($is_vip >= 0) $sel_where[] = ['is_vip','=',$is_vip ];
  40. $query = $this->_query($this->table);
  41. $query->where($sel_where)->order('sort desc,id desc')->page();
  42. }
  43. /**
  44. * 数据列表处理
  45. * @auth true
  46. * @menu true
  47. * @param array $data
  48. * @throws \think\db\exception\DataNotFoundException
  49. * @throws \think\db\exception\ModelNotFoundException
  50. * @throws \think\exception\DbException
  51. */
  52. protected function _index_page_filter(&$data)
  53. {
  54. }
  55. /**
  56. * 添加
  57. * @auth true
  58. * @menu true
  59. * @throws \think\Exception
  60. * @throws \think\db\exception\DataNotFoundException
  61. * @throws \think\db\exception\ModelNotFoundException
  62. * @throws \think\exception\DbException
  63. * @throws \think\exception\PDOException
  64. */
  65. public function add()
  66. {
  67. $this->title = '添加图文';
  68. $this->type = input('get.type',2);
  69. $this->_form($this->table, 'form');
  70. }
  71. /**
  72. * 编辑
  73. * @auth true
  74. * @menu true
  75. * @throws \think\Exception
  76. * @throws \think\db\exception\DataNotFoundException
  77. * @throws \think\db\exception\ModelNotFoundException
  78. * @throws \think\exception\DbException
  79. * @throws \think\exception\PDOException
  80. */
  81. public function edit()
  82. {
  83. $this->title = '编辑图文';
  84. $this->type = input('get.type',2);
  85. $this->_form($this->table, 'form') ;
  86. }
  87. /**
  88. * 禁用
  89. * @auth true
  90. * @menu true
  91. * @throws \think\Exception
  92. * @throws \think\db\exception\DataNotFoundException
  93. * @throws \think\db\exception\ModelNotFoundException
  94. * @throws \think\exception\DbException
  95. * @throws \think\exception\PDOException
  96. */
  97. public function forbid()
  98. {
  99. $this->_save($this->table, ['status' => '0']);
  100. }
  101. /**
  102. * 启用
  103. * @auth true
  104. * @menu true
  105. * @throws \think\Exception
  106. * @throws \think\db\exception\DataNotFoundException
  107. * @throws \think\db\exception\ModelNotFoundException
  108. * @throws \think\exception\DbException
  109. * @throws \think\exception\PDOException
  110. */
  111. public function resume()
  112. {
  113. $this->_save($this->table, ['status' => 1]);
  114. }
  115. /**
  116. * 删除图文
  117. * @auth true
  118. * @menu true
  119. * @throws \think\Exception
  120. * @throws \think\db\exception\DataNotFoundException
  121. * @throws \think\db\exception\ModelNotFoundException
  122. * @throws \think\exception\DbException
  123. * @throws \think\exception\PDOException
  124. */
  125. public function del()
  126. {
  127. $this->_save($this->table, ['is_deleted' => 1]);
  128. }
  129. /**
  130. * 表单数据处理
  131. * @auth true
  132. * @menu true
  133. * @param array $data
  134. */
  135. protected function _form_filter(&$data)
  136. {
  137. if($this->request->isGet()){
  138. $this->r = input('get.r',0);
  139. if($this->request->isGet()){
  140. $all_cate = SeriesArticleCate::where(['is_deleted'=>0])->order('sort desc ,id desc')->select();
  141. $this->cate_tree = make_tree($all_cate);
  142. }
  143. }
  144. if($this->request->isPost()) {
  145. if($this->request->action() == 'add') $data['item_num'] = 0;
  146. }
  147. }
  148. }