Browse Source

追加推送

彭俊 6 years ago
parent
commit
8dfc1d1fe9
34 changed files with 2336 additions and 168 deletions
  1. 223 117
      Application/Api/Controller/BetOrder.php
  2. 16 0
      Application/Api/Model/MoneyBuyDetail.php
  3. 16 0
      Application/Api/Model/MoneyBuyMatch.php
  4. 16 0
      Application/Api/Model/MoneyBuySimplex.php
  5. 15 0
      Application/Commons/Model/Comendnotice.php
  6. 21 0
      Application/Commons/Model/Money_buy_detail.php
  7. 44 0
      Application/Commons/Model/Money_buy_match.php
  8. 14 0
      Application/Commons/Model/Money_buy_str.php
  9. 16 0
      Application/Commons/Model/St_bq_competition.php
  10. 15 0
      Application/Commons/Model/St_bq_result.php
  11. 15 0
      Application/Commons/Model/St_bq_result_record.php
  12. 15 0
      Application/Commons/Model/St_lq_competition.php
  13. 15 0
      Application/Commons/Model/St_lq_result.php
  14. 15 0
      Application/Commons/Model/St_lq_result_record.php
  15. 15 0
      Application/Commons/Model/St_wq_competition.php
  16. 15 0
      Application/Commons/Model/St_wq_result.php
  17. 15 0
      Application/Commons/Model/St_wq_result_record.php
  18. 15 0
      Application/Commons/Model/St_zq_competition.php
  19. 15 0
      Application/Commons/Model/St_zq_result.php
  20. 15 0
      Application/Commons/Model/St_zq_result_record.php
  21. 18 14
      Application/Sports/Controller/Head.php
  22. 41 15
      Application/Sports/Controller/MatchList.php
  23. 11 8
      Application/Sports/Controller/RollingBall.php
  24. 1012 0
      Biz/Common/CommonFunction.php
  25. 1 0
      Biz/Game/TranferMoneyLogic.php
  26. 13 1
      Biz/Match/GetOddsData.php
  27. 15 13
      Biz/Match/GetmatchData.php
  28. 14 0
      Biz/Settlement/Adapter/BqRule.php
  29. 14 0
      Biz/Settlement/Adapter/LqRule.php
  30. 15 0
      Biz/Settlement/Adapter/WqRule.php
  31. 40 0
      Biz/Settlement/Adapter/ZqRule.php
  32. 295 0
      Biz/Settlement/SettlementBase.php
  33. 297 0
      Biz/Settlement/SettlementSql.php
  34. 4 0
      Config/Services.php

+ 223 - 117
Application/Api/Controller/BetOrder.php

@@ -18,6 +18,8 @@ class Betorder extends BaseController{
         $this->MC = new Moneycopy();
         $this->M = new Money();
         $this->accountManager = new AccountManager();
+        $this->commonFunction =  C()->get('commonFunction');
+
     }
     /**
      * 单式串式分类
@@ -29,6 +31,76 @@ class Betorder extends BaseController{
         if(empty($res)){
             Render('', '7003',lang('Errors','Api')->get('error-7003'));
         }
+//        $res = [
+//            [
+//                "type" => 1,
+//                'index' => 0,
+//                'bet_amount'=> 2000
+//            ],
+//            [
+//                "type" => 1,
+//                'index' => 1,
+//                'bet_amount'=> 2000
+//            ],
+//            [
+//                "type" => 1,
+//                'index' => 2,
+//                'bet_amount'=> 2000
+//            ],
+//            [
+//                'type' => '3串1',
+//                'odds' => 16.299205,
+//                'bet_amount' =>'bet_amount'
+//            ],
+//            [
+//                [
+//                    'id'=>656437,
+//                    'home_team' => "阿尔艾利开罗",
+//                    'guest_team' => '金字塔',
+//                    'name' => '阿尔艾利开罗',
+//                    'odds' => 0.31,
+//                    'p_code' => 'concede_size',
+//                    'ballId' => 'zq',
+//                    'odds_code' => 'concede_size',
+//                    'match_id' => 313238,
+//                    'condition' => '+0/0.5',
+//                    'ganame' => 'concede_size',
+//                    'bettingTime' => '',
+//                    'odds_only' => '1dee7e98db303852227cf1e0d8085dfb1555617310.3833947',
+//                    'type' => 1
+//                ],
+//                [
+//                    'id'=>656437,
+//                    'home_team' => "阿尔艾利开罗",
+//                    'guest_team' => '金字塔',
+//                    'name' => '阿尔艾利开罗',
+//                    'odds' => 0.31,
+//                    'p_code' => 'concede_size',
+//                    'ballId' => 'zq',
+//                    'match_id' => 3132384,
+//                    'condition' => '+0/0.5',
+//                    'ganame' => 'concede_size',
+//                    'bettingTime' => '',
+//                    'odds_only' => '1dee7e98db303852227cf1e0d8085dfb1555617310.3833947',
+//                    'type' => 1
+//                ],
+//                [
+//                    'id'=>656431,
+//                    'home_team' => "阿尔艾利开罗",
+//                    'guest_team' => '金字塔',
+//                    'name' => '阿尔艾利开罗',
+//                    'odds' => 0.31,
+//                    'p_code' => 'concede_size',
+//                    'ballId' => 'zq',
+//                    'match_id' => 3132384,
+//                    'condition' => '+0/0.5',
+//                    'ganame' => 'concede_size',
+//                    'bettingTime' => '',
+//                    'odds_only' => '1dee7e98db303852227cf1e0d8085dfb1555617310.3833947',
+//                    'type' => 1
+//                ],
+//            ]
+//        ];
         $data['single'] = [];//单式
         $data['bunch'] = [];//串式
         $last[] = $res[count($res)-1];
@@ -40,10 +112,9 @@ class Betorder extends BaseController{
                 //验证球类代码是否有效
                 $this->verify_gameType($vv['ballId'],$kk+1);
                 //验证赛事下赔率玩法是否有效
-//                $this->verify_odds($vv['ballId'],$vv['id'],$vv['odds_only'],$vv['odds'],$vv['condition'],$kk+1);
+//                $this->verify_odds($vv['ballId'],$vv['record_id'],$vv['odds'],$vv['condition'],$kk+1);
             }
         }
-
         foreach($res as $k => $v){
             //根据类型分组
             if($v['type'] == '1'){
@@ -79,92 +150,106 @@ class Betorder extends BaseController{
         return $data;
     }
 
+    /**
+     * 单式投注数据处理
+     * @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){
+            $gamedate = $this->Group_ball($res[$k]);
+            $this->Simplex_bet_insert($gamedate,$userInfo,$k,$batch_id);
+        }
+    }
+
     /**
      * 单式投注单个球类数据插入
      * @param  [array] $data 单式投注数据
      * @param  [array] $userInfo 用户信息
      * @param  [type] $game_code 球类代码
+     * @param  [int]  $batch_id 批量ID
      * @return  [int] 1 成功 其他失败
      */
-    public function Simplex_bet_insert($data,$userInfo,$game_code,$OrderID,$UUID){
-        if(empty($data)||empty($userInfo)||empty($game_code)||empty($OrderID)||empty($UUID)){
+    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'));
         }
-        $money = 0; //总投注额
         foreach($data as $k => $v){
-            $bet_money = 0; //单个球类单条总投注金额
+            $OrderID = OrderID();//生成订单ID
+            $UUID = UUID(); //生成信息ID
+            $bet_money = 0; //赛事总投注额
             $prize_money = 0; //可赢额
-            //统计该球类投注总额
             foreach($v as $kk => $vv){
                 $bet_money += $vv['bet_amount'];
-                $prize_money += ($vv['odds']-1)*$bet_money;
-                $money += $vv['bet_amount'];
+                $prize_money += ($vv['odds']-1) * $vv['bet_amount'] - $vv['bet_amount'];
+                $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' => date('Y-m-d H:i:s',time()),
+                    'utime' => date('Y-m-d H:i:s',time())
+                ];
+                //插入数据源
+                $moneyBuyMatch = lm('MoneyBuyMatch','Api')->insert($matchData);
+                if(!$moneyBuyMatch){
+                    Render('','-1005',lang('errors','Api')->get('error-3205'));
+                }
             }
             $order =[
                 'info_identity' => $UUID,
                 'account_name' => $userInfo['account'],
                 'account_identity' => $userInfo['account_identity'],
                 'order_id' => $OrderID,
-                'game_name' => $game_code,
-                'game_no'  => "",
+                'game_code' => $game_code,
+                'batch_id' => $batch_id,
                 'match_id' => $k,
+                'game_no'  => "",
                 'prize_money'=> $prize_money,
                 'money' => $bet_money, //投注金额
-                'codes' => json_encode($v,true), //投注信息json
-                'money_time' => $this->time,
+                'money_time' => $this->time
             ];
-            $insert = lm('MoneyBuy','Api')->insert($order);
+            $insert = lm("MoneyBuySimplex",'Api')->insert($order);
             if(!$insert){
                 Render('','-1005',lang('errors','Api')->get('error-3205'));
             }
-        }
-        $insertMoney  = $this->M->insertMoney($userInfo['account_identity'],$money,$OrderID,1,"",$UUID,$userInfo);
-        if($insertMoney!=1){
-            Render('', $insertMoney,lang('Errors','Api')->get('error'.$insertMoney));
-        }
-    }
-    /**
-     * 单式投注数据处理
-     * @param  [array] $res 单式投注数据
-     * @return  [int] 1 成功 其他失败
-     *
-     */
-    public function Simplex_bet(array $res,array $userInfo){
-        if(empty($res)||empty($userInfo)){
-            Render('', '7003',lang('Errors','Api')->get('error-7003'));
-        }
-        //验证与判断投注了几种
-        foreach($res as $k => $v){
-            $num = $k + 1;
-//            $this->verify_match($v['ballId'],$v['match_id'],$num);
-////            $this->verify_odds($v['ballId'],$v['odds_id'],$v['odds_only'],$v['odds'],$v['condition'],$num);
-            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]);
+            $insertMoney  = $this->M->insertMoney($userInfo['account_identity'],$bet_money,$OrderID,1,"",$UUID,$userInfo);
+            if($insertMoney!=1){
+                Render('', $insertMoney,lang('Errors','Api')->get('error'.$insertMoney));
             }
         }
-        $OrderID = OrderID();//生成订单ID
-        $UUID = UUID(); //生成信息ID
-        //球类联赛分类并且插入数据库
-        $zq = $this->Group_ball($res['zq']);
-        if(!empty($zq)) $this->Simplex_bet_insert($zq,$userInfo,'zq',$OrderID,$UUID);
-
-        $lq = $this->Group_ball($res['lq']);
-        if(!empty($lq)) $this->Simplex_bet_insert($zq,$userInfo,'lq',$OrderID,$UUID);
-
-        $bq = $this->Group_ball($res['bq']);
-        if(!empty($bq)) $this->Simplex_bet_insert($zq,$userInfo,'bq',$OrderID,$UUID);
-
-        $wq = $this->Group_ball($res['wq']);
-        if(!empty($wq)) $this->Simplex_bet_insert($zq,$userInfo,'wq',$OrderID,$UUID);
     }
 
     public function Bet(){
@@ -178,18 +263,18 @@ class Betorder extends BaseController{
         if(!$this->M->verifyMoney($bet_money,$userInfo['cash'])){
             Render('', '4204',lang('Errors','Api')->get('error-4204'));
         }
-//assAss
+        $batch_id = strtotime(date('Y-m-d H:i:s',time())).mt_rand('1','99');//批量ID
         //执行数据插入
         try {
             _beginTransaction();//开启事务
             $data = $this->Classify($data);
             if(!empty($data['single'])){
-                $this->Simplex_bet($data['single'],$userInfo);//单式数据处理
+                $this->Simplex_bet($data['single'],$userInfo,$batch_id);//单式数据处理
             }
             if(!empty($data['bunch'])){
                 $data_all = $data['bunch'][count($data['bunch'])-1];//获取最后一个数组
                 unset($data['bunch'][count($data['bunch'])-1]);//删除最后一个元素
-                $this->stringBet($data['bunch'],$data_all,$userInfo);
+                $this->stringBet($data['bunch'],$data_all,$userInfo,$batch_id);
             }
             _commit();//提交
             Render('', '1',lang('Errors','Api')->get('error-1'));
@@ -224,7 +309,7 @@ class Betorder extends BaseController{
                 Render([], '5109',$msg);
         }
         //根据球类代码 获取相关model
-        $models = getModels($game_code);
+        $models = $this->commonFunction->getModels($game_code);
         $model_match = $models['model_match'];
         $info = lm($model_match,'Sports')
             ->select('status')
@@ -262,35 +347,31 @@ class Betorder extends BaseController{
      * @param  [type] $game_code 球类代码
      *  @param  [type] $odds_id 赔率IDkk
      */
-    public function verify_odds($game_code,$odds_id,$odds_only,$odds,$condition,$num = 1){
-        if(empty($odds_id)||empty($odds_only)||empty($condition)||empty($odds)){
+    public function verify_odds($game_code,$record_id,$odds,$condition,$num = 1){
+        if(empty($record_id)||empty($condition)||empty($odds)){
             $msg = '第'.$num.'条数据'.lang('Errors','Api')->get('error-7029');
             Render([], '7029', $msg);
         }
-
         //根据球类代码 获取相关model
-        $models = getModels($game_code);
+        $models = $this->commonFunction->getModels($game_code);
         $model_odds = $models['model_odds'];
         $model_odds_record = $models['model_odds_record'];
+
         $odds_info = lm($model_odds,'Sports')
-            ->select('odds','condition')
-            ->where('id',$odds_id)
-            ->first();
-        $odds_record = lm($model_odds_record,'Sports')
-            ->select('odds','condition')
-            ->where('odds_only',$odds_only)
+            ->join($model_odds_record,$model_odds_record.'.id',$model_odds.'.record_id')
+            ->select($model_odds_record.'.odds',$model_odds_record.'.condition')
+            ->where($model_odds.'.record_id',$record_id)
             ->first();
-        if(empty($odds_info)||empty($odds_record)){
+        if(empty($odds_info)){
             $msg = '第'.$num.'条数据'.lang('Errors','Api')->get('error-7029');
             Render([], '70291', $msg);
         }
         $odds_info = $odds_info->toarray();
-        $odds_record = $odds_record->toarray();
-        if($odds != $odds_info['odds']||$odds != $odds_record['odds']){
+        if($odds != $odds_info['odds']){
             $msg = '第'.$num.'条数据'.lang('Errors','Api')->get('error-7029');
             Render([], '70292', $msg);
         }
-        if($condition = $odds_info['condition']||$condition = $odds_record['condition']){
+        if($condition = $odds_info['condition']){
             $msg = '第'.$num.'条数据'.lang('Errors','Api')->get('error-7029');
             Render([], '70293', $msg);
         }
@@ -302,8 +383,9 @@ class Betorder extends BaseController{
      * $data_str 各串式 数据
      * $data_all 所有赛事 数据
      * $userInfo 用户数据
+     * $batch_id 批次号
      */
-    public function stringBet($data_str=[],$data_all=[],$userInfo=[]){
+    public function stringBet($data_str=[],$data_all=[],$userInfo=[],$batch_id=23456){
 //        $userInfo = $this->getAgent();
 //        dd($userInfo);
 //        //所有串式数据
@@ -329,14 +411,15 @@ class Betorder extends BaseController{
 //                'bet_amount'=> 1,
 //            ],
 //        ];
-//
+////
 //        $data_all = [
+//
 //            [
 //                'id' => 887529,
 //                'home_team' => '阿尔艾利开罗',
 //                'guest_team' => '金字塔',
 //                'name' => '阿尔艾利开罗',
-//                'odds' => '2.02',
+//                'odds' => '3.02',
 //                'p_code' => 'concede_size',
 //                'ballId' => 'zq',
 //                'match_id' => 3129809,
@@ -351,7 +434,7 @@ class Betorder extends BaseController{
 //                'home_team' => '阿尔艾利开罗',
 //                'guest_team' => '金字塔',
 //                'name' => '阿尔艾利开罗',
-//                'odds' => '1.84',
+//                'odds' => '2.84',
 //                'p_code' => 'concede_size',
 //                'ballId' => 'zq',
 //                'match_id' => 3124863,
@@ -365,7 +448,7 @@ class Betorder extends BaseController{
 //                'home_team' => '阿尔艾利开罗',
 //                'guest_team' => '金字塔',
 //                'name' => '阿尔艾利开罗',
-//                'odds' => '2.01',
+//                'odds' => '3.01',
 //                'p_code' => 'concede_size',
 //                'ballId' => 'zq',
 //                'match_id' => 3133254,
@@ -379,7 +462,7 @@ class Betorder extends BaseController{
 //                'home_team' => '阿尔艾利开罗',
 //                'guest_team' => '金字塔',
 //                'name' => '阿尔艾利开罗',
-//                'odds' => '1.94',
+//                'odds' => '2.94',
 //                'p_code' => 'concede_size',
 //                'ballId' => 'zq',
 //                'match_id' => 3127596,
@@ -391,22 +474,12 @@ class Betorder extends BaseController{
 //            ]
 //        ];
 
-        if(empty($data_all)){
-            Render($data_all, '1', lang('Tips','Sports')->get('success'));
-        }
-
         //验证串式投注是否合法
         $this->verify_stringType($data_all);
-
-        //写入串式投注 所有数据 json_encode($oddsData,true)
-        $bet_ttr_id = lm('BetStr','Api')->insertGetId(['bet_str_all'=>json_encode($data_all,true)]);
-        if($bet_ttr_id < 1) Render([], '50039',lang('Errors','Api')->get('error-50039'));
         //获取串式 总赛事数量
         $groupNum = count($data_all);//总数量
 
         $orderData = [];
-        $orderID = OrderID();
-        $all_money=[];//所有投注金额
         foreach ($data_str as $k=>$v){
             //字符串替换
             $str = str_ireplace("串","_",$v['type']);
@@ -429,32 +502,65 @@ class Betorder extends BaseController{
             }
             //投注金额
             $moneyData = $money_all['moneyData'];
-            //所有投注金额
-            $all_money[] = $moneyData;
             //可赢金额
             $prize_money = $money_all['prize_money'];
-
             $uuid = UUID();
-            $orderData['game_name'] = $v['type'];
-            $orderData['info_identity'] = $uuid;
-            $orderData['account_name'] = $userInfo['account'];
-            $orderData['account_identity'] = $userInfo['account_identity'];
-            $orderData['order_id'] = $orderID;
-            $orderData['game_no'] = "";
-            $orderData['money'] = $moneyData;
-            $orderData['bet_str_id'] = $bet_ttr_id;//投注数据
-            $orderData['money_time'] = $this->time;//下注时间
-            $orderData['prize_money'] = $prize_money;//可赢金额
-
-            $ret = lm('MoneyBuyStr','Api')->insert($orderData);
-
-            if(!$ret){
-                Render('','-1005',lang('errors','Api')->get('error-3205'));
+            $orderID = OrderID();
+
+            $orderData[$k]['info_identity'] = $uuid;
+            $orderData[$k]['account_name'] = $userInfo['account'];
+            $orderData[$k]['account_identity'] = $userInfo['account_identity'];
+            $orderData[$k]['order_id'] = $orderID;
+            $orderData[$k]['game_no'] = "";
+            $orderData[$k]['money'] = $moneyData;//$pay_money//总投注金额
+            $orderData[$k]['money_time'] = $this->time;//下注时间
+            $orderData[$k]['prize_money'] = $prize_money;//$expect_money ;//预期总可赢金额
+            $orderData[$k]['str_type'] = $v['type'];//串式类型
+            $orderData[$k]['batch_id'] = $batch_id;//批次号
+            $orderData[$k]['wait_match_num'] = count($data_all);//批次号
+
+            //写资金变动表
+            $insertMoney  = $this->M->insertMoney($userInfo['account_identity'],$moneyData,$orderID,1,"",$uuid,$userInfo);
+            if($insertMoney!=1){
+                Render('', $insertMoney,lang('Errors','Api')->get('error'.$insertMoney));
             }
+
+        }
+
+        //写注单 表
+        $moneyBuy = lm('MoneyBuyStr','Api')->insert($orderData);
+
+        if(!$moneyBuy){
+            Render('','-1005',lang('errors','Api')->get('error-3205'));
+        }
+
+
+        foreach ($data_all as $kk=>$vv){
+            $getModels = $this->commonFunction->getModels($vv['ballId']);
+            $model_match = $getModels['model_match'];
+
+            $matchData[] = [
+                'batch_id'=>$batch_id,
+                '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'],
+                'status'=>0,
+                'match_id'=>$vv['match_id'],
+                'game_code'=>$vv['ballId'],
+                'lg_id'=>lm($model_match,"Sports")->select('lg_id')->where('match_id',$vv['match_id'])->first()->lg_id,
+                'ctime'=>$this->time,//写入时间
+                'bet_type'=>2
+            ];
         }
-        $insertMoney  = $this->M->insertMoney($userInfo['account_identity'],array_sum($all_money),$orderID,1,"",$uuid,$userInfo);
-        if($insertMoney!=1){
-            Render('', $insertMoney,lang('Errors','Api')->get('error'.$insertMoney));
+        //写赔率数据表
+        $moneyBuyMatch = lm('MoneyBuyMatch','Api')->insert($matchData);
+        if(!$moneyBuyMatch){
+            Render('','-1005',lang('errors','Api')->get('error-3205'));
         }
 
         return true;
@@ -505,7 +611,7 @@ class Betorder extends BaseController{
         }
 
         if($sonNum < $allNum and (int)$after ==1){//例:N场赛事 <N串一
-            $group = combination($odds_all, $sonNum);
+            $group = $this->commonFunction->combination($odds_all, $sonNum);
 
             foreach ($group as $k=>$v){
                 $odds[] = array_product($v);
@@ -570,7 +676,7 @@ class Betorder extends BaseController{
         $data = $_REQUEST;
 //        $data = [['game_code'=>'zq','match_id'=>3095448,'odds_id'=>623078],['game_code'=>'zq','match_id'=>3095448,'odds_id'=>623078]];
         foreach ($data as $k=>$v){
-            $getModels = getModels($v['game_code']);
+            $getModels = $this->commonFunction->getModels($v['game_code']);
             $model_match = $getModels['model_match'];
             $model_odds = $getModels['model_odds'];
 

+ 16 - 0
Application/Api/Model/MoneyBuyDetail.php

@@ -0,0 +1,16 @@
+<?php
+/**
+ *------Create thems Model------
+ *------SCWPHP  Version 1.0.0------
+ *------Dev Model Jions------
+ *------Create Time 2017-06-12 05:08:18------
+ */
+namespace App\Api\Model;
+
+use \System\Model;
+use Biz\Account\AccountManager;
+
+class MoneyBuyDetail extends Model {
+
+    protected $table = 'money_buy_detail';
+}

+ 16 - 0
Application/Api/Model/MoneyBuyMatch.php

@@ -0,0 +1,16 @@
+<?php
+/**
+ *------Create thems Model------
+ *------SCWPHP  Version 1.0.0------
+ *------Dev Model Jions------
+ *------Create Time 2017-06-12 05:08:18------
+ */
+namespace App\Api\Model;
+
+use \System\Model;
+use Biz\Account\AccountManager;
+
+class MoneyBuyMatch extends Model {
+
+    protected $table = 'money_buy_match';
+}

+ 16 - 0
Application/Api/Model/MoneyBuySimplex.php

@@ -0,0 +1,16 @@
+<?php
+/**
+ *------Create thems Model------
+ *------SCWPHP  Version 1.0.0------
+ *------Dev Model Jions------
+ *------Create Time 2017-06-12 05:08:18------
+ */
+namespace App\Api\Model;
+
+use \System\Model;
+use Biz\Account\AccountManager;
+
+class MoneyBuySimplex extends Model {
+
+    protected $table = 'money_buy_simplex';
+}

+ 15 - 0
Application/Commons/Model/Comendnotice.php

@@ -0,0 +1,15 @@
+<?php
+/**
+*------Create thems Model------
+*------SCWPHP  Version 1.0.0------
+*------Dev Model Jions------
+*------Create Time 2017-06-13 18:45:24------
+*/
+namespace App\Commons\Model;
+use \System\Model;
+class Comendnotice extends Model {
+
+    protected $table = 'comendnotice';
+
+
+}

+ 21 - 0
Application/Commons/Model/Money_buy_detail.php

@@ -0,0 +1,21 @@
+<?php
+/**
+*------Create thems Model------
+*------SCWPHP  Version 1.0.0------
+*------Dev Model Jions------
+*------Create Time 2017-06-13 18:45:24------
+*/
+namespace App\Commons\Model;
+use \System\Model;
+class Money_buy_detail extends Model {
+
+    protected $table = 'money_buy_detail';
+
+    public function  getById($id){
+        return  self::get($id);
+    }
+
+
+
+
+}

+ 44 - 0
Application/Commons/Model/Money_buy_match.php

@@ -0,0 +1,44 @@
+<?php
+/**
+*------Create thems Model------
+*------SCWPHP  Version 1.0.0------
+*------Dev Model Jions------
+*------Create Time 2017-06-13 18:45:24------
+*/
+namespace App\Commons\Model;
+
+use \System\Model;
+
+class Money_buy_match extends Model {
+
+    protected $table = 'money_buy_match';
+
+    public function  getByDetail($Detailid){
+            $ret = $this->where('money_buy_detail_id' ,$Detailid)->find();
+            return $ret;
+    }
+
+    public  function  getByTypeMatch($type,$matchId){
+          $rets = $this->where(['game_code'=>$type,'match_id'=>$matchId])->find();
+          return $rets;
+    }
+
+    //查找某个订单下是否还有未处理完的订单情况
+    public function    FindByTypeOrderResult($type,$OrderId,$result=0){
+            if (is_string($result)){
+                $ret = $this->where(['game_code'=>$type,'order_id'=>$OrderId,'result'=>$result])->find();
+            }else{
+                $ret = $this->where(['game_code'=>$type,'order_id'=>$OrderId])->whereIn('result',$result)->find();
+            }
+            return $ret;
+    }
+
+    public function  getByBatchId($batch_id){
+            $ret = $this->where('batch_id',$batch_id)->find();
+            return $ret;
+    }
+
+
+
+
+}

+ 14 - 0
Application/Commons/Model/Money_buy_str.php

@@ -57,4 +57,18 @@ class Money_buy_str extends Model {
 
         return $result;
     }
+
+    /**
+     *
+     * @access public
+     * @param mixed $batch_id 批次ID
+     * @return array JsonString
+     *
+     * */
+     public  function   getByBatchId($batch_id){
+         $result = $this->where(['batch_id',$batch_id])->get();
+         return $result ;
+     }
+
+
 }

+ 16 - 0
Application/Commons/Model/St_bq_competition.php

@@ -0,0 +1,16 @@
+<?php
+/**
+*------Create thems Model------
+*------SCWPHP  Version 1.0.0------
+*------Dev Model Jions------
+*------Create Time 2017-06-13 18:45:24------
+*/
+namespace App\Commons\Model;
+use \System\Model;
+class St_bq_competition extends Model {
+
+    protected $table = 'st_bq_competition';
+
+
+
+}

+ 15 - 0
Application/Commons/Model/St_bq_result.php

@@ -0,0 +1,15 @@
+<?php
+/**
+*------Create thems Model------
+*------SCWPHP  Version 1.0.0------
+*------Dev Model Jions------
+*------Create Time 2017-06-13 18:45:24------
+*/
+namespace App\Commons\Model;
+use \System\Model;
+class St_bq_result extends Model {
+
+    protected $table = 'st_bq_result';
+
+
+}

+ 15 - 0
Application/Commons/Model/St_bq_result_record.php

@@ -0,0 +1,15 @@
+<?php
+/**
+*------Create thems Model------
+*------SCWPHP  Version 1.0.0------
+*------Dev Model Jions------
+*------Create Time 2017-06-13 18:45:24------
+*/
+namespace App\Commons\Model;
+use \System\Model;
+class St_bq_result_record extends Model {
+
+    protected $table = 'st_bq_result_record';
+
+
+}

+ 15 - 0
Application/Commons/Model/St_lq_competition.php

@@ -0,0 +1,15 @@
+<?php
+/**
+*------Create thems Model------
+*------SCWPHP  Version 1.0.0------
+*------Dev Model Jions------
+*------Create Time 2017-06-13 18:45:24------
+*/
+namespace App\Commons\Model;
+use \System\Model;
+class St_lq_competition extends Model {
+
+    protected $table = 'st_lq_competition';
+
+
+}

+ 15 - 0
Application/Commons/Model/St_lq_result.php

@@ -0,0 +1,15 @@
+<?php
+/**
+*------Create thems Model------
+*------SCWPHP  Version 1.0.0------
+*------Dev Model Jions------
+*------Create Time 2017-06-13 18:45:24------
+*/
+namespace App\Commons\Model;
+use \System\Model;
+class St_lq_result extends Model {
+
+    protected $table = 'st_lq_result';
+
+
+}

+ 15 - 0
Application/Commons/Model/St_lq_result_record.php

@@ -0,0 +1,15 @@
+<?php
+/**
+*------Create thems Model------
+*------SCWPHP  Version 1.0.0------
+*------Dev Model Jions------
+*------Create Time 2017-06-13 18:45:24------
+*/
+namespace App\Commons\Model;
+use \System\Model;
+class St_lq_result_record extends Model {
+
+    protected $table = 'st_lq_result_record';
+
+
+}

+ 15 - 0
Application/Commons/Model/St_wq_competition.php

@@ -0,0 +1,15 @@
+<?php
+/**
+*------Create thems Model------
+*------SCWPHP  Version 1.0.0------
+*------Dev Model Jions------
+*------Create Time 2017-06-13 18:45:24------
+*/
+namespace App\Commons\Model;
+use \System\Model;
+class St_wq_competition extends Model {
+
+    protected $table = 'st_wq_competition';
+
+
+}

+ 15 - 0
Application/Commons/Model/St_wq_result.php

@@ -0,0 +1,15 @@
+<?php
+/**
+*------Create thems Model------
+*------SCWPHP  Version 1.0.0------
+*------Dev Model Jions------
+*------Create Time 2017-06-13 18:45:24------
+*/
+namespace App\Commons\Model;
+use \System\Model;
+class St_wq_result extends Model {
+
+    protected $table = 'st_wq_result';
+
+
+}

+ 15 - 0
Application/Commons/Model/St_wq_result_record.php

@@ -0,0 +1,15 @@
+<?php
+/**
+*------Create thems Model------
+*------SCWPHP  Version 1.0.0------
+*------Dev Model Jions------
+*------Create Time 2017-06-13 18:45:24------
+*/
+namespace App\Commons\Model;
+use \System\Model;
+class St_wq_result_record extends Model {
+
+    protected $table = 'st_wq_result_record';
+
+
+}

+ 15 - 0
Application/Commons/Model/St_zq_competition.php

@@ -0,0 +1,15 @@
+<?php
+/**
+*------Create thems Model------
+*------SCWPHP  Version 1.0.0------
+*------Dev Model Jions------
+*------Create Time 2017-06-13 18:45:24------
+*/
+namespace App\Commons\Model;
+use \System\Model;
+class St_zq_competition extends Model {
+
+    protected $table = 'st_zq_competition';
+
+
+}

+ 15 - 0
Application/Commons/Model/St_zq_result.php

@@ -0,0 +1,15 @@
+<?php
+/**
+*------Create thems Model------
+*------SCWPHP  Version 1.0.0------
+*------Dev Model Jions------
+*------Create Time 2017-06-13 18:45:24------
+*/
+namespace App\Commons\Model;
+use \System\Model;
+class St_zq_result extends Model {
+
+    protected $table = 'st_zq_result';
+
+
+}

+ 15 - 0
Application/Commons/Model/St_zq_result_record.php

@@ -0,0 +1,15 @@
+<?php
+/**
+*------Create thems Model------
+*------SCWPHP  Version 1.0.0------
+*------Dev Model Jions------
+*------Create Time 2017-06-13 18:45:24------
+*/
+namespace App\Commons\Model;
+use \System\Model;
+class St_zq_result_record extends Model {
+
+    protected $table = 'st_zq_result_record';
+
+
+}

+ 18 - 14
Application/Sports/Controller/Head.php

@@ -10,6 +10,10 @@ use BaseController\Controller;
  * Date: 2019/3/19
  */
 class Head extends Controller{
+    public function init() {
+        $this->commonFunction =  C()->get('commonFunction');
+
+    }
 
     /**
      * 首页头部类别列表 弃用
@@ -23,11 +27,11 @@ class Head extends Controller{
         $data = [];
         foreach ($type as $key =>$item){
             $matchNum = [];
-            $where = getState($item['type_code']);
+            $where = $this->commonFunction->getState($item['type_code']);
             foreach ($ret as $key1 => $item1){
                 if($item1['game_code'] != 'gj'){
                     //根据球类代码 获取相关model
-                    $models = getModels($item1['game_code'],0);
+                    $models = $this->commonFunction->getModels($item1['game_code'],0);
                     $model_match = $models['model_match'];
 
                     $matchNum[$key1][] = lm($model_match, 'Sports')
@@ -65,11 +69,11 @@ class Head extends Controller{
                 case 'StRollBall'://滚球
                     foreach ($ret as $key1 => $item1){
                         //根据球类代码 获取相关model
-                        $models = getModels($item1['game_code'],1);
+                        $models = $this->commonFunction->getModels($item1['game_code'],1);
                         $model_match = $models['model_match'];
                         $model_result = $models['model_result'];
                         $model_odds = $models['model_odds'];
-                        $where = getState($item['type_code'],$model_match);
+                        $where = $this->commonFunction->getState($item['type_code'],$model_match);
                         if($item1['game_code'] != 'gj'){
                             $matchNum[$key1][] = lm($model_match, 'Sports')
                                 ->join($model_result,$model_result.'.match_id',$model_match . '.match_id')
@@ -82,9 +86,9 @@ class Head extends Controller{
                 case 'StSoon'://即将
                     foreach ($ret as $key1 => $item1){
                         //根据球类代码 获取相关model
-                        $models = getModels($item1['game_code'],1);
+                        $models = $this->commonFunction->getModels($item1['game_code'],1);
                         $model_match = $models['model_match'];
-                        $where = getState($item['type_code'],$model_match);
+                        $where = $this->commonFunction->getState($item['type_code'],$model_match);
                         if($item1['game_code'] != 'gj'){
                             $matchNum[$key1][] = lm($model_match, 'Sports')
                                 ->where($model_match.'.source',$this->source['source'])
@@ -96,9 +100,9 @@ class Head extends Controller{
                 case 'StToday'://今日
                     foreach ($ret as $key1 => $item1){
                         //根据球类代码 获取相关model
-                        $models = getModels($item1['game_code'],1);
+                        $models = $this->commonFunction->getModels($item1['game_code'],1);
                         $model_match = $models['model_match'];
-                        $where = getState($item['type_code'],$model_match);
+                        $where = $this->commonFunction->getState($item['type_code'],$model_match);
                         if($item1['game_code'] != 'gj'){
                             $matchNum[$key1][] = lm($model_match, 'Sports')
                                 ->where($model_match.'.source',$this->source['source'])
@@ -110,9 +114,9 @@ class Head extends Controller{
                 case 'StMorningPlate'://早盘
                     foreach ($ret as $key1 => $item1){
                         //根据球类代码 获取相关model
-                        $models = getModels($item1['game_code'],1);
+                        $models = $this->commonFunction->getModels($item1['game_code'],1);
                         $model_match = $models['model_match'];
-                        $where = getState($item['type_code'],$model_match);
+                        $where = $this->commonFunction->getState($item['type_code'],$model_match);
                         if($item1['game_code'] != 'gj'){
                             $matchNum[$key1][] = lm($model_match, 'Sports')
                                 ->where($model_match.'.source',$this->source['source'])
@@ -124,9 +128,9 @@ class Head extends Controller{
                 case 'StStringScene'://串场
                     foreach ($ret as $key1 => $item1) {
                         //根据球类代码 获取相关model
-                        $models = getModels($item1['game_code'], 1);
+                        $models = $this->commonFunction->getModels($item1['game_code'], 1);
                         $model_match = $models['model_match'];
-                        $where = getState($item['type_code'], $model_match);
+                        $where = $this->commonFunction->getState($item['type_code'], $model_match);
                         if ($item1['game_code'] != 'gj') {
                             $matchNum[$key1][] = lm($model_match, 'Sports')
                                 ->where($model_match . '.source', $this->source['source'])
@@ -138,9 +142,9 @@ class Head extends Controller{
                 case 'StChampion'://冠军
                     foreach ($ret as $key1 => $item1) {
                         //根据球类代码 获取相关model
-                        $models = getModels($item1['game_code'], 1);
+                        $models = $this->commonFunction->getModels($item1['game_code'], 1);
                         $model_odds = $models['model_odds'];
-                        $where = getState($item['type_code']);
+                        $where = $this->commonFunction->getState($item['type_code']);
                         if ($item1['game_code'] != 'gj') {
                             $matchNum[$key1][] =count(lm($model_odds, 'Sports')
                                 ->select("match_id","type")

+ 41 - 15
Application/Sports/Controller/MatchList.php

@@ -19,6 +19,7 @@ class  MatchList extends Controller {
     public function init() {
         $this->getTypeData = new GetmatchData();
         $this->getOddsData = new GetOddsData();
+        $this->commonFunction =  C()->get('commonFunction');
 
     }
 
@@ -33,7 +34,7 @@ class  MatchList extends Controller {
          $data['info'][0]['code'] = 'today';
          $data['info'][0]['count'] = lm('st_zq_competition','Sports')
              ->join('st_zq_league','st_zq_league.lg_id','st_zq_competition.lg_id')
-             ->where(getState('StToday'))
+             ->where($this->commonFunction->getState('StToday'))
              ->where('st_zq_competition.source',$this->source['source'])
              ->distinct('st_zq_competition.match_id')
              ->count('*');
@@ -106,7 +107,7 @@ class  MatchList extends Controller {
      */
      private function qt_participate ($typeGame){
          //===查询该球类是否存在或启用===
-         $getModels = getModels($typeGame);
+         $getModels = $this->commonFunction->getModels($typeGame);
          $data['game_code'] = $typeGame;
          $data['type'] = lm('GameType','Sports')->where('game_code',$typeGame)->value('game_name');
          $st_competition = $getModels['model_match'];
@@ -121,7 +122,7 @@ class  MatchList extends Controller {
          $data['info'][1]['code'] = 'today';
          $data['info'][1]['count']=lm($st_competition,'Sports')
              ->where($st_competition.'.source',$this->source['source'])
-             ->where(getState('StToday',$st_competition))
+             ->where($this->commonFunction->getState('StToday',$st_competition))
              ->count('*');
         return $data;
     }
@@ -144,7 +145,7 @@ class  MatchList extends Controller {
         $code = $_REQUEST['code'];//参赛代码
         $search = $_REQUEST['search'];//参赛代码
         //===查询该球类是否存在或启用===
-        $getModels = getModels($game_code);
+        $getModels = $this->commonFunction->getModels($game_code);
         $st_league = $getModels['model_league'];
         $st_competition = $getModels['model_match'];
         $where_search = function($query)use ($st_competition,$search){
@@ -157,12 +158,12 @@ class  MatchList extends Controller {
         switch ($code)
         {
             case $code == 'today':
-                $where =  getState('StToday',$st_competition);
+                $where =  $this->commonFunction->getState('StToday',$st_competition);
                 //查询今日赛事
                 $data = lm($st_competition,'Sports')
                     ->join($st_league,$st_league.'.lg_id',$st_competition.'.lg_id')
                     ->select($st_league.'.name_chinese',$st_league.'.lg_id')
-                    ->where(getState('StToday',$st_competition))
+                    ->where($where)
                     ->where($where_search)
                     ->where($st_competition.'.source',$this->source['source'])
                     ->distinct($st_competition.'.match_id')
@@ -370,7 +371,7 @@ class  MatchList extends Controller {
         $search = $_REQUEST['search'];
         //===查询该球类是否存在或启用===
         $gameType = empty($gameType)? 'zq':$gameType;
-        $getModels = getModels($gameType);
+        $getModels = $this->commonFunction->getModels($gameType);
         $st_league = $getModels['model_league'];
         $st_competition = $getModels['model_match'];
         $data['type']  = lm('GameType', 'Sports')->where('game_code',$gameType)->value('game_name');
@@ -450,7 +451,7 @@ class  MatchList extends Controller {
         $date = $_REQUEST['datetime'];
         //===查询该球类是否存在或启用===
         $gameType = empty($gameType) ? 'zq':$gameType;
-        $getModels = getModels($gameType);
+        $getModels = $this->commonFunction->getModels($gameType);
         $st_league = $getModels['model_league'];
         $st_competition = $getModels['model_match'];
         //所属球类
@@ -460,7 +461,7 @@ class  MatchList extends Controller {
                 $where=[[$st_competition.'.is_morningplate',1],
                 [$st_competition.'.match_date','>',date("Y-m-d",strtotime("+6 day"))]];
             }else if($date == 'today'){
-                $where  = getState('StToday');
+                $where  = $this->commonFunction->getState('StToday');
             }else {
                 $where[$st_competition.'.match_date'] = $date;
             }
@@ -593,13 +594,13 @@ class  MatchList extends Controller {
             $game = lm('GameType', 'Sports')->where('status',1)->select('game_code','game_name','game_ico_url')->get()->toArray();
 
             //获取 不同状态的查询条件
-            $where = getState($type_code);
+            $where = $this->commonFunction->getState($type_code);
 
             $gameData = [];
 
             foreach ($game as $key=>$type){
                 if($type_code != 'StChampion'){
-                    $matchModel = getModels($type['game_code']);
+                    $matchModel = $this->commonFunction->getModels($type['game_code']);
                     $matchNum = lm($matchModel['model_match'], 'Sports')
                         ->where($this->source)
                         ->where($where)
@@ -609,7 +610,7 @@ class  MatchList extends Controller {
                         $gameData[] = $type;
                     }
                 }else{
-                    $matchModel = getModels($type['game_code']);
+                    $matchModel = $this->commonFunction->getModels($type['game_code']);
                     $matchNum = lm($matchModel['model_odds'], 'Sports')
                         ->where($this->source)
                         ->where($where)
@@ -666,7 +667,7 @@ class  MatchList extends Controller {
             }
 
             //根据球类代码 获取相关model
-            $models = getModels($game_code,0);
+            $models = $this->commonFunction->getModels($game_code,0);
             $model_match = $models['model_match'];
             $model_odds = $models['model_odds'];
             $model_league = $models['model_league'];
@@ -780,7 +781,7 @@ class  MatchList extends Controller {
 
             if(empty($match_date)) $match_date = date('Y-m-d');
             //根据球类代码 获取相关model
-            $models = getModels($game_code);
+            $models = $this->commonFunction->getModels($game_code);
             $model_match = $models['model_match'];
             $matchData = lm($model_match,'Sports')->select('match_id','status','match_date','match_time')->where(['match_date'=>$match_date])->get();
 
@@ -809,7 +810,7 @@ class  MatchList extends Controller {
         $source = $this->source;//数据源 条件
 
         try {
-            $where = getState('StSoon');
+            $where = $this->commonFunction->getState('StSoon');
 
             $data = $this->getTypeData->getAllSoon($source,$where);
 
@@ -849,4 +850,29 @@ class  MatchList extends Controller {
         Render($data, '1', lang('Tips','Sports')->get('success'));
 
     }
+
+    /**
+     * 更新赔率数据
+     */
+    public function updateOdds(){
+        $data = $_REQUEST;
+//        $data = ['game_code'=>'zq','match_id'=>3095448];
+
+        $getModels = $this->commonFunction->getModels($data['game_code']);
+            $model_match = $getModels['model_match'];
+            $model_odds = $getModels['model_odds'];
+
+            $where[] = [$model_match.'.match_id','=',$data['match_id']];
+
+            $oddsData = lm($model_match,"Sports")
+                ->join($model_odds,$model_odds.'.match_id',$model_match.'.match_id')
+                ->select($model_match.'.match_id',$model_match.'.match_date',$model_match.'.home_team',$model_match.'.guest_team',$model_odds.'.id as odds_id',$model_odds.'.p_code',$model_odds.'.odds_code',$model_odds.'.condition',$model_odds.'.odds',$model_odds.'.odds_only',$model_odds.'.status',$model_odds.'.sort')
+                ->where($model_match.'.source',$this->source)
+                ->where($where)
+//                ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
+                ->get()->toArray();
+
+        Render($oddsData, '1', lang('Tips','Sports')->get('success'));
+    }
+
 }

+ 11 - 8
Application/Sports/Controller/RollingBall.php

@@ -11,13 +11,16 @@ use BaseController\Controller;
 use \System\Model;
 
 class RollingBall extends Controller{
+    public function init() {
+        $this->commonFunction =  C()->get('commonFunction');
+    }
 
     /**
      * @throws \Exception
      * 首页足球滚球
      */
     public function zqrollingball(){
-        $models = getModels('zq',1);
+        $models = $this->commonFunction->getModels('zq',1);
 
         $model_result = $models['model_result'];
         $model_match = $models['model_match'];
@@ -31,7 +34,7 @@ class RollingBall extends Controller{
 //            ->get()->toArray();
 
         //获取 滚球查询条件
-        $where = getState('StRollBall',$model_match);
+        $where = $this->commonFunction->getState('StRollBall',$model_match);
 
         $result =lm($model_match,"Sports")
             ->leftjoin($model_result,$model_result.'.match_id',$model_match.'.match_id')
@@ -69,13 +72,13 @@ class RollingBall extends Controller{
      * 首页篮球滚球
      */
     public function lqrollingball(){
-        $models = getModels('lq',1);
+        $models = $this->commonFunction->getModels('lq',1);
 
         $model_result = $models['model_result'];
         $model_match = $models['model_match'];
 
         //获取 滚球查询条件
-        $where = getState('StRollBall',$model_match);
+        $where = $this->commonFunction->getState('StRollBall',$model_match);
         $result =lm($model_match,"Sports")
             ->leftjoin($model_result,$model_result.'.match_id',$model_match.'.match_id')
             ->select($model_match.'.match_id',$model_match.'.tag','match_date as start_date',$model_match.'.match_time as start_time',$model_match.'.home_team',$model_match.'.guest_team','home_score','guest_score',$model_result.'.match_time','match_process')
@@ -100,13 +103,13 @@ class RollingBall extends Controller{
     }
 
     public function wqrollingball(){
-        $models = getModels('wq',1);
+        $models = $this->commonFunction->getModels('wq',1);
 
         $model_result = $models['model_result'];
         $model_match = $models['model_match'];
 
         //获取 滚球查询条件
-        $where = getState('StRollBall',$model_match);
+        $where = $this->commonFunction->getState('StRollBall',$model_match);
         $result =lm($model_match,"Sports")
             ->leftjoin($model_result,$model_result.'.match_id',$model_match.'.match_id')
             ->select($model_match.'.match_id',$model_match.'.tag','match_date as start_date',$model_match.'.match_time as start_time','home_player_name','guest_player_name','first_inning_score','second_inning_score','third_inning_score',$model_result.'.match_time','match_process')
@@ -129,13 +132,13 @@ class RollingBall extends Controller{
     }
 
     public function bqrollingball(){
-        $models = getModels('bq',1);
+        $models = $this->commonFunction->getModels('bq',1);
 
         $model_result = $models['model_result'];
         $model_match = $models['model_match'];
 
         //获取 滚球查询条件
-        $where = getState('StRollBall',$model_match);
+        $where = $this->commonFunction->getState('StRollBall',$model_match);
         $result =lm($model_match,"Sports")
             ->leftjoin($model_result,$model_result.'.match_id',$model_match.'.match_id')
             ->select($model_match.'.match_id',$model_match.'.tag','match_date as start_date',$model_match.'.match_time as start_time',$model_match.'.home_team',$model_match.'.guest_team','home_score','guest_score',$model_result.'.match_time','match_process')

+ 1012 - 0
Biz/Common/CommonFunction.php

@@ -0,0 +1,1012 @@
+<?php
+namespace Biz\Common;
+
+class CommonFunction {
+    function checkDebug()
+    {
+        return (isset($_GET['debug']) && intval($_GET['debug'])==-99999) || APP_DEBUG==1?1:0;
+    }
+    function View($Path = "") {
+        if (!$Path) {
+            global $ViewPath;
+            $ViewPath = explode("\\", $ViewPath);
+            $ViewPath[3] = explode("Controller", $ViewPath[3]);
+            $ViewPath[3] = $ViewPath[3][0];
+            return APP_PATH . "/" . $ViewPath[1] . "/View/" . $ViewPath[3] . "/" . $ViewPath[4] . ".blade.php";
+        } else {
+            return APP_PATH . "/" . $Path . ".blade.php";
+        }
+    }
+
+    function arrayToOptions($data, $key, $val)
+    {
+        $options = array();
+        if (is_array($data) && count($data)) {
+            foreach ($data as $k => $value) {
+                $options[$value[$key]] = $value[$val];
+            }
+        }
+        return $options;
+    }
+
+
+
+    function M($TABLE_NAME = "") {
+        return new DB($TABLE_NAME);
+    }
+
+    function checkClose() {
+        if (file_exists(ROOT_PATH . '/Cache/system.lock')) {
+            if (is_mobile()) {
+                return appExec("Mobile", "Weihu", "index");
+            } else {
+                return appExec("home", "weihu", "index");
+            }
+        }
+    }
+    /**
+     * 发布消息
+     *
+     * @param integer $status
+     * @param string $msg
+     * @param string $data
+     * @return void
+     */
+    function publishNotify($channel, $status = 1, $data = '') {
+        // toLog('publishNotify-'.$channel.'+++'.$data);
+        C()->get('msg')->publish($channel, $data);
+    }
+    /**
+     * 数组分类排序
+     * @param [array] $columnsArr [需要进行排序的数组]
+     * @param [int] $plmid [所属分类ID]
+     */
+    function getColumns($columnsArr, $plmid) {
+        $menu = array();
+
+        foreach ($columnsArr as $v) {
+            if ($v['plmid'] == $plmid) {
+                $menu[] = $v;
+
+                $a = getColumns($columnsArr, $v['lmid']);
+                foreach ($a as $vv) {
+                    $menu[] = $vv;
+                }
+            }
+        }
+        return $menu;
+    }
+
+    /**
+     * 获取客户端真实IP
+     */
+    function GETIP() {
+        global $ip;
+
+        if (getenv("HTTP_CLIENT_IP")) {
+            $ip = getenv("HTTP_CLIENT_IP");
+        } else if (getenv("HTTP_X_FORWARDED_FOR")) {
+            $ip = getenv("HTTP_X_FORWARDED_FOR");
+        } else if (getenv("REMOTE_ADDR")) {
+            $ip = getenv("REMOTE_ADDR");
+        } else {
+            $ip = "Unknow";
+        }
+
+        return $ip;
+
+    }
+
+    function dump($data, $exit = 1) {
+        echo "<pre>";
+        print_r($data);
+        echo "</pre>";
+        if ($exit) {
+            exit;
+        }
+
+    }
+
+    function OrderID($prefix = '') {
+        $num = mt_rand(100, 999);
+        list($s, $m) = explode(' ', microtime());
+        $order = date("YmdHis") . ($s * 1000000) . $num;
+        return $prefix . $order;
+    }
+    /**
+     * 容器
+     */
+    function C() {
+        static $c = array();
+        if (!isset($c['container'])) {
+            $c['container'] = new \System\Di();
+        }
+        return $c['container'];
+    }
+
+    /**
+     * 全局变量快捷操作
+     * @param [type] $key   [description]
+     * @param [type] $value [description]
+     */
+    function S($key, $value = null) {
+        if ($value != null) {
+            $GLOBALS[$key] = $value;
+        }
+        if (isset($GLOBALS[$key])) {
+            return $GLOBALS[$key];
+        }
+    }
+    /**
+     * 载入模型
+     * @param  [type] $name [description]
+     * @param  string $proj [description]
+     * @return [type]       [description]
+     */
+    function lm($name, $proj = '') {
+        $proj = empty($proj) ? S('CUR_PROJECT') : $proj;
+        if (empty($proj)) {
+            throw new \Exception("项目{$proj}不存在", 1);
+        }
+        $cls = "\\App\\" . ucfirst($proj) . "\\Model\\" . ucfirst($name);
+        if(!class_exists($cls)){
+            return;
+        }
+        $key = 'model_' . $name . $proj;
+        C()->shared($key, $cls);
+        return C()->get($key);
+    }
+    /**
+     * 载入语言包
+     * @param  string $key  语言项
+     * @param  string $file 语言文件名
+     * @param  string $proj 项目名称
+     * @return [type]       [description]
+     */
+    function lang($file = '', $proj = '') {
+        $proj = empty($proj) ? S('CUR_PROJECT') : $proj;
+        $file = empty($file) ? S('CUR_CONTROLLER') : $file;
+        $ckey = "Lang_{$proj}_{$file}";
+        if (C()->has($ckey)) {
+            return C()->get($ckey);
+        } else {
+            C()->shared($ckey, function () use ($proj, $file) {
+                $file = ucfirst($file);
+                $proj = ucfirst($proj);
+                $lang = new \System\Lang();
+                $lang_files = array();
+                if (S('CUR_PROJECT') == $proj && S('CUR_CONTROLLER') == $file) {
+                    $lang_files[] = ROOT_PATH . "/Application/Commons/Lang/Common.php";
+                    $lang_files[] = ROOT_PATH . "/Application/{$proj}/Lang/Common.php";
+                }
+                $lang_files[] = ROOT_PATH . "/Application/{$proj}/Lang/{$file}.php";
+                $data = array();
+                foreach ($lang_files as $v) {
+                    if (file_exists($v)) {
+                        $data2 = include $v;
+                        if (is_array($data2)) {
+                            $data = array_merge($data, $data2);
+                        }
+                    }
+                }
+                $lang->load($data);
+                return $lang;
+            });
+            return C()->get($ckey);
+        }
+    }
+
+    /**
+     * 标签替换
+     *
+     * @param [type] $message
+     * @param array $data
+     * @param string $tag
+     * @return void
+     */
+    function parseTag($message,$data=array(),$tag='#'){
+        if(is_array($data) && count($data)>0){
+            foreach ($data as $k => $v) {
+                $message = str_replace($tag . $k . $tag, $v, $message);
+            }
+        }
+
+        return $message;
+    }
+
+    function appExec($proj, $ctrl, $method, $exec = 0) {
+        $proj = ucfirst($proj);
+        $ctrl = ucfirst($ctrl);
+        $method = ucfirst($method);
+        S('CUR_PROJECT', $proj);
+        S('CUR_CONTROLLER', $ctrl);
+        S('CUR_METHOD', $method);
+        checkPlatform();
+        toDomain();
+        //设置REMOTE_KEY
+        lm('setinfo','commons')->setKey();
+
+        $cls = "\\App\\{$proj}\\Controller\\{$ctrl}";
+        C()->set($ctrl, $cls);
+        $cls = C()->get($ctrl);
+        if (!$cls) {
+            exit("404 NOT FOUND");
+        }
+        if ($exec) {
+            $result = $cls->$method();
+            if (!empty($result)) {
+                Render($result);
+            }
+        }
+        if (method_exists($cls, $method)) {
+            $result = $cls->$method();
+            if (!empty($result)) {
+                Render($result);
+            }
+        } else {
+            exit("404 METHOD NOT FOUND");
+        }
+
+    }
+
+    /**
+     * UUID 生成
+     */
+    function UUID() {
+        $prefix = '';
+        $uuid = '';
+        $str = md5(uniqid(mt_rand(), true));
+        $uuid = substr($str, 0, 8) . '-';
+        $uuid .= substr($str, 8, 4) . '-';
+        $uuid .= substr($str, 12, 4) . '-';
+        $uuid .= substr($str, 16, 4) . '-';
+        $uuid .= substr($str, 20, 12);
+        return $prefix . $uuid;
+    }
+
+    /**
+     *密码加密码
+     */
+    function GenEncryption() {
+        srand((double) microtime() * 1000000); //create a random number feed.
+        $ychar = "0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z";
+        $list = explode(",", $ychar);
+        $authnum = "";
+        for ($i = 0; $i < 6; $i++) {
+            $randnum = rand(0, 61); // 10+26;
+            $authnum .= $list[$randnum];
+        }
+        return $authnum;
+    }
+
+//密码加密
+    function GenPassword($password) {
+        $Enc = GenEncryption();
+        $Pwd = md5(md5($Enc . $password));
+        return array("encryption" => $Enc, "password" => $Pwd);
+
+    }
+
+//密码验证
+    function VerPassword($identity, $password) {
+        $account = M("account_password")->where("account_identity = '$identity' and", "status = ", '1')->select("encryption,account_password")->find();
+        $VerPwd = md5(md5($account["encryption"] . $password));
+        if ($VerPwd == $account["account_password"]) {
+            unset($account);
+            unset($VerPwd);
+            return true;
+        } else {
+            unset($account);
+            unset($VerPwd);
+            return false;
+        }
+
+    }
+    /**
+     * Json return
+     * @param string $data   [description]
+     * @param string $status [description]
+     * @param string $msg    [description]
+     * @param string $method [description]
+     */
+    function JsonReturn($data = "", $status = "200", $msg = "", $method = "") {
+        // header("Content-type:application/json;charset:utf-8");
+        // header('content-type:text/html; charset=utf-8');
+        if(isset($_REQUEST['crossdomain']) && !empty($_REQUEST['crossdomain'])){
+            header("Access-Control-Allow-Origin:{$_REQUEST['crossdomain']}");
+        }else{
+            header("Access-Control-Allow-Origin:*");
+        }
+        header('Access-Control-Allow-Methods:POST,GET,PUT,DELETE,OPTIONS');
+        header('Access-Control-Allow-Credentials:true');
+        $retdata=array("status" => $status, "msg" => $msg, "data" =>$data);
+
+        $devicetype=isset($_REQUEST['devicetype'])?trim($_REQUEST['devicetype']):'';
+        if(!empty($devicetype) && in_array($devicetype,array('ios','android'))){
+            $path=S('CUR_PROJECT').'/'.S('CUR_CONTROLLER').'/'.	S('CUR_METHOD');
+            $retdata=C()->get($devicetype."Result")->update($path,$retdata);
+        }
+
+        if ($method == '') {
+            //dump($devicetype);
+            echo (json_encode($retdata,JSON_UNESCAPED_UNICODE));
+        } else {
+            echo ($method . "(" . json_encode($retdata,JSON_UNESCAPED_UNICODE) . ")");
+        }
+    }
+    function XmlReturn($data = "", $status = 200, $msg = '') {
+        // header("Content-type:text/xml;charset:utf-8");
+        $xml = '<?xml version="1.0" encoding="utf-8"?>';
+        $xml .= "<root>";
+        $xml .= '<status>' . $status . '</status>';
+        $xml .= '<msg>' . $msg . '</msg>';
+        $xml .= "<rows>";
+        $xml .= toXml($data);
+        $xml .= "</rows>";
+        $xml .= "</root>";
+        echo($xml);
+    }
+    function toXml($data) {
+        // print_r($data);
+        $xml = '';
+        if (is_array($data) && count($data) > 0) {
+            foreach ($data as $k => $v) {
+                $key = $k;
+                if (is_numeric($k)) {
+                    $key = 'data';
+                }
+                if (is_array($v)) {
+                    $xml .= "<{$key}>" . toXml($v) . "</{$key}>";
+                    continue;
+                }
+                if (is_string($v)) {
+                    $xml .= "<{$key}>{$v}</{$key}>";
+                }
+            }
+        }
+        return $xml;
+    }
+
+    function WriteLog($Log) {
+        $logger = new Logger('LOGGS');
+        $logURI = "Cache/log/" . date("Y-m-d-H-i") . ".log";
+        $logger->pushHandler(new StreamHandler($logURI, Logger::DEBUG));
+        $logger->pushHandler(new FirePHPHandler());
+        $logger->addInfo(var_export($Log,1));
+
+    }
+    /**
+     * 计算当前用时
+     *
+     * @param string $runName
+     * @param integer $return
+     * @return void
+     */
+    function computeTime($runName='',$return=0,$start=1){
+        $curTime= get_millisecond();
+        $numTime=$curTime-(intval($GLOBALS['startTime'])*1000);
+        if($return){
+            return array('curTime'=>$curTime,'numTime'=>$numTime,'runName'=>$runName);
+        }else{
+            echo "<pre>执行{$runName} 功能,当前时间为:{$curTime},累积用时: {$numTime}</pre>";
+            return;
+        }
+
+    }
+
+    function get_millisecond()
+    {
+        list($usec, $sec) = explode(" ", microtime());
+        $msec = round($usec * 1000);
+        return $sec . $msec;
+
+    }
+
+    function toLog($text, $rewrite = 0) {
+        $data = "=============" . date("Y-m-d H:i", time()) . "==========================================" . chr(13);
+        $data .= var_export($text, 1) . chr(13);
+        $data .= "======================================================================================" . chr(13);
+        $data = iconv('utf-8', 'gb2312', $data);
+        if ($rewrite) {
+            file_put_contents(ROOT_PATH . '/logs.txt', $data);
+        } else {
+            file_put_contents(ROOT_PATH . '/logs.txt', $data, FILE_APPEND);
+        }
+    }
+
+    /**
+     * 发送数据到前台,根据请求的数据格式返回相应的数据
+     * @param [type] $data   [description]
+     * @param string $status [description]
+     * @param string $msg    [description]
+     */
+    function Render($data, $status = "1", $msg = "", $method = '') {
+        $format = S('CUR_RETURN_FORMAT');
+        $msg = empty($msg) ? lang('errors', 'api')->get('error' . $status) : $msg;
+
+        if (empty($format) || $format == 'json') {
+            JsonReturn($data, $status, $msg);
+        }
+        if ($format == 'xml') {
+            XmlReturn($data, $status, $msg);
+        }
+        exit;
+    }
+
+
+
+    function _beginTransaction() {
+        S('DB')->beginTransaction();
+    }
+    function _rollBack() {
+        S('DB')->rollBack();
+    }
+    function _commit() {
+        S('DB')->commit();
+    }
+    /**
+     * 服务
+     *
+     * @param string 服务名称
+     * @param array $params
+     * @return void
+     */
+    function SRV($name, $params = array()) {
+        return C()->get($name)->update($params);
+    }
+    /**
+     * 是否验证token过期
+     *
+     * @return bool
+     */
+    function isCheckToken() {
+        $result = true;
+        $allowMethod = include ROOT_PATH . "/Config/AllowMethod.php";
+        $key = S('CUR_PROJECT') . '/' . S('CUR_CONTROLLER') . '/' . S('CUR_METHOD');
+        if ($allowMethod[$key] == 1) {
+            $result = false;
+        }
+        return $result;
+    }
+    function checkPlatform(){
+
+        if(isset($_GET['platform'])){
+            $_SESSION['platform']=$_GET['platform']=='wap'?1:0;
+        }
+        if(isset($_GET['clearPlatform']) && intval($_GET['clearPlatform'])==1){
+            $_SESSION['platform']=null;
+        }
+
+    }
+    function is_mobile() {
+        if(isset($_SESSION['platform']) && $mobile=intval($_SESSION['platform'])>0 ){
+            return $mobile==1?true:false;
+        }
+        $user_agent = $_SERVER['HTTP_USER_AGENT'];
+        $mobile_agents = Array("240x320", "acer", "acoon", "acs-", "abacho", "ahong", "airness", "alcatel", "amoi", "android", "anywhereyougo.com", "applewebkit/525", "applewebkit/532", "asus", "audio", "au-mic", "avantogo", "becker", "benq", "bilbo", "bird", "blackberry", "blazer", "bleu", "cdm-", "compal", "coolpad", "danger", "dbtel", "dopod", "elaine", "eric", "etouch", "fly ", "fly_", "fly-", "go.web", "goodaccess", "gradiente", "grundig", "haier", "hedy", "hitachi", "htc", "huawei", "hutchison", "inno", "ipad", "ipaq", "ipod", "jbrowser", "kddi", "kgt", "kwc", "lenovo", "lg ", "lg2", "lg3", "lg4", "lg5", "lg7", "lg8", "lg9", "lg-", "lge-", "lge9", "longcos", "maemo", "mercator", "meridian", "micromax", "midp", "mini", "mitsu", "mmm", "mmp", "mobi", "mot-", "moto", "nec-", "netfront", "newgen", "nexian", "nf-browser", "nintendo", "nitro", "nokia", "nook", "novarra", "obigo", "palm", "panasonic", "pantech", "philips", "phone", "pg-", "playstation", "pocket", "pt-", "qc-", "qtek", "rover", "sagem", "sama", "samu", "sanyo", "samsung", "sch-", "scooter", "sec-", "sendo", "sgh-", "sharp", "siemens", "sie-", "softbank", "sony", "spice", "sprint", "spv", "symbian", "tablet", "talkabout", "tcl-", "teleca", "telit", "tianyu", "tim-", "toshiba", "tsm", "up.browser", "utec", "utstar", "verykool", "virgin", "vk-", "voda", "voxtel", "vx", "wap", "wellco", "wig browser", "wii", "windows ce", "wireless", "xda", "xde", "zte");
+        $is_mobile = false;
+        foreach ($mobile_agents as $device) {
+            if (stristr($user_agent, $device)) {
+                $is_mobile = true;
+                break;
+            }
+        }
+        return $is_mobile;
+    }
+
+    function toDomain() {
+
+        $domain = $_SERVER['HTTP_HOST'];
+        $config = include ROOT_PATH . '/Config/Domain.php';
+        $is_mobile = is_mobile();
+        $curDomain = $old_domain = $domain;
+        if (is_array($config) && count($config) > 0) {
+            $domains = array();
+            $domains[] = $domain;
+            if ($is_mobile) {
+                $domains[] = str_replace('www.', 'm.', $domain);
+                $domains[] = 'm.' . $domain;
+            } else {
+                $domains[] = str_replace('m.', '', $domain);
+                $domains[] = str_replace('m.', 'www.', $domain);
+            }
+            foreach ($domains as $key => $value) {
+                if (isset($config[$value])) {
+                    $v = $config[$value];
+                    if ($v == 'pay') {
+                        return;
+                    }
+                    if ($is_mobile) {
+                        if ($v == 'pc') {
+                            continue;
+                        }
+                    } else {
+                        if ($v != 'pc') {
+                            continue;
+                        }
+                    }
+
+                    $curDomain = $value;
+                    // $_SESSION['domain']=$value;
+                }
+            }
+        }
+        // echo $curDomain;
+        if ($is_mobile) {
+            if (S('CUR_PROJECT') == 'Home') {
+                header("Location:http://" . $curDomain . "/m");
+                //header("Location:http://" . $curDomain . "/mobile-index/index");
+            }
+        } else {
+            if (S('CUR_PROJECT') == 'Mobile') {
+                header("Location:http://" . $curDomain . "/home-index/index");
+            }
+        }
+        /**
+         * 数据签名认证
+         * @param  array  $data 被认证的数据
+         * @return string       签名
+         */
+        function data_auth_sign($data) {
+            //数据类型检测
+            if (!is_array($data)) {
+                $data = (array) $data;
+            }
+            ksort($data); //排序
+            $code = http_build_query($data); //url编码并生成query字符串
+            $sign = sha1($code); //生成签名
+            return $sign;
+        }
+        /*
+         * 判断用户是否登录
+         * */
+        function isLogin($str = '',$type='agent') {
+            $session = $_SESSION[$type.'Info'];
+            if(empty($session)){
+                return null;
+            }
+            if($type=='agent'){
+                if($str=='name'){
+                    return $session['agent_user'];
+                }
+                if($str=='uid'){
+                    return $session['user_identity'];
+                }
+            }
+        }
+    }
+
+    function jump($url){
+        header('Location:'.$url);
+    }
+
+//手机中间星号
+    function phoneHide($phone)
+    {
+        if (!empty($phone)) {
+            $phone = substr_replace($phone, '****', 3, 4);
+        }
+        return $phone;
+    }
+
+    /**
+     * @param $game_code 球类代码
+     * @param int $isJoin 是否用于join
+     * @return array
+     * @throws Exception
+     * 根据球类代码 定义相关model
+     */
+    function getModels($game_code,$isJoin=1){
+        $game_type = lm('GameType', 'Sports')->where('game_code',$game_code)->select('game_code')->first();
+        // 获取不同球类model
+        if($isJoin == 1){
+            switch ($game_type->game_code){
+                case 'zq':
+                    $model_league = 'st_zq_league';
+                    $model_match = 'st_zq_competition';
+                    $model_odds = 'st_zq_odds';
+                    $model_odds_record = 'st_zq_odds_record';
+                    $model_result = 'st_zq_result';
+
+                    break;
+                case 'lq':
+                    $model_league = 'st_lq_league';
+                    $model_match = 'st_lq_competition';
+                    $model_odds = 'st_lq_odds';
+                    $model_odds_record = 'st_lq_odds_record';
+                    $model_result = 'st_lq_result';
+                    break;
+                case 'wq':
+                    $model_league = 'st_wq_league';
+                    $model_match = 'st_wq_competition';
+                    $model_odds = 'st_wq_odds';
+                    $model_odds_record = 'st_wq_odds_record';
+                    $model_result = 'st_wq_result';
+                    break;
+                case 'bq':
+                    $model_league = 'st_bq_league';
+                    $model_match = 'st_bq_competition';
+                    $model_odds = 'st_bq_odds';
+                    $model_odds_record = 'st_bq_odds_record';
+                    $model_result = 'st_bq_result';
+                    break;
+                case 'gj':
+                    $model_league = 'st_zq_league';
+                    $model_match = 'st_zq_competition';
+                    $model_odds = 'st_zq_odds';
+                    $model_result = 'st_zq_result';
+                    break;
+                default:
+                    throw new \Exception(Render([], '10002', lang('Tips','Sports')->get('PARAM_ERROR')));
+            }
+        }else{
+            switch ($game_type->game_code){
+                case 'zq':
+                    $model_league = 'st_zq_league';
+                    $model_match = 'st_zq_competition';
+                    $model_odds = 'st_zq_odds';
+                    $model_result = 'SoccerResult';
+                    break;
+                case 'lq':
+                    $model_league = 'st_lq_league';
+                    $model_match = 'st_lq_competition';
+                    $model_odds = 'st_lq_odds';
+                    $model_result = 'BasketballResult';
+                    break;
+                case 'wq':
+                    $model_league = 'st_wq_league';
+                    $model_match = 'st_wq_competition';
+                    $model_odds = 'st_wq_odds';
+                    $model_result = 'TennisResult';
+                    break;
+                case 'bq':
+                    $model_league = 'st_bq_league';
+                    $model_match = 'st_bq_competition';
+                    $model_odds = 'st_bq_odds';
+                    $model_result = 'BaseballResult';
+                    break;
+                case 'gj':
+                    $model_league = 'st_zq_league';
+                    $model_match = 'st_zq_competition';
+                    $model_odds = 'st_zq_odds';
+                    $model_result = 'SoccerResult';
+                    break;
+                default:
+                    throw new \Exception(Render([], '10002', lang('Tips','Sports')->get('PARAM_ERROR')));
+            }
+        }
+
+
+        $data = [
+            'model_league'=>$model_league,
+            'model_match'=>$model_match,
+            'model_odds'=>$model_odds,
+            'model_result' =>$model_result,
+            'model_odds_record' => $model_odds_record
+        ];
+        return $data;
+    }
+
+    /**
+     * @param $type_code
+     * @return array
+     * @throws \Exception
+     * 获取不同状态下的 查询条件
+     */
+    function getState($type_code,$model_match = ''){
+        if($model_match == ''){
+            switch ($type_code){
+                case 'StRollBall'://滚球 正在进行
+                    $where = [
+                        ['is_rollball','=',1],
+                        ['match_date','=',date("Y-m-d")],
+                        ['match_time','>',date("H:i:s", time()-(90*60))],
+                        ['match_time','<',date("H:i:s", time())]
+                    ];
+                    break;
+                case 'StSoon'://即将 今日两小时内开始
+                    $where = [
+                        ['status','=','0'],
+                        ['match_date','=',date("Y-m-d")],
+                        ['match_time','<',date("H:i:s", strtotime("+2 hour"))],
+                        ['match_time','>',date("H:i:s", time())]
+
+//                    ['utime','>',date("Y-m-d").' 00:00:00']
+                    ];
+                    break;
+                case 'StToday'://今日 今日未开始未结束
+                    $where = [
+                        ['is_today', '=', 1],
+
+//                    ['type', '=', '1'],
+//                    ['status', '<', '2'],
+                        ['match_date','=',date("Y-m-d")],
+                        ['match_time','>',date("H:i:s", time())],
+//                    ['utime','>',date("Y-m-d").' 00:00:00']
+                    ];
+                    break;
+                case 'StMorningPlate'://早盘
+                    $where = [
+                        ['is_morningplate', '=', 1],
+                        ['us_time','>',qgmdate('Y-m-d H:i:s', '', -4)],
+//                    ['match_date','>',date("Y-m-d",time())],
+//                    ['match_time','>',date("H:i:s", time())],
+//                    ['type', '=', '2'],
+//                    ['status', '<', '2'],
+//                    ['utime','>',date("Y-m-d").' 00:00:00']
+                    ];
+                    break;
+                case 'StStringScene'://串场
+                    $where = [
+                        ['is_stringscene', '=', 1],
+                        ['us_time','>',qgmdate('Y-m-d H:i:s', '', -4)],
+
+//                    ['match_date','>',date("Y-m-d",time())],
+//                    ['match_time','>',date("H:i:s", time())],
+//                    ['type', '=', '3'],
+//                    ['status', '<', '2'],
+//                    ['utime','>',date("Y-m-d").' 00:00:00']
+                    ];
+                    break;
+                case 'StChampion'://冠军
+                    $where = [
+                        'type'=>1
+                    ];
+                    break;
+                default:
+                    throw new \Exception(Render([], '10002', lang('Tips','Sports')->get('PARAM_ERROR')));
+            }
+        }else{
+            switch ($type_code){
+                case 'StRollBall'://滚球 正在进行
+                    $where = [
+                        [$model_match.'.is_rollball','=',1],
+                        [$model_match.'.match_date','=',date("Y-m-d")],
+                        [$model_match.'.match_time','>',date("H:i:s", time()-(90*60))],
+                        [$model_match.'.match_time','<',date("H:i:s", time())]
+                    ];
+                    break;
+                case 'StSoon'://即将 今日两小时内开始
+                    $where = [
+                        [$model_match.'.status','=','0'],
+                        [$model_match.'.match_date','=',date("Y-m-d")],
+                        [$model_match.'.match_time','<',date("H:i:s", strtotime("+2 hour"))],
+                        [$model_match.'.match_time','>',date("H:i:s", time())]
+//                    [$model_match.'.utime','>',date("Y-m-d").' 00:00:00']
+                    ];
+                    break;
+                case 'StToday'://今日 今日未开始未结束
+                    $where = [
+                        [$model_match.'.is_today','=',1],
+//                    [$model_match.'.type', '=', '1'],
+//                    [$model_match.'.status', '<', '2'],
+                        [$model_match.'.match_date','=',date("Y-m-d")],
+                        [$model_match.'.match_time','>',date("H:i:s", time())],
+//                    [$model_match.'.utime','>',date("Y-m-d").' 00:00:00']
+                    ];
+                    break;
+                case 'all'://所有赛事
+                    $where = [
+                        [$model_match.'.status', '<', '2'],
+                    ];
+                    break;
+                case 'StMorningPlate'://早盘
+                    $where = [
+                        [$model_match.'.is_morningplate','=',1],
+                        [$model_match.'.us_time','>',qgmdate('Y-m-d H:i:s', '', -4)],
+//                    [$model_match.'.match_date','>',date("Y-m-d",time())],
+//                    [$model_match.'.match_time','>',date("H:i:s", time())],
+//                    [$model_match.'.type', '=', '2'],
+//                    [$model_match.'.status', '<', '2'],
+//                    [$model_match.'.utime','>',date("Y-m-d").' 00:00:00']
+                    ];
+                    break;
+                case 'StStringScene'://串场 查询串场状态为1 开赛时间大于当前时间
+                    $where = [
+                        [$model_match.'.is_stringscene','=',1],
+                        [$model_match.'.us_time','>',qgmdate('Y-m-d H:i:s', '', -4)],
+
+//                    [$model_match.'.match_date','>',date("Y-m-d",time())],
+//                    [$model_match.'.match_time','>',date("H:i:s", time())],
+//                    [$model_match.'.type', '=', '3'],
+//                    [$model_match.'.status', '<', '2'],
+//                    [$model_match.'.utime','>',date("Y-m-d").' 00:00:00']
+                    ];
+                    break;
+                case 'StChampion'://冠军
+                    $where = [
+                        'type'=>1
+                    ];
+                    break;
+                default:
+                    throw new \Exception(Render([], '10002', lang('Tips','Sports')->get('PARAM_ERROR')));
+            }
+        }
+
+        return $where;
+    }
+
+    /**
+     * @param $data
+     * @return array
+     * 处理当国家下无联赛数据 删除该数组
+     */
+    function handleArr($data){
+        $hData = [];
+        foreach ($data as $key =>$v){
+            if(empty($v['league_count'])){
+                $v = [];
+            }
+            $hData[]=$v;
+        }
+        foreach($hData as $k=>$v){
+            if(empty($v)){
+                unset($hData[$k]);
+            }
+        }
+        foreach ($hData as $k=>$v){
+            $v['league_count'] = array_values($v['league_count']);
+            $hData[$k]=$v;
+        }
+
+        return array_values($hData);
+    }
+
+
+    /**
+     * @param $arr
+     * @param $key
+     * @return array
+     * 去除二维数组重复项
+     */
+    function array_unset_tt($arr,$key){
+        //建立一个目标数组
+        $res = array();
+        foreach ($arr as $value) {
+            //查看有没有重复项
+            if(isset($res[$value[$key]])){
+                unset($value[$key]);  //有:销毁
+            }else{
+                $res[$value[$key]] = $value;
+            }
+        }
+        return $res;
+    }
+
+    /**
+     * 处理冠军盘口 数组结构
+     */
+    function array_gj_tt($data,$oddsData){
+        foreach ($data as $k=>&$v){
+            foreach ($v['league_count'] as $kk=>&$vv){
+                foreach ($oddsData as $kkk=>$vvv){
+                    if($vv['lg_id'] == $vvv['lg_id']){
+                        $vv['oddsData'][]=$vvv;
+                    }
+                }
+
+                if($vv['oddsData']){
+                    $vv['oddsData'] = array_unset_tt($vv['oddsData'],'p_code');
+                    $vv['count'] = count($vv['oddsData']);
+                    unset($vv['oddsData']);
+                }
+
+                if(count($vv) == 5){
+                    unset($v['league_count'][$kk]);
+                }
+            }
+            $v['league_count'] =  array_values($v['league_count']);
+            if(empty($v['league_count'])){
+                unset($data[$k]);
+            }
+        }
+
+        return array_values($data);
+    }
+
+    /**
+     * 时间格式化
+     * @param string $dateformat 时间格式
+     * @param int $timestamp 时间戳
+     * @param int $timeoffset 时区偏差 默认8 北京时间 -4美东时间
+     * @return string
+     */
+    function qgmdate($dateformat = 'Y-m-d H:i:s', $timestamp = '', $timeoffset = 8) {
+        if(empty($timestamp)) {
+            $timestamp = time();
+        }
+        $result = gmdate($dateformat, $timestamp + $timeoffset * 3600);
+        return $result;
+    }
+
+    /**
+     * 判断二维数组是否包含一维数组
+     * @param mixed $arr 查询条件
+     * @param mixed $arrs 运动类型
+     * @return string
+     */
+    function judgeEqual($arr, $arrs){
+        foreach ($arrs as $value) {
+            if (count($value) === count($arr)) {
+                $a = 0;
+                foreach ($value as $key => $v) {
+                    $a++;
+                    if ($v != $arr[$key]) {
+                        break;
+                    }
+                    if ($a == count($key)) {    // 到最后一个元素都没有出现不相等,就说明这两个数组相等。
+                        return true;
+                    }
+                }
+            }
+        }
+        return false;
+    }
+
+// 排列
+    function arrangement($a, $m) {
+        $r = array();
+
+        $n = count($a);
+        if ($m <= 0 || $m > $n) {
+            return $r;
+        }
+
+        for ($i=0; $i<$n; $i++) {
+            $b = $a;
+            $t = array_splice($b, $i, 1);
+            if ($m == 1) {
+                $r[] = $t;
+            } else {
+                $c = arrangement($b, $m-1);
+                foreach ($c as $v) {
+                    $r[] = array_merge($t, $v);
+                }
+            }
+        }
+
+        return $r;
+    }
+
+// 组合
+    function combination($a, $m) {
+        $r = array();
+
+        $n = count($a);
+        if ($m <= 0 || $m > $n) {
+            return $r;
+        }
+
+        for ($i=0; $i<$n; $i++) {
+            $t = array($a[$i]);
+            if ($m == 1) {
+                $r[] = $t;
+            } else {
+                $b = array_slice($a, $i+1);
+                $c = combination($b, $m-1);
+                foreach ($c as $v) {
+                    $r[] = array_merge($t, $v);
+                }
+            }
+        }
+
+        return $r;
+    }
+
+// 阶乘
+    function factorial($n) {
+        return array_product(range(1, $n));
+    }
+
+// 排列数
+    function A1($n, $m) {
+        return factorial($n)/factorial($n-$m);
+    }
+
+// 组合数
+    function C1($n, $m) {
+        return A1($n, $m)/factorial($m);
+    }
+}
+
+?>

+ 1 - 0
Biz/Game/TranferMoneyLogic.php

@@ -172,6 +172,7 @@ class TranferMoneyLogic
         $this->transferModel->tradtype = ($this->type == 'IN') ? 8 : 9 ;
         $this->transferModel->tfrom = 0 ;
         $this->transferModel->tto = 0 ;
+        $this->transferModel->addtime = date("Y-m-d H:i:s") ;
         $this->transferModel->agent_name = $this->wagentModel->agent_name ;
 
         $ret = $this->transferModel->save();

+ 13 - 1
Biz/Match/GetOddsData.php

@@ -8,13 +8,19 @@
  */
 namespace Biz\Match;
 class GetOddsData {
+    public function __construct() {
+        $this->commonFunction =  C()->get('commonFunction');
+    }
     /**
      * 根据不同球类获取相关赔率数据
      */
     public function getOddsData($data,$whereDate,$source){
+        if($data['search']){
+            $search = $data['search'];
+        }
 
         //根据 球类代码 获取相关model
-        $models = getModels($data['game_code']);
+        $models = $this->commonFunction->getModels($data['game_code']);
 
         $model_league = $models['model_league'];
         $model_match = $models['model_match'];
@@ -34,6 +40,12 @@ class GetOddsData {
             ->where($whereDate)
             ->where('st_zq_competition.us_time','>',qgmdate('Y-m-d H:i:s', '', -4))
             ->where('status','<',2)
+            ->where(function($query)use ($model_match,$search){
+                $query->where($model_match.'.home_team','like','%'.$search.'%')
+                    ->orWhere(function($query)use ($model_match,$search) {
+                        $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
+                    });
+            })
             ->get()->toArray();
         if(empty($matchData))  throw new \Exception(Render([], '10004', lang('Tips','Sports')->get('PARAM_ERROR')));
 

+ 15 - 13
Biz/Match/GetmatchData.php

@@ -13,6 +13,7 @@ class GetmatchData {
 
     public function __construct() {
         $this->getOddsData = new GetOddsData();
+        $this->commonFunction =  C()->get('commonFunction');
     }
 
     /**
@@ -24,11 +25,11 @@ class GetmatchData {
      */
     public function typeData($ret,$source){
         //根据球类代码 获取相关model
-        $models = getModels($ret['game_code']);
+        $models = $this->commonFunction->getModels($ret['game_code']);
         $model_match = $models['model_match'];
 
         //获取 不同状态的查询条件
-        $where = getState($ret['type_code'],$model_match);
+        $where = $this->commonFunction->getState($ret['type_code'],$model_match);
 
         //根据联赛id查询
         if(!empty($ret['lg_id'])){
@@ -71,7 +72,7 @@ class GetmatchData {
 
                 }
                 if($ret['str_type'] == 2){//冠军盘口
-                    $where = getState('StChampion',$model_match);
+                    $where = $this->commonFunction->getState('StChampion',$model_match);
                     $data = $this->getChampion($source,$models,$where,$lg_id,$search,'StChampion');
                 }
                 break;
@@ -524,8 +525,8 @@ class GetmatchData {
         }
 
         //处理空联赛国家
-        $countryData = handleArr($country);
-        $areaData = handleArr($area);
+        $countryData = $this->commonFunction->handleArr($country);
+        $areaData = $this->commonFunction->handleArr($area);
 
         //合并数组
         $data = array_merge($countryData,$areaData);
@@ -598,8 +599,8 @@ class GetmatchData {
         }
 
 
-        $countryData = array_gj_tt($countryData,$oddsData);
-        $areaData = array_gj_tt($areaData,$oddsData);
+        $countryData = $this->commonFunction->array_gj_tt($countryData,$oddsData);
+        $areaData = $this->commonFunction->array_gj_tt($areaData,$oddsData);
         $data = array_merge($countryData,$areaData);
         return $data;
     }
@@ -735,7 +736,7 @@ class GetmatchData {
         $data=[];
         foreach ($game as $key=>$item){
             if($item['game_code'] !='gj'){
-                $model = getModels($item['game_code']);
+                $model = $this->commonFunction->getModels($item['game_code']);
 
                 $matchData = lm($model['model_match'], 'Sports')
                     ->select('match_id','home_team','guest_team','match_time')
@@ -773,7 +774,7 @@ class GetmatchData {
         if(!empty($_GET['search'])){
             $search = $_GET['search'];
         }
-        $model = getModels('gj',1);
+        $model = $this->commonFunction->getModels('gj',1);
 
         $model_league = $model['model_league'];
         $leagueData = lm($model_league,'Sports')
@@ -791,6 +792,7 @@ class GetmatchData {
         $StChampion = $this->getUEFAStChampion($model,'StChampion',$source,$leagueData->lg_id,$leagueData->last_time);
 
         $data = [
+            'lg_id' => $leagueData->lg_id,
             'leagueName'=> $leagueData->name_chinese,
             'StRollBall'=>[//滚球数据
                 'typeName'=>'滚球',
@@ -825,7 +827,7 @@ class GetmatchData {
         $model_odds = $model['model_odds'];
         $model_result = $model['model_result'];
 
-        $where = getState($type_code,$model_match);
+        $where = $this->commonFunction->getState($type_code,$model_match);
         $matchData = lm($model_match,"Sports")
             ->leftjoin($model_result,$model_result.'.match_id',$model_match.'.match_id')
             ->select($model_match.'.match_id',$model_match.'.tag','match_date',$model_match.'.match_time',$model_match.'.home_team',$model_match.'.guest_team','home_score','guest_score',$model_result.'.match_time as a_time','match_process')
@@ -897,7 +899,7 @@ class GetmatchData {
         $model_match = $model['model_match'];
         $model_odds = $model['model_odds'];
 
-        $where = getState($type_code);
+        $where = $this->commonFunction->getState($type_code);
         $matchData = lm($model_match,'Sports')
             ->select('match_id','match_date','match_time','tag','home_team','guest_team')
             ->where($model_match.'.source',$source['source'])
@@ -935,7 +937,7 @@ class GetmatchData {
         $model_match = $model['model_match'];
         $model_odds = $model['model_odds'];
 
-        $where = getState($type_code);
+        $where = $this->commonFunction->getState($type_code);
 
         $matchData = lm($model_match,'Sports')
             ->select('match_id','match_date','match_time','tag','home_team','guest_team')
@@ -961,7 +963,7 @@ class GetmatchData {
     public function getUEFAStChampion($model,$type_code,$source,$lg_id,$last_time=''){
         $model_odds = $model['model_odds'];
 
-        $where = getState($type_code);
+        $where = $this->commonFunction->getState($type_code);
         $championData = lm($model_odds, 'Sports')
             ->select("id","lg_id","p_code","odds_code","team","odds","sort","status","odds_only")
 //                ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))

+ 14 - 0
Biz/Settlement/Adapter/BqRule.php

@@ -0,0 +1,14 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/4/25
+ * Time: 14:10
+ */
+
+namespace Biz\Settlement\Adapter\Settlement;
+
+class BqRule
+{
+
+}

+ 14 - 0
Biz/Settlement/Adapter/LqRule.php

@@ -0,0 +1,14 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/4/25
+ * Time: 14:09
+ */
+
+namespace Biz\Settlement\Adapter\Settlement;
+
+class LqRule
+{
+
+}

+ 15 - 0
Biz/Settlement/Adapter/WqRule.php

@@ -0,0 +1,15 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/4/25
+ * Time: 14:10
+ */
+
+namespace Biz\Settlement\Adapter\Settlement;
+
+
+class WqRule
+{
+
+}

+ 40 - 0
Biz/Settlement/Adapter/ZqRule.php

@@ -0,0 +1,40 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/4/25
+ * Time: 14:10
+ */
+
+namespace Biz\Settlement\Adapter\Settlement;
+
+
+class ZqRule
+
+{
+
+    ////////////////////////根据规则判断输赢
+    //让球大小
+     public  function    concede_size($model,$resultModel,$resultRecords){
+
+
+     }
+
+     //全场|主队|让球
+    public  function   concede_home($model,$resultModel,$resultRecords){
+            $zhiball = intval($resultModel->home_score) ;
+            $keballs = intval($resultModel->guest_score) ;
+            $cond = intval($model->condition) ;
+            $cha = $zhiball - $keballs - $cond ;
+
+            if ($cha  >0 ){ return 1; }
+            if($cha ==0 ) { return 2 ;}
+            return -1 ;
+     }
+
+     //主队全场让球条件
+    public  function  concede_home_rule($model,$resultModel,$resultRecords){
+
+    }
+
+}

+ 295 - 0
Biz/Settlement/SettlementBase.php

@@ -0,0 +1,295 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/4/25
+ * Time: 14:10
+ */
+
+namespace Biz\Settlement;
+set_time_limit(600);
+ini_set('memory_limit', '256M');
+
+
+class SettlementBase
+{
+     const  USER_WIN  = 1 ;   //用户赢钱
+     const  USER_LOSE = -1;   //用户输钱
+     const  USER_FLAT = 2 ;   //持平,用户钱原路返回
+
+     public $match_id  = 0 ;     //比赛场次ID
+     public $matchModel = null ;  //比赛场次Model对像
+
+     public $lg_id = 0  ;    //联赛ID
+     public $lgModel = null ;  //联赛Model对像
+
+     public $resultId = 0 ; //比赛最终结果ID
+     public $resultModel = null ; //比赛最终结果对像MODEL
+     public $resultRecords = [] ; //比赛中间结果对像数组;
+
+     public $buyArrays = [] ;   //订单记录表
+
+     public $gameType = '' ;  //类型
+    //类型映射
+     public $gameAllMap = [
+         'zq'=>'ZqRule',
+         'lq'=>'LqRule',
+         'wq'=>'WqRule',
+         'bq'=>'BqRule',
+     ];
+    private  $AdapterObj = null ;
+
+
+    public  function __construct()
+    {
+        C()->set('BqRule','\Biz\Settlement\Adapter\BqRule');
+        C()->set('LqRule','\Biz\Settlement\Adapter\LqRule');
+        C()->set('WqRule','\Biz\Settlement\Adapter\WqRule');
+        C()->set('ZqRule','\Biz\Settlement\Adapter\ZqRule');
+
+        return true;
+    }
+
+    //返回数据
+    private function  makeData($status=1,$message='success',$data=''){
+        return [
+            'status' => $status ,
+            'message' =>$message,
+            'data' => $data ,
+        ] ;
+    }
+
+    //开始结算处理
+    public function  doSettlement(){
+            $model = $this->getNoticeData();
+            if ($model) {    return $this->makeData(1,'no data to process') ;  }
+
+            try{
+                _beginTransaction();
+                $ret1 = $this->doInit($model->type,$model->competionid);
+                if (!$ret1){   _rollBack(); return $this->makeData(0,'false_1') ;  }
+
+                $ret2 = $this->writeStatusBegin($model);
+                if (!$ret2){   _rollBack(); return $this->makeData(0,'false_2') ;  }
+
+                $ret3 = $this->getOrdersByMatchid($this->gameType,$this->match_id);
+                if (!$ret3){
+                    //没有下单数据,本场赛事结算处理完毕
+                    $this->writeStatusEndOk($model);
+                    _commit();
+                    return  $this->makeData();
+                }
+
+                $ret4 = $this->BatchModesResult($ret3);
+                if (!$ret4){
+                    _rollBack(); return $this->makeData(0,'false_4') ;
+                }
+
+
+
+
+
+
+
+                _commit();
+                return  $this->makeData();
+
+            }catch(\Exception $e){
+                _rollBack();
+                return $this->makeData(0,'false',['msg'=>$e->getMessage(),'code'=>$e->getCode()]) ;
+            }
+
+    }
+
+
+    //写处理状态
+    public function  writeStatusBegin($comendnticeModel){
+        $comendnticeModel->status = 1 ;
+        $comendnticeModel->pupdatetime = date("Y-m-d H:i:s");
+        $comendnticeModel->pcount ++ ;
+        $comendnticeModel->logs = 'begin|';
+        $ret = $comendnticeModel->save();
+        return  $ret;
+    }
+
+    //写处理状态结束
+    public function  writeStatusEndOk($comendnticeModel){
+        $comendnticeModel->status = 4 ;
+        $comendnticeModel->pret = 1 ;
+        $comendnticeModel->puodateendtime = date("Y-m-d H:i:s");
+        $comendnticeModel->logs = $comendnticeModel->logs.'end ok';
+        $ret = $comendnticeModel->save();
+        return  $ret;
+    }
+
+
+    //查询是否有未处理的数据
+    public function  getNoticeData($where = ['status'=>0]){
+        $model = lm('Comendnotice','Commons')->where($where)->first();
+        if (!$model){
+            return false;
+        }
+        return $model ;
+    }
+
+    //实现结算功能
+    public function   doInit($type,$match_id){
+            if ( isset($this->gameAllMap)){  throw  new \Exception('赛事类型错误',4002);   return false;  }
+
+            switch ($type){
+                case 'bq':
+                    $this->AdapterObj = C()->get('BqRule');
+                    break;
+                case  'lq':
+                    $this->AdapterObj = C()->get('LqRule');
+                    break;
+                case  'wq':
+                    $this->AdapterObj = C()->get('WqRule');
+                    break;
+                case  'zq':
+                    $this->AdapterObj = C()->get('ZqRule');
+                    break;
+            }
+
+            $this->gameType = $type ;
+            $this->match_id = $match_id ;
+
+            $this->getCompetitionData($type,$match_id);
+            $this->getCompResult($type,$match_id);
+
+            return true ;
+    }
+
+    //获取比赛数据模型
+    public function  getCompetitionData($type,$match_id){
+
+        $model = null ;
+        switch ($type){
+            case 'bq':
+                $model = lm('St_bq_competition','Commons')->where('match_id',$match_id)->first();
+                break;
+            case  'lq':
+                $model = lm('St_lq_competition','Commons')->where('match_id',$match_id)->first();
+                break;
+            case  'wq':
+                $model = lm('St_wq_competition','Commons')->where('match_id',$match_id)->first();
+                break;
+            case  'zq':
+                $model = lm('St_zq_competition','Commons')->where('match_id',$match_id)->first();
+                break;
+        }
+        if (empty($model)){
+            throw  new   \Exception('无效match_id_'.$type.'-'.$match_id,4004);
+            return false;
+        }
+
+        $this->matchModel = $model;
+        return $model ;
+    }
+
+
+    //查询此比较有下单记录
+    public function  getOrdersByMatchid($type,$marchid){
+            $modes = lm('Money_buy_match','Commons')->getByTypeMatch($type,$marchid);
+            return $$modes;
+    }
+
+    //批量结算处理 [只处理状态]
+    public function  BatchModesResult($type,$models){
+             $pclass = $this->AdapterObj ;
+             $RefClass = new  \ReflectionClass($pclass) ;
+            foreach ($models as $model){
+                  $oddscode = $model->odds_code;
+                  if ( $RefClass->hasMethod($oddscode)){
+                      $model->result  = $pclass->$oddscode($model,$this->resultModel,$this->resultRecords);
+                      $model->utime = date("Y-m-d H:i:s");
+                      $ret  = $model->save();
+                      if (!$ret){
+                          throw  new  \Exception('更新记录buy_match失败!',4006);
+                      }
+                      $this->getBuyDatas($model->order_id);
+
+                }else{
+                    throw  new  \Exception('找不到此玩法的胜负规则逻辑!',4005);
+                }
+            }
+            return true;
+    }
+
+
+
+
+
+
+    //某个订单下面的所有比赛是否全部处理完成
+    public function   OrderIsPressFinish($orderId){
+
+
+    }
+
+
+    //得到比赛最终结果记录 和 中间结果记录
+    public function  getCompResult($type,$match_id){
+        $model = null ;
+        switch ($type){
+            case 'bq':
+                $model = lm('St_bq_result','Commons')->where('match_id',$match_id)->first();
+                $models = lm('St_bq_result_record','Commons')->where('match_id',$match_id)->find();
+                break;
+            case  'lq':
+                $model = lm('St_lq_resultn','Commons')->where('match_id',$match_id)->first();
+                $models = lm('St_lq_result_record','Commons')->where('match_id',$match_id)->find();
+                break;
+            case  'wq':
+                $model = lm('St_wq_result','Commons')->where('match_id',$match_id)->first();
+                $models = lm('St_wq_result_record','Commons')->where('match_id',$match_id)->find();
+                break;
+            case  'zq':
+                $model = lm('St_zq_result','Commons')->where('match_id',$match_id)->first();
+                $models = lm('St_zq_result_record','Commons')->where('match_id',$match_id)->find();
+                break;
+        }
+        if (empty($model)){
+            throw  new   \Exception('没找到比赛结果记录match_id_'.$type.'-'.$match_id,4007);
+            return false;
+        }
+
+        $this->resultModel = $model;
+        $this->resultRecords = $models ;
+
+        $ret = [
+            'result' => $model,
+            'records' => $models ,
+        ];
+        return $ret;
+
+    }
+
+    //得到订单信息
+    public function  getBuyDatas($orderId){
+         if ( isset($this->buyArrays[$orderId]) ){
+             return $this->buyArrays[$orderId];
+         }
+
+         $model = lm("Money_buy")->where(['order_id',$orderId])->first();
+         if (!$model){
+             throw new  \Exception('没有订单基本信息_'.$orderId, 4008);
+         }
+
+         $details = lm("Money_buy_detail")->where(['order_id',$orderId])->find();
+         if (!$details){
+             throw new  \Exception('没有订单detail信息_'.$orderId, 4009);
+         }
+
+         $ret = [
+             'buy' =>$model ,
+             'details' => $details ,
+         ];
+
+        $this->buyArrays[$orderId] = $ret  ;
+        return $ret;
+    }
+
+
+
+}

+ 297 - 0
Biz/Settlement/SettlementSql.php

@@ -0,0 +1,297 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/4/25
+ * Time: 14:10
+ */
+
+namespace Biz\Settlement;
+set_time_limit(600);
+ini_set('memory_limit', '256M');
+
+
+class SettlementSql
+{
+
+    //用户的期末基本资料表 [uid]['account'=>$obj,'detail'=>$obj];
+     public  $AccountArrays = []  ;
+
+     //buy_match 里batch_id 相同的数据
+     public  $MatchBatchIdArrays = [] ;
+
+     //buy_str 批次号相同的记录
+    public  $BuyStrBatchIdArrays = [] ;
+
+    //所有比赛场次号相同的记录
+    public  $AllMatchIdArrays = [];
+
+    //比赛结束消息通知模型
+    public  $ComendNoticModel = null  ;
+
+    //返回的sql数组
+    private  $sqlArray = [] ;
+
+    public $gameType = '' ;  //类型
+    public $resultId = 0 ; //比赛最终结果ID
+    public $resultModel = null ; //比赛最终结果对像MODEL
+    public $resultRecords = [] ; //比赛中间结果对像数组;
+
+    //类型映射
+    public $gameAllMap = [
+        'zq'=>'ZqRule',
+        'lq'=>'LqRule',
+        'wq'=>'WqRule',
+        'bq'=>'BqRule',
+    ];
+    private  $AdapterObj = null ;
+
+    private   $RefClass = null  ;
+
+
+    public function   doRun(){
+
+
+        try {
+            _beginTransaction();
+
+            $ComendNoticModel = $this->getComendNoticeModel();
+            if (!$ComendNoticModel) {
+                _commit();
+                return  $this->makeData();
+            }
+            $this->writeStatusBegin($ComendNoticModel);
+
+            $allmatchs = $this->getAllMatchIdArrays($ComendNoticModel->game_code, $ComendNoticModel->match_id, 2);
+            $this->setAdapterObj( $ComendNoticModel->game_code );
+            $this->RefClass = new  \ReflectionClass(  $this->setAdapterObj ) ;
+            $this->getCompResult($ComendNoticModel->game_code,$ComendNoticModel->match_id);
+
+
+            if (!$allmatchs) {
+                $this->writeStatusEndOk($ComendNoticModel);
+                _commit();
+                return  $this->makeData();
+            }
+
+            foreach ($allmatchs  as $buymatchmodel){
+                    $this->doSettlement($buymatchmodel);
+            }
+
+            _commit();
+            return  $this->makeData();
+
+        }catch (\Exception $e){
+            _rollBack();
+            return $this->makeData(0,'false',['msg'=>$e->getMessage(),'code'=>$e->getCode()]) ;
+
+        }
+
+    }
+
+
+    //拼装  逻辑 sql;
+    private  function  doSettlement($model){
+        $fun = $model->odds_code ;
+        if ( $this->RefClass->hasMethod( $fun)){
+                $winorfalse = $this->AdapterObj->$fun($model,$this->resultModel,$this->resultRecords);
+                $this->makesql_up_buymatch_winorfalse($model->id,$winorfalse,date("Y-m-d H:i:s"));
+                if ($winorfalse == -1){
+                    $this->masql_up_buymatch_false($model->batch_id);
+                }
+
+
+
+
+
+
+        }else{
+            throw  new  \Exception('找不到此玩法的胜负规则逻辑!',4005);
+        }
+    }
+
+
+    private function  makesql_up_buymatch_winorfalse($id,$result,$utime){
+        $sql = " update  money_buy_match  set  result=$result,utime=$utime  where id=$id  limit 1";
+        $this->sqlArray[] = $sql;
+        return true;
+    }
+    private function masql_up_buymatch_false($batch_id){
+        $uptime = date("Y-m-d H:i:s");
+        $sql = " update  money_buy_match  set  result=-1 ,utime=$uptime,status=1  where batch_id=$batch_id  ";
+        $this->sqlArray[] = $sql;
+
+        $sql =  "update  money_buy_str  set   settle_status=1,game_status=3 ,wait_match_num=0  where  batch_id=$batch_id " ;
+        $this->sqlArray[] = $sql;
+
+        return true ;
+    }
+
+
+
+
+
+    private  function  setAdapterObj($game_type){
+
+        if ( isset($this->gameAllMap)){  throw  new \Exception('赛事类型错误',4002);   return false;  }
+
+        switch ($game_type){
+            case 'bq':
+                C()->set('BqRule','\Biz\Settlement\Adapter\BqRule');
+                $this->AdapterObj = C()->get('BqRule');
+                break;
+            case  'lq':
+                C()->set('LqRule','\Biz\Settlement\Adapter\LqRule');
+                $this->AdapterObj = C()->get('LqRule');
+                break;
+            case  'wq':
+                C()->set('WqRule','\Biz\Settlement\Adapter\WqRule');
+                $this->AdapterObj = C()->get('WqRule');
+                break;
+            case  'zq':
+                C()->set('ZqRule','\Biz\Settlement\Adapter\ZqRule');
+                $this->AdapterObj = C()->get('ZqRule');
+                break;
+        }
+        return  true ;
+    }
+
+
+    //返回数据
+    private function  makeData($status=1,$message='success',$data=''){
+        return [
+            'status' => $status ,
+            'message' =>$message,
+            'data' => $data ,
+        ] ;
+    }
+
+    //写处理状态
+    public function  writeStatusBegin($comendnticeModel){
+        $comendnticeModel->status = 1 ;
+        $comendnticeModel->pupdatetime = date("Y-m-d H:i:s");
+        $comendnticeModel->pcount ++ ;
+        $comendnticeModel->logs = 'begin|';
+        $ret = $comendnticeModel->save();
+        return  $ret;
+    }
+
+    //写处理状态结束
+    public function  writeStatusEndOk($comendnticeModel){
+        $comendnticeModel->status = 4 ;
+        $comendnticeModel->pret = 1 ;
+        $comendnticeModel->puodateendtime = date("Y-m-d H:i:s");
+        $comendnticeModel->logs = $comendnticeModel->logs.'end ok';
+        $ret = $comendnticeModel->save();
+        return  $ret;
+    }
+
+
+
+
+    public  function   getComendNoticeModel(){
+            $ret = lm('Comendnotice','Commons')->wherer('status',0)->order('id','asc')->first();
+            $this->ComendNoticModel = $ret;
+            return $ret;
+    }
+
+
+    public function  getAllMatchIdArrays( $type,$matchid ,$bet_type=2,$result = 0 ){
+            $ret = lm('Money_buy_match','Commons')->where(['game_code'=>$type,'match_id'=>$matchid,'bet_type'=>$bet_type,'result'=>$result])->find();
+            $this->AllMatchIdArrays = $ret;
+            return $ret;
+    }
+
+
+    public function  getUserInfo($account_name){
+         if (isset($this->AccountArrays[$account_name])){
+             return $this->AccountArrays['$account_name'];
+         }
+
+         $accountModel = lm('Account','Commons')->where(['account',$account_name])->first();
+         if (!$accountModel){
+             throw  new   \Exception('查无此用户数据account='.$account_name,41002);
+         }
+
+         $detailModel = lm('Account_detailed','Commons')->where(['account_identity',$accountModel->identity])->first();
+         if (!$detailModel){
+             throw  new   \Exception('查无此用户数据account_detail='.$accountModel->identity,41002);
+         }
+         $ret = [
+             'account'=>$detailModel,
+             'detail' => $detailModel ,
+         ];
+         $this->AccountArrays[$account_name] = $ret ;
+         $this->AccountArrays[$accountModel->identity] = $ret ;
+
+         return $ret;
+     }
+
+
+    public function  GetMatchBatchIdArrays($batch_id){
+            if (isset($this->MatchBatchIdArrays[$batch_id])){
+                return   $this->MatchBatchIdArrays[$batch_id];
+            }
+            $all = lm("Money_buy_match")->getByBatchId($batch_id);
+            if (!$all) {
+                throw  new  \Exception('无效的Money_buy_str->batch_id='.$batch_id , 41001);
+            }
+            $this->MatchBatchIdArrays[$batch_id] = $all ;
+            return $all ;
+    }
+
+
+    public function  GetBuyStrBatchIdArrays($batch_id){
+
+        if (isset($this->BuyStrBatchIdArrays[$batch_id])){
+            return   $this->BuyStrBatchIdArrays[$batch_id];
+        }
+        $all = lm("Money_buy_str")->getByBatchId($batch_id);
+        if (!$all) {
+            throw  new  \Exception('无效的Money_buy_str->batch_id='.$batch_id , 41001);
+        }
+        $this->BuyStrBatchIdArrays[$batch_id] = $all ;
+        return $all ;
+
+    }
+
+
+    //得到比赛最终结果记录 和 中间结果记录
+    public function  getCompResult($type,$match_id){
+        $model = null ;
+        switch ($type){
+            case 'bq':
+                $model = lm('St_bq_result','Commons')->where('match_id',$match_id)->first();
+                $models = lm('St_bq_result_record','Commons')->where('match_id',$match_id)->find();
+                break;
+            case  'lq':
+                $model = lm('St_lq_resultn','Commons')->where('match_id',$match_id)->first();
+                $models = lm('St_lq_result_record','Commons')->where('match_id',$match_id)->find();
+                break;
+            case  'wq':
+                $model = lm('St_wq_result','Commons')->where('match_id',$match_id)->first();
+                $models = lm('St_wq_result_record','Commons')->where('match_id',$match_id)->find();
+                break;
+            case  'zq':
+                $model = lm('St_zq_result','Commons')->where('match_id',$match_id)->first();
+                $models = lm('St_zq_result_record','Commons')->where('match_id',$match_id)->find();
+                break;
+        }
+        if (empty($model)){
+            throw  new   \Exception('没找到比赛结果记录match_id_'.$type.'-'.$match_id,4007);
+            return false;
+        }
+
+        $this->resultModel = $model;
+        $this->resultRecords = $models ;
+
+        $ret = [
+            'result' => $model,
+            'records' => $models ,
+        ];
+        return $ret;
+
+    }
+
+
+}

+ 4 - 0
Config/Services.php

@@ -1439,3 +1439,7 @@ C()->set('sfsixlottery_settings', '\Biz\Game\Settings\SfsixlotterySettings');
 C()->set('sfsixlottery_handle', '\Biz\Game\Handle\Join\SfsixlotteryHandle');
 
 C()->set('sfsixlotteryParse', '\Biz\Game\Parse\SfsixlotteryParse');
+/*************************************************************************/
+
+// 公共函数
+C()->set('commonFunction', '\Biz\Common\CommonFunction');