From fe97be28933fe7e9573544b513544871bc750450 Mon Sep 17 00:00:00 2001 From: liufumingren Date: Fri, 6 Nov 2026 22:22:41 +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=E5=BA=97=E9=93=BA/?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E7=B1=BB=E5=9E=8B/=E5=95=86=E5=AE=B6?= =?UTF-8?q?=E7=BC=96=E7=A0=81=E5=A4=9A=E5=80=BC=E7=AD=9B=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 列表接口支持 shop_ids / platform_types / outer_codes(逗号分隔或数组,去重、上限 200),店铺与平台类型为 IN 条件,商家编码为多值精确匹配;保留单值 shop_id 与关键词模糊查询 - 前端:店铺改为多选虚拟下拉、新增平台类型多选、新增商家编码多值控件(收起英文逗号拼接、展开一行一个) - 导出同步支持多值筛选(多选控件按 CSV 提交)并补上「平台类型」列 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- backend/app/controller/shopProduct.js | 51 +++++++- backend/app/utils/exportDefs.js | 45 ++++++- frontend/src/api/exportTask.ts | 2 + frontend/src/components/ExportFilterField.vue | 48 +++++++- frontend/src/components/MultiValueFilter.vue | 110 ++++++++++++++++++ frontend/src/views/ShopProduct/Index.vue | 56 +++++++-- 6 files changed, 297 insertions(+), 15 deletions(-) create mode 100644 frontend/src/components/MultiValueFilter.vue diff --git a/backend/app/controller/shopProduct.js b/backend/app/controller/shopProduct.js index ca98d73..24ad840 100644 --- a/backend/app/controller/shopProduct.js +++ b/backend/app/controller/shopProduct.js @@ -10,6 +10,26 @@ const EDITABLE_ORDER_STATUSES = [ ORDER_STATUS.PENDING, ORDER_STATUS.EXCEPTION ] /** 批量绑定的单次上限(避免一次请求里重建过多订单明细) */ const BATCH_BIND_LIMIT = 500; +/** 多值筛选参数的单次上限(防止超长 IN 拖垮查询) */ +const MAX_FILTER_VALUES = 200; + +/** + * 解析多值筛选参数:支持数组(a=1&a=2)与逗号分隔字符串(a=1,2),去空去重 + * @param {*} value 原始参数 + * @param {number} [max] 最多保留的值个数 + * @return {Array} 值列表 + */ +function parseListParam(value, max = MAX_FILTER_VALUES) { + const raw = Array.isArray(value) ? value : String(value == null ? '' : value).split(','); + const list = []; + for (const item of raw) { + const text = String(item == null ? '' : item).trim(); + if (text && !list.includes(text)) list.push(text); + if (list.length >= max) break; + } + return list; +} + /** * @controller ShopProductController 店铺商品管理 * 采集自各平台店铺的商品,可单向绑定系统商品(products)或组合商品(combo_products) @@ -17,14 +37,18 @@ const BATCH_BIND_LIMIT = 500; class ShopProductController extends Controller { /** * @summary 店铺商品列表 - * @description 分页查询店铺商品,支持按店铺、绑定状态、关键词(标题/商家编码/平台商品ID)过滤; + * @description 分页查询店铺商品,支持按店铺(多选)、平台类型(多选)、商家编码(多个精确匹配)、 + * 绑定状态、关键词(标题/商家编码/平台商品ID)过滤; * has_unbound_order=1 时只返回「有订单但未绑定系统商品」的店铺商品 * @router get /api/shop-products * @apikey * @request query integer page 页码,默认 1 * @request query integer pageSize 每页条数,默认 20 * @request query integer principal_id 所属主体ID(必填,需当前账号已绑定该主体) - * @request query integer shop_id 店铺ID,不传则不过滤 + * @request query string shop_ids 店铺ID,多个用英文逗号分隔(如 12,18) + * @request query integer shop_id 店铺ID(单值,兼容旧调用) + * @request query string platform_types 平台类型编码(PDD/DYXD/SPH…),多个用英文逗号分隔 + * @request query string outer_codes 商家编码,多个用英文逗号分隔(精确匹配) * @request query integer bind_type 绑定类型:0未绑定 1系统商品 2组合商品 * @request query integer status 状态:1在售 0下架 * @request query string keyword 关键词,匹配标题、商家编码或平台商品ID @@ -35,12 +59,31 @@ class ShopProductController extends Controller { const { ctx } = this; const Op = this.app.Sequelize.Op; const { page, pageSize, offset, limit } = parsePagination(ctx.query); - const { shop_id: shopId, bind_type: bindType, status, keyword, has_unbound_order: hasUnboundOrder } = ctx.query; + const { + shop_id: shopId, + shop_ids: shopIds, + platform_types: platformTypes, + outer_codes: outerCodes, + bind_type: bindType, + status, + keyword, + has_unbound_order: hasUnboundOrder, + } = ctx.query; const principalId = Number(ctx.state.principalId); const where = {}; where.principal_id = principalId; - if (shopId) where.shop_id = Number(shopId); + const shopIdList = parseListParam(shopIds) + .map(Number) + .filter(id => Number.isInteger(id) && id > 0); + if (shopIdList.length) where.shop_id = { [Op.in]: shopIdList }; + else if (shopId) where.shop_id = Number(shopId); + // 平台类型按系统预设编码筛选(PDD / DYXD / SPH…) + const platformTypeList = parseListParam(platformTypes); + if (platformTypeList.length) where.platform_type = { [Op.in]: platformTypeList }; + // 商家编码支持多个精确匹配(与关键词的模糊匹配区分开) + const outerCodeList = parseListParam(outerCodes).map(code => code.slice(0, 100)); + if (outerCodeList.length) where.outer_code = { [Op.in]: outerCodeList }; if (bindType !== undefined && bindType !== '') where.bind_type = Number(bindType); if (status !== undefined && status !== '') where.status = Number(status); diff --git a/backend/app/utils/exportDefs.js b/backend/app/utils/exportDefs.js index 905aafc..e5b7060 100644 --- a/backend/app/utils/exportDefs.js +++ b/backend/app/utils/exportDefs.js @@ -20,6 +20,7 @@ const { const { BILL_STATUS_LABELS, BILL_STATUS_ORDER } = require('../lib/billStatus'); const { INBOUND_ORDER_TYPES, OUTBOUND_ORDER_TYPES } = require('../lib/wms/orderTypes'); const { BIZ_TYPES } = require('./stockRecord'); +const { PLATFORM_PRESETS, platformNameOf } = require('../lib/platformCode'); /* ==================== 选项常量(标签一律取自各业务模块的单一来源) ==================== */ @@ -70,6 +71,35 @@ const SUCCESS_OPTIONS = [ /** 业务动作选项(出库推送锁定 / 出库解锁 / 订单审核锁定 …) */ const BIZ_TYPE_OPTIONS = Object.keys(BIZ_TYPES).map(value => ({ label: BIZ_TYPES[value].label, value })); +/** + * 多值筛选值 → 去重后的字符串列表(兼容数组与英文/中文逗号分隔) + * @param {*} value 原始筛选值 + * @param {number} [max] 最多保留个数(防止超长 IN) + * @return {Array} 值列表 + */ +function csvValues(value, max = 200) { + const raw = Array.isArray(value) ? value : String(value == null ? '' : value).split(','); + const list = []; + for (const item of raw) { + const text = String(item == null ? '' : item).trim(); + if (text && !list.includes(text)) list.push(text); + if (list.length >= max) break; + } + return list; +} + +/** + * 追加多值 IN 条件(空列表跳过) + * @param {Object} wh makeWhere() 结果 + * @param {string} column 列名 + * @param {Array} values 值列表 + * @return {void} 直接追加到 wh + */ +function whereIn(wh, column, values) { + if (!values.length) return; + wh.raw(`${column} IN (${values.map(() => '?').join(',')})`, ...values); +} + /** 入库单 / 出库单类型选项 */ const INBOUND_TYPE_OPTIONS = Object.keys(INBOUND_ORDER_TYPES).map(value => ({ label: `${INBOUND_ORDER_TYPES[value]}(${value})`, value })); const OUTBOUND_TYPE_OPTIONS = Object.keys(OUTBOUND_ORDER_TYPES).map(value => ({ label: `${OUTBOUND_ORDER_TYPES[value]}(${value})`, value })); @@ -82,6 +112,8 @@ const PLATFORM_OPTIONS = [ { label: '京东', value: 'jd' }, { label: '其他', value: 'other' }, ]; +/** 店铺商品平台类型选项:系统预设平台编码(与 app/lib/platformCode.js 同源) */ +const PLATFORM_TYPE_OPTIONS = PLATFORM_PRESETS.map(item => ({ label: item.name, value: item.code })); const PRINCIPAL_TYPE_OPTIONS = [ { label: '自营', value: 1 }, { label: '加盟', value: 2 }, @@ -480,6 +512,11 @@ const SHOP_PRODUCT_COLUMNS = [ expr: '(SELECT s.name FROM principal_subsidiaries s WHERE s.id = t.subsidiary_id)', }, { key: 'bind_type', header: '绑定类型', format: labels(BIND_TYPE_MAP) }, + { + key: 'platform_type', + header: '平台类型', + format: value => (value ? platformNameOf(value) : ''), + }, { key: 'product_id', header: '系统商品ID' }, { key: 'product_name', header: '系统商品名称', expr: '(SELECT p.item_name FROM products p WHERE p.id = t.product_id)' }, { key: 'combo_product_id', header: '组合商品ID' }, @@ -954,7 +991,9 @@ const EXPORT_TYPES = { shop_product: { label: '店铺商品', filters: [ - { key: 'shop_id', label: '店铺', type: 'shop' }, + { 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: '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: '是' }] }, @@ -967,6 +1006,10 @@ const EXPORT_TYPES = { .eq('t.bind_type', f.bind_type) .eq('t.status', f.status) .kw([ 't.title', 't.outer_item_id', 't.outer_sku_id', 't.outer_code' ], f.keyword); + // 多值筛选:店铺 / 平台类型 / 商家编码(与列表接口同口径) + 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)); // 有订单未绑定:与列表接口同口径(未绑定 + 被未解析的订单明细引用) if (String(f.has_unbound_order) === '1') { wh.raw('t.bind_type = 0'); diff --git a/frontend/src/api/exportTask.ts b/frontend/src/api/exportTask.ts index c6a905e..b0bfd14 100644 --- a/frontend/src/api/exportTask.ts +++ b/frontend/src/api/exportTask.ts @@ -31,6 +31,8 @@ export interface ExportFilterDef { type: ExportFilterType options?: ExportFilterOption[] placeholder?: string + /** 是否多选:多选值提交时按英文逗号拼接(如店铺/平台类型) */ + multiple?: boolean } /** 导出任务状态:0待处理 1处理中 2已完成 3失败 */ diff --git a/frontend/src/components/ExportFilterField.vue b/frontend/src/components/ExportFilterField.vue index 8ae0ce1..6b0806f 100644 --- a/frontend/src/components/ExportFilterField.vue +++ b/frontend/src/components/ExportFilterField.vue @@ -64,6 +64,25 @@ const productId = computed({ set: (v: number | null) => emit('update:modelValue', v), }) +/** + * 多选筛选值(数组 ↔ 英文逗号分隔字符串) + * 导出任务里筛选值统一按字符串保存,多选在提交前拼成 CSV,与后端 CSV 解析口径一致 + */ +const multiValue = computed({ + get: () => { + const raw = props.modelValue + if (Array.isArray(raw)) return raw.map(v => String(v)) + return String(raw ?? '') + .split(',') + .map(item => item.trim()) + .filter(Boolean) + }, + set: (v: unknown) => { + const list = Array.isArray(v) ? v.map(item => String(item)) : [] + emit('update:modelValue', list.join(',')) + }, +}) + function onProductSelect(product: ProductSearchItem) { emit('update:modelValue', product.id) emit('update:productLabel', product.item_code ? `${product.item_code} ${product.item_name}` : product.item_name || '') @@ -77,7 +96,21 @@ function clearProduct() {