- 迁移 shop_database_configs:一店一条,存数据库类型/IP/端口/库名/账号/密码、 商品表/订单表/订单明细表名、三份字段映射与最近校验结果 - 新增 shopDatabase 控制器与 lib:服务端用 mysql2 连接客户库(8s 超时、utf8mb4), 提供配置读取/保存、测试连通、连接拉表、拉表列表与表字段;表名走白名单校验 - 保存时连得上则校验表与列真实存在(不存在拒绝保存),连不上则保存并提示未校验 - 店铺新增支持 type=3 数据库店铺;删除店铺时一并清理数据库配置 - 前端:新增店铺可选「数据库店铺」,创建后自动打开配置弹窗;列表对数据库店铺 显示「配置」,弹窗内填写连接信息、测试连通、连接拉表、选三张表并逐个字段映射 - 契约与路由:补数据库店铺配置相关接口定义 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
89 lines
3.4 KiB
JavaScript
89 lines
3.4 KiB
JavaScript
'use strict';
|
||
|
||
/**
|
||
* 数据库店铺(shops.type=3)可映射的 OMS 字段定义
|
||
*
|
||
* 数据库店铺只支持「明文订单」:源库里的收件人、省市区等字段都是直接可读的值,
|
||
* 不需要解密/解析,因此每个字段都要求人工指定对应的源表列名。
|
||
* 商品表 / 订单表 / 订单明细表三组字段分别独立映射。
|
||
*/
|
||
|
||
/** 支持的数据库类型(当前仅 MySQL) */
|
||
const DB_TYPES = [
|
||
{ value: 'mysql', label: 'MySQL' },
|
||
];
|
||
const DEFAULT_DB_TYPE = 'mysql';
|
||
const DEFAULT_PORT = 3306;
|
||
|
||
/**
|
||
* 三张数据集的定义:key 与表 config 列一一对应
|
||
* - tableColumn:保存表名的列(shop_database_configs 内)
|
||
* - fieldColumn:保存字段映射的列(JSON:{ oms字段: 源列名 })
|
||
*/
|
||
const DATASETS = {
|
||
product: {
|
||
label: '商品表',
|
||
tableColumn: 'product_table',
|
||
fieldColumn: 'product_fields',
|
||
fields: [
|
||
{ key: 'item_code', label: '商品编码', required: true },
|
||
{ key: 'item_name', label: '商品名称', required: true },
|
||
{ key: 'sku_property', label: 'SKU规格', required: false },
|
||
{ key: 'barcode', label: '条码', required: false },
|
||
{ key: 'stock_unit', label: '库存单位', required: false },
|
||
{ key: 'price', label: '单价', required: false },
|
||
],
|
||
},
|
||
order: {
|
||
label: '订单表',
|
||
tableColumn: 'order_table',
|
||
fieldColumn: 'order_fields',
|
||
fields: [
|
||
{ key: 'order_no', label: '订单号', required: true },
|
||
{ key: 'place_order_time', label: '下单时间', required: false },
|
||
{ key: 'receiver', label: '收件人', required: true },
|
||
{ key: 'mobile', label: '手机号', required: false },
|
||
{ key: 'tel', label: '电话', required: false },
|
||
{ key: 'province', label: '省', required: true },
|
||
{ key: 'city', label: '市', required: true },
|
||
{ key: 'area', label: '区/县', required: true },
|
||
{ key: 'town', label: '街道/镇', required: false },
|
||
{ key: 'detail_address', label: '详细地址', required: true },
|
||
{ key: 'zip_code', label: '邮编', required: false },
|
||
{ key: 'total_amount', label: '订单金额', required: false },
|
||
{ key: 'freight', label: '运费', required: false },
|
||
{ key: 'buyer_message', label: '买家留言', required: false },
|
||
{ key: 'seller_message', label: '卖家留言', required: false },
|
||
],
|
||
},
|
||
order_item: {
|
||
label: '订单明细表',
|
||
tableColumn: 'order_item_table',
|
||
fieldColumn: 'order_item_fields',
|
||
fields: [
|
||
{ key: 'order_no', label: '订单号(关联订单表)', required: true },
|
||
{ key: 'item_code', label: '商品编码', required: true },
|
||
{ key: 'item_name', label: '商品名称', required: false },
|
||
{ key: 'sku_property', label: 'SKU规格', required: false },
|
||
{ key: 'quantity', label: '数量', required: true },
|
||
{ key: 'price', label: '单价', required: false },
|
||
],
|
||
},
|
||
};
|
||
|
||
/**
|
||
* 供接口返回给前端的字段定义(含必填标记与保存列名,前端据此渲染映射表单)
|
||
* @return {Array} 三组字段定义
|
||
*/
|
||
function datasetDefs() {
|
||
return Object.entries(DATASETS).map(([ key, def ]) => ({
|
||
key,
|
||
label: def.label,
|
||
table_column: def.tableColumn,
|
||
field_column: def.fieldColumn,
|
||
fields: def.fields.map(field => ({ key: field.key, label: field.label, required: field.required })),
|
||
}));
|
||
}
|
||
|
||
module.exports = { DB_TYPES, DEFAULT_DB_TYPE, DEFAULT_PORT, DATASETS, datasetDefs };
|