来源仓库: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 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
86 lines
2.6 KiB
JavaScript
86 lines
2.6 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;
|
|
}
|
|
|
|
async function main() {
|
|
const token = await login();
|
|
const [supplierCategories, catalogCats] = await Promise.all([
|
|
query(token, { action: 'select', table: 'supplier_categories', select: '*' }),
|
|
query(token, {
|
|
action: 'select',
|
|
table: 'product_catalog',
|
|
select: 'code, name, parent_code, level',
|
|
filters: [{ op: 'eq', column: 'item_type', value: 'category' }],
|
|
}),
|
|
]);
|
|
|
|
const catMap = Object.fromEntries((catalogCats || []).map((c) => [c.code, c]));
|
|
const boundCodes = [...new Set((supplierCategories || []).map((sc) => sc.category_code))];
|
|
|
|
console.log('绑定分类详情:');
|
|
for (const code of boundCodes) {
|
|
const c = catMap[code];
|
|
console.log(` ${code}: ${c?.name || 'NOT IN CATALOG'} L${c?.level ?? '?'} parent=${c?.parent_code || '-'}`);
|
|
}
|
|
|
|
const samples = ['VEG001', 'MEAT001', 'CAT09800987174', 'CAT09800978732', 'CAT97139649', 'CAT09803248242', 'DRY001', 'CAT97128850'];
|
|
console.log('\n样本分类:');
|
|
for (const code of samples) {
|
|
const c = catMap[code];
|
|
if (!c) {
|
|
console.log(` ${code}: NOT FOUND`);
|
|
continue;
|
|
}
|
|
let chain = [code];
|
|
let p = c.parent_code;
|
|
while (p) {
|
|
chain.push(p);
|
|
p = catMap[p]?.parent_code;
|
|
}
|
|
console.log(` ${code}: ${c.name} L${c.level} chain=${chain.map((x) => `${catMap[x]?.name || x}`).join(' > ')}`);
|
|
}
|
|
|
|
// count how many order skus would match if we walk chain
|
|
const skus = await query(token, { action: 'select', table: 'skus', select: 'sku_code, category_code' });
|
|
let match = 0;
|
|
let miss = 0;
|
|
for (const sku of skus || []) {
|
|
if (!sku.category_code) {
|
|
miss++;
|
|
continue;
|
|
}
|
|
let cur = sku.category_code;
|
|
const seen = new Set();
|
|
let found = false;
|
|
while (cur && !seen.has(cur)) {
|
|
seen.add(cur);
|
|
if (boundCodes.includes(cur)) {
|
|
found = true;
|
|
break;
|
|
}
|
|
cur = catMap[cur]?.parent_code;
|
|
}
|
|
if (found) match++;
|
|
else miss++;
|
|
}
|
|
console.log(`\nSKU 分类链匹配绑定: match=${match} miss=${miss} total=${skus?.length}`);
|
|
}
|
|
|
|
main().catch(console.error);
|