VideoUrl.php 6.5 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 asc')->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. if($this->request->action() == 'add')$data['is_vip'] = $this->video_info['is_vip'];
  112. // 文章列表
  113. $this->article_list =\app\common\model\ArticleIntro::with('itemChildren')
  114. ->field('id,title')
  115. ->where(['is_deleted'=>0])->order('id asc')
  116. ->select()->toArray();
  117. // 资料
  118. /* $this->datum_list = DatumIntro::with('urlArr')
  119. ->where(['is_deleted'=>0])->order('id desc')
  120. ->select()->toArray();*/
  121. $this->datum_list = [];
  122. }
  123. if($this->request->isPost()){
  124. list($post) = [$this->request->post()];
  125. if(empty($data['cover'])) $this->error('请上传视频封面');
  126. if(empty($data['ali_vid'])) $this->error('云点播ID不能为空');
  127. $vid_info = getVideoTime($data['ali_vid']);
  128. $data['duration'] = $vid_info['duration'];
  129. $data['duration_str'] = $vid_info['duration_str'];
  130. if(!empty($post['phone'])) {
  131. $user_id = User::where('phone|email',$post['phone'])->value('id');
  132. if(!$user_id) $this->error('账号未注册');
  133. $data['user_id'] = $user_id;
  134. }else{
  135. $data['user_id'] = '';
  136. }
  137. }
  138. }
  139. protected function _form_result($result)
  140. {
  141. $url_num = \app\common\model\VideoUrl::field('id,read_num')->where(['video_id'=>$this->request->post('video_id'),'is_deleted'=>0])->select()->toArray();
  142. $video_info = VideoIntro::where('id',$this->request->post('video_id'))->find()->toArray();
  143. $url = $this->request->post('up_type',1) == 1 ? $this->request->post('up_url'):$this->request->post('path');
  144. $up['url_num'] = count($url_num);
  145. $up['read_num'] = array_sum(array_column($url_num,'read_num'));
  146. if(!$video_info['cover']) $up['cover'] = $this->request->post('cover');
  147. if(!$video_info['video_url']) $up['video_url'] = $url;
  148. if(!$video_info['article_id']) $up['article_id'] = $this->request->post('article_id');
  149. if(!$video_info['article_item']) $up['article_item'] = $this->request->post('article_item');
  150. if(!$video_info['datum_id']) $up['datum_id'] = $this->request->post('datum_id');
  151. if(!$video_info['datum_item']) $up['datum_item'] = $this->request->post('datum_item');
  152. VideoIntro::where('id',$this->request->post('video_id'))->update($up);
  153. $this->success('操作成功', 'javascript:history.back()');
  154. }
  155. /**
  156. * 禁用
  157. * @auth true
  158. * @menu true
  159. * @throws \think\Exception
  160. * @throws \think\db\exception\DataNotFoundException
  161. * @throws \think\db\exception\ModelNotFoundException
  162. * @throws \think\exception\DbException
  163. * @throws \think\exception\PDOException
  164. */
  165. public function forbidden()
  166. {
  167. $this->_save($this->table, ['status' => '0']);
  168. }
  169. /**
  170. * 启用
  171. * @auth true
  172. * @menu true
  173. * @throws \think\Exception
  174. * @throws \think\db\exception\DataNotFoundException
  175. * @throws \think\db\exception\ModelNotFoundException
  176. * @throws \think\exception\DbException
  177. * @throws \think\exception\PDOException
  178. */
  179. public function enable()
  180. {
  181. $this->_save($this->table, ['status' => 1]);
  182. }
  183. }