来源仓库: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 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
151 lines
5.3 KiB
JavaScript
151 lines
5.3 KiB
JavaScript
/**
|
|
* 诊断生产环境分类分配为何未生效
|
|
*/
|
|
const API = (process.env.API_BASE_URL || 'https://www.xdjchuanhui.com/api').replace(/\/+$/, '');
|
|
|
|
async function login() {
|
|
const res = await fetch(`${API}/auth/token`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({
|
|
email: process.env.REPROCESS_EMAIL || 'superadmin@meoo.local',
|
|
password: process.env.REPROCESS_PASSWORD || 'SuperAdmin@123',
|
|
}),
|
|
});
|
|
const data = await res.json();
|
|
if (!res.ok) throw new Error(JSON.stringify(data));
|
|
return data.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),
|
|
});
|
|
const payload = await res.json();
|
|
if (payload.error) throw new Error(payload.error.message || JSON.stringify(payload.error));
|
|
return payload.data;
|
|
}
|
|
|
|
async function main() {
|
|
const token = await login();
|
|
|
|
const [supplierCategories, suppliers, catalogCats, legacyCats, orderItems, skuSample] =
|
|
await Promise.all([
|
|
query(token, {
|
|
action: 'select',
|
|
table: 'supplier_categories',
|
|
select: 'supplier_code, category_code, is_primary',
|
|
}),
|
|
query(token, {
|
|
action: 'select',
|
|
table: 'suppliers',
|
|
select: 'supplier_code, company_name, status',
|
|
filters: [],
|
|
}),
|
|
query(token, {
|
|
action: 'select',
|
|
table: 'product_catalog',
|
|
select: 'code, name, parent_code, item_type',
|
|
filters: [{ op: 'eq', column: 'item_type', value: 'category' }],
|
|
}),
|
|
query(token, {
|
|
action: 'select',
|
|
table: 'categories',
|
|
select: 'category_code, category_name, parent_code',
|
|
}),
|
|
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 }],
|
|
limit: 30,
|
|
}),
|
|
query(token, {
|
|
action: 'select',
|
|
table: 'skus',
|
|
select: 'sku_code, sku_name, category_code',
|
|
limit: 20,
|
|
}),
|
|
]);
|
|
|
|
const catalogCodes = new Set((catalogCats || []).map((c) => c.code));
|
|
const legacyCodes = new Set((legacyCats || []).map((c) => c.category_code));
|
|
const activeSuppliers = new Set(
|
|
(suppliers || []).filter((s) => [10, 20].includes(Number(s.status))).map((s) => s.supplier_code)
|
|
);
|
|
|
|
console.log('\n=== 供应商经营品类 ===');
|
|
console.log('绑定数:', supplierCategories?.length || 0);
|
|
const scIssues = [];
|
|
for (const sc of supplierCategories || []) {
|
|
const inCatalog = catalogCodes.has(sc.category_code);
|
|
const inLegacy = legacyCodes.has(sc.category_code);
|
|
const supplierActive = activeSuppliers.has(sc.supplier_code);
|
|
if (!inCatalog && !inLegacy) scIssues.push({ ...sc, issue: 'category_code 不存在' });
|
|
if (!supplierActive) scIssues.push({ ...sc, issue: '供应商非启用状态' });
|
|
}
|
|
console.log('异常绑定:', scIssues.length);
|
|
scIssues.slice(0, 10).forEach((x) =>
|
|
console.log(` ${x.supplier_code} -> ${x.category_code} (${x.issue})`)
|
|
);
|
|
|
|
console.log('\n=== 分类来源 ===');
|
|
console.log('product_catalog 分类数:', catalogCodes.size);
|
|
console.log('categories 表分类数:', legacyCodes.size);
|
|
const onlyLegacy = [...legacyCodes].filter((c) => !catalogCodes.has(c)).slice(0, 5);
|
|
const onlyCatalog = [...catalogCodes].filter((c) => !legacyCodes.has(c)).slice(0, 5);
|
|
console.log('仅在 categories:', onlyLegacy.join(', ') || '(无)');
|
|
console.log('仅在 product_catalog:', onlyCatalog.join(', ') || '(无)');
|
|
|
|
console.log('\n=== 最近订单明细 ===');
|
|
const skuMap = Object.fromEntries((skuSample || []).map((s) => [s.sku_code, s]));
|
|
const supplierMap = Object.fromEntries((suppliers || []).map((s) => [s.supplier_code, s]));
|
|
const bindingsByCat = {};
|
|
for (const sc of supplierCategories || []) {
|
|
if (!bindingsByCat[sc.category_code]) bindingsByCat[sc.category_code] = [];
|
|
bindingsByCat[sc.category_code].push(sc);
|
|
}
|
|
|
|
let mismatch = 0;
|
|
let noCategory = 0;
|
|
let noBinding = 0;
|
|
for (const item of orderItems || []) {
|
|
const cat =
|
|
item.category_code ||
|
|
skuMap[item.sku_code]?.category_code ||
|
|
null;
|
|
if (!cat) {
|
|
noCategory++;
|
|
continue;
|
|
}
|
|
const bindings = bindingsByCat[cat] || [];
|
|
if (!bindings.length) {
|
|
noBinding++;
|
|
console.log(
|
|
` [无绑定] ${item.order_code} ${item.item_name || item.sku_code} cat=${cat} supplier=${item.supplier_code || '-'}`
|
|
);
|
|
continue;
|
|
}
|
|
const expected = bindings.find((b) => b.is_primary) || bindings[0];
|
|
if (item.supplier_code && item.supplier_code !== expected.supplier_code) {
|
|
mismatch++;
|
|
const expName = supplierMap[expected.supplier_code]?.company_name || expected.supplier_code;
|
|
const actName = supplierMap[item.supplier_code]?.company_name || item.supplier_code;
|
|
console.log(
|
|
` [不匹配] ${item.order_code} ${item.item_name || item.sku_code} cat=${cat} 期望=${expName} 实际=${actName}`
|
|
);
|
|
}
|
|
}
|
|
console.log(`统计: 无分类=${noCategory}, 分类无供应商绑定=${noBinding}, 供应商不匹配=${mismatch}`);
|
|
}
|
|
|
|
main().catch((e) => {
|
|
console.error(e);
|
|
process.exit(1);
|
|
});
|