军团:添加补发捐献宝箱
This commit is contained in:
@@ -1,16 +1,11 @@
|
||||
|
||||
import { DonationModel } from '../db/Donation';
|
||||
import { DonationModel, Report } from '../db/Donation';
|
||||
import { getZeroPoint, nowSeconds } from '../pubUtils/timeUtil';
|
||||
import { GuildModel, GuildType } from '../db/Guild';
|
||||
import { findWhere } from 'underscore';
|
||||
import { GUILD_STRUCTURE } from '../consts/constModules/guildConst';
|
||||
import { getGuildChannelSid } from './chatService';
|
||||
import { pinus } from 'pinus';
|
||||
import { lockData } from './redLockService';
|
||||
import { ACTIVITY_TYPE, DATA_NAME } from '../consts';
|
||||
import { gameData } from '../pubUtils/data';
|
||||
import { shouldRefresh } from '../pubUtils/util';
|
||||
import { getActivitiesByType } from './activity/activityService';
|
||||
import { recordGuildFund } from './activity/timeLimitRankService';
|
||||
import { pushGuildInfoUpdate } from './guildService';
|
||||
/**
|
||||
@@ -18,29 +13,28 @@ import { pushGuildInfoUpdate } from './guildService';
|
||||
* @param code
|
||||
* @param serverId
|
||||
*/
|
||||
export async function getDonation(code: string, guild: GuildType, serverId: number) {
|
||||
let donation = await DonationModel.getDonation(code);
|
||||
if (!donation) {
|
||||
donation = await createDonation(code, guild, serverId);
|
||||
}
|
||||
if (donation.refTime < getZeroPoint()) {
|
||||
let { lv } = guild.structure.find(cur => cur.id == GUILD_STRUCTURE.DONATE);
|
||||
donation = await DonationModel.updateDonation(code, { donateFund:0, reports:[], refTime: nowSeconds(), donationLv: lv});
|
||||
}
|
||||
export async function getDonation(code: string, guild: GuildType) {
|
||||
let refTime = getZeroPoint();
|
||||
let donation = await DonationModel.findOrCreateDonationByRefTime(code, refTime, getDonateLv(guild));
|
||||
return donation;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建军团捐献信息
|
||||
* @param code
|
||||
* @param serverId
|
||||
*/
|
||||
export async function createDonation(code: string, guild: GuildType, serverId: number) {
|
||||
let { lv } = guild.structure.find(cur => cur.id == GUILD_STRUCTURE.DONATE);
|
||||
let donation = await DonationModel.createDonation(code, lv);
|
||||
export async function donate(code: string, fund: number, donateId: number, roleName: string, guild: GuildType) {
|
||||
let refTime = getZeroPoint();
|
||||
let donation = await DonationModel.donate(code, refTime, fund, { id: donateId, roleName, time: refTime }, getDonateLv(guild));
|
||||
return donation;
|
||||
}
|
||||
|
||||
export function getDonateLv(guild: GuildType) {
|
||||
let structure = guild.structure.find(cur => cur.id == GUILD_STRUCTURE.DONATE);
|
||||
return structure? structure.lv: 0;
|
||||
}
|
||||
|
||||
export async function getGuildFundByRefTime(guildCode: string, refTime: number) {
|
||||
let donation = await DonationModel.findDonationByRefTime(guildCode, refTime);
|
||||
return { donationLv: donation? donation.donationLv: 0, fund: donation? donation.donateFund: 0}
|
||||
}
|
||||
|
||||
// 增加资金
|
||||
export async function addFund(code: string, serverId: number, fund: number) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user