fix(douyu): 修正外部单兑换记录判定
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
"""斗鱼外部单协作:账号导入、状态机、鱼翅/积分与兑换记录查询。"""
|
"""斗鱼外部单协作:账号导入、状态机、鱼翅/积分与兑换记录查询。"""
|
||||||
|
|
||||||
|
from datetime import UTC, datetime, timedelta
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from tests.support.db import get_test_engine, make_test_session
|
from tests.support.db import get_test_engine, make_test_session
|
||||||
@@ -28,15 +30,32 @@ from web.backend.schemas import (
|
|||||||
from web.backend.services import douyu_collab_service as collab
|
from web.backend.services import douyu_collab_service as collab
|
||||||
|
|
||||||
|
|
||||||
|
def exchange_record(
|
||||||
|
*,
|
||||||
|
name: str = "礼包A",
|
||||||
|
commodity_id: str = "gift-a",
|
||||||
|
occurred_at: datetime | None = None,
|
||||||
|
) -> dict[str, str]:
|
||||||
|
moment = occurred_at or datetime.now(UTC)
|
||||||
|
return {
|
||||||
|
"commodityId": commodity_id,
|
||||||
|
"commodityName": name,
|
||||||
|
"time": str(int(moment.timestamp())),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class FakeClient:
|
class FakeClient:
|
||||||
def __init__(self, *, points=5000, fish=1000, records=None):
|
def __init__(self, *, points=5000, fish=1000, records=None):
|
||||||
self.points = points
|
self.points = points
|
||||||
self.fish = fish
|
self.fish = fish
|
||||||
self.records = records if records is not None else []
|
self.records = records if records is not None else []
|
||||||
|
self.elite_calls = 0
|
||||||
|
self.gold_calls = 0
|
||||||
self.records_calls = 0
|
self.records_calls = 0
|
||||||
self.orders_calls = 0
|
self.orders_calls = 0
|
||||||
|
|
||||||
def elite_user_info(self, **_):
|
def elite_user_info(self, **_):
|
||||||
|
self.elite_calls += 1
|
||||||
return {
|
return {
|
||||||
"manual_type": 1,
|
"manual_type": 1,
|
||||||
"manual_score": self.points,
|
"manual_score": self.points,
|
||||||
@@ -65,6 +84,7 @@ class FakeClient:
|
|||||||
}
|
}
|
||||||
|
|
||||||
def gold_account(self):
|
def gold_account(self):
|
||||||
|
self.gold_calls += 1
|
||||||
return {"gold": self.fish}
|
return {"gold": self.fish}
|
||||||
|
|
||||||
def list_goods(self, **_):
|
def list_goods(self, **_):
|
||||||
@@ -223,6 +243,7 @@ class TestDouyuCollabOrders:
|
|||||||
shop="店铺A",
|
shop="店铺A",
|
||||||
account_username="douyu-account-a",
|
account_username="douyu-account-a",
|
||||||
gift_name="礼包A",
|
gift_name="礼包A",
|
||||||
|
commodity_id="gift-a",
|
||||||
required_points=100,
|
required_points=100,
|
||||||
home_images=["collab/unlink.png"],
|
home_images=["collab/unlink.png"],
|
||||||
client=FakeClient(),
|
client=FakeClient(),
|
||||||
@@ -950,7 +971,7 @@ class TestDouyuCollabOrders:
|
|||||||
self.session,
|
self.session,
|
||||||
self.admin,
|
self.admin,
|
||||||
order,
|
order,
|
||||||
client=FakeClient(records=[{"commodityName": "礼包A"}]),
|
client=FakeClient(records=[exchange_record()]),
|
||||||
)
|
)
|
||||||
assert result["verdict"] == collab.VERDICT_SUCCESS
|
assert result["verdict"] == collab.VERDICT_SUCCESS
|
||||||
assert result["order"].status == collab.STATUS_DONE
|
assert result["order"].status == collab.STATUS_DONE
|
||||||
@@ -1395,7 +1416,7 @@ class TestDouyuCollabOrders:
|
|||||||
assert order.status == collab.STATUS_VOID
|
assert order.status == collab.STATUS_VOID
|
||||||
assert order.void_reason == "资料不全"
|
assert order.void_reason == "资料不全"
|
||||||
|
|
||||||
def test_points_shortage_enters_points_error(self):
|
def test_record_query_does_not_change_status_from_points_snapshot(self):
|
||||||
order = collab.create_order(
|
order = collab.create_order(
|
||||||
self.session,
|
self.session,
|
||||||
self.admin,
|
self.admin,
|
||||||
@@ -1422,8 +1443,8 @@ class TestDouyuCollabOrders:
|
|||||||
order,
|
order,
|
||||||
client=FakeClient(points=50, records=[]),
|
client=FakeClient(points=50, records=[]),
|
||||||
)
|
)
|
||||||
assert result["points_reason"] == "shortage"
|
assert result["verdict"] == collab.VERDICT_UNKNOWN
|
||||||
assert result["order"].status == collab.STATUS_POINTS_ERROR
|
assert result["order"].status == collab.STATUS_RECHARGED
|
||||||
|
|
||||||
def test_balance_query_skips_records_and_never_changes_status(self):
|
def test_balance_query_skips_records_and_never_changes_status(self):
|
||||||
order = collab.create_order(
|
order = collab.create_order(
|
||||||
@@ -1446,7 +1467,7 @@ class TestDouyuCollabOrders:
|
|||||||
)
|
)
|
||||||
order.points_threshold = 10
|
order.points_threshold = 10
|
||||||
self.session.commit()
|
self.session.commit()
|
||||||
client = FakeClient(points=50, records=[{"commodityName": "礼包A"}])
|
client = FakeClient(points=50, records=[exchange_record()])
|
||||||
|
|
||||||
result = collab.query_activity(
|
result = collab.query_activity(
|
||||||
self.session,
|
self.session,
|
||||||
@@ -1496,7 +1517,7 @@ class TestDouyuCollabOrders:
|
|||||||
self.session,
|
self.session,
|
||||||
self.admin,
|
self.admin,
|
||||||
order,
|
order,
|
||||||
client=FakeClient(records=[{"commodityName": "礼包A"}]),
|
client=FakeClient(records=[exchange_record()]),
|
||||||
)
|
)
|
||||||
assert record_result["order"].status == collab.STATUS_DONE
|
assert record_result["order"].status == collab.STATUS_DONE
|
||||||
|
|
||||||
@@ -1515,6 +1536,247 @@ class TestDouyuCollabOrders:
|
|||||||
assert payload["last_records_matched"] == 1
|
assert payload["last_records_matched"] == 1
|
||||||
assert payload["last_metric_message"] == "仅查询鱼翅与积分,未查询兑换记录"
|
assert payload["last_metric_message"] == "仅查询鱼翅与积分,未查询兑换记录"
|
||||||
|
|
||||||
|
def test_record_query_only_calls_exchange_records(self):
|
||||||
|
order = collab.create_order(
|
||||||
|
self.session,
|
||||||
|
self.admin,
|
||||||
|
order_no="DY-RECORD-ONLY",
|
||||||
|
shop="店铺A",
|
||||||
|
account_username="douyu-account-a",
|
||||||
|
gift_name="礼包A",
|
||||||
|
required_points=100,
|
||||||
|
home_images=["collab/home-record-only.png"],
|
||||||
|
client=FakeClient(),
|
||||||
|
)
|
||||||
|
collab.set_status(
|
||||||
|
self.session,
|
||||||
|
self.admin,
|
||||||
|
order,
|
||||||
|
status=collab.STATUS_RECHARGED,
|
||||||
|
reason="鱼翅已充值",
|
||||||
|
)
|
||||||
|
collab.set_status(
|
||||||
|
self.session,
|
||||||
|
self.admin,
|
||||||
|
order,
|
||||||
|
status=collab.STATUS_SCRIPTED,
|
||||||
|
reason="脚本已上",
|
||||||
|
)
|
||||||
|
client = FakeClient(records=[exchange_record()])
|
||||||
|
|
||||||
|
result = collab.query_activity(
|
||||||
|
self.session,
|
||||||
|
self.admin,
|
||||||
|
order,
|
||||||
|
client=client,
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result["verdict"] == collab.VERDICT_SUCCESS
|
||||||
|
assert client.records_calls == 1
|
||||||
|
assert client.elite_calls == 0
|
||||||
|
assert client.gold_calls == 0
|
||||||
|
assert client.orders_calls == 0
|
||||||
|
|
||||||
|
def test_record_query_paginates_until_short_page(self):
|
||||||
|
order = collab.create_order(
|
||||||
|
self.session,
|
||||||
|
self.admin,
|
||||||
|
order_no="DY-RECORD-PAGES",
|
||||||
|
shop="店铺A",
|
||||||
|
account_username="douyu-account-a",
|
||||||
|
gift_name="礼包A",
|
||||||
|
commodity_id="gift-a",
|
||||||
|
required_points=100,
|
||||||
|
home_images=["collab/home-record-pages.png"],
|
||||||
|
client=FakeClient(),
|
||||||
|
)
|
||||||
|
records = [exchange_record() for _ in range(101)]
|
||||||
|
|
||||||
|
class PaginatedClient(FakeClient):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__(records=records)
|
||||||
|
self.offsets: list[int] = []
|
||||||
|
|
||||||
|
def exchange_records(self, *, limit, offset, **_):
|
||||||
|
self.offsets.append(offset)
|
||||||
|
self.records_calls += 1
|
||||||
|
return {"records": self.records[offset : offset + limit]}
|
||||||
|
|
||||||
|
client = PaginatedClient()
|
||||||
|
loaded = collab._load_exchange_records_for_orders(
|
||||||
|
self.session,
|
||||||
|
[order],
|
||||||
|
client=client,
|
||||||
|
)
|
||||||
|
|
||||||
|
assert client.offsets == [0, 100]
|
||||||
|
assert len(loaded) == 101
|
||||||
|
|
||||||
|
def test_record_query_rejects_old_record_and_wrong_commodity(self):
|
||||||
|
order = collab.create_order(
|
||||||
|
self.session,
|
||||||
|
self.admin,
|
||||||
|
order_no="DY-RECORD-WINDOW",
|
||||||
|
shop="店铺A",
|
||||||
|
account_username="douyu-account-a",
|
||||||
|
gift_name="礼包A",
|
||||||
|
commodity_id="gift-a",
|
||||||
|
required_points=100,
|
||||||
|
home_images=["collab/home-record-window.png"],
|
||||||
|
client=FakeClient(),
|
||||||
|
)
|
||||||
|
collab.set_status(
|
||||||
|
self.session,
|
||||||
|
self.admin,
|
||||||
|
order,
|
||||||
|
status=collab.STATUS_RECHARGED,
|
||||||
|
reason="鱼翅已充值",
|
||||||
|
)
|
||||||
|
collab.set_status(
|
||||||
|
self.session,
|
||||||
|
self.admin,
|
||||||
|
order,
|
||||||
|
status=collab.STATUS_SCRIPTED,
|
||||||
|
reason="脚本已上",
|
||||||
|
)
|
||||||
|
old_record = exchange_record(occurred_at=datetime.now(UTC) - timedelta(days=1))
|
||||||
|
wrong_commodity = exchange_record(
|
||||||
|
commodity_id="gift-other",
|
||||||
|
name="礼包A",
|
||||||
|
)
|
||||||
|
|
||||||
|
result = collab.query_activity(
|
||||||
|
self.session,
|
||||||
|
self.admin,
|
||||||
|
order,
|
||||||
|
client=FakeClient(records=[old_record, wrong_commodity]),
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result["verdict"] == collab.VERDICT_UNKNOWN
|
||||||
|
assert result["metric"].records_matched == 0
|
||||||
|
assert result["order"].status == collab.STATUS_SCRIPTED
|
||||||
|
|
||||||
|
def test_record_query_waits_for_settlement_before_failure(self):
|
||||||
|
order = collab.create_order(
|
||||||
|
self.session,
|
||||||
|
self.admin,
|
||||||
|
order_no="DY-RECORD-SETTLE",
|
||||||
|
shop="店铺A",
|
||||||
|
account_username="douyu-account-a",
|
||||||
|
gift_name="礼包A",
|
||||||
|
required_points=100,
|
||||||
|
home_images=["collab/home-record-settle.png"],
|
||||||
|
client=FakeClient(),
|
||||||
|
)
|
||||||
|
collab.set_status(
|
||||||
|
self.session,
|
||||||
|
self.admin,
|
||||||
|
order,
|
||||||
|
status=collab.STATUS_RECHARGED,
|
||||||
|
reason="鱼翅已充值",
|
||||||
|
)
|
||||||
|
collab.set_status(
|
||||||
|
self.session,
|
||||||
|
self.admin,
|
||||||
|
order,
|
||||||
|
status=collab.STATUS_SCRIPTED,
|
||||||
|
reason="脚本已上",
|
||||||
|
)
|
||||||
|
|
||||||
|
waiting = collab.query_activity(
|
||||||
|
self.session,
|
||||||
|
self.admin,
|
||||||
|
order,
|
||||||
|
client=FakeClient(records=[]),
|
||||||
|
)
|
||||||
|
assert waiting["verdict"] == collab.VERDICT_UNKNOWN
|
||||||
|
assert "结算等待期" in waiting["message"]
|
||||||
|
assert order.status == collab.STATUS_SCRIPTED
|
||||||
|
|
||||||
|
order.scripted_at = datetime.now(UTC) - timedelta(
|
||||||
|
seconds=collab.ACTIVITY_RECORD_SETTLE_SECONDS + 1
|
||||||
|
)
|
||||||
|
self.session.commit()
|
||||||
|
failed = collab.query_activity(
|
||||||
|
self.session,
|
||||||
|
self.admin,
|
||||||
|
order,
|
||||||
|
client=FakeClient(records=[]),
|
||||||
|
)
|
||||||
|
assert failed["verdict"] == collab.VERDICT_FAILED
|
||||||
|
assert failed["order"].status == collab.STATUS_FAILED
|
||||||
|
|
||||||
|
def test_batch_record_query_fetches_once_per_account(self, monkeypatch):
|
||||||
|
first = collab.create_order(
|
||||||
|
self.session,
|
||||||
|
self.admin,
|
||||||
|
order_no="DY-BATCH-RECORD-1",
|
||||||
|
shop="店铺A",
|
||||||
|
account_username="douyu-account-a",
|
||||||
|
gift_name="礼包A",
|
||||||
|
commodity_id="gift-a",
|
||||||
|
required_points=100,
|
||||||
|
home_images=["collab/home-batch-record-1.png"],
|
||||||
|
client=FakeClient(),
|
||||||
|
)
|
||||||
|
second = collab.create_order(
|
||||||
|
self.session,
|
||||||
|
self.admin,
|
||||||
|
order_no="DY-BATCH-RECORD-2",
|
||||||
|
shop="店铺A",
|
||||||
|
account_username="douyu-account-a",
|
||||||
|
gift_name="礼包B",
|
||||||
|
commodity_id="gift-b",
|
||||||
|
required_points=200,
|
||||||
|
home_images=["collab/home-batch-record-2.png"],
|
||||||
|
client=FakeClient(),
|
||||||
|
)
|
||||||
|
for order in (first, second):
|
||||||
|
collab.set_status(
|
||||||
|
self.session,
|
||||||
|
self.admin,
|
||||||
|
order,
|
||||||
|
status=collab.STATUS_RECHARGED,
|
||||||
|
reason="鱼翅已充值",
|
||||||
|
)
|
||||||
|
collab.set_status(
|
||||||
|
self.session,
|
||||||
|
self.admin,
|
||||||
|
order,
|
||||||
|
status=collab.STATUS_SCRIPTED,
|
||||||
|
reason="脚本已上",
|
||||||
|
)
|
||||||
|
|
||||||
|
calls: list[int] = []
|
||||||
|
records = [
|
||||||
|
exchange_record(name="礼包A", commodity_id="gift-a"),
|
||||||
|
exchange_record(name="礼包B", commodity_id="gift-b"),
|
||||||
|
]
|
||||||
|
|
||||||
|
def load_records(_db, account_orders, *, client=None):
|
||||||
|
del client
|
||||||
|
calls.append(int(account_orders[0].account_id or 0))
|
||||||
|
return records
|
||||||
|
|
||||||
|
monkeypatch.setattr(
|
||||||
|
collab,
|
||||||
|
"_load_exchange_records_for_orders",
|
||||||
|
load_records,
|
||||||
|
)
|
||||||
|
results = collab.query_activity_batch(
|
||||||
|
self.session,
|
||||||
|
self.admin,
|
||||||
|
[first, second],
|
||||||
|
)
|
||||||
|
|
||||||
|
assert len(calls) == 1
|
||||||
|
assert [item["verdict"] for item in results] == [
|
||||||
|
collab.VERDICT_SUCCESS,
|
||||||
|
collab.VERDICT_SUCCESS,
|
||||||
|
]
|
||||||
|
assert first.status == collab.STATUS_DONE
|
||||||
|
assert second.status == collab.STATUS_DONE
|
||||||
|
|
||||||
def test_draft_can_be_created_before_account_resolution(self):
|
def test_draft_can_be_created_before_account_resolution(self):
|
||||||
order = collab.create_order(
|
order = collab.create_order(
|
||||||
self.session,
|
self.session,
|
||||||
|
|||||||
@@ -634,21 +634,16 @@ def query_external_orders_activity(
|
|||||||
current: User = Depends(require_permission("douyu:collab:edit")),
|
current: User = Depends(require_permission("douyu:collab:edit")),
|
||||||
):
|
):
|
||||||
results: list[dict] = []
|
results: list[dict] = []
|
||||||
|
orders = []
|
||||||
for order_id in ids:
|
for order_id in ids:
|
||||||
try:
|
try:
|
||||||
order = collab.get_order(db, order_id)
|
orders.append(collab.get_order(db, order_id))
|
||||||
result = collab.query_activity(db, current, order, source="batch")
|
except Exception as exc: # noqa: BLE001 - 不存在的单逐行隔离
|
||||||
results.append(
|
|
||||||
{
|
|
||||||
"id": order_id,
|
|
||||||
"success": True,
|
|
||||||
"verdict": result["verdict"],
|
|
||||||
"message": result["message"],
|
|
||||||
}
|
|
||||||
)
|
|
||||||
except Exception as exc: # noqa: BLE001
|
|
||||||
db.rollback()
|
|
||||||
results.append({"id": order_id, "success": False, "message": str(exc)})
|
results.append({"id": order_id, "success": False, "message": str(exc)})
|
||||||
|
if orders:
|
||||||
|
results.extend(collab.query_activity_batch(db, current, orders, source="batch"))
|
||||||
|
order_index = {order_id: index for index, order_id in enumerate(ids)}
|
||||||
|
results.sort(key=lambda item: order_index.get(int(item["id"]), len(ids)))
|
||||||
if any(item["success"] for item in results):
|
if any(item["success"] for item in results):
|
||||||
_publish_change(current, scope="orders", action="order.activity_batch")
|
_publish_change(current, scope="orders", action="order.activity_batch")
|
||||||
return {"results": results, "success": all(item["success"] for item in results)}
|
return {"results": results, "success": all(item["success"] for item in results)}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
1. **一行 = 一单 = 一个内部斗鱼账号**。协作单只存 ``account_id`` 和用户名快照,
|
1. **一行 = 一单 = 一个内部斗鱼账号**。协作单只存 ``account_id`` 和用户名快照,
|
||||||
**不复制 CK**;所有查询实时读 ``accounts.cookie``,账号换 CK 后自动生效。
|
**不复制 CK**;所有查询实时读 ``accounts.cookie``,账号换 CK 后自动生效。
|
||||||
2. 鱼翅和手册积分是两笔资产:先充值鱼翅,再用鱼翅赠送精英令换积分。
|
2. 鱼翅和手册积分是两笔资产:先充值鱼翅,再用鱼翅赠送精英令换积分。
|
||||||
查询时两笔都要返回,核账只看手册积分。
|
余额查询单独返回两笔资产,兑换记录查询不混查余额。
|
||||||
3. 同一斗鱼账号允许挂多单;积分核账按账号合并计算所有未作废订单的礼包积分。
|
3. 同一斗鱼账号允许挂多单;积分核账按账号合并计算所有未作废订单的礼包积分。
|
||||||
4. 兑换是否成功只看当前账号的 ``exchangeList``。``getRecordList`` 是全站动态,
|
4. 兑换是否成功只看当前账号的 ``exchangeList``。``getRecordList`` 是全站动态,
|
||||||
不能拿来判断某一单。
|
不能拿来判断某一单。
|
||||||
@@ -16,8 +16,9 @@ from __future__ import annotations
|
|||||||
from collections.abc import Callable, Mapping, Sequence
|
from collections.abc import Callable, Mapping, Sequence
|
||||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||||
from concurrent.futures import TimeoutError as FutureTimeoutError
|
from concurrent.futures import TimeoutError as FutureTimeoutError
|
||||||
from datetime import UTC, datetime
|
from datetime import UTC, datetime, timedelta
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
from unicodedata import normalize as unicode_normalize
|
||||||
|
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
from sqlalchemy import func, or_
|
from sqlalchemy import func, or_
|
||||||
@@ -70,10 +71,7 @@ from .douyu_account_probe import (
|
|||||||
persist_probe_result,
|
persist_probe_result,
|
||||||
probe_account,
|
probe_account,
|
||||||
)
|
)
|
||||||
from .douyu_activity_query import (
|
from .douyu_activity_query import query_exchange_records
|
||||||
query_exchange_orders,
|
|
||||||
query_exchange_records,
|
|
||||||
)
|
|
||||||
from .douyu_goods_service import (
|
from .douyu_goods_service import (
|
||||||
serialize_live_goods as _serialize_live_goods,
|
serialize_live_goods as _serialize_live_goods,
|
||||||
)
|
)
|
||||||
@@ -203,6 +201,12 @@ POINTS_GROUP_STATUSES: tuple[str, ...] = (
|
|||||||
|
|
||||||
POINTS_THRESHOLD_DEFAULT = 100
|
POINTS_THRESHOLD_DEFAULT = 100
|
||||||
POINTS_THRESHOLD_MAX = 1_000_000
|
POINTS_THRESHOLD_MAX = 1_000_000
|
||||||
|
ACTIVITY_RECORD_SETTLE_SECONDS = 300
|
||||||
|
ACTIVITY_RECORD_TIME_SKEW_SECONDS = 60
|
||||||
|
ACTIVITY_RECORD_FETCH_LIMIT = 100
|
||||||
|
ACTIVITY_RECORD_MAX_PAGES = 5
|
||||||
|
# 兑换记录最多翻 5 页,但指标快照只保留必要样本,避免 JSON 列按订单放大存储。
|
||||||
|
ACTIVITY_METRIC_RECORD_LIMIT = 50
|
||||||
MAX_IMAGES = 20
|
MAX_IMAGES = 20
|
||||||
CK_EXPORT_BATCH_MAX = 50
|
CK_EXPORT_BATCH_MAX = 50
|
||||||
CK_EXPORT_ACTION = "douyu:collab:ck_export"
|
CK_EXPORT_ACTION = "douyu:collab:ck_export"
|
||||||
@@ -2643,19 +2647,78 @@ def set_status(
|
|||||||
return order
|
return order
|
||||||
|
|
||||||
|
|
||||||
def _match_gift(records: list[dict[str, Any]], gift_name: str) -> int:
|
def _normalize_exchange_name(value: Any) -> str:
|
||||||
name = _text(gift_name)
|
return "".join(unicode_normalize("NFKC", _text(value)).casefold().split())
|
||||||
if len(name) < 2:
|
|
||||||
return 0
|
|
||||||
matched = 0
|
def _exchange_record_time(record: Mapping[str, Any]) -> datetime | None:
|
||||||
for record in records:
|
raw = (
|
||||||
record_name = _text(
|
record.get("time")
|
||||||
record.get("commodityName") or record.get("commodity_name") or ""
|
or record.get("exchangeTime")
|
||||||
|
or record.get("exchange_time")
|
||||||
|
or record.get("createTime")
|
||||||
|
or record.get("create_time")
|
||||||
|
)
|
||||||
|
if raw is None or raw == "":
|
||||||
|
return None
|
||||||
|
text = str(raw).strip()
|
||||||
|
try:
|
||||||
|
timestamp = float(text)
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
try:
|
||||||
|
parsed = datetime.fromisoformat(text)
|
||||||
|
except ValueError:
|
||||||
|
return None
|
||||||
|
return (
|
||||||
|
parsed.replace(tzinfo=UTC)
|
||||||
|
if parsed.tzinfo is None
|
||||||
|
else parsed.astimezone(UTC)
|
||||||
)
|
)
|
||||||
if not record_name or len(record_name) < 2:
|
if timestamp > 10_000_000_000:
|
||||||
|
timestamp /= 1000
|
||||||
|
try:
|
||||||
|
return datetime.fromtimestamp(timestamp, UTC)
|
||||||
|
except (OverflowError, OSError, ValueError):
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def _matching_exchange_records(
|
||||||
|
records: Sequence[Mapping[str, Any]],
|
||||||
|
order: DouyuExternalOrder,
|
||||||
|
) -> list[dict[str, Any]]:
|
||||||
|
"""按商品 ID、精确名称和上脚本时间匹配,避免历史记录串单。"""
|
||||||
|
expected_cid = _text(order.commodity_id)
|
||||||
|
expected_name = _normalize_exchange_name(order.gift_name)
|
||||||
|
not_before = order.scripted_at
|
||||||
|
if isinstance(not_before, datetime):
|
||||||
|
not_before = not_before - timedelta(seconds=ACTIVITY_RECORD_TIME_SKEW_SECONDS)
|
||||||
|
|
||||||
|
matched: list[dict[str, Any]] = []
|
||||||
|
for record in records:
|
||||||
|
if not isinstance(record, Mapping):
|
||||||
continue
|
continue
|
||||||
if name in record_name or record_name in name:
|
record_cid = _text(
|
||||||
matched += 1
|
record.get("commodityId")
|
||||||
|
or record.get("commodity_id")
|
||||||
|
or record.get("goodsId")
|
||||||
|
)
|
||||||
|
if expected_cid and record_cid:
|
||||||
|
identity_matched = record_cid == expected_cid
|
||||||
|
else:
|
||||||
|
record_name = _normalize_exchange_name(
|
||||||
|
record.get("commodityName")
|
||||||
|
or record.get("commodity_name")
|
||||||
|
or record.get("goodsName")
|
||||||
|
)
|
||||||
|
identity_matched = bool(
|
||||||
|
expected_name and record_name and record_name == expected_name
|
||||||
|
)
|
||||||
|
if not identity_matched:
|
||||||
|
continue
|
||||||
|
record_time = _exchange_record_time(record)
|
||||||
|
if not_before is not None and (record_time is None or record_time < not_before):
|
||||||
|
continue
|
||||||
|
matched.append(dict(record))
|
||||||
return matched
|
return matched
|
||||||
|
|
||||||
|
|
||||||
@@ -2674,17 +2737,15 @@ def group_points_total(db: Session, order: DouyuExternalOrder) -> int:
|
|||||||
return sum(int(item.required_points or 0) for item in rows)
|
return sum(int(item.required_points or 0) for item in rows)
|
||||||
|
|
||||||
|
|
||||||
def query_activity(
|
def _load_exchange_records_for_orders(
|
||||||
db: Session,
|
db: Session,
|
||||||
current: User,
|
orders: Sequence[DouyuExternalOrder],
|
||||||
order: DouyuExternalOrder,
|
|
||||||
*,
|
*,
|
||||||
client: Any | None = None,
|
client: Any | None = None,
|
||||||
source: str = "manual",
|
) -> list[dict[str, Any]]:
|
||||||
include_records: bool = True,
|
if not orders:
|
||||||
commit: bool = True,
|
return []
|
||||||
) -> dict[str, Any]:
|
order = orders[0]
|
||||||
"""查询鱼翅、积分;``include_records`` 时同时查兑换记录并判定。"""
|
|
||||||
account = account_by_id(db, order.account_id) or account_by_username(
|
account = account_by_id(db, order.account_id) or account_by_username(
|
||||||
db, order.account_username
|
db, order.account_username
|
||||||
)
|
)
|
||||||
@@ -2692,71 +2753,139 @@ def query_activity(
|
|||||||
raise CollabError("订单关联的斗鱼账号不存在", code="account_not_found")
|
raise CollabError("订单关联的斗鱼账号不存在", code="account_not_found")
|
||||||
config = resolve_config(db)
|
config = resolve_config(db)
|
||||||
active_client = client or _client_for_account(account)
|
active_client = client or _client_for_account(account)
|
||||||
probe = probe_account(
|
cutoffs = [
|
||||||
account,
|
item.scripted_at - timedelta(seconds=ACTIVITY_RECORD_TIME_SKEW_SECONDS)
|
||||||
config,
|
for item in orders
|
||||||
client=active_client,
|
if item.scripted_at is not None
|
||||||
session_checker=None,
|
]
|
||||||
with_gold=True,
|
not_before = min(cutoffs) if cutoffs else None
|
||||||
with_elite_role=False,
|
|
||||||
)
|
|
||||||
elite = (probe.get("elite") or {}).get("raw") or {}
|
|
||||||
gold = {
|
|
||||||
"gold": (probe.get("gold") or {}).get("balance"),
|
|
||||||
}
|
|
||||||
errors = list((probe.get("errors") or {}).values())
|
|
||||||
records: list[dict[str, Any]] = []
|
records: list[dict[str, Any]] = []
|
||||||
orders: list[dict[str, Any]] = []
|
for page in range(ACTIVITY_RECORD_MAX_PAGES):
|
||||||
if include_records:
|
page_records = query_exchange_records(
|
||||||
try:
|
active_client,
|
||||||
records = query_exchange_records(
|
manual_id=str(config.manual_id or ""),
|
||||||
active_client,
|
limit=ACTIVITY_RECORD_FETCH_LIMIT,
|
||||||
manual_id=str(config.manual_id or ""),
|
offset=page * ACTIVITY_RECORD_FETCH_LIMIT,
|
||||||
limit=100,
|
)
|
||||||
offset=0,
|
records.extend(page_records)
|
||||||
)
|
if len(page_records) < ACTIVITY_RECORD_FETCH_LIMIT:
|
||||||
except Exception as exc: # noqa: BLE001
|
break
|
||||||
errors.append(f"兑换记录: {exc}")
|
if not_before is not None:
|
||||||
try:
|
page_times = [
|
||||||
orders = query_exchange_orders(
|
record_time
|
||||||
active_client,
|
for record in page_records
|
||||||
manual_id=str(config.manual_id or ""),
|
if (record_time := _exchange_record_time(record)) is not None
|
||||||
page=1,
|
]
|
||||||
page_size=10,
|
if page_times and max(page_times) < not_before:
|
||||||
)
|
break
|
||||||
except Exception as exc: # noqa: BLE001
|
return records
|
||||||
errors.append(f"锁单: {exc}")
|
|
||||||
|
|
||||||
manual_score = _to_int(elite.get("manual_score"))
|
|
||||||
fish = _to_int(gold.get("gold"))
|
def query_activity(
|
||||||
persist_probe_result(
|
db: Session,
|
||||||
db,
|
current: User,
|
||||||
account,
|
order: DouyuExternalOrder,
|
||||||
probe,
|
*,
|
||||||
current=current,
|
client: Any | None = None,
|
||||||
source="douyu_collab.query_activity",
|
records: Sequence[Mapping[str, Any]] | None = None,
|
||||||
record_event=False,
|
record_query_error: str = "",
|
||||||
|
source: str = "manual",
|
||||||
|
include_records: bool = True,
|
||||||
|
commit: bool = True,
|
||||||
|
) -> dict[str, Any]:
|
||||||
|
"""查兑换记录并判定;``include_records=False`` 时只刷新鱼翅和积分。"""
|
||||||
|
account = account_by_id(db, order.account_id) or account_by_username(
|
||||||
|
db, order.account_username
|
||||||
)
|
)
|
||||||
if manual_score is not None:
|
if account is None:
|
||||||
order.points_balance = manual_score
|
raise CollabError("订单关联的斗鱼账号不存在", code="account_not_found")
|
||||||
account.points = manual_score
|
errors: list[str] = []
|
||||||
if fish is not None:
|
probe: dict[str, Any] = {}
|
||||||
order.fish_fin_balance = fish
|
loaded_records: list[dict[str, Any]] = []
|
||||||
account.gold_balance = fish
|
if include_records:
|
||||||
account.updated_at = _now()
|
if records is None:
|
||||||
required_total = group_points_total(db, order)
|
try:
|
||||||
surplus = (
|
loaded_records = _load_exchange_records_for_orders(
|
||||||
(manual_score - required_total)
|
db, [order], client=client
|
||||||
if manual_score is not None and required_total > 0
|
)
|
||||||
else None
|
except Exception as exc: # noqa: BLE001
|
||||||
)
|
errors.append(f"兑换记录: {exc}")
|
||||||
order.points_required_total = required_total
|
else:
|
||||||
order.points_surplus = surplus
|
loaded_records = [dict(record) for record in records]
|
||||||
order.points_checked_at = _now()
|
if record_query_error:
|
||||||
threshold = normalize_threshold(order.points_threshold)
|
errors.append(f"兑换记录: {record_query_error}")
|
||||||
order.points_threshold = threshold
|
manual_score = _to_int(order.points_balance)
|
||||||
|
fish = _to_int(order.fish_fin_balance)
|
||||||
|
required_total = _to_int(order.points_required_total)
|
||||||
|
surplus = _to_int(order.points_surplus)
|
||||||
|
points_reason = _text(order.points_check_reason)
|
||||||
|
points_message = _text(order.points_check_message)
|
||||||
|
threshold = normalize_threshold(order.points_threshold)
|
||||||
|
else:
|
||||||
|
config = resolve_config(db)
|
||||||
|
active_client = client or _client_for_account(account)
|
||||||
|
probe = probe_account(
|
||||||
|
account,
|
||||||
|
config,
|
||||||
|
client=active_client,
|
||||||
|
session_checker=None,
|
||||||
|
with_gold=True,
|
||||||
|
with_elite_role=False,
|
||||||
|
)
|
||||||
|
elite = (probe.get("elite") or {}).get("raw") or {}
|
||||||
|
gold = {
|
||||||
|
"gold": (probe.get("gold") or {}).get("balance"),
|
||||||
|
}
|
||||||
|
errors = list((probe.get("errors") or {}).values())
|
||||||
|
manual_score = _to_int(elite.get("manual_score"))
|
||||||
|
fish = _to_int(gold.get("gold"))
|
||||||
|
persist_probe_result(
|
||||||
|
db,
|
||||||
|
account,
|
||||||
|
probe,
|
||||||
|
current=current,
|
||||||
|
source="douyu_collab.query_activity",
|
||||||
|
record_event=False,
|
||||||
|
)
|
||||||
|
if manual_score is not None:
|
||||||
|
order.points_balance = manual_score
|
||||||
|
account.points = manual_score
|
||||||
|
if fish is not None:
|
||||||
|
order.fish_fin_balance = fish
|
||||||
|
account.gold_balance = fish
|
||||||
|
account.updated_at = _now()
|
||||||
|
required_total = group_points_total(db, order)
|
||||||
|
surplus = (
|
||||||
|
(manual_score - required_total)
|
||||||
|
if manual_score is not None and required_total > 0
|
||||||
|
else None
|
||||||
|
)
|
||||||
|
order.points_required_total = required_total
|
||||||
|
order.points_surplus = surplus
|
||||||
|
order.points_checked_at = _now()
|
||||||
|
threshold = normalize_threshold(order.points_threshold)
|
||||||
|
order.points_threshold = threshold
|
||||||
|
points_reason = ""
|
||||||
|
if surplus is not None:
|
||||||
|
if surplus < 0:
|
||||||
|
points_reason = "shortage"
|
||||||
|
elif surplus > threshold:
|
||||||
|
points_reason = "excess"
|
||||||
|
else:
|
||||||
|
points_reason = "ok"
|
||||||
|
points_message = ""
|
||||||
|
if required_total > 0 or manual_score is not None:
|
||||||
|
points_message = (
|
||||||
|
f"积分 {manual_score if manual_score is not None else '-'} / "
|
||||||
|
f"本账号未完成订单合计 {required_total},结余 "
|
||||||
|
f"{surplus if surplus is not None else '-'}"
|
||||||
|
)
|
||||||
|
order.points_check_reason = points_reason
|
||||||
|
order.points_check_message = points_message
|
||||||
|
|
||||||
matched = 0
|
matched = 0
|
||||||
|
matched_records: list[dict[str, Any]] = []
|
||||||
|
now = _now()
|
||||||
if not include_records:
|
if not include_records:
|
||||||
verdict = VERDICT_UNKNOWN
|
verdict = VERDICT_UNKNOWN
|
||||||
message = ";".join(errors) if errors else "仅查询鱼翅与积分,未查询兑换记录"
|
message = ";".join(errors) if errors else "仅查询鱼翅与积分,未查询兑换记录"
|
||||||
@@ -2767,41 +2896,37 @@ def query_activity(
|
|||||||
verdict = VERDICT_UNKNOWN
|
verdict = VERDICT_UNKNOWN
|
||||||
message = "未填写礼包名,无法判定兑换结果"
|
message = "未填写礼包名,无法判定兑换结果"
|
||||||
else:
|
else:
|
||||||
matched = _match_gift(records, order.gift_name)
|
matched_records = _matching_exchange_records(loaded_records, order)
|
||||||
verdict = VERDICT_SUCCESS if matched else VERDICT_FAILED
|
matched = len(matched_records)
|
||||||
message = (
|
if matched:
|
||||||
f"兑换记录命中「{order.gift_name}」{matched} 条"
|
verdict = VERDICT_SUCCESS
|
||||||
if matched
|
message = f"兑换记录命中「{order.gift_name}」{matched} 条"
|
||||||
else f"兑换记录里没有「{order.gift_name}」"
|
elif order.status != STATUS_SCRIPTED:
|
||||||
)
|
verdict = VERDICT_UNKNOWN
|
||||||
|
message = "订单当前状态不再由兑换记录自动判定"
|
||||||
reason = ""
|
elif order.scripted_at is None:
|
||||||
if surplus is not None:
|
verdict = VERDICT_UNKNOWN
|
||||||
if surplus < 0:
|
message = "订单尚未记录上脚本时间,暂不自动判定"
|
||||||
reason = "shortage"
|
elif now < order.scripted_at + timedelta(
|
||||||
elif surplus > threshold:
|
seconds=ACTIVITY_RECORD_SETTLE_SECONDS
|
||||||
reason = "excess"
|
):
|
||||||
|
verdict = VERDICT_UNKNOWN
|
||||||
|
message = f"兑换记录暂未命中「{order.gift_name}」,仍在结算等待期"
|
||||||
else:
|
else:
|
||||||
reason = "ok"
|
verdict = VERDICT_FAILED
|
||||||
points_message = ""
|
message = f"兑换记录里没有「{order.gift_name}」"
|
||||||
if required_total > 0 or manual_score is not None:
|
|
||||||
points_message = (
|
if not include_records:
|
||||||
f"积分 {manual_score if manual_score is not None else '-'} / "
|
order.points_check_detail = {
|
||||||
f"本账号未完成订单合计 {required_total},结余 "
|
"fish_fin_balance": fish,
|
||||||
f"{surplus if surplus is not None else '-'}"
|
"points_balance": manual_score,
|
||||||
)
|
"required_total": required_total,
|
||||||
order.points_check_reason = reason
|
"surplus": surplus,
|
||||||
order.points_check_message = points_message
|
"threshold": threshold,
|
||||||
order.points_check_detail = {
|
"errors": errors,
|
||||||
"fish_fin_balance": fish,
|
"exchange_records": 0,
|
||||||
"points_balance": manual_score,
|
"locked_orders": 0,
|
||||||
"required_total": required_total,
|
}
|
||||||
"surplus": surplus,
|
|
||||||
"threshold": threshold,
|
|
||||||
"errors": errors,
|
|
||||||
"exchange_records": len(records),
|
|
||||||
"locked_orders": len(orders),
|
|
||||||
}
|
|
||||||
|
|
||||||
metric = DouyuExternalOrderMetric(
|
metric = DouyuExternalOrderMetric(
|
||||||
order_id=order.id,
|
order_id=order.id,
|
||||||
@@ -2812,17 +2937,20 @@ def query_activity(
|
|||||||
points_balance=manual_score,
|
points_balance=manual_score,
|
||||||
points_required_total=required_total,
|
points_required_total=required_total,
|
||||||
points_surplus=surplus,
|
points_surplus=surplus,
|
||||||
records_total=len(records),
|
records_total=len(loaded_records),
|
||||||
records_matched=matched,
|
records_matched=matched,
|
||||||
verdict=verdict,
|
verdict=verdict,
|
||||||
message=message,
|
message=message,
|
||||||
source=_text(source, max_length=16) or "manual",
|
source=_text(source, max_length=16) or "manual",
|
||||||
raw=_json_safe(
|
raw=_json_safe(
|
||||||
{
|
{
|
||||||
"elite": elite,
|
"verdict": verdict,
|
||||||
"gold": gold,
|
"scope": "activity" if include_records else "balances",
|
||||||
"records": records,
|
"probe": probe,
|
||||||
"orders": orders,
|
"records_count": len(loaded_records),
|
||||||
|
"records": loaded_records[:ACTIVITY_METRIC_RECORD_LIMIT],
|
||||||
|
"matched": matched_records[:5],
|
||||||
|
"record_query_error": record_query_error,
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
created_by=current.id,
|
created_by=current.id,
|
||||||
@@ -2843,7 +2971,7 @@ def query_activity(
|
|||||||
"points": manual_score,
|
"points": manual_score,
|
||||||
"required_total": required_total,
|
"required_total": required_total,
|
||||||
"surplus": surplus,
|
"surplus": surplus,
|
||||||
"records": len(records),
|
"records": len(loaded_records),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -2869,31 +2997,18 @@ def query_activity(
|
|||||||
expected_version=None,
|
expected_version=None,
|
||||||
commit=False,
|
commit=False,
|
||||||
)
|
)
|
||||||
elif order.status in (STATUS_RECHARGED, STATUS_SCRIPTED) and reason in (
|
|
||||||
"shortage",
|
|
||||||
"excess",
|
|
||||||
):
|
|
||||||
set_status(
|
|
||||||
db,
|
|
||||||
current,
|
|
||||||
order,
|
|
||||||
status=STATUS_POINTS_ERROR,
|
|
||||||
reason=points_message,
|
|
||||||
expected_version=None,
|
|
||||||
commit=False,
|
|
||||||
)
|
|
||||||
|
|
||||||
record_account_query(
|
record_account_query(
|
||||||
db,
|
db,
|
||||||
account,
|
account,
|
||||||
query_type="collab_activity",
|
query_type="collab_activity",
|
||||||
title="查询鱼翅与积分" if not include_records else "查询积分与兑换记录",
|
title="查询鱼翅与积分" if not include_records else "查询兑换记录",
|
||||||
ok=not bool(errors),
|
ok=not bool(errors),
|
||||||
detail={
|
detail={
|
||||||
"order_no": order.order_no,
|
"order_no": order.order_no,
|
||||||
"include_records": include_records,
|
"include_records": include_records,
|
||||||
"verdict": verdict,
|
"verdict": verdict,
|
||||||
"records": len(records),
|
"records": len(loaded_records),
|
||||||
"errors": errors[:10],
|
"errors": errors[:10],
|
||||||
},
|
},
|
||||||
actor_id=current.id,
|
actor_id=current.id,
|
||||||
@@ -2909,7 +3024,7 @@ def query_activity(
|
|||||||
"scope": "activity" if include_records else "balances",
|
"scope": "activity" if include_records else "balances",
|
||||||
"verdict": verdict,
|
"verdict": verdict,
|
||||||
"message": message,
|
"message": message,
|
||||||
"points_reason": reason,
|
"points_reason": points_reason,
|
||||||
"points_message": points_message,
|
"points_message": points_message,
|
||||||
"fish_fin_balance": fish,
|
"fish_fin_balance": fish,
|
||||||
"points_balance": manual_score,
|
"points_balance": manual_score,
|
||||||
@@ -2919,6 +3034,65 @@ def query_activity(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def query_activity_batch(
|
||||||
|
db: Session,
|
||||||
|
current: User,
|
||||||
|
orders: Sequence[DouyuExternalOrder],
|
||||||
|
*,
|
||||||
|
source: str = "batch",
|
||||||
|
) -> list[dict[str, Any]]:
|
||||||
|
"""按账号复用兑换记录请求,再逐单用商品与时间窗口判定。"""
|
||||||
|
orders_by_account: dict[tuple[str, int | str], list[DouyuExternalOrder]] = {}
|
||||||
|
for order in orders:
|
||||||
|
account_key: tuple[str, int | str]
|
||||||
|
if order.account_id:
|
||||||
|
account_key = ("id", int(order.account_id))
|
||||||
|
else:
|
||||||
|
account_key = ("username", _text(order.account_username).casefold())
|
||||||
|
orders_by_account.setdefault(account_key, []).append(order)
|
||||||
|
|
||||||
|
records_by_account: dict[
|
||||||
|
tuple[str, int | str], tuple[list[dict[str, Any]], str]
|
||||||
|
] = {}
|
||||||
|
for account_key, account_orders in orders_by_account.items():
|
||||||
|
try:
|
||||||
|
records_by_account[account_key] = (
|
||||||
|
_load_exchange_records_for_orders(db, account_orders),
|
||||||
|
"",
|
||||||
|
)
|
||||||
|
except Exception as exc: # noqa: BLE001 - 账号级错误复用到同账号订单
|
||||||
|
records_by_account[account_key] = ([], str(exc))
|
||||||
|
|
||||||
|
results: list[dict[str, Any]] = []
|
||||||
|
for order in orders:
|
||||||
|
if order.account_id:
|
||||||
|
account_key = ("id", int(order.account_id))
|
||||||
|
else:
|
||||||
|
account_key = ("username", _text(order.account_username).casefold())
|
||||||
|
records, record_error = records_by_account[account_key]
|
||||||
|
try:
|
||||||
|
result = query_activity(
|
||||||
|
db,
|
||||||
|
current,
|
||||||
|
order,
|
||||||
|
records=records,
|
||||||
|
record_query_error=record_error,
|
||||||
|
source=source,
|
||||||
|
)
|
||||||
|
results.append(
|
||||||
|
{
|
||||||
|
"id": int(order.id),
|
||||||
|
"success": True,
|
||||||
|
"verdict": result["verdict"],
|
||||||
|
"message": result["message"],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
except Exception as exc: # noqa: BLE001 - 批量逐单隔离
|
||||||
|
db.rollback()
|
||||||
|
results.append({"id": int(order.id), "success": False, "message": str(exc)})
|
||||||
|
return results
|
||||||
|
|
||||||
|
|
||||||
def ensure_shops_registered(
|
def ensure_shops_registered(
|
||||||
db: Session, current: User | None, names: list[str]
|
db: Session, current: User | None, names: list[str]
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|||||||
@@ -322,6 +322,13 @@ export interface DouyuCollabQueryResult {
|
|||||||
errors: string[];
|
errors: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface DouyuCollabBatchQueryItem {
|
||||||
|
id: number;
|
||||||
|
success: boolean;
|
||||||
|
verdict?: string;
|
||||||
|
message?: string;
|
||||||
|
}
|
||||||
|
|
||||||
export const douyuCollabApi = {
|
export const douyuCollabApi = {
|
||||||
listOrders: (params: {
|
listOrders: (params: {
|
||||||
page?: number;
|
page?: number;
|
||||||
@@ -488,7 +495,7 @@ export const douyuCollabApi = {
|
|||||||
data,
|
data,
|
||||||
),
|
),
|
||||||
batchActivity: (ids: number[]) =>
|
batchActivity: (ids: number[]) =>
|
||||||
api.post<{ results: Array<Record<string, unknown>>; success: boolean }, { results: Array<Record<string, unknown>>; success: boolean }>(
|
api.post<{ results: DouyuCollabBatchQueryItem[]; success: boolean }, { results: DouyuCollabBatchQueryItem[]; success: boolean }>(
|
||||||
'/douyu/external-orders/activity/query',
|
'/douyu/external-orders/activity/query',
|
||||||
ids,
|
ids,
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1142,10 +1142,8 @@ export default function DouyuCollabPage() {
|
|||||||
try {
|
try {
|
||||||
message.loading({ content: '正在查询兑换记录…', key: 'dy-collab-records' });
|
message.loading({ content: '正在查询兑换记录…', key: 'dy-collab-records' });
|
||||||
const result = await douyuCollabApi.queryActivity(order.id);
|
const result = await douyuCollabApi.queryActivity(order.id);
|
||||||
message.success({
|
const notify = result.verdict === 'success' ? message.success : message.warning;
|
||||||
content: `${result.message}${result.points_reason ? `;${pointsReasonMeta(result.points_reason).label}` : ''}`,
|
notify({ content: result.message, key: 'dy-collab-records' });
|
||||||
key: 'dy-collab-records',
|
|
||||||
});
|
|
||||||
refreshAll();
|
refreshAll();
|
||||||
if (detail?.id === order.id) void openDetail(order);
|
if (detail?.id === order.id) void openDetail(order);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -1312,8 +1310,11 @@ export default function DouyuCollabPage() {
|
|||||||
setRecordQuerying(true);
|
setRecordQuerying(true);
|
||||||
try {
|
try {
|
||||||
const result = await douyuCollabApi.batchActivity(selectedIds);
|
const result = await douyuCollabApi.batchActivity(selectedIds);
|
||||||
const ok = result.results.filter((item) => item.success).length;
|
const confirmed = result.results.filter((item) => item.success && item.verdict === 'success').length;
|
||||||
message.success(`兑换记录查询完成:${ok}/${result.results.length}`);
|
const pending = result.results.filter((item) => item.success && item.verdict === 'unknown').length;
|
||||||
|
const failed = result.results.length - confirmed - pending;
|
||||||
|
const notify = confirmed === result.results.length ? message.success : message.warning;
|
||||||
|
notify(`兑换记录查询完成:确认成功 ${confirmed},待结算/无法判定 ${pending},失败或查询异常 ${failed}`);
|
||||||
refreshAll();
|
refreshAll();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
message.error(getErrorMessage(error));
|
message.error(getErrorMessage(error));
|
||||||
@@ -1830,7 +1831,7 @@ export default function DouyuCollabPage() {
|
|||||||
查鱼翅/积分
|
查鱼翅/积分
|
||||||
</Button>
|
</Button>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<Tooltip title="查询当前账号兑换记录,命中礼包名后自动推进订单状态">
|
<Tooltip title="只查当前账号兑换记录;按商品、礼包名和上脚本时间匹配,命中后自动完成订单">
|
||||||
<Button size="small" icon={<SearchOutlined />} onClick={() => void queryOneRecords(row)}>
|
<Button size="small" icon={<SearchOutlined />} onClick={() => void queryOneRecords(row)}>
|
||||||
查兑换记录
|
查兑换记录
|
||||||
</Button>
|
</Button>
|
||||||
@@ -2180,7 +2181,7 @@ export default function DouyuCollabPage() {
|
|||||||
批量查鱼翅/积分{selectedCount > 0 ? `(${selectedCount})` : ''}
|
批量查鱼翅/积分{selectedCount > 0 ? `(${selectedCount})` : ''}
|
||||||
</Button>
|
</Button>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<Tooltip title="查询勾选订单的兑换记录;命中礼包名后自动改状态,积分短缺/超额也会标记">
|
<Tooltip title="只查勾选订单的兑换记录;按商品、礼包名和上脚本时间匹配,不会混查鱼翅或积分">
|
||||||
<Button
|
<Button
|
||||||
icon={<SearchOutlined />}
|
icon={<SearchOutlined />}
|
||||||
disabled={selectedCount === 0 || loading || recordQuerying}
|
disabled={selectedCount === 0 || loading || recordQuerying}
|
||||||
|
|||||||
Reference in New Issue
Block a user