SeriesManage.php 5.0 KB

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