fix(platform-fulfillment): 允许预售单提前绑定账号
This commit is contained in:
@@ -9,7 +9,7 @@ from __future__ import annotations
|
||||
from dataclasses import dataclass
|
||||
from datetime import UTC, datetime, timedelta
|
||||
|
||||
from sqlalchemy import case, or_, select
|
||||
from sqlalchemy import and_, case, or_, select
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
@@ -21,7 +21,10 @@ from ...models import (
|
||||
DouyuExternalOrder,
|
||||
User,
|
||||
)
|
||||
from ..account_capability_service import AVAILABILITY_AVAILABLE
|
||||
from ..account_capability_service import (
|
||||
AVAILABILITY_AVAILABLE,
|
||||
AVAILABILITY_NOT_OPEN,
|
||||
)
|
||||
from ..account_events_service import (
|
||||
CATEGORY_OPS,
|
||||
EVENT_LEASE_ACQUIRED,
|
||||
@@ -274,6 +277,7 @@ def capability_candidate_accounts(
|
||||
scope: str = "elite",
|
||||
limit: int = 20,
|
||||
now: datetime | None = None,
|
||||
allow_not_open: bool = False,
|
||||
) -> list[Account]:
|
||||
"""从新鲜的商品能力索引读取候选账号,不产生外部请求。"""
|
||||
commodity = commodity_id.strip()
|
||||
@@ -288,6 +292,43 @@ def capability_candidate_accounts(
|
||||
.exists()
|
||||
)
|
||||
active_collab = _active_collab_order()
|
||||
allowed_availability = (
|
||||
(AVAILABILITY_AVAILABLE, AVAILABILITY_NOT_OPEN)
|
||||
if allow_not_open
|
||||
else (AVAILABILITY_AVAILABLE,)
|
||||
)
|
||||
window_filter = or_(
|
||||
and_(
|
||||
AccountCommodityState.availability == AVAILABILITY_AVAILABLE,
|
||||
or_(
|
||||
AccountCommodityState.available_from.is_(None),
|
||||
AccountCommodityState.available_from <= moment,
|
||||
),
|
||||
or_(
|
||||
AccountCommodityState.available_until.is_(None),
|
||||
AccountCommodityState.available_until >= moment,
|
||||
),
|
||||
),
|
||||
and_(
|
||||
AccountCommodityState.availability == AVAILABILITY_NOT_OPEN,
|
||||
or_(
|
||||
AccountCommodityState.available_until.is_(None),
|
||||
AccountCommodityState.available_until >= moment,
|
||||
),
|
||||
),
|
||||
)
|
||||
if not allow_not_open:
|
||||
window_filter = and_(
|
||||
AccountCommodityState.availability == AVAILABILITY_AVAILABLE,
|
||||
or_(
|
||||
AccountCommodityState.available_from.is_(None),
|
||||
AccountCommodityState.available_from <= moment,
|
||||
),
|
||||
or_(
|
||||
AccountCommodityState.available_until.is_(None),
|
||||
AccountCommodityState.available_until >= moment,
|
||||
),
|
||||
)
|
||||
return (
|
||||
db.query(Account)
|
||||
.join(
|
||||
@@ -298,17 +339,10 @@ def capability_candidate_accounts(
|
||||
AccountCommodityState.platform == "douyu",
|
||||
AccountCommodityState.scope == scope,
|
||||
AccountCommodityState.commodity_id == commodity,
|
||||
AccountCommodityState.availability == AVAILABILITY_AVAILABLE,
|
||||
AccountCommodityState.availability.in_(allowed_availability),
|
||||
AccountCommodityState.valid_until.isnot(None),
|
||||
AccountCommodityState.valid_until > moment,
|
||||
or_(
|
||||
AccountCommodityState.available_from.is_(None),
|
||||
AccountCommodityState.available_from <= moment,
|
||||
),
|
||||
or_(
|
||||
AccountCommodityState.available_until.is_(None),
|
||||
AccountCommodityState.available_until >= moment,
|
||||
),
|
||||
window_filter,
|
||||
or_(
|
||||
AccountCommodityState.last_exchange_at.is_(None),
|
||||
AccountCommodityState.last_exchange_at < since,
|
||||
@@ -326,6 +360,10 @@ def capability_candidate_accounts(
|
||||
~active_collab,
|
||||
)
|
||||
.order_by(
|
||||
case(
|
||||
(AccountCommodityState.availability == AVAILABILITY_AVAILABLE, 0),
|
||||
else_=1,
|
||||
),
|
||||
case((Account.ck_check_status == "valid", 0), else_=1),
|
||||
case((Account.status == "active", 0), else_=1),
|
||||
case((Account.elite_opened.is_(True), 0), else_=1),
|
||||
|
||||
Reference in New Issue
Block a user