From d836d7db1e6288f4c00210949aa9ae9a4b02431a Mon Sep 17 00:00:00 2001 From: "1173117610@qq.com" Date: Tue, 23 Jun 2026 15:03:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/vcs.xml | 4 ++- server.php | 79 +++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 73 insertions(+), 10 deletions(-) diff --git a/.idea/vcs.xml b/.idea/vcs.xml index d843f34..94a25f7 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,4 +1,6 @@ - + + + \ No newline at end of file diff --git a/server.php b/server.php index 75ff686..df7168f 100644 --- a/server.php +++ b/server.php @@ -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();