Files
zclaw_openfang/crates/zclaw-saas/src/billing/mod.rs
iven 6721a1cc6e
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
fix(admin): 行业选择500修复 + 管理员切换订阅计划
- fix(industry): list_industries SQL参数编号错位 — count查询和items查询
  共用WHERE子句但参数从$3开始,sqlx bind按$1/$2顺序绑定导致500
- feat(billing): 新增 PUT /admin/accounts/:id/subscription 端点 (super_admin)
  验证目标计划 → 取消当前订阅 → 创建新订阅(30天) → 同步配额
- feat(admin-v2): Accounts.tsx 编辑弹窗新增「订阅计划」选择区
  显示所有活跃计划,保存时调用admin switch plan API
2026-04-14 19:06:58 +08:00

60 lines
2.6 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//! 计费模块 — 计划管理、订阅、用量配额、支付
pub mod types;
pub mod service;
pub mod handlers;
pub mod payment;
pub mod invoice_pdf;
use axum::routing::{get, post, put};
/// 全部计费路由(用于 main.rs 一次性挂载)
pub fn routes() -> axum::Router<crate::state::AppState> {
axum::Router::new()
.route("/api/v1/billing/plans", get(handlers::list_plans))
.route("/api/v1/billing/plans/:id", get(handlers::get_plan))
.route("/api/v1/billing/subscription", get(handlers::get_subscription))
.route("/api/v1/billing/usage", get(handlers::get_usage))
.route("/api/v1/billing/usage/increment", post(handlers::increment_usage_dimension))
.route("/api/v1/billing/payments", post(handlers::create_payment))
.route("/api/v1/billing/payments/:id", get(handlers::get_payment_status))
.route("/api/v1/billing/invoices/:id/pdf", get(handlers::get_invoice_pdf))
}
/// 计划查询路由(无需 AuthContext可挂载到公开区域
pub fn plan_routes() -> axum::Router<crate::state::AppState> {
axum::Router::new()
.route("/api/v1/billing/plans", get(handlers::list_plans))
.route("/api/v1/billing/plans/:id", get(handlers::get_plan))
}
/// 需要认证的计费路由(订阅、用量、支付、发票)
pub fn protected_routes() -> axum::Router<crate::state::AppState> {
axum::Router::new()
.route("/api/v1/billing/subscription", get(handlers::get_subscription))
.route("/api/v1/billing/usage", get(handlers::get_usage))
.route("/api/v1/billing/usage/increment", post(handlers::increment_usage_dimension))
.route("/api/v1/billing/payments", post(handlers::create_payment))
.route("/api/v1/billing/payments/:id", get(handlers::get_payment_status))
.route("/api/v1/billing/invoices/:id/pdf", get(handlers::get_invoice_pdf))
}
/// 支付回调路由(无需 auth — 支付宝/微信服务器回调)
pub fn callback_routes() -> axum::Router<crate::state::AppState> {
axum::Router::new()
.route("/api/v1/billing/callback/:method", post(handlers::payment_callback))
}
/// mock 支付页面路由(开发模式)
pub fn mock_routes() -> axum::Router<crate::state::AppState> {
axum::Router::new()
.route("/api/v1/billing/mock-pay", get(handlers::mock_pay_page))
.route("/api/v1/billing/mock-pay/confirm", post(handlers::mock_pay_confirm))
}
/// 管理员计费路由(需 super_admin 权限)
pub fn admin_routes() -> axum::Router<crate::state::AppState> {
axum::Router::new()
.route("/api/v1/admin/accounts/:id/subscription", put(handlers::admin_switch_subscription))
}