@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.
Files changed (139) hide show
  1. package/dist/core/index.d.ts +2 -0
  2. package/dist/core/index.js +7 -0
  3. package/dist/model/strategy/adapter/promotion/adapter.d.ts +4 -0
  4. package/dist/model/strategy/adapter/promotion/adapter.js +23 -0
  5. package/dist/model/strategy/adapter/promotion/evaluator.d.ts +17 -0
  6. package/dist/model/strategy/adapter/promotion/evaluator.js +279 -6
  7. package/dist/model/strategy/adapter/promotion/examples.d.ts +86 -0
  8. package/dist/model/strategy/adapter/promotion/examples.js +99 -0
  9. package/dist/model/strategy/adapter/promotion/index.d.ts +1 -1
  10. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  11. package/dist/model/strategy/adapter/promotion/type.d.ts +90 -2
  12. package/dist/model/strategy/adapter/promotion/type.js +45 -0
  13. package/dist/modules/BaseModule.d.ts +1 -0
  14. package/dist/modules/BaseModule.js +24 -28
  15. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +5 -3
  16. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +6 -3
  17. package/dist/modules/OpenData/index.d.ts +2 -0
  18. package/dist/modules/OpenData/index.js +8 -0
  19. package/dist/modules/Order/index.d.ts +41 -10
  20. package/dist/modules/Order/index.js +943 -546
  21. package/dist/modules/Order/payment-utils.d.ts +26 -0
  22. package/dist/modules/Order/payment-utils.js +225 -0
  23. package/dist/modules/Order/types.d.ts +43 -2
  24. package/dist/modules/Order/utils/orderCollectionIdentity.js +7 -2
  25. package/dist/modules/Order/utils.js +10 -6
  26. package/dist/modules/Payment/index.d.ts +2 -0
  27. package/dist/modules/Payment/index.js +79 -50
  28. package/dist/modules/Payment/types.d.ts +107 -28
  29. package/dist/modules/Payment/types.js +20 -3
  30. package/dist/modules/Payment/walletpass.d.ts +38 -1
  31. package/dist/modules/Payment/walletpass.js +917 -114
  32. package/dist/modules/ProductList/index.js +1 -1
  33. package/dist/modules/Rules/index.d.ts +3 -0
  34. package/dist/modules/Rules/index.js +130 -99
  35. package/dist/server/index.d.ts +16 -0
  36. package/dist/server/index.js +2084 -1188
  37. package/dist/server/modules/index.d.ts +1 -1
  38. package/dist/server/modules/order/index.d.ts +70 -4
  39. package/dist/server/modules/order/index.js +1816 -728
  40. package/dist/server/modules/order/types.d.ts +25 -3
  41. package/dist/server/modules/order/types.js +7 -1
  42. package/dist/solution/BaseSales/index.d.ts +114 -14
  43. package/dist/solution/BaseSales/index.js +1848 -478
  44. package/dist/solution/BaseSales/types.d.ts +55 -1
  45. package/dist/solution/BaseSales/types.js +2 -1
  46. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +3 -1
  47. package/dist/solution/BaseSales/utils/cartPromotion.js +90 -31
  48. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +6 -1
  49. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +6 -3
  50. package/dist/solution/BookingByStep/index.d.ts +1 -1
  51. package/dist/solution/BookingTicket/index.d.ts +8 -16
  52. package/dist/solution/BookingTicket/index.js +138 -52
  53. package/dist/solution/BookingTicket/types.d.ts +1 -0
  54. package/dist/solution/BookingTicket/utils/addProductDecision.js +6 -0
  55. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +8 -0
  56. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +173 -83
  57. package/dist/solution/BookingTicket/utils/weighingProductSku.d.ts +5 -0
  58. package/dist/solution/BookingTicket/utils/weighingProductSku.js +45 -0
  59. package/dist/solution/Sales/index.d.ts +1 -0
  60. package/dist/solution/Sales/index.js +10 -2
  61. package/dist/solution/ScanOrder/index.js +31 -20
  62. package/dist/solution/UnifiedBookingSales/index.d.ts +3 -0
  63. package/dist/solution/UnifiedBookingSales/index.js +392 -304
  64. package/dist/solution/UnifiedBookingSales/types.d.ts +7 -0
  65. package/dist/solution/VenueBooking/index.d.ts +1 -0
  66. package/dist/solution/VenueBooking/index.js +34 -24
  67. package/dist/types/index.d.ts +1 -0
  68. package/dist/utils/payment-number.d.ts +9 -0
  69. package/dist/utils/payment-number.js +69 -0
  70. package/lib/core/index.d.ts +2 -0
  71. package/lib/core/index.js +4 -0
  72. package/lib/model/strategy/adapter/promotion/adapter.d.ts +4 -0
  73. package/lib/model/strategy/adapter/promotion/adapter.js +20 -0
  74. package/lib/model/strategy/adapter/promotion/evaluator.d.ts +17 -0
  75. package/lib/model/strategy/adapter/promotion/evaluator.js +235 -0
  76. package/lib/model/strategy/adapter/promotion/examples.d.ts +86 -0
  77. package/lib/model/strategy/adapter/promotion/examples.js +91 -0
  78. package/lib/model/strategy/adapter/promotion/index.d.ts +1 -1
  79. package/lib/model/strategy/adapter/promotion/index.js +2 -0
  80. package/lib/model/strategy/adapter/promotion/type.d.ts +90 -2
  81. package/lib/model/strategy/adapter/promotion/type.js +2 -0
  82. package/lib/modules/BaseModule.d.ts +1 -0
  83. package/lib/modules/BaseModule.js +24 -37
  84. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +2 -1
  85. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +2 -1
  86. package/lib/modules/OpenData/index.d.ts +2 -0
  87. package/lib/modules/OpenData/index.js +5 -0
  88. package/lib/modules/Order/index.d.ts +41 -10
  89. package/lib/modules/Order/index.js +322 -86
  90. package/lib/modules/Order/payment-utils.d.ts +26 -0
  91. package/lib/modules/Order/payment-utils.js +224 -0
  92. package/lib/modules/Order/types.d.ts +43 -2
  93. package/lib/modules/Order/utils/orderCollectionIdentity.js +3 -0
  94. package/lib/modules/Order/utils.js +11 -4
  95. package/lib/modules/Payment/index.d.ts +2 -0
  96. package/lib/modules/Payment/index.js +34 -13
  97. package/lib/modules/Payment/types.d.ts +107 -28
  98. package/lib/modules/Payment/types.js +4 -3
  99. package/lib/modules/Payment/walletpass.d.ts +38 -1
  100. package/lib/modules/Payment/walletpass.js +730 -21
  101. package/lib/modules/ProductList/index.js +9 -1
  102. package/lib/modules/Rules/index.d.ts +3 -0
  103. package/lib/modules/Rules/index.js +39 -10
  104. package/lib/server/index.d.ts +16 -0
  105. package/lib/server/index.js +677 -28
  106. package/lib/server/modules/index.d.ts +1 -1
  107. package/lib/server/modules/order/index.d.ts +70 -4
  108. package/lib/server/modules/order/index.js +818 -69
  109. package/lib/server/modules/order/types.d.ts +25 -3
  110. package/lib/server/modules/order/types.js +1 -0
  111. package/lib/solution/BaseSales/index.d.ts +114 -14
  112. package/lib/solution/BaseSales/index.js +907 -58
  113. package/lib/solution/BaseSales/types.d.ts +55 -1
  114. package/lib/solution/BaseSales/types.js +2 -1
  115. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +3 -1
  116. package/lib/solution/BaseSales/utils/cartPromotion.js +63 -12
  117. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +6 -1
  118. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +3 -2
  119. package/lib/solution/BookingByStep/index.d.ts +1 -1
  120. package/lib/solution/BookingTicket/index.d.ts +8 -16
  121. package/lib/solution/BookingTicket/index.js +63 -9
  122. package/lib/solution/BookingTicket/types.d.ts +1 -0
  123. package/lib/solution/BookingTicket/utils/addProductDecision.js +4 -0
  124. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +8 -0
  125. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +37 -5
  126. package/lib/solution/BookingTicket/utils/weighingProductSku.d.ts +5 -0
  127. package/lib/solution/BookingTicket/utils/weighingProductSku.js +63 -0
  128. package/lib/solution/Sales/index.d.ts +1 -0
  129. package/lib/solution/Sales/index.js +5 -3
  130. package/lib/solution/ScanOrder/index.js +8 -0
  131. package/lib/solution/UnifiedBookingSales/index.d.ts +3 -0
  132. package/lib/solution/UnifiedBookingSales/index.js +48 -2
  133. package/lib/solution/UnifiedBookingSales/types.d.ts +7 -0
  134. package/lib/solution/VenueBooking/index.d.ts +1 -0
  135. package/lib/solution/VenueBooking/index.js +13 -6
  136. package/lib/types/index.d.ts +1 -0
  137. package/lib/utils/payment-number.d.ts +9 -0
  138. package/lib/utils/payment-number.js +64 -0
  139. package/package.json +1 -1
@@ -37,6 +37,8 @@ import Decimal from 'decimal.js';
37
37
  import { cloneDeep, mergeWith } from 'lodash-es';
38
38
  import { createModule } from "../BookingByStep/types";
39
39
  import { composeLinePrice, createUuidV4, ensureProductSku, getProductSkuOptions, resolveIsFormSubject, sumOptionUnitPrice } from "../../modules/Order/utils";
40
+ import { ensureOrderPaymentNumber, isIdentifiedPendingOrderPayment, isPendingOrderPayment, mergeOrderPaymentListsByIdentity, resolveOrderPaymentIdentity } from "../../modules/Order/payment-utils";
41
+ import { resolvePaymentNumberDevicePrefix, resolvePaymentNumberDevicePrefixFromDeviceId } from "../../utils/payment-number";
40
42
  import { applyOrderCollectionUidRemaps, getOrderCollectionPersistentId, getOrderCollectionReferenceUid, getOrderCollectionUid, isSameOrderCollectionItem, mergeOrderCollectionItems, normalizeOrderCollection, normalizeOrderCollections, setOrderCollectionUid } from "../../modules/Order/utils/orderCollectionIdentity";
41
43
  import dayjs from 'dayjs';
42
44
  export * from "./types";
@@ -44,6 +46,89 @@ import { QuotationModule } from "../../modules/Quotation";
44
46
  import { transformBaseProductToOrderProduct as _transformBaseProductToOrderProduct } from "./utils/transformBaseProductToOrderProduct";
45
47
  import { calculateBaseSalesProductBookingPrice } from "./utils/quotationPrice";
46
48
  var SERVER_ORDER_CHANGED_EVENT = 'order:onOrdersChanged';
49
+ var WALLET_PAYMENT_CODE_BY_TAG = {
50
+ product_voucher: 'PRODUCTVOUCHER',
51
+ gift_card: 'GIFTCARD',
52
+ point_card: 'POINTCARD'
53
+ };
54
+ function getSharedWalletAssetId(asset) {
55
+ var _ref, _asset$id;
56
+ return (_ref = (_asset$id = asset === null || asset === void 0 ? void 0 : asset.id) !== null && _asset$id !== void 0 ? _asset$id : asset === null || asset === void 0 ? void 0 : asset.voucher_id) !== null && _ref !== void 0 ? _ref : asset === null || asset === void 0 ? void 0 : asset.code;
57
+ }
58
+ function getSharedWalletAssetAmount(asset) {
59
+ var _ref2, _ref3, _ref4, _ref5, _asset$edit_current_a;
60
+ var value = (_ref2 = (_ref3 = (_ref4 = (_ref5 = (_asset$edit_current_a = asset === null || asset === void 0 ? void 0 : asset.edit_current_amount) !== null && _asset$edit_current_a !== void 0 ? _asset$edit_current_a : asset === null || asset === void 0 ? void 0 : asset._available_max_amount) !== null && _ref5 !== void 0 ? _ref5 : (asset === null || asset === void 0 ? void 0 : asset.tag) === 'point_card' ? asset === null || asset === void 0 ? void 0 : asset.recommended_usage_amount : asset === null || asset === void 0 ? void 0 : asset.available_max_amount) !== null && _ref4 !== void 0 ? _ref4 : asset === null || asset === void 0 ? void 0 : asset.actualDeduction) !== null && _ref3 !== void 0 ? _ref3 : asset === null || asset === void 0 ? void 0 : asset.amount) !== null && _ref2 !== void 0 ? _ref2 : 0;
61
+ var amount = Number(value);
62
+ return Number.isFinite(amount) && amount > 0 ? amount : 0;
63
+ }
64
+ function isRejectedSalesSubmitResult(result) {
65
+ var _result$response, _result$response2;
66
+ var candidates = [result, result === null || result === void 0 ? void 0 : result.data, result === null || result === void 0 || (_result$response = result.response) === null || _result$response === void 0 ? void 0 : _result$response.data, result === null || result === void 0 || (_result$response2 = result.response) === null || _result$response2 === void 0 ? void 0 : _result$response2.body];
67
+ return candidates.some(function (candidate) {
68
+ var _candidate$code;
69
+ if (!candidate || _typeof(candidate) !== 'object') return false;
70
+ var responseCode = Number((_candidate$code = candidate.code) !== null && _candidate$code !== void 0 ? _candidate$code : candidate.statusCode);
71
+ if (Number.isFinite(responseCode) && responseCode >= 400) return true;
72
+ if (candidate.status === false || candidate.success === false || candidate.result === false) {
73
+ return true;
74
+ }
75
+ return ['failed', 'error'].includes(String(candidate.status || '').toLowerCase());
76
+ });
77
+ }
78
+ function getSalesSubmitErrorMessage(result) {
79
+ var _result$data, _result$data2;
80
+ return (result === null || result === void 0 ? void 0 : result.message) || (result === null || result === void 0 ? void 0 : result.msg) || (result === null || result === void 0 || (_result$data = result.data) === null || _result$data === void 0 ? void 0 : _result$data.message) || (result === null || result === void 0 || (_result$data2 = result.data) === null || _result$data2 === void 0 ? void 0 : _result$data2.msg) || 'Wallet 支付确认失败';
81
+ }
82
+ function toWalletFundValue(value) {
83
+ try {
84
+ return new Decimal(value || 0).toDecimalPlaces(2).toFixed(2);
85
+ } catch (_unused) {
86
+ return '0.00';
87
+ }
88
+ }
89
+ function subtractWalletFundValue(left, right) {
90
+ try {
91
+ return new Decimal(left || 0).minus(right || 0).toDecimalPlaces(2).toFixed(2);
92
+ } catch (_unused2) {
93
+ return '0.00';
94
+ }
95
+ }
96
+ function getSharedWalletPassUseValue(params) {
97
+ var asset = params.asset,
98
+ amount = params.amount,
99
+ paymentMethod = params.paymentMethod;
100
+ var configuredValue = Number(asset === null || asset === void 0 ? void 0 : asset.wallet_pass_use_value);
101
+ if (Number.isFinite(configuredValue) && configuredValue > 0) {
102
+ return configuredValue;
103
+ }
104
+ var isPointCard = (asset === null || asset === void 0 ? void 0 : asset.tag) === 'point_card' || paymentMethod.code === 'POINTCARD';
105
+ var usageUnit = asset === null || asset === void 0 ? void 0 : asset.wallet_pass_usage_unit;
106
+ if (isPointCard && usageUnit !== null && usageUnit !== void 0 && usageUnit.points && usageUnit !== null && usageUnit !== void 0 && usageUnit.price) {
107
+ return new Decimal(amount).div(usageUnit.price).mul(usageUnit.points).toDecimalPlaces(2, Decimal.ROUND_DOWN).toNumber();
108
+ }
109
+ return amount;
110
+ }
111
+ function buildSharedWalletFundRecord(params) {
112
+ var _ref6, _ref7, _asset$balance_par_va, _asset$voucher_id;
113
+ var asset = params.asset,
114
+ amount = params.amount,
115
+ paymentMethod = params.paymentMethod;
116
+ var isPointCard = (asset === null || asset === void 0 ? void 0 : asset.tag) === 'point_card' || paymentMethod.code === 'POINTCARD';
117
+ var usingBeforeValue = (_ref6 = (_ref7 = (_asset$balance_par_va = asset === null || asset === void 0 ? void 0 : asset.balance_par_value) !== null && _asset$balance_par_va !== void 0 ? _asset$balance_par_va : asset === null || asset === void 0 ? void 0 : asset.balance) !== null && _ref7 !== void 0 ? _ref7 : asset === null || asset === void 0 ? void 0 : asset.using_before_value) !== null && _ref6 !== void 0 ? _ref6 : 0;
118
+ var walletPassUseValue = getSharedWalletPassUseValue(params);
119
+ var usingValue = isPointCard ? walletPassUseValue : amount;
120
+ var walletPassName = (asset === null || asset === void 0 ? void 0 : asset.wallet_pass_name) || (asset === null || asset === void 0 ? void 0 : asset.format_title) || (asset === null || asset === void 0 ? void 0 : asset.product_name) || (asset === null || asset === void 0 ? void 0 : asset.name) || paymentMethod.name;
121
+ return {
122
+ voucher_id: (_asset$voucher_id = asset === null || asset === void 0 ? void 0 : asset.voucher_id) !== null && _asset$voucher_id !== void 0 ? _asset$voucher_id : asset === null || asset === void 0 ? void 0 : asset.id,
123
+ wallet_pass_name: walletPassName && _typeof(walletPassName) === 'object' ? walletPassName : {
124
+ default: walletPassName || ''
125
+ },
126
+ code: (asset === null || asset === void 0 ? void 0 : asset.code) || (asset === null || asset === void 0 ? void 0 : asset.tag),
127
+ encoded: asset === null || asset === void 0 ? void 0 : asset.encoded,
128
+ using_before_value: toWalletFundValue(usingBeforeValue),
129
+ using_after_value: subtractWalletFundValue(usingBeforeValue, usingValue)
130
+ };
131
+ }
47
132
  function isBaseSalesManualProductDiscountProduct(product) {
48
133
  var _product$metadata, _product$metadata2;
49
134
  return (product === null || product === void 0 || (_product$metadata = product.metadata) === null || _product$metadata === void 0 ? void 0 : _product$metadata.is_manual_discount) === true || (product === null || product === void 0 || (_product$metadata2 = product.metadata) === null || _product$metadata2 === void 0 ? void 0 : _product$metadata2.is_manual_discount) === 1 || ((product === null || product === void 0 ? void 0 : product.discount_list) || []).some(function (item) {
@@ -72,6 +157,10 @@ function preserveManualProductDiscountProducts(previousProducts, nextProducts) {
72
157
  function isBaseSalesHistoricalDiscountEntry(discount) {
73
158
  return Boolean((discount === null || discount === void 0 ? void 0 : discount.isEditMode) || (discount === null || discount === void 0 ? void 0 : discount.isDisabled) || (discount === null || discount === void 0 ? void 0 : discount.order_discount_id) != null);
74
159
  }
160
+ function getBaseSalesUniqueArrayMetadataKey(key) {
161
+ if (key === 'products' || key === 'bookings') return 'unique_identification_number';
162
+ return null;
163
+ }
75
164
  var BASE_SALES_PERSISTENT_ID_FIELD_BY_KIND = {
76
165
  product: 'order_detail_id',
77
166
  booking: 'schedule_event_id',
@@ -143,6 +232,15 @@ function mergeBaseSalesCollectionItem(kind, currentItem, incomingItem, uidRemaps
143
232
  return kind === 'product' ? mergeBaseSalesProductSnapshotFields(currentItem, mergedItem) : mergedItem;
144
233
  }
145
234
  function mergeBaseSalesOrderCollection(kind, currentValue, incomingValue, strategy, uidRemaps) {
235
+ if (kind === 'payment') {
236
+ return mergeOrderPaymentListsByIdentity(currentValue, incomingValue, strategy === 'preserve-local' ? {
237
+ preserveUnmatchedExisting: true
238
+ } : {
239
+ preserveUnmatchedExistingWhen: function preserveUnmatchedExistingWhen(payment) {
240
+ return isIdentifiedPendingOrderPayment(payment) || !getOrderCollectionPersistentId('payment', payment);
241
+ }
242
+ });
243
+ }
146
244
  var currentItems = normalizeOrderCollection(kind, currentValue, {
147
245
  ensureUid: false
148
246
  }).items;
@@ -189,6 +287,34 @@ function normalizeBaseSalesRecordCollections(sourceRecord, options) {
189
287
  }
190
288
  return normalizedRecord;
191
289
  }
290
+ function getBaseSalesMetadataUid(item, metadataKey) {
291
+ var _item$metadata$metada, _item$metadata;
292
+ var uid = (_item$metadata$metada = item === null || item === void 0 || (_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata[metadataKey]) !== null && _item$metadata$metada !== void 0 ? _item$metadata$metada : item === null || item === void 0 ? void 0 : item[metadataKey];
293
+ if (uid === undefined || uid === null || uid === '') return null;
294
+ return String(uid);
295
+ }
296
+ function mergeBaseSalesUniqueArray(currentValue, loadedValue, metadataKey) {
297
+ var result = [];
298
+ var indexByUid = new Map();
299
+ var appendOrReplaceByUid = function appendOrReplaceByUid(item) {
300
+ var clonedItem = cloneDeep(item);
301
+ var uid = getBaseSalesMetadataUid(clonedItem, metadataKey);
302
+ if (!uid) {
303
+ result.push(clonedItem);
304
+ return;
305
+ }
306
+ var existingIndex = indexByUid.get(uid);
307
+ if (existingIndex !== undefined) {
308
+ result[existingIndex] = clonedItem;
309
+ return;
310
+ }
311
+ indexByUid.set(uid, result.length);
312
+ result.push(clonedItem);
313
+ };
314
+ currentValue.forEach(appendOrReplaceByUid);
315
+ loadedValue.forEach(appendOrReplaceByUid);
316
+ return result;
317
+ }
192
318
  function mergeSalesDetailRecordWithTempOrder(currentTempOrder, loadedRecord, strategy) {
193
319
  var normalizedLoadedRecord = normalizeBaseSalesRecordCollections(loadedRecord || {}, {
194
320
  ensureUid: false
@@ -206,6 +332,15 @@ function mergeSalesDetailRecordWithTempOrder(currentTempOrder, loadedRecord, str
206
332
  return mergeBaseSalesOrderCollection(collectionKind, Array.isArray(currentValue) ? currentValue : [], loadedValue, strategy, uidRemaps);
207
333
  }
208
334
  if (Array.isArray(currentValue) && Array.isArray(loadedValue)) {
335
+ if (key === 'payments' || key === 'payment') {
336
+ return mergeOrderPaymentListsByIdentity(currentValue, loadedValue, {
337
+ preserveUnmatchedExisting: true
338
+ });
339
+ }
340
+ var metadataKey = getBaseSalesUniqueArrayMetadataKey(key);
341
+ if (metadataKey) {
342
+ return mergeBaseSalesUniqueArray(currentValue, loadedValue, metadataKey);
343
+ }
209
344
  return [].concat(_toConsumableArray(cloneDeep(currentValue)), _toConsumableArray(cloneDeep(loadedValue)));
210
345
  }
211
346
  if (Array.isArray(loadedValue)) return cloneDeep(loadedValue);
@@ -217,6 +352,22 @@ function mergeSalesDetailRecordWithTempOrder(currentTempOrder, loadedRecord, str
217
352
  delete mergedRecord.request_unique_idempotency_token;
218
353
  return normalizeBaseSalesRecordCollections(applyOrderCollectionUidRemaps(mergedRecord, uidRemaps));
219
354
  }
355
+ function filterPendingPaymentsFromLoadedSalesDetail(sourceRecord) {
356
+ if (!sourceRecord || _typeof(sourceRecord) !== 'object') return sourceRecord;
357
+ var record = _objectSpread({}, sourceRecord);
358
+ if (Array.isArray(sourceRecord.payments)) {
359
+ record.payments = sourceRecord.payments.filter(function (payment) {
360
+ return !isPendingOrderPayment(payment);
361
+ });
362
+ }
363
+ // 兼容少量历史详情数据使用的单数 payment 字段。
364
+ if (Array.isArray(sourceRecord.payment)) {
365
+ record.payment = sourceRecord.payment.filter(function (payment) {
366
+ return !isPendingOrderPayment(payment);
367
+ });
368
+ }
369
+ return record;
370
+ }
220
371
  export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
221
372
  _inherits(BaseSalesImpl, _BaseModule);
222
373
  var _super = _createSuper(BaseSalesImpl);
@@ -236,6 +387,11 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
236
387
  });
237
388
  _defineProperty(_assertThisInitialized(_this), "otherParams", {});
238
389
  _defineProperty(_assertThisInitialized(_this), "cacheId", void 0);
390
+ /**
391
+ * 由已在初始化阶段解析过设备短号的业务解决方案写入。
392
+ * 未设置时,支付编号仍按原逻辑实时读取设备信息。
393
+ */
394
+ _defineProperty(_assertThisInitialized(_this), "paymentNumberDevicePrefix", null);
239
395
  /**
240
396
  * window / request 暴露为 public:现存外部工具(如 BookingTicket Scan)通过
241
397
  * `solution.window` / `solution.request` 直接访问插件,保持原有契约不破坏。
@@ -253,6 +409,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
253
409
  _defineProperty(_assertThisInitialized(_this), "autoPaymentSyncTimer", null);
254
410
  _defineProperty(_assertThisInitialized(_this), "salesDetailLoadInFlightCount", 0);
255
411
  _defineProperty(_assertThisInitialized(_this), "salesDetailLoadSequence", 0);
412
+ _defineProperty(_assertThisInitialized(_this), "walletAssetsRefreshSequence", 0);
256
413
  _defineProperty(_assertThisInitialized(_this), "salesDetailHydrateQueue", Promise.resolve());
257
414
  _defineProperty(_assertThisInitialized(_this), "serverOrderChangeUnsubscribe", null);
258
415
  _defineProperty(_assertThisInitialized(_this), "serverOrderChangeHydrateInFlight", null);
@@ -445,12 +602,12 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
445
602
  return _context3.abrupt("return");
446
603
  case 14:
447
604
  this.serverOrderChangeHydrateInFlight = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
448
- var _getTempOrder, _ref2;
605
+ var _getTempOrder, _ref9;
449
606
  var currentTempOrder, record, sales;
450
607
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
451
608
  while (1) switch (_context2.prev = _context2.next) {
452
609
  case 0:
453
- currentTempOrder = (_getTempOrder = (_ref2 = _this2.store.order).getTempOrder) === null || _getTempOrder === void 0 ? void 0 : _getTempOrder.call(_ref2);
610
+ currentTempOrder = (_getTempOrder = (_ref9 = _this2.store.order).getTempOrder) === null || _getTempOrder === void 0 ? void 0 : _getTempOrder.call(_ref9);
454
611
  record = mergeSalesDetailRecordWithTempOrder(currentTempOrder, changedOrder, 'authoritative-incoming');
455
612
  _context2.next = 4;
456
613
  return _this2.store.order.hydrateTempOrderFromRecord(record, {
@@ -510,7 +667,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
510
667
  }, {
511
668
  key: "hydrateLatestLoadedSalesDetail",
512
669
  value: function () {
513
- var _hydrateLatestLoadedSalesDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(record, loadSequence) {
670
+ var _hydrateLatestLoadedSalesDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(record, loadSequence, hydrateSource) {
514
671
  var _this4 = this;
515
672
  var hydratedSales, skippedBeforeHydrate, hydrateTask, queuedTask;
516
673
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
@@ -519,7 +676,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
519
676
  hydratedSales = null;
520
677
  skippedBeforeHydrate = false;
521
678
  hydrateTask = /*#__PURE__*/function () {
522
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
679
+ var _ref10 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
523
680
  var sales;
524
681
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
525
682
  while (1) switch (_context4.prev = _context4.next) {
@@ -538,7 +695,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
538
695
  throw new Error('order 模块未初始化');
539
696
  case 5:
540
697
  _context4.next = 7;
541
- return _this4.store.order.hydrateTempOrderFromRecord(record, {
698
+ return _this4.store.order.hydrateTempOrderFromRecord(record, hydrateSource === 'sessionStorage' ? {
699
+ recalcOnHydrate: true,
700
+ source: 'sessionStorage'
701
+ } : {
542
702
  recalcOnHydrate: false
543
703
  });
544
704
  case 7:
@@ -564,7 +724,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
564
724
  }, _callee4);
565
725
  }));
566
726
  return function hydrateTask() {
567
- return _ref3.apply(this, arguments);
727
+ return _ref10.apply(this, arguments);
568
728
  };
569
729
  }();
570
730
  queuedTask = this.salesDetailHydrateQueue.then(hydrateTask, hydrateTask);
@@ -589,7 +749,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
589
749
  }
590
750
  }, _callee5, this);
591
751
  }));
592
- function hydrateLatestLoadedSalesDetail(_x2, _x3) {
752
+ function hydrateLatestLoadedSalesDetail(_x2, _x3, _x4) {
593
753
  return _hydrateLatestLoadedSalesDetail.apply(this, arguments);
594
754
  }
595
755
  return hydrateLatestLoadedSalesDetail;
@@ -658,10 +818,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
658
818
  });
659
819
  }
660
820
  quotation.setScheduleResolver(function (id) {
661
- var _scheduleModule$getSc, _getScheduleByIds, _ref4;
821
+ var _scheduleModule$getSc, _getScheduleByIds, _ref11;
662
822
  var scheduleId = String(id);
663
823
  if (scheduleById.has(scheduleId)) return scheduleById.get(scheduleId);
664
- var schedules = ((_scheduleModule$getSc = scheduleModule.getScheduleListByIds) === null || _scheduleModule$getSc === void 0 ? void 0 : _scheduleModule$getSc.call(scheduleModule, [id])) || ((_getScheduleByIds = (_ref4 = scheduleModule).getScheduleByIds) === null || _getScheduleByIds === void 0 ? void 0 : _getScheduleByIds.call(_ref4, [id])) || [];
824
+ var schedules = ((_scheduleModule$getSc = scheduleModule.getScheduleListByIds) === null || _scheduleModule$getSc === void 0 ? void 0 : _scheduleModule$getSc.call(scheduleModule, [id])) || ((_getScheduleByIds = (_ref11 = scheduleModule).getScheduleByIds) === null || _getScheduleByIds === void 0 ? void 0 : _getScheduleByIds.call(_ref11, [id])) || [];
665
825
  if (schedules[0]) scheduleById.set(scheduleId, schedules[0]);
666
826
  return schedules[0];
667
827
  });
@@ -692,7 +852,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
692
852
  }
693
853
  }, _callee6, this);
694
854
  }));
695
- function loadQuotationForPriceQuery(_x4) {
855
+ function loadQuotationForPriceQuery(_x5) {
696
856
  return _loadQuotationForPriceQuery.apply(this, arguments);
697
857
  }
698
858
  return loadQuotationForPriceQuery;
@@ -797,7 +957,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
797
957
  }
798
958
  }, _callee7, this, [[4, 15]]);
799
959
  }));
800
- function loadProductsForPriceQuery(_x5) {
960
+ function loadProductsForPriceQuery(_x6) {
801
961
  return _loadProductsForPriceQuery.apply(this, arguments);
802
962
  }
803
963
  return loadProductsForPriceQuery;
@@ -835,7 +995,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
835
995
  }
836
996
  }, _callee8, this);
837
997
  }));
838
- function loadProductForPriceQuery(_x6, _x7) {
998
+ function loadProductForPriceQuery(_x7, _x8) {
839
999
  return _loadProductForPriceQuery.apply(this, arguments);
840
1000
  }
841
1001
  return loadProductForPriceQuery;
@@ -848,10 +1008,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
848
1008
  return groups.flatMap(function (group) {
849
1009
  var items = Array.isArray(group === null || group === void 0 ? void 0 : group.bundle_item) ? group.bundle_item : Array.isArray(group === null || group === void 0 ? void 0 : group.bundleItem) ? group.bundleItem : [];
850
1010
  return items.map(function (item) {
851
- var _item$group_id, _ref5, _item$bundle_group_id;
1011
+ var _item$group_id, _ref12, _item$bundle_group_id;
852
1012
  return _objectSpread(_objectSpread({}, item), {}, {
853
1013
  group_id: (_item$group_id = item === null || item === void 0 ? void 0 : item.group_id) !== null && _item$group_id !== void 0 ? _item$group_id : group === null || group === void 0 ? void 0 : group.id,
854
- bundle_group_id: (_ref5 = (_item$bundle_group_id = item === null || item === void 0 ? void 0 : item.bundle_group_id) !== null && _item$bundle_group_id !== void 0 ? _item$bundle_group_id : item === null || item === void 0 ? void 0 : item.group_id) !== null && _ref5 !== void 0 ? _ref5 : group === null || group === void 0 ? void 0 : group.id
1014
+ bundle_group_id: (_ref12 = (_item$bundle_group_id = item === null || item === void 0 ? void 0 : item.bundle_group_id) !== null && _item$bundle_group_id !== void 0 ? _item$bundle_group_id : item === null || item === void 0 ? void 0 : item.group_id) !== null && _ref12 !== void 0 ? _ref12 : group === null || group === void 0 ? void 0 : group.id
855
1015
  });
856
1016
  });
857
1017
  });
@@ -882,21 +1042,21 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
882
1042
  }, {
883
1043
  key: "getAuthoritativeBundleUnitPrice",
884
1044
  value: function getAuthoritativeBundleUnitPrice(bundle) {
885
- var _ref6, _ref7, _ref8, _bundle$price;
886
- return (_ref6 = (_ref7 = (_ref8 = (_bundle$price = bundle.price) !== null && _bundle$price !== void 0 ? _bundle$price : bundle.bundle_selling_price) !== null && _ref8 !== void 0 ? _ref8 : bundle.custom_price) !== null && _ref7 !== void 0 ? _ref7 : bundle.product_price) !== null && _ref6 !== void 0 ? _ref6 : bundle.base_price;
1045
+ var _ref13, _ref14, _ref15, _bundle$price;
1046
+ return (_ref13 = (_ref14 = (_ref15 = (_bundle$price = bundle.price) !== null && _bundle$price !== void 0 ? _bundle$price : bundle.bundle_selling_price) !== null && _ref15 !== void 0 ? _ref15 : bundle.custom_price) !== null && _ref14 !== void 0 ? _ref14 : bundle.product_price) !== null && _ref13 !== void 0 ? _ref13 : bundle.base_price;
887
1047
  }
888
1048
  }, {
889
1049
  key: "mergeProductForPriceQuery",
890
1050
  value: function mergeProductForPriceQuery(product, authoritativeProduct) {
891
1051
  var _this5 = this,
892
1052
  _product$id,
893
- _ref9,
1053
+ _ref16,
894
1054
  _product$product_id2,
895
- _ref10,
1055
+ _ref17,
896
1056
  _product$product_vari,
897
- _ref11,
1057
+ _ref18,
898
1058
  _product$num,
899
- _ref12,
1059
+ _ref19,
900
1060
  _product$quantity,
901
1061
  _product$metadata4;
902
1062
  if (!authoritativeProduct) return product;
@@ -916,10 +1076,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
916
1076
  });
917
1077
  return _objectSpread(_objectSpread(_objectSpread({}, product), authoritativeProduct), {}, {
918
1078
  id: (_product$id = product.id) !== null && _product$id !== void 0 ? _product$id : authoritativeProduct.id,
919
- product_id: (_ref9 = (_product$product_id2 = product.product_id) !== null && _product$product_id2 !== void 0 ? _product$product_id2 : authoritativeProduct.product_id) !== null && _ref9 !== void 0 ? _ref9 : authoritativeProduct.id,
920
- product_variant_id: (_ref10 = (_product$product_vari = product.product_variant_id) !== null && _product$product_vari !== void 0 ? _product$product_vari : authoritativeProduct.product_variant_id) !== null && _ref10 !== void 0 ? _ref10 : 0,
921
- num: (_ref11 = (_product$num = product.num) !== null && _product$num !== void 0 ? _product$num : product.quantity) !== null && _ref11 !== void 0 ? _ref11 : authoritativeProduct.num,
922
- quantity: (_ref12 = (_product$quantity = product.quantity) !== null && _product$quantity !== void 0 ? _product$quantity : product.num) !== null && _ref12 !== void 0 ? _ref12 : authoritativeProduct.quantity,
1079
+ product_id: (_ref16 = (_product$product_id2 = product.product_id) !== null && _product$product_id2 !== void 0 ? _product$product_id2 : authoritativeProduct.product_id) !== null && _ref16 !== void 0 ? _ref16 : authoritativeProduct.id,
1080
+ product_variant_id: (_ref17 = (_product$product_vari = product.product_variant_id) !== null && _product$product_vari !== void 0 ? _product$product_vari : authoritativeProduct.product_variant_id) !== null && _ref17 !== void 0 ? _ref17 : 0,
1081
+ num: (_ref18 = (_product$num = product.num) !== null && _product$num !== void 0 ? _product$num : product.quantity) !== null && _ref18 !== void 0 ? _ref18 : authoritativeProduct.num,
1082
+ quantity: (_ref19 = (_product$quantity = product.quantity) !== null && _product$quantity !== void 0 ? _product$quantity : product.num) !== null && _ref19 !== void 0 ? _ref19 : authoritativeProduct.quantity,
923
1083
  product_sku: function () {
924
1084
  var authoritativeSku = ensureProductSku(authoritativeProduct);
925
1085
  var productSku = ensureProductSku(product);
@@ -973,13 +1133,23 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
973
1133
  * const params = this.buildSubModuleOtherParams();
974
1134
  * this.core.registerModule(orderModule, { otherParams: params });
975
1135
  */
1136
+ }, {
1137
+ key: "isSessionStoragePersistEnabled",
1138
+ value: function isSessionStoragePersistEnabled() {
1139
+ return Boolean(this.cacheId);
1140
+ }
1141
+ }, {
1142
+ key: "shouldUseSessionStorageForSubModule",
1143
+ value: function shouldUseSessionStorageForSubModule(_moduleName) {
1144
+ return this.isSessionStoragePersistEnabled();
1145
+ }
976
1146
  }, {
977
1147
  key: "buildSubModuleOtherParams",
978
- value: function buildSubModuleOtherParams() {
1148
+ value: function buildSubModuleOtherParams(moduleName) {
979
1149
  return _objectSpread(_objectSpread({}, this.otherParams), {}, {
980
1150
  salesSummaryModuleName: "".concat(this.name, "_salesSummary"),
981
1151
  fatherModule: this.name,
982
- openCache: this.cacheId ? true : false,
1152
+ openCache: this.shouldUseSessionStorageForSubModule(moduleName),
983
1153
  cacheId: this.cacheId
984
1154
  });
985
1155
  }
@@ -995,24 +1165,22 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
995
1165
  value: (function () {
996
1166
  var _syncOtherParamsToSubModules = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(changedParams) {
997
1167
  var _this6 = this;
998
- var _ref13,
999
- _ref13$cover,
1168
+ var _ref20,
1169
+ _ref20$cover,
1000
1170
  cover,
1001
- nextSubModuleOtherParams,
1002
1171
  _args10 = arguments;
1003
1172
  return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1004
1173
  while (1) switch (_context10.prev = _context10.next) {
1005
1174
  case 0:
1006
- _ref13 = _args10.length > 1 && _args10[1] !== undefined ? _args10[1] : {}, _ref13$cover = _ref13.cover, cover = _ref13$cover === void 0 ? false : _ref13$cover;
1007
- nextSubModuleOtherParams = this.buildSubModuleOtherParams();
1008
- _context10.next = 4;
1175
+ _ref20 = _args10.length > 1 && _args10[1] !== undefined ? _args10[1] : {}, _ref20$cover = _ref20.cover, cover = _ref20$cover === void 0 ? false : _ref20$cover;
1176
+ _context10.next = 3;
1009
1177
  return Promise.all(Object.entries(this.store).map( /*#__PURE__*/function () {
1010
- var _ref15 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(_ref14) {
1011
- var _ref16, moduleName, subModule, targetModule;
1178
+ var _ref22 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(_ref21) {
1179
+ var _ref23, moduleName, subModule, targetModule, nextSubModuleOtherParams;
1012
1180
  return _regeneratorRuntime().wrap(function _callee9$(_context9) {
1013
1181
  while (1) switch (_context9.prev = _context9.next) {
1014
1182
  case 0:
1015
- _ref16 = _slicedToArray(_ref14, 2), moduleName = _ref16[0], subModule = _ref16[1];
1183
+ _ref23 = _slicedToArray(_ref21, 2), moduleName = _ref23[0], subModule = _ref23[1];
1016
1184
  if (!_this6.reusedSharedSubModuleNames.has(moduleName)) {
1017
1185
  _context9.next = 3;
1018
1186
  break;
@@ -1026,28 +1194,29 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1026
1194
  }
1027
1195
  return _context9.abrupt("return");
1028
1196
  case 6:
1029
- _context9.next = 8;
1197
+ nextSubModuleOtherParams = _this6.buildSubModuleOtherParams(moduleName);
1198
+ _context9.next = 9;
1030
1199
  return targetModule.updateOtherParams(nextSubModuleOtherParams, {
1031
1200
  changedParams: changedParams,
1032
1201
  cover: cover
1033
1202
  });
1034
- case 8:
1203
+ case 9:
1035
1204
  case "end":
1036
1205
  return _context9.stop();
1037
1206
  }
1038
1207
  }, _callee9);
1039
1208
  }));
1040
- return function (_x9) {
1041
- return _ref15.apply(this, arguments);
1209
+ return function (_x10) {
1210
+ return _ref22.apply(this, arguments);
1042
1211
  };
1043
1212
  }()));
1044
- case 4:
1213
+ case 3:
1045
1214
  case "end":
1046
1215
  return _context10.stop();
1047
1216
  }
1048
1217
  }, _callee10, this);
1049
1218
  }));
1050
- function syncOtherParamsToSubModules(_x8) {
1219
+ function syncOtherParamsToSubModules(_x9) {
1051
1220
  return _syncOtherParamsToSubModules.apply(this, arguments);
1052
1221
  }
1053
1222
  return syncOtherParamsToSubModules;
@@ -1060,13 +1229,16 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1060
1229
  }, {
1061
1230
  key: "readSessionCacheData",
1062
1231
  value: function readSessionCacheData() {
1063
- if (!this.cacheId || !this.window) return {};
1232
+ var cacheId = this.cacheId;
1233
+ if (!cacheId || !this.isSessionStoragePersistEnabled() || !this.window) {
1234
+ return {};
1235
+ }
1064
1236
  try {
1065
1237
  var sessionData = this.window.sessionStorage.getItem(this.name);
1066
1238
  if (!sessionData) return {};
1067
1239
  var data = JSON.parse(sessionData);
1068
- return data && data[this.cacheId] || {};
1069
- } catch (_unused) {
1240
+ return data && data[cacheId] || {};
1241
+ } catch (_unused3) {
1070
1242
  return {};
1071
1243
  }
1072
1244
  }
@@ -1080,6 +1252,38 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1080
1252
  var coreData = app === null || app === void 0 || (_app$models = app.models) === null || _app$models === void 0 || (_app$models$getStore = _app$models.getStore) === null || _app$models$getStore === void 0 || (_app$models$getStore$ = (_app$models$getStore$2 = _app$models$getStore.call(_app$models)).getDataByModel) === null || _app$models$getStore$ === void 0 ? void 0 : _app$models$getStore$.call(_app$models$getStore$2, 'core', 'core');
1081
1253
  return coreData === null || coreData === void 0 ? void 0 : coreData[key];
1082
1254
  }
1255
+
1256
+ /**
1257
+ * 复用业务解决方案初始化时已解析的支付设备短号。
1258
+ * 空值会清除缓存,使后续支付恢复实时读取设备信息的兼容路径。
1259
+ */
1260
+ }, {
1261
+ key: "setPaymentNumberDevicePrefix",
1262
+ value: function setPaymentNumberDevicePrefix(prefix) {
1263
+ var normalized = String(prefix !== null && prefix !== void 0 ? prefix : '').trim();
1264
+ this.paymentNumberDevicePrefix = normalized || null;
1265
+ }
1266
+ }, {
1267
+ key: "getPaymentNumberDevicePrefixSync",
1268
+ value: function getPaymentNumberDevicePrefixSync() {
1269
+ var _this7 = this;
1270
+ if (!this.appPlugin) return 'LOCAL';
1271
+ return resolvePaymentNumberDevicePrefixFromDeviceId(function (key) {
1272
+ return _this7.getAppData(key);
1273
+ });
1274
+ }
1275
+ }, {
1276
+ key: "getPaymentNumberDevicePrefixAsync",
1277
+ value: function getPaymentNumberDevicePrefixAsync() {
1278
+ var _this8 = this;
1279
+ if (!this.appPlugin) return Promise.resolve('LOCAL');
1280
+ if (this.paymentNumberDevicePrefix) {
1281
+ return Promise.resolve(this.paymentNumberDevicePrefix);
1282
+ }
1283
+ return resolvePaymentNumberDevicePrefix(function (key) {
1284
+ return _this8.getAppData(key);
1285
+ });
1286
+ }
1083
1287
  }, {
1084
1288
  key: "syncAppDataToTempOrder",
1085
1289
  value: function syncAppDataToTempOrder(tempOrder) {
@@ -1125,7 +1329,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1125
1329
  var _this$otherParams4,
1126
1330
  _this$appPlugin2,
1127
1331
  _this$appPlugin2$getA,
1128
- _this7 = this,
1332
+ _this9 = this,
1129
1333
  _this$otherParams5;
1130
1334
  var options,
1131
1335
  app,
@@ -1138,6 +1342,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1138
1342
  options = _args11.length > 1 && _args11[1] !== undefined ? _args11[1] : {};
1139
1343
  this.core = core;
1140
1344
  this.initializeOptions = options || {};
1345
+ this.paymentNumberDevicePrefix = null;
1141
1346
  // this.store = { ...this.store, ...(options.store as Partial<BaseSalesState>) };
1142
1347
  this.otherParams = options.otherParams || {};
1143
1348
  this.cacheId = (_this$otherParams4 = this.otherParams) === null || _this$otherParams4 === void 0 ? void 0 : _this$otherParams4.cacheId;
@@ -1155,48 +1360,48 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1155
1360
  targetCacheData = this.readSessionCacheData();
1156
1361
  moduleNames = this.getRegisteredModuleNames();
1157
1362
  moduleNames.forEach(function (step) {
1158
- var reusedModule = _this7.getReusableSharedSubModule(step);
1363
+ var reusedModule = _this9.getReusableSharedSubModule(step);
1159
1364
  if (reusedModule) {
1160
- _this7.store[step] = reusedModule;
1161
- _this7.reusedSharedSubModuleNames.add(step);
1365
+ _this9.store[step] = reusedModule;
1366
+ _this9.reusedSharedSubModuleNames.add(step);
1162
1367
  return;
1163
1368
  }
1164
- var targetModule = _this7.createSubModule(step);
1369
+ var targetModule = _this9.createSubModule(step);
1165
1370
  if (!targetModule) {
1166
1371
  throw new Error("\u6A21\u5757 ".concat(step, " \u4E0D\u5B58\u5728"));
1167
1372
  }
1168
- var hooks = _this7.getSubModuleHooks(step);
1169
- _this7.store[step] = targetModule;
1170
- _this7.core.registerModule(targetModule, _objectSpread(_objectSpread({
1171
- initialState: (targetCacheData === null || targetCacheData === void 0 ? void 0 : targetCacheData[targetModule.name]) || {}
1373
+ var hooks = _this9.getSubModuleHooks(step);
1374
+ _this9.store[step] = targetModule;
1375
+ _this9.core.registerModule(targetModule, _objectSpread(_objectSpread({
1376
+ initialState: _this9.shouldUseSessionStorageForSubModule(step) ? (targetCacheData === null || targetCacheData === void 0 ? void 0 : targetCacheData[targetModule.name]) || {} : {}
1172
1377
  }, hooks ? {
1173
1378
  hooks: hooks
1174
1379
  } : {}), {}, {
1175
- otherParams: _this7.buildSubModuleOtherParams()
1380
+ otherParams: _this9.buildSubModuleOtherParams(step)
1176
1381
  }));
1177
1382
  });
1178
1383
  if (!(this.store.schedule && !this.isScheduleListLoaded(this.store.schedule))) {
1179
- _context11.next = 18;
1384
+ _context11.next = 19;
1180
1385
  break;
1181
1386
  }
1182
- _context11.next = 18;
1387
+ _context11.next = 19;
1183
1388
  return this.store.schedule.loadAllSchedule();
1184
- case 18:
1389
+ case 19:
1185
1390
  if (this.store.order && typeof ((_this$otherParams5 = this.otherParams) === null || _this$otherParams5 === void 0 ? void 0 : _this$otherParams5.enableTempOrderPersist) === 'boolean') {
1186
1391
  this.store.order.setEnableTempOrderPersist(this.otherParams.enableTempOrderPersist);
1187
1392
  }
1188
- _context11.next = 21;
1393
+ _context11.next = 22;
1189
1394
  return this.getPaymentMethodsAsync();
1190
- case 21:
1395
+ case 22:
1191
1396
  this.registerServerOrderChangeSync();
1192
1397
  this.core.effects.emit("".concat(this.name, ":onInited"), {});
1193
- case 23:
1398
+ case 24:
1194
1399
  case "end":
1195
1400
  return _context11.stop();
1196
1401
  }
1197
1402
  }, _callee11, this);
1198
1403
  }));
1199
- function initialize(_x10) {
1404
+ function initialize(_x11) {
1200
1405
  return _initialize.apply(this, arguments);
1201
1406
  }
1202
1407
  return initialize;
@@ -1206,15 +1411,15 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1206
1411
  value: function () {
1207
1412
  var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
1208
1413
  var _this$serverOrderChan2,
1209
- _this8 = this;
1414
+ _this10 = this;
1210
1415
  return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1211
1416
  while (1) switch (_context12.prev = _context12.next) {
1212
1417
  case 0:
1213
1418
  (_this$serverOrderChan2 = this.serverOrderChangeUnsubscribe) === null || _this$serverOrderChan2 === void 0 || _this$serverOrderChan2.call(this);
1214
1419
  this.serverOrderChangeUnsubscribe = null;
1215
1420
  Object.keys(this.store).forEach(function (key) {
1216
- if (_this8.reusedSharedSubModuleNames.has(key)) return;
1217
- var sub = _this8.store[key];
1421
+ if (_this10.reusedSharedSubModuleNames.has(key)) return;
1422
+ var sub = _this10.store[key];
1218
1423
  if (sub && typeof sub.destroy === 'function') {
1219
1424
  try {
1220
1425
  sub.destroy();
@@ -1224,13 +1429,15 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1224
1429
  }
1225
1430
  });
1226
1431
  this.currentSalesDetail = null;
1432
+ this.paymentNumberDevicePrefix = null;
1227
1433
  this.queuedServerOrderChanges = [];
1228
1434
  this.salesDetailLoadSequence += 1;
1229
- _context12.next = 8;
1435
+ this.walletAssetsRefreshSequence += 1;
1436
+ _context12.next = 10;
1230
1437
  return this.core.effects.emit("".concat(this.name, ":onDestroy"), {});
1231
- case 8:
1438
+ case 10:
1232
1439
  _get(_getPrototypeOf(BaseSalesImpl.prototype), "destroy", this).call(this);
1233
- case 9:
1440
+ case 11:
1234
1441
  case "end":
1235
1442
  return _context12.stop();
1236
1443
  }
@@ -1252,7 +1459,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1252
1459
  key: "loadSalesDetail",
1253
1460
  value: (function () {
1254
1461
  var _loadSalesDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(orderIdOrParams) {
1255
- var loadSequence, _ref17, _ref18, _ref19, _ref20, _params$orderId, params, externalSaleNumber, preloadedSalesDetail, lookup, loadedRecord, message, remoteRecord, currentTempOrder, record;
1462
+ var loadSequence, _ref24, _ref25, _ref26, _ref27, _params$orderId, params, externalSaleNumber, preloadedSalesDetail, lookup, loadedRecord, message, loadedSalesDetail, shouldFilterPendingPayments, remoteRecord, currentTempOrder, mergedRecord, record;
1256
1463
  return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1257
1464
  while (1) switch (_context13.prev = _context13.next) {
1258
1465
  case 0:
@@ -1270,7 +1477,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1270
1477
  };
1271
1478
  externalSaleNumber = params.externalSaleNumber || params.external_sale_number;
1272
1479
  preloadedSalesDetail = params.preloadedSalesDetail;
1273
- lookup = (_ref17 = (_ref18 = (_ref19 = (_ref20 = (_params$orderId = params.orderId) !== null && _params$orderId !== void 0 ? _params$orderId : externalSaleNumber) !== null && _ref20 !== void 0 ? _ref20 : params.orderNumber) !== null && _ref19 !== void 0 ? _ref19 : preloadedSalesDetail === null || preloadedSalesDetail === void 0 ? void 0 : preloadedSalesDetail.order_id) !== null && _ref18 !== void 0 ? _ref18 : preloadedSalesDetail === null || preloadedSalesDetail === void 0 ? void 0 : preloadedSalesDetail.external_sale_number) !== null && _ref17 !== void 0 ? _ref17 : preloadedSalesDetail === null || preloadedSalesDetail === void 0 ? void 0 : preloadedSalesDetail.order_number;
1480
+ lookup = (_ref24 = (_ref25 = (_ref26 = (_ref27 = (_params$orderId = params.orderId) !== null && _params$orderId !== void 0 ? _params$orderId : externalSaleNumber) !== null && _ref27 !== void 0 ? _ref27 : params.orderNumber) !== null && _ref26 !== void 0 ? _ref26 : preloadedSalesDetail === null || preloadedSalesDetail === void 0 ? void 0 : preloadedSalesDetail.order_id) !== null && _ref25 !== void 0 ? _ref25 : preloadedSalesDetail === null || preloadedSalesDetail === void 0 ? void 0 : preloadedSalesDetail.external_sale_number) !== null && _ref24 !== void 0 ? _ref24 : preloadedSalesDetail === null || preloadedSalesDetail === void 0 ? void 0 : preloadedSalesDetail.order_number;
1274
1481
  if (!(!preloadedSalesDetail && (lookup === undefined || lookup === null || lookup === ''))) {
1275
1482
  _context13.next = 11;
1276
1483
  break;
@@ -1301,41 +1508,44 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1301
1508
  message = loadedRecord && (loadedRecord.message || loadedRecord.msg) || "\u52A0\u8F7D\u9500\u552E\u8BE6\u60C5\u5931\u8D25: ".concat(lookup);
1302
1509
  throw new Error(message);
1303
1510
  case 22:
1304
- remoteRecord = preloadedSalesDetail !== null && preloadedSalesDetail !== void 0 ? preloadedSalesDetail : loadedRecord.data;
1511
+ loadedSalesDetail = preloadedSalesDetail !== null && preloadedSalesDetail !== void 0 ? preloadedSalesDetail : loadedRecord.data; // payment_pending 只存在于本地;远端详情需过滤,但会话快照必须完整恢复。
1512
+ shouldFilterPendingPayments = params.hydrateSource !== 'sessionStorage';
1513
+ remoteRecord = shouldFilterPendingPayments ? filterPendingPaymentsFromLoadedSalesDetail(loadedSalesDetail) : loadedSalesDetail;
1305
1514
  currentTempOrder = params.merge ? this.store.order.getTempOrder() : null;
1306
- record = params.merge ? mergeSalesDetailRecordWithTempOrder(currentTempOrder, remoteRecord, 'preserve-local') : remoteRecord;
1307
- _context13.next = 27;
1308
- return this.hydrateLatestLoadedSalesDetail(record, loadSequence);
1309
- case 27:
1515
+ mergedRecord = params.merge ? mergeSalesDetailRecordWithTempOrder(currentTempOrder, remoteRecord, 'preserve-local') : remoteRecord;
1516
+ record = shouldFilterPendingPayments ? filterPendingPaymentsFromLoadedSalesDetail(mergedRecord) : mergedRecord;
1517
+ _context13.next = 30;
1518
+ return this.hydrateLatestLoadedSalesDetail(record, loadSequence, params.hydrateSource);
1519
+ case 30:
1310
1520
  return _context13.abrupt("return", _context13.sent);
1311
- case 28:
1312
- _context13.prev = 28;
1521
+ case 31:
1522
+ _context13.prev = 31;
1313
1523
  this.salesDetailLoadInFlightCount = Math.max(0, this.salesDetailLoadInFlightCount - 1);
1314
1524
  if (!(this.salesDetailLoadInFlightCount === 0)) {
1315
- _context13.next = 39;
1525
+ _context13.next = 42;
1316
1526
  break;
1317
1527
  }
1318
- _context13.prev = 31;
1319
- _context13.next = 34;
1528
+ _context13.prev = 34;
1529
+ _context13.next = 37;
1320
1530
  return this.drainQueuedServerOrderChanges();
1321
- case 34:
1322
- _context13.next = 39;
1531
+ case 37:
1532
+ _context13.next = 42;
1323
1533
  break;
1324
- case 36:
1325
- _context13.prev = 36;
1326
- _context13.t1 = _context13["catch"](31);
1534
+ case 39:
1535
+ _context13.prev = 39;
1536
+ _context13.t1 = _context13["catch"](34);
1327
1537
  this.logError('drain queued server order changes failed', {
1328
1538
  error: _context13.t1 instanceof Error ? _context13.t1.message : String(_context13.t1)
1329
1539
  });
1330
- case 39:
1331
- return _context13.finish(28);
1332
- case 40:
1540
+ case 42:
1541
+ return _context13.finish(31);
1542
+ case 43:
1333
1543
  case "end":
1334
1544
  return _context13.stop();
1335
1545
  }
1336
- }, _callee13, this, [[4,, 28, 40], [31, 36]]);
1546
+ }, _callee13, this, [[4,, 31, 43], [34, 39]]);
1337
1547
  }));
1338
- function loadSalesDetail(_x11) {
1548
+ function loadSalesDetail(_x12) {
1339
1549
  return _loadSalesDetail.apply(this, arguments);
1340
1550
  }
1341
1551
  return loadSalesDetail;
@@ -1442,7 +1652,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1442
1652
  }
1443
1653
  }, _callee14, this);
1444
1654
  }));
1445
- function replaceTempOrder(_x12) {
1655
+ function replaceTempOrder(_x13) {
1446
1656
  return _replaceTempOrder.apply(this, arguments);
1447
1657
  }
1448
1658
  return replaceTempOrder;
@@ -1610,7 +1820,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1610
1820
  key: "restoreOrder",
1611
1821
  value: function () {
1612
1822
  var _restoreOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
1613
- var tempOrder;
1823
+ var _this$store$payment, tempOrder, wallet;
1614
1824
  return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1615
1825
  while (1) switch (_context17.prev = _context17.next) {
1616
1826
  case 0:
@@ -1626,29 +1836,39 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1626
1836
  this.currentSalesDetail = null;
1627
1837
  this.discountConfigCacheKey = null;
1628
1838
  this.hasManualDiscountSelection = false;
1629
- _context17.next = 9;
1839
+ wallet = (_this$store$payment = this.store.payment) === null || _this$store$payment === void 0 ? void 0 : _this$store$payment.wallet;
1840
+ if (!wallet) {
1841
+ _context17.next = 13;
1842
+ break;
1843
+ }
1844
+ this.walletAssetsRefreshSequence += 1;
1845
+ wallet.clearAllCache();
1846
+ _context17.next = 13;
1847
+ return this.publishWalletAssetsState(wallet.getWalletAssetsState());
1848
+ case 13:
1849
+ _context17.next = 15;
1630
1850
  return this.effectsEmit('onTempOrderReplaced', {
1631
1851
  tempOrder: tempOrder
1632
1852
  });
1633
- case 9:
1853
+ case 15:
1634
1854
  if (!(this.syncAppDataToTempOrder(tempOrder) && this.isTempOrderPersistEnabled())) {
1635
- _context17.next = 13;
1855
+ _context17.next = 19;
1636
1856
  break;
1637
1857
  }
1638
1858
  this.store.order.persistTempOrder();
1639
- _context17.next = 13;
1859
+ _context17.next = 19;
1640
1860
  return this.store.order.saveDraft();
1641
- case 13:
1861
+ case 19:
1642
1862
  return _context17.abrupt("return", tempOrder);
1643
- case 16:
1644
- _context17.prev = 16;
1863
+ case 22:
1864
+ _context17.prev = 22;
1645
1865
  _context17.t0 = _context17["catch"](0);
1646
1866
  throw _context17.t0;
1647
- case 19:
1867
+ case 25:
1648
1868
  case "end":
1649
1869
  return _context17.stop();
1650
1870
  }
1651
- }, _callee17, this, [[0, 16]]);
1871
+ }, _callee17, this, [[0, 22]]);
1652
1872
  }));
1653
1873
  function restoreOrder() {
1654
1874
  return _restoreOrder.apply(this, arguments);
@@ -1761,10 +1981,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1761
1981
  }, {
1762
1982
  key: "getHistoricalProductDiscountList",
1763
1983
  value: function getHistoricalProductDiscountList(products) {
1764
- var _this9 = this;
1984
+ var _this11 = this;
1765
1985
  var historyDiscountList = [];
1766
1986
  products.forEach(function (item) {
1767
- if (!_this9.isPersistedOrderProduct(item)) return;
1987
+ if (!_this11.isPersistedOrderProduct(item)) return;
1768
1988
  (item.discount_list || []).forEach(function (discount) {
1769
1989
  var _discount$discount, _discount$metadata, _discount$discount2, _discount$discount3, _discount$discount4;
1770
1990
  var discountId = ((_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) || discount.id;
@@ -1824,11 +2044,11 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1824
2044
  }, {
1825
2045
  key: "shouldSkipAutoApplyFetchedDiscountsInEditMode",
1826
2046
  value: function shouldSkipAutoApplyFetchedDiscountsInEditMode(params) {
1827
- var _this10 = this;
2047
+ var _this12 = this;
1828
2048
  if (params.discountAction !== 'edit') return false;
1829
2049
  if (!params.products.length) return false;
1830
2050
  var hasDraftProduct = params.products.some(function (product) {
1831
- return !_this10.isPersistedOrderProduct(product);
2051
+ return !_this12.isPersistedOrderProduct(product);
1832
2052
  });
1833
2053
  if (hasDraftProduct) return false;
1834
2054
  var hasSelectedDiscount = params.currentDiscountList.some(function (discount) {
@@ -2072,7 +2292,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2072
2292
  }
2073
2293
  }, _callee20, this, [[46, 65, 68, 71]]);
2074
2294
  }));
2075
- function loadDiscountConfig(_x13) {
2295
+ function loadDiscountConfig(_x14) {
2076
2296
  return _loadDiscountConfig.apply(this, arguments);
2077
2297
  }
2078
2298
  return loadDiscountConfig;
@@ -2170,7 +2390,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2170
2390
  }
2171
2391
  }, _callee21, this);
2172
2392
  }));
2173
- function bestDiscount(_x14) {
2393
+ function bestDiscount(_x15) {
2174
2394
  return _bestDiscount.apply(this, arguments);
2175
2395
  }
2176
2396
  return bestDiscount;
@@ -2233,7 +2453,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2233
2453
  }
2234
2454
  }, _callee22, this);
2235
2455
  }));
2236
- function replaceDiscountStoreLists(_x15) {
2456
+ function replaceDiscountStoreLists(_x16) {
2237
2457
  return _replaceDiscountStoreLists.apply(this, arguments);
2238
2458
  }
2239
2459
  return replaceDiscountStoreLists;
@@ -2276,12 +2496,15 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2276
2496
  tempOrder: tempOrder
2277
2497
  });
2278
2498
  case 13:
2279
- return _context23.abrupt("return", {
2280
- isAvailable: raw.isAvailable,
2499
+ return _context23.abrupt("return", _objectSpread(_objectSpread({
2500
+ isAvailable: raw.isAvailable
2501
+ }, raw.isAccepted !== undefined ? {
2502
+ isAccepted: raw.isAccepted
2503
+ } : {}), {}, {
2281
2504
  type: raw.type,
2282
2505
  unavailableReason: raw.unavailableReason,
2283
2506
  scannedDiscountList: raw.scannedDiscountList
2284
- });
2507
+ }));
2285
2508
  case 16:
2286
2509
  _context23.prev = 16;
2287
2510
  _context23.t0 = _context23["catch"](0);
@@ -2292,7 +2515,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2292
2515
  }
2293
2516
  }, _callee23, this, [[0, 16]]);
2294
2517
  }));
2295
- function scanPromotionCode(_x16, _x17) {
2518
+ function scanPromotionCode(_x17, _x18) {
2296
2519
  return _scanPromotionCode.apply(this, arguments);
2297
2520
  }
2298
2521
  return scanPromotionCode;
@@ -2407,10 +2630,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2407
2630
  product.discount_list = filterSelectedDiscountDetails(product.discount_list);
2408
2631
  if (Array.isArray(product.product_bundle)) {
2409
2632
  product.product_bundle = product.product_bundle.map(function (bundle) {
2410
- var _ref21, _bundle$original_pric;
2633
+ var _ref28, _bundle$original_pric;
2411
2634
  var nextBundleDiscountList = filterSelectedDiscountDetails(bundle === null || bundle === void 0 ? void 0 : bundle.discount_list);
2412
2635
  var shouldRestoreBundlePrice = nextBundleDiscountList.length === 0;
2413
- var restoredBundlePrice = (_ref21 = (_bundle$original_pric = bundle === null || bundle === void 0 ? void 0 : bundle.original_price) !== null && _bundle$original_pric !== void 0 ? _bundle$original_pric : bundle === null || bundle === void 0 ? void 0 : bundle.product_price) !== null && _ref21 !== void 0 ? _ref21 : bundle === null || bundle === void 0 ? void 0 : bundle.price;
2636
+ var restoredBundlePrice = (_ref28 = (_bundle$original_pric = bundle === null || bundle === void 0 ? void 0 : bundle.original_price) !== null && _bundle$original_pric !== void 0 ? _bundle$original_pric : bundle === null || bundle === void 0 ? void 0 : bundle.product_price) !== null && _ref28 !== void 0 ? _ref28 : bundle === null || bundle === void 0 ? void 0 : bundle.price;
2414
2637
  return _objectSpread(_objectSpread(_objectSpread({}, bundle), shouldRestoreBundlePrice ? {
2415
2638
  price: restoredBundlePrice,
2416
2639
  bundle_selling_price: restoredBundlePrice
@@ -2483,7 +2706,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2483
2706
  }
2484
2707
  }, _callee24, this, [[0, 54], [17, 38, 41, 44]]);
2485
2708
  }));
2486
- function setDiscountSelected(_x18) {
2709
+ function setDiscountSelected(_x19) {
2487
2710
  return _setDiscountSelected.apply(this, arguments);
2488
2711
  }
2489
2712
  return setDiscountSelected;
@@ -2553,7 +2776,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2553
2776
  }
2554
2777
  }, _callee25, this, [[0, 21]]);
2555
2778
  }));
2556
- function applyDiscountCalculationResult(_x19) {
2779
+ function applyDiscountCalculationResult(_x20) {
2557
2780
  return _applyDiscountCalculationResult.apply(this, arguments);
2558
2781
  }
2559
2782
  return applyDiscountCalculationResult;
@@ -2572,7 +2795,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2572
2795
  }
2573
2796
  }, _callee26, this);
2574
2797
  }));
2575
- function submitScanOrder(_x20) {
2798
+ function submitScanOrder(_x21) {
2576
2799
  return _submitScanOrder.apply(this, arguments);
2577
2800
  }
2578
2801
  return submitScanOrder;
@@ -2626,17 +2849,16 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2626
2849
  }
2627
2850
  }, _callee27, this);
2628
2851
  }));
2629
- function submitSalesOrder(_x21) {
2852
+ function submitSalesOrder(_x22) {
2630
2853
  return _submitSalesOrder.apply(this, arguments);
2631
2854
  }
2632
2855
  return submitSalesOrder;
2633
2856
  }())
2634
2857
  }, {
2635
- key: "submitTempOrderAsync",
2858
+ key: "saveSalesOrderDraft",
2636
2859
  value: function () {
2637
- var _submitTempOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(params) {
2638
- var _params$smallTicketDa2, _this$otherParams10, _this$otherParams11, _this$otherParams12, _this$otherParams13;
2639
- var inferredPaymentStatus, smallTicketDataFlag, submitParams;
2860
+ var _saveSalesOrderDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(params) {
2861
+ var _params$platform, _this$otherParams10, _this$otherParams11, _this$otherParams12, _params$channel, _params$type, _this$otherParams13;
2640
2862
  return _regeneratorRuntime().wrap(function _callee28$(_context28) {
2641
2863
  while (1) switch (_context28.prev = _context28.next) {
2642
2864
  case 0:
@@ -2645,15 +2867,50 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2645
2867
  break;
2646
2868
  }
2647
2869
  throw new Error('BaseSales 解决方案需要 order 模块支持');
2870
+ case 2:
2871
+ return _context28.abrupt("return", this.store.order.saveTempOrderAsDraft(_objectSpread({
2872
+ cacheId: this.cacheId,
2873
+ platform: (_params$platform = params === null || params === void 0 ? void 0 : params.platform) !== null && _params$platform !== void 0 ? _params$platform : (_this$otherParams10 = this.otherParams) === null || _this$otherParams10 === void 0 ? void 0 : _this$otherParams10.platform,
2874
+ businessCode: (params === null || params === void 0 ? void 0 : params.businessCode) || ((_this$otherParams11 = this.otherParams) === null || _this$otherParams11 === void 0 ? void 0 : _this$otherParams11.businessCode) || ((_this$otherParams12 = this.otherParams) === null || _this$otherParams12 === void 0 ? void 0 : _this$otherParams12.business_code),
2875
+ channel: (_params$channel = params === null || params === void 0 ? void 0 : params.channel) !== null && _params$channel !== void 0 ? _params$channel : this.getSubmitOrderSalesChannel(),
2876
+ type: (_params$type = params === null || params === void 0 ? void 0 : params.type) !== null && _params$type !== void 0 ? _params$type : (_this$otherParams13 = this.otherParams) === null || _this$otherParams13 === void 0 ? void 0 : _this$otherParams13.type
2877
+ }, (params === null || params === void 0 ? void 0 : params.enhancePayload) !== undefined ? {
2878
+ enhancePayload: params.enhancePayload
2879
+ } : {})));
2880
+ case 3:
2881
+ case "end":
2882
+ return _context28.stop();
2883
+ }
2884
+ }, _callee28, this);
2885
+ }));
2886
+ function saveSalesOrderDraft(_x23) {
2887
+ return _saveSalesOrderDraft.apply(this, arguments);
2888
+ }
2889
+ return saveSalesOrderDraft;
2890
+ }()
2891
+ }, {
2892
+ key: "submitTempOrderAsync",
2893
+ value: function () {
2894
+ var _submitTempOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(params) {
2895
+ var _params$smallTicketDa2, _this$otherParams14, _this$otherParams15, _this$otherParams16, _this$otherParams17;
2896
+ var inferredPaymentStatus, smallTicketDataFlag, submitParams;
2897
+ return _regeneratorRuntime().wrap(function _callee29$(_context29) {
2898
+ while (1) switch (_context29.prev = _context29.next) {
2899
+ case 0:
2900
+ if (this.store.order) {
2901
+ _context29.next = 2;
2902
+ break;
2903
+ }
2904
+ throw new Error('BaseSales 解决方案需要 order 模块支持');
2648
2905
  case 2:
2649
2906
  inferredPaymentStatus = this.getSubmitPaymentStatus(params === null || params === void 0 ? void 0 : params.paymentStatus);
2650
2907
  smallTicketDataFlag = (_params$smallTicketDa2 = params === null || params === void 0 ? void 0 : params.smallTicketDataFlag) !== null && _params$smallTicketDa2 !== void 0 ? _params$smallTicketDa2 : this.getDefaultCheckoutSmallTicketDataFlag();
2651
2908
  submitParams = _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
2652
2909
  cacheId: this.cacheId,
2653
- platform: (_this$otherParams10 = this.otherParams) === null || _this$otherParams10 === void 0 ? void 0 : _this$otherParams10.platform,
2654
- businessCode: ((_this$otherParams11 = this.otherParams) === null || _this$otherParams11 === void 0 ? void 0 : _this$otherParams11.businessCode) || ((_this$otherParams12 = this.otherParams) === null || _this$otherParams12 === void 0 ? void 0 : _this$otherParams12.business_code),
2910
+ platform: (_this$otherParams14 = this.otherParams) === null || _this$otherParams14 === void 0 ? void 0 : _this$otherParams14.platform,
2911
+ businessCode: ((_this$otherParams15 = this.otherParams) === null || _this$otherParams15 === void 0 ? void 0 : _this$otherParams15.businessCode) || ((_this$otherParams16 = this.otherParams) === null || _this$otherParams16 === void 0 ? void 0 : _this$otherParams16.business_code),
2655
2912
  channel: this.getSubmitOrderSalesChannel(),
2656
- type: (_this$otherParams13 = this.otherParams) === null || _this$otherParams13 === void 0 ? void 0 : _this$otherParams13.type,
2913
+ type: (_this$otherParams17 = this.otherParams) === null || _this$otherParams17 === void 0 ? void 0 : _this$otherParams17.type,
2657
2914
  request_unique_idempotency_token: this.store.order.generateIdempotencyToken()
2658
2915
  }, (params === null || params === void 0 ? void 0 : params.payments) !== undefined ? {
2659
2916
  payments: params.payments
@@ -2666,14 +2923,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2666
2923
  } : {}), (params === null || params === void 0 ? void 0 : params.enhancePayload) !== undefined ? {
2667
2924
  enhancePayload: params.enhancePayload
2668
2925
  } : {});
2669
- return _context28.abrupt("return", this.store.order.submitTempOrderAsync(submitParams));
2926
+ return _context29.abrupt("return", this.store.order.submitTempOrderAsync(submitParams));
2670
2927
  case 6:
2671
2928
  case "end":
2672
- return _context28.stop();
2929
+ return _context29.stop();
2673
2930
  }
2674
- }, _callee28, this);
2931
+ }, _callee29, this);
2675
2932
  }));
2676
- function submitTempOrderAsync(_x22) {
2933
+ function submitTempOrderAsync(_x24) {
2677
2934
  return _submitTempOrderAsync.apply(this, arguments);
2678
2935
  }
2679
2936
  return submitTempOrderAsync;
@@ -2685,8 +2942,8 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2685
2942
  }, {
2686
2943
  key: "shouldUseCheckoutSyncTask",
2687
2944
  value: function shouldUseCheckoutSyncTask() {
2688
- var _this$otherParams14;
2689
- var configured = (_this$otherParams14 = this.otherParams) === null || _this$otherParams14 === void 0 ? void 0 : _this$otherParams14.checkoutSyncTaskEnabled;
2945
+ var _this$otherParams18;
2946
+ var configured = (_this$otherParams18 = this.otherParams) === null || _this$otherParams18 === void 0 ? void 0 : _this$otherParams18.checkoutSyncTaskEnabled;
2690
2947
  return typeof configured === 'boolean' ? configured : true;
2691
2948
  }
2692
2949
 
@@ -2699,14 +2956,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2699
2956
  }, {
2700
2957
  key: "printLocalOrderReceipt",
2701
2958
  value: function () {
2702
- var _printLocalOrderReceipt = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(lookup) {
2703
- var _this$otherParams15, _this$otherParams16, _this$otherParams17, _this$otherParams18;
2959
+ var _printLocalOrderReceipt = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(lookup) {
2960
+ var _this$otherParams19, _this$otherParams20, _this$otherParams21, _this$otherParams22;
2704
2961
  var hasLookup, lookupPayload, context, payload, response, _this$store$order$app, _this$store$order5, _data;
2705
- return _regeneratorRuntime().wrap(function _callee29$(_context29) {
2706
- while (1) switch (_context29.prev = _context29.next) {
2962
+ return _regeneratorRuntime().wrap(function _callee30$(_context30) {
2963
+ while (1) switch (_context30.prev = _context30.next) {
2707
2964
  case 0:
2708
2965
  if (this.store.order) {
2709
- _context29.next = 2;
2966
+ _context30.next = 2;
2710
2967
  break;
2711
2968
  }
2712
2969
  throw new Error('BaseSales 解决方案需要 order 模块支持');
@@ -2718,10 +2975,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2718
2975
  external_sale_number: lookup
2719
2976
  };
2720
2977
  context = {
2721
- platform: (_this$otherParams15 = this.otherParams) === null || _this$otherParams15 === void 0 ? void 0 : _this$otherParams15.platform,
2722
- businessCode: ((_this$otherParams16 = this.otherParams) === null || _this$otherParams16 === void 0 ? void 0 : _this$otherParams16.businessCode) || ((_this$otherParams17 = this.otherParams) === null || _this$otherParams17 === void 0 ? void 0 : _this$otherParams17.business_code),
2978
+ platform: (_this$otherParams19 = this.otherParams) === null || _this$otherParams19 === void 0 ? void 0 : _this$otherParams19.platform,
2979
+ businessCode: ((_this$otherParams20 = this.otherParams) === null || _this$otherParams20 === void 0 ? void 0 : _this$otherParams20.businessCode) || ((_this$otherParams21 = this.otherParams) === null || _this$otherParams21 === void 0 ? void 0 : _this$otherParams21.business_code),
2723
2980
  channel: this.getSubmitOrderSalesChannel(),
2724
- type: (_this$otherParams18 = this.otherParams) === null || _this$otherParams18 === void 0 ? void 0 : _this$otherParams18.type
2981
+ type: (_this$otherParams22 = this.otherParams) === null || _this$otherParams22 === void 0 ? void 0 : _this$otherParams22.type
2725
2982
  };
2726
2983
  payload = hasLookup ? _objectSpread(_objectSpread({}, lookupPayload), {}, {
2727
2984
  lookup_order_from_db: 1,
@@ -2737,28 +2994,28 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2737
2994
  channel: context.channel,
2738
2995
  type: context.type
2739
2996
  });
2740
- _context29.next = 8;
2997
+ _context30.next = 8;
2741
2998
  return this.request.post('/local/print-order', payload, {
2742
2999
  osServer: true,
2743
3000
  customToast: function customToast() {}
2744
3001
  });
2745
3002
  case 8:
2746
- response = _context29.sent;
3003
+ response = _context30.sent;
2747
3004
  if (hasLookup) {
2748
- _context29.next = 12;
3005
+ _context30.next = 12;
2749
3006
  break;
2750
3007
  }
2751
- _context29.next = 12;
3008
+ _context30.next = 12;
2752
3009
  return (_this$store$order$app = (_this$store$order5 = this.store.order).applyLocalPrintOrderNumbers) === null || _this$store$order$app === void 0 ? void 0 : _this$store$order$app.call(_this$store$order5, response === null || response === void 0 || (_data = response.data) === null || _data === void 0 ? void 0 : _data.order);
2753
3010
  case 12:
2754
- return _context29.abrupt("return", response);
3011
+ return _context30.abrupt("return", response);
2755
3012
  case 13:
2756
3013
  case "end":
2757
- return _context29.stop();
3014
+ return _context30.stop();
2758
3015
  }
2759
- }, _callee29, this);
3016
+ }, _callee30, this);
2760
3017
  }));
2761
- function printLocalOrderReceipt(_x23) {
3018
+ function printLocalOrderReceipt(_x25) {
2762
3019
  return _printLocalOrderReceipt.apply(this, arguments);
2763
3020
  }
2764
3021
  return printLocalOrderReceipt;
@@ -2772,27 +3029,27 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2772
3029
  if (!amountSnapshot) return undefined;
2773
3030
  try {
2774
3031
  return new Decimal(amountSnapshot.amountGap || 0).lte(0) ? 'paid' : undefined;
2775
- } catch (_unused2) {
3032
+ } catch (_unused4) {
2776
3033
  return undefined;
2777
3034
  }
2778
3035
  }
2779
3036
  }, {
2780
3037
  key: "syncPaymentsToOrder",
2781
3038
  value: function () {
2782
- var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(params) {
2783
- var _ref22, _params$businessCode, _this$otherParams19, _this$otherParams20, _params$channel;
3039
+ var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(params) {
3040
+ var _ref29, _params$businessCode, _this$otherParams23, _this$otherParams24, _params$channel2;
2784
3041
  var businessCode, channel, syncParams, syncState, payments, syncResult, latestPayments, amountSnapshot, orderSnapshot, syncPayload;
2785
- return _regeneratorRuntime().wrap(function _callee30$(_context30) {
2786
- while (1) switch (_context30.prev = _context30.next) {
3042
+ return _regeneratorRuntime().wrap(function _callee31$(_context31) {
3043
+ while (1) switch (_context31.prev = _context31.next) {
2787
3044
  case 0:
2788
3045
  if (this.store.order) {
2789
- _context30.next = 2;
3046
+ _context31.next = 2;
2790
3047
  break;
2791
3048
  }
2792
3049
  throw new Error('order 模块未初始化');
2793
3050
  case 2:
2794
- businessCode = (_ref22 = (_params$businessCode = params.businessCode) !== null && _params$businessCode !== void 0 ? _params$businessCode : (_this$otherParams19 = this.otherParams) === null || _this$otherParams19 === void 0 ? void 0 : _this$otherParams19.businessCode) !== null && _ref22 !== void 0 ? _ref22 : (_this$otherParams20 = this.otherParams) === null || _this$otherParams20 === void 0 ? void 0 : _this$otherParams20.business_code;
2795
- channel = (_params$channel = params.channel) !== null && _params$channel !== void 0 ? _params$channel : this.getSubmitOrderSalesChannel();
3051
+ businessCode = (_ref29 = (_params$businessCode = params.businessCode) !== null && _params$businessCode !== void 0 ? _params$businessCode : (_this$otherParams23 = this.otherParams) === null || _this$otherParams23 === void 0 ? void 0 : _this$otherParams23.businessCode) !== null && _ref29 !== void 0 ? _ref29 : (_this$otherParams24 = this.otherParams) === null || _this$otherParams24 === void 0 ? void 0 : _this$otherParams24.business_code;
3052
+ channel = (_params$channel2 = params.channel) !== null && _params$channel2 !== void 0 ? _params$channel2 : this.getSubmitOrderSalesChannel();
2796
3053
  syncParams = _objectSpread(_objectSpread(_objectSpread({}, params), {}, {
2797
3054
  checkoutSyncTaskEnabled: this.shouldUseCheckoutSyncTask()
2798
3055
  }, businessCode !== undefined ? {
@@ -2802,14 +3059,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2802
3059
  } : {});
2803
3060
  syncState = this.store.order.getOrderSyncState();
2804
3061
  if (!(params.submitWhenPaid && syncState === 'submitting')) {
2805
- _context30.next = 9;
3062
+ _context31.next = 9;
2806
3063
  break;
2807
3064
  }
2808
3065
  this.queueLatestAutoPaymentSync();
2809
- return _context30.abrupt("return", this.store.order.syncPaymentsToOrder(syncParams));
3066
+ return _context31.abrupt("return", this.store.order.syncPaymentsToOrder(syncParams));
2810
3067
  case 9:
2811
3068
  payments = params.payments || [];
2812
- _context30.next = 12;
3069
+ _context31.next = 12;
2813
3070
  return this.effectsEmit(BaseSalesHookNames.onPaymentSyncStart, {
2814
3071
  payments: payments,
2815
3072
  params: syncParams,
@@ -2817,11 +3074,11 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2817
3074
  orderSnapshot: this.store.order.getOrderSnapshot()
2818
3075
  });
2819
3076
  case 12:
2820
- _context30.prev = 12;
2821
- _context30.next = 15;
3077
+ _context31.prev = 12;
3078
+ _context31.next = 15;
2822
3079
  return this.store.order.syncPaymentsToOrder(syncParams);
2823
3080
  case 15:
2824
- syncResult = _context30.sent;
3081
+ syncResult = _context31.sent;
2825
3082
  latestPayments = this.store.order.getOrderPayments();
2826
3083
  amountSnapshot = this.store.order.getOrderAmountSnapshot();
2827
3084
  orderSnapshot = this.store.order.getOrderSnapshot();
@@ -2839,25 +3096,25 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2839
3096
  depositAmount: syncResult.depositAmount,
2840
3097
  orderExpectedAmount: syncResult.orderExpectedAmount
2841
3098
  };
2842
- _context30.next = 22;
3099
+ _context31.next = 22;
2843
3100
  return this.effectsEmit(BaseSalesHookNames.onPaymentSyncEnd, syncPayload);
2844
3101
  case 22:
2845
3102
  if (!(syncResult.isDepositFullyPaid && !syncResult.isOrderFullyPaid)) {
2846
- _context30.next = 25;
3103
+ _context31.next = 25;
2847
3104
  break;
2848
3105
  }
2849
- _context30.next = 25;
3106
+ _context31.next = 25;
2850
3107
  return this.effectsEmit(BaseSalesHookNames.onDepositPaymentSyncEnd, syncPayload);
2851
3108
  case 25:
2852
3109
  this.scheduleQueuedAutoPaymentSyncFlush(0);
2853
- return _context30.abrupt("return", syncResult);
3110
+ return _context31.abrupt("return", syncResult);
2854
3111
  case 29:
2855
- _context30.prev = 29;
2856
- _context30.t0 = _context30["catch"](12);
2857
- _context30.next = 33;
3112
+ _context31.prev = 29;
3113
+ _context31.t0 = _context31["catch"](12);
3114
+ _context31.next = 33;
2858
3115
  return this.effectsEmit(BaseSalesHookNames.onPaymentSyncEnd, {
2859
3116
  ok: false,
2860
- error: _context30.t0,
3117
+ error: _context31.t0,
2861
3118
  payments: this.store.order.getOrderPayments(),
2862
3119
  params: syncParams,
2863
3120
  amountSnapshot: this.store.order.getOrderAmountSnapshot(),
@@ -2865,14 +3122,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2865
3122
  });
2866
3123
  case 33:
2867
3124
  this.scheduleQueuedAutoPaymentSyncFlush(0);
2868
- throw _context30.t0;
3125
+ throw _context31.t0;
2869
3126
  case 35:
2870
3127
  case "end":
2871
- return _context30.stop();
3128
+ return _context31.stop();
2872
3129
  }
2873
- }, _callee30, this, [[12, 29]]);
3130
+ }, _callee31, this, [[12, 29]]);
2874
3131
  }));
2875
- function syncPaymentsToOrder(_x24) {
3132
+ function syncPaymentsToOrder(_x26) {
2876
3133
  return _syncPaymentsToOrder.apply(this, arguments);
2877
3134
  }
2878
3135
  return syncPaymentsToOrder;
@@ -2909,58 +3166,58 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2909
3166
  }, {
2910
3167
  key: "scheduleQueuedAutoPaymentSyncFlush",
2911
3168
  value: function scheduleQueuedAutoPaymentSyncFlush() {
2912
- var _this11 = this;
3169
+ var _this13 = this;
2913
3170
  var delay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 100;
2914
3171
  if (!this.queuedAutoPaymentSync) return;
2915
3172
  if (this.autoPaymentSyncTimer) return;
2916
3173
  this.autoPaymentSyncTimer = setTimeout(function () {
2917
- _this11.autoPaymentSyncTimer = null;
2918
- void _this11.flushQueuedAutoPaymentSync();
3174
+ _this13.autoPaymentSyncTimer = null;
3175
+ void _this13.flushQueuedAutoPaymentSync();
2919
3176
  }, delay);
2920
3177
  }
2921
3178
  }, {
2922
3179
  key: "flushQueuedAutoPaymentSync",
2923
3180
  value: function () {
2924
- var _flushQueuedAutoPaymentSync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31() {
3181
+ var _flushQueuedAutoPaymentSync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32() {
2925
3182
  var payments;
2926
- return _regeneratorRuntime().wrap(function _callee31$(_context31) {
2927
- while (1) switch (_context31.prev = _context31.next) {
3183
+ return _regeneratorRuntime().wrap(function _callee32$(_context32) {
3184
+ while (1) switch (_context32.prev = _context32.next) {
2928
3185
  case 0:
2929
3186
  if (this.store.order) {
2930
- _context31.next = 2;
3187
+ _context32.next = 2;
2931
3188
  break;
2932
3189
  }
2933
- return _context31.abrupt("return");
3190
+ return _context32.abrupt("return");
2934
3191
  case 2:
2935
3192
  if (!(!this.queuedAutoPaymentSync || this.autoPaymentSyncFlushing)) {
2936
- _context31.next = 4;
3193
+ _context32.next = 4;
2937
3194
  break;
2938
3195
  }
2939
- return _context31.abrupt("return");
3196
+ return _context32.abrupt("return");
2940
3197
  case 4:
2941
3198
  if (!(this.store.order.getOrderSyncState() === 'submitting')) {
2942
- _context31.next = 7;
3199
+ _context32.next = 7;
2943
3200
  break;
2944
3201
  }
2945
3202
  this.scheduleQueuedAutoPaymentSyncFlush();
2946
- return _context31.abrupt("return");
3203
+ return _context32.abrupt("return");
2947
3204
  case 7:
2948
3205
  this.autoPaymentSyncFlushing = true;
2949
- _context31.prev = 8;
3206
+ _context32.prev = 8;
2950
3207
  case 9:
2951
3208
  if (!this.queuedAutoPaymentSync) {
2952
- _context31.next = 18;
3209
+ _context32.next = 18;
2953
3210
  break;
2954
3211
  }
2955
3212
  this.queuedAutoPaymentSync = false;
2956
3213
  payments = this.store.order.getOrderPayments();
2957
3214
  if (payments.length) {
2958
- _context31.next = 14;
3215
+ _context32.next = 14;
2959
3216
  break;
2960
3217
  }
2961
- return _context31.abrupt("continue", 9);
3218
+ return _context32.abrupt("continue", 9);
2962
3219
  case 14:
2963
- _context31.next = 16;
3220
+ _context32.next = 16;
2964
3221
  return this.syncPaymentsToOrder({
2965
3222
  payments: payments,
2966
3223
  paymentStatus: this.getPaymentStatusForSync(payments),
@@ -2968,44 +3225,94 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2968
3225
  smallTicketDataFlag: 1
2969
3226
  });
2970
3227
  case 16:
2971
- _context31.next = 9;
3228
+ _context32.next = 9;
2972
3229
  break;
2973
3230
  case 18:
2974
- _context31.next = 23;
3231
+ _context32.next = 23;
2975
3232
  break;
2976
3233
  case 20:
2977
- _context31.prev = 20;
2978
- _context31.t0 = _context31["catch"](8);
3234
+ _context32.prev = 20;
3235
+ _context32.t0 = _context32["catch"](8);
2979
3236
  this.logError('queued auto sync payments failed', {
2980
- error: _context31.t0 instanceof Error ? _context31.t0.message : String(_context31.t0)
3237
+ error: _context32.t0 instanceof Error ? _context32.t0.message : String(_context32.t0)
2981
3238
  });
2982
3239
  case 23:
2983
- _context31.prev = 23;
3240
+ _context32.prev = 23;
2984
3241
  this.autoPaymentSyncFlushing = false;
2985
3242
  if (this.queuedAutoPaymentSync) {
2986
3243
  this.scheduleQueuedAutoPaymentSyncFlush(0);
2987
3244
  }
2988
- return _context31.finish(23);
3245
+ return _context32.finish(23);
2989
3246
  case 27:
2990
3247
  case "end":
2991
- return _context31.stop();
3248
+ return _context32.stop();
2992
3249
  }
2993
- }, _callee31, this, [[8, 20, 23, 27]]);
3250
+ }, _callee32, this, [[8, 20, 23, 27]]);
2994
3251
  }));
2995
3252
  function flushQueuedAutoPaymentSync() {
2996
3253
  return _flushQueuedAutoPaymentSync.apply(this, arguments);
2997
3254
  }
2998
3255
  return flushQueuedAutoPaymentSync;
2999
- }() /** 追加单个支付项到当前订单。 */
3256
+ }()
3257
+ /**
3258
+ * 同步兼容入口。无法等待 IoT 短号时,按调用当下的 device_id 或 LOCAL 生成。
3259
+ */
3000
3260
  }, {
3001
3261
  key: "addOrderPayment",
3002
3262
  value: function addOrderPayment(payment) {
3003
- var _this$otherParams21,
3263
+ var hasPaymentNumber = String(payment.payment_number || '').trim() !== '';
3264
+ return this.addOrderPaymentWithDevicePrefix(payment, hasPaymentNumber ? 'LOCAL' : this.getPaymentNumberDevicePrefixSync());
3265
+ }
3266
+
3267
+ /**
3268
+ * 创建新支付项时优先使用业务解决方案初始化阶段缓存的设备短号;
3269
+ * 未缓存的通用 BaseSales 保持实时读取设备信息的兼容语义。
3270
+ */
3271
+ }, {
3272
+ key: "addOrderPaymentAsync",
3273
+ value: (function () {
3274
+ var _addOrderPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(payment) {
3275
+ var paymentRecord, hasPaymentNumber, devicePrefix;
3276
+ return _regeneratorRuntime().wrap(function _callee33$(_context33) {
3277
+ while (1) switch (_context33.prev = _context33.next) {
3278
+ case 0:
3279
+ paymentRecord = payment;
3280
+ hasPaymentNumber = String(paymentRecord.payment_number || '').trim() !== '';
3281
+ if (!hasPaymentNumber) {
3282
+ _context33.next = 6;
3283
+ break;
3284
+ }
3285
+ _context33.t0 = 'LOCAL';
3286
+ _context33.next = 9;
3287
+ break;
3288
+ case 6:
3289
+ _context33.next = 8;
3290
+ return this.getPaymentNumberDevicePrefixAsync();
3291
+ case 8:
3292
+ _context33.t0 = _context33.sent;
3293
+ case 9:
3294
+ devicePrefix = _context33.t0;
3295
+ return _context33.abrupt("return", this.addOrderPaymentWithDevicePrefix(payment, devicePrefix));
3296
+ case 11:
3297
+ case "end":
3298
+ return _context33.stop();
3299
+ }
3300
+ }, _callee33, this);
3301
+ }));
3302
+ function addOrderPaymentAsync(_x27) {
3303
+ return _addOrderPaymentAsync.apply(this, arguments);
3304
+ }
3305
+ return addOrderPaymentAsync;
3306
+ }())
3307
+ }, {
3308
+ key: "addOrderPaymentWithDevicePrefix",
3309
+ value: function addOrderPaymentWithDevicePrefix(payment, devicePrefix) {
3310
+ var _this$otherParams25,
3004
3311
  _paymentRecord$paymen,
3005
3312
  _paymentRecord$create,
3006
- _ref23,
3313
+ _ref30,
3007
3314
  _paymentRecord$origin,
3008
- _this12 = this;
3315
+ _this14 = this;
3009
3316
  if (!this.store.order) throw new Error('order 模块未初始化');
3010
3317
  var paymentRecord = payment;
3011
3318
  var paymentAmount = new Decimal(paymentRecord.amount || 0);
@@ -3016,25 +3323,26 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3016
3323
  return this.store.order.getOrderPayments();
3017
3324
  }
3018
3325
  var metadata = paymentRecord.metadata && _typeof(paymentRecord.metadata) === 'object' ? _objectSpread({}, paymentRecord.metadata) : {};
3019
- var shopWalletPassId = (_this$otherParams21 = this.otherParams) === null || _this$otherParams21 === void 0 ? void 0 : _this$otherParams21.shop_wallet_pass_id;
3326
+ var shopWalletPassId = (_this$otherParams25 = this.otherParams) === null || _this$otherParams25 === void 0 ? void 0 : _this$otherParams25.shop_wallet_pass_id;
3020
3327
  if (shopWalletPassId !== undefined && shopWalletPassId !== null) {
3021
3328
  metadata.shop_wallet_pass_id = shopWalletPassId;
3022
3329
  }
3023
- if (!metadata.unique_payment_number) {
3024
- metadata.unique_payment_number = createUuidV4();
3025
- }
3330
+ var normalizedPaymentRecord = ensureOrderPaymentNumber(paymentRecord, devicePrefix, createUuidV4);
3026
3331
  var paymentTimestamp = dayjs().format('YYYY-MM-DD HH:mm:ss');
3027
3332
  var paymentTime = (_paymentRecord$paymen = paymentRecord.payment_time) !== null && _paymentRecord$paymen !== void 0 ? _paymentRecord$paymen : paymentTimestamp;
3028
3333
  var createdAt = (_paymentRecord$create = paymentRecord.created_at) !== null && _paymentRecord$create !== void 0 ? _paymentRecord$create : paymentTimestamp;
3029
3334
  var serviceCharge = paymentRecord.service_charge && _typeof(paymentRecord.service_charge) === 'object' ? paymentRecord.service_charge : null;
3030
- var calculatedServiceFee = serviceCharge ? new Decimal((_ref23 = (_paymentRecord$origin = paymentRecord.origin_amount) !== null && _paymentRecord$origin !== void 0 ? _paymentRecord$origin : paymentRecord.amount) !== null && _ref23 !== void 0 ? _ref23 : 0).times(serviceCharge.percentage || 0).plus(serviceCharge.amount || 0).toDecimalPlaces(2).toFixed(2) : undefined;
3031
- var payments = this.store.order.addOrderPayment(_objectSpread(_objectSpread(_objectSpread({}, paymentRecord), calculatedServiceFee !== undefined ? {
3335
+ var calculatedServiceFee = serviceCharge ? new Decimal((_ref30 = (_paymentRecord$origin = paymentRecord.origin_amount) !== null && _paymentRecord$origin !== void 0 ? _paymentRecord$origin : paymentRecord.amount) !== null && _ref30 !== void 0 ? _ref30 : 0).times(serviceCharge.percentage || 0).plus(serviceCharge.amount || 0).toDecimalPlaces(2).toFixed(2) : undefined;
3336
+ var payments = this.store.order.addOrderPayment(_objectSpread(_objectSpread(_objectSpread({}, normalizedPaymentRecord), calculatedServiceFee !== undefined ? {
3032
3337
  service_fee: calculatedServiceFee
3033
3338
  } : {}), {}, {
3034
3339
  metadata: metadata,
3035
3340
  payment_time: paymentTime,
3036
3341
  created_at: createdAt
3037
3342
  }));
3343
+ if (paymentRecord.status === 'payment_pending') {
3344
+ return payments;
3345
+ }
3038
3346
  var amountSnapshot = this.store.order.getOrderAmountSnapshot();
3039
3347
  var syncState = this.store.order.getOrderSyncState();
3040
3348
  if (amountSnapshot) {
@@ -3048,7 +3356,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3048
3356
  submitWhenPaid: true,
3049
3357
  smallTicketDataFlag: 1
3050
3358
  }).catch(function (error) {
3051
- _this12.logError('auto sync payments failed', {
3359
+ _this14.logError('auto sync payments failed', {
3052
3360
  error: error instanceof Error ? error.message : String(error)
3053
3361
  });
3054
3362
  });
@@ -3059,12 +3367,131 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3059
3367
  /** 更新当前订单中的指定支付项。 */
3060
3368
  }, {
3061
3369
  key: "updateOrderPayment",
3062
- value: function updateOrderPayment(paymentIdentity, updates) {
3063
- if (!this.store.order) throw new Error('order 模块未初始化');
3064
- return this.store.order.updateOrderPayment(paymentIdentity, updates);
3065
- }
3066
-
3067
- /** 删除当前订单中的指定支付项。 */
3370
+ value: (function () {
3371
+ var _updateOrderPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(paymentIdentity, updates) {
3372
+ var _result$payment, _result$payment2;
3373
+ var options,
3374
+ matchMode,
3375
+ previousMatch,
3376
+ previousPayment,
3377
+ _this$store$order$get2,
3378
+ currentPayments,
3379
+ _syncResult,
3380
+ _options$smallTicketD,
3381
+ result,
3382
+ draftResult,
3383
+ draftError,
3384
+ becamePaid,
3385
+ shouldSubmit,
3386
+ syncResult,
3387
+ _options$smallTicketD2,
3388
+ _args34 = arguments;
3389
+ return _regeneratorRuntime().wrap(function _callee34$(_context34) {
3390
+ while (1) switch (_context34.prev = _context34.next) {
3391
+ case 0:
3392
+ options = _args34.length > 2 && _args34[2] !== undefined ? _args34[2] : {};
3393
+ if (this.store.order) {
3394
+ _context34.next = 3;
3395
+ break;
3396
+ }
3397
+ throw new Error('order 模块未初始化');
3398
+ case 3:
3399
+ matchMode = options.matchBy === 'compat' || options.matchBy === 'legacy' ? 'compat' : 'payment_number';
3400
+ previousMatch = resolveOrderPaymentIdentity(this.store.order.getOrderPayments(), paymentIdentity, matchMode);
3401
+ previousPayment = previousMatch === null || previousMatch === void 0 ? void 0 : previousMatch.payment;
3402
+ if (!((previousPayment === null || previousPayment === void 0 ? void 0 : previousPayment.status) === 'paid' && !options.applyUpdatesWhenPaid)) {
3403
+ _context34.next = 13;
3404
+ break;
3405
+ }
3406
+ currentPayments = this.store.order.getOrderPayments();
3407
+ if (!(options.submitWhenPaid && options.forceSubmitIfPaid)) {
3408
+ _context34.next = 12;
3409
+ break;
3410
+ }
3411
+ _context34.next = 11;
3412
+ return this.syncPaymentsToOrder({
3413
+ payments: currentPayments,
3414
+ paymentStatus: this.getPaymentStatusForSync(currentPayments),
3415
+ submitWhenPaid: true,
3416
+ smallTicketDataFlag: (_options$smallTicketD = options.smallTicketDataFlag) !== null && _options$smallTicketD !== void 0 ? _options$smallTicketD : 1
3417
+ });
3418
+ case 11:
3419
+ _syncResult = _context34.sent;
3420
+ case 12:
3421
+ return _context34.abrupt("return", _objectSpread({
3422
+ updated: false,
3423
+ payment: previousPayment,
3424
+ payments: currentPayments,
3425
+ summary: ((_this$store$order$get2 = this.store.order.getOrderAmountSnapshot()) === null || _this$store$order$get2 === void 0 ? void 0 : _this$store$order$get2.summary) || null
3426
+ }, _syncResult !== undefined ? {
3427
+ syncResult: _syncResult
3428
+ } : {}));
3429
+ case 13:
3430
+ _context34.next = 15;
3431
+ return this.store.order.updateOrderPayment(paymentIdentity, updates, {
3432
+ matchBy: matchMode
3433
+ });
3434
+ case 15:
3435
+ result = _context34.sent;
3436
+ if (!(options.persistDraft !== false)) {
3437
+ _context34.next = 29;
3438
+ break;
3439
+ }
3440
+ _context34.prev = 17;
3441
+ _context34.next = 20;
3442
+ return this.saveSalesOrderDraft();
3443
+ case 20:
3444
+ draftResult = _context34.sent;
3445
+ _context34.next = 29;
3446
+ break;
3447
+ case 23:
3448
+ _context34.prev = 23;
3449
+ _context34.t0 = _context34["catch"](17);
3450
+ draftError = _context34.t0;
3451
+ this.logError('updateOrderPayment: 保存支付草稿失败', {
3452
+ paymentIdentity: paymentIdentity,
3453
+ error: _context34.t0 instanceof Error ? _context34.t0.message : String(_context34.t0)
3454
+ });
3455
+ if (options.submitWhenPaid) {
3456
+ _context34.next = 29;
3457
+ break;
3458
+ }
3459
+ throw _context34.t0;
3460
+ case 29:
3461
+ becamePaid = (previousPayment === null || previousPayment === void 0 ? void 0 : previousPayment.status) !== 'paid' && ((_result$payment = result.payment) === null || _result$payment === void 0 ? void 0 : _result$payment.status) === 'paid';
3462
+ shouldSubmit = Boolean(options.submitWhenPaid && ((_result$payment2 = result.payment) === null || _result$payment2 === void 0 ? void 0 : _result$payment2.status) === 'paid' && (becamePaid || options.forceSubmitIfPaid));
3463
+ if (!shouldSubmit) {
3464
+ _context34.next = 35;
3465
+ break;
3466
+ }
3467
+ _context34.next = 34;
3468
+ return this.syncPaymentsToOrder({
3469
+ payments: result.payments,
3470
+ paymentStatus: this.getPaymentStatusForSync(result.payments),
3471
+ submitWhenPaid: true,
3472
+ smallTicketDataFlag: (_options$smallTicketD2 = options.smallTicketDataFlag) !== null && _options$smallTicketD2 !== void 0 ? _options$smallTicketD2 : 1
3473
+ });
3474
+ case 34:
3475
+ syncResult = _context34.sent;
3476
+ case 35:
3477
+ return _context34.abrupt("return", _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, result), draftResult !== undefined ? {
3478
+ draftResult: draftResult
3479
+ } : {}), draftError !== undefined ? {
3480
+ draftError: draftError
3481
+ } : {}), syncResult !== undefined ? {
3482
+ syncResult: syncResult
3483
+ } : {}));
3484
+ case 36:
3485
+ case "end":
3486
+ return _context34.stop();
3487
+ }
3488
+ }, _callee34, this, [[17, 23]]);
3489
+ }));
3490
+ function updateOrderPayment(_x28, _x29) {
3491
+ return _updateOrderPayment.apply(this, arguments);
3492
+ }
3493
+ return updateOrderPayment;
3494
+ }() /** 删除当前订单中的指定支付项。 */)
3068
3495
  }, {
3069
3496
  key: "deleteOrderPayment",
3070
3497
  value: function deleteOrderPayment(paymentIdentity) {
@@ -3079,11 +3506,42 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3079
3506
  if (!this.store.order) throw new Error('order 模块未初始化');
3080
3507
  return this.store.order.updateVoucherOrderPayments(payments, options);
3081
3508
  }
3509
+ }, {
3510
+ key: "updateVoucherOrderPaymentsAsync",
3511
+ value: function () {
3512
+ var _updateVoucherOrderPaymentsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(payments, options) {
3513
+ return _regeneratorRuntime().wrap(function _callee35$(_context35) {
3514
+ while (1) switch (_context35.prev = _context35.next) {
3515
+ case 0:
3516
+ if (this.store.order) {
3517
+ _context35.next = 2;
3518
+ break;
3519
+ }
3520
+ throw new Error('order 模块未初始化');
3521
+ case 2:
3522
+ return _context35.abrupt("return", this.store.order.updateVoucherOrderPaymentsAsync(payments, options));
3523
+ case 3:
3524
+ case "end":
3525
+ return _context35.stop();
3526
+ }
3527
+ }, _callee35, this);
3528
+ }));
3529
+ function updateVoucherOrderPaymentsAsync(_x30, _x31) {
3530
+ return _updateVoucherOrderPaymentsAsync.apply(this, arguments);
3531
+ }
3532
+ return updateVoucherOrderPaymentsAsync;
3533
+ }()
3082
3534
  }, {
3083
3535
  key: "confirmPendingVoucherPayments",
3084
3536
  value: function confirmPendingVoucherPayments() {
3085
3537
  if (!this.store.order) throw new Error('order 模块未初始化');
3086
- return this.store.order.confirmPendingVoucherPayments();
3538
+ var payments = this.store.order.confirmPendingVoucherPayments();
3539
+ if (this.store.payment) {
3540
+ var committed = this.getCommittedWalletAssets();
3541
+ var state = this.store.payment.wallet.setCommittedWalletAssets(committed.ids, committed.assets);
3542
+ void this.publishWalletAssetsState(state);
3543
+ }
3544
+ return payments;
3087
3545
  }
3088
3546
  }, {
3089
3547
  key: "discardPendingVoucherPayments",
@@ -3152,64 +3610,72 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3152
3610
  });
3153
3611
  return walletProducts;
3154
3612
  }
3613
+ }, {
3614
+ key: "buildWalletInitBusinessData",
3615
+ value: function buildWalletInitBusinessData(params) {
3616
+ var _this$store$order8, _params$order_wait_pa, _ref31, _tempOrder$is_price_i;
3617
+ var snapshot = (_this$store$order8 = this.store.order) === null || _this$store$order8 === void 0 ? void 0 : _this$store$order8.getOrderSnapshot();
3618
+ var tempOrder = snapshot === null || snapshot === void 0 ? void 0 : snapshot.tempOrder;
3619
+ var amount = snapshot === null || snapshot === void 0 ? void 0 : snapshot.amount;
3620
+ if (!tempOrder || !amount) return null;
3621
+ return _objectSpread({
3622
+ customer_id: tempOrder.customer_id ? Number(tempOrder.customer_id) : undefined,
3623
+ holder: tempOrder.holder,
3624
+ amountInfo: {
3625
+ totalAmount: amount.totalAmount,
3626
+ subTotal: amount.summary.product_amount || amount.summary.product_expect_amount || amount.totalAmount,
3627
+ depositAmount: amount.depositAmount,
3628
+ isDeposit: tempOrder.is_deposit
3629
+ },
3630
+ products: this.getWalletProductList(),
3631
+ order_wait_pay_amount: (_params$order_wait_pa = params === null || params === void 0 ? void 0 : params.order_wait_pay_amount) !== null && _params$order_wait_pa !== void 0 ? _params$order_wait_pa : Number(amount.amountGap || 0),
3632
+ is_price_include_tax: (_ref31 = (_tempOrder$is_price_i = tempOrder.is_price_include_tax) !== null && _tempOrder$is_price_i !== void 0 ? _tempOrder$is_price_i : this.otherParams.is_price_include_tax) !== null && _ref31 !== void 0 ? _ref31 : 1
3633
+ }, snapshot.identity.orderId ? {
3634
+ payment_order_id: String(snapshot.identity.orderId)
3635
+ } : {});
3636
+ }
3155
3637
  }, {
3156
3638
  key: "initWalletData",
3157
3639
  value: function () {
3158
- var _initWalletData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(params) {
3159
- var _params$order_wait_pa, _ref24, _tempOrder$is_price_i;
3160
- var snapshot, tempOrder, amount, walletBusinessData, result;
3161
- return _regeneratorRuntime().wrap(function _callee32$(_context32) {
3162
- while (1) switch (_context32.prev = _context32.next) {
3640
+ var _initWalletData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(params) {
3641
+ var _snapshot$identity;
3642
+ var snapshot, walletBusinessData, result;
3643
+ return _regeneratorRuntime().wrap(function _callee36$(_context36) {
3644
+ while (1) switch (_context36.prev = _context36.next) {
3163
3645
  case 0:
3164
3646
  if (this.store.order) {
3165
- _context32.next = 2;
3647
+ _context36.next = 2;
3166
3648
  break;
3167
3649
  }
3168
3650
  throw new Error('order 模块未初始化');
3169
3651
  case 2:
3170
3652
  if (this.store.payment) {
3171
- _context32.next = 4;
3653
+ _context36.next = 4;
3172
3654
  break;
3173
3655
  }
3174
3656
  throw new Error('payment 模块未初始化');
3175
3657
  case 4:
3176
3658
  snapshot = this.store.order.getOrderSnapshot();
3177
- tempOrder = snapshot === null || snapshot === void 0 ? void 0 : snapshot.tempOrder;
3178
- amount = snapshot === null || snapshot === void 0 ? void 0 : snapshot.amount;
3179
- if (!(!tempOrder || !amount)) {
3180
- _context32.next = 9;
3659
+ walletBusinessData = this.buildWalletInitBusinessData(params);
3660
+ if (walletBusinessData) {
3661
+ _context36.next = 8;
3181
3662
  break;
3182
3663
  }
3183
- return _context32.abrupt("return", {
3664
+ return _context36.abrupt("return", {
3184
3665
  walletRecommendList: [],
3185
3666
  userIdentificationCodes: [],
3186
3667
  transformList: [],
3187
3668
  noApplicableVoucher: [],
3188
3669
  products: []
3189
3670
  });
3190
- case 9:
3191
- walletBusinessData = _objectSpread({
3192
- customer_id: tempOrder.customer_id ? Number(tempOrder.customer_id) : undefined,
3193
- holder: tempOrder.holder,
3194
- amountInfo: {
3195
- totalAmount: amount.totalAmount,
3196
- subTotal: amount.summary.product_amount || amount.summary.product_expect_amount || amount.totalAmount,
3197
- depositAmount: amount.depositAmount,
3198
- isDeposit: tempOrder.is_deposit
3199
- },
3200
- products: this.getWalletProductList(),
3201
- order_wait_pay_amount: (_params$order_wait_pa = params === null || params === void 0 ? void 0 : params.order_wait_pay_amount) !== null && _params$order_wait_pa !== void 0 ? _params$order_wait_pa : Number(amount.amountGap || 0),
3202
- is_price_include_tax: (_ref24 = (_tempOrder$is_price_i = tempOrder.is_price_include_tax) !== null && _tempOrder$is_price_i !== void 0 ? _tempOrder$is_price_i : this.otherParams.is_price_include_tax) !== null && _ref24 !== void 0 ? _ref24 : 1
3203
- }, snapshot.identity.orderId ? {
3204
- payment_order_id: String(snapshot.identity.orderId)
3205
- } : {});
3206
- _context32.next = 12;
3671
+ case 8:
3672
+ _context36.next = 10;
3207
3673
  return this.store.payment.wallet.initializeWalletDataFromBusinessAsync(walletBusinessData);
3208
- case 12:
3209
- result = _context32.sent;
3210
- _context32.next = 15;
3674
+ case 10:
3675
+ result = _context36.sent;
3676
+ _context36.next = 13;
3211
3677
  return this.core.effects.emit("".concat(this.name, ":onWalletDataInitialized"), {
3212
- orderId: snapshot.identity.orderId,
3678
+ orderId: snapshot === null || snapshot === void 0 || (_snapshot$identity = snapshot.identity) === null || _snapshot$identity === void 0 ? void 0 : _snapshot$identity.orderId,
3213
3679
  customerId: walletBusinessData.customer_id,
3214
3680
  walletBusinessData: {
3215
3681
  customer_id: walletBusinessData.customer_id,
@@ -3218,25 +3684,421 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3218
3684
  },
3219
3685
  timestamp: Date.now()
3220
3686
  });
3221
- case 15:
3222
- return _context32.abrupt("return", result);
3223
- case 16:
3687
+ case 13:
3688
+ return _context36.abrupt("return", result);
3689
+ case 14:
3224
3690
  case "end":
3225
- return _context32.stop();
3691
+ return _context36.stop();
3226
3692
  }
3227
- }, _callee32, this);
3693
+ }, _callee36, this);
3228
3694
  }));
3229
- function initWalletData(_x25) {
3695
+ function initWalletData(_x32) {
3230
3696
  return _initWalletData.apply(this, arguments);
3231
3697
  }
3232
3698
  return initWalletData;
3233
3699
  }()
3700
+ }, {
3701
+ key: "getCommittedWalletAssets",
3702
+ value: function getCommittedWalletAssets() {
3703
+ var _this$store$order9, _this$store$order9$ge;
3704
+ var payments = ((_this$store$order9 = this.store.order) === null || _this$store$order9 === void 0 || (_this$store$order9$ge = _this$store$order9.getOrderPayments) === null || _this$store$order9$ge === void 0 ? void 0 : _this$store$order9$ge.call(_this$store$order9)) || [];
3705
+ var committed = payments.filter(function (payment) {
3706
+ var voucherId = payment === null || payment === void 0 ? void 0 : payment.voucher_id;
3707
+ if (voucherId === undefined || voucherId === null || voucherId === 0) {
3708
+ return false;
3709
+ }
3710
+ return (payment === null || payment === void 0 ? void 0 : payment.status) === 'paid' || (payment === null || payment === void 0 ? void 0 : payment.isSynced) === true || (payment === null || payment === void 0 ? void 0 : payment.order_payment_id) !== undefined && (payment === null || payment === void 0 ? void 0 : payment.order_payment_id) !== null && (payment === null || payment === void 0 ? void 0 : payment.order_payment_id) !== '';
3711
+ });
3712
+ return {
3713
+ ids: committed.map(function (payment) {
3714
+ return payment.voucher_id;
3715
+ }),
3716
+ assets: committed.map(function (payment) {
3717
+ var _Object$entries$find;
3718
+ var fundRecord = (payment === null || payment === void 0 ? void 0 : payment.fund_record) || {};
3719
+ var walletPassName = fundRecord.wallet_pass_name;
3720
+ var title = walletPassName && _typeof(walletPassName) === 'object' ? walletPassName.default || Object.values(walletPassName)[0] : walletPassName;
3721
+ var code = String((payment === null || payment === void 0 ? void 0 : payment.code) || '').toUpperCase();
3722
+ var tag = ((_Object$entries$find = Object.entries(WALLET_PAYMENT_CODE_BY_TAG).find(function (_ref32) {
3723
+ var _ref33 = _slicedToArray(_ref32, 2),
3724
+ paymentCode = _ref33[1];
3725
+ return paymentCode === code;
3726
+ })) === null || _Object$entries$find === void 0 ? void 0 : _Object$entries$find[0]) || fundRecord.tag;
3727
+ return {
3728
+ id: payment.voucher_id,
3729
+ voucher_id: payment.voucher_id,
3730
+ code: fundRecord.code,
3731
+ tag: tag,
3732
+ product_name: title || payment.name,
3733
+ name: title || payment.name,
3734
+ amount: Number(payment.amount || 0),
3735
+ _available_max_amount: Number(payment.amount || 0),
3736
+ unified_available_status: 1,
3737
+ _unified_available_status: 1,
3738
+ _committed_payment: payment
3739
+ };
3740
+ })
3741
+ };
3742
+ }
3743
+ }, {
3744
+ key: "publishWalletAssetsState",
3745
+ value: function () {
3746
+ var _publishWalletAssetsState = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(state) {
3747
+ return _regeneratorRuntime().wrap(function _callee37$(_context37) {
3748
+ while (1) switch (_context37.prev = _context37.next) {
3749
+ case 0:
3750
+ _context37.next = 2;
3751
+ return this.effectsEmit(BaseSalesHookNames.onWalletAssetsStateChanged, {
3752
+ state: state
3753
+ });
3754
+ case 2:
3755
+ return _context37.abrupt("return", state);
3756
+ case 3:
3757
+ case "end":
3758
+ return _context37.stop();
3759
+ }
3760
+ }, _callee37, this);
3761
+ }));
3762
+ function publishWalletAssetsState(_x33) {
3763
+ return _publishWalletAssetsState.apply(this, arguments);
3764
+ }
3765
+ return publishWalletAssetsState;
3766
+ }()
3767
+ }, {
3768
+ key: "syncSelectedWalletAssets",
3769
+ value: function () {
3770
+ var _syncSelectedWalletAssets = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(state) {
3771
+ var paymentMethods, methodByCode, preparePayments, selectedAssetById, voucherPayments, payments;
3772
+ return _regeneratorRuntime().wrap(function _callee38$(_context38) {
3773
+ while (1) switch (_context38.prev = _context38.next) {
3774
+ case 0:
3775
+ if (!(!this.store.order || !this.store.payment)) {
3776
+ _context38.next = 2;
3777
+ break;
3778
+ }
3779
+ throw new Error('订单或支付模块未初始化');
3780
+ case 2:
3781
+ paymentMethods = this.getPaymentMethods();
3782
+ if (!(!paymentMethods.length && state.selectedItems.length)) {
3783
+ _context38.next = 7;
3784
+ break;
3785
+ }
3786
+ _context38.next = 6;
3787
+ return this.getPaymentMethodsAsync();
3788
+ case 6:
3789
+ paymentMethods = _context38.sent;
3790
+ case 7:
3791
+ methodByCode = new Map(paymentMethods.map(function (method) {
3792
+ return [String(method.code || '').toUpperCase(), method];
3793
+ }));
3794
+ preparePayments = this.store.payment.wallet.formatWalletPassList2PreparePayments(state.selectedItems);
3795
+ selectedAssetById = new Map(state.selectedItems.map(function (asset) {
3796
+ return [String(getSharedWalletAssetId(asset)), asset];
3797
+ }));
3798
+ voucherPayments = preparePayments.flatMap(function (item) {
3799
+ var asset = selectedAssetById.get(String(item.voucher_id));
3800
+ var paymentCode = WALLET_PAYMENT_CODE_BY_TAG[String(item.tag || (asset === null || asset === void 0 ? void 0 : asset.tag) || '')] || String(item.tag || (asset === null || asset === void 0 ? void 0 : asset.tag) || '').toUpperCase();
3801
+ var paymentMethod = methodByCode.get(paymentCode);
3802
+ var formattedAmount = Number(item.amount);
3803
+ var amount = Number.isFinite(formattedAmount) && formattedAmount > 0 ? formattedAmount : getSharedWalletAssetAmount(asset);
3804
+ if (!asset || !paymentMethod || !Number.isFinite(amount) || amount <= 0) {
3805
+ return [];
3806
+ }
3807
+ var walletPassUseValue = getSharedWalletPassUseValue({
3808
+ asset: asset,
3809
+ amount: amount,
3810
+ paymentMethod: paymentMethod
3811
+ });
3812
+ return [{
3813
+ amount: amount.toFixed(2),
3814
+ code: paymentMethod.code,
3815
+ custom_payment_id: paymentMethod.id,
3816
+ name: paymentMethod.name,
3817
+ type: paymentMethod.type,
3818
+ voucher_id: item.voucher_id,
3819
+ wallet_pass_usage_unit: item.wallet_pass_usage_unit,
3820
+ wallet_pass_use_value: walletPassUseValue,
3821
+ fund_record: buildSharedWalletFundRecord({
3822
+ asset: asset,
3823
+ amount: amount,
3824
+ paymentMethod: paymentMethod
3825
+ })
3826
+ }];
3827
+ });
3828
+ payments = this.updateVoucherOrderPayments(voucherPayments, {
3829
+ status: 'payment_pending'
3830
+ });
3831
+ _context38.next = 14;
3832
+ return this.store.order.recalculateSummary({
3833
+ createIfMissing: true
3834
+ });
3835
+ case 14:
3836
+ return _context38.abrupt("return", payments);
3837
+ case 15:
3838
+ case "end":
3839
+ return _context38.stop();
3840
+ }
3841
+ }, _callee38, this);
3842
+ }));
3843
+ function syncSelectedWalletAssets(_x34) {
3844
+ return _syncSelectedWalletAssets.apply(this, arguments);
3845
+ }
3846
+ return syncSelectedWalletAssets;
3847
+ }() /** 读取购物车与 Shared Checkout 共用的钱包资产状态。 */
3848
+ }, {
3849
+ key: "getWalletAssetsState",
3850
+ value: function getWalletAssetsState() {
3851
+ if (!this.store.payment) throw new Error('payment 模块未初始化');
3852
+ return this.store.payment.wallet.getWalletAssetsState();
3853
+ }
3854
+
3855
+ /** 导出 Shared Checkout 跨运行时恢复所需的钱包状态与搜索缓存。 */
3856
+ }, {
3857
+ key: "exportWalletAssetsSnapshot",
3858
+ value: function exportWalletAssetsSnapshot() {
3859
+ if (!this.store.payment) throw new Error('payment 模块未初始化');
3860
+ return this.store.payment.wallet.exportWalletAssetsSnapshot();
3861
+ }
3862
+
3863
+ /** 配置仅影响 Wallet Assets,不改变 Promotion/Voucher 选择流程。 */
3864
+ }, {
3865
+ key: "configureWalletAssetsBehavior",
3866
+ value: function configureWalletAssetsBehavior(options) {
3867
+ if (!this.store.payment) throw new Error('payment 模块未初始化');
3868
+ this.store.payment.wallet.configureWalletAssetsBehavior(options);
3869
+ }
3870
+
3871
+ /**
3872
+ * 恢复 Shared Checkout 钱包快照,并把选择重新同步为订单 pending payment。
3873
+ */
3874
+ }, {
3875
+ key: "importWalletAssetsSnapshot",
3876
+ value: (function () {
3877
+ var _importWalletAssetsSnapshot = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(snapshot) {
3878
+ var state;
3879
+ return _regeneratorRuntime().wrap(function _callee39$(_context39) {
3880
+ while (1) switch (_context39.prev = _context39.next) {
3881
+ case 0:
3882
+ if (this.store.payment) {
3883
+ _context39.next = 2;
3884
+ break;
3885
+ }
3886
+ throw new Error('payment 模块未初始化');
3887
+ case 2:
3888
+ state = this.store.payment.wallet.importWalletAssetsSnapshot(snapshot);
3889
+ _context39.next = 5;
3890
+ return this.syncSelectedWalletAssets(state);
3891
+ case 5:
3892
+ return _context39.abrupt("return", this.publishWalletAssetsState(state));
3893
+ case 6:
3894
+ case "end":
3895
+ return _context39.stop();
3896
+ }
3897
+ }, _callee39, this);
3898
+ }));
3899
+ function importWalletAssetsSnapshot(_x35) {
3900
+ return _importWalletAssetsSnapshot.apply(this, arguments);
3901
+ }
3902
+ return importWalletAssetsSnapshot;
3903
+ }()
3904
+ /**
3905
+ * 基于当前订单快照刷新钱包资产。商品变化保留并重验选择;客户变化强制清空。
3906
+ */
3907
+ )
3908
+ }, {
3909
+ key: "refreshWalletAssets",
3910
+ value: (function () {
3911
+ var _refreshWalletAssets = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(params) {
3912
+ var _previousState$custom, _businessData$custome;
3913
+ var refreshSequence, wallet, businessData, emptyState, previousState, hasPreviousWalletContext, customerChanged, clearedState, refreshTask, state, committed;
3914
+ return _regeneratorRuntime().wrap(function _callee40$(_context40) {
3915
+ while (1) switch (_context40.prev = _context40.next) {
3916
+ case 0:
3917
+ if (this.store.order) {
3918
+ _context40.next = 2;
3919
+ break;
3920
+ }
3921
+ throw new Error('order 模块未初始化');
3922
+ case 2:
3923
+ if (this.store.payment) {
3924
+ _context40.next = 4;
3925
+ break;
3926
+ }
3927
+ throw new Error('payment 模块未初始化');
3928
+ case 4:
3929
+ refreshSequence = ++this.walletAssetsRefreshSequence;
3930
+ wallet = this.store.payment.wallet;
3931
+ businessData = this.buildWalletInitBusinessData(params);
3932
+ if (businessData) {
3933
+ _context40.next = 12;
3934
+ break;
3935
+ }
3936
+ wallet.clearAllCache();
3937
+ emptyState = wallet.getWalletAssetsState();
3938
+ this.updateVoucherOrderPayments([], {
3939
+ status: 'payment_pending'
3940
+ });
3941
+ return _context40.abrupt("return", this.publishWalletAssetsState(emptyState));
3942
+ case 12:
3943
+ previousState = wallet.getWalletAssetsState();
3944
+ hasPreviousWalletContext = previousState.status !== 'idle' || previousState.items.length > 0 || previousState.selectedIds.length > 0 || previousState.customerId !== undefined;
3945
+ customerChanged = hasPreviousWalletContext && String((_previousState$custom = previousState.customerId) !== null && _previousState$custom !== void 0 ? _previousState$custom : '') !== String((_businessData$custome = businessData.customer_id) !== null && _businessData$custome !== void 0 ? _businessData$custome : '');
3946
+ if (!customerChanged) {
3947
+ _context40.next = 20;
3948
+ break;
3949
+ }
3950
+ clearedState = wallet.clearWalletAssetSelection();
3951
+ this.updateVoucherOrderPayments([], {
3952
+ status: 'payment_pending'
3953
+ });
3954
+ _context40.next = 20;
3955
+ return this.publishWalletAssetsState(clearedState);
3956
+ case 20:
3957
+ refreshTask = wallet.refreshWalletAssetsFromBusinessAsync(businessData, {
3958
+ preserveSelection: (params === null || params === void 0 ? void 0 : params.preserveSelection) !== false && !customerChanged
3959
+ });
3960
+ _context40.next = 23;
3961
+ return this.publishWalletAssetsState(wallet.getWalletAssetsState());
3962
+ case 23:
3963
+ _context40.next = 25;
3964
+ return refreshTask;
3965
+ case 25:
3966
+ state = _context40.sent;
3967
+ if (!(refreshSequence !== this.walletAssetsRefreshSequence)) {
3968
+ _context40.next = 28;
3969
+ break;
3970
+ }
3971
+ return _context40.abrupt("return", wallet.getWalletAssetsState());
3972
+ case 28:
3973
+ if (state.status !== 'error') {
3974
+ committed = this.getCommittedWalletAssets();
3975
+ state = wallet.setCommittedWalletAssets(committed.ids, committed.assets);
3976
+ }
3977
+ _context40.next = 31;
3978
+ return this.syncSelectedWalletAssets(state);
3979
+ case 31:
3980
+ return _context40.abrupt("return", this.publishWalletAssetsState(state));
3981
+ case 32:
3982
+ case "end":
3983
+ return _context40.stop();
3984
+ }
3985
+ }, _callee40, this);
3986
+ }));
3987
+ function refreshWalletAssets(_x36) {
3988
+ return _refreshWalletAssets.apply(this, arguments);
3989
+ }
3990
+ return refreshWalletAssets;
3991
+ }() /** 选择或取消单张钱包资产,并立即同步 pending wallet payments。 */)
3992
+ }, {
3993
+ key: "selectWalletAsset",
3994
+ value: (function () {
3995
+ var _selectWalletAsset = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(params) {
3996
+ var state;
3997
+ return _regeneratorRuntime().wrap(function _callee41$(_context41) {
3998
+ while (1) switch (_context41.prev = _context41.next) {
3999
+ case 0:
4000
+ if (this.store.payment) {
4001
+ _context41.next = 2;
4002
+ break;
4003
+ }
4004
+ throw new Error('payment 模块未初始化');
4005
+ case 2:
4006
+ state = this.store.payment.wallet.selectWalletAsset(params.assetId, {
4007
+ selected: params.selected,
4008
+ source: params.source
4009
+ });
4010
+ _context41.next = 5;
4011
+ return this.syncSelectedWalletAssets(state);
4012
+ case 5:
4013
+ return _context41.abrupt("return", this.publishWalletAssetsState(state));
4014
+ case 6:
4015
+ case "end":
4016
+ return _context41.stop();
4017
+ }
4018
+ }, _callee41, this);
4019
+ }));
4020
+ function selectWalletAsset(_x37) {
4021
+ return _selectWalletAsset.apply(this, arguments);
4022
+ }
4023
+ return selectWalletAsset;
4024
+ }() /** 扫码精确查券;仅可用资产会被自动选中。 */)
4025
+ }, {
4026
+ key: "scanWalletAsset",
4027
+ value: (function () {
4028
+ var _scanWalletAsset = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42(code) {
4029
+ var result;
4030
+ return _regeneratorRuntime().wrap(function _callee42$(_context42) {
4031
+ while (1) switch (_context42.prev = _context42.next) {
4032
+ case 0:
4033
+ if (this.store.payment) {
4034
+ _context42.next = 2;
4035
+ break;
4036
+ }
4037
+ throw new Error('payment 模块未初始化');
4038
+ case 2:
4039
+ _context42.next = 4;
4040
+ return this.store.payment.wallet.scanWalletAssetAsync(code);
4041
+ case 4:
4042
+ result = _context42.sent;
4043
+ if (!(result.type === 'normalCode')) {
4044
+ _context42.next = 10;
4045
+ break;
4046
+ }
4047
+ _context42.next = 8;
4048
+ return this.syncSelectedWalletAssets(result.state);
4049
+ case 8:
4050
+ _context42.next = 10;
4051
+ return this.publishWalletAssetsState(result.state);
4052
+ case 10:
4053
+ return _context42.abrupt("return", result);
4054
+ case 11:
4055
+ case "end":
4056
+ return _context42.stop();
4057
+ }
4058
+ }, _callee42, this);
4059
+ }));
4060
+ function scanWalletAsset(_x38) {
4061
+ return _scanWalletAsset.apply(this, arguments);
4062
+ }
4063
+ return scanWalletAsset;
4064
+ }() /** 清空全部未确认钱包选择,已支付钱包项由 Order 模块继续保留。 */)
4065
+ }, {
4066
+ key: "clearWalletAssetSelection",
4067
+ value: (function () {
4068
+ var _clearWalletAssetSelection = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43() {
4069
+ var state;
4070
+ return _regeneratorRuntime().wrap(function _callee43$(_context43) {
4071
+ while (1) switch (_context43.prev = _context43.next) {
4072
+ case 0:
4073
+ if (this.store.payment) {
4074
+ _context43.next = 2;
4075
+ break;
4076
+ }
4077
+ throw new Error('payment 模块未初始化');
4078
+ case 2:
4079
+ state = this.store.payment.wallet.clearWalletAssetSelection();
4080
+ _context43.next = 5;
4081
+ return this.syncSelectedWalletAssets(state);
4082
+ case 5:
4083
+ return _context43.abrupt("return", this.publishWalletAssetsState(state));
4084
+ case 6:
4085
+ case "end":
4086
+ return _context43.stop();
4087
+ }
4088
+ }, _callee43, this);
4089
+ }));
4090
+ function clearWalletAssetSelection() {
4091
+ return _clearWalletAssetSelection.apply(this, arguments);
4092
+ }
4093
+ return clearWalletAssetSelection;
4094
+ }()
3234
4095
  /**
3235
4096
  * 更新当前订单客户字段。
3236
4097
  *
3237
4098
  * 这是 PaymentModal 客户切换的订单事实入口;外部客户模块同步应由
3238
4099
  * 调用方通过 onCustomerChange 回调完成。
3239
4100
  */
4101
+ )
3240
4102
  }, {
3241
4103
  key: "updateOrderCustomer",
3242
4104
  value: function updateOrderCustomer(customer) {
@@ -3253,35 +4115,35 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3253
4115
  }, {
3254
4116
  key: "getPaymentMethodsAsync",
3255
4117
  value: (function () {
3256
- var _getPaymentMethodsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33() {
4118
+ var _getPaymentMethodsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee44() {
3257
4119
  var response, paymentMethods;
3258
- return _regeneratorRuntime().wrap(function _callee33$(_context33) {
3259
- while (1) switch (_context33.prev = _context33.next) {
4120
+ return _regeneratorRuntime().wrap(function _callee44$(_context44) {
4121
+ while (1) switch (_context44.prev = _context44.next) {
3260
4122
  case 0:
3261
- _context33.prev = 0;
3262
- _context33.next = 3;
4123
+ _context44.prev = 0;
4124
+ _context44.next = 3;
3263
4125
  return this.request.get('/pay/custom-payment/all', {
3264
4126
  filterPaymentMethods: true
3265
4127
  }, {
3266
4128
  osServer: true
3267
4129
  });
3268
4130
  case 3:
3269
- response = _context33.sent;
4131
+ response = _context44.sent;
3270
4132
  paymentMethods = (response === null || response === void 0 ? void 0 : response.data) || [];
3271
4133
  this.paymentMethodsCache = Array.isArray(paymentMethods) ? _toConsumableArray(paymentMethods) : [];
3272
- return _context33.abrupt("return", this.getPaymentMethods());
4134
+ return _context44.abrupt("return", this.getPaymentMethods());
3273
4135
  case 9:
3274
- _context33.prev = 9;
3275
- _context33.t0 = _context33["catch"](0);
4136
+ _context44.prev = 9;
4137
+ _context44.t0 = _context44["catch"](0);
3276
4138
  this.logWarning('getPaymentMethodsAsync: 获取支付方式列表失败,使用缓存列表', {
3277
- error: _context33.t0 instanceof Error ? _context33.t0.message : String(_context33.t0)
4139
+ error: _context44.t0 instanceof Error ? _context44.t0.message : String(_context44.t0)
3278
4140
  });
3279
- return _context33.abrupt("return", this.getPaymentMethods());
4141
+ return _context44.abrupt("return", this.getPaymentMethods());
3280
4142
  case 13:
3281
4143
  case "end":
3282
- return _context33.stop();
4144
+ return _context44.stop();
3283
4145
  }
3284
- }, _callee33, this, [[0, 9]]);
4146
+ }, _callee44, this, [[0, 9]]);
3285
4147
  }));
3286
4148
  function getPaymentMethodsAsync() {
3287
4149
  return _getPaymentMethodsAsync.apply(this, arguments);
@@ -3293,85 +4155,593 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3293
4155
  value: function getPaymentMethods() {
3294
4156
  return _toConsumableArray(this.paymentMethodsCache);
3295
4157
  }
3296
-
3297
- /** 轻量舍入能力,供现金支付 UI 计算 rounding_amount。 */
3298
4158
  }, {
3299
- key: "roundAmount",
3300
- value: function roundAmount(params) {
3301
- var amount = new Decimal(params.amount || 0);
3302
- var interval = new Decimal(params.interval || 0.05);
3303
- var rule = params.rule || 'standard_rounding';
3304
- var quotient = amount.div(interval);
3305
- var roundedQuotient;
3306
- if (rule === 'always_up') {
3307
- roundedQuotient = quotient.ceil();
3308
- } else if (rule === 'always_down') {
3309
- roundedQuotient = quotient.floor();
3310
- } else if (rule === 'standard_down') {
3311
- roundedQuotient = quotient.toDecimalPlaces(0, Decimal.ROUND_HALF_DOWN);
3312
- } else {
3313
- roundedQuotient = quotient.toDecimalPlaces(0, Decimal.ROUND_HALF_UP);
3314
- }
3315
- var roundedAmount = roundedQuotient.times(interval).toDecimalPlaces(2);
3316
- return {
3317
- originalAmount: amount.toFixed(2),
3318
- roundedAmount: roundedAmount.toFixed(2),
3319
- roundingDifference: roundedAmount.minus(amount).toFixed(2)
3320
- };
4159
+ key: "findCashPaymentMethod",
4160
+ value: function findCashPaymentMethod(paymentMethods) {
4161
+ return paymentMethods.find(function (method) {
4162
+ var identifiers = [method === null || method === void 0 ? void 0 : method.code, method === null || method === void 0 ? void 0 : method.type, method === null || method === void 0 ? void 0 : method.tag].map(function (value) {
4163
+ return String(value || '').toUpperCase();
4164
+ });
4165
+ return identifiers.includes('CASHMANUAL') && (method === null || method === void 0 ? void 0 : method.enabled) !== false && (method === null || method === void 0 ? void 0 : method.enable) !== false;
4166
+ });
4167
+ }
4168
+ }, {
4169
+ key: "getPendingWalletPaymentAmount",
4170
+ value: function getPendingWalletPaymentAmount() {
4171
+ var _this$store$order10, _this$store$order10$g;
4172
+ var payments = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ((_this$store$order10 = this.store.order) === null || _this$store$order10 === void 0 || (_this$store$order10$g = _this$store$order10.getOrderPayments) === null || _this$store$order10$g === void 0 ? void 0 : _this$store$order10$g.call(_this$store$order10)) || [];
4173
+ return payments.reduce(function (total, payment) {
4174
+ if ((payment === null || payment === void 0 ? void 0 : payment.status) !== 'payment_pending' || (payment === null || payment === void 0 ? void 0 : payment.voucher_id) === undefined || Number(payment.voucher_id) === 0) {
4175
+ return total;
4176
+ }
4177
+ try {
4178
+ return total.plus(payment.amount || 0).plus(payment.rounding_amount || 0);
4179
+ } catch (_unused5) {
4180
+ return total;
4181
+ }
4182
+ }, new Decimal(0));
3321
4183
  }
3322
4184
 
4185
+ /** 读取现金 action 所需的支付方式、待付金额和快捷金额。 */
4186
+ }, {
4187
+ key: "getCashPaymentConfig",
4188
+ value: (function () {
4189
+ var _getCashPaymentConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee45() {
4190
+ var _this$store$order11, _this$store$order11$g, _this$store$order12, _this$store$order12$g, _this$otherParams26;
4191
+ var paymentMethods, paymentMethod, amountSnapshot, pendingWalletAmount, amountDue, currency, recommendedAmounts;
4192
+ return _regeneratorRuntime().wrap(function _callee45$(_context45) {
4193
+ while (1) switch (_context45.prev = _context45.next) {
4194
+ case 0:
4195
+ if (this.store.payment) {
4196
+ _context45.next = 2;
4197
+ break;
4198
+ }
4199
+ throw new Error('payment 模块未初始化');
4200
+ case 2:
4201
+ paymentMethods = this.getPaymentMethods();
4202
+ paymentMethod = this.findCashPaymentMethod(paymentMethods);
4203
+ if (paymentMethod) {
4204
+ _context45.next = 9;
4205
+ break;
4206
+ }
4207
+ _context45.next = 7;
4208
+ return this.getPaymentMethodsAsync();
4209
+ case 7:
4210
+ paymentMethods = _context45.sent;
4211
+ paymentMethod = this.findCashPaymentMethod(paymentMethods);
4212
+ case 9:
4213
+ amountSnapshot = (_this$store$order11 = this.store.order) === null || _this$store$order11 === void 0 || (_this$store$order11$g = _this$store$order11.getOrderAmountSnapshot) === null || _this$store$order11$g === void 0 ? void 0 : _this$store$order11$g.call(_this$store$order11);
4214
+ pendingWalletAmount = this.getPendingWalletPaymentAmount();
4215
+ amountDue = Decimal.max(new Decimal((amountSnapshot === null || amountSnapshot === void 0 ? void 0 : amountSnapshot.amountGap) || 0).minus(pendingWalletAmount), 0).toDecimalPlaces(2).toNumber();
4216
+ currency = ((_this$store$order12 = this.store.order) === null || _this$store$order12 === void 0 || (_this$store$order12$g = _this$store$order12.getTempOrder) === null || _this$store$order12$g === void 0 || (_this$store$order12$g = _this$store$order12$g.call(_this$store$order12)) === null || _this$store$order12$g === void 0 ? void 0 : _this$store$order12$g.currency_code) || ((_this$otherParams26 = this.otherParams) === null || _this$otherParams26 === void 0 ? void 0 : _this$otherParams26.currency) || 'USD';
4217
+ recommendedAmounts = amountDue > 0 ? this.store.payment.cash.getRecommendedAmount(amountDue, currency) : [];
4218
+ return _context45.abrupt("return", {
4219
+ available: Boolean(paymentMethod && amountDue > 0),
4220
+ paymentMethod: paymentMethod,
4221
+ amountDue: amountDue,
4222
+ recommendedAmounts: recommendedAmounts
4223
+ });
4224
+ case 15:
4225
+ case "end":
4226
+ return _context45.stop();
4227
+ }
4228
+ }, _callee45, this);
4229
+ }));
4230
+ function getCashPaymentConfig() {
4231
+ return _getCashPaymentConfig.apply(this, arguments);
4232
+ }
4233
+ return getCashPaymentConfig;
4234
+ }()
4235
+ /**
4236
+ * 确认足额覆盖订单的 pending Wallet 支付并提交订单。
4237
+ *
4238
+ * Order 模块在构造提交参数时将 pending voucher 转为 paid;只有提交成功后
4239
+ * 才同步 Wallet committed 状态。失败时恢复调用前 payments,允许用户重试。
4240
+ */
4241
+ )
4242
+ }, {
4243
+ key: "confirmWalletPayment",
4244
+ value: (function () {
4245
+ var _confirmWalletPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee46() {
4246
+ var _this$store$order$get3, _this$store$order13, _this$store$order$get4, _this$store$order$get5, _this$store$order14;
4247
+ var beforePayments, pendingWalletAmount, amountSnapshot, effectiveAmountDue, beforePaymentStatus, submitResult, restoredTempOrder, committed, walletState, latestAmountSnapshot;
4248
+ return _regeneratorRuntime().wrap(function _callee46$(_context46) {
4249
+ while (1) switch (_context46.prev = _context46.next) {
4250
+ case 0:
4251
+ if (this.store.order) {
4252
+ _context46.next = 2;
4253
+ break;
4254
+ }
4255
+ throw new Error('order 模块未初始化');
4256
+ case 2:
4257
+ beforePayments = cloneDeep(this.store.order.getOrderPayments());
4258
+ pendingWalletAmount = this.getPendingWalletPaymentAmount(beforePayments);
4259
+ if (!pendingWalletAmount.lte(0)) {
4260
+ _context46.next = 6;
4261
+ break;
4262
+ }
4263
+ throw new Error('当前订单没有待确认的 Wallet 支付');
4264
+ case 6:
4265
+ amountSnapshot = (_this$store$order$get3 = (_this$store$order13 = this.store.order).getOrderAmountSnapshot) === null || _this$store$order$get3 === void 0 ? void 0 : _this$store$order$get3.call(_this$store$order13);
4266
+ effectiveAmountDue = Decimal.max(new Decimal((amountSnapshot === null || amountSnapshot === void 0 ? void 0 : amountSnapshot.amountGap) || 0).minus(pendingWalletAmount), 0);
4267
+ if (!effectiveAmountDue.gt(0.01)) {
4268
+ _context46.next = 10;
4269
+ break;
4270
+ }
4271
+ throw new Error('Wallet 支付尚未覆盖全部待支付金额');
4272
+ case 10:
4273
+ beforePaymentStatus = (_this$store$order$get4 = this.store.order.getTempOrder()) === null || _this$store$order$get4 === void 0 ? void 0 : _this$store$order$get4.payment_status;
4274
+ _context46.prev = 11;
4275
+ _context46.next = 14;
4276
+ return this.submitSalesOrder({
4277
+ smallTicketDataFlag: 1,
4278
+ confirmPendingVoucherPayments: true
4279
+ });
4280
+ case 14:
4281
+ submitResult = _context46.sent;
4282
+ if (!isRejectedSalesSubmitResult(submitResult)) {
4283
+ _context46.next = 17;
4284
+ break;
4285
+ }
4286
+ throw new Error(getSalesSubmitErrorMessage(submitResult));
4287
+ case 17:
4288
+ _context46.next = 27;
4289
+ break;
4290
+ case 19:
4291
+ _context46.prev = 19;
4292
+ _context46.t0 = _context46["catch"](11);
4293
+ this.store.order.setOrderPayments(beforePayments);
4294
+ restoredTempOrder = this.store.order.getTempOrder();
4295
+ if (restoredTempOrder && beforePaymentStatus !== undefined) {
4296
+ restoredTempOrder.payment_status = beforePaymentStatus;
4297
+ this.store.order.persistTempOrder();
4298
+ }
4299
+ _context46.next = 26;
4300
+ return this.store.order.recalculateSummary({
4301
+ createIfMissing: true
4302
+ });
4303
+ case 26:
4304
+ throw _context46.t0;
4305
+ case 27:
4306
+ if (!this.store.payment) {
4307
+ _context46.next = 38;
4308
+ break;
4309
+ }
4310
+ _context46.prev = 28;
4311
+ committed = this.getCommittedWalletAssets();
4312
+ walletState = this.store.payment.wallet.setCommittedWalletAssets(committed.ids, committed.assets);
4313
+ _context46.next = 33;
4314
+ return this.publishWalletAssetsState(walletState);
4315
+ case 33:
4316
+ _context46.next = 38;
4317
+ break;
4318
+ case 35:
4319
+ _context46.prev = 35;
4320
+ _context46.t1 = _context46["catch"](28);
4321
+ this.logWarning('confirmWalletPayment: Wallet committed 状态同步失败', {
4322
+ error: _context46.t1 instanceof Error ? _context46.t1.message : String(_context46.t1)
4323
+ });
4324
+ case 38:
4325
+ latestAmountSnapshot = (_this$store$order$get5 = (_this$store$order14 = this.store.order).getOrderAmountSnapshot) === null || _this$store$order$get5 === void 0 ? void 0 : _this$store$order$get5.call(_this$store$order14);
4326
+ return _context46.abrupt("return", {
4327
+ submitResult: submitResult,
4328
+ payments: this.store.order.getOrderPayments(),
4329
+ isOrderFullyPaid: new Decimal((latestAmountSnapshot === null || latestAmountSnapshot === void 0 ? void 0 : latestAmountSnapshot.amountGap) || 0).lte(0)
4330
+ });
4331
+ case 40:
4332
+ case "end":
4333
+ return _context46.stop();
4334
+ }
4335
+ }, _callee46, this, [[11, 19], [28, 35]]);
4336
+ }));
4337
+ function confirmWalletPayment() {
4338
+ return _confirmWalletPayment.apply(this, arguments);
4339
+ }
4340
+ return confirmWalletPayment;
4341
+ }()
4342
+ /**
4343
+ * 购物车现金直付:写入现金记录并等待支付同步完成。
4344
+ * 同步失败会恢复调用前 payments(包含 Wallet pending 状态)。
4345
+ */
4346
+ )
4347
+ }, {
4348
+ key: "payCash",
4349
+ value: (function () {
4350
+ var _payCash = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee47(params) {
4351
+ var _this$store$order$get6, _params$actualPaidAmo, _this$otherParams27, _this$window, _this$window$postMess;
4352
+ var amount, config, paymentMethod, roundingAmount, effectivePaymentAmount, beforePayments, beforePaymentStatus, uniquePaymentNumber, paymentTimestamp, actualPaidAmount, changeAmount, shopWalletPassId, payments, payment, syncResult, committed, walletState, restoredTempOrder;
4353
+ return _regeneratorRuntime().wrap(function _callee47$(_context47) {
4354
+ while (1) switch (_context47.prev = _context47.next) {
4355
+ case 0:
4356
+ if (this.store.order) {
4357
+ _context47.next = 2;
4358
+ break;
4359
+ }
4360
+ throw new Error('order 模块未初始化');
4361
+ case 2:
4362
+ amount = Number(params.amount || 0);
4363
+ if (!(!Number.isFinite(amount) || amount <= 0)) {
4364
+ _context47.next = 5;
4365
+ break;
4366
+ }
4367
+ throw new Error('现金支付金额必须大于 0');
4368
+ case 5:
4369
+ _context47.next = 7;
4370
+ return this.getCashPaymentConfig();
4371
+ case 7:
4372
+ config = _context47.sent;
4373
+ paymentMethod = config.paymentMethod;
4374
+ if (paymentMethod) {
4375
+ _context47.next = 11;
4376
+ break;
4377
+ }
4378
+ throw new Error('未找到可用的 CASHMANUAL 支付方式');
4379
+ case 11:
4380
+ if (!(config.amountDue <= 0)) {
4381
+ _context47.next = 13;
4382
+ break;
4383
+ }
4384
+ throw new Error('当前订单没有待支付金额');
4385
+ case 13:
4386
+ roundingAmount = Number(params.roundingAmount || 0);
4387
+ effectivePaymentAmount = new Decimal(amount).minus(roundingAmount);
4388
+ if (!effectivePaymentAmount.gt(new Decimal(config.amountDue).plus(0.01))) {
4389
+ _context47.next = 17;
4390
+ break;
4391
+ }
4392
+ throw new Error('现金支付金额超过当前待支付金额');
4393
+ case 17:
4394
+ beforePayments = cloneDeep(this.store.order.getOrderPayments());
4395
+ beforePaymentStatus = (_this$store$order$get6 = this.store.order.getTempOrder()) === null || _this$store$order$get6 === void 0 ? void 0 : _this$store$order$get6.payment_status;
4396
+ uniquePaymentNumber = createUuidV4();
4397
+ paymentTimestamp = dayjs().format('YYYY-MM-DD HH:mm:ss');
4398
+ actualPaidAmount = Number((_params$actualPaidAmo = params.actualPaidAmount) !== null && _params$actualPaidAmo !== void 0 ? _params$actualPaidAmo : amount);
4399
+ changeAmount = Number(params.changeAmount || 0);
4400
+ shopWalletPassId = (_this$otherParams27 = this.otherParams) === null || _this$otherParams27 === void 0 ? void 0 : _this$otherParams27.shop_wallet_pass_id;
4401
+ if (!(!Number.isFinite(actualPaidAmount) || actualPaidAmount + 0.01 < amount)) {
4402
+ _context47.next = 26;
4403
+ break;
4404
+ }
4405
+ throw new Error('顾客实收现金不能小于支付金额');
4406
+ case 26:
4407
+ (_this$window = this.window) === null || _this$window === void 0 || (_this$window = _this$window.interaction) === null || _this$window === void 0 || (_this$window = _this$window.utils) === null || _this$window === void 0 || (_this$window$postMess = _this$window.postMessageToApp) === null || _this$window$postMess === void 0 || _this$window$postMess.call(_this$window, {
4408
+ module: 'till',
4409
+ key: 'open_till',
4410
+ data: {
4411
+ type: 'cash'
4412
+ }
4413
+ });
4414
+ payments = this.store.order.addOrderPayment({
4415
+ amount: amount.toFixed(2),
4416
+ code: paymentMethod.code,
4417
+ custom_payment_id: paymentMethod.id,
4418
+ name: paymentMethod.name,
4419
+ custom_payment_type: paymentMethod.type,
4420
+ voucher_id: 0,
4421
+ rounding_amount: roundingAmount.toFixed(2),
4422
+ metadata: _objectSpread(_objectSpread({
4423
+ unique_payment_number: uniquePaymentNumber
4424
+ }, shopWalletPassId !== undefined && shopWalletPassId !== null ? {
4425
+ shop_wallet_pass_id: shopWalletPassId
4426
+ } : {}), {}, {
4427
+ actual_paid_amount: Number.isFinite(actualPaidAmount) ? actualPaidAmount : amount,
4428
+ change_given_amount: Number.isFinite(changeAmount) ? changeAmount : 0
4429
+ }),
4430
+ payment_time: paymentTimestamp,
4431
+ created_at: paymentTimestamp
4432
+ });
4433
+ payment = payments.find(function (item) {
4434
+ var _item$metadata2;
4435
+ return (item === null || item === void 0 || (_item$metadata2 = item.metadata) === null || _item$metadata2 === void 0 ? void 0 : _item$metadata2.unique_payment_number) === uniquePaymentNumber;
4436
+ });
4437
+ _context47.prev = 29;
4438
+ _context47.next = 32;
4439
+ return this.syncPaymentsToOrder({
4440
+ payments: payments,
4441
+ submitWhenPaid: true,
4442
+ smallTicketDataFlag: 1,
4443
+ confirmPendingVoucherPayments: true
4444
+ });
4445
+ case 32:
4446
+ syncResult = _context47.sent;
4447
+ if (!this.store.payment) {
4448
+ _context47.next = 38;
4449
+ break;
4450
+ }
4451
+ committed = this.getCommittedWalletAssets();
4452
+ walletState = this.store.payment.wallet.setCommittedWalletAssets(committed.ids, committed.assets);
4453
+ _context47.next = 38;
4454
+ return this.publishWalletAssetsState(walletState);
4455
+ case 38:
4456
+ return _context47.abrupt("return", {
4457
+ payment: payment || {},
4458
+ payments: this.store.order.getOrderPayments(),
4459
+ syncResult: syncResult,
4460
+ isOrderFullyPaid: syncResult.isOrderFullyPaid
4461
+ });
4462
+ case 41:
4463
+ _context47.prev = 41;
4464
+ _context47.t0 = _context47["catch"](29);
4465
+ this.store.order.setOrderPayments(beforePayments);
4466
+ restoredTempOrder = this.store.order.getTempOrder();
4467
+ if (restoredTempOrder && beforePaymentStatus !== undefined) {
4468
+ restoredTempOrder.payment_status = beforePaymentStatus;
4469
+ this.store.order.persistTempOrder();
4470
+ }
4471
+ _context47.next = 48;
4472
+ return this.store.order.recalculateSummary({
4473
+ createIfMissing: true
4474
+ });
4475
+ case 48:
4476
+ throw _context47.t0;
4477
+ case 49:
4478
+ case "end":
4479
+ return _context47.stop();
4480
+ }
4481
+ }, _callee47, this, [[29, 41]]);
4482
+ }));
4483
+ function payCash(_x39) {
4484
+ return _payCash.apply(this, arguments);
4485
+ }
4486
+ return payCash;
4487
+ }()
4488
+ /**
4489
+ * 提交一次已由支付设备确认成功的非 Wallet 支付。
4490
+ *
4491
+ * 与 addOrderPayment 不同,本入口不会启动后台 fire-and-forget 同步;调用方会等待
4492
+ * 本次 payment、当前 pending Wallet 以及订单提交共同完成。任何同步失败都会恢复
4493
+ * 调用前的 payments 与 payment_status,便于 UI 安全解锁并重试。
4494
+ */
4495
+ )
4496
+ }, {
4497
+ key: "commitPaymentMethodPayment",
4498
+ value: (function () {
4499
+ var _commitPaymentMethodPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee48(params) {
4500
+ var _this$store$order$get7, _this$store$order15, _this$store$order$get8, _params$metadata, _params$originAmount;
4501
+ var amount, paymentMethods, findPaymentMethod, paymentMethod, amountSnapshot, pendingWalletAmount, amountDue, beforePayments, beforePaymentStatus, paymentTimestamp, metadata, serviceCharge, serviceFee, payments, payment, syncResult, committed, walletState, restoredTempOrder;
4502
+ return _regeneratorRuntime().wrap(function _callee48$(_context48) {
4503
+ while (1) switch (_context48.prev = _context48.next) {
4504
+ case 0:
4505
+ if (this.store.order) {
4506
+ _context48.next = 2;
4507
+ break;
4508
+ }
4509
+ throw new Error('order 模块未初始化');
4510
+ case 2:
4511
+ amount = Number(params.amount || 0);
4512
+ if (!(!Number.isFinite(amount) || amount <= 0)) {
4513
+ _context48.next = 5;
4514
+ break;
4515
+ }
4516
+ throw new Error('支付金额必须大于 0');
4517
+ case 5:
4518
+ paymentMethods = this.getPaymentMethods();
4519
+ findPaymentMethod = function findPaymentMethod() {
4520
+ var methodCode = String(params.paymentMethodCode || '').toUpperCase();
4521
+ return paymentMethods.find(function (method) {
4522
+ var idMatched = params.paymentMethodId !== undefined && String(method.id) === String(params.paymentMethodId);
4523
+ var codeMatched = Boolean(methodCode) && String(method.code || '').toUpperCase() === methodCode;
4524
+ return (idMatched || codeMatched) && method.enabled !== false && method.enable !== false;
4525
+ });
4526
+ };
4527
+ paymentMethod = findPaymentMethod();
4528
+ if (paymentMethod) {
4529
+ _context48.next = 13;
4530
+ break;
4531
+ }
4532
+ _context48.next = 11;
4533
+ return this.getPaymentMethodsAsync();
4534
+ case 11:
4535
+ paymentMethods = _context48.sent;
4536
+ paymentMethod = findPaymentMethod();
4537
+ case 13:
4538
+ if (paymentMethod) {
4539
+ _context48.next = 15;
4540
+ break;
4541
+ }
4542
+ throw new Error("\u672A\u627E\u5230\u53EF\u7528\u7684\u652F\u4ED8\u65B9\u5F0F\uFF1A".concat(params.paymentMethodCode || params.paymentMethodId || ''));
4543
+ case 15:
4544
+ amountSnapshot = (_this$store$order$get7 = (_this$store$order15 = this.store.order).getOrderAmountSnapshot) === null || _this$store$order$get7 === void 0 ? void 0 : _this$store$order$get7.call(_this$store$order15);
4545
+ pendingWalletAmount = this.getPendingWalletPaymentAmount();
4546
+ amountDue = Decimal.max(new Decimal((amountSnapshot === null || amountSnapshot === void 0 ? void 0 : amountSnapshot.amountGap) || 0).minus(pendingWalletAmount), 0);
4547
+ if (!amountDue.lte(0)) {
4548
+ _context48.next = 20;
4549
+ break;
4550
+ }
4551
+ throw new Error('当前订单没有待支付金额');
4552
+ case 20:
4553
+ if (!new Decimal(amount).gt(amountDue.plus(0.01))) {
4554
+ _context48.next = 22;
4555
+ break;
4556
+ }
4557
+ throw new Error('支付金额超过当前待支付金额');
4558
+ case 22:
4559
+ beforePayments = cloneDeep(this.store.order.getOrderPayments());
4560
+ beforePaymentStatus = (_this$store$order$get8 = this.store.order.getTempOrder()) === null || _this$store$order$get8 === void 0 ? void 0 : _this$store$order$get8.payment_status;
4561
+ paymentTimestamp = dayjs().format('YYYY-MM-DD HH:mm:ss');
4562
+ metadata = _objectSpread(_objectSpread({}, params.metadata || {}), {}, {
4563
+ unique_payment_number: ((_params$metadata = params.metadata) === null || _params$metadata === void 0 ? void 0 : _params$metadata.unique_payment_number) || createUuidV4()
4564
+ });
4565
+ serviceCharge = params.serviceCharge ? {
4566
+ amount: String(params.serviceCharge.amount || 0),
4567
+ percentage: String(params.serviceCharge.percentage || 0)
4568
+ } : undefined;
4569
+ serviceFee = serviceCharge ? new Decimal((_params$originAmount = params.originAmount) !== null && _params$originAmount !== void 0 ? _params$originAmount : amount).times(serviceCharge.percentage || 0).plus(serviceCharge.amount || 0).toDecimalPlaces(2).toFixed(2) : undefined;
4570
+ payments = this.store.order.addOrderPayment(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, params.paymentData || {}), {}, {
4571
+ amount: amount.toFixed(2)
4572
+ }, params.originAmount !== undefined ? {
4573
+ origin_amount: Number(params.originAmount).toFixed(2)
4574
+ } : {}), {}, {
4575
+ code: paymentMethod.code,
4576
+ custom_payment_id: paymentMethod.id,
4577
+ name: paymentMethod.name,
4578
+ custom_payment_type: paymentMethod.type,
4579
+ voucher_id: 0
4580
+ }, serviceCharge ? {
4581
+ service_charge: serviceCharge
4582
+ } : {}), serviceFee !== undefined ? {
4583
+ service_fee: serviceFee
4584
+ } : {}), {}, {
4585
+ metadata: metadata,
4586
+ payment_time: paymentTimestamp,
4587
+ created_at: paymentTimestamp
4588
+ }));
4589
+ payment = payments.find(function (item) {
4590
+ var _item$metadata3;
4591
+ return (item === null || item === void 0 || (_item$metadata3 = item.metadata) === null || _item$metadata3 === void 0 ? void 0 : _item$metadata3.unique_payment_number) === metadata.unique_payment_number;
4592
+ });
4593
+ _context48.prev = 30;
4594
+ _context48.next = 33;
4595
+ return this.syncPaymentsToOrder({
4596
+ payments: payments,
4597
+ submitWhenPaid: true,
4598
+ smallTicketDataFlag: 1,
4599
+ confirmPendingVoucherPayments: true
4600
+ });
4601
+ case 33:
4602
+ syncResult = _context48.sent;
4603
+ if (!this.store.payment) {
4604
+ _context48.next = 39;
4605
+ break;
4606
+ }
4607
+ committed = this.getCommittedWalletAssets();
4608
+ walletState = this.store.payment.wallet.setCommittedWalletAssets(committed.ids, committed.assets);
4609
+ _context48.next = 39;
4610
+ return this.publishWalletAssetsState(walletState);
4611
+ case 39:
4612
+ return _context48.abrupt("return", {
4613
+ payment: payment || {},
4614
+ payments: this.store.order.getOrderPayments(),
4615
+ syncResult: syncResult,
4616
+ isOrderFullyPaid: syncResult.isOrderFullyPaid
4617
+ });
4618
+ case 42:
4619
+ _context48.prev = 42;
4620
+ _context48.t0 = _context48["catch"](30);
4621
+ this.store.order.setOrderPayments(beforePayments);
4622
+ restoredTempOrder = this.store.order.getTempOrder();
4623
+ if (restoredTempOrder && beforePaymentStatus !== undefined) {
4624
+ restoredTempOrder.payment_status = beforePaymentStatus;
4625
+ this.store.order.persistTempOrder();
4626
+ }
4627
+ _context48.next = 49;
4628
+ return this.store.order.recalculateSummary({
4629
+ createIfMissing: true
4630
+ });
4631
+ case 49:
4632
+ throw _context48.t0;
4633
+ case 50:
4634
+ case "end":
4635
+ return _context48.stop();
4636
+ }
4637
+ }, _callee48, this, [[30, 42]]);
4638
+ }));
4639
+ function commitPaymentMethodPayment(_x40) {
4640
+ return _commitPaymentMethodPayment.apply(this, arguments);
4641
+ }
4642
+ return commitPaymentMethodPayment;
4643
+ }()
4644
+ /**
4645
+ * 按当前店铺的现金舍入配置计算金额,供现金支付 UI 使用。
4646
+ *
4647
+ * 舍入开关取自 CASHMANUAL 支付方式;舍入规则取自
4648
+ * otherParams.order_rounding_setting,金额算法统一由 PaymentModule 维护。
4649
+ */
4650
+ )
4651
+ }, {
4652
+ key: "roundAmount",
4653
+ value: (function () {
4654
+ var _roundAmount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee49(params) {
4655
+ var _cashManualPayment$me, _this$otherParams$ord2, _this$otherParams$ord3;
4656
+ var amount, cashManualPayment;
4657
+ return _regeneratorRuntime().wrap(function _callee49$(_context49) {
4658
+ while (1) switch (_context49.prev = _context49.next) {
4659
+ case 0:
4660
+ amount = params.amount;
4661
+ cashManualPayment = this.paymentMethodsCache.find(function (paymentMethod) {
4662
+ return paymentMethod.code === 'CASHMANUAL';
4663
+ });
4664
+ if (cashManualPayment !== null && cashManualPayment !== void 0 && (_cashManualPayment$me = cashManualPayment.metadata) !== null && _cashManualPayment$me !== void 0 && _cashManualPayment$me.order_rounding_switch) {
4665
+ _context49.next = 4;
4666
+ break;
4667
+ }
4668
+ return _context49.abrupt("return", {
4669
+ originalAmount: amount.toString(),
4670
+ roundedAmount: amount.toString(),
4671
+ roundingDifference: '0.00'
4672
+ });
4673
+ case 4:
4674
+ if (this.payment) {
4675
+ _context49.next = 6;
4676
+ break;
4677
+ }
4678
+ throw new Error('payment 模块未初始化');
4679
+ case 6:
4680
+ return _context49.abrupt("return", this.payment.roundAmountAsync(amount, (_this$otherParams$ord2 = this.otherParams.order_rounding_setting) === null || _this$otherParams$ord2 === void 0 ? void 0 : _this$otherParams$ord2.interval, (_this$otherParams$ord3 = this.otherParams.order_rounding_setting) === null || _this$otherParams$ord3 === void 0 ? void 0 : _this$otherParams$ord3.type));
4681
+ case 7:
4682
+ case "end":
4683
+ return _context49.stop();
4684
+ }
4685
+ }, _callee49, this);
4686
+ }));
4687
+ function roundAmount(_x41) {
4688
+ return _roundAmount.apply(this, arguments);
4689
+ }
4690
+ return roundAmount;
4691
+ }()
3323
4692
  /**
3324
4693
  * 发送支付链接。
3325
4694
  *
3326
4695
  * 如果没有 orderIds 或显式 submitBeforeSend,会先提交当前本地订单到云端;
3327
4696
  * 只有成功拿到远端 order_id 后才调用 OrderModule 发送邮件。
3328
4697
  */
4698
+ )
3329
4699
  }, {
3330
4700
  key: "sendCustomerPayLink",
3331
4701
  value: (function () {
3332
- var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(params) {
3333
- var orderIds, _ref25, _ref26, _submitResult$data$or, _submitResult$data, _submitResult$data2, submitResult, orderId;
3334
- return _regeneratorRuntime().wrap(function _callee34$(_context34) {
3335
- while (1) switch (_context34.prev = _context34.next) {
4702
+ var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee50(params) {
4703
+ var orderIds, _ref34, _ref35, _submitResult$data$or, _submitResult$data, _submitResult$data2, submitResult, orderId;
4704
+ return _regeneratorRuntime().wrap(function _callee50$(_context50) {
4705
+ while (1) switch (_context50.prev = _context50.next) {
3336
4706
  case 0:
3337
4707
  if (this.store.order) {
3338
- _context34.next = 2;
4708
+ _context50.next = 2;
3339
4709
  break;
3340
4710
  }
3341
4711
  throw new Error('order 模块未初始化');
3342
4712
  case 2:
3343
4713
  orderIds = params.order_ids || params.orderIds || [];
3344
4714
  if (!(!orderIds.length || params.submitBeforeSend)) {
3345
- _context34.next = 11;
4715
+ _context50.next = 11;
3346
4716
  break;
3347
4717
  }
3348
- _context34.next = 6;
4718
+ _context50.next = 6;
3349
4719
  return this.submitSalesOrder({
3350
4720
  smallTicketDataFlag: 1
3351
4721
  });
3352
4722
  case 6:
3353
- submitResult = _context34.sent;
3354
- orderId = (_ref25 = (_ref26 = (_submitResult$data$or = submitResult === null || submitResult === void 0 || (_submitResult$data = submitResult.data) === null || _submitResult$data === void 0 ? void 0 : _submitResult$data.order_id) !== null && _submitResult$data$or !== void 0 ? _submitResult$data$or : submitResult === null || submitResult === void 0 ? void 0 : submitResult.order_id) !== null && _ref26 !== void 0 ? _ref26 : submitResult === null || submitResult === void 0 || (_submitResult$data2 = submitResult.data) === null || _submitResult$data2 === void 0 ? void 0 : _submitResult$data2.id) !== null && _ref25 !== void 0 ? _ref25 : submitResult === null || submitResult === void 0 ? void 0 : submitResult.id;
4723
+ submitResult = _context50.sent;
4724
+ orderId = (_ref34 = (_ref35 = (_submitResult$data$or = submitResult === null || submitResult === void 0 || (_submitResult$data = submitResult.data) === null || _submitResult$data === void 0 ? void 0 : _submitResult$data.order_id) !== null && _submitResult$data$or !== void 0 ? _submitResult$data$or : submitResult === null || submitResult === void 0 ? void 0 : submitResult.order_id) !== null && _ref35 !== void 0 ? _ref35 : submitResult === null || submitResult === void 0 || (_submitResult$data2 = submitResult.data) === null || _submitResult$data2 === void 0 ? void 0 : _submitResult$data2.id) !== null && _ref34 !== void 0 ? _ref34 : submitResult === null || submitResult === void 0 ? void 0 : submitResult.id;
3355
4725
  if (orderId) {
3356
- _context34.next = 10;
4726
+ _context50.next = 10;
3357
4727
  break;
3358
4728
  }
3359
4729
  throw new Error('本地订单提交云端失败,无法发送支付链接');
3360
4730
  case 10:
3361
4731
  orderIds = [orderId];
3362
4732
  case 11:
3363
- return _context34.abrupt("return", this.store.order.sendCustomerPayLink({
4733
+ return _context50.abrupt("return", this.store.order.sendCustomerPayLink({
3364
4734
  emails: params.emails,
3365
4735
  notify_action: params.notify_action,
3366
4736
  order_ids: orderIds
3367
4737
  }));
3368
4738
  case 12:
3369
4739
  case "end":
3370
- return _context34.stop();
4740
+ return _context50.stop();
3371
4741
  }
3372
- }, _callee34, this);
4742
+ }, _callee50, this);
3373
4743
  }));
3374
- function sendCustomerPayLink(_x26) {
4744
+ function sendCustomerPayLink(_x42) {
3375
4745
  return _sendCustomerPayLink.apply(this, arguments);
3376
4746
  }
3377
4747
  return sendCustomerPayLink;
@@ -3384,27 +4754,27 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3384
4754
  }, {
3385
4755
  key: "calculateProductBookingPrice",
3386
4756
  value: function () {
3387
- var _calculateProductBookingPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(params) {
4757
+ var _calculateProductBookingPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee51(params) {
3388
4758
  var _params$customer_id;
3389
4759
  var quotation, customerId, authoritativeProduct, product;
3390
- return _regeneratorRuntime().wrap(function _callee35$(_context35) {
3391
- while (1) switch (_context35.prev = _context35.next) {
4760
+ return _regeneratorRuntime().wrap(function _callee51$(_context51) {
4761
+ while (1) switch (_context51.prev = _context51.next) {
3392
4762
  case 0:
3393
4763
  quotation = this.store.quotation;
3394
4764
  customerId = (_params$customer_id = params.customer_id) !== null && _params$customer_id !== void 0 ? _params$customer_id : this.getCurrentOrderCustomerId();
3395
- _context35.next = 4;
4765
+ _context51.next = 4;
3396
4766
  return this.loadProductForPriceQuery(params, customerId);
3397
4767
  case 4:
3398
- authoritativeProduct = _context35.sent;
4768
+ authoritativeProduct = _context51.sent;
3399
4769
  product = this.mergeProductForPriceQuery(params.product, authoritativeProduct);
3400
- _context35.next = 8;
4770
+ _context51.next = 8;
3401
4771
  return this.loadQuotationForPriceQuery({
3402
4772
  quotation: quotation,
3403
4773
  customer_id: customerId,
3404
4774
  channel: params.channel
3405
4775
  });
3406
4776
  case 8:
3407
- return _context35.abrupt("return", calculateBaseSalesProductBookingPrice(_objectSpread(_objectSpread({}, params), {}, {
4777
+ return _context51.abrupt("return", calculateBaseSalesProductBookingPrice(_objectSpread(_objectSpread({}, params), {}, {
3408
4778
  product: product,
3409
4779
  fallback_price: authoritativeProduct ? undefined : params.fallback_price,
3410
4780
  customer_id: customerId,
@@ -3412,11 +4782,11 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3412
4782
  })));
3413
4783
  case 9:
3414
4784
  case "end":
3415
- return _context35.stop();
4785
+ return _context51.stop();
3416
4786
  }
3417
- }, _callee35, this);
4787
+ }, _callee51, this);
3418
4788
  }));
3419
- function calculateProductBookingPrice(_x27) {
4789
+ function calculateProductBookingPrice(_x43) {
3420
4790
  return _calculateProductBookingPrice.apply(this, arguments);
3421
4791
  }
3422
4792
  return calculateProductBookingPrice;
@@ -3424,7 +4794,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3424
4794
  }, {
3425
4795
  key: "getQuotationCustomerScopeInfo",
3426
4796
  value: function getQuotationCustomerScopeInfo() {
3427
- var _this13 = this;
4797
+ var _this15 = this;
3428
4798
  var quotation = this.store.quotation;
3429
4799
  if (quotation && typeof quotation.getQuotationCustomerScopeInfo === 'function') {
3430
4800
  return quotation.getQuotationCustomerScopeInfo();
@@ -3436,7 +4806,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3436
4806
  }).map(function (item) {
3437
4807
  var localSeen = new Set();
3438
4808
  var customers = item.customer.filter(function (customer) {
3439
- var customerId = _this13.normalizePriceContextCustomerId(customer === null || customer === void 0 ? void 0 : customer.id);
4809
+ var customerId = _this15.normalizePriceContextCustomerId(customer === null || customer === void 0 ? void 0 : customer.id);
3440
4810
  if (!customerId || localSeen.has(customerId)) return false;
3441
4811
  localSeen.add(customerId);
3442
4812
  if (!customerById.has(customerId)) customerById.set(customerId, customer);
@@ -3486,32 +4856,32 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3486
4856
  }, {
3487
4857
  key: "calculateProductBookingPrices",
3488
4858
  value: function () {
3489
- var _calculateProductBookingPrices = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(paramsList) {
4859
+ var _calculateProductBookingPrices = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee53(paramsList) {
3490
4860
  var _paramsList$0$custome,
3491
4861
  _paramsList$,
3492
- _this14 = this,
4862
+ _this16 = this,
3493
4863
  _paramsList$2;
3494
4864
  var quotation, customerId, productMapsByGroup, groups;
3495
- return _regeneratorRuntime().wrap(function _callee37$(_context37) {
3496
- while (1) switch (_context37.prev = _context37.next) {
4865
+ return _regeneratorRuntime().wrap(function _callee53$(_context53) {
4866
+ while (1) switch (_context53.prev = _context53.next) {
3497
4867
  case 0:
3498
4868
  if (paramsList.length) {
3499
- _context37.next = 2;
4869
+ _context53.next = 2;
3500
4870
  break;
3501
4871
  }
3502
- return _context37.abrupt("return", []);
4872
+ return _context53.abrupt("return", []);
3503
4873
  case 2:
3504
4874
  quotation = this.store.quotation;
3505
4875
  customerId = (_paramsList$0$custome = (_paramsList$ = paramsList[0]) === null || _paramsList$ === void 0 ? void 0 : _paramsList$.customer_id) !== null && _paramsList$0$custome !== void 0 ? _paramsList$0$custome : this.getCurrentOrderCustomerId();
3506
4876
  productMapsByGroup = new Map();
3507
4877
  groups = new Map();
3508
4878
  paramsList.forEach(function (params) {
3509
- var _this14$otherParams;
4879
+ var _this16$otherParams;
3510
4880
  var product = params.product || {};
3511
- var productId = _this14.getPriceQueryProductId(product);
4881
+ var productId = _this16.getPriceQueryProductId(product);
3512
4882
  if (productId === null) return;
3513
- var schedule = _this14.getPriceQuerySchedule(params);
3514
- var channel = params.channel || ((_this14$otherParams = _this14.otherParams) === null || _this14$otherParams === void 0 ? void 0 : _this14$otherParams.channel);
4883
+ var schedule = _this16.getPriceQuerySchedule(params);
4884
+ var channel = params.channel || ((_this16$otherParams = _this16.otherParams) === null || _this16$otherParams === void 0 ? void 0 : _this16$otherParams.channel);
3515
4885
  var groupKey = [schedule.schedule_date, schedule.schedule_datetime, channel || ''].join('|');
3516
4886
  var group = groups.get(groupKey) || {
3517
4887
  ids: new Set(),
@@ -3521,51 +4891,51 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3521
4891
  group.ids.add(productId);
3522
4892
  groups.set(groupKey, group);
3523
4893
  });
3524
- _context37.next = 9;
4894
+ _context53.next = 9;
3525
4895
  return Promise.all(Array.from(groups.entries()).map( /*#__PURE__*/function () {
3526
- var _ref28 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(_ref27) {
3527
- var _ref29, groupKey, group, productsById;
3528
- return _regeneratorRuntime().wrap(function _callee36$(_context36) {
3529
- while (1) switch (_context36.prev = _context36.next) {
4896
+ var _ref37 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee52(_ref36) {
4897
+ var _ref38, groupKey, group, productsById;
4898
+ return _regeneratorRuntime().wrap(function _callee52$(_context52) {
4899
+ while (1) switch (_context52.prev = _context52.next) {
3530
4900
  case 0:
3531
- _ref29 = _slicedToArray(_ref27, 2), groupKey = _ref29[0], group = _ref29[1];
3532
- _context36.next = 3;
3533
- return _this14.loadProductsForPriceQuery({
4901
+ _ref38 = _slicedToArray(_ref36, 2), groupKey = _ref38[0], group = _ref38[1];
4902
+ _context52.next = 3;
4903
+ return _this16.loadProductsForPriceQuery({
3534
4904
  ids: Array.from(group.ids),
3535
4905
  schedule: group.schedule,
3536
4906
  customerId: customerId,
3537
4907
  channel: group.channel
3538
4908
  });
3539
4909
  case 3:
3540
- productsById = _context36.sent;
4910
+ productsById = _context52.sent;
3541
4911
  productMapsByGroup.set(groupKey, productsById);
3542
4912
  case 5:
3543
4913
  case "end":
3544
- return _context36.stop();
4914
+ return _context52.stop();
3545
4915
  }
3546
- }, _callee36);
4916
+ }, _callee52);
3547
4917
  }));
3548
- return function (_x29) {
3549
- return _ref28.apply(this, arguments);
4918
+ return function (_x45) {
4919
+ return _ref37.apply(this, arguments);
3550
4920
  };
3551
4921
  }()));
3552
4922
  case 9:
3553
- _context37.next = 11;
4923
+ _context53.next = 11;
3554
4924
  return this.loadQuotationForPriceQuery({
3555
4925
  quotation: quotation,
3556
4926
  customer_id: customerId,
3557
4927
  channel: (_paramsList$2 = paramsList[0]) === null || _paramsList$2 === void 0 ? void 0 : _paramsList$2.channel
3558
4928
  });
3559
4929
  case 11:
3560
- return _context37.abrupt("return", paramsList.map(function (params) {
3561
- var _this14$otherParams2, _productMapsByGroup$g;
4930
+ return _context53.abrupt("return", paramsList.map(function (params) {
4931
+ var _this16$otherParams2, _productMapsByGroup$g;
3562
4932
  var productInput = params.product || {};
3563
- var productId = _this14.getPriceQueryProductId(productInput);
3564
- var schedule = _this14.getPriceQuerySchedule(params);
3565
- var channel = params.channel || ((_this14$otherParams2 = _this14.otherParams) === null || _this14$otherParams2 === void 0 ? void 0 : _this14$otherParams2.channel);
4933
+ var productId = _this16.getPriceQueryProductId(productInput);
4934
+ var schedule = _this16.getPriceQuerySchedule(params);
4935
+ var channel = params.channel || ((_this16$otherParams2 = _this16.otherParams) === null || _this16$otherParams2 === void 0 ? void 0 : _this16$otherParams2.channel);
3566
4936
  var groupKey = [schedule.schedule_date, schedule.schedule_datetime, channel || ''].join('|');
3567
4937
  var authoritativeProduct = productId === null ? null : ((_productMapsByGroup$g = productMapsByGroup.get(groupKey)) === null || _productMapsByGroup$g === void 0 ? void 0 : _productMapsByGroup$g.get(productId)) || null;
3568
- var product = _this14.mergeProductForPriceQuery(productInput, authoritativeProduct);
4938
+ var product = _this16.mergeProductForPriceQuery(productInput, authoritativeProduct);
3569
4939
  return calculateBaseSalesProductBookingPrice(_objectSpread(_objectSpread({}, params), {}, {
3570
4940
  product: product,
3571
4941
  fallback_price: authoritativeProduct ? undefined : params.fallback_price,
@@ -3575,11 +4945,11 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3575
4945
  }));
3576
4946
  case 12:
3577
4947
  case "end":
3578
- return _context37.stop();
4948
+ return _context53.stop();
3579
4949
  }
3580
- }, _callee37, this);
4950
+ }, _callee53, this);
3581
4951
  }));
3582
- function calculateProductBookingPrices(_x28) {
4952
+ function calculateProductBookingPrices(_x44) {
3583
4953
  return _calculateProductBookingPrices.apply(this, arguments);
3584
4954
  }
3585
4955
  return calculateProductBookingPrices;
@@ -3587,34 +4957,34 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3587
4957
  }, {
3588
4958
  key: "addProductToOrder",
3589
4959
  value: function () {
3590
- var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(product, booking) {
4960
+ var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee54(product, booking) {
3591
4961
  var products;
3592
- return _regeneratorRuntime().wrap(function _callee38$(_context38) {
3593
- while (1) switch (_context38.prev = _context38.next) {
4962
+ return _regeneratorRuntime().wrap(function _callee54$(_context54) {
4963
+ while (1) switch (_context54.prev = _context54.next) {
3594
4964
  case 0:
3595
- _context38.prev = 0;
4965
+ _context54.prev = 0;
3596
4966
  if (this.store.order) {
3597
- _context38.next = 3;
4967
+ _context54.next = 3;
3598
4968
  break;
3599
4969
  }
3600
4970
  throw new Error('order 模块未初始化');
3601
4971
  case 3:
3602
- _context38.next = 5;
4972
+ _context54.next = 5;
3603
4973
  return this.store.order.addProductToOrder(product, booking);
3604
4974
  case 5:
3605
- products = _context38.sent;
3606
- return _context38.abrupt("return", products);
4975
+ products = _context54.sent;
4976
+ return _context54.abrupt("return", products);
3607
4977
  case 9:
3608
- _context38.prev = 9;
3609
- _context38.t0 = _context38["catch"](0);
3610
- throw _context38.t0;
4978
+ _context54.prev = 9;
4979
+ _context54.t0 = _context54["catch"](0);
4980
+ throw _context54.t0;
3611
4981
  case 12:
3612
4982
  case "end":
3613
- return _context38.stop();
4983
+ return _context54.stop();
3614
4984
  }
3615
- }, _callee38, this, [[0, 9]]);
4985
+ }, _callee54, this, [[0, 9]]);
3616
4986
  }));
3617
- function addProductToOrder(_x30, _x31) {
4987
+ function addProductToOrder(_x46, _x47) {
3618
4988
  return _addProductToOrder.apply(this, arguments);
3619
4989
  }
3620
4990
  return addProductToOrder;
@@ -3622,34 +4992,34 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3622
4992
  }, {
3623
4993
  key: "updateOrderProduct",
3624
4994
  value: function () {
3625
- var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(params) {
4995
+ var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee55(params) {
3626
4996
  var products;
3627
- return _regeneratorRuntime().wrap(function _callee39$(_context39) {
3628
- while (1) switch (_context39.prev = _context39.next) {
4997
+ return _regeneratorRuntime().wrap(function _callee55$(_context55) {
4998
+ while (1) switch (_context55.prev = _context55.next) {
3629
4999
  case 0:
3630
- _context39.prev = 0;
5000
+ _context55.prev = 0;
3631
5001
  if (this.store.order) {
3632
- _context39.next = 3;
5002
+ _context55.next = 3;
3633
5003
  break;
3634
5004
  }
3635
5005
  throw new Error('order 模块未初始化');
3636
5006
  case 3:
3637
- _context39.next = 5;
5007
+ _context55.next = 5;
3638
5008
  return this.store.order.updateOrderProduct(params);
3639
5009
  case 5:
3640
- products = _context39.sent;
3641
- return _context39.abrupt("return", products);
5010
+ products = _context55.sent;
5011
+ return _context55.abrupt("return", products);
3642
5012
  case 9:
3643
- _context39.prev = 9;
3644
- _context39.t0 = _context39["catch"](0);
3645
- throw _context39.t0;
5013
+ _context55.prev = 9;
5014
+ _context55.t0 = _context55["catch"](0);
5015
+ throw _context55.t0;
3646
5016
  case 12:
3647
5017
  case "end":
3648
- return _context39.stop();
5018
+ return _context55.stop();
3649
5019
  }
3650
- }, _callee39, this, [[0, 9]]);
5020
+ }, _callee55, this, [[0, 9]]);
3651
5021
  }));
3652
- function updateOrderProduct(_x32) {
5022
+ function updateOrderProduct(_x48) {
3653
5023
  return _updateOrderProduct.apply(this, arguments);
3654
5024
  }
3655
5025
  return updateOrderProduct;
@@ -3657,34 +5027,34 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3657
5027
  }, {
3658
5028
  key: "updateOrderProducts",
3659
5029
  value: function () {
3660
- var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(paramsList) {
5030
+ var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee56(paramsList) {
3661
5031
  var products;
3662
- return _regeneratorRuntime().wrap(function _callee40$(_context40) {
3663
- while (1) switch (_context40.prev = _context40.next) {
5032
+ return _regeneratorRuntime().wrap(function _callee56$(_context56) {
5033
+ while (1) switch (_context56.prev = _context56.next) {
3664
5034
  case 0:
3665
- _context40.prev = 0;
5035
+ _context56.prev = 0;
3666
5036
  if (this.store.order) {
3667
- _context40.next = 3;
5037
+ _context56.next = 3;
3668
5038
  break;
3669
5039
  }
3670
5040
  throw new Error('order 模块未初始化');
3671
5041
  case 3:
3672
- _context40.next = 5;
5042
+ _context56.next = 5;
3673
5043
  return this.store.order.updateOrderProducts(paramsList);
3674
5044
  case 5:
3675
- products = _context40.sent;
3676
- return _context40.abrupt("return", products);
5045
+ products = _context56.sent;
5046
+ return _context56.abrupt("return", products);
3677
5047
  case 9:
3678
- _context40.prev = 9;
3679
- _context40.t0 = _context40["catch"](0);
3680
- throw _context40.t0;
5048
+ _context56.prev = 9;
5049
+ _context56.t0 = _context56["catch"](0);
5050
+ throw _context56.t0;
3681
5051
  case 12:
3682
5052
  case "end":
3683
- return _context40.stop();
5053
+ return _context56.stop();
3684
5054
  }
3685
- }, _callee40, this, [[0, 9]]);
5055
+ }, _callee56, this, [[0, 9]]);
3686
5056
  }));
3687
- function updateOrderProducts(_x33) {
5057
+ function updateOrderProducts(_x49) {
3688
5058
  return _updateOrderProducts.apply(this, arguments);
3689
5059
  }
3690
5060
  return updateOrderProducts;
@@ -3692,34 +5062,34 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3692
5062
  }, {
3693
5063
  key: "updateOrderProductQuantity",
3694
5064
  value: function () {
3695
- var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(params) {
5065
+ var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee57(params) {
3696
5066
  var products;
3697
- return _regeneratorRuntime().wrap(function _callee41$(_context41) {
3698
- while (1) switch (_context41.prev = _context41.next) {
5067
+ return _regeneratorRuntime().wrap(function _callee57$(_context57) {
5068
+ while (1) switch (_context57.prev = _context57.next) {
3699
5069
  case 0:
3700
- _context41.prev = 0;
5070
+ _context57.prev = 0;
3701
5071
  if (this.store.order) {
3702
- _context41.next = 3;
5072
+ _context57.next = 3;
3703
5073
  break;
3704
5074
  }
3705
5075
  throw new Error('order 模块未初始化');
3706
5076
  case 3:
3707
- _context41.next = 5;
5077
+ _context57.next = 5;
3708
5078
  return this.store.order.updateOrderProductQuantity(params);
3709
5079
  case 5:
3710
- products = _context41.sent;
3711
- return _context41.abrupt("return", products);
5080
+ products = _context57.sent;
5081
+ return _context57.abrupt("return", products);
3712
5082
  case 9:
3713
- _context41.prev = 9;
3714
- _context41.t0 = _context41["catch"](0);
3715
- throw _context41.t0;
5083
+ _context57.prev = 9;
5084
+ _context57.t0 = _context57["catch"](0);
5085
+ throw _context57.t0;
3716
5086
  case 12:
3717
5087
  case "end":
3718
- return _context41.stop();
5088
+ return _context57.stop();
3719
5089
  }
3720
- }, _callee41, this, [[0, 9]]);
5090
+ }, _callee57, this, [[0, 9]]);
3721
5091
  }));
3722
- function updateOrderProductQuantity(_x34) {
5092
+ function updateOrderProductQuantity(_x50) {
3723
5093
  return _updateOrderProductQuantity.apply(this, arguments);
3724
5094
  }
3725
5095
  return updateOrderProductQuantity;
@@ -3742,12 +5112,12 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3742
5112
  }, {
3743
5113
  key: "setOrderProductLineNote",
3744
5114
  value: (function () {
3745
- var _setOrderProductLineNote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42(identity, note) {
5115
+ var _setOrderProductLineNote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee58(identity, note) {
3746
5116
  var params, products;
3747
- return _regeneratorRuntime().wrap(function _callee42$(_context42) {
3748
- while (1) switch (_context42.prev = _context42.next) {
5117
+ return _regeneratorRuntime().wrap(function _callee58$(_context58) {
5118
+ while (1) switch (_context58.prev = _context58.next) {
3749
5119
  case 0:
3750
- _context42.prev = 0;
5120
+ _context58.prev = 0;
3751
5121
  params = {
3752
5122
  product_id: identity.product_id,
3753
5123
  product_variant_id: identity.product_variant_id,
@@ -3762,22 +5132,22 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3762
5132
  params.product_sku = identity.product_sku;
3763
5133
  }
3764
5134
  if (identity.product_bundle !== undefined) params.product_bundle = identity.product_bundle;
3765
- _context42.next = 7;
5135
+ _context58.next = 7;
3766
5136
  return this.updateOrderProduct(params);
3767
5137
  case 7:
3768
- products = _context42.sent;
3769
- return _context42.abrupt("return", products);
5138
+ products = _context58.sent;
5139
+ return _context58.abrupt("return", products);
3770
5140
  case 11:
3771
- _context42.prev = 11;
3772
- _context42.t0 = _context42["catch"](0);
3773
- throw _context42.t0;
5141
+ _context58.prev = 11;
5142
+ _context58.t0 = _context58["catch"](0);
5143
+ throw _context58.t0;
3774
5144
  case 14:
3775
5145
  case "end":
3776
- return _context42.stop();
5146
+ return _context58.stop();
3777
5147
  }
3778
- }, _callee42, this, [[0, 11]]);
5148
+ }, _callee58, this, [[0, 11]]);
3779
5149
  }));
3780
- function setOrderProductLineNote(_x35, _x36) {
5150
+ function setOrderProductLineNote(_x51, _x52) {
3781
5151
  return _setOrderProductLineNote.apply(this, arguments);
3782
5152
  }
3783
5153
  return setOrderProductLineNote;
@@ -3792,32 +5162,32 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3792
5162
  }, {
3793
5163
  key: "removeProductsFromOrder",
3794
5164
  value: (function () {
3795
- var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43(identities) {
3796
- return _regeneratorRuntime().wrap(function _callee43$(_context43) {
3797
- while (1) switch (_context43.prev = _context43.next) {
5165
+ var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee59(identities) {
5166
+ return _regeneratorRuntime().wrap(function _callee59$(_context59) {
5167
+ while (1) switch (_context59.prev = _context59.next) {
3798
5168
  case 0:
3799
- _context43.prev = 0;
5169
+ _context59.prev = 0;
3800
5170
  if (this.store.order) {
3801
- _context43.next = 3;
5171
+ _context59.next = 3;
3802
5172
  break;
3803
5173
  }
3804
5174
  throw new Error('order 模块未初始化');
3805
5175
  case 3:
3806
- _context43.next = 5;
5176
+ _context59.next = 5;
3807
5177
  return this.store.order.removeProductsFromOrder(identities);
3808
5178
  case 5:
3809
- return _context43.abrupt("return", _context43.sent);
5179
+ return _context59.abrupt("return", _context59.sent);
3810
5180
  case 8:
3811
- _context43.prev = 8;
3812
- _context43.t0 = _context43["catch"](0);
3813
- throw _context43.t0;
5181
+ _context59.prev = 8;
5182
+ _context59.t0 = _context59["catch"](0);
5183
+ throw _context59.t0;
3814
5184
  case 11:
3815
5185
  case "end":
3816
- return _context43.stop();
5186
+ return _context59.stop();
3817
5187
  }
3818
- }, _callee43, this, [[0, 8]]);
5188
+ }, _callee59, this, [[0, 8]]);
3819
5189
  }));
3820
- function removeProductsFromOrder(_x37) {
5190
+ function removeProductsFromOrder(_x53) {
3821
5191
  return _removeProductsFromOrder.apply(this, arguments);
3822
5192
  }
3823
5193
  return removeProductsFromOrder;
@@ -3825,18 +5195,18 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3825
5195
  }, {
3826
5196
  key: "removeProductFromOrder",
3827
5197
  value: function () {
3828
- var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee44(identity) {
3829
- return _regeneratorRuntime().wrap(function _callee44$(_context44) {
3830
- while (1) switch (_context44.prev = _context44.next) {
5198
+ var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee60(identity) {
5199
+ return _regeneratorRuntime().wrap(function _callee60$(_context60) {
5200
+ while (1) switch (_context60.prev = _context60.next) {
3831
5201
  case 0:
3832
- return _context44.abrupt("return", this.removeProductsFromOrder([identity]));
5202
+ return _context60.abrupt("return", this.removeProductsFromOrder([identity]));
3833
5203
  case 1:
3834
5204
  case "end":
3835
- return _context44.stop();
5205
+ return _context60.stop();
3836
5206
  }
3837
- }, _callee44, this);
5207
+ }, _callee60, this);
3838
5208
  }));
3839
- function removeProductFromOrder(_x38) {
5209
+ function removeProductFromOrder(_x54) {
3840
5210
  return _removeProductFromOrder.apply(this, arguments);
3841
5211
  }
3842
5212
  return removeProductFromOrder;
@@ -3886,23 +5256,23 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3886
5256
  }, {
3887
5257
  key: "applyPromotion",
3888
5258
  value: (function () {
3889
- var _applyPromotion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee45() {
3890
- return _regeneratorRuntime().wrap(function _callee45$(_context45) {
3891
- while (1) switch (_context45.prev = _context45.next) {
5259
+ var _applyPromotion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee61() {
5260
+ return _regeneratorRuntime().wrap(function _callee61$(_context61) {
5261
+ while (1) switch (_context61.prev = _context61.next) {
3892
5262
  case 0:
3893
5263
  if (this.store.order) {
3894
- _context45.next = 2;
5264
+ _context61.next = 2;
3895
5265
  break;
3896
5266
  }
3897
5267
  throw new Error('order 模块未初始化');
3898
5268
  case 2:
3899
- _context45.next = 4;
5269
+ _context61.next = 4;
3900
5270
  return this.store.order.applyPromotion();
3901
5271
  case 4:
3902
5272
  case "end":
3903
- return _context45.stop();
5273
+ return _context61.stop();
3904
5274
  }
3905
- }, _callee45, this);
5275
+ }, _callee61, this);
3906
5276
  }));
3907
5277
  function applyPromotion() {
3908
5278
  return _applyPromotion.apply(this, arguments);
@@ -3912,16 +5282,16 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3912
5282
  }, {
3913
5283
  key: "getUnfulfilledPromotions",
3914
5284
  value: function getUnfulfilledPromotions() {
3915
- var _this$store$order8;
3916
- return ((_this$store$order8 = this.store.order) === null || _this$store$order8 === void 0 ? void 0 : _this$store$order8.getUnfulfilledPromotions()) || [];
5285
+ var _this$store$order16;
5286
+ return ((_this$store$order16 = this.store.order) === null || _this$store$order16 === void 0 ? void 0 : _this$store$order16.getUnfulfilledPromotions()) || [];
3917
5287
  }
3918
5288
 
3919
5289
  /** 最近一次促销计算输出的赠品操作 diff。 */
3920
5290
  }, {
3921
5291
  key: "getLastGiftActions",
3922
5292
  value: function getLastGiftActions() {
3923
- var _this$store$order9;
3924
- return ((_this$store$order9 = this.store.order) === null || _this$store$order9 === void 0 ? void 0 : _this$store$order9.getLastGiftActions()) || null;
5293
+ var _this$store$order17;
5294
+ return ((_this$store$order17 = this.store.order) === null || _this$store$order17 === void 0 ? void 0 : _this$store$order17.getLastGiftActions()) || null;
3925
5295
  }
3926
5296
 
3927
5297
  // 获取商品列表
@@ -3929,18 +5299,18 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3929
5299
  }, {
3930
5300
  key: "getProductList",
3931
5301
  value: function () {
3932
- var _getProductList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee46() {
3933
- var _this$otherParams22;
5302
+ var _getProductList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee62() {
5303
+ var _this$otherParams28;
3934
5304
  var menu_list_ids, _this$store$products, res;
3935
- return _regeneratorRuntime().wrap(function _callee46$(_context46) {
3936
- while (1) switch (_context46.prev = _context46.next) {
5305
+ return _regeneratorRuntime().wrap(function _callee62$(_context62) {
5306
+ while (1) switch (_context62.prev = _context62.next) {
3937
5307
  case 0:
3938
5308
  // 可以直接通过配置里的 menu 读取
3939
- menu_list_ids = ((_this$otherParams22 = this.otherParams) === null || _this$otherParams22 === void 0 || (_this$otherParams22 = _this$otherParams22.dineInConfig) === null || _this$otherParams22 === void 0 ? void 0 : _this$otherParams22['menu.associated_menus'].map(function (n) {
5309
+ menu_list_ids = ((_this$otherParams28 = this.otherParams) === null || _this$otherParams28 === void 0 || (_this$otherParams28 = _this$otherParams28.dineInConfig) === null || _this$otherParams28 === void 0 ? void 0 : _this$otherParams28['menu.associated_menus'].map(function (n) {
3940
5310
  return Number(n.value);
3941
5311
  })) || [];
3942
- _context46.prev = 1;
3943
- _context46.next = 4;
5312
+ _context62.prev = 1;
5313
+ _context62.next = 4;
3944
5314
  return (_this$store$products = this.store.products) === null || _this$store$products === void 0 ? void 0 : _this$store$products.loadProducts({
3945
5315
  menu_list_ids: menu_list_ids,
3946
5316
  cacheId: this.cacheId,
@@ -3948,17 +5318,17 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3948
5318
  schedule_datetime: dayjs().format('YYYY-MM-DD HH:mm:ss')
3949
5319
  });
3950
5320
  case 4:
3951
- res = _context46.sent;
3952
- return _context46.abrupt("return", res);
5321
+ res = _context62.sent;
5322
+ return _context62.abrupt("return", res);
3953
5323
  case 8:
3954
- _context46.prev = 8;
3955
- _context46.t0 = _context46["catch"](1);
3956
- throw _context46.t0;
5324
+ _context62.prev = 8;
5325
+ _context62.t0 = _context62["catch"](1);
5326
+ throw _context62.t0;
3957
5327
  case 11:
3958
5328
  case "end":
3959
- return _context46.stop();
5329
+ return _context62.stop();
3960
5330
  }
3961
- }, _callee46, this, [[1, 8]]);
5331
+ }, _callee62, this, [[1, 8]]);
3962
5332
  }));
3963
5333
  function getProductList() {
3964
5334
  return _getProductList.apply(this, arguments);
@@ -3973,33 +5343,33 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3973
5343
  }, {
3974
5344
  key: "setOtherParams",
3975
5345
  value: function () {
3976
- var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee47(params) {
3977
- var _this$otherParams23;
3978
- var _ref30,
3979
- _ref30$cover,
5346
+ var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee63(params) {
5347
+ var _this$otherParams29;
5348
+ var _ref39,
5349
+ _ref39$cover,
3980
5350
  cover,
3981
- _args47 = arguments;
3982
- return _regeneratorRuntime().wrap(function _callee47$(_context47) {
3983
- while (1) switch (_context47.prev = _context47.next) {
5351
+ _args63 = arguments;
5352
+ return _regeneratorRuntime().wrap(function _callee63$(_context63) {
5353
+ while (1) switch (_context63.prev = _context63.next) {
3984
5354
  case 0:
3985
- _ref30 = _args47.length > 1 && _args47[1] !== undefined ? _args47[1] : {}, _ref30$cover = _ref30.cover, cover = _ref30$cover === void 0 ? false : _ref30$cover;
5355
+ _ref39 = _args63.length > 1 && _args63[1] !== undefined ? _args63[1] : {}, _ref39$cover = _ref39.cover, cover = _ref39$cover === void 0 ? false : _ref39$cover;
3986
5356
  if (cover) {
3987
5357
  this.otherParams = _objectSpread({}, params);
3988
5358
  } else {
3989
5359
  this.otherParams = _objectSpread(_objectSpread({}, this.otherParams), params);
3990
5360
  }
3991
- this.cacheId = (_this$otherParams23 = this.otherParams) === null || _this$otherParams23 === void 0 ? void 0 : _this$otherParams23.cacheId;
3992
- _context47.next = 5;
5361
+ this.cacheId = (_this$otherParams29 = this.otherParams) === null || _this$otherParams29 === void 0 ? void 0 : _this$otherParams29.cacheId;
5362
+ _context63.next = 5;
3993
5363
  return this.syncOtherParamsToSubModules(params, {
3994
5364
  cover: cover
3995
5365
  });
3996
5366
  case 5:
3997
5367
  case "end":
3998
- return _context47.stop();
5368
+ return _context63.stop();
3999
5369
  }
4000
- }, _callee47, this);
5370
+ }, _callee63, this);
4001
5371
  }));
4002
- function setOtherParams(_x39) {
5372
+ function setOtherParams(_x55) {
4003
5373
  return _setOtherParams.apply(this, arguments);
4004
5374
  }
4005
5375
  return setOtherParams;