fix🐛: 修复开箱时最后开箱日期数据未更新

This commit is contained in:
HibiKier 2023-08-21 00:31:18 +08:00
parent 0a4df8296e
commit 6519ed7101
4 changed files with 27 additions and 10 deletions

View File

@ -334,6 +334,7 @@ PS: **ARM平台** 请使用全量版 同时 **如果你的机器 RAM < 1G 可能
### 2022/8/20
* 修复词条回答包含at时使用模糊|正则等问时无法正确匹配问题
* 修复开箱时最后开箱日期数据未更新
### 2023/8/7

View File

@ -1,3 +1,5 @@
from datetime import datetime
from tortoise import fields
from services.db_context import Model
@ -39,7 +41,7 @@ class OpenCasesUser(Model):
"""赚取金币"""
today_open_total: int = fields.IntField(default=0)
"""今日开箱数量"""
open_cases_time_last = fields.DatetimeField()
open_cases_time_last: datetime = fields.DatetimeField()
"""最后开箱日期"""
knifes_name: str = fields.TextField(default="")
"""已获取金色"""

View File

@ -122,7 +122,10 @@ async def open_case(user_id: str, group_id: int, case_name: str) -> Union[str, M
case_price = case_skin.sell_min_price
user.today_open_total += 1
user.total_count += 1
await user.save(update_fields=["today_open_total", "total_count"])
user.open_cases_time_last = datetime.now()
await user.save(
update_fields=["today_open_total", "total_count", "open_cases_time_last"]
)
add_count(user, skin, case_price)
ridicule_result = random.choice(RESULT_MESSAGE[skin.color])
price_result = skin.sell_min_price
@ -203,7 +206,10 @@ async def open_multiple_case(
now = datetime.now()
user.today_open_total += num
user.total_count += num
await user.save(update_fields=["today_open_total", "total_count"])
user.open_cases_time_last = datetime.now()
await user.save(
update_fields=["today_open_total", "total_count", "open_cases_time_last"]
)
case_price = 0
if case_skin := await BuffSkin.get_or_none(case_name=case_name, color="CASE"):
case_price = case_skin.sell_min_price
@ -275,8 +281,12 @@ def _handle_is_MAX_COUNT() -> str:
return f"今天已达开箱上限了喔,明天再来吧\n(提升好感度可以增加每日开箱数 #疯狂暗示)"
async def total_open_statistics(user_id: str, group: str) -> str:
user, _ = await OpenCasesUser.get_or_create(user_id=user_id, group_id=group)
async def total_open_statistics(
user_id: Union[str, int], group_id: Union[str, int]
) -> str:
user, _ = await OpenCasesUser.get_or_create(
user_id=str(user_id), group_id=str(group_id)
)
return (
f"开箱总数:{user.total_count}\n"
f"今日开箱:{user.today_open_total}\n"
@ -296,8 +306,8 @@ async def total_open_statistics(user_id: str, group: str) -> str:
)
async def group_statistics(group: str):
user_list = await OpenCasesUser.filter(group_id=group).all()
async def group_statistics(group_id: Union[int, str]):
user_list = await OpenCasesUser.filter(group_id=str(group_id)).all()
# lan zi fen hong jin pricei
uplist = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0, 0, 0]
for user in user_list:
@ -332,7 +342,9 @@ async def group_statistics(group: str):
)
async def get_my_knifes(user_id: str, group_id: str) -> Union[str, MessageSegment]:
async def get_my_knifes(
user_id: Union[str, int], group_id: Union[str, int]
) -> Union[str, MessageSegment]:
"""获取我的金色
Args:
@ -342,7 +354,7 @@ async def get_my_knifes(user_id: str, group_id: str) -> Union[str, MessageSegmen
Returns:
Union[str, MessageSegment]: 回复消息或图片
"""
data_list = await get_old_knife(user_id, group_id)
data_list = await get_old_knife(str(user_id), str(group_id))
data_list += await OpenCasesLog.filter(
user_id=user_id, group_id=group_id, color="KNIFE"
).all()

View File

@ -48,7 +48,9 @@ async def init():
if not i_bind:
i_bind = f"{sql_name}://{user}:{password}@{address}:{port}/{database}"
try:
await Tortoise.init(db_url=i_bind, modules={"models": MODELS})
await Tortoise.init(
db_url=i_bind, modules={"models": MODELS}, timezone="Asia/Shanghai"
)
await Tortoise.generate_schemas()
logger.info(f"Database loaded successfully!")
except Exception as e: