Video.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 good(){
  38. $id = input('id');
  39. Db::name('video')->where('id',$id)->setInc('goodnum');
  40. $this->success('点赞成功');
  41. }
  42. //评论
  43. public function answer(){
  44. $id = input('id',0);
  45. $info = input('info','');
  46. if(empty($info) || empty($id)){
  47. $this->error();
  48. }
  49. //关键字替换
  50. $info = Keyworld::sensitive($info);
  51. //data
  52. $data = [
  53. 'video_id' => $id,
  54. 'user_id' => $this->auth->id,
  55. 'info' => $info,
  56. 'createtime' => time(),
  57. 'updatetime' => time(),
  58. ];
  59. Db::startTrans();
  60. $rs = Db::name('video_answer')->insertGetId($data);
  61. $answernum = Db::name('video')->where('id',$id)->setInc('answernum');
  62. Db::commit();
  63. $this->success('评价成功');
  64. }
  65. }