This commit is contained in:
mamengke01
2021-01-29 16:35:42 +08:00
parent 75d07b0550
commit afddeba1c9
12 changed files with 205 additions and 41 deletions
+26
View File
@@ -0,0 +1,26 @@
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;
}
+4 -4
View File
@@ -161,7 +161,7 @@ export async function addActive(roleId: string, serverId: number, id: number, ty
}
/**
* 获取用户公会表并刷新活跃
* 获取用户公会表并刷新活跃和每日捐赠以及每日许愿数据
* @param roleId 用户id
* @param select 筛选字段
*/
@@ -174,9 +174,9 @@ export async function getUserGuildWithRefActive(roleId: string, select: string)
const now = new Date();
let isRefDaily = shouldRefresh(refTimeDaily, now, 0);
if(isRefDaily) {
receivedActive = []; refTimeDaily = now; activeDaily = 0; activeRecord = [];
userGuild = await UserGuildModel.updateInfo(roleId, { receivedActive, refTimeDaily, activeDaily, activeRecord }, {}, select);
receivedActive = []; refTimeDaily = now; activeDaily = 0; activeRecord = [];
let wishGoods = [], receiveBoxs = [], wishDntCnt = 0, donateCnt = 0;
userGuild = await UserGuildModel.updateInfo(roleId, { receivedActive, refTimeDaily, activeDaily, activeRecord, wishGoods, receiveBoxs, wishDntCnt, donateCnt }, {}, select);
if(!userGuild) return false;
}