462 lines
11 KiB
JavaScript
462 lines
11 KiB
JavaScript
'use strict';
|
||
|
||
module.exports = app => {
|
||
const { Sequelize, model } = app;
|
||
const { STRING, BIGINT, DECIMAL, TEXT, ENUM, DATE, INTEGER, CHAR, SMALLINT } = Sequelize;
|
||
|
||
// 状态机枚举定义
|
||
const StatusEnum = {
|
||
STATUS: [ 'pedding', 'created', 'cancel', 'error' ],
|
||
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' ],
|
||
INSPECTION_STATUS: [ 'none', 'padding', 'running', 'fin', 'error' ],
|
||
PRINT_STATUS: [ 'none', 'padding', 'fin', 'error' ],
|
||
CLAIM_STATUS: [ 'none', 'padding', 'fin', 'error' ],
|
||
OUTBOUND_STATUS: [ 'none', 'padding', 'fin', '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: STRING(200),
|
||
allowNull: true,
|
||
comment: '订单标记',
|
||
},
|
||
source_platform_code: {
|
||
type: STRING(50),
|
||
allowNull: true,
|
||
comment: '来源平台编码',
|
||
},
|
||
source_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: STRING(50),
|
||
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审核时间',
|
||
},
|
||
shop_nick: {
|
||
type: STRING(200),
|
||
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: '物流公司名称',
|
||
},
|
||
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: '发货服务类型',
|
||
},
|
||
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: STRING(255),
|
||
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: DECIMAL(10, 2),
|
||
allowNull: false,
|
||
defaultValue: 0.00,
|
||
comment: '总重量(kg)',
|
||
},
|
||
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表示未分配',
|
||
},
|
||
// 状态机字段
|
||
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: '打包状态机',
|
||
},
|
||
inspection_status: {
|
||
type: ENUM(...StatusEnum.INSPECTION_STATUS),
|
||
allowNull: true,
|
||
defaultValue: 'none',
|
||
comment: '检验状态机',
|
||
},
|
||
print_status: {
|
||
type: ENUM(...StatusEnum.PRINT_STATUS),
|
||
allowNull: true,
|
||
defaultValue: null,
|
||
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: null,
|
||
comment: '锁定状态机',
|
||
},
|
||
intercept_status: {
|
||
type: ENUM(...StatusEnum.INTERCEPT_STATUS),
|
||
allowNull: true,
|
||
defaultValue: null,
|
||
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: [ '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;
|
||
};
|