ResultMatch.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace App\Sports\Controller;
  3. use BaseController\Controller;
  4. use Biz\Match\GetmatchData;
  5. use Biz\Match\GetOddsData;
  6. /**
  7. * 前台赛果数据接口
  8. * User: tank
  9. * Date: 2019/9/24
  10. */
  11. class ResultMatch extends Controller{
  12. public function init() {
  13. $this->commonFunction = C()->get('commonFunction');
  14. $this->getTypeData = new GetmatchData();
  15. $this->getOddsData = new GetOddsData();
  16. }
  17. /**
  18. * 获取各球类赛果数据
  19. */
  20. public function getMatchResult(){
  21. //获取球类代码
  22. $game_code = $_REQUEST['game_code'];
  23. //获取开赛日期
  24. $match_date = $_REQUEST['match_date'];
  25. try {
  26. if(empty($game_code) || empty($match_date)){
  27. throw new \Exception(Render([], '10001', lang('Tips','Sports')->get('PARAM_ERROR')));
  28. }
  29. //获取球类 model
  30. $getModels = $this->commonFunction->getModels($game_code);
  31. $model_result_express = $getModels['model_result_express'];
  32. //拼装查询条件
  33. $where = [
  34. ['match_date','=',$match_date]
  35. ];
  36. //获取赛果数据
  37. //获取联赛数据
  38. $match_result_league= lm($model_result_express,"Sports")
  39. ->select('league_id','league_name')
  40. ->where($where)
  41. ->groupBy('league_id','league_name')
  42. ->orderBy('league_id','asc')
  43. ->get()
  44. ->toArray();
  45. //获取各球类查询字段
  46. if($game_code == 'zq'){
  47. $select = ['league_id','league_name','match_date','match_time','home_team','guest_team','score_half','score_full','play_data','c_time','source','match_id'];
  48. }
  49. if($game_code == 'lq'){
  50. $select = ['league_id','league_name','match_date','match_time','home_team','guest_team','score_half','score_below','score_result','play_data','c_time','source','match_id'];
  51. }
  52. if($game_code == 'wq'){
  53. $select = ['league_id','league_name','match_date','match_time','home_team','guest_team','score_half','score_full','score_result','play_data','c_time','source','match_id'];
  54. }
  55. if($game_code == 'bq'){
  56. $select = ['league_id','league_name','match_date','match_time','home_team','guest_team','score_half','score_full','score_result','play_data','c_time','source','match_id'];
  57. }
  58. //获取赛事数据
  59. $match_result_match = lm($model_result_express,"Sports")
  60. ->select($select)
  61. ->where($where)
  62. ->get()
  63. ->toArray();
  64. //拼装数据
  65. $match_result_data = [];
  66. if(!empty($match_result_league) and !empty($match_result_match)){
  67. foreach($match_result_league as $k=>$v){
  68. foreach($match_result_match as $kk=>$vv){
  69. if($v['league_id'] == $vv['league_id']){
  70. $vv['play_data'] = \json_decode($vv['play_data'],true);
  71. $v['match_data'][] = $vv;
  72. }
  73. }
  74. $match_result_data[$k] = $v;
  75. }
  76. }
  77. $data = [$match_result_league,$match_result_data];
  78. Render($data, '1', lang('Tips','Sports')->get('success'));
  79. } catch (\Exception $e) {
  80. echo $e->getMessage();
  81. }
  82. }
  83. }