发布(0.4.6): 修复预售兑换记录判定与详情展示并新增工作台强制发放
This commit is contained in:
@@ -87,6 +87,10 @@ from ..services.account_supply_service import (
|
||||
)
|
||||
from ..services.audit_service import record_audit
|
||||
from ..services.automation.scheduler import ensure_jobs
|
||||
from ..services.binding_ownership import (
|
||||
WORKBENCH_GOODS_MUTATION_TYPES,
|
||||
workbench_force_goods_inspection,
|
||||
)
|
||||
from ..services.business_events import record_recharge
|
||||
from ..services.douyu_activity_query import activity_client, query_activity_goods
|
||||
from ..services.douyu_batch_launcher import (
|
||||
@@ -114,6 +118,7 @@ from ..services.douyu_service import (
|
||||
douyu_config_value,
|
||||
douyu_task_payload,
|
||||
ensure_douyu_config,
|
||||
visible_douyu_task_accounts,
|
||||
)
|
||||
from ..services.execution_jobs import (
|
||||
JOB_DOUYU_BATCH,
|
||||
@@ -1525,6 +1530,22 @@ def _prepare_task_batch(
|
||||
)
|
||||
if guard is not None:
|
||||
return guard
|
||||
if req.force_occupied:
|
||||
if not user_has_permission(current, "douyu:task:force"):
|
||||
raise HTTPException(
|
||||
status_code=403,
|
||||
detail="仅超级管理员或运营有权限在占用期间强制发放",
|
||||
)
|
||||
if (
|
||||
req.handbook_scope != "elite"
|
||||
or req.task_type not in WORKBENCH_GOODS_MUTATION_TYPES
|
||||
or req.platform_task_id is not None
|
||||
):
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail="仅精英工作台锁单、支付锁单与兑换商品支持确认角色后强制发放",
|
||||
)
|
||||
|
||||
task_payload = dict(req.payload)
|
||||
if req.recharge_confirmation_token:
|
||||
task_payload["recharge_confirmation_used"] = True
|
||||
@@ -1541,8 +1562,42 @@ def _prepare_task_batch(
|
||||
concurrency=req.concurrency,
|
||||
recharge_channel=recharge_channel,
|
||||
recharge_amount=recharge_amount,
|
||||
force_occupied=req.force_occupied,
|
||||
)
|
||||
except (DouyuActivePaymentError, DouyuLeaseConflictError) as exc:
|
||||
except DouyuLeaseConflictError as exc:
|
||||
if (
|
||||
not req.force_occupied
|
||||
and req.platform_task_id is None
|
||||
and req.handbook_scope == "elite"
|
||||
and req.task_type in WORKBENCH_GOODS_MUTATION_TYPES
|
||||
and user_has_permission(current, "douyu:task:force")
|
||||
):
|
||||
visible_accounts = visible_douyu_task_accounts(db, req.account_ids)
|
||||
inspections = [
|
||||
workbench_force_goods_inspection(db, acc)
|
||||
for acc in visible_accounts
|
||||
]
|
||||
occupied_items = [item for item in inspections if item["occupied"]]
|
||||
blocked = next(
|
||||
(item for item in occupied_items if not item["can_force"]),
|
||||
None,
|
||||
)
|
||||
if blocked is not None:
|
||||
raise HTTPException(status_code=409, detail=blocked["reason"]) from exc
|
||||
if occupied_items:
|
||||
return {
|
||||
"batch_id": "",
|
||||
"count": 0,
|
||||
"success": False,
|
||||
"requires_force_confirmation": True,
|
||||
"occupied_accounts": occupied_items,
|
||||
"message": (
|
||||
"所选账号当前由平台履约订单占用,已校验斗鱼号与绑定角色正常,"
|
||||
"请核对后确认强制发放"
|
||||
),
|
||||
}
|
||||
raise HTTPException(status_code=409, detail=str(exc)) from exc
|
||||
except DouyuActivePaymentError as exc:
|
||||
raise HTTPException(status_code=409, detail=str(exc)) from exc
|
||||
except DouyuTaskBackpressureError as exc:
|
||||
raise HTTPException(
|
||||
@@ -1556,6 +1611,70 @@ def _prepare_task_batch(
|
||||
raise HTTPException(
|
||||
status_code=400, detail="没有可执行的斗鱼账号,请先登录获取 Cookie"
|
||||
)
|
||||
if req.force_occupied:
|
||||
commodity_id = str(
|
||||
req.payload.get("commodity_id") or req.payload.get("commodityId") or ""
|
||||
).strip()
|
||||
snapshot = (
|
||||
db.query(DouyuGoodsSnapshot)
|
||||
.filter(DouyuGoodsSnapshot.commodity_id == commodity_id)
|
||||
.first()
|
||||
if commodity_id
|
||||
else None
|
||||
)
|
||||
goods_name = str(snapshot.name or "").strip() if snapshot else ""
|
||||
forced_rows = (
|
||||
db.query(DouyuTask, Account)
|
||||
.join(Account, Account.id == DouyuTask.account_id)
|
||||
.filter(DouyuTask.batch_id == batch_id)
|
||||
.order_by(DouyuTask.id.asc())
|
||||
.all()
|
||||
)
|
||||
forced_pf_details: list[dict[str, Any]] = []
|
||||
for douyu_task, account in forced_rows:
|
||||
result_data = douyu_task.result if isinstance(douyu_task.result, dict) else {}
|
||||
raw_payload = result_data.get("payload")
|
||||
payload_meta = raw_payload if isinstance(raw_payload, dict) else {}
|
||||
pf_task_id = payload_meta.get("force_platform_task_id")
|
||||
if not payload_meta.get("force_occupied") or not pf_task_id:
|
||||
continue
|
||||
platform_fulfillment_service.record_workbench_force_exchange(
|
||||
db,
|
||||
task_id=int(pf_task_id),
|
||||
current=current,
|
||||
batch_id=batch_id,
|
||||
douyu_task_id=int(douyu_task.id),
|
||||
task_type=req.task_type,
|
||||
commodity_id=commodity_id,
|
||||
goods_name=goods_name,
|
||||
account_id=int(account.id),
|
||||
account_username=str(account.username or ""),
|
||||
account_role=str(account.game_name or ""),
|
||||
)
|
||||
forced_pf_details.append(
|
||||
{
|
||||
"douyu_task_id": int(douyu_task.id),
|
||||
"platform_task_id": int(pf_task_id),
|
||||
"account_id": int(account.id),
|
||||
"account_username": str(account.username or ""),
|
||||
"account_role": str(account.game_name or ""),
|
||||
}
|
||||
)
|
||||
if forced_pf_details:
|
||||
record_audit(
|
||||
db,
|
||||
current,
|
||||
action="douyu:workbench:force_exchange",
|
||||
target=f"douyu_batch:{batch_id}",
|
||||
detail={
|
||||
"batch_id": batch_id,
|
||||
"task_type": req.task_type,
|
||||
"commodity_id": commodity_id,
|
||||
"goods_name": goods_name,
|
||||
"accounts": forced_pf_details,
|
||||
},
|
||||
)
|
||||
db.commit()
|
||||
if req.platform_task_id:
|
||||
douyu_task_ids = [
|
||||
int(task_id)
|
||||
|
||||
@@ -35,6 +35,7 @@ from ..schemas import (
|
||||
DouyuCollabArchiveRequest,
|
||||
DouyuCollabCkExportOut,
|
||||
DouyuCollabCkExportRequest,
|
||||
DouyuCollabExchangeRecordsOut,
|
||||
DouyuCollabGiftCreate,
|
||||
DouyuCollabGiftOut,
|
||||
DouyuCollabGiftUpdate,
|
||||
@@ -721,6 +722,40 @@ def external_order_metrics(
|
||||
return collab.order_metrics(db, order_id)
|
||||
|
||||
|
||||
@router.get(
|
||||
"/external-orders/{order_id}/exchange-records",
|
||||
response_model=DouyuCollabExchangeRecordsOut,
|
||||
)
|
||||
def get_external_order_exchange_records(
|
||||
order_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
current: User = Depends(require_permission("douyu:collab:view")),
|
||||
):
|
||||
"""查看订单关联斗鱼账号已缓存的兑换记录。"""
|
||||
try:
|
||||
order = collab.get_order(db, order_id)
|
||||
return collab.list_order_exchange_records(db, current, order, refresh=False)
|
||||
except collab.CollabError as exc:
|
||||
raise _http_error(exc) from exc
|
||||
|
||||
|
||||
@router.post(
|
||||
"/external-orders/{order_id}/exchange-records/query",
|
||||
response_model=DouyuCollabExchangeRecordsOut,
|
||||
)
|
||||
def query_external_order_exchange_records(
|
||||
order_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
current: User = Depends(require_permission("douyu:collab:edit")),
|
||||
):
|
||||
"""实时向斗鱼拉取兑换记录并展示明细,不自动修改订单状态。"""
|
||||
try:
|
||||
order = collab.get_order(db, order_id)
|
||||
return collab.list_order_exchange_records(db, current, order, refresh=True)
|
||||
except collab.CollabError as exc:
|
||||
raise _http_error(exc) from exc
|
||||
|
||||
|
||||
@router.delete("/external-orders/{order_id}")
|
||||
def delete_external_order(
|
||||
order_id: int,
|
||||
|
||||
Reference in New Issue
Block a user