军团:添加推送
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user