vali hace 6 años
padre
commit
7c590359c2

+ 326 - 1
app/Http/Model/StBqResult.php

@@ -3,6 +3,8 @@ namespace App\Http\Model;
 
 use Illuminate\Database\Eloquent\Model;
 use App\Http\Response\Response;
+use Illuminate\Support\Facades\DB;
+use App\Lib\Biz\Sport\Common as commonFunction;
 
 /**
  * Class StBqResult
@@ -16,8 +18,9 @@ class StBqResult extends Model
 
     /*
      * 写赛事结果
+     * 弃用
      */
-    public static function BQresult($model){
+    public static function BQresult__($model){
         //获取赛事表7天内所有赛事
         $matchData = $model['model_match']::select('id','home_team','guest_team','lg_id','status','tag','match_date','match_time')
             ->where([['ctime','>',date('Y-m-d H:i:s', strtotime("-7 day"))]])
@@ -89,6 +92,328 @@ class StBqResult extends Model
         }
     }
 
+    public static function BQresult_v1($model){
+        //获取赛事表7天内所有赛事
+        $matchData = $model['model_match']::select('id','home_team','guest_team','lg_id','status','tag','match_date','match_time')
+            ->where([['match_date','>',date('Y-m-d',strtotime("-2 day"))],['status','=',2]])
+            ->get()
+            ->toArray();
+
+        
+        //获取赛事结果表 一天内
+        $matchData_r = $model['model_result']::select('match_id')
+            ->where([['ctime','>',date('Y-m-d H:i:s', strtotime("-2 day"))]])
+            ->get()
+            ->toArray();
+
+        if(!empty($matchData_r)){
+            //如果结果表有数据,则获取结果表没有的赛事
+            foreach ($matchData as $k => $v) {
+                foreach ($matchData_r as $kk => $vv) {
+                    if ($v['id'] == $vv['match_id']) {
+                        unset($matchData[$k]);
+                    }
+                }
+            }
+        }
+
+         //没有数据,无需操作
+         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_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)){
+            foreach($matchData as $k =>$v ){
+                //获取开赛时间
+                $start_time = ($v['match_date'].' '.$v['match_time']);
+                $time = time()-strtotime($v['match_time']);
+                $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);
+
+                    //获取进程
+                    $match_process = $resultData['match_process'];
+
+                    //获胜球员
+                    $match_winer = '';
+                    if($result_mark['game_num_H'] > $result_mark['game_num_C']){
+                        $match_winer = $v['home_team'];
+                    }else{
+                        $match_winer = $v['guest_team'];
+                    }
+
+                    //组装输赢结果json
+                    $inning = [
+                        1=>[
+                            "home"=>$result_mark['sc_1th_H'],
+                            "guest"=>$result_mark['sc_1th_C'],
+                        ],
+                        2=>[
+                            "home"=>$result_mark['sc_2th_H'],
+                            "guest"=>$result_mark['sc_2th_C'],
+                        ],
+                        3=>[
+                            "home"=>$result_mark['sc_3th_H'],
+                            "guest"=>$result_mark['sc_3th_C'],
+                        ],
+                        4=>[
+                            "home"=>$result_mark['sc_4th_H'],
+                            "guest"=>$result_mark['sc_4th_C'],
+                        ],
+                        5=>[
+                            "home"=>$result_mark['sc_5th_H'],
+                            "guest"=>$result_mark['sc_5th_C'],
+                        ],
+                        6=>[
+                            "home"=>$result_mark['sc_6th_H'],
+                            "guest"=>$result_mark['sc_6th_C'],
+                        ],
+                        7=>[
+                            "home"=>$result_mark['sc_7th_H'],
+                            "guest"=>$result_mark['sc_7th_C'],
+                        ],
+                        8=>[
+                            "home"=>$result_mark['sc_8th_H'],
+                            "guest"=>$result_mark['sc_8th_C'],
+                        ],
+                        9=>[
+                            "home"=>$result_mark['sc_9th_H'],
+                            "guest"=>$result_mark['sc_9th_C'],
+                        ],
+                        "other"=>[//加时
+                            "home"=>$result_mark['OT_H'],
+                            "guest"=>$result_mark['OT_C'],
+                        ]
+                    
+                    ];
+
+                    //上半场主队进球
+                    $u_home_score = $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'];
+
+                    //上半场客队进球
+                    $u_guest_score = $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'];
+
+                    //总进球数
+                    $all_goal = $result_mark['game_num_H'] + $result_mark['game_num_C'];
+                   
+                    //赛事待写入赛果数据
+                    $set_match_r[] = [
+                        "match_id"=> $v['id'],
+                        "home_team"=>$v['home_team'],
+                        "guest_team"=>$v['guest_team'],
+                        "lg_id"=>$v['lg_id'],
+                        "status"=>$v['status'],
+                        "tag"=> $v['tag'],
+                        'match_time'=>$resultData['a_time']?:0,
+                        "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"=> $resultData['home_rate']?:0, //主队让球
+                        "guest_rate"=> $resultData['guest_rate']?:0, //客队让球
+                        "home_score"=> $result_mark['game_num_H']?:0, //主队进球
+                        "guest_score"=> $result_mark['game_num_C']?:0, //客队进球
+                        "all_goal"=> $all_goal?:0, //总局数
+                        // "first_score"=> $resultData['first_score']?:'', //最先得分
+                        // "last_score"=> $resultData['last_score']?:'', //最后得分
+                        "match_score"=> $match_score?:'',//赛事比分
+                        "match_winer"=>  $match_winer?:'',//获胜队员
+                        "match_process"=> $match_process?:'',//比赛进程
+                        "u_home_score"=> $u_home_score,//上半场主队进球
+                        "u_guest_score"=> $u_guest_score ,//上半场客队进球
+                        "match_score_t"=> json_encode($inning)?:'',//每局输赢结果
+                    ];    
+                }
+            }
+        }
+
+        //写入赛果
+        if(!empty($set_match_r)){
+            $ret = $model['model_result']::insert($set_match_r);
+            if($ret != true) throw new \Exception( Response::generate('',Response::ADD_MATCH_R_ERROR));
+        }
+
+        return 1;
+
+    }
+     /**
+     * 获取自动赛事结果
+     * 只更新已结束+未手动修改的赛事结果
+     * $match_id 本地赛事id 为0时 则用于后台手动刷新赛果 
+     */
+    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($match_ids)) return Response::success();
+
+            $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
+         where a.match_id = b.match_id and a.id = b.id ";
+
+        //赛事最终结果
+        $match_result = DB::select($sql_result);
+
+        if(!empty($match_result)){
+            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);
+
+                    //获取进程
+                    $match_process = $resultData['match_process'];
+
+                    //获胜球员
+                    $match_winer = '';
+                    if($result_mark['game_num_H'] > $result_mark['game_num_C']){
+                        $match_winer = $v->home_team;
+                    }else{
+                        $match_winer = $v->guest_team;
+                    }
+
+                    //组装输赢结果json
+                    $inning = [
+                        1=>[
+                            "home"=>$result_mark['sc_1th_H'],
+                            "guest"=>$result_mark['sc_1th_C'],
+                        ],
+                        2=>[
+                            "home"=>$result_mark['sc_2th_H'],
+                            "guest"=>$result_mark['sc_2th_C'],
+                        ],
+                        3=>[
+                            "home"=>$result_mark['sc_3th_H'],
+                            "guest"=>$result_mark['sc_3th_C'],
+                        ],
+                        4=>[
+                            "home"=>$result_mark['sc_4th_H'],
+                            "guest"=>$result_mark['sc_4th_C'],
+                        ],
+                        5=>[
+                            "home"=>$result_mark['sc_5th_H'],
+                            "guest"=>$result_mark['sc_5th_C'],
+                        ],
+                        6=>[
+                            "home"=>$result_mark['sc_6th_H'],
+                            "guest"=>$result_mark['sc_6th_C'],
+                        ],
+                        7=>[
+                            "home"=>$result_mark['sc_7th_H'],
+                            "guest"=>$result_mark['sc_7th_C'],
+                        ],
+                        8=>[
+                            "home"=>$result_mark['sc_8th_H'],
+                            "guest"=>$result_mark['sc_8th_C'],
+                        ],
+                        9=>[
+                            "home"=>$result_mark['sc_9th_H'],
+                            "guest"=>$result_mark['sc_9th_C'],
+                        ],
+                        "other"=>[//加时
+                            "home"=>$result_mark['OT_H'],
+                            "guest"=>$result_mark['OT_C'],
+                        ]
+                    
+                    ];
+
+                    //上半场主队进球
+                    $u_home_score = $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'];
+
+                    //上半场客队进球
+                    $u_guest_score = $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'];
+
+                    //总进球数
+                    $all_goal = $result_mark['game_num_H'] + $result_mark['game_num_C'];
+                   
+                    //赛事待写入赛果数据
+                    $set_match_r = [
+                        "match_id"=> $v->match_id,
+                        "status"=>2,
+                        "update_time"=>date('Y-m-d H:i:s'),
+
+                        "home_rate"=> $resultData['home_rate']?:0, //主队让球
+                        "guest_rate"=> $resultData['guest_rate']?:0, //客队让球
+                        "home_score"=> $result_mark['game_num_H']?:0, //主队进球
+                        "guest_score"=> $result_mark['game_num_C']?:0, //客队进球
+                        "all_goal"=> $all_goal?:0, //总局数
+                        // "first_score"=> $resultData['first_score']?:'', //最先得分
+                        // "last_score"=> $resultData['last_score']?:'', //最后得分
+                        "match_score"=> $match_score?:'',//赛事比分
+                        "match_winer"=>  $match_winer?:'',//获胜队员
+                        "match_process"=> $match_process?:'',//比赛进程
+                        "u_home_score"=> $u_home_score,//上半场主队进球
+                        "u_guest_score"=> $u_guest_score ,//上半场客队进球
+                        "match_score_t"=> json_encode($inning)?:'',//每局输赢结果
+                        "is_correct"=> -1,//自动比分
+                    ];    
+
+                    $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;
+
+    }
+
     //计算滚球 赛事进行时间
     public static function secTime($sec=0){
         $min = floor($sec/60);

+ 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));               
             }
         }
 

+ 324 - 3
app/Http/Model/StWqResult.php

@@ -3,6 +3,8 @@ namespace App\Http\Model;
 
 use Illuminate\Database\Eloquent\Model;
 use App\Http\Response\Response;
+use Illuminate\Support\Facades\DB;
+use App\Lib\Biz\Sport\Common as commonFunction;
 
 /**
  * Class StWqResult
@@ -16,13 +18,14 @@ class StWqResult extends Model
 
     /*
      * 写赛事结果
+     * 弃用
      */
-    public static function WQresult($model){
+    public static function WQresult__($model){
         //获取赛事表7天内所有赛事
         $matchData = $model['model_match']::select('id','home_team','guest_team','lg_id','status','tag','match_date','match_time')
-            ->where([['ctime','>',date('Y-m-d H:i:s', strtotime("-7 day"))]])
+            ->where([['match_date','>',date('Y-m-d',strtotime("-2 day"))],['status','=',2]])
             ->get()
-            ->toarray();
+            ->toArray();
 
         //没有数据,无需操作
         if(empty($matchData)) return Response::success();
@@ -88,6 +91,324 @@ class StWqResult extends Model
             }
         }
     }
+    public static function WQresult_v1($model){
+
+        //获取赛事表7天内所有赛事
+        $matchData = $model['model_match']::select('id','home_team','guest_team','lg_id','status','tag','match_date','match_time')
+            ->where([['match_date','>',date('Y-m-d',strtotime("-2 day"))],['status','=',2]])
+            ->get()
+            ->toArray();
+
+        //获取赛事结果表 一天内
+        $matchData_r = $model['model_result']::select('match_id')
+            ->where([['ctime','>',date('Y-m-d H:i:s', strtotime("-2 day"))]])
+            ->get()
+            ->toArray();
+
+        if(!empty($matchData_r)){
+            //如果结果表有数据,则获取结果表没有的赛事
+            foreach ($matchData as $k => $v) {
+                foreach ($matchData_r as $kk => $vv) {
+                    if ($v['id'] == $vv['match_id']) {
+                        unset($matchData[$k]);
+                    }
+                }
+            }
+        }
+
+         //没有数据,无需操作
+         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
+        where a.match_id = b.match_id and a.id = b.id ";
+
+        //赛事最终结果
+        $match_result = DB::select($sql_result);
+
+        //拼装赛事结果数据 
+        $set_match_r = [];
+        $ss = [];
+
+        if(!empty($match_result)){
+            foreach($matchData as $k =>$v ){
+                //获取开赛时间
+                $start_time = ($v['match_date'].' '.$v['match_time']);
+                $time = time()-strtotime($v['match_time']);
+                $match_time = self::secTime($time);
+                //获取赛事每节的赛果
+                $resultData = commonFunction::filter_by_value($match_result,'match_id',$v['id']);
+            
+                //如果有获取到结果,并且进程不为空,则写入赛事结果数据
+                if(!empty($resultData) and $resultData['match_process'] != ''){
+                    //获取赛果json
+                    $result_mark = json_decode($resultData['result_mark'],true);
+
+                    $sss[] = $result_mark;
+
+                    //获取进程
+                    $match_process = '';
+                    if($result_mark['schedule']){
+                        $match_process = $result_mark['schedule'];
+                    }
+
+                    //获胜球员
+                    $match_winer = '';
+                    if($result_mark['game_num_H'] > $result_mark['game_num_C']){
+                        $match_winer = $v['home_team'];
+                    }else{
+                        $match_winer = $v['guest_team'];
+                    }
+
+                    //组装输赢结果json
+                    $inning = [
+                        1=>[
+                            "home"=>$result_mark['sc_1th_H'],
+                            "guest"=>$result_mark['sc_1th_C'],
+                        ],
+                        2=>[
+                            "home"=>$result_mark['sc_2th_H'],
+                            "guest"=>$result_mark['sc_2th_C'],
+                        ],
+                        3=>[
+                            "home"=>$result_mark['sc_3th_H'],
+                            "guest"=>$result_mark['sc_3th_C'],
+                        ],
+                        4=>[
+                            "home"=>$result_mark['sc_4th_H'],
+                            "guest"=>$result_mark['sc_4th_C'],
+                        ],
+                        5=>[
+                            "home"=>$result_mark['sc_5th_H'],
+                            "guest"=>$result_mark['sc_5th_C'],
+                        ],
+                    
+                    ];
+
+                    //赛事比分
+                    $match_score = $result_mark['game_num_H'].':'.$result_mark['game_num_C'];
+                   
+                    //赛事待写入赛果数据
+                    /*
+                    $set_match_r[] = [
+                        "match_id"=> $v['id'],
+                        "home_player_name"=>$v['home_team'],
+                        "guest_player_name"=>$v['guest_team'],
+                        "lg_id"=>$v['lg_id'],
+                        "status"=>$v['status'],
+                        "tag"=> $v['tag'],
+                        'match_time'=>$resultData['a_time']?:0,
+                        "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_player_let_plate"=> $resultData['home_player_let_plate']?:0, //主队让盘
+                        "guest_player_let_plate"=> $resultData['guest_player_let_plate']?:0, //客队让盘
+                        "home_player_let_inning"=> $resultData['home_player_let_inning']?:0, //主队让局
+                        "guest_player_let_inning"=> $resultData['guest_player_let_inning']?:0, //客队让局
+                        "home_player_score"=> $result_mark['game_num_H']?:'', //主队得分
+                        "guest_player_score"=> $result_mark['game_num_C']?:'', //客队得分
+                        "all_inning"=> $resultData['all_inning']?:0, //总局数
+                        // "first_score_player"=> $resultData['first_score']?:'', //最先得分
+                        // "last_score_player"=> $resultData['last_score']?:'', //最后得分
+                        "first_inning_score"=> $resultData['first_inning_score']?:0, //第一局比分
+                        "second_inning_score"=> $resultData['second_inning_score']?:0,//第二局比分
+                        "third_inning_score"=> $resultData['third_inning_score']?:0,//第三局比分
+                        "match_score"=> $match_score?:'',//赛事比分
+                        "match_winer_player"=>  $match_winer?:'',//获胜队员
+                        "match_process"=> $match_process?:'',//比赛进程
+                        "inning"=> json_encode($inning)?:'',//每局输赢结果
+                    ]; 
+                    */
+                    $set_match_r[] = [
+                        "match_id"=> $v['id'],
+                        "home_player_name"=>$v['home_team'],
+                        "guest_player_name"=>$v['guest_team'],
+                        "lg_id"=>$v['lg_id'],
+                        "status"=>$v['status'],
+                        "tag"=> $v['tag'],
+                        'match_time'=>$resultData['a_time']?:0,
+                        "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_player_let_plate"=> $resultData['home_player_let_plate']?:0, //主队让盘
+                        "guest_player_let_plate"=> $resultData['guest_player_let_plate']?:0, //客队让盘
+                        "home_player_let_inning"=> $resultData['home_player_let_inning']?:0, //主队让局
+                        "guest_player_let_inning"=> $resultData['guest_player_let_inning']?:0, //客队让局
+                        "home_player_score"=> $result_mark['game_num_H']?:0, //主队得分
+                        "guest_player_score"=> $result_mark['game_num_C']?:0, //客队得分
+                        "all_inning"=> $resultData['all_inning']?:0, //总局数
+                        // "first_score_player"=> $resultData['first_score']?:'', //最先得分
+                        // "last_score_player"=> $resultData['last_score']?:'', //最后得分
+                        "first_inning_score"=> $resultData['first_inning_score']?:'', //第一局比分
+                        "second_inning_score"=> $resultData['second_inning_score']?:'',//第二局比分
+                        "third_inning_score"=> $resultData['third_inning_score']?:'',//第三局比分
+                        "match_score"=> $match_score?:'',//赛事比分
+                        "match_winer_player"=>  $match_winer?:'',//获胜队员
+                        "match_process"=> $match_process?:'',//比赛进程
+                        "inning"=> json_encode($inning)?:'',//每局输赢结果
+                    ]; 
+
+                }
+            }
+        }
+        //写入赛果1
+        if(!empty($set_match_r)){
+            $ret = $model['model_result']::insert($set_match_r);
+            if($ret != true) throw new \Exception( Response::generate('',Response::ADD_MATCH_R_ERROR));
+        }
+
+        return 1;
+
+    }
+
+    /**
+     * 获取自动赛事结果
+     * 只更新已结束+未手动修改的赛事结果
+     * $match_id 本地赛事id 为0时 则用于后台手动刷新赛果 
+     */
+    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();
+
+            $match_ids_str = implode(",", $match_ids);
+        }
+
+        //组装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
+        where a.match_id = b.match_id and a.id = b.id ";
+
+        //赛事最终结果
+        $match_result = DB::select($sql_result);
+
+        if(!empty($match_result)){
+            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
+                    $result_mark = json_decode($resultData['result_mark'],true);
+
+                    //获取进程
+                    $match_process = '';
+                    if($result_mark['schedule']){
+                        $match_process = $result_mark['schedule'];
+                    }
+
+                    //获胜球员
+                    $match_winer = '';
+                    if($result_mark['game_num_H'] > $result_mark['game_num_C']){
+                        $match_winer = $resultData['home_player_name'];
+                    }else{
+                        $match_winer = $resultData['guest_player_name'];
+                    }
+
+                    //组装输赢结果json
+                    $inning = [
+                        1=>[
+                            "home"=>$result_mark['sc_1th_H'],
+                            "guest"=>$result_mark['sc_1th_C'],
+                        ],
+                        2=>[
+                            "home"=>$result_mark['sc_2th_H'],
+                            "guest"=>$result_mark['sc_2th_C'],
+                        ],
+                        3=>[
+                            "home"=>$result_mark['sc_3th_H'],
+                            "guest"=>$result_mark['sc_3th_C'],
+                        ],
+                        4=>[
+                            "home"=>$result_mark['sc_4th_H'],
+                            "guest"=>$result_mark['sc_4th_C'],
+                        ],
+                        5=>[
+                            "home"=>$result_mark['sc_5th_H'],
+                            "guest"=>$result_mark['sc_5th_C'],
+                        ],
+                    
+                    ];
+
+                    //赛事比分
+                    $match_score = $result_mark['game_num_H'].':'.$result_mark['game_num_C'];
+                   
+                    //赛事待写入赛果数据
+                   
+                    $set_match_r = [
+                        "match_id"=> $v->match_id,
+                        "status"=>2,
+                        "update_time"=>date('Y-m-d H:i:s'),
+
+                        "home_player_let_plate"=> $resultData['home_player_let_plate']?:0, //主队让盘
+                        "guest_player_let_plate"=> $resultData['guest_player_let_plate']?:0, //客队让盘
+                        "home_player_let_inning"=> $resultData['home_player_let_inning']?:0, //主队让局
+                        "guest_player_let_inning"=> $resultData['guest_player_let_inning']?:0, //客队让局
+                        "home_player_score"=> $result_mark['game_num_H']?:0, //主队得分
+                        "guest_player_score"=> $result_mark['game_num_C']?:0, //客队得分
+                        "all_inning"=> $resultData['all_inning']?:0, //总局数
+                        // "first_score_player"=> $resultData['first_score']?:'', //最先得分
+                        // "last_score_player"=> $resultData['last_score']?:'', //最后得分
+                        "first_inning_score"=> $resultData['first_inning_score']?:'', //第一局比分
+                        "second_inning_score"=> $resultData['second_inning_score']?:'',//第二局比分
+                        "third_inning_score"=> $resultData['third_inning_score']?:'',//第三局比分
+                        "match_score"=> $match_score?:'',//赛事比分
+                        "match_winer_player"=>  $match_winer?:'',//获胜队员
+                        "match_process"=> $match_process?:'',//比赛进程
+                        "inning"=> json_encode($inning)?:'',//每局输赢结果
+                        "is_correct"=> -1,//自动比分
+
+                    ]; 
+
+                    $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;
+    }
 
     //计算滚球 赛事进行时间
     public static function secTime($sec=0){

+ 2 - 1
app/Http/Model/StZqOdds.php

@@ -30,12 +30,13 @@ class StZqOdds extends Model
     /*
      * 更新赛事下赔率状态
      */
-    public static function upOddsStatus($model=[],$others_match_id='',$others_lg_id=[],$source='',$odds_only=[]){
+    public static function upOddsStatus($model=[],$others_match_id='',$others_lg_id=[],$source='',$odds_only=[],$is_stringscene=0){
         $where = [];
         //普通 赔率
         if(!empty($others_match_id) and !empty($source)){
             $where = [
                 ['others_match_id','=',$others_match_id],
+                ['is_stringscene','=',$is_stringscene],
                 ['source','=',$source]
             ];
             //获取当前 赛事 所有 赔率only

+ 64 - 87
app/Http/Model/StZqResult.php

@@ -192,7 +192,7 @@ class StZqResult extends Model
     /*
      * 写赛事结果
      */
-    public static function ZQresult($model){
+    public static function ZQresult_v1($model){
         //获取当天开始并且已结束的所有赛事
         $matchData = $model['model_match']::select('id','home_team','guest_team','lg_id','status','tag','match_date','match_time')
             ->where([['match_date','>',date('Y-m-d', strtotime("-2 day"))],['status','=',2]])
@@ -331,56 +331,45 @@ class StZqResult extends Model
     }
 
     /**
-     * 测试新结果写入
+     * 获取自动赛事结果
+     * 只更新已结束+未手动修改的赛事结果
+     * $match_id 本地赛事id 为0时 则用于后台手动刷新赛果 
      */
-    public static function ZQresult_xxx($model){
-        //获取当天开始并且已结束的所有赛事
-        $matchData = $model['model_match']::select('id','home_team','guest_team','lg_id','status','tag','match_date','match_time')
-            ->where([['match_date','>',date('Y-m-d', strtotime("-2 day"))],['status','=',2]])
-            ->get()
-            ->toArray();
-
-        //获取赛事结果表 一天内
-        $matchData_r = $model['model_result']::select('match_id','is_correct')
-            ->where([['start_time','>',date('Y-m-d H:i:s', strtotime("-2 day"))],['status','=',2]])
-            ->get()
-            ->toArray();
-            dd($matchData_r);
-
-        if(!empty($matchData_r)){
-            //如果结果表有数据,则获取结果表没有的赛事
-            foreach ($matchData as $k => $v) {
-                foreach ($matchData_r as $kk => $vv) {
-                    if ($v['id'] == $vv['match_id']) {
-                        unset($matchData[$k]);
-                    }
+    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();
 
+            $match_ids_str = implode(",", $match_ids);
         }
-
-        //没有数据,无需操作
-        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_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,
+        $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
         where a.match_id = b.match_id and a.id = b.id ";
 
         //全场
-        $sql_f = "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,a.home_rate,a.guest_rate from st_zq_result_record a,
+        $sql_f = "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,a.home_rate,a.guest_rate from st_zq_result_record a,
         (select match_id,max(id) id from st_zq_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 ";
 
@@ -399,6 +388,8 @@ class StZqResult extends Model
                     if($v->match_id == $vv->match_id){
                         $match_result_record[$k] = [
                             "match_id"=>$v->match_id,
+                            "home_team"=>$v->home_team,
+                            "guest_team"=>$v->guest_team,
                             "home_score"=> $vv->home_score,
                             "guest_score"=> $vv->guest_score,
                             "a_time"=> $vv->a_time,
@@ -417,58 +408,43 @@ class StZqResult extends Model
                 }
             }
         }
-        
 
-        //组装赛果数据
         if(!empty($match_result_record)){
-            foreach ($matchData as $k=>$v){
-                $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){        
-                    if($v['id'] == $vv['match_id']){
-                        //获取获胜球队
-                        if(($vv['home_score']) > ($vv['guest_score'])){
-                            $match_winer = $v['home_team'];
-                        }else{
-                            $match_winer = $v['guest_team'];
-                        }
-                        $set_match_r[] = [
-                            "match_id"=> $v['id'],
-                            "home_team"=>$v['home_team'],
-                            "guest_team"=>$v['guest_team'],
-                            "lg_id"=>$v['lg_id'],
-                            "status"=>$v['status'],
-                            "tag"=> $v['tag'],
-                            'match_time'=>$vv['a_time']?:0,//比赛进行时间
-                            "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, //主队进球数
-                            "guest_score"=> $vv['guest_score']?:0, //客队进球数
-                            "all_goal"=> $vv['all_goal']?:0, //总进球数
-                            // "first_score"=> $vv['first_score']?:'', //最先进球球队
-                            // "last_score"=> $vv['last_score']?:'', //最后进球球队
-                            "match_score"=> $vv['match_score']?:0, //赛事比分
-                            "match_winer"=>  $match_winer?:'',//获胜球队
-                            "match_process"=> $vv['match_process']?:'',//比赛进程
-                            "u_home_score"=> $vv['u_home_score']?:0,//上半场主队进球数
-                            "u_guest_score"=> $vv['u_guest_score']?:0,//上半场客队进球数
-                        ];                        
-                    }                   
+            foreach($match_result_record as $k=>$v){
+                //获取获胜球队
+                if(($v['home_score']) > ($v['guest_score'])){
+                    $match_winer = $v['home_team'];
+                }else{
+                    $match_winer = $v['guest_team'];
+                
                 }
-            }
-        }
 
-        //写入赛果
-        if(!empty($set_match_r)){
-            $ret = $model['model_result']::insert($set_match_r);
-            if($ret != true) throw new \Exception( Response::generate('',Response::ADD_MATCH_R_ERROR));
+                $set_match_r = [
+                    "match_id"=> $v['match_id'],
+                    "update_time"=>date('Y-m-d H:i:s'),
+                    "status"=>2,//已结束
+                    "home_rate"=> $v['home_rate']?:0, //主队让球
+                    "guest_rate"=> $v['guest_rate']?:0, //客队让球
+                    "home_score"=> $v['home_score']?:0, //主队进球数
+                    "guest_score"=> $v['guest_score']?:0, //客队进球数
+                    "all_goal"=> $v['all_goal']?:0, //总进球数
+                    // "first_score"=> $vv['first_score']?:'', //最先进球球队
+                    // "last_score"=> $vv['last_score']?:'', //最后进球球队
+                    "match_score"=> $v['match_score']?:0, //赛事比分
+                    "match_winer"=>  $match_winer?:'',//获胜球队
+                    "match_process"=> $v['match_process']?:'',//比赛进程
+                    "u_home_score"=> $v['u_home_score']?:0,//上半场主队进球数
+                    "u_guest_score"=> $v['u_guest_score']?:0,//上半场客队进球数
+                    "is_correct"=> -1,//自动比分
+                ];     
+                
+                $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;
     }
 
@@ -499,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)),
             ];
 

+ 55 - 0
app/Http/Model/St_match_rule.php

@@ -0,0 +1,55 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+use App\Http\Response\Response;
+
+/**
+ * Class Account
+ * @package App\Sports\Model
+ * 赛事规则model
+ */
+class St_match_rule extends Model
+{
+
+    protected $table = 'st_match_rule';
+    public $timestamps = false;
+
+    /**
+     * 获取赛事规则数据
+     */
+    function getList($limit = 0, $where = []){
+        return  $this->select('id','group_id','group_name','author','atime','utime','status','modular_name')->where($where)
+        ->limit($limit)
+        ->get()
+        ->toArray();
+
+    }
+
+    /**
+     * 添加赛事规则
+     */
+    function addMatchRule($data){
+        $res=$this->insert($data);
+        if(!$res){
+            return -6030001222;
+        }
+    }
+
+    /**
+     * 获取当前id规则
+     */
+    function getDmsg($id=0) {
+		$data = $this->find($id);
+		if (!$data) {
+			return -4010010122; //没有数据
+		}
+		return $data->toArray();
+    }
+
+    //禁用操作
+    public function closeGame($where,$data){
+        return $this->where($where)->update($data);
+    }
+   
+}

+ 20 - 0
app/Http/Model/St_match_rule_group.php

@@ -0,0 +1,20 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+use App\Http\Response\Response;
+
+/**
+ * Class Account
+ * @package App\Sports\Model
+ * 赛事规则组model
+ */
+class St_match_rule_group extends Model
+{
+
+    protected $table = 'st_match_rule_group';
+    public $timestamps = false;
+
+
+   
+}