<?php

/*
 * 查询玩家等级
 */
include_once dirname(__FILE__) . '/../main.php';


$post = query_paras();
$date = $post['date'];

$array = array();
$array2 = array();

$datas = array();
$arr = array();
$count = 0;
$iday = strtotime($date);
$day = date("Ymd", $iday);
$day_format = date("Y-m-d", $iday);

$tabName = "tab_op_log" . $day;
if (daoInst()->tableExist($tabName)) {
    $arr = daoInst()->select('param,ret')->from($tabName)
            ->where('cmd')->eq(6801)
            ->andWhere('ret')->like('%"isFirst":true%%')
            ->fetch_array();
    $count = daoInst()->select('*')->from($tabName)->leftJoin('tab_rolename')
            ->on("$tabName.uid = tab_rolename.userID")
            ->where("$tabName.cmd")->eq(6007)
            ->andWhere("tab_rolename.ts")->ge($day_format . " 00:00:00")
            ->andWhere("tab_rolename.ts")->le($day_format . " 23:59:59")
            ->count();
}

$datas[] = $count;
foreach ($arr as $value) {
    $params = json_decode($value->param);
    $gatelvl = (int) $params[0];
    if (isset($datas[$gatelvl]) && is_integer($datas[$gatelvl]) == true) {
        $datas[$gatelvl]++;
    } else {
        $datas[$gatelvl] = 1;
    }
}

$result = new stdClass();
$result->datas = $datas;
echo json_encode($result);
