ming #1
@ -704,13 +704,13 @@ class ExpressPlatformService extends MainService {
|
|||||||
console.log('order', order);
|
console.log('order', order);
|
||||||
const expressListItem = ExpressList.find(item => item.code === listByWarehousePlatformCode.sys_express_code) || {};
|
const expressListItem = ExpressList.find(item => item.code === listByWarehousePlatformCode.sys_express_code) || {};
|
||||||
let plattradeno = order.source_order_codes;
|
let plattradeno = order.source_order_codes;
|
||||||
if(listByWarehousePlatformCode.platform_code === 'DY' && order.from_key === 23060081 && !!order.pay_no && plattradeno.indexOf(",") > -1){
|
if (listByWarehousePlatformCode.platform_code === 'DY' && order.from_key === 23060081 && !!order.pay_no && plattradeno.indexOf(',') > -1) {
|
||||||
plattradeno = order.pay_no;
|
plattradeno = order.pay_no;
|
||||||
}
|
}
|
||||||
let playload = {
|
let playload = {
|
||||||
object_Id: `${order.warehouse_id.toString(16)}_${order.id}_${order_tmp.business_key}`, // 菠萝派平台要求订单唯一标识必须为字符串
|
object_Id: `${order.warehouse_id.toString(16)}_${Number(order.id || 0).toString(16)}_${order_tmp.business_key}`, // 菠萝派平台要求订单唯一标识必须为字符串
|
||||||
orderno: `${order.warehouse_id.toString(16)}_${order.id}_${order_tmp.business_key}`, // 菠萝派平台要求订单号必须为字符串
|
orderno: `${order.warehouse_id.toString(16)}_${Number(order.id || 0).toString(16)}_${order_tmp.business_key}`, // 菠萝派平台要求订单号必须为字符串
|
||||||
plattradeno: plattradeno,
|
plattradeno,
|
||||||
tid: plattradeno,
|
tid: plattradeno,
|
||||||
ismultiplepieces: order.package_count > 1 ? 1 : 0,
|
ismultiplepieces: order.package_count > 1 ? 1 : 0,
|
||||||
logisticno: allocatedWaybillMap.get(`${Number(order.id) || 0}:${Number(order_tmp.business_key) || 0}`) || '',
|
logisticno: allocatedWaybillMap.get(`${Number(order.id) || 0}:${Number(order_tmp.business_key) || 0}`) || '',
|
||||||
@ -744,7 +744,7 @@ class ExpressPlatformService extends MainService {
|
|||||||
brandno: listByWarehousePlatformCode.brandno || null,
|
brandno: listByWarehousePlatformCode.brandno || null,
|
||||||
needencrypt: 1,
|
needencrypt: 1,
|
||||||
ordertime: order.place_order_time || '',
|
ordertime: order.place_order_time || '',
|
||||||
customername:"测试",
|
customername: '测试',
|
||||||
ordersource: matchedPlatform.ordersource || '',
|
ordersource: matchedPlatform.ordersource || '',
|
||||||
inputsite: order.sys_platform_code === 'XHS' ? '' : listByWarehousePlatformCode.site_code || '',
|
inputsite: order.sys_platform_code === 'XHS' ? '' : listByWarehousePlatformCode.site_code || '',
|
||||||
sitecode: listByWarehousePlatformCode.site_code || '',
|
sitecode: listByWarehousePlatformCode.site_code || '',
|
||||||
@ -793,7 +793,7 @@ class ExpressPlatformService extends MainService {
|
|||||||
|
|
||||||
if (Number(matchedPlatform.platid) === 673) {
|
if (Number(matchedPlatform.platid) === 673) {
|
||||||
playload.BizVersion = '2';
|
playload.BizVersion = '2';
|
||||||
playload.brandno = listByWarehousePlatformCode.brandno === "SF" ? listByWarehousePlatformCode.brandno : undefined;
|
playload.brandno = listByWarehousePlatformCode.brandno === 'SF' ? listByWarehousePlatformCode.brandno : undefined;
|
||||||
}
|
}
|
||||||
if (Number(matchedPlatform.platid) === 544) {
|
if (Number(matchedPlatform.platid) === 544) {
|
||||||
const {
|
const {
|
||||||
@ -866,7 +866,7 @@ class ExpressPlatformService extends MainService {
|
|||||||
customername,
|
customername,
|
||||||
goods,
|
goods,
|
||||||
oaid,
|
oaid,
|
||||||
customercode: logistictype==="SF" ? undefined: customercode || shipperno || listByWarehousePlatformCode.shipperno || listByWarehousePlatformCode.client_id || '',
|
customercode: logistictype === 'SF' ? undefined : customercode || shipperno || listByWarehousePlatformCode.shipperno || listByWarehousePlatformCode.client_id || '',
|
||||||
sender: {
|
sender: {
|
||||||
name: senderName,
|
name: senderName,
|
||||||
phone: senderPhoneRaw,
|
phone: senderPhoneRaw,
|
||||||
@ -908,7 +908,7 @@ class ExpressPlatformService extends MainService {
|
|||||||
playload.mainsubpaymode = '1';
|
playload.mainsubpaymode = '1';
|
||||||
delete playload.plattradeno;
|
delete playload.plattradeno;
|
||||||
}
|
}
|
||||||
playload.ProviderID = listByWarehousePlatformCode.providerid || "";
|
playload.ProviderID = listByWarehousePlatformCode.providerid || '';
|
||||||
console.log('playload', playload);
|
console.log('playload', playload);
|
||||||
return playload;
|
return playload;
|
||||||
}),
|
}),
|
||||||
@ -973,8 +973,8 @@ class ExpressPlatformService extends MainService {
|
|||||||
for (const [ groupReason, groupItems ] of reasonGroups) {
|
for (const [ groupReason, groupItems ] of reasonGroups) {
|
||||||
const itemFailedOrders = [];
|
const itemFailedOrders = [];
|
||||||
for (const failedItem of groupItems) {
|
for (const failedItem of groupItems) {
|
||||||
const [ , order_id, business_key ] = String(failedItem.orderno || '').split('_');
|
const [ , order_id_hex, business_key ] = String(failedItem.orderno || '').split('_');
|
||||||
const orderId = Number(order_id) || 0;
|
const orderId = parseInt(order_id_hex, 16) || 0;
|
||||||
const businessKey = Number(business_key) || 0;
|
const businessKey = Number(business_key) || 0;
|
||||||
if (!orderId || !businessKey) continue;
|
if (!orderId || !businessKey) continue;
|
||||||
|
|
||||||
@ -1017,8 +1017,9 @@ class ExpressPlatformService extends MainService {
|
|||||||
switch (listByWarehousePlatformCode.platform_code) {
|
switch (listByWarehousePlatformCode.platform_code) {
|
||||||
case 'KS':
|
case 'KS':
|
||||||
successUpdates = (result.results || []).map(item => {
|
successUpdates = (result.results || []).map(item => {
|
||||||
const [ warehouse_id_hex, order_id, business_key ] = String(item.orderno || '').split('_');
|
const [ warehouse_id_hex, order_id_hex, business_key ] = String(item.orderno || '').split('_');
|
||||||
const warehouse_id = parseInt(warehouse_id_hex, 16);
|
const warehouse_id = parseInt(warehouse_id_hex, 16);
|
||||||
|
const order_id = parseInt(order_id_hex, 16) || 0;
|
||||||
const waybillCode = resolveWaybillCode(item);
|
const waybillCode = resolveWaybillCode(item);
|
||||||
return {
|
return {
|
||||||
warehouse_id,
|
warehouse_id,
|
||||||
@ -1053,8 +1054,9 @@ class ExpressPlatformService extends MainService {
|
|||||||
break;
|
break;
|
||||||
case 'DY':
|
case 'DY':
|
||||||
successUpdates = (result.results || []).map(item => {
|
successUpdates = (result.results || []).map(item => {
|
||||||
const [ warehouse_id_hex, order_id, business_key ] = String(item.orderno || '').split('_');
|
const [ warehouse_id_hex, order_id_hex, business_key ] = String(item.orderno || '').split('_');
|
||||||
const warehouse_id = parseInt(warehouse_id_hex, 16);
|
const warehouse_id = parseInt(warehouse_id_hex, 16);
|
||||||
|
const order_id = parseInt(order_id_hex, 16) || 0;
|
||||||
|
|
||||||
const waybillCode = resolveWaybillCode(item);
|
const waybillCode = resolveWaybillCode(item);
|
||||||
return {
|
return {
|
||||||
@ -1088,7 +1090,6 @@ class ExpressPlatformService extends MainService {
|
|||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case 'JD':{
|
case 'JD':{
|
||||||
const batchPrintSipshopid = String(listByWarehousePlatformCode.platform_shop_id || '0');
|
|
||||||
const batchPrintOrders = (result.results || []).map(item => ({
|
const batchPrintOrders = (result.results || []).map(item => ({
|
||||||
orderno: String(item.orderno),
|
orderno: String(item.orderno),
|
||||||
logisticno: String(item.logisticno),
|
logisticno: String(item.logisticno),
|
||||||
@ -1155,8 +1156,9 @@ class ExpressPlatformService extends MainService {
|
|||||||
|
|
||||||
successUpdates = (batchPrintResult && batchPrintResult.results || []).map(item => {
|
successUpdates = (batchPrintResult && batchPrintResult.results || []).map(item => {
|
||||||
const objectId = String(item && item.orderno || '').trim();
|
const objectId = String(item && item.orderno || '').trim();
|
||||||
const [ warehouse_id_hex, order_id, business_key ] = objectId.split('_');
|
const [ warehouse_id_hex, order_id_hex, business_key ] = objectId.split('_');
|
||||||
const warehouse_id = parseInt(warehouse_id_hex, 16);
|
const warehouse_id = parseInt(warehouse_id_hex, 16);
|
||||||
|
const order_id = parseInt(order_id_hex, 16) || 0;
|
||||||
const waybillCode = String(item && (item.logisticno || item.waybill_code) || '').trim();
|
const waybillCode = String(item && (item.logisticno || item.waybill_code) || '').trim();
|
||||||
const rawPrintData = item && Object.prototype.hasOwnProperty.call(item, 'printdata')
|
const rawPrintData = item && Object.prototype.hasOwnProperty.call(item, 'printdata')
|
||||||
? item.printdata
|
? item.printdata
|
||||||
@ -1207,8 +1209,9 @@ class ExpressPlatformService extends MainService {
|
|||||||
}
|
}
|
||||||
case 'XHS':{
|
case 'XHS':{
|
||||||
successUpdates = (result.results || []).map(item => {
|
successUpdates = (result.results || []).map(item => {
|
||||||
const [ warehouse_id_hex, order_id, business_key ] = String(item.orderno || '').split('_');
|
const [ warehouse_id_hex, order_id_hex, business_key ] = String(item.orderno || '').split('_');
|
||||||
const warehouse_id = parseInt(warehouse_id_hex, 16);
|
const warehouse_id = parseInt(warehouse_id_hex, 16);
|
||||||
|
const order_id = parseInt(order_id_hex, 16) || 0;
|
||||||
const waybillCode = resolveWaybillCode(item);
|
const waybillCode = resolveWaybillCode(item);
|
||||||
const printInfo = item.print_info ?? item.printinfo;
|
const printInfo = item.print_info ?? item.printinfo;
|
||||||
return {
|
return {
|
||||||
@ -1250,8 +1253,9 @@ class ExpressPlatformService extends MainService {
|
|||||||
if (!objectId || objectIdParts.length < 3) {
|
if (!objectId || objectIdParts.length < 3) {
|
||||||
throw new Error(`视频号取号返回 object_id 无法解析: ${objectId || JSON.stringify(item)}`);
|
throw new Error(`视频号取号返回 object_id 无法解析: ${objectId || JSON.stringify(item)}`);
|
||||||
}
|
}
|
||||||
const [ warehouse_id_hex, order_id, business_key ] = objectIdParts;
|
const [ warehouse_id_hex, order_id_hex, business_key ] = objectIdParts;
|
||||||
const warehouse_id = parseInt(warehouse_id_hex, 16);
|
const warehouse_id = parseInt(warehouse_id_hex, 16);
|
||||||
|
const order_id = parseInt(order_id_hex, 16) || 0;
|
||||||
const waybillCode = resolveWaybillCode(item);
|
const waybillCode = resolveWaybillCode(item);
|
||||||
const rawPrintData = item && Object.prototype.hasOwnProperty.call(item, 'raw')
|
const rawPrintData = item && Object.prototype.hasOwnProperty.call(item, 'raw')
|
||||||
? item.raw
|
? item.raw
|
||||||
@ -1313,8 +1317,9 @@ class ExpressPlatformService extends MainService {
|
|||||||
}
|
}
|
||||||
case 'PDD':
|
case 'PDD':
|
||||||
successUpdates = (result.results || []).map(item => {
|
successUpdates = (result.results || []).map(item => {
|
||||||
const [ warehouse_id_hex, order_id, business_key ] = String(item.orderno || '').split('_');
|
const [ warehouse_id_hex, order_id_hex, business_key ] = String(item.orderno || '').split('_');
|
||||||
const warehouse_id = parseInt(warehouse_id_hex, 16);
|
const warehouse_id = parseInt(warehouse_id_hex, 16);
|
||||||
|
const order_id = parseInt(order_id_hex, 16) || 0;
|
||||||
const waybillCode = resolveWaybillCode(item);
|
const waybillCode = resolveWaybillCode(item);
|
||||||
return {
|
return {
|
||||||
warehouse_id,
|
warehouse_id,
|
||||||
@ -1349,8 +1354,9 @@ class ExpressPlatformService extends MainService {
|
|||||||
case 'QT':
|
case 'QT':
|
||||||
case 'OTHER':
|
case 'OTHER':
|
||||||
successUpdates = (result.results || []).map(item => {
|
successUpdates = (result.results || []).map(item => {
|
||||||
const [ warehouse_id_hex, order_id, business_key ] = String(item.orderno || '').split('_');
|
const [ warehouse_id_hex, order_id_hex, business_key ] = String(item.orderno || '').split('_');
|
||||||
const warehouse_id = parseInt(warehouse_id_hex, 16);
|
const warehouse_id = parseInt(warehouse_id_hex, 16);
|
||||||
|
const order_id = parseInt(order_id_hex, 16) || 0;
|
||||||
const waybillCode = String(item.logisticno || item.waybill_code || '').trim();
|
const waybillCode = String(item.logisticno || item.waybill_code || '').trim();
|
||||||
return {
|
return {
|
||||||
warehouse_id,
|
warehouse_id,
|
||||||
@ -1692,8 +1698,11 @@ class ExpressPlatformService extends MainService {
|
|||||||
|
|
||||||
if (syncedOrderIds.length > 0) {
|
if (syncedOrderIds.length > 0) {
|
||||||
// 异步调用,不阻塞主流程
|
// 异步调用,不阻塞主流程
|
||||||
|
// 显式传仓库上下文:Qimen 创建订单等链路 ctx.user 为空,
|
||||||
|
// 不传会导致 syncOrderIds 因"缺少仓库上下文"静默失败
|
||||||
this.ctx.service.systemMethods.order.pendingOrder.syncOrderIds({
|
this.ctx.service.systemMethods.order.pendingOrder.syncOrderIds({
|
||||||
orderIds: syncedOrderIds,
|
orderIds: syncedOrderIds,
|
||||||
|
warehouseId,
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
this.ctx.logger.error(
|
this.ctx.logger.error(
|
||||||
`[auto_sync_back] polyapi 自动同步失败: ${err.message}`
|
`[auto_sync_back] polyapi 自动同步失败: ${err.message}`
|
||||||
@ -1774,7 +1783,7 @@ class ExpressPlatformService extends MainService {
|
|||||||
: [];
|
: [];
|
||||||
const recipientMobile = orderDelivery && (orderDelivery.mobile || orderDelivery.tel) || '';
|
const recipientMobile = orderDelivery && (orderDelivery.mobile || orderDelivery.tel) || '';
|
||||||
const orderDeliveryOaid = orderDelivery && orderDelivery.oaid ? String(orderDelivery.oaid).trim() : '';
|
const orderDeliveryOaid = orderDelivery && orderDelivery.oaid ? String(orderDelivery.oaid).trim() : '';
|
||||||
const oaidTooLong = orderDeliveryOaid.indexOf("-") !== -1 || orderDeliveryOaid.length > 128;
|
const oaidTooLong = orderDeliveryOaid.indexOf('-') !== -1 || orderDeliveryOaid.length > 128;
|
||||||
|
|
||||||
const tradeOrderInfo = {
|
const tradeOrderInfo = {
|
||||||
logistics_services: normalizedExtData,
|
logistics_services: normalizedExtData,
|
||||||
@ -1817,7 +1826,9 @@ class ExpressPlatformService extends MainService {
|
|||||||
phone: recipientMobile,
|
phone: recipientMobile,
|
||||||
oaid: oaidTooLong ? '' : orderDeliveryOaid,
|
oaid: oaidTooLong ? '' : orderDeliveryOaid,
|
||||||
caid: oaidTooLong ? orderDeliveryOaid : '',
|
caid: oaidTooLong ? orderDeliveryOaid : '',
|
||||||
tid: orderDelivery.source_order_codes,
|
tid: sourceOrderCodes.length > 0
|
||||||
|
? sourceOrderCodes[0]
|
||||||
|
: orderDelivery && orderDelivery.delivery_order_code || '',
|
||||||
},
|
},
|
||||||
user_id: listByWarehousePlatformCode.shop && listByWarehousePlatformCode.shop.owner_id || 0,
|
user_id: listByWarehousePlatformCode.shop && listByWarehousePlatformCode.shop.owner_id || 0,
|
||||||
notify_extend_info: normalizedExtData,
|
notify_extend_info: normalizedExtData,
|
||||||
@ -2045,8 +2056,11 @@ class ExpressPlatformService extends MainService {
|
|||||||
|
|
||||||
if (syncedOrderIds.length > 0) {
|
if (syncedOrderIds.length > 0) {
|
||||||
// 异步调用,不阻塞主流程
|
// 异步调用,不阻塞主流程
|
||||||
|
// 显式传仓库上下文:Qimen 创建订单等链路 ctx.user 为空,
|
||||||
|
// 不传会导致 syncOrderIds 因"缺少仓库上下文"静默失败
|
||||||
this.ctx.service.systemMethods.order.pendingOrder.syncOrderIds({
|
this.ctx.service.systemMethods.order.pendingOrder.syncOrderIds({
|
||||||
orderIds: syncedOrderIds,
|
orderIds: syncedOrderIds,
|
||||||
|
warehouseId,
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
this.ctx.logger.error(
|
this.ctx.logger.error(
|
||||||
`[auto_sync_back] cainiao 自动同步失败: ${err.message}`
|
`[auto_sync_back] cainiao 自动同步失败: ${err.message}`
|
||||||
@ -2745,8 +2759,11 @@ class ExpressPlatformService extends MainService {
|
|||||||
|
|
||||||
if (syncedOrderIds.length > 0) {
|
if (syncedOrderIds.length > 0) {
|
||||||
// 异步调用,不阻塞主流程
|
// 异步调用,不阻塞主流程
|
||||||
|
// 显式传仓库上下文:Qimen 创建订单等链路 ctx.user 为空,
|
||||||
|
// 不传会导致 syncOrderIds 因"缺少仓库上下文"静默失败
|
||||||
this.ctx.service.systemMethods.order.pendingOrder.syncOrderIds({
|
this.ctx.service.systemMethods.order.pendingOrder.syncOrderIds({
|
||||||
orderIds: syncedOrderIds,
|
orderIds: syncedOrderIds,
|
||||||
|
warehouseId,
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
this.ctx.logger.error(
|
this.ctx.logger.error(
|
||||||
`[auto_sync_back] pdd 自动同步失败: ${err.message}`
|
`[auto_sync_back] pdd 自动同步失败: ${err.message}`
|
||||||
|
|||||||
@ -27,6 +27,8 @@ function createCainiaoHarness(options = {}) {
|
|||||||
printQuantityLogCreate: 0,
|
printQuantityLogCreate: 0,
|
||||||
operationLogCreateOperationLogs: 0,
|
operationLogCreateOperationLogs: 0,
|
||||||
operationLogPayloads: [],
|
operationLogPayloads: [],
|
||||||
|
getContractConfigCalls: [],
|
||||||
|
syncOrderIdsCalls: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
const relationRows = [
|
const relationRows = [
|
||||||
@ -55,6 +57,9 @@ function createCainiaoHarness(options = {}) {
|
|||||||
formatDate() {
|
formatDate() {
|
||||||
return '2026-05-24 12:00:00';
|
return '2026-05-24 12:00:00';
|
||||||
},
|
},
|
||||||
|
async setCacheAsync() {
|
||||||
|
// no-op in tests
|
||||||
|
},
|
||||||
},
|
},
|
||||||
model: {
|
model: {
|
||||||
async transaction(callback) {
|
async transaction(callback) {
|
||||||
@ -106,6 +111,9 @@ function createCainiaoHarness(options = {}) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
express: {
|
express: {
|
||||||
|
async loadExpressList() {
|
||||||
|
return [];
|
||||||
|
},
|
||||||
async getWaybillAsyncOrderDeliveryModel() {
|
async getWaybillAsyncOrderDeliveryModel() {
|
||||||
return {
|
return {
|
||||||
async update() {
|
async update() {
|
||||||
@ -122,6 +130,25 @@ function createCainiaoHarness(options = {}) {
|
|||||||
return payloads;
|
return payloads;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
storeWarehouse: {
|
||||||
|
async getContractConfig(warehouseId, storeId) {
|
||||||
|
calls.getContractConfigCalls.push({ warehouseId, storeId });
|
||||||
|
if (options.contractConfig !== undefined) {
|
||||||
|
return options.contractConfig;
|
||||||
|
}
|
||||||
|
return { policy_config: { auto_sync_back: 1 } };
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
systemMethods: {
|
||||||
|
order: {
|
||||||
|
pendingOrder: {
|
||||||
|
async syncOrderIds(request) {
|
||||||
|
calls.syncOrderIdsCalls.push(request);
|
||||||
|
return { flag: 'success' };
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
state: {
|
state: {
|
||||||
@ -335,4 +362,28 @@ describe('test/app/service/systems/express_platform.cainiao.test.js', () => {
|
|||||||
/参数错误/
|
/参数错误/
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('auto_sync_back 开启且无登录用户上下文时,应以显式 warehouseId 触发订单同步回传', async () => {
|
||||||
|
const { service, calls } = createCainiaoHarness();
|
||||||
|
|
||||||
|
await service.cainiao(buildPayload());
|
||||||
|
|
||||||
|
assert.equal(calls.getContractConfigCalls.length, 1);
|
||||||
|
assert.deepEqual(calls.getContractConfigCalls[0], { warehouseId: 100000, storeId: 5001 });
|
||||||
|
assert.equal(calls.syncOrderIdsCalls.length, 1);
|
||||||
|
assert.deepEqual(calls.syncOrderIdsCalls[0], {
|
||||||
|
orderIds: [ 2001 ],
|
||||||
|
warehouseId: 100000,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('auto_sync_back 关闭时不应触发订单同步回传', async () => {
|
||||||
|
const { service, calls } = createCainiaoHarness({
|
||||||
|
contractConfig: { policy_config: { auto_sync_back: 0 } },
|
||||||
|
});
|
||||||
|
|
||||||
|
await service.cainiao(buildPayload());
|
||||||
|
|
||||||
|
assert.equal(calls.syncOrderIdsCalls.length, 0);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -6,9 +6,11 @@ const ExpressPlatformService = require('../../../../app/service/systems/express_
|
|||||||
/**
|
/**
|
||||||
* 构建拼多多服务最小测试桩。
|
* 构建拼多多服务最小测试桩。
|
||||||
*
|
*
|
||||||
|
* @param {Object} [options={}] 测试配置。
|
||||||
|
* @param {Object} [options.contractConfig] 合约配置覆盖值。
|
||||||
* @return {{ service: Object, calls: Object }} 服务实例与调用记录。
|
* @return {{ service: Object, calls: Object }} 服务实例与调用记录。
|
||||||
*/
|
*/
|
||||||
function createPddHarness() {
|
function createPddHarness(options = {}) {
|
||||||
const calls = {
|
const calls = {
|
||||||
curl: 0,
|
curl: 0,
|
||||||
curlOptions: null,
|
curlOptions: null,
|
||||||
@ -19,6 +21,8 @@ function createPddHarness() {
|
|||||||
storeWarehouseUpdate: 0,
|
storeWarehouseUpdate: 0,
|
||||||
printQuantityLogCreate: 0,
|
printQuantityLogCreate: 0,
|
||||||
operationLogCreateOperationLogs: 0,
|
operationLogCreateOperationLogs: 0,
|
||||||
|
getContractConfigCalls: [],
|
||||||
|
syncOrderIdsCalls: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
const ctx = {
|
const ctx = {
|
||||||
@ -71,6 +75,9 @@ function createPddHarness() {
|
|||||||
service: {
|
service: {
|
||||||
systems: {
|
systems: {
|
||||||
express: {
|
express: {
|
||||||
|
async loadExpressList() {
|
||||||
|
return [];
|
||||||
|
},
|
||||||
async getWaybillAsyncOrderDeliveryModel() {
|
async getWaybillAsyncOrderDeliveryModel() {
|
||||||
return {
|
return {
|
||||||
async update() {
|
async update() {
|
||||||
@ -86,6 +93,25 @@ function createPddHarness() {
|
|||||||
return [];
|
return [];
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
storeWarehouse: {
|
||||||
|
async getContractConfig(warehouseId, storeId) {
|
||||||
|
calls.getContractConfigCalls.push({ warehouseId, storeId });
|
||||||
|
if (options.contractConfig !== undefined) {
|
||||||
|
return options.contractConfig;
|
||||||
|
}
|
||||||
|
return { policy_config: { auto_sync_back: 1 } };
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
systemMethods: {
|
||||||
|
order: {
|
||||||
|
pendingOrder: {
|
||||||
|
async syncOrderIds(request) {
|
||||||
|
calls.syncOrderIdsCalls.push(request);
|
||||||
|
return { flag: 'success' };
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
logger: {
|
logger: {
|
||||||
@ -152,6 +178,9 @@ function buildPayload() {
|
|||||||
express: {
|
express: {
|
||||||
PDD: 'YTO',
|
PDD: 'YTO',
|
||||||
},
|
},
|
||||||
|
shop: {
|
||||||
|
owner_id: 'owner-1',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
orders: [
|
orders: [
|
||||||
{
|
{
|
||||||
@ -183,7 +212,7 @@ function buildPayload() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
describe('test/app/service/systems/express_platform.pdd.ext_data.test.js', () => {
|
describe('test/app/service/systems/express_platform.pdd.ext_data.test.js', () => {
|
||||||
it('should stringify object ext_data for logistics_services and notify_extend_info', async () => {
|
it('should stringify object ext_data for logistics_services', async () => {
|
||||||
const { service, calls } = createPddHarness();
|
const { service, calls } = createPddHarness();
|
||||||
const payload = buildPayload();
|
const payload = buildPayload();
|
||||||
|
|
||||||
@ -197,11 +226,33 @@ describe('test/app/service/systems/express_platform.pdd.ext_data.test.js', () =>
|
|||||||
const orderItem = waybillRequest.trade_order_info_dtos[0];
|
const orderItem = waybillRequest.trade_order_info_dtos[0];
|
||||||
|
|
||||||
assert.equal(typeof orderItem.logistics_services, 'string');
|
assert.equal(typeof orderItem.logistics_services, 'string');
|
||||||
assert.equal(typeof orderItem.notify_extend_info, 'string');
|
|
||||||
assert.equal(orderItem.logistics_services, JSON.stringify(payload.listByWarehousePlatformCode.ext_data));
|
assert.equal(orderItem.logistics_services, JSON.stringify(payload.listByWarehousePlatformCode.ext_data));
|
||||||
assert.equal(orderItem.notify_extend_info, JSON.stringify(payload.listByWarehousePlatformCode.ext_data));
|
|
||||||
|
|
||||||
assert.equal(result.flag, true);
|
assert.equal(result.flag, true);
|
||||||
assert.equal(result.code, 0);
|
assert.equal(result.code, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('auto_sync_back 开启且无登录用户上下文时,应以显式 warehouseId 触发订单同步回传', async () => {
|
||||||
|
const { service, calls } = createPddHarness();
|
||||||
|
|
||||||
|
await service.pdd(buildPayload());
|
||||||
|
|
||||||
|
assert.equal(calls.getContractConfigCalls.length, 1);
|
||||||
|
assert.deepEqual(calls.getContractConfigCalls[0], { warehouseId: 100000, storeId: 5001 });
|
||||||
|
assert.equal(calls.syncOrderIdsCalls.length, 1);
|
||||||
|
assert.deepEqual(calls.syncOrderIdsCalls[0], {
|
||||||
|
orderIds: [ 2001 ],
|
||||||
|
warehouseId: 100000,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('auto_sync_back 关闭时不应触发订单同步回传', async () => {
|
||||||
|
const { service, calls } = createPddHarness({
|
||||||
|
contractConfig: { policy_config: { auto_sync_back: 0 } },
|
||||||
|
});
|
||||||
|
|
||||||
|
await service.pdd(buildPayload());
|
||||||
|
|
||||||
|
assert.equal(calls.syncOrderIdsCalls.length, 0);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -46,6 +46,8 @@ function createPolyapiHarness(options = {}) {
|
|||||||
printQuantityLogCreateArgsList: [],
|
printQuantityLogCreateArgsList: [],
|
||||||
getWaybillAsyncOrderDeliveryModel: 0,
|
getWaybillAsyncOrderDeliveryModel: 0,
|
||||||
getWaybillAsyncOrderDeliveryModelArgs: [],
|
getWaybillAsyncOrderDeliveryModelArgs: [],
|
||||||
|
getContractConfigCalls: [],
|
||||||
|
syncOrderIdsCalls: [],
|
||||||
callSequence: [],
|
callSequence: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -195,26 +197,29 @@ function createPolyapiHarness(options = {}) {
|
|||||||
code: '10000',
|
code: '10000',
|
||||||
results: [
|
results: [
|
||||||
{
|
{
|
||||||
orderno: '100000_101_9101',
|
orderno: '186a0_101_9101',
|
||||||
waybill_code: 'REAL-WB-101',
|
waybill_code: 'REAL-WB-101',
|
||||||
logisticno: 'PRE-WB-101',
|
logisticno: 'PRE-WB-101',
|
||||||
printinfo: 'print-101',
|
printinfo: 'print-101',
|
||||||
signature: 'sign-101',
|
signature: 'sign-101',
|
||||||
encryptprintinfo: 'enc-101',
|
encryptprintinfo: 'enc-101',
|
||||||
|
issuccess: '1',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
orderno: '100000_102_9102',
|
orderno: '186a0_102_9102',
|
||||||
logisticno: 'WB-102',
|
logisticno: 'WB-102',
|
||||||
printinfo: 'print-102',
|
printinfo: 'print-102',
|
||||||
signature: 'sign-102',
|
signature: 'sign-102',
|
||||||
encryptprintinfo: 'enc-102',
|
encryptprintinfo: 'enc-102',
|
||||||
|
issuccess: '1',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
orderno: '100000_103_9103',
|
orderno: '186a0_103_9103',
|
||||||
logisticno: 'WB-103',
|
logisticno: 'WB-103',
|
||||||
printinfo: 'print-103',
|
printinfo: 'print-103',
|
||||||
signature: 'sign-103',
|
signature: 'sign-103',
|
||||||
encryptprintinfo: 'enc-103',
|
encryptprintinfo: 'enc-103',
|
||||||
|
issuccess: '1',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
@ -235,6 +240,25 @@ function createPolyapiHarness(options = {}) {
|
|||||||
return payload;
|
return payload;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
storeWarehouse: {
|
||||||
|
async getContractConfig(warehouseId, storeId) {
|
||||||
|
calls.getContractConfigCalls.push({ warehouseId, storeId });
|
||||||
|
if (options.contractConfig !== undefined) {
|
||||||
|
return options.contractConfig;
|
||||||
|
}
|
||||||
|
return { policy_config: { auto_sync_back: 1 } };
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
systemMethods: {
|
||||||
|
order: {
|
||||||
|
pendingOrder: {
|
||||||
|
async syncOrderIds(request) {
|
||||||
|
calls.syncOrderIdsCalls.push(request);
|
||||||
|
return { flag: 'success' };
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -337,7 +361,7 @@ describe('test/app/service/systems/express_platform.polyapi.test.js', () => {
|
|||||||
assert.equal(relationRows[0].print_quantity, 6);
|
assert.equal(relationRows[0].print_quantity, 6);
|
||||||
assert.equal(relationRows[0].print_quantity_locked, 3);
|
assert.equal(relationRows[0].print_quantity_locked, 3);
|
||||||
assert.equal(calls.getWaybillAsyncOrderDeliveryModel, 3);
|
assert.equal(calls.getWaybillAsyncOrderDeliveryModel, 3);
|
||||||
assert.deepEqual(calls.getWaybillAsyncOrderDeliveryModelArgs, [ '100000', '100000', '100000' ]);
|
assert.deepEqual(calls.getWaybillAsyncOrderDeliveryModelArgs, [ 100000, 100000, 100000 ]);
|
||||||
assert.equal(calls.operationLogArgsList[0].businessId, '101');
|
assert.equal(calls.operationLogArgsList[0].businessId, '101');
|
||||||
assert.equal(calls.requestArgs.bizcontent.orders[0].logisticno, 'REAL-WB-101');
|
assert.equal(calls.requestArgs.bizcontent.orders[0].logisticno, 'REAL-WB-101');
|
||||||
assert.equal(calls.requestArgs.bizcontent.orders[1].logisticno, 'REAL-WB-102');
|
assert.equal(calls.requestArgs.bizcontent.orders[1].logisticno, 'REAL-WB-102');
|
||||||
@ -435,4 +459,28 @@ describe('test/app/service/systems/express_platform.polyapi.test.js', () => {
|
|||||||
assert.equal(result.code, 0);
|
assert.equal(result.code, 0);
|
||||||
assert.equal(result.message, '菠萝派平台数据处理成功');
|
assert.equal(result.message, '菠萝派平台数据处理成功');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('auto_sync_back 开启且无登录用户上下文时,应以显式 warehouseId 触发订单同步回传', async () => {
|
||||||
|
const { calls, service } = createPolyapiHarness();
|
||||||
|
|
||||||
|
await service.polyapi(buildPolyapiPayload());
|
||||||
|
|
||||||
|
assert.equal(calls.getContractConfigCalls.length, 1);
|
||||||
|
assert.deepEqual(calls.getContractConfigCalls[0], { warehouseId: 100000, storeId: 2001 });
|
||||||
|
assert.equal(calls.syncOrderIdsCalls.length, 1);
|
||||||
|
assert.deepEqual(calls.syncOrderIdsCalls[0], {
|
||||||
|
orderIds: [ 101, 102 ],
|
||||||
|
warehouseId: 100000,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('auto_sync_back 关闭时不应触发订单同步回传', async () => {
|
||||||
|
const { calls, service } = createPolyapiHarness({
|
||||||
|
contractConfig: { policy_config: { auto_sync_back: 0 } },
|
||||||
|
});
|
||||||
|
|
||||||
|
await service.polyapi(buildPolyapiPayload());
|
||||||
|
|
||||||
|
assert.equal(calls.syncOrderIdsCalls.length, 0);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user