SeriesManage.php 6.9 KB

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