SeriesManage.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. $in_ids = '';
  42. if($phone = $this->request->get('phone')) $in_ids = VideoUrl::where('phone','like','%'.$phone.'%')->column('video_id');
  43. $query = $this->_query($this->table);
  44. $query->where($sel_where)->when($in_ids,function ($query)use ($in_ids){
  45. if(!empty($in_ids)) $query->where('id','in',$in_ids);
  46. })->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. * @param array $data
  139. */
  140. protected function _form_filter(&$data)
  141. {
  142. if($this->request->isGet()){
  143. $all_cate = VCM::where(['is_deleted'=>0])->order('sort desc ,id desc')->select();
  144. $this->r = input('get.r',0);
  145. $this->cate_tree = make_tree($all_cate);
  146. if($this->request->action() == 'add') {
  147. $this->video_url = $this->request->get('type',1) == 1 ? '' :[];
  148. }else{
  149. if($this->request->get('type',1) == 1 ) {
  150. $this->video_url = VideoUrl::where(['video_id'=>$data['id']])->find()->toArray();
  151. }else{
  152. $this->video_url = VideoUrl::where(['video_id'=>$data['id']])->order('sort desc,id asc')->select()->toArray();
  153. }
  154. }
  155. }
  156. if($this->request->isPost()) {
  157. if($data['type'] == 1){
  158. if( !$data['url']) $this->error('请上传视频');
  159. }
  160. if($this->request->action() == 'add') $data['url_num'] = 0;
  161. }
  162. }
  163. protected function _form_result($result){
  164. }
  165. }