彭俊 6 سال پیش
والد
کامیت
01c0603982
1فایلهای تغییر یافته به همراه171 افزوده شده و 36 حذف شده
  1. 171 36
      Application/Api/Controller/Betorder.php

+ 171 - 36
Application/Api/Controller/Betorder.php

@@ -139,9 +139,45 @@ class Betorder extends BaseController{
      * @param  [array] $res 单式投注数据
      * @return  [int] 1 成功 其他失败
      * @param  [int]  $batch_id 批量ID
+     * 弃用
      */
     public function Simplex_bet(array $res,array $userInfo,$batch_id){
 
+        if(empty($res)||empty($userInfo)||empty($batch_id)){
+            Render('', '7003',lang('Errors','Api')->get('error-7003'));
+        }
+        //验证与判断投注了几种
+        foreach($res as $k => $v){
+            $num = $k + 1;
+            if(empty($v['bet_amount'])){
+                $msg = '第'.$num.'条'.lang('Errors','Api')->get('error-5105');
+                Render([], '5105',$msg);
+            }
+            //根据类型分组
+            if(!isset($res[$v['ballId']])){
+                $res[$v['ballId']][] = $v;
+                unset($res[$k]);
+            }else{
+                $res[$v['ballId']][] = $v;
+                unset($res[$k]);
+            }
+
+        }
+        //球类联赛分类并且插入数据库
+        foreach($res as $k => $v){
+            $this->Simplex_bet_insert($v,$userInfo,$k,$batch_id);
+
+            /*
+            $gamedate = $this->Group_ball($res[$k]);
+            $this->Simplex_bet_insert($gamedate,$userInfo,$k,$batch_id);
+            */
+        }
+
+        return $odds_ids;
+    }
+    //弃用 备份
+    public function Simplex_bet___(array $res,array $userInfo,$batch_id){
+
         if(empty($res)||empty($userInfo)||empty($batch_id)){
             Render('', '7003',lang('Errors','Api')->get('error-7003'));
         }
@@ -250,7 +286,8 @@ class Betorder extends BaseController{
             $this->M->fanshui($userInfo['account_identity'],$userInfo['account'],$bet_money,$OrderID);//反水
         }
     }
-    public function Simplex_bet_insert($data,$userInfo,$game_code,$batch_id){
+    //按赛事分组 一个赛事一个注单
+    public function Simplex_bet_insert_v1($data,$userInfo,$game_code,$batch_id){
 
         if(empty($data)||empty($userInfo)||empty($game_code)){
             Render('', '7003',lang('Errors','Api')->get('error-7003'));    
@@ -348,6 +385,103 @@ class Betorder extends BaseController{
             $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'));    
+        }
+        foreach($data as $k => $v){
+            $OrderID = OrderID('S');//生成订单ID
+            $UUID = UUID(); //生成信息ID
+            $bet_money = 0; //赛事总投注额
+            $prize_money = 0; //可赢额
+            //====处理 投注数据
+            //是否是冠军投注,如果==0 则为冠军投注
+             $is_champion = 0;
+             if($v['match_id'] == 0){
+                 $is_champion = 1;
+             }
+             //获取联赛id lg_id
+             $lg_id = $v['lg_id'];
+             $bet_money = $v['bet_amount'];
+             //计算每个投注玩法下的可赢金额
+             $prize_money =  $v['odds']* $v['bet_amount'];
+             //是否是滚球投注
+             $is_rolling = 0;
+             if($v['oddsType']=='StRollBall'){
+                 $is_rolling = 1;
+             }
+             $matchData =[
+                 'odds_id' =>$v['id'],
+                 'home_team' => $v['home_team'],
+                 'guest_team' => $v['guest_team'],
+                 'condition' => $v['condition'],
+                 'odds' => $v['odds'],
+                 'odds_code' => $v['odds_code'],
+                 'p_code' => $v['p_code'],
+                 'odds_only' => $v['odds_only'],
+                 'match_id' => $v['match_id'],
+                 'game_code' => $game_code,
+                 'lg_id' => $lg_id,
+                 'batch_id' => $batch_id,
+                 'bet_type' => 1,
+                 'bet_money' => $bet_money,
+                 'ctime' => $this->time,
+                 'utime' => $this->time,
+                 'is_rolling' =>$is_rolling,
+                 'is_champion' => $is_champion?:0,//1 冠军投注 0普通赛事投注
+                 'order_id'=>$OrderID,//追加所属订单id
+             ];
+              //插入数据源
+             $moneyBuyMatch = lm('MoneyBuyMatch','Api')->insert($matchData);
+             if(!$moneyBuyMatch){
+                 Render('','3205',lang('errors','Api')->get('error-3205'));
+             }
+             //===end===
+            $order = [];
+            $order =[
+                'info_identity' => $UUID,
+                'account_name' => $userInfo['account'],
+                'account_identity' => $userInfo['account_identity'],
+                'order_id' => $OrderID,//$OrderID,
+                'game_code' => $game_code,
+                'batch_id' => $batch_id,
+                'match_id' => $v['match_id'],
+                'lg_id' => $lg_id,
+                'game_no'  => "",
+                'prize_money'=> $prize_money,
+                'money' => $bet_money, //投注金额
+                'money_time' => $this->time,
+                'is_champion' => $is_champion?:0,//1 冠军投注 0普通赛事投注
+            ];
+
+            //如果是冠军投注,追加字段
+            if($is_champion == 1){
+                $json_single_result = [
+                    'lg_id'=> '',
+                    'game_name' => '',
+                    'result' => '',
+                    'updatetime' => '',
+                ];
+                $order['single_result'] = json_encode($json_single_result);
+            }
+            //如果是滚球投注,追加字段
+            if($is_rolling == 1 and $game_code == 'zq'){
+                $order['roll_ratify'] = 2;//未审核滚球投注
+            }
+            $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 Bet(){
         /*
@@ -362,57 +496,58 @@ class Betorder extends BaseController{
                 [
                     'type'=>1,
                     'index'=>1,
-                    'bet_amount'=>200,
+                    'bet_amount'=>100,
                 ],
                 [
                     [
-                        'id'=>226063,
-                        'home_team'=>'内蒙古草上飞',
-                        'guest_team'=>'吉林百嘉',
-                        'name'=>'内蒙古草上飞',
-                        'odds'=>0.81,
-                        'match_id'=>0,
-                        'condition'=>'0.5/1',
+                        'id'=>10350565,
+                        'home_team'=>'什鲁斯伯里',
+                        'guest_team'=>'彼德堡',
+                        'name'=>'',
+                        'odds'=>1.09,
+                        'match_id'=>1463,
+                        'condition'=>'2.5/3',
                         'ballId'=>'zq',
-                        'odds_code'=>'concede_home',
-                        'p_code'=>'concede',
-                        'play_name'=>'让球',
+                        'odds_code'=>'gsb',
+                        'p_code'=>'GS',
+                        'play_name'=>'进球大小',
                         'score'=>0,
                         'bettingTime'=>date('Y-m-d H:i:s',time()),
-                        'odds_only'=>'272af2647b112b7eb337a2ed16753c6f',
-                        'lg_id'=>29,
-                        'repeat'=>'false',
-                        'match_type'=>'StRollBall',//滚球投注
-                        // 'is_champion'=>1,//是否是冠军联赛
+                        'odds_only'=>'6a003dec710a42849a82dd1ea978f572',
+                        'lg_id'=>17,
+                        'match_type'=>'',//滚球投注
+                        'odds_id'=>10350565,
+                        'repeat'=>'true',
+                        'is_champion'=>0,//是否是冠军联赛
                     ],
                     [
-                        'id'=>2260632,
-                        'home_team'=>'内蒙古草上飞1',
-                        'guest_team'=>'吉林百嘉2',
-                        'name'=>'内蒙古草上飞',
-                        'odds'=>0.81,
-                        'match_id'=>1249,
-                        'condition'=>'0.5/1',
+                        'id'=>10781633,
+                        'home_team'=>'什鲁斯伯里',
+                        'guest_team'=>'彼德堡',
+                        'name'=>'彼德堡',
+                        'odds'=>1,
+                        'match_id'=>1463,
+                        'condition'=>'-0/0.5',
                         'ballId'=>'zq',
-                        'odds_code'=>'concede_home',
-                        'p_code'=>'concede',
+                        'odds_code'=>'cog',
+                        'p_code'=>'CO',
                         'play_name'=>'让球',
                         'score'=>0,
                         'bettingTime'=>date('Y-m-d H:i:s',time()),
-                        'odds_only'=>'272af2647b112b7eb337a2ed16753c6f1',
-                        'lg_id'=>29,
-                        'repeat'=>'false',                       
-                        'match_type'=>'StRollBall',//滚球投注
+                        'odds_only'=>'390e2b68992587438c0020179abc94f5',
+                        'lg_id'=>17,
+                        'match_type'=>'',//滚球投注
+                        'odds_id'=>10781633,
+                        'repeat'=>'true',
                         'is_champion'=>0,//是否是冠军联赛
-                    ],
+                    ]
                 ]
             ],
             
-            'token'=>'mKoaQr15712941335da80bb5beb4e',
-            'bet_money'=>900,
-            'bet_money_arr'=>[100,200,300],
-
+            'token'=>'hdetVs15729386035dc1236b1c189',
+            'bet_money'=>200,
         ];
+        */
 
         /*
         //  模拟串式数据
@@ -507,7 +642,7 @@ class Betorder extends BaseController{
             $bet_money = $_REQUEST['bet_money'];
             $token = $_REQUEST['token'];
             // $bet_money_arr = $_REQUEST['bet_money_arr'];
-        }   
+        } 
 
         /*
         $data = $get_data['data'];