<?php

include_once dirname(__FILE__) . '/../main.php';

$GET = query_paras();

$date = $GET['date'];
$date1 = $GET['date1'];
$uid = $GET['oid'];

$ret = array();

$endDate = strtotime("$date1");
// 计算新增人数
for ($i = 0; $i <= 999; $i++) {
    $iday = strtotime("$date   +$i   day");
    $day = date("Ymd", $iday);
    if ($iday > $endDate) {
        break;
    }
    $tableName = "tab_op_log" . $day;

    if (!daoInst()->tableExist($tableName)) {
        continue;
    }

    $arr = daoInst()->select('*')->from($tableName)
            ->where('uid')->eq($uid)
//            ->limit
            ->fetch_array();
    array_pushs($ret, $arr);
}

// <editor-fold defaultstate="collapsed" desc="辅助方法"> 

/**
 * 命令码转中文
 * @staticvar type $arr
 * @param type $cmd
 * @return type
 */
function getCmdName($cmd) {
    static $arr;
    if (null == $arr) {
        $arr = daoInst()->select('cmd,info')->from("ddt_cmd_info")->fetchAll();
    }
    foreach ($arr as $cmdInfo) {
        if ($cmdInfo->cmd == $cmd) {
            return $cmdInfo->info;
        }
    }
    return $cmd;
}

/**
 * 根据cmd添加附加提示信息
 * @param userinfomo $info
 */
function getCmdDes($info) {
    $cmd = $info->cmd;
    switch ($cmd) {
        case '6001':
            $str = "";
            $ret = json_decode($info->ret);
            $str .= "昵称:" . $ret->game->basInfo->name;
            $str .= "; 分区:" . $ret->zoneid;
            $str .= "; 等级:" . $ret->game->basInfo->level;
            return $str;
        default:
            break;
    }
    return "";
}

// </editor-fold> 

$count = count($ret);

for ($i = 0; $i < $count; $i++) {
    $ret[$i]->name = getCmdName($ret[$i]->cmd);
    $ret[$i]->des = getCmdDes($ret[$i]);
}
echo json_encode($ret);
