本地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, platformOrderId,
productName, productName,
rewardAmount, rewardAmount,
sellerId: String(shop.sellerId || shop.shopId || '').trim(), sellerId: String(shop.sellerId || '').trim(),
shopName: String(shop.shopName || '').trim(),
}), }),
now, now,
}) })
@@ -133,31 +134,36 @@ export function resolveAdminMockWorkOrderInput(
}) })
} }
const shopId = String(payload.sellerId || payload.shopId || '').trim() const shopIdentity = String(payload.sellerId || payload.shopId || '').trim()
if (!shopId) { if (!shopIdentity) {
throw createHttpError('请选择店铺', { throw createHttpError('请选择或输入店铺', {
statusCode: 400, statusCode: 400,
errorCode: 'mock_work_order_shop_required', errorCode: 'mock_work_order_shop_required',
}) })
} }
const shop = const matchedShop =
shops.find( shops.find(
(item) => (item) =>
String(item.sellerId || item.shopId || '').trim() === shopId || String(item.sellerId || item.shopId || '').trim() === shopIdentity ||
String(item.shopId || '').trim() === shopId, String(item.shopId || '').trim() === shopIdentity,
) || null ) || null
if (!shop) { if (matchedShop?.enabled === false) {
throw createHttpError('所选店铺不存在', {
statusCode: 400,
errorCode: 'mock_work_order_shop_invalid',
})
}
if (shop.enabled === false) {
throw createHttpError('所选店铺已停用', { throw createHttpError('所选店铺已停用', {
statusCode: 409, statusCode: 409,
errorCode: 'mock_work_order_shop_disabled', 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 { return {
platformOrderId, platformOrderId,
@@ -276,10 +276,15 @@ test('本地 Mock 工单要求订单、店铺、商品与两个金额完整有
resolveAdminMockWorkOrderInput({ platformOrderId: 'MOCK-1', productName: '测试商品' }, shops), resolveAdminMockWorkOrderInput({ platformOrderId: 'MOCK-1', productName: '测试商品' }, shops),
{ errorCode: 'mock_work_order_shop_required' }, { 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( assert.throws(
() => resolveAdminMockWorkOrderInput({ ...baseInput, sellerId: 'seller-disabled' }, shops), () => resolveAdminMockWorkOrderInput({ ...baseInput, sellerId: 'seller-disabled' }, shops),
{ errorCode: 'mock_work_order_shop_disabled' }, { errorCode: 'mock_work_order_shop_disabled' },
@@ -1,6 +1,6 @@
import { PlusOutlined } from '@ant-design/icons' import { PlusOutlined } from '@ant-design/icons'
import { useQuery } from '@tanstack/react-query' 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 { useState } from 'react'
import { createAdminMockWorkOrder } from '@/services/admin' import { createAdminMockWorkOrder } from '@/services/admin'
@@ -105,14 +105,21 @@ export function MockWorkOrderForm({ onCreated }: { onCreated: () => Promise<void
className="worker-order-mock-field-shop" className="worker-order-mock-field-shop"
label="店铺" label="店铺"
name="sellerId" name="sellerId"
rules={[{ required: true, message: '请选择店铺' }]} rules={[{ required: true, whitespace: true, message: '请选择或输入店铺' }]}
> >
<Select <AutoComplete
showSearch
optionFilterProp="label"
loading={shopsQuery.isLoading}
options={shopOptions} 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>
<Form.Item <Form.Item