Sports.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. namespace App\Sports\Controller;
  3. use BaseController\Controller;
  4. /**
  5. * Class Register
  6. * @package App\Sports\Controller
  7. * User: junghwi
  8. * Date: 2019/3/21
  9. */
  10. class Sports extends Controller{
  11. function init() {
  12. $this->date = date('Y-m-d');//当前日期时间戳
  13. }
  14. /*
  15. * 首页体育-足球比赛数据
  16. */
  17. private function football(){
  18. $data=[];
  19. $data['name'] = '足球';
  20. $data['game_code'] = 'zq';
  21. //查询今日正在进行的和未开始的足球比赛
  22. $data['match'] = lm("st_zq_competition","Sports")
  23. ->leftjoin('st_zq_odds','st_zq_odds.match_id','=','st_zq_competition.match_id')
  24. ->leftjoin('st_zq_league','st_zq_league.id','=','st_zq_competition.lg_id')
  25. ->select('st_zq_competition.match_id','st_zq_competition.home_team','st_zq_competition.guest_team','st_zq_competition.match_date','st_zq_competition.match_time')
  26. ->where('st_zq_competition.match_date',$this->date)
  27. ->where('st_zq_league.source',$this->source)
  28. ->whereIn('st_zq_competition.status',['0','1'])
  29. ->limit('2')
  30. ->get();
  31. //今日联赛
  32. $lg_id = lm('st_zq_competition','Sports')->select('lg_id')->where('source',$this->source)->where(['match_date'=>$this->date])->distinct('lg_id')->get()->toarray();
  33. if (!empty($lg_id)) {
  34. foreach($lg_id as $k => $v){
  35. $data['league'][$k]['lg_id'] = $v['lg_id'];
  36. $data['league'][$k]['name'] = lm('st_zq_league','Sports')->where('lg_id',$v['lg_id'])->where('source',$this->source)->value('name_chinese');
  37. $data['league'][$k]['count'] = lm('st_zq_competition','Sports')->where('source',$this->source)->where('lg_id',$v['lg_id'])->count();
  38. }
  39. }else {
  40. $data['league'] =[];
  41. }
  42. return $data;
  43. }
  44. /*
  45. * 首页体育-篮球比赛数据
  46. */
  47. private function basketball(){
  48. $data=[];
  49. $data['name']='篮球';
  50. $data['game_code'] = 'lq';
  51. //查询今日正在进行的和未开始的足球比赛/2
  52. $data['match'] = lm("st_lq_competition","Sports")
  53. ->leftjoin('st_lq_odds','st_lq_odds.match_id','=','st_lq_competition.match_id')
  54. ->leftjoin('st_lq_league','st_lq_league.id','=','st_lq_competition.lg_id')
  55. ->select('st_lq_competition.match_id','st_lq_competition.home_team','st_lq_competition.guest_team','st_lq_competition.match_date','st_lq_competition.match_time')
  56. ->where('st_lq_competition.match_date',$this->date)
  57. ->where('st_lq_competition.source',$this->source)
  58. ->whereIn('st_lq_competition.status',['0','1'])
  59. ->limit('2')
  60. ->get();
  61. //今日联赛
  62. $lg_id = lm('st_lq_competition','Sports')->select('lg_id')->where('source',$this->source)->where(['match_date'=>$this->date])->distinct('lg_id')->get()->toarray();
  63. if (!empty($lg_id)) {
  64. foreach($lg_id as $k => $v){
  65. $data['league'][$k]['lg_id'] = $v['lg_id'];
  66. $data['league'][$k]['name'] = lm('st_lq_league','Sports')
  67. ->where($this->source)
  68. ->where('lg_id',$v['lg_id'])
  69. ->value('name_chinese');
  70. $data['league'][$k]['count'] = lm('st_lq_league','Sports')
  71. ->where($this->source)
  72. ->where('lg_id',$v['lg_id'])
  73. ->count();
  74. }
  75. }else {
  76. $data['league'] =[];
  77. }
  78. return $data;
  79. }
  80. /*
  81. * 首页体育-网球比赛数据
  82. */
  83. private function tennis(){
  84. $data=[];
  85. $data['name']='网球';
  86. $data['game_code'] = 'wq';
  87. //查询今日正在进行的和未开始的足球比赛/2
  88. $data['match'] = lm("st_wq_competition","Sports")
  89. ->leftjoin('st_wq_odds','st_wq_odds.match_id','=','st_wq_competition.match_id')
  90. ->leftjoin('st_wq_league','st_wq_league.id','=','st_wq_competition.lg_id')
  91. ->select('st_wq_competition.match_id','st_wq_competition.home_team','st_wq_competition.guest_team','st_wq_competition.match_date','st_wq_competition.match_time')
  92. ->where('st_wq_competition.match_date',$this->date)
  93. ->where('st_wq_competition.source',$this->source)
  94. ->whereIn('st_wq_competition.status',['0','1'])
  95. ->limit('2')
  96. ->get();
  97. //今日联赛
  98. $lg_id = lm('st_wq_competition','Sports')->select('lg_id')->where('source',$this->source)->where(['match_date'=>$this->date])->distinct('lg_id')->get()->toarray();
  99. if (!empty($lg_id)) {
  100. foreach($lg_id as $k => $v){
  101. $data['league'][$k]['lg_id'] = $v['lg_id'];
  102. $data['league'][$k]['name'] = lm('st_wq_league','Sports')
  103. ->where('source',$this->source)
  104. ->where('lg_id',$v['lg_id'])
  105. ->value('name_chinese');
  106. $data['league'][$k]['count'] = lm('st_wq_competition','Sports')
  107. ->where('source',$this->source)
  108. ->where('lg_id',$v['lg_id'])
  109. ->count();
  110. }
  111. }else {
  112. $data['league'] =[];
  113. }
  114. return $data;
  115. }
  116. /*
  117. * 首页体育-棒球比赛数据
  118. */
  119. private function baseball(){
  120. $data=[];
  121. $data['name']='棒球';
  122. $data['game_code'] = 'bq';
  123. //查询今日正在进行的和未开始的足球比赛/2
  124. $data['match'] = lm("st_bq_competition","Sports")
  125. ->leftjoin('st_bq_odds','st_bq_odds.match_id','=','st_bq_competition.match_id')
  126. ->leftjoin('st_bq_league','st_bq_league.id','=','st_bq_competition.lg_id')
  127. ->select('st_bq_competition.match_id','st_bq_competition.home_team','st_bq_competition.guest_team','st_bq_competition.match_date','st_bq_competition.match_time')
  128. ->where('st_bq_competition.match_date',$this->date)
  129. ->where('st_bq_competition.source',$this->source)
  130. ->whereIn('st_bq_competition.status',['0','1'])
  131. ->limit('2')
  132. ->get();
  133. //今日联赛
  134. $lg_id = lm('st_bq_competition','Sports')->select('lg_id')->where('source',$this->source)->where(['match_date'=>$this->date])->distinct('lg_id')->get()->toarray();
  135. if (!empty($lg_id)) {
  136. foreach($lg_id as $k => $v){
  137. $data['league'][$k]['lg_id'] = $v['lg_id'];
  138. $data['league'][$k]['name'] = lm('st_bq_league','Sports')
  139. ->where('source',$this->source)
  140. ->where('lg_id',$v['lg_id'])
  141. ->value('name_chinese');
  142. $data['league'][$k]['count'] = lm('st_bq_competition','Sports')
  143. ->where('source',$this->source)
  144. ->where('lg_id',$v['lg_id'])
  145. ->count();
  146. }
  147. }else {
  148. $data['league'] =[];
  149. }
  150. return $data;
  151. }
  152. /*
  153. * 返回数据
  154. */
  155. public function data(){
  156. $lq[] = $this->basketball();
  157. $wq[] = $this->tennis();
  158. $bq[] = $this->baseball();
  159. $zq[] = $this->football();
  160. $data = array_add($zq,$lq,$wq,$bq);
  161. Render($data,'1', lang('Tips','Sports')->get('success'));
  162. }
  163. }