Spaces:
Running
Running
Refactor order flow to In-Store Pickup model (remove address, update statuses)
Browse files- bot/bot.js +9 -9
bot/bot.js
CHANGED
|
@@ -439,8 +439,8 @@ if (process.env.BOT_TOKEN && process.env.BOT_TOKEN !== 'YOUR_TELEGRAM_BOT_TOKEN'
|
|
| 439 |
for (const o of orders) {
|
| 440 |
let productsText = "";
|
| 441 |
o.products.forEach(p => { productsText += `β ${p.name} (${p.quantity} ta) \n`; });
|
| 442 |
-
let statusEmoji = o.status === 'Kutilmoqda' ? 'β³' : o.status === '
|
| 443 |
-
const msg = `π§Ύ *ID:* \`${o._id}\`\nπ€ Mijoz: *${o.customerName}*\nπ Tel: ${o.phone}\nπ
|
| 444 |
|
| 445 |
await ctx.reply(msg, { parse_mode: 'Markdown', ...orderStatusButtonsForNotify(o._id, o.status) });
|
| 446 |
}
|
|
@@ -460,9 +460,9 @@ if (process.env.BOT_TOKEN && process.env.BOT_TOKEN !== 'YOUR_TELEGRAM_BOT_TOKEN'
|
|
| 460 |
const orderId = ctx.match[2];
|
| 461 |
|
| 462 |
let newStatus = 'Kutilmoqda';
|
| 463 |
-
if (action === 'accept') newStatus = '
|
| 464 |
-
if (action === 'ship') newStatus = '
|
| 465 |
-
if (action === 'deliver') newStatus = '
|
| 466 |
if (action === 'cancel') newStatus = 'Bekor qilindi';
|
| 467 |
|
| 468 |
try {
|
|
@@ -1046,7 +1046,7 @@ if (process.env.BOT_TOKEN && process.env.BOT_TOKEN !== 'YOUR_TELEGRAM_BOT_TOKEN'
|
|
| 1046 |
productsText += `β ${p.name} (${p.quantity} ta) x ${formatPrice(p.price)}\n`;
|
| 1047 |
});
|
| 1048 |
|
| 1049 |
-
const statusEmoji = order.status === 'Kutilmoqda' ? 'β³' : order.status === '
|
| 1050 |
const msg = `π§Ύ *TOPILDI β ID:* \`${order._id}\`\n${thinLine}\n` +
|
| 1051 |
`π€ Mijoz: *${order.customerName}*\nπ Tel: ${order.phone}\n\nπ *Tovarlar:*\n${productsText}\n` +
|
| 1052 |
`π° *Jami summa:* ${formatPrice(order.totalAmount)} so'm\n\n` +
|
|
@@ -1418,11 +1418,11 @@ const orderStatusButtonsForNotify = (orderId, currentStatus) => {
|
|
| 1418 |
const s = (label, status) => currentStatus === status ? `β
${label}` : label;
|
| 1419 |
return Markup.inlineKeyboard([
|
| 1420 |
[
|
| 1421 |
-
Markup.button.callback(s('π₯
|
| 1422 |
-
Markup.button.callback(s('
|
| 1423 |
],
|
| 1424 |
[
|
| 1425 |
-
Markup.button.callback(s('
|
| 1426 |
Markup.button.callback(s('β Bekor', 'Bekor qilindi'), `order_status_cancel_${orderId}`)
|
| 1427 |
]
|
| 1428 |
]);
|
|
|
|
| 439 |
for (const o of orders) {
|
| 440 |
let productsText = "";
|
| 441 |
o.products.forEach(p => { productsText += `β ${p.name} (${p.quantity} ta) \n`; });
|
| 442 |
+
let statusEmoji = o.status === 'Kutilmoqda' ? 'β³' : o.status === 'Xaridorga topshirildi' ? 'β
' : o.status === 'Olib ketishga tayyor' ? 'π' : 'π₯';
|
| 443 |
+
const msg = `π§Ύ *ID:* \`${o._id}\`\nπ€ Mijoz: *${o.customerName}*\nπ Tel: ${o.phone}\nπ Izoh: ${o.address}\n\nπ *Tovarlar:*\n${productsText}\nπ° *Jami:* ${formatPrice(o.totalAmount)} so'm\nπ *Holati:* ${statusEmoji} ${o.status}\nπ Vaqt: ${formatDate(o.createdAt)}`;
|
| 444 |
|
| 445 |
await ctx.reply(msg, { parse_mode: 'Markdown', ...orderStatusButtonsForNotify(o._id, o.status) });
|
| 446 |
}
|
|
|
|
| 460 |
const orderId = ctx.match[2];
|
| 461 |
|
| 462 |
let newStatus = 'Kutilmoqda';
|
| 463 |
+
if (action === 'accept') newStatus = 'Yig\'ilmoqda';
|
| 464 |
+
if (action === 'ship') newStatus = 'Olib ketishga tayyor';
|
| 465 |
+
if (action === 'deliver') newStatus = 'Xaridorga topshirildi';
|
| 466 |
if (action === 'cancel') newStatus = 'Bekor qilindi';
|
| 467 |
|
| 468 |
try {
|
|
|
|
| 1046 |
productsText += `β ${p.name} (${p.quantity} ta) x ${formatPrice(p.price)}\n`;
|
| 1047 |
});
|
| 1048 |
|
| 1049 |
+
const statusEmoji = order.status === 'Kutilmoqda' ? 'β³' : order.status === 'Xaridorga topshirildi' ? 'β
' : order.status === 'Olib ketishga tayyor' ? 'π' : 'π₯';
|
| 1050 |
const msg = `π§Ύ *TOPILDI β ID:* \`${order._id}\`\n${thinLine}\n` +
|
| 1051 |
`π€ Mijoz: *${order.customerName}*\nπ Tel: ${order.phone}\n\nπ *Tovarlar:*\n${productsText}\n` +
|
| 1052 |
`π° *Jami summa:* ${formatPrice(order.totalAmount)} so'm\n\n` +
|
|
|
|
| 1418 |
const s = (label, status) => currentStatus === status ? `β
${label}` : label;
|
| 1419 |
return Markup.inlineKeyboard([
|
| 1420 |
[
|
| 1421 |
+
Markup.button.callback(s('π₯ Yig\'ish', 'Yig\'ilmoqda'), `order_status_accept_${orderId}`),
|
| 1422 |
+
Markup.button.callback(s('π Tayyor', 'Olib ketishga tayyor'), `order_status_ship_${orderId}`)
|
| 1423 |
],
|
| 1424 |
[
|
| 1425 |
+
Markup.button.callback(s('β
Topshirildi', 'Xaridorga topshirildi'), `order_status_deliver_${orderId}`),
|
| 1426 |
Markup.button.callback(s('β Bekor', 'Bekor qilindi'), `order_status_cancel_${orderId}`)
|
| 1427 |
]
|
| 1428 |
]);
|