St_zq_competition.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. namespace App\Sports\Model;
  3. use \System\Model;
  4. /**
  5. * Class St_zq_competition
  6. * @package App\Sports\Model
  7. * 足球赛事
  8. */
  9. class St_zq_competition extends Model
  10. {
  11. protected $table = 'st_zq_competition';
  12. public function init() {
  13. // $this->commonFunction = C()->get('commonFunction');
  14. }
  15. /**
  16. * @param array $where 条件
  17. * @param string $select 字段
  18. * @param string $sort 排序字段
  19. * @param string $orderby 排序方式
  20. * @return mixed
  21. * 获取赛事数据
  22. */
  23. public static function getMatchData($where=[],$select='id',$sort='id',$orderby='asc'){
  24. $matchData = self::select($select)->where($where)->orderBy($sort,$orderby)->get();
  25. return $matchData;
  26. }
  27. /*
  28. * 获取各球类 滚球赛事关联赛事结果数据
  29. */
  30. public static function getRollMatchDataAll($source,$models,$where,$lg_ids=[],$ret){
  31. $model_match = $models['model_match'];
  32. $model_result = $models['model_result'];
  33. $game_code = $ret['game_code'];
  34. $select = [$model_match.'.lg_id',$model_match.'.id as match_id',$model_match.'.tag','match_date',$model_match.'.match_time',$model_match.'.home_team',$model_match.'.guest_team'];
  35. //获取赛事数据
  36. $matchData = lm($model_match,"Sports")
  37. ->select($select)
  38. ->whereIn($model_match.'.lg_id',$lg_ids)
  39. ->where($where)
  40. ->get()
  41. ->toarray();
  42. $match_ids = [];
  43. foreach ($matchData as $k=>$v){
  44. $match_ids[] = $v['match_id'];
  45. }
  46. //查询 赛事结果记录最新的一条
  47. $match_ids_str = implode(",", $match_ids);
  48. $result_record = $models['model_result_record'];
  49. //如果是网球
  50. // if($result_record == 'st_wq_result_record'){
  51. // $sql = "select a.match_id,a.home_player_score,a.guest_player_score,a.match_time as a_time,a.match_process from $result_record a,
  52. // (select match_id,max(id) id from $result_record where match_id IN ($match_ids_str) group by match_id)b
  53. // where a.match_id = b.match_id and a.id = b.id ";
  54. // }else{
  55. // $sql = "select a.match_id,a.home_score,a.guest_score,a.match_time as a_time,a.match_process from $result_record a,
  56. // (select match_id,max(id) id from $result_record where match_id IN ($match_ids_str) group by match_id)b
  57. // where a.match_id = b.match_id and a.id = b.id ";
  58. // }
  59. //如果是网球
  60. if($game_code == 'wq'){
  61. $sql = "select a.match_id,a.home_player_score,a.guest_player_score,a.match_time as a_time,a.match_process,a.result_mark from $result_record a,
  62. (select match_id,max(id) id from $result_record where match_id IN ($match_ids_str) group by match_id)b
  63. where a.match_id = b.match_id and a.id = b.id ";
  64. }else
  65. //如果是棒球
  66. if($game_code == 'bq'){
  67. $sql = "select a.match_id,a.home_score,a.guest_score,a.match_time as a_time,a.match_process,a.result_mark from $result_record a,
  68. (select match_id,max(id) id from $result_record where match_id IN ($match_ids_str) group by match_id)b
  69. where a.match_id = b.match_id and a.id = b.id ";
  70. }else{
  71. //其他球类
  72. $sql = "select a.match_id,a.home_score,a.guest_score,a.match_time as a_time,a.match_process from $result_record a,
  73. (select match_id,max(id) id from $result_record where match_id IN ($match_ids_str) group by match_id)b
  74. where a.match_id = b.match_id and a.id = b.id ";
  75. }
  76. $match_result_record = S ('DB')->select ($sql);
  77. //处理赛事数据,追加比分及进程
  78. if(!empty($matchData)){
  79. foreach ($matchData as $k=>$v){
  80. if( !empty($match_result_record)){
  81. foreach ($match_result_record as $kk => $vv){
  82. if($v['match_id'] == $vv->match_id){
  83. //如果是网球
  84. if($model_result == 'st_wq_result'){
  85. $matchData[$k]['home_player_score'] = $vv->home_player_score?:0;
  86. $matchData[$k]['guest_player_score'] = $vv->guest_player_score?:0;
  87. }else{
  88. $matchData[$k]['home_score'] = $vv->home_score?:0;
  89. $matchData[$k]['guest_score'] = $vv->guest_score?:0;
  90. }
  91. $matchData[$k]['a_time'] = $vv->a_time?:C()->get('commonFunction')->getMatchTime($v['match_date'],$v['match_time']);
  92. $matchData[$k]['match_process'] = $vv->match_process?:C()->get('commonFunction')->getMatchProcess( $matchData[$k]['a_time'],$ret['game_code']);
  93. }
  94. }
  95. }
  96. else{
  97. //如果是网球
  98. if($model_result == 'st_wq_result'){
  99. $matchData[$k]['home_player_score'] = 0;
  100. $matchData[$k]['guest_player_score'] = 0;
  101. }else{
  102. $matchData[$k]['home_score'] = 0;
  103. $matchData[$k]['guest_score'] = 0;
  104. }
  105. $matchData[$k]['a_time'] = C()->get('commonFunction')->getMatchTime($v['match_date'],$v['match_time']);
  106. $matchData[$k]['match_process'] = C()->get('commonFunction')->getMatchProcess( $matchData[$k]['a_time'],$ret['game_code']);
  107. }
  108. }
  109. }
  110. return $matchData;
  111. }
  112. /*
  113. * 获取各球类 非滚球赛事关联赛事结果数据
  114. */
  115. public static function getSoonMatchDataAll($source,$models,$where,$lg_ids=[]){
  116. $model_match = $models['model_match'];
  117. $data = lm($model_match,"Sports")
  118. ->select($model_match.'.lg_id',$model_match.'.id as match_id',$model_match.'.tag','match_date',$model_match.'.match_time',$model_match.'.home_team',$model_match.'.guest_team',$model_match.'.us_time')
  119. ->where($where)
  120. ->whereIn($model_match.'.lg_id',$lg_ids)
  121. ->orderBy('match_time','asc')
  122. ->get()
  123. ->toarray();
  124. return $data;
  125. }
  126. }