拍卖行:出价、关注接口和测试用例
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { DividendModel } from './../db/Dividend';
|
||||
import { LOT_CODE_LEN, AUCTION_STAGE, AUCTION_TIME, DIVIDEND_CODE_LEN, DIVIDEND_STATUS } from './../consts';
|
||||
import { LOT_CODE_LEN, AUCTION_STAGE, AUCTION_TIME, DIVIDEND_CODE_LEN, DIVIDEND_STATUS, LOT_STATUS } from './../consts';
|
||||
import { DividendRec, ItemReward } from "../domain/dbGeneral";
|
||||
import { genCode } from '../pubUtils/util';
|
||||
import { LotModel, LotParam } from '../db/Lot';
|
||||
@@ -64,14 +64,17 @@ export async function genAuction(guildCode: string, sourceType: number, sourceCo
|
||||
const code = genCode(LOT_CODE_LEN);
|
||||
return {
|
||||
auctionStage: AUCTION_STAGE.DEFAULT, sourceType,
|
||||
sourceCode, serverId, guildCode, code, gid: id, count, begin, end,
|
||||
sourceCode, serverId, guildCode, code, gid: id, count, begin, end, status: LOT_STATUS.DEFAULT,
|
||||
maxPrice: getMaxPrice(id, count), curPrice: getBasePrice(id, count),
|
||||
}
|
||||
});
|
||||
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, begin
|
||||
guildCode, sourceType, sourceCode, serverId, code: dividendCode, dividends: [], totalPrice: 0, begin, lots: lots.map(lot => {
|
||||
const { code, gid } = lot;
|
||||
return { code, gid, price: 0 }
|
||||
}),
|
||||
};
|
||||
const dividend = await DividendModel.createDividend(dividendData);
|
||||
return { lots, dividend };
|
||||
@@ -109,8 +112,9 @@ function weekendDividend(totalPrice: number, roleNum: number, date: Date) {
|
||||
}
|
||||
|
||||
export async function calculateDividend(dividend: DividendType) {
|
||||
if (!dividend) return null;
|
||||
const { code, guildCode, sourceType, sourceCode, lots, totalPrice, status, begin } = dividend;
|
||||
if (status === DIVIDEND_STATUS.SENT) return null;
|
||||
if (status === DIVIDEND_STATUS.SENT) return dividend;
|
||||
const calcuTotalPrice = lots.reduce((acc, lot) => { return acc + lot.price }, 0);
|
||||
if (calcuTotalPrice !== totalPrice) {
|
||||
await DividendModel.updateDividend(code, { totalPrice: calcuTotalPrice });
|
||||
@@ -132,5 +136,5 @@ export async function calculateDividend(dividend: DividendType) {
|
||||
status: 0, // 0:未领取,1:已领取
|
||||
};
|
||||
});
|
||||
await DividendModel.updateDividend(code, { dividends });
|
||||
return await DividendModel.updateDividend(code, { dividends });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user