This commit is contained in:
2026-09-09 09:52:46 +08:00
parent 68a5612598
commit 4379b721bc
9 changed files with 195 additions and 46 deletions
+40 -14
View File
@@ -247,7 +247,39 @@ async function uploadProductImage(gateway, timeoutMs, token, marker) {
return data.fileId
}
export function buildOrderPayload({ marker, index, profile, master, product, packageCount, options = randomOrderOptions(), productImageFileId }) {
async function ensurePickupAddress(gateway, timeoutMs, token, profile, marker) {
const listResponse = await request(gateway, timeoutMs, 'GET',
'/api/merchant/v1/orders/first-leg/addresses?addressType=PICKUP', { token })
const existing = items(requireSuccess(listResponse, 'Query pickup addresses'))
.find((address) => address?.id)
if (existing) return String(existing.id)
const location = pickRandom(SENDER_LOCATIONS)
const createResponse = await request(gateway, timeoutMs, 'POST',
'/api/merchant/v1/orders/first-leg/addresses', {
token,
body: {
addressType: 'PICKUP',
addressName: '待审核订单测试取货地址',
companyName: profile.tenantName || `固定客户-${marker}`,
contactName: '订单测试联系人',
phone: '13800138000',
email: 'pending-order@example.com',
countryCode: 'CN',
province: location.province,
city: location.city,
district: location.district,
addressLine: `${marker} 固定客户测试地址`,
postalCode: location.postalCode,
defaultAddress: true,
},
})
const addressId = String(requireSuccess(createResponse, 'Create pickup address') ?? '')
if (!addressId) throw new Error('Create pickup address did not return address ID')
return addressId
}
export function buildOrderPayload({ marker, index, profile, master, product, packageCount, options = randomOrderOptions(), productImageFileId, pickupAddressId }) {
const sequence = String(index).padStart(3, '0')
const shipmentId = `SHIP-${sequence}-${marker}`.slice(0, 64)
const referenceId = `REF-${sequence}-${marker}`.slice(0, 64)
@@ -282,18 +314,10 @@ export function buildOrderPayload({ marker, index, profile, master, product, pac
amazonWarehouseCode: master.destination.warehouseCode,
shipmentId,
referenceId,
sender: options.pickupMethod === 'PICKUP' ? {
companyName,
contactName: '订单测试联系人',
phone: '13800138000',
email: 'pending-order@example.com',
countryCode: 'CN',
province: options.senderLocation.province,
city: options.senderLocation.city,
district: options.senderLocation.district,
addressLine: `${marker} 固定客户测试地址`,
postalCode: options.senderLocation.postalCode,
} : null,
requestedPickupAt: options.pickupMethod === 'PICKUP'
? new Date(Date.now() + 7 * 86_400_000).toISOString().slice(0, 19) : null,
senderAddressId: options.pickupMethod === 'PICKUP' ? pickupAddressId : null,
sender: null,
receiver: null,
cargoes: [{
skuNo: `SKU-${sequence}-${marker}`.slice(0, 64),
@@ -325,6 +349,7 @@ export function buildOrderPayload({ marker, index, profile, master, product, pac
referenceId,
upcNo: `${Date.now()}${sequence}`.slice(-12),
productImageFileId,
woodenProduct: false,
dangerousGoods: false,
cargoRemark: `待审核订单货物 ${sequence} ${marker}`,
}],
@@ -383,6 +408,7 @@ export async function main(argv = process.argv.slice(2)) {
const routePool = await loadPricedRoutes(gateway, timeoutMs, token)
const productImageFileId = await uploadProductImage(gateway, timeoutMs, token, marker)
const pickupAddressId = await ensurePickupAddress(gateway, timeoutMs, token, profile, marker)
const randomizedProducts = shuffled(PRODUCT_CATALOG)
const sameChannel = args['same-channel'] === true
const randomizedRoutes = sameChannel ? selectSameChannelRoutes(routePool) : diversifyRoutes(routePool)
@@ -392,7 +418,7 @@ export async function main(argv = process.argv.slice(2)) {
const product = randomizedProducts[(index - 1) % randomizedProducts.length]
const packageCount = randomInt(1, 31)
const options = randomOrderOptions()
const payload = buildOrderPayload({ marker, index, profile, master, product, packageCount, options, productImageFileId })
const payload = buildOrderPayload({ marker, index, profile, master, product, packageCount, options, productImageFileId, pickupAddressId })
const createResponse = await request(gateway, timeoutMs, 'POST',
'/api/merchant/v1/orders/first-leg', {
token,