vali 6 年之前
父节点
当前提交
00fda5d16f

+ 16 - 0
app/Http/Model/StBqResultExpress.php

@@ -0,0 +1,16 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class Account
+ * @package App\Sports\Model
+ * 用户账号
+ */
+class StBqResultExpress extends Model
+{
+    protected $table = 'st_bq_result_express';
+    public $timestamps = false;
+
+}

+ 266 - 4
app/Http/Model/StLqResult.php

@@ -3,6 +3,10 @@ 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 StLqResult
@@ -16,19 +20,21 @@ class StLqResult extends Model
 
     /*
      * 写赛事结果
+     * 弃用
      */
-    public static function LQresult($model){
+    public static function LQresult___($model){
+        dd(123);
         //获取赛事表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([['ctime','>',date('Y-m-d H:i:s', strtotime("-1 day"))]])
             ->get()
             ->toarray();
 
         //没有数据,无需操作
         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("-7 day"))]])
+            ->where([['ctime','>',date('Y-m-d H:i:s', strtotime("-1 day"))]])
             ->get()
             ->toarray();
         //结果表无数据,直接插入
@@ -101,6 +107,262 @@ class StLqResult extends Model
         }
     }
 
+    /*
+     * 写赛事结果
+     */
+    public static function LQresult_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]])
+            ->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_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
+        where a.match_id = b.match_id and a.id = b.id ";
+        //第二节
+        $sql_2 = "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
+        where a.match_id = b.match_id and a.id = b.id ";
+        //第三节
+        $sql_3 = "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
+        where a.match_id = b.match_id and a.id = b.id ";
+        //第四节
+        $sql_4 = "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
+        where a.match_id = b.match_id and a.id = b.id ";
+
+
+        //第一节最终结果
+        $match_result_1 = DB::select($sql_1);
+        //第二节最终结果
+        $match_result_2 = DB::select($sql_2);
+        //第三节最终结果
+        $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']);
+                $time = time()-strtotime($v['match_time']);
+                $match_time = self::secTime($time);
+                //获取赛事每节的赛果
+                $result_1 = commonFunction::filter_by_value($match_result_1,'match_id',$v['id']);
+                $result_2 = commonFunction::filter_by_value($match_result_2,'match_id',$v['id']);
+                $result_3 = commonFunction::filter_by_value($match_result_3,'match_id',$v['id']);
+                $result_4 = commonFunction::filter_by_value($match_result_4,'match_id',$v['id']);
+                
+
+                if(!empty($result_1) and !empty($result_2) and !empty($result_3) and !empty($result_4)){
+
+                    //拼接赛事主队比分  {"1":0,"2":0,"3":0,"4":0}
+                    $home_score = [
+                        '1'=>$result_1['home_score'],
+                        '2'=>$result_2['home_score'] - $result_1['home_score'],
+                        '3'=>$result_3['home_score'] - $result_2['home_score'],
+                        '4'=>$result_4['home_score'] - $result_3['home_score'],
+                    ];
+                    //拼接赛事客队比分
+                    $guest_score = [
+                        '1'=>$result_1['guest_score'],
+                        '2'=>$result_2['guest_score'] - $result_1['guest_score'],
+                        '3'=>$result_3['guest_score'] - $result_2['guest_score'],
+                        '4'=>$result_4['guest_score'] - $result_3['guest_score'],
+                    ];
+
+                    //获取获胜球队
+                    if(($result_4['home_score']) > ($result_4['guest_score'])){
+                        $match_winer = $v['home_team'];
+                    }else{
+                        $match_winer = $v['guest_team'];
+                    }
+
+                    //获取总进球数
+                    $all_goal = ($result_4['home_score'])+($result_4['guest_score']);
+
+                    //赛事待写入赛果数据
+                    $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'=>$result_4['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"=> $result_4['home_rate']?:0, //主队让球
+                        "guest_rate"=> $result_4['guest_rate']?:0, //客队让球
+                        "home_score"=> json_encode($home_score)?:'', //主队进球数
+                        "guest_score"=> json_encode($guest_score)?:'', //客队进球数
+                        "all_goal"=> $all_goal?:0, //总进球数
+                        // "first_score"=> $result_4['first_score']?:'', //最先进球球队
+                        // "last_score"=> $result_4['last_score']?:'', //最后进球球队
+                        "match_score"=> $result_4['match_score']?:0, //赛事比分
+                        "match_winer"=>  $match_winer?:'',//获胜球队
+                        "match_process"=> $result_4['match_process']?:'',//比赛进程
+                        "u_home_score"=> $result_2['home_score']?:0,//上半场主队进球数
+                        "u_guest_score"=> $result_2['guest_score']?:0,//上半场客队进球数
+                    ];    
+                }
+            }
+        }
+
+
+        //写入赛果
+        if(!empty($set_match_r)){
+            $ret = $model['model_result']::insert($set_match_r);
+            if($ret != true) throw new \Exception( Response::generate('',Response::ADD_MATCH_R_ERROR));
+        }
+
+        return 1;
+    }
+
+    /**
+     * 获取自动赛事结果
+     * 只更新已结束+未手动修改的赛事结果
+     */
+    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();
+
+     
+        //没有数据,无需操作
+        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.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
+        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){
+                //获取结果json
+                $mark_result = json_decode($v->result_mark,true);
+                //如果为空,设默认值
+                if($mark_result == []){
+                    $mark_result_json = '{"schedule":"ot","r_time":"00:00","sc_1th_H":0,"sc_1th_C":0,"sc_2th_H":0,"sc_2th_C":0,"sc_3th_H":0,"sc_3th_C":0,"sc_4th_H":0,"sc_4th_C":0,"overtime_H":0,"overtime_C":0,"half_H":0,"half_C":0,"full_H":0,"full_C":0,"whole_H":0,"whole_C":0}';
+                    $mark_result = json_decode($mark_result_json,true);
+                }
+                //获取总进球数
+                $all_goal = $mark_result['whole_H']+$mark_result['whole_C'];
+                //获取比分
+                $match_score = $mark_result['whole_H'].':'.$mark_result['whole_C'];
+                //获取获胜球队
+                if(($mark_result['whole_H']) > ($mark_result['whole_C'])){
+                    $match_winer = $v->home_team;
+                }else{
+                    $match_winer = $v->guest_team;
+                }
+                //拼接赛事主队比分  {"1":0,"2":0,"3":0,"4":0}
+                $home_score = [
+                    '1'=>$mark_result['sc_1th_H'],
+                    '2'=>$mark_result['sc_2th_H'],
+                    '3'=>$mark_result['sc_3th_H'],
+                    '4'=>$mark_result['sc_4th_H'],
+                ];
+                //拼接赛事客队比分
+                $guest_score = [
+                    '1'=>$mark_result['sc_1th_C'],
+                    '2'=>$mark_result['sc_2th_C'],
+                    '3'=>$mark_result['sc_3th_C'],
+                    '4'=>$mark_result['sc_4th_C'],
+                ];
+                //赛事待写入赛果数据
+                $set_match_r = [
+                    "match_id"=> $v->match_id,
+                    "status"=>2,
+                    "update_time"=>date('Y-m-d H:i:s'),
+
+                    "home_rate"=> $v->home_rate?:0, //主队让球
+                    "guest_rate"=> $v->guest_rate?:0, //客队让球
+                    "home_score"=> json_encode($home_score)?:'', //主队进球数
+                    "guest_score"=> json_encode($guest_score)?:'', //客队进球数
+                    "all_goal"=> $all_goal?:0, //总进球数
+                    // "first_score"=> $result_4['first_score']?:'', //最先进球球队
+                    // "last_score"=> $result_4['last_score']?:'', //最后进球球队
+                    "match_score"=> $match_score?:0, //赛事比分
+                    "match_winer"=>  $match_winer?:'',//获胜球队
+                    "match_process"=> $mark_result['schedule']?:'',//比赛进程
+                    "u_home_score"=> $mark_result['half_H']?:0,//上半场主队进球数
+                    "u_guest_score"=> $mark_result['half_C']?:0,//上半场客队进球数
+                    "is_correct"=> -1,//自动比分
+
+                ];  
+
+                $ret = $model['model_result']::where(['match_id' => $v->match_id])
+                    ->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);

+ 16 - 0
app/Http/Model/StLqResultExpress.php

@@ -0,0 +1,16 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class Account
+ * @package App\Sports\Model
+ * 用户账号
+ */
+class StLqResultExpress extends Model
+{
+    protected $table = 'st_lq_result_express';
+    public $timestamps = false;
+
+}

+ 16 - 0
app/Http/Model/StWqResultExpress.php

@@ -0,0 +1,16 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class Account
+ * @package App\Sports\Model
+ * 用户账号
+ */
+class StWqResultExpress extends Model
+{
+    protected $table = 'st_wq_result_express';
+    public $timestamps = false;
+
+}

+ 16 - 0
app/Http/Model/StZqResultExpress.php

@@ -0,0 +1,16 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class Account
+ * @package App\Sports\Model
+ * 用户账号
+ */
+class StZqResultExpress extends Model
+{
+    protected $table = 'st_zq_result_express';
+    public $timestamps = false;
+
+}

+ 7 - 0
app/Http/Response/Response.php

@@ -59,6 +59,10 @@ class Response
     //===写预植赛果失败===
     const SET_MATCH_ERR = 10042;
 
+    //===写赛果失败===
+    const SET_MATCH_R_ERR = 10043;
+
+
 
     private static $errorMsgs = [
         self::SUCCESS => '成功',
@@ -110,6 +114,9 @@ class Response
         //===写预植赛果失败===
         self::SET_MATCH_ERR =>'写预植赛果失败',
 
+        //===写赛果失败===
+        self::SET_MATCH_R_ERR =>'写赛果失败',
+
     ];
 
     public static function getMsg($code)

+ 15 - 1
app/Lib/Biz/Sport/Common.php

@@ -15,6 +15,8 @@ use App\Http\Model\StZqOddsRecord;
 use App\Http\Model\StZqResult;
 use App\Http\Model\StZqResultRecord;
 use App\Http\Model\StZqBroadcast;
+use App\Http\Model\StZqResultExpress;
+
 
 use App\Http\Model\StLqMatch;
 use App\Http\Model\StLqLeague;
@@ -26,6 +28,8 @@ use App\Http\Model\StLqOddsRecord;
 use App\Http\Model\StLqResult;
 use App\Http\Model\StLqResultRecord;
 use App\Http\Model\StLqBroadcast;
+use App\Http\Model\StLqResultExpress;
+
 
 use App\Http\Model\StWqResultRecord;
 use App\Http\Model\StWqMatch;
@@ -37,6 +41,8 @@ use App\Http\Model\StWqOdds;
 use App\Http\Model\StWqOddsRecord;
 use App\Http\Model\StWqResult;
 use App\Http\Model\StWqBroadcast;
+use App\Http\Model\StWqResultExpress;
+
 
 use App\Http\Model\StBqResultRecord;
 use App\Http\Model\StBqMatch;
@@ -48,6 +54,8 @@ use App\Http\Model\StBqOdds;
 use App\Http\Model\StBqOddsRecord;
 use App\Http\Model\StBqResult;
 use App\Http\Model\StBqBroadcast;
+use App\Http\Model\StBqResultExpress;
+
 
 class Common
 {
@@ -712,6 +720,8 @@ class Common
                     $model_local_league = new StZqLocalLeague;
                     $model_local_match = new StZqLocalMatch;
                     $model_broadcast = new StZqBroadcast;
+                    $model_result_express = new StZqResultExpress;
+                    
                     break;
                 case 'lq':
                     $model_league = new StLqLeague;
@@ -724,6 +734,7 @@ class Common
                     $model_local_league = new StLqLocalLeague;
                     $model_local_match = new StLqLocalMatch;
                     $model_broadcast = new StLqBroadcast;
+                    $model_result_express = new StLqResultExpress;
                     break;
                 case 'wq':
                     $model_league = new StWqLeague;
@@ -736,6 +747,7 @@ class Common
                     $model_local_league = new StWqLocalLeague;
                     $model_local_match = new StWqLocalMatch;
                     $model_broadcast = new StWqBroadcast;
+                    $model_result_express = new StWqResultExpress;
                     break;
                 case 'bq':
                     $model_league = new StBqLeague;
@@ -748,6 +760,7 @@ class Common
                     $model_local_league = new StBqLocalLeague;
                     $model_local_match = new StBqLocalMatch;
                     $model_broadcast = new StBqBroadcast;
+                    $model_result_express = new StBqResultExpress;
                     break;
                 default:
                     throw new \Exception(Response::generate(Response::ABNORMAL));
@@ -763,7 +776,8 @@ class Common
             'model_league_result' => $model_league_result,//联赛结果
             'model_local_league' => $model_local_league,//本地关联联赛
             'model_local_match' => $model_local_match,//本地关联赛事
-            'model_broadcast' => $model_broadcast,
+            'model_broadcast' => $model_broadcast, //直播数据接口
+            'model_result_express' => $model_result_express,//赛果数据
         ];
         return $data;
     }

+ 67 - 1
app/Logic/DataLogic.php

@@ -158,6 +158,72 @@ class DataLogic
         }
     }
 
+
+    //写赛果接口
+    public function setResultExpress(Req $data)
+    {
+        $ret = $this->setResultExpress_v1($data);
+        return $ret;
+    }
+
+    /**
+     * 写赛果数据
+     */
+    public function setResultExpress_v1($data)
+    {
+        try {
+            //开启事务
+            DB::beginTransaction();
+            $obt = $data['data;'];
+
+            //请求 数据 为空
+            if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
+            $getData = $this->getAddData($obt);
+
+            //不是 赛事 结果 记录 数据
+            if ($getData['title'] != 'result') throw new \Exception(Response::generate('不是赛果数据,', Response::ABNORMAL));
+
+            //获取球类代码
+            $game_code = $getData['game_code'];
+            //获取数据源
+            $source = $getData['source'];
+            //获取球类名称
+            $gameName = gameModel::getGameName($game_code);
+            //获取 model
+            $models = commonFunction::getModels($game_code, 1);
+            //获取 赛事 数据
+            $match_r_data = $getData['data'];
+
+            if (!empty($match_r_data)) {
+                foreach ($match_r_data as $k => $v) {
+                    $del = $models['model_result_express']::where('match_id', $v['match_id'])->delete();
+                    $v['c_time'] = date('Y-m-d H:i:s', time());
+                    $v['u_time'] = date('Y-m-d H:i:s', time());
+                    $v['source'] = $source;
+                    $v['play_data'] = json_encode($v['play_data'], JSON_UNESCAPED_UNICODE);
+
+                    $ret = $models['model_result_express']::insert($v);
+                    if ($ret != true) throw new \Exception(Response::generate($gameName . ';', Response::SET_MATCH_R_ERR));
+                }
+
+                //写 赛事 结果 记录
+            }
+
+
+            $this->writeLog($data, Response::success());
+            //提交事务
+            DB::commit();
+            //写请求数据 日志记录
+            return Response::success();
+        } catch (\Exception $e) {
+            //回滚事务
+            DB::rollBack();
+            $this->writeLog($data, ['file' => $e->getFile(), 'line' => $e->getLine(), 'msg' => $e->getMessage()]);
+            return $e->getMessage();
+        }
+    }
+
+
     /*
      * 写 赛事 数据
      * 每个请求 包含 N个联赛 下 N个赛事
@@ -360,7 +426,7 @@ class DataLogic
                                 'team_h' => $data['home_team'],
                                 'team_g' => $data['guest_team'],
                             ];
-                            
+
                             StTeamModel::setTeam($game_code, $team, $source);
 
                             //追加写赛事结果

+ 5 - 3
datainf/logic/HttpServerDataInf.php

@@ -74,13 +74,13 @@ class HttpServerDataInf
     {
         $response->header('Content-Type', 'text/html; charset=utf-8');
         $response->header('Server', 'DataInfaceServer');
-        $now = explode(" ",microtime());
-        $paras = array_merge(['request_time' => date("H:i:s",$now[1]).substr($now[0],1,5)], !empty($request->get) ? $request->get : [], !empty($request->post) ? $request->post : []);
+        $now = explode(" ", microtime());
+        $paras = array_merge(['request_time' => date("H:i:s", $now[1]) . substr($now[0], 1, 5)], !empty($request->get) ? $request->get : [], !empty($request->post) ? $request->post : []);
         $this->httpserver->account->add();
 
 
         $request_uri = substr($request->server['request_uri'], 1);
-        $urls = ['setLeague', 'setMatch', 'setMatchResult', 'setOdds', 'setOddsCH', 'setBroadCast', 'upMatch'];
+        $urls = ['setLeague', 'setMatch', 'setMatchResult', 'setOdds', 'setOddsCH', 'setBroadCast', 'upMatch', 'setResultExpress'];
 
         if (!in_array($request_uri, $urls)) {
             $data = Response::generate('', 0, '', '无效的url');
@@ -147,6 +147,8 @@ class HttpServerDataInf
             case 'upMatch':
                 $ret = DataLogic::getInstance()->upMatch($data);
                 break;
+            case 'setResultExpress':
+                $ret = DataLogic::getInstance()->setResultExpress($data);
             default:
                 $ret = 'false';
                 break;