Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
|
| 2 |
import os
|
| 3 |
import io
|
| 4 |
import base64
|
|
@@ -10,7 +9,7 @@ from datetime import datetime, timedelta, timezone
|
|
| 10 |
from uuid import uuid4
|
| 11 |
import random
|
| 12 |
import string
|
| 13 |
-
from flask import Flask, render_template_string, request, redirect, url_for, flash, jsonify,
|
| 14 |
from PIL import Image
|
| 15 |
import google.generativeai as genai
|
| 16 |
import numpy as np
|
|
@@ -530,7 +529,7 @@ CATALOG_TEMPLATE = '''
|
|
| 530 |
.dark-theme .product-image-container { background-color: #1a1a1a; }
|
| 531 |
.product-image-container img { width: 100%; height: 100%; object-fit: cover; }
|
| 532 |
.top-product-indicator { position: absolute; top: 10px; right: 10px; background-color: var(--accent); color: var(--text-dark); padding: 4px 10px; font-size: 0.75rem; border-radius: 12px; font-weight: 700; z-index: 10; box-shadow: 0 2px 5px rgba(0,0,0,0.2); }
|
| 533 |
-
.price-badge { position: absolute; bottom: 10px; left: 10px; background-color: rgba(0,0,0,0.6); color: white; padding: 2px 8px; border-radius: 8px; font-size: 0.8rem; font-weight: 600; }
|
| 534 |
.product-info-bottom { display: none; }
|
| 535 |
.no-results-message { padding: 40px 20px; text-align: center; font-size: 1.2rem; color: #ccc; font-weight: 500; }
|
| 536 |
.floating-buttons-container { position: fixed; bottom: 25px; right: 25px; display: flex; flex-direction: column; gap: 15px; z-index: 1000; }
|
|
@@ -563,7 +562,6 @@ CATALOG_TEMPLATE = '''
|
|
| 563 |
.quantity-btn:disabled { opacity: 0.5; cursor: not-allowed; }
|
| 564 |
.dark-theme .quantity-btn { background-color: #444; color: #fff; }
|
| 565 |
.dark-theme .quantity-btn:hover { background-color: #555; }
|
| 566 |
-
.cart-item-quantity span { font-weight: 600; font-size: 1.1rem; min-width: 20px; text-align: center;}
|
| 567 |
.cart-item-total { font-weight: 800; text-align: right; grid-column: 3 / span 2; grid-row: 2; font-size: 1.1rem; color: var(--bg-medium);}
|
| 568 |
.dark-theme .cart-item-total { color: var(--accent); }
|
| 569 |
.cart-item-remove { grid-column: 4; grid-row: 1; justify-self: end; background:none; border:none; color: var(--danger); cursor:pointer; font-size: 1.4rem; padding: 5px; transition: transform 0.2s; }
|
|
@@ -588,6 +586,7 @@ CATALOG_TEMPLATE = '''
|
|
| 588 |
.notification { position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%) translateY(20px); background-color: var(--bg-medium); color: #fff; padding: 12px 25px; border-radius: 30px; box-shadow: 0 10px 25px rgba(0,0,0,0.2); z-index: 1002; opacity: 0; transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55); font-size: 0.95rem; font-weight: 600;}
|
| 589 |
.notification.show { opacity: 1; transform: translateX(-50%) translateY(0); }
|
| 590 |
.tag-marker-overlay { position: absolute; width: 16px; height: 16px; background-color: var(--accent); border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 8px rgba(0,0,0,0.6); transform: translate(-50%, -50%); cursor: pointer; z-index: 100; transition: transform 0.2s; }
|
|
|
|
| 591 |
.tag-marker-overlay:hover { transform: translate(-50%, -50%) scale(1.3); }
|
| 592 |
.hidden-marker { display: none; }
|
| 593 |
@media (max-width: 480px) { .cart-item { grid-template-columns: 70px 1fr auto; } .cart-item-details { grid-column: 2; } .cart-item-remove { grid-column: 3; } .cart-item-quantity { grid-column: 2; grid-row: 2; justify-self: start; } .cart-item-total { grid-column: 3; grid-row: 2; } }
|
|
@@ -786,6 +785,7 @@ CATALOG_TEMPLATE = '''
|
|
| 786 |
if (swiperContainer) {
|
| 787 |
const swiper = new Swiper(swiperContainer, {
|
| 788 |
slidesPerView: 1, spaceBetween: 20, grabCursor: true,
|
|
|
|
| 789 |
pagination: { el: '.swiper-pagination', clickable: true },
|
| 790 |
navigation: { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev' }
|
| 791 |
});
|
|
@@ -885,36 +885,27 @@ CATALOG_TEMPLATE = '''
|
|
| 885 |
const controlsDiv = document.getElementById(`controls-${tagId}`);
|
| 886 |
if (controlsDiv) {
|
| 887 |
controlsDiv.innerHTML = `
|
| 888 |
-
<button class="quantity-btn" onclick="updateInlineCart('${productId}', '${colorCode}', '${unitType}', -1, '${tagId}')"
|
| 889 |
-
<input type="number" value="${currentQty}" style="width:
|
| 890 |
<button class="quantity-btn" onclick="updateInlineCart('${productId}', '${colorCode}', '${unitType}', 1, '${tagId}')">+</button>
|
| 891 |
`;
|
| 892 |
}
|
| 893 |
};
|
| 894 |
|
| 895 |
-
function
|
|
|
|
|
|
|
| 896 |
const cartItemId = `${productId}-${colorCode}-${unitType}`;
|
| 897 |
-
let
|
| 898 |
-
|
| 899 |
-
if (newQty < 0) newQty = 0;
|
| 900 |
-
const product = getProductById(productId);
|
| 901 |
-
const itemIndex = cart.findIndex(i => i.id === cartItemId);
|
| 902 |
-
|
| 903 |
if (newQty === 0) {
|
| 904 |
if (itemIndex > -1) cart.splice(itemIndex, 1);
|
| 905 |
} else {
|
|
|
|
| 906 |
const tag = product.tags.find(t => t.id === tagId);
|
| 907 |
let variantName = colorCode.includes('_VAR_') ? colorCode.split('_VAR_')[1] : "";
|
| 908 |
-
|
| 909 |
-
let
|
| 910 |
-
let itemPrice = tag.price;
|
| 911 |
-
if (unitType === 'box') {
|
| 912 |
-
unitLabel = ` [Упак: ${tag.box_qty}шт]`;
|
| 913 |
-
itemPrice = tag.box_price;
|
| 914 |
-
} else {
|
| 915 |
-
unitLabel = ` [Шт]`;
|
| 916 |
-
}
|
| 917 |
-
|
| 918 |
let itemName = product.name + " (" + tag.name + (variantName ? ` - ${variantName}` : "") + ")" + unitLabel;
|
| 919 |
let photoUrl = product.photos && product.photos[tag.photo_index] ? product.photos[tag.photo_index] : null;
|
| 920 |
|
|
@@ -929,6 +920,13 @@ CATALOG_TEMPLATE = '''
|
|
| 929 |
window.updateVariantRow(productId, tagId);
|
| 930 |
}
|
| 931 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 932 |
function updateCartButton() {
|
| 933 |
const cartCountElement = document.getElementById('cart-count');
|
| 934 |
const cartButton = document.getElementById('cart-button');
|
|
@@ -963,7 +961,7 @@ CATALOG_TEMPLATE = '''
|
|
| 963 |
</div>
|
| 964 |
<div class="cart-item-quantity">
|
| 965 |
<button class="quantity-btn" onclick="decrementCartItem('${item.id}')">-</button>
|
| 966 |
-
<
|
| 967 |
<button class="quantity-btn" onclick="incrementCartItem('${item.id}')">+</button>
|
| 968 |
</div>
|
| 969 |
<span class="cart-item-total">${itemTotal.toFixed(2)}</span>
|
|
@@ -979,22 +977,31 @@ CATALOG_TEMPLATE = '''
|
|
| 979 |
if (modal) { modal.style.display = "block"; document.body.style.overflow = 'hidden'; }
|
| 980 |
}
|
| 981 |
|
| 982 |
-
function
|
|
|
|
| 983 |
const itemIndex = cart.findIndex(item => item.id === itemId);
|
| 984 |
if (itemIndex > -1) {
|
| 985 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 986 |
localStorage.setItem(`mekaCart_${envId}`, JSON.stringify(cart));
|
| 987 |
-
openCartModal(); updateCartButton(); renderVariantsList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 988 |
}
|
| 989 |
}
|
| 990 |
|
| 991 |
function decrementCartItem(itemId) {
|
| 992 |
const itemIndex = cart.findIndex(item => item.id === itemId);
|
| 993 |
if (itemIndex > -1) {
|
| 994 |
-
cart[itemIndex].quantity-
|
| 995 |
-
if (cart[itemIndex].quantity <= 0) cart.splice(itemIndex, 1);
|
| 996 |
-
localStorage.setItem(`mekaCart_${envId}`, JSON.stringify(cart));
|
| 997 |
-
openCartModal(); updateCartButton(); renderVariantsList();
|
| 998 |
}
|
| 999 |
}
|
| 1000 |
|
|
@@ -1094,7 +1101,7 @@ PRODUCT_DETAIL_TEMPLATE = '''
|
|
| 1094 |
{% for photo in product['photos'] %}
|
| 1095 |
{% set photo_idx = loop.index0 %}
|
| 1096 |
<div class="swiper-slide" style="display: flex; justify-content: center; align-items: center; padding: 10px;">
|
| 1097 |
-
<div style="position: relative; display: inline-block;">
|
| 1098 |
<img src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/photos/{{ photo }}"
|
| 1099 |
alt="{{ product['name'] }}"
|
| 1100 |
style="max-width: 100%; max-height: 400px; object-fit: contain; display: block; margin: auto;">
|
|
@@ -1136,7 +1143,7 @@ ORDER_TEMPLATE = '''
|
|
| 1136 |
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400;600&display=swap" rel="stylesheet">
|
| 1137 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
|
| 1138 |
<style>
|
| 1139 |
-
:root { --bg-light: #f4f6f9; --bg-medium: #135D66; --accent: #48D1CC; --text-dark: #333; --text-light: #E3FEF7; }
|
| 1140 |
body { font-family: 'Montserrat', sans-serif; background: var(--bg-light); color: var(--text-dark); line-height: 1.6; padding: 20px; }
|
| 1141 |
.container { max-width: 800px; margin: 20px auto; padding: 30px; background: #fff; border-radius: 15px; box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08); border: 1px solid #e0e0e0; }
|
| 1142 |
h1 { text-align: center; color: var(--bg-medium); margin-bottom: 25px; font-size: 1.8rem; font-weight: 600; }
|
|
@@ -1150,7 +1157,7 @@ ORDER_TEMPLATE = '''
|
|
| 1150 |
.item-details strong { display: block; margin-bottom: 5px; font-size: 1.05rem; color: var(--text-dark);}
|
| 1151 |
.item-details span { font-size: 0.9rem; color: #666; display: block;}
|
| 1152 |
.item-quantity-total { grid-column: 3; text-align: right; }
|
| 1153 |
-
.item-quantity { display: flex; align-items: center; justify-content: flex-end; gap:
|
| 1154 |
.item-total { font-weight: bold; font-size: 1rem; color: var(--bg-medium);}
|
| 1155 |
.order-summary { margin-top: 30px; padding-top: 20px; border-top: 2px solid var(--accent); text-align: right; }
|
| 1156 |
.order-summary p { margin-bottom: 10px; font-size: 1.1rem; }
|
|
@@ -1177,7 +1184,7 @@ ORDER_TEMPLATE = '''
|
|
| 1177 |
@media print {
|
| 1178 |
body { background: white; padding: 0; }
|
| 1179 |
.container { box-shadow: none; border: none; padding: 0; margin: 0; }
|
| 1180 |
-
.no-print, .actions, .catalog-link, .item-quantity button { display: none !important; }
|
| 1181 |
body.print-table .container > *:not(#printTableContainer) { display: none !important; }
|
| 1182 |
body.print-table #printTableContainer { display: block !important; }
|
| 1183 |
}
|
|
@@ -1213,7 +1220,7 @@ ORDER_TEMPLATE = '''
|
|
| 1213 |
<div class="item-quantity-total">
|
| 1214 |
<div class="item-quantity">
|
| 1215 |
<button onclick="updateOrderItem({{ loop.index0 }}, 'dec')" style="padding: 2px 8px; cursor: pointer; border: 1px solid #ccc; background: #eee; border-radius: 4px;">-</button>
|
| 1216 |
-
<
|
| 1217 |
<button onclick="updateOrderItem({{ loop.index0 }}, 'inc')" style="padding: 2px 8px; cursor: pointer; border: 1px solid #ccc; background: #eee; border-radius: 4px;">+</button>
|
| 1218 |
<button onclick="if(confirm('Удалить товар из заказа?')) updateOrderItem({{ loop.index0 }}, 'remove')" style="padding: 2px 8px; cursor: pointer; color: white; background: var(--danger); border: none; border-radius: 4px; margin-left: 10px;"><i class="fas fa-trash"></i></button>
|
| 1219 |
</div>
|
|
@@ -1308,11 +1315,11 @@ ORDER_TEMPLATE = '''
|
|
| 1308 |
window.print();
|
| 1309 |
setTimeout(() => { document.body.classList.remove('print-table'); }, 1000);
|
| 1310 |
}
|
| 1311 |
-
function updateOrderItem(index, action) {
|
| 1312 |
fetch(`/${envId}/update_order/${orderId}`, {
|
| 1313 |
method: 'POST',
|
| 1314 |
headers: { 'Content-Type': 'application/json' },
|
| 1315 |
-
body: JSON.stringify({ index: index, action: action })
|
| 1316 |
})
|
| 1317 |
.then(res => res.json())
|
| 1318 |
.then(data => {
|
|
@@ -1348,7 +1355,7 @@ HISTORY_TEMPLATE = '''
|
|
| 1348 |
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400;500;600&display=swap" rel="stylesheet">
|
| 1349 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
|
| 1350 |
<style>
|
| 1351 |
-
:root { --bg-light: #f4f6f9; --bg-medium: #135D66; --accent: #48D1CC; --text-dark: #333; }
|
| 1352 |
body { font-family: 'Montserrat', sans-serif; background-color: var(--bg-light); color: var(--text-dark); padding: 20px; line-height: 1.6; }
|
| 1353 |
.container { max-width: 1200px; margin: 0 auto; background-color: #fff; padding: 25px; border-radius: 10px; box-shadow: 0 3px 10px rgba(0,0,0,0.05); }
|
| 1354 |
h1 { color: var(--bg-medium); margin-bottom: 20px; }
|
|
@@ -1361,12 +1368,14 @@ HISTORY_TEMPLATE = '''
|
|
| 1361 |
.order-link { color: var(--bg-medium); text-decoration: none; font-weight: 500; }
|
| 1362 |
.order-link:hover { text-decoration: underline; }
|
| 1363 |
.btn-back { display: inline-block; margin-bottom: 20px; color: var(--bg-medium); text-decoration: none; }
|
|
|
|
|
|
|
| 1364 |
</style>
|
| 1365 |
</head>
|
| 1366 |
<body>
|
| 1367 |
<div class="container">
|
| 1368 |
<a href="{{ url_for('admin', env_id=env_id) }}" class="btn-back"><i class="fas fa-arrow-left"></i> Назад в админ-панель</a>
|
| 1369 |
-
<h1><i class="fas fa-history"></i> История Продаж
|
| 1370 |
<div class="filters">
|
| 1371 |
<input type="text" id="search" placeholder="Поиск (ID, Имя...)" oninput="filterTable()">
|
| 1372 |
<select id="empFilter" onchange="filterTable()">
|
|
@@ -1384,7 +1393,7 @@ HISTORY_TEMPLATE = '''
|
|
| 1384 |
<th onclick="sortTable(1)">Дата <i class="fas fa-sort"></i></th>
|
| 1385 |
<th onclick="sortTable(2)">Сотрудник <i class="fas fa-sort"></i></th>
|
| 1386 |
<th onclick="sortTable(3)">Сумма <i class="fas fa-sort"></i></th>
|
| 1387 |
-
<th>Действи
|
| 1388 |
</tr>
|
| 1389 |
</thead>
|
| 1390 |
<tbody>
|
|
@@ -1394,7 +1403,12 @@ HISTORY_TEMPLATE = '''
|
|
| 1394 |
<td>{{ order.created_at }}</td>
|
| 1395 |
<td>{{ order.employee_name if order.employee_name else 'Прямой заказ' }}</td>
|
| 1396 |
<td>{{ "%.2f"|format(order.total_price) }} {{ currency_code }}</td>
|
| 1397 |
-
<td>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1398 |
</tr>
|
| 1399 |
{% endfor %}
|
| 1400 |
</tbody>
|
|
@@ -1514,6 +1528,7 @@ ADMIN_TEMPLATE = '''
|
|
| 1514 |
.tagging-container { position: relative; display: inline-block; max-width: 100%; margin-top: 10px; border: 1px solid #ccc; background: #fff;}
|
| 1515 |
.tagging-img { max-width: 100%; display: none; cursor: crosshair; }
|
| 1516 |
.tag-marker { position: absolute; width: 16px; height: 16px; background-color: var(--accent); border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 5px rgba(0,0,0,0.5); transform: translate(-50%, -50%); cursor: pointer; z-index: 10; }
|
|
|
|
| 1517 |
.tag-list-item { display: flex; justify-content: space-between; background: #f0f0f0; padding: 5px 10px; margin-top: 5px; border-radius: 4px; font-size: 0.9rem; }
|
| 1518 |
.thumbnail-row { display: flex; gap: 10px; overflow-x: auto; padding: 10px 0; }
|
| 1519 |
.thumbnail-img { width: 60px; height: 60px; object-fit: cover; border: 2px solid transparent; cursor: pointer; border-radius: 4px; }
|
|
@@ -1530,13 +1545,25 @@ ADMIN_TEMPLATE = '''
|
|
| 1530 |
.ai-quick-btn { background: #e0f2f1; color: var(--bg-medium); border: none; padding: 5px 10px; border-radius: 15px; font-size: 0.8rem; cursor: pointer; transition: background 0.2s; white-space: nowrap; margin-right: 5px;}
|
| 1531 |
.ai-quick-btn:hover { background: #b2dfdb; }
|
| 1532 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1533 |
@media (max-width: 600px) {
|
| 1534 |
#admin-ai-widget {
|
| 1535 |
width: calc(100% - 40px);
|
| 1536 |
bottom: 10px;
|
| 1537 |
right: 20px;
|
| 1538 |
left: 20px;
|
| 1539 |
-
z-index:
|
| 1540 |
}
|
| 1541 |
.ai-chat-body {
|
| 1542 |
height: 300px;
|
|
@@ -1545,6 +1572,11 @@ ADMIN_TEMPLATE = '''
|
|
| 1545 |
</style>
|
| 1546 |
</head>
|
| 1547 |
<body>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1548 |
<div class="container">
|
| 1549 |
<div class="header">
|
| 1550 |
<div class="logo-title-container" style="display: flex; align-items: center; gap: 15px;">
|
|
@@ -1571,10 +1603,10 @@ ADMIN_TEMPLATE = '''
|
|
| 1571 |
<div class="section">
|
| 1572 |
<h2><i class="fas fa-sync-alt"></i> Синхронизация с Датацентром</h2>
|
| 1573 |
<div class="sync-buttons">
|
| 1574 |
-
<form method="POST" action="{{ url_for('force_upload', env_id=env_id) }}" style="display: inline;" onsubmit="return confirm('Вы уверены, что хотите принудительно загрузить локальные данные на сервер? Это перезапишет данные на сервере.');">
|
| 1575 |
<button type="submit" class="button add-button"><i class="fas fa-upload"></i> Загрузить БД</button>
|
| 1576 |
</form>
|
| 1577 |
-
<form method="POST" action="{{ url_for('force_download', env_id=env_id) }}" style="display: inline;" onsubmit="return confirm('Вы уверены, что хотите принудительно скачать данные с сервера? Это перезапишет ваши локальные файлы.');">
|
| 1578 |
<button type="submit" class="button download-hf-button"><i class="fas fa-download"></i> Скачать БД</button>
|
| 1579 |
</form>
|
| 1580 |
</div>
|
|
@@ -1686,7 +1718,7 @@ ADMIN_TEMPLATE = '''
|
|
| 1686 |
<details>
|
| 1687 |
<summary><i class="fas fa-cog"></i> Настройки магазина</summary>
|
| 1688 |
<div class="form-content">
|
| 1689 |
-
<form method="POST" enctype="multipart/form-data">
|
| 1690 |
<input type="hidden" name="action" value="update_settings">
|
| 1691 |
|
| 1692 |
<div style="background: #f1f3f5; padding: 15px; border-radius: 8px; margin-bottom: 20px;">
|
|
@@ -1808,7 +1840,7 @@ ADMIN_TEMPLATE = '''
|
|
| 1808 |
<details>
|
| 1809 |
<summary><i class="fas fa-plus-circle"></i> Добавить новый пост</summary>
|
| 1810 |
<div class="form-content">
|
| 1811 |
-
<form id="add-product-form" method="POST" enctype="multipart/form-data">
|
| 1812 |
<input type="hidden" name="action" value="add_product">
|
| 1813 |
<label>Название поста/образа *:</label>
|
| 1814 |
<input type="text" name="name" required>
|
|
@@ -1902,7 +1934,7 @@ ADMIN_TEMPLATE = '''
|
|
| 1902 |
|
| 1903 |
<div class="item-actions">
|
| 1904 |
<button type="button" class="button" onclick="toggleEditForm('edit-form-{{ loop.index0 }}', {{ loop.index0 }})"><i class="fas fa-edit"></i> Редактировать</button>
|
| 1905 |
-
<form method="POST" style="margin:0;" onsubmit="return confirm('Удалить пост?');">
|
| 1906 |
<input type="hidden" name="action" value="delete_product">
|
| 1907 |
<input type="hidden" name="product_id" value="{{ product.get('product_id', '') }}">
|
| 1908 |
<button type="submit" class="delete-button"><i class="fas fa-trash-alt"></i> Удалить</button>
|
|
@@ -1911,7 +1943,7 @@ ADMIN_TEMPLATE = '''
|
|
| 1911 |
|
| 1912 |
<div id="edit-form-{{ loop.index0 }}" class="edit-form-container">
|
| 1913 |
<h4><i class="fas fa-edit"></i> Редактирование</h4>
|
| 1914 |
-
<form method="POST" enctype="multipart/form-data">
|
| 1915 |
<input type="hidden" name="action" value="edit_product">
|
| 1916 |
<input type="hidden" name="product_id" value="{{ product.get('product_id', '') }}">
|
| 1917 |
<label>Название *:</label>
|
|
@@ -1989,6 +2021,10 @@ ADMIN_TEMPLATE = '''
|
|
| 1989 |
const formStates = {};
|
| 1990 |
let adminAiHistory = [];
|
| 1991 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1992 |
function filterAdminProducts() {
|
| 1993 |
const query = document.getElementById('adminProductSearch').value.toLowerCase().trim();
|
| 1994 |
const items = document.querySelectorAll('#admin-products-list .item');
|
|
@@ -2520,7 +2556,7 @@ def update_order(env_id, order_id):
|
|
| 2520 |
idx = req.get('index')
|
| 2521 |
action = req.get('action')
|
| 2522 |
|
| 2523 |
-
if idx is None or action not in ['inc', 'dec', 'remove']:
|
| 2524 |
return jsonify({"error": "Некорректный запрос."}), 400
|
| 2525 |
|
| 2526 |
try:
|
|
@@ -2535,6 +2571,12 @@ def update_order(env_id, order_id):
|
|
| 2535 |
cart[idx]['quantity'] -= 1
|
| 2536 |
if cart[idx]['quantity'] <= 0:
|
| 2537 |
cart.pop(idx)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2538 |
elif action == 'remove':
|
| 2539 |
cart.pop(idx)
|
| 2540 |
|
|
@@ -2547,6 +2589,17 @@ def update_order(env_id, order_id):
|
|
| 2547 |
except Exception as e:
|
| 2548 |
return jsonify({"error": str(e)}), 500
|
| 2549 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2550 |
@app.route('/<env_id>/order/<order_id>')
|
| 2551 |
def view_order(env_id, order_id):
|
| 2552 |
data = get_env_data(env_id)
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import io
|
| 3 |
import base64
|
|
|
|
| 9 |
from uuid import uuid4
|
| 10 |
import random
|
| 11 |
import string
|
| 12 |
+
from flask import Flask, render_template_string, request, redirect, url_for, flash, jsonify, session
|
| 13 |
from PIL import Image
|
| 14 |
import google.generativeai as genai
|
| 15 |
import numpy as np
|
|
|
|
| 529 |
.dark-theme .product-image-container { background-color: #1a1a1a; }
|
| 530 |
.product-image-container img { width: 100%; height: 100%; object-fit: cover; }
|
| 531 |
.top-product-indicator { position: absolute; top: 10px; right: 10px; background-color: var(--accent); color: var(--text-dark); padding: 4px 10px; font-size: 0.75rem; border-radius: 12px; font-weight: 700; z-index: 10; box-shadow: 0 2px 5px rgba(0,0,0,0.2); }
|
| 532 |
+
.price-badge { position: absolute; bottom: 10px; left: 10px; background-color: rgba(0,0,0,0.6); color: white; padding: 2px 8px; border-radius: 8px; font-size: 0.8rem; font-weight: 600; z-index: 10; }
|
| 533 |
.product-info-bottom { display: none; }
|
| 534 |
.no-results-message { padding: 40px 20px; text-align: center; font-size: 1.2rem; color: #ccc; font-weight: 500; }
|
| 535 |
.floating-buttons-container { position: fixed; bottom: 25px; right: 25px; display: flex; flex-direction: column; gap: 15px; z-index: 1000; }
|
|
|
|
| 562 |
.quantity-btn:disabled { opacity: 0.5; cursor: not-allowed; }
|
| 563 |
.dark-theme .quantity-btn { background-color: #444; color: #fff; }
|
| 564 |
.dark-theme .quantity-btn:hover { background-color: #555; }
|
|
|
|
| 565 |
.cart-item-total { font-weight: 800; text-align: right; grid-column: 3 / span 2; grid-row: 2; font-size: 1.1rem; color: var(--bg-medium);}
|
| 566 |
.dark-theme .cart-item-total { color: var(--accent); }
|
| 567 |
.cart-item-remove { grid-column: 4; grid-row: 1; justify-self: end; background:none; border:none; color: var(--danger); cursor:pointer; font-size: 1.4rem; padding: 5px; transition: transform 0.2s; }
|
|
|
|
| 586 |
.notification { position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%) translateY(20px); background-color: var(--bg-medium); color: #fff; padding: 12px 25px; border-radius: 30px; box-shadow: 0 10px 25px rgba(0,0,0,0.2); z-index: 1002; opacity: 0; transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55); font-size: 0.95rem; font-weight: 600;}
|
| 587 |
.notification.show { opacity: 1; transform: translateX(-50%) translateY(0); }
|
| 588 |
.tag-marker-overlay { position: absolute; width: 16px; height: 16px; background-color: var(--accent); border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 8px rgba(0,0,0,0.6); transform: translate(-50%, -50%); cursor: pointer; z-index: 100; transition: transform 0.2s; }
|
| 589 |
+
.tag-marker-overlay::after { content: ''; position: absolute; top: -20px; bottom: -20px; left: -20px; right: -20px; border-radius: 50%; background: transparent; cursor: pointer; }
|
| 590 |
.tag-marker-overlay:hover { transform: translate(-50%, -50%) scale(1.3); }
|
| 591 |
.hidden-marker { display: none; }
|
| 592 |
@media (max-width: 480px) { .cart-item { grid-template-columns: 70px 1fr auto; } .cart-item-details { grid-column: 2; } .cart-item-remove { grid-column: 3; } .cart-item-quantity { grid-column: 2; grid-row: 2; justify-self: start; } .cart-item-total { grid-column: 3; grid-row: 2; } }
|
|
|
|
| 785 |
if (swiperContainer) {
|
| 786 |
const swiper = new Swiper(swiperContainer, {
|
| 787 |
slidesPerView: 1, spaceBetween: 20, grabCursor: true,
|
| 788 |
+
zoom: { maxRatio: 3, minRatio: 1 },
|
| 789 |
pagination: { el: '.swiper-pagination', clickable: true },
|
| 790 |
navigation: { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev' }
|
| 791 |
});
|
|
|
|
| 885 |
const controlsDiv = document.getElementById(`controls-${tagId}`);
|
| 886 |
if (controlsDiv) {
|
| 887 |
controlsDiv.innerHTML = `
|
| 888 |
+
<button class="quantity-btn" onclick="updateInlineCart('${productId}', '${colorCode}', '${unitType}', -1, '${tagId}')">-</button>
|
| 889 |
+
<input type="number" value="${currentQty}" style="width: 50px; text-align: center; border: 1px solid #ccc; border-radius: 4px; padding: 4px;" onchange="setInlineCartQty('${productId}', '${colorCode}', '${unitType}', this.value, '${tagId}')" min="0">
|
| 890 |
<button class="quantity-btn" onclick="updateInlineCart('${productId}', '${colorCode}', '${unitType}', 1, '${tagId}')">+</button>
|
| 891 |
`;
|
| 892 |
}
|
| 893 |
};
|
| 894 |
|
| 895 |
+
function setInlineCartQty(productId, colorCode, unitType, value, tagId) {
|
| 896 |
+
let newQty = parseInt(value);
|
| 897 |
+
if (isNaN(newQty) || newQty < 0) newQty = 0;
|
| 898 |
const cartItemId = `${productId}-${colorCode}-${unitType}`;
|
| 899 |
+
let itemIndex = cart.findIndex(i => i.id === cartItemId);
|
| 900 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 901 |
if (newQty === 0) {
|
| 902 |
if (itemIndex > -1) cart.splice(itemIndex, 1);
|
| 903 |
} else {
|
| 904 |
+
const product = getProductById(productId);
|
| 905 |
const tag = product.tags.find(t => t.id === tagId);
|
| 906 |
let variantName = colorCode.includes('_VAR_') ? colorCode.split('_VAR_')[1] : "";
|
| 907 |
+
let unitLabel = unitType === 'box' ? ` [Упак: ${tag.box_qty}шт]` : ` [Шт]`;
|
| 908 |
+
let itemPrice = unitType === 'box' ? tag.box_price : tag.price;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 909 |
let itemName = product.name + " (" + tag.name + (variantName ? ` - ${variantName}` : "") + ")" + unitLabel;
|
| 910 |
let photoUrl = product.photos && product.photos[tag.photo_index] ? product.photos[tag.photo_index] : null;
|
| 911 |
|
|
|
|
| 920 |
window.updateVariantRow(productId, tagId);
|
| 921 |
}
|
| 922 |
|
| 923 |
+
function updateInlineCart(productId, colorCode, unitType, change, tagId) {
|
| 924 |
+
const cartItemId = `${productId}-${colorCode}-${unitType}`;
|
| 925 |
+
let item = cart.find(i => i.id === cartItemId);
|
| 926 |
+
let currentQty = item ? item.quantity : 0;
|
| 927 |
+
setInlineCartQty(productId, colorCode, unitType, currentQty + change, tagId);
|
| 928 |
+
}
|
| 929 |
+
|
| 930 |
function updateCartButton() {
|
| 931 |
const cartCountElement = document.getElementById('cart-count');
|
| 932 |
const cartButton = document.getElementById('cart-button');
|
|
|
|
| 961 |
</div>
|
| 962 |
<div class="cart-item-quantity">
|
| 963 |
<button class="quantity-btn" onclick="decrementCartItem('${item.id}')">-</button>
|
| 964 |
+
<input type="number" value="${item.quantity}" style="width: 50px; text-align: center; border: 1px solid #ccc; border-radius: 4px; padding: 4px; font-weight: bold;" onchange="setCartItemQty('${item.id}', this.value)" min="1">
|
| 965 |
<button class="quantity-btn" onclick="incrementCartItem('${item.id}')">+</button>
|
| 966 |
</div>
|
| 967 |
<span class="cart-item-total">${itemTotal.toFixed(2)}</span>
|
|
|
|
| 977 |
if (modal) { modal.style.display = "block"; document.body.style.overflow = 'hidden'; }
|
| 978 |
}
|
| 979 |
|
| 980 |
+
function setCartItemQty(itemId, value) {
|
| 981 |
+
let newQty = parseInt(value);
|
| 982 |
const itemIndex = cart.findIndex(item => item.id === itemId);
|
| 983 |
if (itemIndex > -1) {
|
| 984 |
+
if (isNaN(newQty) || newQty <= 0) {
|
| 985 |
+
cart.splice(itemIndex, 1);
|
| 986 |
+
} else {
|
| 987 |
+
cart[itemIndex].quantity = newQty;
|
| 988 |
+
}
|
| 989 |
localStorage.setItem(`mekaCart_${envId}`, JSON.stringify(cart));
|
| 990 |
+
openCartModal(); updateCartButton(); renderVariantsList();
|
| 991 |
+
}
|
| 992 |
+
}
|
| 993 |
+
|
| 994 |
+
function incrementCartItem(itemId) {
|
| 995 |
+
const itemIndex = cart.findIndex(item => item.id === itemId);
|
| 996 |
+
if (itemIndex > -1) {
|
| 997 |
+
setCartItemQty(itemId, cart[itemIndex].quantity + 1);
|
| 998 |
}
|
| 999 |
}
|
| 1000 |
|
| 1001 |
function decrementCartItem(itemId) {
|
| 1002 |
const itemIndex = cart.findIndex(item => item.id === itemId);
|
| 1003 |
if (itemIndex > -1) {
|
| 1004 |
+
setCartItemQty(itemId, cart[itemIndex].quantity - 1);
|
|
|
|
|
|
|
|
|
|
| 1005 |
}
|
| 1006 |
}
|
| 1007 |
|
|
|
|
| 1101 |
{% for photo in product['photos'] %}
|
| 1102 |
{% set photo_idx = loop.index0 %}
|
| 1103 |
<div class="swiper-slide" style="display: flex; justify-content: center; align-items: center; padding: 10px;">
|
| 1104 |
+
<div class="swiper-zoom-container" style="position: relative; display: inline-block; width: 100%; height: 100%;">
|
| 1105 |
<img src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/photos/{{ photo }}"
|
| 1106 |
alt="{{ product['name'] }}"
|
| 1107 |
style="max-width: 100%; max-height: 400px; object-fit: contain; display: block; margin: auto;">
|
|
|
|
| 1143 |
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400;600&display=swap" rel="stylesheet">
|
| 1144 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
|
| 1145 |
<style>
|
| 1146 |
+
:root { --bg-light: #f4f6f9; --bg-medium: #135D66; --accent: #48D1CC; --text-dark: #333; --text-light: #E3FEF7; --danger: #E57373; }
|
| 1147 |
body { font-family: 'Montserrat', sans-serif; background: var(--bg-light); color: var(--text-dark); line-height: 1.6; padding: 20px; }
|
| 1148 |
.container { max-width: 800px; margin: 20px auto; padding: 30px; background: #fff; border-radius: 15px; box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08); border: 1px solid #e0e0e0; }
|
| 1149 |
h1 { text-align: center; color: var(--bg-medium); margin-bottom: 25px; font-size: 1.8rem; font-weight: 600; }
|
|
|
|
| 1157 |
.item-details strong { display: block; margin-bottom: 5px; font-size: 1.05rem; color: var(--text-dark);}
|
| 1158 |
.item-details span { font-size: 0.9rem; color: #666; display: block;}
|
| 1159 |
.item-quantity-total { grid-column: 3; text-align: right; }
|
| 1160 |
+
.item-quantity { display: flex; align-items: center; justify-content: flex-end; gap: 5px; margin-bottom: 5px;}
|
| 1161 |
.item-total { font-weight: bold; font-size: 1rem; color: var(--bg-medium);}
|
| 1162 |
.order-summary { margin-top: 30px; padding-top: 20px; border-top: 2px solid var(--accent); text-align: right; }
|
| 1163 |
.order-summary p { margin-bottom: 10px; font-size: 1.1rem; }
|
|
|
|
| 1184 |
@media print {
|
| 1185 |
body { background: white; padding: 0; }
|
| 1186 |
.container { box-shadow: none; border: none; padding: 0; margin: 0; }
|
| 1187 |
+
.no-print, .actions, .catalog-link, .item-quantity button, .item-quantity input { display: none !important; }
|
| 1188 |
body.print-table .container > *:not(#printTableContainer) { display: none !important; }
|
| 1189 |
body.print-table #printTableContainer { display: block !important; }
|
| 1190 |
}
|
|
|
|
| 1220 |
<div class="item-quantity-total">
|
| 1221 |
<div class="item-quantity">
|
| 1222 |
<button onclick="updateOrderItem({{ loop.index0 }}, 'dec')" style="padding: 2px 8px; cursor: pointer; border: 1px solid #ccc; background: #eee; border-radius: 4px;">-</button>
|
| 1223 |
+
<input type="number" value="{{ item.quantity }}" style="width: 50px; text-align: center; border: 1px solid #ccc; border-radius: 4px; font-weight: bold;" onchange="updateOrderItem({{ loop.index0 }}, 'set', this.value)" min="1">
|
| 1224 |
<button onclick="updateOrderItem({{ loop.index0 }}, 'inc')" style="padding: 2px 8px; cursor: pointer; border: 1px solid #ccc; background: #eee; border-radius: 4px;">+</button>
|
| 1225 |
<button onclick="if(confirm('Удалить товар из заказа?')) updateOrderItem({{ loop.index0 }}, 'remove')" style="padding: 2px 8px; cursor: pointer; color: white; background: var(--danger); border: none; border-radius: 4px; margin-left: 10px;"><i class="fas fa-trash"></i></button>
|
| 1226 |
</div>
|
|
|
|
| 1315 |
window.print();
|
| 1316 |
setTimeout(() => { document.body.classList.remove('print-table'); }, 1000);
|
| 1317 |
}
|
| 1318 |
+
function updateOrderItem(index, action, value=null) {
|
| 1319 |
fetch(`/${envId}/update_order/${orderId}`, {
|
| 1320 |
method: 'POST',
|
| 1321 |
headers: { 'Content-Type': 'application/json' },
|
| 1322 |
+
body: JSON.stringify({ index: index, action: action, value: value })
|
| 1323 |
})
|
| 1324 |
.then(res => res.json())
|
| 1325 |
.then(data => {
|
|
|
|
| 1355 |
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400;500;600&display=swap" rel="stylesheet">
|
| 1356 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
|
| 1357 |
<style>
|
| 1358 |
+
:root { --bg-light: #f4f6f9; --bg-medium: #135D66; --accent: #48D1CC; --text-dark: #333; --danger: #E57373; }
|
| 1359 |
body { font-family: 'Montserrat', sans-serif; background-color: var(--bg-light); color: var(--text-dark); padding: 20px; line-height: 1.6; }
|
| 1360 |
.container { max-width: 1200px; margin: 0 auto; background-color: #fff; padding: 25px; border-radius: 10px; box-shadow: 0 3px 10px rgba(0,0,0,0.05); }
|
| 1361 |
h1 { color: var(--bg-medium); margin-bottom: 20px; }
|
|
|
|
| 1368 |
.order-link { color: var(--bg-medium); text-decoration: none; font-weight: 500; }
|
| 1369 |
.order-link:hover { text-decoration: underline; }
|
| 1370 |
.btn-back { display: inline-block; margin-bottom: 20px; color: var(--bg-medium); text-decoration: none; }
|
| 1371 |
+
.delete-btn { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 1.1rem; padding: 5px; transition: transform 0.2s; }
|
| 1372 |
+
.delete-btn:hover { transform: scale(1.1); color: #d32f2f; }
|
| 1373 |
</style>
|
| 1374 |
</head>
|
| 1375 |
<body>
|
| 1376 |
<div class="container">
|
| 1377 |
<a href="{{ url_for('admin', env_id=env_id) }}" class="btn-back"><i class="fas fa-arrow-left"></i> Назад в админ-панель</a>
|
| 1378 |
+
<h1><i class="fas fa-history"></i> История Продаж</h1>
|
| 1379 |
<div class="filters">
|
| 1380 |
<input type="text" id="search" placeholder="Поиск (ID, Имя...)" oninput="filterTable()">
|
| 1381 |
<select id="empFilter" onchange="filterTable()">
|
|
|
|
| 1393 |
<th onclick="sortTable(1)">Дата <i class="fas fa-sort"></i></th>
|
| 1394 |
<th onclick="sortTable(2)">Сотрудник <i class="fas fa-sort"></i></th>
|
| 1395 |
<th onclick="sortTable(3)">Сумма <i class="fas fa-sort"></i></th>
|
| 1396 |
+
<th>Действия</th>
|
| 1397 |
</tr>
|
| 1398 |
</thead>
|
| 1399 |
<tbody>
|
|
|
|
| 1403 |
<td>{{ order.created_at }}</td>
|
| 1404 |
<td>{{ order.employee_name if order.employee_name else 'Прямой заказ' }}</td>
|
| 1405 |
<td>{{ "%.2f"|format(order.total_price) }} {{ currency_code }}</td>
|
| 1406 |
+
<td>
|
| 1407 |
+
<a href="{{ url_for('view_order', env_id=env_id, order_id=order.id) }}" style="color: var(--bg-medium); margin-right: 15px;"><i class="fas fa-eye"></i></a>
|
| 1408 |
+
<form method="POST" action="{{ url_for('delete_order', env_id=env_id, order_id=order.id) }}" style="display:inline;" onsubmit="return confirm('Вы уверены, что хотите удалить заказ навсегда?');">
|
| 1409 |
+
<button type="submit" class="delete-btn"><i class="fas fa-trash-alt"></i></button>
|
| 1410 |
+
</form>
|
| 1411 |
+
</td>
|
| 1412 |
</tr>
|
| 1413 |
{% endfor %}
|
| 1414 |
</tbody>
|
|
|
|
| 1528 |
.tagging-container { position: relative; display: inline-block; max-width: 100%; margin-top: 10px; border: 1px solid #ccc; background: #fff;}
|
| 1529 |
.tagging-img { max-width: 100%; display: none; cursor: crosshair; }
|
| 1530 |
.tag-marker { position: absolute; width: 16px; height: 16px; background-color: var(--accent); border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 5px rgba(0,0,0,0.5); transform: translate(-50%, -50%); cursor: pointer; z-index: 10; }
|
| 1531 |
+
.tag-marker::after { content: ''; position: absolute; top: -20px; bottom: -20px; left: -20px; right: -20px; border-radius: 50%; background: transparent; cursor: pointer; }
|
| 1532 |
.tag-list-item { display: flex; justify-content: space-between; background: #f0f0f0; padding: 5px 10px; margin-top: 5px; border-radius: 4px; font-size: 0.9rem; }
|
| 1533 |
.thumbnail-row { display: flex; gap: 10px; overflow-x: auto; padding: 10px 0; }
|
| 1534 |
.thumbnail-img { width: 60px; height: 60px; object-fit: cover; border: 2px solid transparent; cursor: pointer; border-radius: 4px; }
|
|
|
|
| 1545 |
.ai-quick-btn { background: #e0f2f1; color: var(--bg-medium); border: none; padding: 5px 10px; border-radius: 15px; font-size: 0.8rem; cursor: pointer; transition: background 0.2s; white-space: nowrap; margin-right: 5px;}
|
| 1546 |
.ai-quick-btn:hover { background: #b2dfdb; }
|
| 1547 |
|
| 1548 |
+
#loadingOverlay {
|
| 1549 |
+
display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
|
| 1550 |
+
background: rgba(0,0,0,0.8); z-index: 10000; flex-direction: column;
|
| 1551 |
+
justify-content: center; align-items: center; color: white; text-align: center;
|
| 1552 |
+
}
|
| 1553 |
+
.spinner {
|
| 1554 |
+
width: 60px; height: 60px; border: 6px solid #f3f3f3;
|
| 1555 |
+
border-top: 6px solid var(--accent); border-radius: 50%;
|
| 1556 |
+
animation: spin 1s linear infinite; margin-bottom: 20px;
|
| 1557 |
+
}
|
| 1558 |
+
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
|
| 1559 |
+
|
| 1560 |
@media (max-width: 600px) {
|
| 1561 |
#admin-ai-widget {
|
| 1562 |
width: calc(100% - 40px);
|
| 1563 |
bottom: 10px;
|
| 1564 |
right: 20px;
|
| 1565 |
left: 20px;
|
| 1566 |
+
z-index: 9000;
|
| 1567 |
}
|
| 1568 |
.ai-chat-body {
|
| 1569 |
height: 300px;
|
|
|
|
| 1572 |
</style>
|
| 1573 |
</head>
|
| 1574 |
<body>
|
| 1575 |
+
<div id="loadingOverlay">
|
| 1576 |
+
<div class="spinner"></div>
|
| 1577 |
+
<h2>Сохранение данных...</h2>
|
| 1578 |
+
<p>Пожалуйста, подождите, идет обработка и загрузка.</p>
|
| 1579 |
+
</div>
|
| 1580 |
<div class="container">
|
| 1581 |
<div class="header">
|
| 1582 |
<div class="logo-title-container" style="display: flex; align-items: center; gap: 15px;">
|
|
|
|
| 1603 |
<div class="section">
|
| 1604 |
<h2><i class="fas fa-sync-alt"></i> Синхронизация с Датацентром</h2>
|
| 1605 |
<div class="sync-buttons">
|
| 1606 |
+
<form method="POST" action="{{ url_for('force_upload', env_id=env_id) }}" style="display: inline;" onsubmit="return confirm('Вы уверены, что хотите принудительно загрузить локальные данные на сервер? Это перезапишет данные на сервере.'); showLoadingOverlay();">
|
| 1607 |
<button type="submit" class="button add-button"><i class="fas fa-upload"></i> Загрузить БД</button>
|
| 1608 |
</form>
|
| 1609 |
+
<form method="POST" action="{{ url_for('force_download', env_id=env_id) }}" style="display: inline;" onsubmit="return confirm('Вы уверены, что хотите принудительно скачать данные с сервера? Это перезапишет ваши локальные файлы.'); showLoadingOverlay();">
|
| 1610 |
<button type="submit" class="button download-hf-button"><i class="fas fa-download"></i> Скачать БД</button>
|
| 1611 |
</form>
|
| 1612 |
</div>
|
|
|
|
| 1718 |
<details>
|
| 1719 |
<summary><i class="fas fa-cog"></i> Настройки магазина</summary>
|
| 1720 |
<div class="form-content">
|
| 1721 |
+
<form method="POST" enctype="multipart/form-data" onsubmit="showLoadingOverlay()">
|
| 1722 |
<input type="hidden" name="action" value="update_settings">
|
| 1723 |
|
| 1724 |
<div style="background: #f1f3f5; padding: 15px; border-radius: 8px; margin-bottom: 20px;">
|
|
|
|
| 1840 |
<details>
|
| 1841 |
<summary><i class="fas fa-plus-circle"></i> Добавить новый пост</summary>
|
| 1842 |
<div class="form-content">
|
| 1843 |
+
<form id="add-product-form" method="POST" enctype="multipart/form-data" onsubmit="showLoadingOverlay()">
|
| 1844 |
<input type="hidden" name="action" value="add_product">
|
| 1845 |
<label>Название поста/образа *:</label>
|
| 1846 |
<input type="text" name="name" required>
|
|
|
|
| 1934 |
|
| 1935 |
<div class="item-actions">
|
| 1936 |
<button type="button" class="button" onclick="toggleEditForm('edit-form-{{ loop.index0 }}', {{ loop.index0 }})"><i class="fas fa-edit"></i> Редактировать</button>
|
| 1937 |
+
<form method="POST" style="margin:0;" onsubmit="return confirm('Удалить пост?'); showLoadingOverlay();">
|
| 1938 |
<input type="hidden" name="action" value="delete_product">
|
| 1939 |
<input type="hidden" name="product_id" value="{{ product.get('product_id', '') }}">
|
| 1940 |
<button type="submit" class="delete-button"><i class="fas fa-trash-alt"></i> Удалить</button>
|
|
|
|
| 1943 |
|
| 1944 |
<div id="edit-form-{{ loop.index0 }}" class="edit-form-container">
|
| 1945 |
<h4><i class="fas fa-edit"></i> Редактирование</h4>
|
| 1946 |
+
<form method="POST" enctype="multipart/form-data" onsubmit="showLoadingOverlay()">
|
| 1947 |
<input type="hidden" name="action" value="edit_product">
|
| 1948 |
<input type="hidden" name="product_id" value="{{ product.get('product_id', '') }}">
|
| 1949 |
<label>Название *:</label>
|
|
|
|
| 2021 |
const formStates = {};
|
| 2022 |
let adminAiHistory = [];
|
| 2023 |
|
| 2024 |
+
function showLoadingOverlay() {
|
| 2025 |
+
document.getElementById('loadingOverlay').style.display = 'flex';
|
| 2026 |
+
}
|
| 2027 |
+
|
| 2028 |
function filterAdminProducts() {
|
| 2029 |
const query = document.getElementById('adminProductSearch').value.toLowerCase().trim();
|
| 2030 |
const items = document.querySelectorAll('#admin-products-list .item');
|
|
|
|
| 2556 |
idx = req.get('index')
|
| 2557 |
action = req.get('action')
|
| 2558 |
|
| 2559 |
+
if idx is None or action not in ['inc', 'dec', 'set', 'remove']:
|
| 2560 |
return jsonify({"error": "Некорректный запрос."}), 400
|
| 2561 |
|
| 2562 |
try:
|
|
|
|
| 2571 |
cart[idx]['quantity'] -= 1
|
| 2572 |
if cart[idx]['quantity'] <= 0:
|
| 2573 |
cart.pop(idx)
|
| 2574 |
+
elif action == 'set':
|
| 2575 |
+
val = int(req.get('value', 1))
|
| 2576 |
+
if val <= 0:
|
| 2577 |
+
cart.pop(idx)
|
| 2578 |
+
else:
|
| 2579 |
+
cart[idx]['quantity'] = val
|
| 2580 |
elif action == 'remove':
|
| 2581 |
cart.pop(idx)
|
| 2582 |
|
|
|
|
| 2589 |
except Exception as e:
|
| 2590 |
return jsonify({"error": str(e)}), 500
|
| 2591 |
|
| 2592 |
+
@app.route('/<env_id>/delete_order/<order_id>', methods=['POST'])
|
| 2593 |
+
def delete_order(env_id, order_id):
|
| 2594 |
+
data = get_env_data(env_id)
|
| 2595 |
+
if 'orders' in data and order_id in data['orders']:
|
| 2596 |
+
del data['orders'][order_id]
|
| 2597 |
+
save_env_data(env_id, data)
|
| 2598 |
+
flash("Заказ успешно удален.", "success")
|
| 2599 |
+
else:
|
| 2600 |
+
flash("Заказ не найден.", "error")
|
| 2601 |
+
return redirect(url_for('history_page', env_id=env_id))
|
| 2602 |
+
|
| 2603 |
@app.route('/<env_id>/order/<order_id>')
|
| 2604 |
def view_order(env_id, order_id):
|
| 2605 |
data = get_env_data(env_id)
|