v4.0.18版本提交

This commit is contained in:
2026-09-08 10:07:34 +08:00
parent 4bdb09068c
commit 23ba639e9b
46 changed files with 1922 additions and 162 deletions
@@ -1,4 +1,4 @@
/** 企微结算账单正文:字段块 + 字节上限(机器人 markdown 约 4096 字节) */
/** 企微结算账单正文:字段块 / markdown_v2 表格 + 字节上限(机器人约 4096 字节) */
export type WecomBankLike = {
bankAccountName?: string | null;
@@ -51,6 +51,27 @@ export function formatWecomFieldBlock(rows: Array<[string, string]>): string {
return rows.map(([k, v]) => `${k}${v}`).join('\n');
}
function escapeWecomTableCell(v: string): string {
const text = String(v ?? '')
.replace(/\|/g, '')
.replace(/\r?\n/g, ' ')
.trim();
return text || '—';
}
/** 企微 markdown_v2 键值表:表头为标题,下列为字段/值 */
export function formatWecomKvTable(header: string, rows: Array<[string, string]>): string {
const lines = [`| ${escapeWecomTableCell(header)} | |`, '| :--- | ---: |'];
for (const [k, v] of rows) {
lines.push(`| ${escapeWecomTableCell(k)} | ${escapeWecomTableCell(v)} |`);
}
return lines.join('\n');
}
export function filterNonZeroWecomBills<T extends { amount: number }>(rows: T[]): T[] {
return rows.filter((r) => Number(r.amount) > 0);
}
export function joinLimited(names: string[], unit: string, max = 8): string {
const uniq = [...new Set(names.map((n) => n.trim()).filter(Boolean))];
if (!uniq.length) return '—';
@@ -104,31 +125,31 @@ export function formatStoreBillWecomBlock(row: {
}
export function formatPartnerBillWecomBlock(row: {
cityName: string;
partnerLabel: string;
period: string;
orderCount?: number;
redeemCount?: number;
orderAmount?: number;
orderCommission: number;
redeemCount?: number;
redeemAmount?: number;
redeemCommission: number;
amount: number;
bank?: WecomBankLike | null;
}): string {
const bank = wecomBankParts(row.bank);
const rows: Array<[string, string]> = [
['城市', row.cityName || '—'],
['合伙人', row.partnerLabel || '—'],
];
if (row.orderCount != null) rows.push(['订单笔数', String(row.orderCount)]);
if (row.redeemCount != null) rows.push(['核销笔数', String(row.redeemCount)]);
rows.push(
return formatWecomKvTable(row.partnerLabel || '—', [
['账期', row.period || '—'],
['订单数量', String(row.orderCount ?? 0)],
['订单金额', formatYuan(row.orderAmount ?? 0)],
['订单佣金', formatYuan(row.orderCommission)],
['核销单数量', String(row.redeemCount ?? 0)],
['核销金额', formatYuan(row.redeemAmount ?? 0)],
['核销佣金', formatYuan(row.redeemCommission)],
['账单', formatYuan(row.amount)],
['累计金额', formatYuan(row.amount)],
['收款人', bank.payee],
['收款账户', bank.accountNo],
['收款开户行', bank.bankBranch],
);
return formatWecomFieldBlock(rows);
['收款银行账号', bank.accountNo],
['开户行', bank.bankBranch],
]);
}
export function formatLogisticsBillWecomBlock(row: {