拍卖:优化

This commit is contained in:
luying
2021-10-27 16:40:24 +08:00
parent b03802136b
commit 0dde8fd09a
9 changed files with 146 additions and 68 deletions
@@ -247,7 +247,6 @@ export class ChatRemote {
public async pushCurrentTime(serverId: number, time: number) {
let roomId = groupRoomId(CHANNEL_PREFIX.WORLD, serverId);
let channel = this.channelService.getChannel(roomId, false);
console.log('*********', roomId, channel);
if (!channel) return { result: false, serverId };
channel.pushMessage('onPushCurrentTime', resResult(STATUS.SUCCESS, { time }));
@@ -21,6 +21,7 @@ import { ActivityGroupTypeModel } from '../../../db/ActivityGroupType';
import { GuildActivityCityModel } from '../../../db/GuildActivityCity';
import { GuildActivityRecordModel } from '../../../db/GuildActivityRec';
import { getTimeFunM } from '../../../pubUtils/timeUtil';
import { sendUngotDividend } from '../../../services/auctionService';
let timer: NodeJS.Timer;
export default function (app: Application) {
return new GmHandler(app);
@@ -385,6 +386,7 @@ export class GmHandler {
let time = <number>getTimeFunM().getAfterDayWithHour(0);
pinus.app.rpc.guild.guildActivityRemote.setCurrentTime.broadcast(time);
await pushCurrentTime(time);
await sendUngotDividend();
}, startActivity * 1000 + endActivity * 1000 + startGuildAuction * 1000 + endGuildAuction * 1000 + startWorldAuction * 1000 + endWorldAuction * 1000 + startNextDay * 1000)
return resResult(STATUS.SUCCESS, {
startActivity: startTimes[0],
@@ -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 { resResult } from "../../../pubUtils/util";
import { auctionStage, calculateDividend, genAuction, sendUngotDividend, startGuildAuction, startWorldAuction, stopAuction, todayGuildBegin, getBasePrice, debugAuctionLots, officialAuctionLots, auctionBidStatus, getMaxPrice, guildBidStatus, getAuction, pushAuctionOver } from "../../../services/auctionService";
import { auctionStage, calculateDividend, genAuction, sendUngotDividend, startGuildAuction, startWorldAuction, stopAuction, todayGuildBegin, getBasePrice, debugAuctionLots, officialAuctionLots, auctionBidStatus, getMaxPrice, guildBidStatus, getAuction, pushAuctionOver, treatSingleLotTime, treatLotsTime } from "../../../services/auctionService";
import { addItems, handleCost } from '../../../services/rewardService';
import { getSimpleRoleInfo } from '../../../services/roleService';
import { getRoleOnlineInfo } from '../../../services/redisService';
@@ -125,7 +125,8 @@ export class AuctionHandler {
const dividend = await DividendModel.updateLot(code, gid, newPrice, incPrice, max);
newDividend = await calculateDividend(dividend);
}
return resResult(STATUS.SUCCESS, { lot: newLot, dividend: newDividend });
let newLotResult = await treatSingleLotTime(newLot);
return resResult(STATUS.SUCCESS, { lot: newLotResult, dividend: newDividend });
} catch (e) {
console.log('offer got err:', e);
res.releaseCallback();
@@ -178,7 +179,8 @@ export class AuctionHandler {
const begin = await todayGuildBegin();
const lots = await LotModel.watchingLotsByBegin(serverId, roleId, begin);
const stage = await auctionStage();
return resResult(STATUS.SUCCESS, { lots: stage === AUCTION_STAGE.END ? [] : lots });
let newLots = await treatLotsTime(lots);
return resResult(STATUS.SUCCESS, { lots: stage === AUCTION_STAGE.END ? [] : newLots });
}
async offerRecs(msg: { count: number }, session: BackendSession) {
+37 -12
View File
@@ -51,18 +51,28 @@ export async function officialAuctionLots(session: FrontendOrBackendSession, beg
lots = await LotModel.findWorldLotsByBegin(serverId, begin);
}
return await treatLotsTime(lots);
}
export async function treatLotsTime(lots: LotType[]) {
let result: LotType[] = []
for(let lot of lots) {
result.push(await treatSingleLotTime(lot));
}
return result;
}
export async function treatSingleLotTime(lot: LotType) {
if(dicParam.SERVER_DEBUG_MODE.CURRENT_TIME == 1) {
let current = await getCurrentTime();
if(Math.floor(current/1000) != nowSeconds()) {
lots = lots.map(cur => {
cur.begin.setHours(20, 20, 0, 0);
cur.end.setHours(22, 0, 0, 0);
return {...cur, begin: cur.begin, end: cur.end}
});
lot.begin.setHours(20, 20, 0, 0);
lot.end.setHours(22, 0, 0, 0);
return {...lot, begin: lot.begin, end: lot.end}
}
}
return lots;
return lot
}
// 拍卖行开始时间 今天20:20
@@ -185,7 +195,7 @@ export async function getBossAuctionEnd() {
* @param {number} serverId
* @param {ItemReward[]} rewards
*/
export async function genAuction(guildCode: string, sourceType: number, sourceCode: string, serverId: number, rewards: { goods: RewardInter, basePrice: number, maxPrice: number}[]) {
export async function genAuction(guildCode: string, sourceType: number, sourceCode: string, serverId: number, rewards: { goods: RewardInter, basePrice: number, maxPrice: number, sort: number}[]) {
let begin = await auctionBegin();
let end = await auctionEnd();
if(sourceType == AUCTION_SOURCE.BOSS) { // 军团boss本
@@ -193,13 +203,13 @@ export async function genAuction(guildCode: string, sourceType: number, sourceCo
end = await getBossAuctionEnd();
}
const guildEnd = await guildAuctionEnd();
const lotsData: LotParam[] = rewards.map(({ goods, basePrice, maxPrice }) => {
const lotsData: LotParam[] = rewards.map(({ goods, basePrice, maxPrice, sort }) => {
const { id, count } = goods;
const code = genCode(LOT_CODE_LEN);
return {
auctionStage: AUCTION_STAGE.DEFAULT, sourceType,
sourceCode, serverId, guildCode, code, gid: id, count, begin, end, status: LOT_STATUS.DEFAULT,
maxPrice, curPrice: basePrice,
maxPrice, curPrice: basePrice, sort
}
});
const lots = await LotModel.createRecs(lotsData);
@@ -283,11 +293,25 @@ export async function startGuildAuction() {
}
}
export async function sendLotsRewardToMlail(lots: LotType[]) {
let lotByRole = new Map<string, RewardInter[]>();
for(let lot of lots) {
if(!lotByRole.has(lot.curBuyer)) {
lotByRole.set(lot.curBuyer, []);
}
lotByRole.get(lot.curBuyer).push({ id: lot.gid, count: lot.count });
}
for(let [roleId, goods ] of lotByRole) {
await sendMailByContent(MAIL_TYPE.AUTION_REWARD, roleId, { goods });
}
}
export async function startWorldAuction() {
try {
console.log('schedule startWorldAuction called:', new Date());
const begin = await todayGuildBegin();
await LotModel.setLotSoldByBegin(begin);
let lots = await LotModel.setLotSoldByBegin(begin); // 正在竞拍的拍品
await sendLotsRewardToMlail(lots);
await LotModel.updateUnSoldLotsStageByBegin(begin, AUCTION_STAGE.WORLD);
await DividendModel.updateDividendsStatus(begin, DIVIDEND_STATUS.END);
@@ -308,7 +332,8 @@ export async function stopAuction() {
try {
console.log('schedule stopAuction called:', new Date());
const begin = await todayGuildBegin();
await LotModel.setLotSoldByBegin(begin);
let lots = await LotModel.setLotSoldByBegin(begin); // 正在竞拍的拍品
await sendLotsRewardToMlail(lots);
await LotModel.updateLotsStageByBegin(begin, AUCTION_STAGE.END);
if(dicParam.SERVER_DEBUG_MODE.CURRENT_TIME == 1) {