vali 6 years ago
parent
commit
f68f3b6e1f
1 changed files with 142 additions and 44 deletions
  1. 142 44
      app/Logic/DataLogic.php

+ 142 - 44
app/Logic/DataLogic.php

@@ -416,11 +416,11 @@ class DataLogic
      */
     public function setOdds($data)
     {
-
         try {
             //开启事务
             DB::beginTransaction();
             $obt = $data['data'];
+
             //请求 数据 为空
             if(empty($obt)) throw new \Exception(Response::generate('请求数据为空,',Response::ABNORMAL));
             $getData = $this->getAddData($obt);
@@ -428,6 +428,12 @@ class DataLogic
             //不是 赔率 数据
             if($getData['title'] != 'odds') throw new \Exception(Response::generate('不是赔率数据,',Response::ABNORMAL));
 
+            /*
+            //写请求数据 日志记录
+            $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'];
             //获取数据源
@@ -437,7 +443,7 @@ class DataLogic
             //获取源数据赛事ID
             $s_match_id = $getData['match_id'];
             //获取赔率所属赛事 tag 值 玩法数量
-            $tag = $getData['tag'];
+            $tag = $getData['tag']?:99;
 
             //获取球类名称
             $gameName = gameModel::getGameName($game_code);
@@ -447,57 +453,149 @@ class DataLogic
             $match_id = $this->matchVerify($models,$s_match_id,$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'];
-            if(!empty($oddsData)){
-                //获取 当前 所有 可用 赔率 sole
-                $odds_only = $getData['odds_only'];
-                //更新赛事下所有 不在本次请求的赔率 状态
-                $ret= OddsModel::upOddsStatus($models,$s_match_id,'',$source,$odds_only);
-                if($ret != true) throw new \Exception(Response::generate($gameName,Response::ODDS_SOLE_ERR));
-
-                //拼装 待写入 赔率数据
-                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,
-                        'others_lg_id'=> $v['lg_id'],
-                        'ctime'=> date('Y-m-d H:i:s'),
-                        'utime'=> date('Y-m-d H:i:s'),
-                    ];
-                    //写赔率记录数据
-                    $ret = $models['model_odds_record']->updateOrCreate(
-                        ['odds_only'=>$v['odds_only']],$set_odds
-                    );
-                    if(empty($ret)) throw new \Exception(Response::generate($gameName.'赔率记录-odds_only:'.$v['odds_only'].';',Response::ADD_ODDS_R_ERROR));
-
-                    //追加参数
-                    $set_odds['sole'] = $v['sole'];
-                    $set_odds['expire_time'] = date('Y-m-d H:i:s',time()+60);
-                    //写赔率 数据
-                    $ret = $models['model_odds']->updateOrCreate(
-                        ['odds_only'=>$v['odds_only']],$set_odds
-                    );
-                    if(empty($ret)) throw new \Exception(Response::generate($gameName.'赔率-odds_only:'.$v['odds_only'].';',Response::ADD_ODDS_ERROR));
+            //获取 当前 所有 可用 赔率 sole
+            $odds_only = $getData['odds_only'];
+            //更新赛事下所有 不在本次请求的赔率 状态
+            $ret= OddsModel::upOddsStatus($models,$s_match_id,'',$source,$odds_only);
+            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();
+            if(empty($l_odds_data)){
+                if(!empty($oddsData)){
+                    //处理待写入 赔率数据
+                    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,
+                            'others_lg_id'=> $v['lg_id'],
+                            'ctime'=> date('Y-m-d H:i:s'),
+                            'utime'=> date('Y-m-d H:i:s'),
+                        ];
+                        //写赔率记录数据
+                        $ret = $models['model_odds_record']::insert($set_odds);
+                        if($ret != true) throw new \Exception(Response::generate($gameName.'赔率记录-odds_only:'.$v['odds_only'].';',Response::ADD_ODDS_R_ERROR));
+                        //追加参数
+                        $set_odds['sole'] = $v['sole'];
+                        $set_odds['expire_time'] = date('Y-m-d H:i:s',time()+60);
+                        //写赔率 数据
+                        $ret = $models['model_odds']::insert($set_odds);
+                        if($ret != true) throw new \Exception(Response::generate($gameName.'赔率-odds_only:'.$v['odds_only'].';',Response::ADD_ODDS_ERROR));
+                    }
                 }
+            }else{
+                //区分本地已有的赔率
+                //需更新赔率
+                $up_odds_data = [];
+                //需写入赔率
+                $in_odds_data = [];
+
+                if(!empty($oddsData)){
+                    foreach($oddsData as $k=>$v){
+                        foreach($l_odds_data as $kk=>$vv){
+                            if($v['odds_only'] == $vv['odds_only']){
+                                $up_odds_data[] = $v;
+                            }else{
+                                $in_odds_data[] = $v;
+                            }
+                        }
+                    }
+                    /*
+                    //执行 更新赔率
+                    if(!empty($up_odds_data)){
+                        foreach($up_odds_data 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,
+                                'others_lg_id'=> $v['lg_id'],
+                                'ctime'=> date('Y-m-d H:i:s'),
+                                'utime'=> date('Y-m-d H:i:s'),
+                            ];
+                            //写赔率记录数据
+                            $ret = $models['model_odds_record']::where(['odds_only'=>$v['odds_only']])
+                                        -> update($set_odds);
+                            if($ret < 1) throw new \Exception(Response::generate($gameName.'赔率记录-odds_only:'.$v['odds_only'].';',Response::ADD_ODDS_R_ERROR));
+                            //追加参数
+                            $set_odds['sole'] = $v['sole'];
+                            $set_odds['expire_time'] = date('Y-m-d H:i:s',time()+60);
+                            //写赔率 数据
+                            $ret = $models['model_odds']::where(['odds_only'=>$v['odds_only']])
+                                        -> update($set_odds);
+                            if($ret < 1) throw new \Exception(Response::generate($gameName.'赔率-odds_only:'.$v['odds_only'].';',Response::ADD_ODDS_ERROR));
+                        }
+                    }
+                    */
+                    //执行 新增赔率
+                    if(!empty($in_odds_data)){
+                        foreach($in_odds_data 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,
+                                'others_lg_id'=> $v['lg_id'],
+                                'ctime'=> date('Y-m-d H:i:s'),
+                                'utime'=> date('Y-m-d H:i:s'),
+                            ];
+                            //写赔率记录数据
+                            $ret = $models['model_odds_record']::insert($set_odds);
+                            if($ret != true) throw new \Exception(Response::generate($gameName.'赔率记录-odds_only:'.$v['odds_only'].';',Response::ADD_ODDS_R_ERROR));
+                            //追加参数
+                            $set_odds['sole'] = $v['sole'];
+                            $set_odds['expire_time'] = date('Y-m-d H:i:s',time()+60);
+                            //写赔率 数据
+                            $ret = $models['model_odds']::insert($set_odds);
+                            if($ret != true) throw new \Exception(Response::generate($gameName.'赔率-odds_only:'.$v['odds_only'].';',Response::ADD_ODDS_ERROR));
+                        }
+                    }
+                }
+
             }
 
+
             $this->writeLog($data,Response::success());
             //提交事务
             DB::commit();