Refund reconciliation demo - 建国表格工坊
AI-assisted, deterministic browser JavaScript demo. Six synthetic CSV refund cases, integer-fen arithmetic, source-row evidence, and manual-review states. Chinese UI; no real customer data. By 李建国.
HTML
<main>
<p><a href="https://jianguo-tablecheck.spry-bud-5759.chatgpt.site/" style="color:inherit">建国表格工坊</a> · <a href="https://jianguo-tablecheck.spry-bud-5759.chatgpt.site/#request" style="color:inherit">提交定制需求</a></p>
<h1>退款核对 · 六条虚构记录演示</h1>
<p class="intro">这是建国表格工坊的公开代码演示,由李建国使用 AI 辅助制作。只运行内置虚构数据,帮助理解逐笔核对和待核分类;没有真实订单或收益数据。</p><p><a href="https://jianguo-tablecheck.spry-bud-5759.chatgpt.site/check.html" target="_blank" rel="noopener noreferrer">打开免费完整工具</a> · <a href="https://jianguo-tablecheck.spry-bud-5759.chatgpt.site/#request" target="_blank" rel="noopener noreferrer">表格适配与脚本定制说明</a></p>
<section class="box" aria-labelledby="input-title">
<h2 id="input-title">查看样例和复算结果</h2><p>观察日固定为 2026-11-29。下面的缺口是虚构样例计算值,不代表追回款项。</p>
<div class="fields">
<div class="field"><label for="refund-file">成功售后明细</label><input id="refund-file" type="file" disabled hidden accept=".csv,text/csv"><br><button type="button" class="plain" id="download-refunds">下载售后示例 CSV</button></div>
<div class="field"><label for="ledger-file">供应商结算台账</label><input id="ledger-file" type="file" disabled hidden accept=".csv,text/csv"><br><button type="button" class="plain" id="download-ledger">下载台账示例 CSV</button></div>
</div>
<label hidden class="date" for="cutoff">核对截至 <input id="cutoff" type="date" required></label>
<label hidden><input type="checkbox" id="coverage"> 我已确认文件覆盖相关原结算、成功售后,以及截至核对日的全部冲回记录。</label>
<div class="controls"><button type="button" id="run" class="primary" disabled hidden>核对所选文件</button><button type="button" id="demo">运行虚构示例</button></div>
<div id="notice" role="alert"></div>
<details><summary>文件要求和金额口径</summary>
<p>使用 UTF-8 CSV,首行为表头。列名与示例一致,允许调整列顺序和添加其他列。每份文件最多 10,000 条数据、2 MiB。同次仅核对一家店,可包含多家供应商。请将单号按文本导出,以保留前导零。</p>
<p>日期格式为 YYYY-MM-DD。人民币金额用非负十进制数,最多两位小数;冲回金额填扣回金额的正数。售后文件只放已成功的退款。台账的记录类型为“原订单结算”或“退款冲回”。</p>
<p>供应商承担额与冲回截止日由双方约定;不明时留空。买家退款总额可作参考。原订单已结算、退款已到期、且能逐笔对应时才计算少扣差额。同日先后不明、重复或无法关联的记录请按来源行复核。结果供查账,不会修改原文件或执行扣款。</p>
</details>
</section>
<section class="box" id="result"...
CSS
:root{color-scheme:light;--ink:#152d2b;--dim:#4f6562;--line:#c9d6d2;--accent:#076450;--wash:#edf4f0}
*{box-sizing:border-box}
body{margin:0;background:#f6f8f5;color:var(--ink);font:16px/1.6 "PingFang SC","Microsoft YaHei",system-ui,sans-serif}
main{max-width:1150px;margin:40px auto;padding:0 24px 40px}
h1{font-size:clamp(28px,4vw,38px);margin:0 0 6px;line-height:1.25}
h2{font-size:21px;margin:0 0 12px}
p{margin:4px 0 13px}
.intro,.note,details{color:var(--dim)}
.box{background:white;border:1px solid var(--line);border-radius:14px;margin:21px 0;padding:22px}
.fields{display:grid;grid-template-columns:1fr 1fr;gap:18px}
.field{padding:12px 14px;background:var(--wash);border-radius:8px}
label{display:block}.field label{font-weight:650}
input[type=file]{font:inherit;max-width:100%;margin-top:7px}
input[type=date]{font:inherit;padding:4px 7px;color:var(--ink);background:white;border:1px solid var(--line);border-radius:5px}
.date{margin:15px 0 9px}.date input{margin-left:5px}
.controls{display:flex;gap:12px;align-items:center;flex-wrap:wrap;margin:16px 0 8px}
button{padding:8px 14px;font:inherit;font-weight:600;border:1px solid var(--line);border-radius:7px;cursor:pointer;background:#fff;color:var(--ink)}
button.primary{background:var(--accent);color:white;border-color:var(--accent)}
button:focus-visible,input:focus-visible,summary:focus-visible{outline:3px solid #187a9c;outline-offset:2px}
button:disabled{opacity:.58;cursor:default}
.plain{padding:2px 0;border:0;color:var(--accent);text-decoration:underline;font-weight:500}
.note,details{font-size:15px}.note{margin:8px 0}
summary{cursor:pointer}details p{margin:6px 0}
#notice:not(:empty){padding:9px 12px;margin:10px 0;background:#fff2dc;color:#793707;border-radius:5px}
.total{font-size:23px;font-weight:700;color:var(--accent);font-variant-numeric:tabular-nums}
.tableWrap{overflow-x:auto;max-height:570px;border:1px solid...
JavaScript
'use strict';
function parseCSV(text, requiredHeaders, tableName) {
const rows = [];
const maxRows = 10000;
const maxColumns = 256;
let headers = null;
let line = 1;
let startLine = 1;
let fields = [];
let field = "";
let quoted = false;
let afterQuote = false;
let hadQuotes = false;
function fail(reason, at = startLine) {
throw new Error(`${tableName}第 ${at} 行:${reason}`);
}
function finishField() {
if (fields.length >= maxColumns) fail(`单表最多支持 ${maxColumns} 列`);
fields.push(field);
field = "";
afterQuote = false;
}
function finishRecord() {
finishField();
const isBlankLine = !hadQuotes && fields.length === 1 && fields[0].trim() === "";
if (!isBlankLine) {
if (headers === null) {
headers = fields.map((name) => name.trim());
const seen = new Set();
for (const name of headers) {
if (!name) fail("表头存在空列名");
if (seen.has(name)) fail(`重复表头“${name}”`);
seen.add(name);
}
const missing = requiredHeaders.filter((name) => !seen.has(name));
if (missing.length) fail(`缺少必需列:${missing.join("、")}`);
} else {
if (fields.length !== headers.length) {
fail(`有 ${fields.length} 列,表头有 ${headers.length} 列`);
}
if (rows.length >= maxRows) fail(`单表最多支持 ${maxRows} 条数据`);
const values = Object.fromEntries(headers.map((name, index) => [name, fields[index]]));
rows.push({ line: startLine, values });
}
}
fields = [];
hadQuotes = false;
}
if (typeof text !== "string") fail("请提供 CSV 文本");
if (text.length > 8 * 1024 * 1024) fail("文本过大,请分批导入");
const first = text.charCodeAt(0) === 0xfeff ? 1 : 0;
for (let i = first; i < text.length; i++) {
const char = text[i];
if (char === "\r" || char === "\n") {
const crlf = char === "\r" && text[i + 1] === "\n";
if (quoted) field += crlf ? "\r\n" : char;
else finishRecord();
if (crlf) i++;
...