oms/backend/app/model/shop.js
liufumingren 74ddeca3c0 feat(shop): 店铺支持设置默认发货仓库,拉单与未审核订单自动带仓库
- shops 新增 default_warehouse_id(迁移 + 模型 + 契约),仓库须存在、启用且属于店铺货主

- 新增 PUT /api/shops/:id/default-warehouse 单独维护该字段,外部打单平台店铺的货主权限也可配置

- 新增 shopWarehouse 服务:保存后把该店铺待审核订单中仓库为空或是旧默认值的订单回填为新仓库(手工改过的不覆盖)

- 打单平台与数据库店铺拉单落待审核时自动带上默认仓库(含 warehouse_code 快照);一键拉单店铺查询补 default_warehouse_id

- 前端:店铺列表新增「默认仓库」列与配置弹窗,新增/编辑表单增加默认发货仓库下拉(按货主过滤),详情面板展示

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-06 22:23:23 +08:00

52 lines
3.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'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' },
subsidiary_id: { type: BIGINT.UNSIGNED, comment: '所属货主(下属公司ID)' },
default_warehouse_id: { type: BIGINT.UNSIGNED, 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.PrincipalSubsidiary, { foreignKey: 'subsidiary_id', as: 'subsidiary' });
app.model.Shop.belongsTo(app.model.ExternalPrintAccount, { foreignKey: 'external_print_account_id', as: 'externalPrintAccount' });
app.model.Shop.belongsTo(app.model.Warehouse, { foreignKey: 'default_warehouse_id', as: 'defaultWarehouse' });
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;
};