소스 검색

代理相关

彭俊 6 년 전
부모
커밋
a6e129dc44
2개의 변경된 파일141개의 추가작업 그리고 73개의 파일을 삭제
  1. 84 73
      Application/InApi/Controller/Index.php
  2. 57 0
      Biz/Game/GameLogic.php

+ 84 - 73
Application/InApi/Controller/Index.php

@@ -5,6 +5,7 @@
  *------Dev Model Jions------
  *------Create Time 2017-06-23 15:06:45------
  */
+
 namespace App\InApi\Controller;
 
 
@@ -13,45 +14,50 @@ use Biz\Game\GameLogic;
 use App\Commons\Model\Wagent;
 
 
-class Index extends Controller {
+class Index extends Controller
+{
     //用户上传参数数组;
-    private $paras = [] ;
+    private $paras = [];
     private $parasString = '';
-    private $userKey = '' ;
-    private $model = null ;
-    private $logic = null ;
+    private $userKey = '';
+    private $model = null;
+    private $logic = null;
 
     //默认返回数据格式
-    private $defformat = 'json' ;
+    private $defformat = 'json';
 
     //所有请求入口
-	public function dobusiness() {
-	   $this->doLogic();
-	}
+    public function dobusiness()
+    {
+        $this->doLogic();
+    }
 
-	public function   getdata(){
+    public function getdata()
+    {
         $this->doLogic();
     }
 
 
-    private function  doLogic(){
+    private function doLogic()
+    {
         $this->ParasCheck();
         $this->AgentKeyCheck();
 
         $method = $this->ActionMap()[$this->paras['method']];
-        $this->logic = new GameLogic($this->paras,$this->userKey,$this->model);
+        $this->logic = new GameLogic($this->paras, $this->userKey, $this->model);
 
-        if ( (new  \ReflectionClass($this->logic))->hasMethod($method)){
+        if ((new  \ReflectionClass($this->logic))->hasMethod($method)) {
             $ret = $this->logic->$method();
-            Render($ret['datas'],$ret['status'],$ret['msg']);
+            Render($ret['datas'], $ret['status'], $ret['msg']);
         }
-        Render('',10009,lang('Errors','Sports')->get('error-10009'));
+        Render('', 10009, lang('Errors', 'Sports')->get('error-10009'));
 
     }
 
-	private  function ActionMap(){
-	    $maps = [
-	        'caie' => 'CheckAccountIsExist',
+    private function ActionMap()
+    {
+        $maps = [
+            'caie' => 'CheckAccountIsExist',
             'caca' => 'CheckAndCreateAccount',
             'gb' => 'GetBalance',
             'ptc' => 'TransferCredit',
@@ -69,119 +75,124 @@ class Index extends Controller {
             'gvvi' => 'GetVideoVendorId',
             'gsvi' => 'GetSportVendorId',
             'atin' => 'AutoLogin',
+            'todaycr' => 'ConsumptionRanking',
         ];
-	    return $maps;
+        return $maps;
     }
 
 
     //输入参数校验
-	private function  ParasCheck(){
+    private function ParasCheck()
+    {
         $this->parasString = $params = $_REQUEST['params'];
         $this->userKey = $_REQUEST['Key'];
 
-        $arr = explode('&',base64_decode($params));
+        $arr = explode('&', base64_decode($params));
 
-        if  (is_array($arr)){
-            foreach ($arr as $substring){
-                $tmp = explode("=",$substring);
-                if (isset($tmp['0'])){
+        if (is_array($arr)) {
+            foreach ($arr as $substring) {
+                $tmp = explode("=", $substring);
+                if (isset($tmp['0'])) {
                     $tmpkey = strtolower(trim($tmp['0']));
-                    $val = isset($tmp['1']) ?  trim($tmp['1']) : '' ;
+                    $val = isset($tmp['1']) ? trim($tmp['1']) : '';
                     $this->paras[$tmpkey] = $val;
                 }
             }
-        }else{
-            Render('',10010,lang('Errors','Sports')->get('error-10009'));
+        } else {
+            Render('', 10010, lang('Errors', 'Sports')->get('error-10009'));
         }
 
         $allmap = $this->ActionMap();
         $method = isset($this->paras['method']) ? $this->paras['method'] : '';
 
-        if (!isset( $allmap[$method] )){
-            Render('',10011,lang('Errors','Sports')->get('error-10009'));
+        if (!isset($allmap[$method])) {
+            Render('', 10011, lang('Errors', 'Sports')->get('error-10009'));
         }
 
-        $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);
+        $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');
+    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');
+        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',2,'Token overTime,please Refresh!');
+        $ret = $model->CheckKey($model, $this->parasString, $this->userKey);
+        if ($ret != 1) {
+            if ($ret == -1) {
+                Render('10', 2, 'Token overTime,please Refresh!');
             }
-            Render('10',0,'key check error!-'.$ret);
+            Render('10', 0, 'key check error!-' . $ret);
         }
 
-        $this->model = $model ;
-        return  true;
+        $this->model = $model;
+        return true;
     }
 
 
     //调试地址生成用
-    public function  makeurl(){
+    public function makeurl()
+    {
 
         $remotip = $_SERVER['REMOTE_ADDR'];
-        if (!($remotip =='127.0.0.1' || substr($remotip,0,7) == '192.168')){
+        if (!($remotip == '127.0.0.1' || substr($remotip, 0, 7) == '192.168')) {
             //只能在内网调试使用
             exit;
         }
 
-	    $paras = $_REQUEST;
-	    unset($paras['_url']);
-	    if (empty($paras)){
-	        exit ;
+        $paras = $_REQUEST;
+        unset($paras['_url']);
+        if (empty($paras)) {
+            exit;
         }
 
-	    $strArr = array() ;
-        foreach ($paras as $key=>$val){
+        $strArr = array();
+        foreach ($paras as $key => $val) {
             //if ($key=='agent'){   $val = 'test1agent' ;   }
-            array_push($strArr,$key.'='.$val);
+            array_push($strArr, $key . '=' . $val);
         }
-        $string = implode ('&',$strArr);
-	    $key = md5(base64_encode($string).'58f306c11e6a9d4cc74723bb76b17500');
+        $string = implode('&', $strArr);
+        $key = md5(base64_encode($string) . '58f306c11e6a9d4cc74723bb76b17500');
 
-	    if (isset($_REQUEST['debug'])){
+        if (isset($_REQUEST['debug'])) {
             $host = $_SERVER['HTTP_HOST'];
-            $url = 'http://' . $host . '/InApi-index/dobusiness?params='.base64_encode($string).'&Key='.$key;
-        }else{
-            $url = 'http://sports.5gogo.com/InApi-index/dobusiness?params='.base64_encode($string).'&Key='.$key;
+            $url = 'http://' . $host . '/InApi-index/dobusiness?params=' . base64_encode($string) . '&Key=' . $key;
+        } else {
+            $url = 'http://sports.5gogo.com/InApi-index/dobusiness?params=' . base64_encode($string) . '&Key=' . $key;
         }
 
-        Render(['url'=>$url],1,'success');
+        Render(['url' => $url], 1, 'success');
 
     }
 
 
     //客户获取token用于 Key 的生成使用
-    public function  getToken(){
+    public function getToken()
+    {
 
-            $agengname = $_POST['wagent_name'] ;
-            $key = $_POST['wagent_key'] ;
-            $secret = $_POST['wagent_secret'] ;
+        $agengname = $_POST['wagent_name'];
+        $key = $_POST['wagent_key'];
+        $secret = $_POST['wagent_secret'];
 
-            $model  = (new Wagent)->TokenGetAndUpdate($agengname,$key,$secret);
-            if (!$model){
-                    Render('',3,'get Token false!');
-            }
+        $model = (new Wagent)->TokenGetAndUpdate($agengname, $key, $secret);
+        if (!$model) {
+            Render('', 3, 'get Token false!');
+        }
 
-            Render(['token'=>$model->auth_token],1,'success');
+        Render(['token' => $model->auth_token], 1, 'success');
 
     }
 
 
-
-
 }

+ 57 - 0
Biz/Game/GameLogic.php

@@ -120,9 +120,14 @@ class GameLogic
 
     private function nameCheck($name)
     {
+        if (!preg_match("/^(\w){4,24}$/", $name)) {
+            return false;
+        }
+        /*
         if (mb_strlen($name) >= 32) {
             return false;
         }
+        */
         return true;
     }
 
@@ -499,5 +504,57 @@ class GameLogic
 
     }
 
+    //得到本代理用户消费排行(现只做下单)
+    public function ConsumptionRanking()
+    {
+        //$type = isset($this->paras['type']) ? $this->paras['type'] : 1;
+        $wagetnname = $this->wagetnModel->agent_name;
+        $prlen = strlen($this->wagetnModel->agent_pre);
+        $dtime = date("Y-m-d H") . ":00:00";
+
+        $key = $wagetnname . '' . $dtime;
+        $cache = cache($key);
+
+        if ($cache && isset($cache['data'])) {
+            return $this->makeret(1, 'success', $cache['data']);
+        }
+
+        $SQL = <<<LONGSQL
+                    select  "user".*,"money".money from  
+                    (
+                        select "identity",account  from  account  where "identity" in ( select  account_identity from    account_detailed   where   wagent_name=':name')
+                    ) as  "user" 
+                    inner join  
+                    (
+                            select account_identity,sum(money) as money from  money_details where account_identity in 
+                            ( select  account_identity from    account_detailed   where   wagent_name=':name')
+                            and  money_time>=':dtime'
+                            and  trade_type=1 
+                            group by  account_identity
+                            order by money desc limit  20 
+                    ) as  money
+                    on   "user"."identity"="money".account_identity
+                    where  money>0 
+                    order by  money desc
+LONGSQL;
+
+        $ret = DB::select($SQL, [':name' => $wagetnname, 'dtime' => $dtime]);
+        if (!$ret) {
+            $return = [];
+        } else {
+            foreach ($ret as $item) {
+                $return[] = [
+                    'name' => substr($item, $prlen),
+                    'money' => $item->money,
+                ];
+            }
+        }
+
+        $cachedata = ['datetime' => $dtime, 'data' => $return];
+        cache($key, $cachedata, 1800);
+
+        return $this->makeret(1, 'success', $return);
+    }
+
 
 }