From 4c1e6a36c294e66c6099c61615cc4b9092e2fb1e Mon Sep 17 00:00:00 2001 From: xingc Date: Mon, 28 Apr 2025 18:23:25 +0800 Subject: [PATCH] =?UTF-8?q?feat(user):=20=E4=B8=A5=E6=A0=BC=E4=BC=9A?= =?UTF-8?q?=E5=91=98=E9=BB=98=E8=AE=A4=E8=BF=87=E6=9C=9F=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/db/models.py | 9 +++++++-- core/routers/pay/actions.py | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) 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} )