Bladeren bron

更新提交

彭俊 6 jaren geleden
bovenliggende
commit
b6faa49b4d

+ 82 - 73
Application/Api/Controller/BetOrder.php

@@ -90,74 +90,67 @@ class BetOrder extends BaseController{
      */
 
     public function bet_order(){
-        $data = [
-            ['game_code'=>'zq','match_id'=>1,'lg_id'=>1,'odds_id'=>'1','record_id'=> 2,'bet_amount'=>100,'bet_odds'=>1,'odds_only'=>'e5a38602e4ba44848ab303f82bd224511555376747.3722475'],
-            ['game_code'=>'lq','match_id'=>1,'lg_id'=>1,'odds_id'=>'1','record_id'=> 2,'bet_amount'=>100,'bet_odds'=>1,'odds_only'=>'e5a38602e4ba44848ab303f82bd224511555376747.3722475'],
-            ['game_code'=>'lq','match_id'=>1,'lg_id'=>1,'odds_id'=>'1','record_id'=> 2,'bet_amount'=>100,'bet_odds'=>1,'odds_only'=>'e5a38602e4ba44848ab303f82bd224511555376747.3722475']
-        ];
+        $data = $_REQUEST['data'];
         if(empty($data)){
             Render('', '51029',lang('Errors','Api')->get('error-51029'));
         }
-        $userInfo =[
-            "id" => 93985,
-            "identity"=>"76b04b38-e31b-691b-1eaf-19e8ed1f790a",
-            "account"=> "181817994081",
-            "status"=> 1,
-            "fanshui"=> 1,
-            "remark"=> "",
-            "user_type"=> 1,
-            "account_identity"=> "edfe719d-914b-49b1-3f73-46cae73738c2",
-            "register_time"=> "2019-04-09 18:16:06",
-            "register_ip"=>"127.0.0.1",
-            "last_time"=> "2019-04-12 10:58:12.242624",
-            "last_ip"=> "127.0.0.1",
-            "grade"=> 0,
-            "email"=> "",
-            "phone"=>"18181799409",
-            "invitation"=>"",
-            "available_cash"=> "1000.00",
-            "cash"=>"1000.00",
-            "frozen_cash"=>"0.00",
-            "open_invitation"=>"93985",
-            "spread"=>"0",
-            "placing"=>"0",
-            "token"=>"lADqQI15550666925cb06f44ad5b6",
-            "statuss"=>"1",
-            "ranking"=>null,
-            "card"=>"5",
-            "name"=>"junghwi1",
-            "show"=> "0",
-            "img_url"=> null,
-            "qq"=>"",
-            "register_url"=> "www.weba.com",
-            "last_url"=> "www.weba.com",
-            "group_code"=> "0,1,",
-            "group_name"=> "|普通会员|",
-            "parent_id"=> null,
-            "parent_path"=> null,
-            "level"=> 2,
-            "finance_cash"=> null,
-            "img_id"=> null,
-            "wechat"=> "",
-            "og_type"=> 1,
-            "now_game"=> null,
-            "ip"=>"127.0.0.1",
-       ];//$this->getAgent();//用户信息
+//        $userInfo =[
+//            "id" => 93985,
+//            "identity"=>"76b04b38-e31b-691b-1eaf-19e8ed1f790a",
+//            "account"=> "181817994081",
+//            "status"=> 1,
+//            "fanshui"=> 1,
+//            "remark"=> "",
+//            "user_type"=> 1,
+//            "account_identity"=> "edfe719d-914b-49b1-3f73-46cae73738c2",
+//            "register_time"=> "2019-04-09 18:16:06",
+//            "register_ip"=>"127.0.0.1",
+//            "last_time"=> "2019-04-12 10:58:12.242624",
+//            "last_ip"=> "127.0.0.1",
+//            "grade"=> 0,
+//            "email"=> "",
+//            "phone"=>"18181799409",
+//            "invitation"=>"",
+//            "available_cash"=> "800.00",
+//            "cash"=>"800.00",
+//            "frozen_cash"=>"0.00",
+//            "open_invitation"=>"93985",
+//            "spread"=>"0",
+//            "placing"=>"0",
+//            "token"=>"lADqQI15550666925cb06f44ad5b6",
+//            "statuss"=>"1",
+//            "ranking"=>null,
+//            "card"=>"5",
+//            "name"=>"junghwi1",
+//            "show"=> "0",
+//            "img_url"=> null,
+//            "qq"=>"",
+//            "register_url"=> "www.weba.com",
+//            "last_url"=> "www.weba.com",
+//            "group_code"=> "0,1,",
+//            "group_name"=> "|普通会员|",
+//            "parent_id"=> null,
+//            "parent_path"=> null,
+//            "level"=> 2,
+//            "finance_cash"=> null,
+//            "img_id"=> null,
+//            "wechat"=> "",
+//            "og_type"=> 1,
+//            "now_game"=> null,
+//            "ip"=>"127.0.0.1",
+//       ];//
+        $userInfo = $this->getAgent();//获取用户信息
         //验证与判断投注了几种
         foreach($data as $k => $v){
             $num = $k + 1;
-//            $this->verify_gameType($v['game_code'],$num);
-//            $this->verify_match($v['game_code'],$v['match_id'],$num);
-//            $this->verify_league($v['game_code'],$v['lg_id'],$num);
-//            $this->verify_odds($data['game_code'],$v['odds_id'],$v['record_id'],$num);
+            $this->verify_gameType($v['game_code'],$num);
+            $this->verify_match($v['game_code'],$v['match_id'],$num);
+            $this->verify_league($v['game_code'],$v['lg_id'],$num);
+            $this->verify_odds($data['game_code'],$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(empty($v['bet_odds'])){
-                $msg = '第'.$num.'条'.lang('Errors','Api')->get('error-5106');
-                Render([], '5106',$msg);
-            }
             //所需付款总金额计算
             $this->order_money += $v['bet_amount'];
             //根据类型分组
@@ -170,10 +163,9 @@ class BetOrder extends BaseController{
             }
         }
         //获取用户金额信息
-//        $getAccount = $this->M->getAccount($userInfo['account_identity']);
-//        if(!$this->M->verifyMoney($this->order_money,$getAccount['cash'])){
-//            Render('', '4204',lang('Errors','Api')->get('error-4204'));
-//        }
+        if(!$this->M->verifyMoney($this->order_money,$userInfo['cash'])){
+            Render('', '4204',lang('Errors','Api')->get('error-4204'));
+        }
         //执行数据插入
         try {
             _beginTransaction();//开启事务
@@ -182,11 +174,12 @@ class BetOrder extends BaseController{
                 foreach($v as $kk => $vv){
                     $this->bet_money += $vv['bet_amount'];
                 }
+                $OrderID = OrderID();
                 $order =[
                     'info_identity' => UUID(),
                     'account_name' => $userInfo['account'],
                     'account_identity' => $userInfo['account_identity'],
-                    'order_id' => OrderID(),
+                    'order_id' => $OrderID,
                     'game_name' => $k,
                     'game_no'  => "",
                     'money' => $this->bet_money, //投注金额
@@ -197,7 +190,7 @@ class BetOrder extends BaseController{
                 if(!$insert){
                     Render('','-1005',lang('errors','Api')->get('error-3205'));
                 }
-                $insertMoney  = $this->M->insertMoney($userInfo['account_identity'],$v['bet_amount'],$v['order_id'],1,"",$userInfo);
+                $insertMoney  = $this->M->insertMoney($userInfo['account_identity'],$this->bet_money,$OrderID,1,"",$userInfo);
                 if($insertMoney!=1){
                     Render('', $insertMoney,lang('Errors','Api')->get('error'.$insertMoney));
                 }
@@ -229,7 +222,7 @@ class BetOrder extends BaseController{
      * @param  [type] $lg_id     联赛ID
      * @param  [type] $num 循环键值
      */
-    public  function verify_league($game_code,$lg_id,$num = 0){
+    public  function verify_league($game_code,$lg_id,$num){
         if(empty($lg_id)){
             $msg = '第'.$num.'条'.lang('Errors','Api')->get('error-5104');
             Render([], '5104',$msg);
@@ -251,7 +244,7 @@ class BetOrder extends BaseController{
      * @param  [type] $match_id  赛事ID
      * @param  [type] $num 循环键值
      */
-    public  function verify_match($game_code,$match_id,$num = 0){
+    public  function verify_match($game_code,$match_id,$num){
         if(empty($match_id)){
             $msg = '第'.$num.'条'.lang('Errors','Api')->get('error-5103');
             Render([], '5103',$msg);
@@ -272,7 +265,7 @@ class BetOrder extends BaseController{
      * @param  [type] $game_code 球类代码
      * @param  [type] $num 第几条
      */
-    public  function verify_gameType($game_code,$num = 0){
+    public  function verify_gameType($game_code,$num){
         if(empty($game_code)){
             $msg = '第'.$num.'条数据'.lang('Errors','Api')->get('error-5102');
             Render([], '5102', $msg);
@@ -290,16 +283,32 @@ class BetOrder extends BaseController{
      * @param  [type] $game_code 球类代码
      *  @param  [type] $odds_id 赔率ID
      */
-    public function verify_odds($game_code,$odds_id,$odds_only){
-        if(empty($odds_id)||$odds_only){
-            Render([], '7029', lang('Errors','Api')->get('error-7029'));
+    public function verify_odds($game_code,$odds_id,$odds_only,$odds,$condition,$num){
+        if(empty($odds_id)||$odds_only||$condition||$odds){
+            $msg = '第'.$num.'条数据'.lang('Errors','Api')->get('error-7029');
+            Render([], '7029', $msg);
         }
         //根据球类代码 获取相关model
         $models = getModels($game_code);
         $model_odds = $models['model_odds'];
-        $info = lm($model_odds,'Sports')->where(['id',$odds_id,'odds_id'])->first();
-        if(empty($info)){
-            Render([], '7029', lang('Errors','Api')->get('error-7029'));
+        $model_odds_record = $models['model_odds_record'];
+        $info = lm($model_odds,'Sports')
+            ->join($model_odds_record,$model_odds_record.'.odds_only',$model_odds.'.odds_only')
+            ->select($model_odds_record.'.odds',$model_odds_record.'.condition')
+            ->where($model_odds.'.odds_only',$odds_only)
+            ->first();
+        if(!$info){
+            $msg = '第'.$num.'条数据'.lang('Errors','Api')->get('error-7029');
+            Render([], '7029', $msg);
+        }
+        $info->toarray();
+        if($odds != $info['odds']){
+            $msg = '第'.$num.'条数据'.lang('Errors','Api')->get('error-7029');
+            Render([], '7029', $msg);
+        }
+        if($condition = $info['condition']){
+            $msg = '第'.$num.'条数据'.lang('Errors','Api')->get('error-7029');
+            Render([], '7029', $msg);
         }
         return $info;
     }

+ 76 - 13
Application/Api/Controller/UserBuy.php

@@ -12,20 +12,17 @@ use App\Api\Model\Lottery_money;
 use App\Api\Model\Lottery_money_log;
 
 use App\Api\Model\MoneyBuy;
+use App\Api\Model\MoneyRecharge;
+use App\Api\Model\MoneyPrize;
 use Biz\Common\Common;
 use Biz\Game\GameList;
 use System\Lang;
+use \Exception;
 
 
 class UserBuy extends BaseController {
 
-    private $moneyBuyClass;
-
-    public function init() {
-        // 实例化
-        $this -> moneyBuyClass = new MoneyBuy();
-    }
-
+    public function init() {}
 
     /**
      * 投注记录
@@ -34,10 +31,20 @@ class UserBuy extends BaseController {
      * @return array JsonString
      */
     public function bettingRecord() {
-        // 获取下注信息
-        $result = $this -> moneyBuyClass -> bettingRecord();
+        $code = 0;
+        $msg = lang('Common','Api') -> get('error');
+        try{
+            $moneyBuyClass = new MoneyBuy();
+            // 获取下注信息
+            $result = $moneyBuyClass -> bettingRecord();
+            $code = 1;
+            $msg = lang('Index','Api') -> get('success');
 
-        Render($result, '1', 'success');
+            Render($result, $code, $msg);
+        } catch (Exception $e) {
+            Render([], $code, $msg);
+            //Render([], $code, $e->getMessage());
+        }
     }
 
     /**
@@ -47,9 +54,65 @@ class UserBuy extends BaseController {
      * @return array JsonString
      */
     public function moneyRecord() {
-        // 获取盈亏记录
-        $result = $this -> moneyBuyClass -> moneyRecord();
+        $code = 0;
+        $msg = lang('Common','Api') -> get('error');
+        try{
+            $moneyBuyClass = new MoneyBuy();
+            // 获取盈亏记录
+            $result = $moneyBuyClass -> moneyRecord();
+            $code = 1;
+            $msg = lang('Index','Api') -> get('success');
+
+            Render($result, $code, $msg);
+        } catch (Exception $e) {
+            Render([], $code, $msg);
+            //Render([], $code, $e->getMessage());
+        }
+    }
+
+    /**
+     * 充值记录
+     *
+     * @access public
+     * @return array JsonString
+     */
+    public function rechargeRecord() {
+        $code = 0;
+        $msg = lang('Common','Api') -> get('error');
+        try{
+            $moneyRechargeClass = new MoneyRecharge();
+            // 获取充值记录
+            $result = $moneyRechargeClass -> rechargeRecord();
+            $code = 1;
+            $msg = lang('Index','Api') -> get('success');
+
+            Render($result, $code, $msg);
+        } catch (Exception $e) {
+            Render([], $code, $msg);
+            //Render([], $code, $e->getMessage());
+        }
+    }
+
+    /**
+     * 中奖记录
+     *
+     * @access public
+     * @return array JsonString
+     */
+    public function prizeRecord() {
+        $code = 0;
+        $msg = lang('Common','Api') -> get('error');
+        try{
+            $moneyRechargeClass = new MoneyPrize();
+            // 获取充值记录
+            $result = $moneyRechargeClass -> prizeRecord();
+            $code = 1;
+            $msg = lang('Index','Api') -> get('success');
 
-        Render($result, '1', 'success');
+            Render($result, $code, $msg);
+        } catch (Exception $e) {
+            Render([], $code, $msg);
+            //Render([], $code, $e->getMessage());
+        }
     }
 }

+ 1 - 0
Application/Api/Lang/Common.php

@@ -1,5 +1,6 @@
 <?php
 return array(
+    'error' => '未知错误',
 	'cash fail' => '提现失败',
 	'no withdraw data' => '没有提现数据',
 	'notice no identity' => '通知内容没有传入ID',

+ 1 - 0
Application/Api/Lang/Errors.php

@@ -1,6 +1,7 @@
 <?php
 
 return array(
+    'error-0' => '错误',
     'error-1' => '成功',
     'error1' => '成功',
     'error2' => '追号成功',

+ 8 - 8
Application/Api/Model/MoneyBuy.php

@@ -70,10 +70,10 @@ class MoneyBuy extends Model {
     public function bettingRecord()
     {
         // 获取用户信息
-        $moneyClass = new AccountManager;
-        $userInfo = $moneyClass -> getCurrentUser();
+        $accountManagerClass = new AccountManager;
+        $userInfo = $accountManagerClass -> getCurrentUser();
         if (empty($userInfo['identity'])) {
-            return -4010;
+            Render([], '2001', lang('Common','Api') -> get('user does login'));
         }
         $moneyBuyWhere = array();
         // 用户ID
@@ -114,7 +114,7 @@ class MoneyBuy extends Model {
         // 获取投注记录
         $result['list'] = $moneyBuy -> moneyBuy($moneyBuyWhere, $moneyBuyBetween, $begin, $pageSize);
         // 获取记录总数
-        $result['total'] = $moneyBuy -> moneyBuyTotal($moneyBuyWhere, $moneyBuyBetween);
+        $result['total'] = count($result['list']);
         // 总页数计算
         $result['countPage'] = ceil($result['total'] / $pageSize);
         $result['currentPage'] = $currentPage;
@@ -131,10 +131,10 @@ class MoneyBuy extends Model {
     public function moneyRecord()
     {
         // 获取用户信息
-        $moneyClass = new AccountManager;
-        $userInfo = $moneyClass -> getCurrentUser();
+        $accountManagerClass = new AccountManager;
+        $userInfo = $accountManagerClass -> getCurrentUser();
         if (empty($userInfo['identity'])) {
-            return -4010;
+            Render([], '2001', lang('Common','Api') -> get('user does login'));
         }
         $moneyRecordWhere = array();
         // 用户ID
@@ -155,7 +155,7 @@ class MoneyBuy extends Model {
         // 获取盈亏记录
         $result['list'] = $moneyRecord -> moneyRecord($moneyRecordSelect, $moneyRecordWhere, $moneyRecordBetween, $begin, $pageSize);
         // 获取记录总数
-        $result['total'] = $moneyRecord -> moneyRecordTotal($moneyRecordWhere, $moneyRecordBetween);
+        $result['total'] = count($result['list']);
         // 总页数计算
         $result['countPage'] = ceil($result['total'] / $pageSize);
         $result['currentPage'] = $currentPage;

+ 54 - 0
Application/Api/Model/MoneyPrize.php

@@ -0,0 +1,54 @@
+<?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 MoneyPrize extends Model {
+    /**
+     * 中奖记录
+     *
+     * @access public
+     * @return String
+     */
+    public function prizeRecord()
+    {
+        // 获取用户信息
+        $accountManagerClass = new AccountManager;
+        $userInfo = $accountManagerClass -> getCurrentUser();
+        if (empty($userInfo['identity'])) {
+            Render([], '2001', lang('Common','Api') -> get('user does login'));
+        }
+        $prizeRecordWhere = array();
+        // 用户ID
+        $prizeRecordWhere['account_identity'] = $userInfo['identity'];
+        $prizeRecordWhere['status'] = 1;
+        // 时间区间
+        $startTime = isset($_POST['startTime'])? $_POST['startTime'] : '1900-01-01 00:00:00';
+        $endTime = isset($_POST['endTime'])? $_POST['endTime'] : date("Y-m-d H:m:s");
+        $prizeRecordBetween = [$startTime, $endTime];
+        // 当前页
+        $currentPage = isset($_POST['currentPage']) ? $_POST['currentPage'] : "1";
+        // 分页大小
+        $pageSize = isset($_POST['pageSize']) ? $_POST['pageSize'] : "10";
+        // 起始查询位置
+        $begin = ($currentPage - 1) * $pageSize;
+        $prizeRecord = lm('money_prize', "commons");
+        //$prizeRecordSelect = ['info_identity', 'trade_id', 'account_identity', 'money', 'money_time', 'money_type'];
+        // 获取盈亏记录
+        $result['list'] = $prizeRecord -> prizeRecord($prizeRecordWhere, $prizeRecordBetween, $begin, $pageSize);
+        // 获取记录总数
+        $result['total'] = count($result['list']);
+        // 总页数计算
+        $result['countPage'] = ceil($result['total'] / $pageSize);
+        $result['currentPage'] = $currentPage;
+
+        return $result;
+    }
+}

+ 42 - 0
Application/Api/Model/MoneyRecharge.php

@@ -7,6 +7,7 @@
  */
 namespace App\Api\Model;
 use \System\Model;
+use Biz\Account\AccountManager;
 
 class MoneyRecharge extends Model {
 
@@ -66,4 +67,45 @@ class MoneyRecharge extends Model {
         return $save;
     }
 
+    /**
+     * 充值记录
+     *
+     * @access public
+     * @return String
+     */
+    public function rechargeRecord()
+    {
+        // 获取用户信息
+        $accountManagerClass = new AccountManager;
+        $userInfo = $accountManagerClass -> getCurrentUser();
+        if (empty($userInfo['identity'])) {
+            Render([], '2001', lang('Common','Api') -> get('user does login'));
+        }
+        $rechargeRecordWhere = array();
+        // 用户ID
+        $rechargeRecordWhere['account_identity'] = $userInfo['identity'];
+        $rechargeRecordWhere['status'] = 1;
+        // 时间区间
+        $startTime = isset($_POST['startTime'])? $_POST['startTime'] : '1900-01-01 00:00:00';
+        $endTime = isset($_POST['endTime'])? $_POST['endTime'] : date("Y-m-d H:m:s");
+        $rechargeRecordBetween = [$startTime, $endTime];
+        // 当前页
+        $currentPage = isset($_POST['currentPage']) ? $_POST['currentPage'] : "1";
+        // 分页大小
+        $pageSize = isset($_POST['pageSize']) ? $_POST['pageSize'] : "10";
+        // 起始查询位置
+        $begin = ($currentPage - 1) * $pageSize;
+        $rechargeRecord = lm('money_recharge', "commons");
+        $rechargeRecordSelect = ['id', 'info_identity', 'order_id', 'apply_time', 'money', 'recharge_type', 'money_cash'];
+        // 获取盈亏记录
+        $result['list'] = $rechargeRecord -> rechargeRecord($rechargeRecordSelect, $rechargeRecordWhere, $rechargeRecordBetween, $begin, $pageSize);
+        // 获取记录总数
+        $result['total'] = count($result['list']);
+        // 总页数计算
+        $result['countPage'] = ceil($result['total'] / $pageSize);
+        $result['currentPage'] = $currentPage;
+
+        return $result;
+    }
+
 }

+ 1 - 0
Application/Commons/Model/Money_buy.php

@@ -28,6 +28,7 @@ class Money_buy extends Model {
      */
     public function moneyBuy($moneyBuyWhere, $moneyBuyBetween, $begin, $pageSize, $orderBy = 'money_time') {
         $result = $this
+            //-> join('article','money_buy.info_identity','=','article.identity')
             -> where($moneyBuyWhere)
             -> whereBetween('money_time', $moneyBuyBetween)
             -> offset($begin)

+ 41 - 0
Application/Commons/Model/Money_prize.php

@@ -0,0 +1,41 @@
+<?php
+/**
+*------Create thems Model------
+*------SCWPHP  Version 1.0.0------
+*------Dev Model Jions------
+*------Create Time 2019-04-15 16:05:26------
+*/
+namespace App\Commons\Model;
+
+use \System\Model;
+
+class Money_prize extends Model {
+
+    // 对象表
+    protected $table = 'money_prize';
+    public $timestamps = false;
+
+    /**
+     * 中奖记录
+     *
+     * @access public
+     * @param mixed $prizeRecordWhere 查询条件
+     * @param mixed $prizeRecordBetween 查询条件区间
+     * @param mixed $begin 起始查询位置
+     * @param mixed $pageSize 分页大小
+     * @param mixed $orderBy 排序字段
+     * @return array JsonString
+     */
+    public function prizeRecord($prizeRecordWhere, $prizeRecordBetween, $begin, $pageSize, $orderBy = 'money_time') {
+        $result = $this
+            //-> join('article','money_prize.info_identity','=','article.identity')
+            -> where($prizeRecordWhere)
+            -> whereBetween('money_time', $prizeRecordBetween)
+            -> offset($begin)
+            -> limit($pageSize)
+            -> orderBy($orderBy)
+            -> get();
+
+        return $result;
+    }
+}

+ 25 - 0
Application/Commons/Model/Money_recharge.php

@@ -164,4 +164,29 @@ protected $table = 'money_recharge';
         ];
         return $arr[$key];
     }
+
+    /**
+     * 充值记录
+     *
+     * @access public
+     * @param mixed $rechargeRecordSelect 查询条件字段
+     * @param mixed $rechargeRecordWhere 查询条件
+     * @param mixed $rechargeRecordBetween 查询条件区间
+     * @param mixed $begin 起始查询位置
+     * @param mixed $pageSize 分页大小
+     * @param mixed $orderBy 排序字段
+     * @return array JsonString
+     */
+    public function rechargeRecord($rechargeRecordSelect, $rechargeRecordWhere, $rechargeRecordBetween, $begin, $pageSize, $orderBy = 'apply_time') {
+        $result = $this
+            -> select($rechargeRecordSelect)
+            -> where($rechargeRecordWhere)
+            -> whereBetween('apply_time', $rechargeRecordBetween)
+            -> offset($begin)
+            -> limit($pageSize)
+            -> orderBy($orderBy)
+            -> get();
+
+        return $result;
+    }
 }

+ 23 - 0
Application/Commons/Model/Money_transfer.php

@@ -0,0 +1,23 @@
+<?php
+/**
+*------Create thems Model------
+*------SCWPHP  Version 1.0.0------
+*------Dev Model Jions------
+*------Create Time 2019-04-15 16:05:26------
+*/
+namespace App\Commons\Model;
+
+use \System\Model;
+
+class Money_transfer extends Model {
+
+    // 对象表
+    protected $table = 'money_transfer';
+    public $timestamps = false;
+
+    public function  findOneByAttr($attr,$val){
+        $model = $this->where($attr,$val)->first();
+        return $model ;
+    }
+
+}

+ 77 - 0
Application/Commons/Model/Wagent.php

@@ -0,0 +1,77 @@
+<?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 Wagent extends Model {
+
+protected $table = 'wagent';
+
+    function getByName($name){
+        $data = $this->where('agent_name', $name)->first();
+
+        if (!$data) {
+            return false;
+        }
+        return $data;
+    }
+
+
+    //验证是否正确
+    function   CheckKey($model , $parentString,$keyString){
+        //token超时
+        if ( time()  > $model->auth_expire){
+                return -1 ;
+         }
+
+        if (empty($model->auth_token)){
+            return -3;
+        }
+
+        if ($model->status != 1){
+            return -4 ;
+        }
+
+        //验证不通过
+        $md5String = md5($parentString.$model->auth_token);
+
+        if ( $md5String != $keyString){
+            return -2;
+        }
+
+        return  1  ;
+
+    }
+
+
+    public  function   TokenGetAndUpdate($agentName,$agentKey,$agentSecret){
+        $model = $this->getByName($agentName);
+
+        if (!$model){
+            return false;
+        }
+
+        if ($agentKey != $model->agent_key ||  $agentSecret!= $model->agent_secret){
+            return  false;
+        }
+
+        if ($model->status != 1){
+            return false;
+        }
+
+        if ( intval($model->auth_expire) < time() ){
+            $model->auth_expire = time () +   3600*24 ;
+            $model->auth_token = md5($model->agent_name.$model->agent_key.uniqid(mt_rand())) ;
+            $model->save();
+        }
+
+        return $model;
+
+    }
+
+
+}

+ 69 - 22
Application/InApi/Controller/Index.php

@@ -10,43 +10,44 @@ namespace App\InApi\Controller;
 
 use BaseController\Controller;
 use Biz\Game\GameLogic;
+use App\Commons\Model\Wagent;
 
 class Index extends Controller {
     //用户上传参数数组;
     private $paras = [] ;
-
+    private $parasString = '';
     private $userKey = '' ;
+    private $model = null ;
+    private $logic = null ;
 
     //默认返回数据格式
     private $defformat = 'json' ;
 
     //所有请求入口
 	public function dobusiness() {
-	    $this->ParasCheck();
-        $method = $this->ActionMap()[$this->paras['method']];
-        $logic = new GameLogic($this->paras,$this->userKey);
-
-        if ( (new  \ReflectionClass($logic))->hasMethod($method)){
-            $ret = $logic->$method();
-            Render($ret['datas'],$ret['status'],$ret['msg']);
-        }
-        Render('',10009,lang('Errors','Sports')->get('error-10009'));
+	   $this->doLogic();
 	}
 
 	public function   getdata(){
+        $this->doLogic();
+    }
 
+
+    private function  doLogic(){
         $this->ParasCheck();
+        $this->AgentKeyCheck();
+
         $method = $this->ActionMap()[$this->paras['method']];
-        $logic = new GameLogic($this->paras);
-        if ( (new  \ReflectionClass($logic))->hasMethod($method)){
-            $ret = $logic->$method();
+        $this->logic = new GameLogic($this->paras,$this->userKey,$this->model);
+
+        if ( (new  \ReflectionClass($this->logic))->hasMethod($method)){
+            $ret = $this->logic->$method();
             Render($ret['datas'],$ret['status'],$ret['msg']);
         }
         Render('',10009,lang('Errors','Sports')->get('error-10009'));
 
     }
 
-
 	private  function ActionMap(){
 	    $maps = [
 	        'caie' => 'CheckAccountIsExist',
@@ -68,18 +69,14 @@ class Index extends Controller {
             'gsvi' => 'GetSportVendorId',
         ];
 	    return $maps;
-
     }
 
 
     //输入参数校验
 	private function  ParasCheck(){
-        $params = $_REQUEST['params'];
-        $Key = $_REQUEST['Key'];
-        $key1 = md5($params.$this->userKey);
-        if ($Key != $key1){
-            Render('',10008,lang('Errors','Sports')->get('error-10008'));
-        }
+        $this->parasString = $params = $_REQUEST['params'];
+        $this->userKey = $_REQUEST['Key'];
+
         $arr = explode('$',base64_decode($params));
 
         if  (is_array($arr)){
@@ -91,6 +88,8 @@ class Index extends Controller {
                     $this->paras[$tmpkey] = $val;
                 }
             }
+        }else{
+            Render('',10009,lang('Errors','Sports')->get('error-10009'));
         }
 
         $allmap = $this->ActionMap();
@@ -103,12 +102,39 @@ class Index extends Controller {
         $format = isset($this->paras['format']  ) ?   strtolower(trim($this->paras['format'])) : '';
         if ($format =='' || !in_array($format,['json','xml'])){ $format = $this->defformat;   }
         S('CUR_RETURN_FORMAT',$format);
+    }
+
+    //Key验证
+    private  function   AgentKeyCheck(){
+        $agent = isset($this->paras['agent']) ?  trim($this->paras['agent']) : '' ;
+        if (empty($agent)){
+            Render('key_error',0,'key_error');
+        }
+
+        $model = (new Wagent)->getByName($agent);
+        if (empty($model)){
+            Render('10',0,'The agent not exist');
+        }
+        $ret = $model->CheckKey($model,$this->parasString,$this->userKey) ;
+        if ( $ret!=1 ){
+            if ($ret == -1){
+                Render('10',0,'Token overTime,please Refresh!');
+            }
+            Render('10',0,'key check error!');
+        }
 
+        $this->model = $model ;
+        return  true;
     }
 
 
     //调试地址生成用
     public function  makeurl(){
+        $remotip = $_SERVER['REMOTE_ADDR'];
+        if (!($remotip =='127.0.0.1' || substr($remotip,0,7) == '192.168')){
+            //只能在内网调试使用
+            exit;
+        }
 
 	    $paras = $_REQUEST;
 	    unset($paras['_url']);
@@ -118,10 +144,11 @@ class Index extends Controller {
 
 	    $strArr = array() ;
         foreach ($paras as $key=>$val){
+            if ($key=='agent'){   $val = 'test1agent' ;   }
             array_push($strArr,$key.'='.$val);
         }
         $string = implode ('$',$strArr);
-	    $key = md5(base64_encode($string).$this->userKey);
+	    $key = md5(base64_encode($string).'58f306c11e6a9d4cc74723bb76b17500');
 
 	    //$url = 'http://sports.5gogo.com/Inapi-index/dobusiness?params='.base64_encode($string).'&Key='.$key;
         $url = 'http://www.kaiyou-dev.com/Inapi-index/dobusiness?params='.base64_encode($string).'&Key='.$key;
@@ -129,4 +156,24 @@ class Index extends Controller {
 
     }
 
+
+    //客户获取token用于 Key 的生成使用
+    public function  getToken(){
+
+            $agengname = $_REQUEST['name'] ;
+            $key = $_REQUEST['key'] ;
+            $secret = $_REQUEST['secret'] ;
+
+            $model  = (new Wagent)->TokenGetAndUpdate($agengname,$key,$secret);
+            if (!$model){
+                    Render('',0,'get Token false!');
+            }
+
+            Render(['token'=>$model->auth_token],1,'success');
+
+    }
+
+
+
+
 }

+ 66 - 23
Application/Sports/Controller/MatchList.php

@@ -32,16 +32,19 @@ class  MatchList extends Controller {
          $data['info'][0]['name'] = '今日赛事';
          $data['info'][0]['code'] = 'today';
          $data['info'][0]['count'] = lm('st_zq_competition','Sports')
-             ->where('source',$this->source['source'])
+             ->join('st_zq_league','st_zq_league.lg_id','st_zq_competition.lg_id')
              ->where(getState('StToday'))
+             ->where('st_zq_competition.source',$this->source['source'])
+             ->distinct('st_zq_competition.match_id')
              ->count('*');
         //查询明日赛事
          $data['info'][1]['name'] = '明日赛事';
          $data['info'][1]['code'] = 'tomorrow';
          $data['info'][1]['count'] = lm('st_zq_competition','Sports')
-             ->where('source',$this->source['source'])
-             ->where('match_date','tomorrow')
-             ->where('status','0')
+             ->join('st_zq_league','st_zq_league.lg_id','st_zq_competition.lg_id')
+             ->where('st_zq_competition.source',$this->source['source'])
+             ->where('st_zq_competition.match_date','tomorrow')
+             ->where('st_zq_competition.status','0')
              ->count('*');
         //受欢迎的欧洲赛事
          $data['info'][2]['name'] = '受欢迎的欧洲赛事';
@@ -446,13 +449,15 @@ class  MatchList extends Controller {
         $where = [];
         if(!empty($date)){
             if($date == 'morning'){
-                $where[$st_competition.'.is_morningplate'] = 1;
+                $where=[[$st_competition.'.is_morningplate',1],
+                [$st_competition.'.match_date','>',date("Y-m-d",strtotime("+6 day"))]];
+            }else if($date == 'today'){
+                $where  = getState('StToday');
             }else {
                 $where[$st_competition.'.match_date'] = $date;
             }
         }
 
-
         $data['type']  = lm('GameType', 'Sports')
             ->where('game_code',$gameType)
             ->value('game_name');
@@ -468,6 +473,7 @@ class  MatchList extends Controller {
             ->where($st_competition.'.status', '<', '2')
             ->get()
             ->toArray();
+
         //洲下所有联赛
         $area = lm($st_league,"Sports")
             ->join($st_competition,$st_competition.'.lg_id',$st_league.'.lg_id')
@@ -478,7 +484,6 @@ class  MatchList extends Controller {
             ->where($st_league.'.name_chinese','like','%'.$search.'%')
             ->where($where)
             ->where($st_competition.'.status', '<', '2')
-            ->where(getState('all',$getModels['model_match']))
             ->get()
             ->toArray();
         //统计国家联赛下的赛事
@@ -549,7 +554,8 @@ class  MatchList extends Controller {
             $whereDate = [];
             if(!empty($data['matchDate']) ){
                 if($data['matchDate']== "morning"){
-                    $whereDate = ['is_morningplate'=> 1];
+                    $whereDate = [['is_morningplate',1],
+                        ['match_date','>',date("Y-m-d",strtotime("+6 day"))]];
                 }else{
                     $whereDate = ['match_date'=>$data['matchDate']];
                 }
@@ -578,16 +584,30 @@ class  MatchList extends Controller {
             $where = getState($type_code);
 
             $gameData = [];
+
             foreach ($game as $key=>$type){
-                $matchModel = getModels($type['game_code']);
-                $matchNum = lm($matchModel['model_match'], 'Sports')
-                ->where($this->source)
-                ->where($where)
-                ->count('*');
-                //获取满足状态的球类/去除冠军类
-                if($matchNum != 0 and $type['game_code']!='gj'){
-                    $gameData[] = $type;
+                if($type_code != 'StChampion'){
+                    $matchModel = getModels($type['game_code']);
+                    $matchNum = lm($matchModel['model_match'], 'Sports')
+                        ->where($this->source)
+                        ->where($where)
+                        ->count('*');
+                    //获取满足状态的球类/去除冠军类
+                    if($matchNum != 0 and $type['game_code']!='gj'){
+                        $gameData[] = $type;
+                    }
+                }else{
+                    $matchModel = getModels($type['game_code']);
+                    $matchNum = lm($matchModel['model_odds'], 'Sports')
+                        ->where($this->source)
+                        ->where($where)
+                        ->count('*');
+                    //获取满足状态的球类/去除冠军类
+                    if($matchNum != 0 and $type['game_code']!='gj'){
+                        $gameData[] = $type;
+                    }
                 }
+
             }
 
             Render($gameData, '1', lang('Tips','Sports')->get('success'));
@@ -794,14 +814,37 @@ class  MatchList extends Controller {
     public function getOddsCode(){
         $game_code = lm('GameType', 'Sports')->select('game_code')->where('status',1)->get()->toArray();
 
-        $oddsCodeData = [];
-        foreach ($game_code as $k =>$v){
-            $oddsCodeData[$v['game_code']] = lm('st_odds_code','Sports')
-                ->select('id','odds_code','odds_name','p_id','type')
-                ->where('game_type', 'like', '%' . $v['game_code'] . '%')
-                ->get()->toarray();
+//        $oddsCodeData = [];
+//        foreach ($game_code as $k =>$v){
+//            $oddsCodeData[$v['game_code']] = lm('st_odds_code','Sports')
+//                ->select('id','p_id','odds_code','odds_name','type')
+//                ->where('game_type', 'like', '%' . $v['game_code'] . '%')
+////                ->groupBy('id','p_id','odds_code','odds_name','type')
+//                ->get()->toarray();
+//        }
+
+        $p_code = lm('st_odds_code','Sports')
+                ->select('id','p_id','odds_code','odds_name','type')
+                ->where('p_id',0)
+                ->get();
+        foreach ($p_code as $k=>$v){
+               $v->below = lm('st_odds_code','Sports')
+                ->select('id','p_id','odds_code','odds_name','type')
+                ->where('p_id',$v['id'])
+                ->get();
         }
 
-        Render($oddsCodeData, '1', lang('Tips','Sports')->get('success'));
+        Render($p_code, '1', lang('Tips','Sports')->get('success'));
+    }
+
+    /**
+     * 获取 欧洲冠军杯数据
+     */
+    public function getUEFAChampions (){
+
+        $data = $this->getTypeData->getUEFAChampions($this->source);
+
+        Render($data, '1', lang('Tips','Sports')->get('success'));
+
     }
 }

+ 8 - 0
Biz/Account/Repository/AccountRepository.php

@@ -97,6 +97,7 @@ class AccountRepository {
         $parent_id = isset($data['parent_id']) ? $data['parent_id'] : '';
         $parent_path = isset($data['parent_path']) ? $data['parent_path'] : '';
         $level = isset($data['level']) ? $data['level'] : '';
+        $wagent_name = isset($data['wagent_name']) ? $data['wagent_name'] : '';
 
         $accountDetailed = [
             'phone' => $phone,
@@ -111,16 +112,23 @@ class AccountRepository {
             'name' => $name,
             'qq' => $qq,
             'open_invitation' => $open_invitation,
+            
         ];
         if (!empty($parent_id)) {
             $accountDetailed['parent_id'] = $parent_id;
         }
+				
         if (!empty($parent_path)) {
             $accountDetailed['parent_path'] = $parent_path;
         }
         if (!empty($level)) {
             $accountDetailed['level'] = $level;
         }
+		
+		if (!empty($wagent_name)){
+			$accountDetailed['wagent_name'] = $wagent_name,
+		}
+		
         $res = lm('account_detailed', 'Commons')->insert($accountDetailed);
         if (!$res) {
             return -30101;

+ 79 - 14
Biz/Game/GameLogic.php

@@ -9,17 +9,19 @@
 namespace Biz\Game;
 
 use  Biz\Account\AccountManager;
+use  App\Commons\Model\Money_transfer;
 
 class GameLogic
 {
     private $paras = [] ;
     private $userKey = '' ;
+    private $wagetnModel = null ;
 
-
-    public function  __construct($paras,$userKey)
+    public function  __construct($paras,$userKey,$wagentModel)
     {
         $this->paras = $paras;
         $this->userKey = $userKey;
+        $this->wagetnModel =  $wagentModel ;
     }
 
 
@@ -39,6 +41,8 @@ class GameLogic
         if (empty($username)){
             return $this->makeret(0,'请求参数缺失','key_error');
         }
+        $username = $this->wagetnModel->agent_pre.$username;
+
         $ac = new AccountManager();
         $ret = $ac->getAccount($username);
         if ($ret){
@@ -66,11 +70,11 @@ class GameLogic
         $remark['limitroulette'] = isset($this->paras['limitroulette']) ? intval($this->paras['limitroulette']) : 0 ;
         $remark =   json_encode($remark);
 
-
         if (empty($username)   ||  empty($password) ){
             return $this->makeret(0,'请求参数缺失','key_error');
         }
 
+        $username = $this->wagetnModel->agent_pre.$username;
         $ac = new AccountManager();
         $userInfo = $ac->getAccount($username);
         if ($userInfo){
@@ -85,6 +89,7 @@ class GameLogic
             return $this->makeret(0,'false',2);
         }
 
+        $wagent_name = isset($this->paras['agent']) ?  $this->paras['agent'] : '';
         $postdatas = [
             'account' => $username,
             'password' => $password,
@@ -92,6 +97,7 @@ class GameLogic
             'name' =>  $username,
             'phone' => uniqid('agent_'),
             'remark' => $remark,
+            'wagent_name' => $wagent_name,
         ];
         $ac = new AccountManager();
         $ret = $ac->register($postdatas);
@@ -126,37 +132,94 @@ class GameLogic
     //GetBalance(查询余额)
     public function GetBalance(){
 
+        $accountModel= $this->accountAndPassCheck();
+        $account_identity = $accountModel->account_indentity;
+
+        $parentinfo = lm('account_detailed', 'commons')->where('account_identity', $account_identity)->first();
+        if (empty($parentinfo)) {
+            return $this->makeret(1,'账号记录不存在','0');
+        }
+        return $this->makeret(1,'success',$parentinfo->cash) ;
+
+    }
+
+
+    public function  accountAndPassCheck(){
         $username= isset($this->paras['username']) ?  trim($this->paras['username']) : '';
         $password =  isset($this->paras['password']) ?  trim($this->paras['password']) : '';
 
         if (empty($username) || empty($password) ){
-            return $this->makeret(0,'请求参数缺失','key_error');
+            $ret =  $this->makeret(0,'请求参数缺失','key_error');
+            Render($ret['datas'],$ret['status'],$ret['msg']);
         }
+
+        $username = $this->wagetnModel->agent_pre.$username;
         $ac = new AccountManager();
         $account = $ac->getAccount($username);
         if (!$account){
-            return $this->makeret(0,'账号不存在','key_error');
+            $ret = $this->makeret(0,'账号不存在','account_no_exist');
+            Render($ret['datas'],$ret['status'],$ret['msg']);
         }
 
         $account_identity = $account->identity;
         $passCheckret = VerPassword($account_identity,$password);
         if (!$passCheckret){
-            return $this->makeret(0,'密码有误','key_error');
+            $ret =  $this->makeret(0,'密码有误','key_error');
+            Render($ret['datas'],$ret['status'],$ret['msg']);
         }
+        return  $account ;
+    }
 
-        $parentinfo = lm('account_detailed', 'commons')->where('account_identity', $account_identity)->first();
-        if (empty($parentinfo)) {
-            return $this->makeret(1,'账号记录不存在','0');
-        }
-        return $this->makeret(1,'success',$parentinfo->cash) ;
 
-    }
 
     //TransferCredit(转帐)
     public function TransferCredit(){
 
-        $ret = $this->makeret() ;
-        return $ret;
+        $accountModel = $this->accountAndPassCheck();
+        if ($accountModel->status !=1){
+            $ret = $this->makeret(0,'false','userStatus false!') ;
+            return $ret;
+        }
+
+        $type = isset($this->paras['type']) ?  strtoupper(trim($this->paras['type'])) : '';
+        if (!in_array( $type , ['IN','OUT'])){ return $this->makeret(0,'type error!','type error');  }
+
+        $credit  = isset($this->paras['credit']) ?  floatval(trim($this->paras['credit'])) : 0;
+        if ( $credit <=0 ){   return $this->makeret(0,'credit error','credit error'); }
+
+        $billno = isset($this->paras['billno']) ?  strtoupper(trim($this->paras['billno'])) : '';
+        if (empty($billno)){ return $this->makeret(0,'billno empty','billno empty');  }
+        $transferModel = new Money_transfer();
+        $hasexit = $transferModel->findOneByAttr('billno',$billno);
+        if ( $hasexit ){   return $this->makeret(0,'billno exists','billno exists'); }
+
+        $parentinfo = lm('account_detailed', 'commons')->where('account_identity', $accountModel->account_identity)->first();
+        if (empty($parentinfo)) {  return $this->makeret(1,'account_detailed not exists','0');     }
+        $cash = $parentinfo->cash ;
+        if ( $type == 'OUT'  &&  $cash<$credit ){
+            return $this->makeret(0,'no_enough_credit','no_enough_credit');
+        }
+
+        $transferModel->account_indent = $accountModel->identity;
+        $transferModel->ordernumber = OrderID('transfer_') ;
+        $transferModel->billno = $billno;
+        $transferModel->tradeamount = $credit ;
+        $transferModel->blance = ($type == 'IN') ? $cash + $credit :  $cash - $credit ;
+        $transferModel->type = $type ;
+        $transferModel->tradtype = ($type == 'IN') ? 8 : 9 ;
+        $transferModel->tfrom = 0 ;
+        $transferModel->tto = 0 ;
+        $transferModel->agent_name = $this->wagetnModel->agent_name ;
+        $ret = $transferModel->save();
+
+        if  ($ret){
+            $ret = $this->makeret(1,'success',1) ;
+            return $ret;
+        }else{
+            $ret = $this->makeret(0,'false',0) ;
+            return $ret;
+        }
+
     }
 
     //ConfirmTransferCredit(查询转帐)
@@ -247,6 +310,8 @@ class GameLogic
         if (empty($username)   ||  empty($password) ){
             return $this->makeret(0,'请求参数缺失','key_error');
         }
+
+        $username = $this->wagetnModel->agent_pre.$username;
         $ac = new AccountManager();
         $userInfo = $ac->getAccount($username);
         if (!$userInfo){

+ 172 - 34
Biz/Match/GetmatchData.php

@@ -49,7 +49,11 @@ class GetmatchData {
                 if(empty($ret['match_date'])){
                     $match_date = date("Y-m-d");
                 }else{
-                    $match_date = $ret['match_date'];
+                    if($ret['match_date'] == 'other'){
+                        $match_date = $ret['match_date'];
+                    }else{
+                        $match_date = date("Y-m-d");
+                    }
                 }
                 $data = $this->getMorningPlate($source,$models,$where,$lg_id,$search,$match_date);
                 break;
@@ -343,6 +347,12 @@ class GetmatchData {
 
         //根据联赛id 获取联赛下 冠军玩法盘口
         if($lg_id >0){
+            $last_time = lm($model_league, 'Sports')
+                ->select('last_time')
+//                ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
+                ->where($source)
+                ->where('lg_id',$lg_id)
+                ->first()->last_time;
             $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"))
@@ -361,6 +371,7 @@ class GetmatchData {
             $sd = [];
             foreach ($p_code as $k1=>$v1){
                 foreach ($v1 as $k2=>$v2){
+                    $sd[$v2['p_code']]['last_time'] =$last_time;
                     $sd[$v2['p_code']][$v2['odds_code']][] = $v2;
                 }
             }
@@ -380,6 +391,7 @@ class GetmatchData {
         $country = lm($model_league,"Sports")
             ->leftjoin('st_country','st_country.country_id',$model_league.'.country_id')
             ->select('st_country.country_id as region_id','st_country.name_chinese as region')
+//            ->select('st_country.country_id as region_id','st_country.name_chinese as region',$model_league.'.lg_id', $model_league.'.name_chinese as league')
             ->distinct('st_country.name_chinese')
             ->where($model_league.'.source',$source['source'])
             ->where($model_league.'.name_chinese','like','%'.$search.'%')
@@ -389,6 +401,7 @@ class GetmatchData {
         $area = lm($model_league,"Sports")
             ->leftjoin('st_area','st_area.id',$model_league.'.area_id')
             ->select('st_area.id as region_id','st_area.title as region')
+//            ->select('st_area.id as region_id','st_area.title as region',$model_league.'.lg_id', $model_league.'.name_chinese as league')
             ->distinct('st_area.title')
             ->where($model_league.'.source',$source['source'])
             ->where($model_league.'.name_chinese','like','%'.$search.'%')
@@ -419,13 +432,16 @@ class GetmatchData {
                 foreach($v['league_count'] as $kk => $vv ){
                     if(!empty($model_odds)){//冠军玩法,获取赔率盘口数量
                         $where = getState('StChampion');
-                        $country[$k]['league_count'][$kk]['count'] = lm($model_odds, 'Sports')->select("p_code")
+                        $country[$k]['league_count'][$kk]['count'] = lm($model_odds, 'Sports')
+                            ->select("p_code")
                             ->where($source)
                             ->where('lg_id',$vv['lg_id'])
                             ->where($where)
 //                            ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
-                            ->groupby("p_code")->count("*");
+                            ->distinct("p_code")
+                            ->count("p_code");
                     }
+
                     if(!empty($model_match)){//非冠军玩法,获取联赛下赛事数量
                         if(empty($time)){
                             $country[$k]['league_count'][$kk]['count'] = lm($model_match, 'Sports')
@@ -435,13 +451,24 @@ class GetmatchData {
                                 ->where($where)
                                 ->count("*");
                         }else{
-                            $country[$k]['league_count'][$kk]['count'] = lm($model_match, 'Sports')
-                                ->select("match_id")
-                                ->where($source)
-                                ->where('lg_id',$vv['lg_id'])
-                                ->where($where)
-                                ->where('match_date',$time)
-                                ->count("*");
+                            if($time == 'other'){
+                                $country[$k]['league_count'][$kk]['count'] = lm($model_match, 'Sports')
+                                    ->select("match_id")
+                                    ->where($source)
+                                    ->where('lg_id',$vv['lg_id'])
+                                    ->where($where)
+                                    ->where('match_date','>',date("Y-m-d",strtotime("+1weeks",strtotime(date('Y-m-d',time())))))
+                                    ->count("*");
+                            }else{
+                                $country[$k]['league_count'][$kk]['count'] = lm($model_match, 'Sports')
+                                    ->select("match_id")
+                                    ->where($source)
+                                    ->where('lg_id',$vv['lg_id'])
+                                    ->where($where)
+                                    ->where('match_date','>',date("Y-m-d",strtotime("+1weeks",strtotime(date('Y-m-d',time())))))
+                                    ->count("*");
+                            }
+
                         }
                     }
                     if($country[$k]['league_count'][$kk]['count'] == 0){
@@ -450,6 +477,7 @@ class GetmatchData {
                 }
             }
         }
+
         //统计 地区 联赛-赛事/盘口数量
         if(!empty($area)){
             foreach($area as $k => $v) {
@@ -470,7 +498,8 @@ class GetmatchData {
                             ->where('lg_id',$vv['lg_id'])
                             ->where($where)
 //                            ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
-                            ->groupby("p_code")->count("*");
+                            ->distinct("p_code")
+                            ->count("p_code");
                     }
                     if(!empty($model_match)){//非冠军玩法,获取联赛下赛事数量
                         if(empty($time)){
@@ -480,15 +509,26 @@ class GetmatchData {
                                 ->where('lg_id',$vv['lg_id'])
                                 ->where($where)
                                 ->count("*");
-                        }else{
-                            $area[$k]['league_count'][$kk]['count'] = lm($model_match, 'Sports')
-                                ->select("match_id")
-                                ->where($source)
-                                ->where('lg_id',$vv['lg_id'])
-                                ->where($where)
-                                ->where('match_date',$time)
-                                ->count("*");
-                        }                    }
+                        }else {
+                            if ($time == 'other') {
+                                $area[$k]['league_count'][$kk]['count'] = lm($model_match, 'Sports')
+                                    ->select("match_id")
+                                    ->where($source)
+                                    ->where('lg_id', $vv['lg_id'])
+                                    ->where($where)
+                                    ->where('match_date', '>', date("Y-m-d", strtotime("+1weeks", strtotime(date('Y-m-d', time())))))
+                                    ->count("*");
+                            } else {
+                                $area[$k]['league_count'][$kk]['count'] = lm($model_match, 'Sports')
+                                    ->select("match_id")
+                                    ->where($source)
+                                    ->where('lg_id', $vv['lg_id'])
+                                    ->where('match_date','>',date("Y-m-d",strtotime("+1weeks",strtotime(date('Y-m-d',time())))))
+                                    ->where('match_date', $time)
+                                    ->count("*");
+                            }
+                        }
+                        }
                     if($area[$k]['league_count'][$kk]['count'] == 0){
                         unset($area[$k]['league_count'][$kk]);
                     }
@@ -516,20 +556,38 @@ class GetmatchData {
             ->where('lg_id',$lg_id)
             ->first();
         if(!empty($time)){
-            $matchData = lm($model_match,"Sports")
-                ->select($model_match.'.match_id',$model_match.'.tag','match_date',$model_match.'.match_time',$model_match.'.home_team',$model_match.'.guest_team')
-                ->where($source)
-                ->where($model_match.'.lg_id',$lg_id)
-                ->where($where)
-                ->where('match_date',$time)
-                ->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($time == 'other'){
+                $matchData = lm($model_match,"Sports")
+                    ->select($model_match.'.match_id',$model_match.'.tag','match_date',$model_match.'.match_time',$model_match.'.home_team',$model_match.'.guest_team')
+                    ->where($source)
+                    ->where($model_match.'.lg_id',$lg_id)
+                    ->where($where)
+                    ->where('match_date','>',date("Y-m-d",strtotime("+1weeks",strtotime(date('Y-m-d',time())))))
+                    ->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();
+            }else{
+                $matchData = lm($model_match,"Sports")
+                    ->select($model_match.'.match_id',$model_match.'.tag','match_date',$model_match.'.match_time',$model_match.'.home_team',$model_match.'.guest_team')
+                    ->where($source)
+                    ->where($model_match.'.lg_id',$lg_id)
+                    ->where($where)
+                    ->where('match_date',$time)
+                    ->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();
+            }
+
         }else{
             $matchData = lm($model_match,"Sports")
                 ->select($model_match.'.match_id',$model_match.'.tag','match_date',$model_match.'.match_time',$model_match.'.home_team',$model_match.'.guest_team')
@@ -630,4 +688,84 @@ class GetmatchData {
 
     }
 
+    /**
+     * 获取欧冠 赛事数据
+     */
+    public function getUEFAChampions($source){
+        $model = getModels('gj',1);
+        //获取滚球数据
+        $StRollBall = $this->getUEFAMatchData($model,'StRollBall',$source);
+        //获取滚球数据
+        $StToday = $this->getUEFAMatchData($model,'StToday',$source);
+        //获取滚球数据
+        $StMorningPlate = $this->getUEFAMatchData($model,'StMorningPlate',$source);
+        //获取滚球数据
+        $StChampion = $this->getUEFAMatchData($model,'StChampion',$source);
+
+        $data = [
+            'StRollBall'=>[//滚球数据
+                'typeName'=>'滚球',
+                'matchNum'=>count($StRollBall),
+                'matchData'=>$StRollBall
+            ],
+            'StToday'=>[//今日数据
+                'typeName'=>'今日',
+                'matchNum'=>count($StToday),
+                'matchData'=>$StToday
+            ],
+            'StMorningPlate'=>[//早盘数据
+                'typeName'=>'早盘',
+                'matchNum'=>count($StMorningPlate),
+                'matchData'=>$StMorningPlate
+            ],
+            'StChampion'=>[//冠军盘口
+                'typeName'=>'冠军盘口',
+                'matchNum'=>count($StChampion),
+                'matchData'=>$StChampion
+            ]
+        ];
+
+        return $data;
+    }
+
+    /**
+     * 获取欧冠 各状态赛事及赔率数据
+     */
+    public function getUEFAMatchData($model,$type_code,$source){
+        $model_league = $model['model_league'];
+        $model_match = $model['model_match'];
+        $model_odds = $model['model_odds'];
+
+        $where = getState($type_code,$model_match);
+
+        if($type_code != 'StChampion'){
+            $matchData = lm($model_match,'Sports')
+                ->leftjoin($model_league,$model_league.'.lg_id',$model_match.'.lg_id')
+                ->select($model_league.'.name_chinese',$model_match.'.match_id','match_date','match_time','tag','home_team','guest_team')
+                ->where($model_match.'.source',$source['source'])
+                ->where($where)
+                ->where($model_league.'.name_chinese','欧洲冠军杯')
+
+                ->get()->toArray();
+
+            foreach($matchData as $kk => $vv) {
+                $oddsData = lm($model_match, "Sports")
+                    ->leftjoin($model_odds, $model_odds . '.match_id', $model_match . '.match_id')
+                    ->select($model_odds . '.id','p_code', 'odds_code','odds_only', $model_odds . '.status', 'odds', 'condition', 'sort')
+                    ->where($model_match.'.source',$source['source'])
+                    ->where([$model_odds . '.match_id' => $vv['match_id']])
+//                ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
+                    ->groupBy($model_odds . '.id','p_code', 'odds_code','odds_only', $model_odds . '.status', 'odds', 'condition', 'sort')
+                    ->orderBy($model_odds . '.id','desc')
+                    ->get()
+                    ->toarray();
+                $matchData[$kk]['oddsData'] = $oddsData;
+            }
+        }else{
+            $matchData = [];
+        }
+
+        return $matchData;
+    }
+
 }

+ 35 - 45
Biz/Money/Money.php

@@ -52,21 +52,21 @@ class Money {
 			return '-4020';
 		}
 		//查询余额
-//		$getAccount = $this->getAccount($account_identity);
-//		//验证流水金额与余额是否正常
-//		$checkWater = $this->checkWater($account_identity,$getAccount['available_cash']);
-//		if($checkWater != 1){
-//			return $checkWater;
-//		}
+		$getAccount = $this->getAccount($account_identity);
+		//验证流水金额与余额是否正常
+		$checkWater = $this->checkWater($account_identity,$getAccount['available_cash']);
+		if($checkWater != 1){
+			return $checkWater;
+		}
 		//获取money_type
 		$m_type = $this->getMtype($type);
-		//判断是否加减金额
+		//判断加减金额
 		if ($m_type == 1) {
-			$nowMoney = $account['available_cash'] + $money;
-            $nowCash = $account['cash'] + $money;
+			$nowMoney = $getAccount['available_cash'] + $money;
+            $nowCash = $getAccount['cash'] + $money;
 		} else {
-			$nowMoney = $account['available_cash'] - $money;
-            $nowCash = $account['cash'] - $money;
+			$nowMoney = $getAccount['available_cash'] - $money;
+            $nowCash = $getAccount['cash'] - $money;
 		}
 		//更新用户余额
 		$updateAccountMoney = $this->updateAccountMoney($account_identity,$nowMoney, $nowCash);
@@ -74,7 +74,7 @@ class Money {
 			return $updateAccountMoney;
 		}else {
 			//插入资金详情
-			$insertDetail = $this->insertDetail($account_identity, $order_id, $money, $nowMoney, $type,$account=array());
+			$insertDetail = $this->insertDetail($account_identity, $order_id, $money, $nowMoney, $type,$account);
 			if($insertDetail !=1){
 				return $insertDetail;
 			}
@@ -100,7 +100,7 @@ class Money {
 				'cash'=> $nowCash,
 				'available_cash' => $nowMoney
 			]);
-		if($res){
+		if(!$res){
 			return '-7024';
 		}
 		return '1';
@@ -115,19 +115,19 @@ class Money {
 	 * @param  [type] $type       交易类型的数字表示
 	 * @return [type]             [description]
 	 */
-	public function insertDetail($account_identity, $order_id, $money, $nowMoney, $type,$account=array())
+	public function insertDetail($account_identity, $order_id, $money, $nowMoney, $type,$account)
 	{
 		//获取用户信息
-		if(!empty($account)){
+		if(empty($account)){
 			return '-4020';
 		}
 		//获取money_type
 		$m_type = $this->getMtype($type);
-        $trade_desc = $this->getDesc($account['account_name'], $money, $order_id, $type);
+        $trade_desc = $this->getDesc($account['account'], $money, $order_id, $type);
 		$data2 = array(
 			'info_identity' => UUID(),
 			'trade_id' => $order_id,
-			'account_name' => $account['account_name'],
+			'account_name' => $account['account'],
 			'account_identity' => $account_identity,
 			'money' => $money,
 			'money_time' => date('Y-m-d H:i:s', time()),
@@ -137,7 +137,7 @@ class Money {
 			'trade_type' => $type,
 			'trade_desc' => $trade_desc,
 		);
-		$res3 = lm($this->money_details, 'commons')->insert($data2);
+		$res3 = lm($this->money_details,'commons')->insert($data2);
 		if ($res3) {
 			return '1';
 		}
@@ -150,16 +150,15 @@ class Money {
 	 * @return [type]                   用户资金相关数组
 	 */
 	public function getAccount($account_identity) {
-		$data = array();
 		$res = lm($this->account_detailed, 'Commons')
 			->select('available_cash', 'cash', 'frozen_cash', 'account_identity')
 			->where('account_identity', $account_identity)
 			->first();
-		Render('', '4204',lang('Errors','Api')->get('error-4204'));
-		$res2 = lm($this->account_table, 'commons')->select('account')->where('identity', $account_identity)->first()->toArray();
-		$data = $res->toArray();
-		$data['account_name'] = $res2['account'];
-		return $data;
+		if(!$res){
+			Render('', '2115',lang('Errors','Api')->get('error-2115'));
+		}
+		$res->toarray();
+		return $res;
 	}
 
 	/**
@@ -238,56 +237,47 @@ class Money {
 	 * @param  string $account_name 用户名
 	 * @param  string $money        金额
 	 * @param  string $order_id     订单号
-	 * @param  int     $type         操作类型
+	 * @param  int 	$type         操作类型
 	 * @return [type]               [description]
 	 */
-	public function getDesc($account_name, $money, $order_id, $type, $game_name = '', $game_no = '')
+	public function getDesc($account_name, $money, $order_id, $type)
 	{
-		// return ;
 		switch ($type) {
 			case 1:
-				return sprintf(lang()->get('user betting'), $game_name, $game_no, $account_name, $money, $order_id);
+				return $account_name . '投注' . $money . '元。' . '订单号' . $order_id;
 				break;
 			case 2:
-				return sprintf(lang()->get('user append'), $game_name, $game_no, $account_name, $money, $order_id);
+				return $account_name . '追号' . $money . '元。' . '订单号' . $order_id;
 				break;
 			case 3:
-				return sprintf(lang()->get('user cancel'), $game_name, $game_no, $account_name, $order_id);
+				return $account_name . '撤单' . '订单号' . $order_id;
 				break;
 			case 4:
-				return sprintf(lang()->get('user prize'), $game_name, $game_no, $account_name, $money, $order_id);
+				return $account_name . '中奖' . $money . '元。' . '订单号' . $order_id;
 				break;
 			case 5:
-				return sprintf(lang()->get('user take money'), $account_name, $money, $order_id);
+				return $account_name . '申请提现' . $money . '元。' . '订单号' . $order_id;
 				break;
 			case 6:
-
-				return sprintf(lang()->get('user charge money'), $account_name, $money, $order_id);
+				return $account_name . '充值' . $money . '元。' . '订单号' . $order_id;
 				break;
 			case 7:
-				return sprintf(lang()->get('user back money'), $account_name, $money, $order_id);
+				return $account_name . '反水' . $money . '元。' . '订单号' . $order_id;
 				break;
 			case 8:
-				return sprintf(lang()->get('user return money'), $account_name, $money, $order_id);
+				return $account_name . '回水' . $money . '元。' . '订单号' . $order_id;
 				break;
 			case 9:
-				return sprintf(lang()->get('cancel prize'), $game_name, $game_no, $account_name, $money, $order_id);
+				return $account_name . '管理员扣款' . $money . '元。' . '订单号' . $order_id;
 				break;
 			case 10:
-				return sprintf(lang()->get('user empty money'), $account_name, $money, $order_id);
-				break;
-			case 11:
-				return sprintf(lang()->get('user cut money'), $account_name, $money, $order_id);
-				break;
-			case 15:
-				return sprintf(lang()->get('frozen money'), $account_name, $money, $order_id);
+				return $account_name . '佣金提成' . $money . '元。' . '订单号' . $order_id;
 				break;
 			default:
 				return '';
 				break;
 		}
 	}
-
 	/**
 	 * 返回money_type
 	 * @param  [type] $type 类型

+ 9 - 3
Library/Common/function.php

@@ -620,24 +620,29 @@ function getModels($game_code,$isJoin=1){
                 $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':
@@ -691,7 +696,8 @@ function getModels($game_code,$isJoin=1){
 		'model_league'=>$model_league,
 		'model_match'=>$model_match,
 		'model_odds'=>$model_odds,
-		'model_result' =>$model_result
+		'model_result' =>$model_result,
+		'model_odds_record' => $model_odds_record
 	];
 	return $data;
 }
@@ -725,7 +731,7 @@ function getState($type_code,$model_match = ''){
                 break;
             case 'StToday'://今日 今日未开始未结束
                 $where = [
-                    ['is_today', '=', 1],
+//                    ['is_today', '=', 1],
 
 //                    ['type', '=', '1'],
 //                    ['status', '<', '2'],
@@ -783,7 +789,7 @@ function getState($type_code,$model_match = ''){
                 break;
             case 'StToday'://今日 今日未开始未结束
                 $where = [
-                    [$model_match.'.is_today','=',1],
+//                    [$model_match.'.is_today','=',1],
 //                    [$model_match.'.type', '=', '1'],
 //                    [$model_match.'.status', '<', '2'],
                     [$model_match.'.match_date','=',date("Y-m-d")],