Browse Source

异常处理 6/11

彭俊 6 năm trước cách đây
mục cha
commit
81ed50fe1a

+ 45 - 3
app/Http/Controllers/Api/WriteSportsController.php

@@ -120,10 +120,52 @@ class WriteSportsController extends BaseController{
         }
     }
 
-
+    /**
+     * @param Req $data
+     * @return string
+     * @throws \App\Lib\Biz\Sport\Exception
+     * 更新赛事状态
+     */
     public function upMatch(Req $data){
-
-        echo 123;exit;
+        try {
+            //开启事务
+            DB::beginTransaction();
+            //获取待更新赛事
+            $obt = $data->data;
+            if($obt){
+                //json转数组
+                $data = $this->getAddData($obt);
+                //获取所有数据源赛事 match_id
+                $others_match_ids = [];
+                foreach ($data as $k=>$v){
+                    $game_code = $v['game_code'];
+                    $source = $v['source'];
+                    $others_match_ids[] = $v['match_id'];
+                }
+                //根据球类代码 获取model
+                $model =commonFunction::getModels($game_code,1);
+                //获取所有赛事 match_id
+                $local_match = $model['model_local_match']::SELECT('others_match_id','match_id')
+                    ->where(['source'=>$source])
+                    ->whereIn('others_match_id',$others_match_ids)
+                    ->get()->toArray();
+                if(empty($local_match)) throw new \Exception(Response::generate('',Response::MATCHID_NULL));
+                //更新状态字段
+                $set_status = ['status'=>2];
+                foreach ($local_match as $k=>$v){
+                    $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));
+                }
+            }
+            //提交事务
+            DB::commit();
+            return Response::success();
+        } catch (\Exception $e) {
+            //回滚事务
+            DB::rollBack();
+            return $e->getMessage();
+        }
     }
 
     //写入直播 数据

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

@@ -13,6 +13,7 @@ class VerifyCsrfToken extends Middleware
      */
     protected $except = [
         'setSports',
+        'upMatch',
         //
     ];
 }

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

@@ -2,6 +2,7 @@
 namespace App\Http\Model;
 
 use Illuminate\Database\Eloquent\Model;
+use App\Http\Response\Response;
 
 /**
  * Class Account

+ 44 - 34
app/Http/Model/StLqResult.php

@@ -2,6 +2,7 @@
 namespace App\Http\Model;
 
 use Illuminate\Database\Eloquent\Model;
+use App\Http\Response\Response;
 
 /**
  * Class Account
@@ -30,45 +31,14 @@ class StLqResult extends Model
             ->toarray();
         //结果表无数据,直接插入
         if(empty($matchData_r)){
-            foreach ($matchData as $k=>$v){
-                $time = time()-strtotime($v['match_time']);
-                $match_time = self::secTime($time);
-                $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_process"=>$process,
-                    'match_time'=>$match_time,
-                    "update_time"=>date('Y-m-d H:m:i')
-                ];
-            }
-            $ret = $model['model_result']::insert($set_match_r);
-            if($ret != true) throw new \Exception( Response::generate('',Response::ADD_MATCH_R_ERROR));
-        }
-
-        //如果结果表有数据,则获取结果表没有的赛事
-        foreach ($matchData as $k=>$v){
-            foreach ($matchData_r as $kk=>$vv){
-                if($v['id'] == $vv['match_id']){
-                    unset($matchData[$k]);
-                }
-            }
-        }
-        //如果还有未写入赛事
-        if(!empty($matchData)){
-            //写入结果表不存在赛事
             foreach ($matchData as $k=>$v){
                 $process = 0;
                 if((int)$v['status'] == 2){
                     $process = 4;
                 }
                 if((int)$v['status'] == 1){
-                    $process = 4;
+                    $process = 1;
                 }
-
                 $time = time()-strtotime($v['match_time']);
                 $match_time = self::secTime($time);
                 $set_match_r[] = [
@@ -78,14 +48,54 @@ class StLqResult extends Model
                     "lg_id"=>$v['lg_id'],
                     "status"=>$v['status'],
                     "tag"=> $v['tag'],
-//                    "match_process"=>$process,
+                    "match_process"=>$process,
                     'match_time'=>$match_time,
                     "update_time"=>date('Y-m-d H:m:i')
                 ];
             }
             $ret = $model['model_result']::insert($set_match_r);
-            if($ret != true) throw new \Exception( Response::generate('',Response::ADD_MATCH_R_ERROR));//Render([], '10022', lang('Tips','Sports')->get('add_match_r_error'));
+            if($ret != true) throw new \Exception( Response::generate('',Response::ADD_MATCH_R_ERROR));
+        }else{
+            //如果结果表有数据,则获取结果表没有的赛事
+            foreach ($matchData as $k=>$v){
+                foreach ($matchData_r as $kk=>$vv){
+                    if($v['id'] == $vv['match_id']){
+                        unset($matchData[$k]);
+                    }
+                }
+            }
+            //如果还有未写入赛事
+            if(!empty($matchData)){
+                //写入结果表不存在赛事
+                foreach ($matchData as $k=>$v){
+                    $process = 0;
+                    if((int)$v['status'] == 2){
+                        $process = 4;
+                    }
+                    if((int)$v['status'] == 1){
+                        $process = 1;
+                    }
+
+                    $time = time()-strtotime($v['match_time']);
+                    $match_time = self::secTime($time);
+                    $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_process"=>$process,
+                        'match_time'=>$match_time,
+                        "update_time"=>date('Y-m-d H:m:i')
+                    ];
+                }
+                $ret = $model['model_result']::insert($set_match_r);
+                if($ret != true) throw new \Exception( Response::generate('',Response::ADD_MATCH_R_ERROR));//Render([], '10022', lang('Tips','Sports')->get('add_match_r_error'));
+            }
         }
+
+
     }
 
     //计算滚球 赛事进行时间

+ 1 - 0
app/Http/Model/StWqResult.php

@@ -2,6 +2,7 @@
 namespace App\Http\Model;
 
 use Illuminate\Database\Eloquent\Model;
+use App\Http\Response\Response;
 
 /**
  * Class Account

+ 1 - 1
app/Http/Model/StZqResult.php

@@ -2,7 +2,7 @@
 namespace App\Http\Model;
 
 use Illuminate\Database\Eloquent\Model;
-
+use App\Http\Response\Response;
 /**
  * Class Account
  * @package App\Sports\Model

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

@@ -25,6 +25,10 @@ class Response
     const AUTH_ERROR = 10026;
     const LOCAL_MATCH_ERROR = 10027;
     const BROADCAST_ERROR = 10028;
+    //===更新赛事状态===
+    const MATCHID_NULL = 10029;
+    const UPSTATUS_ERROR = 10030;
+
 
     private static $errorMsgs = [
         self::SUCCESS => '成功',
@@ -48,6 +52,9 @@ class Response
         self::AUTH_ERROR => '无权操作',
         self::LOCAL_MATCH_ERROR =>'写入赛事关联记录失败',
         self::BROADCAST_ERROR =>'写入直播数据失败',
+        //===更新赛事状态===
+        self::MATCHID_NULL =>'未获取到相关赛事',
+        self::UPSTATUS_ERROR =>'赛事状态更新失败',
     ];
 
     public static function getMsg($code)

+ 3 - 3
app/Lib/Settlement/Adapter/RulePlus.php

@@ -27,7 +27,7 @@ trait RulePlus
         }
 
         if (count($condArr) == 1) {
-            $smin = $scoreDiff - ($hasFH == '+' ? 1 : -1) * $condArr['0'];
+            $smin = $scoreDiff + ($hasFH == '+' ? 1 : -1) * $condArr['0'];
             if ($smin > 0) {
                 $returnDatas['result'] = 1;
             } elseif ($smin == 0) {
@@ -38,8 +38,8 @@ trait RulePlus
             return $returnDatas;
         }
 
-        $smin = $scoreDiff - ($FH == "+" ? 1 : -1) * $condArr[0];
-        $smax = $scoreDiff - ($FH == "+" ? 1 : -1) * $condArr[1];
+        $smin = $scoreDiff + ($FH == "+" ? 1 : -1) * $condArr[0];
+        $smax = $scoreDiff + ($FH == "+" ? 1 : -1) * $condArr[1];
         if ($smin > $smax) {
             $this->doexchage($smin, $smax);
         }