26 lines
1.1 KiB
TypeScript
26 lines
1.1 KiB
TypeScript
|
|
import { DonationModel } from '../db/Donation';
|
|
import { nowSeconds } from '../pubUtils/timeUtil';
|
|
import { GuildModel } from '../db/Guild';
|
|
import { findWhere } from 'underscore';
|
|
import { GUILD_STRUCTURE } from '../consts/constModules/guildConst';
|
|
export async function getDonation(code: string, serverId: number) {
|
|
let donation = await DonationModel.getDonation(code);
|
|
if (!donation) {
|
|
donation = await createDonation(code, serverId);
|
|
}
|
|
if (donation.refTime < nowSeconds()) {
|
|
let { structure } = await GuildModel.findGuild(code, serverId, 'structure');
|
|
let { lv } = findWhere(structure, {id: GUILD_STRUCTURE.DONATE});
|
|
donation = await DonationModel.updateDonation(code, { donateFund:0, reports:[], refTime: nowSeconds(), donationLv: lv});
|
|
}
|
|
return donation;
|
|
}
|
|
|
|
|
|
export async function createDonation(code: string, serverId: number) {
|
|
let { structure } = await GuildModel.findGuild(code, serverId, 'structure');
|
|
let { lv } = findWhere(structure, {id: GUILD_STRUCTURE.DONATE});
|
|
let donation = await DonationModel.createDonation(code, lv);
|
|
return donation;
|
|
} |