select($select) -> orderBy($orderBy) -> get(); return $result; } /** * 循环获取国家级联关系 * * @access public * @param mixed $select 查询参数 * @param mixed $where 查询条件 * @param mixed $gameType 球类型 * @param mixed $orderBy 排序字段 * @return array JsonString */ public function getCountry($select, $where, $gameType, $gameTypeId, $orderBy = 'country_order') { // 获取国家的数据 $result['country'] = DB :: table('st_country') -> select($select) -> where($where) -> orderBy($orderBy) -> get(); // 从洲直接获取联赛 $getLeagueSelect = ['name_chinese', 'name_english', 'kind', 'league_pic', 'country_id', 'area_id', 'id', 'lg_id']; $leagueByAreaWhere['area_id'] = $where['country_area']; $leagueByArea = $this -> getLeague($getLeagueSelect, $leagueByAreaWhere, $gameType); $getCompetitionSelect = ['id', 'home_team', 'guest_team', 'lg_id']; // 循环从国家取联赛、球队 $leagueByCountry = []; $competitionByCountry = []; foreach ($result['country'] as $key => $value) { // 获取联赛 $leagueByCountryWhere['country_id'] = $value -> country_id; $getLeagueByCountry = $this->getLeague($getLeagueSelect, $leagueByCountryWhere, $gameType); $leagueByCountry = array_merge($leagueByCountry, $getLeagueByCountry); // 获取球队 /*$leagueByCountryWhere['game_type_id'] = $gameTypeId; $getCompetitionByCountry = $this->getCompetitionByCountry($getLeagueSelect, $leagueByCountryWhere, $gameType); $competitionByCountry = array_merge_recursive($competitionByCountry, $getCompetitionByCountry);*/ } // 不同获取路径合并 并去重 $league = array_merge($leagueByCountry, $leagueByArea); $result['league'] = array_unique($league, SORT_REGULAR)['league']; // 从联赛获取球队 $competitionByLeague = []; foreach ($result['league'] as $key => $value) { $competitionByLeagueWhere['lg_id'] = $value -> lg_id; $getCompetitionByLeague = $this -> getCompetition($getCompetitionSelect, $competitionByLeagueWhere, $gameType); $competitionByLeague = array_merge_recursive($competitionByLeague, $getCompetitionByLeague); } foreach ($competitionByLeague['competition'] as $key => $value) { $result['competition'] = array_unique($value, SORT_REGULAR); } return $result; } /** * 循环获取联赛级联关系 * * @access public * @param mixed $select 查询参数 * @param mixed $where 查询条件 * @param mixed $gameType 球类型 * @return array JsonString */ public function league($select, $where, $gameType) { // 获取联赛 $getLeagueByCountry = $this->getLeague($select, $where, $gameType); $result['league'] = $getLeagueByCountry['league']; // 从联赛获取球队 $getCompetitionSelect = ['id', 'home_team', 'guest_team', 'lg_id']; $competitionByLeague = []; foreach ($result['league'] as $key => $value) { $competitionByLeagueWhere['lg_id'] = $value -> lg_id; $getCompetitionByLeague = $this -> getCompetition($getCompetitionSelect, $competitionByLeagueWhere, $gameType); $competitionByLeague = array_merge_recursive($competitionByLeague, $getCompetitionByLeague); } foreach ($competitionByLeague['competition'] as $key => $value) { $result['competition'] = array_unique($value, SORT_REGULAR); } return $result; } /** * 获取联赛 * * @access public * @param mixed $select 查询参数 * @param mixed $where 查询条件 * @param mixed $gameType 球类型 * @param mixed $orderBy 排序字段 * @return array JsonString */ public function getLeague($select, $where, $gameType, $orderBy = 'league_list') { $leagueTable = 'st_' . $gameType . '_league'; $result['league'] = DB :: table($leagueTable) -> select($select) -> where($where) -> orderBy($orderBy) -> get(); return $result; } /** * 获取球队 * * @access public * @param mixed $select 查询参数 * @param mixed $where 查询条件 * @param mixed $gameType 球类型 * @param mixed $orderBy 排序字段 * @return array JsonString */ public function getCompetition($select, $where, $gameType, $orderBy = 'id') { $competitionTable = 'st_' . $gameType . '_competition'; $result['competition'] = DB :: table($competitionTable) -> select($select) -> where($where) -> orderBy($orderBy) -> get(); return $result; } /** * 获取球队 * * @access public * @param mixed $select 查询参数 * @param mixed $where 查询条件 * @param mixed $gameType 球类型 * @param mixed $orderBy 排序字段 * @return array JsonString */ public function getCompetitionByCountry($select, $where, $gameType, $orderBy = 'id') { $competitionTable = 'st_' . $gameType . '_competition'; $result['competition'] = DB :: table('st_team') -> join($competitionTable, $competitionTable.'.team_id','=','st_team.id') -> select($select) -> where($where) -> orderBy($orderBy) -> get(); return $result; } }