<?php
/**
 * Created by PhpStorm.
 * User: Gold
 * Date: 2024/1/15
 * Time: 17:45
 */

namespace app\api\controller;

use app\admin\model\video\Video as VideoModel; //视频
use app\admin\model\video\VideoFile; //视频
use app\common\controller\Api;

class Video extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 视频列表
     *
     * api/video/getVideoList
     */
    public function getVideoList(){
        $data = input();
        $where = [];
        if(!isset($data['page']) || $data['page'] == '' || $data['page'] == null){
            $page = 1;
        }else{
            $page = $data['page'];
        }
        if(!isset($data['limit']) || $data['limit'] == '' || $data['limit'] == null){
            $limit = 20;
        }else{
            $limit = $data['limit'];
        }
        if ( isset($data['keywords']) && $data['keywords'] != '' && $data['keywords'] != null){
            $where['title'] = ['like','%'.$data['keywords'].'%'];
        }
        $VideoModel = new VideoModel();
        $list = $VideoModel->where('is_deleted',1)->where($where)->order('sort desc,id desc')->paginate([
            'list_rows'=> $limit,
            'page' => $page,
        ]);
        $this->success('操作成功',$list);
    }


    /**
     * 视频详情
     *
     * api/video/getVideoInfo
     */
    public function getVideoInfo(){
        $data = input();
        if(!isset($data['id']) || !$data['id']){
            $this->error('参数错误');
        }
        $VideoModel = new VideoModel();
        $id = $data['id'];
        $list = $VideoModel->where('id',$id)->where('is_deleted',1)->with(['file'])->find();
        if(!$list){
            $this->error('教材不存在或已删除');
        }
        $this->success('操作成功',$list);
    }


}
