SeriesDatum.php 5.3 KB

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