fix: bill, app detail

This commit is contained in:
archer
2023-07-19 08:36:06 +08:00
parent 58cbf10c85
commit 7a76f54148
12 changed files with 64 additions and 42 deletions

View File

@@ -47,7 +47,7 @@ export const pushTaskBillListItem = async ({
});
} catch (error) {}
};
export const finishTaskBill = async ({ billId }: { billId: string }) => {
export const finishTaskBill = async ({ billId, shareId }: { billId: string; shareId?: string }) => {
try {
// update bill
const res = await Bill.findByIdAndUpdate(billId, [
@@ -63,6 +63,13 @@ export const finishTaskBill = async ({ billId }: { billId: string }) => {
if (!res) return;
const total = res.list.reduce((sum, item) => sum + item.amount, 0) || 0;
if (shareId) {
updateShareChatBill({
shareId,
total
});
}
console.log('finish bill:', formatPrice(total));
// 账号扣费
@@ -85,16 +92,19 @@ export const delTaskBill = async (billId?: string) => {
export const updateShareChatBill = async ({
shareId,
tokens
total
}: {
shareId: string;
tokens: number;
total: number;
}) => {
try {
await ShareChat.findByIdAndUpdate(shareId, {
$inc: { tokens },
lastTime: new Date()
});
await ShareChat.findOneAndUpdate(
{ shareId },
{
$inc: { total },
lastTime: new Date()
}
);
} catch (error) {
console.log('update shareChat error', error);
}