@pisell/pisellos 2.3.106 → 2.3.108
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 +4 -2
- package/dist/modules/Order/index.js +69 -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/plugins/request.d.ts +2 -1
- package/dist/plugins/request.js +4 -2
- package/dist/server/index.d.ts +14 -0
- package/dist/server/index.js +1732 -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 +7 -1
- package/dist/solution/BaseSales/index.js +128 -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 +526 -447
- package/dist/solution/UnifiedBookingSales/types.d.ts +7 -1
- 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 +4 -2
- package/lib/modules/Order/index.js +52 -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/plugins/request.d.ts +2 -1
- package/lib/plugins/request.js +3 -2
- package/lib/server/index.d.ts +14 -0
- package/lib/server/index.js +453 -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 +7 -1
- package/lib/solution/BaseSales/index.js +90 -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 +44 -15
- 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',
|
|
@@ -3429,6 +3451,80 @@ class Server {
|
|
|
3429
3451
|
isLocalCheckoutOrderId(orderId) {
|
|
3430
3452
|
return typeof orderId === 'string' && orderId.startsWith('LOCAL_');
|
|
3431
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
|
+
}
|
|
3432
3528
|
applyCheckoutFulfillmentBuzzer(data, title) {
|
|
3433
3529
|
if (!data || typeof data !== 'object') return data;
|
|
3434
3530
|
const next = {
|
|
@@ -3670,6 +3766,8 @@ class Server {
|
|
|
3670
3766
|
payload: {
|
|
3671
3767
|
backendPath: params.backendPath,
|
|
3672
3768
|
data: params.data,
|
|
3769
|
+
invoice: this.normalizePrintInvoiceLayoutConfig(params.invoiceLayoutConfig),
|
|
3770
|
+
template_settings: this.normalizePrintInvoiceTemplateSettings(params.invoiceTemplateSettings),
|
|
3673
3771
|
external_sale_number: params.data?.external_sale_number,
|
|
3674
3772
|
title: params.title
|
|
3675
3773
|
},
|
|
@@ -3705,6 +3803,7 @@ class Server {
|
|
|
3705
3803
|
device_id: params.deviceId ?? deviceId,
|
|
3706
3804
|
payload: {
|
|
3707
3805
|
type: params.isManualPrint ? '0' : '99',
|
|
3806
|
+
template_settings: this.normalizePrintInvoiceTemplateSettings(params.invoiceTemplateSettings),
|
|
3708
3807
|
data: params.receiptOnly ? {
|
|
3709
3808
|
order_id: printIdentity,
|
|
3710
3809
|
small_ticket_data: params.syncedOrder?.payment_info?.small_ticket_data,
|
|
@@ -3748,7 +3847,8 @@ class Server {
|
|
|
3748
3847
|
};
|
|
3749
3848
|
}
|
|
3750
3849
|
const printableOrder = await this.withLocalSmallTicketData(params.order, {
|
|
3751
|
-
requireFullyPaid: params.requireFullyPaid
|
|
3850
|
+
requireFullyPaid: params.requireFullyPaid,
|
|
3851
|
+
invoiceTemplateSettings: params.invoiceTemplateSettings
|
|
3752
3852
|
});
|
|
3753
3853
|
if (!(0, _smallTicket.hasSmallTicketData)(printableOrder.payment_info?.small_ticket_data)) {
|
|
3754
3854
|
return {
|
|
@@ -3766,7 +3866,9 @@ class Server {
|
|
|
3766
3866
|
syncedOrder: printableOrder,
|
|
3767
3867
|
response: params.response,
|
|
3768
3868
|
receiptOnly: true,
|
|
3769
|
-
isManualPrint: params.isManualPrint
|
|
3869
|
+
isManualPrint: params.isManualPrint,
|
|
3870
|
+
invoiceLayoutConfig: params.invoiceLayoutConfig,
|
|
3871
|
+
invoiceTemplateSettings: params.invoiceTemplateSettings
|
|
3770
3872
|
});
|
|
3771
3873
|
return {
|
|
3772
3874
|
printed: true,
|
|
@@ -3786,11 +3888,35 @@ class Server {
|
|
|
3786
3888
|
}
|
|
3787
3889
|
return undefined;
|
|
3788
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
|
+
}
|
|
3789
3900
|
handleLocalPrintOrder = async ({
|
|
3790
3901
|
data
|
|
3791
3902
|
}) => {
|
|
3792
3903
|
try {
|
|
3793
|
-
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);
|
|
3794
3920
|
if (!inputOrder || typeof inputOrder !== 'object') {
|
|
3795
3921
|
return {
|
|
3796
3922
|
code: 400,
|
|
@@ -3802,13 +3928,13 @@ class Server {
|
|
|
3802
3928
|
}
|
|
3803
3929
|
};
|
|
3804
3930
|
}
|
|
3805
|
-
const shouldLookup = this.shouldLookupLocalPrintOrder(inputOrder) || this.shouldLookupLocalPrintOrder(data);
|
|
3931
|
+
const shouldLookup = this.shouldLookupLocalPrintOrder(inputOrder) || this.shouldLookupLocalPrintOrder(extractedRequest.data);
|
|
3806
3932
|
this.logInfo('handleLocalPrintOrder: 是否需要查找本地订单', {
|
|
3807
3933
|
shouldLookup,
|
|
3808
3934
|
inputOrder,
|
|
3809
3935
|
data
|
|
3810
3936
|
});
|
|
3811
|
-
const lookup = shouldLookup ? this.getLocalPrintOrderLookup(inputOrder) ?? this.getLocalPrintOrderLookup(data) : undefined;
|
|
3937
|
+
const lookup = shouldLookup ? this.getLocalPrintOrderLookup(inputOrder) ?? this.getLocalPrintOrderLookup(extractedRequest.data) : undefined;
|
|
3812
3938
|
let sourceOrder = inputOrder;
|
|
3813
3939
|
if (shouldLookup) {
|
|
3814
3940
|
if (lookup === undefined) {
|
|
@@ -3833,24 +3959,25 @@ class Server {
|
|
|
3833
3959
|
}
|
|
3834
3960
|
};
|
|
3835
3961
|
}
|
|
3836
|
-
|
|
3962
|
+
let localOrder = await this.order.getLocalOrderByLookup(lookup);
|
|
3837
3963
|
if (!localOrder) {
|
|
3838
|
-
|
|
3839
|
-
|
|
3840
|
-
|
|
3841
|
-
|
|
3842
|
-
|
|
3843
|
-
|
|
3844
|
-
|
|
3845
|
-
|
|
3846
|
-
|
|
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;
|
|
3847
3979
|
}
|
|
3848
|
-
sourceOrder =
|
|
3849
|
-
...localOrder,
|
|
3850
|
-
...inputOrder,
|
|
3851
|
-
order_id: localOrder.order_id ?? inputOrder.order_id ?? inputOrder.orderId,
|
|
3852
|
-
external_sale_number: localOrder.external_sale_number ?? inputOrder.external_sale_number ?? inputOrder.externalSaleNumber
|
|
3853
|
-
};
|
|
3980
|
+
sourceOrder = this.mergeLocalPrintOrderInput(localOrder, inputOrder);
|
|
3854
3981
|
}
|
|
3855
3982
|
const checkoutData = await this.ensureCheckoutOrderNumbers({
|
|
3856
3983
|
...sourceOrder,
|
|
@@ -3869,7 +3996,9 @@ class Server {
|
|
|
3869
3996
|
order: printableOrder,
|
|
3870
3997
|
response: null,
|
|
3871
3998
|
requireFullyPaid: false,
|
|
3872
|
-
isManualPrint: true
|
|
3999
|
+
isManualPrint: true,
|
|
4000
|
+
invoiceLayoutConfig,
|
|
4001
|
+
invoiceTemplateSettings
|
|
3873
4002
|
});
|
|
3874
4003
|
return {
|
|
3875
4004
|
code: 200,
|
|
@@ -3896,6 +4025,99 @@ class Server {
|
|
|
3896
4025
|
};
|
|
3897
4026
|
}
|
|
3898
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
|
+
};
|
|
3899
4121
|
handleMachinecodeBatchMeta = async ({
|
|
3900
4122
|
data
|
|
3901
4123
|
}) => {
|
|
@@ -4080,9 +4302,17 @@ class Server {
|
|
|
4080
4302
|
async handleOrderCheckoutSubmit(params) {
|
|
4081
4303
|
const {
|
|
4082
4304
|
backendPath,
|
|
4083
|
-
data,
|
|
4084
4305
|
title
|
|
4085
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);
|
|
4086
4316
|
this.logInfo(`${title}: 开始处理`, {
|
|
4087
4317
|
backendPath,
|
|
4088
4318
|
order_id: data?.order_id,
|
|
@@ -4093,17 +4323,20 @@ class Server {
|
|
|
4093
4323
|
return this.handleSyncCheckoutSubmit({
|
|
4094
4324
|
backendPath,
|
|
4095
4325
|
data,
|
|
4096
|
-
title
|
|
4326
|
+
title,
|
|
4327
|
+
invoiceLayoutConfig,
|
|
4328
|
+
invoiceTemplateSettings
|
|
4097
4329
|
});
|
|
4098
4330
|
}
|
|
4099
4331
|
const normalizedData = await this.normalizeCheckoutSubmitData(data, title);
|
|
4100
4332
|
const numberedData = await this.ensureCheckoutOrderNumbers(normalizedData, title);
|
|
4101
|
-
const checkoutData = this.applyCheckoutFulfillmentBuzzer(numberedData, title);
|
|
4333
|
+
const checkoutData = this.normalizeCheckoutCollections(this.applyCheckoutFulfillmentBuzzer(numberedData, title));
|
|
4102
4334
|
const pendingResult = await this.handlePendingSyncCheckoutOrder({
|
|
4103
4335
|
backendPath,
|
|
4104
4336
|
data: checkoutData,
|
|
4105
4337
|
title,
|
|
4106
|
-
reason: 'checkout 已转入设备任务同步'
|
|
4338
|
+
reason: 'checkout 已转入设备任务同步',
|
|
4339
|
+
invoiceTemplateSettings
|
|
4107
4340
|
});
|
|
4108
4341
|
if (pendingResult?.status === true) {
|
|
4109
4342
|
const pendingOrder = pendingResult.data;
|
|
@@ -4112,13 +4345,17 @@ class Server {
|
|
|
4112
4345
|
checkoutData,
|
|
4113
4346
|
order: pendingOrder,
|
|
4114
4347
|
response: pendingResult,
|
|
4115
|
-
requireFullyPaid: true
|
|
4348
|
+
requireFullyPaid: true,
|
|
4349
|
+
invoiceLayoutConfig,
|
|
4350
|
+
invoiceTemplateSettings
|
|
4116
4351
|
});
|
|
4117
4352
|
}
|
|
4118
4353
|
await this.dispatchCheckoutSyncTask({
|
|
4119
4354
|
backendPath,
|
|
4120
4355
|
data: checkoutData,
|
|
4121
|
-
title
|
|
4356
|
+
title,
|
|
4357
|
+
invoiceLayoutConfig,
|
|
4358
|
+
invoiceTemplateSettings
|
|
4122
4359
|
});
|
|
4123
4360
|
}
|
|
4124
4361
|
if (!pendingResult.data.order_id) {
|
|
@@ -4136,7 +4373,9 @@ class Server {
|
|
|
4136
4373
|
const {
|
|
4137
4374
|
backendPath,
|
|
4138
4375
|
data,
|
|
4139
|
-
title
|
|
4376
|
+
title,
|
|
4377
|
+
invoiceLayoutConfig,
|
|
4378
|
+
invoiceTemplateSettings
|
|
4140
4379
|
} = params;
|
|
4141
4380
|
if (!this.app?.request?.post) {
|
|
4142
4381
|
this.logError(`${title}: sync checkout app.request 不可用`);
|
|
@@ -4152,7 +4391,9 @@ class Server {
|
|
|
4152
4391
|
backendPath,
|
|
4153
4392
|
data,
|
|
4154
4393
|
title,
|
|
4155
|
-
persistCheckoutDataWithResponse: true
|
|
4394
|
+
persistCheckoutDataWithResponse: true,
|
|
4395
|
+
invoiceLayoutConfig,
|
|
4396
|
+
invoiceTemplateSettings
|
|
4156
4397
|
});
|
|
4157
4398
|
if (syncResult.rejected) {
|
|
4158
4399
|
const normalized = this.normalizeCheckoutResponse(syncResult.errorResponse);
|
|
@@ -4170,7 +4411,9 @@ class Server {
|
|
|
4170
4411
|
checkoutData: syncResult.checkoutData,
|
|
4171
4412
|
order: syncedOrder,
|
|
4172
4413
|
response: syncResult.normalizedResponse,
|
|
4173
|
-
requireFullyPaid: true
|
|
4414
|
+
requireFullyPaid: true,
|
|
4415
|
+
invoiceLayoutConfig,
|
|
4416
|
+
invoiceTemplateSettings
|
|
4174
4417
|
// print_all 的 type=0 是收据打印;不要沿用同步成功后的券/手环打印 type=99。
|
|
4175
4418
|
});
|
|
4176
4419
|
}
|
|
@@ -4202,9 +4445,16 @@ class Server {
|
|
|
4202
4445
|
}
|
|
4203
4446
|
async handleOrderDraftSubmit(params) {
|
|
4204
4447
|
const {
|
|
4205
|
-
data,
|
|
4206
4448
|
title
|
|
4207
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
|
+
});
|
|
4208
4458
|
this.logInfo(`${title}: 开始处理`, {
|
|
4209
4459
|
order_id: data?.order_id,
|
|
4210
4460
|
external_sale_number: data?.external_sale_number,
|
|
@@ -4265,9 +4515,10 @@ class Server {
|
|
|
4265
4515
|
backendPath,
|
|
4266
4516
|
data,
|
|
4267
4517
|
title,
|
|
4268
|
-
reason
|
|
4518
|
+
reason,
|
|
4519
|
+
invoiceTemplateSettings
|
|
4269
4520
|
} = params;
|
|
4270
|
-
const pendingOrder = await this.buildPendingSyncCheckoutOrder(data);
|
|
4521
|
+
const pendingOrder = await this.buildPendingSyncCheckoutOrder(data, invoiceTemplateSettings);
|
|
4271
4522
|
if (!pendingOrder) {
|
|
4272
4523
|
this.logError(`${title}: checkout 失败且订单缺少本地存储标识`, {
|
|
4273
4524
|
backendPath,
|
|
@@ -4333,23 +4584,39 @@ class Server {
|
|
|
4333
4584
|
};
|
|
4334
4585
|
}
|
|
4335
4586
|
}
|
|
4336
|
-
async buildPendingSyncCheckoutOrder(data) {
|
|
4587
|
+
async buildPendingSyncCheckoutOrder(data, invoiceTemplateSettings) {
|
|
4337
4588
|
if (!data || typeof data !== 'object') return null;
|
|
4338
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 !== '';
|
|
4339
4590
|
if (!hasStorageKey) return null;
|
|
4340
|
-
const pendingOrder = {
|
|
4591
|
+
const pendingOrder = this.normalizeCheckoutCollections({
|
|
4341
4592
|
...data,
|
|
4342
4593
|
need_sync: 1,
|
|
4343
4594
|
is_draft_order: 0
|
|
4344
|
-
};
|
|
4595
|
+
});
|
|
4345
4596
|
const productMap = await this.buildSmallTicketProductMap(pendingOrder);
|
|
4346
4597
|
const orderWithProductTitles = this.withPendingSyncProductTitles(pendingOrder, productMap);
|
|
4347
4598
|
return this.withLocalSmallTicketData(orderWithProductTitles, {
|
|
4348
4599
|
requireFullyPaid: true,
|
|
4349
|
-
productMap
|
|
4600
|
+
productMap,
|
|
4601
|
+
invoiceTemplateSettings
|
|
4350
4602
|
});
|
|
4351
4603
|
}
|
|
4352
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
|
+
|
|
4353
4620
|
/**
|
|
4354
4621
|
* Android 结账自动小票由当前设备设置控制;其它平台保持原有行为。
|
|
4355
4622
|
*/
|
|
@@ -4667,11 +4934,27 @@ class Server {
|
|
|
4667
4934
|
if (!this.shouldBuildSmallTicketData(order)) return order;
|
|
4668
4935
|
if (options?.requireFullyPaid && !this.isSalesOrderFullyPaid(order)) return order;
|
|
4669
4936
|
try {
|
|
4670
|
-
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);
|
|
4671
4953
|
const productMap = options?.productMap ?? (await this.buildSmallTicketProductMap(enrichedOrder));
|
|
4672
4954
|
const smallTicketData = (0, _smallTicket.buildSmallTicketData)({
|
|
4673
4955
|
order: enrichedOrder,
|
|
4674
4956
|
shopInfo: this.getSmallTicketShopInfo(),
|
|
4957
|
+
locales: [...(0, _OpenData.resolveInvoiceReceiptLocales)(options?.invoiceTemplateSettings), ...(options?.locales || [])],
|
|
4675
4958
|
productMap
|
|
4676
4959
|
});
|
|
4677
4960
|
return {
|
|
@@ -4688,6 +4971,122 @@ class Server {
|
|
|
4688
4971
|
return order;
|
|
4689
4972
|
}
|
|
4690
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
|
+
}
|
|
4691
5090
|
handleOrderSalesDetail = async ({
|
|
4692
5091
|
url,
|
|
4693
5092
|
data,
|
|
@@ -4736,73 +5135,22 @@ class Server {
|
|
|
4736
5135
|
};
|
|
4737
5136
|
}
|
|
4738
5137
|
}
|
|
4739
|
-
|
|
4740
|
-
|
|
4741
|
-
return {
|
|
4742
|
-
code: 500,
|
|
4743
|
-
status: false,
|
|
4744
|
-
message: 'app.request 不可用',
|
|
4745
|
-
data: null
|
|
4746
|
-
};
|
|
4747
|
-
}
|
|
4748
|
-
const backendPath = this.buildOrderSalesDetailBackendPath(lookup, data);
|
|
4749
|
-
try {
|
|
4750
|
-
const response = await this.app.request.get(backendPath, {
|
|
4751
|
-
lookup_mode: 'multi'
|
|
4752
|
-
}, {
|
|
4753
|
-
isShopApi: true,
|
|
4754
|
-
customToast: () => {}
|
|
4755
|
-
});
|
|
4756
|
-
const fresh = response?.data ?? response;
|
|
4757
|
-
if (!fresh || typeof fresh !== 'object' || fresh.order_id == null) {
|
|
4758
|
-
this.logInfo('handleOrderSalesDetail: 后端返回订单为空', {
|
|
4759
|
-
lookup,
|
|
4760
|
-
backendPath
|
|
4761
|
-
});
|
|
4762
|
-
return {
|
|
4763
|
-
code: 500,
|
|
4764
|
-
status: false,
|
|
4765
|
-
message: '后端返回订单为空',
|
|
4766
|
-
data: null
|
|
4767
|
-
};
|
|
4768
|
-
}
|
|
4769
|
-
await this.order.upsertOrdersFromRemote([fresh]);
|
|
4770
|
-
const savedOrder = await this.order.getLocalOrderByLookup(lookup);
|
|
4771
|
-
if (!savedOrder) {
|
|
4772
|
-
this.logError('handleOrderSalesDetail: 订单写入后回读失败', {
|
|
4773
|
-
lookup
|
|
4774
|
-
});
|
|
4775
|
-
return {
|
|
4776
|
-
code: 500,
|
|
4777
|
-
status: false,
|
|
4778
|
-
message: '订单写入后回读失败',
|
|
4779
|
-
data: null
|
|
4780
|
-
};
|
|
4781
|
-
}
|
|
4782
|
-
this.logInfo('handleOrderSalesDetail: 远端订单已同步到本地', {
|
|
4783
|
-
lookup
|
|
4784
|
-
});
|
|
4785
|
-
const enrichedOrder = await this.withSalesDetailProductSnapshots(savedOrder);
|
|
5138
|
+
const remoteResult = await this.fetchAndPersistSalesOrderByLookup(lookup, data, 'handleOrderSalesDetail');
|
|
5139
|
+
if (!remoteResult.order) {
|
|
4786
5140
|
return {
|
|
4787
|
-
code:
|
|
4788
|
-
status: true,
|
|
4789
|
-
message: '',
|
|
4790
|
-
data: enrichedOrder
|
|
4791
|
-
};
|
|
4792
|
-
} catch (error) {
|
|
4793
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
4794
|
-
this.logInfo('handleOrderSalesDetail: 请求失败', {
|
|
4795
|
-
lookup,
|
|
4796
|
-
backendPath,
|
|
4797
|
-
error: errorMessage
|
|
4798
|
-
});
|
|
4799
|
-
return {
|
|
4800
|
-
code: 500,
|
|
5141
|
+
code: remoteResult.code,
|
|
4801
5142
|
status: false,
|
|
4802
|
-
message:
|
|
5143
|
+
message: remoteResult.message,
|
|
4803
5144
|
data: null
|
|
4804
5145
|
};
|
|
4805
5146
|
}
|
|
5147
|
+
const enrichedOrder = await this.withSalesDetailProductSnapshots(remoteResult.order);
|
|
5148
|
+
return {
|
|
5149
|
+
code: 200,
|
|
5150
|
+
status: true,
|
|
5151
|
+
message: '',
|
|
5152
|
+
data: enrichedOrder
|
|
5153
|
+
};
|
|
4806
5154
|
};
|
|
4807
5155
|
|
|
4808
5156
|
/**
|