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