Video.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. use app\common\library\Keyworld;
  6. /**
  7. * 视频
  8. */
  9. class Video extends Api
  10. {
  11. protected $noNeedLogin = ['typelist','lists','info','good'];
  12. protected $noNeedRight = ['*'];
  13. public function typelist(){
  14. $list = Db::name('video_type')->where('is_show',1)->order('weigh desc')->select();
  15. $this->success('success',$list);
  16. }
  17. public function lists(){
  18. $type_id = input('type_id',0);
  19. $where = [
  20. 'is_show' => 1
  21. ];
  22. if($type_id){
  23. $where['type_id'] = $type_id;
  24. }
  25. $list = Db::name('video')->where($where)->order('weigh desc')->autopage()->select();
  26. $list = list_domain_image($list,['video_file','video_image']);
  27. $this->success('success',$list);
  28. }
  29. //获取详情
  30. public function info(){
  31. $id = input('id',0);
  32. $info = Db::name('video')->where('id',$id)->find();
  33. $info = info_domain_image($info,['video_file','video_image']);
  34. $this->success('success',$info);
  35. }
  36. //评论列表
  37. public function answer_list(){
  38. $id = input('id',0);
  39. $list = Db::name('video_answer')->alias('va')
  40. ->field('va.info,va.createtime,user.nickname,user.avatar')
  41. ->join('user','va.user_id = user.id','LEFT')
  42. ->where('va.video_id',$id)
  43. ->order('va.id desc')->autopage()->select();
  44. if(!empty($list)){
  45. foreach($list as $key => &$val){
  46. $val['createtime'] = get_last_time($val['createtime']);
  47. $val['avatar'] = localpath_to_netpath($val['avatar']);
  48. }
  49. }
  50. $this->success(1,$list);
  51. }
  52. //点赞
  53. public function good(){
  54. $id = input('id');
  55. Db::name('video')->where('id',$id)->setInc('goodnum');
  56. $this->success('点赞成功');
  57. }
  58. //评论
  59. public function answer(){
  60. $id = input('id',0);
  61. $info = input('info','');
  62. if(empty($info) || empty($id)){
  63. $this->error();
  64. }
  65. //关键字替换
  66. $info = Keyworld::sensitive($info);
  67. //data
  68. $data = [
  69. 'video_id' => $id,
  70. 'user_id' => $this->auth->id,
  71. 'info' => $info,
  72. 'createtime' => time(),
  73. 'updatetime' => time(),
  74. ];
  75. Db::startTrans();
  76. $rs = Db::name('video_answer')->insertGetId($data);
  77. $answernum = Db::name('video')->where('id',$id)->setInc('answernum');
  78. Db::commit();
  79. $this->success('评价成功');
  80. }
  81. }