<?php



namespace Admin\Controller;



use Common\Controller\AdminbaseController;



class MainController extends AdminbaseController {



	



    public function index(){



    	



    	$mysql= M()->query("select VERSION() as version");



    	$mysql=$mysql[0]['version'];



    	$mysql=empty($mysql)?L('UNKNOWN'):$mysql;



    	



    	//server infomaions



    	$info = array(



    			L('OPERATING_SYSTEM') => PHP_OS,



    			L('OPERATING_ENVIRONMENT') => $_SERVER["SERVER_SOFTWARE"],



    			L('PHP_RUN_MODE') => php_sapi_name(),



    			L('MYSQL_VERSION') =>$mysql,



    			L('PROGRAM_VERSION') => SIMPLEWIND_CMS_VERSION . "&nbsp;&nbsp;&nbsp; [<a href='http://www.wancms.com' target='_blank'>WanCMS</a>]",



    			L('UPLOAD_MAX_FILESIZE') => ini_get('upload_max_filesize'),



    			L('MAX_EXECUTION_TIME') => ini_get('max_execution_time') . "s",



    			L('DISK_FREE_SPACE') => round((@disk_free_space(".") / (1024 * 1024)), 2) . 'M',



    	);



    	$this->assign('server_info', $info);


       

    	$this->display();



    }


    /**

     * 首页统计返回数据

     * @author bboyyu

     */

    public function data(){
        if(IS_POST){
            $paymodel=M('pay_ok');
            $user_model=M('users');
            $gid=I('post.gid');
            $this->assign('gid',$gid);
            if(!empty($gid)){
                $where['gid']=$gid;
            }
            $type=I('post.time');
            $start_time = I('start_time');
            $end_time = I('end_time');
            //传到前台的默认值
            $this->assign('type',$type);
            
            
            if($type=='day'){
            $mes="今日";
            $start_time=date("Y-m-d H:i:s",strtotime("-1 day"));//昨天

            $end_time=date("Y-m-d H:i:s");

            $this->assign('start_time',$start_time);
            $this->assign('end_time',$end_time);

            $begin = strtotime('-1 day');//昨天

            $end =  time();

            }elseif($type=='week'){
            $mes="本周";
            $start_time=date("Y-m-d H:i:s",strtotime('last Sunday'));

            $end_time=date("Y-m-d H:i:s");

            $this->assign('start_time',$start_time);
            $this->assign('end_time',$end_time);

            $begin = strtotime('last Sunday');//上周

            $end = time();

            }else if($type=='times'){
            $mes="";
            $this->assign('start_time',$start_time);
            $this->assign('end_time',$end_time);

            //时间戳转化
            $start_time = strtotime($start_time);

            $end_time = strtotime($end_time);

            $begin = $start_time;

            $end = $end_time;

            }
            $this->assign('mes',$mes);

        $Model = new \Think\Model(); // 实例化一个model对象 没有对应任何数据表
        $prefix=C('DB_PREFIX');
        //查询在这个时间段内注册的人数
        $aa = $Model->query("SELECT COUNT(*) as number

                            FROM ".$prefix."users

                            where `create_time` between $begin and $end AND `user_type` = '2'

                            ");
        $users=$aa['0']['number'];//时间段的网站注册人数

        $this->assign('users',$users);

        if(!empty($gid)){
            $where['gid']=$gid;
        }
        
        $where['game_status']=1;

        $where['order_status']=1;

        $where['success_time']=array('between',array($begin,$end));

        //查询该时间段内该款游戏的充值总金额
        $bb = $paymodel->where($where)->sum('pay_really_money');//时间段充值总金额

        //查询该时间段内该款游戏的充值总人数
        $cc = $paymodel->where($where)->field('uid')->group('uid')->select();//时间段充值总人数

        $cc=count($cc);

        $sumpay=$bb;

        $payuser=$cc;

        $this->assign('sumpay',$sumpay);

        $this->assign('payuser',$payuser);


        //重新执行index()一遍

        $mysql= M()->query("select VERSION() as version");



        $mysql=$mysql[0]['version'];



        $mysql=empty($mysql)?L('UNKNOWN'):$mysql;


        //server infomaions



        $info = array(



                L('OPERATING_SYSTEM') => PHP_OS,



                L('OPERATING_ENVIRONMENT') => $_SERVER["SERVER_SOFTWARE"],



                L('PHP_RUN_MODE') => php_sapi_name(),



                L('MYSQL_VERSION') =>$mysql,



                L('PROGRAM_VERSION') => SIMPLEWIND_CMS_VERSION . "&nbsp;&nbsp;&nbsp; [<a href='http://www.wancms.com' target='_blank'>WanCMS</a>]",



                L('UPLOAD_MAX_FILESIZE') => ini_get('upload_max_filesize'),



                L('MAX_EXECUTION_TIME') => ini_get('max_execution_time') . "s",



                L('DISK_FREE_SPACE') => round((@disk_free_space(".") / (1024 * 1024)), 2) . 'M',



        );



        $this->assign('server_info', $info);
        $this->display('Main/index');

            
        }


    }



}