拍卖行:添加实时推送
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user