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