vali %!s(int64=6) %!d(string=hai) anos
pai
achega
18c73b8ad8
Modificáronse 1 ficheiros con 76 adicións e 67 borrados
  1. 76 67
      app/Logic/DataLogic.php

+ 76 - 67
app/Logic/DataLogic.php

@@ -43,19 +43,21 @@ class DataLogic
             //开启事务
             DB::beginTransaction();
             $obt = $data['data'];
-            //请求 数据 为空
 
             //请求 数据 为空
-            if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
+            if(empty($obt)) throw new \Exception(Response::generate('请求数据为空,',Response::ABNORMAL));
             $getData = $this->getAddData($obt);
             //不是 联赛 数据
-            if ($getData['title'] != 'league') throw new \Exception(Response::generate('不是联赛数据,', Response::ABNORMAL));
+            if($getData['title'] != 'league') 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));
+            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'];
@@ -73,45 +75,45 @@ class DataLogic
 
             //获取 当前请求 所有 联赛 uuid
             $identity = [];
-            foreach ($leagueData as $k => $v) {
+            foreach($leagueData as $k=>$v){
                 $identity[] = $v['uuid'];
             }
             $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 = $models['model_local_league']::whereIn('identity',$identity)->select('identity','lg_id')->get()->toArray();
             //二维数组去重
-            $l_lg_data = commonFunction::uniquArrV2($l_lg_data, 'identity');
+            $l_lg_data = commonFunction::uniquArrV2($l_lg_data,'identity');
             //循环对比 请求identity->本地identity
-            foreach ($l_lg_data as $k => $v) {
-                foreach ($identity as $kk => $uuid) {
-                    if ($v['identity'] == $uuid) {
+            foreach($l_lg_data as $k=>$v){
+                foreach($identity as $kk=> $uuid){
+                    if($v['identity'] == $uuid){
                         unset($identity[$kk]);
                     }
                 }
             }
             //去除本地和请求里都存在的联赛,如果还有剩余联赛uuid,则将其写入
-            if (!empty($identity)) {
+            if(!empty($identity)) {
                 //没有 决赛时间 默认获取本年最后一天
                 $last_time = date('Y-12-31 23:59:59');
-                foreach ($leagueData as $k => $v) {
-                    foreach ($identity as $kk => $uuid) {
-                        if ($v['uuid'] == $uuid) {
+                foreach($leagueData as $k=>$v){
+                    foreach($identity as $kk=> $uuid){
+                        if($v['uuid'] == $uuid){
                             //如有 决赛时间
-                            if ($v['last_time']) {
+                            if($v['last_time']){
                                 $last_time = $v['last_time'];
                             }
                             //获取联赛所属国家或地区
                             $getArea = $this->getArea($v['name_chinese']);
-                            if ($getArea['pid'] == 0) {
+                            if($getArea['pid'] == 0){
                                 $area_id = $getArea['id'];
                                 $country_id = 0;
-                            } else {
+                            }else{
                                 $area_id = $getArea['pid'];
                                 $country_id = $getArea['id'];
                             }
-                            if (empty($v['uuid'])) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $v['lg_id'] . ';', Response::LG__UUID_NULL));
+                            if(empty($v['uuid'])) throw new \Exception(Response::generate($gameName.'联赛-lg_id:'.$v['lg_id'].';',Response::LG__UUID_NULL));
                             $set_lg['name_chinese'] = $v['name_chinese'];
                             $set_lg['kind'] = $v['kind'];
                             $set_lg['match_mode'] = $v['match_mode'];
@@ -124,18 +126,18 @@ class DataLogic
                             //写入联赛
                             $id = $models['model_league']::insertGetId($set_lg);
                             $m_lg_id = $id;
-                            if ($m_lg_id < 1) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $v['lg_id'] . ';', Response::INSERT_ERROR));
+                            if($m_lg_id < 1) throw new \Exception(Response::generate($gameName.'联赛-lg_id:'.$v['lg_id'].';',Response::INSERT_ERROR));
 
                             //写入 本地 联赛记录
                             $set_local = [
-                                'lg_id' => $id,
-                                'others_lg_id' => $v['lg_id'],
-                                'source' => $source,
-                                'ctime' => date('Y-m-d H:i:s'),
-                                'identity' => $v['uuid'],
+                                'lg_id'=>$id,
+                                'others_lg_id'=>$v['lg_id'],
+                                'source'=>$source,
+                                'ctime'=>date('Y-m-d H:i:s'),
+                                'identity'=>$v['uuid'],
                             ];
                             $ret = $models['model_local_league']::insertGetId($set_local);
-                            if ($ret < 1) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $data['lg_id'] . ';', Response::LOCAL_LEAGUE_ERROR));//Render([], '10017', lang('Tips','Sports')->get('local_league_error'));
+                            if($ret < 1) throw new \Exception(Response::generate($gameName.'联赛-lg_id:'.$data['lg_id'].';',Response::LOCAL_LEAGUE_ERROR)) ;//Render([], '10017', lang('Tips','Sports')->get('local_league_error'));
 
                         }
                     }
@@ -149,7 +151,7 @@ class DataLogic
         } catch (\Exception $e) {
             //回滚事务
             DB::rollBack();
-            $this->writeLog($data, $e->getMessage());
+            $this->writeLog($data, ['file'=>$e->getFile(),'line'=>$e->getLine(),'msg'=>$e->getMessage()]);
             return $e->getMessage();
         }
     }
@@ -171,11 +173,13 @@ class DataLogic
             //不是 赛事 数据
             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'];
             //获取数据源
@@ -189,6 +193,7 @@ class DataLogic
             //获取 当前请求 所有 uuid
             $identity = [];
             $s_match_ids = [];
+            $match_uuids = [];
             foreach($matchData as $k=>$v){
                 $identity[] = $v['uuid'];
                 $s_match_ids[] = $v['match_id'];
@@ -219,15 +224,17 @@ class DataLogic
             $s_match_ids = [];
             foreach($matchData as $k=>$v){
                 $s_match_ids[] = $v['match_id'];
+                //追加获取赛事uuid
+                $match_uuids[] = $v['match_identity'];
             }
-
             //====获取 本地 已存在 赛事====
-            $s_match_ids = array_unique($s_match_ids);
-            sort($s_match_ids);
+            $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 = $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');
+            $l_match_data = commonFunction::uniquArrV2($l_match_data,'identity');
 
             //循环对比 请求match_id->本地others_match_id
             //如果本地有 赛事,则分别获取本地已存在/不存在赛事
@@ -235,21 +242,21 @@ class DataLogic
                 //本地已存在赛事,用于更新
                 $matchData_y = [];
                 foreach($l_match_data as $k=>$v){
-                    foreach($s_match_ids as $kk=> $s_match_id){
-                        if($v['others_match_id'] == $s_match_id){
-                            $matchData_y[$k]['others_match_id'] = $s_match_id;
+                    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($s_match_ids[$kk]);
+                            unset($match_uuids[$kk]);
                         }
                     }
                 }
-                sort($s_match_ids);
+                sort($match_uuids);
             }
             //如果 请求中 有本地赛事,则执行更新
             if(!empty($matchData_y)){
                 foreach($matchData as $k=>$v){
                     foreach($matchData_y as $kk=> $vv){
-                        if($v['match_id'] == $vv['others_match_id']){
+                        if($v['match_identity'] == $vv['match_identity']){
                             $data = $v;
                             $up_match=[];
                             $up_match['utime'] = date('Y-m-d H:i:s');
@@ -268,13 +275,10 @@ class DataLogic
                                 $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'])){
@@ -288,12 +292,11 @@ class DataLogic
                     }
                 }
             }
-
             //剩余 赛事 数据 写入
-            if(!empty($s_match_ids)){
+            if(!empty($match_uuids)){
                 foreach($matchData as $k=>$v){
-                    foreach($s_match_ids as $kk=> $s_match_id){
-                        if($v['match_id'] == $s_match_id){
+                    foreach($match_uuids as $kk=> $match_identity){
+                        if($v['match_identity'] == $match_identity){
                             $data = $v;
                             $half_match_id = $v['half_match_id'];
                             //获取 本地 联赛 ID
@@ -331,6 +334,7 @@ class DataLogic
                                 '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 字段
@@ -346,10 +350,11 @@ class DataLogic
                                 '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)) ;//Render([], '10018', lang('Tips','Sports')->get('local_match_error'));
+                            if($ret < 1) throw new \Exception(Response::generate($gameName.'赛事-match_id:'.$data['match_id'].';',Response::LOCAL_MATCH_ERROR)) ;
                         }
                     }
                 }
@@ -363,7 +368,7 @@ class DataLogic
         } catch (\Exception $e) {
             //回滚事务
             DB::rollBack();
-            $this->writeLog($data, $e->getMessage());
+            $this->writeLog($data, ['file'=>$e->getFile(),'line'=>$e->getLine(),'msg'=>$e->getMessage()]);
             return $e->getMessage();
         }
 
@@ -380,18 +385,19 @@ class DataLogic
             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'];
@@ -407,9 +413,12 @@ class DataLogic
             //获取 当前请求 所有 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'];
             }
 
             //====验证 赛事 所属 联赛 是否存在====
@@ -434,19 +443,19 @@ class DataLogic
             //====end====
 
             //====验证 赛事结果记录 所属赛事 是否存在====
-            $s_match_ids = array_unique($s_match_ids);
-            sort($s_match_ids);
+            $match_uuids = array_unique($match_uuids);
+            sort($match_uuids);
 
             //获取 本地 已存在 赛事
-            $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 = $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,'others_match_id');
+            $l_match_data = commonFunction::uniquArrV2($l_match_data,'identity');
 
-            //循环对比 请求match_id->本地others_match_id
+            //循环对比 请求identity->本地identity
             foreach($l_match_data as $k=>$v){
-                foreach($s_match_ids as $kk=> $s_match_id){
-                    if($v['others_match_id'] == $s_match_id){
-                        unset($s_match_ids[$kk]);
+                foreach($match_uuids as $kk=> $match_identity){
+                    if($v['identity'] == $match_identity){
+                        unset($match_uuids[$kk]);
                     }
                 }
             }
@@ -461,7 +470,7 @@ class DataLogic
                 //获取 本地 联赛 ID
                 $lg_id = commonFunction::searcharray($data['uuid'],'identity',$l_lg_data,'lg_id');
                 //获取 本地 赛事 ID
-                $match_id = commonFunction::searcharray($data['match_id'],'others_match_id',$l_match_data,'match_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);
@@ -479,7 +488,7 @@ class DataLogic
         } catch (\Exception $e) {
             //回滚事务
             DB::rollBack();
-            $this->writeLog($data, $e->getMessage());
+            $this->writeLog($data, ['file'=>$e->getFile(),'line'=>$e->getLine(),'msg'=>$e->getMessage()]);
             return $e->getMessage();
         }
 
@@ -627,7 +636,7 @@ class DataLogic
         } catch (\Exception $e) {
             //回滚事务
             DB::rollBack();
-            $this->writeLog($data, $e->getMessage());
+            $this->writeLog($data, ['file'=>$e->getFile(),'line'=>$e->getLine(),'msg'=>$e->getMessage()]);
             return $e->getMessage();
         }
     }
@@ -699,7 +708,7 @@ class DataLogic
         } catch (\Exception $e) {
             //回滚事务
             DB::rollBack();
-            $this->writeLog($data, $e->getMessage());
+            $this->writeLog($data, ['file'=>$e->getFile(),'line'=>$e->getLine(),'msg'=>$e->getMessage()]);
             return $e->getMessage();
         }
     }
@@ -848,7 +857,7 @@ class DataLogic
         } catch (\Exception $e) {
             //回滚事务
             DB::rollBack();
-            $this->writeLog($data, $e->getMessage());
+            $this->writeLog($data, ['file'=>$e->getFile(),'line'=>$e->getLine(),'msg'=>$e->getMessage()]);
             return $e->getMessage();
         }
     }
@@ -909,7 +918,7 @@ class DataLogic
         } catch (\Exception $e) {
             //回滚事务
             DB::rollBack();
-            $this->writeLog($data, $e->getMessage());
+            $this->writeLog($data, ['file'=>$e->getFile(),'line'=>$e->getLine(),'msg'=>$e->getMessage()]);
             return $e->getMessage();
         }
     }