优化
This commit is contained in:
@@ -2,7 +2,8 @@ param(
|
||||
[string]$GatewayBaseUrl = 'http://8.163.30.128:9000',
|
||||
[string]$PlatformUsername = 'platform_admin',
|
||||
[string]$MerchantUsername = 'merchant_admin',
|
||||
[string]$Password = 'ChangeMe123!',
|
||||
[string]$PlatformPassword = 'ChangeMe123!',
|
||||
[string]$MerchantPassword = 'ChangeMe123!',
|
||||
[long]$TenantId = 10001,
|
||||
[string]$OutputPath = ''
|
||||
)
|
||||
@@ -16,7 +17,7 @@ if ([string]::IsNullOrWhiteSpace($OutputPath)) {
|
||||
}
|
||||
|
||||
$steps = [System.Collections.Generic.List[object]]::new()
|
||||
$ids = [ordered]@{ tenantId = [string]$TenantId; qualificationReviewId = $null; warehouseId = $null; carrierId = $null; orderId = $null; inboundId = $null; measurementId = $null; weightResultId = $null; fileId = $null }
|
||||
$ids = [ordered]@{ tenantId = [string]$TenantId; qualificationReviewId = $null; warehouseId = $null; carrierId = $null; customerRuleId = $null; carrierRateId = $null; orderId = $null; inboundId = $null; measurementId = $null; weightResultId = $null; fileId = $null; feeId = $null }
|
||||
$versions = [ordered]@{ inbound = $null; measurement = $null; weightResult = $null }
|
||||
$fatal = $null
|
||||
$billingDefect = $null
|
||||
@@ -56,19 +57,20 @@ function Invoke-Api(
|
||||
}
|
||||
|
||||
function Invoke-Upload([string]$Path, [string]$Token, [string]$FilePath) {
|
||||
$response = Invoke-WebRequest -Method POST -Uri "$GatewayBaseUrl$Path" `
|
||||
-Headers @{ Authorization = "Bearer $Token" } -Form @{ file = Get-Item -LiteralPath $FilePath } `
|
||||
-TimeoutSec 60 -SkipHttpErrorCheck
|
||||
$file = Get-Item -LiteralPath $FilePath
|
||||
$content = & curl.exe -sS -X POST "$GatewayBaseUrl$Path" `
|
||||
-H "Authorization: Bearer $Token" -F "file=@$($file.FullName);type=image/png"
|
||||
if ($LASTEXITCODE -ne 0) { throw '称重图片上传发生传输错误' }
|
||||
$json = $null
|
||||
if (-not [string]::IsNullOrWhiteSpace($response.Content)) {
|
||||
try { $json = $response.Content | ConvertFrom-Json } catch { }
|
||||
if (-not [string]::IsNullOrWhiteSpace($content)) {
|
||||
try { $json = $content | ConvertFrom-Json } catch { }
|
||||
}
|
||||
return [pscustomobject]@{
|
||||
http = [int]$response.StatusCode
|
||||
http = 200
|
||||
body = $json
|
||||
raw = if ($null -eq $json) { $response.Content } else { $null }
|
||||
requestId = if ($null -ne $json) { $json.requestId } else { $response.Headers['X-Request-Id'] }
|
||||
traceId = if ($null -ne $json) { $json.traceId } else { $response.Headers['X-Trace-Id'] }
|
||||
raw = if ($null -eq $json) { [string]$content } else { $null }
|
||||
requestId = if ($null -ne $json) { $json.requestId } else { $null }
|
||||
traceId = if ($null -ne $json) { $json.traceId } else { $null }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,11 +127,11 @@ function Require-Condition([string]$Name, $Response, [bool]$Condition, [string]$
|
||||
}
|
||||
|
||||
try {
|
||||
$platformLoginResponse = Invoke-Api POST '/api/auth/login' '' @{ username = $PlatformUsername; password = $Password }
|
||||
$platformLoginResponse = Invoke-Api POST '/api/auth/login' '' @{ username = $PlatformUsername; password = $PlatformPassword }
|
||||
$platformLogin = Require-Success '平台登录' $platformLoginResponse
|
||||
$platformToken = $platformLogin.accessToken
|
||||
|
||||
$merchantLoginResponse = Invoke-Api POST '/api/auth/login' '' @{ username = $MerchantUsername; password = $Password }
|
||||
$merchantLoginResponse = Invoke-Api POST '/api/auth/login' '' @{ username = $MerchantUsername; password = $MerchantPassword }
|
||||
$merchantLogin = Require-Success '商户登录' $merchantLoginResponse
|
||||
$merchantToken = $merchantLogin.accessToken
|
||||
|
||||
@@ -216,6 +218,28 @@ try {
|
||||
$warehouseResponse = Invoke-Api POST '/api/platform/v1/warehouse-admin' $platformToken $warehousePayload
|
||||
$ids.warehouseId = [string](Require-Success '创建启用收货能力的公共测试仓' $warehouseResponse)
|
||||
|
||||
$effectiveFrom = (Get-Date).AddDays(-1).ToString('yyyy-MM-ddTHH:mm:ss')
|
||||
$customerRuleResponse = Invoke-Api POST "/api/platform/v1/fba-pricing/customer-rules/versions?tenantId=$TenantId" $platformToken @{
|
||||
ruleCode = "API-E2E-RULE-$stamp"; customerId = '191000000000000001'
|
||||
customerName = '深圳示例贸易有限公司'; businessType = 'FBA_SEA'; chargeMode = 'KG'
|
||||
taxMode = 'TAX_INCLUDED'; conversionFactor = 167; roundingScale = 3
|
||||
roundingMode = 'HALF_UP'; currency = 'CNY'; effectiveFrom = $effectiveFrom
|
||||
effectiveTo = $null; remark = $marker
|
||||
}
|
||||
$customerRule = Require-Success '创建客户计费规则版本' $customerRuleResponse
|
||||
$ids.customerRuleId = [string]$customerRule.id
|
||||
|
||||
$carrierRateResponse = Invoke-Api POST '/api/platform/v1/fba-pricing/carrier-rates/versions' $platformToken @{
|
||||
rateCode = "API-E2E-RATE-$stamp"; originWarehouseId = $ids.warehouseId
|
||||
originWarehouseName = $warehousePayload.warehouseName; businessType = 'FBA_SEA'
|
||||
channelCode = 'API-E2E-SEA'; carrierId = $ids.carrierId
|
||||
carrierName = $carrierPayload.partnerName; destinationCode = 'ABE2'; chargeUnit = 'KG'
|
||||
unitPrice = 2; currency = 'CNY'; additionalFee = 10; effectiveFrom = $effectiveFrom
|
||||
effectiveTo = $null; remark = $marker
|
||||
}
|
||||
$carrierRate = Require-Success '创建承运商 FBA 费率版本' $carrierRateResponse
|
||||
$ids.carrierRateId = [string]$carrierRate.id
|
||||
|
||||
$sender = [ordered]@{
|
||||
companyName = '深圳示例贸易有限公司'; contactName = 'API Tester'; phone = '13800138000'
|
||||
email = 'api-e2e@example.com'; countryCode = 'CN'; province = '广东省'; city = '深圳市'
|
||||
@@ -387,19 +411,13 @@ try {
|
||||
Require-Condition '二期边界停在 WAIT_SPLIT' $approvedInboundResponse ($approvedInbound.summary.processStatus -eq 'WAIT_SPLIT' -and $approvedInbound.summary.measureReviewStatus -eq 'APPROVED') "processStatus=$($approvedInbound.summary.processStatus), reviewStatus=$($approvedInbound.summary.measureReviewStatus)"
|
||||
|
||||
$feeResponse = Invoke-Api POST "/api/platform/v1/inbounds/$($ids.inboundId)/fees/calculate?tenantId=$TenantId" $platformToken @{} @{ 'Idempotency-Key' = (New-Key 'fee-calculate') }
|
||||
$feePassed = $feeResponse.http -eq 200 -and [string]$feeResponse.body.code -eq '200'
|
||||
Add-Step '二期计费接口试算' $feeResponse $feePassed "inboundStatus=$($approvedInbound.summary.processStatus)"
|
||||
if (-not $feePassed) {
|
||||
$billingDefect = [ordered]@{
|
||||
severity = 'P0'
|
||||
summary = '测量审核后进入 WAIT_SPLIT,但计费接口不接受该状态,二期正常链路无法计费'
|
||||
http = $feeResponse.http
|
||||
code = [string]$feeResponse.body.code
|
||||
message = [string]$feeResponse.body.message
|
||||
requestId = $feeResponse.requestId
|
||||
traceId = $feeResponse.traceId
|
||||
}
|
||||
}
|
||||
$calculatedFee = Require-Success '二期计费接口试算' $feeResponse
|
||||
$ids.feeId = [string]$calculatedFee.feeId
|
||||
Require-Condition '计费试算保持 WAIT_SPLIT 主流程边界' $feeResponse ($calculatedFee.nextProcessStatus -eq 'WAIT_SPLIT') "nextProcessStatus=$($calculatedFee.nextProcessStatus)"
|
||||
|
||||
$feeConfirmResponse = Invoke-Api POST "/api/platform/v1/inbounds/$($ids.inboundId)/fees/confirm?tenantId=$TenantId" $platformToken $null @{ 'Idempotency-Key' = (New-Key 'fee-confirm') }
|
||||
$confirmedFee = Require-Success '确认二期费用快照' $feeConfirmResponse
|
||||
Require-Condition '费用确认后仍保持 WAIT_SPLIT 主流程边界' $feeConfirmResponse ($confirmedFee.feeStatus -eq 'CONFIRMED' -and $confirmedFee.nextProcessStatus -eq 'WAIT_SPLIT') "feeStatus=$($confirmedFee.feeStatus), nextProcessStatus=$($confirmedFee.nextProcessStatus)"
|
||||
}
|
||||
catch {
|
||||
$fatal = $_.Exception.Message
|
||||
|
||||
Reference in New Issue
Block a user