Add variant selection with price and integrate into order
This commit is contained in:
parent
b7c0542f17
commit
e5bf8ffbe0
BIN
WhatsApp Image 2026-10-06 at 11.31.02 _1_-1.jpeg
Normal file
BIN
WhatsApp Image 2026-10-06 at 11.31.02 _1_-1.jpeg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 169 KiB |
BIN
WhatsApp Image 2026-10-06 at 11.31.02 _2_-1.jpeg
Normal file
BIN
WhatsApp Image 2026-10-06 at 11.31.02 _2_-1.jpeg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 196 KiB |
BIN
WhatsApp Image 2026-10-06 at 11.31.02-1.jpeg
Normal file
BIN
WhatsApp Image 2026-10-06 at 11.31.02-1.jpeg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 209 KiB |
BIN
WhatsApp Image 2026-10-06 at 11.31.03 _1_-1.jpeg
Normal file
BIN
WhatsApp Image 2026-10-06 at 11.31.03 _1_-1.jpeg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 178 KiB |
BIN
WhatsApp Image 2026-10-06 at 11.31.03 _2_-1.jpeg
Normal file
BIN
WhatsApp Image 2026-10-06 at 11.31.03 _2_-1.jpeg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 152 KiB |
38
bot.js
38
bot.js
@ -59,6 +59,7 @@ function formatOrder(order) {
|
|||||||
return `📦 Номер заказа: ${order.id}\n`
|
return `📦 Номер заказа: ${order.id}\n`
|
||||||
+ `🧁 Вид: ${order.type}\n`
|
+ `🧁 Вид: ${order.type}\n`
|
||||||
+ `🔢 Кол‑во: ${order.quantity}\n`
|
+ `🔢 Кол‑во: ${order.quantity}\n`
|
||||||
|
+ `🧩 Вариант: ${order.variant + 1}\n`
|
||||||
+ `📅 Дата доставки: ${order.date}\n`
|
+ `📅 Дата доставки: ${order.date}\n`
|
||||||
+ `🕒 Время: ${order.time}\n`
|
+ `🕒 Время: ${order.time}\n`
|
||||||
+ `👤 Имя: ${order.name}\n`
|
+ `👤 Имя: ${order.name}\n`
|
||||||
@ -77,14 +78,20 @@ bot.command('start', async (ctx) => {
|
|||||||
await ctx.replyWithPhoto(new InputFile(filePath), { caption: `Вариант ${i + 1}` }).catch(() => {});
|
await ctx.replyWithPhoto(new InputFile(filePath), { caption: `Вариант ${i + 1}` }).catch(() => {});
|
||||||
}
|
}
|
||||||
// Кнопки выбора типа продукта
|
// Кнопки выбора типа продукта
|
||||||
await ctx.reply('Какой вариант вас интересует?', {
|
// Предлагаем выбрать вариант товара с ценой
|
||||||
|
const variantButtons = images.map((_, i) => {
|
||||||
|
const price = i % 2 === 0 ? PRICE['букет'] : PRICE['коробка'];
|
||||||
|
return `Вариант ${i + 1} – ${price}₸`;
|
||||||
|
});
|
||||||
|
const variantKeyboard = variantButtons.map(b => [b]);
|
||||||
|
await ctx.reply('Выберите вариант товара:', {
|
||||||
reply_markup: {
|
reply_markup: {
|
||||||
keyboard: [['Букет', 'Коробка']],
|
keyboard: variantKeyboard,
|
||||||
one_time_keyboard: true,
|
one_time_keyboard: true,
|
||||||
resize_keyboard: true,
|
resize_keyboard: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
setStage(ctx.chat.id, { stage: 'choose_type' });
|
setStage(ctx.chat.id, { stage: 'choose_variant' });
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.on('message:text', async (ctx) => {
|
bot.on('message:text', async (ctx) => {
|
||||||
@ -99,7 +106,28 @@ bot.on('message:text', async (ctx) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch (session.stage) {
|
switch (session.stage) {
|
||||||
case 'choose_type': {
|
case 'choose_variant': {
|
||||||
|
const match = text.match(/Вариант\s(\d+)/);
|
||||||
|
if (!match) {
|
||||||
|
await ctx.reply('Пожалуйста, выберите вариант из списка.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const idx = parseInt(match[1], 10) - 1;
|
||||||
|
if (idx < 0 || idx >= images.length) {
|
||||||
|
await ctx.reply('Неправильный вариант.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setStage(chatId, { variant: idx, stage: 'choose_type' });
|
||||||
|
await ctx.reply('Какой вариант вас интересует? Выберите: Букет или Коробка.', {
|
||||||
|
reply_markup: {
|
||||||
|
keyboard: [['Букет', 'Коробка']],
|
||||||
|
one_time_keyboard: true,
|
||||||
|
resize_keyboard: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'choose_type': {
|
||||||
if (text !== 'букет' && text !== 'коробка') {
|
if (text !== 'букет' && text !== 'коробка') {
|
||||||
await ctx.reply('Пожалуйста, укажите "букет" или "коробка".');
|
await ctx.reply('Пожалуйста, укажите "букет" или "коробка".');
|
||||||
return;
|
return;
|
||||||
@ -253,7 +281,7 @@ case 'await_time': {
|
|||||||
const { type, quantity, date, time, name } = session;
|
const { type, quantity, date, time, name } = session;
|
||||||
const total = PRICE[type] * quantity;
|
const total = PRICE[type] * quantity;
|
||||||
const orderId = Date.now();
|
const orderId = Date.now();
|
||||||
const order = { id: orderId, type, quantity, date, time, name, phone, total };
|
const order = { id: orderId, type, quantity, date, time, name, phone, total, variant: session.variant };
|
||||||
saveOrder(order);
|
saveOrder(order);
|
||||||
// Формируем итоговое сообщение
|
// Формируем итоговое сообщение
|
||||||
await ctx.reply(formatOrder(order));
|
await ctx.reply(formatOrder(order));
|
||||||
|
|||||||
20
data.json
20
data.json
@ -28,5 +28,25 @@
|
|||||||
"name": "Роман",
|
"name": "Роман",
|
||||||
"phone": "+77059631941",
|
"phone": "+77059631941",
|
||||||
"total": 9000
|
"total": 9000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 1791288625288,
|
||||||
|
"type": "букет",
|
||||||
|
"quantity": 3,
|
||||||
|
"date": "2026-10-07",
|
||||||
|
"time": "12:00",
|
||||||
|
"name": "Роман",
|
||||||
|
"phone": "+77059631941",
|
||||||
|
"total": 15000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 1791288816480,
|
||||||
|
"type": "коробка",
|
||||||
|
"quantity": 4,
|
||||||
|
"date": "2026-10-06",
|
||||||
|
"time": "12:00",
|
||||||
|
"name": "Ро",
|
||||||
|
"phone": "97483828727181",
|
||||||
|
"total": 12000
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
Loading…
Reference in New Issue
Block a user