获得试炼奖励
This commit is contained in:
@@ -79,11 +79,10 @@ export class GuildTrainHandler {
|
||||
const { guildCode: code } = userGuild;
|
||||
let guildTrains = await GuildTrainModel.findGuildTrain(code);
|
||||
let resTrainBoxs = [];
|
||||
let { trainId: curTrainId } = await GuildModel.findGuild(code, serverId, 'trainId');
|
||||
guildTrains.forEach(({trainInstances, trainId}) =>{
|
||||
let { trainInstances: instances } = getArmyTrainJuDian(trainId);
|
||||
let flag = false;
|
||||
let boxRewards = []
|
||||
let boxRewards = [];
|
||||
trainInstances.map(({hid, progress, endTime, trainBoxs})=>{
|
||||
let instance = findWhere(instances, { hid });
|
||||
let isComplete = false;
|
||||
@@ -93,11 +92,11 @@ export class GuildTrainHandler {
|
||||
flag = true;
|
||||
boxRewards.push({hid, recordBoxs: trainBoxs, trainId, endTime, isComplete});
|
||||
});
|
||||
if (flag || trainId == curTrainId) {
|
||||
resTrainBoxs.push(...boxRewards);
|
||||
if (flag) {
|
||||
resTrainBoxs.push({ trainId, boxRewards });
|
||||
}
|
||||
})
|
||||
return resResult(STATUS.SUCCESS, {trainBoxs: resTrainBoxs});
|
||||
return resResult(STATUS.SUCCESS, {trainBoxRewards: resTrainBoxs});
|
||||
}
|
||||
|
||||
async trainBattleStart(msg: { hid: number, trainId: number, difficulty: number }, session: BackendSession) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import { resResult } from "../pubUtils/util";
|
||||
import { STATUS, FUNC_OPT_TYPE } from "../consts";
|
||||
import { eventOnPlayerLvUp } from '../services/playerEventService';
|
||||
import { checkesetTrain } from '../services/guildTrainService';
|
||||
import { getUserGuildWithRefActive } from '../services/guildService';
|
||||
// 开启功能
|
||||
export async function switchOnFunc(roleId: string, type: number, param: number, session: (BackendSession|FrontendSession)) {
|
||||
|
||||
@@ -35,4 +36,5 @@ export async function switchOnFunc(roleId: string, type: number, param: number,
|
||||
export async function chackFunOpenWhenLogin(role: any, session: BackendSession|FrontendSession) {
|
||||
await switchOnFunc(role.roleId, FUNC_OPT_TYPE.LEVEL_UP, role.lv, session);
|
||||
await checkesetTrain(role.roleId, role.serverId);
|
||||
await getUserGuildWithRefActive(role.roleId, '', true)
|
||||
}
|
||||
@@ -9,6 +9,8 @@ import { STATUS } from '../consts/statusCode';
|
||||
import { deepCopy, resResult } from '../pubUtils/util';
|
||||
import { BattleRecordModel } from '../db/BattleRecord';
|
||||
import { getArmyBossRank } from '../pubUtils/data';
|
||||
import { getMailContent } from '../services/mailService';
|
||||
import { pushMail } from '../pubUtils/interface';
|
||||
/**
|
||||
*
|
||||
* @param bossInstance
|
||||
@@ -119,24 +121,17 @@ export async function bossResult(code: string, serverId: number, dataName: strin
|
||||
return b.score - a.score + a.time - b.time;
|
||||
});
|
||||
let mails = new Array<MailType>();
|
||||
let pushMessage = [];
|
||||
let pushMessage = new Array<pushMail>();
|
||||
recordRanks.forEach(async function({roleId, score}, index){
|
||||
let rankLv = index + 1;
|
||||
const doc = new MailModel();
|
||||
let goods = getArmyBossRankReward(rankLv);
|
||||
if (!goods || !goods.length)
|
||||
return;
|
||||
const mail = Object.assign(doc.toJSON(), {roleId, goods, sendName: '系统', mailId: 1, sendTime: nowSeconds(), content:'恭喜玩家获得演武台第' + rankLv +'名 奖励如下:'});
|
||||
mails.push(mail);
|
||||
let key = 'login_roleId_' + roleId;
|
||||
let sid = await getRedis(key);
|
||||
if (!!sid) {
|
||||
pushMessage.push({route: 'onMailsAdd', data:[mail], uids: [{uid:roleId, sid}]});
|
||||
}
|
||||
await getMailContent(roleId, 1, [JSON.stringify(rankLv)], goods, mails, pushMessage);
|
||||
});
|
||||
await MailModel.addMails(mails);
|
||||
pushMessage.forEach(({route, data, uids })=>{
|
||||
pinus.app.channelService.pushMessageByUids(route, resResult(STATUS.SUCCESS, {mails:data}), uids);
|
||||
pinus.app.channelService.pushMessageByUids(route, resResult(STATUS.SUCCESS, { mails:data }), uids);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,9 @@ import { setRank, getMyRank, initSingleRank } from "./redisService";
|
||||
import { GuildRankParam, GuildLeader } from "../domain/rank";
|
||||
import { lockData, isLocked } from '../services/redLockService';
|
||||
import { ErrLogModel } from '../db/ErrLog';
|
||||
|
||||
import { MailType, MailModel } from '../db/Mail';
|
||||
import { pushMail } from '../pubUtils/interface';
|
||||
import { getMailContent } from '../services/mailService';
|
||||
/**
|
||||
* @description 检查该玩家是否有权限做操作
|
||||
* @param func 操作id
|
||||
@@ -165,17 +167,29 @@ export async function addActive(roleId: string, serverId: number, id: number, ty
|
||||
* @param roleId 用户id
|
||||
* @param select 筛选字段
|
||||
*/
|
||||
export async function getUserGuildWithRefActive(roleId: string, select: string) {
|
||||
let userGuild = await UserGuildModel.getMyGuild(roleId, select? select + ' +refTimeDaily': '+refTimeDaily');
|
||||
export async function getUserGuildWithRefActive(roleId: string, select: string, notPush?: boolean) {
|
||||
let userGuild = await UserGuildModel.getMyGuild(roleId, select? select + ' wishGoods +refTimeDaily': '+refTimeDaily');
|
||||
console.log(JSON.stringify(userGuild))
|
||||
if(!userGuild) return false;
|
||||
let { receivedActive, refTimeDaily, activeDaily, activeRecord } = userGuild;
|
||||
let { receivedActive, refTimeDaily, activeDaily, activeRecord, wishGoods } = userGuild;
|
||||
|
||||
const now = new Date();
|
||||
let isRefDaily = shouldRefresh(refTimeDaily, now, 0);
|
||||
if(isRefDaily) {
|
||||
receivedActive = []; refTimeDaily = now; activeDaily = 0; activeRecord = [];
|
||||
let wishGoods = [], receiveBoxs = [], wishDntCnt = 0, donateCnt = 0;
|
||||
let goods = wishGoods.map(({ goodId, drawCnt})=>{
|
||||
return {id: goodId, count: drawCnt};
|
||||
});
|
||||
let mails = new Array<MailType>();
|
||||
let pushMessage = new Array<pushMail>();
|
||||
await getMailContent(roleId, 1, [], goods, mails, pushMessage);
|
||||
await MailModel.addMails(mails);
|
||||
if (!notPush) {
|
||||
pushMessage.forEach(({route, data, uids })=>{
|
||||
pinus.app.channelService.pushMessageByUids(route, resResult(STATUS.SUCCESS, { mails:data }), uids);
|
||||
});
|
||||
}
|
||||
receivedActive = []; refTimeDaily = now; activeDaily = 0; activeRecord = []; wishGoods = [];
|
||||
let receiveBoxs = [], wishDntCnt = 0, donateCnt = 0;
|
||||
userGuild = await UserGuildModel.updateInfo(roleId, { receivedActive, refTimeDaily, activeDaily, activeRecord, wishGoods, receiveBoxs, wishDntCnt, donateCnt }, {}, select);
|
||||
if(!userGuild) return false;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import { RewardInter } from "../pubUtils/interface";
|
||||
import { MailModel } from "../db/Mail";
|
||||
import { RewardInter, pushMail } from "../pubUtils/interface";
|
||||
import { MailModel, MailType } from "../db/Mail";
|
||||
import { getRedis } from "./redisService";
|
||||
import { pinus } from "pinus";
|
||||
import { gameData } from "../pubUtils/data";
|
||||
import { nowSeconds } from '../pubUtils/timeUtil';
|
||||
import { STATUS } from '../consts/statusCode';
|
||||
import { resResult } from '../pubUtils/util';
|
||||
|
||||
export async function sendMail(operate: number, toRoleId: string, sendName: string = '系统', params: string[] = [], goods: RewardInter[] = []) {
|
||||
let content = getContent( operate, params);
|
||||
@@ -11,7 +14,7 @@ export async function sendMail(operate: number, toRoleId: string, sendName: stri
|
||||
let key = 'login_roleId_' + toRoleId;
|
||||
let sid = await getRedis(key);
|
||||
if (!!sid) {
|
||||
pinus.app.rpc.connector.connectorRemote.pushMessage.toServer(sid, toRoleId, 'onMailsAdd', [mail]);
|
||||
pinus.app.channelService.pushMessageByUids('onMailsAdd', resResult(STATUS.SUCCESS, { mails:[mail] }), [{uid: toRoleId, sid}]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,4 +24,16 @@ export function getContent(operate: number, params: string[]) {
|
||||
content = content.replace(/%d/, p);
|
||||
}
|
||||
return content
|
||||
}
|
||||
}
|
||||
export async function getMailContent(roleId: string, operate: number, params: string[], goods:RewardInter[], mails:MailType[], pushMessage:pushMail[], sendName: string = '系统') {
|
||||
const doc = new MailModel();
|
||||
let content = getContent( operate, params);
|
||||
|
||||
const mail = Object.assign(doc.toJSON(), {roleId, goods, sendName, mailId: 1, sendTime: nowSeconds(), content});
|
||||
mails.push(mail);
|
||||
let key = 'login_roleId_' + roleId;
|
||||
let sid = await getRedis(key);
|
||||
if (!!sid) {
|
||||
pushMessage.push({route: 'onMailsAdd', data:[mail], uids: [{uid:roleId, sid}]});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import PvpDefenseType,{ PvpDefenseModel } from '../db/PvpDefense';
|
||||
import { PVP } from '../pubUtils/dicParam';
|
||||
import { nowSeconds, getTodayZeroPoint } from '../pubUtils/timeUtil';
|
||||
import { getPvpGkWarIds, getPvpRankRewards, getPvpHeroRewards, getResultMaxRank } from '../pubUtils/data';
|
||||
import { deepCopy, getRandomArr } from '../pubUtils/util';
|
||||
import { deepCopy, getRandomArr, resResult } from '../pubUtils/util';
|
||||
import { getLvByScore } from './pvpService';
|
||||
import { getMyRank, setRank, getRedis, resetPvpRanks } from './redisService';
|
||||
import { REDIS_KEY } from '../consts';
|
||||
@@ -16,6 +16,7 @@ import { pinus } from 'pinus';
|
||||
import { indexOf } from 'underscore';
|
||||
import { PvpSeasonResultModel } from '../db/PvpSeasonResult';
|
||||
import { settleGuildWeekly } from './guildService';
|
||||
import { STATUS } from '../consts/statusCode';
|
||||
const PER_SECOND = 1 * 1000;
|
||||
const PER_DAY = 24 * 60 * 60;
|
||||
const SETTLE_DIFF = 29 * 60;
|
||||
@@ -167,7 +168,7 @@ export async function setPvpDefResult(pvpDefense: PvpDefenseType, seasonNum: num
|
||||
let key = 'login_roleId_' + roleId;
|
||||
let sid = await getRedis(key);
|
||||
if (!!sid) {
|
||||
pinus.app.rpc.connector.connectorRemote.pushMessage.toServer(sid, pvpDefense.roleId, 'onMailsAdd', [mail]);
|
||||
pinus.app.channelService.pushMessageByUids('onMailsAdd', resResult(STATUS.SUCCESS, { mails:[mail] }), [{uid: roleId, sid}]);
|
||||
}
|
||||
return pvpDefense;
|
||||
}
|
||||
|
||||
@@ -96,3 +96,14 @@ export interface pvpEndParamInter {
|
||||
heal: number;
|
||||
underDamage: number;
|
||||
}
|
||||
|
||||
export interface Uid {
|
||||
uid: string;
|
||||
sid: string;
|
||||
}
|
||||
|
||||
export interface pushMail {
|
||||
route: string;
|
||||
data:any[];
|
||||
uids:Uid[];
|
||||
}
|
||||
Reference in New Issue
Block a user