捐献
This commit is contained in:
@@ -6,11 +6,11 @@ import { DonationModel } from '../../../db/Donation';
|
||||
import { nowSeconds } from '../../../pubUtils/timeUtil';
|
||||
import { getArmyDonateBaseByLv, getArmyDonateBoxBaseById } from '../../../pubUtils/data';
|
||||
import { GuildModel } from '../../../db/Guild';
|
||||
import { GUILD_STRUCTURE } from '../../../consts/constModules/guildConst';
|
||||
import { findWhere } from 'underscore';
|
||||
import { handleCost, addItems } from '../../../services/rewardService';
|
||||
import { CHAT_SERVER } from '../../../consts';
|
||||
|
||||
import { getDonation } from '../../../services/donateService';
|
||||
import { getUserGuildWithRefActive } from '../../../services/guildService';
|
||||
import { ARMY } from '../../../pubUtils/dicParam';
|
||||
export default function(app: Application) {
|
||||
return new DonationHandler(app);
|
||||
}
|
||||
@@ -22,11 +22,13 @@ export class DonationHandler {
|
||||
|
||||
async getDonation(msg: {}, session: BackendSession) {
|
||||
const roleId: string = session.get('roleId');
|
||||
let userGuild = await UserGuildModel.getMyGuild(roleId,'donateCnt receiveBoxs guildCode');
|
||||
const serverId: number = parseInt(session.get('serverId'));
|
||||
|
||||
let userGuild = await getUserGuildWithRefActive(roleId, 'donateCnt receiveBoxs guildCode');
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code, donateCnt, receiveBoxs } = userGuild;
|
||||
let { donateFund, reports } = await DonationModel.getDonation(code);
|
||||
let { donateFund, reports } = await getDonation(code, serverId);
|
||||
return resResult(STATUS.SUCCESS, { receiveBoxs, donateFund, reports, donateCnt });
|
||||
}
|
||||
|
||||
@@ -36,22 +38,24 @@ export class DonationHandler {
|
||||
const roleName: string = session.get('roleName');
|
||||
const serverId: number = parseInt(session.get('serverId'));
|
||||
const sid: string = session.get('sid');
|
||||
let userGuild = await UserGuildModel.getMyGuild(roleId,'donateCnt receiveBoxs guildCode');
|
||||
let userGuild = await getUserGuildWithRefActive(roleId, 'donateCnt receiveBoxs guildCode');
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code, donateCnt: resdonateCnt } = userGuild;
|
||||
if (resdonateCnt <= 0)
|
||||
return resResult(STATUS.SUCCESS);
|
||||
let { structure } = await GuildModel.findGuild(code, serverId, 'structure');
|
||||
let { lv } = findWhere(structure, {id: GUILD_STRUCTURE.DONATE});
|
||||
let { donateReward } = getArmyDonateBaseByLv(lv);
|
||||
if (resdonateCnt >= ARMY.ARMY_DONATE_TIMES)
|
||||
return resResult(STATUS.GUILD_DONATE_TIMES_NOT_ENOUGH);
|
||||
let { donationLv } = await getDonation(code, serverId);
|
||||
let { donateReward } = getArmyDonateBaseByLv(donationLv);
|
||||
let { rewardGood, rewardFund, cosume } = donateReward.get(id);
|
||||
let result = await handleCost(roleId, sid, [cosume]);
|
||||
if(!result)
|
||||
return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
||||
let { donateCnt } = await UserGuildModel.donateFund(roleId, 1);
|
||||
|
||||
let { donateFund, reports } = await DonationModel.donation(code, rewardFund, { reports: {id, roleName, time: nowSeconds()}});
|
||||
let goods = await addItems(roleId, roleName, sid, [rewardGood]);
|
||||
let goods = [];
|
||||
if (!!rewardGood)
|
||||
goods = await addItems(roleId, roleName, sid, [rewardGood]);
|
||||
//增加基金
|
||||
const { fund } = await GuildModel.updateInfo(code, {}, { fund: rewardFund }, 'fund');
|
||||
this.app.rpc.chat.guildRemote.updateInfo.toServer(CHAT_SERVER, code, { fund });
|
||||
@@ -63,20 +67,24 @@ export class DonationHandler {
|
||||
const roleId: string = session.get('roleId');
|
||||
const roleName: string = session.get('roleName');
|
||||
const sid: string = session.get('sid');
|
||||
let userGuild = await UserGuildModel.getMyGuild(roleId,'donateCnt receiveBoxs guildCode');
|
||||
const serverId: number = parseInt(session.get('serverId'));
|
||||
let userGuild = await getUserGuildWithRefActive(roleId, 'donateCnt receiveBoxs guildCode');
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code, donateCnt: resdonateCnt, receiveBoxs: resReceiveBoxs } = userGuild;
|
||||
const { guildCode: code, receiveBoxs: resReceiveBoxs } = userGuild;
|
||||
if (resReceiveBoxs.indexOf(id) != -1)
|
||||
return resResult(STATUS.SUCCESS);
|
||||
return resResult(STATUS.GUILD_DONATE_BOXS_IS_GOT);
|
||||
let { boxRewards, fund } = getArmyDonateBoxBaseById(id);
|
||||
if (resdonateCnt <= 0)
|
||||
return resResult(STATUS.SUCCESS);
|
||||
let { donateFund, donationLv } = await getDonation(code, serverId);
|
||||
let { boxRewardRatio, requireRewardRatio } = getArmyDonateBaseByLv(donationLv);
|
||||
if (donateFund < fund * (100 + requireRewardRatio) )
|
||||
return resResult(STATUS.GUILD_DONATE_BOXS_NOT_GOT);
|
||||
boxRewards = boxRewards.map(({id, count})=>{
|
||||
return { id, count: count * (boxRewardRatio + 100) };
|
||||
});
|
||||
resReceiveBoxs.push(id);
|
||||
let { receiveBoxs } = await UserGuildModel.updateInfo(roleId, { receiveBoxs: resReceiveBoxs }, {}, 'receiveBoxs');
|
||||
let goods = await addItems(roleId, roleName, sid, boxRewards);
|
||||
const { fund: resFund } = await GuildModel.updateInfo(code, {}, { fund }, 'fund');
|
||||
this.app.rpc.chat.guildRemote.updateInfo.toServer(CHAT_SERVER, code, { fund: resFund });
|
||||
return resResult(STATUS.SUCCESS, { receiveBoxs, goods });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -38,8 +38,8 @@ export class GuildRefineHandler {
|
||||
return resResult(STATUS.SUCCESS, { scienceTrees: guildRefine.scienceTrees });
|
||||
}
|
||||
|
||||
async refineEquip(msg: {eid: number}, session: BackendSession) {
|
||||
let { eid } = msg;
|
||||
async refineEquip(msg: {pid: number}, session: BackendSession) {
|
||||
let { pid } = msg;
|
||||
const roleId: string = session.get('roleId');
|
||||
const sid: string = session.get('sid');
|
||||
const roleName: string = session.get('roleName');
|
||||
@@ -47,13 +47,14 @@ export class GuildRefineHandler {
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
let { guildCode: code } = userGuild;
|
||||
let equpInfo = getGoodById(eid);
|
||||
let pieceInfo = getGoodById(pid);
|
||||
//判断是否有该装备或物品
|
||||
let { scienceTrees } = await GuildRefineModel.getRefine(code);
|
||||
let findDevelopConsume;
|
||||
for (let scienceTree of scienceTrees) {
|
||||
if (scienceTree.endTime < nowSeconds()) {
|
||||
let developConsume = getArmyDevelopConsumeById(scienceTree.id);
|
||||
if (developConsume.quality && developConsume.levelMax >= equpInfo.lvLimited && equpInfo.lvLimited <= developConsume.levelMin) {
|
||||
if (developConsume.quality && developConsume.levelMax >= pieceInfo.lvLimited && pieceInfo.lvLimited <= developConsume.levelMin) {
|
||||
findDevelopConsume = developConsume;
|
||||
break;
|
||||
}
|
||||
@@ -65,7 +66,7 @@ export class GuildRefineHandler {
|
||||
let result = await handleCost(roleId, sid, findDevelopConsume.honourConsume);
|
||||
if(!result)
|
||||
return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
||||
let goods = await addItems(roleId, roleName, sid, [{id: eid, count: 1}]);
|
||||
let goods = await addItems(roleId, roleName, sid, [{id: pid, count: 1}]);
|
||||
return resResult(STATUS.SUCCESS, { goods });
|
||||
}
|
||||
|
||||
|
||||
53
game-server/app/servers/battle/handler/wishPoolHandler.ts
Normal file
53
game-server/app/servers/battle/handler/wishPoolHandler.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { Application, BackendSession } from 'pinus';
|
||||
import { UserGuildModel } from '../../../db/UserGuild';
|
||||
import { GuildModel } from '../../../db/Guild';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
import { STATUS } from '../../../consts';
|
||||
import { DonationModel } from '../../../db/Donation';
|
||||
import { nowSeconds } from '../../../pubUtils/timeUtil';
|
||||
import { getArmyDonateBaseByLv, getArmyDonateBoxBaseById } from '../../../pubUtils/data';
|
||||
import { handleCost, addItems } from '../../../services/rewardService';
|
||||
import { CHAT_SERVER } from '../../../consts';
|
||||
import { getDonation } from '../../../services/donateService';
|
||||
import { getUserGuildWithRefActive } from '../../../services/guildService';
|
||||
import { ARMY } from '../../../pubUtils/dicParam';
|
||||
export default function(app: Application) {
|
||||
return new WishPoolHandler(app);
|
||||
}
|
||||
|
||||
export class WishPoolHandler {
|
||||
constructor(private app: Application) {
|
||||
|
||||
}
|
||||
|
||||
async getWishPool(msg: {}, session: BackendSession) {
|
||||
const roleId: string = session.get('roleId');
|
||||
let userGuild = await getUserGuildWithRefActive(roleId, 'donateCnt receiveBoxs guildCode');
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code, wishDntCnt, wishGoods } = userGuild;
|
||||
let userGuilds = await UserGuildModel.getWishPoolGoods(code, ' wishDntCnt wishGoods');
|
||||
let list = [];
|
||||
userGuilds.map(({ wishGoods })=>{
|
||||
wishGoods.map(({ type, goodId, count, receiveCnt, drawCnt, _id })=>{
|
||||
list.push({ type, goodId, count, receiveCnt, drawCnt, id: _id })
|
||||
});
|
||||
});
|
||||
return resResult(STATUS.SUCCESS, { list, wishDntCnt, wishGoods });
|
||||
}
|
||||
|
||||
async wishGoods(msg: {roleId: string, id: number}, session: BackendSession) {
|
||||
const roleId: string = session.get('roleId');
|
||||
const serverId: number = parseInt(session.get('serverId'));
|
||||
let userGuild = await getUserGuildWithRefActive(roleId, 'donateCnt receiveBoxs guildCode');
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code, wishDntCnt, wishGoods } = userGuild;
|
||||
const { wishPoolLv } = await GuildModel.findGuild(code, serverId);
|
||||
|
||||
if (wishDntCnt >= 0)
|
||||
|
||||
return resResult(STATUS.SUCCESS, { list, wishDntCnt, wishGoods });
|
||||
}
|
||||
|
||||
}
|
||||
26
game-server/app/services/donateService.ts
Normal file
26
game-server/app/services/donateService.ts
Normal 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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user