Spaces:
Running
Running
Refactor: Change address to comment to reflect in-store pickup model + Code cleanup
Browse files- bot/bot.js +2 -17
- index.js +4 -4
- models/Order.js +2 -2
bot/bot.js
CHANGED
|
@@ -440,7 +440,7 @@ if (process.env.BOT_TOKEN && process.env.BOT_TOKEN !== 'YOUR_TELEGRAM_BOT_TOKEN'
|
|
| 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.
|
| 444 |
|
| 445 |
await ctx.reply(msg, { parse_mode: 'Markdown', ...orderStatusButtonsForNotify(o._id, o.status) });
|
| 446 |
}
|
|
@@ -540,7 +540,7 @@ if (process.env.BOT_TOKEN && process.env.BOT_TOKEN !== 'YOUR_TELEGRAM_BOT_TOKEN'
|
|
| 540 |
`Quyidagi bo'limlar orqali do'konni to'liq boshqarasiz:\n\n` +
|
| 541 |
`π¦ *Tovarlar* - Tahrirlash, O'chirish va Rasm o'zgartirish.\n` +
|
| 542 |
`π *Kategoriyalar* - Guruhlar yaratish, nomini o'zgartirish.\n` +
|
| 543 |
-
`π *Buyurtmalar* - Holatini (
|
| 544 |
`π *Qidirish* - Ismi bilan izlab topib tahrirlash.\n` +
|
| 545 |
`π *Statistika* - Tushumlar va statistika.`;
|
| 546 |
ctx.reply(msg, { parse_mode: 'Markdown' });
|
|
@@ -1212,21 +1212,6 @@ if (process.env.BOT_TOKEN && process.env.BOT_TOKEN !== 'YOUR_TELEGRAM_BOT_TOKEN'
|
|
| 1212 |
return;
|
| 1213 |
}
|
| 1214 |
|
| 1215 |
-
// AI Banner (eski usul backup)
|
| 1216 |
-
if (state.step === 'ai_banner_prompt') {
|
| 1217 |
-
try {
|
| 1218 |
-
await ctx.reply('π§ Gemini orqali prompt tayyorlanmoqda...');
|
| 1219 |
-
const finalPrompt = await enhancePromptWithGemini(text);
|
| 1220 |
-
appState[userId] = { step: 'ai_generating', lastPrompt: text, finalPrompt };
|
| 1221 |
-
await generateAIBannerVariants(ctx, finalPrompt, text);
|
| 1222 |
-
} catch (e) {
|
| 1223 |
-
console.error("ai_banner_prompt error:", e);
|
| 1224 |
-
ctx.reply('β Kechirasiz, tarmoqda xatolik yuz berdi. Iltimos qayta urining.', getMainMenu());
|
| 1225 |
-
delete appState[userId];
|
| 1226 |
-
}
|
| 1227 |
-
return;
|
| 1228 |
-
}
|
| 1229 |
-
|
| 1230 |
// Qidiruv
|
| 1231 |
if (state.step === 'searching_product') {
|
| 1232 |
try {
|
|
|
|
| 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.comment}\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 |
}
|
|
|
|
| 540 |
`Quyidagi bo'limlar orqali do'konni to'liq boshqarasiz:\n\n` +
|
| 541 |
`π¦ *Tovarlar* - Tahrirlash, O'chirish va Rasm o'zgartirish.\n` +
|
| 542 |
`π *Kategoriyalar* - Guruhlar yaratish, nomini o'zgartirish.\n` +
|
| 543 |
+
`π *Buyurtmalar* - Holatini (yig'ilmoqda, tayyor) tasdiqlash.\n` +
|
| 544 |
`π *Qidirish* - Ismi bilan izlab topib tahrirlash.\n` +
|
| 545 |
`π *Statistika* - Tushumlar va statistika.`;
|
| 546 |
ctx.reply(msg, { parse_mode: 'Markdown' });
|
|
|
|
| 1212 |
return;
|
| 1213 |
}
|
| 1214 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1215 |
// Qidiruv
|
| 1216 |
if (state.step === 'searching_product') {
|
| 1217 |
try {
|
index.js
CHANGED
|
@@ -159,10 +159,10 @@ app.post('/api/validate-cart', async (req, res) => {
|
|
| 159 |
|
| 160 |
// Yangi buyurtma yaratish
|
| 161 |
app.post('/api/orders', async (req, res) => {
|
| 162 |
-
const { customerName, phone,
|
| 163 |
|
| 164 |
// ββ Validatsiya ββ
|
| 165 |
-
if (!customerName || !phone || !
|
| 166 |
return res.status(400).json({ message: 'Barcha maydonlarni to\'ldiring' });
|
| 167 |
}
|
| 168 |
if (!products || !Array.isArray(products) || products.length === 0) {
|
|
@@ -186,7 +186,7 @@ app.post('/api/orders', async (req, res) => {
|
|
| 186 |
const order = new Order({
|
| 187 |
customerName,
|
| 188 |
phone,
|
| 189 |
-
|
| 190 |
products,
|
| 191 |
totalAmount
|
| 192 |
});
|
|
@@ -200,7 +200,7 @@ app.post('/api/orders', async (req, res) => {
|
|
| 200 |
productsText += `β ${p.name}${sizeStr} (${p.quantity} x ${Number(p.price).toLocaleString()}) \n`;
|
| 201 |
});
|
| 202 |
|
| 203 |
-
const msg = `π¦ *YANGI BUYURTMA!*\n\nπ€ Mijoz: ${customerName}\nπ Tel: ${phone}\nπ
|
| 204 |
|
| 205 |
await notifyAdmin(msg, createdOrder._id.toString());
|
| 206 |
|
|
|
|
| 159 |
|
| 160 |
// Yangi buyurtma yaratish
|
| 161 |
app.post('/api/orders', async (req, res) => {
|
| 162 |
+
const { customerName, phone, comment, products, totalAmount } = req.body;
|
| 163 |
|
| 164 |
// ββ Validatsiya ββ
|
| 165 |
+
if (!customerName || !phone || !comment) {
|
| 166 |
return res.status(400).json({ message: 'Barcha maydonlarni to\'ldiring' });
|
| 167 |
}
|
| 168 |
if (!products || !Array.isArray(products) || products.length === 0) {
|
|
|
|
| 186 |
const order = new Order({
|
| 187 |
customerName,
|
| 188 |
phone,
|
| 189 |
+
comment,
|
| 190 |
products,
|
| 191 |
totalAmount
|
| 192 |
});
|
|
|
|
| 200 |
productsText += `β ${p.name}${sizeStr} (${p.quantity} x ${Number(p.price).toLocaleString()}) \n`;
|
| 201 |
});
|
| 202 |
|
| 203 |
+
const msg = `π¦ *YANGI BUYURTMA!*\n\nπ€ Mijoz: ${customerName}\nπ Tel: ${phone}\nπ Izoh: ${comment}\n\nπ Tovarlar:\n${productsText}\nπ° Umumiy: ${Number(totalAmount).toLocaleString()} so'm`;
|
| 204 |
|
| 205 |
await notifyAdmin(msg, createdOrder._id.toString());
|
| 206 |
|
models/Order.js
CHANGED
|
@@ -5,7 +5,7 @@ const orderSchema = mongoose.Schema(
|
|
| 5 |
userId: { type: String, required: false },
|
| 6 |
customerName: { type: String, required: true },
|
| 7 |
phone: { type: String, required: true },
|
| 8 |
-
|
| 9 |
products: [
|
| 10 |
{
|
| 11 |
productId: { type: mongoose.Schema.Types.ObjectId, ref: 'Product', required: true },
|
|
@@ -16,7 +16,7 @@ const orderSchema = mongoose.Schema(
|
|
| 16 |
}
|
| 17 |
],
|
| 18 |
totalAmount: { type: Number, required: true },
|
| 19 |
-
status: { type: String, default: 'Kutilmoqda' } // Kutilmoqda,
|
| 20 |
},
|
| 21 |
{
|
| 22 |
timestamps: true,
|
|
|
|
| 5 |
userId: { type: String, required: false },
|
| 6 |
customerName: { type: String, required: true },
|
| 7 |
phone: { type: String, required: true },
|
| 8 |
+
comment: { type: String, required: true },
|
| 9 |
products: [
|
| 10 |
{
|
| 11 |
productId: { type: mongoose.Schema.Types.ObjectId, ref: 'Product', required: true },
|
|
|
|
| 16 |
}
|
| 17 |
],
|
| 18 |
totalAmount: { type: Number, required: true },
|
| 19 |
+
status: { type: String, default: 'Kutilmoqda' } // Kutilmoqda, Yig'ilmoqda, Olib ketishga tayyor, Xaridorga topshirildi, Bekor qilindi
|
| 20 |
},
|
| 21 |
{
|
| 22 |
timestamps: true,
|