feat(card): 新增非会员卡片展示限制

This commit is contained in:
xingc
2025-05-07 17:42:28 +08:00
parent 30a03efd3b
commit 9ce1ebbb98
3 changed files with 23 additions and 3 deletions

View File

@@ -294,6 +294,14 @@ async def display_card_status(
login_user: LoginUser = Depends(get_current_user_form_http), login_user: LoginUser = Depends(get_current_user_form_http),
db_session: AsyncSession = Depends(get_async_session) 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) db_crud = CRUD(db_session, UserCollection)
result = await db_crud.updates( result = await db_crud.updates(
data={ data={

View File

@@ -4,6 +4,8 @@
# @Software : PyCharm # @Software : PyCharm
# @Author : xingc # @Author : xingc
# @Desc : # @Desc :
from typing import Dict
from sqlalchemy import select from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession 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 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) db_crud = CRUD(db_session, User)
user = await db_crud.get(filters={'user_id': login_user.user_id}) user = await db_crud.get(filters={'user_id': login_user.user_id})
if user.is_vip(): if user.is_vip():
return True 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 return settings.USER_MAX_CREATED_CARD_NUM > total

View File

@@ -154,7 +154,7 @@ class WechatPayApi(BaseClient):
def generate_sign(self, params: dict) -> str: 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() return md5(f'{plaintext}&key={self.appi_key}').upper()
def generate_payment_params(self, prepay_id) -> dict: def generate_payment_params(self, prepay_id) -> dict: