From 28adc28ea6290b9653f38471cdc561c1de9cc21b Mon Sep 17 00:00:00 2001 From: liufumingren Date: Sun, 8 Nov 2026 11:04:30 +0800 Subject: [PATCH] =?UTF-8?q?feat(shop-product):=20=E5=BA=97=E9=93=BA?= =?UTF-8?q?=E5=95=86=E5=93=81=E6=94=AF=E6=8C=81=E6=8C=89=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E5=95=86=E5=93=81ID=20/=20=E8=A7=84=E6=A0=BCID=20=E7=AD=9B?= =?UTF-8?q?=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 排查「某件商品/某个规格拉没拉全、绑定到哪」时只能靠关键词模糊搜,容易漏(关键词只匹配标题/商家编码/商品ID)。 - 后端 shopProduct.index:新增 outer_item_ids / outer_sku_ids 多值精确筛选(IN), 与 outer_codes 同口径(英文逗号分隔);keyword 增加 outer_sku_id 模糊匹配, 与导出关键词口径对齐 - 前端店铺商品页:搜索栏加「商品ID」「规格ID」两个多值输入; 重置/查询/导出条件同步带上 - 导出(exportDefs.shop_product):补 outer_item_ids / outer_sku_ids 筛选与 whereIn, 导出抽屉里同样能按 ID 过滤 验证:真实库按 outer_item_id=3835275595751752044、outer_sku_id IN (…) 命中 2 行; vue-tsc / eslint / vite build 通过;test/app 139 passing(request_log 既有失败) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- backend/app/controller/shopProduct.js | 13 +++++++++++- backend/app/utils/exportDefs.js | 4 ++++ frontend/src/views/ShopProduct/Index.vue | 26 +++++++++++++++++++++++- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/backend/app/controller/shopProduct.js b/backend/app/controller/shopProduct.js index 0ea78fe..dada0d1 100644 --- a/backend/app/controller/shopProduct.js +++ b/backend/app/controller/shopProduct.js @@ -38,7 +38,7 @@ class ShopProductController extends Controller { /** * @summary 店铺商品列表 * @description 分页查询店铺商品,支持按店铺(多选)、平台类型(多选)、商家编码(多个精确匹配)、 - * 绑定状态、关键词(标题/商家编码/平台商品ID)过滤; + * 平台商品ID / 平台规格ID(多个精确匹配)、绑定状态、关键词(标题/商家编码/平台商品ID)过滤; * has_unbound_order=1 时只返回「有订单但未绑定系统商品」的店铺商品 * @router get /api/shop-products * @apikey @@ -49,6 +49,8 @@ class ShopProductController extends Controller { * @request query integer shop_id 店铺ID(单值,兼容旧调用) * @request query string platform_types 平台类型编码(PDD/DYXD/SPH…),多个用英文逗号分隔 * @request query string outer_codes 商家编码,多个用英文逗号分隔(精确匹配) + * @request query string outer_item_ids 平台商品ID,多个用英文逗号分隔(精确匹配) + * @request query string outer_sku_ids 平台规格ID,多个用英文逗号分隔(精确匹配) * @request query integer bind_type 绑定类型:0未绑定 1系统商品 2组合商品 * @request query integer status 状态:1在售 0下架 * @request query string keyword 关键词,匹配标题、商家编码或平台商品ID @@ -64,6 +66,8 @@ class ShopProductController extends Controller { shop_ids: shopIds, platform_types: platformTypes, outer_codes: outerCodes, + outer_item_ids: outerItemIds, + outer_sku_ids: outerSkuIds, bind_type: bindType, status, keyword, @@ -84,6 +88,11 @@ class ShopProductController extends Controller { // 商家编码支持多个精确匹配(与关键词的模糊匹配区分开) const outerCodeList = parseListParam(outerCodes).map(code => code.slice(0, 100)); if (outerCodeList.length) where.outer_code = { [Op.in]: outerCodeList }; + // 平台商品ID / 平台规格ID:多值精确匹配(排查某件商品、某个规格时按原样粘 ID 查) + const outerItemIdList = parseListParam(outerItemIds).map(id => id.slice(0, 100)); + if (outerItemIdList.length) where.outer_item_id = { [Op.in]: outerItemIdList }; + const outerSkuIdList = parseListParam(outerSkuIds).map(id => id.slice(0, 100)); + if (outerSkuIdList.length) where.outer_sku_id = { [Op.in]: outerSkuIdList }; if (bindType !== undefined && bindType !== '') where.bind_type = Number(bindType); if (status !== undefined && status !== '') where.status = Number(status); @@ -97,6 +106,8 @@ class ShopProductController extends Controller { { title: { [Op.like]: `%${keyword}%` } }, { outer_code: { [Op.like]: `%${keyword}%` } }, { outer_item_id: { [Op.like]: `%${keyword}%` } }, + // 与导出/关键词口径一致:规格ID 也能模糊搜 + { outer_sku_id: { [Op.like]: `%${keyword}%` } }, ]; } diff --git a/backend/app/utils/exportDefs.js b/backend/app/utils/exportDefs.js index 9aba442..b9b6d1d 100644 --- a/backend/app/utils/exportDefs.js +++ b/backend/app/utils/exportDefs.js @@ -1029,6 +1029,8 @@ const EXPORT_TYPES = { { key: 'shop_ids', label: '店铺', type: 'shop', multiple: true }, { key: 'platform_types', label: '平台类型', type: 'select', options: PLATFORM_TYPE_OPTIONS, multiple: true }, { key: 'outer_codes', label: '商家编码', type: 'text', placeholder: '多个用英文逗号分隔' }, + { key: 'outer_item_ids', label: '平台商品ID', type: 'text', placeholder: '多个用英文逗号分隔' }, + { key: 'outer_sku_ids', label: '平台规格ID', type: 'text', placeholder: '多个用英文逗号分隔' }, { key: 'bind_type', label: '绑定类型', type: 'select', options: BIND_TYPE_OPTIONS }, { key: 'status', label: '状态', type: 'select', options: ENABLE_OPTIONS }, { key: 'has_unbound_order', label: '只看有订单未绑定', type: 'select', options: [{ value: '1', label: '是' }] }, @@ -1045,6 +1047,8 @@ const EXPORT_TYPES = { whereIn(wh, 't.shop_id', csvValues(f.shop_ids).map(Number).filter(id => Number.isInteger(id) && id > 0)); whereIn(wh, 't.platform_type', csvValues(f.platform_types)); whereIn(wh, 't.outer_code', csvValues(f.outer_codes)); + whereIn(wh, 't.outer_item_id', csvValues(f.outer_item_ids)); + whereIn(wh, 't.outer_sku_id', csvValues(f.outer_sku_ids)); // 有订单未绑定:与列表接口同口径(未绑定 + 被未解析的订单明细引用; // 只算待审核/异常的单,已流转的单不会因绑定而重建) if (String(f.has_unbound_order) === '1') { diff --git a/frontend/src/views/ShopProduct/Index.vue b/frontend/src/views/ShopProduct/Index.vue index 6ddd24a..6db7b74 100644 --- a/frontend/src/views/ShopProduct/Index.vue +++ b/frontend/src/views/ShopProduct/Index.vue @@ -35,6 +35,10 @@ const query = reactive({ platform_types: [] as string[], /** 商家编码多值(精确匹配) */ outer_codes: [] as string[], + /** 平台商品ID 多值(精确匹配) */ + outer_item_ids: [] as string[], + /** 平台规格ID 多值(精确匹配) */ + outer_sku_ids: [] as string[], bind_type: '' as string | number, status: '' as string | number, keyword: '', @@ -56,6 +60,8 @@ const { loading, list, total, elapsed, fetchList, search, handlePageChange, hand if (query.shop_ids.length) params.shop_ids = query.shop_ids.join(',') if (query.platform_types.length) params.platform_types = query.platform_types.join(',') if (query.outer_codes.length) params.outer_codes = query.outer_codes.join(',') + if (query.outer_item_ids.length) params.outer_item_ids = query.outer_item_ids.join(',') + if (query.outer_sku_ids.length) params.outer_sku_ids = query.outer_sku_ids.join(',') if (!params.keyword) delete params.keyword if (params.bind_type === '') delete params.bind_type if (params.status === '') delete params.status @@ -81,6 +87,8 @@ function reset() { query.shop_ids = [] query.platform_types = [] query.outer_codes = [] + query.outer_item_ids = [] + query.outer_sku_ids = [] query.bind_type = '' query.status = '' query.keyword = '' @@ -99,6 +107,8 @@ const exportFilters = computed(() => ({ shop_ids: query.shop_ids.join(','), platform_types: query.platform_types.join(','), outer_codes: query.outer_codes.join(','), + outer_item_ids: query.outer_item_ids.join(','), + outer_sku_ids: query.outer_sku_ids.join(','), bind_type: query.has_unbound_order ? 0 : query.bind_type, status: query.status, keyword: query.keyword.trim(), @@ -506,10 +516,24 @@ onBeforeUnmount(() => { width="200px" /> + + + + + +