oms/backend/app/model/warehouse.js
liufumingren 839b81f661 feat: 商品与外部仓库关联所属货主(下属公司)
- products、warehouses 新增 subsidiary_id(下属公司),创建/更新必填并校验归属当前主体
- 商品批量导入新增「所属货主」列,按下属公司名称匹配,缺失时报错
- 商品、外部仓库列表与导出新增所属货主列、筛选与下拉控件
- 仓库下拉与详情接口返回 subsidiary_id / subsidiary_name

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-05 00:50:27 +08:00

39 lines
1.8 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';
/**
* 仓库模型,对应 warehouses 表
* 仅保存仓库基础信息;接口配置拆分到 warehouse_apis(一个仓库可有多条接口配置)
* @param {Egg.Application} app egg application
* @return {object} warehouse model
*/
module.exports = app => {
const { BIGINT, STRING, TINYINT, DATE } = app.Sequelize;
const Warehouse = app.model.define('warehouse', {
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)' },
code: { type: STRING(50), allowNull: false, comment: '仓库编码(系统自动生成,WH 前缀)' },
name: { type: STRING(100), allowNull: false, comment: '仓库名称' },
type: { type: STRING(50), comment: '仓库类型:wms/erp/other' },
status: { type: TINYINT, allowNull: false, defaultValue: 1, comment: '状态:1启用 0禁用' },
remark: { type: STRING(255), comment: '备注' },
deleted_at: { type: DATE, comment: '软删除时间' },
}, {
paranoid: true,
deletedAt: 'deleted_at',
});
Warehouse.associate = () => {
app.model.Warehouse.belongsTo(app.model.Principal, { foreignKey: 'principal_id', as: 'principal' });
// 所属公司(下属公司):新建/编辑仓库时必选
app.model.Warehouse.belongsTo(app.model.PrincipalSubsidiary, { foreignKey: 'subsidiary_id', as: 'subsidiary' });
// 一个仓库可配置多个接口
app.model.Warehouse.hasMany(app.model.WarehouseApi, { foreignKey: 'warehouse_id', as: 'apis' });
// 仓库-商品关联:记录商品是否已推送到该仓库
app.model.Warehouse.hasMany(app.model.WarehouseProduct, { foreignKey: 'warehouse_id', as: 'warehouseProducts' });
};
return Warehouse;
};