Browse Source

处理空赔率赛事

彭俊 6 years ago
parent
commit
e6a220b6ca

+ 21 - 6
Application/Api/Controller/Betorder.php

@@ -189,10 +189,25 @@ class Betorder extends BaseController{
     }
 
     public function Bet(){
+        //如果获取不到data,则为游戏端提交,需转成数组
+
+        if(!empty($_REQUEST['json_bet_data'])){
+            $data = json_decode($_REQUEST['json_bet_data'],true);
+
+            $token = $data['token'];
+            dd($token);
+
+            $bet_money = $data['bet_money'];
+            $data = $data['data'];
+            $userInfo = $this->getAgent($token);//获取用户信息
+        }else{
+            $data = $_REQUEST['data'];
+            $bet_money = $_REQUEST['bet_money'];
+            $token = $_REQUEST['token'];
+            $userInfo = $this->getAgent($token);//获取用户信息
+
+        }
 
-        $userInfo = $this->getAgent();//获取用户信息
-        $data = $_REQUEST['data'];
-        $bet_money = $_REQUEST['bet_money'];
         if(empty($data)||empty($bet_money)){
             Render('', '51029',lang('Errors','Api')->get('error-51029'));
         }
@@ -224,12 +239,12 @@ class Betorder extends BaseController{
     /**
      * token获取用户详情
      */
-    public function getAgent() {
-        $checkToken = $this->accountManager->checkEffectiveTime();
+    public function getAgent($token = '') {
+        $checkToken = $this->accountManager->checkEffectiveTime($token);
         if ($checkToken['status'] != 1) {
             Render($checkToken['data'], $checkToken['status'], lang('commons')->get('user does login'));
         };
-        $result = $this->accountManager->refreshToken();
+        $result = $this->accountManager->refreshToken($token);
         return $result['data'];
     }
 

+ 12 - 6
Biz/Account/AccountManager.php

@@ -280,8 +280,13 @@ class AccountManager {
      *
      * @return int
      */
-    public function refreshToken() {
-        $str_token = $_POST['token'] ? trim($_POST['token']) : '';
+    public function refreshToken($token = '') {
+        if(!empty($token)) {
+            $str_token = $token ? trim($token) : '';
+        }else{
+            $str_token = $_POST['token'] ? trim($_POST['token']) : '';
+        }
+       
         $token = new TokenManager();
         $userInfo = $token->getAccountInfo($str_token);
         if (count($userInfo) > 0) {
@@ -466,8 +471,9 @@ class AccountManager {
      * @return mixed
      * @throws \Exception
      */
-    public function getCurrentUser() {
-        $token = $_POST['token'];
+    public function getCurrentUser($token = '') {
+        if(empty($token)) $token = $_POST['token'];
+        
         $token = trim($token, "\"");
 
         $token = trim($token, "'");
@@ -805,13 +811,13 @@ class AccountManager {
      *
      * @return array
      */
-    public function checkEffectiveTime() {
+    public function checkEffectiveTime($token = '') {
         //重写此方法  by xmj
         define("OVERTIME", 1800);
 
         if (isCheckToken()) {
 
-            $account = $this->getCurrentUser();
+            $account = $this->getCurrentUser($token);
             // $identity = $account->account_identity;
 
             if ($account) {

+ 0 - 1
Biz/Match/GetOddsData.php

@@ -116,7 +116,6 @@ class GetOddsData {
             ->get()->toArray();
 
         foreach ($matchData as $kk=>$vv){
-
             //获取赛事下赔率并且分组
             $odds = [];
             foreach ($oddsData as $kkk=>$vvv) {

+ 99 - 33
Biz/Match/GetmatchData.php

@@ -339,7 +339,7 @@ class GetmatchData {
             return $leagueData;
         }
 
-        $data = $this->getMatch($source,$model_league,$model_match,'',$search,$where);
+        $data = $this->getMatch($source,$models,$search,$where);
         return $data;
     }
 
@@ -359,7 +359,7 @@ class GetmatchData {
             return $leagueData;
         }
 
-        $data = $this->getMatch($source,$model_league,$model_match,'',$search,$where,$time);
+        $data = $this->getMatch($source,$models,$search,$where,$time);
         return $data;
     }
 
@@ -380,7 +380,7 @@ class GetmatchData {
             return $leagueData;
         }
 
-        $data = $this->getMatch($source,$model_league,$model_match,'',$search,$where,$time);
+        $data = $this->getMatch($source,$models,$search,$where,$time);
         return $data;
     }
 
@@ -424,38 +424,38 @@ class GetmatchData {
         }
 
         //获取国家/洲下所有联赛及数量
-        $data = $this->getMatch($source,$model_league,'',$model_odds,$search,$where,'',$type_code);
+        $data = $this->getMatch($source,$models,$search,$where,'',$type_code);
         return $data;
     }
 
     /**
      * 获取国家/洲 下联赛
      */
-    public function getMatch($source,$model_league,$model_match='',$model_odds='',$search,$where,$time='',$type_code=''){
+    public function getMatch($source,$models,$search,$where,$time='',$type_code=''){
         //国家下所有联赛
-        $country = lm($model_league,"Sports")
-            ->leftjoin('st_area_country','st_area_country.id',$model_league.'.country_id')
+        $country = lm($models['model_league'],"Sports")
+            ->leftjoin('st_area_country','st_area_country.id',$models['model_league'].'.country_id')
             ->select('st_area_country.id as country_id','st_area_country.name as region')
             ->distinct('st_area_country.name')
-            ->where([[$model_league.'.name_chinese','!=','']])
-            ->where($model_league.'.name_chinese','like','%'.$search.'%')
+            ->where([[$models['model_league'].'.name_chinese','!=','']])
+            ->where($models['model_league'].'.name_chinese','like','%'.$search.'%')
             ->get()
             ->toArray();
         //洲下所有联赛
-        $area = lm($model_league,"Sports")
-            ->leftjoin('st_area_country','st_area_country.id',$model_league.'.area_id')
+        $area = lm($models['model_league'],"Sports")
+            ->leftjoin('st_area_country','st_area_country.id',$models['model_league'].'.area_id')
             ->select('st_area_country.id as area_id','st_area_country.name as region')
             ->distinct('st_area_country.name')
-            ->where([[$model_league.'.name_chinese','!=','']])
-            ->where($model_league.'.name_chinese','like','%'.$search.'%')
+            ->where([[$models['model_league'].'.name_chinese','!=','']])
+            ->where($models['model_league'].'.name_chinese','like','%'.$search.'%')
             ->get()
             ->toArray();
 
 
         if($type_code != 'StChampion'){//非冠军赛事
-            $data = $this->getMatchNum($source,$country,$area,$model_league,$model_match,$model_odds,$where,$search,$time);
+            $data = $this->getMatchNum($source,$country,$area,$models,$where,$search,$time);
         }else{//冠军赛事
-            $data = $this->getMatchStChampionNum($source,$country,$area,$model_league,$model_match,$model_odds,$where,$search,$time);
+            $data = $this->getMatchStChampionNum($source,$country,$area,$models,$where,$search,$time);
         }
 
         return $data;
@@ -465,14 +465,15 @@ class GetmatchData {
      * 获取联赛下赛事 数量
      * 非冠军盘口
      */
-    public function getMatchNum($source,$country,$area,$model_league,$model_match='',$model_odds='',$where,$search,$time='',$type=0){
-        $leagueData = lm($model_league,'Sports')
+    public function getMatchNum($source,$country,$area,$models,$where,$search,$time='',$type=0){
+        $leagueData = lm($models['model_league'],'Sports')
             ->select('id as lg_id','name_chinese as league','country_id','area_id')
-            ->where([[$model_league.'.name_chinese','!=','']])
-            ->where($model_league.'.name_chinese','like','%'.$search.'%')
+            ->where([[$models['model_league'].'.name_chinese','!=','']])
+            ->where($models['model_league'].'.name_chinese','like','%'.$search.'%')
             ->get()
             ->toArray();
 
+        //如果有时间条件 
         $timeWhere = [];
         if(!empty($time)){
             if($time == 'other'){
@@ -481,16 +482,49 @@ class GetmatchData {
                 $timeWhere[] = ['match_date',$time];
             }
         }
-        $matchData = lm($model_match,'Sports')
+        //获取赛事
+        $matchData = lm($models['model_match'],'Sports')
             ->select('id as match_id','lg_id')
             ->where($where)
             ->where($timeWhere)
             ->get()
             ->toArray();
 
+        //如果赛事为空,直接返回
+        if(empty($matchData)) return $matchData;
+
+        //===获取当前赛事是否有赔率,如果没有则去除===
+        //获取当前match_id
+        $match_ids = [];
+        foreach($matchData as $k=>$v){
+            $match_ids[] = $v['match_id'];
+        }
+        //获取下赛事赔率
+        $oddsData = lm($models['model_odds'],'Sports')
+        ->select('id','match_id')
+        ->whereIn('match_id',$match_ids)
+        ->get()
+        ->toArray();
+
+        //根据match_id 去重
+        $oddsData = $this->commonFunction->array_unset_tt($oddsData,'match_id');
+        sort($oddsData);
+
+        //如果赔率为空,则返回空
+        if(empty($oddsData)) return $oddsData;
+        $matchData_new = [];
+        foreach($matchData as $k=>$v){
+            foreach($oddsData as $kk=>$vv){
+                if($v['match_id'] == $vv['match_id']){
+                    $matchData_new[] = $matchData[$k];
+                }
+            }
+        }
+        //===赛事空赔率 处理end ===
+
         //按国家
         $countryData = [];
-        if(!empty($country) and !empty($leagueData) and !empty($matchData)){
+        if(!empty($country) and !empty($leagueData) and !empty($matchData_new)){
             foreach ($country as $k=>$v){
                 if($v['country_id']){
                     $countryData[$k] = $v;
@@ -512,7 +546,7 @@ class GetmatchData {
 
         //按地区
         $areaData = [];
-        if(!empty($area) and !empty($leagueData) and($matchData)){
+        if(!empty($area) and !empty($leagueData) and($matchData_new)){
             foreach ($area as $k=>$v){
                 if($v['area_id']){
                     $areaData[$k] = $v;
@@ -531,8 +565,8 @@ class GetmatchData {
                 unset($areaData[$k]);
             }
         }
-        $countryData = $this->commonFunction->array_other_tt($countryData,$matchData);
-        $areaData = $this->commonFunction->array_other_tt($areaData,$matchData);
+        $countryData = $this->commonFunction->array_other_tt($countryData,$matchData_new);
+        $areaData = $this->commonFunction->array_other_tt($areaData,$matchData_new);
         $data = array_merge($countryData,$areaData);
         return $data;
     }
@@ -541,16 +575,16 @@ class GetmatchData {
      * 获取联赛下赛事 数量
      * 冠军盘口
      */
-    public function getMatchStChampionNum($source,$country,$area,$model_league,$model_match='',$model_odds='',$where,$search,$time='',$type=0){
+    public function getMatchStChampionNum($source,$country,$area,$models,$where,$search,$time='',$type=0){
 
-        $leagueData = lm($model_league,'Sports')
+        $leagueData = lm($models['model_league'],'Sports')
             ->select('id as lg_id','name_chinese as league','country_id','area_id')
-            ->where([[$model_league.'.name_chinese','!=','']])
-            ->where($model_league.'.name_chinese','like','%'.$search.'%')
+            ->where([[$models['model_league'].'.name_chinese','!=','']])
+            ->where($models['model_league'].'.name_chinese','like','%'.$search.'%')
             ->get()
             ->toArray();
 
-        $oddsData = lm($model_odds,'Sports')
+        $oddsData = lm($models['model_odds'],'Sports')
             ->select('id','lg_id','p_code')
             ->distinct("p_code")//去重
             ->where($where)
@@ -654,20 +688,52 @@ class GetmatchData {
             ->get()
             ->toarray();
 
+        //如果赛事为空,直接返回
+        if(empty($matchData)) return $matchData;
+
+        //===获取当前赛事是否有赔率,如果没有则去除===
+        //获取当前match_id
+        $match_ids = [];
+        foreach($matchData as $k=>$v){
+            $match_ids[] = $v['match_id'];
+        }
+        //获取下赛事赔率
+        $oddsData = lm($model_odds,'Sports')
+        ->select('id','match_id')
+        ->whereIn('match_id',$match_ids)
+        ->get()
+        ->toArray();
+
+        //根据match_id 去重
+        $oddsData = $this->commonFunction->array_unset_tt($oddsData,'match_id');
+        sort($oddsData);
+
+        //如果赔率为空,则返回空
+        if(empty($oddsData)) return $oddsData;
+        $matchData_new = [];
+        foreach($matchData as $k=>$v){
+            foreach($oddsData as $kk=>$vv){
+                if($v['match_id'] == $vv['match_id']){
+                    $matchData_new[] = $matchData[$k];
+                }
+            }
+        }
+        //===赛事空赔率 处理end ===
+
         //获取各球类默认赔率
         $game_code = $_REQUEST['game_code'];
         switch ($game_code) {
             case 'zq'://足球
-                $matchData = $this->getOddsData->getOddsZQ($matchData, $model_odds, $source,$oddsTypeWhere);
+                $matchData = $this->getOddsData->getOddsZQ($matchData_new, $model_odds, $source,$oddsTypeWhere);
                 break;
             case 'lq'://篮球
-                $matchData = $this->getOddsData->getOddsLQ($matchData, $model_odds, $source,$oddsTypeWhere);
+                $matchData = $this->getOddsData->getOddsLQ($matchData_new, $model_odds, $source,$oddsTypeWhere);
                 break;
             case 'wq'://网球
-                $matchData = $this->getOddsData->getOddsWQ($matchData, $model_odds, $source,$oddsTypeWhere);
+                $matchData = $this->getOddsData->getOddsWQ($matchData_new, $model_odds, $source,$oddsTypeWhere);
                 break;
             case 'bq'://棒球
-                $matchData = $this->getOddsData->getOddsBQ($matchData, $model_odds, $source,$oddsTypeWhere);
+                $matchData = $this->getOddsData->getOddsBQ($matchData_new, $model_odds, $source,$oddsTypeWhere);
                 break;
         }
         $leagueData->matchNum = count($matchData);