oms/backend/app/model/orderSyncTask.js
liufumingren e1e3bb638f feat(order): 拉单任务、外部发货同步与取号记录
- 拉单任务:新增 order_sync_tasks 异步任务池,按店铺逐店拉取外部打单平台订单,前端轮询进度
- 外部发货同步:配送后把发货结果同步回店管家,提供数量统计与批量重试(externalSendSync)
- 取号:新增 waybill_fetch_records 记录取号过程,外部快递接口补充菜鸟授权信息
- 补齐相关迁移、订单页同步入口/状态展示,并新增对接说明文档

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-04 20:53:35 +08:00

50 lines
3.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';
/**
* 拉单任务模型,对应 order_sync_tasks。
*
* 全局异步任务池:前端提交「拉取订单」→ 落一条待处理任务并立即返回任务ID →
* 定时任务(orderSyncWorker)认领后逐店拉单并实时写回进度 → 前端轮询展示。
*
* 与 export_tasks 的区别:本表按「店铺」维度推进(total_shops / processed_shops),
* 逐店结果存 items(JSON 数组),便于直接展示每个店铺的拉单结果与失败原因。
* @param {Egg.Application} app egg application
* @return {object} orderSyncTask model
*/
module.exports = app => {
const { BIGINT, STRING, TINYINT, INTEGER, JSON: JsonType, DATE } = app.Sequelize;
const OrderSyncTask = app.model.define('order_sync_task', {
id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' },
principal_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '所属主体ID' },
scope: { type: STRING(30), allowNull: false, defaultValue: 'external_print', comment: '拉单范围:external_print=外部打单平台店铺' },
status: { type: TINYINT, allowNull: false, defaultValue: 0, comment: '状态:0待处理 1处理中 2已完成 3部分失败 4失败' },
start_time: { type: DATE, comment: '拉单起始时间' },
end_time: { type: DATE, comment: '拉单结束时间' },
lookback_days: { type: INTEGER, comment: '回看天数(0=全部待处理)' },
shop_ids: { type: JsonType, comment: '指定店铺ID数组;空表示按范围匹配全部' },
total_shops: { type: INTEGER, allowNull: false, defaultValue: 0, comment: '待拉取店铺数' },
processed_shops: { type: INTEGER, allowNull: false, defaultValue: 0, comment: '已处理店铺数' },
failed_shops: { type: INTEGER, allowNull: false, defaultValue: 0, comment: '失败店铺数' },
created_orders: { type: INTEGER, allowNull: false, defaultValue: 0, comment: '新增订单数' },
updated_orders: { type: INTEGER, allowNull: false, defaultValue: 0, comment: '更新订单数' },
skipped_orders: { type: INTEGER, allowNull: false, defaultValue: 0, comment: '跳过(平台已发货)订单数' },
voided_orders: { type: INTEGER, allowNull: false, defaultValue: 0, comment: '自动作废订单数(合计)' },
voided_shipped_orders: { type: INTEGER, allowNull: false, defaultValue: 0, comment: '自动作废中「平台已发货/已终结」的订单数' },
voided_missing_orders: { type: INTEGER, allowNull: false, defaultValue: 0, comment: '自动作废中「平台已查不到」的订单数' },
progress: { type: TINYINT, allowNull: false, defaultValue: 0, comment: '进度百分比 0-100' },
items: { type: JsonType, comment: '逐店结果 JSON 数组' },
error_message: { type: STRING(500), comment: '整体失败原因' },
created_by: { type: BIGINT.UNSIGNED, comment: '提交人ID' },
started_at: { type: DATE, comment: '开始执行时间' },
finished_at: { type: DATE, comment: '执行结束时间' },
created_at: { type: DATE, comment: '创建时间' },
updated_at: { type: DATE, comment: '更新时间' },
}, {
tableName: 'order_sync_tasks',
comment: '拉单异步任务',
});
return OrderSyncTask;
};