@pisell/pisellos 0.10.2 → 0.10.4
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 +0 -9
- package/dist/model/strategy/adapter/promotion/type.d.ts +90 -2
- package/dist/model/strategy/adapter/promotion/type.js +45 -0
- package/dist/modules/BaseModule.d.ts +1 -0
- package/dist/modules/BaseModule.js +24 -28
- package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +5 -3
- package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +6 -3
- package/dist/modules/OpenData/index.d.ts +2 -0
- package/dist/modules/OpenData/index.js +8 -0
- package/dist/modules/Order/index.d.ts +41 -10
- package/dist/modules/Order/index.js +943 -546
- 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 +43 -2
- 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 +79 -50
- package/dist/modules/Payment/types.d.ts +107 -28
- package/dist/modules/Payment/types.js +20 -3
- package/dist/modules/Payment/walletpass.d.ts +38 -1
- package/dist/modules/Payment/walletpass.js +917 -114
- package/dist/modules/ProductList/index.js +1 -1
- package/dist/modules/Rules/index.d.ts +3 -0
- package/dist/modules/Rules/index.js +130 -99
- package/dist/server/index.d.ts +16 -0
- package/dist/server/index.js +2084 -1188
- 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 +114 -14
- package/dist/solution/BaseSales/index.js +1848 -478
- 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 +90 -31
- 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 +8 -16
- package/dist/solution/BookingTicket/index.js +138 -52
- package/dist/solution/BookingTicket/types.d.ts +1 -0
- package/dist/solution/BookingTicket/utils/addProductDecision.js +6 -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/BookingTicket/utils/weighingProductSku.d.ts +5 -0
- package/dist/solution/BookingTicket/utils/weighingProductSku.js +45 -0
- package/dist/solution/Sales/index.d.ts +1 -0
- package/dist/solution/Sales/index.js +10 -2
- package/dist/solution/ScanOrder/index.js +31 -20
- package/dist/solution/UnifiedBookingSales/index.d.ts +3 -0
- package/dist/solution/UnifiedBookingSales/index.js +392 -304
- package/dist/solution/UnifiedBookingSales/types.d.ts +7 -0
- package/dist/solution/VenueBooking/index.d.ts +1 -0
- package/dist/solution/VenueBooking/index.js +34 -24
- 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 +2 -0
- package/lib/model/strategy/adapter/promotion/type.d.ts +90 -2
- package/lib/model/strategy/adapter/promotion/type.js +2 -0
- package/lib/modules/BaseModule.d.ts +1 -0
- package/lib/modules/BaseModule.js +24 -37
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +2 -1
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +2 -1
- package/lib/modules/OpenData/index.d.ts +2 -0
- package/lib/modules/OpenData/index.js +5 -0
- package/lib/modules/Order/index.d.ts +41 -10
- package/lib/modules/Order/index.js +322 -86
- 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 +43 -2
- 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 +34 -13
- package/lib/modules/Payment/types.d.ts +107 -28
- package/lib/modules/Payment/types.js +4 -3
- package/lib/modules/Payment/walletpass.d.ts +38 -1
- package/lib/modules/Payment/walletpass.js +730 -21
- package/lib/modules/ProductList/index.js +9 -1
- package/lib/modules/Rules/index.d.ts +3 -0
- package/lib/modules/Rules/index.js +39 -10
- package/lib/server/index.d.ts +16 -0
- package/lib/server/index.js +677 -28
- 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 +114 -14
- package/lib/solution/BaseSales/index.js +907 -58
- 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 +63 -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 +8 -16
- package/lib/solution/BookingTicket/index.js +63 -9
- package/lib/solution/BookingTicket/types.d.ts +1 -0
- package/lib/solution/BookingTicket/utils/addProductDecision.js +4 -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/BookingTicket/utils/weighingProductSku.d.ts +5 -0
- package/lib/solution/BookingTicket/utils/weighingProductSku.js +63 -0
- package/lib/solution/Sales/index.d.ts +1 -0
- package/lib/solution/Sales/index.js +5 -3
- package/lib/solution/ScanOrder/index.js +8 -0
- package/lib/solution/UnifiedBookingSales/index.d.ts +3 -0
- package/lib/solution/UnifiedBookingSales/index.js +48 -2
- package/lib/solution/UnifiedBookingSales/types.d.ts +7 -0
- package/lib/solution/VenueBooking/index.d.ts +1 -0
- package/lib/solution/VenueBooking/index.js +13 -6
- 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
|
@@ -40,6 +40,8 @@ var import_decimal = __toESM(require("decimal.js"));
|
|
|
40
40
|
var import_lodash_es = require("lodash-es");
|
|
41
41
|
var import_types2 = require("../BookingByStep/types");
|
|
42
42
|
var import_utils = require("../../modules/Order/utils");
|
|
43
|
+
var import_payment_utils = require("../../modules/Order/payment-utils");
|
|
44
|
+
var import_payment_number = require("../../utils/payment-number");
|
|
43
45
|
var import_orderCollectionIdentity = require("../../modules/Order/utils/orderCollectionIdentity");
|
|
44
46
|
var import_dayjs = __toESM(require("dayjs"));
|
|
45
47
|
__reExport(BaseSales_exports, require("./types"), module.exports);
|
|
@@ -47,6 +49,88 @@ var import_Quotation = require("../../modules/Quotation");
|
|
|
47
49
|
var import_transformBaseProductToOrderProduct = require("./utils/transformBaseProductToOrderProduct");
|
|
48
50
|
var import_quotationPrice = require("./utils/quotationPrice");
|
|
49
51
|
var SERVER_ORDER_CHANGED_EVENT = "order:onOrdersChanged";
|
|
52
|
+
var WALLET_PAYMENT_CODE_BY_TAG = {
|
|
53
|
+
product_voucher: "PRODUCTVOUCHER",
|
|
54
|
+
gift_card: "GIFTCARD",
|
|
55
|
+
point_card: "POINTCARD"
|
|
56
|
+
};
|
|
57
|
+
function getSharedWalletAssetId(asset) {
|
|
58
|
+
return (asset == null ? void 0 : asset.id) ?? (asset == null ? void 0 : asset.voucher_id) ?? (asset == null ? void 0 : asset.code);
|
|
59
|
+
}
|
|
60
|
+
function getSharedWalletAssetAmount(asset) {
|
|
61
|
+
const value = (asset == null ? void 0 : asset.edit_current_amount) ?? (asset == null ? void 0 : asset._available_max_amount) ?? ((asset == null ? void 0 : asset.tag) === "point_card" ? asset == null ? void 0 : asset.recommended_usage_amount : asset == null ? void 0 : asset.available_max_amount) ?? (asset == null ? void 0 : asset.actualDeduction) ?? (asset == null ? void 0 : asset.amount) ?? 0;
|
|
62
|
+
const amount = Number(value);
|
|
63
|
+
return Number.isFinite(amount) && amount > 0 ? amount : 0;
|
|
64
|
+
}
|
|
65
|
+
function isRejectedSalesSubmitResult(result) {
|
|
66
|
+
var _a, _b;
|
|
67
|
+
const candidates = [
|
|
68
|
+
result,
|
|
69
|
+
result == null ? void 0 : result.data,
|
|
70
|
+
(_a = result == null ? void 0 : result.response) == null ? void 0 : _a.data,
|
|
71
|
+
(_b = result == null ? void 0 : result.response) == null ? void 0 : _b.body
|
|
72
|
+
];
|
|
73
|
+
return candidates.some((candidate) => {
|
|
74
|
+
if (!candidate || typeof candidate !== "object")
|
|
75
|
+
return false;
|
|
76
|
+
const responseCode = Number(candidate.code ?? candidate.statusCode);
|
|
77
|
+
if (Number.isFinite(responseCode) && responseCode >= 400)
|
|
78
|
+
return true;
|
|
79
|
+
if (candidate.status === false || candidate.success === false || candidate.result === false) {
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
return ["failed", "error"].includes(
|
|
83
|
+
String(candidate.status || "").toLowerCase()
|
|
84
|
+
);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
function getSalesSubmitErrorMessage(result) {
|
|
88
|
+
var _a, _b;
|
|
89
|
+
return (result == null ? void 0 : result.message) || (result == null ? void 0 : result.msg) || ((_a = result == null ? void 0 : result.data) == null ? void 0 : _a.message) || ((_b = result == null ? void 0 : result.data) == null ? void 0 : _b.msg) || "Wallet 支付确认失败";
|
|
90
|
+
}
|
|
91
|
+
function toWalletFundValue(value) {
|
|
92
|
+
try {
|
|
93
|
+
return new import_decimal.default(value || 0).toDecimalPlaces(2).toFixed(2);
|
|
94
|
+
} catch {
|
|
95
|
+
return "0.00";
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function subtractWalletFundValue(left, right) {
|
|
99
|
+
try {
|
|
100
|
+
return new import_decimal.default(left || 0).minus(right || 0).toDecimalPlaces(2).toFixed(2);
|
|
101
|
+
} catch {
|
|
102
|
+
return "0.00";
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function getSharedWalletPassUseValue(params) {
|
|
106
|
+
const { asset, amount, paymentMethod } = params;
|
|
107
|
+
const configuredValue = Number(asset == null ? void 0 : asset.wallet_pass_use_value);
|
|
108
|
+
if (Number.isFinite(configuredValue) && configuredValue > 0) {
|
|
109
|
+
return configuredValue;
|
|
110
|
+
}
|
|
111
|
+
const isPointCard = (asset == null ? void 0 : asset.tag) === "point_card" || paymentMethod.code === "POINTCARD";
|
|
112
|
+
const usageUnit = asset == null ? void 0 : asset.wallet_pass_usage_unit;
|
|
113
|
+
if (isPointCard && (usageUnit == null ? void 0 : usageUnit.points) && (usageUnit == null ? void 0 : usageUnit.price)) {
|
|
114
|
+
return new import_decimal.default(amount).div(usageUnit.price).mul(usageUnit.points).toDecimalPlaces(2, import_decimal.default.ROUND_DOWN).toNumber();
|
|
115
|
+
}
|
|
116
|
+
return amount;
|
|
117
|
+
}
|
|
118
|
+
function buildSharedWalletFundRecord(params) {
|
|
119
|
+
const { asset, amount, paymentMethod } = params;
|
|
120
|
+
const isPointCard = (asset == null ? void 0 : asset.tag) === "point_card" || paymentMethod.code === "POINTCARD";
|
|
121
|
+
const usingBeforeValue = (asset == null ? void 0 : asset.balance_par_value) ?? (asset == null ? void 0 : asset.balance) ?? (asset == null ? void 0 : asset.using_before_value) ?? 0;
|
|
122
|
+
const walletPassUseValue = getSharedWalletPassUseValue(params);
|
|
123
|
+
const usingValue = isPointCard ? walletPassUseValue : amount;
|
|
124
|
+
const walletPassName = (asset == null ? void 0 : asset.wallet_pass_name) || (asset == null ? void 0 : asset.format_title) || (asset == null ? void 0 : asset.product_name) || (asset == null ? void 0 : asset.name) || paymentMethod.name;
|
|
125
|
+
return {
|
|
126
|
+
voucher_id: (asset == null ? void 0 : asset.voucher_id) ?? (asset == null ? void 0 : asset.id),
|
|
127
|
+
wallet_pass_name: walletPassName && typeof walletPassName === "object" ? walletPassName : { default: walletPassName || "" },
|
|
128
|
+
code: (asset == null ? void 0 : asset.code) || (asset == null ? void 0 : asset.tag),
|
|
129
|
+
encoded: asset == null ? void 0 : asset.encoded,
|
|
130
|
+
using_before_value: toWalletFundValue(usingBeforeValue),
|
|
131
|
+
using_after_value: subtractWalletFundValue(usingBeforeValue, usingValue)
|
|
132
|
+
};
|
|
133
|
+
}
|
|
50
134
|
function isBaseSalesManualProductDiscountProduct(product) {
|
|
51
135
|
var _a, _b;
|
|
52
136
|
return ((_a = product == null ? void 0 : product.metadata) == null ? void 0 : _a.is_manual_discount) === true || ((_b = product == null ? void 0 : product.metadata) == null ? void 0 : _b.is_manual_discount) === 1 || ((product == null ? void 0 : product.discount_list) || []).some((item) => (item == null ? void 0 : item.type) === "product");
|
|
@@ -77,6 +161,11 @@ function isBaseSalesHistoricalDiscountEntry(discount) {
|
|
|
77
161
|
(discount == null ? void 0 : discount.isEditMode) || (discount == null ? void 0 : discount.isDisabled) || (discount == null ? void 0 : discount.order_discount_id) != null
|
|
78
162
|
);
|
|
79
163
|
}
|
|
164
|
+
function getBaseSalesUniqueArrayMetadataKey(key) {
|
|
165
|
+
if (key === "products" || key === "bookings")
|
|
166
|
+
return "unique_identification_number";
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
80
169
|
var BASE_SALES_PERSISTENT_ID_FIELD_BY_KIND = {
|
|
81
170
|
product: "order_detail_id",
|
|
82
171
|
booking: "schedule_event_id",
|
|
@@ -150,6 +239,15 @@ function mergeBaseSalesCollectionItem(kind, currentItem, incomingItem, uidRemaps
|
|
|
150
239
|
return kind === "product" ? mergeBaseSalesProductSnapshotFields(currentItem, mergedItem) : mergedItem;
|
|
151
240
|
}
|
|
152
241
|
function mergeBaseSalesOrderCollection(kind, currentValue, incomingValue, strategy, uidRemaps) {
|
|
242
|
+
if (kind === "payment") {
|
|
243
|
+
return (0, import_payment_utils.mergeOrderPaymentListsByIdentity)(
|
|
244
|
+
currentValue,
|
|
245
|
+
incomingValue,
|
|
246
|
+
strategy === "preserve-local" ? { preserveUnmatchedExisting: true } : {
|
|
247
|
+
preserveUnmatchedExistingWhen: (payment) => (0, import_payment_utils.isIdentifiedPendingOrderPayment)(payment) || !(0, import_orderCollectionIdentity.getOrderCollectionPersistentId)("payment", payment)
|
|
248
|
+
}
|
|
249
|
+
);
|
|
250
|
+
}
|
|
153
251
|
const currentItems = (0, import_orderCollectionIdentity.normalizeOrderCollection)(kind, currentValue, {
|
|
154
252
|
ensureUid: false
|
|
155
253
|
}).items;
|
|
@@ -209,6 +307,35 @@ function normalizeBaseSalesRecordCollections(sourceRecord, options) {
|
|
|
209
307
|
}
|
|
210
308
|
return normalizedRecord;
|
|
211
309
|
}
|
|
310
|
+
function getBaseSalesMetadataUid(item, metadataKey) {
|
|
311
|
+
var _a;
|
|
312
|
+
const uid = ((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a[metadataKey]) ?? (item == null ? void 0 : item[metadataKey]);
|
|
313
|
+
if (uid === void 0 || uid === null || uid === "")
|
|
314
|
+
return null;
|
|
315
|
+
return String(uid);
|
|
316
|
+
}
|
|
317
|
+
function mergeBaseSalesUniqueArray(currentValue, loadedValue, metadataKey) {
|
|
318
|
+
const result = [];
|
|
319
|
+
const indexByUid = /* @__PURE__ */ new Map();
|
|
320
|
+
const appendOrReplaceByUid = (item) => {
|
|
321
|
+
const clonedItem = (0, import_lodash_es.cloneDeep)(item);
|
|
322
|
+
const uid = getBaseSalesMetadataUid(clonedItem, metadataKey);
|
|
323
|
+
if (!uid) {
|
|
324
|
+
result.push(clonedItem);
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
const existingIndex = indexByUid.get(uid);
|
|
328
|
+
if (existingIndex !== void 0) {
|
|
329
|
+
result[existingIndex] = clonedItem;
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
indexByUid.set(uid, result.length);
|
|
333
|
+
result.push(clonedItem);
|
|
334
|
+
};
|
|
335
|
+
currentValue.forEach(appendOrReplaceByUid);
|
|
336
|
+
loadedValue.forEach(appendOrReplaceByUid);
|
|
337
|
+
return result;
|
|
338
|
+
}
|
|
212
339
|
function mergeSalesDetailRecordWithTempOrder(currentTempOrder, loadedRecord, strategy) {
|
|
213
340
|
const normalizedLoadedRecord = normalizeBaseSalesRecordCollections(
|
|
214
341
|
loadedRecord || {},
|
|
@@ -237,6 +364,15 @@ function mergeSalesDetailRecordWithTempOrder(currentTempOrder, loadedRecord, str
|
|
|
237
364
|
);
|
|
238
365
|
}
|
|
239
366
|
if (Array.isArray(currentValue) && Array.isArray(loadedValue)) {
|
|
367
|
+
if (key === "payments" || key === "payment") {
|
|
368
|
+
return (0, import_payment_utils.mergeOrderPaymentListsByIdentity)(currentValue, loadedValue, {
|
|
369
|
+
preserveUnmatchedExisting: true
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
const metadataKey = getBaseSalesUniqueArrayMetadataKey(key);
|
|
373
|
+
if (metadataKey) {
|
|
374
|
+
return mergeBaseSalesUniqueArray(currentValue, loadedValue, metadataKey);
|
|
375
|
+
}
|
|
240
376
|
return [
|
|
241
377
|
...(0, import_lodash_es.cloneDeep)(currentValue),
|
|
242
378
|
...(0, import_lodash_es.cloneDeep)(loadedValue)
|
|
@@ -255,6 +391,18 @@ function mergeSalesDetailRecordWithTempOrder(currentTempOrder, loadedRecord, str
|
|
|
255
391
|
(0, import_orderCollectionIdentity.applyOrderCollectionUidRemaps)(mergedRecord, uidRemaps)
|
|
256
392
|
);
|
|
257
393
|
}
|
|
394
|
+
function filterPendingPaymentsFromLoadedSalesDetail(sourceRecord) {
|
|
395
|
+
if (!sourceRecord || typeof sourceRecord !== "object")
|
|
396
|
+
return sourceRecord;
|
|
397
|
+
const record = { ...sourceRecord };
|
|
398
|
+
if (Array.isArray(sourceRecord.payments)) {
|
|
399
|
+
record.payments = sourceRecord.payments.filter((payment) => !(0, import_payment_utils.isPendingOrderPayment)(payment));
|
|
400
|
+
}
|
|
401
|
+
if (Array.isArray(sourceRecord.payment)) {
|
|
402
|
+
record.payment = sourceRecord.payment.filter((payment) => !(0, import_payment_utils.isPendingOrderPayment)(payment));
|
|
403
|
+
}
|
|
404
|
+
return record;
|
|
405
|
+
}
|
|
258
406
|
var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
259
407
|
constructor(name, version) {
|
|
260
408
|
super(name, version);
|
|
@@ -266,6 +414,11 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
266
414
|
order: void 0
|
|
267
415
|
};
|
|
268
416
|
this.otherParams = {};
|
|
417
|
+
/**
|
|
418
|
+
* 由已在初始化阶段解析过设备短号的业务解决方案写入。
|
|
419
|
+
* 未设置时,支付编号仍按原逻辑实时读取设备信息。
|
|
420
|
+
*/
|
|
421
|
+
this.paymentNumberDevicePrefix = null;
|
|
269
422
|
// 当前缓存中已加载的最新 SalesDetail;只读 getter 走它对外暴露详情数据。
|
|
270
423
|
this.currentSalesDetail = null;
|
|
271
424
|
this.discountConfigCacheKey = null;
|
|
@@ -277,6 +430,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
277
430
|
this.autoPaymentSyncTimer = null;
|
|
278
431
|
this.salesDetailLoadInFlightCount = 0;
|
|
279
432
|
this.salesDetailLoadSequence = 0;
|
|
433
|
+
this.walletAssetsRefreshSequence = 0;
|
|
280
434
|
this.salesDetailHydrateQueue = Promise.resolve();
|
|
281
435
|
this.serverOrderChangeUnsubscribe = null;
|
|
282
436
|
this.serverOrderChangeHydrateInFlight = null;
|
|
@@ -434,7 +588,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
434
588
|
});
|
|
435
589
|
});
|
|
436
590
|
}
|
|
437
|
-
async hydrateLatestLoadedSalesDetail(record, loadSequence) {
|
|
591
|
+
async hydrateLatestLoadedSalesDetail(record, loadSequence, hydrateSource) {
|
|
438
592
|
let hydratedSales = null;
|
|
439
593
|
let skippedBeforeHydrate = false;
|
|
440
594
|
const hydrateTask = async () => {
|
|
@@ -444,9 +598,10 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
444
598
|
}
|
|
445
599
|
if (!this.store.order)
|
|
446
600
|
throw new Error("order 模块未初始化");
|
|
447
|
-
const sales = await this.store.order.hydrateTempOrderFromRecord(
|
|
448
|
-
|
|
449
|
-
|
|
601
|
+
const sales = await this.store.order.hydrateTempOrderFromRecord(
|
|
602
|
+
record,
|
|
603
|
+
hydrateSource === "sessionStorage" ? { recalcOnHydrate: true, source: "sessionStorage" } : { recalcOnHydrate: false }
|
|
604
|
+
);
|
|
450
605
|
hydratedSales = sales;
|
|
451
606
|
if (loadSequence !== this.salesDetailLoadSequence)
|
|
452
607
|
return;
|
|
@@ -737,12 +892,18 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
737
892
|
* const params = this.buildSubModuleOtherParams();
|
|
738
893
|
* this.core.registerModule(orderModule, { otherParams: params });
|
|
739
894
|
*/
|
|
740
|
-
|
|
895
|
+
isSessionStoragePersistEnabled() {
|
|
896
|
+
return Boolean(this.cacheId);
|
|
897
|
+
}
|
|
898
|
+
shouldUseSessionStorageForSubModule(_moduleName) {
|
|
899
|
+
return this.isSessionStoragePersistEnabled();
|
|
900
|
+
}
|
|
901
|
+
buildSubModuleOtherParams(moduleName) {
|
|
741
902
|
return {
|
|
742
903
|
...this.otherParams,
|
|
743
904
|
salesSummaryModuleName: `${this.name}_salesSummary`,
|
|
744
905
|
fatherModule: this.name,
|
|
745
|
-
openCache: this.
|
|
906
|
+
openCache: this.shouldUseSessionStorageForSubModule(moduleName),
|
|
746
907
|
cacheId: this.cacheId
|
|
747
908
|
};
|
|
748
909
|
}
|
|
@@ -753,7 +914,6 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
753
914
|
* await this.syncOtherParamsToSubModules({ channel: 'pos' });
|
|
754
915
|
*/
|
|
755
916
|
async syncOtherParamsToSubModules(changedParams, { cover = false } = {}) {
|
|
756
|
-
const nextSubModuleOtherParams = this.buildSubModuleOtherParams();
|
|
757
917
|
await Promise.all(
|
|
758
918
|
Object.entries(this.store).map(async ([moduleName, subModule]) => {
|
|
759
919
|
if (this.reusedSharedSubModuleNames.has(moduleName)) {
|
|
@@ -763,6 +923,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
763
923
|
if (!targetModule || typeof targetModule.updateOtherParams !== "function") {
|
|
764
924
|
return;
|
|
765
925
|
}
|
|
926
|
+
const nextSubModuleOtherParams = this.buildSubModuleOtherParams(moduleName);
|
|
766
927
|
await targetModule.updateOtherParams(nextSubModuleOtherParams, {
|
|
767
928
|
changedParams,
|
|
768
929
|
cover
|
|
@@ -775,14 +936,16 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
775
936
|
* sessionStorage 损坏时静默忽略,按空状态注册。
|
|
776
937
|
*/
|
|
777
938
|
readSessionCacheData() {
|
|
778
|
-
|
|
939
|
+
const cacheId = this.cacheId;
|
|
940
|
+
if (!cacheId || !this.isSessionStoragePersistEnabled() || !this.window) {
|
|
779
941
|
return {};
|
|
942
|
+
}
|
|
780
943
|
try {
|
|
781
944
|
const sessionData = this.window.sessionStorage.getItem(this.name);
|
|
782
945
|
if (!sessionData)
|
|
783
946
|
return {};
|
|
784
947
|
const data = JSON.parse(sessionData);
|
|
785
|
-
return data && data[
|
|
948
|
+
return data && data[cacheId] || {};
|
|
786
949
|
} catch {
|
|
787
950
|
return {};
|
|
788
951
|
}
|
|
@@ -796,6 +959,27 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
796
959
|
const coreData = (_f = (_d = (_c = app == null ? void 0 : app.models) == null ? void 0 : _c.getStore) == null ? void 0 : (_e = _d.call(_c)).getDataByModel) == null ? void 0 : _f.call(_e, "core", "core");
|
|
797
960
|
return coreData == null ? void 0 : coreData[key];
|
|
798
961
|
}
|
|
962
|
+
/**
|
|
963
|
+
* 复用业务解决方案初始化时已解析的支付设备短号。
|
|
964
|
+
* 空值会清除缓存,使后续支付恢复实时读取设备信息的兼容路径。
|
|
965
|
+
*/
|
|
966
|
+
setPaymentNumberDevicePrefix(prefix) {
|
|
967
|
+
const normalized = String(prefix ?? "").trim();
|
|
968
|
+
this.paymentNumberDevicePrefix = normalized || null;
|
|
969
|
+
}
|
|
970
|
+
getPaymentNumberDevicePrefixSync() {
|
|
971
|
+
if (!this.appPlugin)
|
|
972
|
+
return "LOCAL";
|
|
973
|
+
return (0, import_payment_number.resolvePaymentNumberDevicePrefixFromDeviceId)((key) => this.getAppData(key));
|
|
974
|
+
}
|
|
975
|
+
getPaymentNumberDevicePrefixAsync() {
|
|
976
|
+
if (!this.appPlugin)
|
|
977
|
+
return Promise.resolve("LOCAL");
|
|
978
|
+
if (this.paymentNumberDevicePrefix) {
|
|
979
|
+
return Promise.resolve(this.paymentNumberDevicePrefix);
|
|
980
|
+
}
|
|
981
|
+
return (0, import_payment_number.resolvePaymentNumberDevicePrefix)((key) => this.getAppData(key));
|
|
982
|
+
}
|
|
799
983
|
syncAppDataToTempOrder(tempOrder) {
|
|
800
984
|
const isPriceIncludeTax = this.getAppData("is_price_include_tax");
|
|
801
985
|
const taxCountryCode = this.getAppData("tax_country_code");
|
|
@@ -836,6 +1020,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
836
1020
|
var _a, _b, _c, _d;
|
|
837
1021
|
this.core = core;
|
|
838
1022
|
this.initializeOptions = options || {};
|
|
1023
|
+
this.paymentNumberDevicePrefix = null;
|
|
839
1024
|
this.otherParams = options.otherParams || {};
|
|
840
1025
|
this.cacheId = (_a = this.otherParams) == null ? void 0 : _a.cacheId;
|
|
841
1026
|
this.reusedSharedSubModuleNames.clear();
|
|
@@ -862,9 +1047,9 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
862
1047
|
const hooks = this.getSubModuleHooks(step);
|
|
863
1048
|
this.store[step] = targetModule;
|
|
864
1049
|
this.core.registerModule(targetModule, {
|
|
865
|
-
initialState: (targetCacheData == null ? void 0 : targetCacheData[targetModule.name]) || {},
|
|
1050
|
+
initialState: this.shouldUseSessionStorageForSubModule(step) ? (targetCacheData == null ? void 0 : targetCacheData[targetModule.name]) || {} : {},
|
|
866
1051
|
...hooks ? { hooks } : {},
|
|
867
|
-
otherParams: this.buildSubModuleOtherParams()
|
|
1052
|
+
otherParams: this.buildSubModuleOtherParams(step)
|
|
868
1053
|
});
|
|
869
1054
|
});
|
|
870
1055
|
if (this.store.schedule && !this.isScheduleListLoaded(this.store.schedule)) {
|
|
@@ -896,8 +1081,10 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
896
1081
|
}
|
|
897
1082
|
});
|
|
898
1083
|
this.currentSalesDetail = null;
|
|
1084
|
+
this.paymentNumberDevicePrefix = null;
|
|
899
1085
|
this.queuedServerOrderChanges = [];
|
|
900
1086
|
this.salesDetailLoadSequence += 1;
|
|
1087
|
+
this.walletAssetsRefreshSequence += 1;
|
|
901
1088
|
await this.core.effects.emit(`${this.name}:onDestroy`, {});
|
|
902
1089
|
super.destroy();
|
|
903
1090
|
}
|
|
@@ -929,14 +1116,21 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
929
1116
|
const message = loadedRecord && (loadedRecord.message || loadedRecord.msg) || `加载销售详情失败: ${lookup}`;
|
|
930
1117
|
throw new Error(message);
|
|
931
1118
|
}
|
|
932
|
-
const
|
|
1119
|
+
const loadedSalesDetail = preloadedSalesDetail ?? loadedRecord.data;
|
|
1120
|
+
const shouldFilterPendingPayments = params.hydrateSource !== "sessionStorage";
|
|
1121
|
+
const remoteRecord = shouldFilterPendingPayments ? filterPendingPaymentsFromLoadedSalesDetail(loadedSalesDetail) : loadedSalesDetail;
|
|
933
1122
|
const currentTempOrder = params.merge ? this.store.order.getTempOrder() : null;
|
|
934
|
-
const
|
|
1123
|
+
const mergedRecord = params.merge ? mergeSalesDetailRecordWithTempOrder(
|
|
935
1124
|
currentTempOrder,
|
|
936
1125
|
remoteRecord,
|
|
937
1126
|
"preserve-local"
|
|
938
1127
|
) : remoteRecord;
|
|
939
|
-
|
|
1128
|
+
const record = shouldFilterPendingPayments ? filterPendingPaymentsFromLoadedSalesDetail(mergedRecord) : mergedRecord;
|
|
1129
|
+
return await this.hydrateLatestLoadedSalesDetail(
|
|
1130
|
+
record,
|
|
1131
|
+
loadSequence,
|
|
1132
|
+
params.hydrateSource
|
|
1133
|
+
);
|
|
940
1134
|
} finally {
|
|
941
1135
|
this.salesDetailLoadInFlightCount = Math.max(
|
|
942
1136
|
0,
|
|
@@ -1111,6 +1305,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1111
1305
|
// 重置 tempOrder 与与上一单强相关的运行态(resource/entryPaxNumber/enabledReservationRuleProducts),
|
|
1112
1306
|
// 适用于从支付页通过 react-router 跳回继续下单时清理残留数据
|
|
1113
1307
|
async restoreOrder() {
|
|
1308
|
+
var _a;
|
|
1114
1309
|
try {
|
|
1115
1310
|
if (!this.store.order) {
|
|
1116
1311
|
throw new Error("scanOrder 解决方案需要 order 模块支持");
|
|
@@ -1119,6 +1314,12 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1119
1314
|
this.currentSalesDetail = null;
|
|
1120
1315
|
this.discountConfigCacheKey = null;
|
|
1121
1316
|
this.hasManualDiscountSelection = false;
|
|
1317
|
+
const wallet = (_a = this.store.payment) == null ? void 0 : _a.wallet;
|
|
1318
|
+
if (wallet) {
|
|
1319
|
+
this.walletAssetsRefreshSequence += 1;
|
|
1320
|
+
wallet.clearAllCache();
|
|
1321
|
+
await this.publishWalletAssetsState(wallet.getWalletAssetsState());
|
|
1322
|
+
}
|
|
1122
1323
|
await this.effectsEmit("onTempOrderReplaced", { tempOrder });
|
|
1123
1324
|
if (this.syncAppDataToTempOrder(tempOrder) && this.isTempOrderPersistEnabled()) {
|
|
1124
1325
|
this.store.order.persistTempOrder();
|
|
@@ -1531,6 +1732,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1531
1732
|
}
|
|
1532
1733
|
return {
|
|
1533
1734
|
isAvailable: raw.isAvailable,
|
|
1735
|
+
...raw.isAccepted !== void 0 ? { isAccepted: raw.isAccepted } : {},
|
|
1534
1736
|
type: raw.type,
|
|
1535
1737
|
unavailableReason: raw.unavailableReason,
|
|
1536
1738
|
scannedDiscountList: raw.scannedDiscountList
|
|
@@ -1727,6 +1929,20 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1727
1929
|
};
|
|
1728
1930
|
return this.shouldUseCheckoutSyncTask() ? this.store.order.submitTempOrder(submitParams) : this.store.order.submitTempOrderAsync(submitParams);
|
|
1729
1931
|
}
|
|
1932
|
+
async saveSalesOrderDraft(params) {
|
|
1933
|
+
var _a, _b, _c, _d;
|
|
1934
|
+
if (!this.store.order) {
|
|
1935
|
+
throw new Error("BaseSales 解决方案需要 order 模块支持");
|
|
1936
|
+
}
|
|
1937
|
+
return this.store.order.saveTempOrderAsDraft({
|
|
1938
|
+
cacheId: this.cacheId,
|
|
1939
|
+
platform: (params == null ? void 0 : params.platform) ?? ((_a = this.otherParams) == null ? void 0 : _a.platform),
|
|
1940
|
+
businessCode: (params == null ? void 0 : params.businessCode) || ((_b = this.otherParams) == null ? void 0 : _b.businessCode) || ((_c = this.otherParams) == null ? void 0 : _c.business_code),
|
|
1941
|
+
channel: (params == null ? void 0 : params.channel) ?? this.getSubmitOrderSalesChannel(),
|
|
1942
|
+
type: (params == null ? void 0 : params.type) ?? ((_d = this.otherParams) == null ? void 0 : _d.type),
|
|
1943
|
+
...(params == null ? void 0 : params.enhancePayload) !== void 0 ? { enhancePayload: params.enhancePayload } : {}
|
|
1944
|
+
});
|
|
1945
|
+
}
|
|
1730
1946
|
async submitTempOrderAsync(params) {
|
|
1731
1947
|
var _a, _b, _c, _d;
|
|
1732
1948
|
if (!this.store.order) {
|
|
@@ -1943,8 +2159,29 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1943
2159
|
}
|
|
1944
2160
|
}
|
|
1945
2161
|
}
|
|
1946
|
-
/**
|
|
2162
|
+
/**
|
|
2163
|
+
* 同步兼容入口。无法等待 IoT 短号时,按调用当下的 device_id 或 LOCAL 生成。
|
|
2164
|
+
*/
|
|
1947
2165
|
addOrderPayment(payment) {
|
|
2166
|
+
const hasPaymentNumber = String(
|
|
2167
|
+
payment.payment_number || ""
|
|
2168
|
+
).trim() !== "";
|
|
2169
|
+
return this.addOrderPaymentWithDevicePrefix(
|
|
2170
|
+
payment,
|
|
2171
|
+
hasPaymentNumber ? "LOCAL" : this.getPaymentNumberDevicePrefixSync()
|
|
2172
|
+
);
|
|
2173
|
+
}
|
|
2174
|
+
/**
|
|
2175
|
+
* 创建新支付项时优先使用业务解决方案初始化阶段缓存的设备短号;
|
|
2176
|
+
* 未缓存的通用 BaseSales 保持实时读取设备信息的兼容语义。
|
|
2177
|
+
*/
|
|
2178
|
+
async addOrderPaymentAsync(payment) {
|
|
2179
|
+
const paymentRecord = payment;
|
|
2180
|
+
const hasPaymentNumber = String(paymentRecord.payment_number || "").trim() !== "";
|
|
2181
|
+
const devicePrefix = hasPaymentNumber ? "LOCAL" : await this.getPaymentNumberDevicePrefixAsync();
|
|
2182
|
+
return this.addOrderPaymentWithDevicePrefix(payment, devicePrefix);
|
|
2183
|
+
}
|
|
2184
|
+
addOrderPaymentWithDevicePrefix(payment, devicePrefix) {
|
|
1948
2185
|
var _a;
|
|
1949
2186
|
if (!this.store.order)
|
|
1950
2187
|
throw new Error("order 模块未初始化");
|
|
@@ -1961,21 +2198,26 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1961
2198
|
if (shopWalletPassId !== void 0 && shopWalletPassId !== null) {
|
|
1962
2199
|
metadata.shop_wallet_pass_id = shopWalletPassId;
|
|
1963
2200
|
}
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
2201
|
+
const normalizedPaymentRecord = (0, import_payment_utils.ensureOrderPaymentNumber)(
|
|
2202
|
+
paymentRecord,
|
|
2203
|
+
devicePrefix,
|
|
2204
|
+
import_utils.createUuidV4
|
|
2205
|
+
);
|
|
1967
2206
|
const paymentTimestamp = (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss");
|
|
1968
2207
|
const paymentTime = paymentRecord.payment_time ?? paymentTimestamp;
|
|
1969
2208
|
const createdAt = paymentRecord.created_at ?? paymentTimestamp;
|
|
1970
2209
|
const serviceCharge = paymentRecord.service_charge && typeof paymentRecord.service_charge === "object" ? paymentRecord.service_charge : null;
|
|
1971
2210
|
const calculatedServiceFee = serviceCharge ? new import_decimal.default(paymentRecord.origin_amount ?? paymentRecord.amount ?? 0).times(serviceCharge.percentage || 0).plus(serviceCharge.amount || 0).toDecimalPlaces(2).toFixed(2) : void 0;
|
|
1972
2211
|
const payments = this.store.order.addOrderPayment({
|
|
1973
|
-
...
|
|
2212
|
+
...normalizedPaymentRecord,
|
|
1974
2213
|
...calculatedServiceFee !== void 0 ? { service_fee: calculatedServiceFee } : {},
|
|
1975
2214
|
metadata,
|
|
1976
2215
|
payment_time: paymentTime,
|
|
1977
2216
|
created_at: createdAt
|
|
1978
2217
|
});
|
|
2218
|
+
if (paymentRecord.status === "payment_pending") {
|
|
2219
|
+
return payments;
|
|
2220
|
+
}
|
|
1979
2221
|
const amountSnapshot = this.store.order.getOrderAmountSnapshot();
|
|
1980
2222
|
const syncState = this.store.order.getOrderSyncState();
|
|
1981
2223
|
if (amountSnapshot) {
|
|
@@ -1997,10 +2239,73 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1997
2239
|
return payments;
|
|
1998
2240
|
}
|
|
1999
2241
|
/** 更新当前订单中的指定支付项。 */
|
|
2000
|
-
updateOrderPayment(paymentIdentity, updates) {
|
|
2242
|
+
async updateOrderPayment(paymentIdentity, updates, options = {}) {
|
|
2243
|
+
var _a, _b, _c;
|
|
2001
2244
|
if (!this.store.order)
|
|
2002
2245
|
throw new Error("order 模块未初始化");
|
|
2003
|
-
|
|
2246
|
+
const matchMode = options.matchBy === "compat" || options.matchBy === "legacy" ? "compat" : "payment_number";
|
|
2247
|
+
const previousMatch = (0, import_payment_utils.resolveOrderPaymentIdentity)(
|
|
2248
|
+
this.store.order.getOrderPayments(),
|
|
2249
|
+
paymentIdentity,
|
|
2250
|
+
matchMode
|
|
2251
|
+
);
|
|
2252
|
+
const previousPayment = previousMatch == null ? void 0 : previousMatch.payment;
|
|
2253
|
+
if ((previousPayment == null ? void 0 : previousPayment.status) === "paid" && !options.applyUpdatesWhenPaid) {
|
|
2254
|
+
const currentPayments = this.store.order.getOrderPayments();
|
|
2255
|
+
let syncResult2;
|
|
2256
|
+
if (options.submitWhenPaid && options.forceSubmitIfPaid) {
|
|
2257
|
+
syncResult2 = await this.syncPaymentsToOrder({
|
|
2258
|
+
payments: currentPayments,
|
|
2259
|
+
paymentStatus: this.getPaymentStatusForSync(currentPayments),
|
|
2260
|
+
submitWhenPaid: true,
|
|
2261
|
+
smallTicketDataFlag: options.smallTicketDataFlag ?? 1
|
|
2262
|
+
});
|
|
2263
|
+
}
|
|
2264
|
+
return {
|
|
2265
|
+
updated: false,
|
|
2266
|
+
payment: previousPayment,
|
|
2267
|
+
payments: currentPayments,
|
|
2268
|
+
summary: ((_a = this.store.order.getOrderAmountSnapshot()) == null ? void 0 : _a.summary) || null,
|
|
2269
|
+
...syncResult2 !== void 0 ? { syncResult: syncResult2 } : {}
|
|
2270
|
+
};
|
|
2271
|
+
}
|
|
2272
|
+
const result = await this.store.order.updateOrderPayment(paymentIdentity, updates, {
|
|
2273
|
+
matchBy: matchMode
|
|
2274
|
+
});
|
|
2275
|
+
let draftResult;
|
|
2276
|
+
let draftError;
|
|
2277
|
+
if (options.persistDraft !== false) {
|
|
2278
|
+
try {
|
|
2279
|
+
draftResult = await this.saveSalesOrderDraft();
|
|
2280
|
+
} catch (error) {
|
|
2281
|
+
draftError = error;
|
|
2282
|
+
this.logError("updateOrderPayment: 保存支付草稿失败", {
|
|
2283
|
+
paymentIdentity,
|
|
2284
|
+
error: error instanceof Error ? error.message : String(error)
|
|
2285
|
+
});
|
|
2286
|
+
if (!options.submitWhenPaid)
|
|
2287
|
+
throw error;
|
|
2288
|
+
}
|
|
2289
|
+
}
|
|
2290
|
+
const becamePaid = (previousPayment == null ? void 0 : previousPayment.status) !== "paid" && ((_b = result.payment) == null ? void 0 : _b.status) === "paid";
|
|
2291
|
+
const shouldSubmit = Boolean(
|
|
2292
|
+
options.submitWhenPaid && ((_c = result.payment) == null ? void 0 : _c.status) === "paid" && (becamePaid || options.forceSubmitIfPaid)
|
|
2293
|
+
);
|
|
2294
|
+
let syncResult;
|
|
2295
|
+
if (shouldSubmit) {
|
|
2296
|
+
syncResult = await this.syncPaymentsToOrder({
|
|
2297
|
+
payments: result.payments,
|
|
2298
|
+
paymentStatus: this.getPaymentStatusForSync(result.payments),
|
|
2299
|
+
submitWhenPaid: true,
|
|
2300
|
+
smallTicketDataFlag: options.smallTicketDataFlag ?? 1
|
|
2301
|
+
});
|
|
2302
|
+
}
|
|
2303
|
+
return {
|
|
2304
|
+
...result,
|
|
2305
|
+
...draftResult !== void 0 ? { draftResult } : {},
|
|
2306
|
+
...draftError !== void 0 ? { draftError } : {},
|
|
2307
|
+
...syncResult !== void 0 ? { syncResult } : {}
|
|
2308
|
+
};
|
|
2004
2309
|
}
|
|
2005
2310
|
/** 删除当前订单中的指定支付项。 */
|
|
2006
2311
|
deleteOrderPayment(paymentIdentity) {
|
|
@@ -2014,10 +2319,24 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
2014
2319
|
throw new Error("order 模块未初始化");
|
|
2015
2320
|
return this.store.order.updateVoucherOrderPayments(payments, options);
|
|
2016
2321
|
}
|
|
2322
|
+
async updateVoucherOrderPaymentsAsync(payments, options) {
|
|
2323
|
+
if (!this.store.order)
|
|
2324
|
+
throw new Error("order 模块未初始化");
|
|
2325
|
+
return this.store.order.updateVoucherOrderPaymentsAsync(payments, options);
|
|
2326
|
+
}
|
|
2017
2327
|
confirmPendingVoucherPayments() {
|
|
2018
2328
|
if (!this.store.order)
|
|
2019
2329
|
throw new Error("order 模块未初始化");
|
|
2020
|
-
|
|
2330
|
+
const payments = this.store.order.confirmPendingVoucherPayments();
|
|
2331
|
+
if (this.store.payment) {
|
|
2332
|
+
const committed = this.getCommittedWalletAssets();
|
|
2333
|
+
const state = this.store.payment.wallet.setCommittedWalletAssets(
|
|
2334
|
+
committed.ids,
|
|
2335
|
+
committed.assets
|
|
2336
|
+
);
|
|
2337
|
+
void this.publishWalletAssetsState(state);
|
|
2338
|
+
}
|
|
2339
|
+
return payments;
|
|
2021
2340
|
}
|
|
2022
2341
|
discardPendingVoucherPayments() {
|
|
2023
2342
|
if (!this.store.order)
|
|
@@ -2078,24 +2397,14 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
2078
2397
|
});
|
|
2079
2398
|
return walletProducts;
|
|
2080
2399
|
}
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
if (!this.store.payment)
|
|
2085
|
-
throw new Error("payment 模块未初始化");
|
|
2086
|
-
const snapshot = this.store.order.getOrderSnapshot();
|
|
2400
|
+
buildWalletInitBusinessData(params) {
|
|
2401
|
+
var _a;
|
|
2402
|
+
const snapshot = (_a = this.store.order) == null ? void 0 : _a.getOrderSnapshot();
|
|
2087
2403
|
const tempOrder = snapshot == null ? void 0 : snapshot.tempOrder;
|
|
2088
2404
|
const amount = snapshot == null ? void 0 : snapshot.amount;
|
|
2089
|
-
if (!tempOrder || !amount)
|
|
2090
|
-
return
|
|
2091
|
-
|
|
2092
|
-
userIdentificationCodes: [],
|
|
2093
|
-
transformList: [],
|
|
2094
|
-
noApplicableVoucher: [],
|
|
2095
|
-
products: []
|
|
2096
|
-
};
|
|
2097
|
-
}
|
|
2098
|
-
const walletBusinessData = {
|
|
2405
|
+
if (!tempOrder || !amount)
|
|
2406
|
+
return null;
|
|
2407
|
+
return {
|
|
2099
2408
|
customer_id: tempOrder.customer_id ? Number(tempOrder.customer_id) : void 0,
|
|
2100
2409
|
holder: tempOrder.holder,
|
|
2101
2410
|
amountInfo: {
|
|
@@ -2109,11 +2418,29 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
2109
2418
|
is_price_include_tax: tempOrder.is_price_include_tax ?? this.otherParams.is_price_include_tax ?? 1,
|
|
2110
2419
|
...snapshot.identity.orderId ? { payment_order_id: String(snapshot.identity.orderId) } : {}
|
|
2111
2420
|
};
|
|
2421
|
+
}
|
|
2422
|
+
async initWalletData(params) {
|
|
2423
|
+
var _a;
|
|
2424
|
+
if (!this.store.order)
|
|
2425
|
+
throw new Error("order 模块未初始化");
|
|
2426
|
+
if (!this.store.payment)
|
|
2427
|
+
throw new Error("payment 模块未初始化");
|
|
2428
|
+
const snapshot = this.store.order.getOrderSnapshot();
|
|
2429
|
+
const walletBusinessData = this.buildWalletInitBusinessData(params);
|
|
2430
|
+
if (!walletBusinessData) {
|
|
2431
|
+
return {
|
|
2432
|
+
walletRecommendList: [],
|
|
2433
|
+
userIdentificationCodes: [],
|
|
2434
|
+
transformList: [],
|
|
2435
|
+
noApplicableVoucher: [],
|
|
2436
|
+
products: []
|
|
2437
|
+
};
|
|
2438
|
+
}
|
|
2112
2439
|
const result = await this.store.payment.wallet.initializeWalletDataFromBusinessAsync(
|
|
2113
2440
|
walletBusinessData
|
|
2114
2441
|
);
|
|
2115
2442
|
await this.core.effects.emit(`${this.name}:onWalletDataInitialized`, {
|
|
2116
|
-
orderId: snapshot.identity.orderId,
|
|
2443
|
+
orderId: (_a = snapshot == null ? void 0 : snapshot.identity) == null ? void 0 : _a.orderId,
|
|
2117
2444
|
customerId: walletBusinessData.customer_id,
|
|
2118
2445
|
walletBusinessData: {
|
|
2119
2446
|
customer_id: walletBusinessData.customer_id,
|
|
@@ -2124,6 +2451,208 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
2124
2451
|
});
|
|
2125
2452
|
return result;
|
|
2126
2453
|
}
|
|
2454
|
+
getCommittedWalletAssets() {
|
|
2455
|
+
var _a, _b;
|
|
2456
|
+
const payments = ((_b = (_a = this.store.order) == null ? void 0 : _a.getOrderPayments) == null ? void 0 : _b.call(_a)) || [];
|
|
2457
|
+
const committed = payments.filter((payment) => {
|
|
2458
|
+
const voucherId = payment == null ? void 0 : payment.voucher_id;
|
|
2459
|
+
if (voucherId === void 0 || voucherId === null || voucherId === 0) {
|
|
2460
|
+
return false;
|
|
2461
|
+
}
|
|
2462
|
+
return (payment == null ? void 0 : payment.status) === "paid" || (payment == null ? void 0 : payment.isSynced) === true || (payment == null ? void 0 : payment.order_payment_id) !== void 0 && (payment == null ? void 0 : payment.order_payment_id) !== null && (payment == null ? void 0 : payment.order_payment_id) !== "";
|
|
2463
|
+
});
|
|
2464
|
+
return {
|
|
2465
|
+
ids: committed.map((payment) => payment.voucher_id),
|
|
2466
|
+
assets: committed.map((payment) => {
|
|
2467
|
+
var _a2;
|
|
2468
|
+
const fundRecord = (payment == null ? void 0 : payment.fund_record) || {};
|
|
2469
|
+
const walletPassName = fundRecord.wallet_pass_name;
|
|
2470
|
+
const title = walletPassName && typeof walletPassName === "object" ? walletPassName.default || Object.values(walletPassName)[0] : walletPassName;
|
|
2471
|
+
const code = String((payment == null ? void 0 : payment.code) || "").toUpperCase();
|
|
2472
|
+
const tag = ((_a2 = Object.entries(WALLET_PAYMENT_CODE_BY_TAG).find(
|
|
2473
|
+
([, paymentCode]) => paymentCode === code
|
|
2474
|
+
)) == null ? void 0 : _a2[0]) || fundRecord.tag;
|
|
2475
|
+
return {
|
|
2476
|
+
id: payment.voucher_id,
|
|
2477
|
+
voucher_id: payment.voucher_id,
|
|
2478
|
+
code: fundRecord.code,
|
|
2479
|
+
tag,
|
|
2480
|
+
product_name: title || payment.name,
|
|
2481
|
+
name: title || payment.name,
|
|
2482
|
+
amount: Number(payment.amount || 0),
|
|
2483
|
+
_available_max_amount: Number(payment.amount || 0),
|
|
2484
|
+
unified_available_status: 1,
|
|
2485
|
+
_unified_available_status: 1,
|
|
2486
|
+
_committed_payment: payment
|
|
2487
|
+
};
|
|
2488
|
+
})
|
|
2489
|
+
};
|
|
2490
|
+
}
|
|
2491
|
+
async publishWalletAssetsState(state) {
|
|
2492
|
+
await this.effectsEmit(import_types.BaseSalesHookNames.onWalletAssetsStateChanged, {
|
|
2493
|
+
state
|
|
2494
|
+
});
|
|
2495
|
+
return state;
|
|
2496
|
+
}
|
|
2497
|
+
async syncSelectedWalletAssets(state) {
|
|
2498
|
+
if (!this.store.order || !this.store.payment) {
|
|
2499
|
+
throw new Error("订单或支付模块未初始化");
|
|
2500
|
+
}
|
|
2501
|
+
let paymentMethods = this.getPaymentMethods();
|
|
2502
|
+
if (!paymentMethods.length && state.selectedItems.length) {
|
|
2503
|
+
paymentMethods = await this.getPaymentMethodsAsync();
|
|
2504
|
+
}
|
|
2505
|
+
const methodByCode = new Map(
|
|
2506
|
+
paymentMethods.map((method) => [String(method.code || "").toUpperCase(), method])
|
|
2507
|
+
);
|
|
2508
|
+
const preparePayments = this.store.payment.wallet.formatWalletPassList2PreparePayments(
|
|
2509
|
+
state.selectedItems
|
|
2510
|
+
);
|
|
2511
|
+
const selectedAssetById = new Map(
|
|
2512
|
+
state.selectedItems.map((asset) => [
|
|
2513
|
+
String(getSharedWalletAssetId(asset)),
|
|
2514
|
+
asset
|
|
2515
|
+
])
|
|
2516
|
+
);
|
|
2517
|
+
const voucherPayments = preparePayments.flatMap((item) => {
|
|
2518
|
+
const asset = selectedAssetById.get(String(item.voucher_id));
|
|
2519
|
+
const paymentCode = WALLET_PAYMENT_CODE_BY_TAG[String(item.tag || (asset == null ? void 0 : asset.tag) || "")] || String(item.tag || (asset == null ? void 0 : asset.tag) || "").toUpperCase();
|
|
2520
|
+
const paymentMethod = methodByCode.get(paymentCode);
|
|
2521
|
+
const formattedAmount = Number(item.amount);
|
|
2522
|
+
const amount = Number.isFinite(formattedAmount) && formattedAmount > 0 ? formattedAmount : getSharedWalletAssetAmount(asset);
|
|
2523
|
+
if (!asset || !paymentMethod || !Number.isFinite(amount) || amount <= 0) {
|
|
2524
|
+
return [];
|
|
2525
|
+
}
|
|
2526
|
+
const walletPassUseValue = getSharedWalletPassUseValue({
|
|
2527
|
+
asset,
|
|
2528
|
+
amount,
|
|
2529
|
+
paymentMethod
|
|
2530
|
+
});
|
|
2531
|
+
return [
|
|
2532
|
+
{
|
|
2533
|
+
amount: amount.toFixed(2),
|
|
2534
|
+
code: paymentMethod.code,
|
|
2535
|
+
custom_payment_id: paymentMethod.id,
|
|
2536
|
+
name: paymentMethod.name,
|
|
2537
|
+
type: paymentMethod.type,
|
|
2538
|
+
voucher_id: item.voucher_id,
|
|
2539
|
+
wallet_pass_usage_unit: item.wallet_pass_usage_unit,
|
|
2540
|
+
wallet_pass_use_value: walletPassUseValue,
|
|
2541
|
+
fund_record: buildSharedWalletFundRecord({
|
|
2542
|
+
asset,
|
|
2543
|
+
amount,
|
|
2544
|
+
paymentMethod
|
|
2545
|
+
})
|
|
2546
|
+
}
|
|
2547
|
+
];
|
|
2548
|
+
});
|
|
2549
|
+
const payments = this.updateVoucherOrderPayments(voucherPayments, {
|
|
2550
|
+
status: "payment_pending"
|
|
2551
|
+
});
|
|
2552
|
+
await this.store.order.recalculateSummary({ createIfMissing: true });
|
|
2553
|
+
return payments;
|
|
2554
|
+
}
|
|
2555
|
+
/** 读取购物车与 Shared Checkout 共用的钱包资产状态。 */
|
|
2556
|
+
getWalletAssetsState() {
|
|
2557
|
+
if (!this.store.payment)
|
|
2558
|
+
throw new Error("payment 模块未初始化");
|
|
2559
|
+
return this.store.payment.wallet.getWalletAssetsState();
|
|
2560
|
+
}
|
|
2561
|
+
/** 导出 Shared Checkout 跨运行时恢复所需的钱包状态与搜索缓存。 */
|
|
2562
|
+
exportWalletAssetsSnapshot() {
|
|
2563
|
+
if (!this.store.payment)
|
|
2564
|
+
throw new Error("payment 模块未初始化");
|
|
2565
|
+
return this.store.payment.wallet.exportWalletAssetsSnapshot();
|
|
2566
|
+
}
|
|
2567
|
+
/** 配置仅影响 Wallet Assets,不改变 Promotion/Voucher 选择流程。 */
|
|
2568
|
+
configureWalletAssetsBehavior(options) {
|
|
2569
|
+
if (!this.store.payment)
|
|
2570
|
+
throw new Error("payment 模块未初始化");
|
|
2571
|
+
this.store.payment.wallet.configureWalletAssetsBehavior(options);
|
|
2572
|
+
}
|
|
2573
|
+
/**
|
|
2574
|
+
* 恢复 Shared Checkout 钱包快照,并把选择重新同步为订单 pending payment。
|
|
2575
|
+
*/
|
|
2576
|
+
async importWalletAssetsSnapshot(snapshot) {
|
|
2577
|
+
if (!this.store.payment)
|
|
2578
|
+
throw new Error("payment 模块未初始化");
|
|
2579
|
+
const state = this.store.payment.wallet.importWalletAssetsSnapshot(snapshot);
|
|
2580
|
+
await this.syncSelectedWalletAssets(state);
|
|
2581
|
+
return this.publishWalletAssetsState(state);
|
|
2582
|
+
}
|
|
2583
|
+
/**
|
|
2584
|
+
* 基于当前订单快照刷新钱包资产。商品变化保留并重验选择;客户变化强制清空。
|
|
2585
|
+
*/
|
|
2586
|
+
async refreshWalletAssets(params) {
|
|
2587
|
+
if (!this.store.order)
|
|
2588
|
+
throw new Error("order 模块未初始化");
|
|
2589
|
+
if (!this.store.payment)
|
|
2590
|
+
throw new Error("payment 模块未初始化");
|
|
2591
|
+
const refreshSequence = ++this.walletAssetsRefreshSequence;
|
|
2592
|
+
const wallet = this.store.payment.wallet;
|
|
2593
|
+
const businessData = this.buildWalletInitBusinessData(params);
|
|
2594
|
+
if (!businessData) {
|
|
2595
|
+
wallet.clearAllCache();
|
|
2596
|
+
const emptyState = wallet.getWalletAssetsState();
|
|
2597
|
+
this.updateVoucherOrderPayments([], { status: "payment_pending" });
|
|
2598
|
+
return this.publishWalletAssetsState(emptyState);
|
|
2599
|
+
}
|
|
2600
|
+
const previousState = wallet.getWalletAssetsState();
|
|
2601
|
+
const hasPreviousWalletContext = previousState.status !== "idle" || previousState.items.length > 0 || previousState.selectedIds.length > 0 || previousState.customerId !== void 0;
|
|
2602
|
+
const customerChanged = hasPreviousWalletContext && String(previousState.customerId ?? "") !== String(businessData.customer_id ?? "");
|
|
2603
|
+
if (customerChanged) {
|
|
2604
|
+
const clearedState = wallet.clearWalletAssetSelection();
|
|
2605
|
+
this.updateVoucherOrderPayments([], { status: "payment_pending" });
|
|
2606
|
+
await this.publishWalletAssetsState(clearedState);
|
|
2607
|
+
}
|
|
2608
|
+
const refreshTask = wallet.refreshWalletAssetsFromBusinessAsync(
|
|
2609
|
+
businessData,
|
|
2610
|
+
{
|
|
2611
|
+
preserveSelection: (params == null ? void 0 : params.preserveSelection) !== false && !customerChanged
|
|
2612
|
+
}
|
|
2613
|
+
);
|
|
2614
|
+
await this.publishWalletAssetsState(wallet.getWalletAssetsState());
|
|
2615
|
+
let state = await refreshTask;
|
|
2616
|
+
if (refreshSequence !== this.walletAssetsRefreshSequence) {
|
|
2617
|
+
return wallet.getWalletAssetsState();
|
|
2618
|
+
}
|
|
2619
|
+
if (state.status !== "error") {
|
|
2620
|
+
const committed = this.getCommittedWalletAssets();
|
|
2621
|
+
state = wallet.setCommittedWalletAssets(committed.ids, committed.assets);
|
|
2622
|
+
}
|
|
2623
|
+
await this.syncSelectedWalletAssets(state);
|
|
2624
|
+
return this.publishWalletAssetsState(state);
|
|
2625
|
+
}
|
|
2626
|
+
/** 选择或取消单张钱包资产,并立即同步 pending wallet payments。 */
|
|
2627
|
+
async selectWalletAsset(params) {
|
|
2628
|
+
if (!this.store.payment)
|
|
2629
|
+
throw new Error("payment 模块未初始化");
|
|
2630
|
+
const state = this.store.payment.wallet.selectWalletAsset(params.assetId, {
|
|
2631
|
+
selected: params.selected,
|
|
2632
|
+
source: params.source
|
|
2633
|
+
});
|
|
2634
|
+
await this.syncSelectedWalletAssets(state);
|
|
2635
|
+
return this.publishWalletAssetsState(state);
|
|
2636
|
+
}
|
|
2637
|
+
/** 扫码精确查券;仅可用资产会被自动选中。 */
|
|
2638
|
+
async scanWalletAsset(code) {
|
|
2639
|
+
if (!this.store.payment)
|
|
2640
|
+
throw new Error("payment 模块未初始化");
|
|
2641
|
+
const result = await this.store.payment.wallet.scanWalletAssetAsync(code);
|
|
2642
|
+
if (result.type === "normalCode") {
|
|
2643
|
+
await this.syncSelectedWalletAssets(result.state);
|
|
2644
|
+
await this.publishWalletAssetsState(result.state);
|
|
2645
|
+
}
|
|
2646
|
+
return result;
|
|
2647
|
+
}
|
|
2648
|
+
/** 清空全部未确认钱包选择,已支付钱包项由 Order 模块继续保留。 */
|
|
2649
|
+
async clearWalletAssetSelection() {
|
|
2650
|
+
if (!this.store.payment)
|
|
2651
|
+
throw new Error("payment 模块未初始化");
|
|
2652
|
+
const state = this.store.payment.wallet.clearWalletAssetSelection();
|
|
2653
|
+
await this.syncSelectedWalletAssets(state);
|
|
2654
|
+
return this.publishWalletAssetsState(state);
|
|
2655
|
+
}
|
|
2127
2656
|
/**
|
|
2128
2657
|
* 更新当前订单客户字段。
|
|
2129
2658
|
*
|
|
@@ -2160,29 +2689,349 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
2160
2689
|
getPaymentMethods() {
|
|
2161
2690
|
return [...this.paymentMethodsCache];
|
|
2162
2691
|
}
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2692
|
+
findCashPaymentMethod(paymentMethods) {
|
|
2693
|
+
return paymentMethods.find((method) => {
|
|
2694
|
+
const identifiers = [method == null ? void 0 : method.code, method == null ? void 0 : method.type, method == null ? void 0 : method.tag].map(
|
|
2695
|
+
(value) => String(value || "").toUpperCase()
|
|
2696
|
+
);
|
|
2697
|
+
return identifiers.includes("CASHMANUAL") && (method == null ? void 0 : method.enabled) !== false && (method == null ? void 0 : method.enable) !== false;
|
|
2698
|
+
});
|
|
2699
|
+
}
|
|
2700
|
+
getPendingWalletPaymentAmount(payments = ((_b) => (_b = ((_a) => (_a = this.store.order) == null ? void 0 : _a.getOrderPayments)()) == null ? void 0 : _b.call(_a))() || []) {
|
|
2701
|
+
return payments.reduce((total, payment) => {
|
|
2702
|
+
if ((payment == null ? void 0 : payment.status) !== "payment_pending" || (payment == null ? void 0 : payment.voucher_id) === void 0 || Number(payment.voucher_id) === 0) {
|
|
2703
|
+
return total;
|
|
2704
|
+
}
|
|
2705
|
+
try {
|
|
2706
|
+
return total.plus(payment.amount || 0).plus(payment.rounding_amount || 0);
|
|
2707
|
+
} catch {
|
|
2708
|
+
return total;
|
|
2709
|
+
}
|
|
2710
|
+
}, new import_decimal.default(0));
|
|
2711
|
+
}
|
|
2712
|
+
/** 读取现金 action 所需的支付方式、待付金额和快捷金额。 */
|
|
2713
|
+
async getCashPaymentConfig() {
|
|
2714
|
+
var _a, _b, _c, _d, _e, _f;
|
|
2715
|
+
if (!this.store.payment)
|
|
2716
|
+
throw new Error("payment 模块未初始化");
|
|
2717
|
+
let paymentMethods = this.getPaymentMethods();
|
|
2718
|
+
let paymentMethod = this.findCashPaymentMethod(paymentMethods);
|
|
2719
|
+
if (!paymentMethod) {
|
|
2720
|
+
paymentMethods = await this.getPaymentMethodsAsync();
|
|
2721
|
+
paymentMethod = this.findCashPaymentMethod(paymentMethods);
|
|
2178
2722
|
}
|
|
2179
|
-
const
|
|
2723
|
+
const amountSnapshot = (_b = (_a = this.store.order) == null ? void 0 : _a.getOrderAmountSnapshot) == null ? void 0 : _b.call(_a);
|
|
2724
|
+
const pendingWalletAmount = this.getPendingWalletPaymentAmount();
|
|
2725
|
+
const amountDue = import_decimal.default.max(
|
|
2726
|
+
new import_decimal.default((amountSnapshot == null ? void 0 : amountSnapshot.amountGap) || 0).minus(pendingWalletAmount),
|
|
2727
|
+
0
|
|
2728
|
+
).toDecimalPlaces(2).toNumber();
|
|
2729
|
+
const currency = ((_e = (_d = (_c = this.store.order) == null ? void 0 : _c.getTempOrder) == null ? void 0 : _d.call(_c)) == null ? void 0 : _e.currency_code) || ((_f = this.otherParams) == null ? void 0 : _f.currency) || "USD";
|
|
2730
|
+
const recommendedAmounts = amountDue > 0 ? this.store.payment.cash.getRecommendedAmount(amountDue, currency) : [];
|
|
2180
2731
|
return {
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2732
|
+
available: Boolean(paymentMethod && amountDue > 0),
|
|
2733
|
+
paymentMethod,
|
|
2734
|
+
amountDue,
|
|
2735
|
+
recommendedAmounts
|
|
2184
2736
|
};
|
|
2185
2737
|
}
|
|
2738
|
+
/**
|
|
2739
|
+
* 确认足额覆盖订单的 pending Wallet 支付并提交订单。
|
|
2740
|
+
*
|
|
2741
|
+
* Order 模块在构造提交参数时将 pending voucher 转为 paid;只有提交成功后
|
|
2742
|
+
* 才同步 Wallet committed 状态。失败时恢复调用前 payments,允许用户重试。
|
|
2743
|
+
*/
|
|
2744
|
+
async confirmWalletPayment() {
|
|
2745
|
+
var _a, _b, _c, _d, _e;
|
|
2746
|
+
if (!this.store.order)
|
|
2747
|
+
throw new Error("order 模块未初始化");
|
|
2748
|
+
const beforePayments = (0, import_lodash_es.cloneDeep)(this.store.order.getOrderPayments());
|
|
2749
|
+
const pendingWalletAmount = this.getPendingWalletPaymentAmount(beforePayments);
|
|
2750
|
+
if (pendingWalletAmount.lte(0)) {
|
|
2751
|
+
throw new Error("当前订单没有待确认的 Wallet 支付");
|
|
2752
|
+
}
|
|
2753
|
+
const amountSnapshot = (_b = (_a = this.store.order).getOrderAmountSnapshot) == null ? void 0 : _b.call(_a);
|
|
2754
|
+
const effectiveAmountDue = import_decimal.default.max(
|
|
2755
|
+
new import_decimal.default((amountSnapshot == null ? void 0 : amountSnapshot.amountGap) || 0).minus(pendingWalletAmount),
|
|
2756
|
+
0
|
|
2757
|
+
);
|
|
2758
|
+
if (effectiveAmountDue.gt(0.01)) {
|
|
2759
|
+
throw new Error("Wallet 支付尚未覆盖全部待支付金额");
|
|
2760
|
+
}
|
|
2761
|
+
const beforePaymentStatus = (_c = this.store.order.getTempOrder()) == null ? void 0 : _c.payment_status;
|
|
2762
|
+
let submitResult;
|
|
2763
|
+
try {
|
|
2764
|
+
submitResult = await this.submitSalesOrder({
|
|
2765
|
+
smallTicketDataFlag: 1,
|
|
2766
|
+
confirmPendingVoucherPayments: true
|
|
2767
|
+
});
|
|
2768
|
+
if (isRejectedSalesSubmitResult(submitResult)) {
|
|
2769
|
+
throw new Error(getSalesSubmitErrorMessage(submitResult));
|
|
2770
|
+
}
|
|
2771
|
+
} catch (error) {
|
|
2772
|
+
this.store.order.setOrderPayments(beforePayments);
|
|
2773
|
+
const restoredTempOrder = this.store.order.getTempOrder();
|
|
2774
|
+
if (restoredTempOrder && beforePaymentStatus !== void 0) {
|
|
2775
|
+
restoredTempOrder.payment_status = beforePaymentStatus;
|
|
2776
|
+
this.store.order.persistTempOrder();
|
|
2777
|
+
}
|
|
2778
|
+
await this.store.order.recalculateSummary({ createIfMissing: true });
|
|
2779
|
+
throw error;
|
|
2780
|
+
}
|
|
2781
|
+
if (this.store.payment) {
|
|
2782
|
+
try {
|
|
2783
|
+
const committed = this.getCommittedWalletAssets();
|
|
2784
|
+
const walletState = this.store.payment.wallet.setCommittedWalletAssets(
|
|
2785
|
+
committed.ids,
|
|
2786
|
+
committed.assets
|
|
2787
|
+
);
|
|
2788
|
+
await this.publishWalletAssetsState(walletState);
|
|
2789
|
+
} catch (error) {
|
|
2790
|
+
this.logWarning("confirmWalletPayment: Wallet committed 状态同步失败", {
|
|
2791
|
+
error: error instanceof Error ? error.message : String(error)
|
|
2792
|
+
});
|
|
2793
|
+
}
|
|
2794
|
+
}
|
|
2795
|
+
const latestAmountSnapshot = (_e = (_d = this.store.order).getOrderAmountSnapshot) == null ? void 0 : _e.call(_d);
|
|
2796
|
+
return {
|
|
2797
|
+
submitResult,
|
|
2798
|
+
payments: this.store.order.getOrderPayments(),
|
|
2799
|
+
isOrderFullyPaid: new import_decimal.default(
|
|
2800
|
+
(latestAmountSnapshot == null ? void 0 : latestAmountSnapshot.amountGap) || 0
|
|
2801
|
+
).lte(0)
|
|
2802
|
+
};
|
|
2803
|
+
}
|
|
2804
|
+
/**
|
|
2805
|
+
* 购物车现金直付:写入现金记录并等待支付同步完成。
|
|
2806
|
+
* 同步失败会恢复调用前 payments(包含 Wallet pending 状态)。
|
|
2807
|
+
*/
|
|
2808
|
+
async payCash(params) {
|
|
2809
|
+
var _a, _b, _c, _d, _e, _f;
|
|
2810
|
+
if (!this.store.order)
|
|
2811
|
+
throw new Error("order 模块未初始化");
|
|
2812
|
+
const amount = Number(params.amount || 0);
|
|
2813
|
+
if (!Number.isFinite(amount) || amount <= 0) {
|
|
2814
|
+
throw new Error("现金支付金额必须大于 0");
|
|
2815
|
+
}
|
|
2816
|
+
const config = await this.getCashPaymentConfig();
|
|
2817
|
+
const paymentMethod = config.paymentMethod;
|
|
2818
|
+
if (!paymentMethod)
|
|
2819
|
+
throw new Error("未找到可用的 CASHMANUAL 支付方式");
|
|
2820
|
+
if (config.amountDue <= 0)
|
|
2821
|
+
throw new Error("当前订单没有待支付金额");
|
|
2822
|
+
const roundingAmount = Number(params.roundingAmount || 0);
|
|
2823
|
+
const effectivePaymentAmount = new import_decimal.default(amount).minus(roundingAmount);
|
|
2824
|
+
if (effectivePaymentAmount.gt(new import_decimal.default(config.amountDue).plus(0.01))) {
|
|
2825
|
+
throw new Error("现金支付金额超过当前待支付金额");
|
|
2826
|
+
}
|
|
2827
|
+
const beforePayments = (0, import_lodash_es.cloneDeep)(this.store.order.getOrderPayments());
|
|
2828
|
+
const beforePaymentStatus = (_a = this.store.order.getTempOrder()) == null ? void 0 : _a.payment_status;
|
|
2829
|
+
const uniquePaymentNumber = (0, import_utils.createUuidV4)();
|
|
2830
|
+
const paymentTimestamp = (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss");
|
|
2831
|
+
const actualPaidAmount = Number(params.actualPaidAmount ?? amount);
|
|
2832
|
+
const changeAmount = Number(params.changeAmount || 0);
|
|
2833
|
+
const shopWalletPassId = (_b = this.otherParams) == null ? void 0 : _b.shop_wallet_pass_id;
|
|
2834
|
+
if (!Number.isFinite(actualPaidAmount) || actualPaidAmount + 0.01 < amount) {
|
|
2835
|
+
throw new Error("顾客实收现金不能小于支付金额");
|
|
2836
|
+
}
|
|
2837
|
+
(_f = (_e = (_d = (_c = this.window) == null ? void 0 : _c.interaction) == null ? void 0 : _d.utils) == null ? void 0 : _e.postMessageToApp) == null ? void 0 : _f.call(_e, {
|
|
2838
|
+
module: "till",
|
|
2839
|
+
key: "open_till",
|
|
2840
|
+
data: { type: "cash" }
|
|
2841
|
+
});
|
|
2842
|
+
const payments = this.store.order.addOrderPayment({
|
|
2843
|
+
amount: amount.toFixed(2),
|
|
2844
|
+
code: paymentMethod.code,
|
|
2845
|
+
custom_payment_id: paymentMethod.id,
|
|
2846
|
+
name: paymentMethod.name,
|
|
2847
|
+
custom_payment_type: paymentMethod.type,
|
|
2848
|
+
voucher_id: 0,
|
|
2849
|
+
rounding_amount: roundingAmount.toFixed(2),
|
|
2850
|
+
metadata: {
|
|
2851
|
+
unique_payment_number: uniquePaymentNumber,
|
|
2852
|
+
...shopWalletPassId !== void 0 && shopWalletPassId !== null ? { shop_wallet_pass_id: shopWalletPassId } : {},
|
|
2853
|
+
actual_paid_amount: Number.isFinite(actualPaidAmount) ? actualPaidAmount : amount,
|
|
2854
|
+
change_given_amount: Number.isFinite(changeAmount) ? changeAmount : 0
|
|
2855
|
+
},
|
|
2856
|
+
payment_time: paymentTimestamp,
|
|
2857
|
+
created_at: paymentTimestamp
|
|
2858
|
+
});
|
|
2859
|
+
const payment = payments.find(
|
|
2860
|
+
(item) => {
|
|
2861
|
+
var _a2;
|
|
2862
|
+
return ((_a2 = item == null ? void 0 : item.metadata) == null ? void 0 : _a2.unique_payment_number) === uniquePaymentNumber;
|
|
2863
|
+
}
|
|
2864
|
+
);
|
|
2865
|
+
try {
|
|
2866
|
+
const syncResult = await this.syncPaymentsToOrder({
|
|
2867
|
+
payments,
|
|
2868
|
+
submitWhenPaid: true,
|
|
2869
|
+
smallTicketDataFlag: 1,
|
|
2870
|
+
confirmPendingVoucherPayments: true
|
|
2871
|
+
});
|
|
2872
|
+
if (this.store.payment) {
|
|
2873
|
+
const committed = this.getCommittedWalletAssets();
|
|
2874
|
+
const walletState = this.store.payment.wallet.setCommittedWalletAssets(
|
|
2875
|
+
committed.ids,
|
|
2876
|
+
committed.assets
|
|
2877
|
+
);
|
|
2878
|
+
await this.publishWalletAssetsState(walletState);
|
|
2879
|
+
}
|
|
2880
|
+
return {
|
|
2881
|
+
payment: payment || {},
|
|
2882
|
+
payments: this.store.order.getOrderPayments(),
|
|
2883
|
+
syncResult,
|
|
2884
|
+
isOrderFullyPaid: syncResult.isOrderFullyPaid
|
|
2885
|
+
};
|
|
2886
|
+
} catch (error) {
|
|
2887
|
+
this.store.order.setOrderPayments(beforePayments);
|
|
2888
|
+
const restoredTempOrder = this.store.order.getTempOrder();
|
|
2889
|
+
if (restoredTempOrder && beforePaymentStatus !== void 0) {
|
|
2890
|
+
restoredTempOrder.payment_status = beforePaymentStatus;
|
|
2891
|
+
this.store.order.persistTempOrder();
|
|
2892
|
+
}
|
|
2893
|
+
await this.store.order.recalculateSummary({ createIfMissing: true });
|
|
2894
|
+
throw error;
|
|
2895
|
+
}
|
|
2896
|
+
}
|
|
2897
|
+
/**
|
|
2898
|
+
* 提交一次已由支付设备确认成功的非 Wallet 支付。
|
|
2899
|
+
*
|
|
2900
|
+
* 与 addOrderPayment 不同,本入口不会启动后台 fire-and-forget 同步;调用方会等待
|
|
2901
|
+
* 本次 payment、当前 pending Wallet 以及订单提交共同完成。任何同步失败都会恢复
|
|
2902
|
+
* 调用前的 payments 与 payment_status,便于 UI 安全解锁并重试。
|
|
2903
|
+
*/
|
|
2904
|
+
async commitPaymentMethodPayment(params) {
|
|
2905
|
+
var _a, _b, _c, _d;
|
|
2906
|
+
if (!this.store.order)
|
|
2907
|
+
throw new Error("order 模块未初始化");
|
|
2908
|
+
const amount = Number(params.amount || 0);
|
|
2909
|
+
if (!Number.isFinite(amount) || amount <= 0) {
|
|
2910
|
+
throw new Error("支付金额必须大于 0");
|
|
2911
|
+
}
|
|
2912
|
+
let paymentMethods = this.getPaymentMethods();
|
|
2913
|
+
const findPaymentMethod = () => {
|
|
2914
|
+
const methodCode = String(params.paymentMethodCode || "").toUpperCase();
|
|
2915
|
+
return paymentMethods.find((method) => {
|
|
2916
|
+
const idMatched = params.paymentMethodId !== void 0 && String(method.id) === String(params.paymentMethodId);
|
|
2917
|
+
const codeMatched = Boolean(methodCode) && String(method.code || "").toUpperCase() === methodCode;
|
|
2918
|
+
return (idMatched || codeMatched) && method.enabled !== false && method.enable !== false;
|
|
2919
|
+
});
|
|
2920
|
+
};
|
|
2921
|
+
let paymentMethod = findPaymentMethod();
|
|
2922
|
+
if (!paymentMethod) {
|
|
2923
|
+
paymentMethods = await this.getPaymentMethodsAsync();
|
|
2924
|
+
paymentMethod = findPaymentMethod();
|
|
2925
|
+
}
|
|
2926
|
+
if (!paymentMethod) {
|
|
2927
|
+
throw new Error(
|
|
2928
|
+
`未找到可用的支付方式:${params.paymentMethodCode || params.paymentMethodId || ""}`
|
|
2929
|
+
);
|
|
2930
|
+
}
|
|
2931
|
+
const amountSnapshot = (_b = (_a = this.store.order).getOrderAmountSnapshot) == null ? void 0 : _b.call(_a);
|
|
2932
|
+
const pendingWalletAmount = this.getPendingWalletPaymentAmount();
|
|
2933
|
+
const amountDue = import_decimal.default.max(
|
|
2934
|
+
new import_decimal.default((amountSnapshot == null ? void 0 : amountSnapshot.amountGap) || 0).minus(pendingWalletAmount),
|
|
2935
|
+
0
|
|
2936
|
+
);
|
|
2937
|
+
if (amountDue.lte(0))
|
|
2938
|
+
throw new Error("当前订单没有待支付金额");
|
|
2939
|
+
if (new import_decimal.default(amount).gt(amountDue.plus(0.01))) {
|
|
2940
|
+
throw new Error("支付金额超过当前待支付金额");
|
|
2941
|
+
}
|
|
2942
|
+
const beforePayments = (0, import_lodash_es.cloneDeep)(this.store.order.getOrderPayments());
|
|
2943
|
+
const beforePaymentStatus = (_c = this.store.order.getTempOrder()) == null ? void 0 : _c.payment_status;
|
|
2944
|
+
const paymentTimestamp = (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss");
|
|
2945
|
+
const metadata = {
|
|
2946
|
+
...params.metadata || {},
|
|
2947
|
+
unique_payment_number: ((_d = params.metadata) == null ? void 0 : _d.unique_payment_number) || (0, import_utils.createUuidV4)()
|
|
2948
|
+
};
|
|
2949
|
+
const serviceCharge = params.serviceCharge ? {
|
|
2950
|
+
amount: String(params.serviceCharge.amount || 0),
|
|
2951
|
+
percentage: String(params.serviceCharge.percentage || 0)
|
|
2952
|
+
} : void 0;
|
|
2953
|
+
const serviceFee = serviceCharge ? new import_decimal.default(params.originAmount ?? amount).times(serviceCharge.percentage || 0).plus(serviceCharge.amount || 0).toDecimalPlaces(2).toFixed(2) : void 0;
|
|
2954
|
+
const payments = this.store.order.addOrderPayment({
|
|
2955
|
+
...params.paymentData || {},
|
|
2956
|
+
amount: amount.toFixed(2),
|
|
2957
|
+
...params.originAmount !== void 0 ? { origin_amount: Number(params.originAmount).toFixed(2) } : {},
|
|
2958
|
+
code: paymentMethod.code,
|
|
2959
|
+
custom_payment_id: paymentMethod.id,
|
|
2960
|
+
name: paymentMethod.name,
|
|
2961
|
+
custom_payment_type: paymentMethod.type,
|
|
2962
|
+
voucher_id: 0,
|
|
2963
|
+
...serviceCharge ? { service_charge: serviceCharge } : {},
|
|
2964
|
+
...serviceFee !== void 0 ? { service_fee: serviceFee } : {},
|
|
2965
|
+
metadata,
|
|
2966
|
+
payment_time: paymentTimestamp,
|
|
2967
|
+
created_at: paymentTimestamp
|
|
2968
|
+
});
|
|
2969
|
+
const payment = payments.find(
|
|
2970
|
+
(item) => {
|
|
2971
|
+
var _a2;
|
|
2972
|
+
return ((_a2 = item == null ? void 0 : item.metadata) == null ? void 0 : _a2.unique_payment_number) === metadata.unique_payment_number;
|
|
2973
|
+
}
|
|
2974
|
+
);
|
|
2975
|
+
try {
|
|
2976
|
+
const syncResult = await this.syncPaymentsToOrder({
|
|
2977
|
+
payments,
|
|
2978
|
+
submitWhenPaid: true,
|
|
2979
|
+
smallTicketDataFlag: 1,
|
|
2980
|
+
confirmPendingVoucherPayments: true
|
|
2981
|
+
});
|
|
2982
|
+
if (this.store.payment) {
|
|
2983
|
+
const committed = this.getCommittedWalletAssets();
|
|
2984
|
+
const walletState = this.store.payment.wallet.setCommittedWalletAssets(
|
|
2985
|
+
committed.ids,
|
|
2986
|
+
committed.assets
|
|
2987
|
+
);
|
|
2988
|
+
await this.publishWalletAssetsState(walletState);
|
|
2989
|
+
}
|
|
2990
|
+
return {
|
|
2991
|
+
payment: payment || {},
|
|
2992
|
+
payments: this.store.order.getOrderPayments(),
|
|
2993
|
+
syncResult,
|
|
2994
|
+
isOrderFullyPaid: syncResult.isOrderFullyPaid
|
|
2995
|
+
};
|
|
2996
|
+
} catch (error) {
|
|
2997
|
+
this.store.order.setOrderPayments(beforePayments);
|
|
2998
|
+
const restoredTempOrder = this.store.order.getTempOrder();
|
|
2999
|
+
if (restoredTempOrder && beforePaymentStatus !== void 0) {
|
|
3000
|
+
restoredTempOrder.payment_status = beforePaymentStatus;
|
|
3001
|
+
this.store.order.persistTempOrder();
|
|
3002
|
+
}
|
|
3003
|
+
await this.store.order.recalculateSummary({ createIfMissing: true });
|
|
3004
|
+
throw error;
|
|
3005
|
+
}
|
|
3006
|
+
}
|
|
3007
|
+
/**
|
|
3008
|
+
* 按当前店铺的现金舍入配置计算金额,供现金支付 UI 使用。
|
|
3009
|
+
*
|
|
3010
|
+
* 舍入开关取自 CASHMANUAL 支付方式;舍入规则取自
|
|
3011
|
+
* otherParams.order_rounding_setting,金额算法统一由 PaymentModule 维护。
|
|
3012
|
+
*/
|
|
3013
|
+
async roundAmount(params) {
|
|
3014
|
+
var _a, _b, _c;
|
|
3015
|
+
const amount = params.amount;
|
|
3016
|
+
const cashManualPayment = this.paymentMethodsCache.find(
|
|
3017
|
+
(paymentMethod) => paymentMethod.code === "CASHMANUAL"
|
|
3018
|
+
);
|
|
3019
|
+
if (!((_a = cashManualPayment == null ? void 0 : cashManualPayment.metadata) == null ? void 0 : _a.order_rounding_switch)) {
|
|
3020
|
+
return {
|
|
3021
|
+
originalAmount: amount.toString(),
|
|
3022
|
+
roundedAmount: amount.toString(),
|
|
3023
|
+
roundingDifference: "0.00"
|
|
3024
|
+
};
|
|
3025
|
+
}
|
|
3026
|
+
if (!this.payment) {
|
|
3027
|
+
throw new Error("payment 模块未初始化");
|
|
3028
|
+
}
|
|
3029
|
+
return this.payment.roundAmountAsync(
|
|
3030
|
+
amount,
|
|
3031
|
+
(_b = this.otherParams.order_rounding_setting) == null ? void 0 : _b.interval,
|
|
3032
|
+
(_c = this.otherParams.order_rounding_setting) == null ? void 0 : _c.type
|
|
3033
|
+
);
|
|
3034
|
+
}
|
|
2186
3035
|
/**
|
|
2187
3036
|
* 发送支付链接。
|
|
2188
3037
|
*
|