拍卖行:领取奖励、查看关注、查看出价的接口实现和测试用例
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { AUCTION_BID_STATUS } from './../../../consts/constModules/auctionConst';
|
||||
import { pick } from 'lodash';
|
||||
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";
|
||||
@@ -82,7 +84,7 @@ export class AuctionHandler {
|
||||
newPrice = maxPrice;
|
||||
await addItems(roleId, roleName, sid, [{ id: gid, count }]);
|
||||
}
|
||||
bidRoles.push({roleId, price: newPrice, time: new Date()});
|
||||
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])) });
|
||||
res.releaseCallback();
|
||||
|
||||
@@ -122,15 +124,52 @@ export class AuctionHandler {
|
||||
}
|
||||
|
||||
async getDividend(msg: { sourceType: number }, session: BackendSession) {
|
||||
return resResult(STATUS.SUCCESS);
|
||||
const roleId = session.get('roleId');
|
||||
const sid = session.get('sid');
|
||||
const roleName = session.get('roleName');
|
||||
const guildCode = session.get('guildCode');
|
||||
const { sourceType } = msg;
|
||||
const dividendData = await DividendModel.findReadyDividend(guildCode, sourceType);
|
||||
if (!dividendData) return resResult(STATUS.DIVIDEND_NOT_READY);
|
||||
const { dividends } = dividendData;
|
||||
const dividend = dividends.find(item => { return item.roleId === roleId });
|
||||
if (!dividend) return resResult(STATUS.DIVIDEND_GUILD_PLAYER_ONLY);
|
||||
await addItems(roleId, roleName, sid, [{ id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.GOLD), count: dividend.total }]);
|
||||
await DividendModel.updateReceiveStatus(dividendData.code, roleId);
|
||||
return resResult(STATUS.SUCCESS, { dividend });
|
||||
}
|
||||
|
||||
async myOffers(msg: {}, session: BackendSession) {
|
||||
return resResult(STATUS.SUCCESS);
|
||||
async myWatching(msg: {}, session: BackendSession) {
|
||||
const roleId = session.get('roleId');
|
||||
const serverId = session.get('serverId');
|
||||
const begin = todayGuildBegin();
|
||||
const lots = await LotModel.watchingLotsByBegin(serverId, roleId, begin);
|
||||
return resResult(STATUS.SUCCESS, { lots });
|
||||
}
|
||||
|
||||
async offerRecs(msg: { count: number }, session: BackendSession) {
|
||||
return resResult(STATUS.SUCCESS);
|
||||
const roleId = session.get('roleId');
|
||||
const serverId = session.get('serverId');
|
||||
const lotsData = await LotModel.recentBidLots(serverId, roleId, msg.count);
|
||||
const bidRecs = lotsData.map(lot => {
|
||||
const bidRec = lot.bidRoles.find(role => { return role.roleId === roleId });
|
||||
const { curBuyer } = lot;
|
||||
return { ...bidRec, status: curBuyer === roleId ? AUCTION_BID_STATUS.SUC : AUCTION_BID_STATUS.RETURN };
|
||||
});
|
||||
return resResult(STATUS.SUCCESS, { bidRecs });
|
||||
}
|
||||
|
||||
// ! 测试接口
|
||||
async debugSetDividendReady(msg: { magicWord: string, sourceType: number}, session: BackendSession) {
|
||||
const { magicWord, sourceType } = msg;
|
||||
if (magicWord !== DEBUG_MAGIC_WORD) {
|
||||
return resResult(STATUS.TOKEN_ERR);
|
||||
}
|
||||
|
||||
const guildCode: string = session.get('guildCode');
|
||||
if (!guildCode) return resResult(STATUS.GUILD_NOT_FOUND)
|
||||
const dividend = await DividendModel.updateDividendReady(guildCode, sourceType);
|
||||
return resResult(STATUS.SUCCESS, { dividend });
|
||||
}
|
||||
|
||||
// ! 测试接口
|
||||
|
||||
@@ -3,7 +3,7 @@ import 'mocha';
|
||||
import { PinusWSClient } from 'pinus-robot-plugin';
|
||||
import { expect } from 'chai';
|
||||
import { checkSuccessResponse } from './CheckPatten';
|
||||
import { DEBUG_MAGIC_WORD, AUCTION_SOURCE } from '../app/consts';
|
||||
import { DEBUG_MAGIC_WORD, AUCTION_SOURCE, CURRENCY_BY_TYPE, CURRENCY_TYPE } from '../app/consts';
|
||||
import { LOT_STATUS } from '../../shared/consts';
|
||||
|
||||
const GOOD_ID_TIEJIAN = 1;
|
||||
@@ -191,22 +191,69 @@ describe('拍卖行测试', function() {
|
||||
});
|
||||
|
||||
it('领取分红', function(done) {
|
||||
pinusClient.request('battle.auctionHandler.getDividend', {}, (res) => {
|
||||
checkSuccessResponse(res, false);
|
||||
done();
|
||||
pinusClient.on('onItemUpdate', (res) => {
|
||||
checkSuccessResponse(res);
|
||||
expect(res.data.goods).to.be.an('array');
|
||||
for (let info of res.data.goods) {
|
||||
expect(info.id).to.be.equal(CURRENCY_BY_TYPE.get(CURRENCY_TYPE.GOLD));
|
||||
}
|
||||
});
|
||||
pinusClient.request('battle.auctionHandler.debugSetDividendReady', { magicWord: DEBUG_MAGIC_WORD, sourceType: AUCTION_SOURCE.GATE }, (res) => {
|
||||
checkSuccessResponse(res);
|
||||
checkDividend(res.data.dividend);
|
||||
pinusClient.request('battle.auctionHandler.getDividend', { sourceType: AUCTION_SOURCE.GATE }, (res) => {
|
||||
checkSuccessResponse(res);
|
||||
expect(res.data.dividend).to.be.an('object');
|
||||
expect(res.data.dividend.roleId).to.be.a('string');
|
||||
expect(res.data.dividend.baseNum).to.be.a('number');
|
||||
expect(res.data.dividend.posNum).to.be.a('number');
|
||||
expect(res.data.dividend.weekendNum).to.be.a('number');
|
||||
expect(res.data.dividend.total).to.be.a('number');
|
||||
expect(res.data.dividend.status).to.be.a('number');
|
||||
setTimeout(() => {
|
||||
done();
|
||||
}, 100);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('查看我的关注', function(done) {
|
||||
pinusClient.request('battle.auctionHandler.myOffers', {}, (res) => {
|
||||
checkSuccessResponse(res, false);
|
||||
done();
|
||||
pinusClient.request('battle.auctionHandler.getAuction', {}, (res) => {
|
||||
checkSuccessResponse(res);
|
||||
expect(res.data.lots).to.be.an('array');
|
||||
checkLots(res.data.lots);
|
||||
expect(res.data.dividends).to.be.an('array');
|
||||
checkDividends(res.data.dividends);
|
||||
if (res.data.lots.length === 0) {
|
||||
console.warn('没有可关注的拍品');
|
||||
done();
|
||||
return;
|
||||
}
|
||||
const code = res.data.lots[0].code;
|
||||
pinusClient.request('battle.auctionHandler.watchLot', { code }, (res) => {
|
||||
checkSuccessResponse(res);
|
||||
checkLot(res.data.lot);
|
||||
expect(res.data.lot.watchingRoles.indexOf(roleInfo.roleId)).to.be.above(-1);
|
||||
pinusClient.request('battle.auctionHandler.myWatching', {}, (res) => {
|
||||
checkSuccessResponse(res);
|
||||
checkLots(res.data.lots);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('查看我的拍卖纪录', function(done) {
|
||||
pinusClient.request('battle.auctionHandler.offerRecs', { count: 10 }, (res) => {
|
||||
checkSuccessResponse(res, false);
|
||||
checkSuccessResponse(res);
|
||||
expect(res.data.bidRecs).to.be.an('array');
|
||||
for (let bidRec of res.data.bidRecs) {
|
||||
expect(bidRec.roleId).to.be.a('string');
|
||||
expect(bidRec.price).to.be.a('number');
|
||||
expect(Date.parse(bidRec.time)).to.be.a('number');
|
||||
expect(bidRec.status).to.be.a('number');
|
||||
}
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user