fix: 抢单池 clumber 只读合并有效期内充值单,体验会员按正式展示
不写库、不 sync;修复体验单已付但 huiyuangoumai 未落库时老端显示未开通。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -311,20 +311,38 @@ def _build_user_clumber_core(yonghu_id):
|
||||
return items
|
||||
|
||||
|
||||
def _merge_clumber_extra_items(items, extra):
|
||||
"""只读合并:有效期内充值单合成的会员条目补进 clumber(体验=正式)。"""
|
||||
if not extra:
|
||||
return items
|
||||
seen_cores = set()
|
||||
for it in items:
|
||||
hid = normalize_huiyuan_id(it.get('huiyuanid') or it.get('huiyuan_id'))
|
||||
if hid:
|
||||
seen_cores.add(hid.lstrip('0') or '0')
|
||||
for it in extra:
|
||||
hid = normalize_huiyuan_id(it.get('huiyuanid') or it.get('huiyuan_id'))
|
||||
if not hid:
|
||||
continue
|
||||
core = hid.lstrip('0') or '0'
|
||||
if core in seen_cores:
|
||||
continue
|
||||
items.append(it)
|
||||
seen_cores.add(core)
|
||||
return items
|
||||
|
||||
|
||||
def _build_clumber_from_paid_czjilu(yonghu_id):
|
||||
"""huiyuangoumai 缺失时,用已支付会员充值单合成 clumber(体验=正式)。"""
|
||||
from jituan.constants import CLUB_ID_DEFAULT
|
||||
"""只读:huiyuangoumai 缺失时,用已支付会员充值单合成 clumber(体验=正式,不写库)。"""
|
||||
from jituan.services.member_recharge import (
|
||||
MEMBER_LEIXING,
|
||||
MEMBER_PAID_STATUS,
|
||||
_order_is_trial_like,
|
||||
club_huiyuan_sellable,
|
||||
czjilu_entitlement_active,
|
||||
)
|
||||
from products.models import Czjilu, Huiyuan
|
||||
|
||||
items = []
|
||||
seen = set()
|
||||
now = _normalize_datetime_for_compare(timezone.now())
|
||||
for order in Czjilu.query.filter(
|
||||
yonghuid=yonghu_id,
|
||||
leixing=MEMBER_LEIXING,
|
||||
@@ -333,21 +351,16 @@ def _build_clumber_from_paid_czjilu(yonghu_id):
|
||||
hid = normalize_huiyuan_id(order.huiyuan_id)
|
||||
if not hid:
|
||||
continue
|
||||
cid = getattr(order, 'club_id', None) 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, hid, is_trial=is_trial)
|
||||
days = max(int(days or 0), 1)
|
||||
start = _normalize_datetime_for_compare(order.CreateTime or now)
|
||||
daoqi = start + timedelta(days=days)
|
||||
if daoqi <= now:
|
||||
cid = getattr(order, 'club_id', None) or ''
|
||||
if not czjilu_entitlement_active(order, cid):
|
||||
continue
|
||||
try:
|
||||
hy = Huiyuan.query.get(huiyuan_id=hid)
|
||||
ming = hy.jieshao or f'会员{hid}'
|
||||
except Huiyuan.DoesNotExist:
|
||||
ming = f'会员{hid}'
|
||||
from jituan.services.member_recharge import _czjilu_entitlement_end
|
||||
daoqi = _czjilu_entitlement_end(order, cid)
|
||||
base = {
|
||||
'huiyuanming': ming,
|
||||
'daoqi': format_legacy_daoqi(daoqi),
|
||||
@@ -360,8 +373,8 @@ def _build_clumber_from_paid_czjilu(yonghu_id):
|
||||
|
||||
def ensure_grab_pool_clumber(yonghu_id, club_id=None):
|
||||
"""
|
||||
dddhq / dashouxinxi:只读 huiyuangoumai 生成 clumber(体验=正式)。
|
||||
不在每次请求全量 sync 充值单(后台移除后会被补回)。
|
||||
dddhq / dashouxinxi:只读 huiyuangoumai + 有效期内充值单 生成 clumber(体验=正式)。
|
||||
不写库、不全量 sync;仅在无任何会员时尝试补最近已付单(防回调丢失)。
|
||||
"""
|
||||
from jituan.services.member_recharge import repair_recent_paid_entitlements_if_missing
|
||||
|
||||
@@ -369,6 +382,7 @@ def ensure_grab_pool_clumber(yonghu_id, club_id=None):
|
||||
if not items:
|
||||
repair_recent_paid_entitlements_if_missing(yonghu_id, limit=3)
|
||||
items = _build_user_clumber_core(yonghu_id)
|
||||
items = _merge_clumber_extra_items(items, _build_clumber_from_paid_czjilu(yonghu_id))
|
||||
return bool(items), items
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user