feat(weibo): 支持超级管理员强制恢复作废订单
This commit is contained in:
@@ -498,6 +498,7 @@ def set_external_orders_status_batch(
|
||||
req.status,
|
||||
reason=req.reason,
|
||||
rollback=req.rollback,
|
||||
force=req.force,
|
||||
)
|
||||
except collab.CollabError as exc:
|
||||
raise _http_error(exc) from exc
|
||||
@@ -627,6 +628,7 @@ def set_external_order_status(
|
||||
req.status,
|
||||
reason=req.reason,
|
||||
rollback=req.rollback,
|
||||
force=req.force,
|
||||
)
|
||||
except collab.CollabError as exc:
|
||||
raise _http_error(exc) from exc
|
||||
|
||||
@@ -869,6 +869,8 @@ class WeiboCollabStatusRequest(BaseModel):
|
||||
status: str = Field(..., min_length=1, max_length=20)
|
||||
reason: str = Field("", max_length=256)
|
||||
rollback: bool = False
|
||||
# 仅超级管理员可用:从「已作废」强制恢复,必须同时填写 reason。
|
||||
force: bool = False
|
||||
expected_version: int | None = None
|
||||
|
||||
|
||||
@@ -877,6 +879,8 @@ class WeiboCollabStatusBatchRequest(BaseModel):
|
||||
status: str = Field(..., min_length=1, max_length=20)
|
||||
reason: str = Field("", max_length=256)
|
||||
rollback: bool = False
|
||||
# 仅超级管理员可用;混合批次里只对 void 行生效,必须同时填写 reason。
|
||||
force: bool = False
|
||||
|
||||
|
||||
class WeiboCollabCkExportRequest(BaseModel):
|
||||
|
||||
@@ -679,6 +679,7 @@ def set_status(
|
||||
*,
|
||||
reason: str = "",
|
||||
rollback: bool = False,
|
||||
force: bool = False,
|
||||
allow_check: bool = False,
|
||||
commit: bool = True,
|
||||
) -> dict[str, Any]:
|
||||
@@ -693,8 +694,31 @@ def set_status(
|
||||
old = order.status
|
||||
if old == target:
|
||||
return {"from": old, "to": target}
|
||||
force_applied = False
|
||||
force_reason = ""
|
||||
previous_void_reason = ""
|
||||
if old == STATUS_VOID:
|
||||
raise CollabError("已作废订单不能直接改回流程内", code="order_void")
|
||||
if not force:
|
||||
raise CollabError("已作废订单不能直接改回流程内", code="order_void")
|
||||
if current.role != "super_admin":
|
||||
raise CollabError(
|
||||
"只有超级管理员可以强制恢复已作废的订单",
|
||||
status_code=403,
|
||||
code="force_admin_required",
|
||||
)
|
||||
if target not in STAGE_INDEX:
|
||||
raise CollabError(
|
||||
"已作废订单只能强制恢复到正常流程状态",
|
||||
code="force_target_invalid",
|
||||
)
|
||||
force_reason = _text(reason, max_length=256)
|
||||
if not force_reason:
|
||||
raise CollabError(
|
||||
"强制恢复已作废订单必须填写原因",
|
||||
code="force_reason_required",
|
||||
)
|
||||
force_applied = True
|
||||
previous_void_reason = order.void_reason or ""
|
||||
if target == STATUS_VOID:
|
||||
clean_reason = _text(reason, max_length=256)
|
||||
if not clean_reason:
|
||||
@@ -728,6 +752,15 @@ def set_status(
|
||||
code="recharge_precondition",
|
||||
)
|
||||
now = _now()
|
||||
if force_applied:
|
||||
# 重新进入流程时不能沿用作废前的阶段时间和资金来源。
|
||||
order.recharged_at = None
|
||||
order.funding_source = ""
|
||||
order.funding_source_detail = ""
|
||||
order.funding_recharge_record_id = None
|
||||
order.scripted_at = None
|
||||
order.exchange_started_at = None
|
||||
order.done_at = None
|
||||
if target == STATUS_TO_RECHARGE:
|
||||
order.recharged_at = None
|
||||
order.funding_source = ""
|
||||
@@ -766,7 +799,14 @@ def set_status(
|
||||
current,
|
||||
order,
|
||||
"weibo:collab:status",
|
||||
{"from": old, "to": target, "rollback": rollback, "reason": reason},
|
||||
{
|
||||
"from": old,
|
||||
"to": target,
|
||||
"rollback": rollback,
|
||||
"reason": force_reason if force_applied else reason,
|
||||
"force": force_applied,
|
||||
"previous_void_reason": previous_void_reason if force_applied else "",
|
||||
},
|
||||
)
|
||||
if commit:
|
||||
db.commit()
|
||||
@@ -782,6 +822,7 @@ def set_status_batch(
|
||||
*,
|
||||
reason: str = "",
|
||||
rollback: bool = False,
|
||||
force: bool = False,
|
||||
) -> dict[str, Any]:
|
||||
rows = list(orders)
|
||||
if not rows:
|
||||
@@ -800,6 +841,7 @@ def set_status_batch(
|
||||
target,
|
||||
reason=reason,
|
||||
rollback=rollback,
|
||||
force=force,
|
||||
allow_check=False,
|
||||
commit=False,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user