创建公会
This commit is contained in:
@@ -1,8 +1,15 @@
|
||||
import {Application, BackendSession, pinus} from 'pinus';
|
||||
import { Application, BackendSession, pinus } from 'pinus';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
import { STATUS } from '../../../consts';
|
||||
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 { GUILD } from '../../../pubUtils/dicParam';
|
||||
import { handleCost } from '../../../services/rewardService';
|
||||
import { getGoldObject } from '../../../pubUtils/itemUtils';
|
||||
|
||||
export default function(app: Application) {
|
||||
export default function (app: Application) {
|
||||
return new GuildHandler(app);
|
||||
}
|
||||
|
||||
@@ -11,13 +18,46 @@ export class GuildHandler {
|
||||
}
|
||||
|
||||
//TODO创建军团
|
||||
async createGuild() {
|
||||
async createGuild(msg: { name: string, icon: number, notice: string }, session: BackendSession) {
|
||||
|
||||
const roleId = session.get('roleId');
|
||||
const sid = session.get('sid');
|
||||
const { name, icon, notice } = msg;
|
||||
|
||||
// 检查权限是否够,包括是否参过团
|
||||
const { auth } = await UserGuildModel.getMyGuild(roleId);
|
||||
const checkResult = checkAuth(GUILD_OPERATE.CREATE_GUILD, auth);
|
||||
if(!checkResult) return resResult(STATUS.GUILD_AUTH_NOT_ENOUGH);
|
||||
|
||||
// 检查名字是否重
|
||||
const checkNameResult = await GuildModel.checkName(name);
|
||||
if(checkNameResult) return resResult(STATUS.GUILD_NAME_DUP);
|
||||
|
||||
// 检查元宝是否够
|
||||
const role = await RoleModel.findByRoleId(roleId);
|
||||
if(GUILD.GUILD_CREATE_COST > role.gold) { // TODO 系统参数表字段更改
|
||||
return resResult(STATUS.DAILY_REFRESH_GOLD_LACK);
|
||||
}
|
||||
|
||||
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 });
|
||||
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 });
|
||||
if(!userGuild) return resResult(STATUS.GUILD_CREATE_ERROR);
|
||||
|
||||
// TODO 加入排行
|
||||
const rank = 0;
|
||||
|
||||
// 返回
|
||||
const result = { ...guild, rank, myInfo: {...userGuild}};
|
||||
return resResult(STATUS.SUCCESS, result);
|
||||
}
|
||||
|
||||
//TODO 获取军团列表
|
||||
async getGuildList(msg: {page: number, showPeopleMax: boolean, name: string }, session: BackendSession) {
|
||||
|
||||
async getGuildList(msg: { page: number, showPeopleMax: boolean, name: string }, session: BackendSession) {
|
||||
|
||||
const list = [{
|
||||
code: "code",
|
||||
name: "name",
|
||||
|
||||
Reference in New Issue
Block a user