vali 6 年之前
父節點
當前提交
4854a919a8
共有 5 個文件被更改,包括 258 次插入104 次删除
  1. 41 28
      app/Http/Model/StBqResult.php
  2. 30 16
      app/Http/Model/StLqResult.php
  3. 44 33
      app/Http/Model/StWqResult.php
  4. 110 27
      app/Http/Model/StZqResult.php
  5. 33 0
      app/Lib/Biz/Sport/Common.php

+ 41 - 28
app/Http/Model/StBqResult.php

@@ -100,7 +100,7 @@ class StBqResult extends Model
             ->get()
             ->toArray();
 
-        
+
         //获取赛事结果表 一天内
         $matchData_r = $model['model_result']::select('match_id')
             ->where([['ctime','>',date('Y-m-d H:i:s', strtotime("-2 day"))]])
@@ -118,8 +118,8 @@ class StBqResult extends Model
             }
         }
 
-         //没有数据,无需操作
-         if(empty($matchData)) return Response::success();
+        //没有数据,无需操作
+        if(empty($matchData)) return Response::success();
         //获取赛事id 用于获取赛事对应结果比分
         $match_ids = [];
         foreach($matchData as $k =>$v){
@@ -131,15 +131,15 @@ class StBqResult extends Model
 
         $match_ids_str = implode(",", $match_ids);
 
-         // 组装sql
-         $sql_result = "select a.match_id,a.home_score,a.guest_score,a.match_time as a_time,a.match_process,a.all_inning,a.first_score,a.last_score,a.match_score,a.match_winer,a.home_rate,a.guest_rate,a.result_mark from st_bq_result_record a,
+        // 组装sql
+        $sql_result = "select a.match_id,a.home_score,a.guest_score,a.match_time as a_time,a.match_process,a.all_inning,a.first_score,a.last_score,a.match_score,a.match_winer,a.home_rate,a.guest_rate,a.result_mark from st_bq_result_record a,
          (select match_id,max(id) id from st_bq_result_record where match_id IN ($match_ids_str) group by match_id)b
          where a.match_id = b.match_id and a.id = b.id ";
 
         //赛事最终结果
         $match_result = DB::select($sql_result);
 
-        //拼装赛事结果数据 
+        //拼装赛事结果数据
         $set_match_r = [];
 
         if(!empty($match_result)){
@@ -150,7 +150,7 @@ class StBqResult extends Model
                 $match_time = self::secTime($time);
                 //获取赛事每节的赛果
                 $resultData = commonFunction::filter_by_value($match_result,'match_id',$v['id']);
-            
+
                 if(!empty($resultData)){
                     //获取赛果json
                     $result_mark = json_decode($resultData['result_mark'],true);
@@ -208,7 +208,7 @@ class StBqResult extends Model
                             "home"=>$result_mark['OT_H'],
                             "guest"=>$result_mark['OT_C'],
                         ]
-                    
+
                     ];
 
                     //上半场主队进球
@@ -222,7 +222,7 @@ class StBqResult extends Model
 
                     //总进球数
                     $all_goal = $result_mark['game_num_H'] + $result_mark['game_num_C'];
-                   
+
                     //赛事待写入赛果数据
                     $set_match_r[] = [
                         "match_id"=> $v['id'],
@@ -249,7 +249,7 @@ class StBqResult extends Model
                         "u_home_score"=> $u_home_score,//上半场主队进球
                         "u_guest_score"=> $u_guest_score ,//上半场客队进球
                         "match_score_t"=> json_encode($inning)?:'',//每局输赢结果
-                    ];    
+                    ];
                 }
             }
         }
@@ -263,23 +263,24 @@ class StBqResult extends Model
         return 1;
 
     }
-     /**
+    /**
      * 获取自动赛事结果
      * 只更新已结束+未手动修改的赛事结果
-     * $match_id 本地赛事id 为0时 则用于后台手动刷新赛果 
+     * $match_id 本地赛事id 为0时 则用于后台手动刷新赛果
      */
     public static function BQresult_v2($model,$match_id=0){
-         //如果有赛事id 则只更新当前赛事结果
-         if($match_id > 0){
+        //如果有赛事id 则只更新当前赛事结果
+        if($match_id > 0){
             $match_ids_str = $match_id;
+            $match_ids = [$match_id];
         }else{
             //获取两天内的结束赛事
             $matchData = $model['model_match']
-            ->join('st_bq_result','st_bq_result.match_id','=','st_bq_competition.id')
-            ->select('st_bq_competition.id','is_correct')
-            ->where([['st_bq_competition.match_date','>',date('Y-m-d', strtotime("-2 day"))],['st_bq_competition.status','=',2],['st_bq_result.is_correct','=',-1]])
-            ->get()
-            ->toArray();
+                ->join('st_bq_result','st_bq_result.match_id','=','st_bq_competition.id')
+                ->select('st_bq_competition.id','is_correct')
+                ->where([['st_bq_competition.match_date','>',date('Y-m-d', strtotime("-2 day"))],['st_bq_competition.status','=',2],['st_bq_result.is_correct','=',-1]])
+                ->get()
+                ->toArray();
 
 
             //没有数据,无需操作
@@ -296,8 +297,16 @@ class StBqResult extends Model
 
             $match_ids_str = implode(",", $match_ids);
         }
-         // 组装sql
-         $sql_result = "select a.match_id,a.home_team,a.guest_team,a.home_score,a.guest_score,a.match_time as a_time,a.match_process,a.all_inning,a.first_score,a.last_score,a.match_score,a.match_winer,a.home_rate,a.guest_rate,a.result_mark from st_bq_result_record a,
+        //如果有赛事id 获取结果中的手动数据
+        if(!empty($match_ids)){
+            $manual_result_data = self::select('match_id','manual_result')
+                ->whereIn('match_id',$match_ids)
+                ->get()
+                ->toArray();
+        }
+
+        // 组装sql
+        $sql_result = "select a.match_id,a.home_team,a.guest_team,a.home_score,a.guest_score,a.match_time as a_time,a.match_process,a.all_inning,a.first_score,a.last_score,a.match_score,a.match_winer,a.home_rate,a.guest_rate,a.result_mark from st_bq_result_record a,
          (select match_id,max(id) id from st_bq_result_record where match_id IN ($match_ids_str) group by match_id)b
          where a.match_id = b.match_id and a.id = b.id ";
 
@@ -308,7 +317,7 @@ class StBqResult extends Model
             foreach($match_result as $k=>$v){
                 //获取赛事每节的赛果
                 $resultData = commonFunction::filter_by_value($match_result,'match_id',$v->match_id);
-            
+
                 if(!empty($resultData)){
                     //获取赛果json
                     $result_mark = json_decode($resultData['result_mark'],true);
@@ -366,7 +375,7 @@ class StBqResult extends Model
                             "home"=>$result_mark['OT_H'],
                             "guest"=>$result_mark['OT_C'],
                         ]
-                    
+
                     ];
 
                     //上半场主队进球
@@ -380,7 +389,10 @@ class StBqResult extends Model
 
                     //总进球数
                     $all_goal = $result_mark['game_num_H'] + $result_mark['game_num_C'];
-                   
+
+                    //===追加获取手动结果数据===
+                    $manual_result_json = commonFunction::getManual_result($manual_result_data,$inning,$v->match_id);
+
                     //赛事待写入赛果数据
                     $set_match_r = [
                         "match_id"=> $v->match_id,
@@ -401,12 +413,13 @@ class StBqResult extends Model
                         "u_guest_score"=> $u_guest_score ,//上半场客队进球
                         "match_score_t"=> json_encode($inning)?:'',//每局输赢结果
                         "is_correct"=> -1,//自动比分
-                    ];    
+                        "manual_result"=> $manual_result_json,//手动结果
+                    ];
 
                     $ret = $model['model_result']::where(['match_id' => $v->match_id,'is_correct'=>-1])
-                    ->update($set_match_r);
-  
-                    // if($ret < 1) throw new \Exception( Response::generate('',Response::ADD_MATCH_R_ERROR));  
+                        ->update($set_match_r);
+
+                    // if($ret < 1) throw new \Exception( Response::generate('',Response::ADD_MATCH_R_ERROR));
                 }
             }
         }

+ 30 - 16
app/Http/Model/StLqResult.php

@@ -33,7 +33,7 @@ class StLqResult extends Model
 
         //没有数据,无需操作
         if(empty($matchData)) return Response::success();
-        //获取赛事结果表 15天内 
+        //获取赛事结果表 15天内
         $matchData_r = $model['model_result']::select('match_id')
             ->where([['ctime','>',date('Y-m-d H:i:s', strtotime("-1 day"))]])
             ->get()
@@ -139,7 +139,7 @@ class StLqResult extends Model
 
         //没有数据,无需操作
         if(empty($matchData)) return Response::success();
-        
+
         //获取赛事id 用于获取赛事对应结果比分
         $match_ids = [];
         foreach($matchData as $k =>$v){
@@ -151,7 +151,7 @@ class StLqResult extends Model
 
 
         $match_ids_str = implode(",", $match_ids);
-        
+
         //第一节
         $sql_1 = "select a.match_id,a.home_score,a.guest_score,a.match_time as a_time,a.home_rate,a.guest_rate,a.match_process,a.first_score,a.last_score,a.match_score,a.match_winer from st_lq_result_record a,
         (select match_id,max(id) id from st_lq_result_record where match_process = '第一节' and match_id IN ($match_ids_str) group by match_id)b
@@ -178,12 +178,12 @@ class StLqResult extends Model
         $match_result_3 = DB::select($sql_3);
         //第四节最终结果
         $match_result_4 = DB::select($sql_4);
-        
-        //拼装赛事结果数据 
+
+        //拼装赛事结果数据
         $set_match_r = [];
 
         if(!empty($match_result_1) and !empty($match_result_2) and !empty($match_result_3) and !empty($match_result_4)){
-           
+
             foreach($matchData as $k =>$v ){
                 //获取开赛时间
                 $start_time = ($v['match_date'].' '.$v['match_time']);
@@ -194,7 +194,7 @@ class StLqResult extends Model
                 $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)){
 
@@ -248,7 +248,7 @@ 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,//上半场客队进球数
-                    ];    
+                    ];
                 }
             }
         }
@@ -266,12 +266,13 @@ class StLqResult extends Model
     /**
      * 获取自动赛事结果
      * 只更新已结束+未手动修改的赛事结果
-     * $match_id 本地赛事id 为0时 则用于后台手动刷新赛果 
+     * $match_id 本地赛事id 为0时 则用于后台手动刷新赛果
      */
     public static function LQresult_v2($model,$match_id=0){
         //如果有赛事id 则只更新当前赛事结果
         if($match_id > 0){
             $match_ids_str = $match_id;
+            $match_ids = [$match_id];
         }else{
             //获取两天内的结束赛事
             $matchData = $model['model_match']
@@ -281,7 +282,7 @@ class StLqResult extends Model
                 ->get()
                 ->toArray();
 
-        
+
             //没有数据,无需操作
             if(empty($matchData)) return Response::success();
             //获取需更新结果的赛事ID
@@ -297,6 +298,15 @@ class StLqResult extends Model
             $match_ids_str = implode(",", $match_ids);
         }
 
+        //如果有赛事id 获取结果中的手动数据
+        if(!empty($match_ids)){
+            $manual_result_data = self::select('match_id','manual_result')
+                ->whereIn('match_id',$match_ids)
+                ->get()
+                ->toArray();
+        }
+
+
         //拼接sql
         $sql_result = "select a.match_id,a.home_team,a.guest_team,a.home_score,a.guest_score,a.match_time as a_time,a.home_rate,a.guest_rate,a.match_process,a.first_score,a.last_score,a.match_score,a.match_winer,a.result_mark from st_lq_result_record a,
         (select match_id,max(id) id from st_lq_result_record where  match_id IN ($match_ids_str) group by match_id)b
@@ -341,7 +351,7 @@ class StLqResult extends Model
                 //拼接赛事主客队比分
                 $inning = [
                     1=>[
-                        "home"=>$mark_result['sc_1th_H'],
+                        "home"=>1231,//$mark_result['sc_1th_H'],
                         "guest"=>$mark_result['sc_1th_C'],
                     ],
                     2=>[
@@ -356,11 +366,11 @@ class StLqResult extends Model
                         "home"=>$mark_result['sc_4th_H'],
                         "guest"=>$mark_result['sc_4th_C'],
                     ],
-                    5=>[
+                    5=>[//上半场
                         "home"=>$mark_result['sc_1th_H']+$mark_result['sc_2th_H'],
                         "guest"=>$mark_result['sc_1th_C']+$mark_result['sc_2th_C'],
                     ],
-                    6=>[
+                    6=>[//下半场
                         "home"=>$mark_result['sc_3th_H']+$mark_result['sc_4th_H'],
                         "guest"=>$mark_result['sc_3th_C']+$mark_result['sc_4th_C'],
                     ],
@@ -371,6 +381,9 @@ class StLqResult extends Model
 
                 ];
 
+                //===追加获取手动结果数据===
+                $manual_result_json = commonFunction::getManual_result($manual_result_data,$inning,$v->match_id);
+
                 //赛事待写入赛果数据
                 $set_match_r = [
                     "match_id"=> $v->match_id,
@@ -391,13 +404,14 @@ class StLqResult extends Model
                     "u_home_score"=> $mark_result['half_H']?:0,//上半场主队进球数
                     "u_guest_score"=> $mark_result['half_C']?:0,//上半场客队进球数
                     "is_correct"=> -1,//自动比分
+                    "manual_result"=> $manual_result_json,//手动结果
 
-                ];  
+                ];
 
                 $ret = $model['model_result']::where(['match_id' => $v->match_id,'is_correct'=>-1])
                     ->update($set_match_r);
-  
-                // if($ret < 1) throw new \Exception( Response::generate('',Response::ADD_MATCH_R_ERROR));               
+
+                // if($ret < 1) throw new \Exception( Response::generate('',Response::ADD_MATCH_R_ERROR));
             }
         }
 

+ 44 - 33
app/Http/Model/StWqResult.php

@@ -117,21 +117,21 @@ class StWqResult extends Model
             }
         }
 
-         //没有数据,无需操作
-         if(empty($matchData)) return Response::success();
-        
-         //获取赛事id 用于获取赛事对应结果比分
-         $match_ids = [];
-         foreach($matchData as $k =>$v){
-             //只获取赛事已结束的
-             if($v['status'] == 2){
-                 $match_ids[] = $v['id'];
-             }
-         }
- 
-         $match_ids_str = implode(",", $match_ids);
-
-        //组装sql 
+        //没有数据,无需操作
+        if(empty($matchData)) return Response::success();
+
+        //获取赛事id 用于获取赛事对应结果比分
+        $match_ids = [];
+        foreach($matchData as $k =>$v){
+            //只获取赛事已结束的
+            if($v['status'] == 2){
+                $match_ids[] = $v['id'];
+            }
+        }
+
+        $match_ids_str = implode(",", $match_ids);
+
+        //组装sql
         //获取赛事最终赛果
         $sql_result = "select a.match_id,a.home_player_score,a.guest_player_score,a.match_time as a_time,a.home_player_let_plate,a.guest_player_let_plate,a.home_player_let_inning,a.guest_player_let_inning,a.all_inning,a.match_process,a.first_score_player,a.last_score_player,a.first_inning_score,a.second_inning_score,a.third_inning_score,a.match_winer_player,a.result_mark from st_wq_result_record a,
         (select match_id,max(id) id from st_wq_result_record where match_id IN ($match_ids_str) group by match_id)b
@@ -140,7 +140,7 @@ class StWqResult extends Model
         //赛事最终结果
         $match_result = DB::select($sql_result);
 
-        //拼装赛事结果数据 
+        //拼装赛事结果数据
         $set_match_r = [];
         $ss = [];
 
@@ -152,7 +152,7 @@ class StWqResult extends Model
                 $match_time = self::secTime($time);
                 //获取赛事每节的赛果
                 $resultData = commonFunction::filter_by_value($match_result,'match_id',$v['id']);
-            
+
                 //如果有获取到结果,并且进程不为空,则写入赛事结果数据
                 if(!empty($resultData) and $resultData['match_process'] != ''){
                     //获取赛果json
@@ -200,12 +200,12 @@ class StWqResult extends Model
                             "home"=>$result_mark['sc_1th_H']+$result_mark['sc_2th_H']+$result_mark['sc_3th_H']+$result_mark['sc_4th_H']+$result_mark['sc_5th_H'],
                             "guest"=>$result_mark['sc_1th_C']+$result_mark['sc_2th_C']+$result_mark['sc_3th_C']+$result_mark['sc_4th_C']+$result_mark['sc_5th_C'],
                         ],
-                    
+
                     ];
 
                     //赛事比分
                     $match_score = $result_mark['game_num_H'].':'.$result_mark['game_num_C'];
-                   
+
                     //赛事待写入赛果数据
                     /*
                     $set_match_r[] = [
@@ -236,7 +236,7 @@ class StWqResult extends Model
                         "match_winer_player"=>  $match_winer?:'',//获胜队员
                         "match_process"=> $match_process?:'',//比赛进程
                         "inning"=> json_encode($inning)?:'',//每局输赢结果
-                    ]; 
+                    ];
                     */
                     $set_match_r[] = [
                         "match_id"=> $v['id'],
@@ -266,7 +266,7 @@ class StWqResult extends Model
                         "match_winer_player"=>  $match_winer?:'',//获胜队员
                         "match_process"=> $match_process?:'',//比赛进程
                         "inning"=> json_encode($inning)?:'',//每局输赢结果
-                    ]; 
+                    ];
 
                 }
             }
@@ -284,12 +284,13 @@ class StWqResult extends Model
     /**
      * 获取自动赛事结果
      * 只更新已结束+未手动修改的赛事结果
-     * $match_id 本地赛事id 为0时 则用于后台手动刷新赛果 
+     * $match_id 本地赛事id 为0时 则用于后台手动刷新赛果
      */
     public static function WQresult_v2($model,$match_id=0){
         //如果有赛事id 则只更新当前赛事结果
         if($match_id > 0){
             $match_ids_str = $match_id;
+            $match_ids = [$match_id];
         }else{
 
             //获取两天内的结束赛事
@@ -300,7 +301,7 @@ class StWqResult extends Model
                 ->get()
                 ->toArray();
 
-    
+
             //没有数据,无需操作
             if(empty($matchData)) return Response::success();
             //获取需更新结果的赛事ID
@@ -316,7 +317,15 @@ class StWqResult extends Model
             $match_ids_str = implode(",", $match_ids);
         }
 
-        //组装sql 
+        //如果有赛事id 获取结果中的手动数据
+        if(!empty($match_ids)){
+            $manual_result_data = self::select('match_id','manual_result')
+                ->whereIn('match_id',$match_ids)
+                ->get()
+                ->toArray();
+        }
+
+        //组装sql
         //获取赛事最终赛果
         $sql_result = "select a.match_id,a.home_player_name,a.guest_player_name,a.home_player_score,a.guest_player_score,a.match_time as a_time,a.home_player_let_plate,a.guest_player_let_plate,a.home_player_let_inning,a.guest_player_let_inning,a.all_inning,a.match_process,a.first_score_player,a.last_score_player,a.first_inning_score,a.second_inning_score,a.third_inning_score,a.match_winer_player,a.result_mark from st_wq_result_record a,
         (select match_id,max(id) id from st_wq_result_record where match_id IN ($match_ids_str) group by match_id)b
@@ -329,7 +338,7 @@ class StWqResult extends Model
             foreach($match_result as $k=>$v){
                 //获取赛事每节的赛果
                 $resultData = commonFunction::filter_by_value($match_result,'match_id',$v->match_id);
-            
+
                 //如果有获取到结果,并且进程不为空,则写入赛事结果数据
                 if(!empty($resultData) and $resultData['match_process'] != ''){
                     //获取赛果json
@@ -375,14 +384,16 @@ class StWqResult extends Model
                             "home"=>$result_mark['sc_1th_H']+$result_mark['sc_2th_H']+$result_mark['sc_3th_H']+$result_mark['sc_4th_H']+$result_mark['sc_5th_H'],
                             "guest"=>$result_mark['sc_1th_C']+$result_mark['sc_2th_C']+$result_mark['sc_3th_C']+$result_mark['sc_4th_C']+$result_mark['sc_5th_C'],
                         ],
-                    
+
                     ];
 
                     //赛事比分
                     $match_score = $result_mark['game_num_H'].':'.$result_mark['game_num_C'];
-                   
+
+                    //===追加获取手动结果数据===
+                    $manual_result_json = commonFunction::getManual_result($manual_result_data,$inning,$v->match_id);
+
                     //赛事待写入赛果数据
-                   
                     $set_match_r = [
                         "match_id"=> $v->match_id,
                         "status"=>2,
@@ -405,13 +416,13 @@ class StWqResult extends Model
                         "match_process"=> $match_process?:'',//比赛进程
                         "inning"=> json_encode($inning)?:'',//每局输赢结果
                         "is_correct"=> -1,//自动比分
-
-                    ]; 
+                        "manual_result"=> $manual_result_json,//手动结果
+                    ];
 
                     $ret = $model['model_result']::where(['match_id' => $v->match_id,'is_correct'=>-1])
-                    ->update($set_match_r);
-  
-                    // if($ret < 1) throw new \Exception( Response::generate('',Response::ADD_MATCH_R_ERROR));  
+                        ->update($set_match_r);
+
+                    // if($ret < 1) throw new \Exception( Response::generate('',Response::ADD_MATCH_R_ERROR));
                 }
             }
         }

+ 110 - 27
app/Http/Model/StZqResult.php

@@ -6,6 +6,7 @@ use App\Http\Response\Response;
 use Fideloper\Proxy\TrustedProxyServiceProvider;
 //use Illuminate\Support\Facades\DB;
 use Illuminate\Database\Capsule\Manager as DB;
+use App\Lib\Biz\Sport\Common as commonFunction;
 
 
 /**
@@ -47,7 +48,7 @@ class StZqResult extends Model
             }
         }
         $match_ids_str = implode(",", $match_ids);
-        
+
         //上半场
         $sql_h = "select a.match_id,a.home_score,a.guest_score,a.match_time as a_time,a.match_process,a.all_goal,a.first_score,a.last_score,a.match_score,a.match_winer from st_zq_result_record a,
         (select match_id,max(id) id from st_zq_result_record where match_process = '上半场' and match_id IN ($match_ids_str) group by match_id)b
@@ -89,7 +90,7 @@ class StZqResult extends Model
                 }
             }
         }
-        
+
 
         //结果表无数据,直接插入
         if(empty($matchData_r)){
@@ -97,7 +98,7 @@ class StZqResult extends Model
                 $start_time = ($v['match_date'].' '.$v['match_time']);
                 $time = time()-strtotime($v['match_time']);
                 $match_time = self::secTime($time);
-                foreach($match_result_record as $kk =>$vv){        
+                foreach($match_result_record as $kk =>$vv){
                     if($v['id'] == $vv['match_id']){
                         $set_match_r[] = [
                             "match_id"=> $v['id'],
@@ -123,8 +124,8 @@ class StZqResult extends Model
                             "match_process"=> $vv['match_process']?:'',//比赛进程
                             "u_home_score"=> $vv['u_home_score']?:0,//上半场主队进球数
                             "u_guest_score"=> $vv['u_guest_score']?:0,//上半场客队进球数
-                        ];                        
-                    }                   
+                        ];
+                    }
                 }
             }
             /*
@@ -133,7 +134,7 @@ class StZqResult extends Model
                 if($ret != true) throw new \Exception( Response::generate('',Response::ADD_MATCH_R_ERROR));
             }
             */
-            
+
         }else {
             //如果结果表有数据,则获取结果表没有的赛事
             foreach ($matchData as $k => $v) {
@@ -150,7 +151,7 @@ class StZqResult extends Model
                     $start_time = ($v['match_date'].' '.$v['match_time']);
                     $time = time()-strtotime($v['match_time']);
                     // $match_time = self::secTime($time);
-                    foreach($match_result_record as $kk =>$vv){        
+                    foreach($match_result_record as $kk =>$vv){
                         if($v['id'] == $vv['match_id']){
                             $set_match_r[] = [
                                 "match_id"=> $v['id'],
@@ -163,7 +164,7 @@ class StZqResult extends Model
                                 "ctime"=>date('Y-m-d H:i:s'),
                                 "update_time"=>date('Y-m-d H:i:s'),
                                 "start_time"=>date('Y-m-d H:i:s',strtotime($start_time)),
-    
+
                                 "home_rate"=> $vv['home_rate']?:0, //主队让球
                                 "guest_rate"=> $vv['guest_rate']?:0, //客队让球
                                 "home_score"=> $vv['home_score']?:0, //主队进球数
@@ -176,8 +177,8 @@ class StZqResult extends Model
                                 "match_process"=> $vv['match_process']?:'',//比赛进程
                                 "u_home_score"=> $vv['u_home_score']?:0,//上半场主队进球数
                                 "u_guest_score"=> $vv['u_guest_score']?:0,//上半场客队进球数
-                            ];                      
-                        }                   
+                            ];
+                        }
                     }
                 }
             }
@@ -233,7 +234,7 @@ class StZqResult extends Model
 
 
         $match_ids_str = implode(",", $match_ids);
-        
+
         //上半场
         $sql_h = "select a.match_id,a.home_score,a.guest_score,a.match_time as a_time,a.match_process,a.all_goal,a.first_score,a.last_score,a.match_score,a.match_winer from st_zq_result_record a,
         (select match_id,max(id) id from st_zq_result_record where match_process = '半场' and match_id IN ($match_ids_str) group by match_id)b
@@ -277,7 +278,7 @@ class StZqResult extends Model
                 }
             }
         }
-        
+
 
         //组装赛果数据
         if(!empty($match_result_record)){
@@ -285,7 +286,7 @@ class StZqResult extends Model
                 $start_time = ($v['match_date'].' '.$v['match_time']);
                 $time = time()-strtotime($v['match_time']);
                 $match_time = self::secTime($time);
-                foreach($match_result_record as $kk =>$vv){        
+                foreach($match_result_record as $kk =>$vv){
                     if($v['id'] == $vv['match_id']){
                         //获取获胜球队
                         if(($vv['home_score']) > ($vv['guest_score'])){
@@ -317,8 +318,8 @@ class StZqResult extends Model
                             "match_process"=> $vv['match_process']?:'',//比赛进程
                             "u_home_score"=> $vv['u_home_score']?:0,//上半场主队进球数
                             "u_guest_score"=> $vv['u_guest_score']?:0,//上半场客队进球数
-                        ];                        
-                    }                   
+                        ];
+                    }
                 }
             }
         }
@@ -335,22 +336,21 @@ class StZqResult extends Model
     /**
      * 获取自动赛事结果
      * 只更新已结束+未手动修改的赛事结果
-     * $match_id 本地赛事id 为0时 则用于后台手动刷新赛果 
+     * $match_id 本地赛事id 为0时 则用于后台手动刷新赛果
      */
     public static function ZQresult_v2($model,$match_id = 0){
-
         //如果有赛事id 则只更新当前赛事结果
         if($match_id > 0){
             $match_ids_str = $match_id;
+            $match_ids = [$match_id];
         }else{
             //获取两天内的结束赛事
             $matchData = $model['model_match']
                 ->join('st_zq_result','st_zq_result.match_id','=','st_zq_competition.id')
-                ->select('st_zq_competition.id','is_correct')
-                ->where([['st_zq_competition.match_date','>',date('Y-m-d', strtotime("-2 day"))],['st_zq_competition.status','=',2],['st_zq_result.is_correct','=',-1]])
+                ->select('st_zq_competition.id','is_correct','manual_result')
+                ->where([['st_zq_competition.match_date','>',date('Y-m-d', strtotime("-2 day"))],['st_zq_competition.status','=',2],['st_zq_result.is_correct','=',-1]])//
                 ->get()
                 ->toArray();
-            
             //没有数据,无需操作
             if(empty($matchData)) return Response::success();
             //获取需更新结果的赛事ID
@@ -365,7 +365,15 @@ class StZqResult extends Model
 
             $match_ids_str = implode(",", $match_ids);
         }
-        
+
+        //如果有赛事id 获取结果中的手动数据
+        if(!empty($match_ids)){
+            $manual_result_data = self::select('match_id','manual_result')
+                ->whereIn('match_id',$match_ids)
+                ->get()
+                ->toArray();
+        }
+
         //上半场
         $sql_h = "select a.match_id,a.home_team,a.guest_team,a.home_score,a.guest_score,a.match_time as a_time,a.match_process,a.all_goal,a.first_score,a.last_score,a.match_score,a.match_winer from st_zq_result_record a,
         (select match_id,max(id) id from st_zq_result_record where match_process = '半场' and match_id IN ($match_ids_str) group by match_id)b
@@ -419,9 +427,12 @@ class StZqResult extends Model
                     $match_winer = $v['home_team'];
                 }else{
                     $match_winer = $v['guest_team'];
-                
+
                 }
 
+                //===追加获取手动结果数据===
+                $manual_result_json = self::getManual_result($manual_result_data,$v,$v['match_id']);
+
                 $set_match_r = [
                     "match_id"=> $v['match_id'],
                     "update_time"=>date('Y-m-d H:i:s'),
@@ -439,18 +450,90 @@ class StZqResult extends Model
                     "u_home_score"=> $v['u_home_score']?:0,//上半场主队进球数
                     "u_guest_score"=> $v['u_guest_score']?:0,//上半场客队进球数
                     "is_correct"=> -1,//自动比分
-                ];     
-                
+                    "manual_result"=> $manual_result_json,//手动结果
+                ];
                 $ret = $model['model_result']::where(['match_id' => $v['match_id'],'is_correct'=>-1])
                     ->update($set_match_r);
-      
+
                 // if($ret < 1) throw new \Exception( Response::generate('',Response::ADD_MATCH_R_ERROR));
             }
         }
-        
+
         return 1;
     }
 
+    /**
+     * 处理 拼接手动结果数据
+     * $manual_result_data arr 多个赛事手动结果数据
+     * $match_id int 赛事id
+     */
+    public static function getManual_result($manual_result_data,$auto_result,$match_id){
+        $resultData = commonFunction::filter_by_value($manual_result_data,'match_id',$match_id);
+        //手动结果数据 json
+        $manual_result_json = $resultData['manual_result'];
+        //手动结果数据 arr
+        $manual_result_arr = json_decode($manual_result_json,true);
+
+        //拼接手动数据
+        foreach($manual_result_arr as $kk=>$vv){
+            //上半场角球
+            if($kk == 'half_corner'){
+                //赋值 上半场角球
+                if(empty($vv['home']) || empty($vv['guest'])){
+                    $vv['home'] = 0;
+                    $vv['guest'] = 0;
+                }
+            }
+            //全场角球
+            if($kk == 'all_corner'){
+                if(empty($vv['home']) || empty($vv['guest'])){
+                    $vv['home'] = 0;
+                    $vv['guest'] = 0;
+                }
+            }
+            //上半场比分
+            if($kk == 'half'){
+                if(empty($vv['home']) || empty($vv['guest'])){
+                    $vv['home'] = $auto_result['u_home_score']?:0;
+                    $vv['guest'] = $auto_result['u_guest_score']?:0;
+                }
+            }
+            //全场比分
+            if($kk == 'all'){
+                if(empty($vv['home']) || empty($vv['guest'])){
+                    $vv['home'] = $auto_result['home_score']?:0;
+                    $vv['guest'] = $auto_result['guest_score']?:0;
+                }
+            }
+            //上半场罚牌
+            if($kk == 'half_penalty'){
+                if(empty($vv['home']) || empty($vv['guest'])){
+                    $vv['home'] = 0;
+                    $vv['guest'] = 0;
+                }
+            }
+
+            //全场罚牌
+            if($kk == 'all_penalty'){
+                if(empty($vv['home']) || empty($vv['guest'])){
+                    $vv['home'] = 0;
+                    $vv['guest'] = 0;
+                }
+            }
+            //首进球时间
+            if($kk == 'first_score'){
+                if(empty($vv['home']) || empty($vv['guest'])){
+                    $vv['time'] = 0;
+                }
+            }
+
+            $manual_result_arr[$kk] =$vv;
+        }
+        //转回json
+        $manual_result_json = json_encode($manual_result_arr);
+
+        return $manual_result_json;
+    }
 
     //计算滚球 赛事进行时间
     public static function secTime($sec=0){
@@ -541,7 +624,7 @@ class StZqResult extends Model
 
             //更新
             $ret = self::where(['match_id' => $match_id])
-                    ->update(['warn_more'=>$warn_data,'update_time'=>date('Y-m-d H:i:s')]);
+                ->update(['warn_more'=>$warn_data,'update_time'=>date('Y-m-d H:i:s')]);
         }
 
         return $ret;

+ 33 - 0
app/Lib/Biz/Sport/Common.php

@@ -1314,6 +1314,39 @@ class Common
         return [];
     }
 
+    /**
+     * 处理 拼接手动结果数据
+     * $manual_result_data arr 多个赛事手动结果数据
+     * $match_id int 赛事id
+     * $auto_result arr 自动结果
+     */
+    public static function getManual_result($manual_result_data,$auto_result,$match_id){
+        $resultData = self::filter_by_value($manual_result_data,'match_id',$match_id);
+        //手动结果数据 json
+        $manual_result_json = $resultData['manual_result'];
+        //手动结果数据 arr
+        $manual_result_arr = json_decode($manual_result_json,true);
+
+        //拼接手动数据
+        foreach($manual_result_arr as $k=>$v){
+            foreach($auto_result as $kk=>$vv){
+                //赋值
+                if($k == $kk){
+                    if(empty($v['home']) || empty($v['guest'])){
+                        $v['home'] = $vv['home']?:0;
+                        $v['guest'] = $vv['guest']?:0;
+                    }
+                }
+            }
+
+            $manual_result_arr[$k] =$v;
+        }
+        //转回json
+        $manual_result_json = json_encode($manual_result_arr);
+
+        return $manual_result_json;
+    }
+
 
 }