This commit is contained in:
hujiabin 2023-08-02 13:55:44 +08:00
parent 2203a5e6ef
commit 32c6f0c498
2 changed files with 33 additions and 21 deletions

View File

@ -14,7 +14,9 @@ class Rankings {
console.log('Rankings.start');
while (true) {
await this.doRanking();
const sleepTime = 60*60*2;
const nowTime = utils.getUtcTime();
const daySeconds = utils.getDaySeconds(nowTime, constant.TIME_ZONE);
const sleepTime = daySeconds + 3600 * 24 - nowTime;
console.log('sleepTime:' + sleepTime, new Date(), sleepTime /60);
await utils.sleep(sleepTime * 1000);
}
@ -73,8 +75,15 @@ class Rankings {
sorted,
(value , index) =>{
value.ranking = index+1
Redis.hset(RANKING_KEY + "ranking",value.ranking,value.account_id)
Redis.hset(RANKING_KEY + "account",value.account_id,value.ranking)
let dataJson = {
"account_id" : value.account_id,
"score" : value.score,
"ranking" : value.ranking,
}
// Redis.hset(RANKING_KEY + "ranking",value.ranking,value.account_id)
Redis.hset(RANKING_KEY + "ranking",value.ranking,dataJson)
// Redis.hset(RANKING_KEY + "account",value.account_id,value.ranking)
Redis.hset(RANKING_KEY + "account",value.account_id,dataJson)
}
)
}

View File

@ -59,7 +59,9 @@ class SeasonController extends BaseAuthedController {
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']
$redisData= json_decode($this->redisService->hget(RANKING_KEY.$this->redis_key_account,$myInfo['account_id']),true);//$myInfo['account_id']
$myInfo['ranking'] = intval($redisData['ranking']);
$myInfo['score'] = $redisData['score'];
}else{
$myInfo['ranking'] = 10001;
}
@ -100,9 +102,10 @@ class SeasonController extends BaseAuthedController {
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;
$redisData = json_decode($this->redisService->hget(RANKING_KEY.$this->redis_key_ranking,$i),true);
$userDb = User::find($redisData['account_id']);
$userDb['ranking'] = intval($redisData['ranking']);
$userDb['score'] = $redisData['score'];
$userDto = $this->_getRewardByRanking($userDb);
array_push($rankList,$userDto);
}
@ -176,18 +179,18 @@ class SeasonController extends BaseAuthedController {
if (!$user){
return ;
}
$userDto = User::getUserByRankMess($user);
// $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']);
if ($user['score'] >= $this->starshine){
if ($user['ranking'] <= 10000 ){
$user['echelonTopX'] = \services\FormulaService::echelonTopX($user['ranking']);
$user['point'] = \services\FormulaService::standardTopX($user['ranking'],$user['echelonTopX']);
}else{
$userDto['point'] = 30;
$user['point'] = 30;
}
}else{
$userDto['point'] = 0;
$user['point'] = 0;
}
// //当月排位赛最大分配金额
// $maxSum = \services\FormulaService::calcCECMaxSum();
@ -211,13 +214,13 @@ class SeasonController extends BaseAuthedController {
// }
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),
'ranking' => $user['ranking'],
'name' => $user['name'],
'head_id' => $user['head_id'],
'head_frame' => $user['head_frame'],
'rank' => $user['rank'],
'score' => $user['score'],
'point' => round($user['point'],0),
);
}