1
This commit is contained in:
parent
13d0ce42be
commit
c47af32a59
@ -18,6 +18,19 @@ class Circuit(object):
|
|||||||
_common.RspHead(),
|
_common.RspHead(),
|
||||||
['!info', [stageInfo()], '巡回赛当前阶段信息'],
|
['!info', [stageInfo()], '巡回赛当前阶段信息'],
|
||||||
]
|
]
|
||||||
|
},{
|
||||||
|
'name': 'getCircuitRanking',
|
||||||
|
'desc': '巡回赛排行',
|
||||||
|
'group': 'Circuit',
|
||||||
|
'url': 'webapp/index.php?c=Circuit&a=getCircuitRanking',
|
||||||
|
'params': [
|
||||||
|
_common.ReqHead(),
|
||||||
|
],
|
||||||
|
'response': [
|
||||||
|
_common.RspHead(),
|
||||||
|
['!rank_list', [rankingInfo()], '榜信息'],
|
||||||
|
['my_rank', rankingInfo(), '我的信息'],
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -30,6 +43,18 @@ class stageInfo(object):
|
|||||||
self.fields = [
|
self.fields = [
|
||||||
['start_time', 0, '开始时间'],
|
['start_time', 0, '开始时间'],
|
||||||
['end_time', 0, '结束时间'],
|
['end_time', 0, '结束时间'],
|
||||||
['cec_pool', 0, '当前阶段奖池'],
|
['stage_cec_pool', 0, '当前阶段奖池'],
|
||||||
|
['total_cec_pool', 0, '赛季总奖池'],
|
||||||
]
|
]
|
||||||
|
|
||||||
|
class rankingInfo(object):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.fields = [
|
||||||
|
['account_id', 0, 'account'],
|
||||||
|
['name', 0, '名字'],
|
||||||
|
['head_id', 0, '头像'],
|
||||||
|
['head_frame', 0, '头像框'],
|
||||||
|
['ranking', 0, '排名'],
|
||||||
|
['score', 0, '积分'],
|
||||||
|
]
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
define('TEAMID_KEY', 'team_uuid:');
|
define('TEAMID_KEY', 'team_uuid:');
|
||||||
define('RANKING_KEY', 'game2006api:');
|
define('RANKING_KEY', 'game2006api:');
|
||||||
|
define('CIRCUIT_RANKING_KEY', 'game2006api:circuit_ranking');
|
||||||
define('DAILY_SELECTION_KEY', 'game2006api:daily_selection:');
|
define('DAILY_SELECTION_KEY', 'game2006api:daily_selection:');
|
||||||
define('PLANET_BUY_KEY', 'game2006api:planet_buy:');
|
define('PLANET_BUY_KEY', 'game2006api:planet_buy:');
|
||||||
|
|
||||||
|
@ -1,21 +1,30 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
require_once('mt/Parameter.php');
|
||||||
require_once('mt/CircuitTime.php');
|
require_once('mt/CircuitTime.php');
|
||||||
|
require_once('mt/CircuitReward.php');
|
||||||
require_once('models/Circuit.php');
|
require_once('models/Circuit.php');
|
||||||
|
require_once('models/User.php');
|
||||||
|
|
||||||
|
|
||||||
use models\Circuit;
|
use models\Circuit;
|
||||||
|
use models\User;
|
||||||
|
use phpcommon\SqlHelper;
|
||||||
class CircuitController extends BaseAuthedController {
|
class CircuitController extends BaseAuthedController {
|
||||||
|
private $redis_key_circuit_ranking = 'circuit_ranking';
|
||||||
|
|
||||||
public function getCurrentStage(){
|
public function getCurrentStage(){
|
||||||
$circuitStageMeta = mt\CircuitTime::getCurrentStage();
|
$circuitStageMeta = mt\CircuitTime::getCurrentStage();
|
||||||
if (!$circuitStageMeta){
|
if (!$circuitStageMeta){
|
||||||
$this->_rspErr(1, 'current stage Have not yet started');
|
$this->_rspErr(1, 'current stage Have not yet started');
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
$currentCircuitMeta = mt\CircuitTime::getCurrentCircuit();
|
||||||
$info = array(
|
$info = array(
|
||||||
'start_time' => strtotime($circuitStageMeta['start_time']),
|
'start_time' => strtotime($circuitStageMeta['start_time']),
|
||||||
'end_time' => strtotime($circuitStageMeta['end_time']),
|
'end_time' => strtotime($circuitStageMeta['end_time']),
|
||||||
'cec_pool' => $circuitStageMeta['cec_pool']
|
'stage_cec_pool' => $circuitStageMeta['cec_pool'],
|
||||||
|
'total_cec_pool' => $currentCircuitMeta['cec_pool']
|
||||||
);
|
);
|
||||||
$this->_rspData(array('info' => $info));
|
$this->_rspData(array('info' => $info));
|
||||||
}
|
}
|
||||||
@ -26,5 +35,82 @@ class CircuitController extends BaseAuthedController {
|
|||||||
$this->_rspErr(1, 'current stage Have not yet started');
|
$this->_rspErr(1, 'current stage Have not yet started');
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$redis = $this->_getRedis($this->redis_key_circuit_ranking);
|
||||||
|
if (! $redis->exists(CIRCUIT_RANKING_KEY.$this->redis_key_circuit_ranking)){
|
||||||
|
$rows = Circuit::getRankingList($currentCircuitMeta['circuit_season']);
|
||||||
|
$list = $this->_extractRankingInfo($rows);
|
||||||
|
$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());
|
||||||
|
}
|
||||||
|
$myRankedInfo = $this->_celMyRankingInfo($list);
|
||||||
|
$this->_rspData(array(
|
||||||
|
'rank_list' => $list,
|
||||||
|
'my_rank' => $myRankedInfo,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function _extractRankingInfo($data){
|
||||||
|
$rankingList = array();
|
||||||
|
foreach ($data as $k=>$row){
|
||||||
|
$userDb = User::find($row['account_id']);
|
||||||
|
$ranking = $k+1;
|
||||||
|
$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'],
|
||||||
|
'ranking' => $ranking,
|
||||||
|
'weight' => $rewardWeight,
|
||||||
|
'score' => $row['cumulative_score'],
|
||||||
|
);
|
||||||
|
array_push($rankingList,$info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $rankingList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function _celMyRankingInfo($list){
|
||||||
|
$currentCircuitMeta = mt\CircuitTime::getCurrentCircuit();
|
||||||
|
$userDb = User::find(myself()->_getAccountId());
|
||||||
|
$myRankedInfo = array(
|
||||||
|
'ranking' => 0,
|
||||||
|
'account_id' => $userDb['account_id'],
|
||||||
|
'name' => $userDb['name'],
|
||||||
|
'head_id' => $userDb['head_id'],
|
||||||
|
'head_frame' => $userDb['head_frame'],
|
||||||
|
'score' => Circuit::getMyScore($currentCircuitMeta['circuit_season']),
|
||||||
|
'cec' => 0,
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
if (count($list) > 0){
|
||||||
|
$totalWeight = 0;
|
||||||
|
$rate = \mt\Parameter::getVal('circuit_reward_rate','');
|
||||||
|
$count = floor(count($list) * $rate) ;
|
||||||
|
foreach ($list as $value){
|
||||||
|
if ($value['ranking'] <= $count){
|
||||||
|
$totalWeight += $value['weight'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$circuitStageMeta = mt\CircuitTime::getCurrentStage();
|
||||||
|
$cecPool = $circuitStageMeta ? $circuitStageMeta['cec_pool'] : 0;
|
||||||
|
foreach ($list as $value){
|
||||||
|
$cec = 0;
|
||||||
|
if ($value['ranking'] <= $count){
|
||||||
|
$cec = ($value['weight'] / $totalWeight) * $cecPool;
|
||||||
|
}
|
||||||
|
if ($value['account_id'] == myself()->_getAccountId()){
|
||||||
|
$myRankedInfo['ranking'] = $value['ranking'];
|
||||||
|
$myRankedInfo['cec'] = $cec;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $myRankedInfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ class Circuit extends BaseModel
|
|||||||
|
|
||||||
public static function getMyScore($season){
|
public static function getMyScore($season){
|
||||||
$row = SqlHelper::ormSelectOne(
|
$row = SqlHelper::ormSelectOne(
|
||||||
myself()->_getMysql(''),
|
myself()->_getSelfMysql(),
|
||||||
't_circuit_battle',
|
't_circuit_battle',
|
||||||
array(
|
array(
|
||||||
'account_id' => myself()->_getAccountId(),
|
'account_id' => myself()->_getAccountId(),
|
||||||
@ -41,4 +41,16 @@ class Circuit extends BaseModel
|
|||||||
return $row ? $row['cumulative_score'] : 0;
|
return $row ? $row['cumulative_score'] : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getRankingList($season){
|
||||||
|
$sql = "select * from t_circuit_battle where season=:season order by cumulative_score desc,modifytime asc";
|
||||||
|
$whereKv = array(
|
||||||
|
"season" => $season,
|
||||||
|
);
|
||||||
|
$rows = myself()->_getSelfMysql()->execQuery($sql,$whereKv);
|
||||||
|
if (!$rows){
|
||||||
|
$rows = array();
|
||||||
|
}
|
||||||
|
return $rows;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
29
webapp/mt/CircuitReward.php
Normal file
29
webapp/mt/CircuitReward.php
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace mt;
|
||||||
|
|
||||||
|
use phpcommon;
|
||||||
|
|
||||||
|
class CircuitReward {
|
||||||
|
|
||||||
|
public static function getRewardWeight($ranking){
|
||||||
|
$rewardWeight = 0;
|
||||||
|
foreach (self::getMetaList() as $meta){
|
||||||
|
if ($ranking >= $meta['rankMin']){
|
||||||
|
$rewardWeight = $meta['rewardWeight'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $rewardWeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static function getMetaList()
|
||||||
|
{
|
||||||
|
if (!self::$metaList) {
|
||||||
|
self::$metaList = getMetaTable('circuitReward@circuitReward.php');
|
||||||
|
}
|
||||||
|
return self::$metaList;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static $metaList;
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user