fix: 禁止过期充值单补开通 + 管理命令收回错误恢复会员
rollback_erroneous_member_restore:后台已减仍有效、充值单已过期仍显示有效。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -634,6 +634,60 @@ def _czjilu_entitlement_revoked(order):
|
||||
return ENTITLEMENT_REVOKED_MARKER in (getattr(order, 'shuoming', None) or '')
|
||||
|
||||
|
||||
def _czjilu_entitlement_end(order, club_id=None):
|
||||
"""充值单对应权益的原定到期时刻(CreateTime + purchase_days)。"""
|
||||
from jituan.services.huiyuan_bundle import _normalize_datetime_for_compare
|
||||
|
||||
cid = getattr(order, 'club_id', None) or club_id or CLUB_ID_DEFAULT
|
||||
is_trial = _order_is_trial_like(order, cid)
|
||||
days = int(getattr(order, 'purchase_days', None) or 0)
|
||||
if days <= 0:
|
||||
_, _, days = club_huiyuan_sellable(cid, order.huiyuan_id, is_trial=is_trial)
|
||||
days = max(int(days or 0), 1)
|
||||
start = _normalize_datetime_for_compare(order.CreateTime or timezone.now())
|
||||
return start + timedelta(days=days)
|
||||
|
||||
|
||||
def czjilu_entitlement_active(order, club_id=None):
|
||||
"""充值单权益是否仍在原定期限内(未撤销且未过期)。"""
|
||||
if not order or _czjilu_entitlement_revoked(order):
|
||||
return False
|
||||
from jituan.services.huiyuan_bundle import _normalize_datetime_for_compare
|
||||
now = _normalize_datetime_for_compare(timezone.now())
|
||||
return _czjilu_entitlement_end(order, club_id) > now
|
||||
|
||||
|
||||
def user_has_active_czjilu_entitlement(yonghu_id, huiyuan_id, club_id=None):
|
||||
"""用户是否仍有未过期的已付充值单支撑该会员类型。"""
|
||||
from jituan.services.huiyuan_bundle import huiyuan_ids_match
|
||||
|
||||
for order in Czjilu.query.filter(
|
||||
yonghuid=yonghu_id,
|
||||
leixing=MEMBER_LEIXING,
|
||||
zhuangtai=MEMBER_PAID_STATUS,
|
||||
).order_by('-CreateTime'):
|
||||
if not huiyuan_ids_match(order.huiyuan_id, huiyuan_id):
|
||||
continue
|
||||
if czjilu_entitlement_active(order, club_id):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def expire_huiyuangoumai_record(rec, reason=''):
|
||||
"""将会员记录置为已过期(不删行,便于审计)。"""
|
||||
from jituan.services.huiyuan_bundle import _normalize_datetime_for_compare
|
||||
|
||||
now = _normalize_datetime_for_compare(timezone.now())
|
||||
rec.daoqi_time = now - timedelta(seconds=1)
|
||||
rec.huiyuan_zhuangtai = 0
|
||||
rec.save(update_fields=['daoqi_time', 'huiyuan_zhuangtai', 'UpdateTime'])
|
||||
logger.warning(
|
||||
'会员权益已收回 yonghu=%s huiyuan=%s reason=%s',
|
||||
rec.yonghu_id, rec.huiyuan_id, reason or 'cleanup',
|
||||
)
|
||||
return True
|
||||
|
||||
|
||||
def repair_member_entitlement_if_paid(dingdan_id):
|
||||
order = Czjilu.query.filter(dingdan_id=dingdan_id, leixing=MEMBER_LEIXING).first()
|
||||
if not order or order.zhuangtai != MEMBER_PAID_STATUS or not order.huiyuan_id:
|
||||
@@ -659,6 +713,8 @@ def repair_member_entitlement_if_paid(dingdan_id):
|
||||
if days <= 0:
|
||||
_, _, days = club_huiyuan_sellable(club_id, order.huiyuan_id, is_trial=is_trial)
|
||||
days = max(int(days or 0), 1)
|
||||
if not czjilu_entitlement_active(order, club_id):
|
||||
return False
|
||||
with transaction.atomic():
|
||||
_apply_huiyuan_entitlement(
|
||||
order.yonghuid, order.huiyuan_id, huiyuan, club_id, is_trial, days,
|
||||
|
||||
Reference in New Issue
Block a user