refactor(douyu): 统一账号准入与本地查询链路
This commit is contained in:
@@ -252,6 +252,47 @@ def classify_goods_items(
|
||||
return assessments
|
||||
|
||||
|
||||
def exchange_gate_for_availability(
|
||||
availability: str | None,
|
||||
*,
|
||||
reason: str = "",
|
||||
limited: bool = False,
|
||||
allow_not_open: bool = False,
|
||||
) -> tuple[str, str, str]:
|
||||
"""把统一能力状态映射为履约兑换门槛,避免各入口重复维护状态表。"""
|
||||
if limited:
|
||||
return (
|
||||
"limited",
|
||||
"commodity_limit_reached",
|
||||
reason or "该账号已达到此商品兑换上限",
|
||||
)
|
||||
if availability == AVAILABILITY_AVAILABLE:
|
||||
return "", "", ""
|
||||
if allow_not_open and availability == AVAILABILITY_NOT_OPEN:
|
||||
return (
|
||||
"waiting_release",
|
||||
"commodity_not_open",
|
||||
reason or "商品限时兑换尚未开始,可提前绑定角色",
|
||||
)
|
||||
issue_map = {
|
||||
None: ("commodity_not_offered", "官方商品列表本次未返回该商品,可能已下架"),
|
||||
AVAILABILITY_NOT_OPEN: ("commodity_not_open", "商品限时兑换尚未开始"),
|
||||
AVAILABILITY_EXPIRED: ("commodity_expired", "商品限时兑换已经结束"),
|
||||
AVAILABILITY_NO_STOCK: ("commodity_no_stock", "商品当前无库存"),
|
||||
AVAILABILITY_NOT_OFFERED: ("commodity_not_offered", "商品当前未上架"),
|
||||
AVAILABILITY_UNKNOWN: ("commodity_status_unknown", "商品资格状态未知"),
|
||||
AVAILABILITY_LIMITED: (
|
||||
"commodity_limit_reached",
|
||||
"该账号已达到此商品兑换上限",
|
||||
),
|
||||
}
|
||||
issue_code, fallback = issue_map.get(
|
||||
availability,
|
||||
("commodity_not_exchangeable", "商品当前不可兑换"),
|
||||
)
|
||||
return "not_available", issue_code, reason or fallback
|
||||
|
||||
|
||||
def _exchange_stats(
|
||||
db: Session,
|
||||
*,
|
||||
@@ -642,6 +683,7 @@ __all__ = [
|
||||
"capability_ttl_seconds",
|
||||
"classify_goods_item",
|
||||
"classify_goods_items",
|
||||
"exchange_gate_for_availability",
|
||||
"goods_time_window",
|
||||
"invalidate_account_commodity_states",
|
||||
"mark_commodity_exchanged",
|
||||
|
||||
Reference in New Issue
Block a user