put the upsert into transactions, show all purchasable tickets

This commit is contained in:
2024-06-23 04:08:07 +07:00
parent f1b02a3bc6
commit f9bc8cedfc

View File

@ -1,6 +1,4 @@
import itertools
import logging
import json
from datetime import datetime, timedelta
import pytz
@ -131,19 +129,22 @@ class ChuniBase:
return {"length": 0, "gameChargeList": []}
charges = []
for x in range(len(game_charge_list)):
for _, charge_list in itertools.groupby(game_charge_list, key=lambda x: x["chargeId"] // 1000):
for price, charge in enumerate(charge_list):
charges.append(
{
"orderId": x,
"chargeId": game_charge_list[x]["chargeId"],
"price": 1,
"orderId": len(charges),
"chargeId": charge["chargeId"],
"price": price + 1,
"startDate": "2017-12-05 07:00:00.0",
"endDate": "2099-12-31 00:00:00.0",
"salePrice": 1,
"saleStartDate": "2017-12-05 07:00:00.0",
"saleStartDate": "2099-12-31 07:00:00.0",
"saleEndDate": "2099-12-31 00:00:00.0",
}
)
return {"length": len(charges), "gameChargeList": charges}
async def handle_get_game_event_api_request(self, data: Dict) -> Dict:
@ -787,6 +788,7 @@ class ChuniBase:
self.logger.info("Guest play from place ID %d, ignoring.", place_id)
return {"returnCode": "1"}
with self.data.session.begin():
if "userData" in upsert:
try:
upsert["userData"][0]["userName"] = self.read_wtf8(
@ -848,17 +850,6 @@ class ChuniBase:
for song in upsert["userMusicDetailList"]:
await self.data.score.put_score(user_id, song)
if "userPlaylogList" in upsert:
for playlog in upsert["userPlaylogList"]:
# convert the player names to utf-8
if playlog["playedUserName1"] is not None:
playlog["playedUserName1"] = self.read_wtf8(playlog["playedUserName1"])
if playlog["playedUserName2"] is not None:
playlog["playedUserName2"] = self.read_wtf8(playlog["playedUserName2"])
if playlog["playedUserName3"] is not None:
playlog["playedUserName3"] = self.read_wtf8(playlog["playedUserName3"])
await self.data.score.put_playlog(user_id, playlog, self.version)
if "userTeamPoint" in upsert:
team_points = upsert["userTeamPoint"]
try:
@ -901,17 +892,6 @@ class ChuniBase:
for rp in upsert["userRecentPlayerList"]:
pass
for rating_type in {"userRatingBaseList", "userRatingBaseHotList", "userRatingBaseNextList"}:
if rating_type not in upsert:
continue
await self.data.profile.put_profile_rating(
user_id,
self.version,
rating_type,
upsert[rating_type],
)
# added in LUMINOUS
if "userCMissionList" in upsert:
for cmission in upsert["userCMissionList"]:
@ -937,6 +917,29 @@ class ChuniBase:
)
await self.data.profile.put_net_battle(user_id, net_battle)
with self.data.session.begin():
for rating_type in {"userRatingBaseList", "userRatingBaseHotList", "userRatingBaseNextList"}:
if rating_type not in upsert:
continue
await self.data.profile.put_profile_rating(
user_id,
self.version,
rating_type,
upsert[rating_type],
)
if "userPlaylogList" in upsert:
for playlog in upsert["userPlaylogList"]:
# convert the player names to utf-8
if playlog["playedUserName1"] is not None:
playlog["playedUserName1"] = self.read_wtf8(playlog["playedUserName1"])
if playlog["playedUserName2"] is not None:
playlog["playedUserName2"] = self.read_wtf8(playlog["playedUserName2"])
if playlog["playedUserName3"] is not None:
playlog["playedUserName3"] = self.read_wtf8(playlog["playedUserName3"])
await self.data.score.put_playlog(user_id, playlog, self.version)
return {"returnCode": "1"}
async def handle_upsert_user_chargelog_api_request(self, data: Dict) -> Dict: