Head.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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. $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. $where = [
  154. ['type','=',1],
  155. // ['source','=',$this->source]
  156. ];
  157. $select = ['match_id','type'];
  158. $ZQoddsData = ZQoddsModel::getOddsData($where,$select)->toArray();
  159. $LQoddsData = LQoddsModel::getOddsData($where,$select)->toArray();
  160. $WQoddsData = WQoddsModel::getOddsData($where,$select)->toArray();
  161. $BQoddsData = BQoddsModel::getOddsData($where,$select)->toArray();
  162. //合并所有球类冠军盘口
  163. $oddsAll = array_merge_recursive($ZQoddsData,$LQoddsData,$WQoddsData,$BQoddsData);
  164. $StRollBall = [];
  165. $StSoon = [];
  166. $StToday = [];
  167. $StMorningPlate = [];
  168. $StStringScene = [];
  169. //获取当天结束时间戳
  170. $endTime = mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
  171. //按状态条件分装数组
  172. foreach ($matchAll as $kk=>$vv){
  173. //滚球
  174. if($vv['status'] == 1 ){
  175. $StRollBall[] = $vv;
  176. }
  177. //即将
  178. 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())){
  179. $StSoon[] = $vv;
  180. }
  181. //今日
  182. if($vv['match_date'] == date("Y-m-d") and $vv['match_time'] > date("H:i:s", time()) and $vv['status'] < 2){
  183. $StToday[] = $vv;
  184. }
  185. //早盘
  186. if($vv['us_time'] > $this->commonFunction->qgmdate('Y-m-d H:i:s', $endTime, -4) and $vv['status'] < 2 ){
  187. $StMorningPlate[] = $vv;
  188. }
  189. //串场
  190. if($vv['is_stringscene'] == 1 and $vv['us_time'] > $this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4) and $vv['status'] < 2){
  191. $StStringScene[] = $vv;
  192. }
  193. }
  194. //获取所有状态
  195. $type = lang('GameTypes','Sports')->getAll();
  196. foreach ($type as $k=>$v){
  197. switch ($v['type_code']) {
  198. case 'StRollBall'://滚球
  199. $type[$k]['matchNum'] = count($StRollBall);
  200. // $type[$k]['matchNum'] = $this->getRollBallNum();
  201. break;
  202. case 'StSoon'://即将
  203. $type[$k]['matchNum'] = count($StSoon);
  204. break;
  205. case 'StToday'://今日
  206. $type[$k]['matchNum'] = count($StToday);
  207. break;
  208. case 'StMorningPlate'://早盘
  209. $type[$k]['matchNum'] = count($StMorningPlate);
  210. break;
  211. case 'StStringScene'://串场
  212. $type[$k]['matchNum'] = count($StStringScene);
  213. break;
  214. case 'StChampion'://冠军
  215. $type[$k]['matchNum'] = count($oddsAll);
  216. break;
  217. default:
  218. throw new \Exception(Render([], '10002', lang('Tips', 'Sports')->get('PARAM_ERROR')));
  219. }
  220. }
  221. Render($type, '1', lang('Tips','Sports')->get('success'));
  222. }
  223. /**
  224. * 获取各球类滚球数量
  225. */
  226. public function getRollBallNum(){
  227. $ret = lm('GameType', 'Sports')->select('id','game_code')->where('status',1)->get()->toArray();
  228. //滚球赛事数量
  229. $matchNum = [];
  230. foreach($ret as $k=>$v){
  231. if($v['game_code'] != 'gj'){
  232. //根据球类代码 获取相关model
  233. $models = $this->commonFunction->getModels($v['game_code']);
  234. $model_match = $models['model_match'];
  235. //获取 不同状态的查询条件
  236. $where = $this->commonFunction->getState('StRollBall',$model_match,$v['game_code']);
  237. //获取滚球数据
  238. $match_data= $this->getTypeData->getRollBall('',$models,$where,$v);
  239. if(!empty($match_data)){
  240. foreach($match_data as $kk=>$vv){
  241. $matchNum[] = $vv['matchNum'];
  242. }
  243. }
  244. }
  245. }
  246. $matchNum = array_sum($matchNum);
  247. return $matchNum;
  248. }
  249. }