拍卖行:获取数据接口和出价接口部分功能
This commit is contained in:
@@ -3,7 +3,7 @@ import { LOT_CODE_LEN, AUCTION_STAGE, AUCTION_TIME, DIVIDEND_CODE_LEN, DIVIDEND_
|
||||
import { DividendRec, ItemReward } from "../domain/dbGeneral";
|
||||
import { genCode } from '../pubUtils/util';
|
||||
import { LotModel, LotParam } from '../db/Lot';
|
||||
import { getNextTime } from '../pubUtils/timeUtil';
|
||||
import { getNextTime, getTodayZeroDate } from '../pubUtils/timeUtil';
|
||||
import { getGoodById } from '../pubUtils/data';
|
||||
import { DividendParam, DividendType } from '../db/Dividend';
|
||||
|
||||
@@ -19,6 +19,25 @@ function getMaxPrice(gid: number, count: number) {
|
||||
return (good ? good.quality * 200 : 200) * count;
|
||||
}
|
||||
|
||||
export function auctionStage() {
|
||||
const curTime = new Date().getTime();
|
||||
const todayGuildBegin = getNextTime(getTodayZeroDate(), AUCTION_TIME.GUILD_BEGIN_HOUR, AUCTION_TIME.GUILD_BEGIN_MIN).getTime();
|
||||
const todayWorldBegin = getNextTime(getTodayZeroDate(), AUCTION_TIME.WORLD_BEGIN_HOUR, AUCTION_TIME.WORLD_BEGIN_MIN).getTime();
|
||||
const todayWorldEnd = getNextTime(getTodayZeroDate(), AUCTION_TIME.WORLD_END_HOUR, AUCTION_TIME.WORLD_END_MIN).getTime();
|
||||
if (curTime < todayGuildBegin) return AUCTION_STAGE.DEFAULT;
|
||||
if (curTime < todayWorldBegin && curTime > todayGuildBegin) return AUCTION_STAGE.GUILD;
|
||||
if (curTime > todayWorldBegin && curTime < todayWorldEnd) return AUCTION_STAGE.WORLD;
|
||||
if (curTime > todayWorldEnd) return AUCTION_STAGE.END;
|
||||
}
|
||||
|
||||
export function auctionBegin() {
|
||||
return getNextTime(new Date(), AUCTION_TIME.GUILD_BEGIN_HOUR, AUCTION_TIME.GUILD_BEGIN_MIN);
|
||||
}
|
||||
|
||||
export function auctionEnd() {
|
||||
return getNextTime(new Date(), AUCTION_TIME.WORLD_END_HOUR, AUCTION_TIME.WORLD_END_MIN);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 生成拍卖数据
|
||||
* @export
|
||||
@@ -29,8 +48,8 @@ function getMaxPrice(gid: number, count: number) {
|
||||
* @param {ItemReward[]} rewards
|
||||
*/
|
||||
export async function genAuction(guildCode: string, sourceType: number, sourceCode: string, serverId: number, rewards: ItemReward[]) {
|
||||
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 begin = auctionBegin();
|
||||
const end = auctionEnd();
|
||||
const lotsData: LotParam[] = rewards.map(reward => {
|
||||
const { id, count } = reward;
|
||||
const code = genCode(LOT_CODE_LEN);
|
||||
@@ -43,7 +62,7 @@ export async function genAuction(guildCode: string, sourceType: number, sourceCo
|
||||
const lots = await LotModel.createRecs(lotsData);
|
||||
const dividendCode = genCode(DIVIDEND_CODE_LEN);
|
||||
const dividendData: DividendParam = {
|
||||
guildCode, sourceType, sourceCode, serverId, code: dividendCode, lots: [], dividends: [], totalPrice: 0, end
|
||||
guildCode, sourceType, sourceCode, serverId, code: dividendCode, lots: [], dividends: [], totalPrice: 0, begin
|
||||
};
|
||||
const dividend = await DividendModel.createDividend(dividendData);
|
||||
return { lots, dividend };
|
||||
@@ -81,7 +100,7 @@ function weekendDividend(totalPrice: number, roleNum: number, date: Date) {
|
||||
}
|
||||
|
||||
export async function calculateDividend(dividend: DividendType) {
|
||||
const { code, guildCode, sourceType, sourceCode, lots, totalPrice, status, end } = dividend;
|
||||
const { code, guildCode, sourceType, sourceCode, lots, totalPrice, status, begin } = dividend;
|
||||
if (status === DIVIDEND_STATUS.SENT) return null;
|
||||
const calcuTotalPrice = lots.reduce((acc, lot) => { return acc + lot.price }, 0);
|
||||
if (calcuTotalPrice !== totalPrice) {
|
||||
@@ -94,7 +113,7 @@ export async function calculateDividend(dividend: DividendType) {
|
||||
const roleNum = participantsData.length;
|
||||
const baseNum = baseDividend(calcuTotalPrice, roleNum);
|
||||
const posNum = posDividend(calcuTotalPrice, roleNum, position);
|
||||
const weekendNum = weekendDividend(calcuTotalPrice, roleNum, end);
|
||||
const weekendNum = weekendDividend(calcuTotalPrice, roleNum, begin);
|
||||
return {
|
||||
roleId,
|
||||
baseNum, // 基础分红
|
||||
|
||||
@@ -102,6 +102,7 @@ function sortConsumes(goods: Array<ItemInter>, bags: Array<ItemInter>, currencys
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO: sid 在方法内部获取,且不一定存在
|
||||
export async function addItems(roleId: string, roleName: string, sid: string, goods: Array<ItemInter>) {
|
||||
let showItems: Array<ItemInter> = [];
|
||||
let currencysMap: any = {};
|
||||
|
||||
Reference in New Issue
Block a user