军团:弹劾

This commit is contained in:
luying
2021-01-21 11:37:37 +08:00
parent 89937ef672
commit 3a0f31ea0b
8 changed files with 76 additions and 28 deletions

View File

@@ -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
});
}
}

View File

@@ -14,6 +14,7 @@ import { UserGuildApplyModel } from "../db/UserGuildApply";
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);

View File

@@ -58,6 +58,7 @@ export enum GUILD_OPERATE {
EQUIP_PRODUCE = 25, // 炼器堂研发
BE_KICKED = 26, // 被踢出军团
BE_SET_AUTH = 27, // 被授权头衔
BE_IMPEACH = 28, // 被弹劾
}
// 军团状态

View File

@@ -137,6 +137,7 @@ export const STATUS = {
GUILD_INVITE_NOT_FOUND: { code: 20910, simStr: '该邀请未找到' },
GUILD_AUTH_NOT_CHANGE: { code: 20911, simStr: '权限未发生变化' },
GUILD_MEMBER_NOT_FOUND: { code: 20912, simStr: '未找到该成员' },
GUILD_LEADER_LOGIN: { code: 20913, simStr: '团长未离线满72小时' },
// 通用 30000 - 30099
DIC_DATA_NOT_FOUND: { code: 30000, simStr: '数据表未找到' },

View File

@@ -86,7 +86,7 @@ export default class Guild extends BaseModel {
delete update._id;
const code = genCode(6);
const result: GuildType = await GuildModel.findOneAndUpdate({ code }, update, { upsert: true, new: true })
.populate('leader', 'roleName sHid headHid lv loginTime ce', 'Role')
.populate('leader', 'roleId roleName sHid headHid lv loginTime ce', 'Role')
.lean();
return result;
@@ -117,7 +117,7 @@ export default class Guild extends BaseModel {
public static async findByCode(code: string, serverId: number, select?: string) {
const result = await GuildModel.findOne({ code, status: GUILD_STATUS.RUNNING, serverId })
.select(select)
.populate('leader', 'roleName sHid headHid lv loginTime ce', 'Role')
.populate('leader', 'roleId roleName sHid headHid lv loginTime ce', 'Role')
.lean();
return result;
}

View File

@@ -30,6 +30,9 @@ export default class UserGuild extends BaseModel {
@prop({ required: true, default: 0 })
honourWeekly: number;
@prop({ required: true, default: Date.now() })
honourUpdateTime: number;
@prop({ required: true, default: USER_GUILD_STATUS.ON, enum: USER_GUILD_STATUS})
status: number;
@@ -70,6 +73,15 @@ export default class UserGuild extends BaseModel {
return userGuilds;
}
public static async findTopHonour(guildCode: string, select?: string) {
const userGuilds: UserGuildType = await UserGuildModel.findOne({ guildCode, status: USER_GUILD_STATUS.ON, auth: { $ne: GUILD_AUTH.LEADER } })
.sort({ honourWeekly: -1, honourUpdateTime: 1 })
.select(select)
.populate('role', 'roleId roleName ce headHid sHid lv title loginTime', 'Role')
.lean();
return userGuilds;
}
public static async createUserGuild(guildCode: string, role: RoleType, isLeader: boolean) {
const doc = new UserGuildModel();
let job = isLeader? GUILD_JOB.JIANGJUN: GUILD_JOB.SHIZHANG;
@@ -77,7 +89,7 @@ export default class UserGuild extends BaseModel {
const update = Object.assign(doc.toJSON(), { guildCode, roleId: role.roleId, role: role._id, job, auth });
delete update._id;
const result: UserGuildType = await UserGuildModel.findOneAndUpdate({ roleId: role.roleId, guildCode, status: USER_GUILD_STATUS.ON }, update, { upsert: true, new: true })
.select('honourWeekly job auth')
.select('honourWeekly honourUpdateTime job auth')
.lean();
return result;

View File

@@ -32,22 +32,10 @@ export function getBeforeDayDate(day: number) {
}
/**
* 获取 x天后的y点
* @param curTime 现在时间
* @param hour 几点刷新
* 获取几天以前(按秒获取)
* @param day 几天以前
*/
export function getRefTime(now = new Date(), checkHour: number, day = 0) {
let curTime = new Date(now.getTime());
if (checkHour < 0) {
checkHour = 24 + checkHour;
if (curTime.getHours() >= checkHour) {
curTime.setDate(curTime.getDate() + 1);
}
} else {
if (curTime.getHours() < checkHour) {
curTime.setDate(curTime.getDate() - 1);
}
}
let today = curTime.setHours(checkHour, 0, 0, 0);;
return new Date(today + day * 24 * 60 * 60 * 1000);
export function getBeforeDaySeconds(day: number) {
let time = nowSeconds() - day * PER_DAY;
return time;
}

View File

@@ -23,5 +23,6 @@
{"id": 22, "auths": "1&2"},
{"id": 23, "auths": "1&2&3"},
{"id": 26, "auths": "2&3"},
{"id": 27, "auths": "2&3"}
{"id": 27, "auths": "2&3"},
{"id": 28, "auths": "1&"}
]