fix(fulfillment): 优先刷新联合皮肤全资格账号
This commit is contained in:
@@ -21,7 +21,7 @@ from ...models import (
|
||||
AccountLease,
|
||||
AccountSyncState,
|
||||
)
|
||||
from ..account_capability_service import OFFER_STATE_ACTIVE
|
||||
from ..account_capability_service import OFFER_STATE_ACTIVE, OFFER_STATE_BEFORE
|
||||
from ..account_events_service import (
|
||||
CATEGORY_OPS,
|
||||
EVENT_LEASE_ACQUIRED,
|
||||
@@ -723,6 +723,8 @@ def storehome_refresh_candidate_accounts(
|
||||
limit: int = 20,
|
||||
now: datetime | None = None,
|
||||
exclude_account_ids: tuple[int, ...] | list[int] = (),
|
||||
scope: str = "elite",
|
||||
preferred_commodity_groups: tuple[tuple[str, ...], ...] = (),
|
||||
) -> list[Account]:
|
||||
"""选择 CK 有效但缺少新鲜 storehome 快照的账号做全量能力补全。
|
||||
|
||||
@@ -745,6 +747,44 @@ def storehome_refresh_candidate_accounts(
|
||||
excluded_ids = tuple(
|
||||
dict.fromkeys(int(account_id) for account_id in exclude_account_ids)
|
||||
)
|
||||
preferred_groups = tuple(
|
||||
dict.fromkeys(
|
||||
tuple(
|
||||
dict.fromkeys(
|
||||
str(commodity_id).strip()
|
||||
for commodity_id in group
|
||||
if str(commodity_id).strip()
|
||||
)
|
||||
)
|
||||
for group in preferred_commodity_groups
|
||||
)
|
||||
)
|
||||
preferred_groups = tuple(group for group in preferred_groups if len(group) >= 2)
|
||||
preferred_exprs = [
|
||||
and_(
|
||||
*[
|
||||
select(AccountCommodityState.id)
|
||||
.where(
|
||||
AccountCommodityState.account_id == Account.id,
|
||||
AccountCommodityState.platform == "douyu",
|
||||
AccountCommodityState.scope == scope,
|
||||
AccountCommodityState.commodity_id == commodity_id,
|
||||
AccountCommodityState.account_eligibility == "eligible",
|
||||
AccountCommodityState.offer_state.in_(
|
||||
(OFFER_STATE_ACTIVE, OFFER_STATE_BEFORE)
|
||||
),
|
||||
or_(
|
||||
AccountCommodityState.last_exchange_at.is_(None),
|
||||
AccountCommodityState.last_exchange_at
|
||||
< moment - timedelta(days=EXCHANGE_COOLDOWN_DAYS),
|
||||
),
|
||||
)
|
||||
.exists()
|
||||
for commodity_id in group
|
||||
]
|
||||
)
|
||||
for group in preferred_groups
|
||||
]
|
||||
query = db.query(Account).filter(
|
||||
~fresh_storehome,
|
||||
cookie_present_filter(),
|
||||
@@ -755,11 +795,11 @@ def storehome_refresh_candidate_accounts(
|
||||
)
|
||||
if excluded_ids:
|
||||
query = query.filter(~Account.id.in_(excluded_ids))
|
||||
return (
|
||||
query.order_by(*_refresh_candidate_order_by(moment))
|
||||
.limit(max(1, min(int(limit), 100)))
|
||||
.all()
|
||||
)
|
||||
order_by: list[Any] = []
|
||||
if preferred_exprs:
|
||||
order_by.append(case((or_(*preferred_exprs), 0), else_=1))
|
||||
order_by.extend(_refresh_candidate_order_by(moment))
|
||||
return query.order_by(*order_by).limit(max(1, min(int(limit), 100))).all()
|
||||
|
||||
|
||||
def has_recent_exchange(
|
||||
|
||||
Reference in New Issue
Block a user