Head.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. $where = $this->commonFunction->getState($item['type_code'],$model_match);
  78. if($item1['game_code'] != 'gj'){
  79. $matchNum[$key1][] = lm($model_match, 'Sports')
  80. ->where($model_match.'.source',$this->source['source'])
  81. ->where($where)
  82. ->count("*");
  83. }
  84. }
  85. break;
  86. case 'StToday'://今日
  87. foreach ($ret as $key1 => $item1){
  88. //根据球类代码 获取相关model
  89. $models = $this->commonFunction->getModels($item1['game_code'],1);
  90. $model_match = $models['model_match'];
  91. $where = $this->commonFunction->getState($item['type_code'],$model_match);
  92. if($item1['game_code'] != 'gj'){
  93. $matchNum[$key1][] = lm($model_match, 'Sports')
  94. ->where($model_match.'.source',$this->source['source'])
  95. ->where($where)
  96. ->count("*");
  97. }
  98. }
  99. break;
  100. case 'StMorningPlate'://早盘
  101. foreach ($ret as $key1 => $item1){
  102. //根据球类代码 获取相关model
  103. $models = $this->commonFunction->getModels($item1['game_code'],1);
  104. $model_match = $models['model_match'];
  105. $where = $this->commonFunction->getState($item['type_code'],$model_match);
  106. if($item1['game_code'] != 'gj'){
  107. $matchNum[$key1][] = lm($model_match, 'Sports')
  108. ->where($model_match.'.source',$this->source['source'])
  109. ->where($where)
  110. ->count("*");
  111. }
  112. }
  113. break;
  114. case 'StStringScene'://串场
  115. foreach ($ret as $key1 => $item1) {
  116. //根据球类代码 获取相关model
  117. $models = $this->commonFunction->getModels($item1['game_code'], 1);
  118. $model_match = $models['model_match'];
  119. $where = $this->commonFunction->getState($item['type_code'], $model_match);
  120. if ($item1['game_code'] != 'gj') {
  121. $matchNum[$key1][] = lm($model_match, 'Sports')
  122. ->where($model_match . '.source', $this->source['source'])
  123. ->where($where)
  124. ->count("*");
  125. }
  126. }
  127. break;
  128. case 'StChampion'://冠军
  129. foreach ($ret as $key1 => $item1) {
  130. //根据球类代码 获取相关model
  131. $models = $this->commonFunction->getModels($item1['game_code'], 1);
  132. $model_odds = $models['model_odds'];
  133. $where = $this->commonFunction->getState($item['type_code']);
  134. if ($item1['game_code'] != 'gj') {
  135. $matchNum[$key1][] =count(lm($model_odds, 'Sports')
  136. ->select("match_id","type")
  137. ->where($this->source)
  138. ->where($where)
  139. ->groupby("match_id","type")
  140. ->get()
  141. );
  142. }
  143. }
  144. break;
  145. default:
  146. throw new \Exception(Render([], '10002', lang('Tips','Sports')->get('PARAM_ERROR')));
  147. }
  148. $num_s = array_sum(array_column($matchNum, 0));
  149. //追加统计 各状态赛事数量
  150. $item['matchNum'] = $num_s;
  151. $data[$key][]=$item;
  152. }
  153. Render($data, '1', lang('Tips','Sports')->get('success'));
  154. }
  155. /**
  156. * @throws \Exception
  157. * 返回首页球类列表
  158. */
  159. public function ballList (){
  160. $ret = lm('GameType', 'Sports')->select('id','game_name','game_code','game_ico_url')->where('status',1)->get();
  161. if(!empty($ret)) Render($ret, '1', lang('Tips','Sports')->get('success'));
  162. }
  163. }