refactor: 收口跨平台重复业务实现
This commit is contained in:
@@ -16,7 +16,7 @@ from zoneinfo import ZoneInfo
|
||||
from sqlalchemy import func, or_
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from core.weibo import WeiboClient, WeiboError
|
||||
from core.weibo import WeiboError
|
||||
|
||||
from ..models import (
|
||||
AuditLog,
|
||||
@@ -28,7 +28,12 @@ from ..models import (
|
||||
WeiboExternalOrderMetric,
|
||||
)
|
||||
from .audit_service import record_audit
|
||||
from .weibo_service import query_weibo_mall, refresh_weibo_account
|
||||
from .collab_common import apply_order_visibility, count_archived
|
||||
from .weibo_service import (
|
||||
query_weibo_exchange_records,
|
||||
query_weibo_mall,
|
||||
refresh_weibo_account,
|
||||
)
|
||||
|
||||
STATUS_INCOMPLETE = "incomplete"
|
||||
STATUS_TO_RECHARGE = "to_recharge"
|
||||
@@ -99,7 +104,6 @@ VERDICT_LABELS = {
|
||||
VERDICT_UNKNOWN: "无法判定",
|
||||
}
|
||||
|
||||
ARCHIVE_SCOPES = ("active", "archived", "all")
|
||||
ARCHIVABLE_STATUSES = (STATUS_DONE,)
|
||||
MAX_IMAGES = 20
|
||||
CHECK_BATCH_MAX = 50
|
||||
@@ -1029,7 +1033,7 @@ def check_balance_groups(
|
||||
)
|
||||
continue
|
||||
try:
|
||||
data = WeiboClient(account.cookie or "").list_mall(activity)
|
||||
data = query_weibo_mall(db, account, activity=activity)
|
||||
except (WeiboError, ValueError) as exc:
|
||||
for order in account_orders:
|
||||
failures.append(
|
||||
@@ -1233,8 +1237,10 @@ def check_exchange_records(
|
||||
)
|
||||
continue
|
||||
try:
|
||||
data = WeiboClient(account.cookie or "").list_exchange_records(
|
||||
activity,
|
||||
data = query_weibo_exchange_records(
|
||||
db,
|
||||
account,
|
||||
activity=activity,
|
||||
page=1,
|
||||
page_size=100,
|
||||
)
|
||||
@@ -1622,13 +1628,13 @@ def _apply_filters(
|
||||
keyword: str = "",
|
||||
include_void: bool = False,
|
||||
):
|
||||
scope = archive_scope if archive_scope in ARCHIVE_SCOPES else "active"
|
||||
if scope == "active":
|
||||
query = query.filter(WeiboExternalOrder.archived_at.is_(None))
|
||||
elif scope == "archived":
|
||||
query = query.filter(WeiboExternalOrder.archived_at.isnot(None))
|
||||
if not include_void:
|
||||
query = query.filter(WeiboExternalOrder.status != STATUS_VOID)
|
||||
query = apply_order_visibility(
|
||||
query,
|
||||
WeiboExternalOrder,
|
||||
archive_scope=archive_scope,
|
||||
include_void=include_void,
|
||||
void_status=STATUS_VOID,
|
||||
)
|
||||
if _text(status):
|
||||
query = query.filter(WeiboExternalOrder.status == status)
|
||||
if _text(ck_status):
|
||||
@@ -1798,12 +1804,7 @@ def summary(
|
||||
),
|
||||
"account_disabled": int(account_disabled),
|
||||
"ck_invalid": int(ck_invalid),
|
||||
"archived_total": (
|
||||
db.query(func.count(WeiboExternalOrder.id))
|
||||
.filter(WeiboExternalOrder.archived_at.isnot(None))
|
||||
.scalar()
|
||||
or 0
|
||||
),
|
||||
"archived_total": count_archived(db, WeiboExternalOrder),
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user