邮件一键领取bug
This commit is contained in:
@@ -9,6 +9,8 @@ import { findWhere } from 'underscore';
|
||||
import { nowSeconds } from '../../../pubUtils/timeUtil';
|
||||
import { GroupMailType } from '../../../db/GroupMail';
|
||||
import { MailType } from '../../../db/Mail';
|
||||
import { mongoose } from '@typegoose/typegoose';
|
||||
const { ObjectId } = mongoose.Types;
|
||||
export default function (app: Application) {
|
||||
return new GMRemote(app);
|
||||
}
|
||||
@@ -150,22 +152,22 @@ export class GMRemote {
|
||||
let nowTime = nowSeconds();
|
||||
let mailGoods = [];
|
||||
let mails = [];
|
||||
let mailIds: string[] = [];
|
||||
let groupMailIds: string[] = [];
|
||||
let mailIds = [];
|
||||
let groupMailIds = [];
|
||||
groupMailRewards.map(({_id, goods, mailId, mailTemType})=>{
|
||||
if (mailTemType == MAIL_TEM_TYPE.GMTYPE) {
|
||||
let gmMail = getGmMailById(mailId, serverId, nowTime);
|
||||
if (!gmMail || !gmMail.goods.length|| gmMail.endTime < nowSeconds()) {
|
||||
return;
|
||||
}
|
||||
mailGoods.push(...gmMail.goods);
|
||||
mailGoods.push(...goods);
|
||||
} else {
|
||||
if (goods.length)
|
||||
return;
|
||||
mailGoods.push(...goods);
|
||||
}
|
||||
mails.push({id: _id, status: MAIL_STATUS.RECEIVED, mailType: MAIL_TYPE.GROUPMAIL});
|
||||
groupMailIds.push(_id);
|
||||
groupMailIds.push(ObjectId(_id));
|
||||
});
|
||||
mailRewards.map(({_id, goods, mailId, mailTemType})=>{
|
||||
if (mailTemType == MAIL_TEM_TYPE.GMTYPE) {
|
||||
@@ -180,7 +182,7 @@ export class GMRemote {
|
||||
mailGoods.push(...goods);
|
||||
}
|
||||
mails.push({id: _id, status: MAIL_STATUS.RECEIVED, mailType: MAIL_TYPE.SINGLEMAIL});
|
||||
mailIds.push(_id);
|
||||
mailIds.push(ObjectId(_id));
|
||||
});
|
||||
return {mailIds, groupMailIds, mails, mailGoods};
|
||||
}
|
||||
|
||||
@@ -6,7 +6,8 @@ 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';
|
||||
import { mongoose } from '@typegoose/typegoose';
|
||||
const { ObjectId } = mongoose.Types;
|
||||
import { nowSeconds } from '../../../pubUtils/timeUtil';
|
||||
export default function(app: Application) {
|
||||
return new RoleHandler(app);
|
||||
@@ -55,15 +56,15 @@ export class RoleHandler {
|
||||
} else {//一键删除
|
||||
let mails = [];
|
||||
let resGroupMailIds = await GroupMailModel.findReadAndRewardsMails(roleId);
|
||||
let groupMailIds: string[] = resGroupMailIds.map(({_id})=>{
|
||||
let groupMailIds = resGroupMailIds.map(({_id})=>{
|
||||
mails.push({id:_id, status: MAIL_STATUS.DELETE, mailType: MAIL_TYPE.GROUPMAIL});
|
||||
return _id;
|
||||
return ObjectId(_id);
|
||||
});
|
||||
await GroupMailModel.updateMailStatus(groupMailIds, MAIL_STATUS.DELETE, roleId);
|
||||
let resMailIds = await MailModel.findReadAndRewardsMails(roleId);
|
||||
let mailIds: string[] = resMailIds.map(({_id})=>{
|
||||
let mailIds = resMailIds.map(({_id})=>{
|
||||
mails.push({id: _id, status: MAIL_STATUS.DELETE, mailType: MAIL_TYPE.SINGLEMAIL});
|
||||
return _id;
|
||||
return ObjectId(_id);
|
||||
});
|
||||
await MailModel.updateMailStatus(mailIds, MAIL_STATUS.DELETE);
|
||||
|
||||
|
||||
@@ -86,9 +86,9 @@ export default class GroupMail extends BaseModel {
|
||||
return ids;
|
||||
}
|
||||
|
||||
public static async updateMailStatus(ids: string[], status: number, roleId: string) {
|
||||
const result = await GroupMailModel.update({_id: {$in: ids}, 'sendRoles.roleId': roleId, sendTime:{$lte: nowSeconds()}}, { $set:{ 'sendRoles.$.status': status } });
|
||||
return result;
|
||||
public static async updateMailStatus(ids: any[], status: number, roleId: string) {
|
||||
const count = await GroupMailModel.update({_id: {$in: ids}, 'sendRoles.roleId': roleId, sendTime:{$lte: nowSeconds()}}, { $set:{ 'sendRoles.$.status': status } });
|
||||
return count;
|
||||
}
|
||||
|
||||
public static async delMail(_id: string, roleId: string, lean = true) {
|
||||
|
||||
@@ -81,8 +81,9 @@ export default class Mail extends BaseModel {
|
||||
return ids;
|
||||
}
|
||||
|
||||
public static async updateMailStatus(ids: string[], status: number) {
|
||||
await MailModel.update({ _id: { $in: ids } }, { $set: { status } });
|
||||
public static async updateMailStatus(ids: any[], status: number) {
|
||||
let count = await MailModel.update({ _id: { $in: ids } }, { $set: { status } });
|
||||
return count;
|
||||
}
|
||||
|
||||
public static async delMail(_id: string, lean = true) {
|
||||
|
||||
@@ -34,8 +34,7 @@ export async function mailInit() {
|
||||
let gmMail = new Map<number, any>();
|
||||
let mails = await GMMailModel.getMails();
|
||||
mails.map((o:any)=>{
|
||||
let id:string = JSON.stringify(o._id);
|
||||
o.id = id;
|
||||
o.id = o._id.toString();
|
||||
o.updatedAt = Math.floor(o.updatedAt.getTime()/1000);
|
||||
let mail = gmMail.get(o.serverId);
|
||||
if (!mail)
|
||||
@@ -50,8 +49,7 @@ export async function mailInit() {
|
||||
|
||||
export function setMails(mails:GMMail[], gmMail) {
|
||||
mails.map((o:any)=>{
|
||||
let id:string = JSON.stringify(o._id);
|
||||
o.id = id;
|
||||
o.id = o._id.toString();
|
||||
o.updatedAt = Math.floor(o.updatedAt.getTime()/1000);
|
||||
o.sendName = o.sendName||'系统';
|
||||
let mail = gmMail.get(o.serverId);
|
||||
|
||||
Reference in New Issue
Block a user