军团:添加推送
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { Application, BackendSession, pinus } from 'pinus';
|
||||
import { Application, BackendSession, pinus, ChannelService } from 'pinus';
|
||||
import { resResult, getRandEelm, reduceCe } from '../../../pubUtils/util';
|
||||
import { STATUS, GUILD_OPERATE, GUILD_AUTH, GUILD_JOB, GUILD_APPLY_TYPE, GUILD_STRUCTURE, GUILD_REC_TYPE, GUILD_STRUCTURE_NAME } from '../../../consts';
|
||||
import { UserGuildModel } from '../../../db/UserGuild';
|
||||
import { checkAuth, joinGuild, costFund, getGuildWithRefActive, getUserGuildWithRefActive, addGuildActive } from '../../../services/guildService';
|
||||
import { checkAuth, joinGuild, costFund, getGuildWithRefActive, getUserGuildWithRefActive, addGuildActive, message } from '../../../services/guildService';
|
||||
import { GuildModel, GuildType } from '../../../db/Guild';
|
||||
import { RoleModel, RoleType } from '../../../db/Role';
|
||||
import { GUILD } from '../../../pubUtils/dicParam';
|
||||
@@ -15,7 +15,6 @@ import { hasStructureConsume, getStructureConsume, gameData } from '../../../pub
|
||||
import { GuildRecModel } from '../../../db/GuildRec';
|
||||
import { MailModel } from '../../../db/Mail';
|
||||
import { getRedis } from '../../../services/redisService';
|
||||
import User from '../../../db/User';
|
||||
|
||||
export default function (app: Application) {
|
||||
return new GuildHandler(app);
|
||||
@@ -65,10 +64,12 @@ export class GuildHandler {
|
||||
|
||||
// TODO 加入排行
|
||||
const rank = 0;
|
||||
// TODO 加入channel
|
||||
// 加入channel
|
||||
message.enterChannel(guild.code, roleId, sid);
|
||||
|
||||
// 添加动态
|
||||
await GuildRecModel.createGuildRec(roleId, guild.code, GUILD_REC_TYPE.JOIN_GUILD, [roleName]);
|
||||
const rec = await GuildRecModel.createGuildRec(roleId, guild.code, GUILD_REC_TYPE.JOIN_GUILD, [roleName]);
|
||||
message.addRec(rec);
|
||||
|
||||
// 返回
|
||||
const result = { ...guild, rank, myInfo: userGuild};
|
||||
@@ -113,6 +114,7 @@ export class GuildHandler {
|
||||
|
||||
const select = ['code', 'name', 'notice', 'introduce', 'ceLimit', 'isAuto', 'icon'];
|
||||
const guild = await GuildModel.updateInfo(code, { name, notice, introduce, ceLimit, isAuto }, {}, select.join(' '));
|
||||
message.updateInfo(code, { name, notice, introduce, ceLimit, isAuto });
|
||||
// 返回
|
||||
return resResult(STATUS.SUCCESS, { ...guild });
|
||||
|
||||
@@ -192,15 +194,23 @@ export class GuildHandler {
|
||||
await UserGuildModel.updateInfo(roleId, { auth: GUILD_AUTH.MEMBER }); // 自己降权限
|
||||
}
|
||||
|
||||
guild = await GuildModel.updateInfo(code, updateObject, { managerCnt: managerCntInc }, 'managerCnt'); // 如果有转让团长设置leader
|
||||
guild = await GuildModel.updateInfo(code, updateObject, { managerCnt: managerCntInc }, 'managerCnt code'); // 如果有转让团长设置leader
|
||||
|
||||
// 添加动态
|
||||
if(auth == GUILD_AUTH.MANAGER) {
|
||||
await GuildRecModel.createGuildRec(roleId, code, GUILD_REC_TYPE.SET_MANAGER, [role.roleName]);
|
||||
const rec = await GuildRecModel.createGuildRec(roleId, code, GUILD_REC_TYPE.SET_MANAGER, [role.roleName]);
|
||||
message.updateInfo(code, { managerCnt: guild.managerCnt });
|
||||
message.addRec(rec);
|
||||
|
||||
} else if (auth == GUILD_AUTH.LEADER) {
|
||||
await GuildRecModel.createGuildRec(roleId, code, GUILD_REC_TYPE.SET_LEADER, [roleName, role.roleName]);
|
||||
const rec = await GuildRecModel.createGuildRec(roleId, code, GUILD_REC_TYPE.SET_LEADER, [roleName, role.roleName]);
|
||||
message.changeLeader(code, guild.managerCnt, role, roleId);
|
||||
message.addRec(rec);
|
||||
} else {
|
||||
message.updateInfo(code, { managerCnt: guild.managerCnt });
|
||||
}
|
||||
|
||||
|
||||
// 返回
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
roleId: memberRoleId, auth: userGuild.auth, managerCnt: guild.managerCnt
|
||||
@@ -213,6 +223,7 @@ export class GuildHandler {
|
||||
|
||||
const roleId = session.get('roleId');
|
||||
const serverId = session.get('serverId');
|
||||
const sid = session.get('sid');
|
||||
|
||||
let userGuild = await getUserGuildWithRefActive(roleId, 'honour job auth guildCode receivedActive');
|
||||
if(!userGuild) {
|
||||
@@ -231,7 +242,8 @@ export class GuildHandler {
|
||||
guild.leader = <RoleType>guild.leader;
|
||||
guild.leader.ce = reduceCe(guild.leader.ce);
|
||||
|
||||
// TODO 刷新日活跃,周活跃
|
||||
// 打开公会页面,加入channel
|
||||
message.enterChannel(userGuild.guildCode, roleId, sid);
|
||||
|
||||
// TODO 获取排行榜
|
||||
const rank = 0;
|
||||
@@ -247,6 +259,7 @@ export class GuildHandler {
|
||||
const roleId = session.get('roleId');
|
||||
const roleName = session.get('roleName');
|
||||
const serverId = session.get('serverId');
|
||||
const sid = session.get('sid');
|
||||
const { code } = msg;
|
||||
|
||||
// 检查权限
|
||||
@@ -278,7 +291,10 @@ export class GuildHandler {
|
||||
}
|
||||
|
||||
// 添加动态
|
||||
await GuildRecModel.createGuildRec(roleId, code, GUILD_REC_TYPE.JOIN_GUILD, [roleName]);
|
||||
const rec = await GuildRecModel.createGuildRec(roleId, code, GUILD_REC_TYPE.JOIN_GUILD, [roleName]);
|
||||
// 更新人数增加
|
||||
message.updateInfo(code, { memberCnt: joinResult.memberCnt });
|
||||
message.addRec(rec);
|
||||
|
||||
hasGuild = true;
|
||||
} else { // 不自动加入,插入申请表
|
||||
@@ -330,8 +346,11 @@ export class GuildHandler {
|
||||
const joinResult = await joinGuild(code, guild.lv, roleId, serverId);
|
||||
if(joinResult.status == 0) continue;
|
||||
|
||||
// 更新人数增加
|
||||
message.updateInfo(code, { memberCnt: joinResult.memberCnt });
|
||||
// 添加动态
|
||||
await GuildRecModel.createGuildRec(roleId, code, GUILD_REC_TYPE.JOIN_GUILD, [joinResult.roleName]);
|
||||
const rec = await GuildRecModel.createGuildRec(roleId, code, GUILD_REC_TYPE.JOIN_GUILD, [joinResult.roleName]);
|
||||
message.addRec(rec);
|
||||
|
||||
roleIds.push(roleId);
|
||||
}
|
||||
@@ -446,8 +465,11 @@ export class GuildHandler {
|
||||
return joinResult.resResult;
|
||||
}
|
||||
|
||||
// 更新人数增加
|
||||
message.updateInfo(code, { memberCnt: joinResult.memberCnt });
|
||||
// 添加动态
|
||||
await GuildRecModel.createGuildRec(roleId, code, GUILD_REC_TYPE.JOIN_GUILD, [joinResult.roleName]);
|
||||
const rec = await GuildRecModel.createGuildRec(roleId, code, GUILD_REC_TYPE.JOIN_GUILD, [joinResult.roleName]);
|
||||
message.addRec(rec);
|
||||
|
||||
code = guild.code;
|
||||
}
|
||||
@@ -520,6 +542,8 @@ export class GuildHandler {
|
||||
|
||||
// 删除channel
|
||||
|
||||
message.dismiss(code);
|
||||
|
||||
return resResult(STATUS.SUCCESS, { code, status: guild.status });
|
||||
}
|
||||
|
||||
@@ -529,6 +553,7 @@ export class GuildHandler {
|
||||
const roleId = session.get('roleId');
|
||||
const roleName = session.get('roleName');
|
||||
const serverId = session.get('serverId');
|
||||
const sid = session.get('sid');
|
||||
const { code } = msg;
|
||||
|
||||
// 检查权限
|
||||
@@ -545,7 +570,9 @@ export class GuildHandler {
|
||||
if(!guild) return resResult(STATUS.GUILD_QUIT_ERROR);
|
||||
|
||||
// 添加动态
|
||||
await GuildRecModel.createGuildRec(roleId, code, GUILD_REC_TYPE.QUIT_GUILD, [roleName]);
|
||||
const rec = await GuildRecModel.createGuildRec(roleId, code, GUILD_REC_TYPE.QUIT_GUILD, [roleName]);
|
||||
message.addRec(rec);
|
||||
message.memberQuit(code, roleId, guild, sid);
|
||||
|
||||
return resResult(STATUS.SUCCESS, { hasGuild: role.hasGuild });
|
||||
}
|
||||
@@ -577,9 +604,11 @@ export class GuildHandler {
|
||||
|
||||
// TODO 发送邮件,发送推送
|
||||
|
||||
message.memberQuit(code, roleId, guild);
|
||||
|
||||
// 添加动态
|
||||
await GuildRecModel.createGuildRec(roleId, code, GUILD_REC_TYPE.QUIT_GUILD, [role.roleName]);
|
||||
const rec = await GuildRecModel.createGuildRec(roleId, code, GUILD_REC_TYPE.QUIT_GUILD, [role.roleName]);
|
||||
message.addRec(rec);
|
||||
|
||||
return resResult(STATUS.SUCCESS, { memberCnt: guild.memberCnt });
|
||||
}
|
||||
@@ -612,7 +641,7 @@ export class GuildHandler {
|
||||
const topUser = <RoleType>topUserGuild.role;
|
||||
// 交换
|
||||
|
||||
// TODO redlock 推送
|
||||
// TODO redlock
|
||||
await UserGuildModel.updateInfo(leaderRoleId, { auth: GUILD_AUTH.MEMBER }, 'auth'); // 团长撤
|
||||
await UserGuildModel.updateInfo(topUserGuild.roleId, { auth: GUILD_AUTH.LEADER }, 'auth'); // 最高功勋人升
|
||||
let managerCntInc = topUserGuild.auth == GUILD_AUTH.MANAGER ? -1 : 0; // 管理人数
|
||||
@@ -620,8 +649,10 @@ export class GuildHandler {
|
||||
const guild = await GuildModel.updateInfo(code, { leader: topUser._id }, { managerCnt: managerCntInc }, 'managerCnt'); // 如果有转让团长设置leader
|
||||
|
||||
// 添加动态
|
||||
await GuildRecModel.createGuildRec(roleId, code, GUILD_REC_TYPE.IMPEACH, [ oldRoleName, topUser.roleName]);
|
||||
const rec = await GuildRecModel.createGuildRec(roleId, code, GUILD_REC_TYPE.IMPEACH, [ oldRoleName, topUser.roleName]);
|
||||
message.addRec(rec);
|
||||
|
||||
message.changeLeader(code, guild.managerCnt, topUser, leaderRoleId);
|
||||
|
||||
const leader = { ...topUser, ce: reduceCe(topUser.ce) }
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
@@ -672,9 +703,13 @@ export class GuildHandler {
|
||||
}
|
||||
const resultStructure = result.structure.find(cur => cur.id == id);
|
||||
|
||||
// 修改信息
|
||||
message.updateInfo(code, { ...result });
|
||||
|
||||
// 添加动态
|
||||
const structureName = GUILD_STRUCTURE_NAME.get(id);
|
||||
await GuildRecModel.createGuildRec(roleId, code, GUILD_REC_TYPE.STRUCTURE_UP, [structureName, resultStructure.lv.toString()]);
|
||||
const rec = await GuildRecModel.createGuildRec(roleId, code, GUILD_REC_TYPE.STRUCTURE_UP, [structureName, resultStructure.lv.toString()]);
|
||||
message.addRec(rec);
|
||||
|
||||
return resResult(STATUS.SUCCESS, result);
|
||||
}
|
||||
|
||||
@@ -2,11 +2,13 @@ import { gameData } from "../pubUtils/data";
|
||||
import { GuildModel, GuildType } from "../db/Guild";
|
||||
import { resResult, shouldRefreshWeek, shouldRefresh } from "../pubUtils/util";
|
||||
import { STATUS } from "../consts";
|
||||
import { RoleModel } from "../db/Role";
|
||||
import { RoleModel, RoleType } from "../db/Role";
|
||||
import { UserGuildModel, UserGuildType } from "../db/UserGuild";
|
||||
import { UserGuildApplyModel } from "../db/UserGuildApply";
|
||||
import { SystemConfigModel } from "../db/SystemConfig";
|
||||
import { nowSeconds } from "../pubUtils/timeUtil";
|
||||
import { pinus } from "pinus";
|
||||
import { GuildRecType } from "../db/GuildRec";
|
||||
|
||||
/**
|
||||
* @description 检查该玩家是否有权限做操作
|
||||
@@ -55,7 +57,7 @@ export async function joinGuild(code: string, lv: number, roleId: string, server
|
||||
|
||||
await UserGuildApplyModel.deleteApply(roleId); // 删除玩家所有对其他公会的申请
|
||||
|
||||
return { status: 1, guild, userGuild, roleName: role.roleName }
|
||||
return { status: 1, guild, userGuild, roleName: role.roleName, memberCnt: guild.memberCnt }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -143,7 +145,7 @@ export async function getUserGuildWithRefActive(roleId: string, select: string)
|
||||
}
|
||||
|
||||
/**
|
||||
* 每周结算上周公会周功勋和 活跃并发奖励
|
||||
* 每周结算上周公会周功勋和 活跃并发奖励(未完)
|
||||
*
|
||||
*/
|
||||
export async function settleGuildWeekly() {
|
||||
@@ -157,4 +159,78 @@ export async function settleGuildWeekly() {
|
||||
}
|
||||
|
||||
await SystemConfigModel.updateSystemConfig({settleGuildWeeklyTime: nowSeconds()}); // 记录一下
|
||||
}
|
||||
|
||||
export const message = {
|
||||
getChannel: function(name: string, create: boolean = false) {
|
||||
let channel = pinus.app.get('channelService').getChannel(name, create);
|
||||
return channel
|
||||
},
|
||||
enterChannel: function (guildCode: string, roleId: string, sid: string) {
|
||||
// 加入channel
|
||||
let channel = this.getChannel(`guild${guildCode}`, true);
|
||||
let users = channel.getMembers();
|
||||
if (users.indexOf(roleId) === -1) {
|
||||
channel.add(roleId, sid);
|
||||
}
|
||||
return channel
|
||||
},
|
||||
memberQuit: function (guildCode: string, roleId: string, guild: GuildType,sid?: string) {
|
||||
// 被踢出公会
|
||||
this.pushMessageByUids(`guild${guildCode}`, 'onMemberQuit', roleId, {
|
||||
code: guildCode,
|
||||
roleId
|
||||
}, sid);
|
||||
// 更新人数减少
|
||||
this.updateInfo(guildCode, { memberCnt: guild.memberCnt });
|
||||
},
|
||||
dismiss: function(guildCode: string) {
|
||||
let channel = this.getChannel(`guild${guildCode}`);
|
||||
if(!!channel) {
|
||||
channel.pushMessage('onDismiss', resResult(STATUS.SUCCESS, { code: guildCode }));
|
||||
channel.destroy();
|
||||
}
|
||||
},
|
||||
updateInfo: function(guildCode: string, info: any) {
|
||||
let channel = this.getChannel(`guild${guildCode}`);
|
||||
if(!!channel) {
|
||||
channel.pushMessage('onGuildInfoUpdate', resResult(STATUS.SUCCESS, {code: guildCode, ...info}));
|
||||
}
|
||||
},
|
||||
changeLeader: function(guildCode: string, managerCnt: number, newLeader: RoleType, oldLeaderId: string) {
|
||||
let { roleId, roleName, sHid, headHid, lv, loginTime } = newLeader;
|
||||
this.updateInfo(guildCode, {managerCnt, leader: { roleId, roleName, sHid, headHid, lv, loginTime }});
|
||||
this.demotion(guildCode, oldLeaderId);
|
||||
this.promotion(guildCode, roleId);
|
||||
},
|
||||
demotion: function(guildCode: string, roleId: string) {
|
||||
this.pushMessageByUids(`guild${guildCode}`, 'onDemotion', roleId, {
|
||||
code: guildCode
|
||||
});
|
||||
},
|
||||
promotion: function(guildCode: string, roleId: string) {
|
||||
this.pushMessageByUids(`guild${guildCode}`, 'onPromotion', roleId, {
|
||||
code: guildCode
|
||||
});
|
||||
},
|
||||
addRec: function(guildRecType: GuildRecType) {
|
||||
let { guildCode, type, params, createTime } = guildRecType;
|
||||
let channel = this.getChannel(`guild${guildCode}`);
|
||||
if(!!channel) {
|
||||
channel.pushMessage('onGuildRecAdd', resResult(STATUS.SUCCESS, {type, params, createTime}));
|
||||
}
|
||||
},
|
||||
pushMessageByUids: function (name: string, path: string, roleId: string, message: {code: string, roleId?: string}, sid?: string) {
|
||||
|
||||
let channel = this.getChannel(name);
|
||||
let uids = [];
|
||||
if(!sid) {
|
||||
sid = channel && channel.getMember(roleId)['sid'];
|
||||
}
|
||||
if(sid) {
|
||||
uids.push({roleId, sid});
|
||||
pinus.app.get('channelService').pushMessageByUids(path, resResult(STATUS.SUCCESS, message), uids);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,7 +13,7 @@ export default class GuildRec extends BaseModel {
|
||||
@prop({ required: true, select: false })
|
||||
roleId: string;
|
||||
|
||||
@prop({ required: true, select: false })
|
||||
@prop({ required: true })
|
||||
guildCode: string;
|
||||
|
||||
@prop({ required: true, default: GUILD_REC_TYPE.JOIN_GUILD, enum: GUILD_REC_TYPE })
|
||||
|
||||
Reference in New Issue
Block a user