From 4cba1a152ab3b80f2a3a6803ee0721877c11a00d Mon Sep 17 00:00:00 2001 From: liufumingren Date: Thu, 5 Nov 2026 17:07:23 +0800 Subject: [PATCH] =?UTF-8?q?feat(shop):=20=E6=96=B0=E5=A2=9E=E7=BA=BF?= =?UTF-8?q?=E4=B8=8B=E5=BA=97=E9=93=BA=E7=B1=BB=E5=9E=8B=EF=BC=8C=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=E5=BA=97=E9=93=BA=E5=B9=B3=E5=8F=B0=E6=94=B9=E4=B8=BA?= =?UTF-8?q?=E5=BF=85=E5=A1=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 店铺类型新增 4 线下店铺(手工建单用,无自动拉单/平台对接) - 线下店铺不展示也不保存自动拉取订单与拉取间隔,平台字段一并清空 - 平台店铺新增/编辑都强制校验平台必填(前后端一致) - 列表与详情的「自动拉取」「平台」列对线下店铺显示为 - Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- backend/app/contract/index.js | 4 +- backend/app/controller/shop.js | 53 ++++++++++++++++++++++---- frontend/src/views/Shop/Index.vue | 62 +++++++++++++++++++++---------- 3 files changed, 90 insertions(+), 29 deletions(-) diff --git a/backend/app/contract/index.js b/backend/app/contract/index.js index ac25d3d..57995f5 100644 --- a/backend/app/contract/index.js +++ b/backend/app/contract/index.js @@ -1161,8 +1161,8 @@ module.exports = { subsidiary_id: { type: 'integer', required: true, description: '所属货主(下属公司ID),必填;所在公司权限只能选自己所属公司' }, code: { type: 'string', description: '店铺编码,留空则自动生成 OMS 前缀编码;传入时同一主体下唯一' }, name: { type: 'string', required: true, description: '店铺名称' }, - platform: { type: 'string', description: '平台标识:taobao/pdd/douyin/jd/other' }, - type: { type: 'integer', description: '店铺类型:1 平台店铺(默认)/ 3 数据库店铺' }, + platform: { type: 'string', description: '平台标识:taobao/pdd/douyin/jd/other(平台店铺必填)' }, + type: { type: 'integer', description: '店铺类型:1 平台店铺(默认)/ 3 数据库店铺 / 4 线下店铺(无线下自动拉单)' }, contact_name: { type: 'string', description: '联系人' }, contact_phone: { type: 'string', description: '联系电话' }, status: { type: 'integer', description: '状态:1启用 0禁用,默认1' }, diff --git a/backend/app/controller/shop.js b/backend/app/controller/shop.js index fb64634..2c22d61 100644 --- a/backend/app/controller/shop.js +++ b/backend/app/controller/shop.js @@ -15,8 +15,11 @@ const SHOP_TYPE_EXTERNAL = 2; /** 店铺类型:数据库店铺(自建 MySQL 库拉取明文订单,需单独配置连接与字段映射) */ const SHOP_TYPE_DATABASE = 3; -/** 手工新增时允许选择的店铺类型:平台店铺 / 数据库店铺 */ -const CREATABLE_TYPES = [ SHOP_TYPE_PLATFORM, SHOP_TYPE_DATABASE ]; +/** 店铺类型:线下店铺(OMS 内手工建单使用,无自动拉单/平台对接) */ +const SHOP_TYPE_OFFLINE = 4; + +/** 手工新增时允许选择的店铺类型:平台店铺 / 数据库店铺 / 线下店铺 */ +const CREATABLE_TYPES = [ SHOP_TYPE_PLATFORM, SHOP_TYPE_DATABASE, SHOP_TYPE_OFFLINE ]; /** 自动拉取订单的最小间隔(分钟) */ const MIN_AUTO_FETCH_INTERVAL = 3; @@ -72,7 +75,7 @@ class ShopController extends Controller { * @request query string keyword 关键词,匹配店铺名称或编码 * @request query string platform 平台标识,如 taobao/pdd/douyin/jd * @request query integer status 状态:1启用 0禁用,不传则不过滤 - * @request query integer type 店铺类型:1平台店铺 2外部打单平台商家,不传则不过滤 + * @request query integer type 店铺类型:1平台店铺 2外部打单平台商家 3数据库店铺 4线下店铺,不传则不过滤 * @response 200 shopListResponse success */ async index() { @@ -199,7 +202,7 @@ class ShopController extends Controller { /** * @summary 新增店铺 * @description name 必填;code 留空时自动生成 OMS 前缀编码(表示该店铺由 OMS 创建), - * 传入 code 时校验同一主体下唯一;type 可选 1 平台店铺(默认)/ 3 数据库店铺 + * 传入 code 时校验同一主体下唯一;type 可选 1 平台店铺(默认)/ 3 数据库店铺 / 4 线下店铺 * @router post /api/shops * @apikey * @request body createShopRequest *body @@ -272,22 +275,37 @@ class ShopController extends Controller { const incoming = Number(body.type); if (!CREATABLE_TYPES.includes(incoming)) { ctx.status = 400; - ctx.body = { code: 400, message: '店铺类型仅支持:1 平台店铺 / 3 数据库店铺' }; + ctx.body = { code: 400, message: '店铺类型仅支持:1 平台店铺 / 3 数据库店铺 / 4 线下店铺' }; return; } shopType = incoming; } delete body.type; + // 平台店铺必须选择平台;线下店铺不涉及平台 + const platform = String(body.platform || '').trim(); + if (shopType === SHOP_TYPE_PLATFORM && !platform) { + ctx.status = 400; + ctx.body = { code: 400, message: '平台店铺必须选择平台' }; + return; + } + body.platform = shopType === SHOP_TYPE_OFFLINE ? null : (platform || null); + + // 线下店铺没有自动拉单:关闭自动拉取并复位间隔 + const isOfflineShop = shopType === SHOP_TYPE_OFFLINE; + const autoFetchOrder = isOfflineShop + ? 0 + : (autoFetch.auto_fetch_order == null ? 0 : autoFetch.auto_fetch_order); + const shop = await ctx.model.Shop.create({ ...body, type: shopType, code: shopCode, subsidiary_id: subsidiary.value, - auto_fetch_order: autoFetch.auto_fetch_order == null ? 0 : autoFetch.auto_fetch_order, - auto_fetch_interval: autoFetch.auto_fetch_interval == null + auto_fetch_order: autoFetchOrder, + auto_fetch_interval: isOfflineShop ? MIN_AUTO_FETCH_INTERVAL - : autoFetch.auto_fetch_interval, + : (autoFetch.auto_fetch_interval == null ? MIN_AUTO_FETCH_INTERVAL : autoFetch.auto_fetch_interval), }); ctx.body = { code: 0, message: 'success', data: { id: shop.id, code: shop.code } }; } @@ -443,6 +461,25 @@ class ShopController extends Controller { } Object.assign(ctx.request.body, autoFetch); + // 平台店铺必须选择平台;线下店铺不涉及自动拉单 + if (Number(shop.type) === SHOP_TYPE_PLATFORM) { + const platform = ctx.request.body.platform === undefined + ? String(shop.platform || '').trim() + : String(ctx.request.body.platform || '').trim(); + if (!platform) { + ctx.status = 400; + ctx.body = { code: 400, message: '平台店铺必须选择平台' }; + return; + } + ctx.request.body.platform = platform; + } + if (Number(shop.type) === SHOP_TYPE_OFFLINE) { + // 线下店铺:没有自动拉单,也不涉及平台 + ctx.request.body.auto_fetch_order = 0; + ctx.request.body.auto_fetch_interval = MIN_AUTO_FETCH_INTERVAL; + delete ctx.request.body.platform; + } + // 编码留空视为不修改;改动时校验同主体唯一,避免撞唯一索引报 500 const code = String(ctx.request.body.code || '').trim(); if (code) { diff --git a/frontend/src/views/Shop/Index.vue b/frontend/src/views/Shop/Index.vue index 2679f95..afb5b84 100644 --- a/frontend/src/views/Shop/Index.vue +++ b/frontend/src/views/Shop/Index.vue @@ -47,15 +47,17 @@ const PLATFORMS = [ const STATUS_LABELS: Record = { 1: '启用', 0: '禁用' } -/** 店铺类型:1 平台店铺 2 外部打单平台商家 3 数据库店铺 */ -const TYPE_LABELS: Record = { 1: '平台店铺', 2: '外部打单平台', 3: '数据库店铺' } +/** 店铺类型:1 平台店铺 2 外部打单平台商家 3 数据库店铺 4 线下店铺 */ +const TYPE_LABELS: Record = { 1: '平台店铺', 2: '外部打单平台', 3: '数据库店铺', 4: '线下店铺' } -/** 新建店铺可选类型:平台店铺 / 数据库店铺(外部打单平台店铺由打单平台导入) */ +/** 新建店铺可选类型:平台店铺 / 数据库店铺 / 线下店铺(外部打单平台店铺由打单平台导入) */ const SHOP_TYPE_PLATFORM = 1 const SHOP_TYPE_DATABASE = 3 +const SHOP_TYPE_OFFLINE = 4 const CREATABLE_TYPES = [ { label: '平台店铺', value: SHOP_TYPE_PLATFORM }, { label: '数据库店铺', value: SHOP_TYPE_DATABASE }, + { label: '线下店铺', value: SHOP_TYPE_OFFLINE }, ] function platformLabel(value?: string | null) { @@ -162,6 +164,19 @@ const rules: FormRules = { subsidiary_id: [{ required: true, message: '请选择所属货主', trigger: 'change' }], name: [{ required: true, message: '请输入店铺名称', trigger: 'blur' }], status: [{ required: true, message: '请选择状态', trigger: 'change' }], + platform: [ + { + validator: (_rule: unknown, _value: unknown, callback: (e?: string | Error) => void) => { + // 平台店铺必须选择平台(数据库店铺 / 线下店铺不需要) + if (form.type === SHOP_TYPE_PLATFORM && !form.platform) { + callback(new Error('平台店铺必须选择平台')) + } else { + callback() + } + }, + trigger: 'change', + }, + ], auto_fetch_interval: [ { validator: (_rule: unknown, value: unknown, callback: (e?: string | Error) => void) => { @@ -217,9 +232,12 @@ async function submitForm() { if (!valid) return submitting.value = true try { + // 线下店铺没有自动拉单,且不涉及平台 + const isOffline = Number(form.type) === SHOP_TYPE_OFFLINE const payload = { ...form, subsidiary_id: form.subsidiary_id == null ? null : Number(form.subsidiary_id), + ...(isOffline ? { auto_fetch_order: 0, platform: '' } : {}), // 店铺类型只在新增时提交,编辑接口不接受改类型 ...(editId.value == null ? {} : { type: undefined }), } @@ -852,17 +870,20 @@ onMounted(() => { @@ -979,7 +1000,10 @@ onMounted(() => { {{ platformLabel(currentShop.platform) }} - {{ currentShop.auto_fetch_order === 1 ? `是(每 ${currentShop.auto_fetch_interval} 分钟)` : '否' }} + - + + {{ currentShop.auto_fetch_order === 1 ? `是(每 ${currentShop.auto_fetch_interval} 分钟)` : '否' }} + @@ -1070,8 +1094,8 @@ onMounted(() => { 数据库店铺保存后需在列表「配置」中填写数据库连接、选表与字段映射 - - + + @@ -1087,11 +1111,11 @@ onMounted(() => { - + 开启后按间隔自动拉取该店铺订单 - +