| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- <?php
- namespace App\Models;
- use DB;
- /**
- * 获取级联关系 Model
- */
- class Cascade extends BaseModel
- {
- /**
- * 获取洲
- *
- * @access public
- * @param mixed $select 查询参数
- * @param mixed $orderBy 排序字段
- * @return array JsonString
- */
- public function getArea($select, $orderBy = 'id') {
- $result = [];
- $result['area'] = DB :: table('st_area')
- -> 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;
- }
- }
|