St_zq_competition.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace App\Sports\Model;
  3. use \System\Model;
  4. /**
  5. * Class Account
  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. public static function getRollMatchDataAll($source,$models,$where,$lg_ids=[]){
  26. $model_match = $models['model_match'];
  27. $model_result = $models['model_result'];
  28. $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'];
  29. //获取赛事数据
  30. $matchData = lm($model_match,"Sports")
  31. ->select($select)
  32. ->whereIn($model_match.'.lg_id',$lg_ids)
  33. ->where($where)
  34. ->get()
  35. ->toarray();
  36. $match_ids = [];
  37. foreach ($matchData as $k=>$v){
  38. $match_ids[] = $v['match_id'];
  39. }
  40. //查询 赛事结果记录最新的一条
  41. $match_ids_str = implode(",", $match_ids);
  42. $result_record = $models['model_result_record'];
  43. $sql = "select a.match_id,a.home_score,a.guest_score,a.match_time as a_time,a.match_process from $result_record a,
  44. (select match_id,max(id) id from $result_record where match_id IN ($match_ids_str) group by match_id)b
  45. where a.match_id = b.match_id and a.id = b.id ";
  46. //如果是网球
  47. if($result_record == 'st_wq_result_record'){
  48. $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,
  49. (select match_id,max(id) id from $result_record where match_id IN ($match_ids_str) group by match_id)b
  50. where a.match_id = b.match_id and a.id = b.id ";
  51. }
  52. $match_result_record = S ('DB')->select ($sql);
  53. //处理赛事数据,追加比分及进程
  54. foreach ($matchData as $k=>$v){
  55. foreach ($match_result_record as $kk => $vv){
  56. if($v['match_id'] == $vv->match_id){
  57. //如果是网球
  58. if($model_result == 'st_wq_result'){
  59. $matchData[$k]['home_player_score'] = $vv->home_player_score;
  60. $matchData[$k]['guest_player_score'] = $vv->guest_player_score;
  61. }else{
  62. $matchData[$k]['home_score'] = $vv->home_score;
  63. $matchData[$k]['guest_score'] = $vv->guest_score;
  64. }
  65. $matchData[$k]['a_time'] = $vv->a_time;
  66. $matchData[$k]['match_process'] = $vv->match_process;
  67. }
  68. }
  69. }
  70. return $matchData;
  71. }
  72. //获取各球类 非滚球赛事关联赛事结果数据
  73. public static function getSoonMatchDataAll($source,$models,$where,$lg_ids=[]){
  74. $model_match = $models['model_match'];
  75. $data = lm($model_match,"Sports")
  76. ->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')
  77. // ->where($source)
  78. ->where($where)
  79. ->whereIn($model_match.'.lg_id',$lg_ids)
  80. ->orderBy('match_time','asc')
  81. ->get()
  82. ->toarray();
  83. return $data;
  84. }
  85. }