彭俊 6 gadi atpakaļ
vecāks
revīzija
891501058a
1 mainītis faili ar 334 papildinājumiem un 8 dzēšanām
  1. 334 8
      Application/Api/Controller/Betorder.php

+ 334 - 8
Application/Api/Controller/Betorder.php

@@ -45,13 +45,14 @@ class Betorder extends BaseController{
                 //验证联赛是否存在
                 $this->verify_league($vv['ballId'],(int)$vv['lg_id'],$num);
                 //验证赛事/赔率代码是否存在,如果match_id = 0 则为冠军联赛赔率,无需验证
-                if($vv['match_id'] > 0){
+                if($vv['match_id'] > 0 and $vv['is_champion'] == 0){
                     $this->verify_match($vv['ballId'],$vv['match_id'],$num);
                      //验证赛事下赔率玩法是否有效
                      $this->verify_odds($vv['ballId'],$vv['odds_only'],$vv['odds'],$vv['condition'],$vv['odds_code'],$num);
                 }
             }
         }
+
         foreach($res as $k => $v){
             //根据类型分组
             if($v['type'] == '1'){
@@ -75,7 +76,9 @@ class Betorder extends BaseController{
         if(empty($data)){
             return $data;
         }
+      
         foreach($data as $k => $v){
+            //普通赛事
             if($v['match_id'] > 0){
                 if(!isset($data[$v['match_id']])){
                     $data[$v['match_id']][] = $v;
@@ -84,7 +87,9 @@ class Betorder extends BaseController{
                     $data[$v['match_id']][] = $v;
                     unset($data[$k]);
                 }
-            }else{
+            }
+            //冠军联赛
+            if($v['match_id'] == 0){
                 if(!isset($data[$v['lg_id']])){
                     $data[$v['lg_id']][] = $v;
                     unset($data[$k]);
@@ -141,6 +146,77 @@ class Betorder extends BaseController{
      * @param  [int]  $batch_id 批量ID
      * @return  [int] 1 成功 其他失败
      */
+    public function Simplex_bet_insert__($data,$userInfo,$game_code,$batch_id){
+        if(empty($data)||empty($userInfo)||empty($game_code)){
+            Render('', '7003',lang('Errors','Api')->get('error-7003'));
+        }
+        foreach($data as $k => $v){
+            $OrderID = OrderID('S');//生成订单ID
+            $UUID = UUID(); //生成信息ID
+            $bet_money = 0; //赛事总投注额
+            $prize_money = 0; //可赢额
+            //获取投注单中是否有冠军联赛数据
+            $championData = [];
+            foreach($v as $kk => $vv){
+                $bet_money += $vv['bet_amount'];
+                //计算每个投注玩法下的可赢金额
+                // $prize_money += $this->commonFunction->getEarnMoney($game_code,$vv['p_code'],$vv['odds'],$vv['bet_amount'],1);
+                $prize_money +=  $vv['odds']* $vv['bet_amount'];
+                //是否是滚球投注
+                $is_rolling = 0;
+                if($vv['oddsType']=='StRollBall'){
+                    $is_rolling = 1;
+                }
+                $matchData =[
+                    'odds_id' =>$vv['id'],
+                    'home_team' => $vv['home_team'],
+                    'guest_team' => $vv['guest_team'],
+                    'condition' => $vv['condition'],
+                    'odds' => $vv['odds'],
+                    'odds_code' => $vv['odds_code'],
+                    'p_code' => $vv['p_code'],
+                    'odds_only' => $vv['odds_only'],
+                    'match_id' => $vv['match_id'],
+                    'game_code' => $game_code,
+                    'lg_id' => $vv['lg_id'],
+                    'batch_id' => $batch_id,
+                    'bet_type' => 1,
+                    'bet_money' => $vv['bet_amount'],
+                    'ctime' => $this->time,
+                    'utime' => $this->time,
+                    'is_rolling' =>$is_rolling,
+                ];
+                //插入数据源
+                $moneyBuyMatch = lm('MoneyBuyMatch','Api')->insert($matchData);
+                if(!$moneyBuyMatch){
+                    Render('','3205',lang('errors','Api')->get('error-3205'));
+                }
+            }
+            $order =[
+                'info_identity' => $UUID,
+                'account_name' => $userInfo['account'],
+                'account_identity' => $userInfo['account_identity'],
+                'order_id' => OrderID('S'),//$OrderID,
+                'game_code' => $game_code,
+                'batch_id' => $batch_id,
+                'match_id' => $k,
+                'game_no'  => "",
+                'prize_money'=> $prize_money,
+                'money' => $bet_money, //投注金额
+                'money_time' => $this->time
+            ];
+            $insert = lm("MoneyBuySimplex",'Api')->insert($order);
+            if(!$insert){
+                Render('','3205',lang('errors','Api')->get('error-3205'));
+            }
+            $insertMoney  = $this->M->insertMoney($userInfo['account_identity'],$bet_money,$OrderID,1,"",$UUID,$userInfo);
+            
+            if($insertMoney!=1){
+                Render('', $insertMoney,lang('Errors','Api')->get('error'.$insertMoney));
+            }
+            $this->M->fanshui($userInfo['account_identity'],$userInfo['account'],$bet_money,$OrderID);//反水
+        }
+    }
     public function Simplex_bet_insert($data,$userInfo,$game_code,$batch_id){
         if(empty($data)||empty($userInfo)||empty($game_code)){
             Render('', '7003',lang('Errors','Api')->get('error-7003'));
@@ -150,6 +226,227 @@ class Betorder extends BaseController{
             $UUID = UUID(); //生成信息ID
             $bet_money = 0; //赛事总投注额
             $prize_money = 0; //可赢额
+
+            foreach($v as $kk => $vv){
+                //是否是冠军投注
+                $is_champion = $vv['is_champion'];
+                $bet_money += $vv['bet_amount'];
+                //计算每个投注玩法下的可赢金额
+                // $prize_money += $this->commonFunction->getEarnMoney($game_code,$vv['p_code'],$vv['odds'],$vv['bet_amount'],1);
+                $prize_money +=  $vv['odds']* $vv['bet_amount'];
+                //是否是滚球投注
+                $is_rolling = 0;
+                if($vv['oddsType']=='StRollBall'){
+                    $is_rolling = 1;
+                }
+                $matchData[] =[
+                    'odds_id' =>$vv['id'],
+                    'home_team' => $vv['home_team'],
+                    'guest_team' => $vv['guest_team'],
+                    'condition' => $vv['condition'],
+                    'odds' => $vv['odds'],
+                    'odds_code' => $vv['odds_code'],
+                    'p_code' => $vv['p_code'],
+                    'odds_only' => $vv['odds_only'],
+                    'match_id' => $vv['match_id'],
+                    'game_code' => $game_code,
+                    'lg_id' => $vv['lg_id'],
+                    'batch_id' => $batch_id,
+                    'bet_type' => 1,
+                    'bet_money' => $vv['bet_amount'],
+                    'ctime' => $this->time,
+                    'utime' => $this->time,
+                    'is_rolling' =>$is_rolling,
+                ];
+            }
+             //插入数据源
+             $moneyBuyMatch = lm('MoneyBuyMatch','Api')->insert($matchData);
+             if(!$moneyBuyMatch){
+                 Render('','3205',lang('errors','Api')->get('error-3205'));
+             }
+            $order =[
+                'info_identity' => $UUID,
+                'account_name' => $userInfo['account'],
+                'account_identity' => $userInfo['account_identity'],
+                'order_id' => OrderID('S'),//$OrderID,
+                'game_code' => $game_code,
+                'batch_id' => $batch_id,
+                'match_id' => $k,
+                'game_no'  => "",
+                'prize_money'=> $prize_money,
+                'money' => $bet_money, //投注金额
+                'money_time' => $this->time,
+                'is_champion' => $is_champion?:0,//1 冠军投注 0普通赛事投注
+            ];
+            $insert = lm("MoneyBuySimplex",'Api')->insert($order);
+            if(!$insert){
+                Render('','3205',lang('errors','Api')->get('error-3205'));
+            }
+            $insertMoney  = $this->M->insertMoney($userInfo['account_identity'],$bet_money,$OrderID,1,"",$UUID,$userInfo);
+            
+            if($insertMoney!=1){
+                Render('', $insertMoney,lang('Errors','Api')->get('error'.$insertMoney));
+            }
+            $this->M->fanshui($userInfo['account_identity'],$userInfo['account'],$bet_money,$OrderID);//反水
+
+            /*
+            //获取投注单中冠军联赛数据
+            $championData = [];
+            //获取投注单中普通赛事数据
+            $matchData = [];
+            foreach($v as $kk=>$vv){
+
+                if($vv['is_champion'] == 1){
+                    $championData[]=$vv;
+                }
+                else if($vv['is_champion'] ==0){
+                    $matchData[]=$vv;
+                }
+            }
+
+            //处理普通赛事数据
+            if(!empty($matchData)){
+                foreach($matchData as $k_match=>$v_match){
+                    $bet_money += $v_match['bet_amount'];
+                    //计算每个投注玩法下的可赢金额
+                    // $prize_money += $this->commonFunction->getEarnMoney($game_code,$vv['p_code'],$vv['odds'],$vv['bet_amount'],1);
+                    $prize_money +=  $v_match['odds']* $v_match['bet_amount'];
+                    //是否是滚球投注
+                    $is_rolling = 0;
+                    if($vv['oddsType']=='StRollBall'){
+                        $is_rolling = 1;
+                    }
+                    $matchData_set[] =[
+                        'odds_id' =>$v_match['id'],
+                        'home_team' => $v_match['home_team'],
+                        'guest_team' => $v_match['guest_team'],
+                        'condition' => $v_match['condition'],
+                        'odds' => $v_match['odds'],
+                        'odds_code' => $v_match['odds_code'],
+                        'p_code' => $v_match['p_code'],
+                        'odds_only' => $v_match['odds_only'],
+                        'match_id' => $v_match['match_id'],
+                        'game_code' => $game_code,
+                        'lg_id' => $v_match['lg_id'],
+                        'batch_id' => $batch_id,
+                        'bet_type' => 1,
+                        'bet_money' => $v_match['bet_amount'],
+                        'ctime' => $this->time,
+                        'utime' => $this->time,
+                        'is_rolling' =>$is_rolling,
+                    ];
+                }
+
+                 //插入数据源 赛事
+                 $moneyBuyMatch = lm('MoneyBuyMatch','Api')->insert($matchData_set);
+                 if(!$moneyBuyMatch){
+                     Render('','3205',lang('errors','Api')->get('error-3205'));
+                 }
+
+                 $OrderID = IDOrderID('S');
+
+                 //组装注单数据
+                 $order =[
+                    'info_identity' => $UUID,
+                    'account_name' => $userInfo['account'],
+                    'account_identity' => $userInfo['account_identity'],
+                    'order_id' => $OrderID,
+                    'game_code' => $game_code,
+                    'batch_id' => $batch_id,
+                    'match_id' => $k,
+                    'game_no'  => "",
+                    'prize_money'=> $prize_money,
+                    'money' => $bet_money, //投注金额
+                    'money_time' => $this->time,
+                    'is_champion' => 1,//1 冠军投注 0普通赛事投注
+                ];
+                $insert = lm("MoneyBuySimplex",'Api')->insert($order);
+                if(!$insert){
+                    Render('','3205',lang('errors','Api')->get('error-3205'));
+                }
+                //资金变动
+                $insertMoney  = $this->M->insertMoney($userInfo['account_identity'],$bet_money,$OrderID,1,"",$UUID,$userInfo);
+                
+                if($insertMoney!=1){
+                    Render('', $insertMoney,lang('Errors','Api')->get('error'.$insertMoney));
+                }
+                //反水变动
+                $this->M->fanshui($userInfo['account_identity'],$userInfo['account'],$bet_money,$OrderID);//反水
+            }
+
+            //处理冠军投注数据
+            if(!empty($championData)){
+                foreach($championData as $k_champion=>$v_champion){
+                    $bet_money += $v_champion['bet_amount'];
+                    //计算每个投注玩法下的可赢金额
+                    // $prize_money += $this->commonFunction->getEarnMoney($game_code,$vv['p_code'],$vv['odds'],$vv['bet_amount'],1);
+                    $prize_money +=  $v_champion['odds']* $v_champion['bet_amount'];
+                    //是否是滚球投注
+                    $is_rolling = 0;
+                    if($vv['oddsType']=='StRollBall'){
+                        $is_rolling = 1;
+                    }
+                    $matchData_set[] =[
+                        'odds_id' =>$v_champion['id'],
+                        'home_team' => $v_champion['home_team'],
+                        'guest_team' => $v_champion['guest_team'],
+                        'condition' => $v_champion['condition'],
+                        'odds' => $v_champion['odds'],
+                        'odds_code' => $v_champion['odds_code'],
+                        'p_code' => $v_champion['p_code'],
+                        'odds_only' => $v_champion['odds_only'],
+                        'match_id' => $v_champion['match_id'],
+                        'game_code' => $game_code,
+                        'lg_id' => $v_champion['lg_id'],
+                        'batch_id' => $batch_id,
+                        'bet_type' => 1,
+                        'bet_money' => $v_champion['bet_amount'],
+                        'ctime' => $this->time,
+                        'utime' => $this->time,
+                        'is_rolling' =>$is_rolling,
+                    ];
+                }
+
+                 //插入数据源 赛事
+                 $moneyBuyMatch = lm('MoneyBuyMatch','Api')->insert($matchData_set);
+                 if(!$moneyBuyMatch){
+                     Render('','3205',lang('errors','Api')->get('error-3205'));
+                 }
+
+                 $OrderID = IDOrderID('S');
+
+                 //组装注单数据
+                 $order =[
+                    'info_identity' => $UUID,
+                    'account_name' => $userInfo['account'],
+                    'account_identity' => $userInfo['account_identity'],
+                    'order_id' => $OrderID,
+                    'game_code' => $game_code,
+                    'batch_id' => $batch_id,
+                    'match_id' => $k,
+                    'game_no'  => "",
+                    'prize_money'=> $prize_money,
+                    'money' => $bet_money, //投注金额
+                    'money_time' => $this->time,
+                    'is_champion' => 1,//1 冠军投注 0普通赛事投注
+                ];
+                $insert = lm("MoneyBuySimplex",'Api')->insert($order);
+                if(!$insert){
+                    Render('','3205',lang('errors','Api')->get('error-3205'));
+                }
+                //资金变动
+                $insertMoney  = $this->M->insertMoney($userInfo['account_identity'],$bet_money,$OrderID,1,"",$UUID,$userInfo);
+                
+                if($insertMoney!=1){
+                    Render('', $insertMoney,lang('Errors','Api')->get('error'.$insertMoney));
+                }
+                //反水变动
+                $this->M->fanshui($userInfo['account_identity'],$userInfo['account'],$bet_money,$OrderID);//反水
+            }
+
+
+            dd(111);
+            /*
             foreach($v as $kk => $vv){
                 $bet_money += $vv['bet_amount'];
                 //计算每个投注玩法下的可赢金额
@@ -189,7 +486,7 @@ class Betorder extends BaseController{
                 'info_identity' => $UUID,
                 'account_name' => $userInfo['account'],
                 'account_identity' => $userInfo['account_identity'],
-                'order_id' => $OrderID,
+                'order_id' => OrderID('S'),//$OrderID,
                 'game_code' => $game_code,
                 'batch_id' => $batch_id,
                 'match_id' => $k,
@@ -208,12 +505,14 @@ class Betorder extends BaseController{
                 Render('', $insertMoney,lang('Errors','Api')->get('error'.$insertMoney));
             }
             $this->M->fanshui($userInfo['account_identity'],$userInfo['account'],$bet_money,$OrderID);//反水
+            */
+
         }
     }
 
     public function Bet(){
-        // 模拟单式数据
         /*
+        // 模拟单式数据
         $get_data = [
             'data'=>[
                 [
@@ -221,6 +520,11 @@ class Betorder extends BaseController{
                     'index'=>0,
                     'bet_amount'=>1,
                 ],
+                [
+                    'type'=>1,
+                    'index'=>1,
+                    'bet_amount'=>1,
+                ],
                 [
                     [
                         'id'=>226063,
@@ -228,7 +532,7 @@ class Betorder extends BaseController{
                         'guest_team'=>'吉林百嘉',
                         'name'=>'内蒙古草上飞',
                         'odds'=>0.81,
-                        'match_id'=>1249,
+                        'match_id'=>0,
                         'condition'=>'0.5/1',
                         'ballId'=>'zq',
                         'odds_code'=>'concede_home',
@@ -240,11 +544,32 @@ class Betorder extends BaseController{
                         'lg_id'=>29,
                         'repeat'=>'false',
                         'match_type'=>'StRollBall',//滚球投注
+                        'is_champion'=>1,//是否是冠军联赛
+                    ],
+                    [
+                        'id'=>2260632,
+                        'home_team'=>'内蒙古草上飞1',
+                        'guest_team'=>'吉林百嘉2',
+                        'name'=>'内蒙古草上飞',
+                        'odds'=>0.81,
+                        'match_id'=>1249,
+                        'condition'=>'0.5/1',
+                        'ballId'=>'zq',
+                        'odds_code'=>'concede_home',
+                        'p_code'=>'concede',
+                        'play_name'=>'让球',
+                        'score'=>0,
+                        'bettingTime'=>date('Y-m-d H:i:s',time()),
+                        'odds_only'=>'272af2647b112b7eb337a2ed16753c6f1',
+                        'lg_id'=>29,
+                        'repeat'=>'false',                       
+                        'match_type'=>'StRollBall',//滚球投注
+                        'is_champion'=>0,//是否是冠军联赛
                     ],
                 ]
             ],
             
-            'token'=>'leNQX315656035465d5136da9967c',
+            'token'=>'zoUGmH15681966585d78c832ac4a4',
             'bet_money'=>900,
             'bet_money_arr'=>[100,200,300],
 
@@ -342,7 +667,8 @@ class Betorder extends BaseController{
             $bet_money = $_REQUEST['bet_money'];
             $token = $_REQUEST['token'];
             // $bet_money_arr = $_REQUEST['bet_money_arr'];
-        }
+        }   
+
         /*
         $data = $get_data['data'];
         $bet_money = $get_data['bet_money'];
@@ -361,7 +687,7 @@ class Betorder extends BaseController{
         }
 
         //追加验证用户投注金额限额
-        $this->bet_money_limit($data,$userInfo);
+        // $this->bet_money_limit($data,$userInfo);
 
         //获取订单批次号
         $batch_id = OrderID();///strtotime(date('Y-m-d H:i:s',time())).mt_rand('1','99');//批量ID