123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\Db;
- class Tvindex extends Api
- {
- protected $noNeedLogin = ['indexdata','video_list','videoinfo','zhuanti','tudingc','search','history'];
- protected $noNeedRight = '*';
- //首页
- public function indexdata(){
- //左上角 logo,名称,4个按钮
- $data['index_logo'] = localpath_to_netpath(config('site.index_logo'));
- $data['index_appname'] = config('site.index_appname');
- $data['index_tuiding_switch'] = config('site.index_tuiding_switch');
- $data['index_search_switch'] = config('site.index_search_switch');
- $data['index_history_switch'] = config('site.index_history_switch');
- $data['index_dinggou_switch'] = config('site.index_dinggou_switch');
- //右上角 三行
- $data['index_right_1'] = config('site.index_right_1');
- $data['index_right_2'] = config('site.index_right_2');
- $data['index_right_3'] = config('site.index_right_3');
- //固定五个
- $data['index_top_video_image'] = localpath_to_netpath(config('site.index_top_video_image'));
- $data['index_top_video'] = localpath_to_netpath(config('site.index_top_video'));
- $page_wenzhen = Db::name('page_wenzhen')->field('id,name,image,url')->where('status',1)->order('weigh asc')->select();
- $data['page_wenzhen'] = list_domain_image($page_wenzhen,['image']);
- //大分类+剧集
- $video_type = Db::name('video_type')->field('id,name,showtype')->where('status',1)->where('type','neq',3)->order('weigh asc, id desc')->select();
- $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();
- $video = list_domain_image($video, ['image']);
- //分布:1=左一右四,2=两行八个,3=一行四个,4=一行三个
- $more = [
- 'id' => 0,
- 'video_type_id' => 0,
- 'title' => '查看更多',
- 'image' => 'https://jiankang-1304634122.cos.ap-nanjing.myqcloud.com/uploads/20240529/37bd30cf2b80186b51f3bbfedb10a7d5.png',
- 'is_pay'=> 0,
- ];
- foreach($video_type as $key => $type){
- $type['child'] = [];
- //循环放入child
- $child = [];
- foreach($video as $k => $v){
- if($type['id'] == $v['video_type_id']){
- $child[] = $v;
- }
- }
- //查看更多
- if($type['showtype'] == 1){
- if(count($child) > 5){
- $child = array_chunk($child,4)[0];
- $child[] = $more;
- }
- }
- if($type['showtype'] == 2){
- if(count($child) > 8){
- $child = array_chunk($child,7)[0];
- $child[] = $more;
- }
- }
- if($type['showtype'] == 3){
- if(count($child) > 4){
- $child = array_chunk($child,3)[0];
- $child[] = $more;
- }
- }
- if($type['showtype'] == 4){
- if(count($child) > 3){
- $child = array_chunk($child,2)[0];
- $child[] = $more;
- }
- }
- $type['child'] = $child;
- $video_type[$key] = $type;
- }
- $data['video_type'] = $video_type;
- //精彩专题
- $data['buttom_name'] = '精彩专题';
- $buttom_list = Db::name('video_type')->field('id,name,image')->where('status',1)->where('type',3)->order('weigh asc,id desc')->limit(3)->select();
- $data['buttom_list'] = list_domain_image($buttom_list,['image']);
- $this->success('首页',$data);
- }
- //更多页
- //视频列表
- public function video_list() {
- $type_id = input('type_id', 0, 'intval'); //分类id
- if (!$type_id) {
- $this->error('您的网络开小差了~');
- }
- $video_type = Db::name('video_type')->where('id',$type_id)->value('name');
- $list = Db::name('video')->field('id, title, image, is_pay')->where(['video_type_id' => $type_id, 'status' => 1, 'inject_status' => 2])
- ->order('weigh asc, id desc')->select();
- $list = list_domain_image($list, ['image']);
- $result = [
- 'typename' => $video_type,
- 'videolist' => $list,
- ];
- $this->success('视频更多', $result);
- }
- //视频详情
- public function videoinfo() {
- $id = input('id', 0, 'intval'); //视频id
- if (!$id) {
- $this->error('您的网络开小差了');
- }
- $info = Db::name('video')->field('id,video_type_id, title, image, desc, is_pay, status, inject_status, seriesid, programid, movieid')
- ->where(['id' => $id])->find();
- if (!$info) {
- $this->error('数据不存在');
- }
- if ($info['status'] != 1) {
- $this->error('视频丢失');
- }
- if ($info['inject_status'] != 2) {
- $this->error('视频丢失');
- }
- $info['image'] = one_domain_image($info['image']);
- $info['is_collection'] = Db::name('video_collection')->where(['user_id' => $this->auth->id, 'video_id' => $id])->count('id');
- $info['is_good'] = Db::name('video_good')->where(['user_id' => $this->auth->id, 'video_id' => $id])->count('id');
- //剧集列表
- $juji = [];
- $video_list = Db::name('video')->field('id, title, image, is_pay')->where(['video_type_id' => $info['video_type_id'], 'status' => 1, 'inject_status' => 2])
- ->order('weigh asc, id desc')->select();
- if(!empty($video_list)){
- $video_list = list_domain_image($video_list, ['image']);
- $video_list = array_chunk($video_list,10);
- foreach($video_list as $page => $ten){
- $juji[] = [
- 'name'=> ($page*10 + 1) .'-'. ($page*10 + 10),
- 'list'=>$ten,
- ];
- }
- }
- //猜你喜欢
- $guess_list = Db::name('video')->field('id, title, image, is_pay')->where(['status' => 1, 'inject_status' => 2])
- ->orderRaw('rand()')->limit(4)->select();
- $guess_list = list_domain_image($guess_list, ['image']);
- //记录浏览历史
- if($this->auth->isLogin()){
- $view_map = [
- 'user_id' => $this->auth->id,
- 'video_id' => $id,
- ];
- $check_view = Db::name('video_view')->where($view_map)->find();
- if($check_view){
- Db::name('video_view')->where($view_map)->update(['updatetime'=>time()]);
- }else{
- $view_map['createtime'] = time();
- $view_map['updatetime'] = time();
- Db::name('video_view')->insertGetId($view_map);
- }
- }
- //
- $result = [
- 'video_info' => $info,
- 'juji_list' => $juji,
- 'guess_list' => $guess_list,
- ];
- $this->success('详情', $result);
- }
- //专题页
- public function zhuanti(){
- $type_id = input('type_id', 0, 'intval'); //分类id
- if (!$type_id) {
- $this->error('您的网络开小差了~');
- }
- $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();
- $list = list_domain_image($list, ['image']);
- $this->success('视频', $list);
- }
- //退订服务
- public function tudingc()
- {
- $data = config('site.text_tuiding');
- $this->success('', $data);
- }
- //搜索页
- public function search(){
- $keyword = input('keyword','');
- //热门推荐4个
- if(empty($keyword)){
- $list = Db::name('video')->field('id, title, image, is_pay')->where(['status' => 1, 'inject_status' => 2])
- ->orderRaw('rand()')->limit(12)->select();
- $list = list_domain_image($list, ['image']);
- }else{
- $list = Db::name('video')->field('id, title, image, is_pay')->where(['status' => 1, 'inject_status' => 2])->where('search_title','LIKE','%'.$keyword.'%')->order('is_pay asc,weigh asc,id desc')->select();
- $list = list_domain_image($list, ['image']);
- }
- $this->success('视频', $list);
- }
- //浏览历史
- public function history(){
- if($this->auth->isLogin()){
- $video_view = Db::name('video_view')->where('user_id',$this->auth->id)->order('updatetime desc')->group('video_id')->column('video_id,updatetime');
- if(!empty($video_view)){
- $video_ids = implode(',',array_keys($video_view));
- $list = Db::name('video')->field('id, title, image, is_pay')->where(['status' => 1, 'inject_status' => 2])->where('id','IN',$video_ids)->orderRaw('field(id,'.$video_ids.')')->page($this->page,$this->pagenum)->select();
- $list = list_domain_image($list, ['image']);
- foreach($list as $key => $val){
- $list[$key]['history_time'] = $video_view[$val['id']];
- }
- }else{
- $list = [];
- }
- }else{
- $list = [];
- }
- $this->success('视频', $list);
- }
- }
|