优化订单搜索和对账的批量取数与索引查询

This commit is contained in:
黄健铭 committed 2026-12-05 19:15:04 -08:00
1 parent 3aebb62252
commit cf0b0be83f
16 files changed
+671 -186

No files matched your search

@@ -36,12 +36,18 @@ function read(ledger, kind, id) {
'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,
);
return fromFees(fees);
}
function fromFees(fees) {
for (const fee of fees) {
const rate = recordedRate(fee);
if (rate !== null) return rate;
}
return Cards.ratePermille;
}
function forOrder(order, snapshotRate) {
return snapshotRate === undefined ? fromFees(order.fee_items.filter(Cards.isFee)) : Cards.rate(snapshotRate);
}
function capture(ledger, kind, id, value = current(ledger)) {
const table = tableFor(kind);
if (!table) throw new Error('信用卡费率单据类型无效');
@@ -57,4 +63,4 @@ function capture(ledger, kind, id, value = current(ledger)) {
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 };
module.exports = { initialize, current, read, forOrder, capture, remove };