Tvindex.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. class Tvindex extends Api
  6. {
  7. protected $noNeedLogin = '*';
  8. protected $noNeedRight = '*';
  9. //首页
  10. public function indexdata(){
  11. //左上角 logo,名称,4个按钮
  12. $data['index_logo'] = localpath_to_netpath(config('site.index_logo'));
  13. $data['index_appname'] = config('site.index_appname');
  14. $data['index_tuiding_switch'] = config('site.index_tuiding_switch');
  15. $data['index_search_switch'] = config('site.index_search_switch');
  16. $data['index_history_switch'] = config('site.index_history_switch');
  17. $data['index_dinggou_switch'] = config('site.index_dinggou_switch');
  18. //右上角 三行
  19. $data['index_right_1'] = config('site.index_right_1');
  20. $data['index_right_2'] = config('site.index_right_2');
  21. $data['index_right_3'] = config('site.index_right_3');
  22. //固定五个
  23. $data['index_top_video_image'] = localpath_to_netpath(config('site.index_top_video_image'));
  24. $data['index_top_video'] = localpath_to_netpath(config('site.index_top_video'));
  25. $page_wenzhen = Db::name('page_wenzhen')->field('id,name,image,url')->where('status',1)->order('weigh asc')->select();
  26. $data['page_wenzhen'] = list_domain_image($page_wenzhen,['image']);
  27. //大分类+剧集
  28. $video_type = Db::name('video_type')->field('id,name,showtype')->where('status',1)->where('type','neq',3)->order('weigh asc, id desc')->select();
  29. $video = Db::name('video')->field('id, video_type_id, title, image, is_pay')->where(['status' => 1, 'inject_status' => 2])->order('weigh asc, id desc')->select();
  30. $video = list_domain_image($video, ['image']);
  31. //分布:1=左一右四,2=两行八个,3=一行四个,4=一行三个
  32. $more = [
  33. 'id' => 0,
  34. 'video_type_id' => 0,
  35. 'title' => '查看更多',
  36. 'image' => 'https://jiankang-1304634122.cos.ap-nanjing.myqcloud.com/uploads/20240529/37bd30cf2b80186b51f3bbfedb10a7d5.png',
  37. 'is_pay'=> 0,
  38. ];
  39. foreach($video_type as $key => $type){
  40. $type['child'] = [];
  41. //循环放入child
  42. $child = [];
  43. foreach($video as $k => $v){
  44. if($type['id'] == $v['video_type_id']){
  45. $child[] = $v;
  46. }
  47. }
  48. //查看更多
  49. if($type['showtype'] == 1){
  50. if(count($child) > 5){
  51. $child = array_chunk($child,4)[0];
  52. $child[] = $more;
  53. }
  54. }
  55. if($type['showtype'] == 2){
  56. if(count($child) > 8){
  57. $child = array_chunk($child,7)[0];
  58. $child[] = $more;
  59. }
  60. }
  61. if($type['showtype'] == 3){
  62. if(count($child) > 4){
  63. $child = array_chunk($child,3)[0];
  64. $child[] = $more;
  65. }
  66. }
  67. if($type['showtype'] == 4){
  68. if(count($child) > 3){
  69. $child = array_chunk($child,2)[0];
  70. $child[] = $more;
  71. }
  72. }
  73. $type['child'] = $child;
  74. $video_type[$key] = $type;
  75. }
  76. $data['video_type'] = $video_type;
  77. //精彩专题
  78. $data['buttom_name'] = '精彩专题';
  79. $buttom_list = Db::name('video_type')->field('id,name,image')->where('status',1)->where('type',3)->order('weigh asc,id desc')->limit(3)->select();
  80. $data['buttom_list'] = list_domain_image($buttom_list,['image']);
  81. $this->success('首页',$data);
  82. }
  83. //更多页
  84. //视频列表
  85. public function video_list() {
  86. $type_id = input('type_id', 0, 'intval'); //分类id
  87. if (!$type_id) {
  88. $this->error('您的网络开小差了~');
  89. }
  90. $video_type = Db::name('video_type')->where('id',$type_id)->value('name');
  91. $list = Db::name('video')->field('id, title, image, is_pay')->where(['video_type_id' => $type_id, 'status' => 1, 'inject_status' => 2])
  92. ->order('weigh asc, id desc')->select();
  93. $list = list_domain_image($list, ['image']);
  94. $result = [
  95. 'typename' => $video_type,
  96. 'videolist' => $list,
  97. ];
  98. $this->success('视频更多', $result);
  99. }
  100. //视频详情
  101. public function videoinfo() {
  102. $id = input('id', 0, 'intval'); //视频id
  103. if (!$id) {
  104. $this->error('您的网络开小差了');
  105. }
  106. $info = Db::name('video')->field('id,video_type_id, title, image, desc, is_pay, status, inject_status, seriesid, programid, movieid')
  107. ->where(['id' => $id])->find();
  108. if (!$info) {
  109. $this->error('数据不存在');
  110. }
  111. if ($info['status'] != 1) {
  112. $this->error('视频丢失');
  113. }
  114. if ($info['inject_status'] != 2) {
  115. $this->error('视频丢失');
  116. }
  117. $info['image'] = one_domain_image($info['image']);
  118. $info['is_collection'] = Db::name('video_collection')->where(['user_id' => $this->auth->id, 'video_id' => $id])->count('id');
  119. $info['is_good'] = Db::name('video_good')->where(['user_id' => $this->auth->id, 'video_id' => $id])->count('id');
  120. //剧集列表
  121. $juji = [];
  122. $video_list = Db::name('video')->field('id, title, image, is_pay')->where(['video_type_id' => $info['video_type_id'], 'status' => 1, 'inject_status' => 2])
  123. ->order('weigh asc, id desc')->select();
  124. if(!empty($video_list)){
  125. $video_list = list_domain_image($video_list, ['image']);
  126. $video_list = array_chunk($video_list,10);
  127. foreach($video_list as $page => $ten){
  128. $juji[] = [
  129. 'name'=> ($page*10 + 1) .'-'. ($page*10 + 10),
  130. 'list'=>$ten,
  131. ];
  132. }
  133. }
  134. //猜你喜欢
  135. $guess_list = Db::name('video')->field('id, title, image, is_pay')->where(['status' => 1, 'inject_status' => 2])
  136. ->orderRaw('rand()')->limit(4)->select();
  137. $guess_list = list_domain_image($guess_list, ['image']);
  138. //
  139. $result = [
  140. 'video_info' => $info,
  141. 'juji_list' => $juji,
  142. 'guess_list' => $guess_list,
  143. ];
  144. $this->success('详情', $result);
  145. }
  146. //专题页
  147. public function zhuanti(){
  148. $type_id = input('type_id', 0, 'intval'); //分类id
  149. if (!$type_id) {
  150. $this->error('您的网络开小差了~');
  151. }
  152. $list = Db::name('video')->field('id, title, image, is_pay, status, inject_status, seriesid, programid, movieid')->where(['video_type_id' => $type_id, 'status' => 1, 'inject_status' => 2])->order('weigh asc, id desc')->limit(5)->select();
  153. $list = list_domain_image($list, ['image']);
  154. $this->success('视频', $list);
  155. }
  156. }