背包:装备邮件处理
This commit is contained in:
@@ -5,10 +5,14 @@ import { resResult } from '../../../pubUtils/util';
|
||||
import { STATUS } from '../../../consts/statusCode';
|
||||
import { MAIL_STATUS, MAIL_TEM_TYPE, GM_MAIL_TYPE } from '../../../consts/constModules/mailConst';
|
||||
import { addItems } from '../../../services/rewardService';
|
||||
import { getMails } from '../../../services/mailService';
|
||||
import { checkMailGoods, getMails } from '../../../services/mailService';
|
||||
import { ServerMailModel, ServerMailType } from '../../../db/ServerMail';
|
||||
import { MailParam } from '../../../domain/roleField/mail';
|
||||
import { RewardInter } from '../../../pubUtils/interface';
|
||||
import { ItemInter, RewardInter } from '../../../pubUtils/interface';
|
||||
import { RoleModel } from '../../../db/Role';
|
||||
import { gameData } from '../../../pubUtils/data';
|
||||
import { ITID, RECEIVE_MAIL_TYPE } from '../../../consts';
|
||||
import { BAG } from '../../../pubUtils/dicParam';
|
||||
|
||||
export default function(app: Application) {
|
||||
return new MailHandler(app);
|
||||
@@ -80,46 +84,68 @@ export class MailHandler {
|
||||
}
|
||||
}
|
||||
|
||||
public async getMailRewards(msg: { id: string, mailType: number, type: number }, session: BackendSession) {
|
||||
public async getMailRewards(msg: { id: string, mailType: number, type: RECEIVE_MAIL_TYPE }, 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 mails: MailParam[] = [];
|
||||
if (type == 1) {//单个领取
|
||||
let { equipCount } = await RoleModel.findByRoleId(roleId, 'equipCount');
|
||||
|
||||
let originMails: {mailType: GM_MAIL_TYPE, mail: MailType|GroupMailType|ServerMailType}[] = []
|
||||
|
||||
if (type == RECEIVE_MAIL_TYPE.SINGLE) {//单个领取
|
||||
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]);
|
||||
mail = await MailModel.getMailById(id);
|
||||
} else if (mailType == GM_MAIL_TYPE.GROUP) {
|
||||
mail = await GroupMailModel.updateStatusWithCondition(id, roleId, MAIL_STATUS.RECEIVED, [MAIL_STATUS.READ, MAIL_STATUS.CREATE]);
|
||||
mail = await GroupMailModel.getMailById(id);
|
||||
} else if (mailType == GM_MAIL_TYPE.SERVER) {
|
||||
mail = await ServerMailModel.updateStatusWithCondition(id, roleId, MAIL_STATUS.RECEIVED, [MAIL_STATUS.READ, MAIL_STATUS.CREATE]);
|
||||
mail = await ServerMailModel.getMailById(id);
|
||||
}
|
||||
if (!mail) return resResult(STATUS.WRONG_PARMS);
|
||||
mails.push(new MailParam(mailType, mail, roleId));
|
||||
originMails.push({ mailType, mail });
|
||||
} else {//一键领取
|
||||
let singlemails = await MailModel.findRewardsMails(roleId);
|
||||
let groupMails = await GroupMailModel.findRewardsMails(roleId);
|
||||
let servermails = await ServerMailModel.findRewardsMails(serverId, roleId);
|
||||
[
|
||||
{ mails: singlemails, mailType: GM_MAIL_TYPE.SINGLE },
|
||||
{ mails: groupMails, mailType: GM_MAIL_TYPE.GROUP },
|
||||
{ mails: servermails, mailType: GM_MAIL_TYPE.SERVER },
|
||||
].forEach(({ mails, mailType }) => {
|
||||
mails.forEach((mail: MailType|GroupMailType|ServerMailType) => {
|
||||
originMails.push({ mailType, mail })
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
for(let mail of singlemails) {
|
||||
let mailGoods: ItemInter[] = [], mails: MailParam[] = [];
|
||||
for(let { mail, mailType } of originMails) {
|
||||
let { isEquipOver, equipCount: newEquipCount } = checkMailGoods(mail, equipCount);
|
||||
if(isEquipOver) {
|
||||
if(type == RECEIVE_MAIL_TYPE.SINGLE) {
|
||||
return resResult(STATUS.EQUIP_IS_OVER);
|
||||
} else {
|
||||
continue; // 如果有装备数量超过,那么一键领取这条邮件就不领了
|
||||
}
|
||||
}
|
||||
equipCount = newEquipCount;
|
||||
|
||||
if(mailType == GM_MAIL_TYPE.SINGLE) {
|
||||
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) {
|
||||
} else if (mailType == GM_MAIL_TYPE.GROUP) {
|
||||
mail = await GroupMailModel.updateStatusWithCondition(mail._id, roleId, MAIL_STATUS.RECEIVED, [MAIL_STATUS.READ, MAIL_STATUS.CREATE]);
|
||||
} else if (mailType == GM_MAIL_TYPE.SERVER) {
|
||||
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 mailGoods: RewardInter[] = [];
|
||||
for(let mail of mails) {
|
||||
mailGoods.push(...mail.goods)
|
||||
}
|
||||
if(!mail) return resResult(STATUS.MAIL_HAS_RECEIVE);
|
||||
|
||||
let mailObj = new MailParam(mailType, mail, roleId);
|
||||
mailGoods.push(...mailObj.goods);
|
||||
mails.push(mailObj);
|
||||
}
|
||||
|
||||
let resGoods = await addItems(roleId, roleName, sid, mailGoods);
|
||||
|
||||
return resResult(STATUS.SUCCESS, { mails, goods: resGoods });
|
||||
|
||||
Reference in New Issue
Block a user