oms/backend/app/model/warehouseProduct.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

32 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';
/**
* 仓库-商品关联模型,对应 warehouse_products 表
* 只做极简关联:记录某个商品是否已推送到某个仓库(pushed),不存商品快照
* @param {Egg.Application} app egg application
* @return {object} warehouseProduct model
*/
module.exports = app => {
const { BIGINT, TINYINT, DATE } = app.Sequelize;
const WarehouseProduct = app.model.define('warehouse_product', {
id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' },
principal_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '所属主体ID' },
warehouse_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '仓库ID' },
product_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '商品ID' },
pushed: { type: TINYINT, allowNull: false, defaultValue: 0, comment: '是否已推送到仓库:1是 0否' },
pushed_at: { type: DATE, comment: '最近一次推送时间' },
wms_item_id: { type: BIGINT.UNSIGNED, allowNull: true, comment: 'WMS 内部商品ID(singleitem.synchronize 返回),用于按 itemId 查询库存' },
created_at: { type: DATE, comment: '创建时间' },
updated_at: { type: DATE, comment: '更新时间' },
});
WarehouseProduct.associate = () => {
app.model.WarehouseProduct.belongsTo(app.model.Warehouse, { foreignKey: 'warehouse_id', as: 'warehouse' });
app.model.WarehouseProduct.belongsTo(app.model.Product, { foreignKey: 'product_id', as: 'product' });
app.model.WarehouseProduct.belongsTo(app.model.Principal, { foreignKey: 'principal_id', as: 'principal' });
};
return WarehouseProduct;
};