oms/backend/app/model/warehouse.js
liufumingren cbd16752a5 feat(backend): 商品、店铺、组合商品、仓库与库存模块
- 商品/商品图片、店铺、店铺商品、组合商品及明细
- 仓库、仓库商品(WMS itemId 映射)、仓库接口配置与字段定义(warehouseApi/warehouseApiField)
- 库存:stock_items、product_stocks(ZC/CC 双维度)与库存重算工具(utils/recalcStock.js)
- 库存单据与对接日志:stock orders、api_outbound_logs
- 相关迁移:shops/shop_products/stock_orders/warehouses/warehouse_apis/warehouse_products/product_stocks/files-images 等表与字段
2026-09-13 02:23:39 +08:00

36 lines
1.6 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' },
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.hasMany(app.model.WarehouseApi, { foreignKey: 'warehouse_id', as: 'apis' });
// 仓库-商品关联:记录商品是否已推送到该仓库
app.model.Warehouse.hasMany(app.model.WarehouseProduct, { foreignKey: 'warehouse_id', as: 'warehouseProducts' });
};
return Warehouse;
};