This commit is contained in:
aozhiwei 2023-08-24 16:16:39 +08:00
commit 895a4557fa
11 changed files with 217 additions and 29 deletions

View File

@ -7,8 +7,8 @@ function add(name) {
function init() {
add('season');
add('dailyTask');
add('hourlyTask');
//add('dailyTask');
//add('hourlyTask');
add('rankings');
}

View File

@ -13,8 +13,12 @@ class Season {
await this.doRoutine(utils.getUtcTime());
const nowTime = utils.getUtcTime();
const daySeconds = utils.getDaySeconds(nowTime, constant.TIME_ZONE);
const sleepTime = daySeconds + 3600 * 24 - nowTime;
console.log('Season.sleepTime:' + sleepTime, new Date(), sleepTime /60);
// const sleepTime = daySeconds + 3600 * 24 - nowTime;
let sleepTime = 120;
if (utils.isOnlineEnv()) {
sleepTime = daySeconds + 3600 * 25 - nowTime;
}
console.log('Season.sleepTime:' + sleepTime, new Date(), sleepTime / 60);
await utils.sleep(sleepTime*1000);
}
}
@ -112,7 +116,7 @@ class Season {
async getRecords(conn, lastIdx, limit) {
const {err, rows} = await conn.execQuery(
'select idx,account_id,channel,rank,score,createtime, score_modifytime from t_user where idx > ? order by idx LIMIT ?',
'select idx,account_id,`address`,channel,`rank`,`score`,createtime, score_modifytime from t_user where idx > ? order by idx LIMIT ?',
[
lastIdx,
limit
@ -139,7 +143,7 @@ class Season {
// console.time("inserNewRecords");
for (let element of records) {
if (element.score>=2800) {
// if (element.score>=2800) {
sorted.push(element);
sorted.sort(function(a,b) {
let r = b.score - a.score;
@ -151,7 +155,7 @@ class Season {
}
return r;
});
}
// }
}
// if (sorted.length>10000) {
// sorted.length = 10000;
@ -170,11 +174,15 @@ class Season {
async (element, index) => {
let ranking = index+1;
let TopX = FormulaService.celTopX(ranking);
let ponit = FormulaService.celUserRankingPoint(ranking,TopX).toFixed(0);
let ponit = 0;
if (element['score'] >= 2800){
ponit = FormulaService.celUserRankingPoint(ranking,TopX).toFixed(0);
}
await conn.insert(
't_season_ranking',
[
['account_id', element['account_id']],
['address', element['address']],
['channel', element['channel']],
['rank', element['rank']],
['score', element['score']],

View File

@ -0,0 +1,21 @@
begin;
CREATE TABLE `t_ranking_settlement_record` (
`idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id',
`account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id',
`state` int(11) NOT NULL DEFAULT '0' COMMENT '是否重置',
`last_rank` int(11) NOT NULL DEFAULT '0' COMMENT '上赛季段位',
`current_rank` int(11) NOT NULL DEFAULT '0' COMMENT '新段位',
`last_score` int(11) NOT NULL DEFAULT '0' COMMENT '上赛季段位分',
`current_score` int(11) NOT NULL DEFAULT '0' COMMENT '新段位分',
`awards` mediumblob COMMENT '奖励',
`createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
`modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
PRIMARY KEY (`idx`),
KEY `account_id` (`account_id`)
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
insert into version (version) values(2023081501);
commit;

View File

@ -808,6 +808,7 @@ DROP TABLE IF EXISTS `t_season_ranking`;
CREATE TABLE `t_season_ranking` (
`idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id',
`account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id(channel + "_" + gameid + "_" + openid)',
`address` varchar(60) COMMENT 'address',
`channel` int(11) NOT NULL DEFAULT '0' COMMENT 'channel',
`rank` int(11) NOT NULL DEFAULT '0' COMMENT '段位',
`score` int(11) NOT NULL DEFAULT '0' COMMENT '积分',
@ -1615,3 +1616,18 @@ CREATE TABLE `t_hash_rate_reward` (
KEY `account_id` (`account_id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
CREATE TABLE `t_ranking_settlement_record` (
`idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id',
`account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id',
`state` int(11) NOT NULL DEFAULT '0' COMMENT '是否重置',
`last_rank` int(11) NOT NULL DEFAULT '0' COMMENT '上赛季段位',
`current_rank` int(11) NOT NULL DEFAULT '0' COMMENT '新段位',
`last_score` int(11) NOT NULL DEFAULT '0' COMMENT '上赛季段位分',
`current_score` int(11) NOT NULL DEFAULT '0' COMMENT '新段位分',
`awards` mediumblob COMMENT '奖励',
`createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
`modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
PRIMARY KEY (`idx`),
KEY `account_id` (`account_id`)
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

View File

@ -100,8 +100,35 @@ class BagController extends BaseAuthedController {
$this->_rspErr(4, 'The prop function has not been realized yet');
}
}
public function rename()
{
$itemDto = Bag::findByType(mt\Item::FUNC_TYPE, mt\Item::FUNC_RENAME_CARD_SUBTYPE);
if (!$itemDto || $itemDto['item_num'] < 0) {
$this->_rspErr(1, 'Not enough item');
return;
}
$errCode = 0;
$errMsg = '';
$this->internalRename(getReqVal('name', ''), getReqVal('name_sign', ''), $errCode, $errMsg);
if ($errCode) {
$this->_rspErr($errCode, $errMsg);
return;
}
$this->_decItems(array(
array(
'item_id' => $itemDto['item_id'],
'item_num' => 1
)
));
$this->propertyChgService->addBagChg();
$this->propertyChgService->addUserChg();
$this->_rspData(array(
'property_chg' => $this->propertyChgService->toDto(),
));
}
private function oldRename()
{
$itemDto = Bag::findByType(mt\Item::FUNC_TYPE, mt\Item::FUNC_RENAME_CARD_SUBTYPE);
$userInfo = $this->_getOrmUserInfo();

View File

@ -9,10 +9,12 @@ require_once('mt/RankSeason.php');
require_once('models/RealtimeData.php');
require_once('models/Season.php');
require_once('models/RankingSetRecord.php');
use phpcommon\SqlHelper;
use models\RealtimeData;
use models\Season;
use models\RankingSetRecord;
class DailyRequestController extends BaseAuthedController {
private $awardService = null;
@ -79,9 +81,12 @@ class DailyRequestController extends BaseAuthedController {
*/
public function battleRankingSeasonSettlement(){
$currSeasonMeta = mt\RankSeason::getCurrentSeason();
$lastSeasonMeta = mt\RankSeason::getLastSeason();
$season = RealtimeData::getRankSeason();
if ($currSeasonMeta && $currSeasonMeta['id'] > $season) {
if ($season > 1){
// if ($currSeasonMeta && $currSeasonMeta['id'] > $season) {
if (!$currSeasonMeta && $lastSeasonMeta && $lastSeasonMeta['id'] > $season) {
if ($lastSeasonMeta > 1){
$SeasonMeta = mt\RankSeason::get($season-1);
$time = strtotime($SeasonMeta['start_time']);
$rows = myself()->_getMysql('')->execQuery(
@ -116,15 +121,25 @@ class DailyRequestController extends BaseAuthedController {
$award = Season::seasonReward($currRankMeta);
myself()->switchAccount($row['account_id']);
myself()->_addItems($award, null, $this->propertyChgService);
$data = array(
'state' => 1,
'last_rank' => $row['rank'],
'current_rank' => $dropRankMeta['id'],
'last_score' => $row['score'],
'current_score' => $dropRankMeta['rank_score'],
'awards' => json_encode($award),
);
RankingSetRecord::upsert($data);
myself()->_updateUserInfo(array(
'last_season_id' => $currSeasonMeta['id'],
'last_season_id' => $lastSeasonMeta['id'],
'rank' => $dropRankMeta['id'],
'score' => $dropRankMeta['rank_score'],
));
}
error_log("DailyRequestController : Battle Ranking Season ".$season." Settlement Success !" . " Request Time : ". date('Y-M-D h:i:s',time()));
RealtimeData::setRankSeason($currSeasonMeta['id']);
RealtimeData::setRankSeason($lastSeasonMeta['id']);
}
$this->_rspOk();
}
}

View File

@ -8,12 +8,14 @@ require_once('models/Mission.php');
require_once('models/Fragment.php');
require_once('models/Season.php');
require_once('models/SignLog.php');
require_once('models/RankingSetRecord.php');
use models\SignLog;
use phpcommon\SqlHelper;
use models\Mission;
use models\Fragment;
use models\Season;
use models\RankingSetRecord;
class OtherController extends BaseAuthedController {
const MISSION = 1;
const PIECE = 2;
@ -97,4 +99,18 @@ class OtherController extends BaseAuthedController {
'data'=>$data
));
}
public function getRankingState(){
$recordDb = RankingSetRecord::find();
$data = array(
'state' => 0 ,
);
if ($recordDb){
$data = RankingSetRecord::toDto($recordDb);;
}
$this->_rspData(array(
'data'=>$data
));
}
}

View File

@ -30,6 +30,7 @@ class SeasonController extends BaseAuthedController {
private $userInfo = null;
private $currRankSeasonMeta = null;
private $myRankedInfo = null;
private $rankingState = true;
private $redis_key_account = 'account';
private $redis_key_ranking = 'ranking';
@ -40,10 +41,12 @@ class SeasonController extends BaseAuthedController {
parent::_handlePre();
$this->currRankSeasonMeta = mt\RankSeason::getCurrentSeason();
if (!$this->currRankSeasonMeta) {
$this->rankingState = false;
$this->currRankSeasonMeta = mt\RankSeason::getLastSeason();
}
if (!$this->currRankSeasonMeta){
$this->_rspErr(10,'server internal error');
if (!$this->currRankSeasonMeta) {
$this->_rspErr(10, 'server internal error');
die();
}
// $this->propertyChgService = new services\PropertyChgService();
@ -59,7 +62,7 @@ class SeasonController extends BaseAuthedController {
'score' => $this->userInfo['score'],
'point' => 0,
);
if ($this->redisService->exists(RANKING_KEY.$this->redis_key_account)){
if ($this->rankingState && $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'])){
$redisData= json_decode($this->redisService->hget(RANKING_KEY.$this->redis_key_account,$myInfo['account_id']),true);//$myInfo['account_id']
@ -96,13 +99,14 @@ class SeasonController extends BaseAuthedController {
'season_reward' => Season::seasonReward($rankMeta),
'current_point' => $this->myRankedInfo['point'],
'total_point' => $totalPoint,
'celCecVal' => $totalPoint * 0.15,
);
$this->_rspData(['info'=>$info]);
}
public function getRankingInfo(){
$rankList = array();
if ($this->redisService->exists(RANKING_KEY.$this->redis_key_ranking)){
if ( $this->rankingState && $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)){
$redisData = json_decode($this->redisService->hget(RANKING_KEY.$this->redis_key_ranking,$i),true);
@ -167,11 +171,13 @@ class SeasonController extends BaseAuthedController {
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'],
));
if ($row['ranking_point'] > 0){
array_push($list,array(
'season' => $row['season'],
'ranking' => $row['ranking'],
'ranking_point' => $row['ranking_point'],
));
}
});
$this->_rspData(array(
'data' => $list,

View File

@ -0,0 +1,81 @@
<?php
namespace models;
use mt;
use phpcommon;
use phpcommon\SqlHelper;
class RankingSetRecord
{
public static function find(){
$row = SqlHelper::ormSelectOne
(myself()->_getSelfMysql(),
't_ranking_settlement_record',
array(
'account_id' => myself()->_getAccountId(),
)
);
if (!$row){
$row = array();
}
return $row;
}
public static function toDto($row){
$data = array(
'state' => $row['state'],
'last_rank' => $row['last_rank'],
'current_rank' => $row['current_rank'],
'last_score' => $row['last_score'],
'current_score' => $row['current_score'],
'awards' => json_decode($row['awards']),
);
self::updateState();
return $data;
}
public static function updateState(){
SqlHelper::update
(myself()->_getSelfMysql(),
't_ranking_settlement_record',
array(
'account_id' => myself()->_getAccountId(),
),
array(
'state' => 0,
)
);
}
public static function upsert($fieldKv){
SqlHelper::upsert
(myself()->_getSelfMysql(),
't_ranking_settlement_record',
array(
'account_id' => myself()->_getAccountId(),
),
array(
'state' => $fieldKv['state'],
'last_rank' => $fieldKv['last_rank'],
'current_rank' => $fieldKv['current_rank'],
'last_score' => $fieldKv['last_score'],
'current_score' => $fieldKv['current_score'],
'awards' => $fieldKv['awards'],
'modifytime' => myself()->_getNowTime(),
),
array(
'account_id' => myself()->_getAccountId(),
'state' => $fieldKv['state'],
'last_rank' => $fieldKv['last_rank'],
'current_rank' => $fieldKv['current_rank'],
'last_score' => $fieldKv['last_score'],
'current_score' => $fieldKv['current_score'],
'awards' => $fieldKv['awards'],
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime()
)
);
}
}

View File

@ -91,7 +91,7 @@ class RealtimeData extends BaseModel {
//获取排位的赛季
public static function getRankSeason(){
$db = self::internalGet('ranking_season');
return max(1, $db ? $db['value1']: 0);
return max(0, $db ? $db['value1']: 0);
}
//设置排位的赛季
public static function setRankSeason($value){

View File

@ -24,12 +24,11 @@ class RankSeason
$metaList = self::getMetaList();
$count = count($metaList);
foreach ($metaList as $key => $meta) {
if (myself()->_getNowTime() >= strtotime($metaList[$key]['end_time']) &&
myself()->_getNowTime() <= strtotime($metaList[$key+1]['start_time'])) {
return $meta;
}
if ($key == $count && myself()->_getNowTime() >= strtotime($meta['end_time'])) {
return $meta;
}elseif (myself()->_getNowTime() >= strtotime($metaList[$key]['end_time']) &&
myself()->_getNowTime() <= strtotime($metaList[$key+1]['start_time'])) {
return $meta;
}
}
return array();
@ -73,6 +72,5 @@ class RankSeason
return null;
}
protected static $metaList;
}
}