军团:添加邮件
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
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 { STATUS, GUILD_OPERATE, GUILD_AUTH, GUILD_JOB, GUILD_APPLY_TYPE, GUILD_STRUCTURE, GUILD_REC_TYPE, GUILD_STRUCTURE_NAME, MAIL_TYPE } from '../../../consts';
|
||||
import { UserGuildModel } from '../../../db/UserGuild';
|
||||
import { checkAuth, joinGuild, costFund, getGuildWithRefActive, getUserGuildWithRefActive, addGuildActive, message } from '../../../services/guildService';
|
||||
import { checkAuth, joinGuild, getGuildWithRefActive, getUserGuildWithRefActive, addGuildActive, message } from '../../../services/guildService';
|
||||
import { GuildModel, GuildType } from '../../../db/Guild';
|
||||
import { RoleModel, RoleType } from '../../../db/Role';
|
||||
import { GUILD } from '../../../pubUtils/dicParam';
|
||||
import { ARMY } from '../../../pubUtils/dicParam';
|
||||
import { handleCost, addItems } from '../../../services/rewardService';
|
||||
import { getGoldObject } from '../../../pubUtils/itemUtils';
|
||||
import { nowSeconds, getBeforeDaySeconds } from '../../../pubUtils/timeUtil';
|
||||
@@ -13,8 +13,7 @@ import { GuildListInfo } from '../../../pubUtils/interface';
|
||||
import { UserGuildApplyModel } from '../../../db/UserGuildApply';
|
||||
import { hasStructureConsume, getStructureConsume, gameData } from '../../../pubUtils/data';
|
||||
import { GuildRecModel } from '../../../db/GuildRec';
|
||||
import { MailModel } from '../../../db/Mail';
|
||||
import { getRedis } from '../../../services/redisService';
|
||||
import { sendMail } from '../../../services/mailService';
|
||||
|
||||
export default function (app: Application) {
|
||||
return new GuildHandler(app);
|
||||
@@ -43,11 +42,11 @@ export class GuildHandler {
|
||||
|
||||
// 检查元宝是否够
|
||||
const role = await RoleModel.findByRoleId(roleId);
|
||||
if(GUILD.GUILD_CREATE_COST > role.gold) { // TODO 系统参数表字段更改
|
||||
if(ARMY.ARMY_CREAT_COST > role.gold) {
|
||||
return resResult(STATUS.DAILY_REFRESH_GOLD_LACK);
|
||||
}
|
||||
|
||||
await handleCost(roleId, sid, [getGoldObject(GUILD.GUILD_CREATE_COST)]);
|
||||
await handleCost(roleId, sid, [getGoldObject(ARMY.ARMY_CREAT_COST)]);
|
||||
|
||||
// 创建公会
|
||||
const guild = await GuildModel.createGuild({ name, icon, notice }, role, serverId);
|
||||
@@ -194,20 +193,23 @@ export class GuildHandler {
|
||||
await UserGuildModel.updateInfo(roleId, { auth: GUILD_AUTH.MEMBER }); // 自己降权限
|
||||
}
|
||||
|
||||
guild = await GuildModel.updateInfo(code, updateObject, { managerCnt: managerCntInc }, 'managerCnt code'); // 如果有转让团长设置leader
|
||||
guild = await GuildModel.updateInfo(code, updateObject, { managerCnt: managerCntInc }, 'managerCnt code name'); // 如果有转让团长设置leader
|
||||
|
||||
// 添加动态
|
||||
if(auth == GUILD_AUTH.MANAGER) {
|
||||
const rec = await GuildRecModel.createGuildRec(roleId, code, GUILD_REC_TYPE.SET_MANAGER, [role.roleName]);
|
||||
message.updateInfo(code, { managerCnt: guild.managerCnt });
|
||||
message.addRec(rec);
|
||||
await sendMail(MAIL_TYPE.GUILD_BE_SET_MANAGER, memberRoleId, roleName, [guild.name]);
|
||||
|
||||
} else if (auth == GUILD_AUTH.LEADER) {
|
||||
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);
|
||||
await sendMail(MAIL_TYPE.GUILD_BE_SET_LEADER, memberRoleId, roleName, [guild.name]);
|
||||
} else {
|
||||
message.updateInfo(code, { managerCnt: guild.managerCnt });
|
||||
await sendMail(MAIL_TYPE.GUILD_BE_SET_MEMBER, memberRoleId, roleName, [guild.name]);
|
||||
}
|
||||
|
||||
|
||||
@@ -329,6 +331,7 @@ export class GuildHandler {
|
||||
async receiveApply(msg: { code: string, applyCodeList: [string], isReceived: boolean }, session: BackendSession) {
|
||||
|
||||
const roleId = session.get('roleId');
|
||||
const roleName = session.get('roleName');
|
||||
const serverId = session.get('serverId');
|
||||
const { code, applyCodeList, isReceived } = msg;
|
||||
|
||||
@@ -338,9 +341,9 @@ export class GuildHandler {
|
||||
|
||||
const applyList = await UserGuildApplyModel.getListByApplyCode(applyCodeList);
|
||||
|
||||
const guild = await GuildModel.findByCode(code, serverId);
|
||||
let roleIds = new Array<string>();
|
||||
if(isReceived) { // 同意申请,加入
|
||||
const guild = await GuildModel.findByCode(code, serverId);
|
||||
|
||||
for(let { roleId } of applyList) {
|
||||
const joinResult = await joinGuild(code, guild.lv, roleId, serverId);
|
||||
@@ -356,7 +359,7 @@ export class GuildHandler {
|
||||
}
|
||||
} else { // 拒绝申请,删除申请
|
||||
for(let { roleId } of applyList) {
|
||||
// TODO 发送邮件
|
||||
await sendMail(MAIL_TYPE.GUILD_APPLY_REFUSE, roleId, roleName, [guild.name]);
|
||||
}
|
||||
|
||||
await UserGuildApplyModel.deleteApplyByApplyCode(applyCodeList);
|
||||
@@ -494,7 +497,8 @@ export class GuildHandler {
|
||||
if(checkDetailResult) {
|
||||
select.push('auth', 'honourWeekly honourUpdateTime');
|
||||
}
|
||||
let list = await UserGuildModel.getListByGuild(code, select.join(' '));
|
||||
let list = await UserGuildModel.getListByGuild(code, select.join(' '), { auth: 1 });
|
||||
console.log('**', JSON.stringify(list))
|
||||
let result = list.map(cur => {
|
||||
let role = <RoleType>cur.role;
|
||||
delete role._id;
|
||||
@@ -581,6 +585,7 @@ export class GuildHandler {
|
||||
async kick(msg: { code: string, roleId: string }, session: BackendSession) {
|
||||
|
||||
const roleId = session.get('roleId');
|
||||
const roleName = session.get('roleName');
|
||||
const serverId = session.get('serverId');
|
||||
const { code, roleId: memberRoleId } = msg;
|
||||
|
||||
@@ -602,13 +607,12 @@ export class GuildHandler {
|
||||
const guild = await GuildModel.quit(code, memberRoleId, serverId);
|
||||
if(!guild) return resResult(STATUS.GUILD_KICK_ERROR);
|
||||
|
||||
// TODO 发送邮件,发送推送
|
||||
|
||||
message.memberQuit(code, roleId, guild);
|
||||
|
||||
// 添加动态
|
||||
const rec = await GuildRecModel.createGuildRec(roleId, code, GUILD_REC_TYPE.QUIT_GUILD, [role.roleName]);
|
||||
message.addRec(rec);
|
||||
await sendMail(MAIL_TYPE.GUILD_BE_KICK, memberRoleId, roleName, [guild.name]);
|
||||
|
||||
return resResult(STATUS.SUCCESS, { memberCnt: guild.memberCnt });
|
||||
}
|
||||
@@ -617,6 +621,8 @@ export class GuildHandler {
|
||||
async impeach(msg: { code: string, roleId: string }, session: BackendSession) {
|
||||
|
||||
const roleId = session.get('roleId');
|
||||
const roleName = session.get('roleName');
|
||||
const sid = session.get('sid');
|
||||
// const serverId = session.get('serverId');
|
||||
const { code, roleId: leaderRoleId } = msg;
|
||||
|
||||
@@ -638,6 +644,14 @@ export class GuildHandler {
|
||||
if (!topUserGuild) {
|
||||
return resResult(STATUS.GUILD_MEMBER_NOT_FOUND);
|
||||
}
|
||||
|
||||
// 检查元宝是否够
|
||||
const role = await RoleModel.findByRoleId(roleId);
|
||||
if(ARMY.ARMY_IMPEACH_COST > role.gold) {
|
||||
return resResult(STATUS.DAILY_REFRESH_GOLD_LACK);
|
||||
}
|
||||
await handleCost(roleId, sid, [getGoldObject(ARMY.ARMY_IMPEACH_COST)]);
|
||||
|
||||
const topUser = <RoleType>topUserGuild.role;
|
||||
// 交换
|
||||
|
||||
@@ -646,13 +660,15 @@ export class GuildHandler {
|
||||
await UserGuildModel.updateInfo(topUserGuild.roleId, { auth: GUILD_AUTH.LEADER }, 'auth'); // 最高功勋人升
|
||||
let managerCntInc = topUserGuild.auth == GUILD_AUTH.MANAGER ? -1 : 0; // 管理人数
|
||||
|
||||
const guild = await GuildModel.updateInfo(code, { leader: topUser._id }, { managerCnt: managerCntInc }, 'managerCnt'); // 如果有转让团长设置leader
|
||||
const guild = await GuildModel.updateInfo(code, { leader: topUser._id }, { managerCnt: managerCntInc }, 'managerCnt name'); // 如果有转让团长设置leader
|
||||
|
||||
// 添加动态
|
||||
const rec = await GuildRecModel.createGuildRec(roleId, code, GUILD_REC_TYPE.IMPEACH, [ oldRoleName, topUser.roleName]);
|
||||
message.addRec(rec);
|
||||
|
||||
message.changeLeader(code, guild.managerCnt, topUser, leaderRoleId);
|
||||
await sendMail(MAIL_TYPE.GUILD_BE_IMPEACH, leaderRoleId, roleName, [guild.name]);
|
||||
await sendMail(MAIL_TYPE.GUILD_BE_SET_LEADER, topUser.roleId, roleName, [guild.name]);
|
||||
|
||||
const leader = { ...topUser, ce: reduceCe(topUser.ce) }
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
@@ -692,7 +708,7 @@ export class GuildHandler {
|
||||
return resResult(STATUS.GUILD_STRUCTURE_LV_MAX);
|
||||
}
|
||||
const cost = getStructureConsume(id, curStructure.lv);
|
||||
const costResult = await costFund(code, cost, sid);
|
||||
const costResult = await GuildModel.costFund(code, cost);
|
||||
if(!costResult) {
|
||||
return resResult(STATUS.GUILD_FUND_NOT_ENOUGH);
|
||||
}
|
||||
@@ -746,13 +762,7 @@ export class GuildHandler {
|
||||
const { members } = guild;
|
||||
//下发邮件
|
||||
for(let roleId of members) {
|
||||
let mail = await MailModel.addMail({roleId, goods: [], sendName: roleName, mailId: 1, content: info});
|
||||
|
||||
let key = 'login_roleId_' + roleId;
|
||||
let sid = await getRedis(key);
|
||||
if (!!sid) {
|
||||
pinus.app.rpc.connector.connectorRemote.pushMessage.toServer(sid, roleId, 'onMailsAdd', [mail]);
|
||||
}
|
||||
await sendMail(MAIL_TYPE.SEND_MAIL, roleId, roleName, [info]);
|
||||
}
|
||||
|
||||
return resResult(STATUS.SUCCESS, { isSuccess: true });
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { gameData } from "../pubUtils/data";
|
||||
import { GuildModel, GuildType } from "../db/Guild";
|
||||
import { resResult, shouldRefreshWeek, shouldRefresh } from "../pubUtils/util";
|
||||
import { STATUS } from "../consts";
|
||||
import { STATUS, GUILD_OPERATE, MAIL_TYPE } from "../consts";
|
||||
import { RoleModel, RoleType } from "../db/Role";
|
||||
import { UserGuildModel, UserGuildType } from "../db/UserGuild";
|
||||
import { UserGuildApplyModel } from "../db/UserGuildApply";
|
||||
@@ -9,6 +9,9 @@ import { SystemConfigModel } from "../db/SystemConfig";
|
||||
import { nowSeconds } from "../pubUtils/timeUtil";
|
||||
import { pinus } from "pinus";
|
||||
import { GuildRecType } from "../db/GuildRec";
|
||||
import { MailModel } from "../db/Mail";
|
||||
import { RewardInter } from "../pubUtils/interface";
|
||||
import { getRedis } from "./redisService";
|
||||
|
||||
/**
|
||||
* @description 检查该玩家是否有权限做操作
|
||||
@@ -60,18 +63,6 @@ export async function joinGuild(code: string, lv: number, roleId: string, server
|
||||
return { status: 1, guild, userGuild, roleName: role.roleName, memberCnt: guild.memberCnt }
|
||||
}
|
||||
|
||||
/**
|
||||
* 消耗军团资金
|
||||
* @param code 军团唯一code
|
||||
* @param cost 消耗值
|
||||
* @param sid 推送channel
|
||||
*/
|
||||
export async function costFund(code: string, cost: number, sid: string) {
|
||||
const guild = await GuildModel.costFund(code, cost);
|
||||
// TODO 推送
|
||||
return guild;
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新军团活跃
|
||||
* @param guildCode 军团唯一code
|
||||
@@ -233,4 +224,4 @@ export const message = {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
24
game-server/app/services/mailService.ts
Normal file
24
game-server/app/services/mailService.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { RewardInter } from "../pubUtils/interface";
|
||||
import { MailModel } from "../db/Mail";
|
||||
import { getRedis } from "./redisService";
|
||||
import { pinus } from "pinus";
|
||||
import { gameData } from "../pubUtils/data";
|
||||
|
||||
export async function sendMail(operate: number, toRoleId: string, sendName: string, params: string[], goods: RewardInter[] = []) {
|
||||
let content = getContent( operate, params);
|
||||
let mail = await MailModel.addMail({roleId: toRoleId, goods, sendName, mailId: 1, content});
|
||||
|
||||
let key = 'login_roleId_' + toRoleId;
|
||||
let sid = await getRedis(key);
|
||||
if (!!sid) {
|
||||
pinus.app.rpc.connector.connectorRemote.pushMessage.toServer(sid, toRoleId, 'onMailsAdd', [mail]);
|
||||
}
|
||||
}
|
||||
|
||||
export function getContent(operate: number, params: string[]) {
|
||||
let content = gameData.mail.get(operate)||'%d';
|
||||
for(let p of params) {
|
||||
content = content.replace(/%d/, p);
|
||||
}
|
||||
return content
|
||||
}
|
||||
@@ -307,7 +307,8 @@ export const FILENAME = {
|
||||
DIC_GUILD_STORE_BASE: 'dic_army_storeBase',
|
||||
DIC_GUILD_POSITION: 'dic_army_position',
|
||||
DIC_ACTIVE_DAY_REWARD: 'dic_army_activeDayReward',
|
||||
DIC_ACTIVE_WEEK_REWARD: 'dic_army_activeWeekReward'
|
||||
DIC_ACTIVE_WEEK_REWARD: 'dic_army_activeWeekReward',
|
||||
DIC_MAIL: 'dic_email_army'
|
||||
}
|
||||
|
||||
export const WAR_RELATE_TABLES = [
|
||||
@@ -329,4 +330,16 @@ export const EQUIP_STRENGTHEN_TYPE = {
|
||||
SINGLE: 1, // 单件单级强化
|
||||
SINGLE_QUICK: 2, // 单件一键强化
|
||||
ALL_QUICK: 3 // 武将全部装备栏一键强化
|
||||
}
|
||||
}
|
||||
|
||||
// 邮件内容类型
|
||||
export const MAIL_TYPE = {
|
||||
SEND_MAIL: 0,
|
||||
GUILD_APPLY_REFUSE: 1,
|
||||
GUILD_BE_IMPEACH: 2,
|
||||
GUILD_BE_SET_LEADER: 3,
|
||||
GUILD_BE_KICK: 4,
|
||||
GUILD_ACTIVE_REWARD: 5,
|
||||
GUILD_BE_SET_MANAGER: 6,
|
||||
GUILD_BE_SET_MEMBER: 7
|
||||
};
|
||||
@@ -79,7 +79,7 @@ export default class UserGuild extends BaseModel {
|
||||
public static async getListByGuild(guildCode: string, select?: string, sort: { auth?: number, honourWeekly?: number, honourUpdateTime?: number } = {auth: 1}) {
|
||||
const userGuilds: UserGuildType[] = await UserGuildModel.find({ guildCode, status: USER_GUILD_STATUS.ON })
|
||||
.select(select)
|
||||
.sort({ auth: 1 })
|
||||
.sort(sort)
|
||||
.populate('role', 'roleId roleName ce headHid sHid lv title loginTime', 'Role')
|
||||
.lean();
|
||||
return userGuilds;
|
||||
|
||||
@@ -48,6 +48,7 @@ import { dicCenterBase, dicEquipPriduceBase, dicBossBase, dicTrainBase, dicDonat
|
||||
import { dicGuildActiveDayReward } from './dictionary/DicGuildActiveDayReward';
|
||||
import { dicGuildActiveWeekReward } from './dictionary/DicGuildActiveWeekReward';
|
||||
import { dicGuildPosition } from "./dictionary/DicGuildPosition";
|
||||
import { dicMail } from "./dictionary/DicMail";
|
||||
|
||||
export const gameData = {
|
||||
blurprtCompose: dicBlueprtCompose,
|
||||
@@ -119,7 +120,8 @@ export const gameData = {
|
||||
structureConsume: dicStructureConsume,
|
||||
guildActiveDayReward: dicGuildActiveDayReward,
|
||||
guildActiveWeekReward: dicGuildActiveWeekReward,
|
||||
guildPosition: dicGuildPosition
|
||||
guildPosition: dicGuildPosition,
|
||||
mail: dicMail
|
||||
};
|
||||
|
||||
// 在此提供一些原先在gamedata中提供的方法,以便更方便获取gameData数据
|
||||
|
||||
@@ -35,6 +35,16 @@ export const PVP = {
|
||||
PVP_OPPONENT_FREEREFRESH: 3, // pvp挑战对手每日免费刷新次数
|
||||
PVP_WINREWARD_UPLIMIT: 10, // 连胜奖励军功加成上限
|
||||
};
|
||||
export const GUILD = {
|
||||
GUILD_CREATE_COST: 10, // 创建公会消耗元宝
|
||||
export const ARMY = {
|
||||
ARMY_CREAT_COST: 188, // 创建军团需要的元宝
|
||||
ARMY_POSITION_SELL: 30, // 拍卖行职位额外分成占比(%)
|
||||
ARMY_POSITION_WEEKREWARD: 30, // 周奖励职位额外分成占比(%)
|
||||
ARMY_IMPEACH_COST: 30, // 弹劾需要消耗的元宝数量
|
||||
ARMY_DEVELOPMENT_SPEED: 30, // 碎片研发单次加速时间(分钟)
|
||||
ARMY_DEVELOPMENT_SPEEDCOST: 50, // 单次助力加速消耗的元宝
|
||||
ARMY_DEVELOPMENT_SPEEDTMES: 10, // 单个碎片可助力加速的最大次数
|
||||
};
|
||||
export const TREASURE = {
|
||||
CAPTAIN_DROP: 5, // 普通套装图纸队长必掉落次数
|
||||
TEAMMATE_DROP: 10, // 普通套装图纸队员必掉落次数
|
||||
};
|
||||
|
||||
20
shared/pubUtils/dictionary/DicMail.ts
Normal file
20
shared/pubUtils/dictionary/DicMail.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
// 邮件内容
|
||||
import {readJsonFile} from '../util'
|
||||
import { FILENAME } from '../../consts'
|
||||
|
||||
export interface DicMail {
|
||||
// id MAIL_TYPE
|
||||
readonly id: number;
|
||||
// 内容 %d 替换
|
||||
readonly content: string;
|
||||
}
|
||||
|
||||
const str = readJsonFile(FILENAME.DIC_MAIL);
|
||||
let arr = JSON.parse(str);
|
||||
|
||||
export const dicMail = new Map<number, string>();
|
||||
|
||||
arr.forEach(o => {
|
||||
dicMail.set(o.id, o.content);
|
||||
});
|
||||
arr = undefined;
|
||||
@@ -8,7 +8,7 @@ import { DicRandomEffectPool } from './dictionary/DicRandomEffectPool';
|
||||
import { HERO_CE_RATIO, ABI_STAGE } from '../consts';
|
||||
|
||||
import { findIndex } from 'underscore';
|
||||
import { getCurWeekDate, getWeekDate } from './timeUtil';
|
||||
import { getWeekDate } from './timeUtil';
|
||||
const randomName = require("chinese-random-name");
|
||||
const moment = require('moment');
|
||||
|
||||
|
||||
30
shared/resource/jsons/dic_email_army.json
Normal file
30
shared/resource/jsons/dic_email_army.json
Normal file
@@ -0,0 +1,30 @@
|
||||
[
|
||||
{
|
||||
"id": 1,
|
||||
"content": "您对军团%d的申请被拒绝"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"content": "由于被弹劾,您在军团%d的大将军职务已卸任"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"content": "您被任命为军团%d的大将军"
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"content": "您被军团%d踢出"
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"content": "周活跃分成奖励"
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"content": "您被任命为军团%d的管理"
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"content": "您已卸任军团%d的管理"
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user