Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -343,84 +343,7 @@ def write_or():
|
|
343 |
logging.error(f"An error occurred: {str(e)}")
|
344 |
return json.dumps({"error": str(e)}), 500
|
345 |
|
346 |
-
# Работа из VK_ID Запись ордер + прогресс
|
347 |
-
@app.route('/wr_or_pr', methods=['GET'])
|
348 |
-
def write_or_pr():
|
349 |
-
try:
|
350 |
-
logging.debug("Starting shop_order_new")
|
351 |
-
api_sys_control = request.args.get('api_sys')
|
352 |
-
|
353 |
-
if api_sys_control != api_key_sys:
|
354 |
-
logging.warning("Unauthorized access attempt")
|
355 |
-
return json.dumps({"error": "Unauthorized access"}), 403
|
356 |
-
|
357 |
-
name = request.args.get('name', '')
|
358 |
-
email = request.args.get('email', '')
|
359 |
-
vkid = request.args.get('vk_id', '')
|
360 |
-
phone = request.args.get('phone', '').lstrip('+')
|
361 |
-
order = request.args.get('order', '')
|
362 |
-
status = request.args.get('status', '')
|
363 |
-
del_flag = request.args.get('del', '')
|
364 |
-
n_con_flag = request.args.get('n_con', '')
|
365 |
-
prog = request.args.get('progress', '')
|
366 |
-
|
367 |
-
if not email or not phone:
|
368 |
-
logging.error("Email and phone are required")
|
369 |
-
return json.dumps({"error": "Email and phone are required"}), 400
|
370 |
-
|
371 |
-
phone = clean_phone_number_ss(phone)
|
372 |
-
|
373 |
-
conn = sqlite3.connect(DATABASE_NEW)
|
374 |
-
cursor = conn.cursor()
|
375 |
-
|
376 |
-
cursor.execute("SELECT * FROM contacts WHERE email = ? OR phone = ?", (email, phone))
|
377 |
-
result = cursor.fetchone()
|
378 |
-
|
379 |
-
if result:
|
380 |
-
shop_st = result[17] if result[17] else '{}'
|
381 |
-
shop_st_data = json.loads(shop_st)
|
382 |
-
logging.debug(f"Existing record found. Loaded JSON: {shop_st_data}")
|
383 |
-
else:
|
384 |
-
shop_st_data = {}
|
385 |
|
386 |
-
if del_flag == '1':
|
387 |
-
if order in shop_st_data:
|
388 |
-
del shop_st_data[order]
|
389 |
-
elif order and status:
|
390 |
-
shop_st_data[order] = status
|
391 |
-
|
392 |
-
shop_st_json = json.dumps(shop_st_data)
|
393 |
-
|
394 |
-
utc_now = datetime.utcnow()
|
395 |
-
msk_tz = pytz.timezone('Europe/Moscow')
|
396 |
-
msk_now = utc_now.replace(tzinfo=pytz.utc).astimezone(msk_tz)
|
397 |
-
data_on = msk_now.strftime('%Y-%m-%d %H:%M:%S')
|
398 |
-
|
399 |
-
# Преобразуем prog в целое число, если оно не пустое
|
400 |
-
prog = int(prog) if prog else None
|
401 |
-
|
402 |
-
columns_to_update = ['name', 'phone', 'email', 'vk_id', 'fin_prog', 'orders', 'n_con', 'data_on']
|
403 |
-
values_to_update = [name, phone, email, vkid, prog, shop_st_json, n_con_flag, data_on]
|
404 |
-
|
405 |
-
if result:
|
406 |
-
set_clause = ', '.join([f"{col} = ?" for col in columns_to_update])
|
407 |
-
query = f"UPDATE contacts SET {set_clause} WHERE email = ? OR phone = ?"
|
408 |
-
cursor.execute(query, values_to_update + [email, phone])
|
409 |
-
else:
|
410 |
-
query = f"INSERT INTO contacts ({', '.join(columns_to_update)}) VALUES ({', '.join(['?' for _ in columns_to_update])})"
|
411 |
-
cursor.execute(query, values_to_update)
|
412 |
-
|
413 |
-
conn.commit()
|
414 |
-
|
415 |
-
replace_null_with_empty_string(conn)
|
416 |
-
|
417 |
-
conn.close()
|
418 |
-
|
419 |
-
return json.dumps(shop_st_data), 200
|
420 |
-
|
421 |
-
except Exception as e:
|
422 |
-
logging.error(f"An error occurred: {str(e)}")
|
423 |
-
return json.dumps({"error": str(e)}), 500
|
424 |
|
425 |
|
426 |
|
|
|
343 |
logging.error(f"An error occurred: {str(e)}")
|
344 |
return json.dumps({"error": str(e)}), 500
|
345 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
346 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
347 |
|
348 |
|
349 |
|