Video.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Gold
  5. * Date: 2024/1/15
  6. * Time: 17:45
  7. */
  8. namespace app\api\controller;
  9. use app\admin\model\books\Certificate;
  10. use app\admin\model\order\UserGoods;
  11. use app\admin\model\video\Video as VideoModel; //视频
  12. use app\admin\model\video\VideoFile; //视频
  13. use app\common\controller\Api;
  14. class Video extends Api
  15. {
  16. protected $noNeedLogin = ['*'];
  17. protected $noNeedRight = ['*'];
  18. /**
  19. * 视频列表
  20. *
  21. * api/video/getVideoList
  22. */
  23. public function getVideoList(){
  24. $data = input();
  25. $where = [];
  26. if(!isset($data['page']) || $data['page'] == '' || $data['page'] == null){
  27. $page = 1;
  28. }else{
  29. $page = $data['page'];
  30. }
  31. if(!isset($data['limit']) || $data['limit'] == '' || $data['limit'] == null){
  32. $limit = 20;
  33. }else{
  34. $limit = $data['limit'];
  35. }
  36. if ( isset($data['keywords']) && $data['keywords'] != '' && $data['keywords'] != null){
  37. $where['title'] = ['like','%'.$data['keywords'].'%'];
  38. }
  39. $VideoModel = new VideoModel();
  40. $list = $VideoModel->where('is_deleted',1)->where($where)->order('sort desc,id desc')->paginate([
  41. 'list_rows'=> $limit,
  42. 'page' => $page,
  43. ]);
  44. $this->success('操作成功',$list);
  45. }
  46. /**
  47. * 视频详情
  48. *
  49. * api/video/getVideoInfo
  50. */
  51. public function getVideoInfo(){
  52. $data = input();
  53. if(!isset($data['id']) || !$data['id']){
  54. $this->error('参数错误');
  55. }
  56. $VideoModel = new VideoModel();
  57. $id = $data['id'];
  58. $list = $VideoModel->where('id',$id)->where('is_deleted',1)->with(['file'])->find();
  59. $list['is_pay'] = 1;
  60. //判断是否已购买
  61. if($this->auth->isLogin()){
  62. $UserGoods = new UserGoods();
  63. $uid = $this->auth->id;
  64. $good = $UserGoods->where('user_id',$uid)->where('goods_type',1)->where('goods_id',$id)->find();
  65. if($good){
  66. $list['is_pay'] = 0;
  67. }
  68. }
  69. if(!$list){
  70. $this->error('教材不存在或已删除');
  71. }
  72. $this->success('操作成功',$list);
  73. }
  74. }