修复自动发货bug
This commit is contained in:
@@ -215,25 +215,6 @@ function applyEnvOverrides(baseConfig) {
|
||||
nextConfig.platforms.agiso.autoDelivery.apiVersion = agisoAutoDeliveryApiVersion
|
||||
}
|
||||
|
||||
const agisoAutoDeliveryAldsType = parseInteger(process.env.AGISO_AUTO_DELIVERY_ALDS_TYPE)
|
||||
if (agisoAutoDeliveryAldsType !== null) {
|
||||
nextConfig.platforms.agiso.autoDelivery.aldsType = agisoAutoDeliveryAldsType
|
||||
}
|
||||
|
||||
for (const [envKey, configKey] of [
|
||||
['AGISO_AUTO_DELIVERY_IGNORE_ALDS_LOG', 'ignoreAldsLog'],
|
||||
['AGISO_AUTO_DELIVERY_IGNORE_BLACK_LIST', 'ignoreBlackList'],
|
||||
['AGISO_AUTO_DELIVERY_IGNORE_ON_OFF', 'ignoreOnOff'],
|
||||
['AGISO_AUTO_DELIVERY_IGNORE_REFUND_CHECK', 'ignoreRefundCheck'],
|
||||
['AGISO_AUTO_DELIVERY_IGNORE_RESTRICTED', 'ignoreRestricted'],
|
||||
['AGISO_AUTO_DELIVERY_IGNORE_TRADE_STATUS_CHECK', 'ignoreTradeStatusCheck'],
|
||||
]) {
|
||||
const parsed = parseBoolean(process.env[envKey])
|
||||
if (parsed !== null) {
|
||||
nextConfig.platforms.agiso.autoDelivery[configKey] = parsed
|
||||
}
|
||||
}
|
||||
|
||||
const agisoMessageAppSecret = String(process.env.AGISO_MESSAGE_APP_SECRET || '').trim()
|
||||
if (agisoMessageAppSecret) {
|
||||
nextConfig.platforms.agiso.messaging.appSecret = agisoMessageAppSecret
|
||||
|
||||
@@ -306,7 +306,6 @@ export function buildOrderAgisoAutoDeliverySummary(order, tasks = []) {
|
||||
responseStatus: 0,
|
||||
errorMessage: '',
|
||||
requestId: '',
|
||||
aldsType: null,
|
||||
updatedAt: null,
|
||||
sourceTaskId: null,
|
||||
sourceTaskNo: '',
|
||||
@@ -409,7 +408,6 @@ function mapAgisoAutoDeliveryContext(value) {
|
||||
responseStatus: Number(value.responseStatus || 0),
|
||||
errorMessage: String(value.errorMessage || '').trim(),
|
||||
requestId: String(value.requestId || '').trim(),
|
||||
aldsType: Number(value.aldsType || 0) || null,
|
||||
updatedAt: value.updatedAt || null,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ import { parseJsonObject } from '../../../../utils/json.js'
|
||||
import { logWebhook } from '../../../../utils/logger.js'
|
||||
import { nowIso } from '../../../../utils/time.js'
|
||||
|
||||
const AGISO_DUMMY_SEND_ENDPOINT = 'https://gw-api.agiso.com/aldsIdle/Order/DummySend'
|
||||
|
||||
/**
|
||||
* @typedef {{
|
||||
* order?: Record<string, any> | null
|
||||
@@ -82,15 +84,8 @@ export async function ensureAgisoXianyuAutoDeliveryForDeliveredTask({
|
||||
apiVersion: config.apiVersion,
|
||||
})
|
||||
const requestBody = buildRequestBody({
|
||||
tids: String(order.platform_order_id || '').trim(),
|
||||
platformOrderId: String(order.platform_order_id || '').trim(),
|
||||
appSecret: config.appSecret,
|
||||
aldsType: config.aldsType,
|
||||
ignoreAldsLog: config.ignoreAldsLog,
|
||||
ignoreBlackList: config.ignoreBlackList,
|
||||
ignoreOnOff: config.ignoreOnOff,
|
||||
ignoreRefundCheck: config.ignoreRefundCheck,
|
||||
ignoreRestricted: config.ignoreRestricted,
|
||||
ignoreTradeStatusCheck: config.ignoreTradeStatusCheck,
|
||||
})
|
||||
|
||||
logWebhook('[agiso/xianyu/auto-delivery]', '开始执行 Agiso 咸鱼自动发货', {
|
||||
@@ -100,7 +95,6 @@ export async function ensureAgisoXianyuAutoDeliveryForDeliveredTask({
|
||||
shopId: order.shop_id,
|
||||
platformOrderId: order.platform_order_id,
|
||||
endpoint: config.endpoint,
|
||||
aldsType: config.aldsType,
|
||||
})
|
||||
|
||||
try {
|
||||
@@ -116,7 +110,7 @@ export async function ensureAgisoXianyuAutoDeliveryForDeliveredTask({
|
||||
if (success) {
|
||||
const requestId = String(parsed?.RequestId || '').trim()
|
||||
|
||||
// DummySend 接口返回成功后,再查一次 Order/Detail 确认订单真的进入已发货状态 meow~
|
||||
// 发货接口返回成功后,再查一次 Order/Detail 确认订单真的进入已发货状态 meow~
|
||||
const confirmResult = await confirmAgisoXianyuAutoDeliveryShipped({
|
||||
shopId: order.shop_id,
|
||||
platformOrderId: order.platform_order_id,
|
||||
@@ -144,10 +138,9 @@ export async function ensureAgisoXianyuAutoDeliveryForDeliveredTask({
|
||||
order,
|
||||
responseStatus: response.status,
|
||||
response: parsed,
|
||||
errorMessage: `接口返回成功,但订单状态未确认进入已发货 (orderStatus=${confirmResult.orderStatus}, shipTime=${confirmResult.shipTime})`,
|
||||
errorMessage: `Agiso 发货状态更新接口已受理,但订单仍未进入已发货,请检查该订单是否允许无物流发货 (orderStatus=${confirmResult.orderStatus}, shipTime=${confirmResult.shipTime})`,
|
||||
detail: {
|
||||
requestId,
|
||||
aldsType: config.aldsType,
|
||||
confirmOrderStatus: confirmResult.orderStatus,
|
||||
confirmShipTime: confirmResult.shipTime,
|
||||
},
|
||||
@@ -175,7 +168,6 @@ export async function ensureAgisoXianyuAutoDeliveryForDeliveredTask({
|
||||
response: parsed,
|
||||
detail: {
|
||||
requestId,
|
||||
aldsType: config.aldsType,
|
||||
confirmOrderStatus: confirmResult.orderStatus,
|
||||
confirmShipTime: confirmResult.shipTime,
|
||||
},
|
||||
@@ -250,17 +242,10 @@ function resolveAgisoXianyuAutoDeliveryConfig(order) {
|
||||
|
||||
return {
|
||||
enabled: normalizeBooleanLike(baseConfig.enabled, true),
|
||||
endpoint: String(baseConfig.endpoint || '').trim(),
|
||||
endpoint: resolveAgisoAutoDeliveryEndpoint(baseConfig.endpoint),
|
||||
apiVersion: String(baseConfig.apiVersion || shopConfig.apiVersion || '1').trim() || '1',
|
||||
appSecret: String(shopConfig.appSecret || runtimeConfig.platforms?.agiso?.appSecret || '').trim(),
|
||||
accessToken: String(shopConfig.accessToken || '').trim(),
|
||||
aldsType: normalizePositiveInteger(baseConfig.aldsType, 1),
|
||||
ignoreAldsLog: normalizeBooleanLike(baseConfig.ignoreAldsLog, false),
|
||||
ignoreBlackList: normalizeBooleanLike(baseConfig.ignoreBlackList, false),
|
||||
ignoreOnOff: normalizeBooleanLike(baseConfig.ignoreOnOff, false),
|
||||
ignoreRefundCheck: normalizeBooleanLike(baseConfig.ignoreRefundCheck, false),
|
||||
ignoreRestricted: normalizeBooleanLike(baseConfig.ignoreRestricted, false),
|
||||
ignoreTradeStatusCheck: normalizeBooleanLike(baseConfig.ignoreTradeStatusCheck, false),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,26 +257,9 @@ function buildRequestHeaders({ accessToken, apiVersion }) {
|
||||
}
|
||||
}
|
||||
|
||||
function buildRequestBody({
|
||||
tids,
|
||||
appSecret,
|
||||
aldsType,
|
||||
ignoreAldsLog,
|
||||
ignoreBlackList,
|
||||
ignoreOnOff,
|
||||
ignoreRefundCheck,
|
||||
ignoreRestricted,
|
||||
ignoreTradeStatusCheck,
|
||||
}) {
|
||||
function buildRequestBody({ platformOrderId, appSecret }) {
|
||||
const payload = {
|
||||
tids: String(tids || '').trim(),
|
||||
aldsType: String(normalizePositiveInteger(aldsType, 1)),
|
||||
ignoreAldsLog: String(Boolean(ignoreAldsLog)),
|
||||
ignoreBlackList: String(Boolean(ignoreBlackList)),
|
||||
ignoreOnOff: String(Boolean(ignoreOnOff)),
|
||||
ignoreRefundCheck: String(Boolean(ignoreRefundCheck)),
|
||||
ignoreRestricted: String(Boolean(ignoreRestricted)),
|
||||
ignoreTradeStatusCheck: String(Boolean(ignoreTradeStatusCheck)),
|
||||
tid: String(platformOrderId || '').trim(),
|
||||
timestamp: String(Math.floor(Date.now() / 1000)),
|
||||
}
|
||||
|
||||
@@ -350,6 +318,10 @@ export function resolveAgisoAutoDeliveryErrorMessage(payload, rawText, statusCod
|
||||
return text || `Agiso 咸鱼自动发货失败,HTTP ${statusCode}`
|
||||
}
|
||||
|
||||
export function resolveAgisoAutoDeliveryEndpoint(value) {
|
||||
return AGISO_DUMMY_SEND_ENDPOINT
|
||||
}
|
||||
|
||||
async function persistAgisoAutoDeliveryResult(task, {
|
||||
status,
|
||||
trigger,
|
||||
@@ -428,15 +400,6 @@ function isAgisoXianyuOrder(order) {
|
||||
&& Number(order?.id || 0) > 0
|
||||
}
|
||||
|
||||
function normalizePositiveInteger(value, fallbackValue) {
|
||||
const parsed = Number(value)
|
||||
if (Number.isFinite(parsed) && parsed > 0) {
|
||||
return Math.floor(parsed)
|
||||
}
|
||||
|
||||
return fallbackValue
|
||||
}
|
||||
|
||||
function normalizeBooleanLike(value, fallbackValue) {
|
||||
if (typeof value === 'boolean') {
|
||||
return value
|
||||
@@ -463,7 +426,7 @@ function isPlainObject(value) {
|
||||
}
|
||||
|
||||
/**
|
||||
* DummySend 返回成功后,再查一次 Order/Detail 确认订单是否真的进入已发货状态 meow~
|
||||
* 发货接口返回成功后,再查一次 Order/Detail 确认订单是否真的进入已发货状态 meow~
|
||||
* 只有 ship_time > 0 或 orderStatus >= 3 才算发货确认通过
|
||||
*/
|
||||
async function confirmAgisoXianyuAutoDeliveryShipped({ shopId = '', platformOrderId = '', requestId = '' } = {}) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
hasAgisoAutoDeliverySucceeded,
|
||||
isOrderReadyForAgisoAutoDelivery,
|
||||
isAgisoAutoDeliverySuccess,
|
||||
resolveAgisoAutoDeliveryEndpoint,
|
||||
resolveAgisoAutoDeliveryErrorMessage,
|
||||
} from './auto-delivery-service.js'
|
||||
|
||||
@@ -58,3 +59,15 @@ test('resolveAgisoAutoDeliveryErrorMessage prefers structured payload message be
|
||||
'fallback raw body',
|
||||
)
|
||||
})
|
||||
|
||||
test('resolveAgisoAutoDeliveryEndpoint falls back to DummySend', () => {
|
||||
assert.equal(
|
||||
resolveAgisoAutoDeliveryEndpoint(''),
|
||||
'https://gw-api.agiso.com/aldsIdle/Order/DummySend',
|
||||
)
|
||||
|
||||
assert.equal(
|
||||
resolveAgisoAutoDeliveryEndpoint('https://gw-api.agiso.com/aldsIdle/Order/DummySend'),
|
||||
'https://gw-api.agiso.com/aldsIdle/Order/DummySend',
|
||||
)
|
||||
})
|
||||
|
||||
@@ -21,7 +21,6 @@ export {}
|
||||
* responseStatus: number
|
||||
* errorMessage: string
|
||||
* requestId: string
|
||||
* aldsType: number | null
|
||||
* updatedAt: string | null
|
||||
* }} AdminAgisoAutoDeliveryStatus
|
||||
*/
|
||||
|
||||
@@ -76,13 +76,6 @@ export {}
|
||||
* enabled: boolean
|
||||
* endpoint: string
|
||||
* apiVersion: string
|
||||
* aldsType: number
|
||||
* ignoreAldsLog: boolean
|
||||
* ignoreBlackList: boolean
|
||||
* ignoreOnOff: boolean
|
||||
* ignoreRefundCheck: boolean
|
||||
* ignoreRestricted: boolean
|
||||
* ignoreTradeStatusCheck: boolean
|
||||
* }
|
||||
* messaging: {
|
||||
* enabled: boolean
|
||||
|
||||
Reference in New Issue
Block a user