军团:添加补发捐献宝箱

This commit is contained in:
luying
2022-05-12 18:44:22 +08:00
parent eca5ec1733
commit 861ef65e34
6 changed files with 61 additions and 52 deletions
@@ -8,7 +8,7 @@ import { getArmyDonateBaseByLv, getArmyDonateBoxBaseById } from '../../../pubUti
import { GuildModel } from '../../../db/Guild';
import { handleCost, addItems } from '../../../services/role/rewardService';
import { CHAT_SERVER, GUILD_POINT_WAYS } from '../../../consts';
import { addFund, getDonation } from '../../../services/donateService';
import { addFund, donate, getDonation } from '../../../services/donateService';
import { getUserGuildWithRefActive, refreshUserGuild } from '../../../services/guildService';
import { ARMY } from '../../../pubUtils/dicParam';
import { addActive } from '../../../services/guildService'
@@ -44,7 +44,7 @@ export class DonationHandler {
return resResult(STATUS.WRONG_PARMS);
}
const { guildCode: code, donateCnt, receiveBoxs } = userGuild;
let { donateFund, reports, donationLv } = await getDonation(code, guild, serverId);
let { donateFund, reports, donationLv } = await getDonation(code, guild);
return resResult(STATUS.SUCCESS, { receiveBoxs, donateFund, reports, donateCnt: donateCnt || 0, donationLv });
}
/**
@@ -82,7 +82,7 @@ export class DonationHandler {
res.releaseCallback();
return resResult(STATUS.GUILD_DONATE_TIMES_NOT_ENOUGH);
}
let { donationLv } = await getDonation(code, guild, serverId);
let { donationLv } = await getDonation(code, guild);
let { donateReward } = getArmyDonateBaseByLv(donationLv);
let { rewardGood, rewardFund, cosume } = donateReward.get(id);
let consumeResult = getVipDonateConsume(cosume, session.get('vipStartTime'));
@@ -93,7 +93,7 @@ export class DonationHandler {
}
let { donateCnt } = await UserGuildModel.donateFund(roleId, 1);
let { donateFund, reports } = await DonationModel.donation(code, rewardFund, { reports: { id, roleName, time: nowSeconds() } });
let { donateFund, reports } = await donate(code, rewardFund, id, roleName, guild);
let goods = [];
if (!!rewardGood)
goods = await addItems(roleId, roleName, sid, [rewardGood], ITEM_CHANGE_REASON.DONATE);
@@ -133,7 +133,7 @@ export class DonationHandler {
if (resReceiveBoxs.indexOf(id) != -1)
return resResult(STATUS.GUILD_DONATE_BOXS_IS_GOT);
let { boxRewards, fund, level } = getArmyDonateBoxBaseById(id);
let { donateFund, donationLv } = await getDonation(code, guild, serverId);
let { donateFund, donationLv } = await getDonation(code, guild);
if( donationLv < level) return resResult(STATUS.GUILD_DONATE_LV_NOT_ENOUGH)
if (donateFund < fund)
return resResult(STATUS.GUILD_DONATE_BOXS_NOT_GOT);
+1 -1
View File
@@ -181,7 +181,7 @@ export async function getModuleData(type: string, data: { role: RoleType, sessio
case 'donate':
if (hasGuild) {
const { guildCode: code, donateCnt, receiveBoxs } = userGuild;
let { donateFund, reports, donationLv } = await getDonation(code, guild, serverId);
let { donateFund, reports, donationLv } = await getDonation(code, guild);
return { receiveBoxs, donateFund, reports, donateCnt: donateCnt || 0, donationLv };
}
break;
+17 -23
View File
@@ -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 {
+20 -5
View File
@@ -6,7 +6,7 @@ import { RoleModel, RoleType } from "../db/Role";
import { UserGuildModel, UserGuildType, WishGood } from "../db/UserGuild";
import { UserGuildApplyModel } from "../db/UserGuildApply";
import { PVPConfigModel } from "../db/SystemConfig";
import { getZeroPointD, getZeroPointOfTimeD, nowSeconds } from "../pubUtils/timeUtil";
import { getZeroPointD, getZeroPointOfTime, getZeroPointOfTimeD, nowSeconds } from "../pubUtils/timeUtil";
import { pinus, BackendSession, FrontendOrBackendSession } from "pinus";
import { ARMY } from "../pubUtils/dicParam";
import { sendMailByContent } from "./mailService";
@@ -25,6 +25,7 @@ import { sendMessageToGuildWithSuc, sendMessageToUserWithSuc } from "./pushServi
import { delGuildChannel, leaveGuildChannel } from "./chatChannelService";
import { GuildActiveModel, } from "../db/GuildActive";
import { RewardInter } from "../pubUtils/interface";
import { getGuildFundByRefTime } from "./donateService";
export async function getMyGuildInfo(roleId: string, sid: string, userGuild: UserGuildType, guild: GuildType, serverId: number, session: FrontendOrBackendSession) {
@@ -216,15 +217,16 @@ export async function getUserGuildWithRefActive(roleId: string, select?: string)
export async function refreshUserGuild(userGuild: UserGuildType, roleId: string) {
if(!userGuild) return false;
let { receivedActive, refTimeDaily, activeDaily, activeRecord, wishGoods, receivedWishPool } = userGuild;
let { receivedActive, refTimeDaily, activeDaily, activeRecord, wishGoods, receivedWishPool, receiveBoxs } = userGuild;
const now = new Date();
let isRefDaily = shouldRefresh(refTimeDaily, now);
if (isRefDaily) {
await sendUnreceivedWishPool(wishGoods, roleId);
await sendUnreceivedActiveBox(roleId, userGuild.guildCode, refTimeDaily, receivedActive);
receivedActive = []; refTimeDaily = now; activeDaily = 0; activeRecord = []; wishGoods = []; receivedWishPool = [];
let receiveBoxs = [], wishDntCnt = 0, donateCnt = 0;
await sendUnreceivedDonateBox(roleId, userGuild.guildCode, refTimeDaily, receiveBoxs);
receivedActive = []; refTimeDaily = now; activeDaily = 0; activeRecord = []; wishGoods = []; receivedWishPool = [], receiveBoxs = [];
let wishDntCnt = 0, donateCnt = 0;
userGuild = await UserGuildModel.updateInfo(roleId, { receivedActive, refTimeDaily, activeDaily, activeRecord, wishGoods, receiveBoxs, wishDntCnt, donateCnt, receivedWishPool }, {});
if (!userGuild) return false;
}
@@ -252,7 +254,6 @@ async function sendUnreceivedActiveBox(roleId: string, guildCode: string, refTim
let guildActive = await getGuildActiveByRefTime(guildCode, refTime);
let goods: RewardInter[] = [];
for(let [id, { activeDayPoint, reward }] of gameData.guildActiveDayReward) {
console.log('####', guildActive, activeDayPoint, receiveActiveBox)
if(guildActive >= activeDayPoint && receiveActiveBox.indexOf(id) == -1) goods.push(...reward);
}
if(goods.length > 0) {
@@ -260,6 +261,20 @@ async function sendUnreceivedActiveBox(roleId: string, guildCode: string, refTim
}
}
async function sendUnreceivedDonateBox(roleId: string, guildCode: string, refTimeDaily: Date, receiveBoxs: number[]) {
let refTime = getZeroPointOfTime(refTimeDaily);
let { fund: guildFund, donationLv } = await getGuildFundByRefTime(guildCode, refTime);
let goods: RewardInter[] = [];
for(let [id, { boxRewards, fund, level }] of gameData.armyDonateBox) {
if(level == donationLv && guildFund >= fund && receiveBoxs.indexOf(id) == -1) {
if(boxRewards) goods.push(...boxRewards);
}
}
if(goods.length > 0) {
await sendMailByContent(MAIL_TYPE.GUILD_FUND_BOX, roleId, { goods });
}
}
/**
* 每周结算上周公会周功勋和 活跃并发奖励(未完)
*