WMS_MAIN/app/model/stock_check.js
liufumingren 190d3cf9e5 feat(stock.check): 盘点模块功能扩展并同步接口文档(0.3.227)
- 盘点明细/记录支持未知商品(stock_id 可空)与库位范围,模式/状态口径修正
- 新增静态盘点任务、公告相关模型与迁移,stock_warehouse 增加预警数量
- methods/system.json 同步盘点接口文档;headers platform 微信端取值 wx 修正为 miniprogram
2026-10-02 15:43:49 +08:00

136 lines
3.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';
/**
* 库存盘点主表模型。
* @param {import('egg').Application} app Egg 应用实例。
* @return {import('sequelize').ModelCtor<import('sequelize').Model>} Sequelize 模型。
*/
module.exports = app => {
const { BIGINT, STRING, INTEGER, DATE, JSON: JSON_TYPE } = app.Sequelize;
const StockCheck = app.model.define('wms_stock_check', {
id: {
type: BIGINT(20).UNSIGNED,
primaryKey: true,
autoIncrement: true,
comment: '主键',
},
warehouse_id: {
type: BIGINT(20).UNSIGNED,
allowNull: false,
comment: '仓库ID(数据隔离维度)',
},
check_no: {
type: STRING(50),
allowNull: false,
comment: '盘点单号,唯一,生成规则:PD+YYYYMMDD+6位序号',
},
title: {
type: STRING(200),
allowNull: true,
comment: '盘点名称/主题,非必填',
},
type: {
type: STRING(20),
allowNull: false,
defaultValue: 'all',
comment: '盘点范围类型:all=全盘,store=按货主,goods=按商品,location=按库位',
},
mode: {
type: STRING(20),
allowNull: false,
defaultValue: 'open',
comment: '盘点方式:open=明盘(可见账面数量),blind=盲盘(不可见账面数量)',
},
store_id: {
type: BIGINT(20).UNSIGNED,
allowNull: true,
comment: '货主ID,按货主盘点时必填(type=store)',
},
scope_snapshot: {
type: JSON_TYPE,
allowNull: true,
comment: '盘点范围条件快照(JSON),如商品ID列表/库位ID列表,供盘点对比与追溯',
},
status: {
type: STRING(20),
allowNull: false,
defaultValue: 'pending',
comment: '盘点状态:pending=待盘点,in_progress=盘点中,checked=已盘待确认,confirmed=已确认,completed=已完成,cancelled=已取消',
},
detail_status: {
type: STRING(30),
allowNull: false,
defaultValue: 'none_checked',
comment: '明细盘点进度:none_checked=未盘,partial_checked=部分已盘,all_checked=全部已盘',
},
start_time: {
type: DATE,
allowNull: true,
comment: '盘点开始时间(第一个盘点明细写入的时间)',
},
end_time: {
type: DATE,
allowNull: true,
comment: '盘点结束时间(完成盘点的时间)',
},
creator_id: {
type: BIGINT(20).UNSIGNED,
allowNull: false,
comment: '创建人账户ID',
},
creator_name: {
type: STRING(50),
allowNull: true,
comment: '创建人名称快照',
},
total_items: {
type: INTEGER(11),
allowNull: false,
defaultValue: 0,
comment: '明细行数(盘点任务总行数)',
},
checked_items: {
type: INTEGER(11),
allowNull: false,
defaultValue: 0,
comment: '已盘行数',
},
diff_items: {
type: INTEGER(11),
allowNull: false,
defaultValue: 0,
comment: '差异行数(账面与实盘不一致的行数)',
},
remark: {
type: STRING(500),
allowNull: true,
comment: '备注',
},
}, {
tableName: 'wms_stock_check',
comment: '库存盘点主表',
timestamps: true,
createdAt: 'created_at',
updatedAt: 'updated_at',
paranoid: false,
indexes: [
{ name: 'uk_check_no', unique: true, fields: [ 'check_no' ] },
{ name: 'idx_warehouse_status', fields: [ 'warehouse_id', 'status' ] },
{ name: 'idx_store_id', fields: [ 'store_id' ] },
{ name: 'idx_creator_id', fields: [ 'creator_id' ] },
],
});
StockCheck.associate = function() {
const { StockCheckDetail } = app.model;
// 一个盘点单对应多条盘点明细
StockCheck.hasMany(StockCheckDetail, {
foreignKey: 'check_id',
as: 'details',
});
};
return StockCheck;
};