活动:礼包添加批量参数
This commit is contained in:
@@ -5,21 +5,21 @@ import { STATUS, TASK_TYPE } from '../../../consts';
|
||||
import { DonationModel } from '../../../db/Donation';
|
||||
import { nowSeconds } from '../../../pubUtils/timeUtil';
|
||||
import { getArmyDonateBaseByLv, getArmyDonateBoxBaseById } from '../../../pubUtils/data';
|
||||
import { GuildModel } from '../../../db/Guild';
|
||||
import { GuildModel } from '../../../db/Guild';
|
||||
import { handleCost, addItems } from '../../../services/rewardService';
|
||||
import { CHAT_SERVER, GUILD_POINT_WAYS } from '../../../consts';
|
||||
import { getDonation } from '../../../services/donateService';
|
||||
import { getUserGuildWithRefActive } from '../../../services/guildService';
|
||||
import { ARMY } from '../../../pubUtils/dicParam';
|
||||
import { addActive } from '../../../services/guildService'
|
||||
import { checkTask } from '../../../services/taskService';
|
||||
export default function(app: Application) {
|
||||
import { checkActivityTask, checkTask } from '../../../services/taskService';
|
||||
export default function (app: Application) {
|
||||
return new DonationHandler(app);
|
||||
}
|
||||
|
||||
export class DonationHandler {
|
||||
constructor(private app: Application) {
|
||||
|
||||
|
||||
}
|
||||
/**
|
||||
* 捐献所的等级,捐献的次数,战报,捐献达到的基金,领取宝箱记录
|
||||
@@ -31,18 +31,18 @@ export class DonationHandler {
|
||||
const serverId: number = parseInt(session.get('serverId'));
|
||||
|
||||
let userGuild = await getUserGuildWithRefActive(roleId, 'donateCnt receiveBoxs guildCode');
|
||||
if (!userGuild)
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code, donateCnt, receiveBoxs } = userGuild;
|
||||
let { donateFund, reports, donationLv } = await getDonation(code, serverId);
|
||||
return resResult(STATUS.SUCCESS, { receiveBoxs, donateFund, reports, donateCnt:donateCnt||0, donationLv});
|
||||
return resResult(STATUS.SUCCESS, { receiveBoxs, donateFund, reports, donateCnt: donateCnt || 0, donationLv });
|
||||
}
|
||||
/**
|
||||
* 捐献
|
||||
* @param msg
|
||||
* @param session
|
||||
*/
|
||||
async donate(msg: {id: number}, session: BackendSession) {
|
||||
async donate(msg: { id: number }, session: BackendSession) {
|
||||
const { id } = msg;
|
||||
const roleId: string = session.get('roleId');
|
||||
const roleName: string = session.get('roleName');
|
||||
@@ -50,20 +50,20 @@ export class DonationHandler {
|
||||
const sid: string = session.get('sid');
|
||||
const funcs: number[] = session.get('funcs');
|
||||
let userGuild = await getUserGuildWithRefActive(roleId, 'donateCnt receiveBoxs guildCode');
|
||||
if (!userGuild)
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code, donateCnt: resdonateCnt } = userGuild;
|
||||
if (resdonateCnt >= ARMY.ARMY_DONATE_TIMES)
|
||||
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)
|
||||
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 { donateFund, reports } = await DonationModel.donation(code, rewardFund, { reports: { id, roleName, time: nowSeconds() } });
|
||||
let goods = [];
|
||||
if (!!rewardGood)
|
||||
goods = await addItems(roleId, roleName, sid, [rewardGood]);
|
||||
@@ -73,32 +73,34 @@ export class DonationHandler {
|
||||
await addActive(roleId, serverId, GUILD_POINT_WAYS.DONATE, id);
|
||||
// 任务
|
||||
await checkTask(roleId, sid, funcs, TASK_TYPE.GUILD_DONATE, 1, true, {});
|
||||
|
||||
//活动任务
|
||||
await checkActivityTask(serverId, sid, funcs, roleId, TASK_TYPE.GUILD_DONATE, 1);
|
||||
|
||||
return resResult(STATUS.SUCCESS, { donateFund, reports, donateCnt, goods });
|
||||
}
|
||||
/**
|
||||
* 领取宝箱
|
||||
* @param msg
|
||||
* @param session
|
||||
*/
|
||||
async receiveBox(msg: {id: number}, session: BackendSession) {
|
||||
*/
|
||||
async receiveBox(msg: { id: number }, session: BackendSession) {
|
||||
const { id } = msg;
|
||||
const roleId: string = session.get('roleId');
|
||||
const roleName: string = session.get('roleName');
|
||||
const sid: string = session.get('sid');
|
||||
const serverId: number = parseInt(session.get('serverId'));
|
||||
let userGuild = await getUserGuildWithRefActive(roleId, 'donateCnt receiveBoxs guildCode');
|
||||
if (!userGuild)
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code, receiveBoxs: resReceiveBoxs } = userGuild;
|
||||
if (resReceiveBoxs.indexOf(id) != -1)
|
||||
if (resReceiveBoxs.indexOf(id) != -1)
|
||||
return resResult(STATUS.GUILD_DONATE_BOXS_IS_GOT);
|
||||
let { boxRewards, fund } = getArmyDonateBoxBaseById(id);
|
||||
let { donateFund, donationLv } = await getDonation(code, serverId);
|
||||
let { boxRewardRatio, requireRewardRatio } = getArmyDonateBaseByLv(donationLv);
|
||||
if (donateFund < Math.floor(fund * (100 + requireRewardRatio)/100) )
|
||||
if (donateFund < Math.floor(fund * (100 + requireRewardRatio) / 100))
|
||||
return resResult(STATUS.GUILD_DONATE_BOXS_NOT_GOT);
|
||||
boxRewards = boxRewards.map(({id, count})=>{
|
||||
boxRewards = boxRewards.map(({ id, count }) => {
|
||||
return { id, count: count * (boxRewardRatio + 100) };
|
||||
});
|
||||
resReceiveBoxs.push(id);
|
||||
@@ -106,4 +108,4 @@ export class DonationHandler {
|
||||
let goods = await addItems(roleId, roleName, sid, boxRewards);
|
||||
return resResult(STATUS.SUCCESS, { receiveBoxs, goods });
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user