邮件:修改邮件逻辑
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
import {Application, BackendSession, ChannelService} from 'pinus';
|
||||
import { MailModel } from '../../../db/Mail';
|
||||
import { GroupMailModel } from '../../../db/GroupMail';
|
||||
import { MailModel, MailType } from '../../../db/Mail';
|
||||
import { GroupMailModel, GroupMailType } from '../../../db/GroupMail';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
import { STATUS } from '../../../consts/statusCode';
|
||||
import { MAIL_STATUS, MAIL_TEM_TYPE, MAIL_TYPE } from '../../../consts/constModules/mailConst';
|
||||
import { MAIL_STATUS, MAIL_TEM_TYPE, GM_MAIL_TYPE } from '../../../consts/constModules/mailConst';
|
||||
import { addItems } from '../../../services/rewardService';
|
||||
import { nowSeconds } from '../../../pubUtils/timeUtil';
|
||||
import { getMails } from '../../../services/mailService';
|
||||
import { ServerMailModel, ServerMailType } from '../../../db/ServerMail';
|
||||
import { MailParam } from '../../../domain/roleField/mail';
|
||||
import { RewardInter } from '../../../pubUtils/interface';
|
||||
|
||||
export default function(app: Application) {
|
||||
return new MailHandler(app);
|
||||
}
|
||||
@@ -32,47 +35,47 @@ export class MailHandler {
|
||||
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 }] });
|
||||
if (mailType == GM_MAIL_TYPE.SINGLE) {
|
||||
mail = await MailModel.updateStatusWithCondition(id, MAIL_STATUS.READ, [MAIL_STATUS.CREATE]);
|
||||
} else if (mailType == GM_MAIL_TYPE.GROUP) {
|
||||
mail = await GroupMailModel.updateStatusWithCondition(id, roleId, MAIL_STATUS.READ, [MAIL_STATUS.CREATE]);
|
||||
} else if (mailType == GM_MAIL_TYPE.SERVER) {
|
||||
mail = await ServerMailModel.updateStatusWithCondition(id, roleId, MAIL_STATUS.READ, [MAIL_STATUS.CREATE])
|
||||
}
|
||||
// if (!mail)
|
||||
// return resResult(STATUS.WRONG_PARMS);
|
||||
return resResult(STATUS.SUCCESS, { mails: mail?[{ 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);
|
||||
let mail: MailType|GroupMailType|ServerMailType;
|
||||
if (mailType == GM_MAIL_TYPE.SINGLE) {
|
||||
mail = await MailModel.delMailById(id);
|
||||
} else if (mailType == GM_MAIL_TYPE.GROUP) {
|
||||
mail = await GroupMailModel.delMailById(id, roleId);
|
||||
} else if (mailType == GM_MAIL_TYPE.SERVER) {
|
||||
mail = await ServerMailModel.delMailById(id, roleId);
|
||||
}
|
||||
if (!mail) return resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
return resResult(STATUS.SUCCESS, { mails: [{ id: mail._id, mailType, status: MAIL_STATUS.DELETE}] });
|
||||
} else {//一键删除
|
||||
let mails = [];
|
||||
let resGroupMailIds = await GroupMailModel.findReadAndRewardsMails(roleId);
|
||||
let groupMailIds = resGroupMailIds.map(({_id})=>{
|
||||
mails.push({id:_id, status: MAIL_STATUS.DELETE, mailType: MAIL_TYPE.GROUPMAIL});
|
||||
return _id;
|
||||
});
|
||||
await GroupMailModel.updateMailStatus(groupMailIds, MAIL_STATUS.DELETE, roleId);
|
||||
let resMailIds = await MailModel.findReadAndRewardsMails(roleId);
|
||||
let mailIds = resMailIds.map(({_id})=>{
|
||||
mails.push({id: _id, status: MAIL_STATUS.DELETE, mailType: MAIL_TYPE.SINGLEMAIL});
|
||||
return _id;
|
||||
});
|
||||
await MailModel.updateMailStatus(mailIds, MAIL_STATUS.DELETE);
|
||||
let singlemails = await MailModel.delMailsByRoleId(roleId);
|
||||
let groupMails = await GroupMailModel.delMailsByRoleId(roleId);
|
||||
let servermails = await ServerMailModel.delMailsByRoleId(roleId);
|
||||
let mails: { id: string, mailType: GM_MAIL_TYPE, status: MAIL_STATUS }[] = [];
|
||||
for(let mail of singlemails) {
|
||||
mails.push({ id: mail._id, mailType: GM_MAIL_TYPE.SINGLE, status: MAIL_STATUS.DELETE });
|
||||
}
|
||||
for(let mail of groupMails) {
|
||||
mails.push({ id: mail._id, mailType: GM_MAIL_TYPE.GROUP, status: MAIL_STATUS.DELETE });
|
||||
}
|
||||
for(let mail of servermails) {
|
||||
mails.push({ id: mail._id, mailType: GM_MAIL_TYPE.SERVER, status: MAIL_STATUS.DELETE });
|
||||
}
|
||||
return resResult(STATUS.SUCCESS, { mails });
|
||||
}
|
||||
}
|
||||
@@ -83,44 +86,42 @@ export class MailHandler {
|
||||
let sid: string = session.get('sid');
|
||||
let serverId: number = session.get('serverId');
|
||||
let { id, type, mailType } = msg;
|
||||
let mailGoods = [];
|
||||
let mails = [];
|
||||
let nowTime: number = nowSeconds();
|
||||
let mails: MailParam[] = [];
|
||||
if (type == 1) {//单个领取
|
||||
let mail;
|
||||
if (mailType == MAIL_TYPE.SINGLEMAIL) {
|
||||
mail = await MailModel.updateMailByStatus(id, [MAIL_STATUS.READ, MAIL_STATUS.CREATE], { 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, MAIL_STATUS.CREATE]);
|
||||
if (!mail)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
} else {
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
}
|
||||
mails.push({ id, status: MAIL_STATUS.RECEIVED, mailType });
|
||||
if (mail.mailTemType == MAIL_TEM_TYPE.GMTYPE) {
|
||||
let gmMail = await this.app.rpc.gm.gmRemote.getUseGmMailById.toServer('gm-server-1', mail.mailId, serverId, nowTime);
|
||||
if (!gmMail)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
mailGoods.push(...gmMail.goods);
|
||||
} else {
|
||||
mailGoods.push(...mail.goods);
|
||||
let mail: MailType|GroupMailType|ServerMailType;
|
||||
if (mailType == GM_MAIL_TYPE.SINGLE) {
|
||||
mail = await MailModel.updateStatusWithCondition(id, MAIL_STATUS.RECEIVED, [MAIL_STATUS.READ, MAIL_STATUS.CREATE]);
|
||||
} else if (mailType == GM_MAIL_TYPE.GROUP) {
|
||||
mail = await GroupMailModel.updateStatusWithCondition(id, roleId, MAIL_STATUS.RECEIVED, [MAIL_STATUS.READ, MAIL_STATUS.CREATE]);
|
||||
} else if (mailType == GM_MAIL_TYPE.SERVER) {
|
||||
mail = await ServerMailModel.updateStatusWithCondition(id, roleId, MAIL_STATUS.RECEIVED, [MAIL_STATUS.READ, MAIL_STATUS.CREATE]);
|
||||
}
|
||||
if (!mail) return resResult(STATUS.WRONG_PARMS);
|
||||
mails.push(new MailParam(mailType, mail, roleId));
|
||||
} else {//一键领取
|
||||
let groupMailRewards = await GroupMailModel.findRewardsMails(roleId);
|
||||
let mailRewards = await MailModel.findRewardsMails(roleId);
|
||||
let { mailGoods: goods, mailIds, groupMailIds} = await this.app.rpc.gm.gmRemote.getUseMails.toServer('gm-server-1', serverId, groupMailRewards, mailRewards);
|
||||
mailGoods = goods;
|
||||
if (!!groupMailIds.length) //领取群体邮件
|
||||
mails = await GroupMailModel.updateMailStatus(groupMailIds, MAIL_STATUS.RECEIVED, roleId);
|
||||
if (!!mailIds.length) //领取单个邮件
|
||||
mails = await MailModel.updateMailStatus(mailIds, MAIL_STATUS.RECEIVED);
|
||||
let singlemails = await MailModel.findRewardsMails(roleId);
|
||||
let groupMails = await GroupMailModel.findRewardsMails(roleId);
|
||||
let servermails = await ServerMailModel.findRewardsMails(serverId, roleId);
|
||||
|
||||
for(let mail of singlemails) {
|
||||
mail = await MailModel.updateStatusWithCondition(mail._id, MAIL_STATUS.RECEIVED, [MAIL_STATUS.READ, MAIL_STATUS.CREATE]);
|
||||
if(mail) mails.push(new MailParam(GM_MAIL_TYPE.SINGLE, mail, roleId));
|
||||
}
|
||||
for(let mail of groupMails) {
|
||||
mail = await GroupMailModel.updateStatusWithCondition(mail._id, roleId, MAIL_STATUS.RECEIVED, [MAIL_STATUS.READ, MAIL_STATUS.CREATE]);
|
||||
if(mail) mails.push(new MailParam(GM_MAIL_TYPE.GROUP, mail, roleId));
|
||||
}
|
||||
for(let mail of servermails) {
|
||||
mail = await ServerMailModel.updateStatusWithCondition(mail._id, roleId, MAIL_STATUS.RECEIVED, [MAIL_STATUS.READ, MAIL_STATUS.CREATE]);
|
||||
if(mail) mails.push(new MailParam(GM_MAIL_TYPE.SERVER, mail, roleId));
|
||||
}
|
||||
}
|
||||
let resGoods = [];
|
||||
if (!!mailGoods && !!mailGoods.length)
|
||||
resGoods = await addItems(roleId, roleName, sid, mailGoods);
|
||||
let mailGoods: RewardInter[] = [];
|
||||
for(let mail of mails) {
|
||||
mailGoods.push(...mail.goods)
|
||||
}
|
||||
let resGoods = await addItems(roleId, roleName, sid, mailGoods);
|
||||
|
||||
return resResult(STATUS.SUCCESS, { mails, goods: resGoods });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user