军团:修改信息
This commit is contained in:
@@ -11,6 +11,7 @@ import { getGoldObject } from '../../../pubUtils/itemUtils';
|
||||
import { getSeconds, nowSeconds } from '../../../pubUtils/timeUtil';
|
||||
import { GuildListInfo } from '../../../pubUtils/interface';
|
||||
import { UserGuildApplyModel } from '../../../db/UserGuildApply';
|
||||
import User from '../../../db/User';
|
||||
|
||||
export default function (app: Application) {
|
||||
return new GuildHandler(app);
|
||||
@@ -92,6 +93,86 @@ export class GuildHandler {
|
||||
return resResult(STATUS.SUCCESS, { quitTime, list });
|
||||
}
|
||||
|
||||
// 团长修改军团名等信息
|
||||
async setGuildInfo(msg: { code: string, name: string, notice: string, introduce: string, ceLimit: number, isAuto: boolean }, session: BackendSession) {
|
||||
|
||||
const roleId = session.get('roleId');
|
||||
const { code, name, notice, introduce, ceLimit, isAuto } = msg;
|
||||
|
||||
const checkResult = await checkAuth(GUILD_OPERATE.SET_INFO, roleId, code);
|
||||
if(!checkResult) return resResult(STATUS.GUILD_AUTH_NOT_ENOUGH);
|
||||
|
||||
const select = ['code', 'name', 'notice', 'introduce', 'ceLimit', 'isAuto', 'icon'];
|
||||
const guild = await GuildModel.updateInfo(code, { name, notice, introduce, ceLimit, isAuto }, {}, select.join(' '));
|
||||
// 返回
|
||||
return resResult(STATUS.SUCCESS, { ...guild });
|
||||
|
||||
}
|
||||
|
||||
// 游客查看军团详细信息
|
||||
async getGuildInfo(msg: { code: string }, session: BackendSession) {
|
||||
|
||||
const roleId = session.get('roleId');
|
||||
const serverId = session.get('serverId');
|
||||
const { code } = msg;
|
||||
|
||||
const checkResult = await checkAuth(GUILD_OPERATE.GET_GUILD_INFO, roleId, code);
|
||||
if(!checkResult) return resResult(STATUS.GUILD_AUTH_NOT_ENOUGH);
|
||||
|
||||
const select = ['code', 'name', 'notice', 'ceLimit', 'isAuto', 'icon', 'lv', 'memberCnt', 'guildCe'];
|
||||
const guild = await GuildModel.findByCode(code, serverId, select.join(' '));
|
||||
let leader = <RoleType>guild.leader;
|
||||
delete guild.leader;
|
||||
// 返回
|
||||
return resResult(STATUS.SUCCESS, { ...guild, leader: leader.roleName });
|
||||
|
||||
}
|
||||
|
||||
// 团长授权头衔
|
||||
async setAuth(msg: { roleId: string, auth: number }, session: BackendSession) {
|
||||
|
||||
const roleId = session.get('roleId');
|
||||
const { roleId: memberRoleId, auth } = msg;
|
||||
|
||||
const myUserGuild = await UserGuildModel.getMyGuild(roleId, 'auth guildCode');
|
||||
const hisUserGuild = await UserGuildModel.getMyGuild(memberRoleId, 'auth guildCode');
|
||||
|
||||
const checkMyResult = await checkAuth(GUILD_OPERATE.SET_AUTH, roleId, null, myUserGuild);
|
||||
if(!checkMyResult) return resResult(STATUS.GUILD_AUTH_NOT_ENOUGH);
|
||||
|
||||
const checkResult = await checkAuth(GUILD_OPERATE.BE_SET_AUTH, memberRoleId, myUserGuild.guildCode, hisUserGuild);
|
||||
if(!checkResult) return resResult(STATUS.GUILD_AUTH_NOT_ENOUGH);
|
||||
|
||||
const { guildCode: code } = myUserGuild;
|
||||
|
||||
if(auth == hisUserGuild.auth) {
|
||||
return resResult(STATUS.GUILD_AUTH_NOT_CHANGE);
|
||||
}
|
||||
|
||||
// TODO 管理员最大数 等策划表
|
||||
|
||||
const userGuild = await UserGuildModel.updateInfo(memberRoleId, { auth }, 'auth'); // 设置权限
|
||||
if(!userGuild) {
|
||||
return resResult(STATUS.GUILD_MEMBER_NOT_FOUND);
|
||||
}
|
||||
let managerCntInc = 0;
|
||||
let updateObject = {};
|
||||
if(auth == GUILD_AUTH.LEADER) { // 转让团长
|
||||
managerCntInc = hisUserGuild.auth == GUILD_AUTH.MANAGER?-1: 0;
|
||||
const role = await RoleModel.findByRoleId(memberRoleId);
|
||||
updateObject['leader'] = role._id;
|
||||
await UserGuildModel.updateInfo(roleId, { auth: GUILD_AUTH.MEMBER }); // 自己降权限
|
||||
} else {
|
||||
managerCntInc = auth == GUILD_AUTH.MANAGER? 1: -1;
|
||||
}
|
||||
const guild = await GuildModel.updateInfo(code, updateObject, { managerCnt: managerCntInc }, 'managerCnt'); // 如果有转让团长设置leader
|
||||
// 返回
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
roleId: memberRoleId, auth: userGuild.auth, managerCnt: guild.managerCnt
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// 团员获取自己军团详细信息
|
||||
async getMyGuildInfo(msg: { }, session: BackendSession) {
|
||||
|
||||
@@ -234,13 +315,15 @@ export class GuildHandler {
|
||||
const day = getRefTime(new Date(), 0, -3);
|
||||
const d = getSeconds(day);
|
||||
|
||||
const { quitGuildTime: quitTime = 0 } = await RoleModel.findByRoleId(roleId);
|
||||
const allList = await RoleModel.getInviteList(d, serverId);
|
||||
let list = getRandEelm(allList, 10);
|
||||
if(!list.length) list = allList;
|
||||
list = list.map(cur => {
|
||||
return {...cur, ce: reduceCe(cur.ce)}
|
||||
});
|
||||
return resResult(STATUS.SUCCESS, { list });
|
||||
|
||||
return resResult(STATUS.SUCCESS, { quitTime, list });
|
||||
|
||||
}
|
||||
|
||||
@@ -342,13 +425,16 @@ export class GuildHandler {
|
||||
if(checkDetailResult) {
|
||||
select.push('auth', 'honourWeekly');
|
||||
}
|
||||
const list = await UserGuildModel.getListByGuild(code, select.join(' '));
|
||||
const result = list.map(cur => {
|
||||
let list = await UserGuildModel.getListByGuild(code, select.join(' '));
|
||||
let result = list.map(cur => {
|
||||
let role = <RoleType>cur.role;
|
||||
delete role._id;
|
||||
delete cur.role;
|
||||
return { ...cur, ...role, ce: reduceCe(role.ce) };
|
||||
}).sort((a, b) => {
|
||||
});
|
||||
let leader = result.shift();
|
||||
|
||||
result.sort((a, b) => {
|
||||
if(sort == 'honour') {
|
||||
return b.honourWeekly - a.honourWeekly;
|
||||
} else if (sort == 'loginTime') {
|
||||
@@ -358,6 +444,7 @@ export class GuildHandler {
|
||||
}
|
||||
});
|
||||
|
||||
result.unshift(leader);
|
||||
return resResult(STATUS.SUCCESS, { list: result });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user