VideoManage.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. namespace app\Nutrition\controller;
  3. use app\common\model\NutritionCase;
  4. use library\Controller;
  5. use library\tools\Data;
  6. use think\Db;
  7. use app\common\model\VideoCate as VCM;
  8. /**
  9. * 视频管理
  10. * Class VideoManage
  11. * @package app\Nutrition\controller
  12. */
  13. class VideoManage extends Controller
  14. {
  15. /**
  16. * 绑定数据表
  17. * @var string
  18. */
  19. protected $table = 'VideoIntro';
  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. $video_cate = VCM::field('id,title')->select()->toArray();
  34. $this->video_cate = array_column($video_cate,null,'id');
  35. $sel_where = [];
  36. $sel_where[] = ['is_deleted','=',0];
  37. if($title = $this->request->get('title')) $sel_where[] = ['title','like','%'.$title.'%'];
  38. $query = $this->_query($this->table);
  39. $query->where($sel_where)->order('status desc ,is_top desc ,sort desc,id desc')->page();
  40. }
  41. /**
  42. * 数据列表处理
  43. * @auth true
  44. * @menu true
  45. * @param array $data
  46. * @throws \think\db\exception\DataNotFoundException
  47. * @throws \think\db\exception\ModelNotFoundException
  48. * @throws \think\exception\DbException
  49. */
  50. protected function _index_page_filter(&$data)
  51. {
  52. }
  53. /**
  54. * 添加
  55. * @auth true
  56. * @menu true
  57. * @throws \think\Exception
  58. * @throws \think\db\exception\DataNotFoundException
  59. * @throws \think\db\exception\ModelNotFoundException
  60. * @throws \think\exception\DbException
  61. * @throws \think\exception\PDOException
  62. */
  63. public function add()
  64. {
  65. $this->title = '添加视频';
  66. $this->_form($this->table, 'form');
  67. }
  68. /**
  69. * 编辑
  70. * @auth true
  71. * @menu true
  72. * @throws \think\Exception
  73. * @throws \think\db\exception\DataNotFoundException
  74. * @throws \think\db\exception\ModelNotFoundException
  75. * @throws \think\exception\DbException
  76. * @throws \think\exception\PDOException
  77. */
  78. public function edit()
  79. {
  80. $this->title = '编辑视频';
  81. $this->_form($this->table, 'form');
  82. }
  83. /**
  84. * 禁用
  85. * @auth true
  86. * @menu true
  87. * @throws \think\Exception
  88. * @throws \think\db\exception\DataNotFoundException
  89. * @throws \think\db\exception\ModelNotFoundException
  90. * @throws \think\exception\DbException
  91. * @throws \think\exception\PDOException
  92. */
  93. public function forbidden()
  94. {
  95. $this->_save($this->table, ['status' => '0']);
  96. }
  97. /**
  98. * 启用
  99. * @auth true
  100. * @menu true
  101. * @throws \think\Exception
  102. * @throws \think\db\exception\DataNotFoundException
  103. * @throws \think\db\exception\ModelNotFoundException
  104. * @throws \think\exception\DbException
  105. * @throws \think\exception\PDOException
  106. */
  107. public function enable()
  108. {
  109. $this->_save($this->table, ['status' => 1]);
  110. }
  111. /**
  112. * 删除视频
  113. * @auth true
  114. * @menu true
  115. * @throws \think\Exception
  116. * @throws \think\db\exception\DataNotFoundException
  117. * @throws \think\db\exception\ModelNotFoundException
  118. * @throws \think\exception\DbException
  119. * @throws \think\exception\PDOException
  120. */
  121. public function del()
  122. {
  123. $this->_save($this->table, ['is_deleted' => 1]);
  124. }
  125. /**
  126. * 表单数据处理
  127. * @auth true
  128. * @menu true
  129. * @param array $data
  130. */
  131. protected function _form_filter(&$data)
  132. {
  133. if($this->request->isGet()){
  134. $this->cate_tree = VCM::where(['is_deleted'=>0])->order('sort desc ,id desc')->select();
  135. }
  136. if($this->request->isPost()) {
  137. if( !$data['video_url']) $this->error('请上传视频');
  138. }
  139. }
  140. protected function _form_result($result){
  141. if($this->request->isPost()){
  142. Data::save('PlatformMessage',['type'=>1,'create_at'=>date('Y-m-d H:i:s'),'content'=>input('post.title'),'relation_id'=>$result],'type',['type'=>1,'relation_id'=>$result]);
  143. }
  144. }
  145. }