WMS_MAIN/app/model/stock_barcode.js
2026-04-09 01:36:49 +08:00

87 lines
1.9 KiB
JavaScript

'use strict';
module.exports = app => {
const { STRING, BIGINT, DATE } = app.Sequelize;
const StockBarcode = app.model.define('stock_barcodes', {
id: {
type: BIGINT(20),
primaryKey: true,
autoIncrement: true,
comment: '主键ID',
},
stock_id: {
type: BIGINT(20),
allowNull: false,
comment: '主表ID',
references: {
model: 'wms_stock_warehouse',
key: 'id',
},
onDelete: 'CASCADE',
onUpdate: 'NO ACTION',
},
warehouse_id: {
type: BIGINT.UNSIGNED,
allowNull: false,
comment: '仓库id',
},
barcode: {
type: STRING(100),
allowNull: false,
comment: '条码',
charset: 'utf8mb4',
collate: 'utf8mb4_unicode_ci',
},
description: {
type: STRING(255),
allowNull: true,
comment: '条码描述',
charset: 'utf8mb4',
collate: 'utf8mb4_unicode_ci',
},
create_time: {
type: DATE,
allowNull: true,
defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'),
comment: '创建时间',
},
}, {
tableName: 'wms_stock_barcodes',
timestamps: false, // 不使用Sequelize的自动时间戳
charset: 'utf8mb4',
collate: 'utf8mb4_unicode_ci',
paranoid: false,
// 明确指定不使用 deletedAt 字段
deletedAt: false,
comment: 'WMS商品条码表',
indexes: [
{
name: 'idx_stock_id',
fields: [ 'stock_id' ],
},
{
name: 'uk_barcode',
unique: true,
fields: [ 'barcode' ],
},
],
});
// 定义关联关系
StockBarcode.associate = function() {
const { StockWarehouse } = app.model;
console.log('StockWarehouse', StockWarehouse, StockBarcode);
StockBarcode.belongsTo(
app.model.StockWarehouse,
{
foreignKey: 'stock_id',
targetKey: 'id',
as: 'stock',
}
);
};
return StockBarcode;
};