WMS_MAIN/app/model/order_stockout.js
liufumingren 948f600689 feat(inbox): 回调推送、出站文档、搜索增强、日志与推送状态完善
出站回调:
- 新增 warehouse_notify.json 文档(notify.ping/notify.reply),与 warehouse.json 互跳
- 回调体统一 { method, code, data },method 放 query,body 为业务数据
- MD5 签名: sign=MD5(appSecret+timestamp+bodyJson)
- 回调响应: {code:200} 成功,非200/非code:200 视为失败
- docs 页面支持模拟推送调试

搜索增强(searchStock/searchWarehouseStock):
- 直接查 stock_warehouse,不再依赖 stock_store
- 新增字段: gross_weight/box_spec/packing_requirements/prohibited_type
- 管理标识: is_sn_mgmt/is_shelf_life_mgmt/is_batch_mgmt
- 条码关联: wms_stock_barcodes
- 图片: wms_file_reference(business_type=stock)+wms_file,返回数组
- id 修正为 stock_warehouse.id

推送状态完善:
- handleApiMessage 增加 push_status 更新(2成功/3失败)
- 未配回调地址 → push_status=3 + error 原因
- 回调异常 catch 也更新 push_status=3 + 写日志
- 出站日志写入 wms_warehouse_log 表(WN-前缀)

消息列表:
- keyword 兼容 content/keyword,支持数组
- keyword 搜索 content/group_name/user_name 三列
- 支持 where+operator 结构化查询(parseWhereConditions)
- storeId=-1 查询无货主消息; storeId=0→IS NULL
- 日期范围: startDate/endDate

其他:
- silent 动作: AI 识别无需回复时跳过回执
- ai_enabled 灰度开关(群级)
- bindCode 文档修正
- store_name 改用 StoreWarehouse.store_remask
2026-08-08 00:17:38 +08:00

287 lines
7.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';
/**
* 出库单主表 Model。
*
* 对应数据库表 `wms_order_stockout`,存储奇门 stockout.create 接口下发的出库单信息。
*
* 业务类型枚举值:
* - JYCK:一般交易出库
* - HHCK:换货出库
* - BFCK:补发出库
* - QTCK:其他出库
* @param {import('egg').Application} app - Egg 应用实例
*/
module.exports = app => {
const { STRING, INTEGER, BIGINT, ENUM, TEXT, TINYINT, DATE, JSON: JSON_TYPE } = app.Sequelize;
const OrderStockout = app.model.define('wms_order_stockout', {
id: {
type: BIGINT(20).UNSIGNED,
primaryKey: true,
autoIncrement: true,
comment: '主键ID',
},
stockout_order_code: {
type: STRING(50),
allowNull: false,
comment: '出库单号(对应奇门 deliveryOrderCode)',
validate: {
notEmpty: true,
},
},
order_type: {
type: STRING(50),
allowNull: false,
comment: '业务类型(JYCK一般交易出库/HHCK换货出库/BFCK补发出库/QTCK其他出库等)',
validate: {
notEmpty: true,
},
},
total_order_lines: {
type: INTEGER(11),
allowNull: false,
defaultValue: 0,
comment: '单据总行数',
},
order_create_time: {
type: DATE,
allowNull: true,
comment: '订单创建时间(对应奇门 createTime)',
},
source_type: {
type: ENUM('WMS', 'API', 'QM'),
allowNull: false,
defaultValue: 'QM',
comment: '来源类型',
},
order_status: {
type: ENUM('CREATING', 'CREATED', 'PENDING', 'COMPLETED', 'CANCELLED'),
allowNull: false,
defaultValue: 'CREATED',
comment: '订单状态:CREATING=创建中, CREATED=已创建待审核, PENDING=已审核, COMPLETED=已完成, CANCELLED=已作废',
},
sync_status: {
type: ENUM('PENDING', 'SUCCESS', 'FAILED'),
allowNull: false,
defaultValue: 'PENDING',
comment: '同步状态',
},
sync_message: {
type: TEXT,
allowNull: true,
comment: '同步返回信息',
},
warehouse_id: {
type: BIGINT(20).UNSIGNED,
allowNull: false,
comment: '仓库ID',
},
store_id: {
type: BIGINT(20).UNSIGNED,
allowNull: false,
comment: '货主ID',
},
store_name: {
type: STRING(200),
allowNull: true,
comment: '货主名称快照',
},
warehouse_name: {
type: STRING(200),
allowNull: true,
comment: '仓库名称快照',
},
qimen_owner_code: {
type: STRING(100),
allowNull: true,
comment: '奇门货主code(对应 ownerCode)',
},
qimen_warehouse_code: {
type: STRING(100),
allowNull: true,
comment: '奇门仓库code(对应 warehouseCode)',
},
remark: {
type: STRING(500),
allowNull: true,
comment: '备注',
},
express_code: {
type: STRING(50),
allowNull: true,
comment: '快递公司编码(如 SF、STO,用于出站回传 logisticsCode)',
},
express_name: {
type: STRING(200),
allowNull: true,
comment: '快递公司名称(由 express_code 自动解析,如 顺丰、申通)',
},
waybill_code: {
type: STRING(50),
allowNull: true,
comment: '运单号',
},
waybill_codes: {
type: JSON_TYPE,
allowNull: true,
comment: '运单号列表(JSON 数组,支持多包裹场景)',
},
express_codes: {
type: JSON_TYPE,
allowNull: true,
comment: '@deprecated 运单号列表,请使用 waybill_codes',
},
extend_props: {
type: JSON_TYPE,
allowNull: true,
comment: '扩展属性',
},
is_enabled: {
type: TINYINT(1),
allowNull: false,
defaultValue: 1,
comment: '是否启用',
},
created_at: {
type: DATE,
allowNull: false,
comment: '创建时间',
},
updated_at: {
type: DATE,
allowNull: false,
comment: '更新时间',
},
deleted_at: {
type: DATE,
allowNull: true,
comment: '软删除时间',
},
}, {
tableName: 'wms_order_stockout',
comment: '出库单主表',
timestamps: false,
indexes: [
{
name: 'uk_stockout_order_code',
unique: true,
fields: [ 'stockout_order_code', 'warehouse_id', 'store_id' ],
},
{
name: 'idx_order_type',
fields: [ 'order_type' ],
},
{
name: 'idx_order_status',
fields: [ 'order_status' ],
},
{
name: 'idx_sync_status',
fields: [ 'sync_status' ],
},
{
name: 'idx_source_type',
fields: [ 'source_type' ],
},
{
name: 'idx_warehouse_store',
fields: [ 'warehouse_id', 'store_id' ],
},
{
name: 'idx_order_create_time',
fields: [ 'order_create_time' ],
},
{
name: 'idx_is_enabled',
fields: [ 'is_enabled' ],
},
{
name: 'idx_deleted_at',
fields: [ 'deleted_at' ],
},
],
});
/**
* 关联关系定义。
* - 关联货主 / 仓库(均通过 Store 表)
* - 关联出库明细表
*/
OrderStockout.associate = function() {
const { OrderStockout, Store, OrderStockoutItems } = app.model;
// 关联仓库
OrderStockout.belongsTo(Store, {
foreignKey: 'warehouse_id',
as: 'warehouse',
});
// 关联货主
OrderStockout.belongsTo(Store, {
foreignKey: 'store_id',
as: 'store',
});
// 关联出库明细
OrderStockout.hasMany(OrderStockoutItems, {
foreignKey: 'order_id',
as: 'items',
});
};
// ---------- 状态机辅助方法 ----------
/** 判断订单是否处于"已创建"状态 */
OrderStockout.prototype.isCreated = function() {
return this.order_status === 'CREATED';
};
/** 判断订单是否处于"已审核"状态 */
OrderStockout.prototype.isPending = function() {
return this.order_status === 'PENDING';
};
/** 判断订单是否已完成 */
OrderStockout.prototype.isCompleted = function() {
return this.order_status === 'COMPLETED';
};
/** 判断订单是否已作废 */
OrderStockout.prototype.isCancelled = function() {
return this.order_status === 'CANCELLED';
};
/** 当前订单是否允许审核 */
OrderStockout.prototype.canConfirm = function() {
return [ 'CREATED', 'PENDING' ].includes(this.order_status);
};
/** 当前订单是否允许取消 */
OrderStockout.prototype.canCancel = function() {
return [ 'CREATED', 'PENDING' ].includes(this.order_status);
};
/** 当前订单是否允许完成 */
OrderStockout.prototype.canComplete = function() {
return [ 'PENDING' ].includes(this.order_status);
};
/** 同步是否成功 */
OrderStockout.prototype.isSyncSuccess = function() {
return this.sync_status === 'SUCCESS';
};
/** 同步是否失败 */
OrderStockout.prototype.isSyncFailed = function() {
return this.sync_status === 'FAILED';
};
/** 是否启用(未软删除) */
OrderStockout.prototype.isEnabled = function() {
return this.is_enabled === 1 && !this.deleted_at;
};
return OrderStockout;
};