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
|
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):
|
def _build_clumber_from_paid_czjilu(yonghu_id):
|
||||||
"""huiyuangoumai 缺失时,用已支付会员充值单合成 clumber(体验=正式)。"""
|
"""只读:huiyuangoumai 缺失时,用已支付会员充值单合成 clumber(体验=正式,不写库)。"""
|
||||||
from jituan.constants import CLUB_ID_DEFAULT
|
|
||||||
from jituan.services.member_recharge import (
|
from jituan.services.member_recharge import (
|
||||||
MEMBER_LEIXING,
|
MEMBER_LEIXING,
|
||||||
MEMBER_PAID_STATUS,
|
MEMBER_PAID_STATUS,
|
||||||
_order_is_trial_like,
|
czjilu_entitlement_active,
|
||||||
club_huiyuan_sellable,
|
|
||||||
)
|
)
|
||||||
from products.models import Czjilu, Huiyuan
|
from products.models import Czjilu, Huiyuan
|
||||||
|
|
||||||
items = []
|
items = []
|
||||||
seen = set()
|
seen = set()
|
||||||
now = _normalize_datetime_for_compare(timezone.now())
|
|
||||||
for order in Czjilu.query.filter(
|
for order in Czjilu.query.filter(
|
||||||
yonghuid=yonghu_id,
|
yonghuid=yonghu_id,
|
||||||
leixing=MEMBER_LEIXING,
|
leixing=MEMBER_LEIXING,
|
||||||
@@ -333,21 +351,16 @@ def _build_clumber_from_paid_czjilu(yonghu_id):
|
|||||||
hid = normalize_huiyuan_id(order.huiyuan_id)
|
hid = normalize_huiyuan_id(order.huiyuan_id)
|
||||||
if not hid:
|
if not hid:
|
||||||
continue
|
continue
|
||||||
cid = getattr(order, 'club_id', None) or CLUB_ID_DEFAULT
|
cid = getattr(order, 'club_id', None) or ''
|
||||||
is_trial = _order_is_trial_like(order, cid)
|
if not czjilu_entitlement_active(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:
|
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
hy = Huiyuan.query.get(huiyuan_id=hid)
|
hy = Huiyuan.query.get(huiyuan_id=hid)
|
||||||
ming = hy.jieshao or f'会员{hid}'
|
ming = hy.jieshao or f'会员{hid}'
|
||||||
except Huiyuan.DoesNotExist:
|
except Huiyuan.DoesNotExist:
|
||||||
ming = f'会员{hid}'
|
ming = f'会员{hid}'
|
||||||
|
from jituan.services.member_recharge import _czjilu_entitlement_end
|
||||||
|
daoqi = _czjilu_entitlement_end(order, cid)
|
||||||
base = {
|
base = {
|
||||||
'huiyuanming': ming,
|
'huiyuanming': ming,
|
||||||
'daoqi': format_legacy_daoqi(daoqi),
|
'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):
|
def ensure_grab_pool_clumber(yonghu_id, club_id=None):
|
||||||
"""
|
"""
|
||||||
dddhq / dashouxinxi:只读 huiyuangoumai 生成 clumber(体验=正式)。
|
dddhq / dashouxinxi:只读 huiyuangoumai + 有效期内充值单 生成 clumber(体验=正式)。
|
||||||
不在每次请求全量 sync 充值单(后台移除后会被补回)。
|
不写库、不全量 sync;仅在无任何会员时尝试补最近已付单(防回调丢失)。
|
||||||
"""
|
"""
|
||||||
from jituan.services.member_recharge import repair_recent_paid_entitlements_if_missing
|
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:
|
if not items:
|
||||||
repair_recent_paid_entitlements_if_missing(yonghu_id, limit=3)
|
repair_recent_paid_entitlements_if_missing(yonghu_id, limit=3)
|
||||||
items = _build_user_clumber_core(yonghu_id)
|
items = _build_user_clumber_core(yonghu_id)
|
||||||
|
items = _merge_clumber_extra_items(items, _build_clumber_from_paid_czjilu(yonghu_id))
|
||||||
return bool(items), items
|
return bool(items), items
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user