现金流洞察 — AI增强后端 with Xano

发布: (2025年12月14日 GMT+8 20:26)
6 min read
原文: Dev.to

Source: Dev.to

我构建的内容

逾期付款和不可预测的现金流入是中小企业面临的最大运营风险之一。虽然大多数会计工具能够记录发票和付款,但它们很少提供关于 现金何时实际到账哪些客户风险最高、或 企业下一步应采取何种行动 的可操作洞察。因此,财务团队往往依赖电子表格、静态报告或直觉,导致收款延迟和流动性压力。

本项目通过提供一个 可直接投产的现金流情报 API 来填补这一空白,后端基于 Xano 构建。该 API 位于原始发票数据之上,将其转化为清晰的财务信号。它会聚合应收款、分析付款行为、识别高风险客户,并生成通俗易懂的洞察,解释不仅是 发生了什么,更是 为什么

解决的核心问题

  • 可视性不足 – 企业难以了解其应收款中真正可收回的部分与逾期且有风险的部分的比例。
  • 风险检测延迟 – 高风险客户往往在发票严重逾期后才被识别。
  • 数据缺乏指引 – 仅有数字报告无法告诉团队应优先采取哪些行动。

API 功能

  • 计算应收账款的账龄和逾期敞口。
  • 基于实际未结余额预测近期现金流入。
  • 使用行为信号对客户进行付款风险排序。
  • 生成 AI 撰写的解释和建议,将财务数据转化为运营指引。

整个后端完全在 Xano 上实现,强调正确性、清晰度和真实场景的可用性。它能够处理边缘情况(如缺失数据),避免误导性参数,并提供干净的 API 合约,适用于仪表盘、财务工具或集成。最终,这是一项将碎片化发票数据转化为可操作现金流情报的后端服务,帮助企业将精力集中在最关键的地方。

API 文档

基础 URL

https://xbty-lwqs-omi0.m2.xano.io/api:HiJHfYhN

鉴权

所有端点都需要 API 密钥。通过 /signup 端点创建账户以获取密钥。

{
  "business_name": "example name"
}

示例 API 密钥: ec49f7f0-089b-47f8-9f74-b81e6e474fba

端点

POST /insert_invoice_data

插入一条新的发票记录。

请求

curl -X POST 'https://xbty-lwqs-omi0.m2.xano.io/api:HiJHfYhN/insert_invoice_data' \
  -H 'Content-Type: application/json' \
  -H 'x-api-key: 10ebbb4b-a128-479b-b7b9-550d79bcf7cd' \
  --data '{
    "invoice_amount": 250,
    "due_date": "2025-12-23",
    "invoice_date": "2025-12-13",
    "status": "unpaid",
    "paid_date": null,
    "customer_name": "Example_name",
    "Currency": "dollars",
    "invoice_number": "1"
}'

响应

{
  "message": "Invoice created successfully",
  "invoice": {
    "id": 411,
    "created_at": 1765656533022,
    "invoice_date": "2025-12-13",
    "customer_name": "Example_name",
    "business_id": 6,
    "due_date": "2025-12-23",
    "amount": 250,
    "status": "unpaid",
    "paid_date": null,
    "currency": "dollars",
    "invoice_number": 1
  }
}

GET /receivables_analytics

分析企业的应收账款,返回 DSO、账龄区间和逾期比例。

请求

curl -X GET 'https://xbty-lwqs-omi0.m2.xano.io/api:HiJHfYhN/receivables_analytics' \
  -H 'Content-Type: application/json' \
  -H 'x-api-key: ec49f7f0-089b-47f8-9f74-b81e6e474fba'

响应

{
  "response": {
    "days_sales_outstanding": 167.75147928994087,
    "ageing": {
      "0_30": 78.2,
      "31_60": 183.25,
      "61_90": 0,
      "90_plus": 0
    },
    "overdue": 70.08988334289538
  }
}

POST /cashflow_forecast

基于当前发票数据预测现金流入。

请求

curl -X POST 'https://xbty-lwqs-omi0.m2.xano.io/api:HiJHfYhN/cashflow_forecast' \
  -H 'Content-Type: application/json' \
  -H 'x-api-key: 89d9f509-573e-4ff8-94c7-2457832483ca'

响应

{
  "forecast": {
    "expected_inflows": {
      "0_30_days": 234.37,
      "31_60_days": 0,
      "61_90_days": 0
    },
    "assumptions": {
      "average_delay_days": 26
    }
  }
}

POST /calculate_risk_score

对特定客户进行风险分析。将 ai_notes 设置为 1 可获得 AI 生成的通俗说明(由 Google Gemini 提供支持)。

请求

curl -X POST 'https://xbty-lwqs-omi0.m2.xano.io/api:HiJHfYhN/calculate_risk_score' \
  -H 'Content-Type: application/json' \
  -H 'x-api-key: 89d9f509-573e-4ff8-94c7-2457832483ca' \
  --data '{
    "ai_notes": 1,
    "customer_name": "Judith Morales"
}'

响应

{
  "risk_data": {
    "customer_name": "Judith Morales",
    "score": 31,
    "risk_level": "High",
    "late_payment_probability": 1
  },
  "ai_note": "Despite a low percentage of late invoices and no significant long‑term overdues, the \"High\" risk level is primarily driven by the substantial average payment delay of 49 days. This indicates consistent cash‑flow inefficiencies or slow internal payment processes for the customer, impacting your working capital. We recommend shortening payment terms or requiring partial upfront payments to mitigate exposure and improve cash conversion."
}

POST /business_dashboard

汇总所有分析(应收、预测、风险),返回风险最高的前 5 位客户以及业务现金流健康的 AI 摘要。

请求

curl -X POST 'https://xbty-lwqs-omi0.m2.xano.io/api:HiJHfYhN/business_dashboard' \
  -H 'Content-Type: application/json' \
  -H 'x-api-key: ec49f7f0-089b-47f8-9f74-b81e6e474fba'

响应

{
  "stats": {
    "dso": 167.75147928994087,
    "overdue_percent": 70.08988334289538,
    "total_ar_0_30": 78.2,
    "total_ar_31_60": 183.25,
    "total_ar_61_90": 0,
    "total_ar_90_plus": 0,
    "forecast_0_30": 261.45,
    "forecast_31_60": 0,
    "forecast_61_90": 0
  },
  "risky_customers": {
    "itemsReceived": 5,
    "items": [
      {
        "customer_name": "Sue Grant",
        "score": 20,
        "risk_level": "High",
        "late_payment_probability": 1
      },
      {
        "customer_name": "Philip Herrera",
        "score": 23,
        "risk_level": "High",
        "late_payment_probability": 1
      },
      {
        "customer_name": "Elsie Dunn",
        "score": 56,
        "risk_level": "Medium",
        "late_payment_probability": 1
      },
      {
        "customer_name": "Katie Weaver",
        "score": 100,
        "risk_level": "Low",
        "late_payment_probability": 0
      },
      {
        "customer_name": "Terry Ortiz",
        "score": 100,
        "risk_level": "Low",
        "late_payment_probability": 0
      }
    ]
  },
  "summary": "Your accounts receivable health is concerning. Your Days Sales Outstanding (DSO) is very high at 168 days, indicating very slow collections. An alarming 70% of your current receivables are overdue, with a significant amount ($183.25) already 31‑60 days past due. While you forecast $261.45 in cash inflows for the next 30 days, there are no significant inflows projected beyond that for the 31‑90 day period. This gap is critical, especially considering the large existing overdue balance from 31‑60 days. High‑risk customers like Sue Grant, Philip Herrera, and Elsie Dunn are very likely to cause payment delays, directly impacting cash conversion."
}
Back to Blog

相关文章

阅读更多 »