'use strict'; /** * 状态表 / 历史表增加「同步外部发货」状态字段。 * * 配送后需要把发货结果同步回外部打单平台(店管家 `NewOrder/OnlineSendBatch`): * - 逐单记录状态与尝试次数,失败自动重试,超过上限转异常(等人工批量重试); * - 订单流转时按字段定义整体搬运,所以所有状态表 + 历史表都要有这几列。 */ const TABLES = [ 'order_status_pending', 'order_status_queued', 'order_status_exception', 'order_status_outsourcing', 'order_status_delivery', 'order_status_void', 'order_status_canceled', 'order_status_history', ]; module.exports = { async up(queryInterface, Sequelize) { for (const table of TABLES) { await queryInterface.addColumn(table, 'external_send_status', { type: Sequelize.TINYINT.UNSIGNED, allowNull: false, defaultValue: 0, comment: '同步外部发货状态:0待同步 1已同步 2同步失败待重试 3异常(重试超限)', }); await queryInterface.addColumn(table, 'external_send_times', { type: Sequelize.INTEGER.UNSIGNED, allowNull: false, defaultValue: 0, comment: '同步外部发货已尝试次数', }); await queryInterface.addColumn(table, 'external_send_error', { type: Sequelize.STRING(500), allowNull: true, comment: '最近一次同步失败原因', }); await queryInterface.addColumn(table, 'external_send_at', { type: Sequelize.DATE, allowNull: true, comment: '最近一次同步尝试时间', }); await queryInterface.addColumn(table, 'external_sent_at', { type: Sequelize.DATE, allowNull: true, comment: '同步成功时间', }); } await queryInterface.addIndex('order_status_delivery', [ 'principal_id', 'external_send_status' ], { name: 'idx_delivery_external_send_status', }); }, async down(queryInterface) { await queryInterface.removeIndex('order_status_delivery', 'idx_delivery_external_send_status'); for (const table of TABLES) { await queryInterface.removeColumn(table, 'external_sent_at'); await queryInterface.removeColumn(table, 'external_send_at'); await queryInterface.removeColumn(table, 'external_send_error'); await queryInterface.removeColumn(table, 'external_send_times'); await queryInterface.removeColumn(table, 'external_send_status'); } }, };