St_zq_competition.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. if(!empty($lg_ids)){
  37. $matchData = lm($model_match,"Sports")
  38. ->select($select)
  39. ->whereIn($model_match.'.lg_id',$lg_ids)
  40. ->where($where)
  41. ->get()
  42. ->toarray();
  43. }else{
  44. $matchData = lm($model_match,"Sports")
  45. ->select($select)
  46. ->where($where)
  47. ->get()
  48. ->toarray();
  49. }
  50. if(empty($matchData)) return $matchData;
  51. $match_ids = [];
  52. foreach ($matchData as $k=>$v){
  53. $match_ids[] = $v['match_id'];
  54. }
  55. //查询 赛事结果记录最新的一条
  56. $match_ids_str = implode(",", $match_ids);
  57. $result_record = $models['model_result_record'];
  58. //如果是网球
  59. // if($result_record == 'st_wq_result_record'){
  60. // $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,
  61. // (select match_id,max(id) id from $result_record where match_id IN ($match_ids_str) group by match_id)b
  62. // where a.match_id = b.match_id and a.id = b.id ";
  63. // }else{
  64. // $sql = "select a.match_id,a.home_score,a.guest_score,a.match_time as a_time,a.match_process from $result_record a,
  65. // (select match_id,max(id) id from $result_record where match_id IN ($match_ids_str) group by match_id)b
  66. // where a.match_id = b.match_id and a.id = b.id ";
  67. // }
  68. //如果是网球
  69. if($game_code == 'wq'){
  70. $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,
  71. (select match_id,max(id) id from $result_record where match_id IN ($match_ids_str) group by match_id)b
  72. where a.match_id = b.match_id and a.id = b.id ";
  73. }else
  74. //如果是棒球
  75. if($game_code == 'bq' || $game_code == 'lq'){
  76. $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,
  77. (select match_id,max(id) id from $result_record where match_id IN ($match_ids_str) group by match_id)b
  78. where a.match_id = b.match_id and a.id = b.id ";
  79. }else{
  80. //其他球类
  81. $sql = "select a.match_id,a.home_score,a.guest_score,a.match_time as a_time,a.match_process from $result_record a,
  82. (select match_id,max(id) id from $result_record where match_id IN ($match_ids_str) group by match_id)b
  83. where a.match_id = b.match_id and a.id = b.id ";
  84. }
  85. $match_result_record = S ('DB')->select ($sql);
  86. //处理赛事数据,追加比分及进程
  87. /*
  88. if(!empty($matchData)){
  89. foreach ($matchData as $k=>$v){
  90. if( !empty($match_result_record)){
  91. foreach ($match_result_record as $kk => $vv){
  92. if($v['match_id'] == $vv->match_id){
  93. //如果是网球
  94. if($model_result == 'st_wq_result'){
  95. $matchData[$k]['home_player_score'] = $vv->home_player_score?:0;
  96. $matchData[$k]['guest_player_score'] = $vv->guest_player_score?:0;
  97. }else{
  98. $matchData[$k]['home_score'] = $vv->home_score?:0;
  99. $matchData[$k]['guest_score'] = $vv->guest_score?:0;
  100. }
  101. $matchData[$k]['a_time'] = $vv->a_time?:C()->get('commonFunction')->getMatchTime($v['match_date'],$v['match_time']);
  102. $matchData[$k]['match_process'] = $vv->match_process?:C()->get('commonFunction')->getMatchProcess( $matchData[$k]['a_time'],$ret['game_code']);
  103. }
  104. }
  105. }
  106. else{
  107. //如果是网球
  108. if($model_result == 'st_wq_result'){
  109. $matchData[$k]['home_player_score'] = 0;
  110. $matchData[$k]['guest_player_score'] = 0;
  111. }else{
  112. $matchData[$k]['home_score'] = 0;
  113. $matchData[$k]['guest_score'] = 0;
  114. }
  115. $matchData[$k]['a_time'] = C()->get('commonFunction')->getMatchTime($v['match_date'],$v['match_time']);
  116. $matchData[$k]['match_process'] = C()->get('commonFunction')->getMatchProcess( $matchData[$k]['a_time'],$ret['game_code']);
  117. }
  118. }
  119. }
  120. */
  121. if(!empty($matchData)){
  122. foreach ($matchData as $k=>$v){
  123. if( !empty($match_result_record)){
  124. foreach ($match_result_record as $kk => $vv){
  125. if($v['match_id'] == $vv->match_id){
  126. //如果是网球
  127. if($model_result == 'st_wq_result'){
  128. $matchData[$k]['home_player_score'] = $vv->home_player_score?:0;
  129. $matchData[$k]['guest_player_score'] = $vv->guest_player_score?:0;
  130. }else{
  131. $matchData[$k]['home_score'] = $vv->home_score?:0;
  132. $matchData[$k]['guest_score'] = $vv->guest_score?:0;
  133. }
  134. $matchData[$k]['result_mark'] = $vv->result_mark;
  135. $matchData[$k]['a_time'] = $vv->a_time;//?:C()->get('commonFunction')->getMatchTime($v['match_date'],$v['match_time']);
  136. $matchData[$k]['match_process'] = $vv->match_process;//?:C()->get('commonFunction')->getMatchProcess( $matchData[$k]['a_time'],$ret['game_code']);
  137. }
  138. }
  139. }
  140. else{
  141. //如果是网球
  142. if($model_result == 'st_wq_result'){
  143. $matchData[$k]['home_player_score'] = 0;
  144. $matchData[$k]['guest_player_score'] = 0;
  145. }else{
  146. $matchData[$k]['home_score'] = 0;
  147. $matchData[$k]['guest_score'] = 0;
  148. }
  149. $matchData[$k]['result_mark'] = '';
  150. $matchData[$k]['a_time'] = 0;//C()->get('commonFunction')->getMatchTime($v['match_date'],$v['match_time']);
  151. $matchData[$k]['match_process'] = '';//C()->get('commonFunction')->getMatchProcess( $matchData[$k]['a_time'],$ret['game_code']);
  152. }
  153. }
  154. //追加当赛事数量为N ,赛事结果记录< N时的处理
  155. foreach($matchData as $k=>$v){
  156. if(count($v) < 10){
  157. //如果是网球
  158. if($model_result == 'st_wq_result'){
  159. $matchData[$k]['home_player_score'] = 0;
  160. $matchData[$k]['guest_player_score'] = 0;
  161. }else{
  162. $matchData[$k]['home_score'] = 0;
  163. $matchData[$k]['guest_score'] = 0;
  164. }
  165. $matchData[$k]['a_time'] = 0;// C()->get('commonFunction')->getMatchTime($v['match_date'],$v['match_time']);
  166. $matchData[$k]['match_process'] = '';//C()->get('commonFunction')->getMatchProcess( $matchData[$k]['a_time'],$ret['game_code']);
  167. }
  168. }
  169. }
  170. return $matchData;
  171. }
  172. /*
  173. * 获取各球类 非滚球赛事关联赛事结果数据
  174. */
  175. public static function getSoonMatchDataAll($source,$models,$where,$lg_ids=[]){
  176. $model_match = $models['model_match'];
  177. $data = lm($model_match,"Sports")
  178. ->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')
  179. ->where($where)
  180. ->whereIn($model_match.'.lg_id',$lg_ids)
  181. ->orderBy('match_time','asc')
  182. ->get()
  183. ->toarray();
  184. return $data;
  185. }
  186. }