拍卖行:添加实时推送

This commit is contained in:
luying
2021-10-27 14:14:18 +08:00
parent 639f917a75
commit e4d4af4409
8 changed files with 110 additions and 21 deletions

View File

@@ -11,6 +11,7 @@ import { GeneralRankParam } from '../../../domain/rank';
import { getAllGuildActivityStatus } from '../../../services/guildActivityService';
import { MailParam } from '../../../domain/roleField/mail';
import { RankFirstType } from '../../../db/RankFirst';
import { LotType } from '../../../db/Lot';
export default function (app: Application) {
new HandlerService(app, {});
@@ -252,4 +253,26 @@ export class ChatRemote {
channel.pushMessage('onPushCurrentTime', resResult(STATUS.SUCCESS, { time }));
return { result: true, serverId };
}
/**
* @description 实时推送军团拍卖出价
* @param guildCode
*/
public async sendGuildAuction(guildCode: string, lot: LotType) {
let roomId = groupRoomId(CHANNEL_PREFIX.GUILD_AUCTION, guildCode);
let channel = this.channelService.getChannel(roomId, false);
if(!channel) return false;
channel.pushMessage('onAuctionOver', resResult(STATUS.SUCCESS, { lot }));
return true;
}
public async sendWorldAuction(serverId: number, lot: LotType) {
let roomId = groupRoomId(CHANNEL_PREFIX.WORLD_AUCTION, serverId);
let channel = this.channelService.getChannel(roomId, false);
if(!channel) return false;
channel.pushMessage('onAuctionOver', resResult(STATUS.SUCCESS, { lot }));
return true;
}
}

View File

@@ -15,7 +15,7 @@ import { SkinModel } from '../../../db/Skin';
import { nowSeconds, getZeroPoint } from '../../../pubUtils/timeUtil';
import { rmRoleFromQueue, roleLeave, getRoleOnlineInfo, roleLogin } from '../../../services/redisService';
import { addRoleToGuildChannel, addRoleToSysChannel, addRoleToWorldChannel, leaveGuildChannel, leaveSysChannel, leaveWorldChannel, recentGuildMsgs, recentPrivateChatInfos, recentSysMsgs, recentWorldMsgs } from '../../../services/chatService';
import { addRoleToGuildChannel, addRoleToSysChannel, addRoleToWorldChannel, leaveGuildAuctionChannel, leaveGuildChannel, leaveSysChannel, leaveWorldAuctionChannel, leaveWorldChannel, recentGuildMsgs, recentPrivateChatInfos, recentSysMsgs, recentWorldMsgs } from '../../../services/chatService';
import { reportOneOnline, savePlayTime } from '../../../services/authenticateService';
import { Rank } from '../../../services/rankService';
import { checkTaskWithRole, } from '../../../services/taskService';
@@ -205,6 +205,8 @@ export class EntryHandler {
await leaveSysChannel(roleId, sid, serverId);
await leaveWorldChannel(roleId, sid, serverId);
await leaveGuildChannel(roleId, sid, guildCode);
await leaveGuildAuctionChannel(roleId, sid, guildCode);
await leaveWorldAuctionChannel(roleId, sid, serverId);
RoleModel.updateRoleInfo(roleId, { quitTime: nowSeconds() });
if(teamCode) { // 如果有寻宝中的队伍,那么等于战败
setComBtlOnUserLeave(roleId, teamCode)

View File

@@ -1,10 +1,10 @@
import { DividendModel } from './../../../db/Dividend';
import { Application, BackendSession, ChannelService, HandlerService, pinus, } from "pinus";
import { AUCTION_STAGE, DEBUG_MAGIC_WORD, STATUS, CURRENCY_BY_TYPE, CURRENCY_TYPE, DATA_NAME, LOT_STATUS, CHANNEL_PREFIX } from "../../../consts";
import { AUCTION_STAGE, DEBUG_MAGIC_WORD, STATUS, CURRENCY_BY_TYPE, CURRENCY_TYPE, DATA_NAME, LOT_STATUS, CHANNEL_PREFIX, MAIL_TYPE } from "../../../consts";
import { LotModel } from "../../../db/Lot";
import { ItemReward } from "../../../domain/dbGeneral";
import { resResult } from "../../../pubUtils/util";
import { auctionStage, calculateDividend, genAuction, sendUngotDividend, startGuildAuction, startWorldAuction, stopAuction, todayGuildBegin, getBasePrice, debugAuctionLots, officialAuctionLots, auctionBidStatus, getMaxPrice, guildBidStatus, getAuction } from "../../../services/auctionService";
import { auctionStage, calculateDividend, genAuction, sendUngotDividend, startGuildAuction, startWorldAuction, stopAuction, todayGuildBegin, getBasePrice, debugAuctionLots, officialAuctionLots, auctionBidStatus, getMaxPrice, guildBidStatus, getAuction, pushAuctionOver } from "../../../services/auctionService";
import { addItems, handleCost } from '../../../services/rewardService';
import { getSimpleRoleInfo } from '../../../services/roleService';
import { getRoleOnlineInfo } from '../../../services/redisService';
@@ -17,7 +17,10 @@ import { UserGuildModel } from '../../../db/UserGuild';
import { UserGuildApplyModel } from '../../../db/UserGuildApply';
import * as dicParam from '../../../pubUtils/dicParam';
import { getAuctionRewardByPoolId } from '../../../pubUtils/data';
import { channelServer, groupRoomId } from '../../../services/chatService';
import { addRoleToGuildAuctionChannel, addRoleToWorldAuctionChannel, channelServer, groupRoomId, leaveGuildAuctionChannel } from '../../../services/chatService';
import { RewardInter } from '../../../pubUtils/interface';
import { sendMailByContent } from '../../../services/mailService';
import { getGoldObject } from '../../../pubUtils/itemUtils';
export default function (app: Application) {
new HandlerService(app, {});
@@ -34,16 +37,37 @@ export class AuctionHandler {
const { magicWord } = msg;
const guildCode = session.get('guildCode');
// if (!guildCode) return resResult(STATUS.GUILD_NOT_FOUND);
const serverId = session.get('serverId');
const roleId = session.get('roleId');
const sid = session.get('sid');
if(guildCode) {
await addRoleToGuildAuctionChannel(roleId, sid, guildCode);
}
await addRoleToWorldAuctionChannel(roleId, sid, serverId);
let result = await getAuction(guildCode, session, magicWord);
return resResult(STATUS.SUCCESS, result);
}
async leaveAuction(msg: {}, session: BackendSession) {
const guildCode = session.get('guildCode');
const serverId = session.get('serverId');
const roleId = session.get('roleId');
const sid = session.get('sid');
if(guildCode) {
await leaveGuildAuctionChannel(roleId, sid, guildCode);
}
await leaveGuildAuctionChannel(roleId, sid, serverId);
return resResult(STATUS.SUCCESS);
}
async offer(msg: { code: string, max: boolean }, session: BackendSession) {
const { code, max } = msg;
const roleId = session.get('roleId');
const roleName = session.get('roleName');
const sid = session.get('sid');
const serverId = session.get('serverId');
const guildCode = session.get('guildCode');
@@ -83,20 +107,16 @@ export class AuctionHandler {
}
if (curBuyer) {
const { roleName: buyerName } = await getSimpleRoleInfo(curBuyer);
const { isOnline, sid: buyerSid } = await getRoleOnlineInfo(curBuyer);
await addItems(curBuyer, buyerName, buyerSid, [{ id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.GOLD), count: curPrice }]);
if (isOnline) {
this.channelService.pushMessageByUids('onAuctionOver', resResult(STATUS.SUCCESS, { code }), [{ uid: curBuyer, sid: buyerSid }]);
}
await sendMailByContent(MAIL_TYPE.AUCTION_OVER, curBuyer, { goods: [getGoldObject(curPrice)] });
}
if (maxFlag) {
newPrice = maxPrice;
await addItems(roleId, roleName, sid, [{ id: gid, count }]);
await sendMailByContent(MAIL_TYPE.AUTION_REWARD, roleId, { goods: [{ id: gid, count }] });
}
bidRoles.push({ roleId, price: newPrice, time: new Date() });
const newLot = await LotModel.updateLot({ code, curBuyer: roleId, curPrice: newPrice, bidRoles, status: max ? LOT_STATUS.MAX : (maxFlag ? LOT_STATUS.SOLD : LOT_STATUS.ING), watchingRoles: Array.from(new Set([...watchingRoles, roleId])) });
await pushAuctionOver(newLot); // 推送竞价超过标志
res.releaseCallback();
const incPrice = newPrice - (curBuyer ? curPrice : 0);

View File

@@ -12,7 +12,7 @@ import { participants } from './guildActivityService';
import { Member } from '../domain/battleField/guildActivity';
import * as dicParam from '../pubUtils/dicParam';
import { RewardInter } from '../pubUtils/interface';
import { pushCurrentTime } from './chatService';
import { getGuildAuctionChannelSid, getWorldAuctionChannelSid, pushCurrentTime } from './chatService';
// ! 获取底价,假数据
export function getBasePrice(gid: number, count: number) {
@@ -385,7 +385,7 @@ export async function sendUngotDividend(debug = false) {
for (let [roleId, count] of rewards) {
// TODO: 邮件类型修改
await sendMailByContent(MAIL_TYPE.GUILD_BOSS_REWARD, roleId, {
await sendMailByContent(MAIL_TYPE.GUILD_DIVIDEND, roleId, {
params: [JSON.stringify(count)],
goods: [{ id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.GOLD), count }]
});
@@ -414,4 +414,14 @@ export async function getAuction(guildCode: string, session: FrontendOrBackendSe
dividends = await DividendModel.findGuildDividendsByBegin(guildCode, begin);
}
return { lots, dividends };
}
export async function pushAuctionOver(lot: LotType) {
if(lot.auctionStage == AUCTION_STAGE.GUILD) {
let chatSid = await getGuildAuctionChannelSid(lot.guildCode);
pinus.app.rpc.chat.chatRemote.sendGuildAuction.toServer(chatSid, lot.guildCode, lot);
} else if (lot.auctionStage == AUCTION_STAGE.WORLD) {
let chatSid = await getWorldAuctionChannelSid(lot.serverId);
pinus.app.rpc.chat.chatRemote.sendWorldAuction.toServer(chatSid, lot.serverId, lot);
}
}

View File

@@ -46,6 +46,16 @@ export async function addRoleToCityChannel(roleId: string, sid: string, cityId:
await addRoleToChannel(roomId, roleId, sid);
}
export async function addRoleToGuildAuctionChannel(roleId: string, sid: string, guildCode: string) {
const roomId = groupRoomId(CHANNEL_PREFIX.GUILD_AUCTION, guildCode);
await addRoleToChannel(roomId, roleId, sid);
}
export async function addRoleToWorldAuctionChannel(roleId: string, sid: string, serverId: number) {
const roomId = groupRoomId(CHANNEL_PREFIX.GUILD_AUCTION, serverId);
await addRoleToChannel(roomId, roleId, sid);
}
async function leaveChannel(roomId: string, roleId: string, sid: string) {
const channelSid = await channelServer(roomId);
await pinus.app.rpc.chat.chatRemote.leaveChannel.toServer(channelSid, roomId, roleId, sid);
@@ -66,6 +76,15 @@ export async function leaveCityChannel(roleId: string, sid: string, cityId: numb
await leaveChannel(roomId, roleId, sid);
}
export async function leaveGuildAuctionChannel(roleId: string, sid: string, guildCode: string) {
const roomId = groupRoomId(CHANNEL_PREFIX.CITY, guildCode);
await leaveChannel(roomId, roleId, sid);
}
export async function leaveWorldAuctionChannel(roleId: string, sid: string, serverId: number) {
const roomId = groupRoomId(CHANNEL_PREFIX.CITY, serverId);
await leaveChannel(roomId, roleId, sid);
}
export async function leaveGuildChannel(roleId: string, sid: string, guildCode: string) {
if (!guildCode) return;
@@ -89,4 +108,16 @@ export async function getCityChannelSid(cityId: number) {
const roomId = groupRoomId(CHANNEL_PREFIX.CITY, cityId);
const channelSid = await channelServer(roomId);
return channelSid;
}
export async function getGuildAuctionChannelSid(guildCpde: string) {
const roomId = groupRoomId(CHANNEL_PREFIX.GUILD_AUCTION, guildCpde);
const channelSid = await channelServer(roomId);
return channelSid;
}
export async function getWorldAuctionChannelSid(serverId: number) {
const roomId = groupRoomId(CHANNEL_PREFIX.CITY, serverId);
const channelSid = await channelServer(roomId);
return channelSid;
}

View File

@@ -19,6 +19,8 @@ export const CHANNEL_PREFIX = {
GUILD: 'guild',
TEAM: 'com_btl_team',
CITY: 'city', // 军团活动诸侯混战按城池分channel
GUILD_AUCTION: 'g_auction', // 军团拍卖
WORLD_AUCTION: 'w_auction', // 军团拍卖
}
export const CHANNEL_TYPE = new Map([

View File

@@ -33,11 +33,12 @@ export enum MAIL_TYPE {
PVP_RESULT = 12,
PVP_RANK_REWARD = 13,
GUILD_ACTIVITY_REWARD = 14,
GUILD_DIVIDEND = 15, // 拍卖行分红
MONTHLY_REWARD = 16, // 月卡奖品
AUTION_REWARD = 17, // 拍卖行忘领取奖励
EQUIP_OVER = 18, // 拍卖行忘领取奖励
AUCTION_OVER = 15, // 拍卖出价被超过
AUTION_REWARD = 16, // 成功拍取
GUILD_DIVIDEND = 17, // 忘记领取分红
EQUIP_OVER = 18, // 装备超数量
TOWER_TASK_REWARD = 19, // 镇念塔派遣过期奖励
MONTHLY_REWARD = 20, // 月卡奖品
};
export const SEND_NAME = '系统';

View File

@@ -130,12 +130,12 @@ export default class UserGuild extends BaseModel {
public static async createUserGuild(guildCode: string, role: RoleType, isLeader: boolean) {
const lastGuild = await UserGuildModel.findMyLastGuild(role.roleId);
let { receiveBoxs = [], donateCnt = 0, receivedActive = [], encourageCnt = 0, bossChallengeCnt = 0, receivedWishPool = [] } = lastGuild||{};
let { receiveBoxs = [], donateCnt = 0, receivedActive = [], encourageCnt = 0, bossChallengeCnt = 0, receivedWishPool = [], refTimeDaily, refBossTime } = lastGuild||{};
const doc = new UserGuildModel();
let job = isLeader? GUILD_JOB.DAJIANGJUN: GUILD_JOB.SHIBING;
let auth = isLeader? GUILD_AUTH.LEADER: GUILD_AUTH.MEMBER;
const update = Object.assign(doc.toJSON(), { guildCode, roleId: role.roleId, role: role._id, job, auth, receiveBoxs, donateCnt, receivedActive, encourageCnt, bossChallengeCnt, receivedWishPool });
const update = Object.assign(doc.toJSON(), { guildCode, roleId: role.roleId, role: role._id, job, auth, receiveBoxs, donateCnt, receivedActive, encourageCnt, bossChallengeCnt, receivedWishPool, refTimeDaily, refBossTime });
delete update._id;
const result: UserGuildType = await UserGuildModel.findOneAndUpdate({ roleId: role.roleId, guildCode, status: USER_GUILD_STATUS.ON }, update, { upsert: true, new: true })
.select('activeDaily activeRecord activeWeekly activeUpdateTime job auth receivedActive guildCode')