DmitrMakeev
commited on
Commit
•
87d67c6
1
Parent(s):
c4b2049
Update app.py
Browse files
app.py
CHANGED
@@ -1773,7 +1773,6 @@ DATABASE6 = 'data_gc.db'
|
|
1773 |
def clean_phone_number_ss(phone_number):
|
1774 |
return re.sub(r'\D', '', phone_number)
|
1775 |
|
1776 |
-
# Маршрут для приема GET запроса
|
1777 |
@app.route('/order', methods=['GET'])
|
1778 |
def from_shop_st():
|
1779 |
try:
|
@@ -1798,15 +1797,13 @@ def from_shop_st():
|
|
1798 |
conn = sqlite3.connect(DATABASE6)
|
1799 |
cursor = conn.cursor()
|
1800 |
|
1801 |
-
cursor.execute("SELECT
|
1802 |
result = cursor.fetchone()
|
1803 |
|
1804 |
if result:
|
1805 |
-
|
1806 |
-
shop_st = shop_st if shop_st else '{}'
|
1807 |
shop_st_data = json.loads(shop_st)
|
1808 |
else:
|
1809 |
-
name_db, phone_db, email_db = name, phone, email
|
1810 |
shop_st_data = {}
|
1811 |
|
1812 |
if del_flag == '1':
|
@@ -1817,35 +1814,25 @@ def from_shop_st():
|
|
1817 |
shop_st_json = json.dumps(shop_st_data)
|
1818 |
|
1819 |
if result:
|
1820 |
-
|
1821 |
-
|
1822 |
-
|
1823 |
-
|
1824 |
-
|
1825 |
-
|
1826 |
-
|
1827 |
-
|
1828 |
-
|
1829 |
-
|
1830 |
-
|
1831 |
-
|
1832 |
-
|
1833 |
-
update_columns.append('shop_st = ?')
|
1834 |
-
update_values.append(shop_st_json)
|
1835 |
-
|
1836 |
-
update_values.extend([email, phone])
|
1837 |
-
|
1838 |
-
query = f"""
|
1839 |
-
UPDATE contacts
|
1840 |
-
SET {', '.join(update_columns)}
|
1841 |
WHERE email = ? OR phone = ?
|
1842 |
-
"""
|
1843 |
-
cursor.execute(query, update_values)
|
1844 |
else:
|
1845 |
cursor.execute("""
|
1846 |
-
INSERT INTO contacts (name, phone, email, shop_st)
|
1847 |
-
VALUES (?, ?, ?, ?)
|
1848 |
-
|
1849 |
|
1850 |
conn.commit()
|
1851 |
conn.close()
|
@@ -1902,7 +1889,6 @@ def from_shop_st():
|
|
1902 |
|
1903 |
|
1904 |
|
1905 |
-
|
1906 |
|
1907 |
|
1908 |
@app.route('/gc_in', methods=['GET'])
|
|
|
1773 |
def clean_phone_number_ss(phone_number):
|
1774 |
return re.sub(r'\D', '', phone_number)
|
1775 |
|
|
|
1776 |
@app.route('/order', methods=['GET'])
|
1777 |
def from_shop_st():
|
1778 |
try:
|
|
|
1797 |
conn = sqlite3.connect(DATABASE6)
|
1798 |
cursor = conn.cursor()
|
1799 |
|
1800 |
+
cursor.execute("SELECT shop_st FROM contacts WHERE email = ? OR phone = ?", (email, phone))
|
1801 |
result = cursor.fetchone()
|
1802 |
|
1803 |
if result:
|
1804 |
+
shop_st = result[0] if result[0] else '{}'
|
|
|
1805 |
shop_st_data = json.loads(shop_st)
|
1806 |
else:
|
|
|
1807 |
shop_st_data = {}
|
1808 |
|
1809 |
if del_flag == '1':
|
|
|
1814 |
shop_st_json = json.dumps(shop_st_data)
|
1815 |
|
1816 |
if result:
|
1817 |
+
# Получаем текущие значения
|
1818 |
+
cursor.execute("SELECT * FROM contacts WHERE email = ? OR phone = ?", (email, phone))
|
1819 |
+
current_data = cursor.fetchone()
|
1820 |
+
|
1821 |
+
# Сохраняем старые значения
|
1822 |
+
name = name or current_data[1]
|
1823 |
+
phone = phone or current_data[2]
|
1824 |
+
email = email or current_data[3]
|
1825 |
+
|
1826 |
+
cursor.execute("""
|
1827 |
+
UPDATE contacts
|
1828 |
+
SET name = ?, phone = ?, email = ?, shop_st = ?
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1829 |
WHERE email = ? OR phone = ?
|
1830 |
+
""", (name, phone, email, shop_st_json, email, phone))
|
|
|
1831 |
else:
|
1832 |
cursor.execute("""
|
1833 |
+
INSERT INTO contacts (name, phone, email, shop_st)
|
1834 |
+
VALUES (?, ?, ?, ?)
|
1835 |
+
""", (name, phone, email, shop_st_json))
|
1836 |
|
1837 |
conn.commit()
|
1838 |
conn.close()
|
|
|
1889 |
|
1890 |
|
1891 |
|
|
|
1892 |
|
1893 |
|
1894 |
@app.route('/gc_in', methods=['GET'])
|