| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- <?php
- namespace App\Models;
- use DB;
- use PHPUnit\Runner\Filter\NameFilterIterator;
- /**
- * 获取级联关系 Model
- */
- class Cascade extends BaseModel
- {
- /**
- * 获取洲
- *
- * @access public
- * @param mixed $select 查询参数
- * @param mixed $orderBy 排序字段
- * @return array JsonString
- */
- public function allArea($select, $orderBy = 'id') {
- $result = DB :: table('st_area')
- -> select($select)
- -> orderBy($orderBy)
- -> get();
- return $result;
- }
- /**
- * 获取国家
- *
- * @access public
- * @param mixed $select 查询参数
- * @param mixed $where 查询条件
- * @param mixed $orderBy 排序字段
- * @return array JsonString
- */
- public function getCountry($select, $where, $orderBy = 'country_order') {
- $result = [];
- if (empty($where)) {
- $result = DB :: table('st_country')
- -> select($select)
- -> orderBy($orderBy)
- -> get();
- } else {
- $result = DB :: table('st_country')
- -> 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 getLeague($select, $where, $gameType, $orderBy = 'league_list') {
- $leagueTable = 'st_' . $gameType . '_league';
- $result = [];
- if (empty($where)) {
- $result = DB :: table($leagueTable)
- -> select($select)
- -> orderBy($orderBy)
- -> get();
- } else {
- $result = 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 = [];
- if (empty($where)) {
- $result = DB :: table($competitionTable)
- -> select($select)
- -> orderBy($orderBy)
- -> get();
- } else {
- $result = DB :: table($competitionTable)
- -> select($select)
- -> where($where)
- -> orderBy($orderBy)
- -> get();
- }
- return $result;
- }
- /**
- * 获取国家球队
- *
- * @access public
- * @param mixed $select 查询参数
- * @param mixed $where 查询条件
- * @param mixed $orderBy 排序字段
- * @return array JsonString
- */
- public function getCountryCompetition($select, $where, $orderBy = 'id') {
- $result = [];
- if (empty($where)) {
- $result = DB :: table('st_team')
- -> select($select)
- -> orderBy($orderBy)
- -> get();
- } else {
- $result = DB :: table('st_team')
- -> select($select)
- -> where($where)
- -> orderBy($orderBy)
- -> get();
- }
- return $result;
- }
- /**
- * 获取国家级联关系
- *
- * @access public
- * @param mixed $select 查询参数
- * @param mixed $where 查询条件
- * @param mixed $gameType 球类型
- * @param mixed $gameTypeId 运动类型Id
- * @return array JsonString
- */
- public function getCountryByArea($select, $where, $gameType, $gameTypeId) {
- // 获取国家的数据
- $result['country'] = $this -> getCountry($select, $where);
- // 循环获取所有国家ID集
- $countryId = [];
- foreach ($result['country'] as $key => $value) {
- $countryId[] = $value->country_id;
- }
- // 获取所有联赛数据
- $getLeagueSelect = ['name_chinese', 'name_english', 'kind', 'league_pic', 'country_id', 'area_id', 'id', 'lg_id'];
- $getAllLeague = $this -> getLeague($getLeagueSelect, '', $gameType);
- // 获取所有联赛球队
- $getCompetitionSelect = ['id', 'home_team', 'guest_team', 'lg_id'];
- $getAllCompetition = $this -> getCompetition($getCompetitionSelect, '', $gameType);
- // 获取所有国家球队
- $getCtyCtnSelect = ['id', 'team_id', 'country_id', 'game_type_id', 'team_name_cn', 'team_name_en'];
- $getCtyCtnWhere['game_type_id'] = $gameTypeId;
- $getCtyCtn = $this -> getCountryCompetition($getCtyCtnSelect, $getCtyCtnWhere);
- // 循环获取联赛
- $getLeague = [];
- foreach ($getAllLeague as $key => $value) {
- // 从洲直接获取联赛
- if ($value->area_id == $where['country_area']) {
- $getLeague[] = $value;
- // 从国家获取联赛
- } elseif (in_array($value->country_id, $countryId)) {
- $getLeague[] = $value;
- }
- }
- // 数组去重
- $result['league'] = array_unique($getLeague, SORT_REGULAR);
- // 循环获取所有联赛ID集
- $leagueId = [];
- foreach ($result['league'] as $key => $value) {
- $leagueId[] = $value->lg_id;
- }
- // 循环获取联赛球队
- $getCompetition = [];
- foreach ($getAllCompetition as $key => $value) {
- if (in_array($value->lg_id, $leagueId)) {
- $getCompetition[] = $value;
- }
- }
- // 循环获取国家球队
- foreach ($getCtyCtn as $key => $value) {
- if (in_array($value->country_id, $countryId)) {
- $getCompetition[] = $value;
- }
- }
- // 数组去重
- $result['competition'] = array_unique($getCompetition, SORT_REGULAR);
- return $result;
- }
- /**
- * 获取联赛级联关系
- *
- * @access public
- * @param mixed $select 查询参数
- * @param mixed $where 查询条件
- * @param mixed $gameType 球类型
- * @return array JsonString
- */
- public function league($select, $where, $gameType) {
- // 获取联赛数据
- $result['league'] = $this -> getLeague($select, $where, $gameType);
- // 循环获取所有联赛ID集
- $leagueId = [];
- foreach ($result['league'] as $key => $value) {
- $leagueId[] = $value->lg_id;
- }
- // 获取所有联赛球队
- $getCompetitionSelect = ['id', 'home_team', 'guest_team', 'lg_id'];
- $getAllCompetition = $this -> getCompetition($getCompetitionSelect, '', $gameType);
- // 循环获取联赛球队
- $getCompetition = [];
- foreach ($getAllCompetition as $key => $value) {
- if (in_array($value->lg_id, $leagueId)) {
- $getCompetition[] = $value;
- }
- }
- // 数组去重
- $result['competition'] = array_unique($getCompetition, SORT_REGULAR);
- return $result;
- }
- }
|