Update app.py
Browse files
app.py
CHANGED
|
@@ -6,6 +6,8 @@ import logging
|
|
| 6 |
import threading
|
| 7 |
import time
|
| 8 |
import math
|
|
|
|
|
|
|
| 9 |
from datetime import datetime, timedelta, timezone
|
| 10 |
from uuid import uuid4
|
| 11 |
import random
|
|
@@ -209,7 +211,7 @@ def get_env_data(env_id):
|
|
| 209 |
"admin_password": "",
|
| 210 |
"categories_as_lines": False,
|
| 211 |
"about_text": "Привет! Это моя онлайн-визитка.",
|
| 212 |
-
"
|
| 213 |
"order_messenger": "whatsapp",
|
| 214 |
"order_contact": ""
|
| 215 |
}
|
|
@@ -602,27 +604,19 @@ CATALOG_TEMPLATE = '''
|
|
| 602 |
|
| 603 |
.dark-theme .modal-content, .dark-theme .qr-modal-content { background: #222; }
|
| 604 |
|
| 605 |
-
.
|
| 606 |
-
.
|
| 607 |
-
.cart-
|
| 608 |
-
|
| 609 |
-
.cart-
|
| 610 |
-
.cart-
|
| 611 |
-
.cart-
|
| 612 |
-
.cart-
|
|
|
|
|
|
|
| 613 |
.cart-item-info { flex-grow: 1; }
|
| 614 |
-
.cart-item-
|
| 615 |
-
.cart-item-price { font-size: 0.
|
| 616 |
-
.qty-controls { display: flex; align-items: center; gap: 8px; }
|
| 617 |
-
.qty-controls button, .qty-selector button { width: 30px; height: 30px; border-radius: 6px; border: 1px solid var(--accent); background: transparent; color: var(--accent); cursor: pointer; display: flex; justify-content: center; align-items: center; font-size: 1.2rem; }
|
| 618 |
-
.qty-controls input, .qty-selector input { width: 40px; height: 30px; text-align: center; border-radius: 6px; border: 1px solid rgba(255,255,255,0.2); background: rgba(255,255,255,0.1); color: var(--text-light); -moz-appearance: textfield; font-weight: bold;}
|
| 619 |
-
.qty-controls input::-webkit-outer-spin-button, .qty-controls input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
|
| 620 |
-
.cart-item-total { font-weight: bold; color: var(--accent); width: 80px; text-align: right; }
|
| 621 |
-
.cart-total { font-size: 1.3rem; text-align: right; margin-top: 20px; color: var(--accent); font-weight: bold; }
|
| 622 |
-
.checkout-btn, .add-to-cart-btn { width: 100%; padding: 15px; background: var(--accent); color: var(--text-dark); border: none; border-radius: 12px; font-weight: bold; font-size: 1.1rem; margin-top: 20px; cursor: pointer; transition: 0.2s; }
|
| 623 |
-
.checkout-btn:hover, .add-to-cart-btn:hover { background: var(--accent-hover); }
|
| 624 |
-
.cart-controls { display: flex; flex-direction: column; gap: 15px; margin-top: 20px; background: var(--card-bg); padding: 15px; border-radius: 15px; }
|
| 625 |
-
.qty-selector { display: flex; align-items: center; justify-content: center; gap: 10px; }
|
| 626 |
</style>
|
| 627 |
</head>
|
| 628 |
<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 '' }}">
|
|
@@ -689,11 +683,16 @@ CATALOG_TEMPLATE = '''
|
|
| 689 |
</div>
|
| 690 |
{% endif %}
|
| 691 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 692 |
|
| 693 |
<div id="productModal" class="modal">
|
| 694 |
<div class="modal-content">
|
| 695 |
<button class="close-btn" onclick="closeModal('productModal')"><i class="fas fa-times"></i></button>
|
| 696 |
-
<div id="modalContent">
|
| 697 |
</div>
|
| 698 |
</div>
|
| 699 |
|
|
@@ -718,20 +717,19 @@ CATALOG_TEMPLATE = '''
|
|
| 718 |
</div>
|
| 719 |
|
| 720 |
<div id="cartModal" class="modal">
|
| 721 |
-
<div class="modal-content
|
| 722 |
<button class="close-btn" onclick="closeModal('cartModal')"><i class="fas fa-times"></i></button>
|
| 723 |
-
<h2>Корзина</h2>
|
| 724 |
-
<div id="cartItems"></div>
|
| 725 |
-
<div
|
| 726 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
| 727 |
</div>
|
| 728 |
</div>
|
| 729 |
|
| 730 |
-
<div id="floatingCart" class="floating-cart" onclick="openCart()" style="display:none;">
|
| 731 |
-
<i class="fas fa-shopping-cart"></i>
|
| 732 |
-
<span id="cartCount" class="cart-badge">0</span>
|
| 733 |
-
</div>
|
| 734 |
-
|
| 735 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/10.2.0/swiper-bundle.min.js"></script>
|
| 736 |
<script>
|
| 737 |
const allProducts = {{ products_json|safe }};
|
|
@@ -739,13 +737,21 @@ CATALOG_TEMPLATE = '''
|
|
| 739 |
const repoId = '{{ repo_id }}';
|
| 740 |
const currencyCode = '{{ currency_code }}';
|
| 741 |
const orgName = `{{ settings.organization_name }}`.replace(/`/g, '');
|
| 742 |
-
const
|
| 743 |
-
const
|
| 744 |
|
| 745 |
const itemsPerPage = 10;
|
| 746 |
let currentPage = 1;
|
| 747 |
let currentCategory = 'all';
|
| 748 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 749 |
|
| 750 |
document.addEventListener('DOMContentLoaded', () => {
|
| 751 |
const chipsContainer = document.getElementById('category-chips');
|
|
@@ -767,10 +773,68 @@ CATALOG_TEMPLATE = '''
|
|
| 767 |
|
| 768 |
window.addEventListener('click', function(event) { if (event.target.classList.contains('modal')) { closeModal(event.target.id); } });
|
| 769 |
|
|
|
|
| 770 |
renderCatalog();
|
| 771 |
-
updateCartUI();
|
| 772 |
});
|
| 773 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 774 |
function setCategory(cat, btn) {
|
| 775 |
document.querySelectorAll('.chip').forEach(c => c.classList.remove('active'));
|
| 776 |
if(btn) btn.classList.add('active');
|
|
@@ -787,6 +851,24 @@ CATALOG_TEMPLATE = '''
|
|
| 787 |
: `https://via.placeholder.com/300x300.png?text=Нет+фото`;
|
| 788 |
|
| 789 |
let priceText = product.price > 0 ? `<div class="product-price">${parseFloat(product.price).toFixed(0)} ${currencyCode}</div>` : '';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 790 |
|
| 791 |
return `
|
| 792 |
<div class="product-card" onclick="openModalById('${product.product_id}')">
|
|
@@ -796,6 +878,7 @@ CATALOG_TEMPLATE = '''
|
|
| 796 |
<div class="product-info">
|
| 797 |
<div class="product-title">${product.name}</div>
|
| 798 |
${priceText}
|
|
|
|
| 799 |
</div>
|
| 800 |
</div>
|
| 801 |
`;
|
|
@@ -859,6 +942,30 @@ CATALOG_TEMPLATE = '''
|
|
| 859 |
|
| 860 |
function getProductById(productId) { return allProducts.find(p => p.product_id === productId); }
|
| 861 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 862 |
function openModalById(productId) {
|
| 863 |
const product = getProductById(productId);
|
| 864 |
if (!product) return;
|
|
@@ -892,19 +999,6 @@ CATALOG_TEMPLATE = '''
|
|
| 892 |
let catHtml = product.category && product.category !== 'Без категории' ? `<div class="modal-category">${product.category}</div>` : '';
|
| 893 |
let descHtml = product.description ? `<div class="modal-desc">${product.description.replace(/\\n/g, '<br>')}</div>` : '';
|
| 894 |
|
| 895 |
-
let cartHtml = '';
|
| 896 |
-
if (cartEnabled && product.price > 0) {
|
| 897 |
-
cartHtml = `
|
| 898 |
-
<div class="cart-controls">
|
| 899 |
-
<div class="qty-selector">
|
| 900 |
-
<button onclick="changeQtyInput(-1)">-</button>
|
| 901 |
-
<input type="number" id="modalQty" value="1" min="1" onchange="if(this.value<1) this.value=1">
|
| 902 |
-
<button onclick="changeQtyInput(1)">+</button>
|
| 903 |
-
</div>
|
| 904 |
-
<button class="add-to-cart-btn" onclick="addToCart('${product.product_id}')">Добавить в корзину</button>
|
| 905 |
-
</div>`;
|
| 906 |
-
}
|
| 907 |
-
|
| 908 |
modalContent.innerHTML = `
|
| 909 |
<div class="swiper-container">
|
| 910 |
<div class="swiper-wrapper">
|
|
@@ -915,9 +1009,11 @@ CATALOG_TEMPLATE = '''
|
|
| 915 |
<div class="modal-body">
|
| 916 |
${catHtml}
|
| 917 |
<h2 class="modal-title">${product.name}</h2>
|
| 918 |
-
|
|
|
|
|
|
|
|
|
|
| 919 |
${descHtml}
|
| 920 |
-
${cartHtml}
|
| 921 |
</div>
|
| 922 |
`;
|
| 923 |
|
|
@@ -925,147 +1021,104 @@ CATALOG_TEMPLATE = '''
|
|
| 925 |
modal.style.display = "block";
|
| 926 |
document.body.style.overflow = 'hidden';
|
| 927 |
|
| 928 |
-
|
| 929 |
-
if(product.photos && product.photos.length > 1) {
|
| 930 |
-
swiperOptions.pagination = { el: '.swiper-pagination', clickable: true };
|
| 931 |
-
}
|
| 932 |
-
new Swiper('#productModal .swiper-container', swiperOptions);
|
| 933 |
-
}
|
| 934 |
-
|
| 935 |
-
function changeQtyInput(delta) {
|
| 936 |
-
let input = document.getElementById('modalQty');
|
| 937 |
-
let val = parseInt(input.value) || 1;
|
| 938 |
-
val += delta;
|
| 939 |
-
if(val < 1) val = 1;
|
| 940 |
-
input.value = val;
|
| 941 |
-
}
|
| 942 |
|
| 943 |
-
|
| 944 |
-
|
| 945 |
-
|
| 946 |
-
|
| 947 |
-
|
| 948 |
-
existing.qty += qty;
|
| 949 |
-
} else {
|
| 950 |
-
cart.push({
|
| 951 |
-
product_id: product.product_id,
|
| 952 |
-
name: product.name,
|
| 953 |
-
price: product.price,
|
| 954 |
-
photo: (product.photos && product.photos.length > 0) ? product.photos[0] : null,
|
| 955 |
-
qty: qty
|
| 956 |
-
});
|
| 957 |
-
}
|
| 958 |
-
updateCartUI();
|
| 959 |
-
closeModal('productModal');
|
| 960 |
}
|
| 961 |
|
| 962 |
-
function
|
| 963 |
-
|
| 964 |
-
|
| 965 |
-
|
| 966 |
-
|
| 967 |
-
|
| 968 |
-
|
| 969 |
-
}
|
| 970 |
-
if(item.qty <= 0) {
|
| 971 |
-
cart = cart.filter(i => i.product_id !== productId);
|
| 972 |
-
}
|
| 973 |
-
}
|
| 974 |
-
updateCartUI();
|
| 975 |
-
renderCartModal();
|
| 976 |
}
|
| 977 |
|
| 978 |
-
function
|
| 979 |
-
|
| 980 |
-
const
|
| 981 |
-
|
| 982 |
-
|
| 983 |
-
cartBtn.style.display = 'flex';
|
| 984 |
-
cartBadge.innerText = totalCount;
|
| 985 |
-
} else {
|
| 986 |
-
cartBtn.style.display = 'none';
|
| 987 |
-
}
|
| 988 |
}
|
| 989 |
|
| 990 |
-
function
|
| 991 |
renderCartModal();
|
| 992 |
-
document.getElementById('cartModal')
|
|
|
|
| 993 |
document.body.style.overflow = 'hidden';
|
| 994 |
}
|
| 995 |
|
| 996 |
function renderCartModal() {
|
| 997 |
const container = document.getElementById('cartItems');
|
| 998 |
-
const
|
| 999 |
-
|
| 1000 |
-
container.innerHTML = '<p style="text-align:center; margin-top:20px; font-size:1.1rem; opacity:0.8;">Корзина пуста</p>';
|
| 1001 |
-
totalEl.innerHTML = '';
|
| 1002 |
-
document.querySelector('.checkout-btn').style.display = 'none';
|
| 1003 |
-
return;
|
| 1004 |
-
}
|
| 1005 |
-
|
| 1006 |
-
let html = '<div class="cart-list">';
|
| 1007 |
let total = 0;
|
| 1008 |
-
|
| 1009 |
-
let
|
| 1010 |
-
|
| 1011 |
-
|
| 1012 |
html += `
|
| 1013 |
-
|
| 1014 |
-
|
| 1015 |
-
|
| 1016 |
-
|
| 1017 |
-
|
| 1018 |
-
|
| 1019 |
-
|
| 1020 |
-
|
| 1021 |
-
|
| 1022 |
-
|
|
|
|
| 1023 |
</div>
|
| 1024 |
-
|
| 1025 |
-
|
| 1026 |
-
|
| 1027 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1028 |
container.innerHTML = html;
|
| 1029 |
-
totalEl.innerHTML = `Итого: ${parseFloat(total).toFixed(2)} ${currencyCode}`;
|
| 1030 |
-
document.querySelector('.checkout-btn').style.display = 'block';
|
| 1031 |
}
|
| 1032 |
|
| 1033 |
-
async function
|
| 1034 |
-
if(cart.length === 0) return;
|
| 1035 |
-
const
|
| 1036 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1037 |
btn.disabled = true;
|
|
|
|
| 1038 |
try {
|
| 1039 |
-
const res = await fetch(`/${
|
| 1040 |
method: 'POST',
|
| 1041 |
headers: {'Content-Type': 'application/json'},
|
| 1042 |
-
body: JSON.stringify(
|
| 1043 |
});
|
| 1044 |
const data = await res.json();
|
| 1045 |
-
if(data.
|
| 1046 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1047 |
}
|
| 1048 |
} catch(e) {
|
| 1049 |
-
alert(
|
|
|
|
|
|
|
|
|
|
| 1050 |
}
|
| 1051 |
-
btn.innerText = 'Оформить заказ';
|
| 1052 |
-
btn.disabled = false;
|
| 1053 |
-
}
|
| 1054 |
-
|
| 1055 |
-
function openQrModal() {
|
| 1056 |
-
const currentDomain = window.location.origin;
|
| 1057 |
-
const targetUrl = currentDomain + "{{ url_for('catalog', env_id=env_id) }}";
|
| 1058 |
-
const qrApiUrl = `https://api.qrserver.com/v1/create-qr-code/?size=500x500&data=${encodeURIComponent(targetUrl)}&margin=10`;
|
| 1059 |
-
document.getElementById('qrImage').src = qrApiUrl;
|
| 1060 |
-
document.getElementById('qrModal').style.display = 'block';
|
| 1061 |
-
document.body.style.overflow = 'hidden';
|
| 1062 |
-
}
|
| 1063 |
-
|
| 1064 |
-
function openPdfModal(url) {
|
| 1065 |
-
document.getElementById('pdfIframe').src = url;
|
| 1066 |
-
const modal = document.getElementById('pdfModal');
|
| 1067 |
-
modal.style.display = 'block';
|
| 1068 |
-
document.body.style.overflow = 'hidden';
|
| 1069 |
}
|
| 1070 |
|
| 1071 |
function closeModal(modalId) {
|
|
@@ -1083,86 +1136,6 @@ CATALOG_TEMPLATE = '''
|
|
| 1083 |
</html>
|
| 1084 |
'''
|
| 1085 |
|
| 1086 |
-
INVOICE_TEMPLATE = '''
|
| 1087 |
-
<!DOCTYPE html>
|
| 1088 |
-
<html lang="ru">
|
| 1089 |
-
<head>
|
| 1090 |
-
<meta charset="UTF-8">
|
| 1091 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 1092 |
-
<title>Накладная #{{ order.id }}</title>
|
| 1093 |
-
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700;800&display=swap" rel="stylesheet">
|
| 1094 |
-
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
|
| 1095 |
-
<style>
|
| 1096 |
-
:root { --bg: #f4f6f9; --primary: #135D66; --accent: #48D1CC; }
|
| 1097 |
-
body { font-family: 'Montserrat', sans-serif; background: var(--bg); color: #333; margin:0; padding:20px; display:flex; justify-content:center; align-items: flex-start; min-height: 100vh;}
|
| 1098 |
-
.invoice-card { background: #fff; padding: 30px; border-radius: 15px; box-shadow: 0 4px 20px rgba(0,0,0,0.05); width: 100%; max-width: 600px; margin-top: 20px; }
|
| 1099 |
-
.header { text-align: center; border-bottom: 2px dashed #ddd; padding-bottom: 20px; margin-bottom: 20px; }
|
| 1100 |
-
.header h1 { margin:0; color: var(--primary); font-size: 1.8rem; }
|
| 1101 |
-
.header p { color: #777; margin-top:5px; font-size: 0.95rem; }
|
| 1102 |
-
.item { display: flex; align-items: center; border-bottom: 1px solid #eee; padding: 15px 0; gap: 15px;}
|
| 1103 |
-
.item img { width: 70px; height: 70px; object-fit: cover; border-radius: 10px; }
|
| 1104 |
-
.item-info { flex-grow: 1; }
|
| 1105 |
-
.item-name { font-weight: 600; font-size: 1.1rem; }
|
| 1106 |
-
.item-qty { color: #666; font-size: 0.9rem; margin-top: 5px; }
|
| 1107 |
-
.item-total { font-weight: 700; font-size: 1.1rem; color: var(--primary); }
|
| 1108 |
-
.total-section { text-align: right; margin-top: 20px; font-size: 1.4rem; font-weight: 800; color: var(--primary); }
|
| 1109 |
-
.send-btn { display: block; width: 100%; text-align: center; background: #25D366; color: white; padding: 15px; border-radius: 10px; text-decoration: none; font-weight: bold; font-size: 1.1rem; margin-top: 30px; cursor:pointer; border: none; transition: transform 0.2s, background 0.3s;}
|
| 1110 |
-
.send-btn.telegram { background: #0088cc; }
|
| 1111 |
-
.send-btn:hover { transform: translateY(-2px); }
|
| 1112 |
-
.back-link { display: block; text-align: center; margin-top: 20px; color: #666; text-decoration: none; font-weight: 500; }
|
| 1113 |
-
.back-link:hover { color: var(--primary); }
|
| 1114 |
-
</style>
|
| 1115 |
-
</head>
|
| 1116 |
-
<body>
|
| 1117 |
-
<div class="invoice-card">
|
| 1118 |
-
<div class="header">
|
| 1119 |
-
<h1>Накладная #{{ order.id }}</h1>
|
| 1120 |
-
<p>Дата заказа: {{ order.date }}</p>
|
| 1121 |
-
</div>
|
| 1122 |
-
<div class="items">
|
| 1123 |
-
{% for item in order.items %}
|
| 1124 |
-
<div class="item">
|
| 1125 |
-
{% if item.photo %}
|
| 1126 |
-
<img src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/photos/{{ item.photo }}" alt="{{ item.name }}">
|
| 1127 |
-
{% else %}
|
| 1128 |
-
<img src="https://via.placeholder.com/70x70.png?text=��ет+фото" alt="No image">
|
| 1129 |
-
{% endif %}
|
| 1130 |
-
<div class="item-info">
|
| 1131 |
-
<div class="item-name">{{ item.name }}</div>
|
| 1132 |
-
<div class="item-qty">{{ "%.2f"|format(item.price) }} {{ currency }} x {{ item.qty }} шт.</div>
|
| 1133 |
-
</div>
|
| 1134 |
-
<div class="item-total">{{ "%.2f"|format(item.price * item.qty) }} {{ currency }}</div>
|
| 1135 |
-
</div>
|
| 1136 |
-
{% endfor %}
|
| 1137 |
-
</div>
|
| 1138 |
-
<div class="total-section">
|
| 1139 |
-
Итого: {{ "%.2f"|format(order.total) }} {{ currency }}
|
| 1140 |
-
</div>
|
| 1141 |
-
<button class="send-btn {{ settings.order_messenger }}" onclick="sendToMessenger()">
|
| 1142 |
-
<i class="fab fa-{{ settings.order_messenger }}"></i> Отправить продавцу ({{ 'WhatsApp' if settings.order_messenger == 'whatsapp' else 'Telegram' }})
|
| 1143 |
-
</button>
|
| 1144 |
-
<a href="{{ url_for('catalog', env_id=env_id) }}" class="back-link"><i class="fas fa-arrow-left"></i> Вернуться в каталог</a>
|
| 1145 |
-
</div>
|
| 1146 |
-
|
| 1147 |
-
<script>
|
| 1148 |
-
function sendToMessenger() {
|
| 1149 |
-
const text = encodeURIComponent('Здравствуйте! Направляю накладную по новому заказу #{{ order.id }}.\\nПосмотреть детали:\\n' + window.location.href);
|
| 1150 |
-
const messenger = '{{ settings.order_messenger }}';
|
| 1151 |
-
const contact = '{{ settings.order_contact }}';
|
| 1152 |
-
let link = '';
|
| 1153 |
-
if (messenger === 'whatsapp') {
|
| 1154 |
-
link = `https://wa.me/${contact}?text=${text}`;
|
| 1155 |
-
} else if (messenger === 'telegram') {
|
| 1156 |
-
link = `https://t.me/${contact}?text=${text}`;
|
| 1157 |
-
}
|
| 1158 |
-
if(link && contact) window.open(link, '_blank');
|
| 1159 |
-
else alert('Контакт продавца не указан в настройках.');
|
| 1160 |
-
}
|
| 1161 |
-
</script>
|
| 1162 |
-
</body>
|
| 1163 |
-
</html>
|
| 1164 |
-
'''
|
| 1165 |
-
|
| 1166 |
ADMIN_TEMPLATE = '''
|
| 1167 |
<!DOCTYPE html>
|
| 1168 |
<html lang="ru">
|
|
@@ -1328,19 +1301,19 @@ ADMIN_TEMPLATE = '''
|
|
| 1328 |
{% endfor %}
|
| 1329 |
</select>
|
| 1330 |
|
| 1331 |
-
<
|
| 1332 |
-
|
| 1333 |
-
<
|
| 1334 |
-
|
| 1335 |
-
|
| 1336 |
-
|
| 1337 |
-
|
| 1338 |
-
|
| 1339 |
-
</
|
| 1340 |
-
|
| 1341 |
-
|
| 1342 |
-
|
| 1343 |
-
<
|
| 1344 |
|
| 1345 |
<div style="background: #f1f3f5; padding: 20px; border-radius: 12px; margin-top: 25px;">
|
| 1346 |
<h4 style="margin-top: 0; color: var(--bg-medium); font-size: 1.1rem;"><i class="fas fa-lock"></i> Пароль для входа сюда</h4>
|
|
@@ -1747,6 +1720,82 @@ ADMIN_TEMPLATE = '''
|
|
| 1747 |
</html>
|
| 1748 |
'''
|
| 1749 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1750 |
@app.route('/')
|
| 1751 |
def index():
|
| 1752 |
return render_template_string(LANDING_PAGE_TEMPLATE)
|
|
@@ -1788,7 +1837,7 @@ def create_environment():
|
|
| 1788 |
"admin_password": "",
|
| 1789 |
"categories_as_lines": False,
|
| 1790 |
"about_text": "Привет! Это моя онлайн-визитка.",
|
| 1791 |
-
"
|
| 1792 |
"order_messenger": "whatsapp",
|
| 1793 |
"order_contact": ""
|
| 1794 |
}
|
|
@@ -1918,36 +1967,71 @@ def catalog(env_id):
|
|
| 1918 |
|
| 1919 |
@app.route('/<env_id>/checkout', methods=['POST'])
|
| 1920 |
def checkout(env_id):
|
| 1921 |
-
|
| 1922 |
-
|
| 1923 |
-
cart_items = req.get('cart', [])
|
| 1924 |
|
| 1925 |
-
|
| 1926 |
-
|
|
|
|
|
|
|
|
|
|
| 1927 |
|
| 1928 |
order = {
|
| 1929 |
-
|
| 1930 |
-
|
| 1931 |
-
'
|
| 1932 |
-
'
|
|
|
|
|
|
|
| 1933 |
}
|
| 1934 |
|
| 1935 |
-
if 'orders' not in
|
| 1936 |
-
|
| 1937 |
-
|
| 1938 |
-
save_env_data(env_id,
|
| 1939 |
|
| 1940 |
-
return jsonify({'
|
| 1941 |
|
| 1942 |
-
@app.route('/<env_id>/
|
| 1943 |
-
def
|
| 1944 |
-
|
| 1945 |
-
|
|
|
|
|
|
|
|
|
|
| 1946 |
if not order:
|
| 1947 |
return "Заказ не найден", 404
|
|
|
|
|
|
|
| 1948 |
|
| 1949 |
-
|
| 1950 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1951 |
|
| 1952 |
@app.route('/<env_id>/admin', methods=['GET', 'POST'])
|
| 1953 |
def admin(env_id):
|
|
@@ -2139,10 +2223,10 @@ def admin(env_id):
|
|
| 2139 |
|
| 2140 |
settings['currency_code'] = request.form.get('currency_code', 'KGS')
|
| 2141 |
settings['color_scheme'] = request.form.get('color_scheme', 'default')
|
| 2142 |
-
|
| 2143 |
-
settings['
|
| 2144 |
settings['order_messenger'] = request.form.get('order_messenger', 'whatsapp')
|
| 2145 |
-
settings['order_contact'] = request.form.get('order_contact', '').strip()
|
| 2146 |
|
| 2147 |
avatar_file = request.files.get('chat_avatar')
|
| 2148 |
if avatar_file and avatar_file.filename:
|
|
|
|
| 6 |
import threading
|
| 7 |
import time
|
| 8 |
import math
|
| 9 |
+
import re
|
| 10 |
+
import urllib.parse
|
| 11 |
from datetime import datetime, timedelta, timezone
|
| 12 |
from uuid import uuid4
|
| 13 |
import random
|
|
|
|
| 211 |
"admin_password": "",
|
| 212 |
"categories_as_lines": False,
|
| 213 |
"about_text": "Привет! Это моя онлайн-визитка.",
|
| 214 |
+
"enable_cart": False,
|
| 215 |
"order_messenger": "whatsapp",
|
| 216 |
"order_contact": ""
|
| 217 |
}
|
|
|
|
| 604 |
|
| 605 |
.dark-theme .modal-content, .dark-theme .qr-modal-content { background: #222; }
|
| 606 |
|
| 607 |
+
.cart-fab { position: fixed; bottom: 20px; right: 20px; background: var(--accent); color: var(--text-dark); width: 60px; height: 60px; border-radius: 50%; display: flex; justify-content: center; align-items: center; font-size: 1.5rem; cursor: pointer; box-shadow: 0 4px 15px rgba(0,0,0,0.3); z-index: 999; display: none; }
|
| 608 |
+
.cart-badge { position: absolute; top: -5px; right: -5px; background: var(--danger); color: white; border-radius: 50%; width: 24px; height: 24px; font-size: 0.8rem; display: flex; justify-content: center; align-items: center; font-weight: bold; }
|
| 609 |
+
.cart-controls { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; background: var(--bg-medium); border-radius: 8px; overflow: hidden; height: 36px;}
|
| 610 |
+
.cart-controls button { background: var(--accent); color: var(--text-dark); border: none; width: 36px; height: 100%; font-weight: bold; cursor: pointer; font-size: 1.2rem; }
|
| 611 |
+
.cart-controls input { width: 40px; text-align: center; border: none; background: transparent; color: white; font-weight: bold; font-size: 1rem; outline: none; -moz-appearance: textfield; }
|
| 612 |
+
.cart-controls input::-webkit-outer-spin-button, .cart-controls input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
|
| 613 |
+
.add-to-cart-btn { background: var(--accent); color: var(--text-dark); border: none; padding: 10px; border-radius: 8px; font-weight: bold; cursor: pointer; width: 100%; margin-top: 10px; font-size: 1rem; }
|
| 614 |
+
.add-to-cart-btn:hover { background: var(--accent-hover); }
|
| 615 |
+
.cart-item { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid rgba(255,255,255,0.1); gap: 10px;}
|
| 616 |
+
.cart-item img { width: 50px; height: 50px; border-radius: 8px; object-fit: cover; }
|
| 617 |
.cart-item-info { flex-grow: 1; }
|
| 618 |
+
.cart-item-title { font-size: 0.9rem; font-weight: bold; }
|
| 619 |
+
.cart-item-price { font-size: 0.85rem; color: var(--accent); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 620 |
</style>
|
| 621 |
</head>
|
| 622 |
<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 '' }}">
|
|
|
|
| 683 |
</div>
|
| 684 |
{% endif %}
|
| 685 |
</div>
|
| 686 |
+
|
| 687 |
+
<div id="cart-fab" class="cart-fab" onclick="openCartModal()">
|
| 688 |
+
<i class="fas fa-shopping-cart"></i>
|
| 689 |
+
<span id="cart-badge" class="cart-badge">0</span>
|
| 690 |
+
</div>
|
| 691 |
|
| 692 |
<div id="productModal" class="modal">
|
| 693 |
<div class="modal-content">
|
| 694 |
<button class="close-btn" onclick="closeModal('productModal')"><i class="fas fa-times"></i></button>
|
| 695 |
+
<div id="modalContent"></div>
|
| 696 |
</div>
|
| 697 |
</div>
|
| 698 |
|
|
|
|
| 717 |
</div>
|
| 718 |
|
| 719 |
<div id="cartModal" class="modal">
|
| 720 |
+
<div class="modal-content" style="padding: 20px; display: flex; flex-direction: column; min-height: 100vh;">
|
| 721 |
<button class="close-btn" onclick="closeModal('cartModal')"><i class="fas fa-times"></i></button>
|
| 722 |
+
<h2 style="margin-top: 40px; margin-bottom: 20px; color: var(--accent); text-align: center;">Корзина</h2>
|
| 723 |
+
<div id="cartItems" style="flex-grow: 1;"></div>
|
| 724 |
+
<div id="cartTotal" style="font-size: 1.3rem; font-weight: bold; margin-top: 15px; text-align: right; color: var(--accent);"></div>
|
| 725 |
+
<div style="margin-top: 20px; background: var(--card-bg); padding: 15px; border-radius: 12px; border: 1px solid rgba(255,255,255,0.1);">
|
| 726 |
+
<input type="text" id="customerName" placeholder="Ваше Имя" required style="width: 100%; padding: 12px; margin-bottom: 10px; border-radius: 8px; border: none; outline: none;">
|
| 727 |
+
<input type="tel" id="customerPhone" placeholder="Ваш Телефон" required style="width: 100%; padding: 12px; margin-bottom: 10px; border-radius: 8px; border: none; outline: none;">
|
| 728 |
+
<button onclick="submitOrder()" class="save-contact-btn" style="width: 100%; margin-bottom: 0;">Оформить заказ</button>
|
| 729 |
+
</div>
|
| 730 |
</div>
|
| 731 |
</div>
|
| 732 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 733 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/10.2.0/swiper-bundle.min.js"></script>
|
| 734 |
<script>
|
| 735 |
const allProducts = {{ products_json|safe }};
|
|
|
|
| 737 |
const repoId = '{{ repo_id }}';
|
| 738 |
const currencyCode = '{{ currency_code }}';
|
| 739 |
const orgName = `{{ settings.organization_name }}`.replace(/`/g, '');
|
| 740 |
+
const enableCart = {{ 'true' if settings.enable_cart else 'false' }};
|
| 741 |
+
const envId = '{{ env_id }}';
|
| 742 |
|
| 743 |
const itemsPerPage = 10;
|
| 744 |
let currentPage = 1;
|
| 745 |
let currentCategory = 'all';
|
| 746 |
+
|
| 747 |
+
let cart = {};
|
| 748 |
+
try {
|
| 749 |
+
let saved = localStorage.getItem('cart_' + envId);
|
| 750 |
+
if (saved) {
|
| 751 |
+
cart = JSON.parse(saved);
|
| 752 |
+
if (Array.isArray(cart)) cart = {};
|
| 753 |
+
}
|
| 754 |
+
} catch(e) { cart = {}; }
|
| 755 |
|
| 756 |
document.addEventListener('DOMContentLoaded', () => {
|
| 757 |
const chipsContainer = document.getElementById('category-chips');
|
|
|
|
| 773 |
|
| 774 |
window.addEventListener('click', function(event) { if (event.target.classList.contains('modal')) { closeModal(event.target.id); } });
|
| 775 |
|
| 776 |
+
updateCartBadge();
|
| 777 |
renderCatalog();
|
|
|
|
| 778 |
});
|
| 779 |
|
| 780 |
+
function saveCart() {
|
| 781 |
+
localStorage.setItem('cart_' + envId, JSON.stringify(cart));
|
| 782 |
+
}
|
| 783 |
+
|
| 784 |
+
function updateCartBadge() {
|
| 785 |
+
if(!enableCart) return;
|
| 786 |
+
const badge = document.getElementById('cart-badge');
|
| 787 |
+
const fab = document.getElementById('cart-fab');
|
| 788 |
+
let totalItems = 0;
|
| 789 |
+
for(let id in cart) { totalItems += cart[id].qty; }
|
| 790 |
+
badge.innerText = totalItems;
|
| 791 |
+
if(totalItems > 0) {
|
| 792 |
+
fab.style.display = 'flex';
|
| 793 |
+
} else {
|
| 794 |
+
fab.style.display = 'none';
|
| 795 |
+
closeModal('cartModal');
|
| 796 |
+
}
|
| 797 |
+
}
|
| 798 |
+
|
| 799 |
+
function addToCart(productId) {
|
| 800 |
+
if(!cart[productId]) {
|
| 801 |
+
let p = getProductById(productId);
|
| 802 |
+
cart[productId] = {qty: 1, price: parseFloat(p.price)||0, name: p.name, photo: p.photos && p.photos.length > 0 ? p.photos[0] : null};
|
| 803 |
+
} else {
|
| 804 |
+
cart[productId].qty += 1;
|
| 805 |
+
}
|
| 806 |
+
saveCart();
|
| 807 |
+
updateCartBadge();
|
| 808 |
+
renderCatalog();
|
| 809 |
+
renderModalCartControls(productId);
|
| 810 |
+
}
|
| 811 |
+
|
| 812 |
+
function updateQty(productId, delta) {
|
| 813 |
+
if(cart[productId]) {
|
| 814 |
+
cart[productId].qty += delta;
|
| 815 |
+
if(cart[productId].qty <= 0) delete cart[productId];
|
| 816 |
+
saveCart();
|
| 817 |
+
updateCartBadge();
|
| 818 |
+
renderCatalog();
|
| 819 |
+
renderCartModal();
|
| 820 |
+
renderModalCartControls(productId);
|
| 821 |
+
}
|
| 822 |
+
}
|
| 823 |
+
|
| 824 |
+
function setQty(productId, inputElem) {
|
| 825 |
+
let val = parseInt(inputElem.value);
|
| 826 |
+
if(isNaN(val) || val <= 0) {
|
| 827 |
+
delete cart[productId];
|
| 828 |
+
} else {
|
| 829 |
+
cart[productId].qty = val;
|
| 830 |
+
}
|
| 831 |
+
saveCart();
|
| 832 |
+
updateCartBadge();
|
| 833 |
+
renderCatalog();
|
| 834 |
+
renderCartModal();
|
| 835 |
+
renderModalCartControls(productId);
|
| 836 |
+
}
|
| 837 |
+
|
| 838 |
function setCategory(cat, btn) {
|
| 839 |
document.querySelectorAll('.chip').forEach(c => c.classList.remove('active'));
|
| 840 |
if(btn) btn.classList.add('active');
|
|
|
|
| 851 |
: `https://via.placeholder.com/300x300.png?text=Нет+фото`;
|
| 852 |
|
| 853 |
let priceText = product.price > 0 ? `<div class="product-price">${parseFloat(product.price).toFixed(0)} ${currencyCode}</div>` : '';
|
| 854 |
+
|
| 855 |
+
let cartControlsHtml = '';
|
| 856 |
+
if(enableCart && product.price > 0) {
|
| 857 |
+
if(cart[product.product_id]) {
|
| 858 |
+
let qty = cart[product.product_id].qty;
|
| 859 |
+
cartControlsHtml = `
|
| 860 |
+
<div class="cart-controls" onclick="event.stopPropagation()">
|
| 861 |
+
<button onclick="updateQty('${product.product_id}', -1)">-</button>
|
| 862 |
+
<input type="number" value="${qty}" onchange="setQty('${product.product_id}', this)">
|
| 863 |
+
<button onclick="updateQty('${product.product_id}', 1)">+</button>
|
| 864 |
+
</div>
|
| 865 |
+
`;
|
| 866 |
+
} else {
|
| 867 |
+
cartControlsHtml = `
|
| 868 |
+
<button class="add-to-cart-btn" onclick="event.stopPropagation(); addToCart('${product.product_id}')">В корзину</button>
|
| 869 |
+
`;
|
| 870 |
+
}
|
| 871 |
+
}
|
| 872 |
|
| 873 |
return `
|
| 874 |
<div class="product-card" onclick="openModalById('${product.product_id}')">
|
|
|
|
| 878 |
<div class="product-info">
|
| 879 |
<div class="product-title">${product.name}</div>
|
| 880 |
${priceText}
|
| 881 |
+
${cartControlsHtml}
|
| 882 |
</div>
|
| 883 |
</div>
|
| 884 |
`;
|
|
|
|
| 942 |
|
| 943 |
function getProductById(productId) { return allProducts.find(p => p.product_id === productId); }
|
| 944 |
|
| 945 |
+
function renderModalCartControls(productId) {
|
| 946 |
+
const container = document.getElementById('modal-cart-controls-container');
|
| 947 |
+
if(!container) return;
|
| 948 |
+
const product = getProductById(productId);
|
| 949 |
+
if(!product || !enableCart || product.price <= 0) {
|
| 950 |
+
container.innerHTML = '';
|
| 951 |
+
return;
|
| 952 |
+
}
|
| 953 |
+
let html = '';
|
| 954 |
+
if(cart[productId]) {
|
| 955 |
+
let qty = cart[productId].qty;
|
| 956 |
+
html = `
|
| 957 |
+
<div class="cart-controls" style="max-width: 150px;">
|
| 958 |
+
<button onclick="updateQty('${productId}', -1)">-</button>
|
| 959 |
+
<input type="number" value="${qty}" onchange="setQty('${productId}', this)">
|
| 960 |
+
<button onclick="updateQty('${productId}', 1)">+</button>
|
| 961 |
+
</div>
|
| 962 |
+
`;
|
| 963 |
+
} else {
|
| 964 |
+
html = `<button class="add-to-cart-btn" style="max-width: 150px; margin-top: 0;" onclick="addToCart('${productId}')">В корзину</button>`;
|
| 965 |
+
}
|
| 966 |
+
container.innerHTML = html;
|
| 967 |
+
}
|
| 968 |
+
|
| 969 |
function openModalById(productId) {
|
| 970 |
const product = getProductById(productId);
|
| 971 |
if (!product) return;
|
|
|
|
| 999 |
let catHtml = product.category && product.category !== 'Без категории' ? `<div class="modal-category">${product.category}</div>` : '';
|
| 1000 |
let descHtml = product.description ? `<div class="modal-desc">${product.description.replace(/\\n/g, '<br>')}</div>` : '';
|
| 1001 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1002 |
modalContent.innerHTML = `
|
| 1003 |
<div class="swiper-container">
|
| 1004 |
<div class="swiper-wrapper">
|
|
|
|
| 1009 |
<div class="modal-body">
|
| 1010 |
${catHtml}
|
| 1011 |
<h2 class="modal-title">${product.name}</h2>
|
| 1012 |
+
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
|
| 1013 |
+
${priceHtml}
|
| 1014 |
+
<div id="modal-cart-controls-container"></div>
|
| 1015 |
+
</div>
|
| 1016 |
${descHtml}
|
|
|
|
| 1017 |
</div>
|
| 1018 |
`;
|
| 1019 |
|
|
|
|
| 1021 |
modal.style.display = "block";
|
| 1022 |
document.body.style.overflow = 'hidden';
|
| 1023 |
|
| 1024 |
+
renderModalCartControls(productId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1025 |
|
| 1026 |
+
new Swiper('#productModal .swiper-container', {
|
| 1027 |
+
zoom: true,
|
| 1028 |
+
slidesPerView: 1,
|
| 1029 |
+
pagination: { el: '.swiper-pagination', clickable: true }
|
| 1030 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1031 |
}
|
| 1032 |
|
| 1033 |
+
function openQrModal() {
|
| 1034 |
+
const currentDomain = window.location.origin;
|
| 1035 |
+
const targetUrl = currentDomain + "{{ url_for('catalog', env_id=env_id) }}";
|
| 1036 |
+
const qrApiUrl = `https://api.qrserver.com/v1/create-qr-code/?size=500x500&data=${encodeURIComponent(targetUrl)}&margin=10`;
|
| 1037 |
+
document.getElementById('qrImage').src = qrApiUrl;
|
| 1038 |
+
document.getElementById('qrModal').style.display = 'block';
|
| 1039 |
+
document.body.style.overflow = 'hidden';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1040 |
}
|
| 1041 |
|
| 1042 |
+
function openPdfModal(url) {
|
| 1043 |
+
document.getElementById('pdfIframe').src = url;
|
| 1044 |
+
const modal = document.getElementById('pdfModal');
|
| 1045 |
+
modal.style.display = 'block';
|
| 1046 |
+
document.body.style.overflow = 'hidden';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1047 |
}
|
| 1048 |
|
| 1049 |
+
function openCartModal() {
|
| 1050 |
renderCartModal();
|
| 1051 |
+
const modal = document.getElementById('cartModal');
|
| 1052 |
+
modal.style.display = 'block';
|
| 1053 |
document.body.style.overflow = 'hidden';
|
| 1054 |
}
|
| 1055 |
|
| 1056 |
function renderCartModal() {
|
| 1057 |
const container = document.getElementById('cartItems');
|
| 1058 |
+
const totalContainer = document.getElementById('cartTotal');
|
| 1059 |
+
let html = '';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1060 |
let total = 0;
|
| 1061 |
+
for(let id in cart) {
|
| 1062 |
+
let item = cart[id];
|
| 1063 |
+
total += item.qty * item.price;
|
| 1064 |
+
let photoUrl = item.photo ? `https://huggingface.co/datasets/${repoId}/resolve/main/photos/${item.photo}` : `https://via.placeholder.com/50x50.png?text=Фото`;
|
| 1065 |
html += `
|
| 1066 |
+
<div class="cart-item">
|
| 1067 |
+
<img src="${photoUrl}" alt="${item.name}">
|
| 1068 |
+
<div class="cart-item-info">
|
| 1069 |
+
<div class="cart-item-title">${item.name}</div>
|
| 1070 |
+
<div class="cart-item-price">${item.price.toFixed(0)} ${currencyCode}</div>
|
| 1071 |
+
</div>
|
| 1072 |
+
<div class="cart-controls" style="margin-top:0;">
|
| 1073 |
+
<button onclick="updateQty('${id}', -1)">-</button>
|
| 1074 |
+
<input type="number" value="${item.qty}" onchange="setQty('${id}', this)">
|
| 1075 |
+
<button onclick="updateQty('${id}', 1)">+</button>
|
| 1076 |
+
</div>
|
| 1077 |
</div>
|
| 1078 |
+
`;
|
| 1079 |
+
}
|
| 1080 |
+
if(html === '') {
|
| 1081 |
+
html = '<p style="text-align:center; opacity:0.7;">Корзина пуста</p>';
|
| 1082 |
+
totalContainer.innerHTML = '';
|
| 1083 |
+
} else {
|
| 1084 |
+
totalContainer.innerHTML = `Итого: ${total.toFixed(0)} ${currencyCode}`;
|
| 1085 |
+
}
|
| 1086 |
container.innerHTML = html;
|
|
|
|
|
|
|
| 1087 |
}
|
| 1088 |
|
| 1089 |
+
async function submitOrder() {
|
| 1090 |
+
if(Object.keys(cart).length === 0) return alert("Корзина пуста");
|
| 1091 |
+
const cName = document.getElementById('customerName').value.trim();
|
| 1092 |
+
const cPhone = document.getElementById('customerPhone').value.trim();
|
| 1093 |
+
if(!cName || !cPhone) return alert("Пожалуйста, заполните имя и телефон");
|
| 1094 |
+
|
| 1095 |
+
const payload = { items: cart, customer_name: cName, customer_phone: cPhone };
|
| 1096 |
+
|
| 1097 |
+
const btn = document.querySelector('#cartModal .save-contact-btn');
|
| 1098 |
+
const originalText = btn.innerText;
|
| 1099 |
+
btn.innerText = "Оформление...";
|
| 1100 |
btn.disabled = true;
|
| 1101 |
+
|
| 1102 |
try {
|
| 1103 |
+
const res = await fetch(`/${envId}/checkout`, {
|
| 1104 |
method: 'POST',
|
| 1105 |
headers: {'Content-Type': 'application/json'},
|
| 1106 |
+
body: JSON.stringify(payload)
|
| 1107 |
});
|
| 1108 |
const data = await res.json();
|
| 1109 |
+
if(data.success) {
|
| 1110 |
+
cart = {};
|
| 1111 |
+
saveCart();
|
| 1112 |
+
window.location.href = data.url;
|
| 1113 |
+
} else {
|
| 1114 |
+
alert("Ошибка оформления заказа");
|
| 1115 |
}
|
| 1116 |
} catch(e) {
|
| 1117 |
+
alert("Сетевая ошибка");
|
| 1118 |
+
} finally {
|
| 1119 |
+
btn.innerText = originalText;
|
| 1120 |
+
btn.disabled = false;
|
| 1121 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1122 |
}
|
| 1123 |
|
| 1124 |
function closeModal(modalId) {
|
|
|
|
| 1136 |
</html>
|
| 1137 |
'''
|
| 1138 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1139 |
ADMIN_TEMPLATE = '''
|
| 1140 |
<!DOCTYPE html>
|
| 1141 |
<html lang="ru">
|
|
|
|
| 1301 |
{% endfor %}
|
| 1302 |
</select>
|
| 1303 |
|
| 1304 |
+
<h4 style="margin-top: 25px;"><i class="fas fa-shopping-cart"></i> Настройки корзины и заказов</h4>
|
| 1305 |
+
<label style="display: flex; align-items: center; gap: 8px;">
|
| 1306 |
+
<input type="checkbox" name="enable_cart" {% if settings.enable_cart %}checked{% endif %}>
|
| 1307 |
+
Включить корзину (покупка товаров)
|
| 1308 |
+
</label>
|
| 1309 |
+
<label>Мессенджер для приема заказов:</label>
|
| 1310 |
+
<select name="order_messenger">
|
| 1311 |
+
<option value="whatsapp" {% if settings.order_messenger == 'whatsapp' %}selected{% endif %}>WhatsApp</option>
|
| 1312 |
+
<option value="telegram" {% if settings.order_messenger == 'telegram' %}selected{% endif %}>Telegram</option>
|
| 1313 |
+
<option value="none" {% if settings.order_messenger == 'none' %}selected{% endif %}>Не принимать заказы</option>
|
| 1314 |
+
</select>
|
| 1315 |
+
<label>Номер (для WhatsApp) или Username без @ (для Telegram):</label>
|
| 1316 |
+
<input type="text" name="order_contact" value="{{ settings.order_contact }}" placeholder="Например: 996555123456 или myusername">
|
| 1317 |
|
| 1318 |
<div style="background: #f1f3f5; padding: 20px; border-radius: 12px; margin-top: 25px;">
|
| 1319 |
<h4 style="margin-top: 0; color: var(--bg-medium); font-size: 1.1rem;"><i class="fas fa-lock"></i> Пароль для входа сюда</h4>
|
|
|
|
| 1720 |
</html>
|
| 1721 |
'''
|
| 1722 |
|
| 1723 |
+
ORDER_TEMPLATE = '''
|
| 1724 |
+
<!DOCTYPE html>
|
| 1725 |
+
<html lang="ru">
|
| 1726 |
+
<head>
|
| 1727 |
+
<meta charset="UTF-8">
|
| 1728 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 1729 |
+
<title>Заказ #{{ order.id }}</title>
|
| 1730 |
+
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;600;700&display=swap" rel="stylesheet">
|
| 1731 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
|
| 1732 |
+
<style>
|
| 1733 |
+
body { font-family: 'Montserrat', sans-serif; background: #f4f6f9; margin: 0; padding: 20px; color: #333; }
|
| 1734 |
+
.invoice-box { max-width: 600px; margin: 0 auto; background: #fff; padding: 30px; border-radius: 12px; box-shadow: 0 5px 20px rgba(0,0,0,0.05); }
|
| 1735 |
+
.header { text-align: center; border-bottom: 2px solid #eee; padding-bottom: 20px; margin-bottom: 20px; }
|
| 1736 |
+
.header h1 { margin: 0; color: #135D66; font-size: 1.8rem; }
|
| 1737 |
+
.info { margin-bottom: 20px; font-size: 0.95rem; line-height: 1.6; }
|
| 1738 |
+
.info strong { color: #135D66; }
|
| 1739 |
+
.item { display: flex; align-items: center; border-bottom: 1px solid #eee; padding: 15px 0; gap: 15px; }
|
| 1740 |
+
.item img { width: 60px; height: 60px; object-fit: cover; border-radius: 8px; border: 1px solid #eee; }
|
| 1741 |
+
.item-details { flex-grow: 1; }
|
| 1742 |
+
.item-name { font-weight: 600; font-size: 1rem; margin-bottom: 5px; }
|
| 1743 |
+
.item-meta { font-size: 0.9rem; color: #666; }
|
| 1744 |
+
.item-sum { font-weight: 700; font-size: 1.1rem; color: #135D66; text-align: right; }
|
| 1745 |
+
.total { text-align: right; margin-top: 20px; font-size: 1.4rem; font-weight: 700; color: #135D66; }
|
| 1746 |
+
.btn { display: flex; justify-content: center; align-items: center; gap: 10px; width: 100%; padding: 15px; margin-top: 30px; background: #25D366; color: white; text-decoration: none; border-radius: 8px; font-weight: 700; font-size: 1.1rem; transition: background 0.3s; box-sizing: border-box; border: none; cursor: pointer;}
|
| 1747 |
+
.btn.telegram { background: #0088cc; }
|
| 1748 |
+
.btn:hover { opacity: 0.9; }
|
| 1749 |
+
.back-btn { background: #6c757d; margin-top: 10px; }
|
| 1750 |
+
</style>
|
| 1751 |
+
</head>
|
| 1752 |
+
<body>
|
| 1753 |
+
<div class="invoice-box">
|
| 1754 |
+
<div class="header">
|
| 1755 |
+
<h1>Накладная заказа</h1>
|
| 1756 |
+
<p style="margin-top: 5px; color: #777;">#{{ order.id }} от {{ order.date }}</p>
|
| 1757 |
+
</div>
|
| 1758 |
+
<div class="info">
|
| 1759 |
+
<p><strong>Покупатель:</strong> {{ order.customer_name }}</p>
|
| 1760 |
+
<p><strong>Телефон:</strong> {{ order.customer_phone }}</p>
|
| 1761 |
+
<p><strong>Продавец:</strong> {{ settings.organization_name }}</p>
|
| 1762 |
+
</div>
|
| 1763 |
+
|
| 1764 |
+
<div class="items">
|
| 1765 |
+
{% for pid, item in order.items.items() %}
|
| 1766 |
+
<div class="item">
|
| 1767 |
+
{% if item.photo %}
|
| 1768 |
+
<img src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/photos/{{ item.photo }}" alt="{{ item.name }}">
|
| 1769 |
+
{% else %}
|
| 1770 |
+
<img src="https://via.placeholder.com/60x60.png?text=Фото" alt="Нет фото">
|
| 1771 |
+
{% endif %}
|
| 1772 |
+
<div class="item-details">
|
| 1773 |
+
<div class="item-name">{{ item.name }}</div>
|
| 1774 |
+
<div class="item-meta">{{ item.qty }} шт. × {{ "%.2f"|format(item.price) }} {{ currency }}</div>
|
| 1775 |
+
</div>
|
| 1776 |
+
<div class="item-sum">
|
| 1777 |
+
{{ "%.2f"|format(item.qty * item.price) }} {{ currency }}
|
| 1778 |
+
</div>
|
| 1779 |
+
</div>
|
| 1780 |
+
{% endfor %}
|
| 1781 |
+
</div>
|
| 1782 |
+
|
| 1783 |
+
<div class="total">
|
| 1784 |
+
Итого: {{ "%.2f"|format(order.total) }} {{ currency }}
|
| 1785 |
+
</div>
|
| 1786 |
+
|
| 1787 |
+
{% if send_link != "#" %}
|
| 1788 |
+
<a href="{{ send_link }}" target="_blank" class="btn {{ 'telegram' if messenger_name == 'Telegram' else '' }}">
|
| 1789 |
+
<i class="fab fa-{{ 'telegram-plane' if messenger_name == 'Telegram' else 'whatsapp' }}"></i> Отправить продавцу ({{ messenger_name }})
|
| 1790 |
+
</a>
|
| 1791 |
+
{% endif %}
|
| 1792 |
+
|
| 1793 |
+
<a href="{{ url_for('catalog', env_id=env_id) }}" class="btn back-btn">Вернуться в каталог</a>
|
| 1794 |
+
</div>
|
| 1795 |
+
</body>
|
| 1796 |
+
</html>
|
| 1797 |
+
'''
|
| 1798 |
+
|
| 1799 |
@app.route('/')
|
| 1800 |
def index():
|
| 1801 |
return render_template_string(LANDING_PAGE_TEMPLATE)
|
|
|
|
| 1837 |
"admin_password": "",
|
| 1838 |
"categories_as_lines": False,
|
| 1839 |
"about_text": "Привет! Это моя онлайн-визитка.",
|
| 1840 |
+
"enable_cart": False,
|
| 1841 |
"order_messenger": "whatsapp",
|
| 1842 |
"order_contact": ""
|
| 1843 |
}
|
|
|
|
| 1967 |
|
| 1968 |
@app.route('/<env_id>/checkout', methods=['POST'])
|
| 1969 |
def checkout(env_id):
|
| 1970 |
+
req_data = request.get_json()
|
| 1971 |
+
env_data = get_env_data(env_id)
|
|
|
|
| 1972 |
|
| 1973 |
+
items = req_data.get('items', {})
|
| 1974 |
+
if not items:
|
| 1975 |
+
return jsonify({"success": False, "error": "Корзина пуста"})
|
| 1976 |
+
|
| 1977 |
+
total = sum(item.get('qty', 0) * item.get('price', 0) for item in items.values())
|
| 1978 |
|
| 1979 |
order = {
|
| 1980 |
+
"id": ''.join(random.choices(string.digits, k=8)),
|
| 1981 |
+
"date": datetime.now(ALMATY_TZ).strftime('%Y-%m-%d %H:%M:%S'),
|
| 1982 |
+
"customer_name": req_data.get('customer_name', ''),
|
| 1983 |
+
"customer_phone": req_data.get('customer_phone', ''),
|
| 1984 |
+
"items": items,
|
| 1985 |
+
"total": total
|
| 1986 |
}
|
| 1987 |
|
| 1988 |
+
if 'orders' not in env_data:
|
| 1989 |
+
env_data['orders'] = []
|
| 1990 |
+
env_data['orders'].append(order)
|
| 1991 |
+
save_env_data(env_id, env_data)
|
| 1992 |
|
| 1993 |
+
return jsonify({"success": True, "url": url_for('order_invoice', env_id=env_id, order_id=order['id'])})
|
| 1994 |
|
| 1995 |
+
@app.route('/<env_id>/order/<order_id>')
|
| 1996 |
+
def order_invoice(env_id, order_id):
|
| 1997 |
+
env_data = get_env_data(env_id)
|
| 1998 |
+
settings = env_data.get('settings', {})
|
| 1999 |
+
orders = env_data.get('orders', [])
|
| 2000 |
+
|
| 2001 |
+
order = next((o for o in orders if o.get('id') == order_id), None)
|
| 2002 |
if not order:
|
| 2003 |
return "Заказ не найден", 404
|
| 2004 |
+
|
| 2005 |
+
currency = settings.get('currency_code', 'KGS')
|
| 2006 |
|
| 2007 |
+
text = f"Здравствуйте! Я оформил заказ #{order['id']} на сумму {order['total']} {currency}.\nСсылка на накладную: {request.url}"
|
| 2008 |
+
encoded_text = urllib.parse.quote(text)
|
| 2009 |
+
|
| 2010 |
+
messenger = settings.get('order_messenger', 'whatsapp')
|
| 2011 |
+
contact = settings.get('order_contact', '')
|
| 2012 |
+
|
| 2013 |
+
if messenger == 'whatsapp':
|
| 2014 |
+
num = re.sub(r'[^0-9+]', '', contact)
|
| 2015 |
+
send_link = f"https://wa.me/{num}?text={encoded_text}"
|
| 2016 |
+
messenger_name = "WhatsApp"
|
| 2017 |
+
elif messenger == 'telegram':
|
| 2018 |
+
username = contact.replace('@', '').strip()
|
| 2019 |
+
send_link = f"https://t.me/{username}?text={encoded_text}"
|
| 2020 |
+
messenger_name = "Telegram"
|
| 2021 |
+
else:
|
| 2022 |
+
send_link = "#"
|
| 2023 |
+
messenger_name = "Нет"
|
| 2024 |
+
|
| 2025 |
+
return render_template_string(
|
| 2026 |
+
ORDER_TEMPLATE,
|
| 2027 |
+
order=order,
|
| 2028 |
+
currency=currency,
|
| 2029 |
+
send_link=send_link,
|
| 2030 |
+
messenger_name=messenger_name,
|
| 2031 |
+
repo_id=REPO_ID,
|
| 2032 |
+
settings=settings,
|
| 2033 |
+
env_id=env_id
|
| 2034 |
+
)
|
| 2035 |
|
| 2036 |
@app.route('/<env_id>/admin', methods=['GET', 'POST'])
|
| 2037 |
def admin(env_id):
|
|
|
|
| 2223 |
|
| 2224 |
settings['currency_code'] = request.form.get('currency_code', 'KGS')
|
| 2225 |
settings['color_scheme'] = request.form.get('color_scheme', 'default')
|
| 2226 |
+
|
| 2227 |
+
settings['enable_cart'] = 'enable_cart' in request.form
|
| 2228 |
settings['order_messenger'] = request.form.get('order_messenger', 'whatsapp')
|
| 2229 |
+
settings['order_contact'] = request.form.get('order_contact', '').strip()
|
| 2230 |
|
| 2231 |
avatar_file = request.files.get('chat_avatar')
|
| 2232 |
if avatar_file and avatar_file.filename:
|