fix: if user did not purchased 6 ticket before.

This commit is contained in:
7a1dd609-d238-4580-9d5f-ee8412b0f5bc 2025-01-14 00:01:06 +08:00
parent ef817446bf
commit 3bce3545fc

118
host.py
View File

@ -72,47 +72,83 @@ def ticket():
userId = int(userId) userId = int(userId)
timestamp = int(time.time()) timestamp = int(time.time())
charge_data = charge(userId) charge_data = charge(userId)
if charge_data['userChargeList'][2]['stock'] == 0: i = 0
login_data = login(userId, timestamp) while i < 10:
if login_data['returnCode'] == 102: try:
returnCode = 403 if charge_data['userChargeList'][i]['chargeId'] == 6 and charge_data['userChargeList'][i]['stock'] == 0:
status = "403 Forbidden" login_data = login(userId, timestamp)
info = "Unable to operate. Please refresh QrCode." if login_data['returnCode'] == 102:
log = [] returnCode = 403
elif login_data['returnCode'] == 100: status = "403 Forbidden"
returnCode = 403 info = "Unable to operate. Please refresh QrCode."
status = "403 Forbidden" log = []
info = "Unable to operate. Probably User has logged in." break
log = [] elif login_data['returnCode'] == 100:
elif login_data['returnCode'] == 1: returnCode = 403
ticket_data = get_ticket(userId) status = "403 Forbidden"
if ticket_data['returnCode'] == 0: info = "Unable to operate. Probably User has logged in."
logout(userId, timestamp) log = []
returnCode = 405 break
status = "405 Method Not Allowed" elif login_data['returnCode'] == 1:
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." ticket_data = get_ticket(userId)
log = {"UserLoginApiStatus": 1, "UserLogoutApiStatus": 1} if ticket_data['returnCode'] == 0:
elif ticket_data['returnCode'] == 1: logout(userId, timestamp)
logout(userId, timestamp) returnCode = 405
returnCode = 200 status = "405 Method Not Allowed"
status = "200 OK" 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 = "Succeed." log = {"UserLoginApiStatus": 1, "UserLogoutApiStatus": 1}
log = {"UserLoginApiStatus": 1, "UpsertUserChargelogStatus": 1, "UserLogoutApiStatus": 1} break
else: elif ticket_data['returnCode'] == 1:
returnCode = 500 logout(userId, timestamp)
status = "500 Internal Server Error" returnCode = 200
info = "Unknown Error. Failed in UserLogin" status = "200 OK"
log = login_data info = "Succeed."
elif charge_data['userChargeList'][2]['stock'] == 1: log = {"UserLoginApiStatus": 1, "UpsertUserChargelogStatus": 1, "UserLogoutApiStatus": 1}
returnCode = 403 break
status = "403 Forbidden" elif charge_data['userChargeList'][i]['chargeId'] == 6 and charge_data['userChargeList'][i]['stock'] == 1:
info = "User has had a ticket." returnCode = 403
log = [] status = "403 Forbidden"
else: info = "User has had a ticket."
returnCode = 500 log = []
status = "500 Internal Server Error" break
info = "Unknown Error. Failed in GetUserCharge" else:
log = charge_data 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