feat(weibo): 增加协作 CK 批量复制与商品图片代理

This commit is contained in:
yml
2026-11-12 14:12:50 +08:00
parent 31045e0f2e
commit 0e29717c97
18 changed files with 604 additions and 153 deletions
@@ -96,6 +96,7 @@ ARCHIVABLE_STATUSES = (STATUS_DONE,)
MAX_IMAGES = 20
CHECK_BATCH_MAX = 50
ARCHIVE_BATCH_MAX = 5000
CK_EXPORT_ACTION = "weibo:account:ck_export"
DEFAULT_WEIDOU_THRESHOLD = 100
@@ -217,6 +218,109 @@ def list_orders_by_ids(db: Session, ids: Sequence[int]) -> list[WeiboExternalOrd
)
def export_cks(
db: Session,
current: User | None,
order_ids: Sequence[int],
*,
commit: bool = True,
) -> dict[str, Any]:
"""导出所选协作单关联账号的 CK 明文,供前端写入剪贴板。"""
requested = list(dict.fromkeys(int(item) for item in order_ids if int(item) > 0))
if not requested:
raise CollabError("请先勾选要导出的行", code="ck_export_empty")
if len(requested) > CHECK_BATCH_MAX:
raise CollabError(
f"一次最多导出 {CHECK_BATCH_MAX} 行,请分批操作",
code="ck_export_too_large",
)
rows = (
db.query(WeiboExternalOrder).filter(WeiboExternalOrder.id.in_(requested)).all()
)
by_id = {int(order.id): order for order in rows}
accounts = _accounts_by_id(
db, {int(order.account_id) for order in rows if order.account_id}
)
items: list[dict[str, Any]] = []
skipped: list[dict[str, Any]] = []
for order_id in requested:
order = by_id.get(order_id)
if order is None:
skipped.append(
{
"id": order_id,
"order_no": "",
"reason": "协作单不存在或已删除",
}
)
continue
if not order.account_id:
skipped.append(
{
"id": int(order.id),
"order_no": order.order_no,
"reason": "这单还没关联微博账号",
}
)
continue
account = accounts.get(int(order.account_id))
if account is None:
skipped.append(
{
"id": int(order.id),
"order_no": order.order_no,
"reason": "关联的微博账号不存在或已删除",
}
)
continue
ck_text = str(account.cookie or "").strip()
if not ck_text:
skipped.append(
{
"id": int(order.id),
"order_no": order.order_no,
"reason": "关联的微博账号还没有 CK",
}
)
continue
items.append(
{
"id": int(order.id),
"order_no": order.order_no,
"account_id": int(account.id),
"uid": account.uid or order.account_uid or "",
"nickname": account.nickname or order.account_nickname or "",
"ck_status": account.ck_check_status or "",
"ck_text": ck_text,
}
)
record_audit(
db,
current,
action=CK_EXPORT_ACTION,
target=f"weibo_account:{account.id}",
detail={
"account_id": int(account.id),
"uid": account.uid or order.account_uid or "",
"order_id": int(order.id),
"order_no": order.order_no,
"ck_status": account.ck_check_status or "",
"batch_size": len(requested),
},
)
if commit:
db.commit()
return {
"total": len(requested),
"exported": len(items),
"skipped": skipped,
"items": items,
}
def _missing_for_recharge(order: WeiboExternalOrder) -> list[str]:
missing: list[str] = []
if not order.shop: