Skip to content

Commit

Permalink
Merge pull request #19 from woodchen-ink:woodchen-ink/issue18
Browse files Browse the repository at this point in the history
修复预付费额度账号的总额度显示问题
  • Loading branch information
woodchen-ink authored Sep 1, 2023
2 parents 44b1153 + c35af31 commit 4a7edfc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Telegram交流群:https://t.me/ai_cn2023

## 最新示意图(2023.08.28)

![1693240108324.png](https://cdn-img.czl.net/2023/09/01/64f1a1dbf0e93.png)
![示意图](https://cdn-img.czl.net/2023/09/01/64f1ab8497308.png)


## SESS ID获取方法
Expand Down
23 changes: 16 additions & 7 deletions static/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ async function checkBilling(apiKey, apiUrl) {
const urlsetid = apiUrl + '/v1/organizations';
const urlPaymentmethods = `${apiUrl}/v1/dashboard/billing/payment_methods`;
const urlRatelimits = `${apiUrl}/v1/dashboard/rate_limits`;
const urlAdvanceData = apiUrl + '/dashboard/billing/credit_grants'; // 预付费查询接口

try {
let totalAmount, totalUsage, remaining, GPT35CheckResult, GPT4CheckResult, GPT432kCheckResult, setid, isSubscrible;
Expand All @@ -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')}`;

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;
urlUsage = `${apiUrl}/v1/dashboard/billing/usage?start_date=${formatDate(startDate)}&end_date=${formatDate(endDate)}`;
response = await fetch(urlUsage, { headers });
Expand All @@ -66,11 +75,13 @@ async function checkBilling(apiKey, apiUrl) {
response = await fetch(urlUsage, { headers });
const usageData = await response.json();
totalUsage = usageData.total_usage / 100;
remaining = currentDate > expiryDate ? "❌过期" : (totalAmount - totalUsage).toFixed(3);
remaining = (totalAmount - totalUsage).toFixed(3);

} catch (error) {
console.error(error);
errors['subscription'] = error.message;
}

//获取是否绑卡
try {
if (subscriptionData.plan.id.includes('payg')) {
Expand Down Expand Up @@ -254,8 +265,6 @@ function sendRequest() {
let apiUrlSelect = document.getElementById("api-url-select");
let customUrlInput = document.getElementById("custom-url-input");
let table = document.getElementById("result-table");
// let h2 = document.getElementById("result-head");
// h2.style.visibility = "visible";
table.style.visibility = "visible";

if (apiKeyInput.value.trim() === "") {
Expand Down Expand Up @@ -336,7 +345,7 @@ function sendRequest() {

let totalUsedCell = document.createElement("td");
if (!isNaN(data[1])) {
totalUsedCell.textContent = data[1].toFixed(3);
totalUsedCell.textContent = data[1];
} else {
totalUsedCell.textContent = '❌'
}
Expand Down Expand Up @@ -473,7 +482,7 @@ function sendRequest() {
queriedApiKeys = [];
}
serialNumber++; // 增加序列号
h2.style.display = 'block';
// h2.style.display = 'block';
table.style.display = 'table';

hideLoadingAnimation();
Expand Down

0 comments on commit 4a7edfc

Please sign in to comment.