177 lines
6.3 KiB
PHP
177 lines
6.3 KiB
PHP
<?php
|
|
|
|
require_once('models/User.php');
|
|
|
|
require_once('mt/RankActivity.php');
|
|
|
|
use phpcommon\SqlHelper;
|
|
|
|
use models\User;
|
|
|
|
class RankingController extends BaseAuthedController {
|
|
|
|
public function rankingList()
|
|
{
|
|
$userInfo = $this->_getOrmUserInfo();
|
|
$type = getReqVal('type', 0);
|
|
$userList = array();
|
|
{
|
|
$rows = myself()->_getSelfMysql()->execQuery(
|
|
'SELECT * FROM t_user ' .
|
|
"LIMIT 50",
|
|
array(
|
|
)
|
|
);
|
|
foreach ($rows as $row) {
|
|
array_push($userList, User::info($row));
|
|
}
|
|
}
|
|
$rankingList = array();
|
|
$ranked = 1;
|
|
foreach ($userList as $user) {
|
|
array_push($rankingList, array(
|
|
'ranked' => $ranked++,
|
|
'account_id' => $user['account_id'],
|
|
'address' => phpcommon\extractOpenId($user['account_id']),
|
|
'name' => $user['name'],
|
|
'sex' => $user['sex'],
|
|
'head_id' => $user['hero_id'],
|
|
'head_frame' => $user['head_frame'],
|
|
'level' => $user['level'],
|
|
'exp' => $user['exp'],
|
|
'rank' => $user['rank'],
|
|
'score' => $user['score'],
|
|
'gold' => $user['gold'],
|
|
'diamond' => $user['diamond'],
|
|
'hero_id' => $user['hero_id'],
|
|
'first_fight' => $user['first_fight'],
|
|
));
|
|
}
|
|
|
|
$rankingData = array(
|
|
'type' => $type,
|
|
'ranking_list' => $rankingList,
|
|
'my_ranked' => array(
|
|
'ranked' => -1,
|
|
'account_id' => $this->_getAccountId(),
|
|
'address' => $this->_getOpenId(),
|
|
'name' => $userInfo['name'],
|
|
'sex' => $userInfo['sex'],
|
|
'head_id' => $userInfo['hero_id'],
|
|
'head_frame' => $userInfo['head_frame'],
|
|
'level' => $userInfo['level'],
|
|
'exp' => $userInfo['exp'],
|
|
'rank' => $userInfo['rank'],
|
|
'score' => $userInfo['score'],
|
|
'gold' => $userInfo['gold'],
|
|
'diamond' => $userInfo['diamond'],
|
|
'hero_id' => $userInfo['hero_id'],
|
|
'first_fight' => $userInfo['first_fight'],
|
|
)
|
|
);
|
|
$this->_rspData(array(
|
|
'ranking_list' =>$rankingData
|
|
));
|
|
}
|
|
|
|
public function getOpenList()
|
|
{
|
|
$this->_rspData(array(
|
|
'list' => mt\RankActivity::getOpenList()
|
|
));
|
|
}
|
|
|
|
public function activityRankingList()
|
|
{
|
|
$rankingData = $this->internalGetActivityRankData(getReqVal('type', 0));
|
|
$this->_rspData(
|
|
$rankingData
|
|
);
|
|
}
|
|
|
|
private function internalGetActivityRankData($type)
|
|
{
|
|
$channel = 6516;
|
|
$userInfo = $this->_getOrmUserInfo();
|
|
$myRanked = array(
|
|
'ranked' => -1,
|
|
'user' => User::toSimple($userInfo),
|
|
'value' => 0,
|
|
'modifytime' => 0,
|
|
);
|
|
$rankingList = array();
|
|
$meta = mt\RankActivity::get($type);
|
|
if ($meta) {
|
|
$row = myself()->_getSelfMysql()->execQueryOne(
|
|
'SELECT COUNT(*) AS row_count FROM t_rank_activity ' .
|
|
'WHERE type=:type AND channel=:channel AND value>:value;',
|
|
array(
|
|
':type' => $type,
|
|
':channel' => $channel,
|
|
':value' => $meta['cond'],
|
|
)
|
|
);
|
|
if ($row['row_count'] > 0) {
|
|
$count = ceil($row['row_count'] / 2);
|
|
$rows = myself()->_getSelfMysql()->execQuery(
|
|
'SELECT * FROM t_rank_activity ' .
|
|
'WHERE type=:type AND channel=:channel AND value>=:value ' .
|
|
'ORDER BY value DESC, modifytime ASC ' .
|
|
"LIMIT ${count}",
|
|
array(
|
|
':type' => $type,
|
|
':channel' => $channel,
|
|
':value' => $meta['cond']
|
|
)
|
|
);
|
|
$ranked = 1;
|
|
foreach ($rows as $row) {
|
|
$user = User::find($row['account_id']);
|
|
if ($user) {
|
|
if ($user['account_id'] == $myRanked['user']['account_id']) {
|
|
$myRanked['ranked'] = $ranked;
|
|
$myRanked['value'] = $row['value'];
|
|
$myRanked['modifytime'] = $row['modifytime'];
|
|
}
|
|
array_push($rankingList, array(
|
|
'ranked' => $ranked++,
|
|
'user' => User::toSimple($user),
|
|
'value' => $row['value'],
|
|
'modifytime' => $row['modifytime'],
|
|
));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
{
|
|
$row = myself()->_getSelfMysql()->execQueryOne(
|
|
'SELECT * FROM t_rank_activity ' .
|
|
'WHERE type=:type AND channel=:channel AND account_id=:account_id;',
|
|
array(
|
|
':type' => $type,
|
|
':channel' => $channel,
|
|
':account_id' => myself()->_getAccountId(),
|
|
)
|
|
);
|
|
if ($row) {
|
|
$myRanked['value'] = $row['value'];
|
|
$myRanked['modifytime'] = $row['modifytime'];
|
|
}
|
|
}
|
|
$timeZone = 8;
|
|
$rankingData = array(
|
|
/*'daySeconds' => phpcommon\getdayseconds(myself()->_getNowTime(), $timeZone),
|
|
'nextDaySeconds' => phpcommon\getNextDaySeconds(myself()->_getNowTime(), $timeZone),
|
|
'mondaySeconds' => phpcommon\getMondaySeconds(myself()->_getNowTime(), $timeZone),
|
|
'monthFirstDaySeconds' => phpcommon\getThisMonthFirstDaySeconds(myself()->_getNowTime(), $timeZone),
|
|
'nextMonthFirstDaySeconds' => phpcommon\getNextMonthFirstDaySeconds(myself()->_getNowTime(), $timeZone),
|
|
'yearFirstDaySeconds' => phpcommon\getThisYearFirstDaySeconds(myself()->_getNowTime(), $timeZone),*/
|
|
'type' => $type,
|
|
'rows' => $rankingList,
|
|
'my_ranked' => $myRanked
|
|
);
|
|
return $rankingData;
|
|
}
|
|
|
|
}
|