merge dev2.0
This commit is contained in:
@@ -12,30 +12,34 @@ export const pushBill = async ({
|
||||
chatId: string;
|
||||
textLen: number;
|
||||
}) => {
|
||||
await connectToDatabase();
|
||||
|
||||
const modelItem = ModelList.find((item) => item.model === modelName);
|
||||
|
||||
if (!modelItem) return;
|
||||
|
||||
const price = modelItem.price * textLen;
|
||||
|
||||
let billId;
|
||||
try {
|
||||
// 插入 Bill 记录
|
||||
const res = await Bill.create({
|
||||
userId,
|
||||
chatId,
|
||||
textLen,
|
||||
price
|
||||
});
|
||||
billId = res._id;
|
||||
await connectToDatabase();
|
||||
|
||||
// 扣费
|
||||
await User.findByIdAndUpdate(userId, {
|
||||
$inc: { balance: -price }
|
||||
});
|
||||
const modelItem = ModelList.find((item) => item.model === modelName);
|
||||
|
||||
if (!modelItem) return;
|
||||
|
||||
const price = modelItem.price * textLen;
|
||||
|
||||
let billId;
|
||||
try {
|
||||
// 插入 Bill 记录
|
||||
const res = await Bill.create({
|
||||
userId,
|
||||
chatId,
|
||||
textLen,
|
||||
price
|
||||
});
|
||||
billId = res._id;
|
||||
|
||||
// 扣费
|
||||
await User.findByIdAndUpdate(userId, {
|
||||
$inc: { balance: -price }
|
||||
});
|
||||
} catch (error) {
|
||||
billId && Bill.findByIdAndDelete(billId);
|
||||
}
|
||||
} catch (error) {
|
||||
billId && Bill.findByIdAndDelete(billId);
|
||||
console.log(error);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user