fix: 迁移预览兼容naive时间;无资产不强制进迁移页
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -261,6 +261,29 @@ def preview_assets(plan: ClubMigratePlan, from_uid: str) -> List[dict]:
|
||||
return items
|
||||
|
||||
|
||||
def asset_item_has_value(item: dict) -> bool:
|
||||
"""预览项是否有可迁金额/积分/会员。"""
|
||||
kind = (item or {}).get('kind') or ''
|
||||
if kind == 'huiyuan':
|
||||
return True
|
||||
try:
|
||||
if kind == 'int':
|
||||
return int(item.get('amount') or 0) > 0
|
||||
return _money(item.get('amount')) > 0
|
||||
except (TypeError, ValueError):
|
||||
return False
|
||||
|
||||
|
||||
def user_has_migratable_assets(plan: ClubMigratePlan, from_uid: str) -> bool:
|
||||
"""白名单内是否有任意可迁资产;全无则不应强制进迁移页。"""
|
||||
try:
|
||||
items = preview_assets(plan, from_uid)
|
||||
except Exception as e:
|
||||
logger.warning('migrate asset check failed uid=%s: %s', from_uid, e)
|
||||
return True # 检查失败时保守:仍允许进页,避免误放行有资产用户
|
||||
return any(asset_item_has_value(it) for it in items)
|
||||
|
||||
|
||||
def _preview_huiyuan(uid: str, club_id: str, role: str) -> List[dict]:
|
||||
from products.models import Huiyuan, Huiyuangoumai
|
||||
|
||||
@@ -283,7 +306,7 @@ def _preview_huiyuan(uid: str, club_id: str, role: str) -> List[dict]:
|
||||
out = []
|
||||
for r in rows:
|
||||
name = (r.jieshao or '').strip() or name_map.get(r.huiyuan_id) or '会员'
|
||||
exp = r.daoqi_time
|
||||
exp = _aware(r.daoqi_time)
|
||||
exp_text = timezone.localtime(exp).strftime('%Y-%m-%d %H:%M') if exp else ''
|
||||
out.append({
|
||||
'key': f'{role}.huiyuan:{r.huiyuan_id}',
|
||||
@@ -572,12 +595,16 @@ def gate_for_user(*, club_id: str, user_uid: str, roles: Optional[List[str]] = N
|
||||
role_hit = True
|
||||
if roles:
|
||||
role_hit = any(r in force_roles for r in roles)
|
||||
force = bool(plan.force_intercept and role_hit and not done)
|
||||
has_assets = user_has_migratable_assets(plan, user_uid)
|
||||
# 白名单角色下完全无资产:不强制、不展示入口
|
||||
force = bool(plan.force_intercept and role_hit and not done and has_assets)
|
||||
show_entry = bool(has_assets and not done)
|
||||
return {
|
||||
'active': True,
|
||||
'force': force,
|
||||
'show_entry': True,
|
||||
'show_entry': show_entry,
|
||||
'completed': done,
|
||||
'has_assets': has_assets,
|
||||
'plan_id': plan.plan_id,
|
||||
'plan_name': plan.name or '',
|
||||
'from_club_id': plan.from_club_id,
|
||||
|
||||
Reference in New Issue
Block a user