فهرست منبع

更新赛事状态接口追加更新赛事结果

彭俊 6 سال پیش
والد
کامیت
8e4955b6bc

+ 19 - 8
app/Http/Controllers/Api/WriteSportsController.php

@@ -974,7 +974,6 @@ class WriteSportsController extends BaseController
 
                 //写 赛事 结果 记录
                 $ret = $models['model_result_record']::insert($set_match_r);
-
                 if ($ret != true) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::ADD_MATCH_R_R_ERROR));
             }
 
@@ -1902,7 +1901,7 @@ class WriteSportsController extends BaseController
             //请求 数据 为空
             if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
             $data = $this->getAddData($obt);
-            //不是 直播 数据
+            //不是更新赛事状态数据
             if ($data['title'] != 'match_status') throw new \Exception(Response::generate('不是更新赛事状态数据', Response::ABNORMAL));
 
             /*
@@ -1948,6 +1947,12 @@ class WriteSportsController extends BaseController
                             $ret = $model['model_match']::where(['id' => $v['match_id']])
                                 ->update($set_status);
                             if ($ret < 1) throw new \Exception(Response::generate(gameModel::getGameName($game_code) . '赛事-match_id:' . $v['others_match_id'], Response::UPSTATUS_ERROR));
+                        
+                            //===如果赛事已结束 新增 更新 赛事结果===
+                            if($vv['status'] == 2){
+                                $this->match_result($game_code, $v['match_id']);
+                            }
+                            //===end===
                         }
                     }
                 }
@@ -1966,11 +1971,17 @@ class WriteSportsController extends BaseController
                             $ret = $model['model_match']::where(['id' => $v['match_id']])
                                 ->update($set_status);
                             if ($ret < 1) throw new \Exception(Response::generate(gameModel::getGameName($game_code) . '赛事-match_id:' . $v['others_match_id'], Response::UPSTATUS_ERROR));
+                        
+                            //===如果赛事已结束 新增 更新 赛事结果===
+                            if($vv['status'] == 2){
+                                $this->match_result($game_code, $v['match_id']);
+                            }
+                            //===end===
                         }
                     }
                 }
             }
-            
+
             //提交事务
             DB::commit();
             //写请求数据 日志记录
@@ -2276,13 +2287,13 @@ class WriteSportsController extends BaseController
     /*
      * 写入 赛事 初始 结果
      */
-    public function match_result($game_code = '')
+    public function match_result($game_code = '',$match_id = 0)
     {
         $model = commonFunction::getModels($game_code, 1);
-        if ($game_code == 'zq') ZqResultModel::ZQresult_v2($model);
-        if ($game_code == 'lq') LqResultModel::LQresult_v2($model);
-        if ($game_code == 'wq') WqResultModel::WQresult_v2($model);
-        if ($game_code == 'bq') BqResultModel::BQresult_v2($model);
+        if ($game_code == 'zq') ZqResultModel::ZQresult_v2($model,$match_id);
+        if ($game_code == 'lq') LqResultModel::LQresult_v2($model,$match_id);
+        if ($game_code == 'wq') WqResultModel::WQresult_v2($model,$match_id);
+        if ($game_code == 'bq') BqResultModel::BQresult_v2($model,$match_id);
     }
 
     /*

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

@@ -262,33 +262,39 @@ class StBqResult extends Model
         return 1;
 
     }
-    /**
+     /**
      * 获取自动赛事结果
      * 只更新已结束+未手动修改的赛事结果
+     * $match_id 本地赛事id 为0时 则用于后台手动刷新赛果 
      */
-    public static function BQresult_v2($model){
-         //获取两天内的结束赛事
-         $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]])
-         ->get()
-         ->toArray();
+    public static function BQresult_v2($model,$match_id=0){
+         //如果有赛事id 则只更新当前赛事结果
+         if($match_id > 0){
+            $match_ids_str = $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();
 
 
-        //没有数据,无需操作
-        if(empty($matchData)) return Response::success();
-        //获取需更新结果的赛事ID
-        $match_ids = [];
-        foreach($matchData as $k =>$v){
-            //未手动修改比分
-            if($v['is_correct'] == 0){
-                $match_ids[] = $v['id'];
+            //没有数据,无需操作
+            if(empty($matchData)) return Response::success();
+            //获取需更新结果的赛事ID
+            $match_ids = [];
+            foreach($matchData as $k =>$v){
+                //未手动修改比分
+                if($v['is_correct'] == 0){
+                    $match_ids[] = $v['id'];
+                }
             }
-        }
-        if(empty($match_ids)) return Response::success();
+            if(empty($match_ids)) return Response::success();
 
-        $match_ids_str = implode(",", $match_ids);
+            $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,
          (select match_id,max(id) id from st_bq_result_record where match_id IN ($match_ids_str) group by match_id)b
@@ -396,10 +402,10 @@ class StBqResult extends Model
                         "is_correct"=> -1,//自动比分
                     ];    
 
-                    $ret = $model['model_result']::where(['match_id' => $v->match_id])
+                    $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));  
                 }
             }
         }

+ 28 - 22
app/Http/Model/StLqResult.php

@@ -265,30 +265,36 @@ class StLqResult extends Model
     /**
      * 获取自动赛事结果
      * 只更新已结束+未手动修改的赛事结果
+     * $match_id 本地赛事id 为0时 则用于后台手动刷新赛果 
      */
-    public static function LQresult_v2($model){
-         //获取两天内的结束赛事
-         $matchData = $model['model_match']
-            ->join('st_lq_result','st_lq_result.match_id','=','st_lq_competition.id')
-            ->select('st_lq_competition.id','is_correct')
-            ->where([['st_lq_competition.match_date','>',date('Y-m-d', strtotime("-2 day"))],['st_lq_competition.status','=',2]])
-            ->get()
-            ->toArray();
+    public static function LQresult_v2($model,$match_id=0){
+        //如果有赛事id 则只更新当前赛事结果
+        if($match_id > 0){
+            $match_ids_str = $match_id;
+        }else{
+            //获取两天内的结束赛事
+            $matchData = $model['model_match']
+                ->join('st_lq_result','st_lq_result.match_id','=','st_lq_competition.id')
+                ->select('st_lq_competition.id','is_correct')
+                ->where([['st_lq_competition.match_date','>',date('Y-m-d', strtotime("-2 day"))],['st_lq_competition.status','=',2],['st_lq_result.is_correct','=',-1]])
+                ->get()
+                ->toArray();
 
-     
-        //没有数据,无需操作
-        if(empty($matchData)) return Response::success();
-        //获取需更新结果的赛事ID
-        $match_ids = [];
-        foreach($matchData as $k =>$v){
-            //未手动修改比分
-            if($v['is_correct'] == 0){
-                $match_ids[] = $v['id'];
+        
+            //没有数据,无需操作
+            if(empty($matchData)) return Response::success();
+            //获取需更新结果的赛事ID
+            $match_ids = [];
+            foreach($matchData as $k =>$v){
+                //未手动修改比分
+                if($v['is_correct'] == 0){
+                    $match_ids[] = $v['id'];
+                }
             }
-        }
-        if(empty($match_ids)) return Response::success();
+            if(empty($match_ids)) return Response::success();
 
-        $match_ids_str = implode(",", $match_ids);
+            $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.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,
@@ -353,10 +359,10 @@ class StLqResult extends Model
 
                 ];  
 
-                $ret = $model['model_result']::where(['match_id' => $v->match_id])
+                $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));               
             }
         }
 

+ 31 - 26
app/Http/Model/StWqResult.php

@@ -276,34 +276,40 @@ class StWqResult extends Model
 
     }
 
-   /**
+    /**
      * 获取自动赛事结果
      * 只更新已结束+未手动修改的赛事结果
+     * $match_id 本地赛事id 为0时 则用于后台手动刷新赛果 
      */
-    public static function WQresult_v2($model){
-
-        //获取两天内的结束赛事
-        $matchData = $model['model_match']
-            ->join('st_wq_result','st_wq_result.match_id','=','st_wq_competition.id')
-            ->select('st_wq_competition.id','is_correct')
-            ->where([['st_wq_competition.match_date','>',date('Y-m-d', strtotime("-2 day"))],['st_wq_competition.status','=',2]])
-            ->get()
-            ->toArray();
-
- 
-        //没有数据,无需操作
-        if(empty($matchData)) return Response::success();
-        //获取需更新结果的赛事ID
-        $match_ids = [];
-        foreach($matchData as $k =>$v){
-            //未手动修改比分
-            if($v['is_correct'] == 0){
-                $match_ids[] = $v['id'];
+    public static function WQresult_v2($model,$match_id=0){
+        //如果有赛事id 则只更新当前赛事结果
+        if($match_id > 0){
+            $match_ids_str = $match_id;
+        }else{
+
+            //获取两天内的结束赛事
+            $matchData = $model['model_match']
+                ->join('st_wq_result','st_wq_result.match_id','=','st_wq_competition.id')
+                ->select('st_wq_competition.id','is_correct')
+                ->where([['st_wq_competition.match_date','>',date('Y-m-d', strtotime("-2 day"))],['st_wq_competition.status','=',2],['st_wq_result.is_correct','=',-1]])
+                ->get()
+                ->toArray();
+
+    
+            //没有数据,无需操作
+            if(empty($matchData)) return Response::success();
+            //获取需更新结果的赛事ID
+            $match_ids = [];
+            foreach($matchData as $k =>$v){
+                //未手动修改比分
+                if($v['is_correct'] == 0){
+                    $match_ids[] = $v['id'];
+                }
             }
-        }
-        if(empty($match_ids)) return Response::success();
+            if(empty($match_ids)) return Response::success();
 
-        $match_ids_str = implode(",", $match_ids);
+            $match_ids_str = implode(",", $match_ids);
+        }
 
         //组装sql 
         //获取赛事最终赛果
@@ -393,11 +399,10 @@ class StWqResult extends Model
 
                     ]; 
 
-                    $ret = $model['model_result']::where(['match_id' => $v->match_id])
+                    $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));  
                 }
             }
         }

+ 29 - 22
app/Http/Model/StZqResult.php

@@ -333,29 +333,35 @@ class StZqResult extends Model
     /**
      * 获取自动赛事结果
      * 只更新已结束+未手动修改的赛事结果
+     * $match_id 本地赛事id 为0时 则用于后台手动刷新赛果 
      */
-    public static function ZQresult_v2($model){
-        //获取两天内的结束赛事
-        $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]])
-            ->get()
-            ->toArray();
-        
-        //没有数据,无需操作
-        if(empty($matchData)) return Response::success();
-        //获取需更新结果的赛事ID
-        $match_ids = [];
-        foreach($matchData as $k =>$v){
-            //未手动修改比分
-            if($v['is_correct'] == 0){
-                $match_ids[] = $v['id'];
+    public static function ZQresult_v2($model,$match_id = 0){
+        //如果有赛事id 则只更新当前赛事结果
+        if($match_id > 0){
+            $match_ids_str = $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]])
+                ->get()
+                ->toArray();
+            
+            //没有数据,无需操作
+            if(empty($matchData)) return Response::success();
+            //获取需更新结果的赛事ID
+            $match_ids = [];
+            foreach($matchData as $k =>$v){
+                //未手动修改比分
+                if($v['is_correct'] == 0){
+                    $match_ids[] = $v['id'];
+                }
             }
-        }
-        if(empty($match_ids)) return Response::success();
+            if(empty($match_ids)) return Response::success();
 
-        $match_ids_str = implode(",", $match_ids);
+            $match_ids_str = implode(",", $match_ids);
+        }
         
         //上半场
         $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,
@@ -432,10 +438,10 @@ class StZqResult extends Model
                     "is_correct"=> -1,//自动比分
                 ];     
                 
-                $ret = $model['model_result']::where(['match_id' => $v['match_id']])
+                $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));
             }
         }
         
@@ -469,6 +475,7 @@ class StZqResult extends Model
                 'match_time'=>0,//比赛进行时间
                 "ctime"=>date('Y-m-d H:i:s'),
                 "update_time"=>date('Y-m-d H:i:s'),
+                "is_correct" => -1,
                 "start_time"=>date('Y-m-d H:i:s',strtotime($start_time)),
             ];