浏览代码

优化状态赛事查询接口

彭俊 6 年之前
父节点
当前提交
7e2eeb371e

+ 98 - 1
Application/Sports/Controller/Head.php

@@ -37,7 +37,7 @@ class Head extends Controller{
     }
 
     //获取各状态下所有赛事数量
-    public function typeList(){
+    public function __typeList(){
         //获取所有未结束赛事
         $where = [
             ['status','<','2']
@@ -131,4 +131,101 @@ class Head extends Controller{
         Render($type, '1', lang('Tips','Sports')->get('success'));
 
     }
+
+
+    //重写方法
+    public function typeList(){
+        //获取所有未结束赛事
+        $where = [
+            ['status','<','2']
+        ];
+        $zqModel = $this->commonFunction->getModels('zq');
+        $lqModel = $this->commonFunction->getModels('lq');
+        $wqModel = $this->commonFunction->getModels('wq');
+        $bqModel = $this->commonFunction->getModels('bq');
+
+        $ZQmatchData = leagueModel::getLeagueMatchData($zqModel,$where,'zq'); 
+        $LQmatchData = leagueModel::getLeagueMatchData($lqModel,$where,'lq');
+        $WQmatchData = leagueModel::getLeagueMatchData($wqModel,$where,'wq');
+        $BQmatchData = leagueModel::getLeagueMatchData($bqModel,$where,'bq');
+
+        //处理空赔率赛事
+        $ZQmatchData = $this->commonFunction->Handle_Odds_Null($ZQmatchData,$zqModel);
+        $LQmatchData = $this->commonFunction->Handle_Odds_Null($LQmatchData,$lqModel);
+        $WQmatchData = $this->commonFunction->Handle_Odds_Null($WQmatchData,$wqModel);
+        $BQmatchData = $this->commonFunction->Handle_Odds_Null($BQmatchData,$bqModel);
+
+        //合并所有球类赛事
+        $matchAll = array_merge_recursive($ZQmatchData,$LQmatchData,$WQmatchData,$BQmatchData);
+
+        //获取所有冠军盘口
+        $where = [
+            ['type','=',1],
+            // ['source','=',$this->source]
+        ];
+        $select = ['match_id','type'];
+        $ZQoddsData = ZQoddsModel::getOddsData($where,$select)->toArray();
+        $LQoddsData = LQoddsModel::getOddsData($where,$select)->toArray(); 
+        $WQoddsData = WQoddsModel::getOddsData($where,$select)->toArray();
+        $BQoddsData = BQoddsModel::getOddsData($where,$select)->toArray();
+        //合并所有球类冠军盘口
+        $oddsAll = array_merge_recursive($ZQoddsData,$LQoddsData,$WQoddsData,$BQoddsData);
+     
+        $StRollBall = [];
+        $StSoon = [];
+        $StToday = [];
+        $StMorningPlate = [];
+        $StStringScene = [];
+        //按状态条件分装数组
+        foreach ($matchAll as $kk=>$vv){
+            //滚球
+            if($vv['status'] < 2 and $vv['match_date'] == date("Y-m-d") and $vv['match_time'] > date("H:i:s", time()-(90*60)) and $vv['match_time'] < date("H:i:s", time())){
+                $StRollBall[] = $vv;
+            }
+            //即将
+            if($vv['status'] == '0' and $vv['match_date'] == date("Y-m-d") and $vv['match_time'] < date("H:i:s", strtotime("+2 hour")) and $vv['match_time'] > date("H:i:s", time())){
+                $StSoon[] = $vv;
+            }
+            //今日
+            if($vv['match_date'] == date("Y-m-d") and $vv['match_time'] > date("H:i:s", time()) and $vv['status'] < 2){
+                $StToday[] = $vv;
+            }
+            //早盘
+            if($vv['is_morningplate'] == 1 and $vv['us_time'] > $this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4) and $vv['status'] < 2 and $vv['match_date'] > date("Y-m-d")){
+                $StMorningPlate[] = $vv;
+            }
+            //串场
+            if($vv['is_stringscene'] == 1 and $vv['us_time'] > $this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4) and $vv['status'] < 2){
+                $StStringScene[] = $vv;
+            }
+        }
+        //获取所有状态
+        $type = lang('GameTypes','Sports')->getAll();
+        foreach ($type as $k=>$v){
+            switch ($v['type_code']) {
+                case 'StRollBall'://滚球
+                    $type[$k]['matchNum'] = count($StRollBall);
+                    break;
+                case 'StSoon'://即将
+                    $type[$k]['matchNum'] = count($StSoon);
+                    break;
+                case 'StToday'://今日
+                    $type[$k]['matchNum'] = count($StToday);
+                    break;
+                case 'StMorningPlate'://早盘
+                    $type[$k]['matchNum'] = count($StMorningPlate);
+                    break;
+                case 'StStringScene'://串场
+                    $type[$k]['matchNum'] = count($StStringScene);
+                    break;
+                case 'StChampion'://冠军
+                    $type[$k]['matchNum'] = count($oddsAll);
+                    break;
+                default:
+                    throw new \Exception(Render([], '10002', lang('Tips', 'Sports')->get('PARAM_ERROR')));
+            }
+        }
+        Render($type, '1', lang('Tips','Sports')->get('success'));
+
+    }
 }

+ 1 - 1
Application/Sports/Controller/MatchList.php

@@ -622,7 +622,7 @@ where a.match_id = b.match_id and a.id = b.id ";
                     ->where($where)
                     ->where($getState)
                     ->get()
-                    ->toarray();
+                    ->toArray();
 
                     //===获取当前赛事是否有赔率,如果没有则去除===
                     $league = $this->commonFunction->Handle_Odds_Null($league,$models);

+ 3 - 1
Application/Sports/Model/St_zq_league.php

@@ -72,6 +72,7 @@ class St_zq_league extends Model
         $model_match = $models['model_match'];
         $model_league = $models['model_league'];
         $model_result = $models['model_result'];
+        $model_odds = $models['model_odds'];
         //当前状态下所有联赛
        
         $data = lm($model_league,"Sports")
@@ -79,7 +80,8 @@ class St_zq_league extends Model
         ->select($model_league.'.id as lg_id',$model_league.'.name_chinese as leagueName',$model_match.'.id as match_id',$model_match.'.status',$model_match.'.match_date',$model_match.'.match_time',$model_match.'.us_time',$model_match.'.is_morningplate',$model_match.'.is_stringscene',$model_match.'.is_rollball',$model_match.'.is_today')
         ->where([[$model_league.'.name_chinese','!=','']])
         ->where([[$model_match.'.status','<',2]])
-        ->get();
+        ->get()
+        ->toArray();
       
         return $data;
     }

+ 33 - 10
Biz/Common/CommonFunction.php

@@ -1086,21 +1086,36 @@ class CommonFunction {
             $match_ids[] = $v['match_id'];
         }
         //获取下赛事赔率
+        // $oddsData = lm($models['model_odds'],'Sports')
+        // ->whereIn('match_id',$match_ids)
+        // ->where($oddsTypeWhere)
+        // ->pluck('match_id')
+        // ->toArray();
+
         $oddsData = lm($models['model_odds'],'Sports')
+        ->select('match_id')
         ->whereIn('match_id',$match_ids)
         ->where($oddsTypeWhere)
-        ->pluck('match_id')
+        ->distinct('match_id')
+        ->get()
         ->toArray();
 
-        $oddsData = array_unique($oddsData);
-        sort($oddsData);
+        // dd($oddsData);
+        // echo count($oddsData);
+        // $oddsData = $this->array_unset_tt($oddsData,'match_id');
+        // sort($oddsData);
+        // echo '</br>';
+        // echo count($oddsData);
+        // echo '</br>';
+        // echo date('Y-m-d H:i:s',time());
+        // exit;
 
          //如果赔率为空,则返回空
          if(empty($oddsData)) return $oddsData;
          $matchData_new = [];
          foreach($matchData as $k=>$v){
-             foreach($oddsData as $kk=>$match_id){
-                 if($v['match_id'] == $match_id){
+             foreach($oddsData as $kk=>$vv){
+                 if($v['match_id'] == $vv['match_id']){
                      $matchData_new[] = $matchData[$k];
                  }
              }
@@ -1119,21 +1134,29 @@ class CommonFunction {
            $lg_ids[] = $v['lg_id'];
        }
        //获取下赛事赔率
+    //    $oddsData = lm($models['model_odds'],'Sports')
+    //    ->whereIn('lg_id',$lg_ids)
+    //    ->where('type',1)
+    //    ->pluck('lg_id')
+    //    ->toArray();
+
        $oddsData = lm($models['model_odds'],'Sports')
+       ->select('lg_id')
        ->whereIn('lg_id',$lg_ids)
        ->where('type',1)
-       ->pluck('lg_id')
+       ->distinct('lg_id')
+       ->get()
        ->toArray();
 
-       $oddsData = array_unique($oddsData);
-       sort($oddsData);
+    //    $oddsData = array_unique($oddsData);
+    //    sort($oddsData);
 
         //如果赔率为空,则返回空
         if(empty($oddsData)) return $oddsData;
         $matchData_new = [];
         foreach($matchData as $k=>$v){
-            foreach($oddsData as $kk=>$lg_id){
-                if($v['lg_id'] == $lg_id){
+            foreach($oddsData as $kk=>$vv){
+                if($v['lg_id'] == $vv['lg_id']){
                     $matchData_new[] = $matchData[$k];
                 }
             }

+ 1 - 1
Biz/Match/GetmatchData.php

@@ -660,7 +660,7 @@ class GetmatchData {
     /**
      * 获取联赛下 赛事赔率
      */
-    public function getMatchOdds($source,$model_league,$model_match,$model_odds,$where,$search,$lg_id,$time='',$oddsTypeWhere=[]){
+    public function getMatchOdds($source,$model_league,$model_match,$model_odds,$where,$search,$lg_id,$time='',$oddsTypeWhere=[]){        
         $leagueData = lm($model_league,"Sports")
             ->select('id as lg_id','name_chinese as leagueName')
             ->where('id',$lg_id)