Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -624,7 +624,6 @@ def shop_order_new():
|
|
624 |
|
625 |
|
626 |
|
627 |
-
# Работа из VK_ID Запись ордер с полными данными
|
628 |
@app.route('/wr_order_vk_full', methods=['POST'])
|
629 |
def write_order_vk_full():
|
630 |
try:
|
@@ -644,6 +643,7 @@ def write_order_vk_full():
|
|
644 |
status = request.form.get('status', '')
|
645 |
del_flag = request.form.get('del', '')
|
646 |
n_con_flag = request.form.get('n_con', '')
|
|
|
647 |
|
648 |
if not email or not phone:
|
649 |
logging.error("Email and phone are required")
|
@@ -654,15 +654,10 @@ def write_order_vk_full():
|
|
654 |
conn = sqlite3.connect(DATABASE_NEW)
|
655 |
cursor = conn.cursor()
|
656 |
|
657 |
-
#
|
658 |
-
cursor.execute("SELECT * FROM contacts WHERE email = ? OR phone = ?", (email, phone))
|
659 |
result = cursor.fetchone()
|
660 |
|
661 |
-
# Если не найдено, ищем по vk_id
|
662 |
-
if not result:
|
663 |
-
cursor.execute("SELECT * FROM contacts WHERE vk_id = ?", (vkid,))
|
664 |
-
result = cursor.fetchone()
|
665 |
-
|
666 |
if result:
|
667 |
shop_st = result[17] if result[17] else '{}'
|
668 |
shop_st_data = json.loads(shop_st)
|
@@ -683,13 +678,13 @@ def write_order_vk_full():
|
|
683 |
msk_now = utc_now.replace(tzinfo=pytz.utc).astimezone(msk_tz)
|
684 |
data_on = msk_now.strftime('%Y-%m-%d %H:%M:%S')
|
685 |
|
686 |
-
columns_to_update = ['name', 'phone', 'email', 'vk_id', 'orders', 'n_con', 'data_on']
|
687 |
-
values_to_update = [name, phone, email, vkid, shop_st_json, n_con_flag, data_on]
|
688 |
|
689 |
if result:
|
690 |
set_clause = ', '.join([f"{col} = ?" for col in columns_to_update])
|
691 |
-
query = f"UPDATE contacts SET {set_clause} WHERE email = ? OR phone = ? OR vk_id = ?"
|
692 |
-
cursor.execute(query, values_to_update + [email, phone, vkid])
|
693 |
else:
|
694 |
query = f"INSERT INTO contacts ({', '.join(columns_to_update)}) VALUES ({', '.join(['?' for _ in columns_to_update])})"
|
695 |
cursor.execute(query, values_to_update)
|
|
|
624 |
|
625 |
|
626 |
|
|
|
627 |
@app.route('/wr_order_vk_full', methods=['POST'])
|
628 |
def write_order_vk_full():
|
629 |
try:
|
|
|
643 |
status = request.form.get('status', '')
|
644 |
del_flag = request.form.get('del', '')
|
645 |
n_con_flag = request.form.get('n_con', '')
|
646 |
+
chat_id = request.form.get('chat_id', '')
|
647 |
|
648 |
if not email or not phone:
|
649 |
logging.error("Email and phone are required")
|
|
|
654 |
conn = sqlite3.connect(DATABASE_NEW)
|
655 |
cursor = conn.cursor()
|
656 |
|
657 |
+
# Ищем по email, phone, vk_id или chat_id
|
658 |
+
cursor.execute("SELECT * FROM contacts WHERE email = ? OR phone = ? OR vk_id = ? OR chat_id = ?", (email, phone, vkid, chat_id))
|
659 |
result = cursor.fetchone()
|
660 |
|
|
|
|
|
|
|
|
|
|
|
661 |
if result:
|
662 |
shop_st = result[17] if result[17] else '{}'
|
663 |
shop_st_data = json.loads(shop_st)
|
|
|
678 |
msk_now = utc_now.replace(tzinfo=pytz.utc).astimezone(msk_tz)
|
679 |
data_on = msk_now.strftime('%Y-%m-%d %H:%M:%S')
|
680 |
|
681 |
+
columns_to_update = ['name', 'phone', 'email', 'vk_id', 'chat_id', 'orders', 'n_con', 'data_on']
|
682 |
+
values_to_update = [name, phone, email, vkid, chat_id, shop_st_json, n_con_flag, data_on]
|
683 |
|
684 |
if result:
|
685 |
set_clause = ', '.join([f"{col} = ?" for col in columns_to_update])
|
686 |
+
query = f"UPDATE contacts SET {set_clause} WHERE email = ? OR phone = ? OR vk_id = ? OR chat_id = ?"
|
687 |
+
cursor.execute(query, values_to_update + [email, phone, vkid, chat_id])
|
688 |
else:
|
689 |
query = f"INSERT INTO contacts ({', '.join(columns_to_update)}) VALUES ({', '.join(['?' for _ in columns_to_update])})"
|
690 |
cursor.execute(query, values_to_update)
|