feat: admin billing API — DeepSeek + SiliconFlow balances
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 38s
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 38s
This commit is contained in:
parent
ee6ef23fb2
commit
c6aa4cf88a
18
src/modules/admin-billing/admin-billing.controller.ts
Normal file
18
src/modules/admin-billing/admin-billing.controller.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { Controller, Get, UseGuards } from '@nestjs/common';
|
||||
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
|
||||
import { AdminBillingService } from './admin-billing.service';
|
||||
import { AdminAuthGuard } from '../../common/guards/admin-auth.guard';
|
||||
import { AdminRoles } from '../../common/decorators/admin-roles.decorator';
|
||||
import type { AdminRole } from '../../common/types/admin-role.enum';
|
||||
|
||||
@ApiTags('admin-billing')
|
||||
@Controller('admin-api/billing')
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
export class AdminBillingController {
|
||||
constructor(private readonly svc: AdminBillingService) {}
|
||||
@Get()
|
||||
@AdminRoles('SUPER_ADMIN' as AdminRole)
|
||||
@ApiOperation({ summary: 'API 用量与费用' })
|
||||
async get() { return this.svc.getAllBilling(); }
|
||||
}
|
||||
6
src/modules/admin-billing/admin-billing.module.ts
Normal file
6
src/modules/admin-billing/admin-billing.module.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { AdminBillingController } from './admin-billing.controller';
|
||||
import { AdminBillingService } from './admin-billing.service';
|
||||
import { AdminAuthGuard } from '../../common/guards/admin-auth.guard';
|
||||
@Module({ controllers: [AdminBillingController], providers: [AdminBillingService, AdminAuthGuard] })
|
||||
export class AdminBillingModule {}
|
||||
34
src/modules/admin-billing/admin-billing.service.ts
Normal file
34
src/modules/admin-billing/admin-billing.service.ts
Normal file
@ -0,0 +1,34 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
|
||||
export interface BillingInfo {
|
||||
name: string; model: string; balance: string; currency: string; status: 'ok' | 'unknown'; consoleUrl: string; note: string;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class AdminBillingService {
|
||||
private readonly logger = new Logger(AdminBillingService.name);
|
||||
|
||||
async getAllBilling(): Promise<{ providers: BillingInfo[] }> {
|
||||
const [deepseek, siliconflow] = await Promise.all([this.getDeepSeek(), this.getSiliconFlow()]);
|
||||
return { providers: [deepseek, siliconflow, this.getMiniMax(), this.getBaiduOcr()] };
|
||||
}
|
||||
|
||||
private async getDeepSeek(): Promise<BillingInfo> {
|
||||
try {
|
||||
const r = await fetch('https://api.deepseek.com/user/balance', { headers: { Authorization: 'Bearer sk-ddddea4986d843be978ced9e82988fa0' } });
|
||||
const d = await r.json(); const b = d?.balance_infos?.[0]?.total_balance;
|
||||
return { name: 'DeepSeek', model: 'v4-flash / deepseek-chat', balance: b ? `¥${b}` : '—', currency: 'CNY', status: 'ok', consoleUrl: 'https://platform.deepseek.com', note: '充值余额' };
|
||||
} catch { return { name: 'DeepSeek', model: 'v4-flash', balance: '—', currency: 'CNY', status: 'unknown', consoleUrl: 'https://platform.deepseek.com', note: '查询失败' }; }
|
||||
}
|
||||
|
||||
private async getSiliconFlow(): Promise<BillingInfo> {
|
||||
try {
|
||||
const r = await fetch('https://api.siliconflow.cn/v1/user/info', { headers: { Authorization: 'Bearer sk-jdtqzgrlneklatdmymscrnvljvzlkkxcrzylznufpgggswjz' } });
|
||||
const d = await r.json(); const b = d?.data?.totalBalance;
|
||||
return { name: '硅基流动', model: 'BGE-M3 / BGE-Reranker', balance: b ? `¥${b}` : '—', currency: 'CNY', status: 'ok', consoleUrl: 'https://cloud.siliconflow.cn', note: '充值 + 赠送' };
|
||||
} catch { return { name: '硅基流动', model: 'Embedding/Rerank', balance: '—', currency: 'CNY', status: 'unknown', consoleUrl: 'https://cloud.siliconflow.cn', note: '查询失败' }; }
|
||||
}
|
||||
|
||||
private getMiniMax(): BillingInfo { return { name: 'MiniMax', model: 'MiniMax 2.7', balance: '点数制', currency: 'points', status: 'unknown', consoleUrl: 'https://platform.minimaxi.com', note: '需登录控制台查看' }; }
|
||||
private getBaiduOcr(): BillingInfo { return { name: '百度 OCR', model: '通用文字识别', balance: '次数制', currency: 'calls', status: 'unknown', consoleUrl: 'https://console.bce.baidu.com', note: '需登录控制台查看' }; }
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user