74 lines
2.5 KiB
Python
74 lines
2.5 KiB
Python
import rapidjson as json
|
|
import pytz
|
|
from datetime import datetime, timedelta
|
|
|
|
from Config import *
|
|
from API_TitleServer import apiSDGB
|
|
from HelperGetUserThing import implGetUser_
|
|
|
|
from loguru import logger
|
|
from HelperLogInOut import apiLogin, apiLogout, generateTimestamp
|
|
from HelperFullPlay import implFullPlayAction, generateMusicData
|
|
from HelperGetUserThing import implGetUser_
|
|
|
|
def implWipeTickets(userId: int, currentLoginTimestamp:int, currentLoginResult) -> str:
|
|
|
|
currentUserCharge = implGetUser_("Charge", userId)
|
|
currentUserChargeList = currentUserCharge['userChargeList']
|
|
for charge in currentUserChargeList:
|
|
charge['stock'] = 0
|
|
|
|
musicData = generateMusicData()
|
|
userAllPatches = {
|
|
"upsertUserAll": {
|
|
"userChargeList": currentUserChargeList,
|
|
"userMusicDetailList": [musicData],
|
|
"isNewMusicDetailList": "1"
|
|
}}
|
|
|
|
result = implFullPlayAction(userId, currentLoginTimestamp, currentLoginResult, musicData, userAllPatches)
|
|
return result
|
|
|
|
def apiQueryTicket(userId:int) -> str:
|
|
data = json.dumps({
|
|
"userId": userId
|
|
})
|
|
userdata_result = apiSDGB(data, "GetUserChargeApi", userId)
|
|
return userdata_result
|
|
|
|
def apiBuyTicket(userId:int, ticketType:int, price:int, playerRating:int, playCount:int) -> str:
|
|
|
|
nowTime = datetime.now(pytz.timezone('Asia/Shanghai'))
|
|
|
|
|
|
data = json.dumps({
|
|
"userId": userId,
|
|
"userChargelog": {
|
|
"chargeId": ticketType,
|
|
"price": price,
|
|
"purchaseDate": nowTime.strftime("%Y-%m-%d %H:%M:%S.0"),
|
|
"playCount": playCount,
|
|
"playerRating": playerRating,
|
|
"placeId": placeId,
|
|
"regionId": regionId,
|
|
"clientId": clientId
|
|
},
|
|
"userCharge": {
|
|
"chargeId": ticketType,
|
|
"stock": 1,
|
|
"purchaseDate": nowTime.strftime("%Y-%m-%d %H:%M:%S.0"),
|
|
"validDate": (nowTime + timedelta(days=90)).replace(hour=4, minute=0, second=0).strftime("%Y-%m-%d %H:%M:%S")
|
|
}
|
|
})
|
|
return apiSDGB(data, "UpsertUserChargelogApi", userId)
|
|
|
|
def implBuyTicket(userId:int, ticketType:int):
|
|
currentUserData = implGetUser_("Data", userId)
|
|
if currentUserData:
|
|
playerRating = currentUserData['userData']['playerRating']
|
|
playCount = currentUserData['userData'].get('playCount', 0)
|
|
else:
|
|
return False
|
|
getTicketResponseStr = apiBuyTicket(userId, ticketType, ticketType-1, playerRating, playCount)
|
|
return getTicketResponseStr
|