Update app.py
Browse files
app.py
CHANGED
|
@@ -207,18 +207,18 @@ def get_env_data(env_id):
|
|
| 207 |
env_data = all_data.get(env_id, {})
|
| 208 |
if not env_data:
|
| 209 |
env_data = {
|
| 210 |
-
'products': [], 'categories': [], 'orders': {}, 'employees':
|
| 211 |
'organization_info': default_organization_info,
|
| 212 |
'settings': default_settings
|
| 213 |
}
|
| 214 |
|
| 215 |
-
if 'products' not in env_data: env_data['products'] =
|
| 216 |
-
if 'categories' not in env_data: env_data['categories'] =
|
| 217 |
if 'orders' not in env_data: env_data['orders'] = {}
|
| 218 |
if 'organization_info' not in env_data: env_data['organization_info'] = default_organization_info
|
| 219 |
if 'settings' not in env_data: env_data['settings'] = default_settings
|
| 220 |
-
if 'employees' not in env_data: env_data['employees'] =
|
| 221 |
-
if 'blocks' not in env_data: env_data['blocks'] =
|
| 222 |
|
| 223 |
settings_changed = False
|
| 224 |
for key, value in default_settings.items():
|
|
@@ -241,7 +241,7 @@ def get_env_data(env_id):
|
|
| 241 |
product['variant_stock'] = {}
|
| 242 |
products_changed = True
|
| 243 |
if 'tags' not in product:
|
| 244 |
-
product['tags'] =
|
| 245 |
products_changed = True
|
| 246 |
|
| 247 |
if products_changed or settings_changed:
|
|
@@ -385,8 +385,6 @@ ADMHOSTO_TEMPLATE = '''
|
|
| 385 |
.message { padding: 10px 15px; border-radius: 6px; margin-bottom: 15px; text-align: center; }
|
| 386 |
.message.success { background-color: #d4edda; color: #155724; }
|
| 387 |
.message.error { background-color: #f8d7da; color: #721c24; }
|
| 388 |
-
.mode-badge { padding: 4px 8px; border-radius: 4px; font-size: 0.8rem; font-weight: bold; background: #eee; }
|
| 389 |
-
.mode-2in1 { background: #ffeb3b; color: #333; }
|
| 390 |
</style>
|
| 391 |
</head>
|
| 392 |
<body>
|
|
@@ -418,12 +416,15 @@ ADMHOSTO_TEMPLATE = '''
|
|
| 418 |
{% for env in environments %}
|
| 419 |
<li class="env-item">
|
| 420 |
<div class="env-header">
|
| 421 |
-
<
|
| 422 |
-
{{ env.org_name }} (ID: {{ env.id }})
|
| 423 |
-
<
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
|
|
|
|
|
|
|
|
|
| 427 |
<div class="env-actions">
|
| 428 |
<a href="{{ url_for('admin', env_id=env.id) }}" class="button" target="_blank"><i class="fas fa-tools"></i> Админ</a>
|
| 429 |
<a href="{{ url_for('catalog', env_id=env.id) }}" class="button" target="_blank"><i class="fas fa-store"></i> Каталог</a>
|
|
@@ -647,7 +648,7 @@ CATALOG_TEMPLATE = '''
|
|
| 647 |
@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; } }
|
| 648 |
</style>
|
| 649 |
</head>
|
| 650 |
-
<body class="{{ 'dark-theme' if settings.color_scheme in
|
| 651 |
<div class="container">
|
| 652 |
<div class="top-bar">
|
| 653 |
<a href="#" class="logo" onclick="window.scrollTo({top:0, behavior:'smooth'}); return false;">
|
|
@@ -1019,7 +1020,7 @@ CATALOG_TEMPLATE = '''
|
|
| 1019 |
const product = getProductById(productId);
|
| 1020 |
const tag = product.tags.find(t => t.id === tagId);
|
| 1021 |
let variantName = colorCode.includes('_VAR_') ? colorCode.split('_VAR_')[1] : "";
|
| 1022 |
-
let unitLabel = unitType === 'box' ? `
|
| 1023 |
let itemPrice = unitType === 'box' ? tag.box_price : tag.price;
|
| 1024 |
let itemName = product.name + " (" + tag.name + (variantName ? ` - ${variantName}` : "") + ")" + unitLabel;
|
| 1025 |
let photoUrl = product.photos && product.photos[tag.photo_index] ? product.photos[tag.photo_index] : null;
|
|
@@ -1138,7 +1139,7 @@ CATALOG_TEMPLATE = '''
|
|
| 1138 |
|
| 1139 |
function clearCart() {
|
| 1140 |
if (confirm("Вы уверены, что хотите очистить корзину?")) {
|
| 1141 |
-
cart =
|
| 1142 |
openCartModal(); updateCartButton(); renderVariantsList();
|
| 1143 |
}
|
| 1144 |
}
|
|
@@ -1147,8 +1148,7 @@ CATALOG_TEMPLATE = '''
|
|
| 1147 |
if (cart.length === 0) { alert("Корзина пуста!"); return; }
|
| 1148 |
|
| 1149 |
const customerData = {};
|
| 1150 |
-
let hasError = false;
|
| 1151 |
-
['name', 'phone', 'city', 'address', 'zip'].forEach(field => {
|
| 1152 |
const el = document.getElementById('c_' + field);
|
| 1153 |
if (el) {
|
| 1154 |
if (!el.value.trim()) {
|
|
@@ -1173,7 +1173,7 @@ CATALOG_TEMPLATE = '''
|
|
| 1173 |
}).then(data => {
|
| 1174 |
if (data.order_id) {
|
| 1175 |
localStorage.removeItem(`mekaCart_${envId}`);
|
| 1176 |
-
cart =
|
| 1177 |
window.location.href = `/${envId}/order/${data.order_id}`;
|
| 1178 |
} else throw new Error('Не получен ID заказа.');
|
| 1179 |
}).catch(error => {
|
|
@@ -1576,58 +1576,65 @@ POS_TEMPLATE = '''
|
|
| 1576 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
|
| 1577 |
<style>
|
| 1578 |
* { box-sizing: border-box; margin: 0; padding: 0; }
|
| 1579 |
-
body { font-family: 'Montserrat', sans-serif; background-color: #f4f6f9; color: #333; height: 100vh; display: flex;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1580 |
|
| 1581 |
-
.
|
| 1582 |
-
.
|
| 1583 |
-
.search-input { flex-grow: 1; padding: 12px; border-radius: 8px; border: none; font-size: 1rem; outline: none; }
|
| 1584 |
-
.products-grid { flex: 1; overflow-y: auto; padding: 15px; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 15px; align-content: start; }
|
| 1585 |
.product-card { border: 1px solid #e0e0e0; border-radius: 8px; overflow: hidden; cursor: pointer; transition: transform 0.1s; background: #fafafa; display: flex; flex-direction: column; }
|
| 1586 |
.product-card:active { transform: scale(0.98); }
|
| 1587 |
.product-card img { width: 100%; height: 120px; object-fit: cover; }
|
| 1588 |
.product-info { padding: 10px; font-size: 0.9rem; flex-grow: 1; display: flex; flex-direction: column; justify-content: space-between;}
|
| 1589 |
-
.product-name { font-weight: 600; margin-bottom: 5px; }
|
| 1590 |
.product-price { color: #135D66; font-weight: bold; }
|
| 1591 |
-
.product-stock { font-size: 0.
|
| 1592 |
-
|
| 1593 |
-
.cart-
|
| 1594 |
-
.cart-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1595 |
.cart-items { flex: 1; overflow-y: auto; padding: 15px; }
|
| 1596 |
-
.cart-item { display: flex; justify-content: space-between; align-items: center; padding:
|
| 1597 |
.cart-item-details { flex-grow: 1; }
|
| 1598 |
-
.cart-item-name { font-weight: 600; font-size: 0.
|
| 1599 |
-
.cart-item-price { font-size: 0.
|
| 1600 |
-
.cart-controls { display: flex; align-items: center; gap:
|
| 1601 |
-
.qty-btn { width:
|
| 1602 |
-
.qty-input { width: 40px; text-align: center; border: 1px solid #ccc; border-radius: 4px; padding: 4px; }
|
| 1603 |
|
| 1604 |
.checkout-panel { padding: 20px; background: #fff; border-top: 1px solid #e0e0e0; }
|
| 1605 |
-
.total-row { display: flex; justify-content: space-between; font-size: 1.
|
| 1606 |
.input-group { margin-bottom: 15px; }
|
| 1607 |
-
.input-group label { display: block; font-size: 0.
|
| 1608 |
-
.input-group input { width: 100%; padding: 12px; border: 1px solid #ccc; border-radius: 8px; font-size: 1rem; }
|
| 1609 |
-
.btn-checkout { width: 100%; padding: 15px; background: #48D1CC; color: #003C43; border: none; border-radius: 8px; font-size: 1.
|
| 1610 |
.btn-checkout:hover { background: #77E4D8; }
|
| 1611 |
.btn-clear { width: 100%; padding: 10px; background: #eee; color: #555; border: none; border-radius: 8px; font-size: 0.9rem; cursor: pointer; margin-bottom: 10px; }
|
| 1612 |
-
|
| 1613 |
-
@media (max-width: 768px) {
|
| 1614 |
-
body { flex-direction: column; }
|
| 1615 |
-
.products-section { flex: 1; }
|
| 1616 |
-
.cart-section { flex: 1; max-width: 100%; border-top: 2px solid #135D66; }
|
| 1617 |
-
}
|
| 1618 |
</style>
|
| 1619 |
</head>
|
| 1620 |
<body>
|
| 1621 |
-
<div class="
|
| 1622 |
-
<
|
| 1623 |
-
<
|
| 1624 |
-
<
|
| 1625 |
-
</
|
| 1626 |
-
<
|
|
|
|
| 1627 |
</div>
|
| 1628 |
|
| 1629 |
-
<div class="
|
| 1630 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1631 |
<div class="cart-items" id="cart-items"></div>
|
| 1632 |
<div class="checkout-panel">
|
| 1633 |
<button class="btn-clear" onclick="clearCart()">Очистить корзину</button>
|
|
@@ -1649,7 +1656,12 @@ POS_TEMPLATE = '''
|
|
| 1649 |
const empId = '{{ emp_id }}';
|
| 1650 |
const currencyCode = '{{ currency_code }}';
|
| 1651 |
const repoId = '{{ repo_id }}';
|
| 1652 |
-
let cart =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1653 |
|
| 1654 |
function renderProducts() {
|
| 1655 |
const query = document.getElementById('search-input').value.toLowerCase();
|
|
@@ -1659,7 +1671,6 @@ POS_TEMPLATE = '''
|
|
| 1659 |
allProducts.forEach(p => {
|
| 1660 |
if(query && !p.name.toLowerCase().includes(query)) return;
|
| 1661 |
|
| 1662 |
-
// For POS, we show variants directly if possible, or just the main product click
|
| 1663 |
p.tags.forEach(tag => {
|
| 1664 |
if(query && !tag.name.toLowerCase().includes(query) && !p.name.toLowerCase().includes(query)) return;
|
| 1665 |
|
|
@@ -1669,7 +1680,6 @@ POS_TEMPLATE = '''
|
|
| 1669 |
|
| 1670 |
const stockText = tag.stock !== undefined ? `Остаток: ${tag.stock}` : 'В наличии';
|
| 1671 |
|
| 1672 |
-
// JSON escape for onClick
|
| 1673 |
const tagData = JSON.stringify({
|
| 1674 |
id: tag.id, pid: p.product_id, name: `${p.name} (${tag.name})`,
|
| 1675 |
price: tag.price, box_price: tag.box_price, box_qty: tag.box_qty, photo: p.photos ? p.photos[tag.photo_index] : null
|
|
@@ -1702,6 +1712,10 @@ POS_TEMPLATE = '''
|
|
| 1702 |
});
|
| 1703 |
}
|
| 1704 |
renderCart();
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1705 |
}
|
| 1706 |
|
| 1707 |
function updateQty(id, delta) {
|
|
@@ -1714,22 +1728,24 @@ POS_TEMPLATE = '''
|
|
| 1714 |
}
|
| 1715 |
|
| 1716 |
function clearCart() {
|
| 1717 |
-
if(confirm('Очистить?')) { cart =
|
| 1718 |
}
|
| 1719 |
|
| 1720 |
function renderCart() {
|
| 1721 |
const container = document.getElementById('cart-items');
|
| 1722 |
let html = '';
|
| 1723 |
let total = 0;
|
|
|
|
| 1724 |
|
| 1725 |
cart.forEach(item => {
|
| 1726 |
let effPrice = item.orig_price;
|
| 1727 |
if (item.box_qty > 1 && item.quantity >= item.box_qty) {
|
| 1728 |
effPrice = item.box_price / item.box_qty;
|
| 1729 |
}
|
| 1730 |
-
item.price = effPrice;
|
| 1731 |
const itemTotal = effPrice * item.quantity;
|
| 1732 |
total += itemTotal;
|
|
|
|
| 1733 |
|
| 1734 |
html += `
|
| 1735 |
<div class="cart-item">
|
|
@@ -1739,7 +1755,7 @@ POS_TEMPLATE = '''
|
|
| 1739 |
</div>
|
| 1740 |
<div class="cart-controls">
|
| 1741 |
<button class="qty-btn" onclick="updateQty('${item.id}', -1)">-</button>
|
| 1742 |
-
<span style="width: 20px; text-align:center;">${item.quantity}</span>
|
| 1743 |
<button class="qty-btn" onclick="updateQty('${item.id}', 1)">+</button>
|
| 1744 |
</div>
|
| 1745 |
</div>
|
|
@@ -1747,6 +1763,10 @@ POS_TEMPLATE = '''
|
|
| 1747 |
});
|
| 1748 |
container.innerHTML = html;
|
| 1749 |
document.getElementById('cart-total').textContent = total.toFixed(2) + ' ' + currencyCode;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1750 |
}
|
| 1751 |
|
| 1752 |
function checkout() {
|
|
@@ -1770,8 +1790,9 @@ POS_TEMPLATE = '''
|
|
| 1770 |
const msg = `Ваш чек на покупку: ${url}`;
|
| 1771 |
window.open(`https://api.whatsapp.com/send?phone=${phone.replace(/\D/g,'')}&text=${encodeURIComponent(msg)}`, '_blank');
|
| 1772 |
}
|
| 1773 |
-
cart =
|
| 1774 |
renderCart();
|
|
|
|
| 1775 |
alert('Заказ успешно создан!');
|
| 1776 |
location.reload();
|
| 1777 |
}
|
|
@@ -2146,12 +2167,6 @@ ADMIN_TEMPLATE = '''
|
|
| 2146 |
{% endfor %}
|
| 2147 |
</select>
|
| 2148 |
|
| 2149 |
-
<label for="env_mode">Режим работы среды:</label>
|
| 2150 |
-
<select id="env_mode" name="env_mode" style="background-color: #fff3cd; font-weight: bold;">
|
| 2151 |
-
<option value="external" {% if settings.env_mode == 'external' %}selected{% endif %}>Внешняя цифровизация</option>
|
| 2152 |
-
<option value="2in1" {% if settings.env_mode == '2in1' %}selected{% endif %}>2 в 1 (Склад и Касса)</option>
|
| 2153 |
-
</select>
|
| 2154 |
-
|
| 2155 |
<label for="business_type">Тип бизнеса:</label>
|
| 2156 |
<select id="business_type" name="business_type">
|
| 2157 |
<option value="retail" {% if settings.business_type == 'retail' %}selected{% endif %}>Розничный</option>
|
|
@@ -2373,7 +2388,7 @@ ADMIN_TEMPLATE = '''
|
|
| 2373 |
<div style="margin-top: 20px; border: 1px solid #ccc; padding: 15px; border-radius: 8px; background: #fafafa;">
|
| 2374 |
<h4 style="margin-top: 0;"><i class="fas fa-tags"></i> Отметки товаров на фото</h4>
|
| 2375 |
<div id="thumbs-edit_{{ loop.index0 }}" class="thumbnail-row"></div>
|
| 2376 |
-
<input type="hidden" name="tags_json" id="tags_json_edit_{{ loop.index0 }}" value='{{ product.get("tags",
|
| 2377 |
<div id="tagging-container-edit_{{ loop.index0 }}" class="tagging-container">
|
| 2378 |
<img id="tagging-img-edit_{{ loop.index0 }}" class="tagging-img" onclick="handleTagClick(event, 'edit_{{ loop.index0 }}')">
|
| 2379 |
<div id="tag-markers-edit_{{ loop.index0 }}"></div>
|
|
@@ -2459,7 +2474,7 @@ ADMIN_TEMPLATE = '''
|
|
| 2459 |
const bType = '{{ settings.business_type }}';
|
| 2460 |
const envMode = '{{ settings.env_mode }}';
|
| 2461 |
const formStates = {};
|
| 2462 |
-
let adminAiHistory =
|
| 2463 |
|
| 2464 |
function showLoadingOverlay() {
|
| 2465 |
document.getElementById('loadingOverlay').style.display = 'flex';
|
|
@@ -2472,7 +2487,7 @@ ADMIN_TEMPLATE = '''
|
|
| 2472 |
}
|
| 2473 |
|
| 2474 |
function initScope(scope) {
|
| 2475 |
-
if(!formStates[scope]) formStates[scope] = { tags: [], fileUrls:
|
| 2476 |
}
|
| 2477 |
|
| 2478 |
function toggleEditForm(formId, index) {
|
|
@@ -2485,11 +2500,11 @@ ADMIN_TEMPLATE = '''
|
|
| 2485 |
const product = allProductsForAdmin[index];
|
| 2486 |
initScope(scope);
|
| 2487 |
|
| 2488 |
-
let tags =
|
| 2489 |
try { tags = JSON.parse(document.getElementById(`tags_json_${scope}`).value); } catch(e){}
|
| 2490 |
formStates[scope].tags = tags;
|
| 2491 |
|
| 2492 |
-
formStates[scope].fileUrls =
|
| 2493 |
if (product.photos && product.photos.length > 0) {
|
| 2494 |
product.photos.forEach(p => {
|
| 2495 |
formStates[scope].fileUrls.push(`https://huggingface.co/datasets/${repoId}/resolve/main/photos/${p}`);
|
|
@@ -2508,7 +2523,7 @@ ADMIN_TEMPLATE = '''
|
|
| 2508 |
if (!files || files.length === 0) return;
|
| 2509 |
|
| 2510 |
formStates[scope].fileUrls = [];
|
| 2511 |
-
formStates[scope].tags =
|
| 2512 |
document.getElementById(`tags_json_${scope}`).value = '[]';
|
| 2513 |
formStates[scope].currentIdx = 0;
|
| 2514 |
|
|
@@ -2606,7 +2621,7 @@ ADMIN_TEMPLATE = '''
|
|
| 2606 |
|
| 2607 |
function updateHiddenTags(scope) {
|
| 2608 |
const input = document.getElementById(`tags_json_${scope}`);
|
| 2609 |
-
if(input) input.value = JSON.stringify(formStates[scope].tags ||
|
| 2610 |
}
|
| 2611 |
|
| 2612 |
function removeTag(scope, id) {
|
|
@@ -2625,7 +2640,7 @@ ADMIN_TEMPLATE = '''
|
|
| 2625 |
markersContainer.innerHTML = '';
|
| 2626 |
listContainer.innerHTML = '';
|
| 2627 |
|
| 2628 |
-
const tags = formStates[scope].tags ||
|
| 2629 |
tags.forEach(tag => {
|
| 2630 |
if (tag.photo_index === formStates[scope].currentIdx) {
|
| 2631 |
const marker = document.createElement('div');
|
|
@@ -2639,7 +2654,7 @@ ADMIN_TEMPLATE = '''
|
|
| 2639 |
const listItem = document.createElement('div');
|
| 2640 |
listItem.className = 'tag-list-item';
|
| 2641 |
let varText = tag.variants ? ` [Вар: ${tag.variants}]` : '';
|
| 2642 |
-
let boxText = (bType === 'wholesale' || bType === 'combined') ? `
|
| 2643 |
let stockText = tag.stock !== null && tag.stock !== undefined ? ` [Остаток: ${tag.stock}]` : '';
|
| 2644 |
listItem.innerHTML = `
|
| 2645 |
<span>[Фото ${tag.photo_index + 1}] ${tag.name} (Шт: ${tag.price})${boxText}${varText}${stockText}</span>
|
|
@@ -2766,7 +2781,7 @@ def index():
|
|
| 2766 |
@app.route('/admhosto', methods=['GET'])
|
| 2767 |
def admhosto():
|
| 2768 |
data = load_data()
|
| 2769 |
-
environments_data =
|
| 2770 |
for env_id, env_data in data.items():
|
| 2771 |
settings = env_data.get('settings', {})
|
| 2772 |
org_name = settings.get("organization_name", "Gippo312")
|
|
@@ -2790,7 +2805,7 @@ def create_environment():
|
|
| 2790 |
if new_id not in all_data:
|
| 2791 |
break
|
| 2792 |
all_data[new_id] = {
|
| 2793 |
-
'products': [], 'categories': [], 'orders': {}, 'employees': [], 'blocks':
|
| 2794 |
'organization_info': {
|
| 2795 |
"about_us": "Мы — Gippo312, ваш надежный партнер в мире уникальных товаров.",
|
| 2796 |
"shipping": "Доставка осуществляется по всему Кыргызстану.",
|
|
@@ -2810,6 +2825,18 @@ def create_environment():
|
|
| 2810 |
flash(f'Новая среда с ID {new_id} успешно создана.', 'success')
|
| 2811 |
return redirect(url_for('admhosto'))
|
| 2812 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2813 |
@app.route('/admhosto/update_pwd/<env_id>', methods=['POST'])
|
| 2814 |
def update_env_pwd(env_id):
|
| 2815 |
all_data = load_data()
|
|
@@ -2861,16 +2888,16 @@ def admin_logout(env_id):
|
|
| 2861 |
@app.route('/<env_id>/catalog')
|
| 2862 |
def catalog(env_id):
|
| 2863 |
data = get_env_data(env_id)
|
| 2864 |
-
all_products_raw = data.get('products',
|
| 2865 |
settings = data.get('settings', {})
|
| 2866 |
-
blocks = data.get('blocks',
|
| 2867 |
product_categories = set(p.get('category', 'Без категории') for p in all_products_raw)
|
| 2868 |
-
admin_categories = set(data.get('categories',
|
| 2869 |
all_cat_names = sorted(list(product_categories.union(admin_categories)))
|
| 2870 |
-
products_in_stock =
|
| 2871 |
products_sorted_for_js = sorted(products_in_stock, key=lambda p: (not p.get('is_top', False), p.get('name', '').lower()))
|
| 2872 |
|
| 2873 |
-
products_by_category = {cat:
|
| 2874 |
for product in products_in_stock:
|
| 2875 |
products_by_category[product.get('category', 'Без категории')].append(product)
|
| 2876 |
ordered_categories = [cat for cat in all_cat_names if products_by_category.get(cat)]
|
|
@@ -2889,7 +2916,7 @@ def pos_page(env_id):
|
|
| 2889 |
if settings.get('env_mode') != '2in1':
|
| 2890 |
return "POS доступен только в режиме '2 в 1'", 403
|
| 2891 |
emp_id = request.args.get('emp', '')
|
| 2892 |
-
products = data.get('products',
|
| 2893 |
return render_template_string(POS_TEMPLATE, products_json=json.dumps(products), settings=settings, currency_code=settings.get('currency_code', 'KGS'), env_id=env_id, emp_id=emp_id, repo_id=REPO_ID)
|
| 2894 |
|
| 2895 |
@app.route('/<env_id>/reports')
|
|
@@ -2918,7 +2945,7 @@ def reports_page(env_id):
|
|
| 2918 |
emp_stats[emp]['count'] += 1
|
| 2919 |
emp_stats[emp]['revenue'] += o.get('total_price', 0)
|
| 2920 |
|
| 2921 |
-
for item in o.get('cart',
|
| 2922 |
name = item.get('name', 'Неизвестно')
|
| 2923 |
qty = item.get('quantity', 0)
|
| 2924 |
if name not in product_sales:
|
|
@@ -2934,7 +2961,6 @@ def reports_page(env_id):
|
|
| 2934 |
emp_stats=emp_stats, top_products=top_products[:20]
|
| 2935 |
)
|
| 2936 |
|
| 2937 |
-
|
| 2938 |
@app.route('/<env_id>/track_view/<product_id>', methods=['POST'])
|
| 2939 |
def track_view(env_id, product_id):
|
| 2940 |
data = get_env_data(env_id)
|
|
@@ -2948,9 +2974,9 @@ def track_view(env_id, product_id):
|
|
| 2948 |
@app.route('/<env_id>/product/<int:index>')
|
| 2949 |
def product_detail(env_id, index):
|
| 2950 |
data = get_env_data(env_id)
|
| 2951 |
-
all_products_raw = data.get('products',
|
| 2952 |
settings = data.get('settings', {})
|
| 2953 |
-
products_in_stock =
|
| 2954 |
products_sorted = sorted(products_in_stock, key=lambda p: (not p.get('is_top', False), p.get('name', '').lower()))
|
| 2955 |
try:
|
| 2956 |
product = products_sorted[index]
|
|
@@ -2969,7 +2995,7 @@ def create_order(env_id):
|
|
| 2969 |
|
| 2970 |
data = get_env_data(env_id)
|
| 2971 |
settings = data.get('settings', {})
|
| 2972 |
-
products = data.get('products',
|
| 2973 |
env_mode = settings.get('env_mode', 'external')
|
| 2974 |
|
| 2975 |
cart_items = order_data['cart']
|
|
@@ -2980,7 +3006,7 @@ def create_order(env_id):
|
|
| 2980 |
emp_whatsapp = None
|
| 2981 |
|
| 2982 |
if emp_id:
|
| 2983 |
-
employees = data.get('employees',
|
| 2984 |
for emp in employees:
|
| 2985 |
if emp.get('id') == emp_id:
|
| 2986 |
emp_name = emp.get('name')
|
|
@@ -2988,7 +3014,7 @@ def create_order(env_id):
|
|
| 2988 |
break
|
| 2989 |
|
| 2990 |
total_price = 0
|
| 2991 |
-
processed_cart =
|
| 2992 |
|
| 2993 |
for item in cart_items:
|
| 2994 |
if not all(k in item for k in ('name', 'quantity')):
|
|
@@ -3011,7 +3037,7 @@ def create_order(env_id):
|
|
| 3011 |
tag_ref = None
|
| 3012 |
if 'TAG_' in c_color:
|
| 3013 |
tag_id = c_color.split('_VAR_')[0].replace('TAG_', '')
|
| 3014 |
-
tag_ref = next((t for t in product_ref.get('tags',
|
| 3015 |
|
| 3016 |
price = float(item.get('price', 0))
|
| 3017 |
discount_applied = False
|
|
@@ -3082,7 +3108,7 @@ def update_order(env_id, order_id):
|
|
| 3082 |
|
| 3083 |
try:
|
| 3084 |
idx = int(idx)
|
| 3085 |
-
cart = order.get('cart',
|
| 3086 |
if idx < 0 or idx >= len(cart):
|
| 3087 |
return jsonify({"error": "Товар не найден."}), 404
|
| 3088 |
|
|
@@ -3137,7 +3163,7 @@ def history_page(env_id):
|
|
| 3137 |
|
| 3138 |
orders = list(data.get('orders', {}).values())
|
| 3139 |
orders.sort(key=lambda x: x.get('created_at', ''), reverse=True)
|
| 3140 |
-
employees = data.get('employees',
|
| 3141 |
return render_template_string(HISTORY_TEMPLATE, orders=orders, employees=employees, settings=settings, currency_code=settings.get('currency_code', 'KGS'), env_id=env_id)
|
| 3142 |
|
| 3143 |
@app.route('/<env_id>/admin_ai_chat', methods=['POST'])
|
|
@@ -3152,10 +3178,10 @@ def admin_ai_chat(env_id):
|
|
| 3152 |
|
| 3153 |
req = request.get_json()
|
| 3154 |
message = req.get('message')
|
| 3155 |
-
history = req.get('history',
|
| 3156 |
|
| 3157 |
orders = data.get('orders', {})
|
| 3158 |
-
products = data.get('products',
|
| 3159 |
|
| 3160 |
now = datetime.now(ALMATY_TZ)
|
| 3161 |
current_month = now.strftime('%Y-%m')
|
|
@@ -3166,7 +3192,7 @@ def admin_ai_chat(env_id):
|
|
| 3166 |
for o in orders.values():
|
| 3167 |
if o.get('created_at', '').startswith(current_month):
|
| 3168 |
monthly_revenue += o.get('total_price', 0)
|
| 3169 |
-
for item in o.get('cart',
|
| 3170 |
pid = item.get('product_id')
|
| 3171 |
product_sales_counts[pid] = product_sales_counts.get(pid, 0) + item.get('quantity', 0)
|
| 3172 |
|
|
@@ -3175,7 +3201,7 @@ def admin_ai_chat(env_id):
|
|
| 3175 |
views_str = ", ".join(views_str_list) if views_str_list else "Нет просмотров"
|
| 3176 |
|
| 3177 |
sorted_sales_pids = sorted(product_sales_counts.items(), key=lambda x: x[1], reverse=True)[:5]
|
| 3178 |
-
sales_str_list =
|
| 3179 |
for pid, qty in sorted_sales_pids:
|
| 3180 |
p = next((x for x in products if x['product_id'] == pid), None)
|
| 3181 |
if p:
|
|
@@ -3189,12 +3215,12 @@ def admin_ai_chat(env_id):
|
|
| 3189 |
Выручка за этот месяц: {monthly_revenue} {currency}.
|
| 3190 |
Самые просматриваемые товары (Топ-5): {views_str}.
|
| 3191 |
Самые продаваемые товары (Топ-5): {sales_str}.
|
| 3192 |
-
Если упоминаешь товар, используй точный формат:
|
| 3193 |
Помогай владельцу анализировать продажи и отвечать на бизнес-вопросы."""
|
| 3194 |
|
| 3195 |
try:
|
| 3196 |
model = genai.GenerativeModel('gemma-4-26b-a4b-it')
|
| 3197 |
-
messages = [{'role': 'user', 'parts':
|
| 3198 |
for h in history:
|
| 3199 |
messages.append({'role': 'model' if h['role'] == 'ai' else 'user', 'parts': [{'text': h['text']}]})
|
| 3200 |
chat = model.start_chat(history=messages)
|
|
@@ -3212,10 +3238,10 @@ def admin(env_id):
|
|
| 3212 |
return redirect(url_for('admin_login', env_id=env_id))
|
| 3213 |
|
| 3214 |
products = data.get('products', [])
|
| 3215 |
-
categories = data.get('categories',
|
| 3216 |
organization_info = data.get('organization_info', {})
|
| 3217 |
-
employees = data.get('employees',
|
| 3218 |
-
blocks = data.get('blocks',
|
| 3219 |
|
| 3220 |
page = request.args.get('p', 1, type=int)
|
| 3221 |
search_q = request.args.get('q', '').strip()
|
|
@@ -3275,7 +3301,7 @@ def admin(env_id):
|
|
| 3275 |
flash("Сотрудник добавлен.", "success")
|
| 3276 |
elif action == 'delete_employee':
|
| 3277 |
emp_id = request.form.get('emp_id')
|
| 3278 |
-
employees =
|
| 3279 |
data['employees'] = employees
|
| 3280 |
save_env_data(env_id, data)
|
| 3281 |
flash("Сотрудник удален.", "success")
|
|
@@ -3323,7 +3349,6 @@ def admin(env_id):
|
|
| 3323 |
settings['organization_name'] = request.form.get('organization_name', 'Gippo312').strip()
|
| 3324 |
settings['whatsapp_number'] = request.form.get('whatsapp_number', '').strip()
|
| 3325 |
settings['currency_code'] = request.form.get('currency_code', 'KGS')
|
| 3326 |
-
settings['env_mode'] = request.form.get('env_mode', 'external')
|
| 3327 |
settings['business_type'] = request.form.get('business_type', 'retail')
|
| 3328 |
settings['color_scheme'] = request.form.get('color_scheme', 'default')
|
| 3329 |
|
|
@@ -3401,7 +3426,7 @@ def admin(env_id):
|
|
| 3401 |
uploads_dir = 'uploads_temp'
|
| 3402 |
os.makedirs(uploads_dir, exist_ok=True)
|
| 3403 |
api = HfApi()
|
| 3404 |
-
new_photos_list =
|
| 3405 |
photo_limit = 10
|
| 3406 |
uploaded_count = 0
|
| 3407 |
for photo in photos_files:
|
|
@@ -3449,7 +3474,7 @@ def admin(env_id):
|
|
| 3449 |
return redirect(url_for('admin', env_id=env_id, p=page, q=search_q))
|
| 3450 |
deleted_product = products.pop(product_index)
|
| 3451 |
product_name = deleted_product.get('name', 'N/A')
|
| 3452 |
-
photos_to_delete = deleted_product.get('photos',
|
| 3453 |
if photos_to_delete and HF_TOKEN_WRITE:
|
| 3454 |
try:
|
| 3455 |
api = HfApi()
|
|
@@ -3468,7 +3493,7 @@ def admin(env_id):
|
|
| 3468 |
filtered_products = products
|
| 3469 |
if search_q:
|
| 3470 |
q_lower = search_q.lower()
|
| 3471 |
-
filtered_products =
|
| 3472 |
|
| 3473 |
filtered_products = sorted(filtered_products, key=lambda p: p.get('name', '').lower())
|
| 3474 |
|
|
|
|
| 207 |
env_data = all_data.get(env_id, {})
|
| 208 |
if not env_data:
|
| 209 |
env_data = {
|
| 210 |
+
'products': [], 'categories': [], 'orders': {}, 'employees':[], 'blocks':[],
|
| 211 |
'organization_info': default_organization_info,
|
| 212 |
'settings': default_settings
|
| 213 |
}
|
| 214 |
|
| 215 |
+
if 'products' not in env_data: env_data['products'] =[]
|
| 216 |
+
if 'categories' not in env_data: env_data['categories'] =[]
|
| 217 |
if 'orders' not in env_data: env_data['orders'] = {}
|
| 218 |
if 'organization_info' not in env_data: env_data['organization_info'] = default_organization_info
|
| 219 |
if 'settings' not in env_data: env_data['settings'] = default_settings
|
| 220 |
+
if 'employees' not in env_data: env_data['employees'] =[]
|
| 221 |
+
if 'blocks' not in env_data: env_data['blocks'] =[]
|
| 222 |
|
| 223 |
settings_changed = False
|
| 224 |
for key, value in default_settings.items():
|
|
|
|
| 241 |
product['variant_stock'] = {}
|
| 242 |
products_changed = True
|
| 243 |
if 'tags' not in product:
|
| 244 |
+
product['tags'] =[]
|
| 245 |
products_changed = True
|
| 246 |
|
| 247 |
if products_changed or settings_changed:
|
|
|
|
| 385 |
.message { padding: 10px 15px; border-radius: 6px; margin-bottom: 15px; text-align: center; }
|
| 386 |
.message.success { background-color: #d4edda; color: #155724; }
|
| 387 |
.message.error { background-color: #f8d7da; color: #721c24; }
|
|
|
|
|
|
|
| 388 |
</style>
|
| 389 |
</head>
|
| 390 |
<body>
|
|
|
|
| 416 |
{% for env in environments %}
|
| 417 |
<li class="env-item">
|
| 418 |
<div class="env-header">
|
| 419 |
+
<div style="display:flex; align-items:center; gap: 10px; flex-wrap: wrap;">
|
| 420 |
+
<span class="env-id">{{ env.org_name }} (ID: {{ env.id }})</span>
|
| 421 |
+
<form method="POST" action="{{ url_for('update_env_mode', env_id=env.id) }}" style="margin:0;">
|
| 422 |
+
<select name="env_mode" onchange="this.form.submit()" style="padding: 4px; border-radius: 4px; border: 1px solid #ccc; font-size: 0.85rem; font-weight: bold;">
|
| 423 |
+
<option value="external" {% if env.mode == 'external' %}selected{% endif %}>Внешняя цифр.</option>
|
| 424 |
+
<option value="2in1" {% if env.mode == '2in1' %}selected{% endif %}>2 в 1</option>
|
| 425 |
+
</select>
|
| 426 |
+
</form>
|
| 427 |
+
</div>
|
| 428 |
<div class="env-actions">
|
| 429 |
<a href="{{ url_for('admin', env_id=env.id) }}" class="button" target="_blank"><i class="fas fa-tools"></i> Админ</a>
|
| 430 |
<a href="{{ url_for('catalog', env_id=env.id) }}" class="button" target="_blank"><i class="fas fa-store"></i> Каталог</a>
|
|
|
|
| 648 |
@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; } }
|
| 649 |
</style>
|
| 650 |
</head>
|
| 651 |
+
<body class="{{ 'dark-theme' if settings.color_scheme in['dark', 'cyberpunk', 'neon', 'volcano', 'gold', 'monochrome_dark', 'nord', 'dracula', 'ruby', 'sapphire', 'amethyst', 'cosmic', 'crimson', 'mocha', 'minty', 'solar'] else '' }}">
|
| 652 |
<div class="container">
|
| 653 |
<div class="top-bar">
|
| 654 |
<a href="#" class="logo" onclick="window.scrollTo({top:0, behavior:'smooth'}); return false;">
|
|
|
|
| 1020 |
const product = getProductById(productId);
|
| 1021 |
const tag = product.tags.find(t => t.id === tagId);
|
| 1022 |
let variantName = colorCode.includes('_VAR_') ? colorCode.split('_VAR_')[1] : "";
|
| 1023 |
+
let unitLabel = unitType === 'box' ? `[Упак: ${tag.box_qty}шт]` : ` [Шт]`;
|
| 1024 |
let itemPrice = unitType === 'box' ? tag.box_price : tag.price;
|
| 1025 |
let itemName = product.name + " (" + tag.name + (variantName ? ` - ${variantName}` : "") + ")" + unitLabel;
|
| 1026 |
let photoUrl = product.photos && product.photos[tag.photo_index] ? product.photos[tag.photo_index] : null;
|
|
|
|
| 1139 |
|
| 1140 |
function clearCart() {
|
| 1141 |
if (confirm("Вы уверены, что хотите очистить корзину?")) {
|
| 1142 |
+
cart =[]; localStorage.removeItem(`mekaCart_${envId}`);
|
| 1143 |
openCartModal(); updateCartButton(); renderVariantsList();
|
| 1144 |
}
|
| 1145 |
}
|
|
|
|
| 1148 |
if (cart.length === 0) { alert("Корзина пуста!"); return; }
|
| 1149 |
|
| 1150 |
const customerData = {};
|
| 1151 |
+
let hasError = false;['name', 'phone', 'city', 'address', 'zip'].forEach(field => {
|
|
|
|
| 1152 |
const el = document.getElementById('c_' + field);
|
| 1153 |
if (el) {
|
| 1154 |
if (!el.value.trim()) {
|
|
|
|
| 1173 |
}).then(data => {
|
| 1174 |
if (data.order_id) {
|
| 1175 |
localStorage.removeItem(`mekaCart_${envId}`);
|
| 1176 |
+
cart =[]; updateCartButton(); renderVariantsList(); closeModal('cartModal');
|
| 1177 |
window.location.href = `/${envId}/order/${data.order_id}`;
|
| 1178 |
} else throw new Error('Не получен ID заказа.');
|
| 1179 |
}).catch(error => {
|
|
|
|
| 1576 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
|
| 1577 |
<style>
|
| 1578 |
* { box-sizing: border-box; margin: 0; padding: 0; }
|
| 1579 |
+
body { font-family: 'Montserrat', sans-serif; background-color: #f4f6f9; color: #333; height: 100vh; overflow: hidden; display: flex; flex-direction: column;}
|
| 1580 |
+
|
| 1581 |
+
.top-bar { padding: 0 15px; height: 60px; background: #135D66; color: white; display: flex; gap: 15px; align-items: center; flex-shrink: 0;}
|
| 1582 |
+
.cart-toggle { background: transparent; border: none; color: white; font-size: 1.5rem; cursor: pointer; position: relative; display: flex; align-items: center;}
|
| 1583 |
+
.cart-badge { position: absolute; top: -8px; right: -12px; background: #E57373; color: white; font-size: 0.75rem; font-weight: bold; border-radius: 50%; width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; border: 2px solid #135D66;}
|
| 1584 |
|
| 1585 |
+
.search-input { flex-grow: 1; padding: 10px; border-radius: 8px; border: none; font-size: 1rem; outline: none; }
|
| 1586 |
+
.products-grid { flex: 1; overflow-y: auto; padding: 15px; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 15px; align-content: start; }
|
|
|
|
|
|
|
| 1587 |
.product-card { border: 1px solid #e0e0e0; border-radius: 8px; overflow: hidden; cursor: pointer; transition: transform 0.1s; background: #fafafa; display: flex; flex-direction: column; }
|
| 1588 |
.product-card:active { transform: scale(0.98); }
|
| 1589 |
.product-card img { width: 100%; height: 120px; object-fit: cover; }
|
| 1590 |
.product-info { padding: 10px; font-size: 0.9rem; flex-grow: 1; display: flex; flex-direction: column; justify-content: space-between;}
|
| 1591 |
+
.product-name { font-weight: 600; margin-bottom: 5px; font-size: 0.85rem;}
|
| 1592 |
.product-price { color: #135D66; font-weight: bold; }
|
| 1593 |
+
.product-stock { font-size: 0.75rem; color: #666; margin-top: 5px; }
|
| 1594 |
+
|
| 1595 |
+
.cart-sidebar { position: fixed; top: 0; left: -100%; width: 100%; max-width: 400px; height: 100vh; background: #fdfdff; z-index: 1000; transition: left 0.3s ease; display: flex; flex-direction: column; box-shadow: 2px 0 10px rgba(0,0,0,0.2); }
|
| 1596 |
+
.cart-sidebar.open { left: 0; }
|
| 1597 |
+
.cart-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 999; display: none; opacity: 0; transition: opacity 0.3s ease;}
|
| 1598 |
+
.cart-overlay.open { display: block; opacity: 1; }
|
| 1599 |
+
.cart-header { padding: 20px; background: #fff; border-bottom: 1px solid #e0e0e0; font-size: 1.2rem; font-weight: bold; color: #135D66; display: flex; justify-content: space-between; align-items: center; }
|
| 1600 |
+
.close-cart { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: #666; }
|
| 1601 |
.cart-items { flex: 1; overflow-y: auto; padding: 15px; }
|
| 1602 |
+
.cart-item { display: flex; justify-content: space-between; align-items: center; padding: 12px; background: #fff; border: 1px solid #eee; border-radius: 8px; margin-bottom: 10px; }
|
| 1603 |
.cart-item-details { flex-grow: 1; }
|
| 1604 |
+
.cart-item-name { font-weight: 600; font-size: 0.9rem; margin-bottom: 5px; }
|
| 1605 |
+
.cart-item-price { font-size: 0.85rem; color: #666; }
|
| 1606 |
+
.cart-controls { display: flex; align-items: center; gap: 8px; }
|
| 1607 |
+
.qty-btn { width: 28px; height: 28px; background: #eee; border: none; border-radius: 4px; font-weight: bold; cursor: pointer; }
|
|
|
|
| 1608 |
|
| 1609 |
.checkout-panel { padding: 20px; background: #fff; border-top: 1px solid #e0e0e0; }
|
| 1610 |
+
.total-row { display: flex; justify-content: space-between; font-size: 1.3rem; font-weight: bold; color: #135D66; margin-bottom: 15px; }
|
| 1611 |
.input-group { margin-bottom: 15px; }
|
| 1612 |
+
.input-group label { display: block; font-size: 0.85rem; margin-bottom: 5px; color: #555; }
|
| 1613 |
+
.input-group input { width: 100%; padding: 12px; border: 1px solid #ccc; border-radius: 8px; font-size: 1rem; outline: none;}
|
| 1614 |
+
.btn-checkout { width: 100%; padding: 15px; background: #48D1CC; color: #003C43; border: none; border-radius: 8px; font-size: 1.05rem; font-weight: bold; cursor: pointer; transition: background 0.2s; }
|
| 1615 |
.btn-checkout:hover { background: #77E4D8; }
|
| 1616 |
.btn-clear { width: 100%; padding: 10px; background: #eee; color: #555; border: none; border-radius: 8px; font-size: 0.9rem; cursor: pointer; margin-bottom: 10px; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1617 |
</style>
|
| 1618 |
</head>
|
| 1619 |
<body>
|
| 1620 |
+
<div class="top-bar">
|
| 1621 |
+
<button class="cart-toggle" onclick="toggleCart()">
|
| 1622 |
+
<i class="fas fa-shopping-cart"></i>
|
| 1623 |
+
<span class="cart-badge" id="cart-badge" style="display:none;">0</span>
|
| 1624 |
+
</button>
|
| 1625 |
+
<h2 style="margin:0; font-size: 1.2rem; display:none; @media min-width:600px {display:block;}">POS</h2>
|
| 1626 |
+
<input type="text" class="search-input" id="search-input" placeholder="Поиск товаров..." oninput="renderProducts()">
|
| 1627 |
</div>
|
| 1628 |
|
| 1629 |
+
<div class="products-grid" id="products-grid"></div>
|
| 1630 |
+
|
| 1631 |
+
<div id="cart-overlay" class="cart-overlay" onclick="toggleCart()"></div>
|
| 1632 |
+
|
| 1633 |
+
<div id="cart-sidebar" class="cart-sidebar">
|
| 1634 |
+
<div class="cart-header">
|
| 1635 |
+
<span>Текущий заказ</span>
|
| 1636 |
+
<button onclick="toggleCart()" class="close-cart"><i class="fas fa-times"></i></button>
|
| 1637 |
+
</div>
|
| 1638 |
<div class="cart-items" id="cart-items"></div>
|
| 1639 |
<div class="checkout-panel">
|
| 1640 |
<button class="btn-clear" onclick="clearCart()">Очистить корзину</button>
|
|
|
|
| 1656 |
const empId = '{{ emp_id }}';
|
| 1657 |
const currencyCode = '{{ currency_code }}';
|
| 1658 |
const repoId = '{{ repo_id }}';
|
| 1659 |
+
let cart =[];
|
| 1660 |
+
|
| 1661 |
+
function toggleCart() {
|
| 1662 |
+
document.getElementById('cart-sidebar').classList.toggle('open');
|
| 1663 |
+
document.getElementById('cart-overlay').classList.toggle('open');
|
| 1664 |
+
}
|
| 1665 |
|
| 1666 |
function renderProducts() {
|
| 1667 |
const query = document.getElementById('search-input').value.toLowerCase();
|
|
|
|
| 1671 |
allProducts.forEach(p => {
|
| 1672 |
if(query && !p.name.toLowerCase().includes(query)) return;
|
| 1673 |
|
|
|
|
| 1674 |
p.tags.forEach(tag => {
|
| 1675 |
if(query && !tag.name.toLowerCase().includes(query) && !p.name.toLowerCase().includes(query)) return;
|
| 1676 |
|
|
|
|
| 1680 |
|
| 1681 |
const stockText = tag.stock !== undefined ? `Остаток: ${tag.stock}` : 'В наличии';
|
| 1682 |
|
|
|
|
| 1683 |
const tagData = JSON.stringify({
|
| 1684 |
id: tag.id, pid: p.product_id, name: `${p.name} (${tag.name})`,
|
| 1685 |
price: tag.price, box_price: tag.box_price, box_qty: tag.box_qty, photo: p.photos ? p.photos[tag.photo_index] : null
|
|
|
|
| 1712 |
});
|
| 1713 |
}
|
| 1714 |
renderCart();
|
| 1715 |
+
|
| 1716 |
+
const badge = document.getElementById('cart-badge');
|
| 1717 |
+
badge.style.transform = 'scale(1.3)';
|
| 1718 |
+
setTimeout(() => badge.style.transform = 'scale(1)', 200);
|
| 1719 |
}
|
| 1720 |
|
| 1721 |
function updateQty(id, delta) {
|
|
|
|
| 1728 |
}
|
| 1729 |
|
| 1730 |
function clearCart() {
|
| 1731 |
+
if(confirm('Очистить корзину?')) { cart =[]; renderCart(); }
|
| 1732 |
}
|
| 1733 |
|
| 1734 |
function renderCart() {
|
| 1735 |
const container = document.getElementById('cart-items');
|
| 1736 |
let html = '';
|
| 1737 |
let total = 0;
|
| 1738 |
+
let totalQty = 0;
|
| 1739 |
|
| 1740 |
cart.forEach(item => {
|
| 1741 |
let effPrice = item.orig_price;
|
| 1742 |
if (item.box_qty > 1 && item.quantity >= item.box_qty) {
|
| 1743 |
effPrice = item.box_price / item.box_qty;
|
| 1744 |
}
|
| 1745 |
+
item.price = effPrice;
|
| 1746 |
const itemTotal = effPrice * item.quantity;
|
| 1747 |
total += itemTotal;
|
| 1748 |
+
totalQty += item.quantity;
|
| 1749 |
|
| 1750 |
html += `
|
| 1751 |
<div class="cart-item">
|
|
|
|
| 1755 |
</div>
|
| 1756 |
<div class="cart-controls">
|
| 1757 |
<button class="qty-btn" onclick="updateQty('${item.id}', -1)">-</button>
|
| 1758 |
+
<span style="width: 20px; text-align:center; font-weight:bold;">${item.quantity}</span>
|
| 1759 |
<button class="qty-btn" onclick="updateQty('${item.id}', 1)">+</button>
|
| 1760 |
</div>
|
| 1761 |
</div>
|
|
|
|
| 1763 |
});
|
| 1764 |
container.innerHTML = html;
|
| 1765 |
document.getElementById('cart-total').textContent = total.toFixed(2) + ' ' + currencyCode;
|
| 1766 |
+
|
| 1767 |
+
const badge = document.getElementById('cart-badge');
|
| 1768 |
+
badge.textContent = totalQty;
|
| 1769 |
+
badge.style.display = totalQty > 0 ? 'flex' : 'none';
|
| 1770 |
}
|
| 1771 |
|
| 1772 |
function checkout() {
|
|
|
|
| 1790 |
const msg = `Ваш чек на покупку: ${url}`;
|
| 1791 |
window.open(`https://api.whatsapp.com/send?phone=${phone.replace(/\D/g,'')}&text=${encodeURIComponent(msg)}`, '_blank');
|
| 1792 |
}
|
| 1793 |
+
cart =[];
|
| 1794 |
renderCart();
|
| 1795 |
+
toggleCart();
|
| 1796 |
alert('Заказ успешно создан!');
|
| 1797 |
location.reload();
|
| 1798 |
}
|
|
|
|
| 2167 |
{% endfor %}
|
| 2168 |
</select>
|
| 2169 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2170 |
<label for="business_type">Тип бизнеса:</label>
|
| 2171 |
<select id="business_type" name="business_type">
|
| 2172 |
<option value="retail" {% if settings.business_type == 'retail' %}selected{% endif %}>Розничный</option>
|
|
|
|
| 2388 |
<div style="margin-top: 20px; border: 1px solid #ccc; padding: 15px; border-radius: 8px; background: #fafafa;">
|
| 2389 |
<h4 style="margin-top: 0;"><i class="fas fa-tags"></i> Отметки товаров на фото</h4>
|
| 2390 |
<div id="thumbs-edit_{{ loop.index0 }}" class="thumbnail-row"></div>
|
| 2391 |
+
<input type="hidden" name="tags_json" id="tags_json_edit_{{ loop.index0 }}" value='{{ product.get("tags",[])|tojson|safe }}'>
|
| 2392 |
<div id="tagging-container-edit_{{ loop.index0 }}" class="tagging-container">
|
| 2393 |
<img id="tagging-img-edit_{{ loop.index0 }}" class="tagging-img" onclick="handleTagClick(event, 'edit_{{ loop.index0 }}')">
|
| 2394 |
<div id="tag-markers-edit_{{ loop.index0 }}"></div>
|
|
|
|
| 2474 |
const bType = '{{ settings.business_type }}';
|
| 2475 |
const envMode = '{{ settings.env_mode }}';
|
| 2476 |
const formStates = {};
|
| 2477 |
+
let adminAiHistory =[];
|
| 2478 |
|
| 2479 |
function showLoadingOverlay() {
|
| 2480 |
document.getElementById('loadingOverlay').style.display = 'flex';
|
|
|
|
| 2487 |
}
|
| 2488 |
|
| 2489 |
function initScope(scope) {
|
| 2490 |
+
if(!formStates[scope]) formStates[scope] = { tags: [], fileUrls:[], currentIdx: 0, isEdit: scope.startsWith('edit_') };
|
| 2491 |
}
|
| 2492 |
|
| 2493 |
function toggleEditForm(formId, index) {
|
|
|
|
| 2500 |
const product = allProductsForAdmin[index];
|
| 2501 |
initScope(scope);
|
| 2502 |
|
| 2503 |
+
let tags =[];
|
| 2504 |
try { tags = JSON.parse(document.getElementById(`tags_json_${scope}`).value); } catch(e){}
|
| 2505 |
formStates[scope].tags = tags;
|
| 2506 |
|
| 2507 |
+
formStates[scope].fileUrls =[];
|
| 2508 |
if (product.photos && product.photos.length > 0) {
|
| 2509 |
product.photos.forEach(p => {
|
| 2510 |
formStates[scope].fileUrls.push(`https://huggingface.co/datasets/${repoId}/resolve/main/photos/${p}`);
|
|
|
|
| 2523 |
if (!files || files.length === 0) return;
|
| 2524 |
|
| 2525 |
formStates[scope].fileUrls = [];
|
| 2526 |
+
formStates[scope].tags =[];
|
| 2527 |
document.getElementById(`tags_json_${scope}`).value = '[]';
|
| 2528 |
formStates[scope].currentIdx = 0;
|
| 2529 |
|
|
|
|
| 2621 |
|
| 2622 |
function updateHiddenTags(scope) {
|
| 2623 |
const input = document.getElementById(`tags_json_${scope}`);
|
| 2624 |
+
if(input) input.value = JSON.stringify(formStates[scope].tags ||[]);
|
| 2625 |
}
|
| 2626 |
|
| 2627 |
function removeTag(scope, id) {
|
|
|
|
| 2640 |
markersContainer.innerHTML = '';
|
| 2641 |
listContainer.innerHTML = '';
|
| 2642 |
|
| 2643 |
+
const tags = formStates[scope].tags ||[];
|
| 2644 |
tags.forEach(tag => {
|
| 2645 |
if (tag.photo_index === formStates[scope].currentIdx) {
|
| 2646 |
const marker = document.createElement('div');
|
|
|
|
| 2654 |
const listItem = document.createElement('div');
|
| 2655 |
listItem.className = 'tag-list-item';
|
| 2656 |
let varText = tag.variants ? ` [Вар: ${tag.variants}]` : '';
|
| 2657 |
+
let boxText = (bType === 'wholesale' || bType === 'combined') ? `[Упак: ${tag.box_qty}шт за ${tag.box_price}]` : '';
|
| 2658 |
let stockText = tag.stock !== null && tag.stock !== undefined ? ` [Остаток: ${tag.stock}]` : '';
|
| 2659 |
listItem.innerHTML = `
|
| 2660 |
<span>[Фото ${tag.photo_index + 1}] ${tag.name} (Шт: ${tag.price})${boxText}${varText}${stockText}</span>
|
|
|
|
| 2781 |
@app.route('/admhosto', methods=['GET'])
|
| 2782 |
def admhosto():
|
| 2783 |
data = load_data()
|
| 2784 |
+
environments_data =[]
|
| 2785 |
for env_id, env_data in data.items():
|
| 2786 |
settings = env_data.get('settings', {})
|
| 2787 |
org_name = settings.get("organization_name", "Gippo312")
|
|
|
|
| 2805 |
if new_id not in all_data:
|
| 2806 |
break
|
| 2807 |
all_data[new_id] = {
|
| 2808 |
+
'products': [], 'categories': [], 'orders': {}, 'employees': [], 'blocks':[],
|
| 2809 |
'organization_info': {
|
| 2810 |
"about_us": "Мы — Gippo312, ваш надежный партнер в мире уникальных товаров.",
|
| 2811 |
"shipping": "Доставка осуществляется по всему Кыргызстану.",
|
|
|
|
| 2825 |
flash(f'Новая среда с ID {new_id} успешно создана.', 'success')
|
| 2826 |
return redirect(url_for('admhosto'))
|
| 2827 |
|
| 2828 |
+
@app.route('/admhosto/update_mode/<env_id>', methods=['POST'])
|
| 2829 |
+
def update_env_mode(env_id):
|
| 2830 |
+
all_data = load_data()
|
| 2831 |
+
if env_id in all_data:
|
| 2832 |
+
new_mode = request.form.get('env_mode', 'external')
|
| 2833 |
+
all_data[env_id]['settings']['env_mode'] = new_mode
|
| 2834 |
+
save_data(all_data)
|
| 2835 |
+
flash(f'Режим среды {env_id} обновлен.', 'success')
|
| 2836 |
+
else:
|
| 2837 |
+
flash(f'Среда {env_id} не найдена.', 'error')
|
| 2838 |
+
return redirect(url_for('admhosto'))
|
| 2839 |
+
|
| 2840 |
@app.route('/admhosto/update_pwd/<env_id>', methods=['POST'])
|
| 2841 |
def update_env_pwd(env_id):
|
| 2842 |
all_data = load_data()
|
|
|
|
| 2888 |
@app.route('/<env_id>/catalog')
|
| 2889 |
def catalog(env_id):
|
| 2890 |
data = get_env_data(env_id)
|
| 2891 |
+
all_products_raw = data.get('products',[])
|
| 2892 |
settings = data.get('settings', {})
|
| 2893 |
+
blocks = data.get('blocks',[])
|
| 2894 |
product_categories = set(p.get('category', 'Без категории') for p in all_products_raw)
|
| 2895 |
+
admin_categories = set(data.get('categories',[]))
|
| 2896 |
all_cat_names = sorted(list(product_categories.union(admin_categories)))
|
| 2897 |
+
products_in_stock =[p for p in all_products_raw if p.get('in_stock', True)]
|
| 2898 |
products_sorted_for_js = sorted(products_in_stock, key=lambda p: (not p.get('is_top', False), p.get('name', '').lower()))
|
| 2899 |
|
| 2900 |
+
products_by_category = {cat:[] for cat in all_cat_names}
|
| 2901 |
for product in products_in_stock:
|
| 2902 |
products_by_category[product.get('category', 'Без категории')].append(product)
|
| 2903 |
ordered_categories = [cat for cat in all_cat_names if products_by_category.get(cat)]
|
|
|
|
| 2916 |
if settings.get('env_mode') != '2in1':
|
| 2917 |
return "POS доступен только в режиме '2 в 1'", 403
|
| 2918 |
emp_id = request.args.get('emp', '')
|
| 2919 |
+
products = data.get('products',[])
|
| 2920 |
return render_template_string(POS_TEMPLATE, products_json=json.dumps(products), settings=settings, currency_code=settings.get('currency_code', 'KGS'), env_id=env_id, emp_id=emp_id, repo_id=REPO_ID)
|
| 2921 |
|
| 2922 |
@app.route('/<env_id>/reports')
|
|
|
|
| 2945 |
emp_stats[emp]['count'] += 1
|
| 2946 |
emp_stats[emp]['revenue'] += o.get('total_price', 0)
|
| 2947 |
|
| 2948 |
+
for item in o.get('cart',[]):
|
| 2949 |
name = item.get('name', 'Неизвестно')
|
| 2950 |
qty = item.get('quantity', 0)
|
| 2951 |
if name not in product_sales:
|
|
|
|
| 2961 |
emp_stats=emp_stats, top_products=top_products[:20]
|
| 2962 |
)
|
| 2963 |
|
|
|
|
| 2964 |
@app.route('/<env_id>/track_view/<product_id>', methods=['POST'])
|
| 2965 |
def track_view(env_id, product_id):
|
| 2966 |
data = get_env_data(env_id)
|
|
|
|
| 2974 |
@app.route('/<env_id>/product/<int:index>')
|
| 2975 |
def product_detail(env_id, index):
|
| 2976 |
data = get_env_data(env_id)
|
| 2977 |
+
all_products_raw = data.get('products',[])
|
| 2978 |
settings = data.get('settings', {})
|
| 2979 |
+
products_in_stock =[p for p in all_products_raw if p.get('in_stock', True)]
|
| 2980 |
products_sorted = sorted(products_in_stock, key=lambda p: (not p.get('is_top', False), p.get('name', '').lower()))
|
| 2981 |
try:
|
| 2982 |
product = products_sorted[index]
|
|
|
|
| 2995 |
|
| 2996 |
data = get_env_data(env_id)
|
| 2997 |
settings = data.get('settings', {})
|
| 2998 |
+
products = data.get('products',[])
|
| 2999 |
env_mode = settings.get('env_mode', 'external')
|
| 3000 |
|
| 3001 |
cart_items = order_data['cart']
|
|
|
|
| 3006 |
emp_whatsapp = None
|
| 3007 |
|
| 3008 |
if emp_id:
|
| 3009 |
+
employees = data.get('employees',[])
|
| 3010 |
for emp in employees:
|
| 3011 |
if emp.get('id') == emp_id:
|
| 3012 |
emp_name = emp.get('name')
|
|
|
|
| 3014 |
break
|
| 3015 |
|
| 3016 |
total_price = 0
|
| 3017 |
+
processed_cart =[]
|
| 3018 |
|
| 3019 |
for item in cart_items:
|
| 3020 |
if not all(k in item for k in ('name', 'quantity')):
|
|
|
|
| 3037 |
tag_ref = None
|
| 3038 |
if 'TAG_' in c_color:
|
| 3039 |
tag_id = c_color.split('_VAR_')[0].replace('TAG_', '')
|
| 3040 |
+
tag_ref = next((t for t in product_ref.get('tags',[]) if t.get('id') == tag_id), None)
|
| 3041 |
|
| 3042 |
price = float(item.get('price', 0))
|
| 3043 |
discount_applied = False
|
|
|
|
| 3108 |
|
| 3109 |
try:
|
| 3110 |
idx = int(idx)
|
| 3111 |
+
cart = order.get('cart',[])
|
| 3112 |
if idx < 0 or idx >= len(cart):
|
| 3113 |
return jsonify({"error": "Товар не найден."}), 404
|
| 3114 |
|
|
|
|
| 3163 |
|
| 3164 |
orders = list(data.get('orders', {}).values())
|
| 3165 |
orders.sort(key=lambda x: x.get('created_at', ''), reverse=True)
|
| 3166 |
+
employees = data.get('employees',[])
|
| 3167 |
return render_template_string(HISTORY_TEMPLATE, orders=orders, employees=employees, settings=settings, currency_code=settings.get('currency_code', 'KGS'), env_id=env_id)
|
| 3168 |
|
| 3169 |
@app.route('/<env_id>/admin_ai_chat', methods=['POST'])
|
|
|
|
| 3178 |
|
| 3179 |
req = request.get_json()
|
| 3180 |
message = req.get('message')
|
| 3181 |
+
history = req.get('history',[])
|
| 3182 |
|
| 3183 |
orders = data.get('orders', {})
|
| 3184 |
+
products = data.get('products',[])
|
| 3185 |
|
| 3186 |
now = datetime.now(ALMATY_TZ)
|
| 3187 |
current_month = now.strftime('%Y-%m')
|
|
|
|
| 3192 |
for o in orders.values():
|
| 3193 |
if o.get('created_at', '').startswith(current_month):
|
| 3194 |
monthly_revenue += o.get('total_price', 0)
|
| 3195 |
+
for item in o.get('cart',[]):
|
| 3196 |
pid = item.get('product_id')
|
| 3197 |
product_sales_counts[pid] = product_sales_counts.get(pid, 0) + item.get('quantity', 0)
|
| 3198 |
|
|
|
|
| 3201 |
views_str = ", ".join(views_str_list) if views_str_list else "Нет просмотров"
|
| 3202 |
|
| 3203 |
sorted_sales_pids = sorted(product_sales_counts.items(), key=lambda x: x[1], reverse=True)[:5]
|
| 3204 |
+
sales_str_list =[]
|
| 3205 |
for pid, qty in sorted_sales_pids:
|
| 3206 |
p = next((x for x in products if x['product_id'] == pid), None)
|
| 3207 |
if p:
|
|
|
|
| 3215 |
Выручка за этот месяц: {monthly_revenue} {currency}.
|
| 3216 |
Самые просматриваемые товары (Топ-5): {views_str}.
|
| 3217 |
Самые продаваемые товары (Топ-5): {sales_str}.
|
| 3218 |
+
Если упоминаешь товар, используй точный формат:[POST: <product_id> Название: <product_name>].
|
| 3219 |
Помогай владельцу анализировать продажи и отвечать на бизнес-вопросы."""
|
| 3220 |
|
| 3221 |
try:
|
| 3222 |
model = genai.GenerativeModel('gemma-4-26b-a4b-it')
|
| 3223 |
+
messages = [{'role': 'user', 'parts':[{'text': sys_prompt}]}]
|
| 3224 |
for h in history:
|
| 3225 |
messages.append({'role': 'model' if h['role'] == 'ai' else 'user', 'parts': [{'text': h['text']}]})
|
| 3226 |
chat = model.start_chat(history=messages)
|
|
|
|
| 3238 |
return redirect(url_for('admin_login', env_id=env_id))
|
| 3239 |
|
| 3240 |
products = data.get('products', [])
|
| 3241 |
+
categories = data.get('categories',[])
|
| 3242 |
organization_info = data.get('organization_info', {})
|
| 3243 |
+
employees = data.get('employees',[])
|
| 3244 |
+
blocks = data.get('blocks',[])
|
| 3245 |
|
| 3246 |
page = request.args.get('p', 1, type=int)
|
| 3247 |
search_q = request.args.get('q', '').strip()
|
|
|
|
| 3301 |
flash("Сотрудник добавлен.", "success")
|
| 3302 |
elif action == 'delete_employee':
|
| 3303 |
emp_id = request.form.get('emp_id')
|
| 3304 |
+
employees =[e for e in employees if e.get('id') != emp_id]
|
| 3305 |
data['employees'] = employees
|
| 3306 |
save_env_data(env_id, data)
|
| 3307 |
flash("Сотрудник удален.", "success")
|
|
|
|
| 3349 |
settings['organization_name'] = request.form.get('organization_name', 'Gippo312').strip()
|
| 3350 |
settings['whatsapp_number'] = request.form.get('whatsapp_number', '').strip()
|
| 3351 |
settings['currency_code'] = request.form.get('currency_code', 'KGS')
|
|
|
|
| 3352 |
settings['business_type'] = request.form.get('business_type', 'retail')
|
| 3353 |
settings['color_scheme'] = request.form.get('color_scheme', 'default')
|
| 3354 |
|
|
|
|
| 3426 |
uploads_dir = 'uploads_temp'
|
| 3427 |
os.makedirs(uploads_dir, exist_ok=True)
|
| 3428 |
api = HfApi()
|
| 3429 |
+
new_photos_list =[]
|
| 3430 |
photo_limit = 10
|
| 3431 |
uploaded_count = 0
|
| 3432 |
for photo in photos_files:
|
|
|
|
| 3474 |
return redirect(url_for('admin', env_id=env_id, p=page, q=search_q))
|
| 3475 |
deleted_product = products.pop(product_index)
|
| 3476 |
product_name = deleted_product.get('name', 'N/A')
|
| 3477 |
+
photos_to_delete = deleted_product.get('photos',[])
|
| 3478 |
if photos_to_delete and HF_TOKEN_WRITE:
|
| 3479 |
try:
|
| 3480 |
api = HfApi()
|
|
|
|
| 3493 |
filtered_products = products
|
| 3494 |
if search_q:
|
| 3495 |
q_lower = search_q.lower()
|
| 3496 |
+
filtered_products =[p for p in products if q_lower in p.get('name', '').lower() or q_lower in p.get('description', '').lower()]
|
| 3497 |
|
| 3498 |
filtered_products = sorted(filtered_products, key=lambda p: p.get('name', '').lower())
|
| 3499 |
|