St_zq_competition.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. $sql = "select a.match_id,a.home_score,a.guest_score,a.match_time as a_time,a.match_process from $result_record a,
  46. (select match_id,max(id) id from $result_record where match_id IN ($match_ids_str) group by match_id)b
  47. where a.match_id = b.match_id and a.id = b.id ";
  48. //如果是网球
  49. if($result_record == 'st_wq_result_record'){
  50. $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,
  51. (select match_id,max(id) id from $result_record where match_id IN ($match_ids_str) group by match_id)b
  52. where a.match_id = b.match_id and a.id = b.id ";
  53. }
  54. $match_result_record = S ('DB')->select ($sql);
  55. //处理赛事数据,追加比分及进程
  56. foreach ($matchData as $k=>$v){
  57. foreach ($match_result_record as $kk => $vv){
  58. if($v['match_id'] == $vv->match_id){
  59. //如果是网球
  60. if($model_result == 'st_wq_result'){
  61. $matchData[$k]['home_player_score'] = $vv->home_player_score;
  62. $matchData[$k]['guest_player_score'] = $vv->guest_player_score;
  63. }else{
  64. $matchData[$k]['home_score'] = $vv->home_score;
  65. $matchData[$k]['guest_score'] = $vv->guest_score;
  66. }
  67. $matchData[$k]['a_time'] = $vv->a_time;
  68. $matchData[$k]['match_process'] = $vv->match_process;
  69. }
  70. }
  71. }
  72. return $matchData;
  73. }
  74. /*
  75. * 获取各球类 非滚球赛事关联赛事结果数据
  76. */
  77. public static function getSoonMatchDataAll($source,$models,$where,$lg_ids=[]){
  78. $model_match = $models['model_match'];
  79. $data = lm($model_match,"Sports")
  80. ->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')
  81. ->where($where)
  82. ->whereIn($model_match.'.lg_id',$lg_ids)
  83. ->orderBy('match_time','asc')
  84. ->get()
  85. ->toarray();
  86. return $data;
  87. }
  88. }