军团:添加活跃宝箱

This commit is contained in:
luying
2021-01-23 15:17:33 +08:00
parent 368649c53d
commit 789322b913
16 changed files with 820 additions and 26 deletions

View File

@@ -2,11 +2,11 @@ import { Application, BackendSession, pinus } from 'pinus';
import { resResult, getRandEelm, reduceCe } from '../../../pubUtils/util';
import { STATUS, GUILD_OPERATE, GUILD_AUTH, GUILD_JOB, GUILD_APPLY_TYPE, GUILD_STRUCTURE, GUILD_REC_TYPE, GUILD_STRUCTURE_NAME } from '../../../consts';
import { UserGuildModel } from '../../../db/UserGuild';
import { checkAuth, joinGuild, costFund } from '../../../services/guildService';
import { checkAuth, joinGuild, costFund, getGuildWithRefActive, getUserGuildWithRefActive, addGuildActive } from '../../../services/guildService';
import { GuildModel, GuildType } from '../../../db/Guild';
import { RoleModel, RoleType } from '../../../db/Role';
import { GUILD } from '../../../pubUtils/dicParam';
import { handleCost } from '../../../services/rewardService';
import { handleCost, addItems } from '../../../services/rewardService';
import { getGoldObject } from '../../../pubUtils/itemUtils';
import { nowSeconds, getBeforeDaySeconds } from '../../../pubUtils/timeUtil';
import { GuildListInfo } from '../../../pubUtils/interface';
@@ -15,6 +15,7 @@ import { hasStructureConsume, getStructureConsume, gameData } from '../../../pub
import { GuildRecModel } from '../../../db/GuildRec';
import { MailModel } from '../../../db/Mail';
import { getRedis } from '../../../services/redisService';
import User from '../../../db/User';
export default function (app: Application) {
return new GuildHandler(app);
@@ -213,16 +214,18 @@ export class GuildHandler {
const roleId = session.get('roleId');
const serverId = session.get('serverId');
const userGuild = await UserGuildModel.getMyGuild(roleId, 'honour job auth guildCode');
let userGuild = await getUserGuildWithRefActive(roleId, 'honour job auth guildCode receivedActive');
if(!userGuild) {
return resResult(STATUS.SUCCESS, { hasGuild: false })
};
const checkResult = await checkAuth(GUILD_OPERATE.GET_MY_GUILD_INFO, roleId, userGuild.guildCode, userGuild);
if(!checkResult) return resResult(STATUS.GUILD_AUTH_NOT_ENOUGH);
let guild = await GuildModel.findByCode(userGuild.guildCode, serverId);
if(!guild) return resResult(STATUS.GUILD_NOT_FOUND);
let guild = await getGuildWithRefActive(userGuild.guildCode, serverId);
if(!guild) {
return resResult(STATUS.GUILD_NOT_FOUND);
}
guild.guildCe = reduceCe(guild.guildCe);
guild.leader = <RoleType>guild.leader;
@@ -702,7 +705,7 @@ export class GuildHandler {
const checkResult = await checkAuth(GUILD_OPERATE.SEND_MAIL, roleId, code);
if (!checkResult) return resResult(STATUS.GUILD_AUTH_NOT_ENOUGH);
const guild = await GuildModel.findByCode(code, serverId);
const guild = await GuildModel.findByCode(code, serverId, 'members');
if(!guild) return resResult(STATUS.GUILD_NOT_FOUND);
const { members } = guild;
@@ -719,7 +722,7 @@ export class GuildHandler {
return resResult(STATUS.SUCCESS, { isSuccess: true });
}
// 团长发送世界频道
async recruit(msg: { code: string, info: string }, session: BackendSession) {
@@ -740,4 +743,54 @@ export class GuildHandler {
return resResult(STATUS.SUCCESS, { isSuccess: true });
}
// 领取活跃奖励
async receiveActiveBox(msg: { code: string, id: number }, session: BackendSession) {
const roleId = session.get('roleId');
const roleName = session.get('roleName');
const sid = session.get('sid');
const serverId = session.get('serverId');
const { code, id } = msg;
let userGuild = await getUserGuildWithRefActive(roleId, 'receivedActive auth guildCode');
if(!userGuild) return resResult(STATUS.GUILD_NOT_FOUND);
const checkResult = await checkAuth(GUILD_OPERATE.RECEIVE_ACTIVE, roleId, code, userGuild);
if (!checkResult) return resResult(STATUS.GUILD_AUTH_NOT_ENOUGH);
const guild = await getGuildWithRefActive(code, serverId);
if(!guild) return resResult(STATUS.GUILD_NOT_FOUND);
let activeDayReward = gameData.guildActiveDayReward.get(id);
if(!activeDayReward) return resResult(STATUS.GUILD_ACTIVE_BOX_NOT_FOUND);
if(guild.activeDaily < activeDayReward.activeDayPoint) {
return resResult(STATUS.GUILD_ACTIVE_POINT_NOT_REACH);
}
if(userGuild.receivedActive >= activeDayReward.activeDayPoint) {
return resResult(STATUS.GUILD_ACTIVE_BOX_HAS_RECEIVED);
}
let goods = await addItems(roleId, roleName, sid, activeDayReward.reward);
userGuild = await UserGuildModel.updateInfo(roleId, { receivedActive: activeDayReward.activeDayPoint }, 'receivedActive');
return resResult(STATUS.SUCCESS, { goods, receivedActive: userGuild.receivedActive });
}
// debug接口 添加公会活跃值
async debugAddActive(msg: { code: string, active: number }, session: BackendSession) {
const serverId = session.get('serverId');
const { code, active } = msg;
const guild = await addGuildActive(code, serverId, active);
if(!guild) return resResult(STATUS.GUILD_NOT_FOUND);
let { activeDaily, activeWeekly } = guild;
return resResult(STATUS.SUCCESS, { activeDaily, activeWeekly });
}
}

View File

@@ -6,7 +6,7 @@ import { BattleRecordModel } from '../../../db/BattleRecord';
import { nowSeconds, getTodayZeroPoint } from '../../../pubUtils/timeUtil';
import { getUserGuild, getGuildTrainInfo } from '../../../services/guildTrainService';
import { findIndex, findWhere, indexBy } from 'underscore'
import { lockData } from '../../../services/redlockService';
import { lockData } from '../../../services/redLockService';
import { GUILD_DATA_NAME } from '../../../consts/constModules/guildConst';
import { UserGuildModel } from '../../../db/UserGuild';
export default function (app: Application) {