Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -188,7 +188,7 @@ def get_current_time():
|
|
188 |
# Функция для очистки номера телефона
|
189 |
def clean_phone_number_ss(phone_number):
|
190 |
return re.sub(r'\D', '', phone_number)
|
191 |
-
# Работа с ордером из
|
192 |
@app.route('/order_new', methods=['GET'])
|
193 |
def shop_order_new():
|
194 |
try:
|
@@ -268,6 +268,95 @@ def shop_order_new():
|
|
268 |
|
269 |
|
270 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
271 |
# Поднятие страницы с таблицей
|
272 |
@app.route('/data_gc_tab', methods=['GET'])
|
273 |
def data_gc_tab():
|
|
|
188 |
# Функция для очистки номера телефона
|
189 |
def clean_phone_number_ss(phone_number):
|
190 |
return re.sub(r'\D', '', phone_number)
|
191 |
+
# Работа с ордером из сайта без VK_ID
|
192 |
@app.route('/order_new', methods=['GET'])
|
193 |
def shop_order_new():
|
194 |
try:
|
|
|
268 |
|
269 |
|
270 |
|
271 |
+
|
272 |
+
# Работа с VK_ID
|
273 |
+
@app.route('/order_Write', methods=['GET'])
|
274 |
+
def shop_order_Write():
|
275 |
+
try:
|
276 |
+
logging.debug("Starting shop_order_new")
|
277 |
+
api_sys_control = request.args.get('api_sys')
|
278 |
+
|
279 |
+
if api_sys_control != api_key_sys:
|
280 |
+
logging.warning("Unauthorized access attempt")
|
281 |
+
return json.dumps({"error": "Unauthorized access"}), 403
|
282 |
+
|
283 |
+
name = request.args.get('name', '')
|
284 |
+
email = request.args.get('email', '')
|
285 |
+
phone = request.args.get('phone', '').lstrip('+')
|
286 |
+
order = request.args.get('order', '')
|
287 |
+
status = request.args.get('status', '')
|
288 |
+
del_flag = request.args.get('del', '')
|
289 |
+
n_con_flag = request.args.get('n_con', '')
|
290 |
+
|
291 |
+
if not email or not phone:
|
292 |
+
logging.error("Email and phone are required")
|
293 |
+
return json.dumps({"error": "Email and phone are required"}), 400
|
294 |
+
|
295 |
+
phone = clean_phone_number_ss(phone)
|
296 |
+
|
297 |
+
conn = sqlite3.connect(DATABASE_NEW)
|
298 |
+
cursor = conn.cursor()
|
299 |
+
|
300 |
+
cursor.execute("SELECT * FROM contacts WHERE email = ? OR phone = ?", (email, phone))
|
301 |
+
result = cursor.fetchone()
|
302 |
+
|
303 |
+
if result:
|
304 |
+
shop_st = result[17] if result[17] else '{}'
|
305 |
+
shop_st_data = json.loads(shop_st)
|
306 |
+
logging.debug(f"Existing record found. Loaded JSON: {shop_st_data}")
|
307 |
+
else:
|
308 |
+
shop_st_data = {}
|
309 |
+
|
310 |
+
if del_flag == '1':
|
311 |
+
if order in shop_st_data:
|
312 |
+
del shop_st_data[order]
|
313 |
+
elif order and status:
|
314 |
+
shop_st_data[order] = status
|
315 |
+
|
316 |
+
shop_st_json = json.dumps(shop_st_data)
|
317 |
+
|
318 |
+
utc_now = datetime.utcnow()
|
319 |
+
msk_tz = pytz.timezone('Europe/Moscow')
|
320 |
+
msk_now = utc_now.replace(tzinfo=pytz.utc).astimezone(msk_tz)
|
321 |
+
data_on = msk_now.strftime('%Y-%m-%d %H:%M:%S')
|
322 |
+
|
323 |
+
columns_to_update = ['name', 'phone', 'email', 'orders', 'n_con', 'data_on']
|
324 |
+
values_to_update = [name, phone, email, shop_st_json, n_con_flag, data_on]
|
325 |
+
|
326 |
+
if result:
|
327 |
+
set_clause = ', '.join([f"{col} = ?" for col in columns_to_update])
|
328 |
+
query = f"UPDATE contacts SET {set_clause} WHERE email = ? OR phone = ?"
|
329 |
+
cursor.execute(query, values_to_update + [email, phone])
|
330 |
+
else:
|
331 |
+
query = f"INSERT INTO contacts ({', '.join(columns_to_update)}) VALUES ({', '.join(['?' for _ in columns_to_update])})"
|
332 |
+
cursor.execute(query, values_to_update)
|
333 |
+
|
334 |
+
conn.commit()
|
335 |
+
|
336 |
+
replace_null_with_empty_string(conn)
|
337 |
+
|
338 |
+
conn.close()
|
339 |
+
|
340 |
+
return json.dumps(shop_st_data), 200
|
341 |
+
|
342 |
+
except Exception as e:
|
343 |
+
logging.error(f"An error occurred: {str(e)}")
|
344 |
+
return json.dumps({"error": str(e)}), 500
|
345 |
+
|
346 |
+
|
347 |
+
|
348 |
+
|
349 |
+
|
350 |
+
|
351 |
+
|
352 |
+
|
353 |
+
|
354 |
+
|
355 |
+
|
356 |
+
|
357 |
+
|
358 |
+
|
359 |
+
|
360 |
# Поднятие страницы с таблицей
|
361 |
@app.route('/data_gc_tab', methods=['GET'])
|
362 |
def data_gc_tab():
|