MatchList.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860
  1. <?php
  2. namespace App\Sports\Controller;
  3. use BaseController\Controller;
  4. use Biz\Match\GetmatchData;
  5. use Biz\Match\GetOddsData;
  6. /**
  7. * Class RollingData
  8. * @package App\Sports\Controller
  9. * User: tank
  10. * Date: 2019/3/22
  11. */
  12. class MatchList extends Controller {
  13. private $getTypeData;
  14. public function init() {
  15. $this->getTypeData = new GetmatchData();
  16. $this->getOddsData = new GetOddsData();
  17. $this->commonFunction = C()->get('commonFunction');
  18. }
  19. /*
  20. *首页条件筛选(足球参赛表)
  21. */
  22. private function zq_participate (){
  23. $data['type'] = '足球';
  24. $data['game_code'] = 'zq';
  25. $where_search = [];
  26. //查询今日赛事
  27. $where = $this->commonFunction->getState('StToday');
  28. $Orwhere = [];
  29. $data['info'][0]['name'] = '今日赛事';
  30. $data['info'][0]['code'] = 'today';
  31. $data['info'][0]['count'] = $this->getMatchCount($where,$Orwhere,$where_search,$data['game_code']);
  32. //查询明日赛事
  33. $where=[['st_zq_competition.match_date','tomorrow']];
  34. $Orwhere=[];
  35. $data['info'][1]['name'] = '明日赛事';
  36. $data['info'][1]['code'] = 'tomorrow';
  37. $data['info'][1]['count'] = $this->getMatchCount($where,$Orwhere,$where_search,$data['game_code']);
  38. //受欢迎的欧洲赛事
  39. $where =[['area.name_en','Europe'],['st_zq_league.hot',0]];
  40. $Orwhere=[];
  41. $data['info'][2]['name'] = '受欢迎的欧洲赛事';
  42. $data['info'][2]['code'] = 'popular';
  43. $data['info'][2]['count'] = $this->getMatchCount($where,$Orwhere,$where_search,$data['game_code']);
  44. //查询亚洲,澳洲赛事
  45. $where =[];
  46. $Orwhere = function ($query) {
  47. $query->Orwhere('area.name_en','=','Asia')
  48. ->Orwhere('country.name_en','=','Australia');
  49. };
  50. $data['info'][3]['name'] = '亚洲/澳洲赛事';
  51. $data['info'][3]['code'] = 'asia_aus';
  52. $data['info'][3]['count'] = $this->getMatchCount($where,$Orwhere,$where_search,$data['game_code']);
  53. //查询北美,南美赛事
  54. $where = [];
  55. $Orwhere = function ($query) {
  56. $query->Orwhere('area.name_en','=', "South America")
  57. ->Orwhere('area.name_en','=', "North America");
  58. };
  59. $data['info'][4]['name'] = '北美/南美赛事';
  60. $data['info'][4]['code'] = 'south_north';
  61. $data['info'][4]['count'] = $this->getMatchCount($where,$Orwhere,$where_search,$data['game_code']);
  62. //国际赛事
  63. $where = [['area.name_en',"world"]];
  64. $Orwhere = [];
  65. $data['info'][5]['name'] = '国际赛事';
  66. $data['info'][5]['code'] = 'intl';
  67. $data['info'][5]['count'] = $this->getMatchCount($where,$Orwhere,$where_search,$data['game_code']);
  68. return $data;
  69. }
  70. /*
  71. *首页条件筛选(其他球参赛表)
  72. */
  73. private function qt_participate ($typeGame){
  74. //===查询该球类是否存在或启用===
  75. $getModels = $this->commonFunction->getModels($typeGame);
  76. $data['game_code'] = $typeGame;
  77. $data['type'] = lm('GameType','Sports')->where('game_code',$typeGame)->value('game_name');
  78. $st_competition = $getModels['model_match'];
  79. // 所有赛事
  80. $where_search = [];
  81. $where = [];
  82. $Orwhere = [];
  83. $data['info'][0]['name'] = '所有赛事';
  84. $data['info'][0]['code'] = 'all';
  85. $data['info'][0]['count'] = $this->getMatchCount($where,$Orwhere,$where_search,$data['game_code']);
  86. //今日赛事
  87. $where = $this->commonFunction->getState('StToday',$st_competition);
  88. $Orwhere = [];
  89. $data['info'][1]['name'] = '今日赛事';
  90. $data['info'][1]['code'] = 'today';
  91. $data['info'][1]['count']=$this->getMatchCount($where,$Orwhere,$where_search,$data['game_code']);
  92. return $data;
  93. }
  94. /*
  95. * 参赛表数据接口
  96. */
  97. public function participate(){
  98. $type = $_REQUEST['typeGame'];
  99. if($type != 'zq'|| empty($type)){
  100. $data = $this->qt_participate($type);
  101. }else{
  102. $data = $this->zq_participate();
  103. }
  104. Render($data, '1', lang('Tips','Sports')->get('success'));
  105. }
  106. /*
  107. * 参赛列表详情
  108. */
  109. public function participate_details()
  110. {
  111. $game_code = $_REQUEST['game_code'];//游戏代码
  112. $code = $_REQUEST['code'];//参赛代码
  113. $search = $_REQUEST['search'];//参赛代码
  114. $lg_id = $_REQUEST['lg_id'];//参赛代码
  115. //===查询该球类是否存在或启用===
  116. $getModels = $this->commonFunction->getModels($game_code);
  117. $st_league = $getModels['model_league'];
  118. $st_competition = $getModels['model_match'];
  119. $st_odds = $getModels['model_odds'];
  120. $where_search = function($query)use ($st_competition,$search){
  121. $query->where($st_competition.'.home_team','like','%'.$search.'%')
  122. ->orWhere(function($query)use ($st_competition,$search) {
  123. $query->where($st_competition . '.guest_team', 'like', '%' . $search . '%');
  124. });
  125. };
  126. $Orwhere = [];
  127. switch ($code)
  128. {
  129. case $code == 'today':
  130. $where =$this->commonFunction->getState('StToday');
  131. //查询今日赛事
  132. $data = $this->getMatchInfo($where,$Orwhere,$where_search,$game_code);
  133. break;
  134. case $code == 'popular':
  135. $where =[['area.name_en','Europe'],[$st_league.'.hot',0]];
  136. //欧洲最受欢迎的赛事
  137. $data = $this->getMatchInfo($where,$Orwhere,$where_search,$game_code);
  138. break;
  139. case $code == 'asia_aus':
  140. $where = [];
  141. $Orwhere = function ($query) {
  142. $query->Orwhere('area.name_en','=','Asia')
  143. ->Orwhere('country.name_en','=','Australia');
  144. };
  145. //亚洲/澳洲赛事
  146. $data = $this->getMatchInfo($where,$Orwhere,$where_search,$game_code);
  147. break;
  148. case $code == 'south_north':
  149. $where = [];
  150. $Orwhere = function ($query) {
  151. $query->Orwhere('area.name_en','=', "South America")
  152. ->Orwhere('area.name_en','=', "North America");
  153. };
  154. //南美洲/北美洲赛事
  155. $data = $this->getMatchInfo($where,$Orwhere,$where_search,$game_code);
  156. break;
  157. case $code == 'tomorrow':
  158. $where = [[$st_competition.'.match_date','tomorrow']];
  159. //明日赛事
  160. $data = $this->getMatchInfo($where,$Orwhere,$where_search,$game_code);
  161. break;
  162. case $code == 'intl':
  163. $where = [['area.name_en', "world"]];
  164. //国际赛事
  165. $data = $this->getMatchInfo($where,$Orwhere,$where_search,$game_code);
  166. break;
  167. case $code == 'all':
  168. $where = [];
  169. //所有赛事
  170. $data = $this->getMatchInfo($where,$Orwhere,$where_search,$game_code);
  171. break;
  172. case $code == 'qt':
  173. $where = [[$st_league.'.lg_id',$lg_id]];
  174. //指定联赛下的赛事
  175. $data = $this->getMatchInfo($where,$Orwhere,$where_search,$game_code);
  176. break;
  177. }
  178. //根据赛事ID获取赔率数据
  179. foreach($data as $k => $v){
  180. $data[$k]['match_info'] = $this->getOdds($v['match_info'],$st_odds);
  181. }
  182. Render($data, '1', lang('Tips','Sports')->get('success'));
  183. }
  184. /*
  185. *首页条件筛选(所有赛事)
  186. */
  187. public function matchData (){
  188. $gameType = $_REQUEST['gameType'];
  189. $search = $_REQUEST['search'];
  190. $date = $_REQUEST['datetime'];
  191. //=获取球了MODEL
  192. $gameType = empty($gameType) ? 'zq':$gameType;
  193. $getModels = $this->commonFunction->getModels($gameType);
  194. $st_league = $getModels['model_league'];
  195. $st_competition = $getModels['model_match'];
  196. //所属球类
  197. $where = [];
  198. if(!empty($date)){
  199. if($date == 'morning'){
  200. $where=[[$st_competition.'.is_morningplate',1],
  201. [$st_competition.'.match_date','>',date("Y-m-d",strtotime("+6 day"))]];
  202. }else if($date == 'today'){
  203. $where = $this->commonFunction->getState('StToday');
  204. }else {
  205. $where[$st_competition.'.match_date'] = $date;
  206. }
  207. }
  208. //查询球类名称
  209. $data['type'] = lm('GameType', 'Sports')
  210. ->where('game_code',$gameType)
  211. ->value('game_name');
  212. //国家联赛数据
  213. $select=['st_country.country_id as region_id','st_country.name_chinese as region',$st_league.'.lg_id',$st_league.'.name_chinese as league'];
  214. $country = $this->getRegionInfo($where,$search,$select,'st_country','country_id',$gameType);
  215. //洲下所有联赛
  216. $select=['st_area.id as region_id','st_area.title as region',$st_league.'.lg_id',$st_league.'.name_chinese as league'];
  217. $area = $this->getRegionInfo($where,$search,$select,'st_area','id',$gameType);
  218. $data['info'] = array_merge($country,$area);
  219. Render($data, '1', lang('Tips','Sports')->get('success'));
  220. }
  221. /**
  222. * 根据地区获取信息
  223. * @param [array] $where 条件
  224. * @param [array] $search 搜索条件
  225. * @param [string] $regionModel 地区model
  226. * @param [int] $regionID 地区model
  227. * @param [type] $game_code 球类代码
  228. * @return [array] $data
  229. */
  230. public function getRegionInfo($where=[],$search,$select,$regionModel,$regionID,$game_code ='zq'){
  231. $getModels = $this->commonFunction->getModels($game_code);
  232. $st_league = $getModels['model_league'];
  233. $st_competition = $getModels['model_match'];
  234. try{
  235. //地区联赛赛事数据
  236. $regionInfo = lm($st_league,"Sports")
  237. ->join($st_competition,$st_competition.'.lg_id',$st_league.'.lg_id')
  238. ->join($regionModel,$regionModel.'.'.$regionID,$st_league.'.country_id')
  239. ->select($select)
  240. ->where($st_league.'.name_chinese','like','%'.$search.'%')
  241. ->where($where)
  242. ->where([
  243. [$st_competition.'.home_team','<>',null],
  244. [$st_competition.'.guest_team','<>',null],
  245. [$st_league.'.name_chinese','!=',''],
  246. [$st_competition.'.status','<',2],
  247. [$st_competition.'.us_time','>',qgmdate('Y-m-d H:i:s', '', -4)]
  248. ])
  249. ->get()
  250. ->toArray();
  251. //地区分割
  252. $info = [];
  253. foreach($regionInfo as $k => $v){
  254. $info[$k]['region'] = $v['region'];
  255. $info[$k]['region_id'] = $v['region_id'];
  256. }
  257. //地区去重
  258. $info = array_unique($info, SORT_REGULAR);
  259. //根据地区分类
  260. foreach ($info as $key => $vlue) {
  261. foreach ($regionInfo as $k => $v) {
  262. if ($vlue['region'] == $v['region']) {
  263. $info[$key]['league_count'][$k]['league'] = $v['league'];
  264. $info[$key]['league_count'][$k]['lg_id'] = $v['lg_id'];
  265. }
  266. }
  267. }
  268. //联赛去重
  269. foreach ($info as $key => $vlue) {
  270. $info[$key]['league_count'] = array_unique($vlue['league_count'], SORT_REGULAR);
  271. //统计联赛下赛事
  272. foreach ($vlue['league_count'] as $k => $v) {
  273. foreach ($regionInfo as $kk => $vv) {
  274. if ($v['league'] == $vv['league']) {
  275. if(!empty($info[$key]['league_count'][$kk]['league'])){
  276. $info[$key]['league_count'][$kk]['count'] += 1;
  277. }
  278. }
  279. }
  280. }
  281. }
  282. return $info;
  283. } catch (\Exception $e) {
  284. echo $e->getMessage();
  285. }
  286. }
  287. /**
  288. * 联赛下 赛事及默认赔率数据
  289. */
  290. public function matchDetails(){
  291. $data = $_REQUEST;
  292. try {
  293. if(empty($data['game_code']) || empty($data['leagueID']) || empty($data['oddsType'])){
  294. throw new \Exception(Render([], '10001', lang('Tips','Sports')->get('PARAM_ERROR')));
  295. }
  296. //根据时间获取联赛下赛事数据
  297. $whereDate = [];
  298. if(!empty($data['matchDate']) ){
  299. if($data['matchDate']== "morning"){
  300. $whereDate = [['is_morningplate',1],
  301. ['match_date','>',date("Y-m-d",strtotime("+6 day"))]];
  302. }else{
  303. $whereDate = ['match_date'=>$data['matchDate']];
  304. }
  305. }
  306. $models = $this->commonFunction->getModels($data['game_code'],0);
  307. $model_match = $models['model_match'];
  308. $model_odds = $models['model_odds'];
  309. $model_league = $models['model_league'];
  310. $model_result = $models['model_result'];
  311. $oddsTypeWhere = $this->getOddsTypeWhere($model_odds,$data['oddsType']);
  312. $source = $this->source;//数据源
  313. $data = $this->getOddsData->getOddsData($data,$whereDate,$source,$oddsTypeWhere);
  314. Render($data, '1', lang('Tips','Sports')->get('success'));
  315. } catch (\Exception $e) {
  316. echo $e->getMessage();
  317. }
  318. }
  319. //获取各状态下有哪些球类
  320. public function getGame(){
  321. $type_code = $_REQUEST['type_code'];
  322. try {
  323. if(empty($type_code)){
  324. throw new \Exception(Render([], '10001', lang('Tips','Sports')->get('PARAM_ERROR')));
  325. }
  326. //==获取当前可用球类==
  327. $game = lm('GameType', 'Sports')->where('status',1)->select('game_code','game_name','game_ico_url')->get()->toArray();
  328. //获取 不同状态的查询条件
  329. $where = $this->commonFunction->getState($type_code);
  330. $gameData = [];
  331. foreach ($game as $key=>$type){
  332. if($type_code != 'StChampion'){
  333. $matchModel = $this->commonFunction->getModels($type['game_code']);
  334. $matchNum = lm($matchModel['model_league'],"Sports")
  335. ->join($matchModel['model_match'],$matchModel['model_match'].'.lg_id',$matchModel['model_league'].'.lg_id')
  336. ->where($matchModel['model_match'].'.source',$this->source['source'])
  337. ->where($where)
  338. ->where([[$matchModel['model_league'].'.name_chinese','!=','']])
  339. ->count("*");
  340. //获取满足状态的球类/去除冠军类
  341. if($matchNum != 0 and $type['game_code']!='gj'){
  342. $gameData[] = $type;
  343. }
  344. }else{
  345. $matchModel = $this->commonFunction->getModels($type['game_code']);
  346. $matchNum = lm($matchModel['model_odds'], 'Sports')
  347. ->where($this->source)
  348. ->where($where)
  349. ->count('*');
  350. //获取满足状态的球类/去除冠军类
  351. if($matchNum != 0 and $type['game_code']!='gj'){
  352. $gameData[] = $type;
  353. }
  354. }
  355. }
  356. Render($gameData, '1', lang('Tips','Sports')->get('success'));
  357. } catch (\Exception $e) {
  358. echo $e->getMessage();
  359. }
  360. }
  361. /**
  362. * @throws \Exception
  363. * 获取不同状态下 各球类赛事数据
  364. * game_code 球类代码
  365. * type_code 类型代码
  366. */
  367. public function matchState(){
  368. $source = $this->source;//数据源 条件
  369. $ret = $_REQUEST;
  370. try {
  371. if(empty($ret['game_code']) || empty($ret['type_code'])){
  372. throw new \Exception(Render([], '10001', lang('Tips','Sports')->get('PARAM_ERROR')));
  373. }
  374. $data = $this->getTypeData->typeData($ret,$source);
  375. Render($data, '1', lang('Tips','Sports')->get('success'));
  376. } catch (\Exception $e) {
  377. echo $e->getMessage();
  378. }
  379. }
  380. /**
  381. * 根据赛事状态获取赔率查询条件
  382. */
  383. public function getOddsTypeWhere($model_odds,$oddsType){
  384. //获取赛事不同状态下的赔率
  385. if(!empty($oddsType)){
  386. switch ($oddsType)
  387. {
  388. case 'StRollBall'://滚球
  389. $oddsTypeWhere = [[$model_odds.'.is_rollball','=',1]];
  390. break;
  391. case 'StSoon'://即将
  392. $oddsTypeWhere = [[$model_odds.'.is_morningplate','=',1]];
  393. break;
  394. case 'StToday'://今日
  395. $oddsTypeWhere = [[$model_odds.'.is_today','=',1]];
  396. break;
  397. case 'StMorningPlate'://早盘
  398. $oddsTypeWhere = [[$model_odds.'.is_morningplate','=',1]];
  399. break;
  400. case 'StStringScene'://串场
  401. $oddsTypeWhere = [[$model_odds.'.is_stringscene','=',1]];
  402. break;
  403. case 'home'://首页
  404. $oddsTypeWhere = [[$model_odds.'.is_stringscene','=',1]];
  405. break;
  406. default:
  407. $oddsTypeWhere = [];
  408. }
  409. }
  410. return $oddsTypeWhere;
  411. }
  412. /**
  413. * 获取赛事所有玩法赔率数据
  414. */
  415. public function matchOdds(){
  416. $game_code = $_REQUEST['game_code'];
  417. $matchID = $_REQUEST['matchID'];
  418. $status = $_REQUEST['status'];
  419. $oddsType = $_REQUEST['oddsType'];
  420. try {
  421. if(empty($game_code) || empty($matchID) || empty($oddsType)){
  422. throw new \Exception(Render([], '10001', lang('Tips','Sports')->get('PARAM_ERROR')));
  423. }
  424. //根据球类代码 获取相关model
  425. $models = $this->commonFunction->getModels($game_code,0);
  426. $model_match = $models['model_match'];
  427. $model_odds = $models['model_odds'];
  428. $model_league = $models['model_league'];
  429. $model_result = $models['model_result'];
  430. //取消按状态查询赔率数据
  431. //$oddsTypeWhere = $this->getOddsTypeWhere($model_odds,$oddsType);
  432. $oddsData = lm($model_odds, 'Sports')
  433. ->select('sort','p_code','id','odds_only','odds_code',$model_odds.'.status','odds','condition','sort','source','utime')
  434. ->where($this->source)
  435. ->where([$model_odds.'.match_id'=>$matchID,$model_odds.'.type'=>0])//,$model_odds.'.expire_time'=>$utime
  436. ->orderBy('sort', 'desc')
  437. ->orderBy('p_code','desc')
  438. ->orderBy('odds_code','desc')
  439. ->get()->toArray();
  440. $matchData = lm($model_match, 'Sports')
  441. ->join($model_league,$model_league.'.lg_id',$model_match.'.lg_id')
  442. ->select($model_match.'.lg_id','name_chinese','match_id','home_team','guest_team','match_date','match_time',$model_match.'.status')
  443. ->where($model_match.'.source',$this->source['source'])
  444. ->where(['match_id'=>$matchID])
  445. ->first();
  446. if(empty($matchData)) Render(null, '1', lang('Tips','Sports')->get('success'));
  447. $matchData->ptime = '';//赛事进行时间
  448. $matchData->match_score = '';//赛事比分
  449. //如果该赛事正在进行,则获取进行时间
  450. if($matchData->status ==1){
  451. $result = lm($model_result, 'Sports')->select('match_id','match_time','match_score')
  452. ->where($this->source)
  453. ->where(['match_id'=>$matchData->match_id])
  454. ->first();
  455. $matchData->ptime = $result->match_time;
  456. $matchData->match_score = $result->match_score;
  457. }
  458. //赛事已结束
  459. if($matchData->status ==2){
  460. $oddsData = [];
  461. }
  462. //查询当前联赛下的赛事
  463. $league = [];
  464. if($oddsType != 'StRollBall'){
  465. $where = [
  466. ['home_team','<>',null],
  467. ['guest_team','<>',null],
  468. ['status','<',2],
  469. ['us_time','>',qgmdate('Y-m-d H:i:s', '', -4)],
  470. ['lg_id',$matchData->lg_id],
  471. ];
  472. switch ($oddsType)
  473. {
  474. case 'StSoon'://即将
  475. $matchWhere=[['is_morningplate','=',1]];
  476. break;
  477. case 'StToday'://今日
  478. $matchWhere=[['is_today','=',1]];
  479. break;
  480. case 'StMorningPlate'://早盘
  481. $matchWhere=[['is_morningplate','=',1]];
  482. break;
  483. case 'StStringScene'://串场
  484. $matchWhere = [['is_stringscene','=',1]];
  485. break;
  486. case 'home'://首页
  487. $matchWhere = [['is_stringscene','=',1]];
  488. break;
  489. default:
  490. $matchWhere = [];
  491. }
  492. $league = lm($model_match,'Sports')
  493. ->select('match_id','home_team','guest_team','status','match_date','match_time')
  494. ->where($this->source)
  495. ->where($where)
  496. ->where($matchWhere)
  497. ->get()
  498. ->toarray();
  499. }
  500. $list = array();
  501. foreach ($oddsData as $key=>$item){
  502. $item['team'] = '';
  503. if(strpos($item['odds_code'],'home') !== false) {
  504. $item['team'] = 'home';
  505. }
  506. if(strpos($item['odds_code'],'guest') !== false) {
  507. $item['team'] = 'guest';
  508. }
  509. $list[$key] = $item;
  510. }
  511. $p_code_array = [];
  512. foreach ($oddsData as $key =>$val){
  513. $p_code_array[] = $val['p_code'];
  514. }
  515. $p_code_array = array_keys(array_flip(array_unique($p_code_array)));//p_code 去重排序
  516. $data = [
  517. 'lg_id' =>$matchData->lg_id,
  518. 'leagueName' =>$matchData->name_chinese,
  519. 'match_id'=>$matchData->match_id,
  520. 'home_team'=>$matchData->home_team,
  521. 'guest_team'=>$matchData->guest_team,
  522. 'match_time'=>$matchData->match_date." ".$matchData->match_time,
  523. 'match_ptime'=>$matchData->ptime,
  524. 'match_score'=>$matchData->match_score,
  525. 'p_code_array'=> $p_code_array,
  526. 'oddsData'=>$oddsData,
  527. 'league' => $league,
  528. ];
  529. Render($data, '1', lang('Tips','Sports')->get('success'));
  530. } catch (\Exception $e) {
  531. echo $e->getMessage();
  532. }
  533. }
  534. /**
  535. * 手动 更新 赛事状态
  536. */
  537. public function updateMatch () {
  538. $game_code = $_REQUEST['game_code'];
  539. $match_date = $_REQUEST['match_date'];
  540. try {
  541. if(empty($game_code)){
  542. throw new \Exception(Render([], '10001', lang('Tips','Sports')->get('PARAM_ERROR')));
  543. }
  544. if(empty($match_date)) $match_date = date('Y-m-d');
  545. //根据球类代码 获取相关model
  546. $models = $this->commonFunction->getModels($game_code);
  547. $model_match = $models['model_match'];
  548. $matchData = lm($model_match,'Sports')->select('match_id','status','match_date','match_time')->where(['match_date'=>$match_date])->get();
  549. foreach ($matchData as $key=>$item){
  550. $time = strtotime($item->match_date.$item->match_time);
  551. if(($time+(60*90)) < time()){ //更新为 已结束
  552. lm($model_match,'Sports')->where(['match_id'=>$item->match_id])->update(['status'=>2]);
  553. }
  554. if(($time+(60*90)) > time() and $time < time()){ //更新为 进行中
  555. lm($model_match,'Sports')->where(['match_id'=>$item->match_id])->update(['status'=>1]);
  556. }
  557. }
  558. Render([], '1', lang('Tips','Sports')->get('success'));
  559. } catch (\Exception $e) {
  560. echo $e->getMessage();
  561. }
  562. }
  563. /**
  564. * 获取即将开赛 所有赛事
  565. * 首页使用
  566. */
  567. public function getSoon(){
  568. $source = $this->source;//数据源 条件
  569. try {
  570. $where = $this->commonFunction->getState('StSoon');
  571. $data = $this->getTypeData->getAllSoon($source,$where);
  572. Render($data, '1', lang('Tips','Sports')->get('success'));
  573. } catch (\Exception $e) {
  574. echo $e->getMessage();
  575. }
  576. }
  577. /**
  578. * 获取球类-玩法-赔率代码
  579. */
  580. public function getOddsCode(){
  581. $type = $_REQUEST['type'];
  582. if($type == 'p_code'){
  583. $p_code = lm('st_odds_code','Sports')
  584. ->select('odds_code','odds_name')
  585. ->where('p_id',0)
  586. ->get();
  587. }else{
  588. $p_code = lm('st_odds_code','Sports')
  589. ->select('id','odds_code','odds_name')
  590. ->where('p_id',0)
  591. ->get();
  592. foreach ($p_code as $k=>$v){
  593. $v->below = lm('st_odds_code','Sports')
  594. ->select('odds_code','odds_name')
  595. ->where('p_id',$v['id'])
  596. ->get();
  597. }
  598. }
  599. Render($p_code, '1', lang('Tips','Sports')->get('success'));
  600. }
  601. /**
  602. * 获取 欧洲冠军杯数据
  603. */
  604. public function getUEFAChampions (){
  605. $data = $this->getTypeData->getUEFAChampions($this->source);
  606. Render($data, '1', lang('Tips','Sports')->get('success'));
  607. }
  608. /**
  609. * 更新赔率数据
  610. */
  611. public function updateOdds(){
  612. $data = $_REQUEST;
  613. // $data = ['game_code'=>'zq','match_id'=>3095448];
  614. $getModels = $this->commonFunction->getModels($data['game_code']);
  615. $model_match = $getModels['model_match'];
  616. $model_odds = $getModels['model_odds'];
  617. $where[] = [$model_match.'.match_id','=',$data['match_id']];
  618. $oddsData = lm($model_match,"Sports")
  619. ->join($model_odds,$model_odds.'.match_id',$model_match.'.match_id')
  620. ->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')
  621. ->where($model_match.'.source',$this->source)
  622. ->where($model_odds.'.type',0)
  623. ->where($where)
  624. // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  625. ->get()->toArray();
  626. $p_code_array = [];
  627. foreach ($oddsData as $key =>$val){
  628. $p_code_array[$val['p_code']] = lang('OddsTemp','Sports')->get($val['p_code']);
  629. }
  630. $data = [
  631. 'oddsData'=>$oddsData,
  632. 'p_code_array'=>$p_code_array
  633. ];
  634. Render($data, '1', lang('Tips','Sports')->get('success'));
  635. }
  636. /**
  637. * 获取赛事所有数据
  638. * @param [array] $where 条件
  639. *@param [array] $Orwhere 或者条件
  640. * @param [type] $game_code 球类代码
  641. * @return [array] $data
  642. */
  643. public function getMatchInfo($where=[],$Orwhere=[],$where_search=[],$game_code ='zq'){
  644. $getModels = $this->commonFunction->getModels($game_code);
  645. $st_league = $getModels['model_league'];
  646. $st_competition = $getModels['model_match'];
  647. try{
  648. //查询今日赛事
  649. $data = lm($st_competition,'Sports')
  650. ->join($st_league,$st_league.'.lg_id',$st_competition.'.lg_id')
  651. ->leftjoin('st_area_country as country','country.id',$st_league.'.country_id')
  652. ->leftjoin('st_area_country as area','area.id',$st_league.'.area_id')
  653. ->select($st_league.'.name_chinese',$st_league.'.lg_id',$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','country.name as country_name','area.name as area_name')
  654. ->where($where)
  655. ->where($Orwhere)
  656. ->where($where_search)
  657. ->where([
  658. [$st_competition.'.home_team','<>',null],
  659. [$st_competition.'.guest_team','<>',null],
  660. [$st_league.'.name_chinese','<>',null],
  661. [$st_competition.'.status','<',2],
  662. [$st_competition.'.us_time','>',qgmdate('Y-m-d H:i:s', '', -4)]
  663. ])
  664. ->distinct($st_competition.'.match_id')
  665. ->get()
  666. ->toarray();
  667. $data = $this->division($data);
  668. return $data;
  669. } catch (\Exception $e) {
  670. echo $e->getMessage();
  671. }
  672. }
  673. /**
  674. * 数据分割器
  675. * @param [array] $matchData 赛事数据
  676. * @param [type] $type 分割类型 1:以联赛分
  677. * @return [array] $league
  678. */
  679. public function division(array $matchData)
  680. {
  681. //联赛分割
  682. $league = [];
  683. foreach ($matchData as $k => $v) {
  684. $league[$k]['name_chinese'] = $v['name_chinese'];
  685. $league[$k]['lg_id'] = $v['lg_id'];
  686. }
  687. //联赛去重
  688. $league = array_unique($league, SORT_REGULAR);
  689. //根据联赛分类
  690. foreach ($league as $key => $vlue) {
  691. foreach ($matchData as $k => $v) {
  692. if ($vlue['name_chinese'] == $v['name_chinese']) {
  693. $league[$key]['match_info'][$k] = $v;
  694. }
  695. }
  696. }
  697. //统计联赛下赛事
  698. foreach ($league as $key => $vlue) {
  699. $league[$key]['match_info'] = array_sort($league[$key]['match_info']);
  700. $league[$key]['count'] = count($vlue['match_info']);
  701. }
  702. return $league;
  703. }
  704. /**
  705. * 获取赛事赔率数据
  706. * @param [array] $where 条件
  707. *@param [array] $Orwhere 或者条件
  708. * @param [type] $game_code 球类代码
  709. * @return [array] $data
  710. */
  711. private function getOdds(array $data,$st_odds){
  712. //循环获取赛事赔率
  713. foreach ($data as $key=>$item){
  714. $data[$key]['oddsData'] = lm($st_odds, 'Sports')
  715. ->select('id','p_code','odds_code','status','odds','condition','sort')
  716. ->where($this->source)
  717. ->where(['match_id'=>$item['match_id'],'type'=>0])
  718. ->where(function($query)use ($st_odds){
  719. $query->where($st_odds.'.odds_code','concede_home')
  720. ->orWhere(function($query)use ($st_odds){
  721. $query->where($st_odds.'.odds_code','concede_guest');
  722. })
  723. ->orWhere(function($query)use ($st_odds){
  724. $query->where($st_odds.'.odds_code','size_home');
  725. })
  726. ->orWhere(function($query)use ($st_odds){
  727. $query->where($st_odds.'.odds_code','size_guest');
  728. });
  729. })
  730. ->get()->toArray();
  731. if(!empty($data[$key]['oddsData'])){
  732. //根据 排序 获取 最新让球/大小玩法赔率
  733. $sortData = array_column($data[$key]['oddsData'],'sort');
  734. array_multisort($sortData,SORT_DESC,$data[$key]['oddsData']);
  735. $data[$key]['oddsData'] = array_slice($data[$key]['oddsData'],0,4);//前四条 放入
  736. }else{
  737. $data[$key]['oddsData'] = [];
  738. }
  739. }
  740. return $data;
  741. }
  742. /**
  743. * 获取赛事总数
  744. * @param [array] $where 条件
  745. *@param [array] $Orwhere 或者条件
  746. * @param [type] $game_code 球类代码
  747. * @return [int] $dataCount
  748. */
  749. public function getMatchCount($where=[],$Orwhere=[],$where_search=[],$game_code ='zq'){
  750. $getModels = $this->commonFunction->getModels($game_code);
  751. $st_league = $getModels['model_league'];
  752. $st_competition = $getModels['model_match'];
  753. //查询今日赛事
  754. $dataCount = lm($st_competition,'Sports')
  755. ->join($st_league,$st_league.'.lg_id',$st_competition.'.lg_id')
  756. ->leftjoin('st_area_country as country','country.id',$st_league.'.country_id')
  757. ->leftjoin('st_area_country as area','area.id',$st_league.'.area_id')
  758. ->where($where)
  759. ->where($Orwhere)
  760. ->where($where_search)
  761. ->where([
  762. [$st_competition.'.home_team','<>',null],
  763. [$st_competition.'.guest_team','<>',null],
  764. [$st_league.'.name_chinese','<>',null],
  765. [$st_competition.'.status','<',2],
  766. [$st_competition.'.us_time','>',qgmdate('Y-m-d H:i:s', '', -4)]
  767. ])
  768. ->distinct($st_competition.'.match_id')
  769. ->count('*');
  770. return $dataCount;
  771. }
  772. }