<?php
/*
 本代码由 焕岱科技 创建
 技术支持 WX：15285007200
 严禁反编译、逆向等任何形式的侵权行为，违者将追究法律责任
*/

namespace app\api\controller\news;

use app\api\controller\Base;
use think\Db;
use app\common\model\bbfxshop\User;


class Video extends Base
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];
    
    public $model = null;
    public function _initialize(){
        parent::_initialize();
        $this->model = new \app\common\model\bbfxshop\News;
    }
    
    public function getCategory(){
        $params = $this->param();
        
        $where = array("uniacid"=>UNIACID,'type'=>2);
        
        $list = Db::name("bbfx_news_category")->where($where)->order('sort desc,id desc')->select();
        
        __success("操作成功",['list'=>$list]);
    }
    
    public function getList(){
        $params = $this->param(['category_id/d']);
        
        $where = array("uniacid"=>UNIACID,'status'=>1);
        
        if(!empty($params['category_id'])){
            $where['category_id'] = $params['category_id'];
        }
        
        $list = Db::name("bbfx_news_video")->where($where)->order('id desc')->select();
        
        foreach ($list as $key => &$val){
            $val['thumb'] = cdnurl($val['thumb']);
            $val['content'] = cdnurl($info['content']);
        }
        unset($val);
        
        __success("操作成功",['list'=>$list]);
    }
    
    public function detail(){
        $params = $this->param(['id/d']);
        $id = $this->param("id");
        
        $info = Db::name("bbfx_news_video")->where(['id'=>$params['id'],'status'=>1])->find();
        
        if(empty($info)){
            __error("视频不存在");
        }
        
        $info['thumb'] = cdnurl($info['thumb']);
        $video = cdnurl($info['content']);
        if($info['type'] == 2){
            $video = $info['link'];
        }
        
        if(empty($video)){
            __error("视频不存在");
        }
        $info['video'] = $video;
        __success("操作成功",['info'=>$info]);
    }
}