拍卖行:获取军团拍卖记录;修改分红机制
This commit is contained in:
@@ -3,9 +3,9 @@ import { DividendModel } from './../../../db/Dividend';
|
||||
import { Application, BackendSession, ChannelService } from "pinus";
|
||||
import { AUCTION_STAGE, DEBUG_MAGIC_WORD, STATUS, OFFER_RATIO, CURRENCY_BY_TYPE, CURRENCY_TYPE, DATA_NAME, LOT_STATUS } from "../../../consts";
|
||||
import { LotModel } from "../../../db/Lot";
|
||||
import { ItemReward } from "../../../domain/dbGeneral";
|
||||
import { ItemReward, LotRec } from "../../../domain/dbGeneral";
|
||||
import { resResult } from "../../../pubUtils/util";
|
||||
import { auctionStage, calculateDividend, genAuction, sendUngotDividend, startGuildAuction, startWorldAuction, stopAuction, todayGuildBegin } from "../../../services/auctionService";
|
||||
import { auctionStage, calculateDividend, genAuction, sendUngotDividend, startGuildAuction, startWorldAuction, stopAuction, todayGuildBegin, getBasePrice } from "../../../services/auctionService";
|
||||
import { addItems, handleCost } from '../../../services/rewardService';
|
||||
import { getSimpleRoleInfo } from '../../../services/roleService';
|
||||
import { getRoleOnlineInfo } from '../../../services/redisService';
|
||||
@@ -51,7 +51,7 @@ export class AuctionHandler {
|
||||
}
|
||||
|
||||
const lot = await LotModel.findLot(code);
|
||||
if (!lot || lot.status === LOT_STATUS.SOLD) {
|
||||
if (!lot || lot.status === LOT_STATUS.SOLD || lot.status === LOT_STATUS.MAX) {
|
||||
res.releaseCallback();
|
||||
return resResult(STATUS.GUILD_LOT_NOT_FOUND);
|
||||
}
|
||||
@@ -84,12 +84,15 @@ export class AuctionHandler {
|
||||
await addItems(roleId, roleName, sid, [{ id: gid, count }]);
|
||||
}
|
||||
bidRoles.push({ roleId, price: newPrice, time: new Date() });
|
||||
const newLot = await LotModel.updateLot({ code, curBuyer: roleId, curPrice: newPrice, bidRoles, status: maxFlag ? LOT_STATUS.SOLD : LOT_STATUS.ING, watchingRoles: Array.from(new Set([...watchingRoles, roleId])) });
|
||||
const newLot = await LotModel.updateLot({ code, curBuyer: roleId, curPrice: newPrice, bidRoles, status: max ? LOT_STATUS.MAX : (maxFlag ? LOT_STATUS.SOLD : LOT_STATUS.ING), watchingRoles: Array.from(new Set([...watchingRoles, roleId])) });
|
||||
res.releaseCallback();
|
||||
|
||||
const incPrice = newPrice - (curBuyer ? curPrice : 0);
|
||||
const dividend = await DividendModel.updateLot(code, gid, newPrice, incPrice);
|
||||
const newDividend = await calculateDividend(dividend);
|
||||
let newDividend = null;
|
||||
if (auctionStage() === AUCTION_STAGE.GUILD) {
|
||||
const dividend = await DividendModel.updateLot(code, gid, newPrice, incPrice, max);
|
||||
newDividend = await calculateDividend(dividend);
|
||||
}
|
||||
return resResult(STATUS.SUCCESS, { lot: newLot, dividend: newDividend });
|
||||
} catch (e) {
|
||||
console.log('offer got err:', e);
|
||||
@@ -159,6 +162,25 @@ export class AuctionHandler {
|
||||
return resResult(STATUS.SUCCESS, { bidRecs });
|
||||
}
|
||||
|
||||
async guildLotRecs(msg: { count: number }, session: BackendSession) {
|
||||
const guildCode = session.get('guildCode');
|
||||
const dividends = await DividendModel.findDividendsByGuild(guildCode, msg.count);
|
||||
let lotsData: LotRec[] = [];
|
||||
dividends.forEach(dividend => {
|
||||
const lots = dividend.lots.map(lot => {
|
||||
return { ...lot, sourceType: dividend.sourceType };
|
||||
})
|
||||
lotsData = [...lotsData, ...lots];
|
||||
});
|
||||
const lotRecs = lotsData.map(lot => {
|
||||
const price = lot.price === 0 ? getBasePrice(lot.gid, lot.count) : lot.price;
|
||||
const sold = lot.price !== 0;
|
||||
return { ...lot, price, sold };
|
||||
});
|
||||
|
||||
return resResult(STATUS.SUCCESS, { lotRecs });
|
||||
}
|
||||
|
||||
// ! 测试接口
|
||||
async debugSetDividendStatus(msg: { magicWord: string, sourceType: number, status: number }, session: BackendSession) {
|
||||
const { magicWord, sourceType, status } = msg;
|
||||
|
||||
@@ -13,7 +13,7 @@ import { getMailContent } from './mailService';
|
||||
import { pinus } from 'pinus';
|
||||
|
||||
// ! 获取底价,假数据
|
||||
function getBasePrice(gid: number, count: number) {
|
||||
export function getBasePrice(gid: number, count: number) {
|
||||
const good = getGoodById(gid);
|
||||
return (good ? good.quality * 100 : 100) * count;
|
||||
}
|
||||
@@ -36,6 +36,10 @@ export function auctionBegin() {
|
||||
return getNextTime(new Date(), AUCTION_TIME.GUILD_BEGIN_HOUR, AUCTION_TIME.GUILD_BEGIN_MIN);
|
||||
}
|
||||
|
||||
export function guildAuctionEnd() {
|
||||
return getNextTime(new Date(), AUCTION_TIME.GUILD_END_HOUR, AUCTION_TIME.GUILD_END_MIN);
|
||||
}
|
||||
|
||||
export function auctionEnd() {
|
||||
return getNextTime(new Date(), AUCTION_TIME.WORLD_END_HOUR, AUCTION_TIME.WORLD_END_MIN);
|
||||
}
|
||||
@@ -67,6 +71,7 @@ export function todayWorldEnd() {
|
||||
*/
|
||||
export async function genAuction(guildCode: string, sourceType: number, sourceCode: string, serverId: number, rewards: ItemReward[]) {
|
||||
const begin = auctionBegin();
|
||||
const guildEnd = guildAuctionEnd();
|
||||
const end = auctionEnd();
|
||||
const lotsData: LotParam[] = rewards.map(reward => {
|
||||
const { id, count } = reward;
|
||||
@@ -82,7 +87,7 @@ export async function genAuction(guildCode: string, sourceType: number, sourceCo
|
||||
const dividendData: DividendParam = {
|
||||
guildCode, sourceType, sourceCode, serverId, code: dividendCode, dividends: [], totalPrice: 0, begin, lots: lots.map(lot => {
|
||||
const { code, gid } = lot;
|
||||
return { code, gid, price: 0 }
|
||||
return { code, gid, price: 0, time: guildEnd, max: false, count: lot.count }
|
||||
}),
|
||||
};
|
||||
const dividend = await DividendModel.createDividend(dividendData);
|
||||
@@ -172,6 +177,7 @@ export async function startWorldAuction() {
|
||||
try {
|
||||
console.log('schedule startWorldAuction called:', new Date());
|
||||
const begin = todayGuildBegin();
|
||||
await LotModel.setLotSoldByBegin(begin);
|
||||
await LotModel.updateLotsStageByBegin(begin, AUCTION_STAGE.WORLD);
|
||||
return true;
|
||||
} catch (e) {
|
||||
@@ -184,6 +190,7 @@ export async function stopAuction() {
|
||||
try {
|
||||
console.log('schedule stopAuction called:', new Date());
|
||||
const begin = todayGuildBegin();
|
||||
await LotModel.setLotSoldByBegin(begin);
|
||||
await LotModel.updateLotsStageByBegin(begin, AUCTION_STAGE.END);
|
||||
await DividendModel.updateDividendsStatus(begin, DIVIDEND_STATUS.END);
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user