feat(jd): 上架按账号授权 + 建单钉来源店铺 + 店铺不匹配整单判死

2026-11-24 客户(心向大海)两条口径:
「如果没有店铺登入情况 软件怎么知道我们要上架是哪一个店铺?」
「上架的账户 我是这个权限不开给他的」

后端半边(用户端页头与会话核对见 frontend-vue 同笔;客户端发布前核对见 app_client 0f8bcdf)。

一、按账号授权(拒绝型能力,quiet fail 全靠本类判据)
- JdPublishPermissionSupport:V209 app 菜单组键 jd_tools 或子键 jd-publish 命中即放行,
  超管直放;有效键集按 AdminMenuPlatformScope 过滤到账号平台(与登录分发同源)。
  无权限抛 403 + 中文动作句(告诉管理员去哪儿勾)。
- JdPublishController:建单/改品牌重试/选品/面板/历史/批量进度六个用户面入口一律先判;
  客户端执行面(items/chunk/activate/heartbeat/补值/删除)不判——执行器本来就只跑
  已建的任务,判在这里会让进行中的任务断在半路。

二、建单钉来源店铺(一次上架只发一家店)
- resolveSingleShop:按勾选商品快照判店铺,跨店勾选建单即拒并点名两家店;
  同店两种形状(有 id / 只有店名)归一到 id 再比。
- JdPublishTaskCreateRequest 落 shopId/shopName → 队列载荷两键 → 明细页
  JdPublishItemsPageVo.shopId/shopName 下发;旧任务载荷没这两键时回落明细行
  shop_name(V210 就有),保证老任务至少能按店名核对。

三、店铺不匹配整单判死
- JdPublishStaleTaskService.SHOP_MISMATCH_MARK/terminalizeOnJdShopMismatch:
  CAS RUNNING→FAILED、0/1 计数、原文追加动作句;不按累计行数收窄(确定性失败)。
- JdPublishIngestService.fail:命中标记排在凭据致命档之后、页面结构变更之前接线,
  回 accept=true 让客户端收口。

判据:JdPublishPermissionSupportTest 5 支(新)+TaskService +3/Stale +2/Ingest +2,
后端 JdPublish 九类 77 支全绿;四支既有护栏(catch 静默/请求身份/超管单出口/SQL 分层)绿。
This commit is contained in:
2026-11-24 15:21:27 +08:00
parent cf06872cb6
commit 1b10db4bf9
20 changed files with 1156 additions and 6 deletions
+155
View File
@@ -22,6 +22,13 @@ import {
} from '@/shared/api/types/modules/jd-publish'
import { retryClientTask } from '@/shared/api/task-retry'
import { getPywebviewApi } from '@/shared/bridges/pywebview'
import { ensureJdLogin, markJdLoginExpired } from '@/shared/stores/jd-login-autoflow'
import {
evaluateShopGuard,
shopGuardBlocks,
shopLabel,
type JdShopRef,
} from '@/pages/jd/jd-publish-shop'
import { resolvePageHref } from '@/shared/page-prefix'
import { userNotice } from '@/shared/utils/user-notice'
import { formatDateTime } from '@/shared/utils/datetime'
@@ -166,8 +173,109 @@ function isValidBrand(name: string) {
const priceValueMissing = computed(() => priceMode.value !== 'none' && (priceValue.value == null || priceValue.value < 0))
// ---- 本次上架到哪家店(2026-11-24 客户口径「软件怎么知道要上架哪一家店铺」)----
/** 来源店铺=勾选商品行的快照店铺;京麦当前店铺=桥现拉(不缓存、不猜、不自动探测)。 */
const selectedProductRows = computed(() => Array.from(selectedProducts.value.values()))
const currentShop = ref<JdShopRef | null>(null)
const detectingShop = ref(false)
const canDetectShop = ref(false)
const shopNote = ref('')
const shopError = ref('')
const SHOP_DETECT_UNAVAILABLE =
'当前在本机客户端之外打开或客户端版本较旧,无法检测京麦店铺。请在本机客户端中打开本页;'
+ '本机客户端发布前仍会核对任务记录的店铺,不一致整单拦下、一条都不发'
const shopGuard = computed(() => evaluateShopGuard(selectedProductRows.value, currentShop.value))
/** 来源店铺文案:没取到/多家店/单店三档(多店由 shopGuard 直接拦)。 */
const sourceShopText = computed(() => {
const guard = shopGuard.value
if (guard.state === 'unknown') return '未取到(旧商品数据没有店铺信息)'
if (guard.state === 'multi') return guard.shops.map((shop) => shopLabel(shop)).join('、')
return shopLabel(guard.expected)
})
const currentShopText = computed(() => (currentShop.value ? shopLabel(currentShop.value) : '未检测'))
/** 挂载时判可用性:老客户端没有 get_jd_shop_info ⇒ 检测按钮置灰(同「同步分类」口径)。 */
function refreshShopDetectability() {
canDetectShop.value = typeof getPywebviewApi()?.get_jd_shop_info === 'function'
}
/**
* 点「检测当前京麦店铺」:桥现拉京麦首屏(会起客户端专用浏览器,秒级)。
* 失败按 code 分档——jd_busy 走 amber 说明、jd_login 走自动登录链路(登录成功后自动重测一次)、
* jd_page/未知走红色错误。返回值只作 `startPublish` 的判断输入,展示通道由本函数自理。
*/
async function detectShop(options?: { fromAutoLogin?: boolean }) {
if (detectingShop.value && !options?.fromAutoLogin) return
shopError.value = ''
shopNote.value = ''
const api = getPywebviewApi()
const bridge = api?.get_jd_shop_info
if (typeof bridge !== 'function') {
canDetectShop.value = false
shopNote.value = SHOP_DETECT_UNAVAILABLE
return
}
detectingShop.value = true
try {
const result = await bridge()
if (result?.success && (result.shopName || result.shopId)) {
currentShop.value = { shopId: result.shopId, shopName: result.shopName }
return
}
if (result?.code === 'jd_busy') {
shopNote.value = result.error || '京东任务正在运行,等任务结束后再检测京麦店铺'
return
}
if (result?.code === 'jd_login') {
if (options?.fromAutoLogin) {
shopError.value = result.error || '京麦未登录(登录态失效)'
return
}
markJdLoginExpired()
shopNote.value = '检测到京麦未登录,已自动打开京麦登录窗口,请在弹出的浏览器里完成登录'
const gate = await ensureJdLogin(api)
if (gate.status === 'ok') {
shopNote.value = ''
detectingShop.value = false
await detectShop({ fromAutoLogin: true })
return
}
if (gate.severity === 'error') {
shopNote.value = ''
shopError.value = gate.hint || result.error || '打开京麦登录窗口失败,请稍后重试'
} else {
shopNote.value = gate.hint || shopNote.value
}
return
}
shopError.value = result?.error || '检测京麦店铺失败,请稍后重试'
} finally {
detectingShop.value = false
}
}
/**
* 建单前把店铺核一次:已检测且一致就不再开浏览器;命中不匹配/跨店直接给拦截文案。
* 检测失败(页面结构变更、老客户端、京麦任务在跑)**不**拦创建——最终强拦截在客户端
* 执行器(先上报标记再中止)与服务端(命中即整单判死),页面这层只负责提前告知。
*/
async function ensureShopChecked(): Promise<string> {
const guard = shopGuard.value
if (shopGuardBlocks(guard)) return guard.message
if (guard.state !== 'undetected') return ''
await detectShop()
const next = shopGuard.value
return shopGuardBlocks(next) ? next.message : ''
}
const submitDisabled = computed(() =>
submitting.value
|| detectingShop.value
|| shopGuardBlocks(shopGuard.value)
|| !selectedGroupId.value
|| !selectedProducts.value.size
|| !isValidBrand(targetBrandName.value)
@@ -603,6 +711,12 @@ async function startPublish() {
errorMessage.value = JD_UPGRADE_NOTICE
return
}
// 店铺核对在建单之前:京麦登录的不是勾选商品那家店时一条都不发(客户口径「强拦截」)。
const shopIssue = await ensureShopChecked()
if (shopIssue) {
errorMessage.value = shopIssue
return
}
const vo = await createJdPublishTask(categoryId, productIds, priceRule, brand)
board.addPollingTask(vo.taskId)
const pushNote = await pushToClientQueue(vo.queuePayload)
@@ -620,6 +734,7 @@ async function startPublish() {
onMounted(async () => {
const localName = (window.localStorage.getItem('username') || '').trim()
if (localName) username.value = localName
refreshShopDetectability()
board.loadPollingIds()
await Promise.all([
loadGroups().catch(() => undefined),
@@ -666,6 +781,35 @@ onUnmounted(() => {
<main class="jd-body">
<aside class="left-panel">
<!-- 本次上架到哪家店:来源店铺(勾选商品快照)vs 京麦当前登录店铺(现检测) -->
<div class="category-block shop-guard">
<span class="category-label">本次上架到哪家店</span>
<p class="shop-line">
<span class="shop-line__key">商品来源店铺</span>
<span class="shop-line__value">{{ sourceShopText }}</span>
</p>
<p class="shop-line">
<span class="shop-line__key">京麦当前登录</span>
<span class="shop-line__value" :class="{ 'shop-line__value--muted': !currentShop }">{{ currentShopText }}</span>
<button class="shop-detect-btn" type="button" :disabled="detectingShop || !canDetectShop" @click="detectShop()">
{{ detectingShop ? '检测中…' : (currentShop ? '重新检测' : '检测京麦店铺') }}
</button>
</p>
<p v-if="shopError" class="shop-alert">{{ shopError }}</p>
<p v-else-if="shopGuard.state === 'mismatch' || shopGuard.state === 'multi'" class="shop-alert">
{{ shopGuard.message }}
</p>
<p v-else-if="shopGuard.state === 'match'" class="shop-ok">
店铺一致:商品会发布到「{{ shopLabel(shopGuard.expected) }}」。
</p>
<p v-else-if="shopNote" class="category-hint">{{ shopNote }}</p>
<p v-else-if="!canDetectShop" class="category-hint">{{ SHOP_DETECT_UNAVAILABLE }}</p>
<p v-else class="category-hint">
勾选商品后点「检测京麦店铺」可确认京麦当前登录的是不是同一家店;不一致时本页不让建单,
客户端发布前还会再核对一次,一条都不会发出去。
</p>
</div>
<div class="category-block">
<span class="category-label">自定义分类</span>
<el-select v-model="selectedGroupId" placeholder="选择分类" class="shop-cat-select"
@@ -700,6 +844,7 @@ onUnmounted(() => {
<span class="product-info">
<span class="product-title">{{ product.title }}</span>
<span class="product-meta">
<template v-if="product.shopName">店铺 {{ product.shopName }} · </template>
¥{{ product.priceMin ?? '-' }}<template v-if="product.priceMax && product.priceMax !== product.priceMin">~{{ product.priceMax }}</template>
· 库存 {{ product.stockTotal ?? '-' }}<template v-if="product.skuCount"> · {{ product.skuCount }}个SKU</template>
</span>
@@ -797,6 +942,16 @@ onUnmounted(() => {
.category-block { margin-bottom: 16px; }
.category-label { display: block; margin-bottom: 8px; color: #c8d2e2; font-size: 13px; font-weight: 600; }
.category-hint { margin: 8px 0 0; color: #7f8ca3; font-size: 12px; line-height: 1.6; }
.shop-guard { padding: 10px 12px; border: 1px solid #2c3547; border-radius: 8px; background: #20283a; }
.shop-line { display: flex; align-items: center; gap: 8px; margin: 0 0 6px; font-size: 12px; line-height: 1.5; }
.shop-line__key { flex-shrink: 0; color: #7f8ca3; }
.shop-line__value { min-width: 0; overflow: hidden; color: #d9e1ef; text-overflow: ellipsis; white-space: nowrap; }
.shop-line__value--muted { color: #7f8ca3; }
.shop-detect-btn { flex-shrink: 0; margin-left: auto; padding: 3px 10px; border: 1px solid #3e4a62; border-radius: 6px; background: #232b3d; color: #c8d2e2; font-family: inherit; font-size: 12px; cursor: pointer; }
.shop-detect-btn:hover:not(:disabled) { border-color: #6ea8ff; color: #f5f8fc; }
.shop-detect-btn:disabled { opacity: 0.55; cursor: not-allowed; }
.shop-alert { margin: 6px 0 0; padding: 8px 10px; border-radius: 6px; background: rgba(248, 113, 113, 0.12); color: #fca5a5; font-size: 12px; line-height: 1.6; }
.shop-ok { margin: 6px 0 0; color: #6ee7b7; font-size: 12px; }
.shop-cat-select { width: 100%; }
.shop-cat-select :deep(.el-select__wrapper) { background-color: #232b3d; box-shadow: 0 0 0 1px #3e4a62 inset; }
.shop-cat-select :deep(.el-select__placeholder), .shop-cat-select :deep(.el-select__selected-item) { color: #c8d2e2; }