import { LOT_CODE_LEN, AUCTION_STAGE, 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'; import { getGoodById } from '../pubUtils/data'; // ! 获取底价,假数据 function getBasePrice(gid: number, count: number) { const good = getGoodById(gid); return (good ? good.quality * 100 : 100) * count; } // ! 获取一口价,假数据 function getMaxPrice(gid: number, count: number) { const good = getGoodById(gid); return (good ? good.quality * 200 : 200) * count; } /** * @description 生成拍卖数据 * @export * @param {string} guildCode * @param {number} sourceType * @param {string} sourceCode * @param {number} serverId * @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 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, begin, end, maxPrice: getMaxPrice(id, count), curPrice: getBasePrice(id, count), } }); const result = await LotModel.createRecs(lots); return result; } /** * ! 目前返回假数据 * @description 获取活动参加者 * @export * @param {string} guildCode * @param {number} sourceType * @param {string} sourceCode */ export async function participants(guildCode: string, sourceType: number, sourceCode: string) { return [{ roleId: 'rM8NZtlfzD', position: 1, }, { roleId: 'EjX79SEddK', position: 2, }]; }