拍卖行:出价后更新分红
This commit is contained in:
@@ -63,8 +63,9 @@ export class AuctionHandler {
|
||||
bidRoles.push({roleId, price: newPrice, time: new Date()});
|
||||
const newLot = await LotModel.updateLot({ code, curBuyer: roleId, curPrice: newPrice, bidRoles});
|
||||
|
||||
// TODO 更新分红
|
||||
return resResult(STATUS.SUCCESS, { lot: newLot });
|
||||
const incPrice = newPrice - (curBuyer ? curPrice : 0);
|
||||
const dividend = await DividendModel.updateLot(code, gid, newPrice, incPrice);
|
||||
return resResult(STATUS.SUCCESS, { lot: newLot, dividend });
|
||||
}
|
||||
|
||||
async watchLot(msg: { code: string }, session: BackendSession) {
|
||||
|
||||
@@ -9,7 +9,8 @@ import { genCode } from '../pubUtils/util';
|
||||
@modelOptions({ schemaOptions: { id: false } })
|
||||
@index({ code: 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 {
|
||||
@prop({ required: true, default: 0 })
|
||||
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();
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user