Head.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <?php
  2. namespace App\Sports\Controller;
  3. use BaseController\Controller;
  4. /**
  5. * Class Head
  6. * @package App\Sports\Controller
  7. * User: tank
  8. * Date: 2019/3/19
  9. */
  10. class Head extends Controller{
  11. public function init() {
  12. $this->commonFunction = C()->get('commonFunction');
  13. }
  14. /**
  15. * 首页头部类别列表 弃用
  16. */
  17. public function __typeList (){
  18. //获取类型 代码
  19. $type = lang('GameTypes','Sports')->getAll();
  20. $ret = lm('GameType', 'Sports')->select('id','game_name','game_code','game_ico_url')->where('status',1)->get()->toArray();
  21. $data = [];
  22. foreach ($type as $key =>$item){
  23. $matchNum = [];
  24. $where = $this->commonFunction->getState($item['type_code']);
  25. foreach ($ret as $key1 => $item1){
  26. if($item1['game_code'] != 'gj'){
  27. //根据球类代码 获取相关model
  28. $models = $this->commonFunction->getModels($item1['game_code'],0);
  29. $model_match = $models['model_match'];
  30. $matchNum[$key1][] = lm($model_match, 'Sports')
  31. // ->select('match_id')
  32. ->where($this->source)
  33. ->where($where)
  34. ->count("*");
  35. }
  36. }
  37. $num_s = array_sum(array_column($matchNum, 0));
  38. //追加统计 各状态赛事数量
  39. $item['matchNum'] = $num_s;
  40. $data[$key][]=$item;
  41. }
  42. Render($data, '1', lang('Tips','Sports')->get('success'));
  43. }
  44. /**
  45. * 重写获取头部状态及其赛事数量
  46. */
  47. public function typeList(){
  48. //获取所有状态
  49. $type = lang('GameTypes','Sports')->getAll();
  50. $d = [];
  51. $ret = lm('GameType', 'Sports')->select('id','game_name','game_code','game_ico_url')->where('status',1)->get()->toArray();
  52. foreach ($type as $key =>$item){
  53. $matchNum = [];
  54. switch ($item['type_code']){
  55. case 'StRollBall'://滚球
  56. foreach ($ret as $key1 => $item1){
  57. //根据球类代码 获取相关model
  58. $models = $this->commonFunction->getModels($item1['game_code'],1);
  59. $model_match = $models['model_match'];
  60. $model_result = $models['model_result'];
  61. $model_odds = $models['model_odds'];
  62. $where = $this->commonFunction->getState($item['type_code'],$model_match);
  63. if($item1['game_code'] != 'gj'){
  64. $matchNum[$key1][] = lm($model_match, 'Sports')
  65. ->join($model_result,$model_result.'.match_id',$model_match . '.match_id')
  66. ->where($model_match.'.source',$this->source['source'])
  67. ->where($where)
  68. ->count("*");
  69. }
  70. }
  71. break;
  72. case 'StSoon'://即将
  73. foreach ($ret as $key1 => $item1){
  74. //根据球类代码 获取相关model
  75. $models = $this->commonFunction->getModels($item1['game_code'],1);
  76. $model_match = $models['model_match'];
  77. $model_league = $models['model_league'];
  78. $where = $this->commonFunction->getState($item['type_code'],$model_match);
  79. if($item1['game_code'] != 'gj'){
  80. $matchNum[$key1][] = lm($model_league,"Sports")
  81. ->join($model_match,$model_match.'.lg_id',$model_league.'.lg_id')
  82. ->where($model_match.'.source',$this->source['source'])
  83. ->where($where)
  84. ->count("*");
  85. }
  86. }
  87. break;
  88. case 'StToday'://今日
  89. foreach ($ret as $key1 => $item1){
  90. //根据球类代码 获取相关model
  91. $models = $this->commonFunction->getModels($item1['game_code'],1);
  92. $model_match = $models['model_match'];
  93. $model_league = $models['model_league'];
  94. $where = $this->commonFunction->getState($item['type_code'],$model_match);
  95. if($item1['game_code'] != 'gj'){
  96. // $matchNum[$key1][] = lm($model_match, 'Sports')
  97. // ->where($model_match.'.source',$this->source['source'])
  98. // ->where($where)
  99. // ->count("*");
  100. $matchNum[$key1][] = lm($model_league,"Sports")
  101. ->join($model_match,$model_match.'.lg_id',$model_league.'.lg_id')
  102. ->where($model_match.'.source',$this->source['source'])
  103. ->where($where)
  104. ->count("*");
  105. }
  106. }
  107. break;
  108. case 'StMorningPlate'://早盘
  109. foreach ($ret as $key1 => $item1){
  110. //根据球类代码 获取相关model
  111. $models = $this->commonFunction->getModels($item1['game_code'],1);
  112. $model_match = $models['model_match'];
  113. $model_league = $models['model_league'];
  114. $where = $this->commonFunction->getState($item['type_code'],$model_match);
  115. if($item1['game_code'] != 'gj'){
  116. $matchNum[$key1][] = lm($model_league,"Sports")
  117. ->join($model_match,$model_match.'.lg_id',$model_league.'.lg_id')
  118. ->where($model_match.'.source',$this->source['source'])
  119. ->where($where)
  120. ->count("*");
  121. }
  122. }
  123. break;
  124. case 'StStringScene'://串场
  125. foreach ($ret as $key1 => $item1) {
  126. //根据球类代码 获取相关model
  127. $models = $this->commonFunction->getModels($item1['game_code'], 1);
  128. $model_match = $models['model_match'];
  129. $model_league = $models['model_league'];
  130. $where = $this->commonFunction->getState($item['type_code'], $model_match);
  131. if ($item1['game_code'] != 'gj') {
  132. $matchNum[$key1][] = lm($model_league,"Sports")
  133. ->join($model_match,$model_match.'.lg_id',$model_league.'.lg_id')
  134. ->where($model_match.'.source',$this->source['source'])
  135. ->where($where)
  136. ->count("*");
  137. }
  138. }
  139. break;
  140. case 'StChampion'://冠军
  141. foreach ($ret as $key1 => $item1) {
  142. //根据球类代码 获取相关model
  143. $models = $this->commonFunction->getModels($item1['game_code'], 1);
  144. $model_odds = $models['model_odds'];
  145. $where = $this->commonFunction->getState($item['type_code']);
  146. if ($item1['game_code'] != 'gj') {
  147. $matchNum[$key1][] =count(lm($model_odds, 'Sports')
  148. ->select("match_id","type")
  149. ->where($this->source)
  150. ->where($where)
  151. ->groupby("match_id","type")
  152. ->get()
  153. );
  154. }
  155. }
  156. break;
  157. default:
  158. throw new \Exception(Render([], '10002', lang('Tips','Sports')->get('PARAM_ERROR')));
  159. }
  160. $num_s = array_sum(array_column($matchNum, 0));
  161. //追加统计 各状态赛事数量
  162. $item['matchNum'] = $num_s;
  163. $data[$key][]=$item;
  164. }
  165. Render($data, '1', lang('Tips','Sports')->get('success'));
  166. }
  167. /**
  168. * @throws \Exception
  169. * 返回首页球类列表
  170. */
  171. public function ballList (){
  172. $ret = lm('GameType', 'Sports')->select('id','game_name','game_code','game_ico_url')->where('status',1)->get();
  173. if(!empty($ret)) Render($ret, '1', lang('Tips','Sports')->get('success'));
  174. }
  175. }