Head.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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)->where([['id','<',12]])->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. $endTime = mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
  78. //按状态条件分装数组
  79. foreach ($matchAll as $kk=>$vv){
  80. //滚球
  81. // 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())){
  82. // $StRollBall[] = $vv;
  83. // }
  84. if($vv['status'] == 1 ){
  85. $StRollBall[] = $vv;
  86. }
  87. //即将
  88. 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())){
  89. $StSoon[] = $vv;
  90. }
  91. //今日
  92. if($vv['match_date'] == date("Y-m-d") and $vv['match_time'] > date("H:i:s", time()) and $vv['status'] < 2){
  93. $StToday[] = $vv;
  94. }
  95. //早盘
  96. if($vv['us_time'] > $this->commonFunction->qgmdate('Y-m-d H:i:s', $endTime, -4) and $vv['status'] < 2 ){
  97. $StMorningPlate[] = $vv;
  98. }
  99. //串场
  100. if($vv['is_stringscene'] == 1 and $vv['us_time'] > $this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4) and $vv['status'] < 2){
  101. $StStringScene[] = $vv;
  102. }
  103. }
  104. //获取所有状态
  105. $type = lang('GameTypes','Sports')->getAll();
  106. foreach ($type as $k=>$v){
  107. switch ($v['type_code']) {
  108. case 'StRollBall'://滚球
  109. $type[$k]['matchNum'] = count($StRollBall);
  110. break;
  111. case 'StSoon'://即将
  112. $type[$k]['matchNum'] = count($StSoon);
  113. break;
  114. case 'StToday'://今日
  115. $type[$k]['matchNum'] = count($StToday);
  116. break;
  117. case 'StMorningPlate'://早盘
  118. $type[$k]['matchNum'] = count($StMorningPlate);
  119. break;
  120. case 'StStringScene'://串场
  121. $type[$k]['matchNum'] = count($StStringScene);
  122. break;
  123. case 'StChampion'://冠军
  124. $type[$k]['matchNum'] = count($oddsAll);
  125. break;
  126. default:
  127. throw new \Exception(Render([], '10002', lang('Tips', 'Sports')->get('PARAM_ERROR')));
  128. }
  129. }
  130. Render($type, '1', lang('Tips','Sports')->get('success'));
  131. }
  132. public function typeList_v2(){
  133. //获取所有未结束赛事
  134. $where = [
  135. ['status','<','2']
  136. ];
  137. $zqModel = $this->commonFunction->getModels('zq');
  138. $lqModel = $this->commonFunction->getModels('lq');
  139. $wqModel = $this->commonFunction->getModels('wq');
  140. $bqModel = $this->commonFunction->getModels('bq');
  141. $ZQmatchData = leagueModel::getLeagueMatchData($zqModel,$where,'zq');
  142. $LQmatchData = leagueModel::getLeagueMatchData($lqModel,$where,'lq');
  143. $WQmatchData = leagueModel::getLeagueMatchData($wqModel,$where,'wq');
  144. $BQmatchData = leagueModel::getLeagueMatchData($bqModel,$where,'bq');
  145. //处理空赔率赛事
  146. $ZQmatchData = $this->commonFunction->Handle_Odds_Null($ZQmatchData,$zqModel);
  147. $LQmatchData = $this->commonFunction->Handle_Odds_Null($LQmatchData,$lqModel);
  148. $WQmatchData = $this->commonFunction->Handle_Odds_Null($WQmatchData,$wqModel);
  149. $BQmatchData = $this->commonFunction->Handle_Odds_Null($BQmatchData,$bqModel);
  150. //合并所有球类赛事
  151. $matchAll = array_merge_recursive($ZQmatchData,$LQmatchData,$WQmatchData,$BQmatchData);
  152. /*
  153. //获取所有冠军盘口
  154. $where = [
  155. ['type','=',1],
  156. // ['source','=',$this->source]
  157. ];
  158. $select = ['match_id','type'];
  159. $ZQoddsData = ZQoddsModel::getOddsData($where,$select)->toArray();
  160. $LQoddsData = LQoddsModel::getOddsData($where,$select)->toArray();
  161. $WQoddsData = WQoddsModel::getOddsData($where,$select)->toArray();
  162. $BQoddsData = BQoddsModel::getOddsData($where,$select)->toArray();
  163. //合并所有球类冠军盘口
  164. $oddsAll = array_merge_recursive($ZQoddsData,$LQoddsData,$WQoddsData,$BQoddsData);
  165. */
  166. $StRollBall = [];
  167. $StSoon = [];
  168. $StToday = [];
  169. $StMorningPlate = [];
  170. $StStringScene = [];
  171. //获取当天结束时间戳
  172. $endTime = mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
  173. //按状态条件分装数组
  174. foreach ($matchAll as $kk=>$vv){
  175. //滚球
  176. if($vv['status'] == 1 ){
  177. $StRollBall[] = $vv;
  178. }
  179. //即将
  180. 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())){
  181. $StSoon[] = $vv;
  182. }
  183. //今日
  184. if($vv['match_date'] == date("Y-m-d") and $vv['match_time'] > date("H:i:s", time()) and $vv['status'] < 2){
  185. $StToday[] = $vv;
  186. }
  187. //早盘
  188. if($vv['us_time'] > $this->commonFunction->qgmdate('Y-m-d H:i:s', $endTime, -4) and $vv['status'] < 2 ){
  189. $StMorningPlate[] = $vv;
  190. }
  191. //串场
  192. if($vv['is_stringscene'] == 1 and $vv['us_time'] > $this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4) and $vv['status'] < 2){
  193. $StStringScene[] = $vv;
  194. }
  195. }
  196. //获取所有状态
  197. $type = lang('GameTypes','Sports')->getAll();
  198. foreach ($type as $k=>$v){
  199. switch ($v['type_code']) {
  200. case 'StRollBall'://滚球
  201. $type[$k]['matchNum'] = count($StRollBall);
  202. // $type[$k]['matchNum'] = $this->getRollBallNum();
  203. break;
  204. case 'StSoon'://即将
  205. $type[$k]['matchNum'] = count($StSoon);
  206. break;
  207. case 'StToday'://今日
  208. $type[$k]['matchNum'] = count($StToday);
  209. break;
  210. case 'StMorningPlate'://早盘
  211. $type[$k]['matchNum'] = count($StMorningPlate);
  212. break;
  213. case 'StStringScene'://串场
  214. $type[$k]['matchNum'] = count($StStringScene);
  215. break;
  216. case 'StChampion'://冠军
  217. $type[$k]['matchNum'] = count($oddsAll);
  218. break;
  219. default:
  220. throw new \Exception(Render([], '10002', lang('Tips', 'Sports')->get('PARAM_ERROR')));
  221. }
  222. }
  223. Render($type, '1', lang('Tips','Sports')->get('success'));
  224. }
  225. /**
  226. * 获取各球类滚球数量
  227. */
  228. public function getRollBallNum(){
  229. $ret = lm('GameType', 'Sports')->select('id','game_code')->where('status',1)->get()->toArray();
  230. //滚球赛事数量
  231. $matchNum = [];
  232. foreach($ret as $k=>$v){
  233. if($v['game_code'] != 'gj'){
  234. //根据球类代码 获取相关model
  235. $models = $this->commonFunction->getModels($v['game_code']);
  236. $model_match = $models['model_match'];
  237. //获取 不同状态的查询条件
  238. $where = $this->commonFunction->getState('StRollBall',$model_match,$v['game_code']);
  239. //获取滚球数据
  240. $match_data= $this->getTypeData->getRollBall('',$models,$where,$v);
  241. if(!empty($match_data)){
  242. foreach($match_data as $kk=>$vv){
  243. $matchNum[] = $vv['matchNum'];
  244. }
  245. }
  246. }
  247. }
  248. $matchNum = array_sum($matchNum);
  249. return $matchNum;
  250. }
  251. }