SeriesManage.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. if($id = $this->request->get('id')) $sel_where[] = ['id','=',$id];
  42. $in_ids = '';
  43. if($phone = $this->request->get('phone')) $in_ids = VideoUrl::where('phone','like','%'.$phone.'%')->column('video_id');
  44. $query = $this->_query($this->table);
  45. $query->where($sel_where)->when($in_ids,function ($query)use ($in_ids){
  46. if(!empty($in_ids)) $query->where('id','in',$in_ids);
  47. })->order('sort desc,id desc')->page();
  48. }
  49. /**
  50. * 数据列表处理
  51. * @auth true
  52. * @menu true
  53. * @param array $data
  54. * @throws \think\db\exception\DataNotFoundException
  55. * @throws \think\db\exception\ModelNotFoundException
  56. * @throws \think\exception\DbException
  57. */
  58. protected function _index_page_filter(&$data)
  59. {
  60. }
  61. /**
  62. * 添加
  63. * @auth true
  64. * @menu true
  65. * @throws \think\Exception
  66. * @throws \think\db\exception\DataNotFoundException
  67. * @throws \think\db\exception\ModelNotFoundException
  68. * @throws \think\exception\DbException
  69. * @throws \think\exception\PDOException
  70. */
  71. public function add()
  72. {
  73. $this->title = '添加视频';
  74. $this->type = input('get.type',2);
  75. $this->_form($this->table, 'form');
  76. }
  77. /**
  78. * 编辑
  79. * @auth true
  80. * @menu true
  81. * @throws \think\Exception
  82. * @throws \think\db\exception\DataNotFoundException
  83. * @throws \think\db\exception\ModelNotFoundException
  84. * @throws \think\exception\DbException
  85. * @throws \think\exception\PDOException
  86. */
  87. public function edit()
  88. {
  89. $this->title = '编辑视频';
  90. $this->type = input('get.type',2);
  91. $this->_form($this->table, 'form') ;
  92. }
  93. /**
  94. * 禁用
  95. * @auth true
  96. * @menu true
  97. * @throws \think\Exception
  98. * @throws \think\db\exception\DataNotFoundException
  99. * @throws \think\db\exception\ModelNotFoundException
  100. * @throws \think\exception\DbException
  101. * @throws \think\exception\PDOException
  102. */
  103. public function forbidden()
  104. {
  105. $this->_save($this->table, ['status' => '0']);
  106. }
  107. /**
  108. * 启用
  109. * @auth true
  110. * @menu true
  111. * @throws \think\Exception
  112. * @throws \think\db\exception\DataNotFoundException
  113. * @throws \think\db\exception\ModelNotFoundException
  114. * @throws \think\exception\DbException
  115. * @throws \think\exception\PDOException
  116. */
  117. public function enable()
  118. {
  119. $this->_save($this->table, ['status' => 1]);
  120. }
  121. /**
  122. * 删除视频
  123. * @auth true
  124. * @menu true
  125. * @throws \think\Exception
  126. * @throws \think\db\exception\DataNotFoundException
  127. * @throws \think\db\exception\ModelNotFoundException
  128. * @throws \think\exception\DbException
  129. * @throws \think\exception\PDOException
  130. */
  131. public function del()
  132. {
  133. $this->_save($this->table, ['is_deleted' => 1]);
  134. }
  135. /**
  136. * 删除视频
  137. * @auth true
  138. * @menu true
  139. * @throws \think\Exception
  140. * @throws \think\db\exception\DataNotFoundException
  141. * @throws \think\db\exception\ModelNotFoundException
  142. * @throws \think\exception\DbException
  143. * @throws \think\exception\PDOException
  144. */
  145. public function remove()
  146. {
  147. $this->_save($this->table, ['is_deleted' => 1]);
  148. }
  149. /**
  150. * 表单数据处理
  151. * @auth true
  152. * @menu true
  153. * @param array $data
  154. */
  155. protected function _form_filter(&$data)
  156. {
  157. if($this->request->isGet()){
  158. $all_cate = VCM::where(['is_deleted'=>0])->order('sort desc ,id desc')->select();
  159. $this->r = input('get.r',0);
  160. $this->cate_tree = make_tree($all_cate);
  161. if($this->request->action() == 'add') {
  162. $this->video_url = $this->request->get('type',1) == 1 ? '' :[];
  163. }else{
  164. if($this->request->get('type',1) == 1 ) {
  165. $this->video_url = VideoUrl::where(['video_id'=>$data['id']])->find()->toArray();
  166. }else{
  167. $this->video_url = VideoUrl::where(['video_id'=>$data['id']])->order('sort desc,id asc')->select()->toArray();
  168. }
  169. }
  170. }
  171. if($this->request->isPost()) {
  172. if($data['type'] == 1){
  173. if( !$data['url']) $this->error('请上传视频');
  174. }
  175. if($this->request->action() == 'add') $data['url_num'] = 0;
  176. }
  177. }
  178. protected function _form_result($result){
  179. }
  180. }