添加算力玩法
This commit is contained in:
parent
91e411880d
commit
a3b9d97fd8
@ -8,7 +8,7 @@ function add(name) {
|
||||
function init() {
|
||||
add('season');
|
||||
add('dailyTask');
|
||||
//add('hourlyTask');
|
||||
add('hourlyTask');
|
||||
add('rankings');
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,77 @@
|
||||
const app = require('j7/app');
|
||||
const utils = require('j7/utils');
|
||||
const http = require('j7/http');
|
||||
|
||||
|
||||
const constant = require('../constant');
|
||||
class HourlyTask {
|
||||
async start() {
|
||||
console.log('HourlyTask Start ... ');
|
||||
while (true) {
|
||||
await this.doComputingPower()
|
||||
const now = new Date();
|
||||
// 计算距离下一个整点的秒数
|
||||
const sleepTime = 60 * 60 - (now.getMinutes() * 60 + now.getSeconds()) ;
|
||||
console.log('sleepTime:' + sleepTime, new Date(), sleepTime /60);
|
||||
await utils.sleep(sleepTime * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
async doComputingPower(){
|
||||
try {
|
||||
const {err, conn} = await app.getDbConn("GameDb20060");
|
||||
if (err){
|
||||
throw err
|
||||
}
|
||||
await this.getPowerTotalNum(conn)
|
||||
} catch (err){
|
||||
console.log(err);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
async getPowerTotalNum(conn){
|
||||
const {err, rows} = await conn.execQuery(
|
||||
'select period,sum(total_num) as num from t_power_exchange_record group by period',
|
||||
[]
|
||||
);
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
await utils.serial(rows,
|
||||
async (row,index)=> {
|
||||
await this.upsertTotalPowerNum(conn,row)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
async upsertTotalPowerNum(conn,row){
|
||||
await conn.upsert(
|
||||
't_computing_power_period',
|
||||
[
|
||||
['period',row.period]
|
||||
],
|
||||
[
|
||||
['total_num',row.num]
|
||||
],
|
||||
[
|
||||
['period',row.period],
|
||||
['total_num',row.num],
|
||||
['createtime',utils.getUtcTime()],
|
||||
['modifytime',utils.getUtcTime()],
|
||||
]
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function init() {
|
||||
(new HourlyTask()).start();
|
||||
}
|
||||
|
||||
exports.init = init;
|
@ -40,9 +40,12 @@ class SeasonController extends BaseAuthedController {
|
||||
parent::_handlePre();
|
||||
$this->currRankSeasonMeta = mt\RankSeason::getCurrentSeason();
|
||||
if (!$this->currRankSeasonMeta) {
|
||||
$this->_rspErr(10, 'server internal error');
|
||||
die();
|
||||
$this->currRankSeasonMeta = mt\RankSeason::getLastSeason();
|
||||
}
|
||||
if (!$this->currRankSeasonMeta){
|
||||
$this->_rspErr(10,'server internal error');
|
||||
}
|
||||
|
||||
// $this->propertyChgService = new services\PropertyChgService();
|
||||
// $this->awardService = new services\AwardService();
|
||||
$this->userInfo = $this->_safeGetOrmUserInfo();
|
||||
|
@ -19,6 +19,22 @@ class RankSeason
|
||||
return self::$metaList;
|
||||
}
|
||||
|
||||
public static function getLastSeason()
|
||||
{
|
||||
$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;
|
||||
}
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
public static function getCurrentSeason()
|
||||
{
|
||||
foreach (self::getMetaList() as $meta) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user