获取列表,申请,同意
This commit is contained in:
@@ -48,4 +48,17 @@ export enum USER_GUILD_STATUS {
|
||||
}
|
||||
|
||||
// 查询每页显示
|
||||
export const GUILD_PER_PAGE = 30;
|
||||
export const GUILD_PER_PAGE = 30;
|
||||
|
||||
// 公会申请状态
|
||||
export enum GUILD_APPLY_STATUS {
|
||||
WAITING = 1, // 等待操作
|
||||
AGREE = 2, // 同意
|
||||
REFUSE = 3 // 拒绝
|
||||
}
|
||||
|
||||
// 公会申请类型
|
||||
export enum GUILD_APPLY_TYPE {
|
||||
APPLY = 1, // 申请
|
||||
INVITE = 2 // 邀请
|
||||
}
|
||||
@@ -124,8 +124,11 @@ export const STATUS = {
|
||||
|
||||
// 军团 20900-20999
|
||||
GUILD_AUTH_NOT_ENOUGH: { code: 20900, simStr: '权限不足' },
|
||||
GUILD_NAME_DUP: { code: 20901, simStr: '公会名重复' },
|
||||
GUILD_NAME_DUP: { code: 20901, simStr: '军团名重复' },
|
||||
GUILD_CREATE_ERROR: { code: 20902, simStr: '创建失败' },
|
||||
GUILD_MEMBER_MAX: { code: 20903, simStr: '军团人员已满' },
|
||||
GUILD_NOT_REACH_CONDI: { code: 20903, simStr: '您未达到申请军团条件' },
|
||||
GUILD_HAS_JOIN: { code: 20904, simStr: '已加入过其他军团' },
|
||||
|
||||
// 通用 30000 - 30099
|
||||
DIC_DATA_NOT_FOUND: { code: 30000, simStr: '数据表未找到' },
|
||||
|
||||
+11
-2
@@ -95,7 +95,7 @@ export default class Guild extends BaseModel {
|
||||
}
|
||||
|
||||
public static async findByCondition(page: number, showPeopleMax: boolean, name: string) {
|
||||
const condition = {};
|
||||
const condition = { status: GUILD_STATUS.RUNNING };
|
||||
if(!showPeopleMax) {
|
||||
condition['isMemberMax'] = false;
|
||||
}
|
||||
@@ -103,6 +103,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 })
|
||||
.limit(GUILD_PER_PAGE).skip((page - 1) * GUILD_PER_PAGE)
|
||||
.select('code icon name lv memberCnt leader ceLimit isAuto')
|
||||
.populate('leader', 'roleName', 'Role')
|
||||
@@ -111,11 +112,19 @@ export default class Guild extends BaseModel {
|
||||
}
|
||||
|
||||
public static async findByCode(code: string) {
|
||||
const result = await GuildModel.findOne({ code, status: GUILD_STATUS.RUNNING }, { _id: 0 })
|
||||
const result = await GuildModel.findOne({ code, status: GUILD_STATUS.RUNNING })
|
||||
.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();
|
||||
if(result && result.memberCnt >= maxMemberCnt) {
|
||||
result = await GuildModel.findOneAndUpdate({ code }, { $set: { isMemberMax: true } }).lean();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export const GuildModel = getModelForClass(Guild);
|
||||
|
||||
@@ -30,10 +30,7 @@ export default class UserGuild extends BaseModel {
|
||||
job: number;
|
||||
|
||||
@prop({ required: true, default: 0 })
|
||||
honour: number;
|
||||
|
||||
@prop({ required: true, default: 0 })
|
||||
honourWeek: number;
|
||||
honourWeekly: number;
|
||||
|
||||
@prop({ required: true, default: USER_GUILD_STATUS.ON, enum: USER_GUILD_STATUS})
|
||||
status: number;
|
||||
@@ -66,10 +63,10 @@ export default class UserGuild extends BaseModel {
|
||||
const doc = new UserGuildModel();
|
||||
let job = isLeader? GUILD_JOB.JIANGJUN: GUILD_JOB.SHIZHANG;
|
||||
let auth = isLeader? GUILD_AUTH.LEADER: GUILD_AUTH.MEMBER;
|
||||
const update = Object.assign(doc.toJSON(), { guildCode, roleId: role.roleId, job, auth });
|
||||
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 })
|
||||
.select('honour job auth')
|
||||
.select('honourWeekly job auth')
|
||||
.lean();
|
||||
|
||||
return result;
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType, Ref } from '@typegoose/typegoose';
|
||||
import Role, { RoleType } from './Role';
|
||||
import Guild, { GuildType } from './Guild';
|
||||
import { GUILD_AUTH, USER_GUILD_STATUS, GUILD_JOB, GUILD_APPLY_STATUS, GUILD_APPLY_TYPE, GUILD_PER_PAGE, GUILD_STATUS } from '../consts';
|
||||
import { genCode } from '../pubUtils/util';
|
||||
|
||||
@index({ roleId: 1 })
|
||||
export default class UserGuildApply extends BaseModel {
|
||||
@prop({ required: true })
|
||||
applyCode: string; // 唯一code
|
||||
|
||||
@prop({ required: true })
|
||||
roleId: string; // 玩家id
|
||||
|
||||
@prop({ required: true })
|
||||
role: Ref<Role>;
|
||||
|
||||
@prop({ required: true })
|
||||
guildCode: string; // 公会唯一code
|
||||
|
||||
@prop({ required: true })
|
||||
guild: Ref<Guild>;
|
||||
|
||||
@prop({ required: true, enum: GUILD_APPLY_TYPE, select: false})
|
||||
type: number;
|
||||
|
||||
public static async createUserGuildApply(role: RoleType, guild: GuildType, type: number) {
|
||||
const applyCode = genCode(10);
|
||||
const doc = new UserGuildApplyModel();
|
||||
const update = Object.assign(doc.toJSON(), { applyCode, roleId: role.roleId, role: role._id, guildCode: guild.code, guild: guild._id, type });
|
||||
delete update._id;
|
||||
const result: UserGuildApplyType = await UserGuildApplyModel.findOneAndUpdate({ applyCode }, update, { upsert: true, new: true }).lean();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async deleteApply(roleId: string) {
|
||||
const result = await UserGuildApplyModel.deleteMany({ roleId, 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;
|
||||
}
|
||||
|
||||
public static async findByCode(applyCode: string) {
|
||||
const userGuildApply: UserGuildApplyType = await UserGuildApplyModel.findOne({ applyCode }).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;
|
||||
}
|
||||
|
||||
public static async getListByGuild(code: string, lastApplyCode: string) {
|
||||
let condition = { guildCode: code, type: GUILD_APPLY_TYPE.APPLY };
|
||||
if(lastApplyCode) {
|
||||
const lastApply = await this.findByCode(lastApplyCode);
|
||||
condition["createdAt"] = { $lt: lastApply.createdAt };
|
||||
}
|
||||
const list: UserGuildApplyType[] = await UserGuildApplyModel.find(condition)
|
||||
.sort({ createdAt: -1 })
|
||||
.select('applyCode role')
|
||||
.populate('role', 'roleId roleName ce headHid sHid lv title job loginTime', 'Role')
|
||||
.limit(GUILD_PER_PAGE).lean();
|
||||
return list
|
||||
}
|
||||
}
|
||||
|
||||
export const UserGuildApplyModel = getModelForClass(UserGuildApply);
|
||||
|
||||
export interface UserGuildApplyType extends Pick<DocumentType<UserGuildApply>, keyof UserGuildApply> { };
|
||||
export type UserGuildApplyUpdateParam = Partial<UserGuildApplyType>; // 将所有字段变成可选项
|
||||
Reference in New Issue
Block a user