- 拉单任务:新增 order_sync_tasks 异步任务池,按店铺逐店拉取外部打单平台订单,前端轮询进度 - 外部发货同步:配送后把发货结果同步回店管家,提供数量统计与批量重试(externalSendSync) - 取号:新增 waybill_fetch_records 记录取号过程,外部快递接口补充菜鸟授权信息 - 补齐相关迁移、订单页同步入口/状态展示,并新增对接说明文档 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
62 lines
2.3 KiB
JavaScript
62 lines
2.3 KiB
JavaScript
'use strict';
|
|
|
|
const Controller = require('egg').Controller;
|
|
|
|
/**
|
|
* 外部打单平台「同步发货」相关接口
|
|
*
|
|
* 用于配送视图:查看同步数量(异常数量快速展示)、批量重试同步异常/失败的订单。
|
|
* 真正的同步由定时任务 `externalSendSyncWorker` 执行,批量重试会立刻跑一批并返回结果。
|
|
* @controller ExternalSendSyncController
|
|
*/
|
|
class ExternalSendSyncController extends Controller {
|
|
/**
|
|
* @summary 同步状态数量
|
|
* @description 返回当前主体下配送订单的外部发货同步数量:待同步 / 待重试 / 异常 / 已同步 / 合计。
|
|
* @router get /api/external-send/counts
|
|
* @apikey
|
|
* @response 200 externalSendCountsResponse success
|
|
*/
|
|
async counts() {
|
|
const { ctx } = this;
|
|
try {
|
|
const data = await ctx.service.externalSendSync.counts(ctx.state.principalId);
|
|
ctx.body = { code: 0, message: 'success', data };
|
|
} catch (err) {
|
|
const status = Number(err && err.status) || 500;
|
|
ctx.status = status;
|
|
ctx.body = { code: status, message: (err && err.message) || '查询同步数量失败' };
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @summary 批量重试同步外部发货
|
|
* @description 把指定订单(或按状态筛选的订单)重置为「待同步」并立刻同步一批。
|
|
* 不传 ids 时默认重试「异常 + 待重试」的订单;次数会清零重新计数。
|
|
* @router post /api/external-send/retry
|
|
* @apikey
|
|
* @request body externalSendRetryRequest retryRequest 重试参数
|
|
* @response 200 externalSendRetryResponse success
|
|
*/
|
|
async retry() {
|
|
const { ctx } = this;
|
|
const body = ctx.request.body || {};
|
|
const ids = Array.isArray(body.ids) ? body.ids : [];
|
|
const statuses = Array.isArray(body.statuses) ? body.statuses.map(Number) : undefined;
|
|
try {
|
|
const data = await ctx.service.externalSendSync.retry({
|
|
ids,
|
|
statuses,
|
|
principalId: ctx.state.principalId,
|
|
});
|
|
ctx.body = { code: 0, message: 'success', data };
|
|
} catch (err) {
|
|
const status = Number(err && err.status) || 500;
|
|
ctx.status = status;
|
|
ctx.body = { code: status, message: (err && err.message) || '重试同步失败' };
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = ExternalSendSyncController;
|