From 50eca2fca6024d6c31cf168cfbe9256843027dbc Mon Sep 17 00:00:00 2001 From: Christ Date: Thu, 20 Aug 2026 19:03:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=A5=91=E7=BA=A6=E4=B8=8E=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96=E9=97=AD=E7=8E=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 统一 multipart 请求透传并补齐接口契约和边界校验;新增 AI 自动改价、暂时性失败重试、擦亮与确认发货幂等处理;修复聊天已读回执跨端同步误报警,并更新前端静态资源与回归测试。 --- api/openapi.yaml | 73 ++++++- frontend/app/features/accounts/api.ts | 3 +- .../components/AccountAISettingsModal.tsx | 16 +- .../components/accountComponents.test.tsx | 9 +- frontend/app/features/accounts/hooks.ts | 1 + frontend/app/features/accounts/models.ts | 6 + .../features/accounts/submoduleHooks.test.tsx | 2 +- .../app/features/accounts/submoduleHooks.ts | 4 +- frontend/app/features/apiAdapters.test.ts | 189 ++++++++++-------- frontend/app/features/chat/api.ts | 35 ++-- frontend/app/features/items/api.ts | 6 +- frontend/app/features/orders/api.ts | 23 +-- frontend/shared/api-contract/client.test.ts | 100 +++++++++ frontend/shared/api-contract/client.ts | 28 +-- .../shared/api-contract/generated/schema.ts | 70 ++++++- internal/adapter/adapter_events.go | 9 +- internal/adapter/automation_repository.go | 48 +++++ internal/adapter/chat_read_receipt_test.go | 65 ++++++ internal/adapter/settings_repository.go | 29 ++- internal/application/automation/rules.go | 15 ++ internal/application/automation/rules_test.go | 24 +++ internal/application/settings/service.go | 20 ++ internal/application/settings/service_test.go | 31 +++ internal/automation/account_tasks.go | 14 ++ internal/automation/account_tasks_test.go | 34 ++++ internal/automation/action_executor.go | 79 +++++++- .../automation/adjust_price_action_test.go | 142 +++++++++++++ internal/automation/ai_pricing.go | 80 ++++++++ internal/automation/center.go | 4 + internal/automation/center_mock_mtop_test.go | 26 ++- .../browser/multipart_integration_test.go | 120 +++++++++++ internal/chat/service.go | 10 +- internal/db/ai_bargain_quote_test.go | 55 +++++ internal/db/ai_reply.go | 184 ++++++++++++++--- internal/db/automation.go | 14 ++ internal/db/chat.go | 5 +- internal/db/migrate_test.go | 8 +- .../mysql/00034_ai_bargain_auto_price.sql | 25 +++ .../postgres/00034_ai_bargain_auto_price.sql | 27 +++ .../sqlite/00034_ai_bargain_auto_price.sql | 28 +++ internal/db/store.go | 11 + internal/engine/ai.go | 76 ++++++- internal/engine/ai_test.go | 75 ++++++- internal/engine/reply.go | 22 ++ internal/engine/reply_extra_test.go | 35 ++++ internal/server/automation_rule_handlers.go | 16 ++ internal/server/card_batch_handlers.go | 7 +- internal/server/chat_handlers.go | 10 +- internal/server/extras_test.go | 5 +- internal/server/item_handlers.go | 7 +- .../server/item_publish_batch_handlers.go | 7 +- internal/server/order_import.go | 12 +- internal/server/order_refresh_job_handlers.go | 82 +++++++- internal/server/order_refresh_request_test.go | 98 +++++++++ internal/server/settings_handlers.go | 18 +- internal/server/success_api_contract_test.go | 4 +- internal/server/success_contract_support.go | 2 + internal/server/upload_limits.go | 42 +++- internal/server/upload_limits_test.go | 148 ++++++++++++++ .../static/assets/AccountList-CJjq4Hao.js | 3 - .../static/assets/AccountList-CZJPJAzU.js | 3 + ...dList-DmAKXVzi.js => CardList-BC38wNai.js} | 2 +- .../{Chat-B0sXFnFc.js => Chat-B7ZHVqg5.js} | 2 +- ...oard-COZgQmUP.js => Dashboard-BWfd6MyT.js} | 2 +- ...mList-BLPsnCuG.js => ItemList-BgZXwlJZ.js} | 4 +- ...-D90C7V4V.js => Notifications-DFdczI4g.js} | 2 +- .../webui/static/assets/OrderList-CIcqa_PS.js | 1 - .../webui/static/assets/OrderList-CMWPVZno.js | 1 + .../{Rules-B7fgxH9m.js => Rules-BaD_vse7.js} | 2 +- ...tings-BsnTwWjn.js => Settings-BOxCHLU8.js} | 2 +- .../webui/static/assets/index-2BJ5Kkse.js | 2 + .../webui/static/assets/index-6EQ70kIK.css | 1 + .../webui/static/assets/index-DawJY7_a.js | 2 - .../webui/static/assets/index-mo8bfmYY.css | 1 - internal/webui/static/index.html | 4 +- internal/xianyu/mtop/account_tasks.go | 7 +- internal/xianyu/mtop/account_tasks_test.go | 33 +++ 77 files changed, 2138 insertions(+), 274 deletions(-) create mode 100644 frontend/shared/api-contract/client.test.ts create mode 100644 internal/adapter/chat_read_receipt_test.go create mode 100644 internal/automation/ai_pricing.go create mode 100644 internal/browser/multipart_integration_test.go create mode 100644 internal/db/ai_bargain_quote_test.go create mode 100644 internal/db/migrations/mysql/00034_ai_bargain_auto_price.sql create mode 100644 internal/db/migrations/postgres/00034_ai_bargain_auto_price.sql create mode 100644 internal/db/migrations/sqlite/00034_ai_bargain_auto_price.sql create mode 100644 internal/server/order_refresh_request_test.go create mode 100644 internal/server/upload_limits_test.go delete mode 100644 internal/webui/static/assets/AccountList-CJjq4Hao.js create mode 100644 internal/webui/static/assets/AccountList-CZJPJAzU.js rename internal/webui/static/assets/{CardList-DmAKXVzi.js => CardList-BC38wNai.js} (99%) rename internal/webui/static/assets/{Chat-B0sXFnFc.js => Chat-B7ZHVqg5.js} (99%) rename internal/webui/static/assets/{Dashboard-COZgQmUP.js => Dashboard-BWfd6MyT.js} (99%) rename internal/webui/static/assets/{ItemList-BLPsnCuG.js => ItemList-BgZXwlJZ.js} (64%) rename internal/webui/static/assets/{Notifications-D90C7V4V.js => Notifications-DFdczI4g.js} (99%) delete mode 100644 internal/webui/static/assets/OrderList-CIcqa_PS.js create mode 100644 internal/webui/static/assets/OrderList-CMWPVZno.js rename internal/webui/static/assets/{Rules-B7fgxH9m.js => Rules-BaD_vse7.js} (99%) rename internal/webui/static/assets/{Settings-BsnTwWjn.js => Settings-BOxCHLU8.js} (99%) create mode 100644 internal/webui/static/assets/index-2BJ5Kkse.js create mode 100644 internal/webui/static/assets/index-6EQ70kIK.css delete mode 100644 internal/webui/static/assets/index-DawJY7_a.js delete mode 100644 internal/webui/static/assets/index-mo8bfmYY.css diff --git a/api/openapi.yaml b/api/openapi.yaml index 9e28a3f..226e8df 100644 --- a/api/openapi.yaml +++ b/api/openapi.yaml @@ -1760,6 +1760,12 @@ paths: application/json: schema: $ref: '#/components/schemas/ErrorResponse' + '409': + description: AI 议价与固定规则改价配置冲突 + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' '500': description: 统一错误响应 content: @@ -1855,6 +1861,12 @@ paths: application/json: schema: $ref: '#/components/schemas/ErrorResponse' + '409': + description: AI 议价与固定规则改价配置冲突 + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' '500': description: 统一错误响应 content: @@ -3389,6 +3401,12 @@ paths: operationId: postApiV1ItemsPublish summary: postApiV1ItemsPublish security: [{cookieAuth: []}] + requestBody: + required: true + content: + multipart/form-data: + schema: + $ref: '#/components/schemas/ItemPublishRequest' responses: '200': description: 成功 @@ -4749,12 +4767,11 @@ paths: requestBody: required: true content: - multipart/form-data: + application/json: schema: - type: object - properties: - cookie_id: {type: string} - status: {type: string} + $ref: '#/components/schemas/OrderRefreshRequest' + multipart/form-data: + schema: {$ref: '#/components/schemas/OrderRefreshRequest'} responses: '202': description: 成功 @@ -6254,6 +6271,12 @@ paths: schema: type: string security: [{cookieAuth: []}] + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/AIReplySettingsUpdateRequest' responses: '200': description: 成功 @@ -6285,6 +6308,12 @@ paths: application/json: schema: $ref: '#/components/schemas/ErrorResponse' + '409': + description: AI 议价与固定规则改价配置冲突 + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' '500': description: 统一错误响应 content: @@ -6907,14 +6936,25 @@ components: items: {$ref: '#/components/schemas/ItemReplyResponse'} AIReplySettingsResponse: type: object - required: [ai_enabled, max_discount_percent, max_discount_amount, max_bargain_rounds, custom_prompts] + required: [ai_enabled, auto_adjust_price_enabled, max_discount_percent, max_discount_amount, max_bargain_rounds, custom_prompts] properties: cookie_id: {type: string} ai_enabled: {type: boolean} + auto_adjust_price_enabled: {type: boolean} max_discount_percent: {type: integer} max_discount_amount: {type: integer} max_bargain_rounds: {type: integer} custom_prompts: {type: string} + AIReplySettingsUpdateRequest: + type: object + required: [ai_enabled, auto_adjust_price_enabled, max_discount_percent, max_discount_amount, max_bargain_rounds, custom_prompts] + properties: + ai_enabled: {type: boolean} + auto_adjust_price_enabled: {type: boolean} + max_discount_percent: {type: integer, minimum: 0, maximum: 100} + max_discount_amount: {type: integer, minimum: 0} + max_bargain_rounds: {type: integer, minimum: 1, maximum: 10} + custom_prompts: {type: string} AIReplySettingsMapResponse: type: object additionalProperties: @@ -6975,6 +7015,22 @@ components: poi_id: {type: string} poi_name: {type: string} province: {type: string} + ItemPublishRequest: + type: object + required: [cookie_id, title, description, price, original_price, quantity, postage_mode, postage, images] + properties: + cookie_id: {type: string} + title: {type: string} + description: {type: string} + price: {type: string} + original_price: {type: string} + quantity: {type: integer, minimum: 1} + postage_mode: {type: string} + postage: {type: string} + location: {type: string} + images: + type: array + items: {type: string, format: binary} ItemPublishBatchPreviewRow: type: object required: [row_no, valid, cookie_id, title, price, quantity, images, category, automation] @@ -7736,6 +7792,11 @@ components: chat_id: {type: string} system_shipped: {type: boolean} item_title: {type: string} + OrderRefreshRequest: + type: object + properties: + cookie_id: {type: string} + status: {type: string} OrderRefreshDetail: type: object required: [quantity, spec_name, spec_value, order_status, amount] diff --git a/frontend/app/features/accounts/api.ts b/frontend/app/features/accounts/api.ts index 258d844..5f966cc 100644 --- a/frontend/app/features/accounts/api.ts +++ b/frontend/app/features/accounts/api.ts @@ -338,12 +338,13 @@ export const updateAccountAISettings = async (cookieId: string, settings: Partia // payload 请求载荷,用于当前 API 处理流程。 const payload = { ai_enabled: settings.ai_enabled ?? false, + auto_adjust_price_enabled: settings.auto_adjust_price_enabled ?? false, max_discount_percent: settings.max_discount_percent ?? 10, max_discount_amount: settings.max_discount_amount ?? 100, max_bargain_rounds: settings.max_bargain_rounds ?? 3, custom_prompts: settings.custom_prompts ?? '' }; - return runContractRequest(/* signal 控制账号 AI 设置更新的取消和超时。 */ signal => contractClient.PUT('/api/v1/settings/ai-reply/{cookie_id}', { params: { path: { cookie_id: cookieId } }, body: payload as never, signal }), options); + return runContractRequest(/* signal 控制账号 AI 设置更新的取消和超时。 */ signal => contractClient.PUT('/api/v1/settings/ai-reply/{cookie_id}', { params: { path: { cookie_id: cookieId } }, body: payload, signal }), options); } diff --git a/frontend/app/features/accounts/components/AccountAISettingsModal.tsx b/frontend/app/features/accounts/components/AccountAISettingsModal.tsx index e65adad..53c66da 100644 --- a/frontend/app/features/accounts/components/AccountAISettingsModal.tsx +++ b/frontend/app/features/accounts/components/AccountAISettingsModal.tsx @@ -24,7 +24,12 @@ export const AccountAISettingsModal: React.FC = ({ // updateSettings 使用最新草稿合并单个 AI 字段变化。 const updateSettings = (patch: Partial) => onChange({ ...settings, ...patch }); // handleEnabledChange 切换 AI 自动回复开关。 - const handleEnabledChange = () => updateSettings({ ai_enabled: !settings.ai_enabled }); + const handleEnabledChange = () => updateSettings(settings.ai_enabled ? { ai_enabled: false, auto_adjust_price_enabled: false } : { ai_enabled: true }); + // handleAutoAdjustChange 切换真实订单自动改价开关,AI 议价关闭时不允许单独开启。 + const handleAutoAdjustChange = () => { + if (!settings.ai_enabled) return; + updateSettings({ auto_adjust_price_enabled: !settings.auto_adjust_price_enabled }); + }; // handleDiscountPercentChange 更新最大折扣比例。 const handleDiscountPercentChange = (event: React.ChangeEvent) => updateSettings({ max_discount_percent: parseInt(event.target.value, 10) || 0 }); // handleDiscountAmountChange 更新最大折扣金额。 @@ -53,6 +58,13 @@ export const AccountAISettingsModal: React.FC = ({ +
+
自动执行 AI 报价改价
AI 明确报价后,买家在 30 分钟内拍下对应商品时自动修改待付款订单价格。开启 AI 议价后,固定自动化规则改价将不能同时启用。
+ +
+

砍价策略

@@ -65,7 +77,7 @@ export const AccountAISettingsModal: React.FC = ({