DmitrMakeev commited on
Commit
17a5535
·
verified ·
1 Parent(s): 8fa809b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -19
app.py CHANGED
@@ -644,7 +644,6 @@ 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
- scan_flag = request.form.get('scan', 'email')
648
 
649
  if not email or not phone:
650
  logging.error("Email and phone are required")
@@ -655,23 +654,15 @@ def write_order_vk_full():
655
  conn = sqlite3.connect(DATABASE_NEW)
656
  cursor = conn.cursor()
657
 
658
- # Определяем, по какому полю искать
659
- if scan_flag == 'email':
660
- search_field = 'email'
661
- search_value = email
662
- elif scan_flag == 'phone':
663
- search_field = 'phone'
664
- search_value = phone
665
- elif scan_flag == 'vk_id':
666
- search_field = 'vk_id'
667
- search_value = vkid
668
- else:
669
- logging.error("Invalid scan flag")
670
- return json.dumps({"error": "Invalid scan flag"}), 400
671
-
672
- cursor.execute(f"SELECT * FROM contacts WHERE {search_field} = ?", (search_value,))
673
  result = cursor.fetchone()
674
 
 
 
 
 
 
675
  if result:
676
  shop_st = result[17] if result[17] else '{}'
677
  shop_st_data = json.loads(shop_st)
@@ -697,8 +688,8 @@ def write_order_vk_full():
697
 
698
  if result:
699
  set_clause = ', '.join([f"{col} = ?" for col in columns_to_update])
700
- query = f"UPDATE contacts SET {set_clause} WHERE {search_field} = ?"
701
- cursor.execute(query, values_to_update + [search_value])
702
  else:
703
  query = f"INSERT INTO contacts ({', '.join(columns_to_update)}) VALUES ({', '.join(['?' for _ in columns_to_update])})"
704
  cursor.execute(query, values_to_update)
@@ -730,7 +721,6 @@ def write_order_vk_full():
730
 
731
 
732
 
733
-
734
  # Работа из VK_ID только по VK ID
735
  @app.route('/wr_order_vk', methods=['POST'])
736
  def wr_order_vk():
 
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
  conn = sqlite3.connect(DATABASE_NEW)
655
  cursor = conn.cursor()
656
 
657
+ # Сначала ищем по email и phone
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)
 
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)
 
721
 
722
 
723
 
 
724
  # Работа из VK_ID только по VK ID
725
  @app.route('/wr_order_vk', methods=['POST'])
726
  def wr_order_vk():