# 錢包資訊（進階介面API）

使用 **帳戶權限金鑰** 唯讀查詢目前個人帳戶的錢包資金明細、歷史消耗彙總、推廣返佣統計、模型專屬折扣以及儲值與帳變歷史紀錄。

> [!IMPORTANT]
> - **Base URL**：`https://ai.artsmcp.com/api/open/v1`
> - **驗證請求標頭（三選一）**：`Authorization: Bearer <your_account_key>`、`X-Account-Api-Key: <your_account_key>` 或 `X-Api-Key: <your_account_key>`
> - **可用資金說明**：`available_funds` 綜合計算現金餘額（`balance`）、平台贈送金（`gift_balance`）與授信額度（`credit_limit`）；當 `balance + credit_limit < 0` 時，`cash_in_arrears` 回傳 `true`

---

### 1. 取得個人錢包餘額與佣金統計

查詢個人錢包即時餘額、累計消耗統計、推廣佣金餘額與邀請人數，以及目前帳號生效中的單模型專屬折扣清單與結算幣種。

* **路徑**：`GET /api/open/v1/wallet`
* **查詢參數 (Query)**：無
* **呼叫範例 (Curl)**：

```bash
curl -s "https://ai.artsmcp.com/api/open/v1/wallet" \
  -H "Authorization: Bearer <your_account_key>"
```

* **回應範例**：

```json
{
  "balance": 500.0,
  "gift_balance": 20.0,
  "credit_limit": 0.0,
  "available_funds": 520.0,
  "cash_in_arrears": false,
  "total_consumption": 133.5,
  "used_quota": 128.5,
  "gift_used_quota": 5.0,
  "commission_balance": 35.2,
  "total_referred": 6,
  "marketing_enabled": true,
  "commission_ratio": 0.1,
  "commission_basis": "consumption",
  "discounted_models": [],
  "currency": "CNY",
  "currency_symbol": "¥",
  "currency_unit": "元"
}
```

* **回傳欄位說明**：

| 欄位名 | 類型 | 說明 |
| :--- | :--- | :--- |
| `balance` | `number` | 現金錢包餘額 |
| `gift_balance` | `number` | 平台贈送金錢包餘額 |
| `credit_limit` | `number` | 帳戶授信透支額度 |
| `available_funds` | `number` | 綜合可用總額（`balance + gift_balance + credit_limit`；現金欠費時如實回傳負值） |
| `cash_in_arrears` | `boolean` | 是否處於現金透支欠費狀態（`balance + credit_limit < 0` 時為 `true`） |
| `total_consumption` | `number` | 歷史累計總消耗金額（`used_quota + gift_used_quota`） |
| `used_quota` | `number` | 現金錢包累計實扣消耗金額 |
| `gift_used_quota` | `number` | 贈送錢包累計實扣消耗金額 |
| `commission_balance` | `number` | 推廣返佣錢包目前餘額 |
| `total_referred` | `integer` | 累計成功邀請註冊人數 |
| `marketing_enabled` | `boolean` | 目前用戶等級是否開啟推廣返佣權益 |
| `commission_ratio` | `number` | 推廣返佣比例（如 `0.1` 表示 10%） |
| `commission_basis` | `string` | 返佣核算基準（`consumption` 依消費 / `recharge` 依儲值） |
| `discounted_models` | `array` | 目前帳號單獨設定且生效中的模型專屬折扣清單 |
| `currency` / `currency_symbol` / `currency_unit` | `string` | 站點結算幣種代碼、符號與單位名稱 |

---

### 2. 查詢錢包儲值與帳變紀錄

分頁查詢個人錢包的線上儲值訂單、兌換碼入帳與帳變明細（時間統一依站點營運時區輸出）。

* **路徑**：`GET /api/open/v1/wallet/recharges`
* **查詢參數 (Query)**：

| 參數名 | 類型 | 預設值 | 說明 |
| :--- | :--- | :--- | :--- |
| `page` | `integer` | `1` | 頁碼（從 `1` 開始） |
| `per_page` | `integer` | `20` | 每頁筆數（範圍 `1..100`） |
| `wallet_type` | `string` | 全部 | 依錢包類型篩選：`system`（現金錢包）或 `gift`（贈送錢包） |
| `recharge_type` | `string` | 全部 | 依入帳類型篩選（如 `alipay`、`wechat`、`stripe`、`redemption`、`transfer`） |

* **呼叫範例 (Curl)**：

```bash
curl -s "https://ai.artsmcp.com/api/open/v1/wallet/recharges?page=1&per_page=20" \
  -H "Authorization: Bearer <your_account_key>"
```

* **回應範例**：

```json
{
  "data": [
    {
      "amount": 100.0,
      "recharge_type": "wechat",
      "wallet_type": "system",
      "order_no": "ORD202611292015001234",
      "fee_amount": 0.0,
      "remark": "線上儲值",
      "created_at": "2026-11-29 20:15:08 (UTC+8)"
    }
  ],
  "total": 1,
  "page": 1,
  "per_page": 20
}
```

* **回傳欄位說明**：

| 欄位名 | 類型 | 說明 |
| :--- | :--- | :--- |
| `data` | `array` | 目前頁的儲值與帳變紀錄清單 |
| `data[].amount` | `number` | 變動金額（正數表示入帳，負數表示扣減） |
| `data[].recharge_type` | `string` | 入帳類型（如 `alipay`、`wechat`、`stripe`、`redemption`、`transfer`） |
| `data[].wallet_type` | `string` | 所屬錢包類型：`system`（現金錢包）或 `gift`（贈送錢包） |
| `data[].order_no` | `string` | 關聯支付訂單號（僅線上儲值紀錄回傳，無訂單號時省略） |
| `data[].fee_amount` | `number` | 線上儲值對應的支付手續費（非線上儲值時為 `0`） |
| `data[].remark` | `string` | 帳變備註說明（無備註時省略） |
| `data[].created_at` | `string` | 紀錄建立時間（依站點營運時區格式化） |
| `total` | `integer` | 符合篩選條件的總筆數 |
| `page` / `per_page` | `integer` | 目前頁碼與每頁筆數 |
