feat: enhance Telegram notification to include total service cost

- Updated the Telegram notification message to display the total cost of services associated with an order, improving transparency for clients and masters.
- Added logic to calculate the total price based on individual service prices and formatted the price for better readability.
This commit is contained in:
vchikalkin 2025-08-20 17:59:36 +03:00
parent 01fbd1c696
commit 37c28353a9

View File

@ -107,16 +107,28 @@ async function sendTelegramNotification(orderEntity: Order, isUpdate = false) {
const clientName = order.client?.name || '-'; const clientName = order.client?.name || '-';
const masterName = slot.master?.name || '-'; const masterName = slot.master?.name || '-';
// Формируем список всех услуг // Формируем список всех услуг и вычисляем общую стоимость
const servicesList = order.services?.length let servicesList = '-';
? order.services.map(service => service.name).join(', ') let totalPrice = 0;
: '-';
if (order.services?.length) {
servicesList = order.services.map(service => service.name).join(', ');
// Вычисляем общую стоимость
totalPrice = order.services.reduce((sum, service) => {
return sum + (service.price || 0);
}, 0);
}
// Форматируем цену для отображения
const priceText = totalPrice > 0 ? `${totalPrice.toLocaleString('ru-RU')}` : 'Не указана';
const messageForMaster = `${heading} const messageForMaster = `${heading}
<b>Дата:</b> ${date} <b>Дата:</b> ${date}
<b>Время:</b> ${timeStartString} - ${timeEndString} <b>Время:</b> ${timeStartString} - ${timeEndString}
<b>Клиент:</b> ${clientName} <b>Клиент:</b> ${clientName}
<b>Услуги:</b> ${servicesList} <b>Услуги:</b> ${servicesList}
<b>Стоимость:</b> ${priceText}
<b>Статус:</b> ${emojiForState} ${stateLabel}`; <b>Статус:</b> ${emojiForState} ${stateLabel}`;
const messageForClient = `${heading} const messageForClient = `${heading}
@ -124,6 +136,7 @@ async function sendTelegramNotification(orderEntity: Order, isUpdate = false) {
<b>Время:</b> ${timeStartString} - ${timeEndString} <b>Время:</b> ${timeStartString} - ${timeEndString}
<b>Мастер:</b> ${masterName} <b>Мастер:</b> ${masterName}
<b>Услуги:</b> ${servicesList} <b>Услуги:</b> ${servicesList}
<b>Стоимость:</b> ${priceText}
<b>Статус:</b> ${emojiForState} ${stateLabel}`; <b>Статус:</b> ${emojiForState} ${stateLabel}`;
if (masterTelegramId) { if (masterTelegramId) {