连接推送
This commit is contained in:
@@ -8,7 +8,7 @@ import { getCurTask, getPvpTask } from './taskService';
|
||||
import { RoleType } from '../db/Role';
|
||||
import { Application, FrontendOrBackendSession, pinus, RpcClient } from 'pinus';
|
||||
import { resResult } from '../pubUtils/util';
|
||||
import { STATUS, PUSH_BATCH, PUSH_INTERVAL, CONSUME_TYPE } from '../consts';
|
||||
import { STATUS, PUSH_BATCH, PUSH_INTERVAL, CONSUME_TYPE, HERO_SELECT } from '../consts';
|
||||
import { getAllShopList } from './shopService';
|
||||
import { getGeneralRank, getRankFirstReward } from './rankService';
|
||||
import { getFriendList, getApplyList } from './friendService';
|
||||
@@ -33,10 +33,47 @@ import { GuildType } from '../db/Guild';
|
||||
import UserGuild, { UserGuildType } from '../db/UserGuild';
|
||||
import { setPreDayActiveData, getAllGuildActivityStatus } from './guildActivity/guildActivityService';
|
||||
import { getAllOnlineRoles } from './redisService';
|
||||
import Item from '../db/Item';
|
||||
import Item, { ItemModel } from '../db/Item';
|
||||
import { PvpDefenseModel } from '../db/PvpDefense';
|
||||
import { getDonation } from './donateService';
|
||||
import { refChallengeCnt } from './pvpService';
|
||||
import { HeroModel } from '../db/Hero';
|
||||
import { JewelModel } from '../db/Jewel';
|
||||
import { SkinModel } from '../db/Skin';
|
||||
import { getAp } from './actionPointService';
|
||||
|
||||
/**
|
||||
* init: 初始的时候是否推送 true-推 false-不推
|
||||
* refresh: 凌晨5点刷新时是否推送 true-推 false-不推
|
||||
* guild: 是否一定有了军团才要推送 true-必须要 false-不用
|
||||
*/
|
||||
const modules = [
|
||||
{ id: 1, type: 'role', init: true, refresh: true, guild: false },
|
||||
{ id: 2, type: 'battle', init: true, refresh: false, guild: false },
|
||||
{ id: 3, type: 'chapter', init: true, refresh: false, guild: false },
|
||||
{ id: 4, type: 'rank', init: false, refresh: false, guild: false },
|
||||
{ id: 5, type: 'mail', init: false, refresh: false, guild: false },
|
||||
{ id: 6, type: 'friend', init: false, refresh: true, guild: false },
|
||||
{ id: 7, type: 'daily', init: false, refresh: true, guild: false },
|
||||
{ id: 8, type: 'expedition', init: false, refresh: true, guild: false },
|
||||
{ id: 9, type: 'tower', init: false, refresh: true, guild: false },
|
||||
{ id: 10, type: 'comBattle', init: false, refresh: true, guild: false },
|
||||
{ id: 11, type: 'dungeon', init: false, refresh: true, guild: false },
|
||||
{ id: 12, type: 'pvp', init: false, refresh: true, guild: false },
|
||||
{ id: 13, type: 'gacha', init: false, refresh: true, guild: false },
|
||||
{ id: 14, type: 'school', init: false, refresh: false, guild: false },
|
||||
{ id: 15, type: 'task', init: false, refresh: true, guild: false },
|
||||
{ id: 16, type: 'chat', init: false, refresh: false, guild: false },
|
||||
{ id: 17, type: 'event', init: false, refresh: true, guild: false },
|
||||
{ id: 18, type: 'guild', init: false, refresh: true, guild: false },
|
||||
{ id: 19, type: 'auction', init: false, refresh: false, guild: true },
|
||||
{ id: 20, type: 'train', init: false, refresh: false, guild: true },
|
||||
{ id: 21, type: 'boss', init: false, refresh: true, guild: true },
|
||||
{ id: 22, type: 'wishPool', init: false, refresh: true, guild: true },
|
||||
{ id: 23, type: 'guildActivity', init: false, refresh: true, guild: true },
|
||||
{ id: 24, type: 'donate', init: false, refresh: true, guild: true },
|
||||
{ id: 25, type: 'shop', init: false, refresh: true, guild: false },
|
||||
]
|
||||
|
||||
export async function pushData(hasInit: boolean, role: RoleType, session: FrontendOrBackendSession, pushType: 'entry' | 'refresh' = 'entry') {
|
||||
try {
|
||||
@@ -46,29 +83,17 @@ export async function pushData(hasInit: boolean, role: RoleType, session: Fronte
|
||||
pushEntryStart(roleId, sid);
|
||||
// 军团
|
||||
const guildData = await getGuildEntryData(role, sid, session);
|
||||
let modules = [];
|
||||
if(!hasInit) {
|
||||
modules.push('lv', 'battle');
|
||||
} else {
|
||||
modules.push('lv', 'battle', 'rank', 'mail', 'friend', 'daily', 'expedition', 'tower', 'comBattle', 'dungeon', 'pvp', 'gacha', 'school', 'task', 'chat', 'event', 'guild');
|
||||
if (guildData.hasGuild) {
|
||||
modules.push('auction', 'train', 'boss', 'wishPool', 'guildActivity', 'donate');
|
||||
for(let { type, init, refresh, guild } of modules) {
|
||||
if(!hasInit && !init) continue;
|
||||
if(pushType == 'refresh' && !refresh) continue;
|
||||
if(guildData.hasGuild && !guild) continue;
|
||||
|
||||
let data = await getModuleData(type, { role, session }, guildData);
|
||||
if (data) {
|
||||
pushEntryData(type, roleId, sid, data);
|
||||
}
|
||||
modules.push('shop')
|
||||
}
|
||||
let notIncludeModule: string[] = [];
|
||||
if (pushType == 'refresh') { // 每天5点刷新的时候不推送
|
||||
notIncludeModule = ['rank', 'mail', 'school', 'auction', 'train', 'chat', 'battle'];
|
||||
}
|
||||
|
||||
for (let type of modules) {
|
||||
if (notIncludeModule.indexOf(type) == -1) {
|
||||
let data = await getModuleData(type, { role, session }, guildData);
|
||||
if (data) {
|
||||
pushEntryData(type, roleId, sid, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
pushEntryEnd(roleId, sid);
|
||||
} catch (e) {
|
||||
console.error(e.stack);
|
||||
@@ -80,8 +105,24 @@ async function getModuleData(type: string, data: { role: RoleType, session: Fron
|
||||
const { roleId, serverId, roleName, guildCode } = role;
|
||||
let { hasGuild, guild, userGuild, guildResult } = guildData;
|
||||
switch (type) {
|
||||
case 'lv':
|
||||
return role.lv;
|
||||
case 'role':
|
||||
let heros = await HeroModel.findByRole(role.roleId, [], HERO_SELECT.ENTRY, true);
|
||||
let jewels = await JewelModel.findbyRole(role.roleId);
|
||||
let items = await ItemModel.findbyRole(role.roleId);
|
||||
let skins = await SkinModel.findbyRole(role.roleId);
|
||||
|
||||
role['heros'] = heros;
|
||||
role['jewels'] = jewels;
|
||||
role['consumeGoods'] = items;
|
||||
role['skins'] = skins;
|
||||
let apJson = await getAp(role.roleId, '', role.lv);
|
||||
role['apJson'] = apJson;
|
||||
|
||||
if (!role.showLineup) role.showLineup = role.topLineup.map(cur => cur.hid);
|
||||
role.heads = role.heads.filter(cur => cur.status);
|
||||
role.frames = role.frames.filter(cur => cur.status);
|
||||
role.spines = role.spines.filter(cur => cur.status);
|
||||
return role;
|
||||
case 'shop': // 商店
|
||||
return await getAllShopList(roleId);
|
||||
case 'rank': // 排名
|
||||
@@ -125,6 +166,7 @@ async function getModuleData(type: string, data: { role: RoleType, session: Fron
|
||||
let trainBoxRewards = await getTrainBoxRewardsResult(guildCode);
|
||||
return { trainInstance, trainBoxRewards }
|
||||
}
|
||||
break;
|
||||
case 'boss':
|
||||
if (hasGuild) {
|
||||
return await getBossInstanceInfo(userGuild, guild);
|
||||
@@ -138,6 +180,7 @@ async function getModuleData(type: string, data: { role: RoleType, session: Fron
|
||||
let { donateFund, reports, donationLv } = await getDonation(code, guild, serverId);
|
||||
return { receiveBoxs, donateFund, reports, donateCnt: donateCnt || 0, donationLv };
|
||||
}
|
||||
break;
|
||||
case 'task':
|
||||
let tasks = await getCurTask(role.roleId, session);
|
||||
let pvpTask = await getPvpTask(role.roleId);
|
||||
|
||||
Reference in New Issue
Block a user