예제 #1
0
<?php

require '../dao/GetDao.php';
$userId = $_REQUEST['userId'];
$getDao = new GetDao();
$self = (int) $getDao->getCount($userId);
if ($self == 0) {
    echo json_encode(array('mesg' => '没有完成任何成就,匹配不成功', 'result' => false));
    exit;
}
$match_list = json_decode($getDao->match($userId))->resultArray;
if (count($match_list) == 0) {
    echo json_encode(array('mesg' => '未找到任何与您有相同成就的人,匹配不成功', 'result' => false));
    exit;
}
$index = 0;
$max = 0;
for ($i = 0; $i < count($match_list); $i++) {
    $common = $match_list[$i]->common;
    $total = $match_list[$i]->total;
    $value = round($common / sqrt($total * $self), 4);
    if ($value > $max) {
        $max = $value;
        $index = $i;
    }
}
$match = $getDao->getMatchUser($match_list[$index]->getUser, $userId);
$match->matchScore = $max;
echo json_encode($match);
<?php

require '../dao/AchieveDao.php';
date_default_timezone_set('PRC');
/**
 *	$getTime 上一次查询最后一条显示的时间,如果是第一次加载则为当前时间
 */
$getTime = empty($_REQUEST['getTime']) ? Date("Y-m-d H:i:s") : $_REQUEST['getTime'];
$userId = $_REQUEST['userId'];
$achieveDao = new AchieveDao();
$getDao = new GetDao();
$achieve = json_decode($achieveDao->getAchieveByUser($_REQUEST['userId'], $getTime));
$achieve->userGetCount = $getDao->getCount($userId);
echo json_encode($achieve);