mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-30 10:28:42 +00:00
fix: bill, app detail
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
@@ -20,7 +20,7 @@ const ShareChatSchema = new Schema({
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
tokens: {
|
||||
total: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
|
@@ -25,7 +25,10 @@ export const generateToken = (userId: string) => {
|
||||
|
||||
/* set cookie */
|
||||
export const setCookie = (res: NextApiResponse, userId: string) => {
|
||||
res.setHeader('Set-Cookie', `token=${generateToken(userId)}; Path=/; HttpOnly; Max-Age=604800`);
|
||||
res.setHeader(
|
||||
'Set-Cookie',
|
||||
`token=${generateToken(userId)}; Path=/; HttpOnly; Max-Age=604800; Samesite=None; Secure;`
|
||||
);
|
||||
};
|
||||
/* clear cookie */
|
||||
export const clearCookie = (res: NextApiResponse) => {
|
||||
|
Reference in New Issue
Block a user