fix: 使用计算工具重新计算亚克力-单 SKU价格
配件价格调整(按配件清单): - D3-4G: ¥38 → ¥25 - mSATA-32G: ¥25 → ¥20 - mSATA-64G: ¥45 → ¥40 更新内容: - 更新20个SKU文件的成本和售价 - 更新产品价格汇总表亚克力-单部分 - 更新配件价格参考表 - 新增SKU价格计算工具脚本
This commit is contained in:
@@ -1,51 +1,58 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
// SKU价格计算工具
|
||||
// 亚克力-单 固定配件成本
|
||||
const FIXED_COST = 42 + 12 + 4 + 1 + 1 + 10 + 5 + 10; // 机箱+电源+硬盘线+电池+网线+运费+包装+装机 = 85
|
||||
|
||||
// SKU目录
|
||||
const skuDir = path.join(__dirname, '../../产品/飞牛 NAS/fyd-亚克力机箱 - 单/sku');
|
||||
// 配件价格(来自配件清单)
|
||||
const CPU_PRICES = {
|
||||
'N2840': 45,
|
||||
'N2930': 50,
|
||||
'AMD-A4': 45,
|
||||
'J1900': 80,
|
||||
'J3160': 90
|
||||
};
|
||||
|
||||
// 读取所有SKU文件
|
||||
const files = fs.readdirSync(skuDir).filter(f => f.endsWith('.md'));
|
||||
const MEMORY_PRICES = {
|
||||
'2G-16G': { ram: 13, disk: 15 }, // D3-2G + mSATA-16G
|
||||
'2G-32G': { ram: 13, disk: 20 }, // D3-2G + mSATA-32G
|
||||
'4G-64G': { ram: 25, disk: 40 }, // D3-4G + mSATA-64G
|
||||
'4G-128G': { ram: 25, disk: 68 } // D3-4G + mSATA-128G
|
||||
};
|
||||
|
||||
let updatedCount = 0;
|
||||
const CPUS = ['N2840', 'N2930', 'AMD-A4', 'J1900', 'J3160'];
|
||||
const MEMORIES = ['2G-16G', '2G-32G', '4G-64G', '4G-128G'];
|
||||
|
||||
files.forEach(file => {
|
||||
const filePath = path.join(skuDir, file);
|
||||
let content = fs.readFileSync(filePath, 'utf-8');
|
||||
const lines = content.split('\n');
|
||||
|
||||
// 计算总成本(只计算配件,不包括总成本和建议零售价)
|
||||
let totalCost = 0;
|
||||
let shouldCalculate = true;
|
||||
|
||||
lines.forEach(line => {
|
||||
// 遇到总成本行时停止计算
|
||||
if (line.includes('**总成本**')) {
|
||||
shouldCalculate = false;
|
||||
}
|
||||
console.log('=== 亚克力-单 SKU 价格计算 ===\n');
|
||||
|
||||
let results = [];
|
||||
let index = 1;
|
||||
|
||||
CPUS.forEach(cpu => {
|
||||
MEMORIES.forEach(mem => {
|
||||
const cpuCost = CPU_PRICES[cpu];
|
||||
const ramCost = MEMORY_PRICES[mem].ram;
|
||||
const diskCost = MEMORY_PRICES[mem].disk;
|
||||
const totalCost = FIXED_COST + cpuCost + ramCost + diskCost;
|
||||
const price = Math.round(totalCost * 1.3);
|
||||
const profit = price - totalCost;
|
||||
|
||||
if (shouldCalculate) {
|
||||
// 匹配价格行: | **字段** | 配件名称 | ¥价格 |
|
||||
const match = line.match(/\| \*\*[^*]+\*\* \| [^|]+ \| ¥(\d+) |/);
|
||||
if (match) {
|
||||
const price = parseInt(match[1]);
|
||||
if (!isNaN(price)) {
|
||||
totalCost += price;
|
||||
}
|
||||
}
|
||||
}
|
||||
const sku = `亚克力 - 单-${cpu}-${mem}`;
|
||||
results.push({ index, sku, cost: totalCost, price, profit });
|
||||
|
||||
console.log(`${index}. ${sku}`);
|
||||
console.log(` CPU(${cpu}): ¥${cpuCost} + 内存: ¥${ramCost} + 系统盘: ¥${diskCost} + 固定: ¥${FIXED_COST}`);
|
||||
console.log(` 成本: ¥${totalCost} | 售价: ¥${price} | 利润: ¥${profit}\n`);
|
||||
|
||||
index++;
|
||||
});
|
||||
|
||||
const suggestedPrice = Math.round(totalCost * 1.3);
|
||||
|
||||
// 更新总成本
|
||||
content = content.replace(/\| \*\*总成本\*\* \| - \| ¥[^|]+ \|/, `| **总成本** | - | ¥${totalCost} |`);
|
||||
// 更新建议零售价
|
||||
content = content.replace(/\| \*\*建议零售价\*\* \| - \| ¥[^|]+ \|/, `| **建议零售价** | - | ¥${suggestedPrice} |`);
|
||||
|
||||
fs.writeFileSync(filePath, content, 'utf-8');
|
||||
console.log(`Updated: ${file} - 总成本: ¥${totalCost}, 建议零售价: ¥${suggestedPrice}`);
|
||||
updatedCount++;
|
||||
});
|
||||
|
||||
console.log(`\n总计更新 ${updatedCount} 个文件`);
|
||||
// 输出汇总表格式的数据
|
||||
console.log('\n=== 汇总表更新数据 ===');
|
||||
results.forEach(r => {
|
||||
console.log(`| ${r.index} | ${r.sku} | ¥${r.cost} | ¥${r.price} | ¥${r.profit} | 30% |`);
|
||||
});
|
||||
|
||||
// 导出JSON供后续使用
|
||||
const fs = require('fs');
|
||||
fs.writeFileSync('./sku-results.json', JSON.stringify(results, null, 2));
|
||||
console.log('\n已导出计算结果到 sku-results.json');
|
||||
|
||||
Reference in New Issue
Block a user