军团:添加补发捐献宝箱
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 每周结算上周公会周功勋和 活跃并发奖励(未完)
|
||||
*
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
import { nowSeconds } from '../pubUtils/timeUtil';
|
||||
|
||||
class Report {
|
||||
export class Report {
|
||||
@prop({ required: true })
|
||||
roleName: string;
|
||||
|
||||
@@ -20,9 +19,6 @@ export default class Donation extends BaseModel {
|
||||
|
||||
@prop({ required: true, default: 0})
|
||||
donateFund: number;
|
||||
|
||||
@prop({ required: true, default: 0})
|
||||
hisDonateFund: number; //历史捐赠最高
|
||||
|
||||
@prop({ required: true, type: Report, default:[], _id: false })
|
||||
reports: Array<Report>;
|
||||
@@ -33,25 +29,18 @@ export default class Donation extends BaseModel {
|
||||
@prop({ required: true })
|
||||
donationLv: number;
|
||||
|
||||
public static async createDonation(guildCode: string, donationLv: number, lean = true) {
|
||||
const doc = new DonationModel();
|
||||
const update = Object.assign(doc.toJSON(), {refTime: nowSeconds(), reports:[], hisDonateFund: 0, donateFund: 0, donationLv});
|
||||
const result: DonationType = await DonationModel.findOneAndUpdate({ guildCode }, {$set:update}, {upsert: true, new: true}).lean(lean);
|
||||
public static async findOrCreateDonationByRefTime(guildCode: string, refTime: number, donationLv: number ) {
|
||||
const result: DonationType = await DonationModel.findOneAndUpdate({ guildCode, refTime }, { $setOnInsert: { donateFund: 0, reports: [], donationLv }}, { upsert: true, new: true }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async getDonation(guildCode: string, select?: string, lean = true) {
|
||||
const result: DonationType = await DonationModel.findOne({ guildCode }).select(select).lean(lean);
|
||||
public static async donate(guildCode: string, refTime: number, donateFund: number, reports: Report, donationLv: number) {
|
||||
const result: DonationType = await DonationModel.findOneAndUpdate({ guildCode, refTime }, { $setOnInsert: { donationLv }, $inc:{ donateFund }, $push: { reports }}, {upsert: true, new: true}).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async donation(guildCode: string, donateFund: number, pushDate: {reports?: Report}, lean = true) {
|
||||
const result: DonationType = await DonationModel.findOneAndUpdate({ guildCode }, {$inc:{ donateFund, hisDonateFund: donateFund }, $push:pushDate}, {upsert: true, new: true}).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async updateDonation(guildCode: string, update: DonationUpdateParam, lean = true) {
|
||||
const result: DonationType = await DonationModel.findOneAndUpdate({ guildCode }, { $set:update }, {upsert: true, new: true}).lean(lean);
|
||||
public static async findDonationByRefTime(guildCode: string, refTime: number ) {
|
||||
const result: DonationType = await DonationModel.findOne({ guildCode, refTime }).lean();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -489,6 +489,17 @@ export function getZeroPointD(refreshType: SHOP_REFRESH_TYPE = SHOP_REFRESH_TYPE
|
||||
}
|
||||
}
|
||||
|
||||
export function getZeroPointOfTime(refTime: Date, refreshType: SHOP_REFRESH_TYPE = SHOP_REFRESH_TYPE.DAILY) {
|
||||
let t = new Time(TIME_OUTPUT_TYPE.STAMP_10, refTime);
|
||||
if(refreshType == SHOP_REFRESH_TYPE.DAILY) {
|
||||
return <number>t.getDayZeroPoint();
|
||||
} else if (refreshType == SHOP_REFRESH_TYPE.WEEKLY) {
|
||||
return <number>t.getWeekZeroPoint();
|
||||
} else if (refreshType == SHOP_REFRESH_TYPE.MONTHLY) {
|
||||
return <number>t.getMonthZeroPoint();
|
||||
}
|
||||
}
|
||||
|
||||
export function getZeroPointOfTimeD(refTime: Date, refreshType: SHOP_REFRESH_TYPE = SHOP_REFRESH_TYPE.DAILY) {
|
||||
let t = new Time(TIME_OUTPUT_TYPE.DATE, refTime);
|
||||
if(refreshType == SHOP_REFRESH_TYPE.DAILY) {
|
||||
|
||||
Reference in New Issue
Block a user