fix: restore phase five development acceptance chain
This commit is contained in:
@@ -339,7 +339,34 @@ async function loadMasterData(context, merchantToken) {
|
||||
pricingTaxMode: priced.pricingTaxMode, destinationType, partner }
|
||||
}
|
||||
|
||||
function buildPayload(context, profile, master, productImageFileId) {
|
||||
async function ensureCustomerAddress(context, merchantToken, profile, addressType) {
|
||||
const path = `/api/merchant/v1/orders/first-leg/addresses?addressType=${encodeURIComponent(addressType)}`
|
||||
const listResponse = await request(context, 'GET', path, undefined, merchantToken)
|
||||
const existing = context.apiSuccess(MODULE, `Client 查询${addressType}地址簿`, listResponse)
|
||||
const existingId = id(Array.isArray(existing) ? existing[0]?.id : null)
|
||||
if (existingId) return existingId
|
||||
|
||||
const isPickup = addressType === 'PICKUP'
|
||||
const createResponse = await request(context, 'POST', '/api/merchant/v1/orders/first-leg/addresses', {
|
||||
addressType,
|
||||
addressName: isPickup ? '开发联调取货地址' : '开发联调私人目的仓',
|
||||
companyName: profile.tenantName || `订单验收客户-${context.marker}`,
|
||||
contactName: isPickup ? '订单验收发货人' : '订单验收收货人',
|
||||
phone: isPickup ? '13800138000' : '12025550188',
|
||||
email: isPickup ? 'order-acceptance@example.com' : 'private-receiver@example.com',
|
||||
countryCode: isPickup ? 'CN' : 'US',
|
||||
province: isPickup ? '广东省' : 'New York',
|
||||
city: isPickup ? '深圳市' : 'New York',
|
||||
district: isPickup ? '南山区' : 'Queens',
|
||||
addressLine: `${context.marker} ${isPickup ? '开发联调取货地址' : '88 Randomized Test Ave'}`,
|
||||
postalCode: isPickup ? '518000' : '11354',
|
||||
defaultAddress: true,
|
||||
}, merchantToken)
|
||||
return id(context.apiSuccess(MODULE, `Client 创建${addressType}地址`, createResponse,
|
||||
`addressType=${addressType}`, CONTRACT_OPTIONS))
|
||||
}
|
||||
|
||||
function buildPayload(context, profile, master, productImageFileId, customerAddresses) {
|
||||
const shipmentId = `SHIP-${context.marker}`.slice(0, 64)
|
||||
const referenceId = `REF-${context.marker}`.slice(0, 64)
|
||||
const companyName = profile.tenantName || `订单验收客户-${context.marker}`
|
||||
@@ -371,6 +398,8 @@ function buildPayload(context, profile, master, productImageFileId) {
|
||||
expectedShipDate: tomorrow(), customerRemark: `${context.marker} Client 创建隔离订单`,
|
||||
pickupMethod, requestedPickupAt: pickupMethod === 'PICKUP'
|
||||
? new Date(Date.now() + 7 * 86_400_000).toISOString().slice(0, 19) : null,
|
||||
senderAddressId: pickupMethod === 'PICKUP' ? customerAddresses.pickupAddressId : null,
|
||||
privateDestinationAddressId: isPrivate ? customerAddresses.privateDestinationAddressId : null,
|
||||
receivingWarehouseId: master.receiving.id,
|
||||
receivingWarehouseName: master.receiving.warehouseName,
|
||||
channelCode: master.channel.channelCode, channelName: master.channel.channelName,
|
||||
@@ -405,7 +434,7 @@ function buildPayload(context, profile, master, productImageFileId) {
|
||||
shipmentId: master.destinationType === 'FBA' ? shipmentId : null,
|
||||
referenceId: master.destinationType === 'FBA' ? referenceId : null,
|
||||
upcNo: `${Date.now()}${index}`.slice(-12),
|
||||
productImageFileId, dangerousGoods: false,
|
||||
productImageFileId, dangerousGoods: false, woodenProduct: false,
|
||||
cargoRemark: `${context.marker} boxType=${box.boxType}`,
|
||||
}
|
||||
}),
|
||||
@@ -482,7 +511,7 @@ async function waitForInbound(context, tenantId, orderId) {
|
||||
|
||||
export async function run(context) {
|
||||
const loginResponse = await context.request('POST', '/api/auth/login', {
|
||||
username: MERCHANT_USERNAME, password: MERCHANT_PASSWORD,
|
||||
loginId: MERCHANT_USERNAME, password: MERCHANT_PASSWORD,
|
||||
}, '')
|
||||
const login = context.apiSuccess(MODULE, 'Client 测试账号登录', loginResponse,
|
||||
`username=${MERCHANT_USERNAME}`)
|
||||
@@ -509,7 +538,12 @@ export async function run(context) {
|
||||
if (!productImageFileId) throw new Error('产品图片新契约未部署,无法创建带图片的隔离订单')
|
||||
await assertProductImageDownload(context, merchantToken, productImageFileId)
|
||||
|
||||
const payload = buildPayload(context, profile, master, productImageFileId)
|
||||
const customerAddresses = {
|
||||
pickupAddressId: await ensureCustomerAddress(context, merchantToken, profile, 'PICKUP'),
|
||||
privateDestinationAddressId: master.destinationType === 'PRIVATE'
|
||||
? await ensureCustomerAddress(context, merchantToken, profile, 'PRIVATE_DESTINATION') : null,
|
||||
}
|
||||
const payload = buildPayload(context, profile, master, productImageFileId, customerAddresses)
|
||||
const createPath = '/api/merchant/v1/orders/first-leg'
|
||||
const createResponse = await request(context, 'POST', createPath, payload, merchantToken,
|
||||
{ 'Idempotency-Key': key(context, 'client-create') })
|
||||
|
||||
Reference in New Issue
Block a user