oms/backend/app/model/inboundOrder.js
liufumingren 9774ee1414 feat(stock): 出入库单/记录增加货主并按货主隔离,创建人显示员工名称
- 迁移:inbound_orders / outbound_orders 增加 subsidiary_id 与索引,按仓库回填
- 单据货主由仓库决定:创建写入、改仓库同步,接口不接受直写 subsidiary_id
- 入库单/出库单列表返回 subsidiary_name 并新增货主筛选;详情/编辑/删除/审核/
  推送/完成/取消/恢复/作废/驳回与明细接口统一加货主越界 403
- 出入库记录按仓库归属货主:列表与导出收窄、返回 subsidiary_id/subsidiary_name、
  新增货主列与筛选
- 导出:入库单/出库单/出入库记录新增货主列并按所在公司权限收窄
- 新增 resolveAccountNameMap:列表/详情返回 creator_name/auditor_name/voider_name,
  创建人展示员工名称(principal_users.name),不再回退成邮箱账号
- 前端:三个列表新增货主列与筛选,创建人/作废人展示改为员工名称

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-05 15:13:22 +08:00

67 lines
4.4 KiB
JavaScript
Raw Permalink 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';
/**
* 入库单模型,对应 inbound_orders 表(单据头)
* @param {Egg.Application} app egg application
* @return {object} inboundOrder model
*/
module.exports = app => {
const { BIGINT, STRING, TINYINT, DECIMAL, INTEGER, DATE } = app.Sequelize;
const InboundOrder = app.model.define('inbound_order', {
id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' },
bill_no: { type: STRING(50), allowNull: false, comment: '入库单号' },
principal_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '所属主体ID' },
subsidiary_id: { type: BIGINT.UNSIGNED, comment: '所属货主(下属公司ID),跟随仓库' },
shop_id: { type: BIGINT.UNSIGNED, comment: '来源店铺/仓库ID' },
inbound_type: {
type: STRING(20),
allowNull: false,
defaultValue: 'CGRK',
comment: 'WMS 入库单类型:B2BRK B2B入库 / SCRK 生产入库 / LYRK 领用入库 / CCRK 残次品入库 / CGRK 采购入库 / DBRK 调拨入库 / QTRK 其他入库',
},
status: { type: TINYINT, allowNull: false, defaultValue: 1, comment: '状态:1待入库 2已入库 3已取消' },
supplier: { type: STRING(255), comment: '供应商名称' },
supplier_code: { type: STRING(50), comment: '供应商编码' },
operator: { type: STRING(50), comment: '操作人名称' },
operator_code: { type: STRING(50), comment: '操作员编码' },
operate_time: { type: DATE, comment: '操作时间' },
purchase_order_code: { type: STRING(50), comment: '采购单号(orderType=CGRK 时使用)' },
expect_start_time: { type: DATE, comment: '预期到货开始时间' },
expect_end_time: { type: DATE, comment: '最迟预期到货时间' },
logistics_code: { type: STRING(50), comment: '物流公司编码(SF/YTO/ZTO 等)' },
logistics_name: { type: STRING(200), comment: '物流公司名称' },
express_code: { type: STRING(50), comment: '运单号' },
sender_info: { type: JSON, allowNull: true, comment: '发件人信息(WMS senderInfo)' },
receiver_info: { type: JSON, allowNull: true, comment: '收件人信息(WMS receiverInfo)' },
extend_props: { type: JSON, allowNull: true, comment: '扩展属性(WMS extendProps):{ key: value }' },
created_by: { type: BIGINT.UNSIGNED, comment: '创建人ID(关联 users)' },
warehouse_id: { type: BIGINT.UNSIGNED, comment: '仓库ID(关联 warehouses)' },
item_total: { type: DECIMAL(12, 3), allowNull: false, defaultValue: 0, comment: '商品总数(明细数量合计)' },
item_kind: { type: INTEGER.UNSIGNED, allowNull: false, defaultValue: 0, comment: '商品种类数(不重复商品数)' },
total_amount: { type: DECIMAL(12, 2), allowNull: false, defaultValue: 0, comment: '单据总金额' },
remark: { type: STRING(255), comment: '备注' },
audit_by: { type: BIGINT.UNSIGNED, allowNull: true, comment: '审核人ID(关联 users)' },
audit_time: { type: DATE, allowNull: true, comment: '审核时间' },
pushed_at: { type: DATE, allowNull: true, comment: 'WMS 推送时间' },
wms_push_result: { type: JSON, allowNull: true, comment: 'WMS 推送结果(外部单号/返回码/消息/原始报文)' },
void_at: { type: DATE, allowNull: true, comment: '作废时间(状态 5=已作废)' },
void_by: { type: BIGINT.UNSIGNED, allowNull: true, comment: '作废人ID(关联 users)' },
void_reason: { type: STRING(255), allowNull: true, comment: '作废原因' },
created_at: { type: DATE, comment: '创建时间' },
updated_at: { type: DATE, comment: '更新时间' },
});
InboundOrder.associate = () => {
app.model.InboundOrder.belongsTo(app.model.Principal, { foreignKey: 'principal_id', as: 'principal' });
app.model.InboundOrder.belongsTo(app.model.PrincipalSubsidiary, { foreignKey: 'subsidiary_id', as: 'subsidiary' });
app.model.InboundOrder.belongsTo(app.model.Shop, { foreignKey: 'shop_id', as: 'shop' });
app.model.InboundOrder.belongsTo(app.model.Warehouse, { foreignKey: 'warehouse_id', as: 'warehouse' });
app.model.InboundOrder.belongsTo(app.model.User, { foreignKey: 'created_by', as: 'creator' });
app.model.InboundOrder.belongsTo(app.model.User, { foreignKey: 'audit_by', as: 'auditor' });
app.model.InboundOrder.belongsTo(app.model.User, { foreignKey: 'void_by', as: 'voider' });
};
return InboundOrder;
};