<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
include_once dirname(__FILE__) . '/../main.php';

$params = query_paras();

$rType = $params['rType'];
if($rType == 1){
$date = $params['date'];
$zoneid = 1;//先默认是1，其他区还没有
$day = intval((strtotime($date)+28800) / 86400);
$memKey = "gamerun-loginUser-byUid-zone".$zoneid."-day_".$day;

if(!gMem()->exists($memKey)){
    $result = new stdClass();
    $dic = new stdClass();
    $dic->data1 = array(0,0,0,0,0,0,0,0);
    $dic->data2 = array(0,0,0,0,0,0,0);
    $result->data = $dic;
    
    echo json_encode($result);
} else {
    $retArr = array();
    $perArr = array();

    $curLoginUidDic = gMem()->hgetall($memKey);
    $total = count((array)$curLoginUidDic);
    $retArr[] = $total;

    $numbersArr = array(1, 2, 3, 4, 5, 6,7);
    foreach ($numbersArr as $type) {
        $typeDay = $day + $type; 
        $memKey = "gamerun-loginUser-byUid-zone".$zoneid."-day_".$typeDay;
    
        if(!gMem()->exists($memKey)){
            $retArr[] = 0;            
        } else {
            $typeDic = gMem()->hgetall($memKey);
            $n = 0;
            foreach ($curLoginUidDic as $uid=>$val) {
                if(property_exists($typeDic, $uid)){
                    $n += 1;
                }        
            }
            $retArr[] = $n;
        }   
    }

    $index = 0;
    foreach ($retArr as $num) {
        if($index == 0){
            $index += 1;
            continue;
        }

        $per = intval($num/$total*100);
        $perArr[] = $per;
    }

    $result = new stdClass();
    $result->data1 = $retArr;
    $result->data2 = $perArr;
    echo json_encode($result);
}

} else {
    $startTime = $paras['date1'];
    $endTime = $paras['date2'];
    $type = $paras['type'];

    
    
    $result = new stdClass();
    $result->data1 = $retArr;
    $result->data2 = $perArr;
    echo json_encode($result);
}


