DmitrMakeev
commited on
Commit
•
0ecf8c4
1
Parent(s):
34d8c76
Update app.py
Browse files
app.py
CHANGED
@@ -1581,12 +1581,12 @@ def add_data_ver_cur2():
|
|
1581 |
|
1582 |
try:
|
1583 |
# Шаг 1: Сначала записываем пользователя
|
1584 |
-
add_or_update_contact(user_data)
|
1585 |
if curator_on_off == "1":
|
1586 |
current_curator_index = (current_curator_index + 1) % len(curators)
|
1587 |
|
1588 |
# Шаг 2: Обновляем поле shop_st JSON-данными
|
1589 |
-
shop_st_data = {
|
1590 |
update_shop_st(user_data['email'], shop_st_data)
|
1591 |
|
1592 |
response_message = {
|
@@ -1601,7 +1601,7 @@ def add_data_ver_cur2():
|
|
1601 |
return jsonify({'status': 'error', 'message': str(e)}), 500
|
1602 |
|
1603 |
|
1604 |
-
def add_or_update_contact(contact_data):
|
1605 |
conn = sqlite3.connect(DATABASE_NAME3)
|
1606 |
cursor = conn.cursor()
|
1607 |
|
@@ -1622,10 +1622,11 @@ def add_or_update_contact(contact_data):
|
|
1622 |
'pr1', 'pr2', 'pr3', 'pr4', 'pr5', 'gc_url', 'key_pr', 'n_con', 'canal', 'data_on', 'data_t', 'utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'gcpc'
|
1623 |
]
|
1624 |
|
1625 |
-
# Устанавливаем значения по умолчанию для отсутствующих
|
1626 |
-
|
1627 |
-
|
1628 |
-
|
|
|
1629 |
|
1630 |
placeholders = ", ".join([f"{field} = ?" for field in fields])
|
1631 |
|
@@ -1634,10 +1635,10 @@ def add_or_update_contact(contact_data):
|
|
1634 |
|
1635 |
if contact:
|
1636 |
update_query = f"UPDATE contacts SET {placeholders} WHERE id = ?"
|
1637 |
-
cursor.execute(update_query, (*[contact_data
|
1638 |
else:
|
1639 |
insert_query = f"INSERT INTO contacts ({', '.join(fields)}) VALUES ({', '.join(['?' for _ in fields])})"
|
1640 |
-
cursor.execute(insert_query, tuple(contact_data
|
1641 |
|
1642 |
conn.commit()
|
1643 |
conn.close()
|
|
|
1581 |
|
1582 |
try:
|
1583 |
# Шаг 1: Сначала записываем пользователя
|
1584 |
+
add_or_update_contact(user_data, skip_defaults=True)
|
1585 |
if curator_on_off == "1":
|
1586 |
current_curator_index = (current_curator_index + 1) % len(curators)
|
1587 |
|
1588 |
# Шаг 2: Обновляем поле shop_st JSON-данными
|
1589 |
+
shop_st_data = {order: status}
|
1590 |
update_shop_st(user_data['email'], shop_st_data)
|
1591 |
|
1592 |
response_message = {
|
|
|
1601 |
return jsonify({'status': 'error', 'message': str(e)}), 500
|
1602 |
|
1603 |
|
1604 |
+
def add_or_update_contact(contact_data, skip_defaults=False):
|
1605 |
conn = sqlite3.connect(DATABASE_NAME3)
|
1606 |
cursor = conn.cursor()
|
1607 |
|
|
|
1622 |
'pr1', 'pr2', 'pr3', 'pr4', 'pr5', 'gc_url', 'key_pr', 'n_con', 'canal', 'data_on', 'data_t', 'utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'gcpc'
|
1623 |
]
|
1624 |
|
1625 |
+
# Устанавливаем значения по умолчанию для отсутствующих полей, только если не указан флаг skip_defaults
|
1626 |
+
if not skip_defaults:
|
1627 |
+
for field in fields:
|
1628 |
+
if field not in contact_data:
|
1629 |
+
contact_data[field] = ''
|
1630 |
|
1631 |
placeholders = ", ".join([f"{field} = ?" for field in fields])
|
1632 |
|
|
|
1635 |
|
1636 |
if contact:
|
1637 |
update_query = f"UPDATE contacts SET {placeholders} WHERE id = ?"
|
1638 |
+
cursor.execute(update_query, (*[contact_data.get(field, '') for field in fields], contact[0]))
|
1639 |
else:
|
1640 |
insert_query = f"INSERT INTO contacts ({', '.join(fields)}) VALUES ({', '.join(['?' for _ in fields])})"
|
1641 |
+
cursor.execute(insert_query, tuple(contact_data.get(field, '') for field in fields))
|
1642 |
|
1643 |
conn.commit()
|
1644 |
conn.close()
|