@pisell/pisellos 2.2.274 → 2.2.275
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/core/index.d.ts +2 -0
- package/dist/core/index.js +7 -0
- package/dist/model/strategy/adapter/promotion/adapter.d.ts +4 -0
- package/dist/model/strategy/adapter/promotion/adapter.js +23 -0
- package/dist/model/strategy/adapter/promotion/evaluator.d.ts +17 -0
- package/dist/model/strategy/adapter/promotion/evaluator.js +279 -6
- package/dist/model/strategy/adapter/promotion/examples.d.ts +86 -0
- package/dist/model/strategy/adapter/promotion/examples.js +99 -0
- package/dist/model/strategy/adapter/promotion/index.d.ts +1 -1
- package/dist/model/strategy/adapter/promotion/index.js +1 -1
- package/dist/model/strategy/adapter/promotion/type.d.ts +90 -2
- package/dist/model/strategy/adapter/promotion/type.js +45 -0
- package/dist/modules/OpenData/index.d.ts +2 -0
- package/dist/modules/OpenData/index.js +8 -0
- package/dist/modules/Order/index.d.ts +28 -8
- package/dist/modules/Order/index.js +821 -503
- package/dist/modules/Order/payment-utils.d.ts +26 -0
- package/dist/modules/Order/payment-utils.js +225 -0
- package/dist/modules/Order/types.d.ts +35 -1
- package/dist/modules/Order/utils/orderCollectionIdentity.js +7 -2
- package/dist/modules/Order/utils.js +10 -6
- package/dist/modules/Payment/index.d.ts +2 -0
- package/dist/modules/Payment/index.js +78 -49
- package/dist/modules/Payment/types.d.ts +104 -25
- package/dist/modules/Payment/types.js +17 -0
- package/dist/modules/Payment/walletpass.d.ts +38 -1
- package/dist/modules/Payment/walletpass.js +917 -114
- package/dist/modules/Rules/index.d.ts +3 -0
- package/dist/modules/Rules/index.js +100 -70
- package/dist/server/index.d.ts +20 -0
- package/dist/server/index.js +1955 -1049
- package/dist/server/modules/index.d.ts +1 -1
- package/dist/server/modules/order/index.d.ts +70 -4
- package/dist/server/modules/order/index.js +1816 -728
- package/dist/server/modules/order/types.d.ts +25 -3
- package/dist/server/modules/order/types.js +7 -1
- package/dist/solution/BaseSales/index.d.ts +104 -5
- package/dist/solution/BaseSales/index.js +1767 -436
- package/dist/solution/BaseSales/types.d.ts +55 -1
- package/dist/solution/BaseSales/types.js +2 -1
- package/dist/solution/BaseSales/utils/cartPromotion.d.ts +3 -1
- package/dist/solution/BaseSales/utils/cartPromotion.js +94 -32
- package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +6 -1
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +6 -3
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +20 -4
- package/dist/solution/BookingTicket/index.js +138 -52
- package/dist/solution/BookingTicket/types.d.ts +1 -0
- package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +8 -0
- package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +173 -83
- package/dist/solution/Sales/index.d.ts +2 -0
- package/dist/solution/Sales/index.js +26 -4
- package/dist/solution/ScanOrder/index.js +31 -20
- package/dist/solution/VenueBooking/index.d.ts +1 -0
- package/dist/solution/VenueBooking/index.js +30 -19
- package/dist/types/index.d.ts +1 -0
- package/dist/utils/payment-number.d.ts +9 -0
- package/dist/utils/payment-number.js +69 -0
- package/lib/core/index.d.ts +2 -0
- package/lib/core/index.js +4 -0
- package/lib/model/strategy/adapter/promotion/adapter.d.ts +4 -0
- package/lib/model/strategy/adapter/promotion/adapter.js +20 -0
- package/lib/model/strategy/adapter/promotion/evaluator.d.ts +17 -0
- package/lib/model/strategy/adapter/promotion/evaluator.js +235 -0
- package/lib/model/strategy/adapter/promotion/examples.d.ts +86 -0
- package/lib/model/strategy/adapter/promotion/examples.js +91 -0
- package/lib/model/strategy/adapter/promotion/index.d.ts +1 -1
- package/lib/model/strategy/adapter/promotion/index.js +0 -49
- package/lib/model/strategy/adapter/promotion/type.d.ts +90 -2
- package/lib/model/strategy/adapter/promotion/type.js +2 -0
- package/lib/modules/OpenData/index.d.ts +2 -0
- package/lib/modules/OpenData/index.js +5 -0
- package/lib/modules/Order/index.d.ts +28 -8
- package/lib/modules/Order/index.js +240 -74
- package/lib/modules/Order/payment-utils.d.ts +26 -0
- package/lib/modules/Order/payment-utils.js +224 -0
- package/lib/modules/Order/types.d.ts +35 -1
- package/lib/modules/Order/utils/orderCollectionIdentity.js +3 -0
- package/lib/modules/Order/utils.js +11 -4
- package/lib/modules/Payment/index.d.ts +2 -0
- package/lib/modules/Payment/index.js +33 -12
- package/lib/modules/Payment/types.d.ts +104 -25
- package/lib/modules/Payment/types.js +1 -0
- package/lib/modules/Payment/walletpass.d.ts +38 -1
- package/lib/modules/Payment/walletpass.js +730 -21
- package/lib/modules/Rules/index.d.ts +3 -0
- package/lib/modules/Rules/index.js +38 -9
- package/lib/server/index.d.ts +20 -0
- package/lib/server/index.js +684 -24
- package/lib/server/modules/index.d.ts +1 -1
- package/lib/server/modules/order/index.d.ts +70 -4
- package/lib/server/modules/order/index.js +818 -69
- package/lib/server/modules/order/types.d.ts +25 -3
- package/lib/server/modules/order/types.js +1 -0
- package/lib/solution/BaseSales/index.d.ts +104 -5
- package/lib/solution/BaseSales/index.js +858 -27
- package/lib/solution/BaseSales/types.d.ts +55 -1
- package/lib/solution/BaseSales/types.js +2 -1
- package/lib/solution/BaseSales/utils/cartPromotion.d.ts +3 -1
- package/lib/solution/BaseSales/utils/cartPromotion.js +66 -12
- package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +6 -1
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +3 -2
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +20 -4
- package/lib/solution/BookingTicket/index.js +63 -9
- package/lib/solution/BookingTicket/types.d.ts +1 -0
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +8 -0
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +37 -5
- package/lib/solution/Sales/index.d.ts +2 -0
- package/lib/solution/Sales/index.js +20 -6
- package/lib/solution/ScanOrder/index.js +8 -0
- package/lib/solution/VenueBooking/index.d.ts +1 -0
- package/lib/solution/VenueBooking/index.js +8 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/utils/payment-number.d.ts +9 -0
- package/lib/utils/payment-number.js +64 -0
- package/package.json +1 -1
package/lib/server/index.js
CHANGED
|
@@ -34,6 +34,8 @@ __export(server_exports, {
|
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(server_exports);
|
|
36
36
|
var import_dayjs = __toESM(require("dayjs"));
|
|
37
|
+
var import_decimal = __toESM(require("decimal.js"));
|
|
38
|
+
var import_lodash_es = require("lodash-es");
|
|
37
39
|
var import_products = require("./modules/products");
|
|
38
40
|
var import_menu = require("./modules/menu");
|
|
39
41
|
var import_quotation = require("./modules/quotation");
|
|
@@ -50,6 +52,8 @@ var import_types3 = require("./modules/order/types");
|
|
|
50
52
|
var import_filterOrders = require("./modules/order/utils/filterOrders");
|
|
51
53
|
var import_filterBookings = require("./modules/order/utils/filterBookings");
|
|
52
54
|
var import_small_ticket = require("./utils/small-ticket");
|
|
55
|
+
var import_BaseSales = require("../solution/BaseSales");
|
|
56
|
+
var import_payment_utils = require("../modules/Order/payment-utils");
|
|
53
57
|
__reExport(server_exports, require("./modules"), module.exports);
|
|
54
58
|
var PRODUCT_TITLE_SNAPSHOT_KEYS = [
|
|
55
59
|
"en",
|
|
@@ -61,6 +65,7 @@ var PRODUCT_TITLE_SNAPSHOT_KEYS = [
|
|
|
61
65
|
"kitchen",
|
|
62
66
|
"original"
|
|
63
67
|
];
|
|
68
|
+
var AUTO_PRINT_STORAGE_KEY = "auto_print";
|
|
64
69
|
var Server = class {
|
|
65
70
|
constructor(core) {
|
|
66
71
|
this.quotationAvailableCache = /* @__PURE__ */ new Map();
|
|
@@ -87,6 +92,7 @@ var Server = class {
|
|
|
87
92
|
this.BOOKING_REMOTE_CACHE_MAX_ENTRIES = 80;
|
|
88
93
|
this.salesSearchSubscribers = /* @__PURE__ */ new Map();
|
|
89
94
|
this.deviceTaskActionsRegistered = false;
|
|
95
|
+
this.localPaymentUpdateQueues = /* @__PURE__ */ new Map();
|
|
90
96
|
this.floorPlanQuerySubscribers = /* @__PURE__ */ new Map();
|
|
91
97
|
// 模块注册表 - 定义所有可用的模块配置
|
|
92
98
|
this.moduleRegistry = {
|
|
@@ -575,6 +581,128 @@ var Server = class {
|
|
|
575
581
|
title: "handleOrderSalesCheckout"
|
|
576
582
|
});
|
|
577
583
|
};
|
|
584
|
+
this.handleOrderSalesDraft = async ({ data }) => {
|
|
585
|
+
return this.handleOrderDraftSubmit({
|
|
586
|
+
data,
|
|
587
|
+
title: "handleOrderSalesDraft"
|
|
588
|
+
});
|
|
589
|
+
};
|
|
590
|
+
this.handleGetLocalPayment = async ({ data }) => {
|
|
591
|
+
const saleId = data == null ? void 0 : data.sale_id;
|
|
592
|
+
const paymentNumber = data == null ? void 0 : data.payment_number;
|
|
593
|
+
const operationId = this.createLocalPaymentOperationId("get");
|
|
594
|
+
const requestContext = {
|
|
595
|
+
operation_id: operationId,
|
|
596
|
+
sale_id: saleId ?? null,
|
|
597
|
+
payment_number: paymentNumber ?? null
|
|
598
|
+
};
|
|
599
|
+
this.logInfo("handleGetLocalPayment: 请求进入", requestContext);
|
|
600
|
+
if (saleId === void 0 || saleId === null || saleId === "" || paymentNumber === void 0 || paymentNumber === null || paymentNumber === "") {
|
|
601
|
+
this.logWarning("handleGetLocalPayment: 参数校验失败", {
|
|
602
|
+
...requestContext,
|
|
603
|
+
missing_fields: [
|
|
604
|
+
...saleId === void 0 || saleId === null || saleId === "" ? ["sale_id"] : [],
|
|
605
|
+
...paymentNumber === void 0 || paymentNumber === null || paymentNumber === "" ? ["payment_number"] : []
|
|
606
|
+
]
|
|
607
|
+
});
|
|
608
|
+
return {
|
|
609
|
+
code: 400,
|
|
610
|
+
status: false,
|
|
611
|
+
message: "sale_id 和 payment_number 必填",
|
|
612
|
+
data: null
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
if (!this.order) {
|
|
616
|
+
this.logError("handleGetLocalPayment: Order 模块未注册", requestContext);
|
|
617
|
+
return { code: 500, status: false, message: "Order 模块未注册", data: null };
|
|
618
|
+
}
|
|
619
|
+
const startedAt = Date.now();
|
|
620
|
+
try {
|
|
621
|
+
this.logInfo("handleGetLocalPayment: 开始查询本地支付项", requestContext);
|
|
622
|
+
const found = await this.order.getLocalPayment({
|
|
623
|
+
saleId,
|
|
624
|
+
paymentNumber,
|
|
625
|
+
operationId
|
|
626
|
+
});
|
|
627
|
+
if (!found) {
|
|
628
|
+
this.logWarning("handleGetLocalPayment: 本地支付项不存在", {
|
|
629
|
+
...requestContext,
|
|
630
|
+
duration_ms: Date.now() - startedAt
|
|
631
|
+
});
|
|
632
|
+
return { code: 404, status: false, message: "本地支付项不存在", data: null };
|
|
633
|
+
}
|
|
634
|
+
this.logInfo("handleGetLocalPayment: 查询命中", {
|
|
635
|
+
...requestContext,
|
|
636
|
+
duration_ms: Date.now() - startedAt,
|
|
637
|
+
matched_by: found.matchedBy,
|
|
638
|
+
payment_index: found.paymentIndex,
|
|
639
|
+
...this.buildLocalPaymentOrderLogContext(found.order),
|
|
640
|
+
payment: found.payment
|
|
641
|
+
});
|
|
642
|
+
return { code: 200, status: true, message: "", data: found.payment };
|
|
643
|
+
} catch (error) {
|
|
644
|
+
this.logError("handleGetLocalPayment: 查询异常", {
|
|
645
|
+
...requestContext,
|
|
646
|
+
duration_ms: Date.now() - startedAt,
|
|
647
|
+
error: error instanceof Error ? error.message : String(error),
|
|
648
|
+
error_detail: this.normalizeUnknownError(error)
|
|
649
|
+
});
|
|
650
|
+
throw error;
|
|
651
|
+
}
|
|
652
|
+
};
|
|
653
|
+
this.handleUpdateLocalPayment = async ({ data }) => {
|
|
654
|
+
const saleId = data == null ? void 0 : data.sale_id;
|
|
655
|
+
const paymentNumber = data == null ? void 0 : data.payment_number;
|
|
656
|
+
const number = data == null ? void 0 : data.number;
|
|
657
|
+
const status = data == null ? void 0 : data.status;
|
|
658
|
+
const serviceCharge = data == null ? void 0 : data.service_charge;
|
|
659
|
+
const cardReaderSurcharge = data == null ? void 0 : data.card_reader_surcharge;
|
|
660
|
+
const hasSurchargeInput = serviceCharge !== void 0 || cardReaderSurcharge !== void 0;
|
|
661
|
+
const invalidSurchargeFields = this.getInvalidLocalPaymentSurchargeFields(
|
|
662
|
+
serviceCharge,
|
|
663
|
+
cardReaderSurcharge
|
|
664
|
+
);
|
|
665
|
+
const operationId = this.createLocalPaymentOperationId("update");
|
|
666
|
+
const requestContext = {
|
|
667
|
+
operation_id: operationId,
|
|
668
|
+
sale_id: saleId ?? null,
|
|
669
|
+
payment_number: paymentNumber ?? null,
|
|
670
|
+
transaction_number: number ?? null,
|
|
671
|
+
requested_status: status ?? null,
|
|
672
|
+
service_charge: serviceCharge ?? null,
|
|
673
|
+
card_reader_surcharge: cardReaderSurcharge ?? null
|
|
674
|
+
};
|
|
675
|
+
this.logInfo("handleUpdateLocalPayment: 请求进入", requestContext);
|
|
676
|
+
if (saleId === void 0 || saleId === null || saleId === "" || paymentNumber === void 0 || paymentNumber === null || paymentNumber === "" || number === void 0 || number === null || number === "" || status !== "success" && status !== "fail" || invalidSurchargeFields.length > 0) {
|
|
677
|
+
this.logWarning("handleUpdateLocalPayment: 参数校验失败", {
|
|
678
|
+
...requestContext,
|
|
679
|
+
missing_or_invalid_fields: [
|
|
680
|
+
...saleId === void 0 || saleId === null || saleId === "" ? ["sale_id"] : [],
|
|
681
|
+
...paymentNumber === void 0 || paymentNumber === null || paymentNumber === "" ? ["payment_number"] : [],
|
|
682
|
+
...number === void 0 || number === null || number === "" ? ["number"] : [],
|
|
683
|
+
...status !== "success" && status !== "fail" ? ["status"] : [],
|
|
684
|
+
...invalidSurchargeFields
|
|
685
|
+
]
|
|
686
|
+
});
|
|
687
|
+
return {
|
|
688
|
+
code: 400,
|
|
689
|
+
status: false,
|
|
690
|
+
message: invalidSurchargeFields.length > 0 ? `手续费参数非法: ${invalidSurchargeFields.join(", ")}` : "sale_id、payment_number、number 必填,status 仅支持 success/fail",
|
|
691
|
+
data: null
|
|
692
|
+
};
|
|
693
|
+
}
|
|
694
|
+
const queueKey = `${String(saleId)}:${String(paymentNumber)}`;
|
|
695
|
+
return this.runLocalPaymentUpdateInQueue(queueKey, () => this.processLocalPaymentUpdate({
|
|
696
|
+
operationId,
|
|
697
|
+
saleId,
|
|
698
|
+
paymentNumber,
|
|
699
|
+
number: String(number),
|
|
700
|
+
status,
|
|
701
|
+
serviceCharge,
|
|
702
|
+
cardReaderSurcharge,
|
|
703
|
+
hasSurchargeInput
|
|
704
|
+
}), requestContext);
|
|
705
|
+
};
|
|
578
706
|
this.handleOrderCheckout = async ({ data }) => {
|
|
579
707
|
return this.handleOrderCheckoutSubmit({
|
|
580
708
|
backendPath: "/order/checkout",
|
|
@@ -1356,7 +1484,7 @@ var Server = class {
|
|
|
1356
1484
|
const { backendPath, title } = params;
|
|
1357
1485
|
const normalizedData = await this.normalizeCheckoutSubmitData(params.data, title);
|
|
1358
1486
|
const checkoutData = await this.ensureCheckoutOrderNumbers(normalizedData, title);
|
|
1359
|
-
const remoteCheckoutData = this.
|
|
1487
|
+
const remoteCheckoutData = this.buildRemoteCheckoutData(checkoutData, title);
|
|
1360
1488
|
if (!((_b = (_a = this.app) == null ? void 0 : _a.request) == null ? void 0 : _b.post)) {
|
|
1361
1489
|
throw new Error("app.request 不可用");
|
|
1362
1490
|
}
|
|
@@ -1372,20 +1500,20 @@ var Server = class {
|
|
|
1372
1500
|
errorResponse: response,
|
|
1373
1501
|
response,
|
|
1374
1502
|
normalizedResponse: this.normalizeCheckoutResponse(response),
|
|
1375
|
-
checkoutData
|
|
1503
|
+
checkoutData
|
|
1376
1504
|
};
|
|
1377
1505
|
}
|
|
1378
1506
|
const fresh = this.extractOrderDataFromCheckoutResponse(response);
|
|
1379
1507
|
const externalSaleNumber = this.getCheckoutExternalSaleNumber(
|
|
1380
|
-
|
|
1508
|
+
checkoutData,
|
|
1381
1509
|
{
|
|
1382
1510
|
external_sale_number: params.externalSaleNumber,
|
|
1383
|
-
data:
|
|
1511
|
+
data: checkoutData
|
|
1384
1512
|
}
|
|
1385
1513
|
);
|
|
1386
1514
|
const syncedOrder = await this.persistSyncedCheckoutOrder({
|
|
1387
1515
|
backendPath,
|
|
1388
|
-
checkoutData
|
|
1516
|
+
checkoutData,
|
|
1389
1517
|
externalSaleNumber,
|
|
1390
1518
|
fresh,
|
|
1391
1519
|
title,
|
|
@@ -1396,11 +1524,11 @@ var Server = class {
|
|
|
1396
1524
|
checkoutResponseOrder: fresh
|
|
1397
1525
|
}) : void 0;
|
|
1398
1526
|
if (printableSyncedOrder && this.shouldPrintSyncedOrder({
|
|
1399
|
-
checkoutData
|
|
1527
|
+
checkoutData,
|
|
1400
1528
|
syncedOrder: printableSyncedOrder
|
|
1401
1529
|
})) {
|
|
1402
1530
|
await this.dispatchPrintOtherReceiptTask({
|
|
1403
|
-
checkoutData
|
|
1531
|
+
checkoutData,
|
|
1404
1532
|
syncedOrder: printableSyncedOrder,
|
|
1405
1533
|
response,
|
|
1406
1534
|
deviceId: params.deviceId
|
|
@@ -1410,7 +1538,7 @@ var Server = class {
|
|
|
1410
1538
|
rejected: false,
|
|
1411
1539
|
response,
|
|
1412
1540
|
normalizedResponse: this.normalizeCheckoutResponse(response),
|
|
1413
|
-
checkoutData
|
|
1541
|
+
checkoutData,
|
|
1414
1542
|
syncedOrder,
|
|
1415
1543
|
fresh
|
|
1416
1544
|
};
|
|
@@ -1423,6 +1551,54 @@ var Server = class {
|
|
|
1423
1551
|
delete next.syncMode;
|
|
1424
1552
|
return next;
|
|
1425
1553
|
}
|
|
1554
|
+
buildRemoteCheckoutData(data, title) {
|
|
1555
|
+
const next = (0, import_lodash_es.cloneDeep)(this.omitCheckoutSyncMode(data));
|
|
1556
|
+
if (!next || typeof next !== "object")
|
|
1557
|
+
return next;
|
|
1558
|
+
const record = next;
|
|
1559
|
+
if (!Array.isArray(record.payments))
|
|
1560
|
+
return next;
|
|
1561
|
+
const originalPayments = record.payments;
|
|
1562
|
+
const filteredPayments = originalPayments.filter((payment) => !(0, import_payment_utils.isPendingOrderPayment)(payment));
|
|
1563
|
+
const removedPayments = originalPayments.filter((payment) => (0, import_payment_utils.isPendingOrderPayment)(payment));
|
|
1564
|
+
record.payments = filteredPayments;
|
|
1565
|
+
this.logInfo(`${title}: checkout 云端支付项已过滤`, {
|
|
1566
|
+
external_sale_number: record.external_sale_number,
|
|
1567
|
+
original_payment_count: originalPayments.length,
|
|
1568
|
+
remote_payment_count: filteredPayments.length,
|
|
1569
|
+
filtered_pending_count: removedPayments.length,
|
|
1570
|
+
filtered_payment_identities: removedPayments.map((payment) => (0, import_payment_utils.getOrderPaymentIdentityKeys)(payment))
|
|
1571
|
+
});
|
|
1572
|
+
return next;
|
|
1573
|
+
}
|
|
1574
|
+
mergeCheckoutSyncPayments(checkoutData, fresh, title) {
|
|
1575
|
+
const localPayments = Array.isArray(checkoutData == null ? void 0 : checkoutData.payments) ? checkoutData.payments : [];
|
|
1576
|
+
const freshRecord = fresh;
|
|
1577
|
+
if (!Array.isArray(freshRecord.payments)) {
|
|
1578
|
+
return localPayments.length > 0 ? { ...freshRecord, payments: (0, import_lodash_es.cloneDeep)(localPayments) } : freshRecord;
|
|
1579
|
+
}
|
|
1580
|
+
const freshPayments = freshRecord.payments;
|
|
1581
|
+
const mergedPayments = (0, import_payment_utils.mergeOrderPaymentListsByIdentity)(
|
|
1582
|
+
localPayments,
|
|
1583
|
+
freshPayments,
|
|
1584
|
+
{ preserveUnmatchedExistingWhen: import_payment_utils.isIdentifiedPendingOrderPayment }
|
|
1585
|
+
);
|
|
1586
|
+
const remoteIdentityKeys = new Set(
|
|
1587
|
+
freshPayments.flatMap((payment) => (0, import_payment_utils.getOrderPaymentIdentityKeys)(payment))
|
|
1588
|
+
);
|
|
1589
|
+
const preservedPending = localPayments.filter((payment) => (0, import_payment_utils.isIdentifiedPendingOrderPayment)(payment) && !(0, import_payment_utils.getOrderPaymentIdentityKeys)(payment).some((key) => remoteIdentityKeys.has(key)));
|
|
1590
|
+
if (preservedPending.length > 0) {
|
|
1591
|
+
this.logInfo(`${title}: checkout 响应合并保留本地 pending 支付项`, {
|
|
1592
|
+
external_sale_number: checkoutData == null ? void 0 : checkoutData.external_sale_number,
|
|
1593
|
+
preserved_pending_count: preservedPending.length,
|
|
1594
|
+
preserved_payment_identities: preservedPending.map((payment) => (0, import_payment_utils.getOrderPaymentIdentityKeys)(payment))
|
|
1595
|
+
});
|
|
1596
|
+
}
|
|
1597
|
+
return {
|
|
1598
|
+
...freshRecord,
|
|
1599
|
+
payments: mergedPayments
|
|
1600
|
+
};
|
|
1601
|
+
}
|
|
1426
1602
|
async persistSyncedCheckoutOrder(params) {
|
|
1427
1603
|
const {
|
|
1428
1604
|
backendPath,
|
|
@@ -1437,15 +1613,17 @@ var Server = class {
|
|
|
1437
1613
|
if (this.order && fresh && (shouldMergeRemoteOrder || persistCheckoutDataWithResponse)) {
|
|
1438
1614
|
syncedOrder = persistCheckoutDataWithResponse ? {
|
|
1439
1615
|
...checkoutData,
|
|
1440
|
-
...fresh,
|
|
1616
|
+
...this.mergeCheckoutSyncPayments(checkoutData, fresh, title),
|
|
1441
1617
|
external_sale_number: fresh.external_sale_number ?? externalSaleNumber,
|
|
1442
|
-
need_sync: 0
|
|
1618
|
+
need_sync: 0,
|
|
1619
|
+
is_draft_order: 0
|
|
1443
1620
|
} : {
|
|
1444
|
-
...fresh,
|
|
1621
|
+
...this.mergeCheckoutSyncPayments(checkoutData, fresh, title),
|
|
1445
1622
|
external_sale_number: fresh.external_sale_number ?? externalSaleNumber,
|
|
1446
|
-
need_sync: 0
|
|
1623
|
+
need_sync: 0,
|
|
1624
|
+
is_draft_order: 0
|
|
1447
1625
|
};
|
|
1448
|
-
await this.order.upsertOrdersFromRemote([syncedOrder]);
|
|
1626
|
+
await this.order.upsertOrdersFromRemote([syncedOrder], "checkoutSync");
|
|
1449
1627
|
this.logInfo(`${title}: sync_sales 完整订单已同步到本地`, {
|
|
1450
1628
|
order_id: fresh.order_id,
|
|
1451
1629
|
external_sale_number: syncedOrder.external_sale_number,
|
|
@@ -1463,7 +1641,8 @@ var Server = class {
|
|
|
1463
1641
|
...checkoutData,
|
|
1464
1642
|
...patch,
|
|
1465
1643
|
external_sale_number: externalSaleNumber,
|
|
1466
|
-
need_sync: 0
|
|
1644
|
+
need_sync: 0,
|
|
1645
|
+
is_draft_order: 0
|
|
1467
1646
|
};
|
|
1468
1647
|
this.logInfo(`${title}: sync_sales 已按 external_sale_number 标记本地订单`, {
|
|
1469
1648
|
order_id: (syncedOrder == null ? void 0 : syncedOrder.order_id) ?? null,
|
|
@@ -1843,6 +2022,11 @@ var Server = class {
|
|
|
1843
2022
|
path: "/shop/order/sales/checkout",
|
|
1844
2023
|
handler: this.handleOrderSalesCheckout.bind(this)
|
|
1845
2024
|
},
|
|
2025
|
+
{
|
|
2026
|
+
method: "post",
|
|
2027
|
+
path: "/shop/order/sales/draft",
|
|
2028
|
+
handler: this.handleOrderSalesDraft.bind(this)
|
|
2029
|
+
},
|
|
1846
2030
|
{
|
|
1847
2031
|
method: "post",
|
|
1848
2032
|
path: "/order/checkout",
|
|
@@ -1853,6 +2037,16 @@ var Server = class {
|
|
|
1853
2037
|
path: "/shop/local/print-order",
|
|
1854
2038
|
handler: this.handleLocalPrintOrder.bind(this)
|
|
1855
2039
|
},
|
|
2040
|
+
{
|
|
2041
|
+
method: "post",
|
|
2042
|
+
path: "/shop/local/getLocalPayment",
|
|
2043
|
+
handler: this.handleGetLocalPayment.bind(this)
|
|
2044
|
+
},
|
|
2045
|
+
{
|
|
2046
|
+
method: "post",
|
|
2047
|
+
path: "/shop/local/updateLocalPayment",
|
|
2048
|
+
handler: this.handleUpdateLocalPayment.bind(this)
|
|
2049
|
+
},
|
|
1856
2050
|
{
|
|
1857
2051
|
method: "post",
|
|
1858
2052
|
path: "/shop/machinecode/batch",
|
|
@@ -2694,6 +2888,405 @@ var Server = class {
|
|
|
2694
2888
|
};
|
|
2695
2889
|
}
|
|
2696
2890
|
}
|
|
2891
|
+
createLocalPaymentOperationId(action) {
|
|
2892
|
+
return `local_payment_${action}_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
|
|
2893
|
+
}
|
|
2894
|
+
buildLocalPaymentOrderLogContext(order) {
|
|
2895
|
+
if (!order)
|
|
2896
|
+
return {};
|
|
2897
|
+
return {
|
|
2898
|
+
order_id: order.order_id ?? null,
|
|
2899
|
+
external_sale_number: order.external_sale_number ?? null,
|
|
2900
|
+
order_number: order.order_number ?? null,
|
|
2901
|
+
shop_order_number: order.shop_order_number ?? null,
|
|
2902
|
+
shop_full_order_number: order.shop_full_order_number ?? null,
|
|
2903
|
+
order_status: order.status ?? null,
|
|
2904
|
+
payment_status: order.payment_status ?? null,
|
|
2905
|
+
is_draft_order: Number(order.is_draft_order || 0),
|
|
2906
|
+
need_sync: Number(order.need_sync || 0),
|
|
2907
|
+
platform: order.platform ?? null,
|
|
2908
|
+
business_code: order.business_code ?? null,
|
|
2909
|
+
order_sales_channel: order.order_sales_channel ?? null,
|
|
2910
|
+
sales_channel: order.sales_channel ?? null,
|
|
2911
|
+
order_type: order.type ?? null,
|
|
2912
|
+
payments_count: Array.isArray(order.payments) ? order.payments.length : 0
|
|
2913
|
+
};
|
|
2914
|
+
}
|
|
2915
|
+
isValidLocalPaymentDecimal(value) {
|
|
2916
|
+
if (typeof value !== "string" && typeof value !== "number")
|
|
2917
|
+
return false;
|
|
2918
|
+
if (typeof value === "string" && value.trim() === "")
|
|
2919
|
+
return false;
|
|
2920
|
+
try {
|
|
2921
|
+
return new import_decimal.default(value).isFinite();
|
|
2922
|
+
} catch {
|
|
2923
|
+
return false;
|
|
2924
|
+
}
|
|
2925
|
+
}
|
|
2926
|
+
getInvalidLocalPaymentSurchargeFields(serviceCharge, cardReaderSurcharge) {
|
|
2927
|
+
const invalidFields = [];
|
|
2928
|
+
if (serviceCharge !== void 0) {
|
|
2929
|
+
if (serviceCharge === null || typeof serviceCharge !== "object" || Array.isArray(serviceCharge)) {
|
|
2930
|
+
invalidFields.push("service_charge");
|
|
2931
|
+
} else {
|
|
2932
|
+
const input = serviceCharge;
|
|
2933
|
+
if (input.fixed !== void 0 && !this.isValidLocalPaymentDecimal(input.fixed)) {
|
|
2934
|
+
invalidFields.push("service_charge.fixed");
|
|
2935
|
+
}
|
|
2936
|
+
if (input.percentage !== void 0 && !this.isValidLocalPaymentDecimal(input.percentage)) {
|
|
2937
|
+
invalidFields.push("service_charge.percentage");
|
|
2938
|
+
}
|
|
2939
|
+
}
|
|
2940
|
+
}
|
|
2941
|
+
if (cardReaderSurcharge !== void 0 && !this.isValidLocalPaymentDecimal(cardReaderSurcharge)) {
|
|
2942
|
+
invalidFields.push("card_reader_surcharge");
|
|
2943
|
+
}
|
|
2944
|
+
return invalidFields;
|
|
2945
|
+
}
|
|
2946
|
+
buildLocalPaymentSurchargeUpdate(params) {
|
|
2947
|
+
var _a, _b, _c;
|
|
2948
|
+
const amount = new import_decimal.default(((_a = params.serviceCharge) == null ? void 0 : _a.fixed) || 0).plus(params.cardReaderSurcharge || 0).toFixed(2);
|
|
2949
|
+
const serviceFee = new import_decimal.default(params.paymentAmount || 0).times(((_b = params.serviceCharge) == null ? void 0 : _b.percentage) || 0).plus(amount).toDecimalPlaces(2).toFixed(2);
|
|
2950
|
+
return {
|
|
2951
|
+
service_charge: {
|
|
2952
|
+
amount,
|
|
2953
|
+
...((_c = params.serviceCharge) == null ? void 0 : _c.percentage) !== void 0 ? { percentage: params.serviceCharge.percentage } : {}
|
|
2954
|
+
},
|
|
2955
|
+
service_fee: serviceFee
|
|
2956
|
+
};
|
|
2957
|
+
}
|
|
2958
|
+
async runLocalPaymentUpdateInQueue(key, task, context) {
|
|
2959
|
+
var _a;
|
|
2960
|
+
const queuedAt = Date.now();
|
|
2961
|
+
const hasPreviousTask = this.localPaymentUpdateQueues.has(key);
|
|
2962
|
+
const previous = this.localPaymentUpdateQueues.get(key) || Promise.resolve();
|
|
2963
|
+
this.logInfo("handleUpdateLocalPayment: 串行队列入队", {
|
|
2964
|
+
...context,
|
|
2965
|
+
queue_key: key,
|
|
2966
|
+
waiting_for_previous: hasPreviousTask,
|
|
2967
|
+
active_queue_count: this.localPaymentUpdateQueues.size
|
|
2968
|
+
});
|
|
2969
|
+
const current = previous.catch(() => void 0).then(async () => {
|
|
2970
|
+
this.logInfo("handleUpdateLocalPayment: 串行队列开始执行", {
|
|
2971
|
+
...context,
|
|
2972
|
+
queue_key: key,
|
|
2973
|
+
queue_wait_ms: Date.now() - queuedAt
|
|
2974
|
+
});
|
|
2975
|
+
return task();
|
|
2976
|
+
});
|
|
2977
|
+
const tail = current.then(() => void 0, () => void 0);
|
|
2978
|
+
this.localPaymentUpdateQueues.set(key, tail);
|
|
2979
|
+
try {
|
|
2980
|
+
const result = await current;
|
|
2981
|
+
this.logInfo("handleUpdateLocalPayment: 串行队列执行完成", {
|
|
2982
|
+
...context,
|
|
2983
|
+
queue_key: key,
|
|
2984
|
+
total_duration_ms: Date.now() - queuedAt,
|
|
2985
|
+
result_code: result == null ? void 0 : result.code,
|
|
2986
|
+
result_status: result == null ? void 0 : result.status,
|
|
2987
|
+
payment: (_a = result == null ? void 0 : result.data) == null ? void 0 : _a.payment
|
|
2988
|
+
});
|
|
2989
|
+
return result;
|
|
2990
|
+
} catch (error) {
|
|
2991
|
+
this.logError("handleUpdateLocalPayment: 串行队列执行失败", {
|
|
2992
|
+
...context,
|
|
2993
|
+
queue_key: key,
|
|
2994
|
+
total_duration_ms: Date.now() - queuedAt,
|
|
2995
|
+
error: error instanceof Error ? error.message : String(error),
|
|
2996
|
+
error_detail: this.normalizeUnknownError(error)
|
|
2997
|
+
});
|
|
2998
|
+
throw error;
|
|
2999
|
+
} finally {
|
|
3000
|
+
let released = false;
|
|
3001
|
+
if (this.localPaymentUpdateQueues.get(key) === tail) {
|
|
3002
|
+
this.localPaymentUpdateQueues.delete(key);
|
|
3003
|
+
released = true;
|
|
3004
|
+
}
|
|
3005
|
+
this.logInfo("handleUpdateLocalPayment: 串行队列释放", {
|
|
3006
|
+
...context,
|
|
3007
|
+
queue_key: key,
|
|
3008
|
+
released,
|
|
3009
|
+
active_queue_count: this.localPaymentUpdateQueues.size
|
|
3010
|
+
});
|
|
3011
|
+
}
|
|
3012
|
+
}
|
|
3013
|
+
async processLocalPaymentUpdate(params) {
|
|
3014
|
+
var _a, _b, _c;
|
|
3015
|
+
const requestContext = {
|
|
3016
|
+
operation_id: params.operationId,
|
|
3017
|
+
sale_id: params.saleId,
|
|
3018
|
+
payment_number: params.paymentNumber,
|
|
3019
|
+
transaction_number: params.number,
|
|
3020
|
+
requested_status: params.status,
|
|
3021
|
+
service_charge: params.serviceCharge ?? null,
|
|
3022
|
+
card_reader_surcharge: params.cardReaderSurcharge ?? null
|
|
3023
|
+
};
|
|
3024
|
+
this.logInfo("processLocalPaymentUpdate: 开始处理", requestContext);
|
|
3025
|
+
if (!this.order) {
|
|
3026
|
+
this.logError("processLocalPaymentUpdate: Order 模块未注册", requestContext);
|
|
3027
|
+
return { code: 500, status: false, message: "Order 模块未注册", data: null };
|
|
3028
|
+
}
|
|
3029
|
+
this.logInfo("processLocalPaymentUpdate: 开始查询本地支付项", requestContext);
|
|
3030
|
+
const found = await this.order.getLocalPayment({
|
|
3031
|
+
saleId: params.saleId,
|
|
3032
|
+
paymentNumber: params.paymentNumber,
|
|
3033
|
+
operationId: params.operationId
|
|
3034
|
+
});
|
|
3035
|
+
if (!found) {
|
|
3036
|
+
this.logWarning("processLocalPaymentUpdate: 本地支付项不存在", requestContext);
|
|
3037
|
+
return { code: 404, status: false, message: "本地支付项不存在", data: null };
|
|
3038
|
+
}
|
|
3039
|
+
const surchargeUpdate = params.status === "success" && params.hasSurchargeInput ? this.buildLocalPaymentSurchargeUpdate({
|
|
3040
|
+
paymentAmount: (_a = found.payment) == null ? void 0 : _a.amount,
|
|
3041
|
+
serviceCharge: params.serviceCharge,
|
|
3042
|
+
cardReaderSurcharge: params.cardReaderSurcharge
|
|
3043
|
+
}) : void 0;
|
|
3044
|
+
const incomingPaymentUpdate = params.status === "success" ? {
|
|
3045
|
+
status: "paid",
|
|
3046
|
+
...surchargeUpdate || {},
|
|
3047
|
+
metadata: {
|
|
3048
|
+
unique_payment_number: params.number,
|
|
3049
|
+
transactions: [{ number: params.number, status: "success" }]
|
|
3050
|
+
}
|
|
3051
|
+
} : {
|
|
3052
|
+
metadata: {
|
|
3053
|
+
transactions: [{ number: params.number, status: "fail" }]
|
|
3054
|
+
}
|
|
3055
|
+
};
|
|
3056
|
+
const transactions = Array.isArray((_c = (_b = found.payment) == null ? void 0 : _b.metadata) == null ? void 0 : _c.transactions) ? found.payment.metadata.transactions : [];
|
|
3057
|
+
const existingTransaction = transactions.find((item) => String((item == null ? void 0 : item.number) || "") === params.number);
|
|
3058
|
+
const hasRecordedSuccess = transactions.some((item) => (item == null ? void 0 : item.status) === "success");
|
|
3059
|
+
const orderIsDraft = Number(found.order.is_draft_order || 0) === 1;
|
|
3060
|
+
const foundContext = {
|
|
3061
|
+
...requestContext,
|
|
3062
|
+
matched_by: found.matchedBy,
|
|
3063
|
+
payment_index: found.paymentIndex,
|
|
3064
|
+
...this.buildLocalPaymentOrderLogContext(found.order),
|
|
3065
|
+
payment: found.payment,
|
|
3066
|
+
incoming_payment_update: incomingPaymentUpdate,
|
|
3067
|
+
existing_transaction: existingTransaction || null,
|
|
3068
|
+
has_recorded_success: hasRecordedSuccess
|
|
3069
|
+
};
|
|
3070
|
+
this.logInfo("processLocalPaymentUpdate: 查询命中", foundContext);
|
|
3071
|
+
if (params.status === "fail" && (found.payment.status === "paid" || hasRecordedSuccess)) {
|
|
3072
|
+
this.logInfo("processLocalPaymentUpdate: 幂等返回", {
|
|
3073
|
+
...foundContext,
|
|
3074
|
+
idempotent_reason: "ignore_failure_after_success"
|
|
3075
|
+
});
|
|
3076
|
+
return {
|
|
3077
|
+
code: 200,
|
|
3078
|
+
status: true,
|
|
3079
|
+
message: "",
|
|
3080
|
+
data: { payment: found.payment, order: found.order, idempotent: true }
|
|
3081
|
+
};
|
|
3082
|
+
}
|
|
3083
|
+
const alreadyRecordedFailure = params.status === "fail" && (existingTransaction == null ? void 0 : existingTransaction.status) === "fail";
|
|
3084
|
+
if (alreadyRecordedFailure) {
|
|
3085
|
+
this.logInfo("processLocalPaymentUpdate: 幂等返回", {
|
|
3086
|
+
...foundContext,
|
|
3087
|
+
idempotent_reason: "failure_already_recorded"
|
|
3088
|
+
});
|
|
3089
|
+
return {
|
|
3090
|
+
code: 200,
|
|
3091
|
+
status: true,
|
|
3092
|
+
message: "",
|
|
3093
|
+
data: { payment: found.payment, order: found.order, idempotent: true }
|
|
3094
|
+
};
|
|
3095
|
+
}
|
|
3096
|
+
if (params.status === "success" && (existingTransaction == null ? void 0 : existingTransaction.status) === "success" && found.payment.status === "paid" && !orderIsDraft) {
|
|
3097
|
+
this.logInfo("processLocalPaymentUpdate: 幂等返回", {
|
|
3098
|
+
...foundContext,
|
|
3099
|
+
idempotent_reason: "success_already_committed"
|
|
3100
|
+
});
|
|
3101
|
+
return {
|
|
3102
|
+
code: 200,
|
|
3103
|
+
status: true,
|
|
3104
|
+
message: "",
|
|
3105
|
+
data: { payment: found.payment, order: found.order, idempotent: true }
|
|
3106
|
+
};
|
|
3107
|
+
}
|
|
3108
|
+
if (params.status === "success") {
|
|
3109
|
+
this.logInfo("processLocalPaymentUpdate: 进入 success 恢复分支", {
|
|
3110
|
+
...foundContext,
|
|
3111
|
+
force_submit_if_paid: found.payment.status === "paid" && orderIsDraft
|
|
3112
|
+
});
|
|
3113
|
+
return this.processSuccessfulLocalPayment({
|
|
3114
|
+
...params,
|
|
3115
|
+
order: found.order,
|
|
3116
|
+
payment: found.payment,
|
|
3117
|
+
matchBy: found.matchedBy === "payment_number" ? "payment_number" : "compat",
|
|
3118
|
+
forceSubmitIfPaid: found.payment.status === "paid" && orderIsDraft,
|
|
3119
|
+
paymentUpdate: incomingPaymentUpdate
|
|
3120
|
+
});
|
|
3121
|
+
}
|
|
3122
|
+
this.logInfo("processLocalPaymentUpdate: 进入 fail 本地更新分支", {
|
|
3123
|
+
...foundContext,
|
|
3124
|
+
incoming_payment_update: incomingPaymentUpdate
|
|
3125
|
+
});
|
|
3126
|
+
let updated;
|
|
3127
|
+
try {
|
|
3128
|
+
updated = await this.order.updateLocalPayment({
|
|
3129
|
+
saleId: params.saleId,
|
|
3130
|
+
paymentNumber: params.paymentNumber,
|
|
3131
|
+
operationId: params.operationId,
|
|
3132
|
+
updates: incomingPaymentUpdate
|
|
3133
|
+
});
|
|
3134
|
+
} catch (error) {
|
|
3135
|
+
this.logError("processLocalPaymentUpdate: fail 本地更新失败", {
|
|
3136
|
+
...foundContext,
|
|
3137
|
+
incoming_payment_update: incomingPaymentUpdate,
|
|
3138
|
+
error: error instanceof Error ? error.message : String(error),
|
|
3139
|
+
error_detail: this.normalizeUnknownError(error)
|
|
3140
|
+
});
|
|
3141
|
+
throw error;
|
|
3142
|
+
}
|
|
3143
|
+
if (!updated) {
|
|
3144
|
+
this.logWarning("processLocalPaymentUpdate: fail 本地更新未命中", foundContext);
|
|
3145
|
+
return { code: 404, status: false, message: "本地支付项不存在", data: null };
|
|
3146
|
+
}
|
|
3147
|
+
this.logInfo("processLocalPaymentUpdate: fail 本地更新完成", {
|
|
3148
|
+
...requestContext,
|
|
3149
|
+
...this.buildLocalPaymentOrderLogContext(updated.order),
|
|
3150
|
+
previous_payment: updated.previousPayment,
|
|
3151
|
+
payment: updated.payment
|
|
3152
|
+
});
|
|
3153
|
+
return {
|
|
3154
|
+
code: 200,
|
|
3155
|
+
status: true,
|
|
3156
|
+
message: "",
|
|
3157
|
+
data: {
|
|
3158
|
+
local_only: true,
|
|
3159
|
+
payment: updated.payment,
|
|
3160
|
+
order: updated.order
|
|
3161
|
+
}
|
|
3162
|
+
};
|
|
3163
|
+
}
|
|
3164
|
+
async processSuccessfulLocalPayment(params) {
|
|
3165
|
+
var _a, _b, _c, _d, _e;
|
|
3166
|
+
const moduleName = `local_payment_recovery_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
|
|
3167
|
+
const baseSales = new import_BaseSales.BaseSalesImpl(moduleName);
|
|
3168
|
+
const startedAt = Date.now();
|
|
3169
|
+
const recoveryContext = {
|
|
3170
|
+
operation_id: params.operationId,
|
|
3171
|
+
sale_id: params.saleId,
|
|
3172
|
+
payment_number: params.paymentNumber,
|
|
3173
|
+
transaction_number: params.number,
|
|
3174
|
+
requested_status: "success",
|
|
3175
|
+
match_by: params.matchBy,
|
|
3176
|
+
force_submit_if_paid: params.forceSubmitIfPaid,
|
|
3177
|
+
incoming_payment_update: params.paymentUpdate,
|
|
3178
|
+
base_sales_module_name: moduleName,
|
|
3179
|
+
...this.buildLocalPaymentOrderLogContext(params.order),
|
|
3180
|
+
payment: params.payment
|
|
3181
|
+
};
|
|
3182
|
+
this.logInfo("processSuccessfulLocalPayment: 创建临时 BaseSales", recoveryContext);
|
|
3183
|
+
try {
|
|
3184
|
+
const order = this.sanitizeLocalRecoveryOrder(params.order);
|
|
3185
|
+
this.logInfo("processSuccessfulLocalPayment: 本地订单清洗完成", {
|
|
3186
|
+
...recoveryContext,
|
|
3187
|
+
sanitized_order_id: order.order_id ?? null,
|
|
3188
|
+
removed_synthetic_order_id: params.order.order_id != null && order.order_id == null
|
|
3189
|
+
});
|
|
3190
|
+
await baseSales.initialize(this.core, {
|
|
3191
|
+
otherParams: {
|
|
3192
|
+
platform: order.platform,
|
|
3193
|
+
businessCode: order.business_code,
|
|
3194
|
+
business_code: order.business_code,
|
|
3195
|
+
channel: order.order_sales_channel || order.sales_channel,
|
|
3196
|
+
type: order.type,
|
|
3197
|
+
enableTempOrderPersist: false
|
|
3198
|
+
}
|
|
3199
|
+
});
|
|
3200
|
+
this.logInfo("processSuccessfulLocalPayment: BaseSales 初始化完成", recoveryContext);
|
|
3201
|
+
await baseSales.replaceTempOrder(order);
|
|
3202
|
+
this.logInfo("processSuccessfulLocalPayment: 本地订单 tempOrder 恢复完成", recoveryContext);
|
|
3203
|
+
this.logInfo("processSuccessfulLocalPayment: 开始更新支付项并提交", {
|
|
3204
|
+
...recoveryContext,
|
|
3205
|
+
incoming_payment_update: params.paymentUpdate
|
|
3206
|
+
});
|
|
3207
|
+
const result = await baseSales.updateOrderPayment(
|
|
3208
|
+
params.paymentNumber,
|
|
3209
|
+
params.paymentUpdate,
|
|
3210
|
+
{
|
|
3211
|
+
submitWhenPaid: true,
|
|
3212
|
+
matchBy: params.matchBy,
|
|
3213
|
+
forceSubmitIfPaid: params.forceSubmitIfPaid,
|
|
3214
|
+
applyUpdatesWhenPaid: params.forceSubmitIfPaid,
|
|
3215
|
+
smallTicketDataFlag: 1
|
|
3216
|
+
}
|
|
3217
|
+
);
|
|
3218
|
+
this.logInfo("processSuccessfulLocalPayment: 支付恢复完成", {
|
|
3219
|
+
...recoveryContext,
|
|
3220
|
+
duration_ms: Date.now() - startedAt,
|
|
3221
|
+
payment: result.payment,
|
|
3222
|
+
payments_count: ((_a = result.payments) == null ? void 0 : _a.length) || 0,
|
|
3223
|
+
summary: result.summary,
|
|
3224
|
+
sync_result: result.syncResult ? {
|
|
3225
|
+
is_fully_paid: result.syncResult.isFullyPaid,
|
|
3226
|
+
is_order_fully_paid: result.syncResult.isOrderFullyPaid,
|
|
3227
|
+
is_deposit_fully_paid: result.syncResult.isDepositFullyPaid,
|
|
3228
|
+
payment_stage: result.syncResult.paymentStage,
|
|
3229
|
+
deposit_amount: result.syncResult.depositAmount,
|
|
3230
|
+
order_expected_amount: result.syncResult.orderExpectedAmount,
|
|
3231
|
+
submit_result_code: (_b = result.syncResult.submitResult) == null ? void 0 : _b.code,
|
|
3232
|
+
submit_result_status: (_c = result.syncResult.submitResult) == null ? void 0 : _c.status
|
|
3233
|
+
} : null,
|
|
3234
|
+
draft_result: result.draftResult ? {
|
|
3235
|
+
code: (_d = result.draftResult) == null ? void 0 : _d.code,
|
|
3236
|
+
status: (_e = result.draftResult) == null ? void 0 : _e.status
|
|
3237
|
+
} : null,
|
|
3238
|
+
draft_error: result.draftError instanceof Error ? result.draftError.message : result.draftError
|
|
3239
|
+
});
|
|
3240
|
+
return {
|
|
3241
|
+
code: 200,
|
|
3242
|
+
status: true,
|
|
3243
|
+
message: "",
|
|
3244
|
+
data: {
|
|
3245
|
+
payment: result.payment,
|
|
3246
|
+
payments: result.payments,
|
|
3247
|
+
summary: result.summary,
|
|
3248
|
+
sync_result: result.syncResult
|
|
3249
|
+
}
|
|
3250
|
+
};
|
|
3251
|
+
} catch (error) {
|
|
3252
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
3253
|
+
this.logError("processSuccessfulLocalPayment: 支付恢复失败", {
|
|
3254
|
+
...recoveryContext,
|
|
3255
|
+
duration_ms: Date.now() - startedAt,
|
|
3256
|
+
error: message,
|
|
3257
|
+
error_detail: this.normalizeUnknownError(error)
|
|
3258
|
+
});
|
|
3259
|
+
return { code: 500, status: false, message, data: null };
|
|
3260
|
+
} finally {
|
|
3261
|
+
try {
|
|
3262
|
+
await baseSales.destroy();
|
|
3263
|
+
this.logInfo("processSuccessfulLocalPayment: 临时 BaseSales 销毁完成", {
|
|
3264
|
+
...recoveryContext,
|
|
3265
|
+
duration_ms: Date.now() - startedAt
|
|
3266
|
+
});
|
|
3267
|
+
} catch (error) {
|
|
3268
|
+
this.logError("processSuccessfulLocalPayment: 临时 BaseSales 销毁失败", {
|
|
3269
|
+
...recoveryContext,
|
|
3270
|
+
duration_ms: Date.now() - startedAt,
|
|
3271
|
+
error: error instanceof Error ? error.message : String(error),
|
|
3272
|
+
error_detail: this.normalizeUnknownError(error)
|
|
3273
|
+
});
|
|
3274
|
+
}
|
|
3275
|
+
}
|
|
3276
|
+
}
|
|
3277
|
+
sanitizeLocalRecoveryOrder(order) {
|
|
3278
|
+
const next = {
|
|
3279
|
+
...order,
|
|
3280
|
+
country_calling_code: String(order.country_calling_code ?? ""),
|
|
3281
|
+
phone: String(order.phone ?? ""),
|
|
3282
|
+
email: String(order.email ?? "")
|
|
3283
|
+
};
|
|
3284
|
+
const externalSaleNumber = next.external_sale_number;
|
|
3285
|
+
if (Number(next.is_draft_order || 0) === 1 && next.order_id !== void 0 && externalSaleNumber !== void 0 && String(next.order_id) === String(externalSaleNumber)) {
|
|
3286
|
+
delete next.order_id;
|
|
3287
|
+
}
|
|
3288
|
+
return next;
|
|
3289
|
+
}
|
|
2697
3290
|
getDeviceTaskPlugin() {
|
|
2698
3291
|
var _a, _b;
|
|
2699
3292
|
return ((_b = (_a = this.app) == null ? void 0 : _a.getPlugin) == null ? void 0 : _b.call(_a, "deviceTask")) || null;
|
|
@@ -3106,7 +3699,6 @@ var Server = class {
|
|
|
3106
3699
|
});
|
|
3107
3700
|
}
|
|
3108
3701
|
async handleOrderCheckoutSubmit(params) {
|
|
3109
|
-
var _a;
|
|
3110
3702
|
const { backendPath, data, title } = params;
|
|
3111
3703
|
this.logInfo(`${title}: 开始处理`, {
|
|
3112
3704
|
backendPath,
|
|
@@ -3131,15 +3723,14 @@ var Server = class {
|
|
|
3131
3723
|
});
|
|
3132
3724
|
if ((pendingResult == null ? void 0 : pendingResult.status) === true) {
|
|
3133
3725
|
const pendingOrder = pendingResult.data;
|
|
3134
|
-
|
|
3135
|
-
const isAndroid = platform === "android";
|
|
3136
|
-
if (pendingOrder && this.shouldBuildSmallTicketData(checkoutData) && this.isSalesOrderFullyPaid(pendingOrder) && // TODO 这里先加个兼容,如果是安卓,则需要 type=virtual 才走打印,如果是苹果则无限制
|
|
3137
|
-
(isAndroid ? checkoutData.type === "virtual" : true)) {
|
|
3726
|
+
if (pendingOrder && this.shouldBuildSmallTicketData(checkoutData) && this.isSalesOrderFullyPaid(pendingOrder) && this.shouldAutoPrintCheckoutReceipt()) {
|
|
3138
3727
|
await this.dispatchLocalReceiptPrint({
|
|
3139
3728
|
checkoutData,
|
|
3140
3729
|
order: pendingOrder,
|
|
3141
3730
|
response: pendingResult,
|
|
3142
|
-
requireFullyPaid: true
|
|
3731
|
+
requireFullyPaid: true,
|
|
3732
|
+
// 自动小票固定使用 print_all 的收据类型 0,不随订单 type 改成券/手环类型 99。
|
|
3733
|
+
isManualPrint: true
|
|
3143
3734
|
});
|
|
3144
3735
|
}
|
|
3145
3736
|
await this.dispatchCheckoutSyncTask({
|
|
@@ -3216,6 +3807,59 @@ var Server = class {
|
|
|
3216
3807
|
};
|
|
3217
3808
|
}
|
|
3218
3809
|
}
|
|
3810
|
+
async handleOrderDraftSubmit(params) {
|
|
3811
|
+
var _a, _b, _c;
|
|
3812
|
+
const { data, title } = params;
|
|
3813
|
+
this.logInfo(`${title}: 开始处理`, {
|
|
3814
|
+
order_id: data == null ? void 0 : data.order_id,
|
|
3815
|
+
external_sale_number: data == null ? void 0 : data.external_sale_number,
|
|
3816
|
+
order_number: data == null ? void 0 : data.order_number
|
|
3817
|
+
});
|
|
3818
|
+
const normalizedData = await this.normalizeCheckoutSubmitData(data, title);
|
|
3819
|
+
const createdAt = normalizedData.created_at || normalizedData.create_date || (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss");
|
|
3820
|
+
const draftOrder = {
|
|
3821
|
+
...normalizedData,
|
|
3822
|
+
external_sale_number: normalizedData.external_sale_number || `LOCAL_DRAFT_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`,
|
|
3823
|
+
created_at: createdAt,
|
|
3824
|
+
schedule_date: normalizedData.schedule_date || createdAt,
|
|
3825
|
+
need_sync: 0,
|
|
3826
|
+
is_draft_order: 1
|
|
3827
|
+
};
|
|
3828
|
+
if (!this.order || typeof this.order.upsertLocalDraftOrders !== "function") {
|
|
3829
|
+
this.logError(`${title}: Order 模块不支持本地草稿写入`);
|
|
3830
|
+
return {
|
|
3831
|
+
code: 500,
|
|
3832
|
+
status: false,
|
|
3833
|
+
message: "Order 模块不支持本地草稿写入",
|
|
3834
|
+
data: null
|
|
3835
|
+
};
|
|
3836
|
+
}
|
|
3837
|
+
try {
|
|
3838
|
+
await this.order.upsertLocalDraftOrders([draftOrder]);
|
|
3839
|
+
this.logInfo(`${title}: 草稿订单已写入本地`, {
|
|
3840
|
+
order_id: draftOrder.order_id,
|
|
3841
|
+
external_sale_number: draftOrder.external_sale_number
|
|
3842
|
+
});
|
|
3843
|
+
return {
|
|
3844
|
+
code: 200,
|
|
3845
|
+
status: true,
|
|
3846
|
+
message: "",
|
|
3847
|
+
data: {
|
|
3848
|
+
...draftOrder,
|
|
3849
|
+
amount_gap: (_a = draftOrder == null ? void 0 : draftOrder.summary) == null ? void 0 : _a.amount_gap,
|
|
3850
|
+
expect_amount: (_b = draftOrder == null ? void 0 : draftOrder.summary) == null ? void 0 : _b.expect_amount,
|
|
3851
|
+
total_amount: (_c = draftOrder == null ? void 0 : draftOrder.summary) == null ? void 0 : _c.total_amount,
|
|
3852
|
+
payment_status: draftOrder == null ? void 0 : draftOrder.payment_status
|
|
3853
|
+
}
|
|
3854
|
+
};
|
|
3855
|
+
} catch (error) {
|
|
3856
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
3857
|
+
this.logError(`${title}: 写入本地草稿订单失败`, {
|
|
3858
|
+
error: errorMessage
|
|
3859
|
+
});
|
|
3860
|
+
return { code: 500, status: false, message: errorMessage, data: null };
|
|
3861
|
+
}
|
|
3862
|
+
}
|
|
3219
3863
|
async handlePendingSyncCheckoutOrder(params) {
|
|
3220
3864
|
var _a, _b, _c, _d;
|
|
3221
3865
|
const { backendPath, data, title, reason } = params;
|
|
@@ -3291,7 +3935,8 @@ var Server = class {
|
|
|
3291
3935
|
return null;
|
|
3292
3936
|
const pendingOrder = {
|
|
3293
3937
|
...data,
|
|
3294
|
-
need_sync: 1
|
|
3938
|
+
need_sync: 1,
|
|
3939
|
+
is_draft_order: 0
|
|
3295
3940
|
};
|
|
3296
3941
|
const productMap = await this.buildSmallTicketProductMap(pendingOrder);
|
|
3297
3942
|
const orderWithProductTitles = this.withPendingSyncProductTitles(
|
|
@@ -3303,6 +3948,15 @@ var Server = class {
|
|
|
3303
3948
|
{ requireFullyPaid: true, productMap }
|
|
3304
3949
|
);
|
|
3305
3950
|
}
|
|
3951
|
+
/**
|
|
3952
|
+
* Android 结账自动小票由当前设备设置控制;其它平台保持原有行为。
|
|
3953
|
+
*/
|
|
3954
|
+
shouldAutoPrintCheckoutReceipt() {
|
|
3955
|
+
var _a, _b, _c, _d, _e;
|
|
3956
|
+
if (((_b = (_a = this.core.context) == null ? void 0 : _a.getPlatform) == null ? void 0 : _b.call(_a)) !== "android")
|
|
3957
|
+
return true;
|
|
3958
|
+
return ((_e = (_d = (_c = this.app) == null ? void 0 : _c.storage) == null ? void 0 : _d.getStorage) == null ? void 0 : _e.call(_d, AUTO_PRINT_STORAGE_KEY)) === "true";
|
|
3959
|
+
}
|
|
3306
3960
|
shouldBuildSmallTicketData(order) {
|
|
3307
3961
|
if (!order || typeof order !== "object")
|
|
3308
3962
|
return false;
|
|
@@ -3344,7 +3998,7 @@ var Server = class {
|
|
|
3344
3998
|
return 0;
|
|
3345
3999
|
return payments.reduce((sum, payment) => {
|
|
3346
4000
|
const status = String((payment == null ? void 0 : payment.status) || "").toLowerCase();
|
|
3347
|
-
if (status
|
|
4001
|
+
if (status !== "paid")
|
|
3348
4002
|
return sum;
|
|
3349
4003
|
return sum + this.toAmountNumber((payment == null ? void 0 : payment.amount) ?? (payment == null ? void 0 : payment.origin_amount));
|
|
3350
4004
|
}, 0);
|
|
@@ -3911,9 +4565,11 @@ var Server = class {
|
|
|
3911
4565
|
return value === void 0 ? void 0 : String(value);
|
|
3912
4566
|
}
|
|
3913
4567
|
buildCheckoutSyncSuccessPatch(fresh) {
|
|
4568
|
+
const patch = {
|
|
4569
|
+
is_draft_order: 0
|
|
4570
|
+
};
|
|
3914
4571
|
if (!fresh)
|
|
3915
|
-
return
|
|
3916
|
-
const patch = {};
|
|
4572
|
+
return patch;
|
|
3917
4573
|
if (fresh.order_id !== void 0 && fresh.order_id !== null)
|
|
3918
4574
|
patch.order_id = fresh.order_id;
|
|
3919
4575
|
if (fresh.order_number !== void 0 && fresh.order_number !== null) {
|
|
@@ -4194,6 +4850,10 @@ var Server = class {
|
|
|
4194
4850
|
const rawList = this.order.getOrders();
|
|
4195
4851
|
this.logInfo("computeOrderQueryResult: 本地订单数量", { rawCount: rawList.length });
|
|
4196
4852
|
const result = (0, import_filterOrders.filterOrders)(rawList, data);
|
|
4853
|
+
result.list.forEach((order) => {
|
|
4854
|
+
var _a;
|
|
4855
|
+
order.payments = (_a = order.payments) == null ? void 0 : _a.filter((payment) => !(0, import_payment_utils.isPendingOrderPayment)(payment));
|
|
4856
|
+
});
|
|
4197
4857
|
this.logInfo("computeOrderQueryResult: 过滤结果", {
|
|
4198
4858
|
rawCount: rawList.length,
|
|
4199
4859
|
filteredCount: result.count,
|