SeriesDatum.php 4.1 KB

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