85 lines
1.9 KiB
Markdown
85 lines
1.9 KiB
Markdown
# Merchant AI HTTP API
|
|
|
|
PHP 8.2 JSON API service for merchant order statistics, offline order analysis, and merchant ranking.
|
|
|
|
## Environment
|
|
|
|
```bash
|
|
MERCHANT_API_TOKEN=your-admin-api-token
|
|
MERCHANT_API_BASE_URI=https://tpoint.agrimedia.cn
|
|
MERCHANT_API_TIMEOUT=10
|
|
```
|
|
|
|
`MERCHANT_API_TOKEN` is required. `MERCHANT_API_BASE_URI` and `MERCHANT_API_TIMEOUT` are optional.
|
|
|
|
## Start Locally
|
|
|
|
```bash
|
|
php -S 127.0.0.1:8080 server.php
|
|
```
|
|
|
|
## Response Format
|
|
|
|
Success:
|
|
|
|
```json
|
|
{
|
|
"success": true,
|
|
"data": {}
|
|
}
|
|
```
|
|
|
|
Error:
|
|
|
|
```json
|
|
{
|
|
"success": false,
|
|
"error": {
|
|
"code": "server_error",
|
|
"message": "error message"
|
|
}
|
|
}
|
|
```
|
|
|
|
## Endpoints
|
|
|
|
|
|
### `GET|POST /tools`
|
|
|
|
Returns available API tools and input schemas.
|
|
|
|
### `GET|POST /api/order-summary`
|
|
|
|
Returns order count, active merchant count, successful order count, and amount totals.
|
|
|
|
### `GET|POST /api/offline-orders/analyze`
|
|
|
|
Returns status, payment type, order type, and amount distribution analysis.
|
|
|
|
### `GET|POST /api/merchant-ranking`
|
|
|
|
Returns merchant ranking by `orderCount`, `successOrderCount`, `totalOrderAmount`, or `totalRealPay`.
|
|
|
|
## Common Parameters
|
|
|
|
- `date`: date range, for example `2026/06/23-2026/06/23`; defaults to today.
|
|
- `status`: order status; defaults to `-1`.
|
|
- `keyword`: search keyword, sent to upstream API as `real_name`.
|
|
- `fieldKey`: upstream `field_key`; defaults to `all`.
|
|
- `payType`: upstream `pay_type`.
|
|
- `type`: upstream order `type`.
|
|
- `btcId`: upstream merchant category ID.
|
|
|
|
`/api/merchant-ranking` also supports:
|
|
|
|
- `sortBy`: `orderCount`, `successOrderCount`, `totalOrderAmount`, or `totalRealPay`; defaults to `totalRealPay`.
|
|
- `limit`: number of merchants to return; defaults to `10`, max `100`.
|
|
|
|
## POST Example
|
|
|
|
```bash
|
|
curl -X POST http://127.0.0.1:8080/api/merchant-ranking \
|
|
-H "Content-Type: application/json" \
|
|
-d '{"date":"2026/06/23-2026/06/23","sortBy":"totalRealPay","limit":10}'
|
|
```
|