DmitrMakeev commited on
Commit
2e9abd8
1 Parent(s): 6b0524e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -0
app.py CHANGED
@@ -1853,7 +1853,68 @@ def from_shop_st():
1853
 
1854
 
1855
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1856
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1857
 
1858
 
1859
 
 
1853
 
1854
 
1855
 
1856
+ # Маршрут для приема GET запроса
1857
+ @app.route('/order2', methods=['GET'])
1858
+ def from_shop_st():
1859
+ try:
1860
+ api_sys_control = request.args.get('api_sys')
1861
+
1862
+ if api_sys_control != api_key_sys:
1863
+ return json.dumps({"error": "Unauthorized access"}), 403
1864
+
1865
+ name = request.args.get('name', '')
1866
+ email = request.args.get('email', '')
1867
+ phone = request.args.get('phone', '').lstrip('+')
1868
+ order = request.args.get('order', '')
1869
+ status = request.args.get('status', '')
1870
+ del_flag = request.args.get('del', '')
1871
+
1872
+ if not email or not phone:
1873
+ return json.dumps({"error": "Email and phone are required"}), 400
1874
+
1875
+ # Очистка номера телефона
1876
+ phone = clean_phone_number_ss(phone)
1877
+
1878
+ conn = sqlite3.connect(DATABASE6)
1879
+ cursor = conn.cursor()
1880
+
1881
+ cursor.execute("SELECT * FROM contacts WHERE email = ? OR phone = ?", (email, phone))
1882
+ result = cursor.fetchone()
1883
 
1884
+ if result:
1885
+ shop_st = result[17] if result[17] else '{}'
1886
+ shop_st_data = json.loads(shop_st)
1887
+ else:
1888
+ shop_st_data = {}
1889
+
1890
+ if del_flag == '1':
1891
+ shop_st_data = {}
1892
+ elif order and status:
1893
+ shop_st_data[order] = status
1894
+
1895
+ shop_st_json = json.dumps(shop_st_data)
1896
+
1897
+ # Исключаем все столбцы, кроме name, phone, email, shop_st
1898
+ columns_to_update = ['name', 'phone', 'email', 'shop_st']
1899
+ values_to_update = [name, phone, email, shop_st_json]
1900
+
1901
+ if result:
1902
+ # Обновляем только те поля, которые переданы в запросе
1903
+ set_clause = ', '.join([f"{col} = ?" for col in columns_to_update])
1904
+ query = f"UPDATE contacts SET {set_clause} WHERE email = ? OR phone = ?"
1905
+ cursor.execute(query, values_to_update + [email, phone])
1906
+ else:
1907
+ # Вставляем новые данные
1908
+ query = f"INSERT INTO contacts ({', '.join(columns_to_update)}) VALUES ({', '.join(['?' for _ in columns_to_update])})"
1909
+ cursor.execute(query, values_to_update)
1910
+
1911
+ conn.commit()
1912
+ conn.close()
1913
+
1914
+ return json.dumps(shop_st_data), 200
1915
+
1916
+ except Exception as e:
1917
+ return json.dumps({"error": str(e)}), 500
1918
 
1919
 
1920