Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -549,9 +549,9 @@ def shop_order_new():
|
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
-
# Работа из VK_ID Запись ордер
|
| 553 |
-
@app.route('/
|
| 554 |
-
def
|
| 555 |
try:
|
| 556 |
logging.debug("Starting shop_order_new")
|
| 557 |
api_sys_control = request.args.get('api_sys')
|
|
@@ -627,6 +627,86 @@ def write_or():
|
|
| 627 |
|
| 628 |
|
| 629 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 630 |
|
| 631 |
|
| 632 |
|
|
|
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
+
# Работа из VK_ID Запись ордер с полными данными
|
| 553 |
+
@app.route('/wr_order_vk_full', methods=['GET'])
|
| 554 |
+
def write_order_vk_full():
|
| 555 |
try:
|
| 556 |
logging.debug("Starting shop_order_new")
|
| 557 |
api_sys_control = request.args.get('api_sys')
|
|
|
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
+
|
| 631 |
+
|
| 632 |
+
|
| 633 |
+
# Работа из VK_ID только по VK ID
|
| 634 |
+
@app.route('/wr_order_vk', methods=['GET'])
|
| 635 |
+
def wr_order_vk():
|
| 636 |
+
try:
|
| 637 |
+
logging.debug("Starting shop_order_new")
|
| 638 |
+
api_sys_control = request.args.get('api_sys')
|
| 639 |
+
|
| 640 |
+
if api_sys_control != api_key_sys:
|
| 641 |
+
logging.warning("Unauthorized access attempt")
|
| 642 |
+
return json.dumps({"error": "Unauthorized access"}), 403
|
| 643 |
+
|
| 644 |
+
|
| 645 |
+
vkid = request.args.get('vk_id', '')
|
| 646 |
+
|
| 647 |
+
order = request.args.get('order', '')
|
| 648 |
+
status = request.args.get('status', '')
|
| 649 |
+
del_flag = request.args.get('del', '')
|
| 650 |
+
n_con_flag = request.args.get('n_con', '')
|
| 651 |
+
|
| 652 |
+
if not email or not phone:
|
| 653 |
+
logging.error("Email and phone are required")
|
| 654 |
+
return json.dumps({"error": "Email and phone are required"}), 400
|
| 655 |
+
|
| 656 |
+
phone = clean_phone_number_ss(phone)
|
| 657 |
+
|
| 658 |
+
conn = sqlite3.connect(DATABASE_NEW)
|
| 659 |
+
cursor = conn.cursor()
|
| 660 |
+
|
| 661 |
+
cursor.execute("SELECT * FROM contacts WHERE email = ? OR phone = ?", (email, phone))
|
| 662 |
+
result = cursor.fetchone()
|
| 663 |
+
|
| 664 |
+
if result:
|
| 665 |
+
shop_st = result[17] if result[17] else '{}'
|
| 666 |
+
shop_st_data = json.loads(shop_st)
|
| 667 |
+
logging.debug(f"Existing record found. Loaded JSON: {shop_st_data}")
|
| 668 |
+
else:
|
| 669 |
+
shop_st_data = {}
|
| 670 |
+
|
| 671 |
+
if del_flag == '1':
|
| 672 |
+
if order in shop_st_data:
|
| 673 |
+
del shop_st_data[order]
|
| 674 |
+
elif order and status:
|
| 675 |
+
shop_st_data[order] = status
|
| 676 |
+
|
| 677 |
+
shop_st_json = json.dumps(shop_st_data)
|
| 678 |
+
|
| 679 |
+
utc_now = datetime.utcnow()
|
| 680 |
+
msk_tz = pytz.timezone('Europe/Moscow')
|
| 681 |
+
msk_now = utc_now.replace(tzinfo=pytz.utc).astimezone(msk_tz)
|
| 682 |
+
data_on = msk_now.strftime('%Y-%m-%d %H:%M:%S')
|
| 683 |
+
|
| 684 |
+
columns_to_update = ['vk_id', 'orders', 'n_con', 'data_on']
|
| 685 |
+
values_to_update = [vkid, shop_st_json, n_con_flag, data_on]
|
| 686 |
+
|
| 687 |
+
if result:
|
| 688 |
+
set_clause = ', '.join([f"{col} = ?" for col in columns_to_update])
|
| 689 |
+
query = f"UPDATE contacts SET {set_clause} WHERE email = ? OR phone = ?"
|
| 690 |
+
cursor.execute(query, values_to_update + [email, phone])
|
| 691 |
+
else:
|
| 692 |
+
query = f"INSERT INTO contacts ({', '.join(columns_to_update)}) VALUES ({', '.join(['?' for _ in columns_to_update])})"
|
| 693 |
+
cursor.execute(query, values_to_update)
|
| 694 |
+
|
| 695 |
+
conn.commit()
|
| 696 |
+
|
| 697 |
+
replace_null_with_empty_string(conn)
|
| 698 |
+
|
| 699 |
+
conn.close()
|
| 700 |
+
|
| 701 |
+
return json.dumps(shop_st_data), 200
|
| 702 |
+
|
| 703 |
+
except Exception as e:
|
| 704 |
+
logging.error(f"An error occurred: {str(e)}")
|
| 705 |
+
return json.dumps({"error": str(e)}), 500
|
| 706 |
+
|
| 707 |
+
|
| 708 |
+
|
| 709 |
+
|
| 710 |
|
| 711 |
|
| 712 |
|