import { $fetch } from 'ofetch' import { createError, defineEventHandler, readBody, getHeader, getCookie } from 'h3' import { useRuntimeConfig } from '#imports' import { getTenantFromContext } from '../../utils/tenant' /** * 标记订单已支付(幂等)并触发一站式推送 * PUT /api/tender/mark-paid { orderNo } * 代理到 mp-api /api/hjc/order/mark-paid;需登录态。 */ export default defineEventHandler(async (event) => { const config = useRuntimeConfig() const ctx = getTenantFromContext(event, config) const body = await readBody(event) const cookieToken = getCookie(event, 'hjc_token') const auth = getHeader(event, 'authorization') || (cookieToken ? `Bearer ${cookieToken}` : null) try { const res = await $fetch('/hjc/order/mark-paid', { baseURL: config.public.modulesApiBase, method: 'PUT', headers: { TenantId: ctx.tenantId, ...(auth ? { Authorization: auth } : {}) }, query: { TenantId: ctx.tenantId }, body }) as any const data = res && res.data !== undefined ? res.data : res return data } catch (error: any) { throw createError({ statusCode: error?.statusCode || error?.response?.status || 502, statusMessage: error?.statusMessage || 'Failed to mark paid' }) } })