军团:弹劾
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Application, BackendSession, pinus } from 'pinus';
|
||||
import { resResult, getRefTime, getRandEelm, reduceCe } from '../../../pubUtils/util';
|
||||
import { resResult, getRandEelm, reduceCe } from '../../../pubUtils/util';
|
||||
import { STATUS, GUILD_OPERATE, GUILD_AUTH, GUILD_JOB, GUILD_APPLY_TYPE } from '../../../consts';
|
||||
import { UserGuildModel } from '../../../db/UserGuild';
|
||||
import { checkAuth, joinGuild } from '../../../services/guildService';
|
||||
@@ -8,7 +8,7 @@ import Role, { RoleModel, RoleType } from '../../../db/Role';
|
||||
import { GUILD } from '../../../pubUtils/dicParam';
|
||||
import { handleCost } from '../../../services/rewardService';
|
||||
import { getGoldObject } from '../../../pubUtils/itemUtils';
|
||||
import { getSeconds, nowSeconds } from '../../../pubUtils/timeUtil';
|
||||
import { getSeconds, nowSeconds, getBeforeDaySeconds } from '../../../pubUtils/timeUtil';
|
||||
import { GuildListInfo } from '../../../pubUtils/interface';
|
||||
import { UserGuildApplyModel } from '../../../db/UserGuildApply';
|
||||
import User from '../../../db/User';
|
||||
@@ -312,11 +312,10 @@ export class GuildHandler {
|
||||
|
||||
// 离线时间,三天内在线且尚未加入军团。按以下规则排序 离线时间 玩家等级 玩家战力
|
||||
|
||||
const day = getRefTime(new Date(), 0, -3);
|
||||
const d = getSeconds(day);
|
||||
const day = getBeforeDaySeconds(3);
|
||||
|
||||
const { quitGuildTime: quitTime = 0 } = await RoleModel.findByRoleId(roleId);
|
||||
const allList = await RoleModel.getInviteList(d, serverId);
|
||||
const allList = await RoleModel.getInviteList(day, serverId);
|
||||
let list = getRandEelm(allList, 10);
|
||||
if(!list.length) list = allList;
|
||||
list = list.map(cur => {
|
||||
@@ -423,7 +422,7 @@ export class GuildHandler {
|
||||
let select = ['role', 'job'];
|
||||
const checkDetailResult = await checkAuth(GUILD_OPERATE.GET_MEMBER_LIST_DETAIL, roleId, code);
|
||||
if(checkDetailResult) {
|
||||
select.push('auth', 'honourWeekly');
|
||||
select.push('auth', 'honourWeekly honourUpdateTime');
|
||||
}
|
||||
let list = await UserGuildModel.getListByGuild(code, select.join(' '));
|
||||
let result = list.map(cur => {
|
||||
@@ -436,7 +435,11 @@ export class GuildHandler {
|
||||
|
||||
result.sort((a, b) => {
|
||||
if(sort == 'honour') {
|
||||
return b.honourWeekly - a.honourWeekly;
|
||||
if(b.honourWeekly == a.honourWeekly) {
|
||||
return a.honourUpdateTime - b.honourUpdateTime
|
||||
} else {
|
||||
return b.honourWeekly - a.honourWeekly
|
||||
}
|
||||
} else if (sort == 'loginTime') {
|
||||
return b.loginTime - a.loginTime;
|
||||
} else {
|
||||
@@ -524,4 +527,45 @@ export class GuildHandler {
|
||||
|
||||
return resResult(STATUS.SUCCESS, { memberCnt: guild.memberCnt });
|
||||
}
|
||||
|
||||
// 团员弹劾团长
|
||||
async impeach(msg: { code: string, roleId: string }, session: BackendSession) {
|
||||
|
||||
const roleId = session.get('roleId');
|
||||
// const serverId = session.get('serverId');
|
||||
const { code, roleId: leaderRoleId } = msg;
|
||||
|
||||
// 弹劾的权限
|
||||
const checkMyAuth = await checkAuth(GUILD_OPERATE.IMPEACH, roleId, code);
|
||||
if (!checkMyAuth) return resResult(STATUS.GUILD_AUTH_NOT_ENOUGH);
|
||||
|
||||
// 被弹劾的权限
|
||||
const checkHisAuth = await checkAuth(GUILD_OPERATE.BE_IMPEACH, leaderRoleId, code);
|
||||
if (!checkHisAuth) return resResult(STATUS.GUILD_AUTH_NOT_ENOUGH);
|
||||
|
||||
// 离线72小时
|
||||
const { loginTime } = await RoleModel.findByRoleId(leaderRoleId);
|
||||
if (loginTime > getBeforeDaySeconds(3)) {
|
||||
return resResult(STATUS.GUILD_LEADER_LOGIN);
|
||||
}
|
||||
// 上周周功勋最高的人
|
||||
const topUserGuild = await UserGuildModel.findTopHonour(code, 'auth role roleId');
|
||||
if (!topUserGuild) {
|
||||
return resResult(STATUS.GUILD_MEMBER_NOT_FOUND);
|
||||
}
|
||||
const topUser = <RoleType>topUserGuild.role;
|
||||
// 交换
|
||||
|
||||
// TODO redlock 推送
|
||||
await UserGuildModel.updateInfo(leaderRoleId, { auth: GUILD_AUTH.MEMBER }, 'auth'); // 团长撤
|
||||
await UserGuildModel.updateInfo(topUserGuild.roleId, { auth: GUILD_AUTH.LEADER }, 'auth'); // 最高功勋人升
|
||||
let managerCntInc = topUserGuild.auth == GUILD_AUTH.MANAGER ? -1 : 0; // 管理人数
|
||||
|
||||
const guild = await GuildModel.updateInfo(code, { leader: topUser._id }, { managerCnt: managerCntInc }, 'managerCnt'); // 如果有转让团长设置leader
|
||||
|
||||
const leader = { ...topUser, ce: reduceCe(topUser.ce) }
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
code, managerCnt: guild.managerCnt, leader
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user