mirror of
https://github.com/woodchen-ink/openai-billing-query.git
synced 2025-07-18 14:01:59 +08:00
Merge pull request #19 from woodchen-ink:woodchen-ink/issue18
修复预付费额度账号的总额度显示问题
This commit is contained in:
commit
4a7edfc05a
@ -9,7 +9,7 @@ Telegram交流群:https://t.me/ai_cn2023
|
|||||||
|
|
||||||
## 最新示意图(2023.08.28)
|
## 最新示意图(2023.08.28)
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
|
||||||
## SESS ID获取方法
|
## SESS ID获取方法
|
||||||
|
23
static/js.js
23
static/js.js
@ -42,6 +42,7 @@ async function checkBilling(apiKey, apiUrl) {
|
|||||||
const urlsetid = apiUrl + '/v1/organizations';
|
const urlsetid = apiUrl + '/v1/organizations';
|
||||||
const urlPaymentmethods = `${apiUrl}/v1/dashboard/billing/payment_methods`;
|
const urlPaymentmethods = `${apiUrl}/v1/dashboard/billing/payment_methods`;
|
||||||
const urlRatelimits = `${apiUrl}/v1/dashboard/rate_limits`;
|
const urlRatelimits = `${apiUrl}/v1/dashboard/rate_limits`;
|
||||||
|
const urlAdvanceData = apiUrl + '/dashboard/billing/credit_grants'; // 预付费查询接口
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let totalAmount, totalUsage, remaining, GPT35CheckResult, GPT4CheckResult, GPT432kCheckResult, setid, isSubscrible;
|
let totalAmount, totalUsage, remaining, GPT35CheckResult, GPT4CheckResult, GPT432kCheckResult, setid, isSubscrible;
|
||||||
@ -55,9 +56,17 @@ async function checkBilling(apiKey, apiUrl) {
|
|||||||
const formattedDate = `${expiryDate.getFullYear()}-${(expiryDate.getMonth() + 1).toString().padStart(2, '0')}-${expiryDate.getDate().toString().padStart(2, '0')}`;
|
const formattedDate = `${expiryDate.getFullYear()}-${(expiryDate.getMonth() + 1).toString().padStart(2, '0')}-${expiryDate.getDate().toString().padStart(2, '0')}`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
totalAmount = subscriptionData.system_hard_limit_usd;
|
totalAmount = subscriptionData.hard_limit_usd;
|
||||||
|
|
||||||
if (totalAmount > 3) {
|
|
||||||
|
const advanceDataResponse = await fetch(urlAdvanceData, { headers });
|
||||||
|
const advanceData = await advanceDataResponse.json();
|
||||||
|
if ((subscriptionData.billing_mechanism === 'advance') || (totalAmount <= 6 && !subscriptionData.has_credit_card)) {
|
||||||
|
totalAmount = advanceData.total_granted;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (totalAmount > 6) {
|
||||||
startDate = subDate;
|
startDate = subDate;
|
||||||
urlUsage = `${apiUrl}/v1/dashboard/billing/usage?start_date=${formatDate(startDate)}&end_date=${formatDate(endDate)}`;
|
urlUsage = `${apiUrl}/v1/dashboard/billing/usage?start_date=${formatDate(startDate)}&end_date=${formatDate(endDate)}`;
|
||||||
response = await fetch(urlUsage, { headers });
|
response = await fetch(urlUsage, { headers });
|
||||||
@ -66,11 +75,13 @@ async function checkBilling(apiKey, apiUrl) {
|
|||||||
response = await fetch(urlUsage, { headers });
|
response = await fetch(urlUsage, { headers });
|
||||||
const usageData = await response.json();
|
const usageData = await response.json();
|
||||||
totalUsage = usageData.total_usage / 100;
|
totalUsage = usageData.total_usage / 100;
|
||||||
remaining = currentDate > expiryDate ? "❌过期" : (totalAmount - totalUsage).toFixed(3);
|
remaining = (totalAmount - totalUsage).toFixed(3);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
errors['subscription'] = error.message;
|
errors['subscription'] = error.message;
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取是否绑卡
|
//获取是否绑卡
|
||||||
try {
|
try {
|
||||||
if (subscriptionData.plan.id.includes('payg')) {
|
if (subscriptionData.plan.id.includes('payg')) {
|
||||||
@ -254,8 +265,6 @@ function sendRequest() {
|
|||||||
let apiUrlSelect = document.getElementById("api-url-select");
|
let apiUrlSelect = document.getElementById("api-url-select");
|
||||||
let customUrlInput = document.getElementById("custom-url-input");
|
let customUrlInput = document.getElementById("custom-url-input");
|
||||||
let table = document.getElementById("result-table");
|
let table = document.getElementById("result-table");
|
||||||
// let h2 = document.getElementById("result-head");
|
|
||||||
// h2.style.visibility = "visible";
|
|
||||||
table.style.visibility = "visible";
|
table.style.visibility = "visible";
|
||||||
|
|
||||||
if (apiKeyInput.value.trim() === "") {
|
if (apiKeyInput.value.trim() === "") {
|
||||||
@ -336,7 +345,7 @@ function sendRequest() {
|
|||||||
|
|
||||||
let totalUsedCell = document.createElement("td");
|
let totalUsedCell = document.createElement("td");
|
||||||
if (!isNaN(data[1])) {
|
if (!isNaN(data[1])) {
|
||||||
totalUsedCell.textContent = data[1].toFixed(3);
|
totalUsedCell.textContent = data[1];
|
||||||
} else {
|
} else {
|
||||||
totalUsedCell.textContent = '❌'
|
totalUsedCell.textContent = '❌'
|
||||||
}
|
}
|
||||||
@ -473,7 +482,7 @@ function sendRequest() {
|
|||||||
queriedApiKeys = [];
|
queriedApiKeys = [];
|
||||||
}
|
}
|
||||||
serialNumber++; // 增加序列号
|
serialNumber++; // 增加序列号
|
||||||
h2.style.display = 'block';
|
// h2.style.display = 'block';
|
||||||
table.style.display = 'table';
|
table.style.display = 'table';
|
||||||
|
|
||||||
hideLoadingAnimation();
|
hideLoadingAnimation();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user