Selaa lähdekoodia

数据写入接口添加日志

彭俊 6 vuotta sitten
vanhempi
commit
321b87056f

+ 0 - 1
app/Http/Controllers/Admin/SportsfootController.php

@@ -95,7 +95,6 @@ class SportsfootController extends Controller {
 		// }
 		$request['match_id'] = $match_id;
 
-		// return
 		return view('admin.sportsfoot/addwarn', $request);
 	}
 

+ 598 - 57
app/Http/Controllers/Api/WriteSportsController.php

@@ -115,11 +115,14 @@ class WriteSportsController extends BaseController{
             //不是 联赛 数据
             if($getData['title'] != 'league') throw new \Exception(Response::generate('不是联赛数据,',Response::ABNORMAL));
             
+            /*
             //写请求数据 日志记录
             if($this->isRecord){
+                commonFunction::SET_SPORTS_RECORD($obt,$getData['title']);
                 $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'],$obt,$getData);
                 if($setSportsRecord < 1) throw new \Exception(Response::generate('',Response::SPORTS_RECORD_ERR));    
             }
+            */
 
              //获取球类代码
              $game_code = $getData['game_code'];
@@ -208,10 +211,14 @@ class WriteSportsController extends BaseController{
 
              //提交事务
              DB::commit();
+             //写请求数据 日志记录
+             if($this->isRecord) commonFunction::SET_SPORTS_RECORD($obt,$getData['title'],Response::success());
              return Response::success();
          } catch (\Exception $e) {
              //回滚事务
              DB::rollBack();
+             //写请求数据 日志记录
+             if($this->isRecord) commonFunction::SET_SPORTS_RECORD($obt,$getData['title'],$e->getMessage());
              return $e->getMessage();
          }
     }
@@ -236,11 +243,13 @@ class WriteSportsController extends BaseController{
             //不是 赛事 数据
             if($getData['title'] != 'match') throw new \Exception(Response::generate('不是赛事数据,',Response::ABNORMAL));
 
+            /*
             //写请求数据 日志记录
             if($this->isRecord){
                 $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'],$obt,$getData);
                 if($setSportsRecord < 1) throw new \Exception(Response::generate('',Response::SPORTS_RECORD_ERR));    
             }
+            */
             //获取球类代码
             $game_code = $getData['game_code'];
             //获取数据源
@@ -254,6 +263,7 @@ class WriteSportsController extends BaseController{
             //获取 当前请求 所有 uuid
             $identity = [];
             $s_match_ids = [];
+            $match_uuids = [];
             foreach($matchData as $k=>$v){
                 $identity[] = $v['uuid'];
                 $s_match_ids[] = $v['match_id'];
@@ -284,16 +294,232 @@ class WriteSportsController extends BaseController{
             $s_match_ids = [];
             foreach($matchData as $k=>$v){
                 $s_match_ids[] = $v['match_id'];
+                //追加获取赛事uuid
+                $match_uuids[] = $v['match_identity'];
+            }
+            //====获取 本地 已存在 赛事====
+            $match_uuids = array_unique($match_uuids);
+            sort($match_uuids);
+
+            $l_match_data = $models['model_local_match']::whereIn('identity',$match_uuids)->where('source',$source)->select('match_id','identity')->get()->toArray();
+            
+            //二维数组去重
+            $l_match_data = commonFunction::uniquArrV2($l_match_data,'others_match_id');
+
+            //循环对比 请求match_id->本地others_match_id 
+            //如果本地有 赛事,则分别获取本地已存在/不存在赛事
+            if(!empty($l_match_data)){
+                //本地已存在赛事,用于更新
+                $matchData_y = [];
+                foreach($l_match_data as $k=>$v){
+                    foreach($match_uuids as $kk=> $match_identity){
+                        if($v['identity'] == $match_identity){
+                            $matchData_y[$k]['match_identity'] = $match_identity;
+                            $matchData_y[$k]['match_id'] = $v['match_id'];
+                            unset($match_uuids[$kk]);
+                        }
+                    }
+                }
+                sort($match_uuids);
+            }
+            //如果 请求中 有本地赛事,则执行更新
+            if(!empty($matchData_y)){
+                foreach($matchData as $k=>$v){
+                    foreach($matchData_y as $kk=> $vv){
+                        if($v['match_identity'] == $vv['match_identity']){
+                            $data = $v;
+                            $up_match=[];
+                            $up_match['utime'] = date('Y-m-d H:i:s');
+                            $up_match['status'] = $data['status'];
+                            //获取需更新字段
+                            if($data['is_rollball'] == 1){
+                                $up_match['is_rollball'] = $data['is_rollball'];
+                            }
+                            if($data['is_today'] == 1){
+                                $up_match['is_today'] = $data['is_today'];
+                            }
+                            if($data['is_morningplate'] == 1){
+                                $up_match['is_morningplate'] = $data['is_morningplate'];
+                            }
+                            if($data['is_stringscene'] == 1){
+                                $up_match['is_stringscene'] = $data['is_stringscene'];
+                            }  
+                            
+                            //追加更新开赛日期/时间
+                            $up_match['match_date'] = $data['match_date'];
+                            $up_match['match_time'] = $data['match_time'];
+                            $up_match['us_time'] = $data['us_time'];
+
+                            //如果是网球 追加rule 字段
+                            if($game_code == 'wq' and !empty($data['rule'])){
+                                $up_match['rule'] = $data['rule'];
+                            }                  
+                            //更新赛事 返回成功数量
+                            $set = $models['model_match']::where(['id'=>$vv['match_id']])
+                            ->update($up_match);
+                            if($set < 1) throw new \Exception(Response::generate($gameName.'赛事-match_id:'.$data['match_id'].';',Response::UPSTATUS_ERROR)) ;
+                        }
+                    }
+                }
+            }
+            //剩余 赛事 数据 写入
+            if(!empty($match_uuids)){
+                foreach($matchData as $k=>$v){
+                    foreach($match_uuids as $kk=> $match_identity){
+                        if($v['match_identity'] == $match_identity){
+                            $data = $v;
+                            $half_match_id = $v['half_match_id'];
+                            //获取 本地 联赛 ID
+                            //验证本赛事是否有数据源lg_id
+                            if(empty($data['lg_id'])) throw new \Exception(Response::generate($gameName.'赛事-match_id:'.$data['match_id'].';',Response::S_LG_ID_NULL));
+                            $lg_id = commonFunction::searcharray($data['uuid'],'identity',$l_lg_data,'lg_id');
+                            //验证 本赛事是否获取到本地lg_id
+                            if(empty($lg_id)) throw new \Exception(Response::generate($gameName.'赛事-match_id:'.$data['match_id'].';',Response::L_LG_ID_NULL));
+                            //如果赛事没有开始日期,则为冠军盘口赛事 
+                            if(empty($data['match_date'])){
+                                //冠军盘口赛事获取所属联赛结束时间
+                                $last_time = $models['model_league']::where(['id'=>$lg_id])
+                                    ->value('last_time');
+                    
+                                if(empty($last_time)) throw new \Exception(Response::generate($gameName.'联赛-lg_id:'.$data['lg_id'].';',Response::LG_LASTTIME_ERROR));//Render([], '10023', lang('Tips','Sports')->get('lg_lastTime_error'));
+                                //给冠军盘口赛事 赋值时间
+                                $time = strtotime($last_time);
+                                $data['match_date'] = date('Y-m-d',$time);
+                                $data['match_time'] = date('H:i:s',$time);
+                            }
+                            $set_match = [
+                                'ctime'=>date('Y-m-d H:i:s'),
+                                'utime'=>date('Y-m-d H:i:s'),
+                                'expire_time'=>date('Y-m-d H:i:s',time()+60),
+                                'home_team'=>$data['home_team']?:'',
+                                'guest_team'=>$data['guest_team']?:'no_team',
+                                'lg_id'=>$lg_id,
+                                'status'=>$data['status'],
+                                'match_date'=>$data['match_date']?:date('Y-m-d'),
+                                'match_time'=>$data['match_time']?:date('H:i:s'),
+                                'is_rollball'=>$data['is_rollball']?:0,
+                                'is_today'=>$data['is_today']?:0,
+                                'is_morningplate'=>$data['is_morningplate']?:0,
+                                'is_stringscene'=>$data['is_stringscene']?:0,
+                                'us_time'=>$data['us_time']?:commonFunction::qgmdate('Y-m-d H:i:s', '', -4),
+                                'half_match_id'=>$half_match_id?:0,
+                                'identity' => $data['uuid'],
+                                'match_identity' => $data['match_identity'],
+                            ];     
+
+                            //如果是网球 追加rule 字段
+                            if($game_code == 'wq'){
+                                $set_match['rule'] = $data['rule'];
+                            }                  
+                            //写入赛事 返回id
+                            $id = $models['model_match']::insertGetId($set_match);
+                            if($id < 1) throw new \Exception(Response::generate($gameName.'赛事-match_id:'.$data['match_id'].';',Response::INSERT_ERROR)) ;
+                            
+                            //写关联记录
+                            $set_local = [
+                                'match_id'=>$id,
+                                'others_match_id'=>$data['match_id'],
+                                'source'=>$source,
+                                'identity' => $data['match_identity'],
+                                'ctime'=>date('Y-m-d H:i:s')
+                            ];
+                            $ret = $models['model_local_match']::insertGetId($set_local);
+                            if($ret < 1) throw new \Exception(Response::generate($gameName.'赛事-match_id:'.$data['match_id'].';',Response::LOCAL_MATCH_ERROR)) ;
+                        }
+                    }
+                }
             }
            
+             //提交事务
+             DB::commit();
+             //写请求数据 日志记录
+             if($this->isRecord) commonFunction::SET_SPORTS_RECORD($obt,$getData['title'],Response::success());
+             return Response::success();
+         } catch (\Exception $e) {
+             //回滚事务
+             DB::rollBack();
+             //写请求数据 日志记录
+             if($this->isRecord) commonFunction::SET_SPORTS_RECORD($obt,$getData['title'],$e->getMessage());
+             return $e->getMessage();
+         }
+
+    }
+    public function __setMatch(Req $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') throw new \Exception(Response::generate('不是赛事数据,',Response::ABNORMAL));
+
+            /*
+            //写请求数据 日志记录
+            if($this->isRecord){
+                $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'],$obt,$getData);
+                if($setSportsRecord < 1) throw new \Exception(Response::generate('',Response::SPORTS_RECORD_ERR));    
+            }
+            */
+            //获取球类代码
+            $game_code = $getData['game_code'];
+            //获取数据源
+            $source = $getData['source'];
+            //获取球类名称
+            $gameName = gameModel::getGameName($game_code);
+            //获取 model
+            $models = commonFunction::getModels($game_code, 1);
+            //获取 赛事 数据
+            $matchData = $getData['data'];
+            //获取 当前请求 所有 uuid
+            $identity = [];
+            $s_match_ids = [];
+            foreach($matchData as $k=>$v){
+                $identity[] = $v['uuid'];
+                $s_match_ids[] = $v['match_id'];
+            }
+
+            //====验证 赛事 所属 联赛 是否存在====
+            $identity = array_unique($identity);
+            sort($identity);
+
+            //获取 本地 已存在 联赛
+            $l_lg_data = $models['model_local_league']::whereIn('identity',$identity)->select('identity','lg_id','others_lg_id')->get()->toArray();
+            //二维数组去重
+            $l_lg_data = commonFunction::uniquArrV2($l_lg_data,'identity');
+            //如果获取不到本地联赛数据,则返回联赛不存在
+            if(empty($l_lg_data)) throw new \Exception(Response::generate($gameName.'本次请求的所有赛事都没有联赛数据;',Response::LEAGUE_ERROR));
+            
+            //获取到本次请求,所有本地有联赛的赛事
+            $mathData_before = $matchData;//接收原赛事
+            $matchData = [];//获取新赛事
+            foreach($l_lg_data as $k=>$v){
+                foreach($mathData_before as $kk=>$vv){
+                    if($v['identity'] == $vv['uuid']){
+                        $matchData[] = $vv;
+                    }
+                }
+            }
+            //获取当前请求有关联联赛的赛事 match_id
+            $s_match_ids = [];
+            foreach($matchData as $k=>$v){
+                $s_match_ids[] = $v['match_id'];
+            }
             //====获取 本地 已存在 赛事====
             $s_match_ids = array_unique($s_match_ids);
             sort($s_match_ids);
 
             $l_match_data = $models['model_local_match']::whereIn('others_match_id',$s_match_ids)->where('source',$source)->select('others_match_id','match_id')->get()->toArray();
+            
             //二维数组去重
             $l_match_data = commonFunction::uniquArrV2($l_match_data,'others_match_id');
-        
+
             //循环对比 请求match_id->本地others_match_id 
             //如果本地有 赛事,则分别获取本地已存在/不存在赛事
             if(!empty($l_match_data)){
@@ -333,12 +559,10 @@ class WriteSportsController extends BaseController{
                                 $up_match['is_stringscene'] = $data['is_stringscene'];
                             }  
                             
-                            //如果是网球,追加更新开赛日期/时间
-                            if($game_code == 'wq'){
-                                $up_match['match_date'] = $data['match_date'];
-                                $up_match['match_time'] = $data['match_time'];
-                                $up_match['us_time'] = $data['us_time'];
-                            }
+                            //追加更新开赛日期/时间
+                            $up_match['match_date'] = $data['match_date'];
+                            $up_match['match_time'] = $data['match_time'];
+                            $up_match['us_time'] = $data['us_time'];
 
                             //如果是网球 追加rule 字段
                             if($game_code == 'wq' and !empty($data['rule'])){
@@ -352,7 +576,6 @@ class WriteSportsController extends BaseController{
                     }
                 }
             }
-           
             //剩余 赛事 数据 写入
             if(!empty($s_match_ids)){
                 foreach($matchData as $k=>$v){
@@ -419,14 +642,18 @@ class WriteSportsController extends BaseController{
                 }
             }
     
-            //提交事务
-            DB::commit();
-            return Response::success();
-        } catch (\Exception $e) {
-            //回滚事务
-            DB::rollBack();
-            return $e->getMessage();
-        }
+             //提交事务
+             DB::commit();
+             //写请求数据 日志记录
+             if($this->isRecord) commonFunction::SET_SPORTS_RECORD($obt,$getData['title'],Response::success());
+             return Response::success();
+         } catch (\Exception $e) {
+             //回滚事务
+             DB::rollBack();
+             //写请求数据 日志记录
+             if($this->isRecord) commonFunction::SET_SPORTS_RECORD($obt,$getData['title'],$e->getMessage());
+             return $e->getMessage();
+         }
 
     }
 
@@ -452,11 +679,13 @@ class WriteSportsController extends BaseController{
             //不是 赛事 结果 记录 数据
             if($getData['title'] != 'match_result_r') throw new \Exception(Response::generate('不是赛事结果记录数据,',Response::ABNORMAL));
 
+            /*
             //写请求数据 日志记录
             if($this->isRecord){
                 $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'],$obt,$getData);
                 if($setSportsRecord < 1) throw new \Exception(Response::generate('',Response::SPORTS_RECORD_ERR));    
             }
+            */
            
             //获取球类代码
             $game_code = $getData['game_code'];
@@ -472,9 +701,12 @@ class WriteSportsController extends BaseController{
             //获取 当前请求 所有 uuid /match_id
             $identity = [];
             $s_match_ids = [];
+            $match_uuids = [];
             foreach($match_r_data as $k=>$v){
                 $identity[] = $v['uuid'];
                 $s_match_ids[] = $v['match_id'];
+                //追加获取赛事uuid
+                $match_uuids[] = $v['match_identity'];
             }
 
             //====验证 赛事 所属 联赛 是否存在====
@@ -499,11 +731,132 @@ class WriteSportsController extends BaseController{
             //====end====
 
             //====验证 赛事结果记录 所属赛事 是否存在====
+            $match_uuids = array_unique($match_uuids);
+            sort($match_uuids);
+
+            //获取 本地 已存在 赛事
+            $l_match_data = $models['model_local_match']::whereIn('identity',$match_uuids)->where('source',$source)->select('identity','match_id')->get()->toArray();
+            //二维数组去重
+            $l_match_data = commonFunction::uniquArrV2($l_match_data,'identity');
+        
+            //循环对比 请求identity->本地identity
+            foreach($l_match_data as $k=>$v){
+                foreach($match_uuids as $kk=> $match_identity){
+                    if($v['identity'] == $match_identity){
+                        unset($match_uuids[$kk]);
+                    }
+                }
+            }
+            sort($s_match_ids);
+            //去除本地和请求里都存在的赛事,如果还有剩余赛事id,则返回异常
+            if(!empty($s_match_ids))  throw new \Exception(Response::generate($gameName.'赛事-match_id'.$s_match_ids[0].';',Response::MATCH_ERROR));
+            //====end====
+
+            //处理 赛事 结果记录 数据
+            foreach($match_r_data as $k=>$v){
+                $data = $v;
+                //获取 本地 联赛 ID
+                $lg_id = commonFunction::searcharray($data['uuid'],'identity',$l_lg_data,'lg_id');
+                //获取 本地 赛事 ID
+                $match_id = commonFunction::searcharray($data['match_id'],'identity',$l_match_data,'match_id');
+
+                //根据球类 获取 赛事结果记录字段
+                $set_match_r = $this->get_match_r($game_code,$lg_id,$match_id,$data);
+
+                //写 赛事 结果 记录
+                $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));
+            }
+
+              //提交事务
+              DB::commit();
+              //写请求数据 日志记录
+              if($this->isRecord) commonFunction::SET_SPORTS_RECORD($obt,$getData['title'],Response::success());
+              return Response::success();
+          } catch (\Exception $e) {
+              //回滚事务
+              DB::rollBack();
+              //写请求数据 日志记录
+              if($this->isRecord) commonFunction::SET_SPORTS_RECORD($obt,$getData['title'],$e->getMessage());
+              return $e->getMessage();
+          }
+
+    }
+    public function __setMatchResult(Req $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_result_r') throw new \Exception(Response::generate('不是赛事结果记录数据,',Response::ABNORMAL));
+
+            /*
+            //写请求数据 日志记录
+            if($this->isRecord){
+                // $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'],$obt,$getData);
+                // if($setSportsRecord < 1) throw new \Exception(Response::generate('',Response::SPORTS_RECORD_ERR));    
+            }
+            */
+           
+            //获取球类代码
+            $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'];
+
+            //获取 当前请求 所有 uuid /match_id
+            $identity = [];
+            $s_match_ids = [];
+            $match_uuids = [];
+            foreach($match_r_data as $k=>$v){
+                $identity[] = $v['uuid'];
+                $s_match_ids[] = $v['match_id'];
+            }
+
+            //====验证 赛事 所属 联赛 是否存在====
+            $identity = array_unique($identity);
+            sort($identity);
+
+            //获取 本地 已存在 联赛
+            $l_lg_data = $models['model_local_league']::whereIn('identity',$identity)->select('identity','lg_id')->get()->toArray();
+            //二维数组去重
+            $l_lg_data = commonFunction::uniquArrV2($l_lg_data,'identity');
+            //循环对比 请求uuid->本地identity
+            foreach($l_lg_data as $k=>$v){
+                foreach($identity as $kk=> $uuid){
+                    if($v['identity'] == $uuid){
+                        unset($identity[$kk]);
+                    }
+                }
+            }
+            sort($identity);
+            //去除本地和请求里都存在的联赛,如果还有剩余联赛id,则返回异常
+            if(!empty($identity))  throw new \Exception(Response::generate($gameName.'联赛:uuid-'.$identity[0].';',Response::LEAGUE_ERROR));
+            //====end====
+
+            //====验证 赛事结果记录 所属赛事 是否存在====$match_uuids
             $s_match_ids = array_unique($s_match_ids);
             sort($s_match_ids);
 
             //获取 本地 已存在 赛事
             $l_match_data = $models['model_local_match']::whereIn('others_match_id',$s_match_ids)->where('source',$source)->select('others_match_id','match_id')->get()->toArray();
+
             //二维数组去重
             $l_match_data = commonFunction::uniquArrV2($l_match_data,'others_match_id');
         
@@ -537,14 +890,18 @@ class WriteSportsController extends BaseController{
                 if($ret != true) throw new \Exception(Response::generate($gameName.'赛事-match_id:'.$data['match_id'].';',Response::ADD_MATCH_R_R_ERROR));
             }
 
-            //提交事务
-            DB::commit();
-            return Response::success();
-        } catch (\Exception $e) {
-            //回滚事务
-            DB::rollBack();
-            return $e->getMessage();
-        }
+              //提交事务
+              DB::commit();
+              //写请求数据 日志记录
+              if($this->isRecord) commonFunction::SET_SPORTS_RECORD($obt,$getData['title'],Response::success());
+              return Response::success();
+          } catch (\Exception $e) {
+              //回滚事务
+              DB::rollBack();
+              //写请求数据 日志记录
+              if($this->isRecord) commonFunction::SET_SPORTS_RECORD($obt,$getData['title'],$e->getMessage());
+              return $e->getMessage();
+          }
 
     }
 
@@ -571,11 +928,166 @@ class WriteSportsController extends BaseController{
             //不是 赔率 数据
             if($getData['title'] != 'odds') throw new \Exception(Response::generate('不是赔率数据,',Response::ABNORMAL));
 
+            /*
             //写请求数据 日志记录
             if($this->isRecord){
                 $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'],$obt,$getData);
                 if($setSportsRecord < 1) throw new \Exception(Response::generate('',Response::SPORTS_RECORD_ERR));    
             }
+            */
+
+            //获取球类代码
+            $game_code = $getData['game_code'];
+            //获取数据源
+            $source = $getData['source'];
+            //获取源数据联赛ID
+            $uuid = $getData['uuid'];
+            //获取源数据赛事ID
+            $s_match_id = $getData['match_id'];
+            //获取数据源赛事uuid
+            $match_identity = $getData['match_identity'];
+            //获取赔率所属赛事 tag 值 玩法数量
+            $tag = $getData['tag']?:99;
+            //获取赔率是否是串场
+            $is_stringscene = $getData['is_stringscene'];
+
+            //获取球类名称
+            $gameName = gameModel::getGameName($game_code);
+            //验证本次请求所属联赛/赛事是否存在 返回本地联赛/赛事ID
+            $models = commonFunction::getModels($game_code, 1);
+            $lg_id = $this->leagueVerify($models,$uuid,$source,$gameName);
+            $match_id = $this->matchVerify($models,$match_identity,$source,$gameName);
+
+            //更新赛事 tag 值
+            //如果未获取到本地赛事id,则返回异常
+            if(empty($match_id)) throw new \Exception(Response::generate($gameName.'赛事-match_id:'.$s_match_id.';',Response::L_MATCH_ID_ERR)) ;
+
+            $upMatch = $models['model_match']::where(['id'=>$match_id])
+            ->update(['tag'=>$tag,'utime'=>date('Y-m-d H:i:s')]);
+            if($upMatch < 1) throw new \Exception(Response::generate($gameName.'赛事-match_id:'.$s_match_id.';',Response::UPMATCHTAG_ERROR)) ;
+
+            //获取 赔率数据
+            $oddsData = $getData['data'];
+            //获取 当前 所有 可用 赔率 sole
+            $odds_only = $getData['odds_only'];
+            //更新赛事下所有 不在本次请求的赔率 状态
+            $ret= OddsModel::upOddsStatus($models,$s_match_id,'',$source,$odds_only,$is_stringscene);
+            if($ret != true) throw new \Exception(Response::generate($gameName,Response::ODDS_SOLE_ERR));
+
+            //获取当前赛事 在本地的所有赔率
+            $l_odds_data = $models['model_odds']::select('odds_only')->where(['match_id'=>$match_id])->get()->toArray();
+            
+            $set_odds_r = [];
+            $set_odds = [];
+            if(!empty($oddsData)){
+                //去除本地已有的赔率
+                if(!empty($l_odds_data)){
+                    foreach($oddsData as $k=>$v){
+                        foreach($l_odds_data as $kk=>$vv){
+                            if($v['odds_only'] == $vv['odds_only']){
+                                unset($oddsData[$k]);
+                            }
+                        }
+                    }
+                    sort($oddsData);
+                }
+                //处理待写入 赔率记录数据
+                foreach($oddsData as $k=>$v){
+                    //组装数据
+                    $set_odds_r[] = [
+                        'match_id'=> $match_id?:0,
+                        'others_match_id'=> $v['match_id']?:0,
+                        'odds_code'=> $v['odds_code']?:'',
+                        'status'=> $v['status']?:0,
+                        'sort'=> $v['sort']?:0,
+                        'p_code'=> $v['p_code']?:'',
+                        'odds'=> $v['odds']?:0,
+                        'condition'=> $v['condition'],
+                        'odds_only'=> $v['odds_only']?:'',
+                        'source'=> $v['source']?:'',
+                        'type'=> $v['type']?:0,
+                        'team'=> $v['team']?:'',
+                        'lg_id'=> $lg_id,
+                        'is_stringscene'=>$is_stringscene,
+                        'others_lg_id'=> $v['lg_id'],
+                        'ctime'=> date('Y-m-d H:i:s'),
+                        'utime'=> date('Y-m-d H:i:s'),
+                    ];
+                }
+
+                 //处理待写入 赔率数据
+                 foreach($oddsData as $k=>$v){
+                    //组装数据
+                    $set_odds[] = [
+                        'match_id'=> $match_id?:0,
+                        'others_match_id'=> $v['match_id']?:0,
+                        'odds_code'=> $v['odds_code']?:'',
+                        'status'=> $v['status']?:0,
+                        'sort'=> $v['sort']?:0,
+                        'p_code'=> $v['p_code']?:'',
+                        'odds'=> $v['odds']?:0,
+                        'condition'=> $v['condition'],
+                        'odds_only'=> $v['odds_only']?:'',
+                        'source'=> $v['source']?:'',
+                        'type'=> $v['type']?:0,
+                        'team'=> $v['team']?:'',
+                        'lg_id'=> $lg_id,
+                        'is_stringscene'=>$is_stringscene,
+                        'others_lg_id'=> $v['lg_id'],
+                        'ctime'=> date('Y-m-d H:i:s'),
+                        'utime'=> date('Y-m-d H:i:s'),
+                        'sole' => $v['sole'],
+                        'expire_time' => date('Y-m-d H:i:s',time()+60)
+                    ];
+                }
+
+                 //写赔率记录数据
+                 $ret = $models['model_odds_record']::insert($set_odds_r);
+                 if($ret != true) throw new \Exception(Response::generate($gameName.'赔率记录;',Response::ADD_ODDS_R_ERROR));
+                 //写赔率 数据
+                 $ret = $models['model_odds']::insert($set_odds);
+                 if($ret != true) throw new \Exception(Response::generate($gameName.'赔率;',Response::ADD_ODDS_ERROR));
+            }
+
+              //提交事务
+              DB::commit();
+              //写请求数据 日志记录
+              if($this->isRecord) commonFunction::SET_SPORTS_RECORD($obt,$getData['title'],Response::success());
+              return Response::success();
+          } catch (\Exception $e) {
+              //回滚事务
+              DB::rollBack();
+              //写请求数据 日志记录
+              if($this->isRecord) commonFunction::SET_SPORTS_RECORD($obt,$getData['title'],$e->getMessage());
+              return $e->getMessage();
+          }
+    }
+    public function __setOdds(Req $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'] != 'odds') throw new \Exception(Response::generate('不是赔率数据,',Response::ABNORMAL));
+
+            /*
+            //写请求数据 日志记录
+            if($this->isRecord){
+                $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'],$obt,$getData);
+                if($setSportsRecord < 1) throw new \Exception(Response::generate('',Response::SPORTS_RECORD_ERR));    
+            }
+            */
 
             //获取球类代码
             $game_code = $getData['game_code'];
@@ -688,14 +1200,18 @@ class WriteSportsController extends BaseController{
                  if($ret != true) throw new \Exception(Response::generate($gameName.'赔率;',Response::ADD_ODDS_ERROR));
             }
 
-            //提交事务                          
-            DB::commit();
-            return Response::success();
-        } catch (\Exception $e) {
-            //回滚事务
-            DB::rollBack();
-            return $e->getMessage();
-        }
+              //提交事务
+              DB::commit();
+              //写请求数据 日志记录
+              if($this->isRecord) commonFunction::SET_SPORTS_RECORD($obt,$getData['title'],Response::success());
+              return Response::success();
+          } catch (\Exception $e) {
+              //回滚事务
+              DB::rollBack();
+              //写请求数据 日志记录
+              if($this->isRecord) commonFunction::SET_SPORTS_RECORD($obt,$getData['title'],$e->getMessage());
+              return $e->getMessage();
+          }
     }
 
     /*
@@ -719,11 +1235,13 @@ class WriteSportsController extends BaseController{
             //不是 冠军 赔率 数据
             if($getData['title'] != 'odds_ch') throw new \Exception(Response::generate('不是冠军赔率数据,',Response::ABNORMAL));
 
+            /*
             //写请求数据 日志记录
             if($this->isRecord){
                 $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'],$obt,$getData);
                 if($setSportsRecord < 1) throw new \Exception(Response::generate('',Response::SPORTS_RECORD_ERR));    
             }
+            */
             
             //获取球类代码
             $game_code = $getData['game_code'];
@@ -837,14 +1355,18 @@ class WriteSportsController extends BaseController{
              if($ret != true) throw new \Exception(Response::generate($gameName.'赔率;',Response::ADD_ODDS_ERROR));
     
             }
-            //提交事务
-            DB::commit();
-            return Response::success();
-        } catch (\Exception $e) {
-            //回滚事务
-            DB::rollBack();
-            return $e->getMessage();
-        }
+              //提交事务
+              DB::commit();
+              //写请求数据 日志记录
+              if($this->isRecord) commonFunction::SET_SPORTS_RECORD($obt,$getData['title'],Response::success());
+              return Response::success();
+          } catch (\Exception $e) {
+              //回滚事务
+              DB::rollBack();
+              //写请求数据 日志记录
+              if($this->isRecord) commonFunction::SET_SPORTS_RECORD($obt,$getData['title'],$e->getMessage());
+              return $e->getMessage();
+          }
     }
 
     /*
@@ -866,11 +1388,13 @@ class WriteSportsController extends BaseController{
             //不是 直播 数据
             if($getData['title'] != 'broad_cast') throw new \Exception(Response::generate('不是直播数据,',Response::ABNORMAL));
 
+            /*
             //写请求数据 日志记录
             if($this->isRecord){
                 $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'],$obt,$getData);
                 if($setSportsRecord < 1) throw new \Exception(Response::generate('',Response::SPORTS_RECORD_ERR));    
             }
+            */
             //获取 球类
             $game_code = $getData['game_code'];
             //删除当前球类已存在的直播数据
@@ -898,14 +1422,18 @@ class WriteSportsController extends BaseController{
            //写入 直播 数据
             $ret = broadcastModel::insert($set_broadcast);
             if($ret == false) throw new \Exception(Response::generate('',Response::BROADCAST_ERROR));
-            //提交事务
-            DB::commit();
-            return Response::success();
-        } catch (\Exception $e) {
-            //回滚事务
-            DB::rollBack();
-            return $e->getMessage();
-        }
+              //提交事务
+              DB::commit();
+              //写请求数据 日志记录
+              if($this->isRecord) commonFunction::SET_SPORTS_RECORD($obt,$getData['title'],Response::success());
+              return Response::success();
+          } catch (\Exception $e) {
+              //回滚事务
+              DB::rollBack();
+              //写请求数据 日志记录
+              if($this->isRecord) commonFunction::SET_SPORTS_RECORD($obt,$getData['title'],$e->getMessage());
+              return $e->getMessage();
+          }
     }
 
     /*
@@ -922,7 +1450,14 @@ class WriteSportsController extends BaseController{
     /*
      * 验证所属 赛事 是否存在
      */
-    public function matchVerify($models=[],$s_match_id='',$source='',$gameName=''){
+    public function matchVerify($models=[],$match_identity='',$source='',$gameName=''){
+        if(empty($models) || empty($match_identity)) throw new \Exception(Response::generate('',Response::ABNORMAL));
+        $l_match_id = $models['model_local_match']::where(['identity'=>$match_identity,'source'=>$source])->value('match_id');
+
+        if($l_match_id < 1) throw new \Exception(Response::generate($gameName.'match_identity-'.$match_identity,Response::MATCH_ERROR));
+        return $l_match_id;
+    }
+    public function __matchVerify($models=[],$s_match_id='',$source='',$gameName=''){
         if(empty($models) || empty($s_match_id)) throw new \Exception(Response::generate('',Response::ABNORMAL));
         $l_match_id = $models['model_local_match']::where(['others_match_id'=>$s_match_id,'source'=>$source])->value('match_id');
 
@@ -1182,11 +1717,13 @@ class WriteSportsController extends BaseController{
             //不是 直播 数据
             if($getData['title'] != 'match_status') throw new \Exception(Response::generate('不是更新赛事状态数据',Response::ABNORMAL));
 
+            /*
             //写请求数据 日志记录
             if($this->isRecord){
                 $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'],$obt,$getData);
                 if($setSportsRecord < 1) throw new \Exception(Response::generate('',Response::SPORTS_RECORD_ERR));    
             }
+            */
        
             //获取 球类代码
             $game_code = $data['game_code'];
@@ -1220,14 +1757,18 @@ class WriteSportsController extends BaseController{
                     -> 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();
-        }
+              //提交事务
+              DB::commit();
+              //写请求数据 日志记录
+              if($this->isRecord) commonFunction::SET_SPORTS_RECORD($obt,$getData['title'],Response::success());
+              return Response::success();
+          } catch (\Exception $e) {
+              //回滚事务
+              DB::rollBack();
+              //写请求数据 日志记录
+              if($this->isRecord) commonFunction::SET_SPORTS_RECORD($obt,$getData['title'],$e->getMessage());
+              return $e->getMessage();
+          }
     }
 
     /*

+ 9 - 0
app/Lib/Biz/Sport/Common.php

@@ -1,6 +1,8 @@
 <?php
 namespace App\Lib\Biz\Sport;
 use App\Http\Response\Response;
+use Log;
+
 
 use App\Http\Model\StZqMatch;
 use App\Http\Model\StZqLeague;
@@ -1177,6 +1179,13 @@ class Common {
             return $data;
         }
     }
+
+    //写入赛事数据日志文件
+    static function SET_SPORTS_RECORD($obt,$title,$msg){
+        Log::getMonolog()->popHandler(); 
+        Log::useFiles(storage_path('logs/set_sports_record/'.date('Y-m-d',time()).'/'.$title.'.log'), 'info');
+        Log::info('--->msg:' . $msg . ';data:' . $obt);
+    }
 }
 
 ?>