拍卖:优化

This commit is contained in:
luying
2021-10-27 16:39:55 +08:00
parent b03802136b
commit 0dde8fd09a
9 changed files with 146 additions and 68 deletions

View File

@@ -8,6 +8,7 @@ import { BID_REC_COUNT, GUILD_LOTS_REC_COUNT, LOT_STATUS } from '../consts';
* 竞拍物品表
**/
@modelOptions({ schemaOptions: { id: false } })
@index({ sort: 1 })
@index({ code: 1 })
@index({ guildCode: 1, begin: -1 })
@index({ serverId: 1, begin: -1, watchingRoles: 1 })
@@ -44,6 +45,8 @@ export default class Lot extends BaseModel {
end: Date; // 竞拍结束时间
@prop({ required: true, default: 0 })
status: number; // 拍品状态0无人竞拍1竞拍中2已竞拍3一口价
@prop({ required: true, default: 0 })
sort: number; // 排序
public static async createRec(data: LotParam) {
const code = genCode(8);
@@ -63,27 +66,27 @@ export default class Lot extends BaseModel {
}
public static async findLots(codes: string[]) {
const result = await LotModel.find({ code: {$in: codes} }).select('-_id -__v').lean();
const result = await LotModel.find({ code: {$in: codes} }).sort({ sort: 1 }).select('-_id -__v').lean();
return result;
}
public static async findGuildLotsByBegin(guildCode: string, begin: Date) {
const results = await LotModel.find({ guildCode, begin }).select('-_id -__v').lean();
const results = await LotModel.find({ guildCode, begin }).sort({ sort: 1 }).select('-_id -__v').lean();
return results;
}
public static async findWorldLotsByBegin(serverId: number, begin: Date) {
const results = await LotModel.find({ serverId, begin }).select('-_id -__v').lean();
const results = await LotModel.find({ serverId, begin }).sort({ sort: 1 }).select('-_id -__v').lean();
return results;
}
public static async findWatchingLotsByBegin(roleId: string, serverId: number, begin: Date) {
const results = await LotModel.find({ serverId, begin, watchingRoles: roleId }, { new: true }).select('-_id -__v').lean();
const results = await LotModel.find({ serverId, begin, watchingRoles: roleId }, { new: true }).sort({ sort: 1 }).select('-_id -__v').lean();
return results;
}
public static async recentGuildLots(guildCode: string, count = GUILD_LOTS_REC_COUNT ) {
const results = await LotModel.find({ guildCode }).sort({ _id: -1 }).limit(count).select('-_id -__v').lean();
const results = await LotModel.find({ guildCode }).sort({ _id: -1 }).limit(count).sort({ sort: 1 }).select('-_id -__v').lean();
return results;
}
@@ -104,12 +107,12 @@ export default class Lot extends BaseModel {
}
public static async watchingLotsByBegin(serverId: number, roleId: string, begin: Date) {
const results: LotType[] = await LotModel.find({ serverId, begin, watchingRoles: roleId }).select('-_id -__v').lean();
const results: LotType[] = await LotModel.find({ serverId, begin, watchingRoles: roleId }).sort({ sort: 1 }).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').sort({ _id: -1 }).limit(count).lean();
const results: LotType[] = await LotModel.find({ serverId, 'bidRoles.roleId': roleId }).sort({ sort: 1 }).select('-_id -__v').sort({ _id: -1 }).limit(count).lean();
return results;
}
@@ -129,7 +132,8 @@ export default class Lot extends BaseModel {
}
public static async setLotSoldByBegin(begin: Date) {
const results = await LotModel.updateMany({ begin, status: LOT_STATUS.ING }, { status: LOT_STATUS.SOLD }).select('-_id -__v').lean();
const results: LotType[] = await LotModel.find({ begin, status: LOT_STATUS.ING }).sort({ sort: 1 }).select('-_id -__v').lean();
await LotModel.updateMany({ begin, status: LOT_STATUS.ING }, { status: LOT_STATUS.SOLD });
return results;
}
}