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(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
60 lines
2.6 KiB
Rust
60 lines
2.6 KiB
Rust
//! 计费模块 — 计划管理、订阅、用量配额、支付
|
||
|
||
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))
|
||
}
|