Przeglądaj źródła

放开数据写入日志

彭俊 6 lat temu
rodzic
commit
fa4ffd5844

+ 73 - 47
app/Http/Controllers/Api/WriteSportsController.php

@@ -548,11 +548,9 @@ class WriteSportsController extends BaseController{
             //不是 赔率 数据
             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'];
@@ -661,7 +659,7 @@ 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) {
@@ -692,11 +690,9 @@ class WriteSportsController extends BaseController{
             //不是 冠军 赔率 数据
             if($getData['title'] != 'odds_ch') 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'];
             //获取数据源
@@ -710,20 +706,24 @@ class WriteSportsController extends BaseController{
             //获取 赔率数据
             $oddsData = $getData['data'];
             //获取 当前 所有 可用 赔率 sole
-            // $odds_only = $getData['odds_only'];
+            $odds_only = $getData['odds_only'];
 
             //====验证 请求里 所有赔率 所属联赛 是否存在 ====
             //获取 当前请求 所有 联赛 uuid
             $uuids = [];
+            $s_lg_ids = [];
             foreach($oddsData as $k=>$v){
                 $uuids[] = $v['uuid'];
+                $s_lg_ids[] = $v['lg_id'];
             }
+            $s_lg_ids = array_unique($s_lg_ids);
             $uuids = array_unique($uuids);
             sort($uuids);
+            sort($s_lg_ids);
 
-            //更新赛下所有 不在本次请求的赔率 状态
-            // $ret= OddsModel::upOddsStatus($models,'',$s_lg_ids,$source,$odds_only);
-            // if($ret != true) throw new \Exception(Response::generate($gameName,Response::ODDS_SOLE_ERR));
+            //更新赛下所有 不在本次请求的赔率 状态
+            $ret= OddsModel::upOddsStatus($models,'',$s_lg_ids,$source,$odds_only);
+            if($ret != true) throw new \Exception(Response::generate($gameName,Response::ODDS_SOLE_ERR));
 
             //获取 本地 已存在 联赛
             $l_lg_data = $models['model_local_league']::whereIn('identity',$uuids)->select('identity','lg_id')->get()->toArray();
@@ -738,46 +738,72 @@ class WriteSportsController extends BaseController{
                 }
             }
 
-            //去除本地和请求里都存在的联赛,如果还有剩余联赛id,则返回异常;
+            //去除本地和请求里都存在的联赛,如果还有剩余联赛id,则返回异常; 
             if(!empty($uuids))  throw new \Exception(Response::generate($gameName.'冠军联赛:uuid-'.$uuids[0].';',Response::LEAGUE_ERROR));
             //====end====
-             //拼装 待写入 赔率数据
-             foreach($oddsData as $k=>$v){ 
-                //获取 本地 联赛 ID
-                $lg_id = commonFunction::searcharray($data['uuid'],'identity',$l_lg_data,'lg_id');
-                //组装数据
-                $set_odds = [
-                    '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']?:1,
-                    '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));
+            
+            //赔率记录数据
+            $set_odds_r = [];
+            //赔率数据
+            $set_odds = [];
+            if(!empty($oddsData)){
+                foreach($oddsData as $k=>$v){ 
+                    //获取 本地 联赛 ID
+                    $lg_id = commonFunction::searcharray($v['uuid'],'identity',$l_lg_data,'lg_id');
+                    //组装赔率记录数据
+                    $set_odds_r[] = [
+                        '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']?:1,
+                        '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'),
+                    ];
+                }
+
+                foreach($oddsData as $k=>$v){ 
+                    //获取 本地 联赛 ID
+                    $lg_id = commonFunction::searcharray($v['uuid'],'identity',$l_lg_data,'lg_id');
+                    //组装赔率数据
+                    $set_odds[] = [
+                        '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']?:1,
+                        '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'),
+                        '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();

+ 1 - 4
app/Http/Model/StZqOdds.php

@@ -49,7 +49,7 @@ class StZqOdds extends Model
             //获取当前 赛事 所有 赔率only
             $odds_data = $model['model_odds']::select('odds_only')
             ->whereIn('others_lg_id',$others_lg_id)
-            ->where(['source','=',$source])
+            ->where('source',$source)
             ->get()
             ->toArray();
         }
@@ -77,9 +77,6 @@ class StZqOdds extends Model
         //批量更新 赔率状态
         $ds = $model['model_odds']::whereIn('odds_only', $only)
         ->delete();
-            // ->update(['status' => -1]);
-
-            // if($ds > 0 ) return true;
         if($ds) return true;
     }
 }

+ 27 - 13
app/Lib/Settlement/SettlementOrder.php

@@ -31,6 +31,8 @@ class SettlementOrder extends SettlementBase
     private $set_type = 0;
     private $change_status = 1;
 
+    private $SettlementBaseObj = '' ;
+
 
     //返回数据
     public static function makeData($status = 1, $message = 'success', $data = '')
@@ -54,6 +56,10 @@ class SettlementOrder extends SettlementBase
             return self::makeData(8, 'matchid不能为空或0!');
         }
 
+        if (empty($game_code)) {
+            return self::makeData(8, '赛事类型不能为空!');
+        }
+
         if (!in_array($bettype, [1, 2])) {
             return self::makeData(6, '订单类型参数错误!');
         }
@@ -85,6 +91,8 @@ class SettlementOrder extends SettlementBase
         $this->game_code = $game_code;
 
 
+
+
         try {
             DB::beginTransaction();
 
@@ -96,6 +104,7 @@ class SettlementOrder extends SettlementBase
                 if ($this->BuyDatasMainModel->settle_status == 2 && $settype == 1) {
                     continue;
                 }
+
                 if ($bettype == 1) {
                     $this->SingOrder($order_id);
                 } else {
@@ -151,8 +160,13 @@ class SettlementOrder extends SettlementBase
             }
         }
 
+
         // 计算总回款
-        $settlementBase = new \App\Lib\Settlement\SettlementBase;
+        if (empty($this->SettlementBaseObj)){
+            $settlementBase = new \App\Lib\Settlement\SettlementBase();
+        }else{
+            $settlementBase  = $this->SettlementBaseObj;
+        }
         $returnMoney = 0;
         $oddsResult = [];
         foreach ($matchData as $k => $v) {
@@ -163,7 +177,6 @@ class SettlementOrder extends SettlementBase
             $oddsResult[0]['odds'] = $v->odds;
             $getReturnMoney = $settlementBase->stringOdds($oddsResult);
             $returnMoney += $getReturnMoney['returnMoney'] * $v->bet_money;
-
         }
         $returnMoney = sprintf("%.2f", substr(sprintf("%.3f", $returnMoney), 0, -1));
         // 判断盈亏  1 赢  2 输  3 平
@@ -337,24 +350,21 @@ class SettlementOrder extends SettlementBase
     //取消某个赛事订单的结算数据
     public function UndoSettlement($game_code, $match_id, $order_ids, $bettype)
     {
-        /* 不管是首次还是再结算,都作下判断  这个流程暂时不用
-            if ($this->set_type == 1) {
-                  return;
-            }
-        */
+
+        if ($this->set_type == 1) {
+            return;
+        }
 
         $modelSMD = new SettlementMiddleDetailModel();
         $hisData = $modelSMD->getSettledatas($game_code, $match_id, $bettype, $order_ids);
 
         if (count($hisData) <= 0) {
-            return true;
+            goto DONEXT;
         }
 
-
         $this->hissettlementDetail = $hisData;
         $orderList = [];
 
-
         if ($bettype == 1) {
             $order_list = DB::table('money_buy_simplex')->where(['game_code' => $game_code, 'match_id' => $match_id, 'status' => 1])->whereIn('order_id', $order_ids)->get();
 
@@ -381,6 +391,7 @@ class SettlementOrder extends SettlementBase
             }
             $this->insertData($oid, $money, $val->account_identity, $bettype, $game_code, $orderList[$oid]->info_identity, $money, $this->match_id);
         }
+        DONEXT:
         $table = $bettype == 1 ? 'money_buy_simplex' : 'money_buy_str';
         if ($bettype == 1) {
             $ret1 = DB::table($table)->where(['game_code' => $game_code, 'match_id' => $match_id, 'status' => 1])->whereIn('order_id', $order_ids)->update(['settle_status' => 1, 'gain_money' => 0, 'game_status' => 0]);
@@ -388,18 +399,21 @@ class SettlementOrder extends SettlementBase
             $ret1 = DB::table($table)->where(['status' => 1])->whereIn('order_id', $order_ids)->update(['settle_status' => 1, 'gain_money' => 0]);
         }
 
-        $ret2 = DB::table('settlement_middle_detail')->where(['game_code' => $game_code, 'match_id' => $match_id, 'bet_type' => $bettype])->whereIn('order_id', $order_ids)->update(['money' => 0]);
+        DB::table('settlement_middle_detail')->where(['game_code' => $game_code, 'match_id' => $match_id, 'bet_type' => $bettype])->whereIn('order_id', $order_ids)->update(['money' => 0]);
 
-        if ($ret1 && $ret2) {
+        if ($ret1) {
             return true;
         } else {
-            throw new \Exception("取消结算更新数据状态出错操作中止($ret1 $ret2)!");
+            throw new \Exception("取消结算更新数据状态出错操作中止($ret1)!");
         }
 
     }
 
     private function WriteOrAddSettlement($game_code, $match_id, $bet_type, $order_id, $account_ident, $money)
     {
+        if (intval($money * 100) == 0) {
+            return;
+        }
 
         if (isset($this->hissettlementDetail[$order_id])) {
             $ret = DB::table('settlement_middle_detail')

+ 9 - 4
app/Lib/Settlement/SettlementWinFail.php

@@ -60,13 +60,12 @@ class SettlementWinFail
                 return $this->makeData(1, '没有要处理的数据,直接退出');
             }
 
-
             DB::beginTransaction();
-
             $this->writeStatusBegin($ComendNoticModel);
 
             //$allmatchs = DB::table('money_buy_match')->where(['game_code' => $ComendNoticModel->game_code, 'match_id' => $ComendNoticModel->match_id, 'result' => 0])->get();
             $allmatchs = DB::table('money_buy_match')->where(['game_code' => $ComendNoticModel->game_code, 'match_id' => $ComendNoticModel->match_id])->get();
+
             if (count($allmatchs) == 0) {
                 $this->writeStatusEndOk($ComendNoticModel);
                 $this->cgStatus();
@@ -81,6 +80,7 @@ class SettlementWinFail
             $this->RefClass = new  \ReflectionClass($this->AdapterObj);
             $this->getCompResult($ComendNoticModel->game_code, $ComendNoticModel->match_id);
 
+
             $this->Settlement_simplex($this->gameType, $this->match_id);
             $this->Settlement_str($this->gameType, $this->match_id);
 
@@ -161,6 +161,7 @@ class SettlementWinFail
             return true;
         }
 
+
         $buyKeyModel = $buymatchKeyModles = [];
         foreach ($buyModels as $val) {
             $batch_id = $val->batch_id;
@@ -172,7 +173,8 @@ class SettlementWinFail
             $buymatchKeyModles[$batch_id][] = $val;
         }
 
-        foreach ($buyKeyModel as $batch_id => $val) {
+
+        //foreach ($buyKeyModel as $batch_id => $val) {
             foreach ($buymatchKeyModles as $sub_batch_id => $fsval) {
                 foreach ($fsval as $sval) {
                     $winorfalse = $this->winOrfalseInfo($sval);
@@ -183,7 +185,8 @@ class SettlementWinFail
                     DB::table('money_buy_simplex')->where(['batch_id' => $sval->batch_id, 'match_id' => $sval->match_id, 'game_code' => $sval->game_code])->update(['game_status' => $gs_val]);
                 }
             }
-        }
+       // }
+
         return true;
     }
 
@@ -294,6 +297,8 @@ class SettlementWinFail
         if (!in_array($winorfalse['result'], [-1, 1, 2, 3, 4])) {
             throw new \Exception('输赢结果异常!');
         }
+
+
         return $winorfalse;
     }