Files
ZYZ/game-server/app/services/donateService.ts
mamengke01 afddeba1c9 捐献
2021-01-29 16:35:42 +08:00

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;
}