소스 검색

追加危险球写入接口

彭俊 6 년 전
부모
커밋
c1e5cd3db7
5개의 변경된 파일99개의 추가작업 그리고 0개의 파일을 삭제
  1. 65 0
      app/Http/Controllers/Api/WriteSportsController.php
  2. 1 0
      app/Http/Middleware/VerifyCsrfToken.php
  3. 23 0
      app/Http/Model/StZqResult.php
  4. 6 0
      app/Http/Response/Response.php
  5. 4 0
      routes/web.php

+ 65 - 0
app/Http/Controllers/Api/WriteSportsController.php

@@ -85,6 +85,12 @@ class WriteSportsController extends BaseController
         return $ret;
     }
 
+    //写危险球数据
+    public function setMatchWarn(Req $data){
+        $ret = $this->setMatchWarn_v1($data);
+        return $ret;
+    }
+
     //写赛果接口
     public function setResultExpress(Req $data)
     {
@@ -2694,6 +2700,65 @@ class WriteSportsController extends BaseController
 
     }
 
+    /**
+     * 写赛事危险球数据
+     */
+    public function setMatchWarn_v1($data){
+         //验证token
+         $user = new \App\Models\System_user;
+         if (empty($data->token)) return Response::generate('未获取到token', Response::TOKEN_ERR);
+         $token = $user::where(['token' => $data->token])->value('token');
+         if (empty($token)) return Response::generate('token验证不通过', Response::TOKEN_ERR);
+ 
+         try {
+             //开启事务
+             DB::beginTransaction();
+             $obt = $data->data;
+             //请求 数据 为空
+             if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
+             $getData = $this->getAddData($obt);
+ 
+             //不是 赛事 危险球 数据
+             if ($getData['title'] != 'match_warn') throw new \Exception(Response::generate('不是危险球数据,', Response::ABNORMAL));
+
+              //获取球类代码
+            $game_code = $getData['game_code'];
+            //获取数据源
+            $source = $getData['source'];
+            //获取数据源赛事id
+            $others_match_id = $getData['match_id'];
+            //获取球类名称
+            $gameName = gameModel::getGameName($game_code);
+            //获取 model
+            $models = commonFunction::getModels($game_code, 1);
+            //获取 赛事 数据
+            $warn_data = $getData['data'];
+
+             //获取赛事 match_id
+             $match_id = $models['model_local_match']::SELECT('others_match_id', 'match_id')
+             ->where(['source' => $source,'others_match_id'=>$others_match_id])
+             ->first()->match_id;
+
+             if(!empty($match_id)){
+                //更新 危险球
+                $ret = ZqResultModel::set_result_warn($match_id,$warn_data);
+                if($ret < 1) throw new \Exception( Response::generate('',Response::SET_WARN_ERR));
+             }
+             
+             //提交事务
+             DB::commit();
+             //写请求数据 日志记录
+             if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], Response::success());
+             return Response::success();
+        } catch (\Exception $e) {
+             //回滚事务
+             DB::rollBack();
+             //写请求数据 日志记录
+             if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], $e->getMessage());
+             return $e->getMessage();
+        }
+    }
+
     /**
      * @param $data
      * @return mixed

+ 1 - 0
app/Http/Middleware/VerifyCsrfToken.php

@@ -23,6 +23,7 @@ class VerifyCsrfToken extends Middleware
         'setBroadCast',
         'getArea',
         'setResultExpress',
+        'setMatchWarn',
         //'upImg',
         //
     ];

+ 23 - 0
app/Http/Model/StZqResult.php

@@ -336,6 +336,7 @@ class StZqResult extends Model
      * $match_id 本地赛事id 为0时 则用于后台手动刷新赛果 
      */
     public static function ZQresult_v2($model,$match_id = 0){
+
         //如果有赛事id 则只更新当前赛事结果
         if($match_id > 0){
             $match_ids_str = $match_id;
@@ -507,4 +508,26 @@ class StZqResult extends Model
             if ($ret_id < 1) throw new \Exception(Response::generate($opt['gameName'] . '赛事-match_id:' . $opt['match_id'] . ';', Response::SET_MATCH_ERR));
         }
     }
+
+    /**
+     * 更新赛事 危险球 数据
+     */
+    public static function set_result_warn($match_id = 0,$warn_data=[]){
+        if($match_id > 0 and !empty($warn_data)){
+            $data = [];
+            foreach($warn_data as $k=>$v){
+                $data[$k]['timei'] = $v['find_time'];
+                $data[$k]['rtype'] = $v['warn_name'];
+                $data[$k]['timep'] = 90;
+
+            }
+
+            $warn_data = json_encode($data);
+
+            $ret = self::where(['match_id' => $match_id])
+                    ->update(['warn_more'=>$warn_data,'update_time'=>date('Y-m-d H:i:s')]);
+        }
+
+        return $ret;
+    }
 }

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

@@ -62,6 +62,9 @@ class Response
     //===写赛果失败===
     const SET_MATCH_R_ERR = 10043;
 
+    //===写入危险球失败===
+    const SET_WARN_ERR = 10044;
+
 
 
     private static $errorMsgs = [
@@ -117,6 +120,9 @@ class Response
         //===写赛果失败===
         self::SET_MATCH_R_ERR =>'写赛果失败',
 
+        //===写危险球失败===
+        self::SET_WARN_ERR =>'写危险球失败',
+
     ];
 
     public static function getMsg($code)

+ 4 - 0
routes/web.php

@@ -64,6 +64,10 @@ Route::post('/setBroadCast', function () {
 Route::post('/setResultExpress', function () {
     return appExec('api', 'WriteSports', 'setResultExpress');
 });
+//写入危险球数据
+Route::post('/setMatchWarn', function () {
+    return appExec('api', 'WriteSports', 'setMatchWarn');
+});
 //获取联赛所属国家地区
 Route::post('/getArea', function () {
     return appExec('api', 'WriteSports', 'getArea');