拍卖行:出价后更新分红

This commit is contained in:
liangtongchuan
2021-03-18 08:11:54 +08:00
parent 3cc1ff2760
commit 5de951b31c
2 changed files with 10 additions and 3 deletions
@@ -63,8 +63,9 @@ export class AuctionHandler {
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}); const newLot = await LotModel.updateLot({ code, curBuyer: roleId, curPrice: newPrice, bidRoles});
// TODO 更新分红 const incPrice = newPrice - (curBuyer ? curPrice : 0);
return resResult(STATUS.SUCCESS, { lot: newLot }); const dividend = await DividendModel.updateLot(code, gid, newPrice, incPrice);
return resResult(STATUS.SUCCESS, { lot: newLot, dividend });
} }
async watchLot(msg: { code: string }, session: BackendSession) { async watchLot(msg: { code: string }, session: BackendSession) {
+7 -1
View File
@@ -9,7 +9,8 @@ import { genCode } from '../pubUtils/util';
@modelOptions({ schemaOptions: { id: false } }) @modelOptions({ schemaOptions: { id: false } })
@index({ code: 1 }) @index({ code: 1 })
@index({ begin: -1, guildCode: 1 }) @index({ begin: -1, guildCode: 1 })
@index({ begin: -1, serverId: 1}) @index({ begin: -1, serverId: 1 })
@index({ 'lots.code': 1 })
export default class Dividend extends BaseModel { export default class Dividend extends BaseModel {
@prop({ required: true, default: 0 }) @prop({ required: true, default: 0 })
serverId: number; // 区服编号 serverId: number; // 区服编号
@@ -58,6 +59,11 @@ export default class Dividend extends BaseModel {
const result = await DividendModel.findOneAndUpdate({ code }, { ...update }, { new: true }).select('-_id -__v').lean(); const result = await DividendModel.findOneAndUpdate({ code }, { ...update }, { new: true }).select('-_id -__v').lean();
return result; return result;
} }
public static async updateLot(lotCode: string, gid: number, price: number, incPrice: number) {
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;
}
} }
export const DividendModel = getModelForClass(Dividend); export const DividendModel = getModelForClass(Dividend);