fix(fulfillment): 取消商品限时兑换未开始对提前选号绑定的限制

This commit is contained in:
yml
2026-11-28 20:12:33 +08:00
parent d03eeaee18
commit c8efa6d808
7 changed files with 170 additions and 42 deletions
@@ -47,7 +47,6 @@ from ..binding_ownership import (
role_names_match,
)
from ..douyu_account_state import DouyuLiveAccountState
from . import classification
from .account_selector import (
EXCHANGE_COOLDOWN_DAYS,
AccountCandidate,
@@ -244,28 +243,15 @@ def _local_allocation_retry_at(
availability_counts: dict[str, int],
lease_conflict: bool,
) -> tuple[datetime, str]:
"""按本地状态决定下一轮时间,避免永久无库存任务每 45 秒占槽。"""
"""按本地状态决定下一轮时间,避免永久无库存任务每 45 秒占槽。
「商品限时兑换未开始(offer:before)」不再阻止提前选号与绑定,也不再掩盖真实的捆绑资格缺口或触发能力刷新。
"""
if lease_conflict:
return (
now + timedelta(seconds=LOCAL_LEASE_CONFLICT_RETRY_SECONDS),
"lease_conflict",
)
next_open_at = (
db.query(func.min(AccountCommodityState.available_from))
.filter(
AccountCommodityState.platform == TARGET_PLATFORM,
AccountCommodityState.scope == (task.scope or SCOPE_ELITE),
AccountCommodityState.commodity_id == task.commodity_id,
AccountCommodityState.offer_state == OFFER_STATE_BEFORE,
AccountCommodityState.available_from.isnot(None),
AccountCommodityState.available_from > now,
)
.scalar()
)
if next_open_at is not None:
return next_open_at + timedelta(seconds=5), "commodity_not_open"
if availability_counts.get(f"offer:{OFFER_STATE_BEFORE}"):
return now + timedelta(seconds=LOCAL_STOCK_RETRY_SECONDS), "commodity_not_open"
has_capability_rows = any(
int(value or 0)
for key, value in availability_counts.items()
@@ -384,7 +370,6 @@ def _apply_allocated_account_state(
lease: AccountLease,
cached_state: DouyuLiveAccountState,
required_points: int,
is_presale: bool,
current: User,
moment: datetime,
allocation_strategy: str,
@@ -423,7 +408,7 @@ def _apply_allocated_account_state(
gate_status, gate_issue, gate_message = _exchange_gate(
cached_state,
task.commodity_id,
allow_not_open=is_presale,
allow_not_open=True,
)
if gate_status:
task.exchange_status = gate_status
@@ -534,7 +519,6 @@ def _find_reusable_same_role_target(
scope = task.scope or SCOPE_ELITE
since_365 = moment - timedelta(days=EXCHANGE_COOLDOWN_DAYS)
is_presale = classification.normalize_sale_mode(task.sale_mode) == "presale"
sibling_rows = (
db.query(PlatformFulfillmentTask)
@@ -611,7 +595,7 @@ def _find_reusable_same_role_target(
commodity_id=task.commodity_id,
scope=scope,
moment=moment,
allow_before_open=is_presale,
allow_before_open=True,
)
if primary_state is None:
continue
@@ -824,7 +808,6 @@ def _attach_task_to_same_role_target(
lease=lease,
cached_state=cached_state,
required_points=int(task.required_points or 0),
is_presale=classification.normalize_sale_mode(task.sale_mode) == "presale",
current=current,
moment=moment,
allocation_strategy="same_role_reuse",
@@ -908,7 +891,7 @@ def try_reallocate_task_to_same_role(
moment = now or _now()
policy = normalize_allocation_policy(get_settings(db).get("allocationPolicy"))
required_co, _preferred_co = bundle_requirements_for_commodity(
task.commodity_id, policy
policy, task.commodity_id
)
preferred_ids = (int(preferred_account_id),) if preferred_account_id else ()
target = _find_reusable_same_role_target(
@@ -1063,7 +1046,6 @@ def _allocate_task_from_capability(
except ValueError:
candidate_limit = DEFAULT_CAPABILITY_CANDIDATE_LIMIT
candidate_limit = max(1, min(candidate_limit, 100))
is_presale = classification.normalize_sale_mode(task.sale_mode) == "presale"
capability_candidates = capability_candidate_rows(
db,
limit=candidate_limit,
@@ -1071,7 +1053,7 @@ def _allocate_task_from_capability(
commodity_id=task.commodity_id,
scope=task.scope or SCOPE_ELITE,
now=moment,
allow_before_open=is_presale,
allow_before_open=True,
required_co_commodities=required_co,
preferred_co_commodities=preferred_co,
protected_bundle_commodities=protected_co,
@@ -1199,10 +1181,7 @@ def _allocate_task_from_capability(
}
else 0
)
if retry_reason == "commodity_not_open":
task.issue_code = "commodity_not_open"
task.last_error = "该商品尚未到开放时间,已按开放时间安排重新选号"
elif retry_reason == "capability_cache_miss":
if retry_reason == "capability_cache_miss":
task.issue_code = "capability_cache_miss"
task.last_error = "暂无该商品的新鲜账号兑换资格,等待后台刷新"
elif retry_reason == "bundle_co_eligibility_missing":
@@ -1262,7 +1241,6 @@ def _allocate_task_from_capability(
lease=lease,
cached_state=selected_state,
required_points=required_points,
is_presale=is_presale,
current=current,
moment=moment,
allocation_strategy="local_capability",
@@ -45,7 +45,6 @@ from ..external_order_source import (
OrderLookupUnavailable,
lookup_pending_manual_fulfillment,
)
from . import classification
from .account_selector import (
release_lease,
)
@@ -331,7 +330,6 @@ def refresh_exchange_eligibility(
]
assessments = classify_goods_items(storehome_goods, now=_now())
assessment = assessments.get(task.commodity_id)
is_presale = classification.normalize_sale_mode(task.sale_mode) == "presale"
if task.commodity_id in limited_ids:
account_eligibility = ACCOUNT_ELIGIBILITY_LIMITED
offer_state = assessment.offer_state if assessment else OFFER_STATE_UNKNOWN
@@ -368,7 +366,7 @@ def refresh_exchange_eligibility(
gate_status, gate_issue, gate_message = exchange_gate_for_availability(
availability,
reason=commodity_message,
allow_not_open=is_presale,
allow_not_open=True,
)
if gate_status:
task.exchange_status = gate_status