来源仓库: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 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
98 lines
3.4 KiB
JavaScript
98 lines
3.4 KiB
JavaScript
const API = 'https://www.xdjchuanhui.com/api';
|
|
|
|
async function login() {
|
|
const res = await fetch(`${API}/auth/token`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ email: 'superadmin@meoo.local', password: 'SuperAdmin@123' }),
|
|
});
|
|
return (await res.json()).access_token;
|
|
}
|
|
|
|
async function query(token, spec) {
|
|
const res = await fetch(`${API}/data/query`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` },
|
|
body: JSON.stringify(spec),
|
|
});
|
|
return (await res.json()).data;
|
|
}
|
|
|
|
function getCategoryChain(code, map) {
|
|
const chain = [];
|
|
let cur = code;
|
|
const seen = new Set();
|
|
while (cur && !seen.has(cur)) {
|
|
seen.add(cur);
|
|
chain.push(cur);
|
|
cur = map[cur]?.parent_code || null;
|
|
}
|
|
return chain;
|
|
}
|
|
|
|
async function main() {
|
|
const token = await login();
|
|
const [supplierCategories, suppliers, catalogCats, orderItems, skus] = await Promise.all([
|
|
query(token, { action: 'select', table: 'supplier_categories', select: '*' }),
|
|
query(token, { action: 'select', table: 'suppliers', select: 'supplier_code, company_name, status' }),
|
|
query(token, {
|
|
action: 'select',
|
|
table: 'product_catalog',
|
|
select: 'code, name, parent_code, item_type, level',
|
|
filters: [{ op: 'eq', column: 'item_type', value: 'category' }],
|
|
}),
|
|
query(token, {
|
|
action: 'select',
|
|
table: 'order_items',
|
|
select: 'id, order_code, sku_code, item_name, supplier_code, category_code',
|
|
orders: [{ column: 'created_at', ascending: false }],
|
|
}),
|
|
query(token, { action: 'select', table: 'skus', select: 'sku_code, category_code, sku_name' }),
|
|
]);
|
|
|
|
const catMap = Object.fromEntries(
|
|
(catalogCats || []).map((c) => [c.code, { parent_code: c.parent_code, name: c.name, level: c.level }])
|
|
);
|
|
const skuMap = Object.fromEntries((skus || []).map((s) => [s.sku_code, s]));
|
|
const supplierMap = Object.fromEntries((suppliers || []).map((s) => [s.supplier_code, s]));
|
|
|
|
const items = (orderItems || []).slice(0, 20);
|
|
console.log('订单明细样本:', items.length, '/ 总', orderItems?.length);
|
|
|
|
for (const item of items) {
|
|
const cat = item.category_code || skuMap[item.sku_code]?.category_code;
|
|
if (!cat) {
|
|
console.log(` NO_CAT: ${item.item_name || item.sku_code}`);
|
|
continue;
|
|
}
|
|
const chain = getCategoryChain(cat, catMap);
|
|
let matched = null;
|
|
let matchedCode = null;
|
|
for (const code of chain) {
|
|
const hits = (supplierCategories || []).filter((sc) => sc.category_code === code);
|
|
if (hits.length) {
|
|
matched = hits.sort((a, b) => Number(b.is_primary) - Number(a.is_primary))[0];
|
|
matchedCode = code;
|
|
break;
|
|
}
|
|
}
|
|
const catName = catMap[cat]?.name || cat;
|
|
if (matched) {
|
|
const supName = supplierMap[matched.supplier_code]?.company_name || matched.supplier_code;
|
|
const actual = item.supplier_code
|
|
? supplierMap[item.supplier_code]?.company_name || item.supplier_code
|
|
: '(空)';
|
|
console.log(
|
|
` MATCH@${matchedCode}: ${item.item_name || item.sku_code} [${catName}] 期望=${supName} 实际=${actual}`
|
|
);
|
|
} else {
|
|
const chainStr = chain
|
|
.map((c) => `${catMap[c]?.name || '?'}(${c},L${catMap[c]?.level ?? '?'})`)
|
|
.join(' > ');
|
|
console.log(` MISS: ${item.item_name || item.sku_code} [${catName}] 链=${chainStr}`);
|
|
}
|
|
}
|
|
}
|
|
|
|
main().catch(console.error);
|