revert 6550451f89d515647e6eee49ea27f35d9aebd681
revert revert 7f32d466116297bf0d4a822ea00fda47ba5fb876 revert revert 2903fcfcbb4e71b368c8f412cf25b6e3fbb3bab7 revert Обновить furniture.js
This commit is contained in:
parent
6550451f89
commit
90bab56b42
143
furniture.js
143
furniture.js
@ -1,72 +1,73 @@
|
||||
|
||||
const express = require('express');
|
||||
const path = require('path');
|
||||
|
||||
const app = express();
|
||||
// --- ИЗМЕНЕНИЕ: Используйте порт 3201, как в вашем конфиге прокси ---
|
||||
const PORT = 3201;
|
||||
|
||||
app.use(express.json());
|
||||
|
||||
// Раздаем ТОЛЬКО нашу папку 'public'
|
||||
app.use(express.static(path.join(__dirname, 'public')));
|
||||
|
||||
// --- УДАЛЕНО: Раздача папок build и jsm больше не нужна ---
|
||||
// app.use('/build', express.static(path.join(__dirname, 'node_modules/three/build')));
|
||||
// app.use('/jsm', express.static(path.join(__dirname, 'node_modules/three/examples/jsm')));
|
||||
|
||||
|
||||
// API эндпоинт для расчета цены (без изменений)
|
||||
const PRICE_CONFIG = {
|
||||
edgeBandingPerMeter: 50,
|
||||
baseWorkCost: 3000,
|
||||
};
|
||||
const MATERIALS_PRICES = {
|
||||
'Белый': 1500,
|
||||
'Серый': 1650,
|
||||
'Черный': 1800,
|
||||
'Образец1': 2200,
|
||||
'Образец2': 2500,
|
||||
};
|
||||
const PANEL_THICKNESS = 16;
|
||||
|
||||
app.post('/api/calculate-price', (req, res) => {
|
||||
const params = req.body;
|
||||
const pricePerM2 = MATERIALS_PRICES[params.materialName];
|
||||
if (!pricePerM2) {
|
||||
return res.status(400).json({ error: 'Invalid material name' });
|
||||
}
|
||||
const { width, height, depth, columns, rows } = params;
|
||||
const M_IN_MM = 1000;
|
||||
let totalAreaM2 = 0;
|
||||
let totalEdgeLengthM = 0;
|
||||
const innerWidth = width - 2 * PANEL_THICKNESS;
|
||||
const innerHeight = height - 2 * PANEL_THICKNESS;
|
||||
const shelfDepth = depth - PANEL_THICKNESS;
|
||||
totalAreaM2 += (2 * height * depth) / (M_IN_MM * M_IN_MM);
|
||||
totalAreaM2 += (2 * width * depth) / (M_IN_MM * M_IN_MM);
|
||||
totalEdgeLengthM += (2 * height + 2 * width) / M_IN_MM;
|
||||
totalAreaM2 += (innerWidth * innerHeight) / (M_IN_MM * M_IN_MM);
|
||||
const numDividers = columns - 1;
|
||||
if (numDividers > 0) {
|
||||
totalAreaM2 += (numDividers * innerHeight * shelfDepth) / (M_IN_MM * M_IN_MM);
|
||||
totalEdgeLengthM += (numDividers * innerHeight) / M_IN_MM;
|
||||
}
|
||||
const numShelves = rows - 1;
|
||||
if (numShelves > 0) {
|
||||
const sectionWidth = (innerWidth - (numDividers * PANEL_THICKNESS)) / columns;
|
||||
const totalShelfArea = (columns * numShelves * sectionWidth * shelfDepth) / (M_IN_MM * M_IN_MM);
|
||||
totalAreaM2 += totalShelfArea;
|
||||
const totalShelfEdgeLength = (columns * numShelves * sectionWidth) / M_IN_MM;
|
||||
totalEdgeLengthM += totalShelfEdgeLength;
|
||||
}
|
||||
const materialCost = totalAreaM2 * pricePerM2;
|
||||
const edgeBandingCost = totalEdgeLengthM * PRICE_CONFIG.edgeBandingPerMeter;
|
||||
const finalPrice = PRICE_CONFIG.baseWorkCost + materialCost + edgeBandingCost;
|
||||
res.json({ price: Math.round(finalPrice) });
|
||||
});
|
||||
|
||||
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Сервер конструктора мебели запущен на порту: ${PORT}`);
|
||||
// server.js
|
||||
|
||||
const express = require('express');
|
||||
const path = require('path');
|
||||
|
||||
const app = express();
|
||||
// --- ИЗМЕНЕНИЕ: Используйте порт 3201, как в вашем конфиге прокси ---
|
||||
const PORT = 3201;
|
||||
|
||||
app.use(express.json());
|
||||
|
||||
// Раздаем ТОЛЬКО нашу папку 'public'
|
||||
app.use(express.static(path.join(__dirname, 'public')));
|
||||
|
||||
// --- УДАЛЕНО: Раздача папок build и jsm больше не нужна ---
|
||||
// app.use('/build', express.static(path.join(__dirname, 'node_modules/three/build')));
|
||||
// app.use('/jsm', express.static(path.join(__dirname, 'node_modules/three/examples/jsm')));
|
||||
|
||||
|
||||
// API эндпоинт для расчета цены (без изменений)
|
||||
const PRICE_CONFIG = {
|
||||
edgeBandingPerMeter: 50,
|
||||
baseWorkCost: 3000,
|
||||
};
|
||||
const MATERIALS_PRICES = {
|
||||
'Белый': 1500,
|
||||
'Серый': 1650,
|
||||
'Черный': 1800,
|
||||
'Образец1': 2200,
|
||||
'Образец2': 2500,
|
||||
};
|
||||
const PANEL_THICKNESS = 16;
|
||||
|
||||
app.post('/api/calculate-price', (req, res) => {
|
||||
const params = req.body;
|
||||
const pricePerM2 = MATERIALS_PRICES[params.materialName];
|
||||
if (!pricePerM2) {
|
||||
return res.status(400).json({ error: 'Invalid material name' });
|
||||
}
|
||||
const { width, height, depth, columns, rows } = params;
|
||||
const M_IN_MM = 1000;
|
||||
let totalAreaM2 = 0;
|
||||
let totalEdgeLengthM = 0;
|
||||
const innerWidth = width - 2 * PANEL_THICKNESS;
|
||||
const innerHeight = height - 2 * PANEL_THICKNESS;
|
||||
const shelfDepth = depth - PANEL_THICKNESS;
|
||||
totalAreaM2 += (2 * height * depth) / (M_IN_MM * M_IN_MM);
|
||||
totalAreaM2 += (2 * width * depth) / (M_IN_MM * M_IN_MM);
|
||||
totalEdgeLengthM += (2 * height + 2 * width) / M_IN_MM;
|
||||
totalAreaM2 += (innerWidth * innerHeight) / (M_IN_MM * M_IN_MM);
|
||||
const numDividers = columns - 1;
|
||||
if (numDividers > 0) {
|
||||
totalAreaM2 += (numDividers * innerHeight * shelfDepth) / (M_IN_MM * M_IN_MM);
|
||||
totalEdgeLengthM += (numDividers * innerHeight) / M_IN_MM;
|
||||
}
|
||||
const numShelves = rows - 1;
|
||||
if (numShelves > 0) {
|
||||
const sectionWidth = (innerWidth - (numDividers * PANEL_THICKNESS)) / columns;
|
||||
const totalShelfArea = (columns * numShelves * sectionWidth * shelfDepth) / (M_IN_MM * M_IN_MM);
|
||||
totalAreaM2 += totalShelfArea;
|
||||
const totalShelfEdgeLength = (columns * numShelves * sectionWidth) / M_IN_MM;
|
||||
totalEdgeLengthM += totalShelfEdgeLength;
|
||||
}
|
||||
const materialCost = totalAreaM2 * pricePerM2;
|
||||
const edgeBandingCost = totalEdgeLengthM * PRICE_CONFIG.edgeBandingPerMeter;
|
||||
const finalPrice = PRICE_CONFIG.baseWorkCost + materialCost + edgeBandingCost;
|
||||
res.json({ price: Math.round(finalPrice) });
|
||||
});
|
||||
|
||||
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Сервер конструктора мебели запущен на порту: ${PORT}`);
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user