St_zq_competition.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. /**
  13. * @param array $where 条件
  14. * @param string $select 字段
  15. * @param string $sort 排序字段
  16. * @param string $orderby 排序方式
  17. * @return mixed
  18. * 获取赛事数据
  19. */
  20. public static function getMatchData($where=[],$select='id',$sort='id',$orderby='asc'){
  21. $matchData = self::select($select)->where($where)->orderBy($sort,$orderby)->get();
  22. return $matchData;
  23. }
  24. /*
  25. * 获取各球类 滚球赛事关联赛事结果数据
  26. */
  27. public static function getRollMatchDataAll($source,$models,$where,$lg_ids=[]){
  28. $model_match = $models['model_match'];
  29. $model_result = $models['model_result'];
  30. $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'];
  31. //获取赛事数据
  32. $matchData = lm($model_match,"Sports")
  33. ->select($select)
  34. ->whereIn($model_match.'.lg_id',$lg_ids)
  35. ->where($where)
  36. ->get()
  37. ->toarray();
  38. $match_ids = [];
  39. foreach ($matchData as $k=>$v){
  40. $match_ids[] = $v['match_id'];
  41. }
  42. //查询 赛事结果记录最新的一条
  43. $match_ids_str = implode(",", $match_ids);
  44. $result_record = $models['model_result_record'];
  45. //如果是网球
  46. if($result_record == 'st_wq_result_record'){
  47. $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,
  48. (select match_id,max(id) id from $result_record where match_id IN ($match_ids_str) group by match_id)b
  49. where a.match_id = b.match_id and a.id = b.id ";
  50. }else{
  51. $sql = "select a.match_id,a.home_score,a.guest_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. }
  55. $match_result_record = S ('DB')->select ($sql);
  56. //处理赛事数据,追加比分及进程
  57. if(!empty($matchData)){
  58. foreach ($matchData as $k=>$v){
  59. if( !empty($match_result_record)){
  60. foreach ($match_result_record as $kk => $vv){
  61. if($v['match_id'] == $vv->match_id){
  62. //如果是网球
  63. if($model_result == 'st_wq_result'){
  64. $matchData[$k]['home_player_score'] = $vv->home_player_score?:0;
  65. $matchData[$k]['guest_player_score'] = $vv->guest_player_score?:0;
  66. }else{
  67. $matchData[$k]['home_score'] = $vv->home_score?:0;
  68. $matchData[$k]['guest_score'] = $vv->guest_score?:0;
  69. }
  70. $matchData[$k]['a_time'] = $vv->a_time?:0;
  71. $matchData[$k]['match_process'] = $vv->match_process?:'';
  72. }
  73. }
  74. }else{
  75. //如果是网球
  76. if($model_result == 'st_wq_result'){
  77. $matchData[$k]['home_player_score'] = 0;
  78. $matchData[$k]['guest_player_score'] = 0;
  79. }else{
  80. $matchData[$k]['home_score'] = 0;
  81. $matchData[$k]['guest_score'] = 0;
  82. }
  83. $matchData[$k]['a_time'] = 0;
  84. $matchData[$k]['match_process'] = '';
  85. }
  86. }
  87. }
  88. return $matchData;
  89. }
  90. /*
  91. * 获取各球类 非滚球赛事关联赛事结果数据
  92. */
  93. public static function getSoonMatchDataAll($source,$models,$where,$lg_ids=[]){
  94. $model_match = $models['model_match'];
  95. $data = lm($model_match,"Sports")
  96. ->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')
  97. ->where($where)
  98. ->whereIn($model_match.'.lg_id',$lg_ids)
  99. ->orderBy('match_time','asc')
  100. ->get()
  101. ->toarray();
  102. return $data;
  103. }
  104. }