本地Mock店铺支持自定义输入便于录入其他平台订单
This commit is contained in:
@@ -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' },
|
||||
|
||||
Reference in New Issue
Block a user