diff --git a/core/db/models.py b/core/db/models.py index a68a3f2..aaadf17 100644 --- a/core/db/models.py +++ b/core/db/models.py @@ -6,7 +6,7 @@ # @Desc : import enum import uuid -from datetime import datetime, date +from datetime import datetime, date, timedelta from typing import List import ujson @@ -54,6 +54,11 @@ class DateModel: onupdate=func.current_timestamp(), comment='更新时间') +def set_default_vip_expire_date() -> date: + expire_date = (datetime.now() - timedelta(days=1)) + return expire_date.date() + + class User(BaseModel, DateModel): __tablename__ = 'system_users' __table_args__ = ( @@ -73,7 +78,7 @@ class User(BaseModel, DateModel): wechat_openid: Mapped[str] = mapped_column(String(100), comment='微信openid') wechat_union_id: Mapped[str] = mapped_column(String(100), nullable=True, comment='微信unionid') phone: Mapped[str] = mapped_column(String(11), nullable=True, comment='手机号码') - vip_expire_date: Mapped[date] = mapped_column(Date, default=datetime.now().date, comment='会员到期时间') + vip_expire_date: Mapped[date] = mapped_column(Date, default=set_default_vip_expire_date, comment='会员到期时间') points: Mapped[int] = mapped_column(Integer, default=0, comment='会员积分') collections: Mapped[list['UserCollection']] = relationship( diff --git a/core/routers/pay/actions.py b/core/routers/pay/actions.py index 93508c0..3e663fd 100644 --- a/core/routers/pay/actions.py +++ b/core/routers/pay/actions.py @@ -47,7 +47,7 @@ async def actions_after_payment( await db_crud.update( model=User, data={ - 'vip_expire_date': vip_expire_date + 'vip_expire_date': vip_expire_date.date() }, filters={'user_id': order.user_id} )