拍卖行:领取奖励、查看关注、查看出价的接口实现和测试用例

This commit is contained in:
liangtongchuan
2021-03-19 00:54:52 +08:00
parent 39228e1fc9
commit 63e0d33846
6 changed files with 143 additions and 15 deletions
@@ -41,4 +41,16 @@ export const LOT_STATUS = {
SOLD: 2, // 已拍出
}
export const ROLE_RECEIVE_STATUS = {
NO: 0, // 没领取
YES: 1, // 领取了
}
export const AUCTION_BID_STATUS = {
LEAD: 0, // 领先
RETURN: 1, // 退还
SUC: 2, // 竞拍成功
}
export const OFFER_RATIO = 1.1;
export const BID_REC_COUNT = 100;
+2
View File
@@ -194,6 +194,8 @@ export const STATUS = {
GUILD_LOT_NOT_FOUND: { code: 21001, simStr: '拍品未找到' },
LOT_OFFER_SERIAL: { code: 21002, simStr: '不能连续出价' },
DIVIDEND_NOT_READY: { code: 21003, simStr: '还不可以领取分红' },
DIVIDEND_GUILD_PLAYER_ONLY: { code: 21004, simStr: '需要参加军团活动才能领取' },
// 军团活动 21100-21199
GUILD_ACTIVITY_NOT_OPEN: { code: 21100, simStr: '活动未开放' },
+18 -2
View File
@@ -2,6 +2,7 @@ import { LotRec, DividendRec } from './../domain/dbGeneral';
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType, modelOptions } from '@typegoose/typegoose';
import { genCode } from '../pubUtils/util';
import { DIVIDEND_STATUS, ROLE_RECEIVE_STATUS } from '../consts';
/**
* 分红记录表
@@ -22,11 +23,11 @@ export default class Dividend extends BaseModel {
sourceCode: string; // 来源的唯一标识,如活动编号
@prop({ required: true, default: '' })
code: string; // 分红记录唯一标识
@prop({ required: true, type: LotRec, default: [] })
@prop({ required: true, type: LotRec, default: [], _id: false })
lots: LotRec[];
@prop({ required: true, default: 0 })
totalPrice: number; // 分红总金额
@prop({ required: true, type: DividendRec, default: [] })
@prop({ required: true, type: DividendRec, default: [], _id: false })
dividends: DividendRec[];
@prop({ required: true, default: 0 })
status: number; // 0:未开始;1:进行中;2:已结束;3:已发放
@@ -64,6 +65,21 @@ export default class Dividend extends BaseModel {
const result = await DividendModel.findOneAndUpdate({ 'lots.code': lotCode }, { 'lots.$.gid': gid, 'lots.$.price': price, $inc: { totalPrice: incPrice} }, { new: true }).select('-_id -__v').lean();
return result;
}
public static async findReadyDividend(guildCode: string, sourceType: number) {
const result: DividendType = await DividendModel.findOne({ guildCode, sourceType, status: DIVIDEND_STATUS.END }).select('-_id -__v').lean();
return result;
}
public static async updateReceiveStatus(code: string, roleId: string) {
const result: DividendType = await DividendModel.findOneAndUpdate({ code, status: DIVIDEND_STATUS.END, 'lots.roleId': roleId }, { 'lots.status': ROLE_RECEIVE_STATUS.YES }, { new: true }).select('-_id -__v').lean();
return result;
}
public static async updateDividendReady(guildCode: string, sourceType: number) {
const result: DividendType = await DividendModel.findOneAndUpdate({ guildCode, sourceType }, { status: DIVIDEND_STATUS.END }, { new: true }).select('-_id -__v').lean();
return result;
}
}
export const DividendModel = getModelForClass(Dividend);
+12
View File
@@ -2,6 +2,7 @@ import { BidRec } from './../domain/dbGeneral';
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType, modelOptions } from '@typegoose/typegoose';
import { genCode } from '../pubUtils/util';
import { BID_REC_COUNT } from '../consts';
/**
* 竞拍物品表
@@ -9,6 +10,7 @@ import { genCode } from '../pubUtils/util';
@modelOptions({ schemaOptions: { id: false } })
@index({ code: 1 })
@index({ guildCode: 1, begin: -1 })
@index({ serverId: 1, begin: -1, watchingRoles: 1 })
export default class Lot extends BaseModel {
@prop({ required: true, default: 0 })
auctionStage: number; // 0:初始添加,1:军团拍卖,2:世界拍卖,3:拍卖结束
@@ -90,6 +92,16 @@ export default class Lot extends BaseModel {
const result: LotType = await LotModel.findOneAndUpdate({ code }, { $pull: { watchingRoles: roleId } }, { new: true }).select('-_id -__v').lean();
return result;
}
public static async watchingLotsByBegin(serverId: number, roleId: string, begin: Date) {
const results: LotType[] = await LotModel.find({ serverId, begin, watchingRoles: roleId }).select('-_id -__v').lean();
return results;
}
public static async recentBidLots(serverId: number, roleId: string, count = BID_REC_COUNT) {
const results: LotType[] = await LotModel.find({ serverId, 'bidRoles.roleId': roleId }).select('-_id -__v').limit(count).lean();
return results;
}
}
export const LotModel = getModelForClass(Lot);