feat: 完成P6-P8后端能力与P9路由重构(V1-V2,D1,D3,B1-B2,B4,I1-I4,P9A2-P9A3)
这个提交包含在:
@@ -0,0 +1,37 @@
|
||||
const { runMockVerification } = require("./mock");
|
||||
const { runTaxVerification } = require("./tax");
|
||||
|
||||
function getProvider(config) {
|
||||
return String(config.verificationProvider ?? "mock").trim().toLowerCase();
|
||||
}
|
||||
|
||||
function isVerificationEnabled(config) {
|
||||
return Boolean(config.invoiceVerificationEnabled);
|
||||
}
|
||||
|
||||
async function verifyInvoiceByProvider({ config, invoice }) {
|
||||
const provider = getProvider(config);
|
||||
|
||||
if (provider === "mock") {
|
||||
return runMockVerification({ invoice });
|
||||
}
|
||||
|
||||
if (provider === "tax") {
|
||||
return runTaxVerification({ config, invoice });
|
||||
}
|
||||
|
||||
return {
|
||||
status: "error",
|
||||
resultCode: "provider_unsupported",
|
||||
resultMessage: `Unsupported verification provider: ${provider}`,
|
||||
payload: {
|
||||
provider,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getProvider,
|
||||
isVerificationEnabled,
|
||||
verifyInvoiceByProvider,
|
||||
};
|
||||
@@ -0,0 +1,59 @@
|
||||
function normalizeAmount(value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const numberValue = Number(value);
|
||||
if (!Number.isFinite(numberValue)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return numberValue.toFixed(2);
|
||||
}
|
||||
|
||||
async function runMockVerification({ invoice }) {
|
||||
const remarks = String(invoice.remarks ?? "").toLowerCase();
|
||||
const invoiceCode = String(invoice.invoice_code ?? "").toUpperCase();
|
||||
const invoiceNumber = String(invoice.invoice_number ?? "").toUpperCase();
|
||||
|
||||
if (remarks.includes("verify-error") || invoiceNumber.includes("ERR")) {
|
||||
return {
|
||||
status: "error",
|
||||
resultCode: "mock_transport_error",
|
||||
resultMessage: "mock provider transport error",
|
||||
payload: {
|
||||
provider: "mock",
|
||||
marker: "verify-error",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
if (remarks.includes("verify-fail") || invoiceCode.includes("FAIL") || invoiceNumber.includes("FAIL")) {
|
||||
return {
|
||||
status: "failed",
|
||||
resultCode: "invoice_mismatch",
|
||||
resultMessage: "invoice metadata mismatch",
|
||||
payload: {
|
||||
provider: "mock",
|
||||
matched: false,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
status: "passed",
|
||||
resultCode: "verified",
|
||||
resultMessage: "invoice verified",
|
||||
payload: {
|
||||
provider: "mock",
|
||||
matched: true,
|
||||
invoiceCode: invoice.invoice_code ?? null,
|
||||
invoiceNumber: invoice.invoice_number ?? null,
|
||||
totalAmount: normalizeAmount(invoice.total_amount),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
runMockVerification,
|
||||
};
|
||||
@@ -0,0 +1,27 @@
|
||||
async function runTaxVerification({ config, invoice }) {
|
||||
if (!config.invoiceVerificationEnabled) {
|
||||
return {
|
||||
status: "error",
|
||||
resultCode: "verification_disabled",
|
||||
resultMessage: "invoice verification disabled",
|
||||
payload: {
|
||||
provider: "tax",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
status: "error",
|
||||
resultCode: "tax_provider_not_configured",
|
||||
resultMessage: "tax provider is not configured in current environment",
|
||||
payload: {
|
||||
provider: "tax",
|
||||
invoiceCode: invoice.invoice_code ?? null,
|
||||
invoiceNumber: invoice.invoice_number ?? null,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
runTaxVerification,
|
||||
};
|
||||
在新工单中引用
屏蔽一个用户