|
@@ -199,24 +199,23 @@ export const PUT = withAuth(async (request) => {
|
|
|
{ status: 404 }
|
|
|
);
|
|
|
}
|
|
|
- console.log('exchangeHistory=' + exchangeHistory)
|
|
|
- console.log('exchangeHistorypoints=' + exchangeHistory.points)
|
|
|
+
|
|
|
+ const exchangeItem = await ExchangeItem.findById(exchangeHistory.item);
|
|
|
// 更新用户积分
|
|
|
const updatedUser = await User.findByIdAndUpdate(
|
|
|
exchangeHistory.userId,
|
|
|
- { $inc: { points: +exchangeHistory.points } },
|
|
|
+ { $inc: { points: +exchangeItem.points } },
|
|
|
{ new: true, runValidators: true }
|
|
|
);
|
|
|
|
|
|
if (!updatedUser) {
|
|
|
throw new Error("更新用户积分失败");
|
|
|
}
|
|
|
- const exchangeItem = await ExchangeItem.findById(exchangeHistory.item);
|
|
|
// 创建积分加减历史记录
|
|
|
const reason = `返还: ${exchangeItem.title.replace(/<[^>]*>/g, "").trim()} 积分`;
|
|
|
const pointHistory = new PointHistory({
|
|
|
user: updatedUser._id,
|
|
|
- points: +exchangeHistory.points,
|
|
|
+ points: +exchangeItem.points,
|
|
|
reason: reason,
|
|
|
});
|
|
|
await pointHistory.save();
|