<?php
/**
 * Created by PhpStorm.
 * User: Jonlin
 * Date: 2019/3/28
 * Time: 11:34
 */
namespace App\Models;
use Illuminate\Support\Facades\DB;
class BaseLeague extends BaseModel {
    protected $table = "st_bq_league";

    function getinfo($list = 10, $page, $where = '')
    {
//        $source = \App\Models\Setinfo::where('id','1000')->first();
//        if($source->infocontent != '混合数据'){
//            $where[] = array('st_bq_local_league.source', '=', $source->infocontent);
//        }
        if (is_array ($where) && count ($where) > 0){
            $data = $this
                //->join('st_bq_local_league','st_bq_league.id','=','st_bq_local_league.lg_id')
                ->select('st_bq_league.lg_id','st_bq_league.name_chinese','st_bq_league.area_id','st_bq_league.country_id','st_bq_league.utime')
                ->orderby('st_bq_league.utime','desc')
                ->where($where)
                ->paginate ($list);
        }else{
            $data = $this
                //->join('st_bq_local_league','st_bq_league.id','=','st_bq_local_league.lg_id')
                ->select('st_bq_league.lg_id','st_bq_league.name_chinese','st_bq_league.area_id','st_bq_league.country_id','st_bq_league.utime')
                ->orderby('st_bq_league.utime','desc')
                ->paginate ($list);
        }
        if (!$data) {
            return -5040000102; //无相关信息
        }
        //地区
        $area = \App\Models\StAreaCountry::where('pid','0')->get();
//        $str = '';
//        for($a=0;$a<count($area);$a++){
//            $str .= '<option value="'.$area[$a]->id.'">'.$area[$a]->name.'</option>';
//        }
        //国家
        $country = \App\Models\StAreaCountry::where('pid','<>','0')->get();

        for($i=0;$i<count($data);$i++){
            $data[$i]->id = $data[$i]->lg_id;

            if($data[$i]->status == '-1'){
                $data[$i]->league_status = '未启用';
            }
            if($data[$i]->status == '1'){
                $data[$i]->league_status = '启用';
            }

//            $data[$i]->area = '<select name="area" id="area" lay-filter="sect"><option value="-1"></option>'.$str.'</select>';
//            $data[$i]->country = '<select name="country" id="country"></select>';
            $str = 0;
            $str1 = 0;
            if($data[$i]->area_id == '0'){
                $data[$i]->area = '无';
            }else{
                for($b=0;$b<count($area);$b++){
                    if($area[$b]->id == $data[$i]->area_id){
                        $str = 1;
                        $data[$i]->area = $area[$b]->name;
                    }
                }
                if($str == 0){$data[$i]->area = '无';}
            }
            if($data[$i]->country_id == 0){
                $data[$i]->country = '无';
            }else{
                for($c=0;$c<count($country);$c++){
                    if($country[$c]->id == $data[$i]->country_id){
                        $str1 = 1;
                        $data[$i]->country = $country[$c]->name;
                    }
                }
                if($str1 == 0){$data[$i]->country = '无';}
            }

        }

        return $data->toArray();
    }

    //所有赛事
    function allleague()
    {
        $data = $this->select('lg_id','name_chinese')->get();
        if (!$data) {
            return -5040000102; //无相关信息
        }
        return $data->toArray();
    }


}