训练场宝箱展示bug
This commit is contained in:
+14
-10
@@ -3,9 +3,13 @@ import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoos
|
||||
import { nowSeconds } from '../pubUtils/timeUtil';
|
||||
import { MAIL_STATUS } from '../consts/constModules/mailConst';
|
||||
class RewardInter {
|
||||
@prop({ required: true })
|
||||
id: number;
|
||||
@prop({ required: true })
|
||||
count: number;
|
||||
}
|
||||
|
||||
|
||||
@index({ roleId: 1 })
|
||||
@index({ roleId: 1, mailId: 1, type: 1 })
|
||||
|
||||
@@ -17,12 +21,12 @@ export default class Mail extends BaseModel {
|
||||
mailId: string;
|
||||
|
||||
@prop({ required: true, type: RewardInter, default: [], _id: false })
|
||||
goods: RewardInter[];
|
||||
goods: Array<RewardInter>;
|
||||
|
||||
@prop({ required: true, default: nowSeconds() })
|
||||
sendTime: number;
|
||||
|
||||
@prop({ required: true })
|
||||
@prop({ required: true, type: String, _id: false})
|
||||
params: string[];
|
||||
|
||||
@prop({ required: true, default: MAIL_STATUS.CREATE })
|
||||
@@ -48,32 +52,32 @@ export default class Mail extends BaseModel {
|
||||
}
|
||||
|
||||
public static async getMailsByRoleId(roleId: string, lean = true) {
|
||||
const result: MailType[] = await MailModel.find({ roleId, status: { $ne: -1 } }).lean(lean);
|
||||
const result: MailType[] = await MailModel.find({ roleId, status: { $ne: -1 }, sendTime:{$lte: nowSeconds()} }).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async getMail(roleId: string, mailId: string, mailTemType: number, lean = true) {
|
||||
const result: MailType = await MailModel.findOne({ roleId, mailId, mailTemType }).lean(lean);
|
||||
const result: MailType = await MailModel.findOne({ roleId, mailId, mailTemType, sendTime:{$lte: nowSeconds()} }).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async getMailById(_id: string, lean = true) {
|
||||
const result: MailType = await MailModel.findOne({ _id }).lean(lean);
|
||||
const result: MailType = await MailModel.findOne({ _id, sendTime:{$lte: nowSeconds()} }).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async updateMailByStatus(_id: string, conditions: number[], update: MailTypeParam, lean = true) {
|
||||
const result: MailType = await MailModel.findOneAndUpdate({ _id, status: { $in: conditions } }, { $set: update }, { new: true }).lean(lean);
|
||||
const result: MailType = await MailModel.findOneAndUpdate({ _id, status: { $in: conditions }, sendTime:{$lte: nowSeconds()} }, { $set: update }, { new: true }).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async updateMail(_id: string, update: MailTypeParam, lean = true) {
|
||||
const result: MailType = await MailModel.findOneAndUpdate({ _id }, { $set: update }, { new: true }).lean(lean);
|
||||
const result: MailType = await MailModel.findOneAndUpdate({ _id, sendTime:{$lte: nowSeconds()} }, { $set: update }, { new: true }).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async findReadAndRewardsMails(roleId: string, lean = true) {
|
||||
const ids: string[] = await MailModel.find({ roleId, $or: [{ $and: [{ status: MAIL_STATUS.READ, goods: [] }] }, { status: MAIL_STATUS.RECEIVED }] }).select('_id').lean(lean);
|
||||
const ids: string[] = await MailModel.find({ roleId, $or: [{ $and: [{ status: MAIL_STATUS.READ, goods: [] }] }, { status: MAIL_STATUS.RECEIVED }], sendTime:{$lte: nowSeconds()} }).select('_id').lean(lean);
|
||||
return ids;
|
||||
}
|
||||
|
||||
@@ -82,12 +86,12 @@ export default class Mail extends BaseModel {
|
||||
}
|
||||
|
||||
public static async delMail(_id: string, lean = true) {
|
||||
const result: MailType = await MailModel.findOneAndUpdate({ _id, $or: [{ $and: [{ status: MAIL_STATUS.READ, goods: [] }] }, { status: MAIL_STATUS.RECEIVED }] }, { $set: { status: MAIL_STATUS.DELETE } }, { new: true }).lean(lean);
|
||||
const result: MailType = await MailModel.findOneAndUpdate({ _id, $or: [{ $and: [{ status: MAIL_STATUS.READ, goods: [] }] }, { status: MAIL_STATUS.RECEIVED }], sendTime:{$lte: nowSeconds()} }, { $set: { status: MAIL_STATUS.DELETE } }, { new: true }).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async findRewardsMails(roleId: string, lean = true) {
|
||||
const result: MailType[] = await MailModel.find({ roleId, $and: [{ status: MAIL_STATUS.READ, goods: { $ne: [] } }] }).select('_id goods').lean(lean);
|
||||
const result: MailType[] = await MailModel.find({ roleId, status: {$in: [ MAIL_STATUS.CREATE, MAIL_STATUS.READ ] }, sendTime:{$lte: nowSeconds()} }).select('_id goods mailTemType').lean(lean);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user