oms/backend/app/model/order.js
liufumingren ec81f8b3cd feat(backend): 入库单/出库单全流程与 WMS 对接
- 入库单、出库单控制器与模型(状态流转、审核、驳回换号、作废、删除约束)
- 明细共用 stock_items:应/已数量、行级库存类型 ZP/CC、明细锁定
- lib/wms:单据类型常量(orderTypes)、奇门/openapi 客户端(qimenClient)、签名(sign)
- 库存联动:utils/stock.js、utils/completeInbound.js(入库完成加库存,幂等)
- 驳回换号:utils/rejectBillNo.js;旧 orders 模块同步调整
- 相关迁移:入库单 WMS 字段/审核/推送结果、明细计划与实际数量、单据类型落 WMS 编码、出库库存扣减标记等
2026-09-13 02:23:44 +08:00

42 lines
2.2 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';
/**
* 订单模型,对应 orders 表
* 含本系统主状态 status、外部 WMS 状态 wms_status、上交状态 submit_status
* @param {Egg.Application} app egg application
* @return {object} order model
*/
module.exports = app => {
const { BIGINT, STRING, TINYINT, DECIMAL, JSON, DATE } = app.Sequelize;
const Order = app.model.define('order', {
id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' },
order_no: { type: STRING(50), allowNull: false, comment: '业务订单号' },
principal_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '所属主体ID' },
shop_id: { type: BIGINT.UNSIGNED, comment: '所属店铺ID,为空表示未关联店铺' },
order_type: { type: TINYINT, allowNull: false, defaultValue: 1, comment: '订单类型' },
status: { type: TINYINT, allowNull: false, defaultValue: 1, comment: '主状态:1待处理 2处理中 3已完成 4已取消' },
wms_status: { type: STRING(50), comment: '外部WMS状态' },
wms_order_no: { type: STRING(50), comment: '外部WMS单号' },
wms_synced_at: { type: DATE, comment: '最近一次WMS同步时间' },
submit_status: { type: TINYINT, allowNull: false, defaultValue: 0, comment: '上交状态:0未上交 1上交中 2已上交 3上交失败' },
submit_order_no: { type: STRING(50), comment: '上交后返回的单号' },
submit_at: { type: DATE, comment: '上交时间' },
submit_msg: { type: STRING(255), comment: '上交结果/失败原因' },
total_amount: { type: DECIMAL(12, 2), allowNull: false, defaultValue: 0, comment: '订单金额' },
pay_amount: { type: DECIMAL(12, 2), comment: '实付金额' },
receiver: { type: JSON, comment: '收货人信息 JSON:{ name, phone, address }' },
remark: { type: STRING(255), comment: '备注' },
created_at: { type: DATE, comment: '创建时间' },
updated_at: { type: DATE, comment: '更新时间' },
});
Order.associate = () => {
app.model.Order.belongsTo(app.model.Principal, { foreignKey: 'principal_id', as: 'principal' });
app.model.Order.belongsTo(app.model.Shop, { foreignKey: 'shop_id', as: 'shop' });
app.model.Order.hasMany(app.model.OrderItem, { foreignKey: 'order_id', as: 'items' });
};
return Order;
};