From 9ce1ebbb98316d55c4f49b704d5b27c6abe7c992 Mon Sep 17 00:00:00 2001 From: xingc Date: Wed, 7 May 2025 17:42:28 +0800 Subject: [PATCH] =?UTF-8?q?feat(card):=20=E6=96=B0=E5=A2=9E=E9=9D=9E?= =?UTF-8?q?=E4=BC=9A=E5=91=98=E5=8D=A1=E7=89=87=E5=B1=95=E7=A4=BA=E9=99=90?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/routers/card/routes.py | 8 ++++++++ core/routers/card/services.py | 16 ++++++++++++++-- core/wechat/api.py | 2 +- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/core/routers/card/routes.py b/core/routers/card/routes.py index 49455d3..276d1b6 100644 --- a/core/routers/card/routes.py +++ b/core/routers/card/routes.py @@ -294,6 +294,14 @@ async def display_card_status( login_user: LoginUser = Depends(get_current_user_form_http), db_session: AsyncSession = Depends(get_async_session) ): + # 确认用户展示卡权限 + if await check_user_card_created_permission( + db_session, login_user=login_user, other_conditions={'displayed': True} + ) is False and action == 'displayed': + raise HTTPException( + status_code=status.HTTP_400_BAD_REQUEST, detail=f'非会员仅支持展示{settings.USER_MAX_CREATED_CARD_NUM}张卡片' + ) + db_crud = CRUD(db_session, UserCollection) result = await db_crud.updates( data={ diff --git a/core/routers/card/services.py b/core/routers/card/services.py index 10187f2..d1d6361 100644 --- a/core/routers/card/services.py +++ b/core/routers/card/services.py @@ -4,6 +4,8 @@ # @Software : PyCharm # @Author : xingc # @Desc : +from typing import Dict + from sqlalchemy import select from sqlalchemy.ext.asyncio import AsyncSession @@ -22,11 +24,21 @@ async def get_cache_card_by_number(db_session: AsyncSession, *, cert_number: str return card -async def check_user_card_created_permission(db_session: AsyncSession, *, login_user: LoginUser) -> bool: +async def check_user_card_created_permission( + db_session: AsyncSession, *, login_user: LoginUser, other_conditions: Dict = None +) -> bool: + if other_conditions is None: + other_conditions = {} + db_crud = CRUD(db_session, User) user = await db_crud.get(filters={'user_id': login_user.user_id}) if user.is_vip(): return True - total = await db_crud.total(model=UserCollection, filters={'user_id': login_user.user_id}) + total = await db_crud.total( + model=UserCollection, filters={ + 'user_id': login_user.user_id, + **other_conditions + } + ) return settings.USER_MAX_CREATED_CARD_NUM > total diff --git a/core/wechat/api.py b/core/wechat/api.py index e18a832..0f85d10 100644 --- a/core/wechat/api.py +++ b/core/wechat/api.py @@ -154,7 +154,7 @@ class WechatPayApi(BaseClient): def generate_sign(self, params: dict) -> str: """生成签名""" - plaintext = '&'.join([f'{k}={params[k]}' for k in sorted(params.keys())]) + plaintext = '&'.join([f'{k}={v}' for k, v in sorted(params.items()) if v]) return md5(f'{plaintext}&key={self.appi_key}').upper() def generate_payment_params(self, prepay_id) -> dict: