diff --git a/shared/db/Dividend.ts b/shared/db/Dividend.ts index cc492e710..90ed6067c 100644 --- a/shared/db/Dividend.ts +++ b/shared/db/Dividend.ts @@ -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); diff --git a/shared/db/Lot.ts b/shared/db/Lot.ts index a9310edd4..ebe45c49f 100644 --- a/shared/db/Lot.ts +++ b/shared/db/Lot.ts @@ -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);