<?php

namespace app\admin\controller;

use app\admin\logic\VideoLogic;
use app\BaseController;
use think\exception\ValidateException;
use think\facade\Config;
use think\facade\Validate;

//视频
class Video extends BaseController
{

    //获取视频列表
    public function list()
    {
        $param = $this->request->only([
            'page' => 1,
            'size' => 10,
            'status' => '',
            'video_sn' => '',
            'video_name' => '',
            'video_url' => '',
        ], 'post');

        return VideoLogic::list($param);
    }

    //添加视频
    public function add()
    {

        $param = $this->request->only([
            'video_name',
            'video_url',
            'video_img',
            'weight' => '',
            'remark' => '',
        ], 'post');

        $val = Validate::rule(Config::get('validate_rules.videoAdd'));

        if (!$val->check($param)) throw new ValidateException($val->getError());
        return VideoLogic::add($param);
    }

    //读取视频详情
    public function read()
    {
        $id = $this->request->post('id/d', 0);
        return VideoLogic::read($id);
    }

    //编辑视频
    public function edit()
    {
        $param = $this->request->only([
            'id',
            'video_name',
            'video_url',
            'video_img',
            'weight' => '',
            'remark' => '',
        ], 'post');

        $val = Validate::rule(Config::get('validate_rules.videoEdit'));

        if (!$val->check($param)) throw new ValidateException($val->getError());
        return VideoLogic::edit($param);
    }

    //视频启禁用
    public function change()
    {
        $param = $this->request->only(['id', 'status',], 'post');

        $val = Validate::rule(Config::get('validate_rules.status'));

        if (!$val->check($param)) throw new ValidateException($val->getError());
        return VideoLogic::change($param);
    }

    //删除视频
    public function delete()
    {
        $id = $this->request->post('id/d', 0);
        return VideoLogic::delete($id);
    }

}