289 lines
11 KiB
PHP
289 lines
11 KiB
PHP
<?php
|
|
|
|
require_once('mt/Parameter.php');
|
|
require_once('mt/Rank.php');
|
|
require_once('mt/Season.php');
|
|
require_once('mt/Drop.php');
|
|
require_once('mt/RankSeason.php');
|
|
|
|
require_once('models/User.php');
|
|
require_once('models/Season.php');
|
|
require_once('models/Mission.php');
|
|
require_once('models/SeasonRanking.php');
|
|
|
|
require_once('services/AwardService.php');
|
|
require_once('services/PropertyChgService.php');
|
|
require_once('services/SeasonService.php');
|
|
require_once('services/MissionService.php');
|
|
|
|
use phpcommon\SqlHelper;
|
|
use models\User;
|
|
use models\Season;
|
|
use models\SeasonRanking;
|
|
use models\Mission;
|
|
|
|
class SeasonController extends BaseAuthedController {
|
|
|
|
// private $propertyChgService = null;
|
|
// private $awardService = null;
|
|
private $redisService = null;
|
|
private $userInfo = null;
|
|
private $currRankSeasonMeta = null;
|
|
private $myRankedInfo = null;
|
|
|
|
private $redis_key_account = 'account';
|
|
private $redis_key_ranking = 'ranking';
|
|
private $starshine = 2800;
|
|
|
|
public function _handlePre()
|
|
{
|
|
parent::_handlePre();
|
|
$this->currRankSeasonMeta = mt\RankSeason::getCurrentSeason();
|
|
if (!$this->currRankSeasonMeta) {
|
|
$this->_rspErr(10, 'server internal error');
|
|
die();
|
|
}
|
|
// $this->propertyChgService = new services\PropertyChgService();
|
|
// $this->awardService = new services\AwardService();
|
|
$this->userInfo = $this->_safeGetOrmUserInfo();
|
|
$this->redisService = $this->_getRedis($this->redis_key_ranking);
|
|
if ($this->redisService->exists(RANKING_KEY.$this->redis_key_account)){
|
|
$myInfo = $this->userInfo;
|
|
if ($this->redisService->hexists(RANKING_KEY.$this->redis_key_account,$myInfo['account_id'])){
|
|
$myInfo['ranking'] = $this->redisService->hget(RANKING_KEY.$this->redis_key_account,$myInfo['account_id']);//$myInfo['account_id']
|
|
}else{
|
|
$myInfo['ranking'] = 10001;
|
|
}
|
|
$this->myRankedInfo = $this->_getRewardByRanking($myInfo);
|
|
}
|
|
}
|
|
|
|
public function info()
|
|
{
|
|
$rankMeta = mt\Rank::getRankById($this->userInfo['rank']);
|
|
$nextRankMeta = mt\Rank::getNextRankById($this->userInfo['rank']);
|
|
if (!$nextRankMeta){
|
|
$nextRankMeta = mt\Rank::getMaxRank();
|
|
}
|
|
|
|
$totalPoint = 0;
|
|
SeasonRanking::getSeasonList(function ($row) use (&$totalPoint){
|
|
$totalPoint += $row['ranking_point'] ;
|
|
});
|
|
|
|
$info = array(
|
|
'season' => $this->currRankSeasonMeta['id'],
|
|
'season_name' => $this->currRankSeasonMeta['name'],
|
|
'rank' => $this->userInfo['rank'],
|
|
'rank_name' => $rankMeta['rank_name'],
|
|
'score' => $this->userInfo['score'],
|
|
'next_score' => $nextRankMeta['rank_score'],
|
|
'season_end_time' => strtotime($this->currRankSeasonMeta['end_time']),
|
|
'season_reward' => Season::seasonReward($rankMeta),
|
|
'current_point' => $this->myRankedInfo['point'],
|
|
'total_point' => $totalPoint,
|
|
);
|
|
$this->_rspData(['info'=>$info]);
|
|
}
|
|
|
|
public function getRankingInfo(){
|
|
$rankList = array();
|
|
if ($this->redisService->exists(RANKING_KEY.$this->redis_key_ranking)){
|
|
for ($i=1;$i<=100;$i++){
|
|
if ($this->redisService->hexists(RANKING_KEY.$this->redis_key_ranking,$i)){
|
|
$accountId = $this->redisService->hget(RANKING_KEY.$this->redis_key_ranking,$i);
|
|
$userDb = User::find($accountId);
|
|
$userDb['ranking'] = $i;
|
|
$userDto = $this->_getRewardByRanking($userDb);
|
|
array_push($rankList,$userDto);
|
|
}
|
|
}
|
|
}
|
|
// if ($r->exists(RANKING_KEY.$this->redis_key_account)){
|
|
// $myInfo = $this->userInfo;
|
|
// $myInfo['ranking'] = $r->hget(RANKING_KEY.$this->redis_key_account,$myInfo['account_id']);
|
|
// $myRanked = $this->_getRewardByRanking($myInfo);
|
|
// }
|
|
$this->_rspData(array(
|
|
'rankList' => $rankList,
|
|
'myRanked' => $this->myRankedInfo
|
|
));
|
|
}
|
|
|
|
public function getDataInfo(){
|
|
$seasonDb = Season::find($this->currRankSeasonMeta['id']);
|
|
$currRankSeasonHistory = array();
|
|
if ($seasonDb){
|
|
$battleData = json_decode($seasonDb['battle_data'], true);
|
|
$seasonBattleData = isset($battleData) ? getXVal($battleData, 'season_data', array()) : array();
|
|
$gameTimes = getXVal($seasonBattleData, 'total_battle_times', 0);
|
|
$winTimes = getXVal($seasonBattleData, 'total_win_times', 0);
|
|
$topTenTimes = getXVal($seasonBattleData, 'total_top_ten_times', 0);
|
|
$totalKills = getXVal($seasonBattleData, 'total_kills_times', 0);
|
|
$temp = $gameTimes-$winTimes ? $gameTimes-$winTimes:0;
|
|
if (! $temp){
|
|
$kill_killed = 0;
|
|
}else{
|
|
$kill_killed = round($totalKills/$temp,2);
|
|
}
|
|
|
|
$currRankSeasonHistory= array(
|
|
'season_id' => $seasonDb['season_id'],
|
|
// 'total_kills' => $totalKills,
|
|
'game_times' => $gameTimes,
|
|
'win_times' => $winTimes,
|
|
'top_ten_times' => $topTenTimes,
|
|
'kill_killed' => $kill_killed,
|
|
);
|
|
}
|
|
if (!$currRankSeasonHistory){
|
|
$currRankSeasonHistory = array(
|
|
'season_id' => $this->currRankSeasonMeta['id'],
|
|
// 'total_kills' => $totalKills,
|
|
'game_times' => 0,
|
|
'win_times' => 0,
|
|
'top_ten_times' => 0,
|
|
'kill_killed' => 0,
|
|
);
|
|
}
|
|
$this->_rspData(['info'=>$currRankSeasonHistory]);
|
|
}
|
|
|
|
public function getSeasonPoint(){
|
|
$list = array();
|
|
SeasonRanking::getSeasonList(function ($row) use (&$list) {
|
|
array_push($list,array(
|
|
'season' => $row['season'],
|
|
'ranking' => $row['ranking'],
|
|
'ranking_point' => $row['ranking_point'],
|
|
));
|
|
});
|
|
$this->_rspData(array(
|
|
'data' => $list,
|
|
));
|
|
}
|
|
|
|
private function _getRewardByRanking($user){
|
|
if (!$user){
|
|
return ;
|
|
}
|
|
$userDto = User::getUserByRankMess($user);
|
|
$userDto['ranking'] = $user['ranking'];
|
|
if ($userDto['score'] >= $this->starshine){
|
|
if ($userDto['ranking'] <= 10000 ){
|
|
$userDto['echelonTopX'] = \services\FormulaService::echelonTopX($user['ranking']);
|
|
$userDto['point'] = \services\FormulaService::standardTopX($user['ranking'],$userDto['echelonTopX']);
|
|
}else{
|
|
$userDto['point'] = 30;
|
|
}
|
|
|
|
}else{
|
|
$userDto['point'] = 0;
|
|
}
|
|
// //当月排位赛最大分配金额
|
|
// $maxSum = \services\FormulaService::calcCECMaxSum();
|
|
//
|
|
// //排位赛预计分配额
|
|
// $expected_CEC_Sum = 0;
|
|
// $kingCount = User::getKingCount($this->starshine);
|
|
// for ($i=1;$i<=$kingCount;$i++){
|
|
// $echelonTopX = \services\FormulaService::echelonTopX($i);
|
|
// $expected_CEC_Sum += \services\FormulaService::calcCECTopXSum($i,$echelonTopX,$kingCount);
|
|
// }
|
|
//排位赛金额%
|
|
// $rankAmountPre = min($maxSum/($expected_CEC_Sum+1),1); //MIN(当月排位赛最大分配额/(排位赛预计分配额+1),1)
|
|
|
|
|
|
// if ($userDto['score'] >= $this->starshine &&
|
|
// $userDto['ranking'] <= 10000 ){
|
|
// $userDto['cec'] = $userDto['point']*$rankAmountPre;
|
|
// }else{
|
|
// $userDto['cec'] = 30;
|
|
// }
|
|
|
|
return array(
|
|
'ranking' => $userDto['ranking'],
|
|
'name' => $userDto['name'],
|
|
'head_id' => $userDto['head_id'],
|
|
'head_frame' => $userDto['head_frame'],
|
|
'rank' => $userDto['rank'],
|
|
'score' => $userDto['score'],
|
|
'point' => round($userDto['point'],0),
|
|
);
|
|
}
|
|
|
|
|
|
private function checkRankingList($users){
|
|
$rankList = array();
|
|
// $users = User::orderBy(User::allUser());
|
|
$rewardParamMeta = \mt\Parameter::getByName('rank_ring_reward');
|
|
$rewardParamMetaValue = $rewardParamMeta ? $rewardParamMeta['param_value'] : '';
|
|
$rewardList = explode('|',$rewardParamMetaValue);
|
|
if (count($users)>0){
|
|
$KingCount = 0;
|
|
foreach ($users as $k=>$user){
|
|
$userDto = User::getUserByRankMess($user);
|
|
$userDto['rank_sort'] = $k+1;
|
|
if ($userDto['score'] >= $this->starshine){
|
|
$KingCount += 1;
|
|
$userDto['echelonTopX'] = \services\FormulaService::echelonTopX($userDto['rank_sort']);
|
|
switch ($userDto['rank_sort']){
|
|
case 1:$userDto['ring_item_id'] = $rewardList[0];break;
|
|
case 2:$userDto['ring_item_id'] = $rewardList[1];break;
|
|
case 3:$userDto['ring_item_id'] = $rewardList[2];break;
|
|
default : $userDto['ring_item_id'] = 0;
|
|
}
|
|
}else{
|
|
$userDto['ring_item_id'] = 0;
|
|
}
|
|
|
|
array_push($rankList,$userDto);
|
|
}
|
|
|
|
//当月排位赛最大分配金额
|
|
$maxSum = \services\FormulaService::calcCECMaxSum();
|
|
//排位赛参与分配人数
|
|
// $PeopleCapita = $this->calcPeopleCapita($KingCount);
|
|
//排位赛人数%
|
|
// $PeopleCapitaPer = $this->calcPeopleCapitaPer($KingCount);
|
|
//排位赛预计分配额
|
|
$expected_CEC_Sum = 0;
|
|
foreach ($rankList as $k=>$value){
|
|
if ($value['score'] >= $this->starshine){
|
|
$rankList[$k]['standardTopX'] = \services\FormulaService::standardTopX($value['rank_sort'],$value['echelonTopX']);
|
|
$expected_CEC_Sum += \services\FormulaService::calcCECTopXSum($value['rank_sort'],$value['echelonTopX'],$KingCount);
|
|
}
|
|
}
|
|
//排位赛金额%
|
|
$rankAmountPre = min($maxSum/($expected_CEC_Sum+1),1); //MIN(当月排位赛最大分配额/(排位赛预计分配额+1),1)
|
|
|
|
foreach ($rankList as $k=>$value){
|
|
if ($value['score'] >= $this->starshine &&
|
|
$value['rank_sort'] <= 10000 ){
|
|
$rankList[$k]['rewardCEC'] = $value['standardTopX']*$rankAmountPre;
|
|
}else{
|
|
$rankList[$k]['rewardCEC'] = 0;
|
|
}
|
|
}
|
|
}
|
|
return $rankList;
|
|
}
|
|
|
|
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 , 3*60*60*1000);
|
|
}
|
|
|
|
}
|