DmitrMakeev
commited on
Commit
•
ad87451
1
Parent(s):
1a56757
Update app.py
Browse files
app.py
CHANGED
@@ -1559,7 +1559,6 @@ def add_data_ver_cur2():
|
|
1559 |
curator_on_off = request.args.get('cur', '0') # Включает "1" и выключает "0" назначение куратора
|
1560 |
order = request.args.get('order', '')
|
1561 |
status = request.args.get('status', '')
|
1562 |
-
del_flag = request.args.get('del', '')
|
1563 |
template_key = request.args.get('template_key', 'avp')
|
1564 |
mapping_template_cur = mapp_templates.get(template_key, mt_avp)
|
1565 |
|
@@ -1601,6 +1600,47 @@ def add_data_ver_cur2():
|
|
1601 |
return jsonify({'status': 'error', 'message': str(e)}), 500
|
1602 |
|
1603 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1604 |
|
1605 |
|
1606 |
|
|
|
1559 |
curator_on_off = request.args.get('cur', '0') # Включает "1" и выключает "0" назначение куратора
|
1560 |
order = request.args.get('order', '')
|
1561 |
status = request.args.get('status', '')
|
|
|
1562 |
template_key = request.args.get('template_key', 'avp')
|
1563 |
mapping_template_cur = mapp_templates.get(template_key, mt_avp)
|
1564 |
|
|
|
1600 |
return jsonify({'status': 'error', 'message': str(e)}), 500
|
1601 |
|
1602 |
|
1603 |
+
def add_or_update_contact(contact_data):
|
1604 |
+
conn = sqlite3.connect(DATABASE_NAME3)
|
1605 |
+
cursor = conn.cursor()
|
1606 |
+
|
1607 |
+
email = contact_data.get('email')
|
1608 |
+
if not email:
|
1609 |
+
logging.error(f"Missing email in contact data: {contact_data}")
|
1610 |
+
return
|
1611 |
+
|
1612 |
+
utc_now = datetime.utcnow()
|
1613 |
+
msk_tz = pytz.timezone('Europe/Moscow')
|
1614 |
+
msk_now = utc_now.replace(tzinfo=pytz.utc).astimezone(msk_tz)
|
1615 |
+
contact_data['data_t'] = msk_now.strftime('%Y-%m-%d %H:%M:%S')
|
1616 |
+
|
1617 |
+
# Список всех возможных полей
|
1618 |
+
fields = [
|
1619 |
+
'name', 'phone', 'email', 'vk_id', 'chat_id', 'ws_st', 'ws_stop', 'web_st', 'fin_prog',
|
1620 |
+
'b_city', 'b_fin', 'b_ban', 'b_ign', 'b_baners', 'b_butt', 'b_mess', 'shop_st', 'curator',
|
1621 |
+
'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'
|
1622 |
+
]
|
1623 |
+
|
1624 |
+
# Устанавливаем значения по умолчанию для отсутствующих полей
|
1625 |
+
for field in fields:
|
1626 |
+
if field not in contact_data:
|
1627 |
+
contact_data[field] = ''
|
1628 |
+
|
1629 |
+
placeholders = ", ".join([f"{field} = ?" for field in fields])
|
1630 |
+
|
1631 |
+
cursor.execute("SELECT id FROM contacts WHERE email = ?", (email,))
|
1632 |
+
contact = cursor.fetchone()
|
1633 |
+
|
1634 |
+
if contact:
|
1635 |
+
update_query = f"UPDATE contacts SET {placeholders} WHERE id = ?"
|
1636 |
+
cursor.execute(update_query, (*[contact_data[field] for field in fields], contact[0]))
|
1637 |
+
else:
|
1638 |
+
insert_query = f"INSERT INTO contacts ({', '.join(fields)}) VALUES ({', '.join(['?' for _ in fields])})"
|
1639 |
+
cursor.execute(insert_query, tuple(contact_data[field] for field in fields))
|
1640 |
+
|
1641 |
+
conn.commit()
|
1642 |
+
conn.close()
|
1643 |
+
|
1644 |
|
1645 |
|
1646 |
|