feat(douyu): 订单台账按平台履约只读投影
- 外部单协作改名为斗鱼订单台账 - 平台来源台账单的订单号/账号/礼包/商品/积分只读 - 台账显示来源履约任务,隐藏解除/推荐账号入口 - 后端 update_order 拒绝投影字段变更 - set_account 对平台来源要求显式接管转人工 - 补充重构计划第一刀实施状态
This commit is contained in:
@@ -893,6 +893,15 @@ def create_order(
|
||||
return order
|
||||
|
||||
|
||||
PLATFORM_PROJECTED_FIELDS = {
|
||||
"order_no",
|
||||
"account_username",
|
||||
"gift_name",
|
||||
"commodity_id",
|
||||
"required_points",
|
||||
}
|
||||
|
||||
|
||||
def update_order(
|
||||
db: Session,
|
||||
current: User,
|
||||
@@ -950,6 +959,20 @@ def update_order(
|
||||
if new != old:
|
||||
changes[field] = {"old": old, "new": new}
|
||||
|
||||
if order.source_type == SOURCE_TYPE_PLATFORM_FULFILLMENT:
|
||||
# 平台来源台账单是履约任务的投影:订单号/商品/积分/账号由平台维护。
|
||||
# 账号变更只有显式“接管转人工”才允许,避免协作页静默改出两个账号。
|
||||
projected = PLATFORM_PROJECTED_FIELDS.intersection(changes)
|
||||
if "account_username" in projected and takeover_platform_lease:
|
||||
projected.discard("account_username")
|
||||
if projected:
|
||||
raise CollabError(
|
||||
"本单来自直播账号履约,订单号/商品/积分/账号由履约工作台维护;"
|
||||
"确需改账号请先走“接管并转人工”",
|
||||
status_code=409,
|
||||
code="platform_projection_readonly",
|
||||
)
|
||||
|
||||
if order.succeeded_at is not None:
|
||||
locked_changes = SUCCESS_PURCHASE_FIELDS.intersection(changes)
|
||||
if locked_changes:
|
||||
@@ -1074,6 +1097,16 @@ def set_account(
|
||||
_assert_mutable(order)
|
||||
_assert_success_account_change_allowed(current, order)
|
||||
_assert_version(order, expected_version)
|
||||
if (
|
||||
order.source_type == SOURCE_TYPE_PLATFORM_FULFILLMENT
|
||||
and not takeover_platform_lease
|
||||
):
|
||||
raise CollabError(
|
||||
"本单来自直播账号履约,账号由履约工作台维护;"
|
||||
"确需更换账号请确认“接管并转人工”",
|
||||
status_code=409,
|
||||
code="platform_projection_readonly",
|
||||
)
|
||||
account = account_by_username(db, username)
|
||||
if account is None:
|
||||
raise CollabError("斗鱼账号不存在", code="account_not_found")
|
||||
|
||||
@@ -88,7 +88,7 @@ export default function MainLayout({ onLogout }: { onLogout?: () => void }) {
|
||||
|
||||
// 外部单协作:权限独立,客服没有 douyu:task 也要能进共享台账。
|
||||
if (can('douyu:collab:view')) {
|
||||
douyuItems.push({ key: '/douyu/collab', label: '外部单协作', icon: <FileExcelOutlined /> });
|
||||
douyuItems.push({ key: '/douyu/collab', label: '订单台账', icon: <FileExcelOutlined /> });
|
||||
}
|
||||
if (can('platform_fulfillment:view')) {
|
||||
douyuItems.push({ key: '/platform-fulfillment', label: '直播账号履约', icon: <ThunderboltOutlined /> });
|
||||
|
||||
@@ -167,6 +167,7 @@ export default function DouyuCollabPage() {
|
||||
const [createOpen, setCreateOpen] = useState(false);
|
||||
const [editing, setEditing] = useState<DouyuCollabOrder | null>(null);
|
||||
const successfulPurchaseFieldsLocked = Boolean(editing?.succeeded_at && !isAdmin);
|
||||
const isPlatformProjection = editing?.source_type === 'platform_fulfillment';
|
||||
const [form, setForm] = useState<OrderFormState>(EMPTY_FORM);
|
||||
const [lookup, setLookup] = useState<DouyuCollabAccountLookup | null>(null);
|
||||
const lookupSeq = useRef(0);
|
||||
@@ -616,18 +617,22 @@ export default function DouyuCollabPage() {
|
||||
) => {
|
||||
if (editing) {
|
||||
return douyuCollabApi.updateOrder(editing.id, {
|
||||
order_no: form.order_no.trim(),
|
||||
shop: form.shop.trim(),
|
||||
owner_id: form.owner_id,
|
||||
account_username: form.account_username.trim(),
|
||||
gift_name: form.gift_name,
|
||||
commodity_id: form.commodity_id,
|
||||
required_points: form.required_points,
|
||||
home_images: form.home_images,
|
||||
remark: form.remark,
|
||||
expected_version: editing.version,
|
||||
confirm_purchase_change: confirmPurchaseChange,
|
||||
takeover_platform_lease: takeoverPlatformLease,
|
||||
...(!isPlatformProjection
|
||||
? {
|
||||
order_no: form.order_no.trim(),
|
||||
account_username: form.account_username.trim(),
|
||||
gift_name: form.gift_name,
|
||||
commodity_id: form.commodity_id,
|
||||
required_points: form.required_points,
|
||||
}
|
||||
: {}),
|
||||
});
|
||||
}
|
||||
return douyuCollabApi.createOrder({
|
||||
@@ -1737,8 +1742,8 @@ export default function DouyuCollabPage() {
|
||||
return (
|
||||
<Space direction="vertical" size={12} style={{ width: '100%' }}>
|
||||
<div>
|
||||
<h2 style={{ margin: 0 }}>斗鱼外部单协作</h2>
|
||||
<Text type="secondary">订单挂内部斗鱼账号;输入用户名即可读取 CK、角色、鱼翅与手册积分</Text>
|
||||
<h2 style={{ margin: 0 }}>斗鱼订单台账</h2>
|
||||
<Text type="secondary">系统正常订单由直播账号履约工作台维护;这里记录财务、异常和人工补登记</Text>
|
||||
</div>
|
||||
|
||||
<Row gutter={[8, 8]}>
|
||||
@@ -2172,6 +2177,15 @@ export default function DouyuCollabPage() {
|
||||
destroyOnHidden
|
||||
styles={{ body: { maxHeight: '78vh', overflowY: 'auto', paddingRight: 12 } }}
|
||||
>
|
||||
{isPlatformProjection && (
|
||||
<Alert
|
||||
style={{ marginBottom: 12 }}
|
||||
type="info"
|
||||
showIcon
|
||||
message="本单来自直播账号履约工作台"
|
||||
description={`履约任务 #${editing?.source_task_id ?? '-'} 的账号、订单号、礼包和积分由履约工作台维护;这里只维护财务、备注和主页截图。`}
|
||||
/>
|
||||
)}
|
||||
{!editing && (
|
||||
<Alert
|
||||
style={{ marginBottom: 12 }}
|
||||
@@ -2215,8 +2229,8 @@ export default function DouyuCollabPage() {
|
||||
style={{ marginTop: 4 }}
|
||||
value={form.order_no}
|
||||
maxLength={64}
|
||||
placeholder="外部订单编号"
|
||||
disabled={successfulPurchaseFieldsLocked}
|
||||
placeholder="订单编号"
|
||||
disabled={successfulPurchaseFieldsLocked || isPlatformProjection}
|
||||
onChange={(event) => updateForm('order_no', event.target.value)}
|
||||
/>
|
||||
</div>
|
||||
@@ -2258,12 +2272,12 @@ export default function DouyuCollabPage() {
|
||||
<Input
|
||||
value={form.account_username}
|
||||
placeholder="输入内部斗鱼账号用户名,停止输入后自动查询"
|
||||
disabled={successfulPurchaseFieldsLocked}
|
||||
disabled={successfulPurchaseFieldsLocked || isPlatformProjection}
|
||||
onChange={(event) => updateForm('account_username', event.target.value)}
|
||||
/>
|
||||
<Button
|
||||
loading={lookupLoading}
|
||||
disabled={successfulPurchaseFieldsLocked}
|
||||
disabled={successfulPurchaseFieldsLocked || isPlatformProjection}
|
||||
onClick={() => void handleLookup()}
|
||||
>
|
||||
查询账号
|
||||
@@ -2287,6 +2301,7 @@ export default function DouyuCollabPage() {
|
||||
/>
|
||||
)}
|
||||
{editing &&
|
||||
!isPlatformProjection &&
|
||||
canReplaceAccount &&
|
||||
!editing.succeeded_at &&
|
||||
editing.status !== 'done' &&
|
||||
@@ -2323,7 +2338,7 @@ export default function DouyuCollabPage() {
|
||||
allowClear
|
||||
value={form.gift_name}
|
||||
options={giftNameOptions}
|
||||
disabled={successfulPurchaseFieldsLocked}
|
||||
disabled={successfulPurchaseFieldsLocked || isPlatformProjection}
|
||||
placeholder={
|
||||
goodsPool.length || giftRecords.length
|
||||
? '输入礼包名称,或选择已有礼包'
|
||||
@@ -2339,7 +2354,7 @@ export default function DouyuCollabPage() {
|
||||
optionFilterProp="label"
|
||||
value={form.gift_name || undefined}
|
||||
options={giftNameOptions}
|
||||
disabled={successfulPurchaseFieldsLocked}
|
||||
disabled={successfulPurchaseFieldsLocked || isPlatformProjection}
|
||||
placeholder={
|
||||
giftNameOptions.length
|
||||
? '选择礼包(由管理员统一维护)'
|
||||
@@ -2365,7 +2380,7 @@ export default function DouyuCollabPage() {
|
||||
min={0}
|
||||
precision={0}
|
||||
value={form.required_points}
|
||||
disabled={!canManage || successfulPurchaseFieldsLocked}
|
||||
disabled={!canManage || successfulPurchaseFieldsLocked || isPlatformProjection}
|
||||
placeholder={canManage ? '手动填写;选择礼包后自动带出' : '由管理员统一配置'}
|
||||
onChange={(value) => updateForm('required_points', value ?? null)}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user