import { $fetch } from 'ofetch' import { createError, defineEventHandler, readBody, getHeader, getCookie } from 'h3' import { useRuntimeConfig } from '#imports' import { getTenantFromContext } from '../../utils/tenant' /** * 创建标书订单 * POST /api/tender/order { projectId, quantity, contactName, contactPhone, contactEmail } * 代理到 mp-api(mp-java) /api/hjc/order/create;需登录态(从 cookie hjc_token 或 Authorization 透传)。 */ 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/create', { baseURL: config.public.modulesApiBase, method: 'POST', headers: { TenantId: ctx.tenantId, ...(auth ? { Authorization: auth } : {}) }, query: { TenantId: ctx.tenantId }, body }) as any return res?.data ?? res } catch (error: any) { throw createError({ statusCode: error?.statusCode || error?.response?.status || 502, statusMessage: error?.statusMessage || 'Failed to create order' }) } })