军团,创建查询列表,查询个人军团信息

This commit is contained in:
luying
2021-01-19 16:18:45 +08:00
parent 71c5182926
commit ee21a21e80
8 changed files with 220 additions and 97 deletions

View File

@@ -4,10 +4,12 @@ import { STATUS, GUILD_OPERATE, GUILD_AUTH, GUILD_JOB } from '../../../consts';
import { UserGuildModel } from '../../../db/UserGuild';
import { checkAuth } from '../../../services/guildService';
import { GuildModel } from '../../../db/Guild';
import { RoleModel } from '../../../db/Role';
import { RoleModel, RoleType } from '../../../db/Role';
import { GUILD } from '../../../pubUtils/dicParam';
import { handleCost } from '../../../services/rewardService';
import { getGoldObject } from '../../../pubUtils/itemUtils';
import { getSeconds } from '../../../pubUtils/timeUtil';
import { GuildListInfo } from '../../../pubUtils/interface';
export default function (app: Application) {
return new GuildHandler(app);
@@ -17,7 +19,7 @@ export class GuildHandler {
constructor(private app: Application) {
}
//TODO创建军团
// 创建军团
async createGuild(msg: { name: string, icon: number, notice: string }, session: BackendSession) {
const roleId = session.get('roleId');
@@ -25,7 +27,7 @@ export class GuildHandler {
const { name, icon, notice } = msg;
// 检查权限是否够,包括是否参过团
const { auth } = await UserGuildModel.getMyGuild(roleId);
const auth = await UserGuildModel.getMyAuth(roleId);
const checkResult = checkAuth(GUILD_OPERATE.CREATE_GUILD, auth);
if(!checkResult) return resResult(STATUS.GUILD_AUTH_NOT_ENOUGH);
@@ -42,33 +44,63 @@ export class GuildHandler {
await handleCost(roleId, sid, [getGoldObject(GUILD.GUILD_CREATE_COST)]);
// 创建公会
const guild = await GuildModel.createGuild({ name, icon, notice, leader: role._id, members: [roleId], ce: role.ce });
const guild = await GuildModel.createGuild({ name, icon, notice }, role);
if(!guild) return resResult(STATUS.GUILD_CREATE_ERROR);
const userGuild = await UserGuildModel.createUserGuild({ guildCode: guild.code, roleId, role: role._id, guild: guild._id, auth: GUILD_AUTH.LEADER, job: GUILD_JOB.JIANGJUN });
const userGuild = await UserGuildModel.createUserGuild(guild.code, role, true);
if(!userGuild) return resResult(STATUS.GUILD_CREATE_ERROR);
// TODO 加入排行
const rank = 0;
// TODO 加入channel
// 返回
const result = { ...guild, rank, myInfo: {...userGuild}};
const result = { ...guild, rank, myInfo: userGuild};
return resResult(STATUS.SUCCESS, result);
}
//TODO 获取军团列表
// 获取军团列表
async getGuildList(msg: { page: number, showPeopleMax: boolean, name: string }, session: BackendSession) {
const roleId = session.get('roleId');
// const sid = session.get('sid');
const { page = 1, showPeopleMax, name } = msg;
const list = [{
code: "code",
name: "name",
icon: 1,
lv: 0,
memberCnt: 0,
leader: "leader",
ceLimit: 0,
quitTime: 0,
hasApply: true
}];
return resResult(STATUS.SUCCESS, { list });
const guildList = await GuildModel.findByCondition(page, showPeopleMax, name);
// TODO 加入申请列表
const { quitGuildTime: quitTime = 0 } = await RoleModel.findByRoleId(roleId);
const list = new Array<GuildListInfo>();
for(let guild of guildList) {
let info = new GuildListInfo(guild);
// TODO 查询申请
info.setApply(false);
list.push(info);
}
return resResult(STATUS.SUCCESS, { quitTime, list });
}
// 团员获取自己军团详细信息
async getMyGuildInfo(msg: { }, session: BackendSession) {
const roleId = session.get('roleId');
//TODO 检查权限是否够 等策划表
const userGuild = await UserGuildModel.getMyGuild(roleId, 'honour job auth guildCode');
if(!userGuild) {
return resResult(STATUS.SUCCESS, { hasGuild: false })
};
const guild = await GuildModel.findByCode(userGuild.guildCode);
// TODO 获取排行榜
const rank = 0;
// 返回
const result = { hasGuild: true, ...guild, rank, myInfo: userGuild};
return resResult(STATUS.SUCCESS, result);
}
}