Head.php 7.4 KB

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