来源仓库: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 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
127 lines
4.7 KiB
JavaScript
127 lines
4.7 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;
|
|
}
|
|
|
|
const ALIASES = {
|
|
BEEF001: ['牛羊肉', '牛类', '羊类', '牛肉', '羊肉'],
|
|
DAIRY001: ['奶品', '牛奶', '酸奶', '乳制品'],
|
|
DRINK001: ['饮料', '饮品'],
|
|
DRY001: ['干货副食', '干杂', '调味品', '调料', '干货'],
|
|
FROZEN001: ['冷冻品', '冻品'],
|
|
GRAIN001: ['粮油米面', '粮油', '米面', '大米', '面粉'],
|
|
MEAT001: ['猪肉', '鲜肉', '猪类', '排骨', '五花肉', '里脊'],
|
|
POULTRY001: ['禽类', '鸡', '鸭', '鹅'],
|
|
SEA001: ['水产海鲜', '水产', '海鲜', '鱼', '虾', '蟹'],
|
|
STAPLE001: ['面点主食', '面点', '主食', '面食', '馒头', '包子'],
|
|
CAT97139649: ['豆制品', '豆花', '豆腐', '豆皮'],
|
|
FRUIT001: ['水果', '果类'],
|
|
VEG001: ['蔬菜', '叶菜类', '根菜类', '瓜类', '葱蒜类', '茄果类', '菌菇类', '豆类', '甘蓝类', '花菜类', '菱角类', '谷物'],
|
|
};
|
|
|
|
function chain(code, map) {
|
|
const out = [];
|
|
let cur = code;
|
|
const seen = new Set();
|
|
while (cur && !seen.has(cur)) {
|
|
seen.add(cur);
|
|
out.push(cur);
|
|
cur = map[cur]?.parent_code || null;
|
|
}
|
|
return out;
|
|
}
|
|
|
|
function lookupCodes(categoryCode, catMap, bindings) {
|
|
const codes = chain(categoryCode, catMap);
|
|
const names = codes.map((c) => catMap[c]?.name).filter(Boolean);
|
|
const bound = new Set(bindings.map((b) => b.category_code));
|
|
const ordered = [...codes];
|
|
for (const [bindingCode, aliases] of Object.entries(ALIASES)) {
|
|
if (!bound.has(bindingCode)) continue;
|
|
if (aliases.some((a) => names.some((n) => n === a || n.includes(a) || a.includes(n)))) {
|
|
if (!ordered.includes(bindingCode)) ordered.push(bindingCode);
|
|
}
|
|
}
|
|
return ordered;
|
|
}
|
|
|
|
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, 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' }),
|
|
]);
|
|
|
|
const catMap = Object.fromEntries((catalogCats || []).map((c) => [c.code, c]));
|
|
const skuMap = Object.fromEntries((skus || []).map((s) => [s.sku_code, s]));
|
|
const supplierMap = Object.fromEntries((suppliers || []).map((s) => [s.supplier_code, s]));
|
|
const active = new Set((suppliers || []).filter((s) => [10, 20].includes(Number(s.status))).map((s) => s.supplier_code));
|
|
|
|
let matched = 0;
|
|
let mismatch = 0;
|
|
let noBinding = 0;
|
|
let empty = 0;
|
|
|
|
for (const item of (orderItems || []).slice(0, 50)) {
|
|
const cat = item.category_code || skuMap[item.sku_code]?.category_code;
|
|
if (!cat) continue;
|
|
const codes = lookupCodes(cat, catMap, supplierCategories || []);
|
|
let expected = null;
|
|
for (const code of codes) {
|
|
const hits = (supplierCategories || []).filter((sc) => sc.category_code === code);
|
|
if (hits.length) {
|
|
expected = hits.sort((a, b) => Number(b.is_primary) - Number(a.is_primary))[0];
|
|
break;
|
|
}
|
|
}
|
|
const name = item.item_name || item.sku_code;
|
|
if (!expected) {
|
|
noBinding++;
|
|
continue;
|
|
}
|
|
if (!active.has(expected.supplier_code)) continue;
|
|
const expName = supplierMap[expected.supplier_code]?.company_name;
|
|
if (!item.supplier_code) {
|
|
empty++;
|
|
console.log(`[未分配] ${name} 应=${expName}`);
|
|
} else if (item.supplier_code !== expected.supplier_code) {
|
|
mismatch++;
|
|
console.log(`[不一致] ${name} 应=${expName} 实=${supplierMap[item.supplier_code]?.company_name || item.supplier_code}`);
|
|
} else {
|
|
matched++;
|
|
}
|
|
}
|
|
|
|
console.log(`\n样本50: 匹配=${matched} 不一致=${mismatch} 未分配=${empty} 无绑定=${noBinding}`);
|
|
}
|
|
|
|
main().catch(console.error);
|