<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request as Req;
use Request;

/**
 * 级联关系
 */
class CascadeController extends Controller {
	/**
     * 获取级联关系
     *
     * @access public
     * @param mixed $req 传入参数 rank等级 id当前ID gameType球类型
	 * @return array JsonString
	 */
	public function index(Req $req) {
        $code = 200;
        $msg = '失败';
        $data = '';
        $rank = isset($req->rank) ? $req->rank : 0;
        $id = isset($req->id) ? $req->id : 0;
        $gameType = isset($req->gameType) ? $req->gameType : 0;
		// 赛事种类获取
        $gameTypeModel = new \App\Models\StGameType();
        $getGameTypeSelect = ['id', 'game_name', 'game_code'];
        $getGameTypeWhere['status'] = 1;
        if (empty($gameType)) {
            $msg = '运动类型为空';
            return ['code' => $code, 'msg' => $msg, 'data' => ''];
        }
        $getGameTypeWhere['id'] = $gameType;
        $getGameType = $gameTypeModel -> getGameType($getGameTypeSelect, $getGameTypeWhere);
        // 获取级联数据
        $cascadeModel = new \App\Models\Cascade();
        /*$a = $cascadeModel -> getLeague('*', '', $getGameType[0]['game_code']);
        echo json_encode($a);die;*/
        $result = [];
        switch ($rank) {
            // 级联关系[0洲，1国家，2联赛，3球队]
            case 0:
                $getResultSelect = ['id', 'title', 'source'];
                $result = $cascadeModel -> allArea($getResultSelect);
                break;
            case 1:
                $getResultSelect = ['country_id', 'name_chinese', 'name_english', 'country_ico', 'country_area', 'id', 'source'];
                $getResultWhere['country_area'] = $id;
                $result = $cascadeModel -> getCountryByArea($getResultSelect, $getResultWhere, $getGameType[0]['game_code'], $gameType);
                break;
            case 2:
                $getResultSelect = ['name_chinese', 'name_english', 'kind', 'league_pic', 'country_id', 'area_id', 'id', 'lg_id'];
                $getResultWhere['country_id'] = $id;
                $result = $cascadeModel -> league($getResultSelect, $getResultWhere, $getGameType[0]['game_code']);
                break;
            case 3:
                $getResultSelect = ['id', 'home_team', 'guest_team', 'lg_id'];
                $getResultWhere['lg_id'] = $id;
                $result['competition'] = $cascadeModel -> getCompetition($getResultSelect, $getResultWhere, $getGameType[0]['game_code']);
                break;
        }
        $msg = 'success';
        return ['code' => $code, 'msg' => $msg, 'data' => $result];
	}
}

?>