@pisell/pisellos 2.3.105 → 2.3.107
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/modules/Discount/index.js +4 -1
- package/dist/modules/Discount/types.d.ts +10 -0
- package/dist/modules/OpenData/index.d.ts +15 -2
- package/dist/modules/OpenData/index.js +307 -19
- package/dist/modules/OpenData/types.d.ts +55 -0
- package/dist/modules/OpenData/types.js +7 -1
- package/dist/modules/OpenData/utils.d.ts +21 -1
- package/dist/modules/OpenData/utils.js +138 -0
- package/dist/modules/Order/index.d.ts +3 -1
- package/dist/modules/Order/index.js +89 -16
- package/dist/modules/Order/types.d.ts +13 -0
- package/dist/modules/Order/utils.d.ts +4 -1
- package/dist/modules/Order/utils.js +57 -3
- package/dist/modules/ResourcePlanner/planner.d.ts +2 -2
- package/dist/modules/ResourcePlanner/planner.js +172 -49
- package/dist/modules/ResourcePlanner/types.d.ts +19 -0
- package/dist/modules/Rules/index.js +1 -1
- package/dist/plugins/request.d.ts +2 -1
- package/dist/plugins/request.js +4 -2
- package/dist/server/index.d.ts +15 -0
- package/dist/server/index.js +1734 -1285
- package/dist/server/modules/order/types.d.ts +50 -0
- package/dist/server/modules/order/types.js +2 -0
- package/dist/server/utils/small-ticket.d.ts +4 -1
- package/dist/server/utils/small-ticket.js +461 -96
- package/dist/solution/BaseSales/index.d.ts +5 -1
- package/dist/solution/BaseSales/index.js +120 -45
- package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +2 -0
- package/dist/solution/BaseSales/utils/parseSalesResponse.js +1 -1
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +8 -3
- package/dist/solution/BookingTicket/index.js +558 -443
- package/dist/solution/Sales/index.d.ts +16 -1
- package/dist/solution/Sales/index.js +338 -63
- package/dist/solution/Sales/types.d.ts +10 -0
- package/dist/solution/UnifiedBookingSales/index.d.ts +5 -4
- package/dist/solution/UnifiedBookingSales/index.js +614 -462
- package/dist/solution/UnifiedBookingSales/types.d.ts +7 -1
- package/lib/model/strategy/adapter/promotion/index.js +1 -46
- package/lib/modules/Discount/index.js +4 -1
- package/lib/modules/Discount/types.d.ts +10 -0
- package/lib/modules/OpenData/index.d.ts +15 -2
- package/lib/modules/OpenData/index.js +230 -3
- package/lib/modules/OpenData/types.d.ts +55 -0
- package/lib/modules/OpenData/types.js +9 -1
- package/lib/modules/OpenData/utils.d.ts +21 -1
- package/lib/modules/OpenData/utils.js +126 -0
- package/lib/modules/Order/index.d.ts +3 -1
- package/lib/modules/Order/index.js +69 -1
- package/lib/modules/Order/types.d.ts +13 -0
- package/lib/modules/Order/utils.d.ts +4 -1
- package/lib/modules/Order/utils.js +58 -1
- package/lib/modules/ResourcePlanner/planner.d.ts +2 -2
- package/lib/modules/ResourcePlanner/planner.js +141 -35
- package/lib/modules/ResourcePlanner/types.d.ts +19 -0
- package/lib/modules/Rules/index.js +1 -1
- package/lib/plugins/request.d.ts +2 -1
- package/lib/plugins/request.js +3 -2
- package/lib/server/index.d.ts +15 -0
- package/lib/server/index.js +455 -105
- package/lib/server/modules/order/types.d.ts +50 -0
- package/lib/server/modules/order/types.js +1 -0
- package/lib/server/utils/small-ticket.d.ts +4 -1
- package/lib/server/utils/small-ticket.js +427 -72
- package/lib/solution/BaseSales/index.d.ts +5 -1
- package/lib/solution/BaseSales/index.js +84 -7
- package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +2 -0
- package/lib/solution/BaseSales/utils/parseSalesResponse.js +1 -1
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +8 -3
- package/lib/solution/BookingTicket/index.js +60 -15
- package/lib/solution/Sales/index.d.ts +16 -1
- package/lib/solution/Sales/index.js +168 -1
- package/lib/solution/Sales/types.d.ts +10 -0
- package/lib/solution/UnifiedBookingSales/index.d.ts +5 -4
- package/lib/solution/UnifiedBookingSales/index.js +128 -35
- package/lib/solution/UnifiedBookingSales/types.d.ts +7 -1
- package/package.json +1 -1
package/lib/server/index.js
CHANGED
|
@@ -28,6 +28,8 @@ var _smallTicket = require("./utils/small-ticket");
|
|
|
28
28
|
var _BaseSales = require("../solution/BaseSales");
|
|
29
29
|
var _paymentUtils = require("../modules/Order/payment-utils");
|
|
30
30
|
var _salesNotes = require("../modules/Order/salesNotes");
|
|
31
|
+
var _orderCollectionIdentity = require("../modules/Order/utils/orderCollectionIdentity");
|
|
32
|
+
var _OpenData = require("../modules/OpenData");
|
|
31
33
|
var _modules = require("./modules");
|
|
32
34
|
Object.keys(_modules).forEach(function (key) {
|
|
33
35
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -42,6 +44,8 @@ Object.keys(_modules).forEach(function (key) {
|
|
|
42
44
|
});
|
|
43
45
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
44
46
|
const OS_FULFILLMENT_REF_MODE_FIELD = '_os_fulfillment_ref_mode';
|
|
47
|
+
const OS_INVOICE_LAYOUT_CONFIG_FIELD = '_os_invoice_layout_config';
|
|
48
|
+
const OS_INVOICE_TEMPLATE_SETTINGS_FIELD = '_os_invoice_template_settings';
|
|
45
49
|
|
|
46
50
|
// 重新导出类型供外部使用
|
|
47
51
|
|
|
@@ -573,7 +577,16 @@ class Server {
|
|
|
573
577
|
async handleSyncSalesTask(ctx) {
|
|
574
578
|
const payload = ctx.task?.payload || {};
|
|
575
579
|
const backendPath = payload.backendPath;
|
|
576
|
-
const
|
|
580
|
+
const extractedInvoice = this.extractInvoiceLayoutConfig(payload.data, {
|
|
581
|
+
includePublicInvoice: true
|
|
582
|
+
});
|
|
583
|
+
const extractedTemplateSettings = this.extractInvoiceTemplateSettings(extractedInvoice.data, {
|
|
584
|
+
includePublicTemplateSettings: true
|
|
585
|
+
});
|
|
586
|
+
const data = extractedTemplateSettings.data;
|
|
587
|
+
const rawInvoiceLayoutConfig = payload.invoice ?? extractedInvoice.invoiceLayoutConfig;
|
|
588
|
+
const invoiceLayoutConfig = rawInvoiceLayoutConfig === undefined || rawInvoiceLayoutConfig === null ? undefined : this.normalizePrintInvoiceLayoutConfig(rawInvoiceLayoutConfig);
|
|
589
|
+
const invoiceTemplateSettings = this.normalizePrintInvoiceTemplateSettings(payload.template_settings ?? extractedTemplateSettings.invoiceTemplateSettings);
|
|
577
590
|
const title = payload.title || 'sync_sales';
|
|
578
591
|
if (!backendPath || !data) {
|
|
579
592
|
return this.taskFail('INVALID_PAYLOAD', '缺少 backendPath 或 data');
|
|
@@ -589,7 +602,9 @@ class Server {
|
|
|
589
602
|
title,
|
|
590
603
|
externalSaleNumber: payload.external_sale_number,
|
|
591
604
|
deviceId: ctx.task?.device_id,
|
|
592
|
-
persistCheckoutDataWithResponse: false
|
|
605
|
+
persistCheckoutDataWithResponse: false,
|
|
606
|
+
invoiceLayoutConfig,
|
|
607
|
+
invoiceTemplateSettings
|
|
593
608
|
});
|
|
594
609
|
if (syncResult.rejected) {
|
|
595
610
|
this.logError(`${title}: sync_sales 后端明确失败`, {
|
|
@@ -628,7 +643,7 @@ class Server {
|
|
|
628
643
|
} = params;
|
|
629
644
|
const normalizedData = await this.normalizeCheckoutSubmitData(params.data, title);
|
|
630
645
|
const numberedData = await this.ensureCheckoutOrderNumbers(normalizedData, title);
|
|
631
|
-
const checkoutData = this.applyCheckoutFulfillmentBuzzer(numberedData, title);
|
|
646
|
+
const checkoutData = this.normalizeCheckoutCollections(this.applyCheckoutFulfillmentBuzzer(numberedData, title));
|
|
632
647
|
const remoteCheckoutData = this.buildRemoteCheckoutData(checkoutData, title);
|
|
633
648
|
const deviceHeaders = await this.buildCheckoutDeviceHeaders(title);
|
|
634
649
|
if (!this.app?.request?.post) {
|
|
@@ -676,7 +691,9 @@ class Server {
|
|
|
676
691
|
checkoutData,
|
|
677
692
|
syncedOrder: printableSyncedOrder,
|
|
678
693
|
response,
|
|
679
|
-
deviceId: params.deviceId
|
|
694
|
+
deviceId: params.deviceId,
|
|
695
|
+
invoiceLayoutConfig: params.invoiceLayoutConfig,
|
|
696
|
+
invoiceTemplateSettings: params.invoiceTemplateSettings
|
|
680
697
|
});
|
|
681
698
|
}
|
|
682
699
|
return {
|
|
@@ -702,6 +719,7 @@ class Server {
|
|
|
702
719
|
if (!next || typeof next !== 'object') return next;
|
|
703
720
|
const record = next;
|
|
704
721
|
delete record[OS_FULFILLMENT_REF_MODE_FIELD];
|
|
722
|
+
delete record[OS_INVOICE_LAYOUT_CONFIG_FIELD];
|
|
705
723
|
this.applyKioskCheckoutOperator(record);
|
|
706
724
|
if (!Array.isArray(record.payments)) return next;
|
|
707
725
|
const originalPayments = record.payments;
|
|
@@ -1303,6 +1321,10 @@ class Server {
|
|
|
1303
1321
|
method: 'post',
|
|
1304
1322
|
path: '/shop/local/print-order',
|
|
1305
1323
|
handler: this.handleLocalPrintOrder.bind(this)
|
|
1324
|
+
}, {
|
|
1325
|
+
method: 'post',
|
|
1326
|
+
path: '/shop/local/order-receipt-snapshot',
|
|
1327
|
+
handler: this.handleLocalOrderReceiptSnapshot.bind(this)
|
|
1306
1328
|
}, {
|
|
1307
1329
|
method: 'post',
|
|
1308
1330
|
path: '/shop/local/getLocalPayment',
|
|
@@ -2152,10 +2174,12 @@ class Server {
|
|
|
2152
2174
|
|
|
2153
2175
|
/**
|
|
2154
2176
|
* 预约查询是否走本地:
|
|
2177
|
+
* - 日历周/月/资源视图通过 compact_fields 显式标识,始终走远端;
|
|
2155
2178
|
* - 当 sales_time_between 的开始和结束都不是今天时,走远端;
|
|
2156
2179
|
* - 其余情况走本地。
|
|
2157
2180
|
*/
|
|
2158
2181
|
shouldUseLocalBookingQuery(data) {
|
|
2182
|
+
if (data?.compact_fields === true) return false;
|
|
2159
2183
|
const range = data?.sales_time_between;
|
|
2160
2184
|
if (!Array.isArray(range) || range.length < 2) return true;
|
|
2161
2185
|
return !this.isRangeBothNotToday(range[0], range[1]);
|
|
@@ -3427,6 +3451,80 @@ class Server {
|
|
|
3427
3451
|
isLocalCheckoutOrderId(orderId) {
|
|
3428
3452
|
return typeof orderId === 'string' && orderId.startsWith('LOCAL_');
|
|
3429
3453
|
}
|
|
3454
|
+
normalizePrintInvoiceLayoutConfig(value) {
|
|
3455
|
+
if (value === undefined || value === null) {
|
|
3456
|
+
return (0, _OpenData.getDefaultInvoiceLayoutConfig)();
|
|
3457
|
+
}
|
|
3458
|
+
let parsed = value;
|
|
3459
|
+
if (typeof parsed === 'string') {
|
|
3460
|
+
try {
|
|
3461
|
+
parsed = JSON.parse(parsed);
|
|
3462
|
+
} catch {
|
|
3463
|
+
return (0, _OpenData.getDefaultInvoiceLayoutConfig)();
|
|
3464
|
+
}
|
|
3465
|
+
}
|
|
3466
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
3467
|
+
return (0, _OpenData.getDefaultInvoiceLayoutConfig)();
|
|
3468
|
+
}
|
|
3469
|
+
const record = parsed;
|
|
3470
|
+
if (!Array.isArray(record.module)) {
|
|
3471
|
+
return (0, _OpenData.getDefaultInvoiceLayoutConfig)();
|
|
3472
|
+
}
|
|
3473
|
+
return {
|
|
3474
|
+
...(typeof record.locale === 'string' ? {
|
|
3475
|
+
locale: record.locale
|
|
3476
|
+
} : {}),
|
|
3477
|
+
module: record.module.map(moduleConfig => moduleConfig && typeof moduleConfig === 'object' && !Array.isArray(moduleConfig) ? {
|
|
3478
|
+
...moduleConfig
|
|
3479
|
+
} : moduleConfig)
|
|
3480
|
+
};
|
|
3481
|
+
}
|
|
3482
|
+
extractInvoiceLayoutConfig(data, options) {
|
|
3483
|
+
if (!data || typeof data !== 'object' || Array.isArray(data)) {
|
|
3484
|
+
return {
|
|
3485
|
+
data
|
|
3486
|
+
};
|
|
3487
|
+
}
|
|
3488
|
+
const record = data;
|
|
3489
|
+
const rawInvoiceLayoutConfig = options?.includePublicInvoice ? record.invoice ?? record[OS_INVOICE_LAYOUT_CONFIG_FIELD] : record[OS_INVOICE_LAYOUT_CONFIG_FIELD];
|
|
3490
|
+
const next = {
|
|
3491
|
+
...record
|
|
3492
|
+
};
|
|
3493
|
+
delete next[OS_INVOICE_LAYOUT_CONFIG_FIELD];
|
|
3494
|
+
if (options?.includePublicInvoice) delete next.invoice;
|
|
3495
|
+
return {
|
|
3496
|
+
data: next,
|
|
3497
|
+
...(rawInvoiceLayoutConfig !== undefined && rawInvoiceLayoutConfig !== null ? {
|
|
3498
|
+
invoiceLayoutConfig: this.normalizePrintInvoiceLayoutConfig(rawInvoiceLayoutConfig)
|
|
3499
|
+
} : {})
|
|
3500
|
+
};
|
|
3501
|
+
}
|
|
3502
|
+
normalizePrintInvoiceTemplateSettings(value) {
|
|
3503
|
+
if (value === undefined || value === null) {
|
|
3504
|
+
return (0, _OpenData.getDefaultInvoiceTemplateSettings)();
|
|
3505
|
+
}
|
|
3506
|
+
return (0, _OpenData.normalizeRawInvoiceTemplateSettings)(value);
|
|
3507
|
+
}
|
|
3508
|
+
extractInvoiceTemplateSettings(data, options) {
|
|
3509
|
+
if (!data || typeof data !== 'object' || Array.isArray(data)) {
|
|
3510
|
+
return {
|
|
3511
|
+
data
|
|
3512
|
+
};
|
|
3513
|
+
}
|
|
3514
|
+
const record = data;
|
|
3515
|
+
const rawInvoiceTemplateSettings = options?.includePublicTemplateSettings ? record.template_settings ?? record[OS_INVOICE_TEMPLATE_SETTINGS_FIELD] : record[OS_INVOICE_TEMPLATE_SETTINGS_FIELD];
|
|
3516
|
+
const next = {
|
|
3517
|
+
...record
|
|
3518
|
+
};
|
|
3519
|
+
delete next[OS_INVOICE_TEMPLATE_SETTINGS_FIELD];
|
|
3520
|
+
if (options?.includePublicTemplateSettings) delete next.template_settings;
|
|
3521
|
+
return {
|
|
3522
|
+
data: next,
|
|
3523
|
+
...(rawInvoiceTemplateSettings !== undefined && rawInvoiceTemplateSettings !== null ? {
|
|
3524
|
+
invoiceTemplateSettings: this.normalizePrintInvoiceTemplateSettings(rawInvoiceTemplateSettings)
|
|
3525
|
+
} : {})
|
|
3526
|
+
};
|
|
3527
|
+
}
|
|
3430
3528
|
applyCheckoutFulfillmentBuzzer(data, title) {
|
|
3431
3529
|
if (!data || typeof data !== 'object') return data;
|
|
3432
3530
|
const next = {
|
|
@@ -3668,6 +3766,8 @@ class Server {
|
|
|
3668
3766
|
payload: {
|
|
3669
3767
|
backendPath: params.backendPath,
|
|
3670
3768
|
data: params.data,
|
|
3769
|
+
invoice: this.normalizePrintInvoiceLayoutConfig(params.invoiceLayoutConfig),
|
|
3770
|
+
template_settings: this.normalizePrintInvoiceTemplateSettings(params.invoiceTemplateSettings),
|
|
3671
3771
|
external_sale_number: params.data?.external_sale_number,
|
|
3672
3772
|
title: params.title
|
|
3673
3773
|
},
|
|
@@ -3703,6 +3803,7 @@ class Server {
|
|
|
3703
3803
|
device_id: params.deviceId ?? deviceId,
|
|
3704
3804
|
payload: {
|
|
3705
3805
|
type: params.isManualPrint ? '0' : '99',
|
|
3806
|
+
template_settings: this.normalizePrintInvoiceTemplateSettings(params.invoiceTemplateSettings),
|
|
3706
3807
|
data: params.receiptOnly ? {
|
|
3707
3808
|
order_id: printIdentity,
|
|
3708
3809
|
small_ticket_data: params.syncedOrder?.payment_info?.small_ticket_data,
|
|
@@ -3746,7 +3847,8 @@ class Server {
|
|
|
3746
3847
|
};
|
|
3747
3848
|
}
|
|
3748
3849
|
const printableOrder = await this.withLocalSmallTicketData(params.order, {
|
|
3749
|
-
requireFullyPaid: params.requireFullyPaid
|
|
3850
|
+
requireFullyPaid: params.requireFullyPaid,
|
|
3851
|
+
invoiceTemplateSettings: params.invoiceTemplateSettings
|
|
3750
3852
|
});
|
|
3751
3853
|
if (!(0, _smallTicket.hasSmallTicketData)(printableOrder.payment_info?.small_ticket_data)) {
|
|
3752
3854
|
return {
|
|
@@ -3764,7 +3866,9 @@ class Server {
|
|
|
3764
3866
|
syncedOrder: printableOrder,
|
|
3765
3867
|
response: params.response,
|
|
3766
3868
|
receiptOnly: true,
|
|
3767
|
-
isManualPrint: params.isManualPrint
|
|
3869
|
+
isManualPrint: params.isManualPrint,
|
|
3870
|
+
invoiceLayoutConfig: params.invoiceLayoutConfig,
|
|
3871
|
+
invoiceTemplateSettings: params.invoiceTemplateSettings
|
|
3768
3872
|
});
|
|
3769
3873
|
return {
|
|
3770
3874
|
printed: true,
|
|
@@ -3784,11 +3888,35 @@ class Server {
|
|
|
3784
3888
|
}
|
|
3785
3889
|
return undefined;
|
|
3786
3890
|
}
|
|
3891
|
+
mergeLocalPrintOrderInput(localOrder, inputOrder) {
|
|
3892
|
+
const definedInput = Object.fromEntries(Object.entries(inputOrder || {}).filter(([, value]) => value !== undefined));
|
|
3893
|
+
return {
|
|
3894
|
+
...localOrder,
|
|
3895
|
+
...definedInput,
|
|
3896
|
+
order_id: localOrder.order_id ?? definedInput.order_id ?? definedInput.orderId,
|
|
3897
|
+
external_sale_number: localOrder.external_sale_number ?? definedInput.external_sale_number ?? definedInput.externalSaleNumber
|
|
3898
|
+
};
|
|
3899
|
+
}
|
|
3787
3900
|
handleLocalPrintOrder = async ({
|
|
3788
3901
|
data
|
|
3789
3902
|
}) => {
|
|
3790
3903
|
try {
|
|
3791
|
-
const
|
|
3904
|
+
const extractedRequest = this.extractInvoiceLayoutConfig(data, {
|
|
3905
|
+
includePublicInvoice: true
|
|
3906
|
+
});
|
|
3907
|
+
const extractedRequestTemplateSettings = this.extractInvoiceTemplateSettings(extractedRequest.data, {
|
|
3908
|
+
includePublicTemplateSettings: true
|
|
3909
|
+
});
|
|
3910
|
+
const requestOrder = extractedRequestTemplateSettings.data?.order;
|
|
3911
|
+
const nestedOrder = requestOrder && typeof requestOrder === 'object' ? this.extractInvoiceLayoutConfig(requestOrder, {
|
|
3912
|
+
includePublicInvoice: true
|
|
3913
|
+
}) : null;
|
|
3914
|
+
const nestedOrderTemplateSettings = nestedOrder ? this.extractInvoiceTemplateSettings(nestedOrder.data, {
|
|
3915
|
+
includePublicTemplateSettings: true
|
|
3916
|
+
}) : null;
|
|
3917
|
+
const inputOrder = nestedOrderTemplateSettings?.data ?? extractedRequestTemplateSettings.data;
|
|
3918
|
+
const invoiceLayoutConfig = extractedRequest.invoiceLayoutConfig ?? nestedOrder?.invoiceLayoutConfig;
|
|
3919
|
+
const invoiceTemplateSettings = this.normalizePrintInvoiceTemplateSettings(extractedRequestTemplateSettings.invoiceTemplateSettings ?? nestedOrderTemplateSettings?.invoiceTemplateSettings);
|
|
3792
3920
|
if (!inputOrder || typeof inputOrder !== 'object') {
|
|
3793
3921
|
return {
|
|
3794
3922
|
code: 400,
|
|
@@ -3800,13 +3928,13 @@ class Server {
|
|
|
3800
3928
|
}
|
|
3801
3929
|
};
|
|
3802
3930
|
}
|
|
3803
|
-
const shouldLookup = this.shouldLookupLocalPrintOrder(inputOrder) || this.shouldLookupLocalPrintOrder(data);
|
|
3931
|
+
const shouldLookup = this.shouldLookupLocalPrintOrder(inputOrder) || this.shouldLookupLocalPrintOrder(extractedRequest.data);
|
|
3804
3932
|
this.logInfo('handleLocalPrintOrder: 是否需要查找本地订单', {
|
|
3805
3933
|
shouldLookup,
|
|
3806
3934
|
inputOrder,
|
|
3807
3935
|
data
|
|
3808
3936
|
});
|
|
3809
|
-
const lookup = shouldLookup ? this.getLocalPrintOrderLookup(inputOrder) ?? this.getLocalPrintOrderLookup(data) : undefined;
|
|
3937
|
+
const lookup = shouldLookup ? this.getLocalPrintOrderLookup(inputOrder) ?? this.getLocalPrintOrderLookup(extractedRequest.data) : undefined;
|
|
3810
3938
|
let sourceOrder = inputOrder;
|
|
3811
3939
|
if (shouldLookup) {
|
|
3812
3940
|
if (lookup === undefined) {
|
|
@@ -3831,24 +3959,25 @@ class Server {
|
|
|
3831
3959
|
}
|
|
3832
3960
|
};
|
|
3833
3961
|
}
|
|
3834
|
-
|
|
3962
|
+
let localOrder = await this.order.getLocalOrderByLookup(lookup);
|
|
3835
3963
|
if (!localOrder) {
|
|
3836
|
-
|
|
3837
|
-
|
|
3838
|
-
|
|
3839
|
-
|
|
3840
|
-
|
|
3841
|
-
|
|
3842
|
-
|
|
3843
|
-
|
|
3844
|
-
|
|
3964
|
+
const remoteResult = await this.fetchAndPersistSalesOrderByLookup(lookup, {
|
|
3965
|
+
with: ['all']
|
|
3966
|
+
}, 'handleLocalPrintOrder');
|
|
3967
|
+
if (!remoteResult.order) {
|
|
3968
|
+
return {
|
|
3969
|
+
code: remoteResult.code,
|
|
3970
|
+
status: false,
|
|
3971
|
+
message: remoteResult.message,
|
|
3972
|
+
data: {
|
|
3973
|
+
printed: false,
|
|
3974
|
+
order: null
|
|
3975
|
+
}
|
|
3976
|
+
};
|
|
3977
|
+
}
|
|
3978
|
+
localOrder = remoteResult.order;
|
|
3845
3979
|
}
|
|
3846
|
-
sourceOrder =
|
|
3847
|
-
...localOrder,
|
|
3848
|
-
...inputOrder,
|
|
3849
|
-
order_id: localOrder.order_id ?? inputOrder.order_id ?? inputOrder.orderId,
|
|
3850
|
-
external_sale_number: localOrder.external_sale_number ?? inputOrder.external_sale_number ?? inputOrder.externalSaleNumber
|
|
3851
|
-
};
|
|
3980
|
+
sourceOrder = this.mergeLocalPrintOrderInput(localOrder, inputOrder);
|
|
3852
3981
|
}
|
|
3853
3982
|
const checkoutData = await this.ensureCheckoutOrderNumbers({
|
|
3854
3983
|
...sourceOrder,
|
|
@@ -3867,7 +3996,9 @@ class Server {
|
|
|
3867
3996
|
order: printableOrder,
|
|
3868
3997
|
response: null,
|
|
3869
3998
|
requireFullyPaid: false,
|
|
3870
|
-
isManualPrint: true
|
|
3999
|
+
isManualPrint: true,
|
|
4000
|
+
invoiceLayoutConfig,
|
|
4001
|
+
invoiceTemplateSettings
|
|
3871
4002
|
});
|
|
3872
4003
|
return {
|
|
3873
4004
|
code: 200,
|
|
@@ -3894,6 +4025,99 @@ class Server {
|
|
|
3894
4025
|
};
|
|
3895
4026
|
}
|
|
3896
4027
|
};
|
|
4028
|
+
normalizeRequestedReceiptLocales(value) {
|
|
4029
|
+
if (!Array.isArray(value)) return [];
|
|
4030
|
+
return Array.from(new Set(value.filter(locale => typeof locale === 'string').map(locale => locale.trim()).filter(Boolean)));
|
|
4031
|
+
}
|
|
4032
|
+
handleLocalOrderReceiptSnapshot = async ({
|
|
4033
|
+
data
|
|
4034
|
+
}) => {
|
|
4035
|
+
const input = data && typeof data === 'object' && !Array.isArray(data) ? data : {};
|
|
4036
|
+
const lookup = this.getLocalPrintOrderLookup(input);
|
|
4037
|
+
if (lookup === undefined) {
|
|
4038
|
+
return {
|
|
4039
|
+
code: 400,
|
|
4040
|
+
status: false,
|
|
4041
|
+
message: '订单 lookup 缺失',
|
|
4042
|
+
data: {
|
|
4043
|
+
small_ticket_data: null
|
|
4044
|
+
}
|
|
4045
|
+
};
|
|
4046
|
+
}
|
|
4047
|
+
if (!this.order?.getLocalOrderByLookup) {
|
|
4048
|
+
return {
|
|
4049
|
+
code: 500,
|
|
4050
|
+
status: false,
|
|
4051
|
+
message: 'Order 模块未注册',
|
|
4052
|
+
data: {
|
|
4053
|
+
small_ticket_data: null
|
|
4054
|
+
}
|
|
4055
|
+
};
|
|
4056
|
+
}
|
|
4057
|
+
try {
|
|
4058
|
+
let sourceOrder = await this.order.getLocalOrderByLookup(lookup);
|
|
4059
|
+
if (!sourceOrder) {
|
|
4060
|
+
const remoteResult = await this.fetchAndPersistSalesOrderByLookup(lookup, {
|
|
4061
|
+
with: ['all']
|
|
4062
|
+
}, 'handleLocalOrderReceiptSnapshot');
|
|
4063
|
+
if (!remoteResult.order) {
|
|
4064
|
+
return {
|
|
4065
|
+
code: remoteResult.code,
|
|
4066
|
+
status: false,
|
|
4067
|
+
message: remoteResult.message,
|
|
4068
|
+
data: {
|
|
4069
|
+
small_ticket_data: null
|
|
4070
|
+
}
|
|
4071
|
+
};
|
|
4072
|
+
}
|
|
4073
|
+
sourceOrder = remoteResult.order;
|
|
4074
|
+
}
|
|
4075
|
+
const paymentInfo = {
|
|
4076
|
+
...(sourceOrder.payment_info || {})
|
|
4077
|
+
};
|
|
4078
|
+
delete paymentInfo.small_ticket_data;
|
|
4079
|
+
const rebuiltOrder = await this.withLocalSmallTicketData({
|
|
4080
|
+
...sourceOrder,
|
|
4081
|
+
small_ticket_data_flag: 1,
|
|
4082
|
+
payment_info: paymentInfo
|
|
4083
|
+
}, {
|
|
4084
|
+
locales: this.normalizeRequestedReceiptLocales(input.locales)
|
|
4085
|
+
});
|
|
4086
|
+
const smallTicketData = rebuiltOrder.payment_info?.small_ticket_data;
|
|
4087
|
+
if (!(0, _smallTicket.hasSmallTicketData)(smallTicketData)) {
|
|
4088
|
+
return {
|
|
4089
|
+
code: 500,
|
|
4090
|
+
status: false,
|
|
4091
|
+
message: '本地小票 Snapshot 生成失败',
|
|
4092
|
+
data: {
|
|
4093
|
+
small_ticket_data: null
|
|
4094
|
+
}
|
|
4095
|
+
};
|
|
4096
|
+
}
|
|
4097
|
+
return {
|
|
4098
|
+
code: 200,
|
|
4099
|
+
status: true,
|
|
4100
|
+
message: '',
|
|
4101
|
+
data: {
|
|
4102
|
+
small_ticket_data: smallTicketData
|
|
4103
|
+
}
|
|
4104
|
+
};
|
|
4105
|
+
} catch (error) {
|
|
4106
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
4107
|
+
this.logError('handleLocalOrderReceiptSnapshot: 生成失败', {
|
|
4108
|
+
lookup,
|
|
4109
|
+
error: message
|
|
4110
|
+
});
|
|
4111
|
+
return {
|
|
4112
|
+
code: 500,
|
|
4113
|
+
status: false,
|
|
4114
|
+
message,
|
|
4115
|
+
data: {
|
|
4116
|
+
small_ticket_data: null
|
|
4117
|
+
}
|
|
4118
|
+
};
|
|
4119
|
+
}
|
|
4120
|
+
};
|
|
3897
4121
|
handleMachinecodeBatchMeta = async ({
|
|
3898
4122
|
data
|
|
3899
4123
|
}) => {
|
|
@@ -4078,9 +4302,17 @@ class Server {
|
|
|
4078
4302
|
async handleOrderCheckoutSubmit(params) {
|
|
4079
4303
|
const {
|
|
4080
4304
|
backendPath,
|
|
4081
|
-
data,
|
|
4082
4305
|
title
|
|
4083
4306
|
} = params;
|
|
4307
|
+
const extractedInvoice = this.extractInvoiceLayoutConfig(params.data, {
|
|
4308
|
+
includePublicInvoice: true
|
|
4309
|
+
});
|
|
4310
|
+
const extractedTemplateSettings = this.extractInvoiceTemplateSettings(extractedInvoice.data, {
|
|
4311
|
+
includePublicTemplateSettings: true
|
|
4312
|
+
});
|
|
4313
|
+
const data = extractedTemplateSettings.data;
|
|
4314
|
+
const invoiceLayoutConfig = extractedInvoice.invoiceLayoutConfig;
|
|
4315
|
+
const invoiceTemplateSettings = this.normalizePrintInvoiceTemplateSettings(extractedTemplateSettings.invoiceTemplateSettings);
|
|
4084
4316
|
this.logInfo(`${title}: 开始处理`, {
|
|
4085
4317
|
backendPath,
|
|
4086
4318
|
order_id: data?.order_id,
|
|
@@ -4091,17 +4323,20 @@ class Server {
|
|
|
4091
4323
|
return this.handleSyncCheckoutSubmit({
|
|
4092
4324
|
backendPath,
|
|
4093
4325
|
data,
|
|
4094
|
-
title
|
|
4326
|
+
title,
|
|
4327
|
+
invoiceLayoutConfig,
|
|
4328
|
+
invoiceTemplateSettings
|
|
4095
4329
|
});
|
|
4096
4330
|
}
|
|
4097
4331
|
const normalizedData = await this.normalizeCheckoutSubmitData(data, title);
|
|
4098
4332
|
const numberedData = await this.ensureCheckoutOrderNumbers(normalizedData, title);
|
|
4099
|
-
const checkoutData = this.applyCheckoutFulfillmentBuzzer(numberedData, title);
|
|
4333
|
+
const checkoutData = this.normalizeCheckoutCollections(this.applyCheckoutFulfillmentBuzzer(numberedData, title));
|
|
4100
4334
|
const pendingResult = await this.handlePendingSyncCheckoutOrder({
|
|
4101
4335
|
backendPath,
|
|
4102
4336
|
data: checkoutData,
|
|
4103
4337
|
title,
|
|
4104
|
-
reason: 'checkout 已转入设备任务同步'
|
|
4338
|
+
reason: 'checkout 已转入设备任务同步',
|
|
4339
|
+
invoiceTemplateSettings
|
|
4105
4340
|
});
|
|
4106
4341
|
if (pendingResult?.status === true) {
|
|
4107
4342
|
const pendingOrder = pendingResult.data;
|
|
@@ -4110,13 +4345,17 @@ class Server {
|
|
|
4110
4345
|
checkoutData,
|
|
4111
4346
|
order: pendingOrder,
|
|
4112
4347
|
response: pendingResult,
|
|
4113
|
-
requireFullyPaid: true
|
|
4348
|
+
requireFullyPaid: true,
|
|
4349
|
+
invoiceLayoutConfig,
|
|
4350
|
+
invoiceTemplateSettings
|
|
4114
4351
|
});
|
|
4115
4352
|
}
|
|
4116
4353
|
await this.dispatchCheckoutSyncTask({
|
|
4117
4354
|
backendPath,
|
|
4118
4355
|
data: checkoutData,
|
|
4119
|
-
title
|
|
4356
|
+
title,
|
|
4357
|
+
invoiceLayoutConfig,
|
|
4358
|
+
invoiceTemplateSettings
|
|
4120
4359
|
});
|
|
4121
4360
|
}
|
|
4122
4361
|
if (!pendingResult.data.order_id) {
|
|
@@ -4134,7 +4373,9 @@ class Server {
|
|
|
4134
4373
|
const {
|
|
4135
4374
|
backendPath,
|
|
4136
4375
|
data,
|
|
4137
|
-
title
|
|
4376
|
+
title,
|
|
4377
|
+
invoiceLayoutConfig,
|
|
4378
|
+
invoiceTemplateSettings
|
|
4138
4379
|
} = params;
|
|
4139
4380
|
if (!this.app?.request?.post) {
|
|
4140
4381
|
this.logError(`${title}: sync checkout app.request 不可用`);
|
|
@@ -4150,7 +4391,9 @@ class Server {
|
|
|
4150
4391
|
backendPath,
|
|
4151
4392
|
data,
|
|
4152
4393
|
title,
|
|
4153
|
-
persistCheckoutDataWithResponse: true
|
|
4394
|
+
persistCheckoutDataWithResponse: true,
|
|
4395
|
+
invoiceLayoutConfig,
|
|
4396
|
+
invoiceTemplateSettings
|
|
4154
4397
|
});
|
|
4155
4398
|
if (syncResult.rejected) {
|
|
4156
4399
|
const normalized = this.normalizeCheckoutResponse(syncResult.errorResponse);
|
|
@@ -4168,7 +4411,9 @@ class Server {
|
|
|
4168
4411
|
checkoutData: syncResult.checkoutData,
|
|
4169
4412
|
order: syncedOrder,
|
|
4170
4413
|
response: syncResult.normalizedResponse,
|
|
4171
|
-
requireFullyPaid: true
|
|
4414
|
+
requireFullyPaid: true,
|
|
4415
|
+
invoiceLayoutConfig,
|
|
4416
|
+
invoiceTemplateSettings
|
|
4172
4417
|
// print_all 的 type=0 是收据打印;不要沿用同步成功后的券/手环打印 type=99。
|
|
4173
4418
|
});
|
|
4174
4419
|
}
|
|
@@ -4200,9 +4445,16 @@ class Server {
|
|
|
4200
4445
|
}
|
|
4201
4446
|
async handleOrderDraftSubmit(params) {
|
|
4202
4447
|
const {
|
|
4203
|
-
data,
|
|
4204
4448
|
title
|
|
4205
4449
|
} = params;
|
|
4450
|
+
const extractedInvoice = this.extractInvoiceLayoutConfig(params.data, {
|
|
4451
|
+
includePublicInvoice: true
|
|
4452
|
+
});
|
|
4453
|
+
const {
|
|
4454
|
+
data
|
|
4455
|
+
} = this.extractInvoiceTemplateSettings(extractedInvoice.data, {
|
|
4456
|
+
includePublicTemplateSettings: true
|
|
4457
|
+
});
|
|
4206
4458
|
this.logInfo(`${title}: 开始处理`, {
|
|
4207
4459
|
order_id: data?.order_id,
|
|
4208
4460
|
external_sale_number: data?.external_sale_number,
|
|
@@ -4263,9 +4515,10 @@ class Server {
|
|
|
4263
4515
|
backendPath,
|
|
4264
4516
|
data,
|
|
4265
4517
|
title,
|
|
4266
|
-
reason
|
|
4518
|
+
reason,
|
|
4519
|
+
invoiceTemplateSettings
|
|
4267
4520
|
} = params;
|
|
4268
|
-
const pendingOrder = await this.buildPendingSyncCheckoutOrder(data);
|
|
4521
|
+
const pendingOrder = await this.buildPendingSyncCheckoutOrder(data, invoiceTemplateSettings);
|
|
4269
4522
|
if (!pendingOrder) {
|
|
4270
4523
|
this.logError(`${title}: checkout 失败且订单缺少本地存储标识`, {
|
|
4271
4524
|
backendPath,
|
|
@@ -4331,23 +4584,39 @@ class Server {
|
|
|
4331
4584
|
};
|
|
4332
4585
|
}
|
|
4333
4586
|
}
|
|
4334
|
-
async buildPendingSyncCheckoutOrder(data) {
|
|
4587
|
+
async buildPendingSyncCheckoutOrder(data, invoiceTemplateSettings) {
|
|
4335
4588
|
if (!data || typeof data !== 'object') return null;
|
|
4336
4589
|
const hasStorageKey = data.external_sale_number !== undefined && data.external_sale_number !== null && data.external_sale_number !== '' ? true : data.order_id !== undefined && data.order_id !== null && data.order_id !== '';
|
|
4337
4590
|
if (!hasStorageKey) return null;
|
|
4338
|
-
const pendingOrder = {
|
|
4591
|
+
const pendingOrder = this.normalizeCheckoutCollections({
|
|
4339
4592
|
...data,
|
|
4340
4593
|
need_sync: 1,
|
|
4341
4594
|
is_draft_order: 0
|
|
4342
|
-
};
|
|
4595
|
+
});
|
|
4343
4596
|
const productMap = await this.buildSmallTicketProductMap(pendingOrder);
|
|
4344
4597
|
const orderWithProductTitles = this.withPendingSyncProductTitles(pendingOrder, productMap);
|
|
4345
4598
|
return this.withLocalSmallTicketData(orderWithProductTitles, {
|
|
4346
4599
|
requireFullyPaid: true,
|
|
4347
|
-
productMap
|
|
4600
|
+
productMap,
|
|
4601
|
+
invoiceTemplateSettings
|
|
4348
4602
|
});
|
|
4349
4603
|
}
|
|
4350
4604
|
|
|
4605
|
+
/**
|
|
4606
|
+
* Checkout 与本地小票必须消费同一份规范化子项快照。
|
|
4607
|
+
* 商品/预约只折叠持久化 ID 或协议 UID 相同的行;支付额外兼容 payment_number。
|
|
4608
|
+
*/
|
|
4609
|
+
normalizeCheckoutCollections(data) {
|
|
4610
|
+
if (!data || typeof data !== 'object' || Array.isArray(data)) return data;
|
|
4611
|
+
const normalized = (0, _orderCollectionIdentity.normalizeOrderCollections)(data, {
|
|
4612
|
+
ensureUid: false
|
|
4613
|
+
}).order;
|
|
4614
|
+
if (Array.isArray(normalized.payments)) {
|
|
4615
|
+
normalized.payments = (0, _paymentUtils.mergeOrderPaymentListsByIdentity)([], normalized.payments);
|
|
4616
|
+
}
|
|
4617
|
+
return normalized;
|
|
4618
|
+
}
|
|
4619
|
+
|
|
4351
4620
|
/**
|
|
4352
4621
|
* Android 结账自动小票由当前设备设置控制;其它平台保持原有行为。
|
|
4353
4622
|
*/
|
|
@@ -4665,11 +4934,27 @@ class Server {
|
|
|
4665
4934
|
if (!this.shouldBuildSmallTicketData(order)) return order;
|
|
4666
4935
|
if (options?.requireFullyPaid && !this.isSalesOrderFullyPaid(order)) return order;
|
|
4667
4936
|
try {
|
|
4668
|
-
const
|
|
4937
|
+
const normalizedCollections = (0, _orderCollectionIdentity.normalizeOrderCollections)(order, {
|
|
4938
|
+
ensureUid: false
|
|
4939
|
+
});
|
|
4940
|
+
const normalizedOrder = normalizedCollections.order;
|
|
4941
|
+
const collapsedDuplicateCounts = {
|
|
4942
|
+
products: normalizedCollections.stats.product.collapsedDuplicateCount,
|
|
4943
|
+
bookings: normalizedCollections.stats.booking.collapsedDuplicateCount,
|
|
4944
|
+
payments: normalizedCollections.stats.payment.collapsedDuplicateCount
|
|
4945
|
+
};
|
|
4946
|
+
if (Object.values(collapsedDuplicateCounts).some(count => count > 0)) {
|
|
4947
|
+
this.logWarning('withLocalSmallTicketData: 折叠重复订单子项', {
|
|
4948
|
+
order_identifier: normalizedOrder.order_id ?? normalizedOrder.external_sale_number ?? normalizedOrder.shop_order_number ?? null,
|
|
4949
|
+
collapsed_duplicate_counts: collapsedDuplicateCounts
|
|
4950
|
+
});
|
|
4951
|
+
}
|
|
4952
|
+
const enrichedOrder = await this.enrichPaymentNamesByCode(normalizedOrder);
|
|
4669
4953
|
const productMap = options?.productMap ?? (await this.buildSmallTicketProductMap(enrichedOrder));
|
|
4670
4954
|
const smallTicketData = (0, _smallTicket.buildSmallTicketData)({
|
|
4671
4955
|
order: enrichedOrder,
|
|
4672
4956
|
shopInfo: this.getSmallTicketShopInfo(),
|
|
4957
|
+
locales: [...(0, _OpenData.resolveInvoiceReceiptLocales)(options?.invoiceTemplateSettings), ...(options?.locales || [])],
|
|
4673
4958
|
productMap
|
|
4674
4959
|
});
|
|
4675
4960
|
return {
|
|
@@ -4686,6 +4971,122 @@ class Server {
|
|
|
4686
4971
|
return order;
|
|
4687
4972
|
}
|
|
4688
4973
|
}
|
|
4974
|
+
normalizeRemoteSalesOrderErrorCode(value) {
|
|
4975
|
+
if (value === undefined || value === null || value === '') return 500;
|
|
4976
|
+
const code = typeof value === 'number' ? value : Number(value);
|
|
4977
|
+
return Number.isFinite(code) ? code : 500;
|
|
4978
|
+
}
|
|
4979
|
+
async fetchAndPersistSalesOrderByLookup(lookup, data, title) {
|
|
4980
|
+
if (!this.order?.getLocalOrderByLookup || !this.order?.upsertOrdersFromRemote) {
|
|
4981
|
+
this.logError(`${title}: Order 模块未注册`);
|
|
4982
|
+
return {
|
|
4983
|
+
code: 500,
|
|
4984
|
+
message: 'Order 模块未注册',
|
|
4985
|
+
order: null
|
|
4986
|
+
};
|
|
4987
|
+
}
|
|
4988
|
+
if (!this.app?.request?.get) {
|
|
4989
|
+
this.logError(`${title}: app.request 不可用`);
|
|
4990
|
+
return {
|
|
4991
|
+
code: 500,
|
|
4992
|
+
message: 'app.request 不可用',
|
|
4993
|
+
order: null
|
|
4994
|
+
};
|
|
4995
|
+
}
|
|
4996
|
+
const backendPath = this.buildOrderSalesDetailBackendPath(String(lookup), data);
|
|
4997
|
+
try {
|
|
4998
|
+
const response = await this.app.request.get(backendPath, {
|
|
4999
|
+
lookup_mode: 'multi'
|
|
5000
|
+
}, {
|
|
5001
|
+
isShopApi: true,
|
|
5002
|
+
customToast: () => {}
|
|
5003
|
+
});
|
|
5004
|
+
if (this.isCheckoutResponseRejected(response)) {
|
|
5005
|
+
const responseStatusCode = typeof response?.status === 'number' ? response.status : undefined;
|
|
5006
|
+
const code = this.normalizeRemoteSalesOrderErrorCode(response?.code ?? responseStatusCode);
|
|
5007
|
+
const message = response?.message || '后端拒绝订单查询';
|
|
5008
|
+
this.logInfo(`${title}: 后端拒绝订单查询`, {
|
|
5009
|
+
lookup,
|
|
5010
|
+
backendPath,
|
|
5011
|
+
code,
|
|
5012
|
+
message
|
|
5013
|
+
});
|
|
5014
|
+
return {
|
|
5015
|
+
code,
|
|
5016
|
+
message,
|
|
5017
|
+
order: null
|
|
5018
|
+
};
|
|
5019
|
+
}
|
|
5020
|
+
const fresh = this.extractOrderDataFromCheckoutResponse(response);
|
|
5021
|
+
if (!fresh || fresh.order_id === undefined || fresh.order_id === null || String(fresh.order_id).trim() === '') {
|
|
5022
|
+
this.logInfo(`${title}: 后端返回订单为空`, {
|
|
5023
|
+
lookup,
|
|
5024
|
+
backendPath
|
|
5025
|
+
});
|
|
5026
|
+
return {
|
|
5027
|
+
code: 500,
|
|
5028
|
+
message: '后端返回订单为空',
|
|
5029
|
+
order: null
|
|
5030
|
+
};
|
|
5031
|
+
}
|
|
5032
|
+
await this.order.upsertOrdersFromRemote([fresh]);
|
|
5033
|
+
let savedOrder = await this.order.getLocalOrderByLookup(lookup);
|
|
5034
|
+
if (!savedOrder && fresh.order_id !== undefined && fresh.order_id !== null && String(fresh.order_id) !== String(lookup)) {
|
|
5035
|
+
savedOrder = await this.order.getLocalOrderByLookup(fresh.order_id);
|
|
5036
|
+
}
|
|
5037
|
+
if (!savedOrder) {
|
|
5038
|
+
this.logError(`${title}: 订单写入后回读失败`, {
|
|
5039
|
+
lookup,
|
|
5040
|
+
remote_order_id: fresh.order_id
|
|
5041
|
+
});
|
|
5042
|
+
return {
|
|
5043
|
+
code: 500,
|
|
5044
|
+
message: '订单写入后回读失败',
|
|
5045
|
+
order: null
|
|
5046
|
+
};
|
|
5047
|
+
}
|
|
5048
|
+
this.logInfo(`${title}: 远端订单已同步到本地`, {
|
|
5049
|
+
lookup,
|
|
5050
|
+
remote_order_id: fresh.order_id
|
|
5051
|
+
});
|
|
5052
|
+
return {
|
|
5053
|
+
code: 200,
|
|
5054
|
+
message: '',
|
|
5055
|
+
order: savedOrder
|
|
5056
|
+
};
|
|
5057
|
+
} catch (error) {
|
|
5058
|
+
const backendError = this.extractBackendErrorResponse(error);
|
|
5059
|
+
const errorRecord = error;
|
|
5060
|
+
const responseStatusCode = typeof errorRecord?.response?.status === 'number' ? errorRecord.response.status : undefined;
|
|
5061
|
+
if (backendError || responseStatusCode !== undefined) {
|
|
5062
|
+
const backendStatusCode = typeof backendError?.status === 'number' ? backendError.status : undefined;
|
|
5063
|
+
const code = this.normalizeRemoteSalesOrderErrorCode(backendError?.code ?? backendStatusCode ?? responseStatusCode);
|
|
5064
|
+
const message = backendError?.message || this.getUnknownErrorMessage(error);
|
|
5065
|
+
this.logInfo(`${title}: 后端订单查询失败`, {
|
|
5066
|
+
lookup,
|
|
5067
|
+
backendPath,
|
|
5068
|
+
code,
|
|
5069
|
+
message
|
|
5070
|
+
});
|
|
5071
|
+
return {
|
|
5072
|
+
code,
|
|
5073
|
+
message,
|
|
5074
|
+
order: null
|
|
5075
|
+
};
|
|
5076
|
+
}
|
|
5077
|
+
const message = this.getUnknownErrorMessage(error);
|
|
5078
|
+
this.logInfo(`${title}: 请求失败`, {
|
|
5079
|
+
lookup,
|
|
5080
|
+
backendPath,
|
|
5081
|
+
error: message
|
|
5082
|
+
});
|
|
5083
|
+
return {
|
|
5084
|
+
code: 500,
|
|
5085
|
+
message,
|
|
5086
|
+
order: null
|
|
5087
|
+
};
|
|
5088
|
+
}
|
|
5089
|
+
}
|
|
4689
5090
|
handleOrderSalesDetail = async ({
|
|
4690
5091
|
url,
|
|
4691
5092
|
data,
|
|
@@ -4734,73 +5135,22 @@ class Server {
|
|
|
4734
5135
|
};
|
|
4735
5136
|
}
|
|
4736
5137
|
}
|
|
4737
|
-
|
|
4738
|
-
|
|
4739
|
-
return {
|
|
4740
|
-
code: 500,
|
|
4741
|
-
status: false,
|
|
4742
|
-
message: 'app.request 不可用',
|
|
4743
|
-
data: null
|
|
4744
|
-
};
|
|
4745
|
-
}
|
|
4746
|
-
const backendPath = this.buildOrderSalesDetailBackendPath(lookup, data);
|
|
4747
|
-
try {
|
|
4748
|
-
const response = await this.app.request.get(backendPath, {
|
|
4749
|
-
lookup_mode: 'multi'
|
|
4750
|
-
}, {
|
|
4751
|
-
isShopApi: true,
|
|
4752
|
-
customToast: () => {}
|
|
4753
|
-
});
|
|
4754
|
-
const fresh = response?.data ?? response;
|
|
4755
|
-
if (!fresh || typeof fresh !== 'object' || fresh.order_id == null) {
|
|
4756
|
-
this.logInfo('handleOrderSalesDetail: 后端返回订单为空', {
|
|
4757
|
-
lookup,
|
|
4758
|
-
backendPath
|
|
4759
|
-
});
|
|
4760
|
-
return {
|
|
4761
|
-
code: 500,
|
|
4762
|
-
status: false,
|
|
4763
|
-
message: '后端返回订单为空',
|
|
4764
|
-
data: null
|
|
4765
|
-
};
|
|
4766
|
-
}
|
|
4767
|
-
await this.order.upsertOrdersFromRemote([fresh]);
|
|
4768
|
-
const savedOrder = await this.order.getLocalOrderByLookup(lookup);
|
|
4769
|
-
if (!savedOrder) {
|
|
4770
|
-
this.logError('handleOrderSalesDetail: 订单写入后回读失败', {
|
|
4771
|
-
lookup
|
|
4772
|
-
});
|
|
4773
|
-
return {
|
|
4774
|
-
code: 500,
|
|
4775
|
-
status: false,
|
|
4776
|
-
message: '订单写入后回读失败',
|
|
4777
|
-
data: null
|
|
4778
|
-
};
|
|
4779
|
-
}
|
|
4780
|
-
this.logInfo('handleOrderSalesDetail: 远端订单已同步到本地', {
|
|
4781
|
-
lookup
|
|
4782
|
-
});
|
|
4783
|
-
const enrichedOrder = await this.withSalesDetailProductSnapshots(savedOrder);
|
|
5138
|
+
const remoteResult = await this.fetchAndPersistSalesOrderByLookup(lookup, data, 'handleOrderSalesDetail');
|
|
5139
|
+
if (!remoteResult.order) {
|
|
4784
5140
|
return {
|
|
4785
|
-
code:
|
|
4786
|
-
status: true,
|
|
4787
|
-
message: '',
|
|
4788
|
-
data: enrichedOrder
|
|
4789
|
-
};
|
|
4790
|
-
} catch (error) {
|
|
4791
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
4792
|
-
this.logInfo('handleOrderSalesDetail: 请求失败', {
|
|
4793
|
-
lookup,
|
|
4794
|
-
backendPath,
|
|
4795
|
-
error: errorMessage
|
|
4796
|
-
});
|
|
4797
|
-
return {
|
|
4798
|
-
code: 500,
|
|
5141
|
+
code: remoteResult.code,
|
|
4799
5142
|
status: false,
|
|
4800
|
-
message:
|
|
5143
|
+
message: remoteResult.message,
|
|
4801
5144
|
data: null
|
|
4802
5145
|
};
|
|
4803
5146
|
}
|
|
5147
|
+
const enrichedOrder = await this.withSalesDetailProductSnapshots(remoteResult.order);
|
|
5148
|
+
return {
|
|
5149
|
+
code: 200,
|
|
5150
|
+
status: true,
|
|
5151
|
+
message: '',
|
|
5152
|
+
data: enrichedOrder
|
|
5153
|
+
};
|
|
4804
5154
|
};
|
|
4805
5155
|
|
|
4806
5156
|
/**
|