道具:消耗资源
This commit is contained in:
+4
-4
@@ -1,6 +1,5 @@
|
|||||||
import BaseModel from './BaseModel';
|
import BaseModel from './BaseModel';
|
||||||
import { index, getModelForClass, prop, DocumentType, modelOptions } from '@typegoose/typegoose';
|
import { index, getModelForClass, prop, DocumentType, modelOptions } from '@typegoose/typegoose';
|
||||||
import { findIndex } from 'underscore';
|
|
||||||
import { BAG } from '../pubUtils/dicParam';
|
import { BAG } from '../pubUtils/dicParam';
|
||||||
import { SearchItemParam } from '../domain/backEndField/search';
|
import { SearchItemParam } from '../domain/backEndField/search';
|
||||||
// const Transaction = require("mongoose-transactions");
|
// const Transaction = require("mongoose-transactions");
|
||||||
@@ -70,9 +69,10 @@ export default class Item extends BaseModel {
|
|||||||
rec = await ItemModel.findOneAndUpdate({ roleId, id }, { $inc: { count: ratio * count } }, { new: true, upsert: true }).lean(lean);
|
rec = await ItemModel.findOneAndUpdate({ roleId, id }, { $inc: { count: ratio * count } }, { new: true, upsert: true }).lean(lean);
|
||||||
}
|
}
|
||||||
if (!!rec) {
|
if (!!rec) {
|
||||||
let index = findIndex(result,{id})
|
let index = result.findIndex(cur => cur.id == rec.id);
|
||||||
if (!!result[index]) {
|
if (index != -1) {
|
||||||
result[index] = { id: rec.id, count: rec.count, inc: -count }
|
result[index].count = rec.count;
|
||||||
|
result[index].inc += -count;
|
||||||
} else {
|
} else {
|
||||||
result.push({ id: rec.id, count: rec.count, inc: -count });
|
result.push({ id: rec.id, count: rec.count, inc: -count });
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user