若干更新迭代

This commit is contained in:
andy committed 2026-10-02 19:56:32 +08:00
1 parent deb9cc5bcf
commit 4ac786aafb
64 files changed
+3251 -291

No files matched your search

+34
View File
@@ -36,6 +36,8 @@ func (h *billingHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
switch {
case r.URL.Path == "/api/billing":
h.billing(w, r)
case r.URL.Path == "/api/billing/balance":
h.balance(w, r)
case r.URL.Path == "/api/billing/quote":
h.quote(w, r)
case r.URL.Path == "/api/admin/billing":
@@ -53,6 +55,38 @@ func (h *billingHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
}
func (h *billingHandler) balance(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "no-store")
if !allow(w, r, http.MethodGet) {
return
}
session, ok := h.authorize(w, r, PlatformApp)
if !ok {
return
}
organizationID := session.User.OrganizationID
if organizationID == "" {
writeAPIError(w, 422, "当前账号未绑定组织。")
return
}
if h.service == nil {
writeAPIError(w, 500, "服务器内部错误。")
return
}
wallet, err := h.service.Wallet(r.Context(), organizationID)
if err != nil {
writeDomainError(w, err)
return
}
writeJSON(w, 200, struct {
Organization map[string]string `json:"organization"`
Wallet billing.Wallet `json:"wallet"`
}{
Organization: map[string]string{"id": organizationID, "name": first(session.User.OrganizationName, organizationID)},
Wallet: wallet,
})
}
func (h *billingHandler) billing(w http.ResponseWriter, r *http.Request) {
if !allow(w, r, http.MethodGet) {
return