来源仓库:jxc/ai-fresh-delivery 来源提交:f0b1a180e2deb7e4673b9d1c8542619f7bc0f73d 快照树: 09f679334ff38f0ff25e907961c94a8223bcaedd(与来源 HEAD 工作树逐字节一致,3801 个文件) 按约定本仓库不带任何历史提交:来源仓库的历史中含真实凭据 (生产 SSH 私钥 deploy/id_rsa_tencent、server/.env、.env.tencent/.env.production/.env.gitea、 deploy/小程序AppSecret.txt,其中 MP_APPSECRET / S3 AccessKey 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
47 lines
2.2 KiB
TypeScript
47 lines
2.2 KiB
TypeScript
import { pool } from './src/db';
|
||
import { runWithTenantDataAccess } from './src/services/tenantSchemaService';
|
||
import { resolveSkuPricesForCustomer, resolveSkuPriceForCustomer, normalizeUnitKey } from './src/services/orderPricingService';
|
||
|
||
async function main() {
|
||
const branch = process.argv[2] || 'BR002';
|
||
await runWithTenantDataAccess(branch, async () => {
|
||
// 取一个零价样本:CUS34931115429 西瓜 SKU78666937433(报价 ¥2.50)
|
||
const samples = [
|
||
{ customer: 'CUS34931115429', sku: 'SKU78666937433', name: '西瓜' },
|
||
{ customer: 'CUS34952066486', sku: 'SKU78668520975', name: '鲫鱼' },
|
||
{ customer: 'CUS34964973228', sku: 'SKU78668735222', name: '鸡蛋' },
|
||
];
|
||
for (const s of samples) {
|
||
const batchPrice = await resolveSkuPricesForCustomer(s.customer, [s.sku]);
|
||
console.log(`\n=== ${s.name} (${s.customer}/${s.sku}) ===`);
|
||
console.log(`resolveSkuPricesForCustomer -> ${batchPrice.get(s.sku) ?? '(未命中)'}`);
|
||
|
||
// 直接查报价表(不过滤分公司/单位)
|
||
const raw = await pool.query(
|
||
`SELECT customer_code, sku_code, price, unit, branch_code, status, approval_status,
|
||
effective_at, expires_at
|
||
FROM customer_quote_versions
|
||
WHERE customer_code=$1 AND sku_code=$2
|
||
ORDER BY effective_at DESC NULLS LAST LIMIT 5`,
|
||
[s.customer, s.sku]
|
||
);
|
||
console.log('customer_quote_versions 原始行:');
|
||
for (const r of raw.rows) console.log(' ', r);
|
||
|
||
const cust = await pool.query(`SELECT branch_code FROM customers WHERE customer_code=$1`, [s.customer]);
|
||
console.log(`客户 branch_code = ${cust.rows[0]?.branch_code}`);
|
||
}
|
||
|
||
// 顺便看订单明细里的 unit 是什么
|
||
const itemUnit = await pool.query(
|
||
`SELECT oi.order_code, oi.unit, oi.sku_code, o.customer_code
|
||
FROM order_items oi JOIN orders o ON o.order_code=oi.order_code
|
||
WHERE o.customer_code='CUS34931115429' AND oi.sku_code='SKU78666937433'
|
||
ORDER BY oi.created_at DESC LIMIT 3`
|
||
);
|
||
console.log('\n订单明细里的 unit:', itemUnit.rows);
|
||
});
|
||
await pool.end();
|
||
}
|
||
main().catch((e) => { console.error(e); process.exit(1); });
|