拍卖行:获取军团拍卖记录;修改分红机制

This commit is contained in:
liangtongchuan
2021-03-20 01:09:09 +08:00
parent 7df19fd510
commit a9d06173ac
7 changed files with 108 additions and 15 deletions
@@ -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;
+9 -2
View File
@@ -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;
+37 -1
View File
@@ -132,7 +132,9 @@ describe('拍卖行测试', function() {
pinusClient.request('battle.auctionHandler.offer', { code: unsoldLots[0].code, max: false }, (res) => {
checkSuccessResponse(res);
checkLot(res.data.lot);
checkDividend(res.data.dividend);
if (res.data.dividend) {
checkDividend(res.data.dividend);
}
expect(res.data.lot.curBuyer).to.be.equal(roleInfo.roleId);
done();
});
@@ -201,6 +203,13 @@ describe('拍卖行测试', function() {
pinusClient.request('battle.auctionHandler.debugSetDividendStatus', { magicWord: DEBUG_MAGIC_WORD, sourceType: AUCTION_SOURCE.GATE, status: DIVIDEND_STATUS.END }, (res) => {
checkSuccessResponse(res);
checkDividend(res.data.dividend);
// TODO: 找个测试领取分红的方法
const dividend = res.data.dividend.dividends.find(d => { return d.roleId === roleInfo.roleId });
if (!dividend) {
console.warn('未测试到领取分红的情况');
done();
return;
}
pinusClient.request('battle.auctionHandler.getDividend', { sourceType: AUCTION_SOURCE.GATE }, (res) => {
checkSuccessResponse(res);
expect(res.data.dividend).to.be.an('object');
@@ -267,6 +276,11 @@ describe('拍卖行测试', function() {
pinusClient.request('battle.auctionHandler.offerRecs', { count: 10 }, (res) => {
checkSuccessResponse(res);
expect(res.data.bidRecs).to.be.an('array');
if (res.data.bidRecs.length === 0) {
console.warn('没有我的拍卖纪录');
done();
return;
}
for (let bidRec of res.data.bidRecs) {
expect(bidRec.roleId).to.be.a('string');
expect(bidRec.price).to.be.a('number');
@@ -278,6 +292,28 @@ describe('拍卖行测试', function() {
});
});
it('获取军团拍卖记录', function(done) {
pinusClient.request('battle.auctionHandler.guildLotRecs', { count: 10 }, (res) => {
checkSuccessResponse(res);
expect(res.data.lotRecs).to.be.an('array');
if (res.data.lotRecs.length === 0) {
console.warn('没有军团拍卖纪录');
done();
return;
}
for (let lotRec of res.data.lotRecs) {
expect(lotRec.price).to.be.a('number');
expect(Date.parse(lotRec.time)).to.be.a('number');
expect(lotRec.gid).to.be.a('number');
expect(lotRec.sourceType).to.be.a('number');
expect(lotRec.max).to.be.a('boolean');
expect(lotRec.sold).to.be.a('boolean');
}
done();
});
});
it('测试接口,军团拍卖定时', function(done) {
pinusClient.request('battle.auctionHandler.debugScheduleStartGuild', { magicWord: DEBUG_MAGIC_WORD }, (res) => {
checkSuccessResponse(res, false);