获取列表,申请,同意
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { Application, BackendSession, pinus } from 'pinus';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
import { STATUS, GUILD_OPERATE, GUILD_AUTH, GUILD_JOB } from '../../../consts';
|
||||
import { STATUS, GUILD_OPERATE, GUILD_AUTH, GUILD_JOB, GUILD_APPLY_TYPE } from '../../../consts';
|
||||
import { UserGuildModel } from '../../../db/UserGuild';
|
||||
import { checkAuth } from '../../../services/guildService';
|
||||
import { checkAuth, joinGuild } from '../../../services/guildService';
|
||||
import { GuildModel } from '../../../db/Guild';
|
||||
import { RoleModel, RoleType } from '../../../db/Role';
|
||||
import { GUILD } from '../../../pubUtils/dicParam';
|
||||
@@ -10,6 +10,7 @@ import { handleCost } from '../../../services/rewardService';
|
||||
import { getGoldObject } from '../../../pubUtils/itemUtils';
|
||||
import { getSeconds } from '../../../pubUtils/timeUtil';
|
||||
import { GuildListInfo } from '../../../pubUtils/interface';
|
||||
import { UserGuildApplyModel } from '../../../db/UserGuildApply';
|
||||
|
||||
export default function (app: Application) {
|
||||
return new GuildHandler(app);
|
||||
@@ -92,7 +93,9 @@ export class GuildHandler {
|
||||
if(!userGuild) {
|
||||
return resResult(STATUS.SUCCESS, { hasGuild: false })
|
||||
};
|
||||
const guild = await GuildModel.findByCode(userGuild.guildCode);
|
||||
let guild = await GuildModel.findByCode(userGuild.guildCode);
|
||||
|
||||
// TODO 刷新日活跃,周活跃
|
||||
|
||||
// TODO 获取排行榜
|
||||
const rank = 0;
|
||||
@@ -102,5 +105,80 @@ export class GuildHandler {
|
||||
return resResult(STATUS.SUCCESS, result);
|
||||
}
|
||||
|
||||
// 玩家申请公会
|
||||
async applyGuild(msg: { code: string }, session: BackendSession) {
|
||||
|
||||
const roleId = session.get('roleId');
|
||||
const { code } = msg;
|
||||
|
||||
//TODO 检查权限是否够 等策划表
|
||||
|
||||
const guild = await GuildModel.findByCode(code);
|
||||
const { isMemberMax, isAuto, ceLimit, lv } = guild;
|
||||
if(isMemberMax) {
|
||||
return resResult(STATUS.GUILD_MEMBER_MAX);
|
||||
}
|
||||
|
||||
const role = await RoleModel.findByRoleId(roleId);
|
||||
if(ceLimit > role.ce) {
|
||||
return resResult(STATUS.GUILD_NOT_REACH_CONDI);
|
||||
}
|
||||
|
||||
let hasGuild = false;
|
||||
if(isAuto) { // 自动加入
|
||||
const joinResult = await joinGuild(code, lv, roleId);
|
||||
if(joinResult.status == 0) {
|
||||
return joinResult.resResult;
|
||||
}
|
||||
|
||||
hasGuild = true;
|
||||
} else { // 不自动加入,插入申请表
|
||||
await UserGuildApplyModel.createUserGuildApply(role, guild, GUILD_APPLY_TYPE.APPLY);
|
||||
}
|
||||
|
||||
// 返回
|
||||
return resResult(STATUS.SUCCESS, { code, hasGuild });
|
||||
}
|
||||
|
||||
// 玩家申请公会
|
||||
async getApplyList(msg: { code: string, lastApplyCode: string }, session: BackendSession) {
|
||||
|
||||
const roleId = session.get('roleId');
|
||||
const { code, lastApplyCode } = msg;
|
||||
|
||||
// TODO 查询权限 等策划表
|
||||
|
||||
const result = await UserGuildApplyModel.getListByGuild(code, lastApplyCode);
|
||||
const list = result.map(cur => {
|
||||
let role = <RoleType>cur.role;
|
||||
return { applyCode: cur.applyCode, ...role };
|
||||
});
|
||||
|
||||
return resResult(STATUS.SUCCESS, { list });
|
||||
}
|
||||
|
||||
// 团长同意/拒绝公会申请
|
||||
async receiveApply(msg: { code: string, applyCodeList: [string], isReceived: boolean }, session: BackendSession) {
|
||||
|
||||
const roleId = session.get('roleId');
|
||||
const { code, applyCodeList, isReceived } = msg;
|
||||
|
||||
// TODO 查询权限 等策划表
|
||||
|
||||
let roleIds = new Array<string>();
|
||||
if(isReceived) { // 同意申请,加入
|
||||
const guild = await GuildModel.findByCode(code);
|
||||
const applyList = await UserGuildApplyModel.getListByApplyCode(applyCodeList);
|
||||
|
||||
for(let { roleId } of applyList) {
|
||||
const joinResult = await joinGuild(code, guild.lv, roleId);
|
||||
if(joinResult.status == 0) break;
|
||||
roleIds.push(roleId);
|
||||
}
|
||||
} else { // 拒绝申请,删除申请
|
||||
await UserGuildApplyModel.deleteApplyByApplyCode(applyCodeList);
|
||||
}
|
||||
|
||||
return resResult(STATUS.SUCCESS, { roleIds });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user