军团:添加补发捐献宝箱

This commit is contained in:
luying
2022-05-12 18:44:17 +08:00
parent eca5ec1733
commit 861ef65e34
6 changed files with 61 additions and 52 deletions

View File

@@ -1,8 +1,7 @@
import BaseModel from './BaseModel';
import { getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
import { nowSeconds } from '../pubUtils/timeUtil';
class Report {
export class Report {
@prop({ required: true })
roleName: string;
@@ -20,9 +19,6 @@ export default class Donation extends BaseModel {
@prop({ required: true, default: 0})
donateFund: number;
@prop({ required: true, default: 0})
hisDonateFund: number; //历史捐赠最高
@prop({ required: true, type: Report, default:[], _id: false })
reports: Array<Report>;
@@ -33,25 +29,18 @@ export default class Donation extends BaseModel {
@prop({ required: true })
donationLv: number;
public static async createDonation(guildCode: string, donationLv: number, lean = true) {
const doc = new DonationModel();
const update = Object.assign(doc.toJSON(), {refTime: nowSeconds(), reports:[], hisDonateFund: 0, donateFund: 0, donationLv});
const result: DonationType = await DonationModel.findOneAndUpdate({ guildCode }, {$set:update}, {upsert: true, new: true}).lean(lean);
public static async findOrCreateDonationByRefTime(guildCode: string, refTime: number, donationLv: number ) {
const result: DonationType = await DonationModel.findOneAndUpdate({ guildCode, refTime }, { $setOnInsert: { donateFund: 0, reports: [], donationLv }}, { upsert: true, new: true }).lean();
return result;
}
public static async getDonation(guildCode: string, select?: string, lean = true) {
const result: DonationType = await DonationModel.findOne({ guildCode }).select(select).lean(lean);
public static async donate(guildCode: string, refTime: number, donateFund: number, reports: Report, donationLv: number) {
const result: DonationType = await DonationModel.findOneAndUpdate({ guildCode, refTime }, { $setOnInsert: { donationLv }, $inc:{ donateFund }, $push: { reports }}, {upsert: true, new: true}).lean();
return result;
}
public static async donation(guildCode: string, donateFund: number, pushDate: {reports?: Report}, lean = true) {
const result: DonationType = await DonationModel.findOneAndUpdate({ guildCode }, {$inc:{ donateFund, hisDonateFund: donateFund }, $push:pushDate}, {upsert: true, new: true}).lean(lean);
return result;
}
public static async updateDonation(guildCode: string, update: DonationUpdateParam, lean = true) {
const result: DonationType = await DonationModel.findOneAndUpdate({ guildCode }, { $set:update }, {upsert: true, new: true}).lean(lean);
public static async findDonationByRefTime(guildCode: string, refTime: number ) {
const result: DonationType = await DonationModel.findOne({ guildCode, refTime }).lean();
return result;
}
}