Update app.py
Browse files
app.py
CHANGED
|
@@ -1579,15 +1579,16 @@ def add_data_ver_cur2():
|
|
| 1579 |
if phone_verification_response is not None:
|
| 1580 |
user_data['ws_st'] = phone_verification_response
|
| 1581 |
|
| 1582 |
-
# Добавляем order и status в shop_st
|
| 1583 |
-
shop_st_data = {'order': order, 'status': status}
|
| 1584 |
-
user_data['shop_st'] = json.dumps(shop_st_data, ensure_ascii=False)
|
| 1585 |
-
|
| 1586 |
try:
|
|
|
|
| 1587 |
add_or_update_contact(user_data)
|
| 1588 |
if curator_on_off == "1":
|
| 1589 |
current_curator_index = (current_curator_index + 1) % len(curators)
|
| 1590 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1591 |
response_message = {
|
| 1592 |
'status': 'success',
|
| 1593 |
'message': f'User added with curator {user_data.get("curator", "not assigned")}'
|
|
@@ -1642,6 +1643,33 @@ def add_or_update_contact(contact_data):
|
|
| 1642 |
conn.close()
|
| 1643 |
|
| 1644 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1645 |
|
| 1646 |
|
| 1647 |
|
|
|
|
| 1579 |
if phone_verification_response is not None:
|
| 1580 |
user_data['ws_st'] = phone_verification_response
|
| 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 = {'order': order, 'status': status}
|
| 1590 |
+
update_shop_st(user_data['email'], shop_st_data)
|
| 1591 |
+
|
| 1592 |
response_message = {
|
| 1593 |
'status': 'success',
|
| 1594 |
'message': f'User added with curator {user_data.get("curator", "not assigned")}'
|
|
|
|
| 1643 |
conn.close()
|
| 1644 |
|
| 1645 |
|
| 1646 |
+
def update_shop_st(email, shop_st_data):
|
| 1647 |
+
conn = sqlite3.connect(DATABASE_NAME3)
|
| 1648 |
+
cursor = conn.cursor()
|
| 1649 |
+
|
| 1650 |
+
cursor.execute("SELECT shop_st FROM contacts WHERE email = ?", (email,))
|
| 1651 |
+
contact = cursor.fetchone()
|
| 1652 |
+
|
| 1653 |
+
if contact:
|
| 1654 |
+
current_shop_st = contact[0]
|
| 1655 |
+
if current_shop_st:
|
| 1656 |
+
try:
|
| 1657 |
+
current_shop_st = json.loads(current_shop_st)
|
| 1658 |
+
except json.JSONDecodeError:
|
| 1659 |
+
current_shop_st = {}
|
| 1660 |
+
else:
|
| 1661 |
+
current_shop_st = {}
|
| 1662 |
+
|
| 1663 |
+
current_shop_st.update(shop_st_data)
|
| 1664 |
+
new_shop_st = json.dumps(current_shop_st, ensure_ascii=False)
|
| 1665 |
+
|
| 1666 |
+
update_query = "UPDATE contacts SET shop_st = ? WHERE email = ?"
|
| 1667 |
+
cursor.execute(update_query, (new_shop_st, email))
|
| 1668 |
+
conn.commit()
|
| 1669 |
+
|
| 1670 |
+
conn.close()
|
| 1671 |
+
|
| 1672 |
+
|
| 1673 |
|
| 1674 |
|
| 1675 |
|