fix: 优化发票判断是否有票校验逻辑

This commit is contained in:
7a1dd609-d238-4580-9d5f-ee8412b0f5bc 2025-01-15 01:30:27 +08:00
parent 3bce3545fc
commit 1f5988a145

119
host.py
View File

@ -71,84 +71,37 @@ def ticket():
else: else:
userId = int(userId) userId = int(userId)
timestamp = int(time.time()) timestamp = int(time.time())
charge_data = charge(userId) if '{"chargeId": 6, "stock": 1' in json.dumps(charge(userId)):
i = 0 returnCode = 403
while i < 10: status = "403 Forbidden"
try: info = "User has had a ticket."
if charge_data['userChargeList'][i]['chargeId'] == 6 and charge_data['userChargeList'][i]['stock'] == 0: log = {}
login_data = login(userId, timestamp) else:
if login_data['returnCode'] == 102: login_data = login(userId, timestamp)
returnCode = 403 if login_data['returnCode'] == 102:
status = "403 Forbidden" returnCode = 403
info = "Unable to operate. Please refresh QrCode." status = "403 Forbidden"
log = [] info = "Unable to operate. Please refresh QrCode."
break log = {}
elif login_data['returnCode'] == 100: elif login_data['returnCode'] == 100:
returnCode = 403 returnCode = 403
status = "403 Forbidden" status = "403 Forbidden"
info = "Unable to operate. Probably User has logged in." info = "Unable to operate. Probably User has logged in."
log = [] log = {}
break elif login_data['returnCode'] == 1:
elif login_data['returnCode'] == 1: ticket_data = get_ticket(userId)
ticket_data = get_ticket(userId) if ticket_data['returnCode'] == 0:
if ticket_data['returnCode'] == 0: logout(userId, timestamp)
logout(userId, timestamp) returnCode = 405
returnCode = 405 status = "405 Method Not Allowed"
status = "405 Method Not Allowed" info = "WARNING: THIS INFO SHOULD NEVER APPEARS. IF YOU SEE THIS WARNING PLEASE CONTACT Telegram@sasakure. Unable to operate. Successfully Logged in. Probably User has had one ticket."
info = "WARNING: THIS INFO SHOULD NEVER APPEARS. IF YOU SEE THIS WARNING PLEASE CONTACT Telegram@sasakure. Unable to operate. Successfully Logged in. Probably User has had one ticket." log = {"UserLoginApiStatus": 1, "UserLogoutApiStatus": 1}
log = {"UserLoginApiStatus": 1, "UserLogoutApiStatus": 1} elif ticket_data['returnCode'] == 1:
break logout(userId, timestamp)
elif ticket_data['returnCode'] == 1: returnCode = 200
logout(userId, timestamp) status = "200 OK"
returnCode = 200 info = "Succeed."
status = "200 OK" log = {"UserLoginApiStatus": 1, "UpsertUserChargelogStatus": 1, "UserLogoutApiStatus": 1}
info = "Succeed."
log = {"UserLoginApiStatus": 1, "UpsertUserChargelogStatus": 1, "UserLogoutApiStatus": 1}
break
elif charge_data['userChargeList'][i]['chargeId'] == 6 and charge_data['userChargeList'][i]['stock'] == 1:
returnCode = 403
status = "403 Forbidden"
info = "User has had a ticket."
log = []
break
else:
i = i + 1
except IndexError:
login_data = login(userId, timestamp)
if login_data['returnCode'] == 102:
returnCode = 403
status = "403 Forbidden"
info = "Unable to operate. Please refresh QrCode."
log = []
break
elif login_data['returnCode'] == 100:
returnCode = 403
status = "403 Forbidden"
info = "Unable to operate. Probably User has logged in."
log = []
break
elif login_data['returnCode'] == 1:
ticket_data = get_ticket(userId)
if ticket_data['returnCode'] == 0:
logout(userId, timestamp)
returnCode = 405
status = "405 Method Not Allowed"
info = "WARNING: THIS INFO SHOULD NEVER APPEARS. IF YOU SEE THIS WARNING PLEASE CONTACT Telegram@sasakure. Unable to operate. Successfully Logged in. Probably User has had one ticket."
log = {"UserLoginApiStatus": 1, "UserLogoutApiStatus": 1}
break
elif ticket_data['returnCode'] == 1:
logout(userId, timestamp)
returnCode = 200
status = "200 OK"
info = "Succeed."
log = {"UserLoginApiStatus": 1, "UpsertUserChargelogStatus": 1, "UserLogoutApiStatus": 1}
break
else:
returnCode = 500
status = "500 Internal Server Error"
info = "Unknown Error. Failed in UserLogin"
log = login_data
break
data = jsonify({"status": status, "timestamp": timestamp, "info": info, "apiName": "ticket", "date": datetime.now(pytz.timezone('Asia/Shanghai')).strftime('%a, %d %b %Y %H:%M:%S GMT+8'), "userId": userId}) data = jsonify({"status": status, "timestamp": timestamp, "info": info, "apiName": "ticket", "date": datetime.now(pytz.timezone('Asia/Shanghai')).strftime('%a, %d %b %Y %H:%M:%S GMT+8'), "userId": userId})
return data, returnCode return data, returnCode
@ -165,12 +118,12 @@ def mapstock_process():
returnCode = 403 returnCode = 403
status = "403 Forbidden" status = "403 Forbidden"
info = "Unable to operate. Please refresh QrCode." info = "Unable to operate. Please refresh QrCode."
log = [] log = {}
elif login_data['returnCode'] == 100: elif login_data['returnCode'] == 100:
returnCode = 403 returnCode = 403
status = "403 Forbidden" status = "403 Forbidden"
info = "Unable to operate. Probably User has logged in." info = "Unable to operate. Probably User has logged in."
log = [] log = {}
elif login_data['returnCode'] == 1: elif login_data['returnCode'] == 1:
userdata_result = userdata(userId) userdata_result = userdata(userId)
logout(userId, timestamp) logout(userId, timestamp)
@ -178,7 +131,7 @@ def mapstock_process():
returnCode = 403 returnCode = 403
status = "403 Forbidden" status = "403 Forbidden"
info = "User has stocked 99 kilometers." info = "User has stocked 99 kilometers."
log = [] log = {}
else: else:
while True: while True:
login(userId, timestamp) login(userId, timestamp)
@ -230,12 +183,12 @@ def music_post():
returnCode = 403 returnCode = 403
status = "403 Forbidden" status = "403 Forbidden"
info = "Unable to operate. Please refresh QrCode." info = "Unable to operate. Please refresh QrCode."
log = [] log = {}
elif login_data['returnCode'] == 100: elif login_data['returnCode'] == 100:
returnCode = 403 returnCode = 403
status = "403 Forbidden" status = "403 Forbidden"
info = "Unable to operate. Probably User has logged in." info = "Unable to operate. Probably User has logged in."
log = [] log = {}
elif login_data['returnCode'] == 1: elif login_data['returnCode'] == 1:
logout(userId, timestamp) logout(userId, timestamp)
music_data = request_data['music'] music_data = request_data['music']