DatumUrl.php 4.2 KB

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