邮件 活跃度下发
This commit is contained in:
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 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user