目录重组:后端按core/domains分领域存放(仅移动与更新引用)
- 50个后端模块用git mv移入core/与domains/<领域>/,入口server.js、launch.js、restore.js及server/原位不动 - 所有require路径由脚本按新旧位置统一换算(后端、server/、测试) - 新增test/app-paths.test.js,锁定默认数据目录、public目录与飞书配置文件的绝对位置 - 维护与部署.md补充目录说明并更新模块路径 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
95c481c74a
commit
9ec37196d4
172 files changed
+458
-384
No files matched your search
@@ -0,0 +1,60 @@
|
||||
'use strict';
|
||||
// 店铺配置只用于新单。历史单据缺快照时回到原逐笔费率,不能用今天的设置补历史。
|
||||
const Cards = require('../../public/credit-card-fees');
|
||||
const tableFor = kind => (kind === 'order' ? 'orders' : kind === 'price_lock' ? 'price_locks' : null);
|
||||
function initialize(ledger) {
|
||||
// 独立表避免改变旧订单的 SELECT * 结果及待审批申请的快照哈希。
|
||||
ledger.db.exec(
|
||||
"CREATE TABLE IF NOT EXISTS credit_card_rate_snapshots(kind TEXT NOT NULL CHECK(kind IN ('order','price_lock')),entity_id TEXT NOT NULL,rate_permille INTEGER NOT NULL CHECK(rate_permille BETWEEN 0 AND 1000),PRIMARY KEY(kind,entity_id))",
|
||||
);
|
||||
}
|
||||
function current(ledger) {
|
||||
return Cards.rate(require('./shop-settings').read(ledger).creditCardRatePermille);
|
||||
}
|
||||
function recordedRate(fee) {
|
||||
const value = fee.rate_permille ?? fee.card_fee_rate;
|
||||
if (Number.isSafeInteger(value) && value >= 0 && value <= 1000) return value;
|
||||
const match = String(fee.note ?? fee.card_fee_note ?? '').match(/^信用卡手续费((\d+)‰)$/);
|
||||
if (match && Number(match[1]) <= 1000) return Number(match[1]);
|
||||
return null;
|
||||
}
|
||||
function read(ledger, kind, id) {
|
||||
const table = tableFor(kind);
|
||||
if (!table) throw new Error('信用卡费率单据类型无效');
|
||||
const snapshot = ledger.one(
|
||||
'SELECT rate_permille FROM credit_card_rate_snapshots WHERE kind=? AND entity_id=?',
|
||||
kind,
|
||||
id,
|
||||
);
|
||||
if (snapshot) return Cards.rate(snapshot.rate_permille);
|
||||
const row = ledger.one('SELECT * FROM ' + table + ' WHERE id=?', id);
|
||||
if (!row) throw new Error('信用卡费率单据不存在');
|
||||
const fees =
|
||||
kind === 'order'
|
||||
? JSON.parse(row.fee_items).filter(Cards.isFee)
|
||||
: ledger.rows(
|
||||
'SELECT card_fee_rate,card_fee_note FROM price_lock_events WHERE price_lock_id=? AND card_fee_amount IS NOT NULL ORDER BY created,rowid',
|
||||
id,
|
||||
);
|
||||
for (const fee of fees) {
|
||||
const rate = recordedRate(fee);
|
||||
if (rate !== null) return rate;
|
||||
}
|
||||
return Cards.ratePermille;
|
||||
}
|
||||
function capture(ledger, kind, id, value = current(ledger)) {
|
||||
const table = tableFor(kind);
|
||||
if (!table) throw new Error('信用卡费率单据类型无效');
|
||||
const rate = Cards.rate(value);
|
||||
ledger.run(
|
||||
'INSERT INTO credit_card_rate_snapshots(kind,entity_id,rate_permille) VALUES (?,?,?) ON CONFLICT(kind,entity_id) DO UPDATE SET rate_permille=excluded.rate_permille',
|
||||
kind,
|
||||
id,
|
||||
rate,
|
||||
);
|
||||
return rate;
|
||||
}
|
||||
function remove(ledger, kind, id) {
|
||||
ledger.run('DELETE FROM credit_card_rate_snapshots WHERE kind=? AND entity_id=?', kind, id);
|
||||
}
|
||||
module.exports = { initialize, current, read, capture, remove };
|
||||
Reference in new issue
Block a user