This commit is contained in:
1173117610@qq.com 2026-06-23 15:03:54 +08:00
parent e17684e776
commit d836d7db1e
2 changed files with 73 additions and 10 deletions

View File

@ -1,4 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings" defaultProject="true" />
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -13,11 +13,43 @@ $token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwd2QiOiI2ODI5N2FjYzUwZDczYWQzZ
$server = Server::builder()
->setServerInfo('Merchant MCP', '1.0.0')
->addTool(
handler: function () use ($token): array {
handler: function (
?string $date = null,
?int $status = null,
?string $keyword = null,
?string $fieldKey = null,
?string $payType = null,
?string $type = null,
?int $btcId = null,
) use ($token): array {
$client = new Client([
'timeout' => 10,
]);
// page、limit 由 MCP 内部固定,不开放给 AI 配置
$query = [
'status' => $status ?? -1,
'field_key' => $fieldKey ?? 'all',
'page' => 1,
'limit' => 100,
'time' => $date ?? date('Y/m/d') . '-' . date('Y/m/d'),
];
// 仅在传入非空值时追加可选筛选条件
// 注意API 搜索关键词参数是 real_name不是 data
if ($keyword !== null && $keyword !== '') {
$query['real_name'] = $keyword;
}
if ($payType !== null && $payType !== '') {
$query['pay_type'] = $payType;
}
if ($type !== null && $type !== '') {
$query['type'] = $type;
}
if ($btcId !== null && $btcId > 0) {
$query['btc_id'] = $btcId;
}
$response = $client->get(
'https://tpoint.agrimedia.cn/adminapi/offline/list',
[
@ -25,13 +57,7 @@ $server = Server::builder()
'accept' => 'application/json',
'authori-zation' => 'Bearer ' . $token,
],
'query' => [
'status' => -1,
'field_key' => 'all',
'page' => 1,
'limit' => 100,
'time' => '2026/06/23-2026/06/23',
],
'query' => $query,
]
);
@ -72,10 +98,45 @@ $server = Server::builder()
'successOrderCount' => $successOrderCount,
'totalOrderAmount' => round($totalOrderAmount, 2),
'totalRealPay' => round($totalRealPay, 2),
// 调试信息:实际发送给 API 的查询参数
'_debug_query' => $query,
];
},
name: 'get_order_summary',
description: '获取订单总数、活跃商户数、成功订单数和金额统计'
description: '获取订单总数、活跃商户数、成功订单数和金额统计。可按日期、状态、关键词、搜索字段、支付方式、订单类型、商户分类ID筛选。',
inputSchema: [
'type' => 'object',
'properties' => [
'date' => [
'type' => 'string',
'description' => '查询日期,格式如 2026/06/23-2026/06/23起止日期用 - 连接)。不传默认当天。',
],
'status' => [
'type' => 'integer',
'description' => '订单状态,-1 表示全部。不传默认 -1。',
],
'fieldKey' => [
'type' => 'string',
'description' => '搜索字段,对应接口的 field_key 参数。常用值order_sn按订单号搜索、all全部字段。不传默认 all。注意当 keyword 有值时,建议同时指定 fieldKey 以确保搜索生效。',
],
'keyword' => [
'type' => 'string',
'description' => '搜索关键词,对应接口的 data 参数。需配合 fieldKey 一起使用。',
],
'payType' => [
'type' => 'string',
'description' => '支付方式,对应接口的 pay_type 参数。',
],
'type' => [
'type' => 'string',
'description' => '订单类型,对应接口的 type 参数。',
],
'btcId' => [
'type' => 'integer',
'description' => '商户分类ID对应接口的 btc_id 参数。',
],
],
],
)
->build();