feat(douyu): 增加账号角色异常状态
This commit is contained in:
@@ -484,6 +484,67 @@ class TestDouyuCollabOrders:
|
|||||||
assert lease.status == "released"
|
assert lease.status == "released"
|
||||||
assert lease.release_reason == "douyu_collab_done"
|
assert lease.release_reason == "douyu_collab_done"
|
||||||
|
|
||||||
|
def test_account_role_error_keeps_lease_and_requires_explicit_rollback(self):
|
||||||
|
order = collab.create_order(
|
||||||
|
self.session,
|
||||||
|
self.admin,
|
||||||
|
order_no="DY-ROLE-ERROR",
|
||||||
|
shop="店铺A",
|
||||||
|
account_username="douyu-account-a",
|
||||||
|
gift_name="礼包A",
|
||||||
|
required_points=100,
|
||||||
|
home_images=["collab/home-role-error.png"],
|
||||||
|
client=FakeClient(),
|
||||||
|
)
|
||||||
|
|
||||||
|
changed = collab.set_status(
|
||||||
|
self.session,
|
||||||
|
self.admin,
|
||||||
|
order,
|
||||||
|
status=collab.STATUS_ROLE_ERROR,
|
||||||
|
reason="角色区服与订单不一致",
|
||||||
|
)
|
||||||
|
|
||||||
|
assert changed.status == collab.STATUS_ROLE_ERROR
|
||||||
|
assert collab.ORDER_STATUS_LABELS[changed.status] == "账号角色异常"
|
||||||
|
lease = self.session.query(AccountLease).one()
|
||||||
|
assert lease.status == "active"
|
||||||
|
assert (
|
||||||
|
collab.list_orders(self.session, status=collab.STATUS_ROLE_ERROR)["total"]
|
||||||
|
== 1
|
||||||
|
)
|
||||||
|
assert collab.summary(self.session)["by_status"][collab.STATUS_ROLE_ERROR] == 1
|
||||||
|
|
||||||
|
with pytest.raises(collab.CollabError) as excinfo:
|
||||||
|
collab.set_status(
|
||||||
|
self.session,
|
||||||
|
self.admin,
|
||||||
|
order,
|
||||||
|
status=collab.STATUS_SCRIPTED,
|
||||||
|
reason="直接恢复",
|
||||||
|
)
|
||||||
|
assert excinfo.value.code == "rollback_required"
|
||||||
|
|
||||||
|
restored = collab.set_status(
|
||||||
|
self.session,
|
||||||
|
self.admin,
|
||||||
|
order,
|
||||||
|
status=collab.STATUS_SCRIPTED,
|
||||||
|
reason="角色已修正",
|
||||||
|
rollback=True,
|
||||||
|
)
|
||||||
|
assert restored.status == collab.STATUS_SCRIPTED
|
||||||
|
self.session.refresh(lease)
|
||||||
|
assert lease.status == "active"
|
||||||
|
audit = (
|
||||||
|
self.session.query(AuditLog)
|
||||||
|
.filter(AuditLog.action == "douyu:collab:role_error")
|
||||||
|
.order_by(AuditLog.id.desc())
|
||||||
|
.first()
|
||||||
|
)
|
||||||
|
assert audit is not None
|
||||||
|
assert audit.detail is not None and '"from":"to_recharge"' in audit.detail
|
||||||
|
|
||||||
def test_admin_can_restore_voided_order_to_another_status(self):
|
def test_admin_can_restore_voided_order_to_another_status(self):
|
||||||
order = collab.create_order(
|
order = collab.create_order(
|
||||||
self.session,
|
self.session,
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ STATUS_RECHARGED = "recharged"
|
|||||||
STATUS_SCRIPTED = "scripted"
|
STATUS_SCRIPTED = "scripted"
|
||||||
STATUS_DONE = "done"
|
STATUS_DONE = "done"
|
||||||
STATUS_POINTS_ERROR = "points_error"
|
STATUS_POINTS_ERROR = "points_error"
|
||||||
|
STATUS_ROLE_ERROR = "role_error"
|
||||||
STATUS_FAILED = "failed"
|
STATUS_FAILED = "failed"
|
||||||
STATUS_VOID = "void"
|
STATUS_VOID = "void"
|
||||||
LEASE_PURPOSE_DOUYU_COLLAB = "douyu_collab"
|
LEASE_PURPOSE_DOUYU_COLLAB = "douyu_collab"
|
||||||
@@ -90,6 +91,7 @@ COLLAB_LEASE_STATUSES: tuple[str, ...] = (
|
|||||||
STATUS_RECHARGED,
|
STATUS_RECHARGED,
|
||||||
STATUS_SCRIPTED,
|
STATUS_SCRIPTED,
|
||||||
STATUS_POINTS_ERROR,
|
STATUS_POINTS_ERROR,
|
||||||
|
STATUS_ROLE_ERROR,
|
||||||
STATUS_FAILED,
|
STATUS_FAILED,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -100,6 +102,7 @@ ORDER_STATUSES: tuple[str, ...] = (
|
|||||||
STATUS_SCRIPTED,
|
STATUS_SCRIPTED,
|
||||||
STATUS_DONE,
|
STATUS_DONE,
|
||||||
STATUS_POINTS_ERROR,
|
STATUS_POINTS_ERROR,
|
||||||
|
STATUS_ROLE_ERROR,
|
||||||
STATUS_FAILED,
|
STATUS_FAILED,
|
||||||
STATUS_VOID,
|
STATUS_VOID,
|
||||||
)
|
)
|
||||||
@@ -111,6 +114,7 @@ ORDER_STATUS_LABELS = {
|
|||||||
STATUS_SCRIPTED: "已上脚本",
|
STATUS_SCRIPTED: "已上脚本",
|
||||||
STATUS_DONE: "抢购成功",
|
STATUS_DONE: "抢购成功",
|
||||||
STATUS_POINTS_ERROR: "积分异常",
|
STATUS_POINTS_ERROR: "积分异常",
|
||||||
|
STATUS_ROLE_ERROR: "账号角色异常",
|
||||||
STATUS_FAILED: "抢购失败",
|
STATUS_FAILED: "抢购失败",
|
||||||
STATUS_VOID: "已作废",
|
STATUS_VOID: "已作废",
|
||||||
}
|
}
|
||||||
@@ -1751,8 +1755,33 @@ def set_status(
|
|||||||
db.refresh(order)
|
db.refresh(order)
|
||||||
return order
|
return order
|
||||||
|
|
||||||
if old in (STATUS_FAILED, STATUS_VOID) and not rollback:
|
if target == STATUS_ROLE_ERROR:
|
||||||
raise CollabError("从失败/作废状态回流程必须显式回退", code="rollback_required")
|
order.status = STATUS_ROLE_ERROR
|
||||||
|
order.updated_by = current.id
|
||||||
|
order.version = int(order.version or 0) + 1
|
||||||
|
record_audit(
|
||||||
|
db,
|
||||||
|
current,
|
||||||
|
action="douyu:collab:role_error",
|
||||||
|
target=_status_audit_target(order),
|
||||||
|
detail={"from": old, "reason": _text(reason, max_length=256)},
|
||||||
|
)
|
||||||
|
_sync_order_lease(
|
||||||
|
db,
|
||||||
|
current,
|
||||||
|
order,
|
||||||
|
reason="douyu_collab_role_error",
|
||||||
|
)
|
||||||
|
if commit:
|
||||||
|
db.commit()
|
||||||
|
db.refresh(order)
|
||||||
|
return order
|
||||||
|
|
||||||
|
if old in (STATUS_FAILED, STATUS_VOID, STATUS_ROLE_ERROR) and not rollback:
|
||||||
|
raise CollabError(
|
||||||
|
"从失败/角色异常/作废状态回流程必须显式回退",
|
||||||
|
code="rollback_required",
|
||||||
|
)
|
||||||
if target not in STAGE_INDEX:
|
if target not in STAGE_INDEX:
|
||||||
raise CollabError("该状态不能手工切换", code="status_not_manual")
|
raise CollabError("该状态不能手工切换", code="status_not_manual")
|
||||||
current_index = STAGE_INDEX.get(old)
|
current_index = STAGE_INDEX.get(old)
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ export type DouyuCollabStatus =
|
|||||||
| 'scripted'
|
| 'scripted'
|
||||||
| 'done'
|
| 'done'
|
||||||
| 'points_error'
|
| 'points_error'
|
||||||
|
| 'role_error'
|
||||||
| 'failed'
|
| 'failed'
|
||||||
| 'void';
|
| 'void';
|
||||||
|
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ const STATUS_META: Record<DouyuCollabStatus, { label: string; color: string }> =
|
|||||||
scripted: { label: '已上脚本', color: 'purple' },
|
scripted: { label: '已上脚本', color: 'purple' },
|
||||||
done: { label: '抢购成功', color: 'green' },
|
done: { label: '抢购成功', color: 'green' },
|
||||||
points_error: { label: '积分异常', color: 'orange' },
|
points_error: { label: '积分异常', color: 'orange' },
|
||||||
|
role_error: { label: '账号角色异常', color: 'volcano' },
|
||||||
failed: { label: '抢购失败', color: 'red' },
|
failed: { label: '抢购失败', color: 'red' },
|
||||||
void: { label: '已作废', color: 'default' },
|
void: { label: '已作废', color: 'default' },
|
||||||
};
|
};
|
||||||
@@ -119,6 +120,7 @@ const STATUS_ORDER: DouyuCollabStatus[] = [
|
|||||||
'scripted',
|
'scripted',
|
||||||
'done',
|
'done',
|
||||||
'points_error',
|
'points_error',
|
||||||
|
'role_error',
|
||||||
'failed',
|
'failed',
|
||||||
'void',
|
'void',
|
||||||
];
|
];
|
||||||
@@ -462,7 +464,9 @@ export default function DouyuCollabPage() {
|
|||||||
const targetIndex = FLOW_ORDER.indexOf(statusValue);
|
const targetIndex = FLOW_ORDER.indexOf(statusValue);
|
||||||
if (targetIndex < 0) return false;
|
if (targetIndex < 0) return false;
|
||||||
return selectedOrders.some((row) => {
|
return selectedOrders.some((row) => {
|
||||||
if (row.status === 'failed' || row.status === 'void') return true;
|
if (row.status === 'failed' || row.status === 'role_error' || row.status === 'void') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
const currentIndex = FLOW_ORDER.indexOf(row.status);
|
const currentIndex = FLOW_ORDER.indexOf(row.status);
|
||||||
return currentIndex >= 0 && targetIndex < currentIndex;
|
return currentIndex >= 0 && targetIndex < currentIndex;
|
||||||
});
|
});
|
||||||
@@ -834,10 +838,14 @@ export default function DouyuCollabPage() {
|
|||||||
const currentIndex = FLOW_ORDER.indexOf(statusTarget.status);
|
const currentIndex = FLOW_ORDER.indexOf(statusTarget.status);
|
||||||
const targetIndex = FLOW_ORDER.indexOf(statusValue);
|
const targetIndex = FLOW_ORDER.indexOf(statusValue);
|
||||||
const restoringVoid = statusTarget.status === 'void';
|
const restoringVoid = statusTarget.status === 'void';
|
||||||
|
const restoringError =
|
||||||
|
statusTarget.status === 'failed' || statusTarget.status === 'role_error';
|
||||||
await douyuCollabApi.setStatus(statusTarget.id, {
|
await douyuCollabApi.setStatus(statusTarget.id, {
|
||||||
status: statusValue,
|
status: statusValue,
|
||||||
reason: statusReason,
|
reason: statusReason,
|
||||||
rollback: targetIndex >= 0 && currentIndex >= 0 && targetIndex < currentIndex,
|
rollback:
|
||||||
|
restoringError ||
|
||||||
|
(targetIndex >= 0 && currentIndex >= 0 && targetIndex < currentIndex),
|
||||||
expected_version: statusTarget.version,
|
expected_version: statusTarget.version,
|
||||||
});
|
});
|
||||||
message.success(restoringVoid ? '已取消作废并恢复状态' : '状态已更新');
|
message.success(restoringVoid ? '已取消作废并恢复状态' : '状态已更新');
|
||||||
@@ -1470,15 +1478,6 @@ export default function DouyuCollabPage() {
|
|||||||
</Card>
|
</Card>
|
||||||
</Col>
|
</Col>
|
||||||
))}
|
))}
|
||||||
<Col flex="1 1 92px">
|
|
||||||
<Card size="small" style={{ height: '100%' }}>
|
|
||||||
<Statistic
|
|
||||||
title="账号缺失"
|
|
||||||
value={summary.account_missing}
|
|
||||||
styles={{ content: { color: '#cf1322' } }}
|
|
||||||
/>
|
|
||||||
</Card>
|
|
||||||
</Col>
|
|
||||||
<Col flex="1 1 92px">
|
<Col flex="1 1 92px">
|
||||||
<Card
|
<Card
|
||||||
size="small"
|
size="small"
|
||||||
@@ -2065,7 +2064,7 @@ export default function DouyuCollabPage() {
|
|||||||
checked={batchStatusRollback}
|
checked={batchStatusRollback}
|
||||||
onChange={(event) => setBatchStatusRollback(event.target.checked)}
|
onChange={(event) => setBatchStatusRollback(event.target.checked)}
|
||||||
>
|
>
|
||||||
回退(目标比当前状态靠前,或从「抢购失败 / 已作废」回到流程时必须勾选)
|
回退(目标比当前状态靠前,或从「抢购失败 / 账号角色异常 / 已作废」回到流程时必须勾选)
|
||||||
</Checkbox>
|
</Checkbox>
|
||||||
{batchRollbackRequired && !batchStatusRollback && (
|
{batchRollbackRequired && !batchStatusRollback && (
|
||||||
<Alert
|
<Alert
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ const COLLAB_STATUS_LABELS: Record<string, string> = {
|
|||||||
scripted: '已上脚本',
|
scripted: '已上脚本',
|
||||||
done: '抢购成功',
|
done: '抢购成功',
|
||||||
points_error: '积分异常',
|
points_error: '积分异常',
|
||||||
|
role_error: '账号角色异常',
|
||||||
failed: '抢购失败',
|
failed: '抢购失败',
|
||||||
void: '已作废',
|
void: '已作废',
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user