邮件 活跃度下发
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import {Application, RouteRecord, FrontendOrBackendSession, HandlerCallback} from "pinus";
|
||||
import {checkEvent, getCurrentTime} from '../../../services/eventSercive';
|
||||
|
||||
import {checkEvent} from '../../../services/eventSercive';
|
||||
import { refresh } from '../../../services/refreshService';
|
||||
module.exports = function(app: Application) {
|
||||
return new Filter(app);
|
||||
}
|
||||
@@ -15,7 +15,7 @@ Filter.prototype.before = function (routeRecord: RouteRecord, msg: any, session:
|
||||
};
|
||||
|
||||
Filter.prototype.after = function (err: Error, routeRecord: RouteRecord, msg: any, session: FrontendOrBackendSession, resp: any, next: HandlerCallback) {
|
||||
getCurrentTime(session);
|
||||
refresh(session);
|
||||
return checkEvent(session).then(()=>{
|
||||
next(err);
|
||||
}).catch(e => {
|
||||
|
||||
@@ -11,6 +11,7 @@ import { CHAT_SERVER } from '../../../consts';
|
||||
import { getDonation } from '../../../services/donateService';
|
||||
import { getUserGuildWithRefActive } from '../../../services/guildService';
|
||||
import { ARMY } from '../../../pubUtils/dicParam';
|
||||
import { addActive } from '../../../services/guildService'
|
||||
export default function(app: Application) {
|
||||
return new DonationHandler(app);
|
||||
}
|
||||
@@ -59,6 +60,8 @@ export class DonationHandler {
|
||||
//增加基金
|
||||
const { fund } = await GuildModel.updateInfo(code, {}, { fund: rewardFund }, 'fund');
|
||||
this.app.rpc.chat.guildRemote.updateInfo.toServer(CHAT_SERVER, code, { fund });
|
||||
await addActive(roleId, serverId, 1, id);
|
||||
|
||||
return resResult(STATUS.SUCCESS, { donateFund, reports, donateCnt, goods });
|
||||
}
|
||||
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
import { Application, BackendSession, pinus } from 'pinus';
|
||||
import { Application, BackendSession } from 'pinus';
|
||||
import { resResult, genCode, getRandomByLen } from '../../../pubUtils/util';
|
||||
import { STATUS } from '../../../consts';
|
||||
import { BossInstanceModel } from '../../../db/BossInstance';
|
||||
import { BattleRecordModel } from '../../../db/BattleRecord';
|
||||
import { nowSeconds, getTodayZeroPoint } from '../../../pubUtils/timeUtil';
|
||||
import { getBossInstanceInfo, bossResult, checkMemberExists, pushBossHpMessage, getBossInstanceWhenEnd, addBossInstance } from '../../../services/guildBossService';
|
||||
import { findWhere, random } from 'underscore'
|
||||
import { GUILD_DATA_NAME, GUILD_STRUCTURE } from '../../../consts/constModules/guildConst';
|
||||
import { findWhere } from 'underscore'
|
||||
import { GUILD_STRUCTURE } from '../../../consts/constModules/guildConst';
|
||||
import { DATA_NAME } from '../../../consts/dataName';
|
||||
import { UserGuildModel } from '../../../db/UserGuild';
|
||||
import { GUILD_OPERATE } from '../../../consts';
|
||||
import { checkAuth, addActive } from '../../../services/guildService';
|
||||
import { GuildModel } from '../../../db/Guild';
|
||||
import { getBossByLv } from '../../../pubUtils/data';
|
||||
import { lockData } from '../../../services/redLockService';
|
||||
import { handleCost } from '../../../services/rewardService';
|
||||
|
||||
export default function (app: Application) {
|
||||
return new GuildHandler(app);
|
||||
@@ -59,6 +61,8 @@ export class GuildHandler {
|
||||
//开启演武场
|
||||
async openBossInstance(msg: {}, session: BackendSession) {
|
||||
const roleId: string = session.get('roleId');
|
||||
const sid: string = session.get('sid');
|
||||
|
||||
const serverId: number = parseInt(session.get('serverId'));
|
||||
let userGuild = await UserGuildModel.getMyGuild(roleId, 'auth guildCode');
|
||||
if (!userGuild)
|
||||
@@ -66,7 +70,7 @@ export class GuildHandler {
|
||||
const { guildCode: code } = userGuild;
|
||||
const checkMyResult = await checkAuth(GUILD_OPERATE.OPEN_BOSS, roleId, null, userGuild);
|
||||
if(!checkMyResult) return resResult(STATUS.GUILD_AUTH_NOT_ENOUGH);
|
||||
let res:any = await lockData(serverId, GUILD_DATA_NAME.BOSS_SCRIPT, code);//加锁
|
||||
let res:any = await lockData(serverId, DATA_NAME.BOSS_SCRIPT, code);//加锁
|
||||
if (!!res.err)
|
||||
return resResult(STATUS.REDLOCK_ERR);
|
||||
let bossInstance = await BossInstanceModel.findBossInstance(code);
|
||||
@@ -83,14 +87,13 @@ export class GuildHandler {
|
||||
return resResult(STATUS.GUILD_STRUCTURE_NOT_FOUND);
|
||||
}
|
||||
let bossBase = getBossByLv(curStructure.lv);
|
||||
//消耗TODO
|
||||
let {bossHp, warId, bossLevel } = getRandomByLen(bossBase.wars);
|
||||
let resGuild = await GuildModel.costFund(code, bossBase.consume)
|
||||
let { bossHp, warId } = getRandomByLen(bossBase.wars);
|
||||
let resGuild = await GuildModel.costFund(code, bossBase.opencost);
|
||||
if (!resGuild)
|
||||
return resResult(STATUS.GUILD_FUND_NOT_ENOUGH);
|
||||
await BossInstanceModel.openBossInstance(code, bossHp, warId, bossLevel);
|
||||
await BossInstanceModel.openBossInstance(code, bossHp, warId, bossBase.bossLevel);
|
||||
res.releaseCallback();
|
||||
let result = {warId, ranks: [], myRank: {}, bossHp, status: 3, bossLv: bossLevel, isBattled: false};
|
||||
let result = {warId, ranks: [], myRank: {}, bossHp, status: 3, bossLv: bossBase.bossLevel, isBattled: false};
|
||||
return resResult(STATUS.SUCCESS, result);
|
||||
}
|
||||
|
||||
@@ -111,14 +114,10 @@ export class GuildHandler {
|
||||
return resResult(STATUS.GUILD_SCRIPT_IS_BATTLED);
|
||||
let { warId, ranks } = bossInstance;
|
||||
const battleCode = genCode(8); // 关卡唯一值
|
||||
//TODO查看地图字典
|
||||
let warInfo;
|
||||
await BattleRecordModel.updateBattleRecordByCode(battleCode, {
|
||||
$set: {
|
||||
roleId, roleName, battleId: warId,
|
||||
status: 0,
|
||||
// warName: warInfo.gk_name,
|
||||
// warType: warInfo.warType,
|
||||
record: { heroes:[],recordNum: bossInstance.num, bossHp: bossInstance.bossHp},
|
||||
}
|
||||
}, true);
|
||||
@@ -147,7 +146,7 @@ export class GuildHandler {
|
||||
//记录伤害
|
||||
let bossInstance = await BossInstanceModel.updateBossHp(code, damage, roleId);
|
||||
if (!bossInstance) {//进入结算
|
||||
let flag = await bossResult(code, serverId, GUILD_DATA_NAME.BOSS_SCRIPT, roleId, damage);
|
||||
let flag = await bossResult(code, serverId, DATA_NAME.BOSS_SCRIPT, roleId, damage);
|
||||
if (!flag) {
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Application, BackendSession, pinus, ChannelService } from 'pinus';
|
||||
import { resResult, getRandEelm, getRefTime } from '../../../pubUtils/util';
|
||||
import { STATUS, GUILD_OPERATE, GUILD_AUTH, GUILD_JOB, GUILD_APPLY_TYPE, GUILD_STRUCTURE, GUILD_REC_TYPE, GUILD_STRUCTURE_NAME, MAIL_TYPE, REDIS_KEY, GUILD_DATA_NAME, CHAT_SERVER } from '../../../consts';
|
||||
import { STATUS, GUILD_OPERATE, GUILD_AUTH, GUILD_JOB, GUILD_APPLY_TYPE, GUILD_STRUCTURE, GUILD_REC_TYPE, GUILD_STRUCTURE_NAME, MAIL_TYPE, REDIS_KEY, CHAT_SERVER } from '../../../consts';
|
||||
import { UserGuildModel } from '../../../db/UserGuild';
|
||||
import { checkAuth, joinGuild, getGuildWithRefActive, getUserGuildWithRefActive, addActive, settleGuildWeekly } from '../../../services/guildService';
|
||||
import { GuildModel, GuildType } from '../../../db/Guild';
|
||||
@@ -17,7 +17,7 @@ import { GuildRecModel } from '../../../db/GuildRec';
|
||||
import { sendMail } from '../../../services/mailService';
|
||||
import { existsRank, initSingleRankWithServer, getRank, setRank, redisUserInfoUpdate, redisUserInfoAdd, removeFromRank, getMyRank, isRoleOnline } from '../../../services/redisService';
|
||||
import { lockData } from '../../../services/redLockService';
|
||||
|
||||
import { DATA_NAME } from '../../../consts/dataName';
|
||||
import { openGuildRefine } from '../../../services/guildRefineService';
|
||||
import { unlockTrain } from '../../../services/guildTrainService';
|
||||
export default function (app: Application) {
|
||||
@@ -713,7 +713,7 @@ export class GuildHandler {
|
||||
const checkResult = await checkAuth(GUILD_OPERATE.UP_STRUCTURE, roleId, code);
|
||||
if (!checkResult) return resResult(STATUS.GUILD_AUTH_NOT_ENOUGH);
|
||||
|
||||
let res:any = await lockData(serverId, GUILD_DATA_NAME.UP_STRUCTURE, code);// 加锁
|
||||
let res:any = await lockData(serverId, DATA_NAME.UP_STRUCTURE, code);// 加锁
|
||||
if (!!res.err) return resResult(STATUS.REDLOCK_ERR);
|
||||
|
||||
const guild = await GuildModel.findByCode(code, serverId, 'lv structure');
|
||||
|
||||
@@ -9,11 +9,12 @@ import { handleCost, addItems, checkGoods } from '../../../services/rewardServic
|
||||
import { GuildModel } from '../../../db/Guild';
|
||||
import { findIndex, findWhere } from 'underscore';
|
||||
import { lockData } from '../../../services/redLockService';
|
||||
import { GUILD_DATA_NAME, GUILD_STRUCTURE } from '../../../consts/constModules/guildConst';
|
||||
import { checkAuth } from '../../../services/guildService';
|
||||
import { ARMY } from '../../../pubUtils/dicParam';
|
||||
import { CURRENCY_BY_TYPE, CURRENCY_TYPE } from '../../../consts/constModules/itemConst';
|
||||
import { openGuildRefine } from '../../../services/guildRefineService';
|
||||
import { DATA_NAME } from '../../../consts/dataName';
|
||||
|
||||
export default function (app: Application) {
|
||||
return new GuildRefineHandler(app);
|
||||
}
|
||||
@@ -80,7 +81,7 @@ export class GuildRefineHandler {
|
||||
let developConsume = getArmyDevelopConsumeById(id);
|
||||
if (!developConsume)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
let res:any = await lockData(serverId, GUILD_DATA_NAME.GUILD_REFINE, code);//加锁
|
||||
let res:any = await lockData(serverId, DATA_NAME.GUILD_REFINE, code);//加锁
|
||||
if (!!res.err)
|
||||
return resResult(STATUS.REDLOCK_ERR);
|
||||
let guildRefine = await GuildRefineModel.getRefine(code);
|
||||
@@ -115,7 +116,7 @@ export class GuildRefineHandler {
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code } = userGuild;
|
||||
let res:any = await lockData(serverId, GUILD_DATA_NAME.GUILD_ASSIST_REFINE, code);//加锁
|
||||
let res:any = await lockData(serverId, DATA_NAME.GUILD_ASSIST_REFINE, code);//加锁
|
||||
if (!!res.err)
|
||||
return resResult(STATUS.REDLOCK_ERR);
|
||||
let guildRefine = await GuildRefineModel.getRefine(code);
|
||||
|
||||
@@ -7,7 +7,7 @@ import { nowSeconds, getHourPoint, getCurHourPoint } from '../../../pubUtils/tim
|
||||
import { getUserGuild, getGuildTrainInfo, unlockTrain, resetTrain, getGuildTrainRewards} from '../../../services/guildTrainService';
|
||||
import { findIndex, findWhere, indexBy } from 'underscore'
|
||||
import { lockData } from '../../../services/redLockService';
|
||||
import { GUILD_DATA_NAME, REFRESH_HOUR, GUILD_REPORT_NUM } from '../../../consts/constModules/guildConst';
|
||||
import { REFRESH_HOUR, GUILD_REPORT_NUM } from '../../../consts/constModules/guildConst';
|
||||
import { UserGuildModel } from '../../../db/UserGuild';
|
||||
import { GuildModel } from '../../../db/Guild';
|
||||
import { getArmyTrainJuDian, getTrainSoloReward, getTrainBaseByLv } from '../../../pubUtils/data';
|
||||
@@ -16,6 +16,8 @@ import { handleCost, addItems } from '../../../services/rewardService';
|
||||
import { ARMY } from '../../../pubUtils/dicParam';
|
||||
import { addActive } from '../../../services/guildService';
|
||||
import { GuildTrainReportModel } from '../../../db/GuildTrainReport';
|
||||
import { DATA_NAME } from '../../../consts/dataName';
|
||||
|
||||
export default function (app: Application) {
|
||||
return new GuildTrainHandler(app);
|
||||
}
|
||||
@@ -168,7 +170,7 @@ export class GuildTrainHandler {
|
||||
|
||||
let trainId = battleRecord.record.trainId;
|
||||
let hid = battleRecord.record.hid;
|
||||
let res:any = await lockData(serverId, GUILD_DATA_NAME.TRAIN, code + '_' + trainId);//加锁
|
||||
let res:any = await lockData(serverId, DATA_NAME.TRAIN, code + '_' + trainId);//加锁
|
||||
if (!!res.err)
|
||||
return resResult(STATUS.REDLOCK_ERR);
|
||||
let guildTrain = await GuildTrainModel.findTrainByTrainIdNotLock(code, trainId);
|
||||
@@ -249,7 +251,7 @@ export class GuildTrainHandler {
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code } = userGuild;
|
||||
let { trainLv } = await GuildModel.findGuild(code, serverId, 'structure');
|
||||
let res:any = await lockData(serverId, GUILD_DATA_NAME.TRAIN_BOX, code + '_' + trainId);//加锁
|
||||
let res:any = await lockData(serverId, DATA_NAME.TRAIN_BOX, code + '_' + trainId);//加锁
|
||||
if (!!res.err)
|
||||
return resResult(STATUS.REDLOCK_ERR);
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import { UserGuildModel } from '../../../db/UserGuild';
|
||||
import { GuildModel } from '../../../db/Guild';
|
||||
import { gameData } from '../../../pubUtils/data';
|
||||
|
||||
import { getMails } from '../../../services/mailService';
|
||||
export default function (app: Application) {
|
||||
return new EntryHandler(app);
|
||||
}
|
||||
@@ -56,6 +57,7 @@ export class EntryHandler {
|
||||
await session.abind(role.roleId);
|
||||
session.set('uid', role.roleId);
|
||||
session.set('roleId', role.roleId);
|
||||
session.set('updatedMailAt', role.updatedMailAt);
|
||||
session.set('roleName', role.roleName);
|
||||
session.set('eventStatus', role.eventStatus);
|
||||
session.set('sid', self.app.get('serverId'));
|
||||
@@ -89,7 +91,7 @@ export class EntryHandler {
|
||||
let heros = await HeroModel.findByRole(role.roleId, [], HERO_SELECT.ENTRY, true);
|
||||
let equips = await EquipModel.findbyRole(role.roleId);
|
||||
let items = await ItemModel.findbyRole(role.roleId);
|
||||
|
||||
let mails = await getMails(role.roleId, serverId)
|
||||
await chackFunOpenWhenLogin(role, session);
|
||||
await loginRefresh(role.roleId);
|
||||
|
||||
@@ -98,6 +100,9 @@ export class EntryHandler {
|
||||
role['consumeGoods'] = items;
|
||||
let apJson = await getAp(Date.now(), role.roleId);
|
||||
role['apJson'] = apJson;
|
||||
role['ce'] = reduceCe(role.ce);
|
||||
role['topFiveCe'] = reduceCe(role.topFiveCe);
|
||||
role['mails'] = mails;
|
||||
|
||||
if(role.hasGuild) {
|
||||
let userGuild = await UserGuildModel.getMyGuild(role.roleId, USER_GUILD_SELECT.ENTRY );
|
||||
|
||||
20
game-server/app/servers/gate/remote/gateRemote.ts
Normal file
20
game-server/app/servers/gate/remote/gateRemote.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { Application, ChannelService, FrontendSession, RemoterClass } from 'pinus';
|
||||
import { setGmMails, getGmMailById, getGmMails } from '../../../pubUtils/gmData/gmDataUtil';
|
||||
import { MAIL_TYPE, MAIL_TEM_TYPE } from "../../../consts/constModules/mailConst";
|
||||
import { mailData } from "../../../pubUtils/interface";
|
||||
import { getContent } from '../../../services/mailService';
|
||||
import { findWhere } from 'underscore';
|
||||
export default function (app: Application) {
|
||||
return new GateRemote(app);
|
||||
}
|
||||
|
||||
export class GateRemote {
|
||||
|
||||
constructor(private app: Application) {
|
||||
this.app = app;
|
||||
this.channelService = app.get('channelService');
|
||||
}
|
||||
|
||||
private channelService: ChannelService;
|
||||
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
import {Application, BackendSession} from 'pinus';
|
||||
import {Application, BackendSession, pinus} from 'pinus';
|
||||
import { RoleModel } from '../../../db/Role';
|
||||
import { EventRecordModel } from '../../../db/EventRecord';
|
||||
import { getEvent } from '../../../services/eventSercive';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
import { STATUS } from '../../../consts/statusCode';
|
||||
|
||||
|
||||
import { GMMailModel } from '../../../db/GMMail';
|
||||
import { setGmMails } from '../../../pubUtils/gmData/gmDataUtil';
|
||||
export default function(app: Application) {
|
||||
return new GmHandler(app);
|
||||
}
|
||||
@@ -70,7 +70,6 @@ export class GmHandler {
|
||||
channel.add(roleId, sid);
|
||||
}
|
||||
|
||||
|
||||
let tsid = channel.getMember(roleId)['sid'];
|
||||
channelService.pushMessageByUids(eventName, resResult(STATUS.SUCCESS, content), [{
|
||||
uid: roleId,
|
||||
@@ -78,4 +77,10 @@ export class GmHandler {
|
||||
}]);
|
||||
return resResult(STATUS.SUCCESS, { msg: content });
|
||||
}
|
||||
|
||||
async addMail(msg: { endTime: number, serverId: number, sendName: string, content: string, goods, sendRoles:[{roleId: string, status: number}], gmMailType: number, sendTime: number, }) {
|
||||
let {sendRoles, endTime, content, sendName, gmMailType, sendTime, goods, serverId} = msg;
|
||||
let mail = await GMMailModel.addMail({serverId, sendRoles, sendName, endTime, content, gmMailType, sendTime, goods});
|
||||
setGmMails([mail]);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,13 @@
|
||||
import { Application, ChannelService, FrontendSession, RemoterClass } from 'pinus';
|
||||
import { Application, ChannelService } from 'pinus';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
import { STATUS } from '../../../consts';
|
||||
|
||||
import { setGmMails, getGmMailById, getGmMails } from '../../../pubUtils/gmData/gmDataUtil';
|
||||
import { MAIL_TYPE, MAIL_TEM_TYPE } from "../../../consts/constModules/mailConst";
|
||||
import { mailData } from "../../../pubUtils/interface";
|
||||
import { getContent } from '../../../services/mailService';
|
||||
import { findWhere } from 'underscore';
|
||||
export default function (app: Application) {
|
||||
return new ChatRemote(app);
|
||||
return new GMRemote(app);
|
||||
}
|
||||
|
||||
// rpc 定义挪到单独的定义文件(user.rpc.define.ts)。解决ts-node 有可能找不到定义的问题。
|
||||
@@ -13,11 +17,11 @@ export default function (app: Application) {
|
||||
// declare global {
|
||||
// interface UserRpc {
|
||||
// chat: {
|
||||
// chatRemote: RemoterClass<FrontendSession, ChatRemote>;
|
||||
// GMRemote: RemoterClass<FrontendSession, GMRemote>;
|
||||
// };
|
||||
// }
|
||||
// }
|
||||
export class ChatRemote {
|
||||
export class GMRemote {
|
||||
|
||||
constructor(private app: Application) {
|
||||
this.app = app;
|
||||
@@ -91,4 +95,47 @@ export class ChatRemote {
|
||||
};
|
||||
channel.pushMessage('onLeave', resResult(STATUS.SUCCESS, param));
|
||||
}
|
||||
|
||||
public async refreshGmMails(mails:[any]) {
|
||||
setGmMails(mails);
|
||||
}
|
||||
|
||||
public async getMailInfos(roleId: string, serverId: number, mails: [any], groupMails: [any]) {
|
||||
let list: mailData[] = [];
|
||||
mails.map(async function({ mailId, goods, sendTime, params, status, _id, mailTemType, sendName, endTime}) {
|
||||
if (mailTemType == MAIL_TEM_TYPE.GAMEMAIL) { //模板邮件
|
||||
let { content } = getContent(parseInt(mailId), params);
|
||||
if (!content)
|
||||
return;
|
||||
list.push({ id: _id, mailId, goods, sendTime, endTime, content, status, mailType: MAIL_TYPE.SINGLEMAIL, sendName });
|
||||
} else if (mailTemType == MAIL_TEM_TYPE.GMTYPE) { //系统邮件
|
||||
let gmMail = getGmMailById(mailId, serverId);
|
||||
if (!gmMail)
|
||||
return;
|
||||
let { goods, sendTime, content, endTime, sendName } = gmMail;
|
||||
list.push({ id: _id, mailId, goods, sendTime, endTime, content, status, mailType: MAIL_TYPE.SINGLEMAIL, sendName });
|
||||
}
|
||||
});
|
||||
groupMails.map(async function({ mailId, goods, sendTime, endTime, params, sendRoles, _id, mailTemType, sendName }) {
|
||||
let { status } = findWhere(sendRoles, {roleId});
|
||||
if (mailTemType == MAIL_TEM_TYPE.GAMEMAIL) { //模板邮件
|
||||
let { content } = getContent( parseInt(mailId), params);
|
||||
if (!content)
|
||||
return;
|
||||
list.push({ id: _id, mailId, goods, sendTime, content, endTime, status, mailType: MAIL_TYPE.GROUPMAIL, sendName });
|
||||
} else if (mailTemType == MAIL_TEM_TYPE.GMTYPE) { //系统邮件
|
||||
let gmMail = getGmMailById(mailId, serverId);
|
||||
if (!gmMail)
|
||||
return;
|
||||
let { goods, sendTime, content, endTime, sendName } = gmMail;
|
||||
list.push({ id: _id, mailId, goods, sendTime, endTime, content, status, mailType: MAIL_TYPE.GROUPMAIL, sendName });
|
||||
}
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
public async getMails(updatedMailAt: number, serverId: number) {
|
||||
let gmMails = getGmMails(updatedMailAt, serverId);
|
||||
return gmMails;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import {Application, BackendSession, ChannelService} from 'pinus';
|
||||
import { handleCost, addItems } from '../../../services/rewardService';
|
||||
import { calPlayerCeAndSave } from '../../../services/playerCeService';
|
||||
import { resResult, returnHeroCeRatio, getAllAttrStage } from '../../../pubUtils/util';
|
||||
import { resResult, returnHeroCeRatio } from '../../../pubUtils/util';
|
||||
import { STATUS } from '../../../consts/statusCode';
|
||||
import {HeroModel} from '../../../db/Hero';
|
||||
import {CURRENCY_BY_TYPE, CURRENCY_TYPE, CONSUME_TYPE, HERO_GROW_MAX, HERO_SYSTEM_TYPE, ITID, ABI_STAGE, HERO_CE_RATIO} from '../../../consts';
|
||||
|
||||
132
game-server/app/servers/role/handler/mailHandler.ts
Normal file
132
game-server/app/servers/role/handler/mailHandler.ts
Normal file
@@ -0,0 +1,132 @@
|
||||
import {Application, BackendSession, ChannelService} from 'pinus';
|
||||
import { MailModel } from '../../../db/Mail';
|
||||
import { GroupMailModel } from '../../../db/GroupMail';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
import { STATUS } from '../../../consts/statusCode';
|
||||
import { findWhere } from 'underscore';
|
||||
import { MAIL_STATUS, MAIL_TEM_TYPE, MAIL_TYPE } from '../../../consts/constModules/mailConst';
|
||||
import { handleCost, addItems } from '../../../services/rewardService';
|
||||
import { getGmMailById } from '../../../pubUtils/gmData/gmDataUtil';
|
||||
export default function(app: Application) {
|
||||
return new RoleHandler(app);
|
||||
}
|
||||
|
||||
export class RoleHandler {
|
||||
constructor(private app: Application) {
|
||||
|
||||
}
|
||||
|
||||
public async refrshMails(msg:{}) {
|
||||
|
||||
}
|
||||
|
||||
public async readMail(msg: { id: string, mailType: number }, session: BackendSession) {
|
||||
let roleId: string = session.get('roleId');
|
||||
let { id, mailType } = msg;
|
||||
let mail;
|
||||
if (mailType == MAIL_TYPE.SINGLEMAIL) {
|
||||
mail = await MailModel.updateMailByStatus(id, [MAIL_STATUS.CREATE], { status: MAIL_STATUS.READ });
|
||||
} else if (mailType == MAIL_TYPE.GROUPMAIL) {
|
||||
mail = await GroupMailModel.updateMailByStatus(id, roleId, MAIL_STATUS.READ, [MAIL_STATUS.CREATE]);
|
||||
}
|
||||
if (!mail)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
return resResult(STATUS.SUCCESS, { mails: [{ id, status: MAIL_STATUS.READ, mailType }] });
|
||||
}
|
||||
|
||||
public async delMails(msg: { id: string, mailType: number, type: number }, session: BackendSession) {
|
||||
let roleId: string = session.get('roleId');
|
||||
let { id, type, mailType } = msg;
|
||||
if (type == 1) {//单个删除
|
||||
if (mailType == MAIL_TYPE.SINGLEMAIL) {
|
||||
let mail = await MailModel.delMail(id);
|
||||
if (!mail)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
return resResult(STATUS.SUCCESS, { mails: [{ id, status: MAIL_STATUS.DELETE, mailType }] });
|
||||
} else if (mailType == MAIL_TYPE.GROUPMAIL) {
|
||||
let mail = await GroupMailModel.delMail(id, roleId);
|
||||
if (!mail)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
return resResult(STATUS.SUCCESS, { mails: [{ id, status: MAIL_STATUS.DELETE, mailType }] });
|
||||
} else {
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
}
|
||||
} else {//一键删除
|
||||
let groupMailIds = await GroupMailModel.findReadAndRewardsMails(roleId);
|
||||
await GroupMailModel.updateMailStatus(groupMailIds, MAIL_STATUS.DELETE, roleId);
|
||||
let mailIds = await MailModel.findReadAndRewardsMails(roleId);
|
||||
await MailModel.updateMailStatus(mailIds, MAIL_STATUS.DELETE);
|
||||
let mails = [];
|
||||
groupMailIds.map((id)=>{
|
||||
mails.push({id, status: MAIL_STATUS.DELETE, mailType: MAIL_TYPE.GROUPMAIL});
|
||||
});
|
||||
mailIds.map((id)=>{
|
||||
mails.push({id, status: MAIL_STATUS.DELETE, mailType: MAIL_TYPE.SINGLEMAIL});
|
||||
});
|
||||
return resResult(STATUS.SUCCESS, { mails });
|
||||
}
|
||||
}
|
||||
|
||||
public async getMailRewards(msg: { id: string, mailType: number, type: number }, session: BackendSession) {
|
||||
let roleId: string = session.get('roleId');
|
||||
let roleName: string = session.get('roleName');
|
||||
let sid: string = session.get('sid');
|
||||
let serverId: number = session.get('serverId');
|
||||
let { id, type, mailType } = msg;
|
||||
let mailGoods = [];
|
||||
let mails = [];
|
||||
if (type == 1) {//单个领取
|
||||
let mail;
|
||||
if (mailType == MAIL_TYPE.SINGLEMAIL) {
|
||||
mail = await MailModel.updateMailByStatus(id, [MAIL_STATUS.READ], { status: MAIL_STATUS.RECEIVED });
|
||||
if (!mail)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
} else if (mailType == MAIL_TYPE.GROUPMAIL) {
|
||||
mail = await GroupMailModel.updateMailByStatus(id, roleId, MAIL_STATUS.RECEIVED, [MAIL_STATUS.READ]);
|
||||
if (!mail)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
} else {
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
}
|
||||
mails.push({id, status: MAIL_STATUS.DELETE, mailType});
|
||||
if (mail.mailTemType == MAIL_TEM_TYPE.GMTYPE) {
|
||||
let gmMail = getGmMailById(id, serverId);
|
||||
mailGoods.push(...gmMail.goods);
|
||||
} else {
|
||||
mailGoods.push(...mail.goods);
|
||||
}
|
||||
} else {//一键领取
|
||||
let ids;
|
||||
let groupMailRewards = await GroupMailModel.findRewardsMails(roleId);
|
||||
ids = groupMailRewards.map(({_id, goods, mailTemType})=>{
|
||||
if (mailTemType == MAIL_TEM_TYPE.GMTYPE) {
|
||||
let gmMail = getGmMailById(id, serverId);
|
||||
mailGoods.push(...gmMail.goods);
|
||||
} else {
|
||||
mailGoods.push(...goods);
|
||||
}
|
||||
mails.push({id: _id, status: MAIL_STATUS.DELETE, mailType: MAIL_TYPE.GROUPMAIL});
|
||||
return _id;
|
||||
});
|
||||
if (!!ids.length)
|
||||
await GroupMailModel.updateMailStatus(ids, MAIL_STATUS.RECEIVED, roleId);
|
||||
let mailRewards = await MailModel.findRewardsMails(roleId);
|
||||
ids = mailRewards.map(({_id, goods, mailTemType})=>{
|
||||
if (mailTemType == MAIL_TEM_TYPE.GMTYPE) {
|
||||
let gmMail = getGmMailById(id, serverId);
|
||||
mailGoods.push(...gmMail.goods);
|
||||
} else {
|
||||
mailGoods.push(...goods);
|
||||
}
|
||||
mails.push({id, status: MAIL_STATUS.DELETE, mailType: MAIL_TYPE.SINGLEMAIL});
|
||||
return _id;
|
||||
});
|
||||
if (!!ids.length)
|
||||
await MailModel.updateMailStatus(ids, MAIL_STATUS.RECEIVED);
|
||||
}
|
||||
let resGoods = [];
|
||||
if (!!mailGoods && !!mailGoods.length)
|
||||
resGoods = await addItems(roleId, roleName, sid, mailGoods);
|
||||
return resResult(STATUS.SUCCESS, { mails, goods: resGoods });
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import { BattleRemote } from './battle/remote/battleRemote';
|
||||
import { ConnectorRemote } from './connector/remote/connectorRemote';
|
||||
import { SystimerRemote } from './systimer/remote/systimerRemote';
|
||||
import { GuildRemote } from './chat/remote/guildRemote';
|
||||
|
||||
import { GMRemote } from './gm/remote/gmRemote';
|
||||
declare global {
|
||||
interface UserRpc {
|
||||
chat: {
|
||||
@@ -25,6 +25,9 @@ declare global {
|
||||
};
|
||||
systimer: {
|
||||
systimerRemote: RemoterClass<FrontendSession, SystimerRemote>;
|
||||
},
|
||||
gm: {
|
||||
gmRemote: RemoterClass<FrontendSession, GMRemote>;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user