WMS_MAIN/app/model/order_delivery.js
liufumingren 19c3fe09a7 refactor(weight): 重量字段统一为 INTEGER(g),取代 DECIMAL(kg)
- 8 个 model 重量字段类型 DECIMAL→INTEGER,注释 kg→g

- order_express 称重校验改为正整数(g)

- delivery_order 手动单查 StockStore + warehouse 称重毛重

- openapi.json 毛重/净重描述 kg→g

- 迁移: 20260725120000-unify-weight-fields-to-int-g

- 脚本: update-stock-warehouse-weight.cjs
2026-07-27 03:46:07 +08:00

578 lines
13 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';
module.exports = app => {
const { Sequelize, model } = app;
const { STRING, BIGINT, DECIMAL, TEXT, ENUM, DATE, INTEGER, CHAR, SMALLINT, JSON } = Sequelize;
// 状态机枚举定义
const StatusEnum = {
STATUS: [ 'pedding', 'created', 'cancel', 'error', 'finished' ],
SYNC_STATUS: [ 'padding', 'fin', 'error' ],
POST_STATUS: [ 'padding', 'fin', 'timeout', 'error', 'none' ],
STORAGE_STATUS: [ 'padding', 'fin', 'error', 'none' ],
PICK_STATUS: [ 'padding', 'fin', 'error', 'none' ],
PACK_STATUS: [ 'none', 'padding', 'fin', 'error' ],
SENDED_STATUS: [ 'none', 'padding', 'fin', 'error' ],
INSPECTION_STATUS: [ 'none', 'padding', 'running', 'fin', 'error' ],
PRINT_STATUS: [ 'none', 'padding', 'fin', 'error' ],
PRINT_LOCK_STATUS: [ 'none', 'warehouse' ],
CLAIM_STATUS: [ 'none', 'padding', 'fin', 'error' ],
OUTBOUND_STATUS: [ 'none', 'padding', 'fin', 'timeout', 'error' ],
LOCK_STATUS: [ 'none', 'warehouse', 'store' ],
INTERCEPT_STATUS: [
'none', 'requesting', 'requested', 'intercepting',
'intercepted_in_transit', 'intercepted_at_warehouse',
'returning', 'returned', 'delivered_by_mistake',
'timeout', 'cancelled', 'failed', 'exception',
],
URGENCY: [ 'Y', 'N' ],
INVOICE: [ 'Y', 'N' ],
};
// 基础模型定义
const baseModel = {
id: {
type: BIGINT(20).UNSIGNED,
primaryKey: true,
autoIncrement: true,
},
delivery_order_code: {
type: STRING(50),
allowNull: true,
comment: '发货单号',
},
pre_delivery_order_code: {
type: STRING(50),
allowNull: true,
comment: '预发货单号',
},
pre_delivery_order_id: {
type: STRING(50),
allowNull: true,
comment: '预发货单ID',
},
order_type: {
type: STRING(50),
allowNull: true,
comment: '订单类型',
},
warehouse_code: {
type: STRING(50),
allowNull: true,
comment: '仓库编码',
},
order_flag: {
type: TEXT('long'),
allowNull: true,
comment: '订单标记',
},
extend_props: {
type: JSON,
allowNull: true,
comment: '订单扩展属性',
},
source_platform_code: {
type: STRING(50),
allowNull: true,
comment: '来源平台编码',
},
source_platform_name: {
type: STRING(200),
allowNull: true,
comment: '来源平台名称',
},
create_channel: {
type: STRING(20),
allowNull: false,
defaultValue: 'MANUAL',
comment: '创建来源渠道',
},
source_order_codes: {
type: TEXT,
allowNull: true,
comment: '来源订单号集合',
},
sys_platform_code: {
type: STRING(50),
allowNull: true,
comment: '系统平台编码',
},
sys_platform_name: {
type: STRING(200),
allowNull: true,
comment: '系统平台名称',
},
create_at: {
type: DATE,
allowNull: true,
comment: '创建时间',
},
delete_at: {
type: DATE,
allowNull: true,
comment: '删除时间',
},
updated_at: {
type: DATE,
allowNull: true,
comment: '更新时间',
},
place_order_time: {
type: DATE,
allowNull: true,
comment: '店铺创建订单时间',
},
pay_time: {
type: DATE,
allowNull: true,
comment: '支付时间',
},
pay_no: {
type: TEXT,
allowNull: true,
comment: '支付单号',
},
service_code: {
type: STRING(50),
allowNull: true,
comment: '集包服务编码',
},
operator_name: {
type: STRING(50),
allowNull: true,
comment: 'ERP审核人',
},
operate_time: {
type: DATE,
allowNull: true,
comment: 'ERP审核时间',
},
delivery_time: {
type: DATE,
allowNull: true,
comment: '发货时间',
},
shop_nick: {
type: STRING(200),
allowNull: true,
comment: '店铺名称',
},
buyer_message: {
type: STRING(500),
allowNull: true,
comment: '买家留言',
},
seller_message: {
type: STRING(500),
allowNull: true,
comment: '卖家留言',
},
remark: {
type: STRING(500),
allowNull: true,
comment: '备注',
},
seller_nick: {
type: STRING(200),
allowNull: true,
comment: '卖家名称',
},
buyer_nick: {
type: STRING(200),
allowNull: true,
comment: '买家名称',
},
total_amount: {
type: DECIMAL(18, 2),
allowNull: true,
comment: '订单总金额',
},
item_amount: {
type: DECIMAL(18, 2),
allowNull: true,
comment: '商品总金额',
},
discount_amount: {
type: DECIMAL(18, 2),
allowNull: true,
comment: '订单折扣金额',
},
freight: {
type: DECIMAL(18, 2),
allowNull: true,
comment: '快递费用',
},
ar_amount: {
type: DECIMAL(18, 2),
allowNull: true,
comment: '应收金额',
},
got_amount: {
type: DECIMAL(18, 2),
allowNull: true,
comment: '已收金额',
},
service_fee: {
type: DECIMAL(18, 2),
allowNull: true,
comment: 'COD服务费',
},
logistics_code: {
type: STRING(50),
allowNull: true,
comment: '物流公司编码',
},
logistics_name: {
type: STRING(200),
allowNull: true,
comment: '物流公司名称',
},
sys_logistics_code: {
type: STRING(50),
allowNull: true,
comment: '系统物流公司编码',
},
sys_logistics_name: {
type: STRING(200),
allowNull: true,
comment: '系统物流公司名称',
},
basket_number: {
type: STRING(50),
allowNull: true,
comment: '筐号',
},
express_code: {
type: STRING(50),
allowNull: true,
comment: '面单号前置',
},
logistics_area_code: {
type: STRING(50),
allowNull: true,
comment: '快递区域编码, 大头笔信息',
},
delivery_type: {
type: STRING(255),
allowNull: true,
comment: '发货服务类型',
},
weight_type: {
type: INTEGER(11),
allowNull: false,
defaultValue: 0,
comment: '重量类型:0常规、1轻货、2重货、3冷链',
},
is_urgency: {
type: ENUM(...StatusEnum.URGENCY),
allowNull: true,
defaultValue: 'N',
comment: '是否紧急',
},
invoice_flag: {
type: ENUM(...StatusEnum.INVOICE),
allowNull: true,
defaultValue: 'N',
comment: '是否需要发票',
},
status: {
type: ENUM(...StatusEnum.STATUS),
allowNull: true,
defaultValue: 'created',
comment: '订单状态',
},
name: {
type: TEXT,
allowNull: true,
comment: '收件人姓名',
},
zip_code: {
type: STRING(50),
allowNull: true,
comment: '收件人邮编',
},
tel: {
type: TEXT,
allowNull: true,
comment: '收件人电话',
},
mobile: {
type: TEXT,
allowNull: true,
comment: '收件人移动电话',
},
email: {
type: TEXT,
allowNull: true,
comment: '收件人邮箱',
},
country_code: {
type: STRING(255),
allowNull: true,
comment: '国家编码',
},
province: {
type: STRING(255),
allowNull: true,
comment: '省份',
},
city: {
type: STRING(255),
allowNull: true,
comment: '城市',
},
area: {
type: STRING(255),
allowNull: true,
comment: '区',
},
town: {
type: STRING(255),
allowNull: true,
comment: '镇',
},
detail_address: {
type: TEXT,
allowNull: true,
comment: '详细地址',
},
id_type: {
type: STRING(255),
allowNull: true,
comment: '证件类型',
},
id_number: {
type: INTEGER(11),
allowNull: true,
comment: '证件号码',
},
oaid: {
type: TEXT,
allowNull: true,
comment: 'OAID',
},
sync_status: {
type: ENUM(...StatusEnum.SYNC_STATUS),
allowNull: true,
defaultValue: 'padding',
comment: '同步状态',
},
store_id: {
type: BIGINT(20).UNSIGNED,
allowNull: true,
comment: '货主ID',
},
warehouse_id: {
type: BIGINT(20).UNSIGNED,
allowNull: true,
comment: '仓库ID',
},
from_key: {
type: INTEGER(11),
allowNull: true,
comment: '来源键',
},
items: {
type: TEXT,
allowNull: true,
comment: '商品JSON字符串',
},
items_count: {
type: SMALLINT(5).UNSIGNED,
allowNull: false,
defaultValue: 0,
comment: '商品种类数',
},
items_total: {
type: INTEGER(10).UNSIGNED,
allowNull: false,
defaultValue: 0,
comment: '商品总数',
},
items_weight: {
type: INTEGER(11),
allowNull: false,
defaultValue: 0,
comment: '总重量(g)',
},
items_hash: {
type: CHAR(32),
allowNull: false,
defaultValue: '',
comment: 'MD5哈希值(32位)',
},
items_crc: {
type: INTEGER(10).UNSIGNED,
allowNull: false,
defaultValue: 0,
comment: 'CRC32校验码',
},
wave_id: {
type: BIGINT(20),
allowNull: false,
defaultValue: 0,
comment: '波次ID,0表示未分配',
},
wave_no: {
type: STRING(50),
allowNull: false,
defaultValue: '',
comment: '波次号,空字符串表示未分配',
},
wave_strategy_version: {
type: INTEGER(10),
allowNull: false,
defaultValue: 0,
comment: '波次策略版本号',
},
wave_scan_result: {
type: INTEGER(10),
allowNull: false,
defaultValue: 0,
comment: '波次扫描结果,0未扫描,1扫描符合,2扫描没有符合',
},
// 状态机字段
post_status: {
type: ENUM(...StatusEnum.POST_STATUS),
allowNull: true,
defaultValue: 'none',
comment: '分配快递号状态机',
},
storage_status: {
type: ENUM(...StatusEnum.STORAGE_STATUS),
allowNull: true,
defaultValue: 'none',
comment: '分配储位状态机',
},
pick_status: {
type: ENUM(...StatusEnum.PICK_STATUS),
allowNull: true,
defaultValue: 'none',
comment: '拣货状态机',
},
pack_status: {
type: ENUM(...StatusEnum.PACK_STATUS),
allowNull: true,
defaultValue: 'none',
comment: '打包状态机',
},
sended_status: {
type: ENUM(...StatusEnum.SENDED_STATUS),
allowNull: true,
defaultValue: 'none',
comment: '发货状态机',
},
inspection_status: {
type: ENUM(...StatusEnum.INSPECTION_STATUS),
allowNull: true,
defaultValue: 'none',
comment: '检验状态机',
},
recheck_status: {
type: STRING(20),
allowNull: true,
defaultValue: 'none',
comment: '复核状态',
},
recheck_time: {
type: DATE,
allowNull: true,
comment: '复核时间',
},
step: {
type: INTEGER(10),
allowNull: false,
defaultValue: 0,
comment: '订单步骤:0未审核,1已审核,2处理中,3驳回/异常,4配送中,5已完成,9已关闭',
},
print_status: {
type: ENUM(...StatusEnum.PRINT_STATUS),
allowNull: true,
defaultValue: 'none',
comment: '打印状态机',
},
claim_status: {
type: ENUM(...StatusEnum.CLAIM_STATUS),
allowNull: true,
defaultValue: 'none',
comment: '领取状态机',
},
outbound_status: {
type: ENUM(...StatusEnum.OUTBOUND_STATUS),
allowNull: true,
defaultValue: 'none',
comment: '出库状态机',
},
lock_status: {
type: ENUM(...StatusEnum.LOCK_STATUS),
allowNull: true,
defaultValue: 'none',
comment: '锁定状态机',
},
print_lock_status: {
type: ENUM(...StatusEnum.PRINT_LOCK_STATUS),
allowNull: true,
defaultValue: 'none',
comment: '打印锁定状态机',
},
intercept_status: {
type: ENUM(...StatusEnum.INTERCEPT_STATUS),
allowNull: true,
defaultValue: 'none',
comment: '拦截状态机',
},
};
// 主表模型
const OrderDelivery = model.define('order_delivery', baseModel, {
tableName: 'wms_order_delivery',
timestamps: false,
comment: '仓库发货单常用表',
indexes: [
{
name: 'idx_current_store_id',
fields: [ 'store_id' ],
},
{
name: 'idx_current_warehouse_id',
fields: [ 'warehouse_id' ],
},
{
name: 'idx_current_delivery_code',
unique: true,
fields: [ 'delivery_order_code', 'store_id', 'warehouse_id' ],
},
{
name: 'idx_items',
fields: [{ attribute: 'items', length: 50 }],
},
{
name: 'idx_items_hash',
fields: [ 'items_hash' ],
},
{
name: 'idx_hash_crc',
fields: [ 'items_hash', 'items_crc', 'warehouse_id' ],
},
{
name: 'wave_id',
fields: [ 'status', 'wave_id' ],
},
// 状态机索引
{
name: 'idx_statuses_composite',
fields: [
'status',
'post_status',
'pick_status',
'pack_status',
'outbound_status',
],
},
],
});
return OrderDelivery;
};