St_zq_competition.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. $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'];
  34. //获取赛事数据
  35. $matchData = lm($model_match,"Sports")
  36. ->select($select)
  37. ->whereIn($model_match.'.lg_id',$lg_ids)
  38. ->where($where)
  39. ->get()
  40. ->toarray();
  41. $match_ids = [];
  42. foreach ($matchData as $k=>$v){
  43. $match_ids[] = $v['match_id'];
  44. }
  45. //查询 赛事结果记录最新的一条
  46. $match_ids_str = implode(",", $match_ids);
  47. $result_record = $models['model_result_record'];
  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. }else{
  54. $sql = "select a.match_id,a.home_score,a.guest_score,a.match_time as a_time,a.match_process from $result_record a,
  55. (select match_id,max(id) id from $result_record where match_id IN ($match_ids_str) group by match_id)b
  56. where a.match_id = b.match_id and a.id = b.id ";
  57. }
  58. $match_result_record = S ('DB')->select ($sql);
  59. //处理赛事数据,追加比分及进程
  60. if(!empty($matchData)){
  61. foreach ($matchData as $k=>$v){
  62. if( !empty($match_result_record)){
  63. foreach ($match_result_record as $kk => $vv){
  64. if($v['match_id'] == $vv->match_id){
  65. //如果是网球
  66. if($model_result == 'st_wq_result'){
  67. $matchData[$k]['home_player_score'] = $vv->home_player_score?:0;
  68. $matchData[$k]['guest_player_score'] = $vv->guest_player_score?:0;
  69. }else{
  70. $matchData[$k]['home_score'] = $vv->home_score?:0;
  71. $matchData[$k]['guest_score'] = $vv->guest_score?:0;
  72. }
  73. $matchData[$k]['a_time'] = $vv->a_time?:C()->get('commonFunction')->getMatchTime($v['match_date'],$v['match_time']);
  74. $matchData[$k]['match_process'] = $vv->match_process?:C()->get('commonFunction')->getMatchProcess( $matchData[$k]['a_time'],$ret['game_code']);
  75. }
  76. }
  77. }else{
  78. //如果是网球
  79. if($model_result == 'st_wq_result'){
  80. $matchData[$k]['home_player_score'] = 0;
  81. $matchData[$k]['guest_player_score'] = 0;
  82. }else{
  83. $matchData[$k]['home_score'] = 0;
  84. $matchData[$k]['guest_score'] = 0;
  85. }
  86. $matchData[$k]['a_time'] = 0;
  87. $matchData[$k]['match_process'] = '';
  88. }
  89. }
  90. }
  91. return $matchData;
  92. }
  93. /*
  94. * 获取各球类 非滚球赛事关联赛事结果数据
  95. */
  96. public static function getSoonMatchDataAll($source,$models,$where,$lg_ids=[]){
  97. $model_match = $models['model_match'];
  98. $data = lm($model_match,"Sports")
  99. ->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')
  100. ->where($where)
  101. ->whereIn($model_match.'.lg_id',$lg_ids)
  102. ->orderBy('match_time','asc')
  103. ->get()
  104. ->toarray();
  105. return $data;
  106. }
  107. }