Index.php 8.5 KB
<?php

namespace app\index\controller;

use app\api\controller\Message;
use app\common\controller\Frontend;
use think\Db;

class Index extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';

    public function index()
    {
        return $this->view->fetch();
    }

    //会有到期提醒 添加信息记录
    public function mess()
    {
        $data = Db::name('user')
            ->field('id,identity,audit,expirationtime')
            ->where('identity','neq',1)
            ->where('audit',1)
            ->select();
        foreach ($data as &$v){
            if(time() > $v['expirationtime']){
                $message = new Message();
                $message->add($v['id'],'会员到期');
            }else{
                if(time()+86400 >= $v['expirationtime']){
                    $message = new Message();
                    $message->add($v['id'],'会员1天后到期');
                }else{
                    if(time()+2*86400 >= $v['expirationtime']){
                        $message = new Message();
                        $message->add($v['id'],'会员2天后到期');
                    }else{
                        if (time()+3*86400 >= $v['expirationtime']){
                            $message = new Message();
                            $message->add($v['id'],'会员3天后到期');
                        }
                    }
                }
            }
        }
    }


    //文件详情
    public function detail()
    {
        $qiniu = get_addon_config('qiniu')['cdnurl'];
        $user_id = $this->request->param('user_id');
        $file_id = $this->request->param('file_id');

        $data = Db::name('savemes')
            ->where('id',$file_id)
            ->find();
        if($data['type'] == 2){
            $data['video'] = '';
            $data['video_image'] = '';
            $data['content'] = '';
            $data['images'] = $qiniu.$data['images'];
        }elseif ($data['type'] == 3){
            $data['images'] = '';
            $data['content'] = '';
            $data['video'] = $qiniu.$data['video'];
            // 获取视频第一帧图片
            $video_info = json_decode(file_get_contents($data['video'] . '?avinfo'), true);
            $data['video_image'] = $this->get_video_first_image($data['video'], $video_info);


            $data_video = Db::name('open')->where('id',1)->find();
            $data['switch'] = $data_video['switch'];
        }elseif ($data['type'] == 1){
            $data['images'] = '';
            $data['video'] = '';
            $data['video_image'] = '';
        }

        $text = Db::name('official')->where('id',1)->find();
        $data['introduce'] = $text['introduce'];
        $this->assign('data',$data);
        return $this->fetch();
    }

    //文件夹详情
    public function filedetail()
    {
        $qiniu = get_addon_config('qiniu')['cdnurl'];
        $user_id = $this->request->param('user_id');
        $file_id = $this->request->param('file_id');

        //文件夹
        $folder = Db::name('folder')
            ->where('pid',$file_id)
            ->where('is_up',1)
            ->select();

        foreach ($folder as &$v){
            $v['createtime'] = date('Y-m-d',$v['createtime']);
        }
        $times = array_values(array_unique(array_column($folder,'createtime')));
        //将数据放到对应的时间分段
        $arrs = [];
        foreach ($times as $t_k=> $t_v){
            $arrs[$t_k]['times'] = $t_v;
            $k = 0;
            foreach ($folder as $value){
                $k+=0;
                if($t_v == $value['createtime']){
                    $arrs[$t_k]['info'][$k] = $value;
                    $k++;
                }
            }
        }
        $data['folder'] = $arrs;


        //笔记
        $note['folder_id'] = ['eq',$file_id];
        $note['is_up'] = ['eq',1];
        $z_tiao['a.folder_id'] = ['eq',$file_id];
        $z_tiao['b.is_up'] = ['eq',1];
        $note = $this->myfile(1,$note);
        $zhuan_note = $this->zhuan(1,$z_tiao);
        $gong = $this->gong(1,$note,$zhuan_note);
        $data['note'] = $this->sundry($gong);

        //图片
        $pic['folder_id'] = ['eq',$file_id];
        $pic_tiao['a.folder_id'] = ['eq',$file_id];
        $pic = $this->myfile(2,$pic);
        $zhuan_pic = $this->zhuan(2,$pic_tiao);
        $gong1 = $this->gong(2,$pic,$zhuan_pic);
        $data['pic'] = $this->sundry($gong1);

        //视频
        $video['folder_id'] = ['eq',$file_id];
        $video_tiao['a.folder_id'] = ['eq',$file_id];
        $video = $this->myfile(3,$video);
        $zhuan_video = $this->zhuan(3,$video_tiao);
        $gong2 = $this->gong(3,$video,$zhuan_video);
        $data['video'] = $this->sundry($gong2);


        $text = Db::name('official')->where('id',1)->find();
        $data['introduce'] = $text['introduce'];
        $this->assign('data',$data);
        return $this->fetch();
    }

    public function get_video_first_image($video_url,$video_info){
        if(empty($video_info['streams'][0]['width'])) {
            $width = $video_info['streams'][1]['width'];
            $height = $video_info['streams'][1]['height'];
        } else {
            $width = $video_info['streams'][0]['width'];
            $height = $video_info['streams'][0]['height'];
        }
        return $video_url.'?vframe/jpg/offset/1/w/'.$width.'/h/'.$height;
    }




    //通过传入类型获取我自己的不同文件
    public function myfile($type,$where){
        $data = Db::name('savemes')
            ->where($where)
            ->where('type',$type)
            ->field('id,user_id,type,name,share_url,images,video,content,is_open,is_up,createtime')
            ->order('createtime desc')
            ->select();
        return $data;
    }
    //通过传入类型获取转存的不同文件
    public function zhuan($type,$tiao){
        $rotor = Db::name('rotor')
            ->alias('a')
            ->join('savemes b','a.savemes_id = b.id')
            ->field('a.id,a.user_id as unloading_user_id,a.savemes_id,a.folder_id,b.user_id,b.share_url,b.name,b.type,b.images,b.video,b.content,b.is_open,b.is_up,a.createtime')
            ->where('b.type',$type)
            ->where($tiao)
            ->order('a.createtime desc')
            ->select();
        return $rotor;
    }

    //各种类型的文件  转存以及自己的文件
    public function gong($type,$arr1,$arr2){
        $qiniu = get_addon_config('qiniu')['cdnurl'];
        if(!empty($arr2)){
            foreach ($arr2 as &$v_1){
                $v_1['is_zhuan'] = 1;
                $v_1['is_real'] = 2;
            }
            $arr = array_merge($arr1,$arr2);
        }else{
            $arr = $arr1;
        }

        //笔记类型
        if($type == 1){
            foreach ($arr as &$v){
                $v['nowtime'] = date('Y-m-d',$v['createtime']);
                $v['createtime'] = date('m-d',$v['createtime']);
                $v['images'] = '';
                $v['video'] = '';
                $v['video_image'] = '';
            }
        } elseif ($type == 2){
            //图片类型
            foreach ($arr as &$v){
                $v['nowtime'] = date('Y-m-d',$v['createtime']);
                $v['createtime'] = date('m-d',$v['createtime']);
                $v['images'] = $qiniu.$v['images'];
                $v['video'] = '';
                $v['video_image'] = '';
                $v['content'] = '';
            }
        }elseif ($type == 3){
            //视频类型
            foreach ($arr as &$v){
                $v['nowtime'] = date('Y-m-d',$v['createtime']);
                $v['createtime'] = date('m-d',$v['createtime']);
                $v['video'] = $qiniu.$v['video'];
                // 获取视频第一帧图片
                $video_info = json_decode(file_get_contents($v['video'] . '?avinfo'), true);
                $v['video_image'] = $this->get_video_first_image($v['video'], $video_info);
                $v['images'] = '';
                $v['content'] = '';
            }
        }
        return $arr;
    }


    //合并完数据按时间分段
    public function sundry($arr){
        $times = array_values(array_unique(array_column($arr,'createtime')));
        //将数据放到对应的时间分段
        $arrs = [];
        foreach ($times as $t_k=> $t_v){
            $arrs[$t_k]['times'] = $t_v;
            $k = 0;
            foreach ($arr as $value){
                $k+=0;
                if($t_v == $value['createtime']){
                    $arrs[$t_k]['info'][$k] = $value;
                    $k++;
                }
            }
        }
        return $arrs;

    }
}