拍卖行:检查拍卖行阶段

This commit is contained in:
luying
2022-05-13 22:27:19 +08:00
parent 3886533599
commit 38b23de279
4 changed files with 29 additions and 9 deletions

View File

@@ -4,7 +4,7 @@ import { AUCTION_STAGE, DEBUG_MAGIC_WORD, STATUS, CURRENCY_BY_TYPE, CURRENCY_TYP
import { LotModel } from "../../../db/Lot";
import { ItemReward } from "../../../domain/dbGeneral";
import { genCode, resResult } from "../../../pubUtils/util";
import { auctionStage, calculateDividend, genAuction, sendUngotDividend, startGuildAuction, startWorldAuction, stopAuction, todayGuildBegin, getBasePrice, debugAuctionLots, officialAuctionLots, auctionBidStatus, getMaxPrice, guildBidStatus, getAuction, pushAuctionOver, treatSingleLotTime, treatLotsTime, pushAuctionUpdate } from "../../../services/auctionService";
import { auctionStage, calculateDividend, genAuction, sendUngotDividend, startGuildAuction, startWorldAuction, stopAuction, todayGuildBegin, getBasePrice, debugAuctionLots, officialAuctionLots, auctionBidStatus, getMaxPrice, guildBidStatus, getAuction, pushAuctionOver, treatSingleLotTime, treatLotsTime, pushAuctionUpdate, checkAuctionStage } from "../../../services/auctionService";
import { addItems, getGoldObject, handleCost } from '../../../services/role/rewardService';
import { getSimpleRoleInfo } from '../../../services/roleService';
import { getRoleOnlineInfo } from '../../../services/redisService';
@@ -48,17 +48,17 @@ export class AuctionHandler {
}
async offer(msg: { code: string, max: boolean }, session: BackendSession) {
const { code, max } = msg;
async offer(msg: { code: string, max: boolean, auctionStage: number }, session: BackendSession) {
const { code, max, auctionStage } = msg;
const roleId = session.get('roleId');
const sid = session.get('sid');
const serverId = session.get('serverId');
const guildCode = session.get('guildCode');
const ip = session.get('ip');
let res: any = await lockData(serverId, DATA_NAME.AUCTION_LOT, code);// 加锁
let res: any = await lockData(serverId, DATA_NAME.AUCTION_LOT, '');// 加锁
try {
if (!res) {
if (!!res.err) {
return resResult(STATUS.REDLOCK_ERR);
}
@@ -68,11 +68,16 @@ export class AuctionHandler {
return resResult(STATUS.GUILD_LOT_NOT_FOUND);
}
if (lot.auctionStage === AUCTION_STAGE.GUILD && lot.guildCode !== guildCode) {
if (auctionStage === AUCTION_STAGE.GUILD && lot.guildCode !== guildCode) {
res.releaseCallback();
return resResult(STATUS.AUCTION_GUILD_MEMBER_ONLY);
}
if(!checkAuctionStage(auctionStage)) {
res.releaseCallback();
return resResult(STATUS.AUCITON_STAGE_ERR);
}
let { curBuyer, curPrice, prePrice, maxPrice, gid, count, bidRoles, watchingRoles } = lot;
if (curBuyer === roleId && !max) {
res.releaseCallback();
@@ -109,13 +114,13 @@ export class AuctionHandler {
reportTAEvent(roleId, TA_EVENT.AUCTION_ITEM_GET, { item_name: dicGoods?.name, item_count: count, deel_price: newPrice }, ip);
}
bidRoles.push({ roleId, price: newPrice, time: new Date() });
const newLot = await LotModel.updateLot({ code, curBuyer: roleId, curPrice: newPrice, prePrice: curPrice, bidRoles, status: max ? LOT_STATUS.MAX : (maxFlag ? LOT_STATUS.SOLD : LOT_STATUS.ING), watchingRoles: Array.from(new Set([...watchingRoles, roleId])) });
const newLot = await LotModel.updateLot({ code, curBuyer: roleId, curPrice: newPrice, auctionStage, prePrice: curPrice, 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 = curPrice - prePrice > 0? prePrice: 0;
let newDividend = null;
if (lot.auctionStage === AUCTION_STAGE.GUILD) {
if (auctionStage === AUCTION_STAGE.GUILD) {
const dividend = await DividendModel.updateLot(code, gid, curPrice, incPrice, max);
newDividend = await calculateDividend(dividend);
}