feat(weibo): 增加协作 CK 失效筛选与实时同步开关
This commit is contained in:
@@ -1553,6 +1553,7 @@ def _apply_filters(
|
||||
*,
|
||||
archive_scope: str = "active",
|
||||
status: str = "",
|
||||
ck_status: str = "",
|
||||
shop: str = "",
|
||||
owner_id: int | None = None,
|
||||
goods_name: str = "",
|
||||
@@ -1568,6 +1569,10 @@ def _apply_filters(
|
||||
query = query.filter(WeiboExternalOrder.status != STATUS_VOID)
|
||||
if _text(status):
|
||||
query = query.filter(WeiboExternalOrder.status == status)
|
||||
if _text(ck_status):
|
||||
query = query.join(
|
||||
WeiboAccount, WeiboAccount.id == WeiboExternalOrder.account_id
|
||||
).filter(WeiboAccount.ck_check_status == ck_status)
|
||||
if _text(shop):
|
||||
query = query.filter(WeiboExternalOrder.shop == shop)
|
||||
if owner_id is not None:
|
||||
@@ -1598,6 +1603,7 @@ def list_orders(
|
||||
page_size: int,
|
||||
archive_scope: str = "active",
|
||||
status: str = "",
|
||||
ck_status: str = "",
|
||||
shop: str = "",
|
||||
owner_id: int | None = None,
|
||||
goods_name: str = "",
|
||||
@@ -1608,6 +1614,7 @@ def list_orders(
|
||||
_base_query(db),
|
||||
archive_scope=archive_scope,
|
||||
status=status,
|
||||
ck_status=ck_status,
|
||||
shop=shop,
|
||||
owner_id=owner_id,
|
||||
goods_name=goods_name,
|
||||
@@ -1710,7 +1717,7 @@ def summary(
|
||||
)
|
||||
ck_invalid = (
|
||||
query.join(WeiboAccount, WeiboAccount.id == WeiboExternalOrder.account_id)
|
||||
.filter(WeiboAccount.ck_check_status.in_(("invalid", "error")))
|
||||
.filter(WeiboAccount.ck_check_status == "invalid")
|
||||
.with_entities(func.count(WeiboExternalOrder.id))
|
||||
.scalar()
|
||||
or 0
|
||||
|
||||
@@ -190,9 +190,7 @@ def refresh_weibo_account(
|
||||
snapshot = client.fetch_home(activity)
|
||||
client.check_payment_access(activity, home=snapshot)
|
||||
except (WeiboError, ValueError) as exc:
|
||||
account.ck_check_status = _error_status(exc)
|
||||
account.ck_check_message = str(exc)
|
||||
account.ck_checked_at = _now()
|
||||
mark_weibo_account_refresh_failure(db, account, exc, commit=False)
|
||||
if commit:
|
||||
db.commit()
|
||||
raise
|
||||
@@ -204,6 +202,26 @@ def refresh_weibo_account(
|
||||
return snapshot
|
||||
|
||||
|
||||
def mark_weibo_account_refresh_failure(
|
||||
db: Session,
|
||||
account: WeiboAccount,
|
||||
exc: Exception,
|
||||
*,
|
||||
commit: bool = True,
|
||||
) -> bool:
|
||||
"""把一次刷新失败写回账号;业务校验失败不应被误标成 CK 失效。"""
|
||||
|
||||
if not isinstance(exc, (WeiboError, ValueError)):
|
||||
return False
|
||||
account.ck_check_status = _error_status(exc)
|
||||
account.ck_check_message = str(exc)
|
||||
account.ck_checked_at = _now()
|
||||
if commit:
|
||||
db.commit()
|
||||
db.refresh(account)
|
||||
return True
|
||||
|
||||
|
||||
def update_weibo_account_metadata(
|
||||
db: Session,
|
||||
account: WeiboAccount,
|
||||
|
||||
Reference in New Issue
Block a user