活动:限时排行榜
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
import { Application, BackendSession, HandlerService, } from 'pinus';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
import { DEBUG_MAGIC_WORD, getRedisKeyByRankType, HERO_SELECT, ITEM_CHANGE_REASON, RANK_TYPE, ROLE_SELECT, STATUS } from '../../../consts';
|
||||
import { addItems, combineItems, handleCost } from '../../../services/rewardService';
|
||||
import { ActivityTurntableModel } from '../../../db/ActivityTurntableRec';
|
||||
import { pick } from 'underscore';
|
||||
import { addReward, stringToRewardInter, stringToRewardParam } from '../../../services/activity/giftPackageService';
|
||||
import { getTimeLimitRankData, getTimeLimitRankDataShow, sendRankMail, takeSnapshot } from '../../../services/activity/timeLimitRankService';
|
||||
import { getRankInHandler, Rank } from '../../../services/rankService';
|
||||
import { getActivityById } from '../../../services/activity/activityService';
|
||||
import { TimeLimitRankData } from '../../../domain/activityField/timeLimitRankField';
|
||||
import { hasKey } from '../../../services/redisService';
|
||||
import { KeyName } from '../../../domain/rank';
|
||||
|
||||
|
||||
export default function (app: Application) {
|
||||
new HandlerService(app, {});
|
||||
return new TimeLimitRankHandler(app);
|
||||
}
|
||||
|
||||
export class TimeLimitRankHandler {
|
||||
constructor(private app: Application) {
|
||||
}
|
||||
|
||||
/************************幸运转盘****************************/
|
||||
/**
|
||||
* @description 幸运转盘活动
|
||||
* @param {{ activityId: number, }} msg
|
||||
* @param {BackendSession} session
|
||||
* @memberof TimeLimitRankHandler
|
||||
*/
|
||||
async getTimeLimitRankData(msg: { activityId: number }, session: BackendSession) {
|
||||
const { activityId } = msg;
|
||||
|
||||
let playerData = await getTimeLimitRankDataShow(activityId);
|
||||
if (!playerData) {
|
||||
return resResult(STATUS.ACTIVITY_MISSING);
|
||||
}
|
||||
|
||||
return resResult(STATUS.SUCCESS, { playerData });
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获得排行榜
|
||||
* @param {{ activityId: number, }} msg
|
||||
* @param {BackendSession} session
|
||||
* @memberof TimeLimitRankHandler
|
||||
*/
|
||||
async getRank(msg: { activityId: number }, session: BackendSession) {
|
||||
const { activityId } = msg;
|
||||
const roleId = session.get('roleId');
|
||||
const serverId = session.get('serverId');
|
||||
|
||||
let playerData = await getTimeLimitRankData(activityId);
|
||||
if (!playerData) {
|
||||
return resResult(STATUS.ACTIVITY_MISSING);
|
||||
}
|
||||
let type = playerData.rankType;
|
||||
|
||||
let redisKey = getRedisKeyByRankType(type, true);
|
||||
let keyName = new KeyName(redisKey, { serverId, activityId });
|
||||
if(!(await hasKey(keyName.getName()))) {
|
||||
redisKey = getRedisKeyByRankType(type);
|
||||
}
|
||||
if (!redisKey) return resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
let result = await getRankInHandler(redisKey, type, { serverId, activityId: playerData.activityId }, session);
|
||||
if(!result) return resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
...pick(playerData, ['activityId', 'tabName', 'beginTime', 'endTime', 'rankEndTime', 'rankType']),
|
||||
...result
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
async debugSendMail(msg: { magicWord: string, activityId: number }, session: BackendSession) {
|
||||
const { magicWord, activityId } = msg;
|
||||
if (magicWord !== DEBUG_MAGIC_WORD) {
|
||||
return resResult(STATUS.TOKEN_ERR);
|
||||
}
|
||||
let playerData = await getTimeLimitRankData(activityId);
|
||||
await sendRankMail(playerData);
|
||||
return resResult(STATUS.SUCCESS);
|
||||
}
|
||||
|
||||
async debugTakeSnapshot(msg: { magicWord: string, activityId: number }, session: BackendSession) {
|
||||
const { magicWord, activityId } = msg;
|
||||
if (magicWord !== DEBUG_MAGIC_WORD) {
|
||||
return resResult(STATUS.TOKEN_ERR);
|
||||
}
|
||||
let activityData = await getActivityById(activityId);
|
||||
|
||||
let playerData = new TimeLimitRankData(activityData, 0);
|
||||
if(!playerData.needSnapshot) return resResult(STATUS.WRONG_PARMS);
|
||||
await takeSnapshot(playerData, activityData.groupId);
|
||||
return resResult(STATUS.SUCCESS);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user