拍卖行:简单数据库操作

This commit is contained in:
liangtongchuan
2021-03-16 12:24:35 +08:00
parent 8d071b4bac
commit 2bb852135d
2 changed files with 34 additions and 1 deletions

View File

@@ -1,6 +1,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';
/**
* 分红记录表
@@ -15,12 +16,26 @@ export default class Dividend extends BaseModel {
guildCode: string; // 军团编号
@prop({ required: true, default: '' })
sourceCode: string; // 来源的唯一标识,如活动编号
@prop({ required: true, default: '' })
code: string; // 分红记录唯一标识
@prop({ required: true, type: LotRec, default: [] })
lots: LotRec[];
@prop({ required: true, default: 0 })
totalPrice: number; // 分红总金额
@prop({ required: true, type: DividendRec, default: [] })
dividends: DividendRec[];
public static async createDividend(data: DividendParam) {
const code = genCode(8);
const docData = new DividendModel();
const result: DividendType = await DividendModel.findOneAndUpdate({ code }, { ...docData.toJSON(), ...data, code }, { upsert: true, new: true }).select('-_id -__v').lean();
return result;
}
public static async findDividend(code: string) {
const result = await DividendModel.findOne({ code }).select('-_id -__v').lean();
return result;
}
}
export const DividendModel = getModelForClass(Dividend);

View File

@@ -1,13 +1,14 @@
import { BidRec } from './../domain/dbGeneral';
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType, modelOptions } from '@typegoose/typegoose';
import { genCode } from '../pubUtils/util';
/**
* 竞拍物品表
**/
@modelOptions({ schemaOptions: { id: false } })
@index({ code: 1 })
@index({ guildCode: 1 })
@index({ guildCode: 1, createdAt: -1 })
export default class Lot extends BaseModel {
@prop({ required: true, default: 0 })
auctionStage: number; // 0初始添加1军团拍卖2世界拍卖3拍卖结束
@@ -35,6 +36,23 @@ export default class Lot extends BaseModel {
begin: Date; // 竞拍开始时间
@prop({ required: true })
end: Date; // 竞拍结束时间
public static async createRec(data: LotParam) {
const code = genCode(8);
const docData = new LotModel();
const result: LotType = await LotModel.findOneAndUpdate({ code }, { ...docData.toJSON(), ...data, code }, { upsert: true, new: true }).select('-_id').lean();
return result;
}
public static async findLot(code: string) {
const result = await LotModel.findOne({ code }).select('-_id -__v').lean();
return result;
}
public static async findGuildLotsByTime(guildCode: string, time: Date) {
const results = await LotModel.find({ guildCode, createdAt: { $gte: time } }).select('-_id -__v').lean();
return results;
}
}
export const LotModel = getModelForClass(Lot);