锁价支持手动料价和当日加权料池预留

This commit is contained in:
summer committed 2026-11-02 19:30:28 +08:00
1 parent 4e5a04a34e
commit 9893ecf037
22 files changed
+622 -94

No files matched your search

+4
View File
@@ -3,6 +3,7 @@
const {randomUUID}=require('node:crypto');
const MaterialPools=require('./material-pools');
const Rolling=require('./rolling-material-pools');
const LockPoolApprovals=require('./price-lock-pool-approvals');
const hash=require('./order-snapshot-hash');
function activeActor(actor,env){if(!actor||!['owner','assistant'].includes(actor.role))env.fail('请使用麦麦或助理账号处理取消申请',403);}
function owner(actor,env){activeActor(actor,env);if(actor.role!=='owner')env.fail('取消申请必须由麦麦账号审批',403);}
@@ -35,6 +36,9 @@ function snapshot(ledger,id){
for(const table of ['payments','expenses','settlements','journal','movements'])tables[table]=ledger.rows('SELECT * FROM '+table+' WHERE order_id=? ORDER BY rowid',id);
tables.corrections=ledger.rows('SELECT * FROM corrections WHERE target IN (SELECT id FROM payments WHERE order_id=? UNION SELECT id FROM expenses WHERE order_id=? UNION SELECT id FROM settlements WHERE order_id=?) ORDER BY rowid',id,id,id);
tables.materialUsages=ledger.rows('SELECT * FROM material_pool_usages WHERE order_id=? ORDER BY rowid',id);
const poolIds=[...new Set(tables.materialUsages.map(row=>row.pool_id))],poolLocks=poolIds.map(poolId=>({id:poolId,...LockPoolApprovals.snapshot(ledger,{poolId})})).filter(pool=>pool.priceLockPool);
// 作废审计会回传原单详情;仅保存依赖指纹,不能带入其他成员锁单的客户资料。
if(poolLocks.length)tables.priceLockPoolDependencies=poolLocks.map(pool=>({id:pool.id,hash:hash(pool.priceLockPool)}));
const priceLock=ledger.one('SELECT id FROM price_locks WHERE final_order_id=?',id)?.id||null;
// 不改变旧模式申请的哈希;滚动模式另核对跨日来源和第三人归属,防止批准旧试算。
return {order,...tables,priceLock,...(Rolling.enabled(ledger)?{rollingDependency:Rolling.dependency(ledger)}:{})};