拍卖行:获取数据接口和出价接口部分功能
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
import { DividendModel } from './../../../db/Dividend';
|
||||
import { Application, BackendSession, ChannelService } from "pinus";
|
||||
import { DEBUG_MAGIC_WORD, STATUS } from "../../../consts";
|
||||
import { AUCTION_STAGE, DEBUG_MAGIC_WORD, STATUS, OFFER_RATIO, CURRENCY_BY_TYPE, CURRENCY_TYPE } from "../../../consts";
|
||||
import { LotModel } from "../../../db/Lot";
|
||||
import { ItemReward } from "../../../domain/dbGeneral";
|
||||
import { resResult } from "../../../pubUtils/util";
|
||||
import { genAuction } from "../../../services/auctionService";
|
||||
import { auctionBegin, auctionStage, genAuction } from "../../../services/auctionService";
|
||||
import { addItems, handleCost } from '../../../services/rewardService';
|
||||
import { getSimpleRoleInfo } from '../../../services/roleService';
|
||||
import { getRoleOnlineInfo } from '../../../services/redisService';
|
||||
|
||||
export default function (app: Application) {
|
||||
return new AuctionHandler(app);
|
||||
@@ -15,11 +20,51 @@ export class AuctionHandler {
|
||||
}
|
||||
|
||||
async getAuction(msg: {}, session: BackendSession) {
|
||||
return resResult(STATUS.SUCCESS);
|
||||
const guildCode = session.get('guildCode');
|
||||
const serverId = session.get('serverId');
|
||||
if (!guildCode) return resResult(STATUS.GUILD_NOT_FOUND);
|
||||
const begin = auctionBegin();
|
||||
const stage = auctionStage();
|
||||
let lots = [];
|
||||
if (stage === AUCTION_STAGE.DEFAULT || stage === AUCTION_STAGE.GUILD) {
|
||||
lots = await LotModel.findGuildLotsByBegin(guildCode, begin);
|
||||
} else if (stage === AUCTION_STAGE.WORLD) {
|
||||
lots = await LotModel.findWorldLotsByBegin(serverId, begin);
|
||||
}
|
||||
const dividends = await DividendModel.findGuildDividendsByBegin(guildCode, begin);
|
||||
return resResult(STATUS.SUCCESS, { lots, dividends });
|
||||
}
|
||||
|
||||
async offer(msg: { max: boolean }, session: BackendSession) {
|
||||
return resResult(STATUS.SUCCESS);
|
||||
async offer(msg: { code: string, max: boolean }, session: BackendSession) {
|
||||
const { code, max } = msg;
|
||||
let maxFlag = max;
|
||||
const lot = await LotModel.findLot(code);
|
||||
if (!lot) return resResult(STATUS.GUILD_LOT_NOT_FOUND);
|
||||
const roleId = session.get('roleId');
|
||||
const roleName = session.get('roleName');
|
||||
const sid = session.get('sid');
|
||||
const { curBuyer, curPrice, maxPrice, gid, count, bidRoles } = lot;
|
||||
if (curBuyer === roleId) return resResult(STATUS.LOT_OFFER_SERIAL);
|
||||
let newPrice = parseInt((curPrice * OFFER_RATIO).toFixed(0));
|
||||
if (newPrice >= maxPrice) {
|
||||
newPrice = maxPrice;
|
||||
maxFlag = true;
|
||||
}
|
||||
const costRes = await handleCost(roleId, sid, [{ id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.GOLD), count: newPrice }]);
|
||||
if (!costRes) return resResult(STATUS.ROLE_COIN_NOT_ENOUGH);
|
||||
const { roleName: buyerName } = await getSimpleRoleInfo(curBuyer);
|
||||
const { sid: buyerSid } = await getRoleOnlineInfo(buyerName);
|
||||
await addItems(curBuyer, buyerName, buyerSid, [{ id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.GOLD), count: curPrice }]);
|
||||
// TODO 元宝返还纪录
|
||||
if (maxFlag) {
|
||||
newPrice = maxPrice;
|
||||
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});
|
||||
|
||||
// TODO 更新分红
|
||||
return resResult(STATUS.SUCCESS, { lot: newLot });
|
||||
}
|
||||
|
||||
async watchLot(msg: { code: string }, session: BackendSession) {
|
||||
|
||||
Reference in New Issue
Block a user