feat(weibo): 增加外部 CK 账号 CRUD 与生命周期
This commit is contained in:
@@ -26,7 +26,7 @@ TESTS_DIR = Path(__file__).resolve().parent
|
|||||||
PROJECT_ROOT = TESTS_DIR.parent
|
PROJECT_ROOT = TESTS_DIR.parent
|
||||||
VERSIONS_DIR = PROJECT_ROOT / "web" / "backend" / "migrations" / "versions"
|
VERSIONS_DIR = PROJECT_ROOT / "web" / "backend" / "migrations" / "versions"
|
||||||
|
|
||||||
HEAD_REVISION = "20261107_0069"
|
HEAD_REVISION = "20261108_0070"
|
||||||
|
|
||||||
# 迁移新增、但不声明在模型里的复合查询索引。
|
# 迁移新增、但不声明在模型里的复合查询索引。
|
||||||
EXTRA_INDEXES = (
|
EXTRA_INDEXES = (
|
||||||
|
|||||||
@@ -21,10 +21,17 @@ from web.backend.models import User, WeiboAccount
|
|||||||
from web.backend.routers import weibo as weibo_router
|
from web.backend.routers import weibo as weibo_router
|
||||||
from web.backend.routers.weibo import (
|
from web.backend.routers.weibo import (
|
||||||
create_bind_qrcodes,
|
create_bind_qrcodes,
|
||||||
|
disable_account,
|
||||||
|
enable_account,
|
||||||
|
get_account,
|
||||||
import_cookies,
|
import_cookies,
|
||||||
list_accounts,
|
list_accounts,
|
||||||
|
refresh_account,
|
||||||
|
update_account,
|
||||||
)
|
)
|
||||||
from web.backend.schemas import (
|
from web.backend.schemas import (
|
||||||
|
WeiboAccountDisableRequest,
|
||||||
|
WeiboAccountUpdate,
|
||||||
WeiboCookieImport,
|
WeiboCookieImport,
|
||||||
WeiboExchangeRequest,
|
WeiboExchangeRequest,
|
||||||
WeiboPaymentStatusRequest,
|
WeiboPaymentStatusRequest,
|
||||||
@@ -204,6 +211,9 @@ def test_list_accounts_returns_parallel_page_shape(db, current_user):
|
|||||||
"id",
|
"id",
|
||||||
"uid",
|
"uid",
|
||||||
"nickname",
|
"nickname",
|
||||||
|
"tag",
|
||||||
|
"remark",
|
||||||
|
"is_enabled",
|
||||||
"is_bound",
|
"is_bound",
|
||||||
"can_rebind",
|
"can_rebind",
|
||||||
"rebind_remain_days",
|
"rebind_remain_days",
|
||||||
@@ -212,6 +222,96 @@ def test_list_accounts_returns_parallel_page_shape(db, current_user):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def test_account_crud_and_lifecycle(db, current_user):
|
||||||
|
account_out = import_cookies(
|
||||||
|
WeiboCookieImport(text="SCF=a; SUB=b", tag="初始"),
|
||||||
|
db=db,
|
||||||
|
current=current_user,
|
||||||
|
).accounts[0]
|
||||||
|
|
||||||
|
detail = get_account(
|
||||||
|
account_out.id,
|
||||||
|
db=db,
|
||||||
|
current=current_user,
|
||||||
|
).model_dump()
|
||||||
|
assert detail["is_enabled"] is True
|
||||||
|
assert detail["remark"] == ""
|
||||||
|
|
||||||
|
updated = update_account(
|
||||||
|
account_out.id,
|
||||||
|
WeiboAccountUpdate(tag="重点", remark="客户 A"),
|
||||||
|
db=db,
|
||||||
|
current=current_user,
|
||||||
|
).model_dump()
|
||||||
|
assert updated["tag"] == "重点"
|
||||||
|
assert updated["remark"] == "客户 A"
|
||||||
|
|
||||||
|
disabled = disable_account(
|
||||||
|
account_out.id,
|
||||||
|
WeiboAccountDisableRequest(reason="暂停使用"),
|
||||||
|
db=db,
|
||||||
|
current=current_user,
|
||||||
|
).model_dump()
|
||||||
|
assert disabled["is_enabled"] is False
|
||||||
|
assert disabled["disabled_reason"] == "暂停使用"
|
||||||
|
|
||||||
|
disabled_page = list_accounts(
|
||||||
|
enabled=False,
|
||||||
|
page=1,
|
||||||
|
page_size=20,
|
||||||
|
db=db,
|
||||||
|
current=current_user,
|
||||||
|
)
|
||||||
|
assert disabled_page["total"] == 1
|
||||||
|
assert disabled_page["items"][0].model_dump()["is_enabled"] is False
|
||||||
|
|
||||||
|
with pytest.raises(HTTPException) as exc_info:
|
||||||
|
refresh_account(account_out.id, db=db, current=current_user)
|
||||||
|
assert exc_info.value.status_code == 409
|
||||||
|
|
||||||
|
disabled_actions = [
|
||||||
|
lambda: create_bind_qrcodes(account_out.id, db=db, current=current_user),
|
||||||
|
lambda: weibo_router.list_mall_goods(
|
||||||
|
account_out.id,
|
||||||
|
db=db,
|
||||||
|
current=current_user,
|
||||||
|
),
|
||||||
|
lambda: weibo_router.exchange_goods(
|
||||||
|
account_out.id,
|
||||||
|
WeiboExchangeRequest(goods_id=37, expected_price=100, confirm=True),
|
||||||
|
db=db,
|
||||||
|
current=current_user,
|
||||||
|
),
|
||||||
|
lambda: weibo_router.create_recharge_order(
|
||||||
|
account_out.id,
|
||||||
|
WeiboRechargeRequest(amount_yuan=1),
|
||||||
|
db=db,
|
||||||
|
current=current_user,
|
||||||
|
),
|
||||||
|
]
|
||||||
|
for action in disabled_actions:
|
||||||
|
with pytest.raises(HTTPException) as disabled_exc:
|
||||||
|
action()
|
||||||
|
assert disabled_exc.value.status_code == 409
|
||||||
|
|
||||||
|
import_cookies(
|
||||||
|
WeiboCookieImport(text="SCF=c; SUB=d", tag=""),
|
||||||
|
db=db,
|
||||||
|
current=current_user,
|
||||||
|
)
|
||||||
|
account = db.query(WeiboAccount).filter(WeiboAccount.id == account_out.id).one()
|
||||||
|
assert account.is_enabled is False
|
||||||
|
assert account.tag == "重点"
|
||||||
|
|
||||||
|
enabled = enable_account(
|
||||||
|
account_out.id,
|
||||||
|
db=db,
|
||||||
|
current=current_user,
|
||||||
|
).model_dump()
|
||||||
|
assert enabled["is_enabled"] is True
|
||||||
|
assert enabled["disabled_reason"] == ""
|
||||||
|
|
||||||
|
|
||||||
def test_bind_qrcodes_returns_both_channels_and_partial_error(db, current_user):
|
def test_bind_qrcodes_returns_both_channels_and_partial_error(db, current_user):
|
||||||
account = import_cookies(
|
account = import_cookies(
|
||||||
WeiboCookieImport(text="SCF=a; SUB=b", tag=""),
|
WeiboCookieImport(text="SCF=a; SUB=b", tag=""),
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
"""增加微博账号备注与启停生命周期。"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections.abc import Sequence
|
||||||
|
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from alembic import op
|
||||||
|
|
||||||
|
revision: str = "20261108_0070"
|
||||||
|
down_revision: str | None = "20261107_0069"
|
||||||
|
branch_labels: str | Sequence[str] | None = None
|
||||||
|
depends_on: str | Sequence[str] | None = None
|
||||||
|
|
||||||
|
TABLE = "weibo_accounts"
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade() -> None:
|
||||||
|
bind = op.get_bind()
|
||||||
|
inspector = sa.inspect(bind)
|
||||||
|
columns = {column["name"] for column in inspector.get_columns(TABLE)}
|
||||||
|
if "remark" not in columns:
|
||||||
|
op.add_column(
|
||||||
|
TABLE,
|
||||||
|
sa.Column(
|
||||||
|
"remark",
|
||||||
|
sa.String(length=256),
|
||||||
|
nullable=False,
|
||||||
|
server_default="",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
if "is_enabled" not in columns:
|
||||||
|
op.add_column(
|
||||||
|
TABLE,
|
||||||
|
sa.Column(
|
||||||
|
"is_enabled",
|
||||||
|
sa.Boolean(),
|
||||||
|
nullable=False,
|
||||||
|
server_default=sa.text("1"),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
op.create_index(
|
||||||
|
f"ix_{TABLE}_is_enabled",
|
||||||
|
TABLE,
|
||||||
|
["is_enabled"],
|
||||||
|
unique=False,
|
||||||
|
)
|
||||||
|
if "disabled_at" not in columns:
|
||||||
|
op.add_column(TABLE, sa.Column("disabled_at", sa.DateTime(), nullable=True))
|
||||||
|
if "disabled_reason" not in columns:
|
||||||
|
op.add_column(
|
||||||
|
TABLE,
|
||||||
|
sa.Column(
|
||||||
|
"disabled_reason",
|
||||||
|
sa.String(length=256),
|
||||||
|
nullable=False,
|
||||||
|
server_default="",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
bind = op.get_bind()
|
||||||
|
inspector = sa.inspect(bind)
|
||||||
|
columns = {column["name"] for column in inspector.get_columns(TABLE)}
|
||||||
|
indexes = {index["name"] for index in inspector.get_indexes(TABLE)}
|
||||||
|
if f"ix_{TABLE}_is_enabled" in indexes:
|
||||||
|
op.drop_index(f"ix_{TABLE}_is_enabled", table_name=TABLE)
|
||||||
|
for column in ("disabled_reason", "disabled_at", "is_enabled", "remark"):
|
||||||
|
if column in columns:
|
||||||
|
op.drop_column(TABLE, column)
|
||||||
@@ -930,8 +930,19 @@ class WeiboAccount(Base):
|
|||||||
UTCDateTime, nullable=True
|
UTCDateTime, nullable=True
|
||||||
)
|
)
|
||||||
tag: Mapped[str] = mapped_column(String(64), default="")
|
tag: Mapped[str] = mapped_column(String(64), default="")
|
||||||
|
remark: Mapped[str] = mapped_column(
|
||||||
|
String(256), nullable=False, default="", server_default=""
|
||||||
|
)
|
||||||
activity: Mapped[str] = mapped_column(String(64), default="")
|
activity: Mapped[str] = mapped_column(String(64), default="")
|
||||||
|
|
||||||
|
is_enabled: Mapped[bool] = mapped_column(
|
||||||
|
Boolean, nullable=False, default=True, server_default="1", index=True
|
||||||
|
)
|
||||||
|
disabled_at: Mapped[datetime | None] = mapped_column(UTCDateTime, nullable=True)
|
||||||
|
disabled_reason: Mapped[str] = mapped_column(
|
||||||
|
String(256), nullable=False, default="", server_default=""
|
||||||
|
)
|
||||||
|
|
||||||
ck_check_status: Mapped[str] = mapped_column(
|
ck_check_status: Mapped[str] = mapped_column(
|
||||||
String(16), nullable=False, default="", server_default=""
|
String(16), nullable=False, default="", server_default=""
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ PERMISSIONS = {
|
|||||||
# 微博微豆
|
# 微博微豆
|
||||||
"weibo:view": "查看微博账号",
|
"weibo:view": "查看微博账号",
|
||||||
"weibo:import": "导入/刷新微博 CK",
|
"weibo:import": "导入/刷新微博 CK",
|
||||||
|
"weibo:manage": "编辑、停用和启用微博账号",
|
||||||
"weibo:bind": "生成微博绑定二维码",
|
"weibo:bind": "生成微博绑定二维码",
|
||||||
"weibo:recharge": "创建微博助威充值订单",
|
"weibo:recharge": "创建微博助威充值订单",
|
||||||
"weibo:exchange": "执行微博微豆兑换",
|
"weibo:exchange": "执行微博微豆兑换",
|
||||||
@@ -110,6 +111,7 @@ ROLE_PERMISSIONS = {
|
|||||||
"yyb:history",
|
"yyb:history",
|
||||||
"weibo:view",
|
"weibo:view",
|
||||||
"weibo:import",
|
"weibo:import",
|
||||||
|
"weibo:manage",
|
||||||
"weibo:bind",
|
"weibo:bind",
|
||||||
"weibo:recharge",
|
"weibo:recharge",
|
||||||
"weibo:exchange",
|
"weibo:exchange",
|
||||||
|
|||||||
@@ -16,7 +16,9 @@ from ..deps import get_current_user
|
|||||||
from ..models import User, WeiboAccount
|
from ..models import User, WeiboAccount
|
||||||
from ..permissions import user_has_permission
|
from ..permissions import user_has_permission
|
||||||
from ..schemas import (
|
from ..schemas import (
|
||||||
|
WeiboAccountDisableRequest,
|
||||||
WeiboAccountOut,
|
WeiboAccountOut,
|
||||||
|
WeiboAccountUpdate,
|
||||||
WeiboBindQrOut,
|
WeiboBindQrOut,
|
||||||
WeiboBindSchemeOut,
|
WeiboBindSchemeOut,
|
||||||
WeiboCookieImport,
|
WeiboCookieImport,
|
||||||
@@ -38,6 +40,8 @@ from ..schemas import (
|
|||||||
from ..services.audit_service import record_audit
|
from ..services.audit_service import record_audit
|
||||||
from ..services.weibo_service import (
|
from ..services.weibo_service import (
|
||||||
create_weibo_recharge_order,
|
create_weibo_recharge_order,
|
||||||
|
disable_weibo_account,
|
||||||
|
enable_weibo_account,
|
||||||
exchange_weibo_goods,
|
exchange_weibo_goods,
|
||||||
generate_weibo_bind_schemes,
|
generate_weibo_bind_schemes,
|
||||||
import_weibo_cookies,
|
import_weibo_cookies,
|
||||||
@@ -46,6 +50,7 @@ from ..services.weibo_service import (
|
|||||||
query_weibo_payment_status,
|
query_weibo_payment_status,
|
||||||
query_weibo_point_history,
|
query_weibo_point_history,
|
||||||
refresh_weibo_account,
|
refresh_weibo_account,
|
||||||
|
update_weibo_account_metadata,
|
||||||
)
|
)
|
||||||
|
|
||||||
router = APIRouter(prefix="/api/weibo", tags=["微博微豆"])
|
router = APIRouter(prefix="/api/weibo", tags=["微博微豆"])
|
||||||
@@ -81,6 +86,11 @@ def _account_out(account: WeiboAccount) -> WeiboAccountOut:
|
|||||||
return WeiboAccountOut.model_validate(account)
|
return WeiboAccountOut.model_validate(account)
|
||||||
|
|
||||||
|
|
||||||
|
def _ensure_enabled(account: WeiboAccount) -> None:
|
||||||
|
if not account.is_enabled:
|
||||||
|
raise HTTPException(status_code=409, detail="微博账号已停用,请先启用")
|
||||||
|
|
||||||
|
|
||||||
def _refresh_or_http(account: WeiboAccount, db: Session):
|
def _refresh_or_http(account: WeiboAccount, db: Session):
|
||||||
try:
|
try:
|
||||||
return refresh_weibo_account(
|
return refresh_weibo_account(
|
||||||
@@ -128,6 +138,7 @@ def _record_audit_safely(
|
|||||||
def list_accounts(
|
def list_accounts(
|
||||||
search: str = Query(""),
|
search: str = Query(""),
|
||||||
bind_status: str = Query(""),
|
bind_status: str = Query(""),
|
||||||
|
enabled: bool | None = Query(None),
|
||||||
page: int = Query(1, ge=1),
|
page: int = Query(1, ge=1),
|
||||||
page_size: int = Query(20, ge=1, le=200),
|
page_size: int = Query(20, ge=1, le=200),
|
||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
@@ -146,8 +157,11 @@ def list_accounts(
|
|||||||
WeiboAccount.nickname.ilike(pattern),
|
WeiboAccount.nickname.ilike(pattern),
|
||||||
WeiboAccount.game_role_name.ilike(pattern),
|
WeiboAccount.game_role_name.ilike(pattern),
|
||||||
WeiboAccount.tag.ilike(pattern),
|
WeiboAccount.tag.ilike(pattern),
|
||||||
|
WeiboAccount.remark.ilike(pattern),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
if isinstance(enabled, bool):
|
||||||
|
query = query.filter(WeiboAccount.is_enabled.is_(enabled))
|
||||||
bind_value = _query_str(bind_status)
|
bind_value = _query_str(bind_status)
|
||||||
if bind_value == "unbound":
|
if bind_value == "unbound":
|
||||||
query = query.filter(WeiboAccount.is_bound.is_(False))
|
query = query.filter(WeiboAccount.is_bound.is_(False))
|
||||||
@@ -175,6 +189,95 @@ def list_accounts(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/accounts/{account_id}", response_model=WeiboAccountOut)
|
||||||
|
def get_account(
|
||||||
|
account_id: int,
|
||||||
|
db: Session = Depends(get_db),
|
||||||
|
current: User = Depends(get_current_user),
|
||||||
|
):
|
||||||
|
"""查看一个微博账号的本地资料。"""
|
||||||
|
|
||||||
|
_require_weibo_perm(current, "weibo:view")
|
||||||
|
return _account_out(_get_account(db, account_id))
|
||||||
|
|
||||||
|
|
||||||
|
@router.put("/accounts/{account_id}", response_model=WeiboAccountOut)
|
||||||
|
def update_account(
|
||||||
|
account_id: int,
|
||||||
|
req: WeiboAccountUpdate,
|
||||||
|
db: Session = Depends(get_db),
|
||||||
|
current: User = Depends(get_current_user),
|
||||||
|
):
|
||||||
|
"""更新账号的人工标签和备注。"""
|
||||||
|
|
||||||
|
_require_weibo_perm(current, "weibo:manage")
|
||||||
|
account = _get_account(db, account_id)
|
||||||
|
payload = req.model_dump(exclude_unset=True)
|
||||||
|
changes = update_weibo_account_metadata(
|
||||||
|
db,
|
||||||
|
account,
|
||||||
|
tag=payload.get("tag"),
|
||||||
|
remark=payload.get("remark"),
|
||||||
|
)
|
||||||
|
if changes:
|
||||||
|
_record_audit_safely(
|
||||||
|
db,
|
||||||
|
current,
|
||||||
|
action="weibo:account:update",
|
||||||
|
target=f"weibo_account:{account.id}",
|
||||||
|
detail={"account_id": account.id, "uid": account.uid, "changes": changes},
|
||||||
|
)
|
||||||
|
return _account_out(account)
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/accounts/{account_id}/disable", response_model=WeiboAccountOut)
|
||||||
|
def disable_account(
|
||||||
|
account_id: int,
|
||||||
|
req: WeiboAccountDisableRequest,
|
||||||
|
db: Session = Depends(get_db),
|
||||||
|
current: User = Depends(get_current_user),
|
||||||
|
):
|
||||||
|
"""停用账号,保留 CK 和历史资料。"""
|
||||||
|
|
||||||
|
_require_weibo_perm(current, "weibo:manage")
|
||||||
|
account = _get_account(db, account_id)
|
||||||
|
disable_weibo_account(db, account, reason=req.reason)
|
||||||
|
_record_audit_safely(
|
||||||
|
db,
|
||||||
|
current,
|
||||||
|
action="weibo:account:disable",
|
||||||
|
target=f"weibo_account:{account.id}",
|
||||||
|
detail={
|
||||||
|
"account_id": account.id,
|
||||||
|
"uid": account.uid,
|
||||||
|
"reason": account.disabled_reason,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
return _account_out(account)
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/accounts/{account_id}/enable", response_model=WeiboAccountOut)
|
||||||
|
def enable_account(
|
||||||
|
account_id: int,
|
||||||
|
db: Session = Depends(get_db),
|
||||||
|
current: User = Depends(get_current_user),
|
||||||
|
):
|
||||||
|
"""重新检测 CK 与支付风险,通过后启用账号。"""
|
||||||
|
|
||||||
|
_require_weibo_perm(current, "weibo:manage")
|
||||||
|
account = _get_account(db, account_id)
|
||||||
|
_refresh_or_http(account, db)
|
||||||
|
enable_weibo_account(db, account)
|
||||||
|
_record_audit_safely(
|
||||||
|
db,
|
||||||
|
current,
|
||||||
|
action="weibo:account:enable",
|
||||||
|
target=f"weibo_account:{account.id}",
|
||||||
|
detail={"account_id": account.id, "uid": account.uid},
|
||||||
|
)
|
||||||
|
return _account_out(account)
|
||||||
|
|
||||||
|
|
||||||
@router.post("/accounts/import-cookies", response_model=WeiboImportResult)
|
@router.post("/accounts/import-cookies", response_model=WeiboImportResult)
|
||||||
def import_cookies(
|
def import_cookies(
|
||||||
req: WeiboCookieImport,
|
req: WeiboCookieImport,
|
||||||
@@ -231,6 +334,7 @@ def refresh_account(
|
|||||||
|
|
||||||
_require_weibo_perm(current, "weibo:view")
|
_require_weibo_perm(current, "weibo:view")
|
||||||
account = _get_account(db, account_id)
|
account = _get_account(db, account_id)
|
||||||
|
_ensure_enabled(account)
|
||||||
_refresh_or_http(account, db)
|
_refresh_or_http(account, db)
|
||||||
_record_audit_safely(
|
_record_audit_safely(
|
||||||
db,
|
db,
|
||||||
@@ -252,6 +356,7 @@ def create_bind_qrcodes(
|
|||||||
|
|
||||||
_require_weibo_perm(current, "weibo:bind")
|
_require_weibo_perm(current, "weibo:bind")
|
||||||
account = _get_account(db, account_id)
|
account = _get_account(db, account_id)
|
||||||
|
_ensure_enabled(account)
|
||||||
snapshot = _refresh_or_http(account, db)
|
snapshot = _refresh_or_http(account, db)
|
||||||
if snapshot.is_bound and not snapshot.can_rebind:
|
if snapshot.is_bound and not snapshot.can_rebind:
|
||||||
detail = (
|
detail = (
|
||||||
@@ -314,6 +419,7 @@ def list_mall_goods(
|
|||||||
|
|
||||||
_require_weibo_perm(current, "weibo:view")
|
_require_weibo_perm(current, "weibo:view")
|
||||||
account = _get_account(db, account_id)
|
account = _get_account(db, account_id)
|
||||||
|
_ensure_enabled(account)
|
||||||
try:
|
try:
|
||||||
data = query_weibo_mall(
|
data = query_weibo_mall(
|
||||||
db,
|
db,
|
||||||
@@ -366,6 +472,7 @@ def exchange_goods(
|
|||||||
if not req.confirm:
|
if not req.confirm:
|
||||||
raise HTTPException(status_code=400, detail="请先确认兑换商品")
|
raise HTTPException(status_code=400, detail="请先确认兑换商品")
|
||||||
account = _get_account(db, account_id)
|
account = _get_account(db, account_id)
|
||||||
|
_ensure_enabled(account)
|
||||||
try:
|
try:
|
||||||
result = exchange_weibo_goods(
|
result = exchange_weibo_goods(
|
||||||
db,
|
db,
|
||||||
@@ -423,6 +530,7 @@ def list_exchange_records(
|
|||||||
|
|
||||||
_require_weibo_perm(current, "weibo:view")
|
_require_weibo_perm(current, "weibo:view")
|
||||||
account = _get_account(db, account_id)
|
account = _get_account(db, account_id)
|
||||||
|
_ensure_enabled(account)
|
||||||
try:
|
try:
|
||||||
data = query_weibo_exchange_records(
|
data = query_weibo_exchange_records(
|
||||||
db,
|
db,
|
||||||
@@ -471,6 +579,7 @@ def list_point_history(
|
|||||||
|
|
||||||
_require_weibo_perm(current, "weibo:view")
|
_require_weibo_perm(current, "weibo:view")
|
||||||
account = _get_account(db, account_id)
|
account = _get_account(db, account_id)
|
||||||
|
_ensure_enabled(account)
|
||||||
try:
|
try:
|
||||||
data = query_weibo_point_history(
|
data = query_weibo_point_history(
|
||||||
db,
|
db,
|
||||||
@@ -520,6 +629,7 @@ def create_recharge_order(
|
|||||||
|
|
||||||
_require_weibo_perm(current, "weibo:recharge")
|
_require_weibo_perm(current, "weibo:recharge")
|
||||||
account = _get_account(db, account_id)
|
account = _get_account(db, account_id)
|
||||||
|
_ensure_enabled(account)
|
||||||
try:
|
try:
|
||||||
order = create_weibo_recharge_order(
|
order = create_weibo_recharge_order(
|
||||||
db,
|
db,
|
||||||
@@ -567,6 +677,7 @@ def get_recharge_status(
|
|||||||
|
|
||||||
_require_weibo_perm(current, "weibo:recharge")
|
_require_weibo_perm(current, "weibo:recharge")
|
||||||
account = _get_account(db, account_id)
|
account = _get_account(db, account_id)
|
||||||
|
_ensure_enabled(account)
|
||||||
try:
|
try:
|
||||||
status = query_weibo_payment_status(db, account, pay_id=req.pay_id)
|
status = query_weibo_payment_status(db, account, pay_id=req.pay_id)
|
||||||
except (WeiboError, ValueError) as exc:
|
except (WeiboError, ValueError) as exc:
|
||||||
|
|||||||
@@ -480,7 +480,11 @@ class WeiboAccountOut(BaseModel):
|
|||||||
uid: str
|
uid: str
|
||||||
nickname: str = ""
|
nickname: str = ""
|
||||||
tag: str = ""
|
tag: str = ""
|
||||||
|
remark: str = ""
|
||||||
activity: str = ""
|
activity: str = ""
|
||||||
|
is_enabled: bool = True
|
||||||
|
disabled_at: datetime | None = None
|
||||||
|
disabled_reason: str = ""
|
||||||
ck_check_status: str = ""
|
ck_check_status: str = ""
|
||||||
ck_check_message: str = ""
|
ck_check_message: str = ""
|
||||||
ck_checked_at: datetime | None = None
|
ck_checked_at: datetime | None = None
|
||||||
@@ -496,6 +500,15 @@ class WeiboAccountOut(BaseModel):
|
|||||||
model_config = ConfigDict(from_attributes=True)
|
model_config = ConfigDict(from_attributes=True)
|
||||||
|
|
||||||
|
|
||||||
|
class WeiboAccountUpdate(BaseModel):
|
||||||
|
tag: str | None = Field(None, max_length=64)
|
||||||
|
remark: str | None = Field(None, max_length=256)
|
||||||
|
|
||||||
|
|
||||||
|
class WeiboAccountDisableRequest(BaseModel):
|
||||||
|
reason: str = Field("", max_length=256)
|
||||||
|
|
||||||
|
|
||||||
class WeiboImportResult(BaseModel):
|
class WeiboImportResult(BaseModel):
|
||||||
success: bool
|
success: bool
|
||||||
message: str
|
message: str
|
||||||
|
|||||||
@@ -135,6 +135,64 @@ def refresh_weibo_account(
|
|||||||
return snapshot
|
return snapshot
|
||||||
|
|
||||||
|
|
||||||
|
def update_weibo_account_metadata(
|
||||||
|
db: Session,
|
||||||
|
account: WeiboAccount,
|
||||||
|
*,
|
||||||
|
tag: str | None = None,
|
||||||
|
remark: str | None = None,
|
||||||
|
) -> dict[str, dict[str, str]]:
|
||||||
|
"""更新人工维护的账号标签与备注。"""
|
||||||
|
|
||||||
|
changes: dict[str, dict[str, str]] = {}
|
||||||
|
if tag is not None:
|
||||||
|
clean_tag = tag.strip()
|
||||||
|
if clean_tag != (account.tag or ""):
|
||||||
|
changes["tag"] = {"old": account.tag or "", "new": clean_tag}
|
||||||
|
account.tag = clean_tag
|
||||||
|
if remark is not None:
|
||||||
|
clean_remark = remark.strip()
|
||||||
|
if clean_remark != (account.remark or ""):
|
||||||
|
changes["remark"] = {
|
||||||
|
"old": account.remark or "",
|
||||||
|
"new": clean_remark,
|
||||||
|
}
|
||||||
|
account.remark = clean_remark
|
||||||
|
if changes:
|
||||||
|
db.commit()
|
||||||
|
db.refresh(account)
|
||||||
|
return changes
|
||||||
|
|
||||||
|
|
||||||
|
def disable_weibo_account(
|
||||||
|
db: Session,
|
||||||
|
account: WeiboAccount,
|
||||||
|
*,
|
||||||
|
reason: str = "",
|
||||||
|
) -> None:
|
||||||
|
"""停用账号;保留 CK 和资料,后续可重新启用。"""
|
||||||
|
|
||||||
|
if not account.is_enabled:
|
||||||
|
return
|
||||||
|
account.is_enabled = False
|
||||||
|
account.disabled_at = _now()
|
||||||
|
account.disabled_reason = reason.strip()[:256]
|
||||||
|
db.commit()
|
||||||
|
db.refresh(account)
|
||||||
|
|
||||||
|
|
||||||
|
def enable_weibo_account(db: Session, account: WeiboAccount) -> None:
|
||||||
|
"""启用已通过完整 CK 检测的账号。"""
|
||||||
|
|
||||||
|
if account.is_enabled:
|
||||||
|
return
|
||||||
|
account.is_enabled = True
|
||||||
|
account.disabled_at = None
|
||||||
|
account.disabled_reason = ""
|
||||||
|
db.commit()
|
||||||
|
db.refresh(account)
|
||||||
|
|
||||||
|
|
||||||
def generate_weibo_bind_schemes(
|
def generate_weibo_bind_schemes(
|
||||||
account: WeiboAccount,
|
account: WeiboAccount,
|
||||||
bind_url: str,
|
bind_url: str,
|
||||||
|
|||||||
@@ -753,6 +753,10 @@ export interface WeiboAccountItem {
|
|||||||
uid: string;
|
uid: string;
|
||||||
nickname: string;
|
nickname: string;
|
||||||
tag: string;
|
tag: string;
|
||||||
|
remark: string;
|
||||||
|
is_enabled: boolean;
|
||||||
|
disabled_at: string | null;
|
||||||
|
disabled_reason: string;
|
||||||
ck_check_status: string;
|
ck_check_status: string;
|
||||||
ck_check_message: string;
|
ck_check_message: string;
|
||||||
ck_checked_at: string | null;
|
ck_checked_at: string | null;
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ export const weiboApi = {
|
|||||||
listAccounts: (params: {
|
listAccounts: (params: {
|
||||||
search?: string;
|
search?: string;
|
||||||
bind_status?: string;
|
bind_status?: string;
|
||||||
|
enabled?: boolean;
|
||||||
page: number;
|
page: number;
|
||||||
page_size: number;
|
page_size: number;
|
||||||
}) =>
|
}) =>
|
||||||
@@ -24,11 +25,32 @@ export const weiboApi = {
|
|||||||
'/weibo/accounts',
|
'/weibo/accounts',
|
||||||
{ params },
|
{ params },
|
||||||
),
|
),
|
||||||
|
getAccount: (accountId: number) =>
|
||||||
|
api.get<WeiboAccountItem, WeiboAccountItem>(`/weibo/accounts/${accountId}`),
|
||||||
importCookies: (text: string, tag = '') =>
|
importCookies: (text: string, tag = '') =>
|
||||||
api.post<WeiboImportResult, WeiboImportResult>('/weibo/accounts/import-cookies', {
|
api.post<WeiboImportResult, WeiboImportResult>('/weibo/accounts/import-cookies', {
|
||||||
text,
|
text,
|
||||||
tag,
|
tag,
|
||||||
}),
|
}),
|
||||||
|
updateAccount: (
|
||||||
|
accountId: number,
|
||||||
|
data: { tag?: string; remark?: string },
|
||||||
|
) =>
|
||||||
|
api.put<WeiboAccountItem, WeiboAccountItem>(
|
||||||
|
`/weibo/accounts/${accountId}`,
|
||||||
|
data,
|
||||||
|
),
|
||||||
|
disableAccount: (accountId: number, reason = '') =>
|
||||||
|
api.post<WeiboAccountItem, WeiboAccountItem>(
|
||||||
|
`/weibo/accounts/${accountId}/disable`,
|
||||||
|
{ reason },
|
||||||
|
),
|
||||||
|
enableAccount: (accountId: number) =>
|
||||||
|
api.post<WeiboAccountItem, WeiboAccountItem>(
|
||||||
|
`/weibo/accounts/${accountId}/enable`,
|
||||||
|
undefined,
|
||||||
|
{ timeout: 120000 },
|
||||||
|
),
|
||||||
refreshAccount: (accountId: number) =>
|
refreshAccount: (accountId: number) =>
|
||||||
api.post<WeiboAccountItem, WeiboAccountItem>(
|
api.post<WeiboAccountItem, WeiboAccountItem>(
|
||||||
`/weibo/accounts/${accountId}/refresh`,
|
`/weibo/accounts/${accountId}/refresh`,
|
||||||
|
|||||||
@@ -24,10 +24,13 @@ import type { TableProps } from 'antd';
|
|||||||
import {
|
import {
|
||||||
DeleteOutlined,
|
DeleteOutlined,
|
||||||
AppstoreOutlined,
|
AppstoreOutlined,
|
||||||
|
CheckCircleOutlined,
|
||||||
|
EditOutlined,
|
||||||
ImportOutlined,
|
ImportOutlined,
|
||||||
QrcodeOutlined,
|
QrcodeOutlined,
|
||||||
ReloadOutlined,
|
ReloadOutlined,
|
||||||
SearchOutlined,
|
SearchOutlined,
|
||||||
|
StopOutlined,
|
||||||
} from '@ant-design/icons';
|
} from '@ant-design/icons';
|
||||||
import {
|
import {
|
||||||
weiboApi,
|
weiboApi,
|
||||||
@@ -78,6 +81,7 @@ export default function WeiboAccountsPage() {
|
|||||||
const { token } = theme.useToken();
|
const { token } = theme.useToken();
|
||||||
const { can } = usePermissions();
|
const { can } = usePermissions();
|
||||||
const canImport = can('weibo:import');
|
const canImport = can('weibo:import');
|
||||||
|
const canManage = can('weibo:manage');
|
||||||
const canBind = can('weibo:bind');
|
const canBind = can('weibo:bind');
|
||||||
const canRecharge = can('weibo:recharge');
|
const canRecharge = can('weibo:recharge');
|
||||||
const canExchange = can('weibo:exchange');
|
const canExchange = can('weibo:exchange');
|
||||||
@@ -89,13 +93,19 @@ export default function WeiboAccountsPage() {
|
|||||||
const [pageSize, setPageSize] = useState(20);
|
const [pageSize, setPageSize] = useState(20);
|
||||||
const [search, setSearch] = useState('');
|
const [search, setSearch] = useState('');
|
||||||
const [bindFilter, setBindFilter] = useState('');
|
const [bindFilter, setBindFilter] = useState('');
|
||||||
|
const [enabledFilter, setEnabledFilter] = useState('');
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [refreshingId, setRefreshingId] = useState<number | null>(null);
|
const [refreshingId, setRefreshingId] = useState<number | null>(null);
|
||||||
|
const [mutatingId, setMutatingId] = useState<number | null>(null);
|
||||||
|
|
||||||
const [importOpen, setImportOpen] = useState(false);
|
const [importOpen, setImportOpen] = useState(false);
|
||||||
const [importing, setImporting] = useState(false);
|
const [importing, setImporting] = useState(false);
|
||||||
const [importErrors, setImportErrors] = useState<WeiboImportError[]>([]);
|
const [importErrors, setImportErrors] = useState<WeiboImportError[]>([]);
|
||||||
const [form] = Form.useForm<{ text: string; tag?: string }>();
|
const [form] = Form.useForm<{ text: string; tag?: string }>();
|
||||||
|
const [editForm] = Form.useForm<{ tag?: string; remark?: string }>();
|
||||||
|
const [editOpen, setEditOpen] = useState(false);
|
||||||
|
const [editAccount, setEditAccount] = useState<WeiboAccountItem | null>(null);
|
||||||
|
const [editSaving, setEditSaving] = useState(false);
|
||||||
|
|
||||||
const [qrOpen, setQrOpen] = useState(false);
|
const [qrOpen, setQrOpen] = useState(false);
|
||||||
const [qrAccount, setQrAccount] = useState<WeiboAccountItem | null>(null);
|
const [qrAccount, setQrAccount] = useState<WeiboAccountItem | null>(null);
|
||||||
@@ -127,6 +137,12 @@ export default function WeiboAccountsPage() {
|
|||||||
const data: PaginatedResponse<WeiboAccountItem> = await weiboApi.listAccounts({
|
const data: PaginatedResponse<WeiboAccountItem> = await weiboApi.listAccounts({
|
||||||
search: search.trim() || undefined,
|
search: search.trim() || undefined,
|
||||||
bind_status: bindFilter || undefined,
|
bind_status: bindFilter || undefined,
|
||||||
|
enabled:
|
||||||
|
enabledFilter === 'enabled'
|
||||||
|
? true
|
||||||
|
: enabledFilter === 'disabled'
|
||||||
|
? false
|
||||||
|
: undefined,
|
||||||
page,
|
page,
|
||||||
page_size: pageSize,
|
page_size: pageSize,
|
||||||
});
|
});
|
||||||
@@ -137,7 +153,7 @@ export default function WeiboAccountsPage() {
|
|||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
}, [bindFilter, page, pageSize, search]);
|
}, [bindFilter, enabledFilter, page, pageSize, search]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
void loadAccounts();
|
void loadAccounts();
|
||||||
@@ -167,6 +183,10 @@ export default function WeiboAccountsPage() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleRefresh = async (account: WeiboAccountItem) => {
|
const handleRefresh = async (account: WeiboAccountItem) => {
|
||||||
|
if (!account.is_enabled) {
|
||||||
|
message.warning('账号已停用,请先启用');
|
||||||
|
return;
|
||||||
|
}
|
||||||
setRefreshingId(account.id);
|
setRefreshingId(account.id);
|
||||||
try {
|
try {
|
||||||
const updated = await weiboApi.refreshAccount(account.id);
|
const updated = await weiboApi.refreshAccount(account.id);
|
||||||
@@ -186,6 +206,10 @@ export default function WeiboAccountsPage() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const openQr = async (account: WeiboAccountItem) => {
|
const openQr = async (account: WeiboAccountItem) => {
|
||||||
|
if (!account.is_enabled) {
|
||||||
|
message.warning('账号已停用,请先启用');
|
||||||
|
return;
|
||||||
|
}
|
||||||
setQrAccount(account);
|
setQrAccount(account);
|
||||||
setQrResult(null);
|
setQrResult(null);
|
||||||
setQrOpen(true);
|
setQrOpen(true);
|
||||||
@@ -213,6 +237,67 @@ export default function WeiboAccountsPage() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const openEdit = (account: WeiboAccountItem) => {
|
||||||
|
setEditAccount(account);
|
||||||
|
editForm.setFieldsValue({ tag: account.tag, remark: account.remark });
|
||||||
|
setEditOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleEdit = async () => {
|
||||||
|
if (!editAccount) return;
|
||||||
|
const values = await editForm.validateFields();
|
||||||
|
setEditSaving(true);
|
||||||
|
try {
|
||||||
|
const updated = await weiboApi.updateAccount(editAccount.id, {
|
||||||
|
tag: values.tag || '',
|
||||||
|
remark: values.remark || '',
|
||||||
|
});
|
||||||
|
setItems((current) =>
|
||||||
|
current.map((item) => (item.id === updated.id ? updated : item)),
|
||||||
|
);
|
||||||
|
setEditOpen(false);
|
||||||
|
message.success('账号资料已更新');
|
||||||
|
} catch (error) {
|
||||||
|
message.error(getErrorMessage(error));
|
||||||
|
} finally {
|
||||||
|
setEditSaving(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDisable = async (account: WeiboAccountItem) => {
|
||||||
|
setMutatingId(account.id);
|
||||||
|
try {
|
||||||
|
const updated = await weiboApi.disableAccount(account.id);
|
||||||
|
setItems((current) =>
|
||||||
|
current.map((item) => (item.id === updated.id ? updated : item)),
|
||||||
|
);
|
||||||
|
setFeatureAccount((current) =>
|
||||||
|
current?.id === updated.id ? updated : current,
|
||||||
|
);
|
||||||
|
message.success('账号已停用');
|
||||||
|
} catch (error) {
|
||||||
|
message.error(getErrorMessage(error));
|
||||||
|
} finally {
|
||||||
|
setMutatingId(null);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleEnable = async (account: WeiboAccountItem) => {
|
||||||
|
setMutatingId(account.id);
|
||||||
|
try {
|
||||||
|
const updated = await weiboApi.enableAccount(account.id);
|
||||||
|
setItems((current) =>
|
||||||
|
current.map((item) => (item.id === updated.id ? updated : item)),
|
||||||
|
);
|
||||||
|
message.success('账号已通过检测并启用');
|
||||||
|
} catch (error) {
|
||||||
|
message.error(getErrorMessage(error));
|
||||||
|
void loadAccounts();
|
||||||
|
} finally {
|
||||||
|
setMutatingId(null);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const loadMall = async (account: WeiboAccountItem) => {
|
const loadMall = async (account: WeiboAccountItem) => {
|
||||||
setMallLoading(true);
|
setMallLoading(true);
|
||||||
try {
|
try {
|
||||||
@@ -226,6 +311,10 @@ export default function WeiboAccountsPage() {
|
|||||||
|
|
||||||
const handleExchange = async (goods: WeiboMallListResult['goods'][number]) => {
|
const handleExchange = async (goods: WeiboMallListResult['goods'][number]) => {
|
||||||
if (!featureAccount) return;
|
if (!featureAccount) return;
|
||||||
|
if (!featureAccount.is_enabled) {
|
||||||
|
message.warning('账号已停用,请先启用');
|
||||||
|
return;
|
||||||
|
}
|
||||||
setExchangingGoodsId(goods.id);
|
setExchangingGoodsId(goods.id);
|
||||||
try {
|
try {
|
||||||
const result = await weiboApi.exchangeGoods(
|
const result = await weiboApi.exchangeGoods(
|
||||||
@@ -273,6 +362,10 @@ export default function WeiboAccountsPage() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const openFeatures = (account: WeiboAccountItem) => {
|
const openFeatures = (account: WeiboAccountItem) => {
|
||||||
|
if (!account.is_enabled) {
|
||||||
|
message.warning('账号已停用,请先启用');
|
||||||
|
return;
|
||||||
|
}
|
||||||
setFeatureAccount(account);
|
setFeatureAccount(account);
|
||||||
setFeatureOpen(true);
|
setFeatureOpen(true);
|
||||||
setFeatureTab('goods');
|
setFeatureTab('goods');
|
||||||
@@ -297,6 +390,10 @@ export default function WeiboAccountsPage() {
|
|||||||
|
|
||||||
const createRecharge = async () => {
|
const createRecharge = async () => {
|
||||||
if (!featureAccount) return;
|
if (!featureAccount) return;
|
||||||
|
if (!featureAccount.is_enabled) {
|
||||||
|
message.warning('账号已停用,请先启用');
|
||||||
|
return;
|
||||||
|
}
|
||||||
setRechargeCreating(true);
|
setRechargeCreating(true);
|
||||||
setPaymentStatus(null);
|
setPaymentStatus(null);
|
||||||
try {
|
try {
|
||||||
@@ -346,6 +443,13 @@ export default function WeiboAccountsPage() {
|
|||||||
<Text type="secondary" style={{ fontSize: 12 }}>
|
<Text type="secondary" style={{ fontSize: 12 }}>
|
||||||
UID {account.uid}
|
UID {account.uid}
|
||||||
</Text>
|
</Text>
|
||||||
|
{account.remark && (
|
||||||
|
<Tooltip title={account.remark}>
|
||||||
|
<Text type="secondary" ellipsis style={{ fontSize: 12, maxWidth: 190 }}>
|
||||||
|
{account.remark}
|
||||||
|
</Text>
|
||||||
|
</Tooltip>
|
||||||
|
)}
|
||||||
</Space>
|
</Space>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
@@ -371,6 +475,24 @@ export default function WeiboAccountsPage() {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: '启用状态',
|
||||||
|
dataIndex: 'is_enabled',
|
||||||
|
width: 100,
|
||||||
|
render: (value: boolean, account) => (
|
||||||
|
<Tooltip
|
||||||
|
title={
|
||||||
|
value
|
||||||
|
? '账号正在使用'
|
||||||
|
: account.disabled_reason || account.disabled_at || '账号已停用'
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Tag color={value ? 'success' : 'default'}>
|
||||||
|
{value ? '已启用' : '已停用'}
|
||||||
|
</Tag>
|
||||||
|
</Tooltip>
|
||||||
|
),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: '角色绑定',
|
title: '角色绑定',
|
||||||
key: 'bind',
|
key: 'bind',
|
||||||
@@ -404,17 +526,19 @@ export default function WeiboAccountsPage() {
|
|||||||
{
|
{
|
||||||
title: '操作',
|
title: '操作',
|
||||||
key: 'actions',
|
key: 'actions',
|
||||||
width: 390,
|
width: 540,
|
||||||
fixed: 'right',
|
fixed: 'right',
|
||||||
render: (_, account) => {
|
render: (_, account) => {
|
||||||
const cannotBind =
|
const cannotBind =
|
||||||
account.is_bound === true && account.can_rebind !== true;
|
account.is_bound === true && account.can_rebind !== true;
|
||||||
|
const busy = mutatingId === account.id;
|
||||||
return (
|
return (
|
||||||
<Space>
|
<Space wrap>
|
||||||
<Button
|
<Button
|
||||||
size="small"
|
size="small"
|
||||||
icon={<ReloadOutlined />}
|
icon={<ReloadOutlined />}
|
||||||
loading={refreshingId === account.id}
|
loading={refreshingId === account.id}
|
||||||
|
disabled={!account.is_enabled}
|
||||||
onClick={() => void handleRefresh(account)}
|
onClick={() => void handleRefresh(account)}
|
||||||
>
|
>
|
||||||
刷新
|
刷新
|
||||||
@@ -431,7 +555,7 @@ export default function WeiboAccountsPage() {
|
|||||||
type="primary"
|
type="primary"
|
||||||
ghost
|
ghost
|
||||||
icon={<QrcodeOutlined />}
|
icon={<QrcodeOutlined />}
|
||||||
disabled={!canBind || cannotBind}
|
disabled={!canBind || cannotBind || !account.is_enabled}
|
||||||
onClick={() => void openQr(account)}
|
onClick={() => void openQr(account)}
|
||||||
>
|
>
|
||||||
绑定码
|
绑定码
|
||||||
@@ -440,10 +564,51 @@ export default function WeiboAccountsPage() {
|
|||||||
<Button
|
<Button
|
||||||
size="small"
|
size="small"
|
||||||
icon={<AppstoreOutlined />}
|
icon={<AppstoreOutlined />}
|
||||||
|
disabled={!account.is_enabled}
|
||||||
onClick={() => openFeatures(account)}
|
onClick={() => openFeatures(account)}
|
||||||
>
|
>
|
||||||
功能
|
功能
|
||||||
</Button>
|
</Button>
|
||||||
|
{canManage && (
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
icon={<EditOutlined />}
|
||||||
|
onClick={() => openEdit(account)}
|
||||||
|
>
|
||||||
|
编辑
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
{canManage &&
|
||||||
|
(account.is_enabled ? (
|
||||||
|
<Popconfirm
|
||||||
|
title="停用微博账号?"
|
||||||
|
description="停用后不能刷新、绑定、充值或兑换,但会保留 CK 和历史资料。"
|
||||||
|
okText="停用"
|
||||||
|
cancelText="取消"
|
||||||
|
okButtonProps={{ danger: true }}
|
||||||
|
onConfirm={() => void handleDisable(account)}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
danger
|
||||||
|
icon={<StopOutlined />}
|
||||||
|
loading={busy}
|
||||||
|
>
|
||||||
|
停用
|
||||||
|
</Button>
|
||||||
|
</Popconfirm>
|
||||||
|
) : (
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
type="primary"
|
||||||
|
ghost
|
||||||
|
icon={<CheckCircleOutlined />}
|
||||||
|
loading={busy}
|
||||||
|
onClick={() => void handleEnable(account)}
|
||||||
|
>
|
||||||
|
启用
|
||||||
|
</Button>
|
||||||
|
))}
|
||||||
{canDelete && (
|
{canDelete && (
|
||||||
<Popconfirm
|
<Popconfirm
|
||||||
title="删除微博账号?"
|
title="删除微博账号?"
|
||||||
@@ -514,6 +679,7 @@ export default function WeiboAccountsPage() {
|
|||||||
const balance = mallResult?.weidou_balance ?? featureAccount?.weidou_balance ?? 0;
|
const balance = mallResult?.weidou_balance ?? featureAccount?.weidou_balance ?? 0;
|
||||||
const disabled =
|
const disabled =
|
||||||
!canExchange ||
|
!canExchange ||
|
||||||
|
!featureAccount?.is_enabled ||
|
||||||
goods.is_sold_out ||
|
goods.is_sold_out ||
|
||||||
goods.remain_count === 0 ||
|
goods.remain_count === 0 ||
|
||||||
goods.price > balance;
|
goods.price > balance;
|
||||||
@@ -600,15 +766,15 @@ export default function WeiboAccountsPage() {
|
|||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
<Title level={4} style={{ margin: 0 }}>
|
<Title level={4} style={{ margin: 0 }}>
|
||||||
微博账号
|
微博外部 CK 账号
|
||||||
</Title>
|
</Title>
|
||||||
<Text type="secondary">CK 导入、微豆资料刷新和角色绑定二维码</Text>
|
<Text type="secondary">外部 CK 导入、账号生命周期、微豆资料和角色绑定</Text>
|
||||||
</div>
|
</div>
|
||||||
<Space wrap>
|
<Space wrap>
|
||||||
<Input
|
<Input
|
||||||
allowClear
|
allowClear
|
||||||
prefix={<SearchOutlined />}
|
prefix={<SearchOutlined />}
|
||||||
placeholder="UID、昵称、角色、标签"
|
placeholder="UID、昵称、角色、标签、备注"
|
||||||
value={search}
|
value={search}
|
||||||
onChange={(event) => {
|
onChange={(event) => {
|
||||||
setSearch(event.target.value);
|
setSearch(event.target.value);
|
||||||
@@ -630,6 +796,19 @@ export default function WeiboAccountsPage() {
|
|||||||
{ value: 'rebindable', label: '可换绑' },
|
{ value: 'rebindable', label: '可换绑' },
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
|
<Select
|
||||||
|
value={enabledFilter}
|
||||||
|
onChange={(value) => {
|
||||||
|
setEnabledFilter(value);
|
||||||
|
setPage(1);
|
||||||
|
}}
|
||||||
|
style={{ width: 130 }}
|
||||||
|
options={[
|
||||||
|
{ value: '', label: '全部生命周期' },
|
||||||
|
{ value: 'enabled', label: '已启用' },
|
||||||
|
{ value: 'disabled', label: '已停用' },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
<Button icon={<ReloadOutlined />} onClick={() => void loadAccounts()}>
|
<Button icon={<ReloadOutlined />} onClick={() => void loadAccounts()}>
|
||||||
刷新列表
|
刷新列表
|
||||||
</Button>
|
</Button>
|
||||||
@@ -642,7 +821,7 @@ export default function WeiboAccountsPage() {
|
|||||||
setImportOpen(true);
|
setImportOpen(true);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
导入 CK
|
导入外部 CK
|
||||||
</Button>
|
</Button>
|
||||||
</Space>
|
</Space>
|
||||||
</div>
|
</div>
|
||||||
@@ -660,7 +839,7 @@ export default function WeiboAccountsPage() {
|
|||||||
loading={loading}
|
loading={loading}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
dataSource={items}
|
dataSource={items}
|
||||||
scroll={{ x: 1180 }}
|
scroll={{ x: 1360 }}
|
||||||
pagination={{
|
pagination={{
|
||||||
current: page,
|
current: page,
|
||||||
pageSize,
|
pageSize,
|
||||||
@@ -718,6 +897,35 @@ export default function WeiboAccountsPage() {
|
|||||||
)}
|
)}
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
title={
|
||||||
|
editAccount
|
||||||
|
? `编辑账号 · ${editAccount.nickname || editAccount.uid}`
|
||||||
|
: '编辑账号'
|
||||||
|
}
|
||||||
|
open={editOpen}
|
||||||
|
confirmLoading={editSaving}
|
||||||
|
okText="保存"
|
||||||
|
cancelText="取消"
|
||||||
|
onOk={() => void handleEdit()}
|
||||||
|
onCancel={() => setEditOpen(false)}
|
||||||
|
destroyOnHidden
|
||||||
|
>
|
||||||
|
<Form form={editForm} layout="vertical" preserve={false}>
|
||||||
|
<Form.Item name="tag" label="标签">
|
||||||
|
<Input placeholder="可选,例如:客户A、活动账号" maxLength={64} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="remark" label="备注">
|
||||||
|
<TextArea
|
||||||
|
rows={4}
|
||||||
|
placeholder="记录客户、用途或人工处理说明"
|
||||||
|
maxLength={256}
|
||||||
|
showCount
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
</Modal>
|
||||||
|
|
||||||
<Modal
|
<Modal
|
||||||
title={qrAccount ? `绑定二维码 · ${qrAccount.nickname || qrAccount.uid}` : '绑定二维码'}
|
title={qrAccount ? `绑定二维码 · ${qrAccount.nickname || qrAccount.uid}` : '绑定二维码'}
|
||||||
open={qrOpen}
|
open={qrOpen}
|
||||||
@@ -901,6 +1109,7 @@ export default function WeiboAccountsPage() {
|
|||||||
<Button
|
<Button
|
||||||
type="primary"
|
type="primary"
|
||||||
loading={rechargeCreating}
|
loading={rechargeCreating}
|
||||||
|
disabled={!featureAccount.is_enabled}
|
||||||
onClick={() => void createRecharge()}
|
onClick={() => void createRecharge()}
|
||||||
>
|
>
|
||||||
创建充值订单
|
创建充值订单
|
||||||
|
|||||||
Reference in New Issue
Block a user