Files
weiguang-jewelry-ledger/新账系统/public/credit-card-fees.js
T
黄健铭andClaude Opus 5.5 28c64814f0 格式化:Prettier统一代码风格(仅格式,无逻辑变化)
仅为 npm run format 的输出;黄金对照、旧库兼容、浏览器流程与单元测试全部通过且零差异。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-04 08:58:53 -08:00

21 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
'use strict';
// 手续费预览使用整数分;真实费用由服务端按每笔客户付款生成。
(function (root) {
const isAccount = account => ['助理信用卡', '助理1信用卡', '麦麦信用卡', '助理2信用卡'].includes(account);
const ratePermille = 6;
function rate(value = ratePermille) {
if (!Number.isSafeInteger(value) || value < 0 || value > 1000) throw new Error('信用卡手续费率须为0~1000的整数‰');
return value;
}
const normalizeAccount = account => (isAccount(account) ? '麦麦信用卡' : account);
const note = (value = ratePermille) => `信用卡手续费(${rate(value)}‰)`;
const isFee = item => item?.system === 'credit_card' || String(item?.key || '').startsWith('card_fee:');
function amount(cents, value = ratePermille) {
if (!Number.isSafeInteger(cents) || cents < 0 || cents > 100000000000) throw new Error('客户付款金额无效');
return Number((BigInt(cents) * BigInt(rate(value)) + 500n) / 1000n);
}
const api = { isAccount, isFee, amount, rate, ratePermille, normalizeAccount, note };
if (typeof module === 'object' && module.exports) module.exports = api;
else root.CreditCardFees = api;
})(typeof globalThis === 'object' ? globalThis : this);