VideoUrl.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <?php
  2. namespace app\Nutrition\controller;
  3. use app\common\model\DatumIntro;
  4. use app\common\model\User;
  5. use app\common\model\VideoIntro;
  6. use library\Controller;
  7. use app\common\model\VideoCate;
  8. use function AlibabaCloud\Client\value;
  9. /**
  10. * 视频管理
  11. * Class VideoUrl
  12. * @package app\Nutrition\controller
  13. */
  14. class VideoUrl extends Controller
  15. {
  16. /**
  17. * 绑定数据表
  18. * @var string
  19. */
  20. protected $table = 'VideoUrl';
  21. protected $url_suffix = '?x-oss-process=video/snapshot,t_2000,m_fast';
  22. /**
  23. * 列表
  24. * @auth true
  25. * @menu true
  26. * @throws \think\Exception
  27. * @throws \think\db\exception\DataNotFoundException
  28. * @throws \think\db\exception\ModelNotFoundException
  29. * @throws \think\exception\DbException
  30. * @throws \think\exception\PDOException
  31. */
  32. public function index()
  33. {
  34. $this->title = '视频列表';
  35. $this->video_id = input('video_id');
  36. $sel_where = [];
  37. $sel_where[] = ['is_deleted','=',0];
  38. $sel_where[] = ['video_id','=',$this->video_id];
  39. $query = $this->_query($this->table);
  40. $query->where($sel_where)->order('sort desc,id desc')->page(false);
  41. }
  42. /**
  43. * 数据列表处理
  44. * @auth true
  45. * @menu true
  46. * @param array $data
  47. * @throws \think\db\exception\DataNotFoundException
  48. * @throws \think\db\exception\ModelNotFoundException
  49. * @throws \think\exception\DbException
  50. */
  51. protected function _index_page_filter(&$data)
  52. {
  53. }
  54. /**
  55. * 添加
  56. * @auth true
  57. * @menu true
  58. * @throws \think\Exception
  59. * @throws \think\db\exception\DataNotFoundException
  60. * @throws \think\db\exception\ModelNotFoundException
  61. * @throws \think\exception\DbException
  62. * @throws \think\exception\PDOException
  63. */
  64. public function add()
  65. {
  66. $this->title = '添加视频';
  67. $this->_form($this->table, 'form');
  68. }
  69. /**
  70. * 编辑
  71. * @auth true
  72. * @menu true
  73. * @throws \think\Exception
  74. * @throws \think\db\exception\DataNotFoundException
  75. * @throws \think\db\exception\ModelNotFoundException
  76. * @throws \think\exception\DbException
  77. * @throws \think\exception\PDOException
  78. */
  79. public function edit()
  80. {
  81. $this->title = '编辑视频';
  82. $this->_form($this->table, 'form') ;
  83. }
  84. /**
  85. * 删除视频
  86. * @auth true
  87. * @menu true
  88. * @throws \think\Exception
  89. * @throws \think\db\exception\DataNotFoundException
  90. * @throws \think\db\exception\ModelNotFoundException
  91. * @throws \think\exception\DbException
  92. * @throws \think\exception\PDOException
  93. */
  94. public function del()
  95. {
  96. $video_id = \app\common\model\VideoUrl::where('id',input('id'))->value('video_id');
  97. VideoIntro::where('id',$video_id)->setDec('url_num');
  98. $this->_save($this->table, ['is_deleted' => 1]);
  99. }
  100. /**
  101. * 表单数据处理
  102. * @auth true
  103. * @menu true
  104. * @param array $data
  105. */
  106. protected function _form_filter(&$data)
  107. {
  108. if($this->request->isGet()){
  109. $this->video_id = input('video_id');
  110. $this->video_info = VideoIntro::where('id',$this->video_id)->find()->toArray();
  111. // 文章列表
  112. $this->article_list = \app\common\model\ArticleIntro::with('itemList')
  113. ->where(['is_deleted'=>0])->order('id desc')
  114. ->select()->toArray();
  115. // 资料
  116. $this->datum_list = DatumIntro::with('urlArr')
  117. ->where(['is_deleted'=>0])->order('id desc')
  118. ->select()->toArray();
  119. }
  120. if($this->request->isPost()){
  121. list($post) = [$this->request->post()];
  122. if($post['up_type'] == 1){
  123. $data['url'] = $post['up_url'];
  124. }else{
  125. $data['url'] = $post['path'];
  126. }
  127. if(empty($data['cover'])) $this->error('请上传视频封面');
  128. if(empty($data['ali_vid'])) $this->error('云点播ID不能为空');
  129. $vid_info = getVideoTime($data['ali_vid']);
  130. $data['duration'] = $vid_info['duration'];
  131. $data['duration_str'] = $vid_info['duration_str'];
  132. if(!empty($post['phone'])) {
  133. $user_id = User::where('phone|email',$post['phone'])->value('id');
  134. if(!$user_id) $this->error('账号未注册');
  135. $data['user_id'] = $user_id;
  136. }else{
  137. $data['user_id'] = '';
  138. }
  139. }
  140. }
  141. protected function _form_result($result)
  142. {
  143. $url_num = \app\common\model\VideoUrl::where(['video_id'=>$this->request->post('video_id'),'is_deleted'=>0])->count();
  144. $video_info = VideoIntro::where('id',$this->request->post('video_id'))->find()->toArray();
  145. $url = $this->request->post('up_type',1) == 1 ? $this->request->post('up_url'):$this->request->post('path');
  146. $up['url_num'] = $url_num;
  147. if(!$video_info['cover']) $up['cover'] = $this->request->post('cover');
  148. if(!$video_info['video_url']) $up['video_url'] = $url;
  149. if(!$video_info['article_id']) $up['article_id'] = $this->request->post('article_id');
  150. if(!$video_info['article_item']) $up['article_item'] = $this->request->post('article_item');
  151. if(!$video_info['datum_id']) $up['datum_id'] = $this->request->post('datum_id');
  152. if(!$video_info['datum_item']) $up['datum_item'] = $this->request->post('datum_item');
  153. VideoIntro::where('id',$this->request->post('video_id'))->update($up);
  154. $this->success('操作成功', 'javascript:history.back()');
  155. }
  156. /**
  157. * 禁用
  158. * @auth true
  159. * @menu true
  160. * @throws \think\Exception
  161. * @throws \think\db\exception\DataNotFoundException
  162. * @throws \think\db\exception\ModelNotFoundException
  163. * @throws \think\exception\DbException
  164. * @throws \think\exception\PDOException
  165. */
  166. public function forbidden()
  167. {
  168. $this->_save($this->table, ['status' => '0']);
  169. }
  170. /**
  171. * 启用
  172. * @auth true
  173. * @menu true
  174. * @throws \think\Exception
  175. * @throws \think\db\exception\DataNotFoundException
  176. * @throws \think\db\exception\ModelNotFoundException
  177. * @throws \think\exception\DbException
  178. * @throws \think\exception\PDOException
  179. */
  180. public function enable()
  181. {
  182. $this->_save($this->table, ['status' => 1]);
  183. }
  184. }