本地Mock店铺支持自定义输入便于录入其他平台订单

This commit is contained in:
yml2213
2026-08-22 14:26:04 +08:00
parent f92dc6a4c9
commit 72b3f7c592
3 changed files with 43 additions and 25 deletions
@@ -105,7 +105,8 @@ export async function createAdminMockWorkOrder(payload: JsonObject = {}) {
platformOrderId,
productName,
rewardAmount,
sellerId: String(shop.sellerId || shop.shopId || '').trim(),
sellerId: String(shop.sellerId || '').trim(),
shopName: String(shop.shopName || '').trim(),
}),
now,
})
@@ -133,31 +134,36 @@ export function resolveAdminMockWorkOrderInput(
})
}
const shopId = String(payload.sellerId || payload.shopId || '').trim()
if (!shopId) {
throw createHttpError('请选择店铺', {
const shopIdentity = String(payload.sellerId || payload.shopId || '').trim()
if (!shopIdentity) {
throw createHttpError('请选择或输入店铺', {
statusCode: 400,
errorCode: 'mock_work_order_shop_required',
})
}
const shop =
const matchedShop =
shops.find(
(item) =>
String(item.sellerId || item.shopId || '').trim() === shopId ||
String(item.shopId || '').trim() === shopId,
String(item.sellerId || item.shopId || '').trim() === shopIdentity ||
String(item.shopId || '').trim() === shopIdentity,
) || null
if (!shop) {
throw createHttpError('所选店铺不存在', {
statusCode: 400,
errorCode: 'mock_work_order_shop_invalid',
})
}
if (shop.enabled === false) {
if (matchedShop?.enabled === false) {
throw createHttpError('所选店铺已停用', {
statusCode: 409,
errorCode: 'mock_work_order_shop_disabled',
})
}
// 未命中已配置店铺时视为自定义店铺(用于其他平台订单手动录入),
// 与真实店铺一样落入 material.source,保证链路与展示一致。
const shop =
matchedShop ||
({
enabled: true,
sellerId: '',
shopId: '',
shopName: shopIdentity.slice(0, 64),
customShopName: shopIdentity.slice(0, 64),
} as KuaishouIndustryShopConfig)
return {
platformOrderId,
@@ -276,10 +276,15 @@ test('本地 Mock 工单要求订单、店铺、商品与两个金额完整有
resolveAdminMockWorkOrderInput({ platformOrderId: 'MOCK-1', productName: '测试商品' }, shops),
{ errorCode: 'mock_work_order_shop_required' },
)
assert.throws(
() => resolveAdminMockWorkOrderInput({ ...baseInput, sellerId: 'unknown' }, shops),
{ errorCode: 'mock_work_order_shop_invalid' },
)
// 未命中已配置店铺时按自定义店铺放行,便于其他平台订单手动录入
{
const customShop = resolveAdminMockWorkOrderInput(
{ ...baseInput, sellerId: '抖音自定义小店' },
shops,
)
assert.equal(customShop.shop.shopName, '抖音自定义小店')
assert.equal(customShop.shop.sellerId, '')
}
assert.throws(
() => resolveAdminMockWorkOrderInput({ ...baseInput, sellerId: 'seller-disabled' }, shops),
{ errorCode: 'mock_work_order_shop_disabled' },
@@ -1,6 +1,6 @@
import { PlusOutlined } from '@ant-design/icons'
import { useQuery } from '@tanstack/react-query'
import { App, Button, Card, Form, Input, InputNumber, Select, Switch } from 'antd'
import { App, AutoComplete, Button, Card, Form, Input, InputNumber, Select, Switch } from 'antd'
import { useState } from 'react'
import { createAdminMockWorkOrder } from '@/services/admin'
@@ -105,14 +105,21 @@ export function MockWorkOrderForm({ onCreated }: { onCreated: () => Promise<void
className="worker-order-mock-field-shop"
label="店铺"
name="sellerId"
rules={[{ required: true, message: '请选择店铺' }]}
rules={[{ required: true, whitespace: true, message: '请选择或输入店铺' }]}
>
<Select
showSearch
optionFilterProp="label"
loading={shopsQuery.isLoading}
<AutoComplete
options={shopOptions}
placeholder={shopOptions.length > 0 ? '请选择店铺' : '暂无可用店铺'}
filterOption={(inputValue, option) =>
String(option?.label ?? '')
.toLowerCase()
.includes(inputValue.toLowerCase()) ||
String(option?.value ?? '')
.toLowerCase()
.includes(inputValue.toLowerCase())
}
placeholder={
shopOptions.length > 0 ? '选择已配置店铺,或直接输入自定义店铺' : '输入自定义店铺'
}
/>
</Form.Item>
<Form.Item