拍卖行:拍品起止时间

This commit is contained in:
liangtongchuan
2021-03-17 15:43:53 +08:00
parent 0dc4f18d2d
commit a76c0fa7fe
4 changed files with 66 additions and 7 deletions

View File

@@ -1,7 +1,8 @@
import { LOT_CODE_LEN, AUCTION_STAGE, AUCTION_SOURCE } from './../consts';
import { LOT_CODE_LEN, AUCTION_STAGE, AUCTION_SOURCE, AUCTION_TIME } from './../consts';
import { ItemReward } from "../domain/dbGeneral";
import { genCode } from '../pubUtils/util';
import { LotModel, LotParam } from '../db/Lot';
import { getNextTime } from '../pubUtils/timeUtil';
/**
* @description 生成拍卖数据
@@ -13,21 +14,21 @@ import { LotModel, LotParam } from '../db/Lot';
* @param {ItemReward[]} rewards
*/
export async function genAuction(guildCode: string, sourceType: number, sourceCode: string, serverId: number, rewards: ItemReward[]) {
const curTime = new Date();
const begin = getNextTime(new Date(), AUCTION_TIME.GUILD_BEGIN_HOUR, AUCTION_TIME.GUILD_BEGIN_MIN);
const end = getNextTime(new Date(), AUCTION_TIME.WORLD_END_HOUR, AUCTION_TIME.WORLD_END_MIN);
const lots: LotParam[] = rewards.map(reward => {
const { id, count } = reward;
const code = genCode(LOT_CODE_LEN);
return {
auctionStage: AUCTION_STAGE.DEFAULT, sourceType,
sourceCode, serverId, guildCode, code, gid: id, count,
maxPrice: 100, begin: curTime, end: curTime, curPrice: 10, // ! 此行为临时数据
sourceCode, serverId, guildCode, code, gid: id, count, begin, end,
maxPrice: 100, curPrice: 10, // ! 此行为临时数据
}
});
const result = await LotModel.createRecs(lots);
return result;
}
/**
* @description 获取活动参加者
* @export

View File

@@ -0,0 +1,31 @@
import 'mocha';
import { expect } from 'chai';
import { getNextTime } from '../app/pubUtils/timeUtil';
const millisecondsPerDay = 24 * 60 * 60 * 1000;
function checkTime(date: Date, h: number, m: number, s: number) {
expect(date.getHours()).to.be.equal(h);
expect(date.getMinutes()).to.be.equal(m);
expect(date.getSeconds()).to.be.equal(s);
}
describe('测试时间相关工具方法', function () {
it('获取某个时间后的某点,返回当天', function () {
const baseDate = new Date();
const newHour = 9, newMin = 9, newSec = 9;
baseDate.setHours(newHour - 1, 0, 0);
const newDate = getNextTime(baseDate, newHour, newMin, newSec);
checkTime(newDate, newHour, newMin, newSec);
expect(newDate.getDate()).to.be.equal(baseDate.getDate());
});
it('获取某个时间后的某点,返回后一天', function () {
const baseDate = new Date();
const newHour = 9, newMin = 9, newSec = 9;
baseDate.setHours(newHour + 1, 0, 0);
const newDate = getNextTime(baseDate, newHour, newMin, newSec);
checkTime(newDate, newHour, newMin, newSec);
expect(newDate.getDate()).to.be.equal(new Date(baseDate.getTime() + millisecondsPerDay).getDate());
});
});

View File

@@ -13,4 +13,16 @@ export const AUCTION_SOURCE = {
RACE: 4, // 粮草先行
};
export const LOT_CODE_LEN = 8;
export const LOT_CODE_LEN = 8;
// 世界拍卖开始时间需晚于军团拍卖结束时间
export const AUCTION_TIME = {
GUILD_BEGIN_HOUR: 8, // 军团拍卖开始
GUILD_BEGIN_MIN: 20, // 军团拍卖开始
WORLD_BEGIN_HOUR: 8, // 世界拍卖开始
WORLD_BEGIN_MIN: 30, // 世界拍卖开始
GUILD_END_HOUR: 8, // 军团拍卖结束
GUILD_END_MIN: 30, // 军团拍卖结束
WORLD_END_HOUR: 10, // 世界拍卖结束
WORLD_END_MIN: 0, // 世界拍卖结束
}

View File

@@ -129,4 +129,19 @@ export function formatTime(d: Date, type: number) {
if(month < 10) monthStr = '0' + monthStr;
return `${yearStr}/${monthStr}/${dayStr}`;
}
}
}
/**
* @description 获取指定时间后的某个时间点,如给定 date 后的晚八点整
* @export
* @param {Date} date 给定时间
* @param {number} h 给定小时
* @param {number} [m=0] 给定分钟
* @param {number} [s=0] 给定秒
* @returns {Date}
*/
export function getNextTime(date: Date, h: number, m = 0, s = 0): Date {
const milliseconds = date.getTime();
const timeToday = new Date(milliseconds).setHours(h, m, s);
return timeToday > milliseconds ? new Date(timeToday) : new Date(timeToday + PER_DAY * PER_SECOND);
}