| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025 |
- <?php
- namespace App\Sports\Controller;
- use BaseController\Controller;
- use Biz\Match\GetmatchData;
- use Biz\Match\GetOddsData;
- /**
- * Class RollingData
- * @package App\Sports\Controller
- * User: tank
- * Date: 2019/3/22
- */
- class MatchList extends Controller {
- private $getTypeData;
- public function init() {
- $this->getTypeData = new GetmatchData();
- $this->getOddsData = new GetOddsData();
- $this->commonFunction = C()->get('commonFunction');
- }
- /*
- *首页条件筛选(足球参赛表)
- */
- private function zq_participate (){
- $data['type'] = '足球';
- $data['game_code'] = 'zq';
- //查询今日赛事
- $data['info'][0]['name'] = '今日赛事';
- $data['info'][0]['code'] = 'today';
- $data['info'][0]['count'] = lm('st_zq_competition','Sports')
- ->join('st_zq_league','st_zq_league.lg_id','st_zq_competition.lg_id')
- ->where($this->commonFunction->getState('StToday'))
- ->where('st_zq_competition.source',$this->source['source'])
- ->where('st_zq_competition.home_team','<>',null)
- ->where('st_zq_competition.guest_team','<>',null)
- ->distinct('st_zq_competition.match_id')
- ->count('*');
- //查询明日赛事
- $data['info'][1]['name'] = '明日赛事';
- $data['info'][1]['code'] = 'tomorrow';
- $data['info'][1]['count'] = lm('st_zq_competition','Sports')
- ->join('st_zq_league','st_zq_league.lg_id','st_zq_competition.lg_id')
- ->where('st_zq_competition.source',$this->source['source'])
- ->where('st_zq_competition.match_date','tomorrow')
- ->where('st_zq_competition.home_team','<>',null)
- ->where('st_zq_competition.guest_team','<>',null)
- ->count('*');
- //受欢迎的欧洲赛事
- $data['info'][2]['name'] = '受欢迎的欧洲赛事';
- $data['info'][2]['code'] = 'popular';
- $data['info'][2]['count'] = lm('st_zq_competition','Sports')
- ->join('st_zq_league','st_zq_league.lg_id','st_zq_competition.lg_id')
- ->join('st_area','st_area.id','st_zq_league.area_id')
- ->where('st_area.code',"Europe")
- ->where('st_zq_league.hot',0)
- ->where('st_zq_competition.status','<',2)
- ->where('st_zq_competition.us_time','>',qgmdate('Y-m-d H:i:s', '', -4))
- ->where('st_zq_competition.source',$this->source['source'])
- ->where('st_zq_competition.home_team','<>',null)
- ->where('st_zq_competition.guest_team','<>',null)
- ->count('*');
- //查询亚洲,澳洲赛事
- $data['info'][3]['name'] = '亚洲/澳洲赛事';
- $data['info'][3]['code'] = 'asia_aus';
- $data['info'][3]['count'] = lm('st_zq_competition','Sports')
- ->join('st_zq_league','st_zq_league.lg_id','st_zq_competition.lg_id')
- ->leftjoin('st_country','st_country.country_id','st_zq_league.country_id')
- ->leftjoin('st_area','st_area.id','st_zq_league.area_id')
- ->select('match_id')
- ->where(function ($query) {
- $query->Orwhere('st_area.code','=','Asian')
- ->Orwhere('st_country.name_english','=','Australia');
- })
- ->where('st_zq_competition.status','<',2)
- ->where('st_zq_competition.us_time','>',qgmdate('Y-m-d H:i:s', '', -4))
- ->where('st_zq_competition.source',$this->source['source'])
- ->where('st_zq_competition.home_team','<>',null)
- ->where('st_zq_competition.guest_team','<>',null)
- ->count('*');
- //查询北美,南美赛事
- $data['info'][4]['name'] = '北美/南美赛事';
- $data['info'][4]['code'] = 'south_north';
- $data['info'][4]['count'] = lm('st_zq_competition','Sports')
- ->join('st_zq_league','st_zq_league.lg_id','st_zq_competition.lg_id')
- ->join('st_area','st_area.id','st_zq_league.area_id')
- ->where(function ($query) {
- $query->Orwhere('st_area.code','=', "South_America")
- ->Orwhere('st_area.code','=', "North_America");
- })
- ->where('st_zq_competition.status', '<', '2')
- ->where('st_zq_competition.us_time','>',qgmdate('Y-m-d H:i:s', '', -4))
- ->where('st_area.source',$this->source['source'])
- ->where('st_zq_competition.home_team','<>',null)
- ->where('st_zq_competition.guest_team','<>',null)
- ->count('*');
- //国际赛事
- $data['info'][5]['name'] = '国际赛事';
- $data['info'][5]['code'] = 'intl';
- $data['info'][5]['count'] = lm('st_area','Sports')
- ->join('st_zq_league','st_zq_league.area_id','st_area.id')
- ->join('st_zq_competition','st_zq_competition.lg_id','st_zq_league.id')
- ->where('st_area.code',"world")
- ->where('st_zq_competition.status', '<', '2')
- ->where('st_zq_competition.us_time','>',qgmdate('Y-m-d H:i:s', '', -4))
- ->where('st_area.source',$this->source['source'])
- ->where('st_zq_competition.home_team','<>',null)
- ->where('st_zq_competition.guest_team','<>',null)
- ->count('*');
- return $data;
- }
- /*
- *首页条件筛选(其他球参赛表)
- */
- private function qt_participate ($typeGame){
- //===查询该球类是否存在或启用===
- $getModels = $this->commonFunction->getModels($typeGame);
- $data['game_code'] = $typeGame;
- $data['type'] = lm('GameType','Sports')->where('game_code',$typeGame)->value('game_name');
- $st_competition = $getModels['model_match'];
- $data['info'][0]['name'] = '所有赛事';
- $data['info'][0]['code'] = 'all';
- $data['info'][0]['count'] =lm($st_competition,'Sports')
- ->where([[$st_competition.'.status', '<', '2'],
- [$st_competition.'.source',$this->source['source']]])
- ->where($st_competition.'.us_time','>',qgmdate('Y-m-d H:i:s', '', -4))
- ->where($st_competition.'.home_team','<>',null)
- ->where($st_competition.'.guest_team','<>',null)
- ->count('*');
- $data['info'][1]['name'] = '今日赛事';
- $data['info'][1]['code'] = 'today';
- $data['info'][1]['count']=lm($st_competition,'Sports')
- ->where($st_competition.'.source',$this->source['source'])
- ->where($this->commonFunction->getState('StToday',$st_competition))
- ->where($st_competition.'.home_team','<>',null)
- ->where($st_competition.'.guest_team','<>',null)
- ->count('*');
- return $data;
- }
- public function participate(){
- $type = $_REQUEST['typeGame'];
- if($type != 'zq'|| empty($type)){
- $data = $this->qt_participate($type);
- }else{
- $data = $this->zq_participate();
- }
- Render($data, '1', lang('Tips','Sports')->get('success'));
- }
- /*
- * 参赛列表详情
- */
- public function participate_details()
- {
- $game_code = $_REQUEST['game_code'];//游戏代码
- $code = $_REQUEST['code'];//参赛代码
- $search = $_REQUEST['search'];//参赛代码
- $lg_id = $_REQUEST['lg_id'];//参赛代码
- //===查询该球类是否存在或启用===
- $getModels = $this->commonFunction->getModels($game_code);
- $st_league = $getModels['model_league'];
- $st_competition = $getModels['model_match'];
- $where_search = function($query)use ($st_competition,$search){
- $query->where($st_competition.'.home_team','like','%'.$search.'%')
- ->orWhere(function($query)use ($st_competition,$search) {
- $query->where($st_competition . '.guest_team', 'like', '%' . $search . '%');
- });
- };
- $Orwhere = "";
- switch ($code)
- {
- case $code == 'today':
- $where = $this->commonFunction->getState('StToday',$st_competition);
- //查询今日赛事
- $data = lm($st_competition,'Sports')
- ->join($st_league,$st_league.'.lg_id',$st_competition.'.lg_id')
- ->select($st_league.'.name_chinese',$st_league.'.lg_id')
- ->where($where)
- ->where($where_search)
- ->where($st_competition.'.home_team','<>',null)
- ->where($st_competition.'.guest_team','<>',null)
- ->where($st_competition.'.source',$this->source['source'])
- ->distinct($st_competition.'.match_id')
- ->get()
- ->toarray();
- break;
- case $code == 'popular':
- $where =[
- ['st_area.code','Europe'],[$st_league.'.hot',0],
- [$st_competition.'.status', '<', '2'],
- [$st_competition.'.source',$this->source['source']],
- [$st_competition.'.us_time','>',qgmdate('Y-m-d H:i:s', '', -4)],
- [$st_competition.'.home_team','<>',null],
- [$st_competition.'.guest_team','<>',null],
- ];
- //欧洲最受欢迎的赛事
- $data = lm($st_competition,'Sports')
- ->join($st_league,$st_league.'.lg_id',$st_competition.'.lg_id')
- ->join('st_area','st_area.id','st_zq_league.area_id')
- ->select($st_league.'.name_chinese',$st_league.'.lg_id')
- ->where($where)
- ->where($where_search)
- ->distinct($st_competition.'.match_id')
- ->get()
- ->toarray();
- break;
- case $code == 'asia_aus':
- $where = [
- [$st_competition.'.status', '<', '2'],
- [$st_competition.'.source',$this->source['source']],
- [$st_competition.'.us_time','>',qgmdate('Y-m-d H:i:s', '', -4)],
- [$st_competition.'.home_team','<>',null],
- [$st_competition.'.guest_team','<>',null],
- ];
- $Orwhere = function ($query) {
- $query->Orwhere('st_area.code','=','Asian')
- ->Orwhere('st_country.name_english','=','Australia');
- };
- //亚洲/澳洲赛事
- $data = lm($st_competition,'Sports')
- ->join($st_league,$st_league.'.lg_id',$st_competition.'.lg_id')
- ->leftjoin('st_country','st_country.country_id',$st_league.'.country_id')
- ->leftjoin('st_area','st_area.id',$st_league.'.area_id')
- ->select($st_league.'.name_chinese',$st_league.'.lg_id')
- ->where($where)
- ->where($Orwhere)
- ->where($where_search)
- ->distinct($st_competition.'.match_id')
- ->get()
- ->toarray();
- break;
- case $code == 'south_north':
- $where = [
- [$st_competition.'.status', '<', '2'],
- [$st_competition.'.source',$this->source['source']],
- [$st_competition.'.us_time','>',qgmdate('Y-m-d H:i:s', '', -4)],
- [$st_competition.'.home_team','<>',null],
- [$st_competition.'.guest_team','<>',null],
- ];
- $Orwhere = function ($query) {
- $query->Orwhere('st_area.code','=', "South_America")
- ->Orwhere('st_area.code','=', "North_America");
- };
- //南美洲/北美洲赛事
- $data = lm($st_competition,'Sports')
- ->join($st_league,$st_league.'.lg_id',$st_league.'.lg_id')
- ->join('st_area','st_area.id','st_zq_league.area_id')
- ->select($st_league.'.name_chinese',$st_league.'.lg_id')
- ->where($where)
- ->where($Orwhere)
- ->where($where_search)
- ->distinct($st_competition.'.match_id')
- ->get()
- ->toarray();
- break;
- case $code == 'tomorrow':
- $where = [
- [$st_competition.'.match_date','tomorrow'],
- [$st_competition.'.status',0],
- [$st_competition.'.source',$this->source['source']],
- [$st_competition.'.home_team','<>',null],
- [$st_competition.'.guest_team','<>',null],
- ];
- //明日赛事
- $data = lm($st_competition,'Sports')
- ->join($st_league,$st_league.'.lg_id',$st_competition.'.lg_id')
- ->select($st_league.'.name_chinese',$st_league.'.lg_id')
- ->where($where)
- ->where($where_search)
- ->distinct($st_league.'.lg_id')
- ->get()
- ->toarray();
- break;
- case $code == 'intl':
- $where = [
- ['st_area.code', "world"],
- [$st_competition.'.status','<','2'],
- [$st_competition.'.source',$this->source['source']],
- [$st_competition.'.us_time','>',qgmdate('Y-m-d H:i:s', '', -4)],
- [$st_competition.'.home_team','<>',null],
- [$st_competition.'.guest_team','<>',null],
- ];
- //国际赛事
- $data = lm($st_competition,'Sports')
- ->join($st_league,$st_league.'.lg_id',$st_competition.'.lg_id')
- ->join('st_area','st_area.id',$st_league.'.area_id')
- ->select($st_league.'.name_chinese',$st_league.'.lg_id')
- ->where($where)
- ->where($where_search)
- ->distinct($st_competition.'.match_id')
- ->get()
- ->toarray();
- break;
- case $code == 'all':
- $where = [
- [$st_competition.'.status','<', '2'],
- [$st_competition.'.source',$this->source['source']],
- [$st_competition.'.us_time','>',qgmdate('Y-m-d H:i:s', '', -4)],
- [$st_competition.'.home_team','<>',null],
- [$st_competition.'.guest_team','<>',null],
- ];
- //所有赛事
- $data = lm($st_competition,'Sports')
- ->join($st_league,$st_league.'.lg_id',$st_competition.'.lg_id')
- ->select($st_league.'.name_chinese',$st_league.'.lg_id')
- ->where($where)
- ->where($where_search)
- ->distinct($st_competition.'.match_id')
- ->get()
- ->toarray();
- break;
- case $code == 'qt':
- $where = [
- [$st_competition.'.status','<', '2'],
- [$st_competition.'.source',$this->source['source']],
- [$st_competition.'.us_time','>',qgmdate('Y-m-d H:i:s', '', -4)],
- [$st_league.'.lg_id',$lg_id],
- [$st_competition.'.home_team','<>',null],
- [$st_competition.'.guest_team','<>',null],
- ];
- //指定联赛下的赛事
- $data = lm($st_competition,'Sports')
- ->join($st_league,$st_league.'.lg_id',$st_competition.'.lg_id')
- ->select($st_league.'.name_chinese',$st_league.'.lg_id')
- ->where($where)
- ->where($where_search)
- ->distinct($st_competition.'.match_id')
- ->get()
- ->toarray();
- break;
- }
- //根据联赛ID赛事信息
- $data = $this->Competition_info($data,$getModels,$where,$where_search,$Orwhere);
- Render($data, '1', lang('Tips','Sports')->get('success'));
- }
- /*
- * 获取联赛信息
- */
- private function Competition_info(array $data,$getModels,$where,$where_search,$Orwhere){
- $st_competition = $getModels['model_match'];
- $st_odds = $getModels['model_odds'];
- $st_league = $getModels['model_league'];
- if(!$Orwhere){
- $Orwhere = [];
- }
- foreach($data as $k => $v){
- //统计赛事
- $data[$k]['count'] = lm($st_competition,'Sports')
- ->join($st_odds,$st_odds.'.match_id',$st_competition.'.match_id')
- ->join($st_league,$st_league.'.lg_id',$st_competition.'.lg_id')
- ->leftjoin('st_country','st_country.country_id',$st_league.'.country_id')
- ->leftjoin('st_area','st_area.id',$st_league.'.area_id')
- ->where($st_competition.'.lg_id',$v['lg_id'])
- ->where($where)
- ->where($Orwhere)
- ->where($where_search)
- ->distinct($st_competition.'.match_id')
- ->count($st_competition.'.match_id');
- //获取赛事信息
- $data[$k]['match_info'] = lm($st_competition,'Sports')
- ->join($st_odds,$st_odds.'.match_id',$st_competition.'.match_id')
- ->join($st_league,$st_league.'.lg_id',$st_competition.'.lg_id')
- ->leftjoin('st_country','st_country.country_id',$st_league.'.country_id')
- ->leftjoin('st_area','st_area.id',$st_league.'.area_id')
- ->select($st_competition.'.match_id',$st_competition.'.home_team',$st_competition.'.guest_team',$st_competition.'.match_date',$st_competition.'.status',$st_competition.'.match_time',$st_competition.'.tag')
- ->distinct($st_competition.'.match_id')
- ->where($where)
- ->where($Orwhere)
- ->where($where_search)
- ->where($st_competition.'.lg_id',$v['lg_id'])
- ->get()
- ->toarray();
- if(!$data[$k]['match_info']){
- unset($data[$k]);
- }
- //循环获取赛事赔率
- foreach ($data[$k]['match_info'] as $key=>$item){
- $data[$k]['match_info'][$key]['oddsData'] = lm($st_odds, 'Sports')
- ->select('id','p_code','odds_code','status','odds','condition','sort')
- ->where($this->source)
- ->where(['match_id'=>$item['match_id'],'type'=>0])
- ->where(function($query)use ($st_odds){
- $query->where($st_odds.'.odds_code','concede_home')
- ->orWhere(function($query)use ($st_odds){
- $query->where($st_odds.'.odds_code','concede_guest');
- })
- ->orWhere(function($query)use ($st_odds){
- $query->where($st_odds.'.odds_code','size_home');
- })
- ->orWhere(function($query)use ($st_odds){
- $query->where($st_odds.'.odds_code','size_guest');
- });
- })
- ->get()->toArray();
- if(!empty($data[$k]['match_info'][$key]['oddsData'])){
- //根据 排序 获取 最新让球/大小玩法赔率
- $sortData = array_column($data[$k]['match_info'][$key]['oddsData'],'sort');
- array_multisort($sortData,SORT_DESC,$data[$k]['match_info'][$key]['oddsData']);
- $data[$k]['match_info'][$key]['oddsData'] = array_slice($data[$k]['match_info'][$key]['oddsData'],0,4);//前四条 放入
- }else{
- $data[$k]['match_info'][$key]['oddsData'] = [];
- }
- }
- }
- return $data;
- }
- /*
- *首页条件筛选(冠军赛事)
- */
- public function first (){
- $gameType = $_REQUEST['typeGame'];
- $search = $_REQUEST['search'];
- //===查询该球类是否存在或启用===
- $gameType = empty($gameType)? 'zq':$gameType;
- $getModels = $this->commonFunction->getModels($gameType);
- $st_league = $getModels['model_league'];
- $st_competition = $getModels['model_match'];
- $data['type'] = lm('GameType', 'Sports')->where('game_code',$gameType)->value('game_name');
- //国家下所有联赛
- $country = lm($st_league,"Sports")
- ->join($st_competition,$st_competition.'.lg_id',$st_league.'.id')
- ->join('st_country','st_country.country_id',$st_league.'.country_id')
- ->select('st_country.id as region_id','st_country.name_chinese as region')
- ->distinct('st_country.name_chinese')
- ->where($st_league.'.name_chinese','like','%'.$search.'%')
- ->where($st_league.'.source',$this->source)
- ->where([])
- ->where($st_competition.'.home_team','<>',null)
- ->where($st_competition.'.guest_team','<>',null)
- ->get()
- ->toArray();
- //洲下所有联赛
- $area = lm($st_league,"Sports")
- ->join($st_competition,$st_competition.'.lg_id',$st_league.'.id')
- ->join('st_area','st_area.id',$st_league.'.area_id')
- ->select('st_area.id as region_id','st_area.title as region')
- ->distinct('st_area.title')
- ->where($st_league.'.name_chinese','like','%'.$search.'%')
- ->where($st_league.'.source',$this->source)
- ->where()
- ->where([])
- ->where($st_competition.'.home_team','<>',null)
- ->where($st_competition.'.guest_team','<>',null)
- ->get()
- ->toArray();
- //统计国家联赛下的赛事.
- if(!empty($country)){
- foreach($country as $k => $v) {
- $country[$k]['league_count'] = lm($st_league, 'Sports')
- ->select('lg_id', 'name_chinese as league')
- ->where($this->source)
- ->where('country_id', $v['region_id'])
- ->get()->toarray();
- }
- foreach ($country as $k => $v) {
- foreach($v['league_count'] as $kk => $vv ){
- $country[$k]['league_count'][$kk]['count'] = lm($st_competition, 'Sports')
- ->where($this->source)
- ->where('lg_id',$vv['lg_id'])
- ->where($st_competition.'.home_team','<>',null)
- ->where($st_competition.'.guest_team','<>',null)
- ->count('*');
- if($country[$k]['league_count'][$kk]['count'] == 0){
- unset($country[$k]['league_count'][$kk]);
- }
- }
- }
- }
- //统计洲联赛下的赛事
- if(!empty($area)){
- foreach($area as $k => $v) {
- $area[$k]['league_count'] = lm($st_league, 'Sports')
- ->select('lg_id ', 'name_chinese as league')
- ->where($this->source)
- ->where('area_id', $v['region_id'])
- ->get()->toarray();
- }
- foreach ($area as $k => $v) {
- foreach($v['league_count'] as $kk => $vv ){
- $area[$k]['league_count'][$kk]['count'] = lm($st_competition, 'Sports')
- ->where($this->source)
- ->where('lg_id',$vv['lg_id'])
- ->where($st_competition.'.home_team','<>',null)
- ->where($st_competition.'.guest_team','<>',null)
- ->count('*');
- if($area[$k]['league_count'][$kk]['count'] == 0){
- unset($area[$k]['league_count'][$kk]);
- }
- }
- }
- }
- $data['info'] = array_merge($country,$area);
- Render($data, '1', lang('Tips','Sports')->get('success'));
- }
- /*
- *首页条件筛选(所有赛事)
- */
- public function matchData (){
- $gameType = $_REQUEST['gameType'];
- $search = $_REQUEST['search'];
- $date = $_REQUEST['datetime'];
- //===查询该球类是否存在或启用===
- $gameType = empty($gameType) ? 'zq':$gameType;
- $getModels = $this->commonFunction->getModels($gameType);
- $st_league = $getModels['model_league'];
- $st_competition = $getModels['model_match'];
- //所属球类
- $where = [];
- if(!empty($date)){
- if($date == 'morning'){
- $where=[[$st_competition.'.is_morningplate',1],
- [$st_competition.'.match_date','>',date("Y-m-d",strtotime("+6 day"))]];
- }else if($date == 'today'){
- $where = $this->commonFunction->getState('StToday');
- }else {
- $where[$st_competition.'.match_date'] = $date;
- }
- }
- $data['type'] = lm('GameType', 'Sports')
- ->where('game_code',$gameType)
- ->value('game_name');
- //国家联赛数据
- $country = lm($st_league,"Sports")
- ->join($st_competition,$st_competition.'.lg_id',$st_league.'.lg_id')
- ->join('st_country','st_country.country_id',$st_league.'.country_id')
- ->select('st_country.country_id as region_id','st_country.name_chinese as region')
- ->distinct($st_league.'.lg_id')
- ->where($st_league.'.source',$this->source)
- ->where($st_league.'.name_chinese','like','%'.$search.'%')
- ->where($where)
- ->where($st_competition.'.status', '<', '2')
- ->where($st_competition.'.us_time','>',qgmdate('Y-m-d H:i:s', '', -4))
- ->get()
- ->toArray();
- //洲下所有联赛
- $area = lm($st_league,"Sports")
- ->join($st_competition,$st_competition.'.lg_id',$st_league.'.lg_id')
- ->join('st_area','st_area.id',$st_league.'.area_id')
- ->select('st_area.id as region_id','st_area.title as region')
- ->distinct($st_league.'.lg_id')
- ->where($st_league.'.source',$this->source)
- ->where($st_league.'.name_chinese','like','%'.$search.'%')
- ->where($where)
- ->where($st_competition.'.status', '<', '2')
- ->where($st_competition.'.us_time','>',qgmdate('Y-m-d H:i:s', '', -4))
- ->get()
- ->toArray();
- //统计国家联赛下的赛事
- if(!empty($country)){
- foreach($country as $k => $v) {
- $country[$k]['league_count'] = lm($st_league, 'Sports')
- ->select('lg_id', 'name_chinese as league')
- ->where($st_league.'.source',$this->source)
- ->where($st_league.'.name_chinese','like','%'.$search.'%')
- ->where('country_id', $v['region_id'])
- ->get()
- ->toarray();
- }
- foreach ($country as $k => $v) {
- foreach($v['league_count'] as $kk => $vv ){
- $country[$k]['league_count'][$kk]['count'] = lm($st_competition, 'Sports')
- ->where($this->source)
- ->where($where)
- ->where('lg_id',$vv['lg_id'])
- ->where('status', '<', '2')
- ->where('us_time','>',qgmdate('Y-m-d H:i:s', '', -4))
- ->where($st_competition.'.home_team','<>',null)
- ->where($st_competition.'.guest_team','<>',null)
- ->count('*');
- if($country[$k]['league_count'][$kk]['count'] == 0){
- unset($country[$k]['league_count'][$kk]);
- }
- }
- }
- }
- //统计洲联赛下的赛事
- if (!empty($area)){
- foreach($area as $k => $v) {
- $area[$k]['league_count'] = lm($st_league,'Sports')
- ->select('lg_id', 'name_chinese as league')
- ->where($this->source)
- ->where($st_league.'.name_chinese','like','%'.$search.'%')
- ->where('area_id', $v['region_id'])
- ->get()
- ->toarray();
- }
- foreach ($area as $k => $v) {
- foreach($v['league_count'] as $kk => $vv ){
- $area[$k]['league_count'][$kk]['count'] = lm($st_competition, 'Sports')
- ->where($this->source)
- ->where($where)
- ->where($st_competition.'.home_team','<>',null)
- ->where($st_competition.'.guest_team','<>',null)
- ->where('status', '<', '2')
- ->where('us_time','>',qgmdate('Y-m-d H:i:s', '', -4))
- ->where('lg_id',$vv['lg_id'])
- ->count('*');
- if($area[$k]['league_count'][$kk]['count'] == 0){
- unset($area[$k]['league_count'][$kk]);
- }
- }
- }
- }
- $data['info'] = array_merge($country,$area);
- Render($data, '1', lang('Tips','Sports')->get('success'));
- }
- /**
- * 联赛下 赛事及默认赔率数据
- *
- */
- public function matchDetails(){
- $data = $_REQUEST;
- try {
- if(empty($data['game_code']) || empty($data['leagueID']) || empty($data['oddsType'])){
- throw new \Exception(Render([], '10001', lang('Tips','Sports')->get('PARAM_ERROR')));
- }
- //根据时间获取联赛下赛事数据
- $whereDate = [];
- if(!empty($data['matchDate']) ){
- if($data['matchDate']== "morning"){
- $whereDate = [['is_morningplate',1],
- ['match_date','>',date("Y-m-d",strtotime("+6 day"))]];
- }else{
- $whereDate = ['match_date'=>$data['matchDate']];
- }
- }
- $models = $this->commonFunction->getModels($data['game_code'],0);
- $model_match = $models['model_match'];
- $model_odds = $models['model_odds'];
- $model_league = $models['model_league'];
- $model_result = $models['model_result'];
- $oddsTypeWhere = $this->getOddsTypeWhere($model_odds,$data['oddsType']);
- $source = $this->source;//数据源
- $data = $this->getOddsData->getOddsData($data,$whereDate,$source,$oddsTypeWhere);
- Render($data, '1', lang('Tips','Sports')->get('success'));
- } catch (\Exception $e) {
- echo $e->getMessage();
- }
- }
- //获取各状态下有哪些球类
- public function getGame(){
- $type_code = $_REQUEST['type_code'];
- try {
- if(empty($type_code)){
- throw new \Exception(Render([], '10001', lang('Tips','Sports')->get('PARAM_ERROR')));
- }
- //==获取当前可用球类==
- $game = lm('GameType', 'Sports')->where('status',1)->select('game_code','game_name','game_ico_url')->get()->toArray();
- //获取 不同状态的查询条件
- $where = $this->commonFunction->getState($type_code);
- $gameData = [];
- foreach ($game as $key=>$type){
- if($type_code != 'StChampion'){
- $matchModel = $this->commonFunction->getModels($type['game_code']);
- $matchNum = lm($matchModel['model_league'],"Sports")
- ->join($matchModel['model_match'],$matchModel['model_match'].'.lg_id',$matchModel['model_league'].'.lg_id')
- ->where($matchModel['model_match'].'.source',$this->source['source'])
- ->where($where)
- ->where([[$matchModel['model_league'].'.name_chinese','!=','']])
- ->count("*");
- //获取满足状态的球类/去除冠军类
- if($matchNum != 0 and $type['game_code']!='gj'){
- $gameData[] = $type;
- }
- }else{
- $matchModel = $this->commonFunction->getModels($type['game_code']);
- $matchNum = lm($matchModel['model_odds'], 'Sports')
- ->where($this->source)
- ->where($where)
- ->count('*');
- //获取满足状态的球类/去除冠军类
- if($matchNum != 0 and $type['game_code']!='gj'){
- $gameData[] = $type;
- }
- }
- }
- Render($gameData, '1', lang('Tips','Sports')->get('success'));
- } catch (\Exception $e) {
- echo $e->getMessage();
- }
- }
- /**
- * @throws \Exception
- * 获取不同状态下 各球类赛事数据
- * game_code 球类代码
- * type_code 类型代码
- */
- public function matchState(){
- $source = $this->source;//数据源 条件
- $ret = $_REQUEST;
- try {
- if(empty($ret['game_code']) || empty($ret['type_code'])){
- throw new \Exception(Render([], '10001', lang('Tips','Sports')->get('PARAM_ERROR')));
- }
- $data = $this->getTypeData->typeData($ret,$source);
- Render($data, '1', lang('Tips','Sports')->get('success'));
- } catch (\Exception $e) {
- echo $e->getMessage();
- }
- }
- /**
- * 根据赛事状态获取赔率查询条件
- */
- public function getOddsTypeWhere($model_odds,$oddsType){
- //获取赛事不同状态下的赔率
- if(!empty($oddsType)){
- switch ($oddsType)
- {
- case 'StRollBall'://滚球
- $oddsTypeWhere = [[$model_odds.'.is_rollball','=',1]];
- break;
- case 'StSoon'://即将
- $oddsTypeWhere = [[$model_odds.'.is_morningplate','=',1]];
- break;
- case 'StToday'://今日
- $oddsTypeWhere = [[$model_odds.'.is_today','=',1]];
- break;
- case 'StMorningPlate'://早盘
- $oddsTypeWhere = [[$model_odds.'.is_morningplate','=',1]];
- break;
- case 'StStringScene'://串场
- $oddsTypeWhere = [[$model_odds.'.is_stringscene','=',1]];
- break;
- case 'home'://首页
- $oddsTypeWhere = [[$model_odds.'.is_stringscene','=',1]];
- break;
- default:
- $oddsTypeWhere = [];
- }
- }
- return $oddsTypeWhere;
- }
- /**
- * 获取赛事所有玩法赔率数据
- */
- public function matchOdds(){
- $game_code = $_REQUEST['game_code'];
- $matchID = $_REQUEST['matchID'];
- $status = $_REQUEST['status'];
- $oddsType = $_REQUEST['oddsType'];
- try {
- if(empty($game_code) || empty($matchID) || empty($oddsType)){
- throw new \Exception(Render([], '10001', lang('Tips','Sports')->get('PARAM_ERROR')));
- }
- //根据球类代码 获取相关model
- $models = $this->commonFunction->getModels($game_code,0);
- $model_match = $models['model_match'];
- $model_odds = $models['model_odds'];
- $model_league = $models['model_league'];
- $model_result = $models['model_result'];
- //取消按状态查询赔率数据
- //$oddsTypeWhere = $this->getOddsTypeWhere($model_odds,$oddsType);
- $oddsData = lm($model_odds, 'Sports')
- ->select('sort','p_code','id','odds_only','odds_code',$model_odds.'.status','odds','condition','sort','source','utime')
- ->where($this->source)
- ->where([$model_odds.'.match_id'=>$matchID,$model_odds.'.type'=>0])//,$model_odds.'.expire_time'=>$utime
- ->orderBy('sort', 'desc')
- ->orderBy('p_code','desc')
- ->orderBy('odds_code','desc')
- ->get()->toArray();
- $matchData = lm($model_match, 'Sports')
- ->join($model_league,$model_league.'.lg_id',$model_match.'.lg_id')
- ->select($model_match.'.lg_id','name_chinese','match_id','home_team','guest_team','match_date','match_time',$model_match.'.status')
- ->where($model_match.'.source',$this->source['source'])
- ->where(['match_id'=>$matchID])
- ->first();
- if(empty($matchData)) Render(null, '1', lang('Tips','Sports')->get('success'));
- $matchData->ptime = '';//赛事进行时间
- $matchData->match_score = '';//赛事比分
- //如果该赛事正在进行,则获取进行时间
- if($matchData->status ==1){
- $result = lm($model_result, 'Sports')->select('match_id','match_time','match_score')
- ->where($this->source)
- ->where(['match_id'=>$matchData->match_id])
- ->first();
- $matchData->ptime = $result->match_time;
- $matchData->match_score = $result->match_score;
- }
- //赛事已结束
- if($matchData->status ==2){
- $oddsData = [];
- }
- //查询当前联赛下的赛事
- $league = [];
- if($oddsType != 'StRollBall'){
- $where = [
- ['home_team','<>',null],
- ['guest_team','<>',null],
- ['status','<',2],
- ['lg_id',$matchData->lg_id],
- ];
- switch ($oddsType)
- {
- case 'StSoon'://即将
- $matchWhere=[['is_morningplate','=',1]];
- break;
- case 'StToday'://今日
- $matchWhere=[['is_today','=',1]];
- break;
- case 'StMorningPlate'://早盘
- $matchWhere=[['is_morningplate','=',1]];
- break;
- case 'StStringScene'://串场
- $matchWhere = [['is_stringscene','=',1]];
- break;
- case 'home'://首页
- $matchWhere = [['is_stringscene','=',1]];
- break;
- default:
- $matchWhere = [];
- }
- $league = lm($model_match,'Sports')
- ->select('match_id','home_team','guest_team','status','match_date','match_time')
- ->where($this->source)
- ->where($where)
- ->where($matchWhere)
- ->get()
- ->toarray();
- }
- $list = array();
- foreach ($oddsData as $key=>$item){
- $item['team'] = '';
- if(strpos($item['odds_code'],'home') !== false) {
- $item['team'] = 'home';
- }
- if(strpos($item['odds_code'],'guest') !== false) {
- $item['team'] = 'guest';
- }
- $list[$key] = $item;
- }
- $p_code_array = [];
- foreach ($oddsData as $key =>$val){
- $p_code_array[] = $val['p_code'];
- }
- $p_code_array = array_keys(array_flip(array_unique($p_code_array)));//p_code 去重排序
- $data = [
- 'lg_id' =>$matchData->lg_id,
- 'leagueName' =>$matchData->name_chinese,
- 'match_id'=>$matchData->match_id,
- 'home_team'=>$matchData->home_team,
- 'guest_team'=>$matchData->guest_team,
- 'match_time'=>$matchData->match_date." ".$matchData->match_time,
- 'match_ptime'=>$matchData->ptime,
- 'match_score'=>$matchData->match_score,
- 'p_code_array'=> $p_code_array,
- 'oddsData'=>$oddsData,
- 'league' => $league,
- ];
- Render($data, '1', lang('Tips','Sports')->get('success'));
- } catch (\Exception $e) {
- echo $e->getMessage();
- }
- }
- /**
- * 手动 更新 赛事状态
- */
- public function updateMatch () {
- $game_code = $_REQUEST['game_code'];
- $match_date = $_REQUEST['match_date'];
- try {
- if(empty($game_code)){
- throw new \Exception(Render([], '10001', lang('Tips','Sports')->get('PARAM_ERROR')));
- }
- if(empty($match_date)) $match_date = date('Y-m-d');
- //根据球类代码 获取相关model
- $models = $this->commonFunction->getModels($game_code);
- $model_match = $models['model_match'];
- $matchData = lm($model_match,'Sports')->select('match_id','status','match_date','match_time')->where(['match_date'=>$match_date])->get();
- foreach ($matchData as $key=>$item){
- $time = strtotime($item->match_date.$item->match_time);
- if(($time+(60*90)) < time()){ //更新为 已结束
- lm($model_match,'Sports')->where(['match_id'=>$item->match_id])->update(['status'=>2]);
- }
- if(($time+(60*90)) > time() and $time < time()){ //更新为 进行中
- lm($model_match,'Sports')->where(['match_id'=>$item->match_id])->update(['status'=>1]);
- }
- }
- Render([], '1', lang('Tips','Sports')->get('success'));
- } catch (\Exception $e) {
- echo $e->getMessage();
- }
- }
- /**
- * 获取即将开赛 所有赛事
- * 首页使用
- */
- public function getSoon(){
- $source = $this->source;//数据源 条件
- try {
- $where = $this->commonFunction->getState('StSoon');
- $data = $this->getTypeData->getAllSoon($source,$where);
- Render($data, '1', lang('Tips','Sports')->get('success'));
- } catch (\Exception $e) {
- echo $e->getMessage();
- }
- }
- /**
- * 获取球类-玩法-赔率代码
- */
- public function getOddsCode(){
- $type = $_REQUEST['type'];
- if($type == 'p_code'){
- $p_code = lm('st_odds_code','Sports')
- ->select('odds_code','odds_name')
- ->where('p_id',0)
- ->get();
- }else{
- $p_code = lm('st_odds_code','Sports')
- ->select('id','odds_code','odds_name')
- ->where('p_id',0)
- ->get();
- foreach ($p_code as $k=>$v){
- $v->below = lm('st_odds_code','Sports')
- ->select('odds_code','odds_name')
- ->where('p_id',$v['id'])
- ->get();
- }
- }
- Render($p_code, '1', lang('Tips','Sports')->get('success'));
- }
- /**
- * 获取 欧洲冠军杯数据
- */
- public function getUEFAChampions (){
- $data = $this->getTypeData->getUEFAChampions($this->source);
- Render($data, '1', lang('Tips','Sports')->get('success'));
- }
- /**
- * 更新赔率数据
- */
- public function updateOdds(){
- $data = $_REQUEST;
- // $data = ['game_code'=>'zq','match_id'=>3095448];
- $getModels = $this->commonFunction->getModels($data['game_code']);
- $model_match = $getModels['model_match'];
- $model_odds = $getModels['model_odds'];
- $where[] = [$model_match.'.match_id','=',$data['match_id']];
- $oddsData = lm($model_match,"Sports")
- ->join($model_odds,$model_odds.'.match_id',$model_match.'.match_id')
- ->select($model_match.'.match_id',$model_match.'.match_date',$model_match.'.home_team',$model_match.'.guest_team',$model_odds.'.id as odds_id',$model_odds.'.p_code',$model_odds.'.odds_code',$model_odds.'.condition',$model_odds.'.odds',$model_odds.'.odds_only',$model_odds.'.status',$model_odds.'.sort')
- ->where($model_match.'.source',$this->source)
- ->where($model_odds.'.type',0)
- ->where($where)
- // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
- ->get()->toArray();
- $p_code_array = [];
- foreach ($oddsData as $key =>$val){
- $p_code_array[$val['p_code']] = lang('OddsTemp','Sports')->get($val['p_code']);
- }
- $data = [
- 'oddsData'=>$oddsData,
- 'p_code_array'=>$p_code_array
- ];
- Render($data, '1', lang('Tips','Sports')->get('success'));
- }
- }
|