军团:添加活跃宝箱
This commit is contained in:
@@ -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 });
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import { gameData } from "../pubUtils/data";
|
||||
import { GuildModel } from "../db/Guild";
|
||||
import { resResult } from "../pubUtils/util";
|
||||
import { GuildModel, GuildType } from "../db/Guild";
|
||||
import { resResult, shouldRefreshWeek, shouldRefresh } from "../pubUtils/util";
|
||||
import { STATUS } from "../consts";
|
||||
import { RoleModel } from "../db/Role";
|
||||
import { UserGuildModel, UserGuildType } from "../db/UserGuild";
|
||||
import { UserGuildApplyModel } from "../db/UserGuildApply";
|
||||
import { GuildRecModel } from "../db/GuildRec";
|
||||
|
||||
/**
|
||||
* @description 检查该玩家是否有权限做操作
|
||||
@@ -15,6 +14,7 @@ import { GuildRecModel } from "../db/GuildRec";
|
||||
export async function checkAuth(func: number, roleId: string, code?: string, userGuild?: UserGuildType) {
|
||||
const auth = await UserGuildModel.getMyAuth(roleId, code, userGuild);
|
||||
const dicGuildAuth = gameData.guildAuth.get(func);
|
||||
console.log(auth, dicGuildAuth)
|
||||
if(!dicGuildAuth) return false;
|
||||
|
||||
return dicGuildAuth.includes(auth);
|
||||
@@ -56,8 +56,94 @@ export async function joinGuild(code: string, lv: number, roleId: string, server
|
||||
return { status: 1, guild, userGuild, roleName: role.roleName }
|
||||
}
|
||||
|
||||
/**
|
||||
* 消耗军团资金
|
||||
* @param code 军团唯一code
|
||||
* @param cost 消耗值
|
||||
* @param sid 推送channel
|
||||
*/
|
||||
export async function costFund(code: string, cost: number, sid: string) {
|
||||
const guild = await GuildModel.costFund(code, cost);
|
||||
// TODO 推送
|
||||
return guild;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新军团活跃
|
||||
* @param guildCode 军团唯一code
|
||||
* @param serverId 区
|
||||
*/
|
||||
export async function getGuildWithRefActive(guildCode: string, serverId: number) {
|
||||
|
||||
// TODO 加写锁
|
||||
let guild = await GuildModel.findByCode(guildCode, serverId, '+refTimeDaily +refTimeWeekly');
|
||||
if(!guild) return false;
|
||||
|
||||
console.log(JSON.stringify(guild));
|
||||
const now = new Date();
|
||||
let { activeDaily, activeWeekly, refTimeDaily, refTimeWeekly} = guild;
|
||||
let isRefWeek = shouldRefreshWeek(refTimeWeekly, now, 1, 0);
|
||||
if(isRefWeek) {
|
||||
activeWeekly = 0; refTimeWeekly = now;
|
||||
}
|
||||
let isRefDaily = shouldRefresh(refTimeDaily, now, 0);
|
||||
if(isRefDaily) {
|
||||
activeDaily = 0; refTimeDaily = now;
|
||||
}
|
||||
|
||||
if(isRefWeek || isRefDaily) {
|
||||
guild = await GuildModel.updateInfo(guildCode, { activeDaily, activeWeekly, refTimeDaily, refTimeWeekly }, {});
|
||||
}
|
||||
return guild;
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加活跃
|
||||
* @param guildCode 军团唯一code
|
||||
* @param serverId 区
|
||||
* @param active 增加的活跃
|
||||
*/
|
||||
export async function addGuildActive(guildCode: string, serverId: number, active: number) {
|
||||
|
||||
// TODO 加写锁
|
||||
let guild = await GuildModel.findByCode(guildCode, serverId, '+refTimeDaily +refTimeWeekly');
|
||||
if(!guild) return false;
|
||||
|
||||
const now = new Date();
|
||||
let { activeDaily, activeWeekly, refTimeDaily, refTimeWeekly} = guild;
|
||||
let isRefWeek = shouldRefreshWeek(refTimeWeekly, now, 1, 0);
|
||||
if(isRefWeek) {
|
||||
activeWeekly = 0; refTimeWeekly = now;
|
||||
}
|
||||
let isRefDaily = shouldRefresh(refTimeDaily, now, 0);
|
||||
if(isRefDaily) {
|
||||
activeDaily = 0; refTimeDaily = now;
|
||||
}
|
||||
|
||||
activeWeekly += active; activeDaily += active;
|
||||
|
||||
guild = await GuildModel.updateInfo(guildCode, { activeDaily, activeWeekly, refTimeDaily, refTimeWeekly }, {});
|
||||
return guild;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户公会表并刷新活跃
|
||||
* @param roleId 用户id
|
||||
* @param select 筛选字段
|
||||
*/
|
||||
export async function getUserGuildWithRefActive(roleId: string, select: string) {
|
||||
let userGuild = await UserGuildModel.getMyGuild(roleId, select? select + ' +refTimeDaily': '+refTimeDaily');
|
||||
if(!userGuild) return false;
|
||||
let { receivedActive, refTimeDaily } = userGuild;
|
||||
|
||||
const now = new Date();
|
||||
let isRefDaily = shouldRefresh(refTimeDaily, now, 0);
|
||||
if(isRefDaily) {
|
||||
receivedActive = 0; refTimeDaily = now;
|
||||
|
||||
userGuild = await UserGuildModel.updateInfo(roleId, { receivedActive, refTimeDaily }, select);
|
||||
if(!userGuild) return false;
|
||||
}
|
||||
|
||||
return userGuild;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user