346 lines
13 KiB
PHP
346 lines
13 KiB
PHP
<?php
|
|
|
|
require_once('models/User.php');
|
|
require_once('models/Season.php');
|
|
require_once('models/SeasonRanking.php');
|
|
|
|
require_once('mt/RankActivity.php');
|
|
require_once('mt/RankSeason.php');
|
|
require_once('mt/Rank.php');
|
|
|
|
require_once('services/AwardService.php');
|
|
require_once('services/PropertyChgService.php');
|
|
|
|
use phpcommon\SqlHelper;
|
|
|
|
use models\User;
|
|
use models\Season;
|
|
use models\SeasonRanking;
|
|
|
|
class RankingController extends BaseAuthedController {
|
|
private $starshine = 2800;
|
|
private $TopXunid = 'echelon_TopX_';
|
|
|
|
public function getRankStatus(){
|
|
$userInfo = $this->_getOrmUserInfo();
|
|
$currSeasonMeta = mt\RankSeason::getCurrentSeason();
|
|
if($currSeasonMeta){
|
|
$this->_setV(TN_RANK_STATUS, 1, 1);
|
|
if ($userInfo['last_season_id'] > 0 && $currSeasonMeta['id'] != $userInfo['last_season_id'] ){
|
|
$this->_setV(TN_RANK_STATUS, 0, 2);
|
|
}
|
|
}else{
|
|
$this->_setV(TN_RANK_STATUS, 1, 0);
|
|
}
|
|
|
|
$rank_status = $this->_getV(TN_RANK_STATUS, 0 );
|
|
$is_rank = $this->_getV(TN_RANK_STATUS, 1 );
|
|
$this->_rspData(array(
|
|
'status' => $rank_status, // 0:常规状态 1:引导初始排位 2:赛季初,需结算上个赛季
|
|
'is_rank' => $is_rank //赛季是否空挡期
|
|
));
|
|
}
|
|
|
|
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
|
|
);
|
|
}
|
|
|
|
public function resetRankGainAward(){
|
|
$userInfo = $this->_getOrmUserInfo();
|
|
$lastSeasonRank = $userInfo['rank'];
|
|
$lastSeasonScore = $userInfo['score'];
|
|
$currSeasonMeta = mt\RankSeason::getCurrentSeason();
|
|
if ($currSeasonMeta && $userInfo['last_season_id'] > 0 && $currSeasonMeta['id'] > $userInfo['last_season_id']) {
|
|
$rank = $userInfo['rank'];
|
|
for ($i=$userInfo['last_season_id'];$i<$currSeasonMeta['id'];$i++){
|
|
$currRankMeta = mt\Rank::getRankById($rank);
|
|
$dropRankMeta = mt\Rank::getRankById($currRankMeta ? $currRankMeta['next_season'] : 1);
|
|
$rank= $dropRankMeta['id'];
|
|
$award = Season::seasonReward($currRankMeta);
|
|
}
|
|
//掉段
|
|
if ($dropRankMeta) {
|
|
myself()->_updateUserInfo(array(
|
|
'rank' => $dropRankMeta['id'],
|
|
'score' => $dropRankMeta['rank_score'],
|
|
'last_season_id' => $currSeasonMeta['id'],
|
|
));
|
|
}
|
|
$awardService = new services\AwardService();
|
|
$propertyChgService = new services\PropertyChgService();
|
|
$propertyChgService->addUserChg();
|
|
$propertyChgService->addBagChg();
|
|
$propertyChgService->addParachute();
|
|
$cec = $this->calcCECSeasonAward($currSeasonMeta['id']-1);
|
|
$award = array_merge($award,$cec);
|
|
if ($award){
|
|
$this->_addItems($award,$awardService,$propertyChgService);
|
|
}
|
|
$this->_setV(TN_RANK_STATUS, 0, 0);
|
|
$this->_rspData([
|
|
'data'=> array(
|
|
'last_rank'=>$lastSeasonRank,
|
|
'last_score'=>$lastSeasonScore,
|
|
'current_rank'=>$dropRankMeta['id'],
|
|
'current_score'=>$dropRankMeta['rank_score'],
|
|
'award' => $award
|
|
),
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
]);
|
|
return;
|
|
}
|
|
$this->_rspErr(1, "The new season hasn't started yet");
|
|
}
|
|
|
|
private function internalGetActivityRankData($type)
|
|
{
|
|
$channel = 6516;
|
|
if (SERVER_ENV != _ONLINE) {
|
|
$channel = 6513;
|
|
}
|
|
$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'];
|
|
}
|
|
}
|
|
if (SERVER_ENV != _ONLINE) {
|
|
for ($i = 0; $i < 100; ++$i) {
|
|
$userDto = User::find('6513_2006_3WOWIsmpcihK1KTnNP1Ky5MBOh7rt6Rl');
|
|
$userDto = User::toSimple($userDto);
|
|
$userDto['account_id'] = 'test' . $i;
|
|
$userDto['name'] = 'test' . $i;
|
|
array_push($rankingList,
|
|
array(
|
|
'ranked' => count($rankingList) + 1,
|
|
'value' => count($rankingList) + 1,
|
|
'user' => $userDto,
|
|
'modifytime' => myself()->_getNowTime(),
|
|
));
|
|
}
|
|
}
|
|
$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;
|
|
}
|
|
|
|
private function calcCECSeasonAward($seasonId){
|
|
$data = SeasonRanking::getDataBySeasonId($seasonId);
|
|
$rewardParamMeta = \mt\Parameter::getByName('rank_ring_reward');
|
|
$rewardParamMetaValue = $rewardParamMeta ? $rewardParamMeta['param_value'] : '';
|
|
$rewardList = explode('|',$rewardParamMetaValue);
|
|
$award = array();
|
|
if (count($data)>0){
|
|
$KingCount = 0;
|
|
foreach ($data as &$value){
|
|
if ($value['score'] >= $this->starshine){
|
|
$KingCount += 1;
|
|
$value['echelonTopX'] = \services\FormulaService::echelonTopX($value['ranking']);
|
|
switch ($value['ranking']){
|
|
case 1:$value['ring_item_id'] = $rewardList[0];break;
|
|
case 2:$value['ring_item_id'] = $rewardList[1];break;
|
|
case 3:$value['ring_item_id'] = $rewardList[2];break;
|
|
default : $value['ring_item_id'] = 0;
|
|
}
|
|
}else{
|
|
$value['ring_item_id'] = 0;
|
|
}
|
|
}
|
|
//当月排位赛最大分配金额
|
|
$maxSum = \services\FormulaService::calcCECMaxSum();
|
|
//排位赛预计分配额
|
|
$expected_CEC_Sum = 0;
|
|
foreach ($data as &$value){
|
|
if ($value['score'] >= $this->starshine){
|
|
$value['standardTopX'] = \services\FormulaService::standardTopX($value['ranking'],$value['echelonTopX']);
|
|
$expected_CEC_Sum += \services\FormulaService::calcCECTopXSum($value['ranking'],$value['echelonTopX'],$KingCount);
|
|
}
|
|
}
|
|
//排位赛金额%
|
|
$rankAmountPre = min($maxSum/($expected_CEC_Sum+1),1);
|
|
|
|
foreach ($data as $val){
|
|
if ($val['account_id'] == myself()->_getAccountId() &&
|
|
$value['score'] >= $this->starshine &&
|
|
$value['ranking'] <= 10000){
|
|
// $award['CEC'] = $value['standardTopX']*$rankAmountPre;
|
|
// $award['ring_item_id'] = $value['ring_item_id'];
|
|
array_push($award,array(
|
|
'item_id' => V_ITEM_DIAMOND,
|
|
'item_num' => $value['standardTopX']*$rankAmountPre
|
|
));
|
|
if ($value['ring_item_id']){
|
|
array_push($award,array(
|
|
'item_id' => $value['ring_item_id'],
|
|
'item_num' => 1
|
|
));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return $award;
|
|
}
|
|
|
|
private function readRankingList($r,$rankUnid)
|
|
{
|
|
$list = $r->get(RANKING_KEY.$rankUnid);
|
|
if (empty($list)) {
|
|
return array();
|
|
}
|
|
$list = json_decode($list, true);
|
|
return $list;
|
|
}
|
|
|
|
private function saveRankingList($r,$rankUnid ,$list)
|
|
{
|
|
$r->set(RANKING_KEY.$rankUnid , json_encode($list));
|
|
$r->pexpire(RANKING_KEY.$rankUnid , 6*60*60*1000);
|
|
}
|
|
|
|
}
|