拍卖:优化

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
+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) {