军团:添加踢人解散退出,添加权限
This commit is contained in:
+28
-12
@@ -66,7 +66,7 @@ export default class Guild extends BaseModel {
|
||||
refTimeWeekly: Date;
|
||||
|
||||
@prop({ required: true, default: 0 })
|
||||
ce: number; // 总战力
|
||||
guildCe: number; // 总战力
|
||||
|
||||
@prop({ required: true, type: String, default: [], select: false })
|
||||
members: string[]; // 军团成员的roleId,用于增加战力的时候加入总战力
|
||||
@@ -77,9 +77,12 @@ export default class Guild extends BaseModel {
|
||||
@prop({ required: true, default: GUILD_STATUS.RUNNING, enum: GUILD_STATUS })
|
||||
status: number;
|
||||
|
||||
public static async createGuild(params: { name: string, icon: number, notice: string }, role: RoleType) {
|
||||
@prop({ required: true, default: 1, select: false })
|
||||
serverId: number; // 分服
|
||||
|
||||
public static async createGuild(params: { name: string, icon: number, notice: string }, role: RoleType, serverId: number) {
|
||||
const doc = new GuildModel();
|
||||
const update = Object.assign(doc.toJSON(), params, { leader: role._id, members: [role.roleId], ce: role.ce });
|
||||
const update = Object.assign(doc.toJSON(), params, { leader: role._id, members: [role.roleId], guildCe: role.ce, serverId });
|
||||
delete update._id;
|
||||
const code = genCode(6);
|
||||
const result: GuildType = await GuildModel.findOneAndUpdate({ code }, update, { upsert: true, new: true })
|
||||
@@ -89,13 +92,13 @@ export default class Guild extends BaseModel {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async checkName(name: string) {
|
||||
const result = await GuildModel.findOne({ name, status: GUILD_STATUS.RUNNING }).lean();
|
||||
public static async checkName(name: string, serverId: number) {
|
||||
const result = await GuildModel.findOne({ name, status: GUILD_STATUS.RUNNING, serverId }).lean();
|
||||
return !!result;
|
||||
}
|
||||
|
||||
public static async findByCondition(page: number, showPeopleMax: boolean, name: string) {
|
||||
const condition = { status: GUILD_STATUS.RUNNING };
|
||||
public static async findByCondition(page: number, showPeopleMax: boolean, name: string, serverId: number) {
|
||||
const condition = { status: GUILD_STATUS.RUNNING, serverId };
|
||||
if(!showPeopleMax) {
|
||||
condition['isMemberMax'] = false;
|
||||
}
|
||||
@@ -103,7 +106,7 @@ export default class Guild extends BaseModel {
|
||||
condition['name'] = { $regex: new RegExp(name, 'i') }
|
||||
}
|
||||
const guildList = await GuildModel.find(condition)
|
||||
.sort({ lv: -1, ce: -1 })
|
||||
.sort({ lv: -1, guildCe: -1 })
|
||||
.limit(GUILD_PER_PAGE).skip((page - 1) * GUILD_PER_PAGE)
|
||||
.select('code icon name lv memberCnt leader ceLimit isAuto')
|
||||
.populate('leader', 'roleName', 'Role')
|
||||
@@ -111,20 +114,33 @@ export default class Guild extends BaseModel {
|
||||
return guildList;
|
||||
}
|
||||
|
||||
public static async findByCode(code: string) {
|
||||
const result = await GuildModel.findOne({ code, status: GUILD_STATUS.RUNNING })
|
||||
public static async findByCode(code: string, serverId: number) {
|
||||
const result = await GuildModel.findOne({ code, status: GUILD_STATUS.RUNNING, serverId })
|
||||
.populate('leader', 'roleName sHid headHid lv loginTime ce', 'Role')
|
||||
.lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async addGuild(code: string, roleId: string, maxMemberCnt: number) {
|
||||
let result = await GuildModel.findOneAndUpdate({ code, memberCnt: {$lt: maxMemberCnt } }, { $inc: { memberCnt: 1 }, $push: { members: roleId } }, { new: true }).lean();
|
||||
public static async addGuild(code: string, roleId: string, maxMemberCnt: number, serverId: number) {
|
||||
let result = await GuildModel.findOneAndUpdate({ code, memberCnt: {$lt: maxMemberCnt }, serverId }, { $inc: { memberCnt: 1 }, $push: { members: roleId } }, { new: true }).lean();
|
||||
if(result && result.memberCnt >= maxMemberCnt) {
|
||||
result = await GuildModel.findOneAndUpdate({ code }, { $set: { isMemberMax: true } }).lean();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async dismiss(code: string, serverId: number) {
|
||||
const result = await GuildModel.findOneAndUpdate({ code, status: GUILD_STATUS.RUNNING, serverId }, { status: GUILD_STATUS.DISMISSED }, { new: true })
|
||||
.select('+members')
|
||||
.lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async quit(code: string, roleId: string, serverId: number) {
|
||||
const result = await GuildModel.findOneAndUpdate({ code, serverId }, { $inc: { memberCnt: -1}, $pull: { members: roleId }, isMemberMax: false }, { new: true })
|
||||
.lean();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export const GuildModel = getModelForClass(Guild);
|
||||
|
||||
+30
-14
@@ -7,19 +7,6 @@ import { shouldRefresh } from '../pubUtils/util';
|
||||
import { initRoleAtrr } from '../pubUtils/playerCe';
|
||||
import Hero,{} from '../db/Hero';
|
||||
import { nowSeconds } from '../pubUtils/timeUtil';
|
||||
interface roleUpdate {
|
||||
ce?: number;
|
||||
_id?:number;
|
||||
coin?: number;
|
||||
gold?:number;
|
||||
frdCnt?: number;
|
||||
expeditionPoint?:number;
|
||||
globalCeAttr?:CeAttrRole;
|
||||
title?:number;
|
||||
teraphs?: Teraph[];
|
||||
topFive?: TopHero[];
|
||||
topFiveCe?: number;
|
||||
}
|
||||
|
||||
class TopHero {
|
||||
@prop({ required: true })
|
||||
@@ -219,8 +206,10 @@ export default class Role extends BaseModel {
|
||||
teraphs:Array<Teraph>;
|
||||
|
||||
// 公会
|
||||
@prop({ required: true, default: false })
|
||||
hasGuild: boolean; // 是否加入过公会
|
||||
@prop({ required: true, default: 0 })
|
||||
quitGuildTime: number; // 上次退出公会的时间
|
||||
quitGuildTime: number; // 上次退出公会的时间
|
||||
|
||||
public static async findByUid(uid: number, serverId: number, lean = true) {
|
||||
const role: RoleType = await RoleModel.findOneAndUpdate({ 'userInfo.uid': uid, serverId }, { loginTime: nowSeconds() }, { new: true }).lean(lean);
|
||||
@@ -416,8 +405,35 @@ export default class Role extends BaseModel {
|
||||
let result: RoleType = await RoleModel.findOneAndUpdate({roleId}, {$set:roleUpdate}, {new: true}).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
// 记录加入公会
|
||||
public static async joinGuild(roleId: string) {
|
||||
const result = await RoleModel.findOneAndUpdate({ roleId, hasGuild: false }, { hasGuild: true }, { new: true }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
// 获取未加入公会且登录时间在三天内的人
|
||||
public static async getInviteList(time: number) {
|
||||
const result = await RoleModel.find({ loginTime: { $gt: time }, hasGuild: false })
|
||||
.select('roleId roleName ce headHid sHid lv title job loginTime')
|
||||
.limit(100).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
// 公会解散
|
||||
public static async dissmissGuild(members: string[]) {
|
||||
const result = await RoleModel.updateMany({ roleId: { $in: members } }, { hasGuild: false }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
// 退出公会
|
||||
public static async quitGuild(roleId: string, now: number) {
|
||||
const result = await RoleModel.findOneAndUpdate({ roleId, hasGuild: true }, { hasGuild: false, quitGuildTime: now }, { new: true }).lean();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export const RoleModel = getModelForClass(Role);
|
||||
|
||||
export interface RoleType extends Pick<DocumentType<Role>, keyof Role>{};
|
||||
type roleUpdate = Partial<RoleType>; // 将所有字段变成可选项
|
||||
|
||||
+28
-4
@@ -41,23 +41,35 @@ export default class UserGuild extends BaseModel {
|
||||
@prop({ required: true, default: new Date() })
|
||||
refTimeWeekly: number;
|
||||
|
||||
public static async getMyAuth(roleId: string, userGuild?: UserGuildType) {
|
||||
public static async getMyAuth(roleId: string, guildCode?: string, userGuild?: UserGuildType) {
|
||||
let myGuild: UserGuildType;
|
||||
if(!userGuild) {
|
||||
myGuild = await this.getMyGuild(roleId, 'auth');
|
||||
} else {
|
||||
myGuild = userGuild;
|
||||
}
|
||||
|
||||
if(guildCode && userGuild && userGuild.guildCode != guildCode) {
|
||||
return GUILD_AUTH.OTHERS;
|
||||
}
|
||||
|
||||
return myGuild?myGuild.auth: GUILD_AUTH.OTHERS;
|
||||
}
|
||||
|
||||
public static async getMyGuild(roleId: string, select?: string) {
|
||||
|
||||
const myGuild: UserGuildType = await UserGuildModel.findOne({ roleId, status: USER_GUILD_STATUS.ON })
|
||||
.select(select)
|
||||
.lean();
|
||||
.select(select).lean();
|
||||
return myGuild;
|
||||
}
|
||||
|
||||
public static async getListByGuild(guildCode: string, select?: string) {
|
||||
const userGuilds: UserGuildType[] = await UserGuildModel.find({ guildCode, status: USER_GUILD_STATUS.ON })
|
||||
.select(select)
|
||||
.populate('role', 'roleId roleName ce headHid sHid lv title', 'Role')
|
||||
.lean();
|
||||
return userGuilds;
|
||||
}
|
||||
|
||||
public static async createUserGuild(guildCode: string, role: RoleType, isLeader: boolean) {
|
||||
const doc = new UserGuildModel();
|
||||
@@ -65,12 +77,24 @@ export default class UserGuild extends BaseModel {
|
||||
let auth = isLeader? GUILD_AUTH.LEADER: GUILD_AUTH.MEMBER;
|
||||
const update = Object.assign(doc.toJSON(), { guildCode, roleId: role.roleId, role: role._id, job, auth });
|
||||
delete update._id;
|
||||
const result: UserGuildType = await UserGuildModel.findOneAndUpdate({ guildCode, status: USER_GUILD_STATUS.ON }, update, { upsert: true, new: true })
|
||||
const result: UserGuildType = await UserGuildModel.findOneAndUpdate({ roleId: role.roleId, guildCode, status: USER_GUILD_STATUS.ON }, update, { upsert: true, new: true })
|
||||
.select('honourWeekly job auth')
|
||||
.lean();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async dismiss(guildCode: string) {
|
||||
const result = await UserGuildModel.updateMany({guildCode}, {status: USER_GUILD_STATUS.DISMISSED});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// 玩家退出公会
|
||||
public static async quit(guildCode: string, roleId: string) {
|
||||
const result = await UserGuildModel.findOneAndUpdate({ guildCode, roleId, status: USER_GUILD_STATUS.ON }, {status: USER_GUILD_STATUS.QUIT}, {new: true});
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export const UserGuildModel = getModelForClass(UserGuild);
|
||||
|
||||
@@ -40,6 +40,11 @@ export default class UserGuildApply extends BaseModel {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async deleteApplyByGuild(guildCode: string) {
|
||||
const result = await UserGuildApplyModel.deleteMany({ guildCode, type: GUILD_APPLY_TYPE.APPLY });
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async deleteApplyByApplyCode(applyCodeList: string[]) {
|
||||
const result = await UserGuildApplyModel.deleteMany({ applyCode: { $in: applyCodeList}, type: GUILD_APPLY_TYPE.APPLY });
|
||||
return result;
|
||||
@@ -50,6 +55,11 @@ export default class UserGuildApply extends BaseModel {
|
||||
return userGuildApply;
|
||||
}
|
||||
|
||||
public static async findApplyByRole(roleId: string) {
|
||||
const userGuildApply: UserGuildApplyType[] = await UserGuildApplyModel.find({ roleId, type: GUILD_APPLY_TYPE.APPLY }).lean();
|
||||
return userGuildApply;
|
||||
}
|
||||
|
||||
public static async getListByApplyCode(applyCodeList: string[]) {
|
||||
const userGuildApply: UserGuildApplyType[] = await UserGuildApplyModel.find({ applyCode: { $in: applyCodeList}, type: GUILD_APPLY_TYPE.APPLY }).lean();
|
||||
return userGuildApply;
|
||||
|
||||
Reference in New Issue
Block a user