Head.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <?php
  2. namespace App\Sports\Controller;
  3. use BaseController\Controller;
  4. use App\Sports\Model\St_zq_competition as ZQmatchModel;
  5. use App\Sports\Model\St_lq_competition as LQmatchModel;
  6. use App\Sports\Model\St_wq_competition as WQmatchModel;
  7. use App\Sports\Model\St_bq_competition as BQmatchModel;
  8. use App\Sports\Model\St_zq_odds as ZQoddsModel;
  9. use App\Sports\Model\St_lq_odds as LQoddsModel;
  10. use App\Sports\Model\St_wq_odds as WQoddsModel;
  11. use App\Sports\Model\St_bq_odds as BQoddsModel;
  12. use App\Sports\Model\St_zq_league as leagueModel;
  13. use Biz\Match\GetmatchData;
  14. use Biz\Match\GetOddsData;
  15. /**
  16. * Class Head
  17. * @package App\Sports\Controller
  18. * User: tank
  19. * Date: 2019/3/19
  20. */
  21. class Head extends Controller{
  22. public function init() {
  23. $this->commonFunction = C()->get('commonFunction');
  24. $this->getTypeData = new GetmatchData();
  25. $this->getOddsData = new GetOddsData();
  26. }
  27. /**
  28. * @throws \Exception
  29. * 返回首页球类列表
  30. */
  31. public function ballList (){
  32. $ret = lm('GameType', 'Sports')->select('id','game_name','game_code','game_ico_url')->where('status',1)->get();
  33. if(!empty($ret)) Render($ret, '1', lang('Tips','Sports')->get('success'));
  34. }
  35. //获取各状态下所有赛事数量
  36. public function typeList(){
  37. $this->typeList_v2();
  38. }
  39. public function typeList_v1(){
  40. //获取所有未结束赛事
  41. $where = [
  42. ['status','<','2']
  43. ];
  44. $zqModel = $this->commonFunction->getModels('zq');
  45. $lqModel = $this->commonFunction->getModels('lq');
  46. $wqModel = $this->commonFunction->getModels('wq');
  47. $bqModel = $this->commonFunction->getModels('bq');
  48. $ZQmatchData = leagueModel::getLeagueMatchData($zqModel,$where,'zq');
  49. $LQmatchData = leagueModel::getLeagueMatchData($lqModel,$where,'lq');
  50. $WQmatchData = leagueModel::getLeagueMatchData($wqModel,$where,'wq');
  51. $BQmatchData = leagueModel::getLeagueMatchData($bqModel,$where,'bq');
  52. //处理空赔率赛事
  53. $ZQmatchData = $this->commonFunction->Handle_Odds_Null($ZQmatchData,$zqModel);
  54. $LQmatchData = $this->commonFunction->Handle_Odds_Null($LQmatchData,$lqModel);
  55. $WQmatchData = $this->commonFunction->Handle_Odds_Null($WQmatchData,$wqModel);
  56. $BQmatchData = $this->commonFunction->Handle_Odds_Null($BQmatchData,$bqModel);
  57. //合并所有球类赛事
  58. $matchAll = array_merge_recursive($ZQmatchData,$LQmatchData,$WQmatchData,$BQmatchData);
  59. //获取所有冠军盘口
  60. $where = [
  61. ['type','=',1],
  62. // ['source','=',$this->source]
  63. ];
  64. $select = ['match_id','type'];
  65. $ZQoddsData = ZQoddsModel::getOddsData($where,$select)->toArray();
  66. $LQoddsData = LQoddsModel::getOddsData($where,$select)->toArray();
  67. $WQoddsData = WQoddsModel::getOddsData($where,$select)->toArray();
  68. $BQoddsData = BQoddsModel::getOddsData($where,$select)->toArray();
  69. //合并所有球类冠军盘口
  70. $oddsAll = array_merge_recursive($ZQoddsData,$LQoddsData,$WQoddsData,$BQoddsData);
  71. $StRollBall = [];
  72. $StSoon = [];
  73. $StToday = [];
  74. $StMorningPlate = [];
  75. $StStringScene = [];
  76. //按状态条件分装数组
  77. foreach ($matchAll as $kk=>$vv){
  78. //滚球
  79. if($vv['status'] < 2 and $vv['match_date'] == date("Y-m-d") and $vv['match_time'] > date("H:i:s", time()-(90*60)) and $vv['match_time'] < date("H:i:s", time())){
  80. $StRollBall[] = $vv;
  81. }
  82. //即将
  83. if($vv['status'] == '0' and $vv['match_date'] == date("Y-m-d") and $vv['match_time'] < date("H:i:s", strtotime("+2 hour")) and $vv['match_time'] > date("H:i:s", time())){
  84. $StSoon[] = $vv;
  85. }
  86. //今日
  87. if($vv['match_date'] == date("Y-m-d") and $vv['match_time'] > date("H:i:s", time()) and $vv['status'] < 2){
  88. $StToday[] = $vv;
  89. }
  90. //早盘
  91. if($vv['is_morningplate'] == 1 and $vv['us_time'] > $this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4) and $vv['status'] < 2 and $vv['match_date'] > date("Y-m-d")){
  92. $StMorningPlate[] = $vv;
  93. }
  94. //串场
  95. if($vv['is_stringscene'] == 1 and $vv['us_time'] > $this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4) and $vv['status'] < 2){
  96. $StStringScene[] = $vv;
  97. }
  98. }
  99. //获取所有状态
  100. $type = lang('GameTypes','Sports')->getAll();
  101. foreach ($type as $k=>$v){
  102. switch ($v['type_code']) {
  103. case 'StRollBall'://滚球
  104. $type[$k]['matchNum'] = count($StRollBall);
  105. break;
  106. case 'StSoon'://即将
  107. $type[$k]['matchNum'] = count($StSoon);
  108. break;
  109. case 'StToday'://今日
  110. $type[$k]['matchNum'] = count($StToday);
  111. break;
  112. case 'StMorningPlate'://早盘
  113. $type[$k]['matchNum'] = count($StMorningPlate);
  114. break;
  115. case 'StStringScene'://串场
  116. $type[$k]['matchNum'] = count($StStringScene);
  117. break;
  118. case 'StChampion'://冠军
  119. $type[$k]['matchNum'] = count($oddsAll);
  120. break;
  121. default:
  122. throw new \Exception(Render([], '10002', lang('Tips', 'Sports')->get('PARAM_ERROR')));
  123. }
  124. }
  125. Render($type, '1', lang('Tips','Sports')->get('success'));
  126. }
  127. public function typeList_v2(){
  128. //获取所有未结束赛事
  129. $where = [
  130. ['status','<','2']
  131. ];
  132. $zqModel = $this->commonFunction->getModels('zq');
  133. $lqModel = $this->commonFunction->getModels('lq');
  134. $wqModel = $this->commonFunction->getModels('wq');
  135. $bqModel = $this->commonFunction->getModels('bq');
  136. $ZQmatchData = leagueModel::getLeagueMatchData($zqModel,$where,'zq');
  137. $LQmatchData = leagueModel::getLeagueMatchData($lqModel,$where,'lq');
  138. $WQmatchData = leagueModel::getLeagueMatchData($wqModel,$where,'wq');
  139. $BQmatchData = leagueModel::getLeagueMatchData($bqModel,$where,'bq');
  140. //处理空赔率赛事
  141. $ZQmatchData = $this->commonFunction->Handle_Odds_Null($ZQmatchData,$zqModel);
  142. $LQmatchData = $this->commonFunction->Handle_Odds_Null($LQmatchData,$lqModel);
  143. $WQmatchData = $this->commonFunction->Handle_Odds_Null($WQmatchData,$wqModel);
  144. $BQmatchData = $this->commonFunction->Handle_Odds_Null($BQmatchData,$bqModel);
  145. //合并所有球类赛事
  146. $matchAll = array_merge_recursive($ZQmatchData,$LQmatchData,$WQmatchData,$BQmatchData);
  147. //获取所有冠军盘口
  148. $where = [
  149. ['type','=',1],
  150. // ['source','=',$this->source]
  151. ];
  152. $select = ['match_id','type'];
  153. $ZQoddsData = ZQoddsModel::getOddsData($where,$select)->toArray();
  154. $LQoddsData = LQoddsModel::getOddsData($where,$select)->toArray();
  155. $WQoddsData = WQoddsModel::getOddsData($where,$select)->toArray();
  156. $BQoddsData = BQoddsModel::getOddsData($where,$select)->toArray();
  157. //合并所有球类冠军盘口
  158. $oddsAll = array_merge_recursive($ZQoddsData,$LQoddsData,$WQoddsData,$BQoddsData);
  159. $StRollBall = [];
  160. $StSoon = [];
  161. $StToday = [];
  162. $StMorningPlate = [];
  163. $StStringScene = [];
  164. //按状态条件分装数组
  165. foreach ($matchAll as $kk=>$vv){
  166. /*
  167. //滚球
  168. if($vv['status'] < 2 and $vv['match_date'] == date("Y-m-d") and $vv['match_time'] > date("H:i:s", time()-(90*60)) and $vv['match_time'] < date("H:i:s", time())){
  169. $StRollBall[] = $vv;
  170. }
  171. */
  172. //即将
  173. if($vv['status'] == '0' and $vv['match_date'] == date("Y-m-d") and $vv['match_time'] < date("H:i:s", strtotime("+2 hour")) and $vv['match_time'] > date("H:i:s", time())){
  174. $StSoon[] = $vv;
  175. }
  176. //今日
  177. if($vv['match_date'] == date("Y-m-d") and $vv['match_time'] > date("H:i:s", time()) and $vv['status'] < 2){
  178. $StToday[] = $vv;
  179. }
  180. //早盘
  181. if($vv['is_morningplate'] == 1 and $vv['us_time'] > $this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4) and $vv['status'] < 2 and $vv['match_date'] > date("Y-m-d")){
  182. $StMorningPlate[] = $vv;
  183. }
  184. //串场
  185. if($vv['is_stringscene'] == 1 and $vv['us_time'] > $this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4) and $vv['status'] < 2){
  186. $StStringScene[] = $vv;
  187. }
  188. }
  189. //获取所有状态
  190. $type = lang('GameTypes','Sports')->getAll();
  191. foreach ($type as $k=>$v){
  192. switch ($v['type_code']) {
  193. case 'StRollBall'://滚球
  194. // $type[$k]['matchNum'] = count($StRollBall);
  195. $type[$k]['matchNum'] = $this->getRollBallNum();
  196. break;
  197. case 'StSoon'://即将
  198. $type[$k]['matchNum'] = count($StSoon);
  199. break;
  200. case 'StToday'://今日
  201. $type[$k]['matchNum'] = count($StToday);
  202. break;
  203. case 'StMorningPlate'://早盘
  204. $type[$k]['matchNum'] = count($StMorningPlate);
  205. break;
  206. case 'StStringScene'://串场
  207. $type[$k]['matchNum'] = count($StStringScene);
  208. break;
  209. case 'StChampion'://冠军
  210. $type[$k]['matchNum'] = count($oddsAll);
  211. break;
  212. default:
  213. throw new \Exception(Render([], '10002', lang('Tips', 'Sports')->get('PARAM_ERROR')));
  214. }
  215. }
  216. Render($type, '1', lang('Tips','Sports')->get('success'));
  217. }
  218. /**
  219. * 获取各球类滚球数量
  220. */
  221. public function getRollBallNum(){
  222. $ret = lm('GameType', 'Sports')->select('id','game_code')->where('status',1)->get()->toArray();
  223. //滚球赛事数量
  224. $matchNum = [];
  225. foreach($ret as $k=>$v){
  226. if($v['game_code'] != 'gj'){
  227. //根据球类代码 获取相关model
  228. $models = $this->commonFunction->getModels($v['game_code']);
  229. $model_match = $models['model_match'];
  230. //获取 不同状态的查询条件
  231. $where = $this->commonFunction->getState('StRollBall',$model_match,$v['game_code']);
  232. //获取滚球数据
  233. $match_data= $this->getTypeData->getRollBall('',$models,$where,$v);
  234. if(!empty($match_data)){
  235. foreach($match_data as $kk=>$vv){
  236. $matchNum[] = $vv['matchNum'];
  237. }
  238. }
  239. }
  240. }
  241. $matchNum = array_sum($matchNum);
  242. return $matchNum;
  243. }
  244. }