1
This commit is contained in:
parent
a7eb363b0f
commit
a81e5a73e3
@ -128,13 +128,14 @@ class CircuitController extends BaseAuthedController {
|
||||
|
||||
private function _extractRankingInfo($data){
|
||||
$rankingList = array();
|
||||
$ranking = 0;
|
||||
foreach ($data as $k=>$row){
|
||||
++$ranking;
|
||||
$userDb = User::find($row['account_id']);
|
||||
$heroDb = Hero::findByAccountId($userDb['account_id'],$userDb['hero_id']);
|
||||
$skinDb = HeroSkin::find($heroDb['skin_id']);
|
||||
$heroId = $heroDb ? $heroDb['hero_id']:0;
|
||||
$skinId = $skinDb ? $skinDb['skin_id']:0;
|
||||
$ranking = $k+1;
|
||||
$rewardWeight = \mt\CircuitReward::getRewardWeight($ranking);
|
||||
if ($userDb){
|
||||
$info = array(
|
||||
|
@ -10,12 +10,103 @@ require_once('mt/CircuitReward.php');
|
||||
require_once('models/CircuitReward.php');
|
||||
require_once('models/Circuit.php');
|
||||
require_once('models/User.php');
|
||||
require_once('models/Hero.php');
|
||||
require_once('models/HeroSkin.php');
|
||||
|
||||
use services\ServerSwitchService;
|
||||
use models\CircuitReward;
|
||||
use models\Circuit;
|
||||
use models\User;
|
||||
use models\Hero;
|
||||
use models\HeroSkin;
|
||||
class OutAppCircuitController extends BaseController {
|
||||
private $redis_key_circuit_ranking = 'circuit_ranking';
|
||||
private $redis_key_circuit_phase_ranking = 'circuit_phase_ranking';
|
||||
|
||||
public function getCircuitRanking(){
|
||||
$currentCircuitMeta = mt\CircuitTime::getCurrentCircuit();
|
||||
if (!$currentCircuitMeta){
|
||||
$this->_rspErr(1, 'current stage Have not yet started');
|
||||
return ;
|
||||
}
|
||||
$address = getReqVal('address', '');
|
||||
if (empty($address)){
|
||||
myself()->_rspErr(1, 'param error');
|
||||
return;
|
||||
}
|
||||
$user = User::findByAddress($address);
|
||||
if (!$user){
|
||||
myself()->_rspErr(1, 'user not found');
|
||||
return;
|
||||
}
|
||||
$redis = $this->_getRedis($this->redis_key_circuit_ranking);
|
||||
if (! $redis->exists(CIRCUIT_RANKING_KEY.$this->redis_key_circuit_ranking)){
|
||||
$rows = Circuit::getCircuitList($currentCircuitMeta['circuit_season']);
|
||||
$sortRows = myself()->arraySort($rows, 'cumulative_score', 'desc');
|
||||
$list = $this->_extractRankingInfo($sortRows);
|
||||
$redis->set(CIRCUIT_RANKING_KEY.$this->redis_key_circuit_ranking , json_encode($list));
|
||||
$redis->pexpire(CIRCUIT_RANKING_KEY.$this->redis_key_circuit_ranking , 10*60*1000);
|
||||
}else{
|
||||
$listStr = $redis->get(CIRCUIT_RANKING_KEY.$this->redis_key_circuit_ranking);
|
||||
$list = emptyReplace(json_decode($listStr, true), array());
|
||||
}
|
||||
$myInfo = $this->_celMyRankingInfo($list,$user['account_id']);
|
||||
$info = array(
|
||||
'star_time' => strtotime($currentCircuitMeta['start_time']),
|
||||
'end_time' => strtotime($currentCircuitMeta['end_time']),
|
||||
'ranking' => $myInfo['ranking'],
|
||||
'score' => $myInfo['score'],
|
||||
);
|
||||
$this->_rspData(array(
|
||||
'rank_list' => $list,
|
||||
'info' => $info,
|
||||
));
|
||||
}
|
||||
|
||||
public function getCircuitPhaseRanking(){
|
||||
$currentCircuitMeta = mt\CircuitTime::getCurrentCircuit();
|
||||
if (!$currentCircuitMeta){
|
||||
$this->_rspErr(1, 'current stage Have not yet started');
|
||||
return ;
|
||||
}
|
||||
$address = getReqVal('address', '');
|
||||
if (empty($address)){
|
||||
myself()->_rspErr(1, 'param error');
|
||||
return;
|
||||
}
|
||||
$user = User::findByAddress($address);
|
||||
if (!$user){
|
||||
myself()->_rspErr(1, 'user not found');
|
||||
return;
|
||||
}
|
||||
$currentStageMeta = mt\CircuitTime::getCurrentStage();
|
||||
if (!$currentStageMeta){
|
||||
$currentStageMeta = mt\CircuitTime::getPrevStage();
|
||||
}
|
||||
$redis = $this->_getRedis($this->redis_key_circuit_phase_ranking);
|
||||
if (! $redis->exists(CIRCUIT_RANKING_KEY.$this->redis_key_circuit_phase_ranking)){
|
||||
$rows = Circuit::getCircuitPhaseList($currentStageMeta['circuit_season'],$currentStageMeta['circuit_phase']);
|
||||
$sortRows = myself()->arraySort($rows, 'cumulative_score', 'desc');
|
||||
$list = $this->_extractRankingInfo($sortRows);
|
||||
$redis->set(CIRCUIT_RANKING_KEY.$this->redis_key_circuit_phase_ranking , json_encode($list));
|
||||
$redis->pexpire(CIRCUIT_RANKING_KEY.$this->redis_key_circuit_phase_ranking , 10*60*1000);
|
||||
}else{
|
||||
$listStr = $redis->get(CIRCUIT_RANKING_KEY.$this->redis_key_circuit_phase_ranking);
|
||||
$list = emptyReplace(json_decode($listStr, true), array());
|
||||
}
|
||||
$myInfo = $this->_celMyRankingInfo($list,$user['account_id']);
|
||||
$info = array(
|
||||
'star_time' => strtotime($currentStageMeta['start_time']),
|
||||
'end_time' => strtotime($currentStageMeta['end_time']),
|
||||
'ranking' => $myInfo['ranking'],
|
||||
'score' => $myInfo['score'],
|
||||
);
|
||||
$this->_rspData(array(
|
||||
'rank_list' => $list,
|
||||
'info' => $info,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
public function getCircuitRewardHistory(){
|
||||
$address = getReqVal('address', '');
|
||||
@ -95,4 +186,50 @@ class OutAppCircuitController extends BaseController {
|
||||
$this->_rspErr(1,'未满足结算条件');
|
||||
}
|
||||
|
||||
private function _extractRankingInfo($data){
|
||||
$rankingList = array();
|
||||
$ranking = 0;
|
||||
foreach ($data as $k=>$row){
|
||||
++$ranking;
|
||||
$userDb = User::find($row['account_id']);
|
||||
$heroDb = Hero::findByAccountId($userDb['account_id'],$userDb['hero_id']);
|
||||
$skinDb = HeroSkin::find($heroDb['skin_id']);
|
||||
$heroId = $heroDb ? $heroDb['hero_id']:0;
|
||||
$skinId = $skinDb ? $skinDb['skin_id']:0;
|
||||
$rewardWeight = \mt\CircuitReward::getRewardWeight($ranking);
|
||||
if ($userDb){
|
||||
$info = array(
|
||||
'account_id' => $userDb['account_id'],
|
||||
'name' => utf8_encode($userDb['name']),
|
||||
'head_id' => $userDb['head_id'],
|
||||
'head_frame' => $userDb['head_frame'],
|
||||
'hero_id' => $heroId,
|
||||
'skin_id' => $skinId,
|
||||
'ranking' => $ranking,
|
||||
'weight' => $rewardWeight,
|
||||
'score' => $row['cumulative_score'],
|
||||
'score_boost' => $row['score_boost'],
|
||||
);
|
||||
array_push($rankingList,$info);
|
||||
}
|
||||
}
|
||||
return $rankingList;
|
||||
}
|
||||
|
||||
private function _celMyRankingInfo($list,$account){
|
||||
$myRankedInfo = array(
|
||||
'ranking' => 0,
|
||||
'score' => 0,
|
||||
);
|
||||
if (count($list) > 0){
|
||||
foreach ($list as $value){
|
||||
if ($value['account_id'] == $account){
|
||||
$myRankedInfo['ranking'] = $value['ranking'];
|
||||
$myRankedInfo['score'] = $value['score'];
|
||||
}
|
||||
}
|
||||
}
|
||||
return $myRankedInfo;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user