Browse Source

异常处理

彭俊 6 years ago
parent
commit
f3b9005b54
2 changed files with 52 additions and 25 deletions
  1. 12 8
      app/Http/Model/StLqResult.php
  2. 40 17
      app/Lib/Biz/Sport/Common.php

+ 12 - 8
app/Http/Model/StLqResult.php

@@ -182,16 +182,19 @@ class StLqResult extends Model
         $set_match_r = [];
 
         if(!empty($match_result_1) and !empty($match_result_2) and !empty($match_result_3) and !empty($match_result_4)){
-            $start_time = ($v['match_date'].' '.$v['match_time']);
-            $time = time()-strtotime($v['match_time']);
-            $match_time = self::secTime($time);
+           
             foreach($matchData as $k =>$v ){
+                //获取开赛时间
+                $start_time = ($v['match_date'].' '.$v['match_time']);
+                $time = time()-strtotime($v['match_time']);
+                $match_time = self::secTime($time);
                 //获取赛事每节的赛果
-                $result_1 = commonFunction::filter_by_value($match_result_1,$v['id']);
-                $result_2 = commonFunction::filter_by_value($match_result_2,$v['id']);
-                $result_3 = commonFunction::filter_by_value($match_result_3,$v['id']);
-                $result_4 = commonFunction::filter_by_value($match_result_4,$v['id']);
+                $result_1 = commonFunction::filter_by_value($match_result_1,'match_id',$v['id']);
+                $result_2 = commonFunction::filter_by_value($match_result_2,'match_id',$v['id']);
+                $result_3 = commonFunction::filter_by_value($match_result_3,'match_id',$v['id']);
+                $result_4 = commonFunction::filter_by_value($match_result_4,'match_id',$v['id']);
                 
+
                 if(!empty($result_1) and !empty($result_2) and !empty($result_3) and !empty($result_4)){
 
                     //拼接赛事主队比分  {"1":0,"2":0,"3":0,"4":0}
@@ -244,11 +247,12 @@ class StLqResult extends Model
                         "match_process"=> $result_4['match_process']?:'',//比赛进程
                         "u_home_score"=> $result_2['home_score']?:0,//上半场主队进球数
                         "u_guest_score"=> $result_2['guest_score']?:0,//上半场客队进球数
-                    ];     
+                    ];    
                 }
             }
         }
 
+
         //写入赛果
         if(!empty($set_match_r)){
             $ret = $model['model_result']::insert($set_match_r);

+ 40 - 17
app/Lib/Biz/Sport/Common.php

@@ -1280,7 +1280,29 @@ class Common
      * 查询字段
      * $value 字段值
     */ 
-    static function filter_by_value ($array,$match_id){ 
+    static function filter_by_value ($array_l, $index, $value){ 
+        $data_json= json_encode($array_l); 
+        $array = json_decode($data_json,true);
+        if(is_array($array) && count($array)>0)  
+        { 
+            foreach(array_keys($array) as $key){ 
+                $temp[$key] = $array[$key][$index]; 
+                 
+                if ($temp[$key] == $value){ 
+
+                    $newarray = $array[$key]; 
+                    return $newarray; 
+
+                } 
+            } 
+        } 
+    //   return $newarray;  
+    } 
+
+
+    static function filter_by_value_1111 ($array,$match_id){ 
+        $data_json= json_encode($array); 
+        $data_arr = json_decode($data_json,true);
 
 
         /*
@@ -1304,23 +1326,24 @@ class Common
 
         $newarray = [];
 
-        if(is_array($array) && count($array)>0)  
+        if(is_array($data_arr) && count($data_arr)>0)  
         { 
-            foreach($array as $k=>$v){
-                if($v->match_id == $match_id){
-                    $newarray[$k] = [
-                        'match_id'=> $v->match_id,
-                        'home_score'=> $v->home_score,
-                        'guest_score'=> $v->guest_score,
-                        'a_time'=> $v->a_time,
-                        'home_rate'=> $v->home_rate,
-                        'guest_rate'=> $v->guest_rate,
-                        'match_process'=> $v->match_process,
-                        'first_score'=> $v->first_score,
-                        'last_score'=> $v->last_score,
-                        'match_score'=> $v->match_score,
-                        'match_winer'=> $v->match_winer
-                    ];       
+            foreach($data_arr as $k=>$v){
+                if($v['match_id'] == $match_id){
+                    $newarray = $v;
+                    // $newarray[$k] = [
+                    //     'match_id'=> $v->match_id,
+                    //     'home_score'=> $v->home_score,
+                    //     'guest_score'=> $v->guest_score,
+                    //     'a_time'=> $v->a_time,
+                    //     'home_rate'=> $v->home_rate,
+                    //     'guest_rate'=> $v->guest_rate,
+                    //     'match_process'=> $v->match_process,
+                    //     'first_score'=> $v->first_score,
+                    //     'last_score'=> $v->last_score,
+                    //     'match_score'=> $v->match_score,
+                    //     'match_winer'=> $v->match_winer
+                    // ];       
                 }
 
             }