DmitrMakeev commited on
Commit
caee1e3
·
verified ·
1 Parent(s): 0c69a22

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -40
app.py CHANGED
@@ -564,7 +564,6 @@ def shop_order_new():
564
  order = request.args.get('order', '')
565
  status = request.args.get('status', '')
566
  del_flag = request.args.get('del', '')
567
- n_con_flag = request.args.get('n_con', '')
568
 
569
  if not email or not phone:
570
  logging.error("Email and phone are required")
@@ -598,8 +597,8 @@ def shop_order_new():
598
  msk_now = utc_now.replace(tzinfo=pytz.utc).astimezone(msk_tz)
599
  data_on = msk_now.strftime('%Y-%m-%d %H:%M:%S')
600
 
601
- columns_to_update = ['name', 'phone', 'email', 'orders', 'n_con', 'data_on']
602
- values_to_update = [name, phone, email, shop_st_json, n_con_flag, data_on]
603
 
604
  if result:
605
  set_clause = ', '.join([f"{col} = ?" for col in columns_to_update])
@@ -623,11 +622,11 @@ def shop_order_new():
623
 
624
 
625
 
626
- # Работа из VK_ID_full
627
- @app.route('/wr_order_vk_full', methods=['POST'])
628
- def write_order_vk_full():
629
  try:
630
- logging.debug("Starting shop_order_new")
631
 
632
  # Читаем параметры из POST-запроса (формы)
633
  api_sys_control = request.form.get('api_sys')
@@ -637,12 +636,8 @@ def write_order_vk_full():
637
 
638
  name = request.form.get('name', '')
639
  email = request.form.get('email', '')
640
- vkid = request.form.get('vk_id', '')
641
  phone = request.form.get('phone', '').lstrip('+')
642
- order = request.form.get('order', '')
643
- status = request.form.get('status', '')
644
- del_flag = request.form.get('del', '')
645
-
646
 
647
  if not email or not phone:
648
  logging.error("Email and phone are required")
@@ -653,37 +648,17 @@ def write_order_vk_full():
653
  conn = sqlite3.connect(DATABASE_NEW)
654
  cursor = conn.cursor()
655
 
656
- # Ищем по email, phone, vk_id или chat_id
657
- cursor.execute("SELECT * FROM contacts WHERE email = ? OR phone = ? OR vk_id = ? OR chat_id = ?", (email, phone, vkid))
658
  result = cursor.fetchone()
659
 
660
- if result:
661
- shop_st = result[17] if result[17] else '{}'
662
- shop_st_data = json.loads(shop_st)
663
- logging.debug(f"Existing record found. Loaded JSON: {shop_st_data}")
664
- else:
665
- shop_st_data = {}
666
-
667
- if del_flag == '1':
668
- if order in shop_st_data:
669
- del shop_st_data[order]
670
- elif order and status:
671
- shop_st_data[order] = status
672
-
673
- shop_st_json = json.dumps(shop_st_data)
674
-
675
- utc_now = datetime.utcnow()
676
- msk_tz = pytz.timezone('Europe/Moscow')
677
- msk_now = utc_now.replace(tzinfo=pytz.utc).astimezone(msk_tz)
678
- data_on = msk_now.strftime('%Y-%m-%d %H:%M:%S')
679
-
680
- columns_to_update = ['name', 'phone', 'email', 'vk_id', 'orders', 'data_on']
681
- values_to_update = [name, phone, email, vkid, shop_st_json, data_on]
682
 
683
  if result:
684
  set_clause = ', '.join([f"{col} = ?" for col in columns_to_update])
685
- query = f"UPDATE contacts SET {set_clause} WHERE email = ? OR phone = ? OR vk_id = ? OR chat_id = ?"
686
- cursor.execute(query, values_to_update + [email, phone, vkid, chat_id])
687
  else:
688
  query = f"INSERT INTO contacts ({', '.join(columns_to_update)}) VALUES ({', '.join(['?' for _ in columns_to_update])})"
689
  cursor.execute(query, values_to_update)
@@ -694,7 +669,7 @@ def write_order_vk_full():
694
 
695
  conn.close()
696
 
697
- return json.dumps(shop_st_data), 200
698
 
699
  except Exception as e:
700
  logging.error(f"An error occurred: {str(e)}")
@@ -714,7 +689,6 @@ def write_order_vk_full():
714
 
715
 
716
 
717
-
718
  # Работа из VK_ID только по VK ID
719
  @app.route('/wr_order_vk', methods=['POST'])
720
  def wr_order_vk():
 
564
  order = request.args.get('order', '')
565
  status = request.args.get('status', '')
566
  del_flag = request.args.get('del', '')
 
567
 
568
  if not email or not phone:
569
  logging.error("Email and phone are required")
 
597
  msk_now = utc_now.replace(tzinfo=pytz.utc).astimezone(msk_tz)
598
  data_on = msk_now.strftime('%Y-%m-%d %H:%M:%S')
599
 
600
+ columns_to_update = ['name', 'phone', 'email', 'orders', 'data_on']
601
+ values_to_update = [name, phone, email, shop_st_json, data_on]
602
 
603
  if result:
604
  set_clause = ', '.join([f"{col} = ?" for col in columns_to_update])
 
622
 
623
 
624
 
625
+ # Данные формы из ВК
626
+ @app.route('/wr_form_vk', methods=['POST'])
627
+ def wr_form_vk():
628
  try:
629
+ logging.debug("Starting wr_form_vk")
630
 
631
  # Читаем параметры из POST-запроса (формы)
632
  api_sys_control = request.form.get('api_sys')
 
636
 
637
  name = request.form.get('name', '')
638
  email = request.form.get('email', '')
 
639
  phone = request.form.get('phone', '').lstrip('+')
640
+ vkid = request.form.get('vk_id', '')
 
 
 
641
 
642
  if not email or not phone:
643
  logging.error("Email and phone are required")
 
648
  conn = sqlite3.connect(DATABASE_NEW)
649
  cursor = conn.cursor()
650
 
651
+ # Ищем по email, phone или vk_id
652
+ cursor.execute("SELECT * FROM contacts WHERE email = ? OR phone = ? OR vk_id = ?", (email, phone, vkid))
653
  result = cursor.fetchone()
654
 
655
+ columns_to_update = ['name', 'phone', 'email', 'vk_id']
656
+ values_to_update = [name, phone, email, vkid]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
657
 
658
  if result:
659
  set_clause = ', '.join([f"{col} = ?" for col in columns_to_update])
660
+ query = f"UPDATE contacts SET {set_clause} WHERE email = ? OR phone = ? OR vk_id = ?"
661
+ cursor.execute(query, values_to_update + [email, phone, vkid])
662
  else:
663
  query = f"INSERT INTO contacts ({', '.join(columns_to_update)}) VALUES ({', '.join(['?' for _ in columns_to_update])})"
664
  cursor.execute(query, values_to_update)
 
669
 
670
  conn.close()
671
 
672
+ return json.dumps({"success": True}), 200
673
 
674
  except Exception as e:
675
  logging.error(f"An error occurred: {str(e)}")
 
689
 
690
 
691
 
 
692
  # Работа из VK_ID только по VK ID
693
  @app.route('/wr_order_vk', methods=['POST'])
694
  def wr_order_vk():