Просмотр исходного кода

追加模拟第三方投注,串式数据处理

彭俊 6 лет назад
Родитель
Сommit
0dba417c7b
2 измененных файлов с 125 добавлено и 17 удалено
  1. 2 2
      app/Lib/Biz/Sport/Common.php
  2. 123 15
      app/Models/SportsNoteList.php

+ 2 - 2
app/Lib/Biz/Sport/Common.php

@@ -1063,7 +1063,7 @@ class Common
     }
 
 // 组合
-    function combination($a, $m)
+    static function combination($a, $m)
     {
         $r = array();
 
@@ -1078,7 +1078,7 @@ class Common
                 $r[] = $t;
             } else {
                 $b = array_slice($a, $i + 1);
-                $c = $this->combination($b, $m - 1);
+                $c = self::combination($b, $m - 1);
                 foreach ($c as $v) {
                     $r[] = array_merge($t, $v);
                 }

+ 123 - 15
app/Models/SportsNoteList.php

@@ -13,6 +13,7 @@ use App\Lib\Biz\Sport\Common as commonFunction;
 use App\Models\MoneyBuyMatchb;
 use App\Http\Response\Response;
 use App\Http\Model\StZqResult as StZqResultModel;
+use App\Models\MoneyBuyStr as MoneyBuyStrModel;
 
 use App\Http\Model\StZqMatch as ZqMatchModel;
 use App\Http\Model\StLqMatch as LqMatchModel;
@@ -2491,24 +2492,10 @@ class SportsNoteList extends BaseModel
     public function upOrder($order_type='',$order_id='',$order_match=[]){
         //处理单式注单
         if($order_type == 1){
-            //球类代码
-            $game_code = $order_match[0]['game_code'];
-            //赛事id
-            $match_id = $order_match[0]['match_id'];
-            //投注玩法代码
-            $odds_code = $order_match[0]['odds_code'];
             //投注赔率值
             $odds = $order_match[0]['odds'];
             //投注条件
             $condition = $order_match[0]['condition'];
-
-            //拼接 投注 赛事查询条件
-            $where_match = [
-                ['bet_type','=',$order_type],
-                ['order_id','=',$order_id],
-                ['game_code','=',$game_code],
-                ['odds_code','=',$odds_code],
-            ];
             //订单查询条件
             $where_order = [
                 ['order_id','=',$order_id],
@@ -2537,8 +2524,66 @@ class SportsNoteList extends BaseModel
         }
         //处理串式订单
         else if($order_type == 2){
-            throw new \Exception(Response::generate('串式订单:', Response::WAIT_FOR));
+            //订单查询条件
+            $where_order = [
+                ['order_id','=',$order_id],
+            ];
+            $MoneyBuyStr = new MoneyBuyStrModel();
 
+            //获取订单数据
+            $orderData = $MoneyBuyStr->where($where_order)->first();
+            //订单不存在
+            if(empty($orderData)) throw new \Exception(Response::generate('', Response::ORDER_NULL));
+            //订单不是投注状态
+            if($orderData->status != 1) throw new \Exception(Response::generate('订单状态:$orderData->status;', Response::ORDER_STATUS_ERR));
+            //获取投注金额
+            $betMoney = $orderData->money;
+            //获取串式类型
+            $str_type = $orderData->str_type;
+            //字符串替换
+            $str = str_ireplace("串","_",$str_type);
+            //获取type 3_12
+            $after = substr($str,strpos($str,"_")+1);
+            //当前串式 值
+            $sonNum = substr($str,0,strrpos($str,"_"));
+            //获取预期中奖金额
+            $prize_money = $this->getPrizeMoney($order_match,$betMoney,$sonNum,$after);
+
+            //更新订单数据
+            $orderData->prize_money = $prize_money;
+            $orderData->remark = '模拟第三方投注,修正订单';
+            if(!$orderData->save()) throw new \Exception(Response::generate('', Response::ORDER_UP_ERR));
+            
+            //处理数据 更新玩法赔率数值
+            foreach($order_match as $k=>$v){
+                //球类代码
+                $game_code = $v['game_code'];
+                //赛事id
+                $match_id = $v['match_id'];
+                //投注赔率值
+                $odds = $v['odds'];
+                //投注条件
+                $condition = $v['condition'];
+
+                //拼接 投注 赛事查询条件
+                $where_match = [
+                    // ['bet_type','=',$order_type],
+                    ['order_id','=',$order_id],
+                    ['game_code','=',$game_code],
+                    // ['odds_code','=',$odds_code],
+                    ['match_id','=',$match_id],
+                ];
+
+                //更新投注详情数据
+                $match_up = [
+                    'utime'=>date("Y-m-d H:i:s", time()),//更新时间
+                    'condition'=>$condition,//投注条件
+                    'odds' =>$odds,//投注赔率
+                ];
+                $ret_money_buy_match = \App\Models\MoneyBuyMatch::where($where_match)->update($match_up);
+                //订单详情更新失败
+                if($ret_money_buy_match < 1)  throw new \Exception(Response::generate('', Response::ORDER_UP_XQ_ERR));
+            }
         }
         //订单类型错误
         else{
@@ -2547,4 +2592,67 @@ class SportsNoteList extends BaseModel
 
         return 1;
     }
+
+    /**
+     * 计算串式注单 中奖金额
+     * $data_all arr 投注赛事数据
+     * $bet_amount 投注金额
+     * $sonNum 当前串式 数量 N串1 $sonNum=N
+     * $after 串式类型 N串1  $after=1
+     */
+    public function getPrizeMoney($data_all,$bet_amount,$sonNum,$after=0){
+        $allNum = count($data_all);//所有数量
+        $odds_all = [];//所有投注项数据
+        foreach ($data_all as $k=>$v){
+            // $odds_all[] = $v['odds'];
+            $odds_all[] = $v['odds']+1;
+
+        }
+        //计算倍数
+        $Multiple = $this->getMultiple($allNum,$sonNum);
+        //投注总额
+        $bet_amount = $bet_amount/$Multiple;
+        if($sonNum == $allNum and (int)$after ==1){//N场赛事  N串一
+            //获取所有赛事赔率乘积
+            $odds = array_product($odds_all) - 1;
+            //获取可赢金额
+            $prize_money =  sprintf("%.2f",substr(sprintf("%.3f", $bet_amount*$odds), 0, -1));//floor($bet_amount*$odds*100)/100;//保留两位小数
+        }
+
+        if($sonNum < $allNum and (int)$after ==1){//例:N场赛事 <N串一
+            //计算 组合赔率
+            $group = commonFunction::combination($odds_all, $sonNum);
+
+            foreach ($group as $k=>$v){
+                $odds[] = array_product($v);
+            }
+            $odds = (array_sum($odds))-(count($odds));
+
+            //获取可赢金额
+            $prize_money =  sprintf("%.2f",substr(sprintf("%.3f", $bet_amount*$odds), 0, -1));//floor($bet_amount*$odds*100)/100;
+        }
+
+        return $prize_money;
+    }
+
+     /**
+     * 计算串式投注 倍率
+     * $groupNum 总赛事 数量
+     * $sonNum 当前串式 数量
+     */
+    public function getMultiple($groupNum = 0,$sonNum = 0){
+
+        if($groupNum and $sonNum){
+            $group =1;
+            for($i = $groupNum ; $i >($groupNum - $sonNum);$i--) {
+                $group = $group * $i;
+            }
+
+            $son =1;
+            for($i = $sonNum ; $i >0;$i--) {
+                $son = $son * $i;
+            }
+        }
+        return $group/$son;
+    }
 }