feat(weibo): 支持管理员强制更新占用账号 CK

This commit is contained in:
yml
2026-11-14 14:46:38 +08:00
parent b4801336c5
commit 17a2b5c464
7 changed files with 229 additions and 23 deletions
+70 -16
View File
@@ -19,7 +19,7 @@ from core.weibo import (
normalize_weibo_cookie,
)
from ..models import WeiboAccount, WeiboRechargeRecord, WeiboWorkbenchAccount
from ..models import User, WeiboAccount, WeiboRechargeRecord, WeiboWorkbenchAccount
from .weibo_image_service import embed_weibo_goods_images
@@ -27,6 +27,12 @@ from .weibo_image_service import embed_weibo_goods_images
class WeiboImportIssue:
line: int
message: str
account_id: int | None = None
uid: str = ""
assigned_user_id: int | None = None
assigned_username: str = ""
workbench_owner_id: int | None = None
workbench_owner_username: str = ""
@dataclass(frozen=True, slots=True)
@@ -74,6 +80,7 @@ def import_weibo_cookies(
update_existing: bool = False,
current_user_id: int | None = None,
can_update_all: bool = False,
force_update: bool = False,
) -> tuple[
list[WeiboAccount],
list[WeiboImportIssue],
@@ -123,31 +130,78 @@ def import_weibo_cookies(
db.query(WeiboAccount).filter(WeiboAccount.uid == snapshot.uid).first()
)
if account is not None and update_existing and current_user_id is not None:
if (
not can_update_all
and account.assigned_to is not None
and account.assigned_to != current_user_id
):
errors.append(
WeiboImportIssue(
line=line_no,
message="该账号已分配给其他客服,不能更新 CK",
)
assigned_user = (
db.query(User).filter(User.id == account.assigned_to).first()
if account.assigned_to is not None
else None
)
workbench_owner = (
db.query(User)
.join(
WeiboWorkbenchAccount,
WeiboWorkbenchAccount.user_id == User.id,
)
continue
owner_id = (
db.query(WeiboWorkbenchAccount.user_id)
.filter(
WeiboWorkbenchAccount.account_id == account.id,
WeiboWorkbenchAccount.exclusive_slot.is_not(None),
)
.first()
)
if owner_id is not None and owner_id[0] != current_user_id:
assigned_conflict = (
not can_update_all
and account.assigned_to is not None
and account.assigned_to != current_user_id
)
workbench_conflict = (
workbench_owner is not None and workbench_owner.id != current_user_id
)
if not force_update and (assigned_conflict or workbench_conflict):
assigned_label = (
assigned_user.username if assigned_user else account.assigned_to
)
workbench_label = workbench_owner.username if workbench_owner else ""
if (
assigned_conflict
and workbench_conflict
and workbench_owner is not None
):
conflict_message = (
"该账号已分配给其他客服:账号归属客服 "
f"{assigned_label}(ID {account.assigned_to}),"
f"且个人工作台排他槽位归 {workbench_label}"
f"(ID {workbench_owner.id})"
)
elif assigned_conflict:
conflict_message = (
"该账号已分配给其他客服:账号归属客服 "
f"{assigned_label}(ID {account.assigned_to})"
)
else:
assert workbench_owner is not None
conflict_message = (
"该账号已被其他人的工作台占用:个人工作台排他槽位归 "
f"{workbench_label}"
f"(ID {workbench_owner.id})"
)
errors.append(
WeiboImportIssue(
line=line_no,
message="该账号已被其他人的工作台占用,不能更新 CK",
message=(
conflict_message
+ ",不能更新 CK。超级管理员可勾选“强制更新”覆盖,原归属保持不变"
),
account_id=account.id,
uid=account.uid,
assigned_user_id=account.assigned_to,
assigned_username=(
assigned_user.username if assigned_user else ""
),
workbench_owner_id=(
workbench_owner.id if workbench_owner else None
),
workbench_owner_username=(
workbench_owner.username if workbench_owner else ""
),
)
)
continue