diff --git a/backend/app/contract/index.js b/backend/app/contract/index.js index a5932d3..0534b82 100644 --- a/backend/app/contract/index.js +++ b/backend/app/contract/index.js @@ -2511,7 +2511,10 @@ module.exports = { archived_at: { type: 'string', description: '归档时间(仅历史表)' }, transferred_at: { type: 'string', description: '转入历史时间(仅历史表)' }, }, - orderStatusPage: buildPage('orderStatusItem', '订单列表'), + orderStatusPage: { + ...buildPage('orderStatusItem', '订单列表'), + hidden_unbound: { type: 'integer', description: '因「含未绑定商品」被隐藏的订单数(exclude_unbound=1 时返回)' }, + }, orderStatusListResponse: buildListResponse('orderStatusPage'), /** 新建订单(含发货单口径:可直接带 items 创建明细) */ createOrderStatusRequest: { diff --git a/backend/app/controller/orderStatus.js b/backend/app/controller/orderStatus.js index 3d99b8f..54d6602 100644 --- a/backend/app/controller/orderStatus.js +++ b/backend/app/controller/orderStatus.js @@ -79,8 +79,12 @@ class OrderStatusController extends Controller { const { ctx } = this; const { page, pageSize, offset, limit } = parsePagination(ctx.query); try { - const { list, total } = await ctx.service.orderStatus.list({ ...ctx.query, offset, limit }); - ctx.body = { code: 0, message: 'success', data: buildPageResult(list, total, { page, pageSize }) }; + const { list, total, hiddenUnbound } = await ctx.service.orderStatus.list({ ...ctx.query, offset, limit }); + ctx.body = { + code: 0, + message: 'success', + data: { ...buildPageResult(list, total, { page, pageSize }), hidden_unbound: hiddenUnbound || 0 }, + }; } catch (err) { this._fail(ctx, err, '查询订单列表失败'); } diff --git a/backend/app/service/orderStatus.js b/backend/app/service/orderStatus.js index 4305c92..b3d3040 100644 --- a/backend/app/service/orderStatus.js +++ b/backend/app/service/orderStatus.js @@ -454,25 +454,32 @@ class OrderStatusService extends Service { // exclude_unbound=1:排除「有未绑定系统商品的明细」的订单(订单页默认只看已解析订单) // 用 EXISTS 子查询而非 IN 列表,避免未绑定订单很多时拼接超长参数 - if (String(p.exclude_unbound) === '1') { - where[Op.and].push( - ctx.app.Sequelize.literal( - 'NOT EXISTS (SELECT 1 FROM order_status_items oi WHERE oi.order_id = `' + Model.tableName + '`.id ' + - `AND oi.principal_id = ${principalId} AND oi.parse_status = 2)` - ) - ); - } + const excludeUnbound = String(p.exclude_unbound) === '1'; + const unboundClause = ctx.app.Sequelize.literal( + 'NOT EXISTS (SELECT 1 FROM order_status_items oi WHERE oi.order_id = `' + Model.tableName + '`.id ' + + `AND oi.principal_id = ${principalId} AND oi.parse_status = 2)` + ); + const whereWithUnbound = excludeUnbound + ? { ...where, [Op.and]: [ ...where[Op.and], unboundClause ] } + : where; const { count, rows } = await Model.findAndCountAll({ - where, + where: whereWithUnbound, offset: p.offset, limit: p.limit, order: [[ 'id', 'DESC' ]], }); + // 「因商品未绑定被隐藏」的订单数:前端据此提示「另有 N 单未显示」,避免看起来像漏拉 + let hiddenUnbound = 0; + if (excludeUnbound) { + const totalWithUnbound = await Model.count({ where }); + hiddenUnbound = Math.max(0, Number(totalWithUnbound) - Number(count)); + } + const list = rows.map(row => row.get({ plain: true })); await this._attachListMeta(list, principalId, status); - return { list, total: count }; + return { list, total: count, hiddenUnbound }; } /** diff --git a/frontend/src/api/orderStatus.ts b/frontend/src/api/orderStatus.ts index e181a80..797ed6a 100644 --- a/frontend/src/api/orderStatus.ts +++ b/frontend/src/api/orderStatus.ts @@ -294,10 +294,14 @@ export interface OrderStatusArchiveResult { /** 订单列表(按 status 定位状态表;principal_id 由请求拦截器注入) */ export function getOrderStatusList(params: OrderStatusQuery) { - return get<{ list: OrderStatusItem[]; total: number; page: number; pageSize: number }>( - '/order-status/list', - params as unknown as object, - ) + return get<{ + list: OrderStatusItem[] + total: number + page: number + pageSize: number + /** 因商品未绑定被隐藏的订单数(仅 exclude_unbound=1 时返回) */ + hidden_unbound?: number + }>('/order-status/list', params as unknown as object) } /** 筛选项数据源:状态枚举 + 当前主体下的店铺/仓库 + 归档阈值 */ diff --git a/frontend/src/views/Order/StatusPanel.vue b/frontend/src/views/Order/StatusPanel.vue index a28bad5..3157422 100644 --- a/frontend/src/views/Order/StatusPanel.vue +++ b/frontend/src/views/Order/StatusPanel.vue @@ -143,12 +143,24 @@ async function retryOneExternalSend(row: OrderStatusItem) { /** 「含未绑定商品订单」开关(默认关闭:不显示含未绑定商品的订单) */ const showUnboundOrders = ref(false) +/** 因商品未绑定被隐藏的订单数(后端 hidden_unbound),用于提示「不是没拉到,是没显示」 */ +const hiddenUnbound = ref(0) function onUnboundSwitchChange() { query.page = 1 search() } +/** 只在「待审核 + 仅已绑定」视图下提示被隐藏的数量 */ +const showHiddenUnboundHint = computed( + () => props.status === 'pending' && !showUnboundOrders.value && hiddenUnbound.value > 0, +) + +function onShowUnboundClick() { + showUnboundOrders.value = true + onUnboundSwitchChange() +} + const { loading, list, total, elapsed, fetchList, search, handlePageChange, handleSizeChange } = useListPage({ query, @@ -181,7 +193,10 @@ const { loading, list, total, elapsed, fetchList, search, handlePageChange, hand const sendStatus = isDeliveryException.value ? '2,3' : query.external_send_status if (sendStatus) params.external_send_status = sendStatus } - return getOrderStatusList(params as never) + return getOrderStatusList(params as never).then(res => { + hiddenUnbound.value = Number(res?.hidden_unbound) || 0 + return res + }) }, }) @@ -846,6 +861,15 @@ onBeforeUnmount(() => { 已选 {{ selectedIds.length }} 条
+ + + 另有 {{ hiddenUnbound }} 单未显示 + +