This commit is contained in:
2026-10-22 14:37:59 +08:00
parent de96e47d74
commit 760bf8daa1
49 changed files with 2450 additions and 117 deletions
@@ -1,5 +1,6 @@
import { mkdir, writeFile } from 'node:fs/promises'
import { verifyProcurementSample } from './procurement-sample-fulfillment.mjs'
import { normalizeFixedCustomerId } from './merchant-qualification-fixture.mjs'
const MODULE = 'phase4-overseas-wallet-and-pallet-cost'
const SCENARIO = 'phase4-overseas-wallet-and-pallet-cost-http'
@@ -314,7 +315,41 @@ async function verifyDestuffCosts(context, completedFacts) {
return evidence
}
/** 固定客户只执行采购正常链,不初始化余额、授信或修改公共资源。 */
export async function runFixedCustomerProcurement(context, fulfill = procurementFlow) {
const fixture = context.context?.merchantQualificationFixture
const customerId = normalizeFixedCustomerId(context.options?.fixedCustomerId)
if (fixture?.marker !== context.marker || id(fixture?.tenantId) !== customerId
|| fixture?.reused !== true || !fixture?.username || !fixture?.password) {
throw new Error('采购正向链缺少本轮固定客户资格,禁止创建或借用其他客户')
}
if (context.createdResources.procurementSample) throw new Error('已有采购验收证据,不自动重跑或覆盖')
context.addCoverageGap(MODULE, 'fixed-wallet-lifecycle', '授信充值、贴标资金及拆柜成本综合场景',
'本分支仅执行既有余额上的采购正向履约;未执行钱包初始化及原综合模块其他场景',
'not-implemented', { blocking: false })
const warehousesResponse = await context.request('GET', `${PROCUREMENT}/warehouse-options`)
const candidates = success(warehousesResponse) ? warehousesResponse.body.data : null
const warehouse = Array.isArray(candidates) ? candidates.find(row => /^[1-9]\d*$/.test(id(row?.warehouseId))) : null
assert(context, '采购正向链复用正式候选收货仓', warehousesResponse, Boolean(warehouse))
if (!warehouse) throw new Error('缺少现有采购合作仓,不自动创建')
const auth = await merchantLogin(context, fixture)
if (!auth?.accessToken || !auth?.refreshToken) throw new Error('采购客户会话或退出凭据缺失')
try {
const profileResponse = await context.request('GET', '/api/merchant/v1/iam/tenant/profile', undefined, auth.accessToken)
const profile = success(profileResponse) ? profileResponse.body.data : null
const matched = id(profile?.id) === customerId && profile?.status === 'ACTIVE'
assert(context, '采购当前会话属于指定固定客户', profileResponse, matched)
if (!matched) throw new Error('采购客户会话身份不匹配,停止业务写入')
// 共享助手在创建订单前核验现金可用余额至少3元,并逐请求持久化;不足时直接失败。
return await fulfill(context, fixture, auth.accessToken, id(warehouse.warehouseId))
} finally {
const logout = await context.request('POST', '/api/auth/logout', { refreshToken: auth.refreshToken }, auth.accessToken)
assert(context, '退出本轮固定采购客户会话', logout, success(logout))
}
}
export async function run(context) {
if (context.options?.fixedCustomerId) return runFixedCustomerProcurement(context)
const start = context.steps.length
const fixture = context.context?.merchantQualificationFixture
const completedFacts = context.createdResources?.phase4OverseasPda?.completedContainerFacts || []