Video.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace app\api\controller\coach;
  3. use app\common\controller\Apic;
  4. use think\Db;
  5. /**
  6. * 视频
  7. */
  8. class Video extends Apic
  9. {
  10. // 无需登录的接口,*表示全部
  11. protected $noNeedLogin = [];
  12. // 无需鉴权的接口,*表示全部
  13. protected $noNeedRight = ['*'];
  14. public function lists(){
  15. $list = Db::name('video')->where('coach_id',$this->auth->id)->autopage()->order('id desc')->select();
  16. $list = list_domain_image($list,['video_file']);
  17. if(!empty($list)){
  18. foreach($list as $key => &$val){
  19. if(!empty($val['video_file'])){
  20. $val['thumb_image'] = $val['video_file'].'?x-oss-process=video/snapshot,t_100,f_png,m_fast';
  21. }
  22. $val['createtime'] = $this->datetime_lang($val['createtime']);
  23. }
  24. }
  25. $this->success(1,$list);
  26. }
  27. public function addone(){
  28. $name = input('name','');
  29. $video_file = input('video_file','');
  30. $size = input('size','');
  31. $second = input('second',0,'intval');
  32. if(!$name || !$video_file){
  33. $this->error('标题和视频必填');
  34. }
  35. $data = [
  36. 'name' => $name,
  37. 'video_file' => $video_file,
  38. 'createtime' => time(),
  39. 'coach_id' => $this->auth->id,
  40. //获取视频大小和秒数
  41. 'size' => $size,
  42. 'second' => $second,
  43. ];
  44. $id = Db::name('video')->insertGetId($data);
  45. $this->success('发布成功',$id);
  46. }
  47. }