feat(card): 新增非会员卡片展示限制
This commit is contained in:
@@ -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={
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user