feat(shop): 新增线下店铺类型,平台店铺平台改为必填
- 店铺类型新增 4 线下店铺(手工建单用,无自动拉单/平台对接) - 线下店铺不展示也不保存自动拉取订单与拉取间隔,平台字段一并清空 - 平台店铺新增/编辑都强制校验平台必填(前后端一致) - 列表与详情的「自动拉取」「平台」列对线下店铺显示为 - Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
797bbbcd82
commit
4cba1a152a
@ -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' },
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -47,15 +47,17 @@ const PLATFORMS = [
|
||||
|
||||
const STATUS_LABELS: Record<number, string> = { 1: '启用', 0: '禁用' }
|
||||
|
||||
/** 店铺类型:1 平台店铺 2 外部打单平台商家 3 数据库店铺 */
|
||||
const TYPE_LABELS: Record<number, string> = { 1: '平台店铺', 2: '外部打单平台', 3: '数据库店铺' }
|
||||
/** 店铺类型:1 平台店铺 2 外部打单平台商家 3 数据库店铺 4 线下店铺 */
|
||||
const TYPE_LABELS: Record<number, string> = { 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(() => {
|
||||
</el-table-column>
|
||||
<el-table-column label="自动拉取" width="150">
|
||||
<template #default="{ row }">
|
||||
<el-tag v-if="row.auto_fetch_order === 1" type="success">
|
||||
每 {{ row.auto_fetch_interval }} 分钟
|
||||
</el-tag>
|
||||
<el-tag v-else type="info">关闭</el-tag>
|
||||
<el-tooltip
|
||||
v-if="row.last_order_sync_at"
|
||||
:content="`${formatDateTime(row.last_order_sync_at)} ${row.last_order_sync_msg || ''}`"
|
||||
placement="top"
|
||||
>
|
||||
<div class="last-sync">最近拉单</div>
|
||||
</el-tooltip>
|
||||
<span v-if="row.type === SHOP_TYPE_OFFLINE" class="last-sync">-</span>
|
||||
<template v-else>
|
||||
<el-tag v-if="row.auto_fetch_order === 1" type="success">
|
||||
每 {{ row.auto_fetch_interval }} 分钟
|
||||
</el-tag>
|
||||
<el-tag v-else type="info">关闭</el-tag>
|
||||
<el-tooltip
|
||||
v-if="row.last_order_sync_at"
|
||||
:content="`${formatDateTime(row.last_order_sync_at)} ${row.last_order_sync_msg || ''}`"
|
||||
placement="top"
|
||||
>
|
||||
<div class="last-sync">最近拉单</div>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="contact_name" label="联系人" width="100" />
|
||||
@ -979,7 +1000,10 @@ onMounted(() => {
|
||||
{{ platformLabel(currentShop.platform) }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="自动拉取订单">
|
||||
{{ currentShop.auto_fetch_order === 1 ? `是(每 ${currentShop.auto_fetch_interval} 分钟)` : '否' }}
|
||||
<span v-if="currentShop.type === SHOP_TYPE_OFFLINE">-</span>
|
||||
<span v-else>
|
||||
{{ currentShop.auto_fetch_order === 1 ? `是(每 ${currentShop.auto_fetch_interval} 分钟)` : '否' }}
|
||||
</span>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="最近拉单">
|
||||
<span v-if="currentShop.last_order_sync_at">
|
||||
@ -1070,8 +1094,8 @@ onMounted(() => {
|
||||
数据库店铺保存后需在列表「配置」中填写数据库连接、选表与字段映射
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="form.type === SHOP_TYPE_PLATFORM" label="平台" prop="platform">
|
||||
<el-select v-model="form.platform" placeholder="选填" clearable style="width: 100%">
|
||||
<el-form-item v-if="form.type === SHOP_TYPE_PLATFORM" label="平台" prop="platform" required>
|
||||
<el-select v-model="form.platform" placeholder="请选择平台" clearable style="width: 100%">
|
||||
<el-option v-for="p in PLATFORMS" :key="p.value" :label="p.label" :value="p.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
@ -1087,11 +1111,11 @@ onMounted(() => {
|
||||
<el-option label="禁用" :value="0" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="自动拉取订单" prop="auto_fetch_order">
|
||||
<el-form-item v-if="form.type !== SHOP_TYPE_OFFLINE" label="自动拉取订单" prop="auto_fetch_order">
|
||||
<el-switch v-model="form.auto_fetch_order" :active-value="1" :inactive-value="0" />
|
||||
<span class="form-tip">开启后按间隔自动拉取该店铺订单</span>
|
||||
</el-form-item>
|
||||
<el-form-item label="拉取间隔" prop="auto_fetch_interval">
|
||||
<el-form-item v-if="form.type !== SHOP_TYPE_OFFLINE" label="拉取间隔" prop="auto_fetch_interval">
|
||||
<el-input-number
|
||||
v-model="form.auto_fetch_interval"
|
||||
:min="3"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user