后端能力: - 接入店管家订单接口(/NewOrder/List),明细归一化后按店铺商品匹配系统商品/组合商品 - 新增 service/externalPrintOrder:手动与定时拉单共用入库逻辑,同时写入待审核状态分表 - 新增 schedule/fetchExternalShopOrders:按店铺配置的间隔自动拉单(最小 3 分钟,起点重叠 10 分钟) - 新增 lib/orderItemExpand + service/orderItemResolve:平台行与最小单位行互转; 绑定组合商品时按「数量 = 平台数量 x 组合内数量、单价取子商品零售价」拆成子商品行,解绑可还原 - 明细新增 platform_snapshot,保留平台原样(编码/名称/规格/图片/原行号/原数量/原单价) - 店铺商品列表支持 has_unbound_order 筛选,订单列表支持 exclude_unbound(均已同步导出定义) - 店铺商品只读化:移除新增/编辑/删除动作,仅保留查询与绑定; 同步商品时平台已不存在的商品自动清理(未绑定且未被订单引用直接删除,已绑定或被引用仅下架) - 新增 scripts/rebuild-order-items 存量明细重建脚本,新增 orderItemExpand 单测(8 项) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
48 lines
3.2 KiB
JavaScript
48 lines
3.2 KiB
JavaScript
'use strict';
|
||
|
||
/**
|
||
* 店铺模型,对应 shops 表(归属于主体,一个主体可有多个平台店铺)
|
||
* @param {Egg.Application} app egg application
|
||
* @return {object} shop model
|
||
*/
|
||
module.exports = app => {
|
||
const { BIGINT, STRING, TINYINT, INTEGER, JSON, DATE } = app.Sequelize;
|
||
|
||
const Shop = app.model.define('shop', {
|
||
id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' },
|
||
principal_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '所属主体ID' },
|
||
code: { type: STRING(50), allowNull: false, comment: '店铺编码(平台店铺ID或自定义编码,OMS 内新建时按 OMS 前缀自动生成)' },
|
||
name: { type: STRING(100), allowNull: false, comment: '店铺名称' },
|
||
platform: { type: STRING(50), comment: '所属平台:taobao/pdd/douyin/jd/other' },
|
||
contact_name: { type: STRING(50), comment: '联系人' },
|
||
contact_phone: { type: STRING(20), comment: '联系电话' },
|
||
status: { type: TINYINT, allowNull: false, defaultValue: 1, comment: '状态:1启用 0禁用' },
|
||
type: { type: TINYINT, allowNull: false, defaultValue: 1, comment: '店铺类型:1平台店铺 2外部打单平台商家 3数据库模式(预留)' },
|
||
external_print_account_id: { type: BIGINT.UNSIGNED, comment: '来源外部打单账号ID(type=2 时有值)' },
|
||
external_data: { type: JSON, comment: '外部打单平台返回的商家原始结构' },
|
||
db_host: { type: STRING(255), comment: '数据库地址(type=3 数据库模式店铺使用,预留)' },
|
||
db_port: { type: INTEGER, comment: '数据库端口(type=3 数据库模式店铺使用,预留)' },
|
||
db_name: { type: STRING(100), comment: '数据库名(type=3 数据库模式店铺使用,预留)' },
|
||
db_username: { type: STRING(100), comment: '数据库账号(type=3 数据库模式店铺使用,预留)' },
|
||
db_password: { type: STRING(255), comment: '数据库密码(type=3 数据库模式店铺使用,预留,接口不回显)' },
|
||
auto_fetch_order: { type: TINYINT, allowNull: false, defaultValue: 0, comment: '是否自动拉取订单:1是 0否' },
|
||
auto_fetch_interval: { type: INTEGER, allowNull: false, defaultValue: 3, comment: '自动拉取订单间隔(分钟,最小 3)' },
|
||
last_order_sync_at: { type: DATE, comment: '最近一次拉取订单时间' },
|
||
last_order_sync_msg: { type: STRING(255), comment: '最近一次拉取订单结果/失败原因' },
|
||
extra: { type: JSON, comment: '扩展配置 JSON:授权信息、接口参数等' },
|
||
remark: { type: STRING(255), comment: '备注' },
|
||
created_at: { type: DATE, comment: '创建时间' },
|
||
updated_at: { type: DATE, comment: '更新时间' },
|
||
});
|
||
|
||
Shop.associate = () => {
|
||
app.model.Shop.belongsTo(app.model.Principal, { foreignKey: 'principal_id', as: 'principal' });
|
||
app.model.Shop.belongsTo(app.model.ExternalPrintAccount, { foreignKey: 'external_print_account_id', as: 'externalPrintAccount' });
|
||
app.model.Shop.hasMany(app.model.ShopProduct, { foreignKey: 'shop_id', as: 'shopProducts' });
|
||
app.model.Shop.hasMany(app.model.Order, { foreignKey: 'shop_id', as: 'orders' });
|
||
app.model.Shop.hasMany(app.model.OrderItem, { foreignKey: 'shop_id', as: 'orderItems' });
|
||
};
|
||
|
||
return Shop;
|
||
};
|