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

47 lines
3.0 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';
/**
* 出入库明细模型,对应 stock_items 表(出入库单据的共用副表)
* bill_type 区分单据类型(1入库 2出库),bill_id 关联对应单据头
* @param {Egg.Application} app egg application
* @return {object} stockItem model
*/
module.exports = app => {
const { BIGINT, STRING, TINYINT, DECIMAL, DATE } = app.Sequelize;
const StockItem = app.model.define('stock_item', {
id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' },
principal_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '所属主体ID' },
bill_type: { type: TINYINT, allowNull: false, comment: '单据类型:1入库 2出库' },
bill_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '关联单据头ID' },
shop_id: { type: BIGINT.UNSIGNED, comment: '店铺/仓库ID(冗余单据的店铺)' },
product_id: { type: BIGINT.UNSIGNED, comment: '系统商品ID,为空表示仅登记名称' },
combo_product_id: { type: BIGINT.UNSIGNED, comment: '组合商品ID' },
shop_product_id: { type: BIGINT.UNSIGNED, comment: '店铺商品ID' },
name: { type: STRING(255), comment: '商品名称(快照)' },
code: { type: STRING(100), comment: '商品编码(快照)' },
inventory_type: { type: STRING(10), allowNull: false, defaultValue: 'ZP', comment: '库存类型:ZP=正品 CC=残次(对齐 WMS 入库单行级 inventoryType)' },
spec: { type: STRING(255), comment: '规格(快照)' },
unit: { type: STRING(20), comment: '单位' },
quantity: { type: DECIMAL(12, 3), allowNull: false, defaultValue: 0, comment: '数量' },
plan_in_qty: { type: DECIMAL(12, 3), allowNull: false, defaultValue: 0, comment: '应入数量(入库明细,默认取明细数量)' },
actual_in_qty: { type: DECIMAL(12, 3), allowNull: false, defaultValue: 0, comment: '已入数量(入库明细,WMS 收货确认回推)' },
plan_out_qty: { type: DECIMAL(12, 3), allowNull: false, defaultValue: 0, comment: '应出数量(出库明细,默认取明细数量)' },
actual_out_qty: { type: DECIMAL(12, 3), allowNull: false, defaultValue: 0, comment: '已出数量(出库明细,WMS 发货回推)' },
price: { type: DECIMAL(12, 2), comment: '单价' },
total_amount: { type: DECIMAL(12, 2), allowNull: false, defaultValue: 0, comment: '明细金额' },
remark: { type: STRING(255), comment: '备注' },
created_at: { type: DATE, comment: '创建时间' },
updated_at: { type: DATE, comment: '更新时间' },
});
StockItem.associate = () => {
app.model.StockItem.belongsTo(app.model.Principal, { foreignKey: 'principal_id', as: 'principal' });
app.model.StockItem.belongsTo(app.model.Product, { foreignKey: 'product_id', as: 'product' });
app.model.StockItem.belongsTo(app.model.ComboProduct, { foreignKey: 'combo_product_id', as: 'comboProduct' });
app.model.StockItem.belongsTo(app.model.ShopProduct, { foreignKey: 'shop_product_id', as: 'shopProduct' });
};
return StockItem;
};