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