vali 6 年之前
父节点
当前提交
3a08fcf5d2
共有 1 个文件被更改,包括 36 次插入38 次删除
  1. 36 38
      app/Logic/DataLogic.php

+ 36 - 38
app/Logic/DataLogic.php

@@ -121,8 +121,8 @@ class DataLogic
                             $set_lg['identity'] = $v['uuid'];
                             $set_lg['last_time'] = $last_time;
                             $set_lg['utime'] = date('Y-m-d H:i:s');
-                            $set_lg['area_id'] = $area_id;
-                            $set_lg['country_id'] = $country_id;
+                            $set_lg['area_id'] = $area_id ?: 247;
+                            $set_lg['country_id'] = $country_id ?: 0;
                             //写入联赛
                             $id = $models['model_league']::insertGetId($set_lg);
                             $m_lg_id = $id;
@@ -193,7 +193,6 @@ class DataLogic
             //获取 当前请求 所有 uuid
             $identity = [];
             $s_match_ids = [];
-            $match_uuids = [];
             foreach ($matchData as $k => $v) {
                 $identity[] = $v['uuid'];
                 $s_match_ids[] = $v['match_id'];
@@ -224,17 +223,15 @@ class DataLogic
             $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);
+            $s_match_ids = array_unique($s_match_ids);
+            sort($s_match_ids);
 
-            $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, 'identity');
+            $l_match_data = commonFunction::uniquArrV2($l_match_data, 'others_match_id');
 
             //循环对比 请求match_id->本地others_match_id
             //如果本地有 赛事,则分别获取本地已存在/不存在赛事
@@ -242,21 +239,21 @@ class DataLogic
                 //本地已存在赛事,用于更新
                 $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;
+                    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;
                             $matchData_y[$k]['match_id'] = $v['match_id'];
-                            unset($match_uuids[$kk]);
+                            unset($s_match_ids[$kk]);
                         }
                     }
                 }
-                sort($match_uuids);
+                sort($s_match_ids);
             }
             //如果 请求中 有本地赛事,则执行更新
             if (!empty($matchData_y)) {
                 foreach ($matchData as $k => $v) {
                     foreach ($matchData_y as $kk => $vv) {
-                        if ($v['match_identity'] == $vv['match_identity']) {
+                        if ($v['match_id'] == $vv['others_match_id']) {
                             $data = $v;
                             $up_match = [];
                             $up_match['utime'] = date('Y-m-d H:i:s');
@@ -293,10 +290,10 @@ class DataLogic
                 }
             }
             //剩余 赛事 数据 写入
-            if (!empty($match_uuids)) {
+            if (!empty($s_match_ids)) {
                 foreach ($matchData as $k => $v) {
-                    foreach ($match_uuids as $kk => $match_identity) {
-                        if ($v['match_identity'] == $match_identity) {
+                    foreach ($s_match_ids as $kk => $s_match_id) {
+                        if ($v['match_id'] == $s_match_id) {
                             $data = $v;
                             $half_match_id = $v['half_match_id'];
                             //获取 本地 联赛 ID
@@ -334,7 +331,6 @@ 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 字段
@@ -350,11 +346,10 @@ 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));
+                            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'));
                         }
                     }
                 }
@@ -385,6 +380,7 @@ class DataLogic
             DB::beginTransaction();
             $obt = $data['data'];
 
+            //请求 数据 为空
             if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
             $getData = $this->getAddData($obt);
 
@@ -394,8 +390,8 @@ class DataLogic
             /*
             //写请求数据 日志记录
             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));
+                // $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'],$obt,$getData);
+                // if($setSportsRecord < 1) throw new \Exception(Response::generate('',Response::SPORTS_RECORD_ERR));
             }
             */
 
@@ -417,8 +413,6 @@ class DataLogic
             foreach ($match_r_data as $k => $v) {
                 $identity[] = $v['uuid'];
                 $s_match_ids[] = $v['match_id'];
-                //追加获取赛事uuid
-                $match_uuids[] = $v['match_identity'];
             }
 
             //====验证 赛事 所属 联赛 是否存在====
@@ -442,20 +436,21 @@ class DataLogic
             if (!empty($identity)) throw new \Exception(Response::generate($gameName . '联赛:uuid-' . $identity[0] . ';', Response::LEAGUE_ERROR));
             //====end====
 
-            //====验证 赛事结果记录 所属赛事 是否存在====
-            $match_uuids = array_unique($match_uuids);
-            sort($match_uuids);
+            //====验证 赛事结果记录 所属赛事 是否存在====$match_uuids
+            $s_match_ids = array_unique($s_match_ids);
+            sort($s_match_ids);
 
             //获取 本地 已存在 赛事
-            $l_match_data = $models['model_local_match']::whereIn('identity', $match_uuids)->where('source', $source)->select('identity', 'match_id')->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, 'identity');
+            $l_match_data = commonFunction::uniquArrV2($l_match_data, 'others_match_id');
 
-            //循环对比 请求identity->本地identity
+            //循环对比 请求match_id->本地others_match_id
             foreach ($l_match_data as $k => $v) {
-                foreach ($match_uuids as $kk => $match_identity) {
-                    if ($v['identity'] == $match_identity) {
-                        unset($match_uuids[$kk]);
+                foreach ($s_match_ids as $kk => $s_match_id) {
+                    if ($v['others_match_id'] == $s_match_id) {
+                        unset($s_match_ids[$kk]);
                     }
                 }
             }
@@ -470,7 +465,7 @@ class DataLogic
                 //获取 本地 联赛 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');
+                $match_id = commonFunction::searcharray($data['match_id'], 'others_match_id', $l_match_data, 'match_id');
 
                 //根据球类 获取 赛事结果记录字段
                 $set_match_r = $this->get_match_r($game_code, $lg_id, $match_id, $data);
@@ -481,6 +476,7 @@ class DataLogic
                 if ($ret != true) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::ADD_MATCH_R_R_ERROR));
             }
 
+
             $this->writeLog($data, Response::success());
             //提交事务
             DB::commit();
@@ -512,11 +508,13 @@ class DataLogic
             //不是 赔率 数据
             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));
+            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'];