军团:邀请被邀请

This commit is contained in:
luying
2021-01-20 19:30:11 +08:00
parent d9eda973ed
commit 89c7b117b2
8 changed files with 171 additions and 15 deletions

View File

@@ -3,7 +3,7 @@ import { resResult, getRefTime, getRandEelm, reduceCe } from '../../../pubUtils/
import { STATUS, GUILD_OPERATE, GUILD_AUTH, GUILD_JOB, GUILD_APPLY_TYPE } from '../../../consts';
import { UserGuildModel } from '../../../db/UserGuild';
import { checkAuth, joinGuild } from '../../../services/guildService';
import { GuildModel } from '../../../db/Guild';
import { GuildModel, GuildType } from '../../../db/Guild';
import Role, { RoleModel, RoleType } from '../../../db/Role';
import { GUILD } from '../../../pubUtils/dicParam';
import { handleCost } from '../../../services/rewardService';
@@ -146,9 +146,10 @@ export class GuildHandler {
if(ceLimit > reduceCe(role.ce)) {
return resResult(STATUS.GUILD_NOT_REACH_CONDI);
}
if(nowSeconds() - role.quitGuildTime < 3600) { // TODO 时间系统参数表配置
return resResult(STATUS.GUILD_QUIT_TIME);
}
// TODO 暂时关闭
// if(nowSeconds() - role.quitGuildTime < 3600) { // TODO 时间系统参数表配置
// return resResult(STATUS.GUILD_QUIT_TIME);
// }
let hasGuild = false;
if(isAuto) { // 自动加入
@@ -179,6 +180,7 @@ export class GuildHandler {
const result = await UserGuildApplyModel.getListByGuild(code, lastApplyCode);
const list = result.map(cur => {
let role = <RoleType>cur.role;
delete cur.role;
return { applyCode: cur.applyCode, ...role, ce: reduceCe(role.ce) };
});
@@ -222,6 +224,7 @@ export class GuildHandler {
async getInviteMemberList(msg: { }, session: BackendSession) {
const roleId = session.get('roleId');
const serverId = session.get('serverId');
// 检查权限
const checkResult = await checkAuth(GUILD_OPERATE.GET_INIVATION_MEMBER_LIST, roleId);
if(!checkResult) return resResult(STATUS.GUILD_AUTH_NOT_ENOUGH);
@@ -231,21 +234,104 @@ export class GuildHandler {
const day = getRefTime(new Date(), 0, -3);
const d = getSeconds(day);
const allList = await RoleModel.getInviteList(d);
const allList = await RoleModel.getInviteList(d, serverId);
let list = getRandEelm(allList, 10);
if(!list.length) list = allList;
list = list.map(cur => reduceCe(cur));
list = list.map(cur => {
return {...cur, ce: reduceCe(cur.ce)}
});
return resResult(STATUS.SUCCESS, { list });
}
// 团长(一键)邀请人
async inviteMember(msg: { code: string, roleIds: string[] }, session: BackendSession) {
const roleId = session.get('roleId');
const serverId = session.get('serverId');
const { code, roleIds } = msg;
// 检查权限
const checkResult = await checkAuth(GUILD_OPERATE.INVATE_MEMBER, roleId, code);
if(!checkResult) return resResult(STATUS.GUILD_AUTH_NOT_ENOUGH);
const guild = await GuildModel.findByCode(code, serverId);
if(guild.isMemberMax) return resResult(STATUS.GUILD_MEMBER_MAX);
const roleList = await RoleModel.findRoleByField('roleId', roleIds);
let result = new Array<string>();
for(let role of roleList) {
if(!role.hasGuild) {
await UserGuildApplyModel.createUserGuildApply(role, guild, GUILD_APPLY_TYPE.INVITE);
result.push(role.roleId);
}
}
return resResult(STATUS.SUCCESS, { roleIds: result });
}
// 成员收到邀请列表
async getInvitationList(msg: { lastApplyCode: string }, session: BackendSession) {
const roleId = session.get('roleId');
const { lastApplyCode } = msg;
// 检查权限
const checkResult = await checkAuth(GUILD_OPERATE.GET_INVITATION_LIST, roleId);
if(!checkResult) return resResult(STATUS.GUILD_AUTH_NOT_ENOUGH);
const result = await UserGuildApplyModel.getListByRole(roleId, lastApplyCode);
const list = result.map(cur => {
let guild = <GuildType>cur.guild;
let leader = <RoleType>guild.leader;
delete guild.leader;
delete cur.guild;
return { applyCode: cur.applyCode, ...guild, leader: leader.roleName };
});
return resResult(STATUS.SUCCESS, { list });
}
// 成员同意/拒绝邀请
async receiveInvitation(msg: { applyCode: string, isReceived: boolean }, session: BackendSession) {
const roleId = session.get('roleId');
const serverId = session.get('serverId');
const { applyCode, isReceived } = msg;
// 检查权限
const checkResult = await checkAuth(GUILD_OPERATE.RECEIVE_INVITAION, roleId);
if(!checkResult) return resResult(STATUS.GUILD_AUTH_NOT_ENOUGH);
const invite = await UserGuildApplyModel.findByCode(applyCode);
if(!invite) return resResult(STATUS.GUILD_INVITE_NOT_FOUND);
let code: string;
if(isReceived) { // 同意申请,加入
const { guildCode } = invite;
const guild = await GuildModel.findByCode(guildCode, serverId);
const joinResult = await joinGuild(guildCode, guild.lv, roleId, serverId);
if(joinResult.status == 0) {
return joinResult.resResult;
}
code = guild.code;
}
await UserGuildApplyModel.deleteApplyByApplyCode([applyCode]); // 删除这条邀请
return resResult(STATUS.SUCCESS, { applyCode, code, isReceived, hasGuild: isReceived });
}
// 获取军团成员
async getGuildMember(msg: { code: string }, session: BackendSession) {
async getGuildMember(msg: { code: string, sort: string }, session: BackendSession) {
const roleId = session.get('roleId');
// const serverId = session.get('serverId');
const { code } = msg;
const { code, sort } = msg;
// 检查权限
const checkResult = await checkAuth(GUILD_OPERATE.GET_MEMBER_LIST_MAIN, roleId, code);
@@ -262,6 +348,14 @@ export class GuildHandler {
delete role._id;
delete cur.role;
return { ...cur, ...role, ce: reduceCe(role.ce) };
}).sort((a, b) => {
if(sort == 'honour') {
return b.honourWeekly - a.honourWeekly;
} else if (sort == 'loginTime') {
return b.loginTime - a.loginTime;
} else {
return b.ce - a.ce;
}
});
return resResult(STATUS.SUCCESS, { list: result });