@pisell/pisellos 0.10.2 → 0.10.3

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 (131) 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/BookingContext/utils/buildCacheItemFromOrderLine.js +5 -3
  14. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +6 -3
  15. package/dist/modules/OpenData/index.d.ts +2 -0
  16. package/dist/modules/OpenData/index.js +8 -0
  17. package/dist/modules/Order/index.d.ts +28 -8
  18. package/dist/modules/Order/index.js +818 -503
  19. package/dist/modules/Order/payment-utils.d.ts +26 -0
  20. package/dist/modules/Order/payment-utils.js +225 -0
  21. package/dist/modules/Order/types.d.ts +35 -1
  22. package/dist/modules/Order/utils/orderCollectionIdentity.js +7 -2
  23. package/dist/modules/Order/utils.js +10 -6
  24. package/dist/modules/Payment/index.d.ts +2 -0
  25. package/dist/modules/Payment/index.js +79 -50
  26. package/dist/modules/Payment/types.d.ts +107 -28
  27. package/dist/modules/Payment/types.js +20 -3
  28. package/dist/modules/Payment/walletpass.d.ts +38 -1
  29. package/dist/modules/Payment/walletpass.js +917 -114
  30. package/dist/modules/ProductList/index.js +1 -1
  31. package/dist/modules/Rules/index.d.ts +3 -0
  32. package/dist/modules/Rules/index.js +130 -99
  33. package/dist/server/index.d.ts +16 -0
  34. package/dist/server/index.js +2084 -1188
  35. package/dist/server/modules/index.d.ts +1 -1
  36. package/dist/server/modules/order/index.d.ts +70 -4
  37. package/dist/server/modules/order/index.js +1816 -728
  38. package/dist/server/modules/order/types.d.ts +25 -3
  39. package/dist/server/modules/order/types.js +7 -1
  40. package/dist/solution/BaseSales/index.d.ts +111 -13
  41. package/dist/solution/BaseSales/index.js +1799 -446
  42. package/dist/solution/BaseSales/types.d.ts +55 -1
  43. package/dist/solution/BaseSales/types.js +2 -1
  44. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +3 -1
  45. package/dist/solution/BaseSales/utils/cartPromotion.js +90 -31
  46. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +6 -1
  47. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +6 -3
  48. package/dist/solution/BookingByStep/index.d.ts +1 -1
  49. package/dist/solution/BookingTicket/index.d.ts +7 -3
  50. package/dist/solution/BookingTicket/index.js +138 -52
  51. package/dist/solution/BookingTicket/types.d.ts +1 -0
  52. package/dist/solution/BookingTicket/utils/addProductDecision.js +6 -0
  53. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +8 -0
  54. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +173 -83
  55. package/dist/solution/BookingTicket/utils/weighingProductSku.d.ts +5 -0
  56. package/dist/solution/BookingTicket/utils/weighingProductSku.js +45 -0
  57. package/dist/solution/Sales/index.d.ts +1 -0
  58. package/dist/solution/Sales/index.js +10 -2
  59. package/dist/solution/ScanOrder/index.js +31 -20
  60. package/dist/solution/UnifiedBookingSales/index.js +23 -3
  61. package/dist/solution/VenueBooking/index.d.ts +1 -0
  62. package/dist/solution/VenueBooking/index.js +34 -24
  63. package/dist/types/index.d.ts +1 -0
  64. package/dist/utils/payment-number.d.ts +9 -0
  65. package/dist/utils/payment-number.js +69 -0
  66. package/lib/core/index.d.ts +2 -0
  67. package/lib/core/index.js +4 -0
  68. package/lib/model/strategy/adapter/promotion/adapter.d.ts +4 -0
  69. package/lib/model/strategy/adapter/promotion/adapter.js +20 -0
  70. package/lib/model/strategy/adapter/promotion/evaluator.d.ts +17 -0
  71. package/lib/model/strategy/adapter/promotion/evaluator.js +235 -0
  72. package/lib/model/strategy/adapter/promotion/examples.d.ts +86 -0
  73. package/lib/model/strategy/adapter/promotion/examples.js +91 -0
  74. package/lib/model/strategy/adapter/promotion/index.d.ts +1 -1
  75. package/lib/model/strategy/adapter/promotion/index.js +0 -49
  76. package/lib/model/strategy/adapter/promotion/type.d.ts +90 -2
  77. package/lib/model/strategy/adapter/promotion/type.js +2 -0
  78. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +2 -1
  79. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +2 -1
  80. package/lib/modules/OpenData/index.d.ts +2 -0
  81. package/lib/modules/OpenData/index.js +5 -0
  82. package/lib/modules/Order/index.d.ts +28 -8
  83. package/lib/modules/Order/index.js +233 -68
  84. package/lib/modules/Order/payment-utils.d.ts +26 -0
  85. package/lib/modules/Order/payment-utils.js +224 -0
  86. package/lib/modules/Order/types.d.ts +35 -1
  87. package/lib/modules/Order/utils/orderCollectionIdentity.js +3 -0
  88. package/lib/modules/Order/utils.js +11 -4
  89. package/lib/modules/Payment/index.d.ts +2 -0
  90. package/lib/modules/Payment/index.js +34 -13
  91. package/lib/modules/Payment/types.d.ts +107 -28
  92. package/lib/modules/Payment/types.js +4 -3
  93. package/lib/modules/Payment/walletpass.d.ts +38 -1
  94. package/lib/modules/Payment/walletpass.js +730 -21
  95. package/lib/modules/ProductList/index.js +9 -1
  96. package/lib/modules/Rules/index.d.ts +3 -0
  97. package/lib/modules/Rules/index.js +39 -10
  98. package/lib/server/index.d.ts +16 -0
  99. package/lib/server/index.js +677 -28
  100. package/lib/server/modules/index.d.ts +1 -1
  101. package/lib/server/modules/order/index.d.ts +70 -4
  102. package/lib/server/modules/order/index.js +818 -69
  103. package/lib/server/modules/order/types.d.ts +25 -3
  104. package/lib/server/modules/order/types.js +1 -0
  105. package/lib/solution/BaseSales/index.d.ts +111 -13
  106. package/lib/solution/BaseSales/index.js +882 -46
  107. package/lib/solution/BaseSales/types.d.ts +55 -1
  108. package/lib/solution/BaseSales/types.js +2 -1
  109. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +3 -1
  110. package/lib/solution/BaseSales/utils/cartPromotion.js +63 -12
  111. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +6 -1
  112. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +3 -2
  113. package/lib/solution/BookingByStep/index.d.ts +1 -1
  114. package/lib/solution/BookingTicket/index.d.ts +7 -3
  115. package/lib/solution/BookingTicket/index.js +63 -9
  116. package/lib/solution/BookingTicket/types.d.ts +1 -0
  117. package/lib/solution/BookingTicket/utils/addProductDecision.js +4 -0
  118. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +8 -0
  119. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +37 -5
  120. package/lib/solution/BookingTicket/utils/weighingProductSku.d.ts +5 -0
  121. package/lib/solution/BookingTicket/utils/weighingProductSku.js +63 -0
  122. package/lib/solution/Sales/index.d.ts +1 -0
  123. package/lib/solution/Sales/index.js +5 -3
  124. package/lib/solution/ScanOrder/index.js +8 -0
  125. package/lib/solution/UnifiedBookingSales/index.js +10 -2
  126. package/lib/solution/VenueBooking/index.d.ts +1 -0
  127. package/lib/solution/VenueBooking/index.js +13 -6
  128. package/lib/types/index.d.ts +1 -0
  129. package/lib/utils/payment-number.d.ts +9 -0
  130. package/lib/utils/payment-number.js +64 -0
  131. 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, {
@@ -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) {
@@ -564,7 +721,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
564
721
  }, _callee4);
565
722
  }));
566
723
  return function hydrateTask() {
567
- return _ref3.apply(this, arguments);
724
+ return _ref10.apply(this, arguments);
568
725
  };
569
726
  }();
570
727
  queuedTask = this.salesDetailHydrateQueue.then(hydrateTask, hydrateTask);
@@ -658,10 +815,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
658
815
  });
659
816
  }
660
817
  quotation.setScheduleResolver(function (id) {
661
- var _scheduleModule$getSc, _getScheduleByIds, _ref4;
818
+ var _scheduleModule$getSc, _getScheduleByIds, _ref11;
662
819
  var scheduleId = String(id);
663
820
  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])) || [];
821
+ 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
822
  if (schedules[0]) scheduleById.set(scheduleId, schedules[0]);
666
823
  return schedules[0];
667
824
  });
@@ -848,10 +1005,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
848
1005
  return groups.flatMap(function (group) {
849
1006
  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
1007
  return items.map(function (item) {
851
- var _item$group_id, _ref5, _item$bundle_group_id;
1008
+ var _item$group_id, _ref12, _item$bundle_group_id;
852
1009
  return _objectSpread(_objectSpread({}, item), {}, {
853
1010
  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
1011
+ 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
1012
  });
856
1013
  });
857
1014
  });
@@ -882,21 +1039,21 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
882
1039
  }, {
883
1040
  key: "getAuthoritativeBundleUnitPrice",
884
1041
  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;
1042
+ var _ref13, _ref14, _ref15, _bundle$price;
1043
+ 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
1044
  }
888
1045
  }, {
889
1046
  key: "mergeProductForPriceQuery",
890
1047
  value: function mergeProductForPriceQuery(product, authoritativeProduct) {
891
1048
  var _this5 = this,
892
1049
  _product$id,
893
- _ref9,
1050
+ _ref16,
894
1051
  _product$product_id2,
895
- _ref10,
1052
+ _ref17,
896
1053
  _product$product_vari,
897
- _ref11,
1054
+ _ref18,
898
1055
  _product$num,
899
- _ref12,
1056
+ _ref19,
900
1057
  _product$quantity,
901
1058
  _product$metadata4;
902
1059
  if (!authoritativeProduct) return product;
@@ -916,10 +1073,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
916
1073
  });
917
1074
  return _objectSpread(_objectSpread(_objectSpread({}, product), authoritativeProduct), {}, {
918
1075
  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,
1076
+ 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,
1077
+ 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,
1078
+ num: (_ref18 = (_product$num = product.num) !== null && _product$num !== void 0 ? _product$num : product.quantity) !== null && _ref18 !== void 0 ? _ref18 : authoritativeProduct.num,
1079
+ quantity: (_ref19 = (_product$quantity = product.quantity) !== null && _product$quantity !== void 0 ? _product$quantity : product.num) !== null && _ref19 !== void 0 ? _ref19 : authoritativeProduct.quantity,
923
1080
  product_sku: function () {
924
1081
  var authoritativeSku = ensureProductSku(authoritativeProduct);
925
1082
  var productSku = ensureProductSku(product);
@@ -995,24 +1152,24 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
995
1152
  value: (function () {
996
1153
  var _syncOtherParamsToSubModules = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(changedParams) {
997
1154
  var _this6 = this;
998
- var _ref13,
999
- _ref13$cover,
1155
+ var _ref20,
1156
+ _ref20$cover,
1000
1157
  cover,
1001
1158
  nextSubModuleOtherParams,
1002
1159
  _args10 = arguments;
1003
1160
  return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1004
1161
  while (1) switch (_context10.prev = _context10.next) {
1005
1162
  case 0:
1006
- _ref13 = _args10.length > 1 && _args10[1] !== undefined ? _args10[1] : {}, _ref13$cover = _ref13.cover, cover = _ref13$cover === void 0 ? false : _ref13$cover;
1163
+ _ref20 = _args10.length > 1 && _args10[1] !== undefined ? _args10[1] : {}, _ref20$cover = _ref20.cover, cover = _ref20$cover === void 0 ? false : _ref20$cover;
1007
1164
  nextSubModuleOtherParams = this.buildSubModuleOtherParams();
1008
1165
  _context10.next = 4;
1009
1166
  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;
1167
+ var _ref22 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(_ref21) {
1168
+ var _ref23, moduleName, subModule, targetModule;
1012
1169
  return _regeneratorRuntime().wrap(function _callee9$(_context9) {
1013
1170
  while (1) switch (_context9.prev = _context9.next) {
1014
1171
  case 0:
1015
- _ref16 = _slicedToArray(_ref14, 2), moduleName = _ref16[0], subModule = _ref16[1];
1172
+ _ref23 = _slicedToArray(_ref21, 2), moduleName = _ref23[0], subModule = _ref23[1];
1016
1173
  if (!_this6.reusedSharedSubModuleNames.has(moduleName)) {
1017
1174
  _context9.next = 3;
1018
1175
  break;
@@ -1038,7 +1195,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1038
1195
  }, _callee9);
1039
1196
  }));
1040
1197
  return function (_x9) {
1041
- return _ref15.apply(this, arguments);
1198
+ return _ref22.apply(this, arguments);
1042
1199
  };
1043
1200
  }()));
1044
1201
  case 4:
@@ -1066,7 +1223,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1066
1223
  if (!sessionData) return {};
1067
1224
  var data = JSON.parse(sessionData);
1068
1225
  return data && data[this.cacheId] || {};
1069
- } catch (_unused) {
1226
+ } catch (_unused3) {
1070
1227
  return {};
1071
1228
  }
1072
1229
  }
@@ -1080,6 +1237,38 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1080
1237
  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
1238
  return coreData === null || coreData === void 0 ? void 0 : coreData[key];
1082
1239
  }
1240
+
1241
+ /**
1242
+ * 复用业务解决方案初始化时已解析的支付设备短号。
1243
+ * 空值会清除缓存,使后续支付恢复实时读取设备信息的兼容路径。
1244
+ */
1245
+ }, {
1246
+ key: "setPaymentNumberDevicePrefix",
1247
+ value: function setPaymentNumberDevicePrefix(prefix) {
1248
+ var normalized = String(prefix !== null && prefix !== void 0 ? prefix : '').trim();
1249
+ this.paymentNumberDevicePrefix = normalized || null;
1250
+ }
1251
+ }, {
1252
+ key: "getPaymentNumberDevicePrefixSync",
1253
+ value: function getPaymentNumberDevicePrefixSync() {
1254
+ var _this7 = this;
1255
+ if (!this.appPlugin) return 'LOCAL';
1256
+ return resolvePaymentNumberDevicePrefixFromDeviceId(function (key) {
1257
+ return _this7.getAppData(key);
1258
+ });
1259
+ }
1260
+ }, {
1261
+ key: "getPaymentNumberDevicePrefixAsync",
1262
+ value: function getPaymentNumberDevicePrefixAsync() {
1263
+ var _this8 = this;
1264
+ if (!this.appPlugin) return Promise.resolve('LOCAL');
1265
+ if (this.paymentNumberDevicePrefix) {
1266
+ return Promise.resolve(this.paymentNumberDevicePrefix);
1267
+ }
1268
+ return resolvePaymentNumberDevicePrefix(function (key) {
1269
+ return _this8.getAppData(key);
1270
+ });
1271
+ }
1083
1272
  }, {
1084
1273
  key: "syncAppDataToTempOrder",
1085
1274
  value: function syncAppDataToTempOrder(tempOrder) {
@@ -1125,7 +1314,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1125
1314
  var _this$otherParams4,
1126
1315
  _this$appPlugin2,
1127
1316
  _this$appPlugin2$getA,
1128
- _this7 = this,
1317
+ _this9 = this,
1129
1318
  _this$otherParams5;
1130
1319
  var options,
1131
1320
  app,
@@ -1138,6 +1327,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1138
1327
  options = _args11.length > 1 && _args11[1] !== undefined ? _args11[1] : {};
1139
1328
  this.core = core;
1140
1329
  this.initializeOptions = options || {};
1330
+ this.paymentNumberDevicePrefix = null;
1141
1331
  // this.store = { ...this.store, ...(options.store as Partial<BaseSalesState>) };
1142
1332
  this.otherParams = options.otherParams || {};
1143
1333
  this.cacheId = (_this$otherParams4 = this.otherParams) === null || _this$otherParams4 === void 0 ? void 0 : _this$otherParams4.cacheId;
@@ -1155,42 +1345,42 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1155
1345
  targetCacheData = this.readSessionCacheData();
1156
1346
  moduleNames = this.getRegisteredModuleNames();
1157
1347
  moduleNames.forEach(function (step) {
1158
- var reusedModule = _this7.getReusableSharedSubModule(step);
1348
+ var reusedModule = _this9.getReusableSharedSubModule(step);
1159
1349
  if (reusedModule) {
1160
- _this7.store[step] = reusedModule;
1161
- _this7.reusedSharedSubModuleNames.add(step);
1350
+ _this9.store[step] = reusedModule;
1351
+ _this9.reusedSharedSubModuleNames.add(step);
1162
1352
  return;
1163
1353
  }
1164
- var targetModule = _this7.createSubModule(step);
1354
+ var targetModule = _this9.createSubModule(step);
1165
1355
  if (!targetModule) {
1166
1356
  throw new Error("\u6A21\u5757 ".concat(step, " \u4E0D\u5B58\u5728"));
1167
1357
  }
1168
- var hooks = _this7.getSubModuleHooks(step);
1169
- _this7.store[step] = targetModule;
1170
- _this7.core.registerModule(targetModule, _objectSpread(_objectSpread({
1358
+ var hooks = _this9.getSubModuleHooks(step);
1359
+ _this9.store[step] = targetModule;
1360
+ _this9.core.registerModule(targetModule, _objectSpread(_objectSpread({
1171
1361
  initialState: (targetCacheData === null || targetCacheData === void 0 ? void 0 : targetCacheData[targetModule.name]) || {}
1172
1362
  }, hooks ? {
1173
1363
  hooks: hooks
1174
1364
  } : {}), {}, {
1175
- otherParams: _this7.buildSubModuleOtherParams()
1365
+ otherParams: _this9.buildSubModuleOtherParams()
1176
1366
  }));
1177
1367
  });
1178
1368
  if (!(this.store.schedule && !this.isScheduleListLoaded(this.store.schedule))) {
1179
- _context11.next = 18;
1369
+ _context11.next = 19;
1180
1370
  break;
1181
1371
  }
1182
- _context11.next = 18;
1372
+ _context11.next = 19;
1183
1373
  return this.store.schedule.loadAllSchedule();
1184
- case 18:
1374
+ case 19:
1185
1375
  if (this.store.order && typeof ((_this$otherParams5 = this.otherParams) === null || _this$otherParams5 === void 0 ? void 0 : _this$otherParams5.enableTempOrderPersist) === 'boolean') {
1186
1376
  this.store.order.setEnableTempOrderPersist(this.otherParams.enableTempOrderPersist);
1187
1377
  }
1188
- _context11.next = 21;
1378
+ _context11.next = 22;
1189
1379
  return this.getPaymentMethodsAsync();
1190
- case 21:
1380
+ case 22:
1191
1381
  this.registerServerOrderChangeSync();
1192
1382
  this.core.effects.emit("".concat(this.name, ":onInited"), {});
1193
- case 23:
1383
+ case 24:
1194
1384
  case "end":
1195
1385
  return _context11.stop();
1196
1386
  }
@@ -1206,15 +1396,15 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1206
1396
  value: function () {
1207
1397
  var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
1208
1398
  var _this$serverOrderChan2,
1209
- _this8 = this;
1399
+ _this10 = this;
1210
1400
  return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1211
1401
  while (1) switch (_context12.prev = _context12.next) {
1212
1402
  case 0:
1213
1403
  (_this$serverOrderChan2 = this.serverOrderChangeUnsubscribe) === null || _this$serverOrderChan2 === void 0 || _this$serverOrderChan2.call(this);
1214
1404
  this.serverOrderChangeUnsubscribe = null;
1215
1405
  Object.keys(this.store).forEach(function (key) {
1216
- if (_this8.reusedSharedSubModuleNames.has(key)) return;
1217
- var sub = _this8.store[key];
1406
+ if (_this10.reusedSharedSubModuleNames.has(key)) return;
1407
+ var sub = _this10.store[key];
1218
1408
  if (sub && typeof sub.destroy === 'function') {
1219
1409
  try {
1220
1410
  sub.destroy();
@@ -1224,13 +1414,15 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1224
1414
  }
1225
1415
  });
1226
1416
  this.currentSalesDetail = null;
1417
+ this.paymentNumberDevicePrefix = null;
1227
1418
  this.queuedServerOrderChanges = [];
1228
1419
  this.salesDetailLoadSequence += 1;
1229
- _context12.next = 8;
1420
+ this.walletAssetsRefreshSequence += 1;
1421
+ _context12.next = 10;
1230
1422
  return this.core.effects.emit("".concat(this.name, ":onDestroy"), {});
1231
- case 8:
1423
+ case 10:
1232
1424
  _get(_getPrototypeOf(BaseSalesImpl.prototype), "destroy", this).call(this);
1233
- case 9:
1425
+ case 11:
1234
1426
  case "end":
1235
1427
  return _context12.stop();
1236
1428
  }
@@ -1252,7 +1444,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1252
1444
  key: "loadSalesDetail",
1253
1445
  value: (function () {
1254
1446
  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;
1447
+ var loadSequence, _ref24, _ref25, _ref26, _ref27, _params$orderId, params, externalSaleNumber, preloadedSalesDetail, lookup, loadedRecord, message, remoteRecord, currentTempOrder, mergedRecord, record;
1256
1448
  return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1257
1449
  while (1) switch (_context13.prev = _context13.next) {
1258
1450
  case 0:
@@ -1270,7 +1462,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1270
1462
  };
1271
1463
  externalSaleNumber = params.externalSaleNumber || params.external_sale_number;
1272
1464
  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;
1465
+ 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
1466
  if (!(!preloadedSalesDetail && (lookup === undefined || lookup === null || lookup === ''))) {
1275
1467
  _context13.next = 11;
1276
1468
  break;
@@ -1301,39 +1493,40 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1301
1493
  message = loadedRecord && (loadedRecord.message || loadedRecord.msg) || "\u52A0\u8F7D\u9500\u552E\u8BE6\u60C5\u5931\u8D25: ".concat(lookup);
1302
1494
  throw new Error(message);
1303
1495
  case 22:
1304
- remoteRecord = preloadedSalesDetail !== null && preloadedSalesDetail !== void 0 ? preloadedSalesDetail : loadedRecord.data;
1496
+ remoteRecord = filterPendingPaymentsFromLoadedSalesDetail(preloadedSalesDetail !== null && preloadedSalesDetail !== void 0 ? preloadedSalesDetail : loadedRecord.data);
1305
1497
  currentTempOrder = params.merge ? this.store.order.getTempOrder() : null;
1306
- record = params.merge ? mergeSalesDetailRecordWithTempOrder(currentTempOrder, remoteRecord, 'preserve-local') : remoteRecord;
1307
- _context13.next = 27;
1498
+ mergedRecord = params.merge ? mergeSalesDetailRecordWithTempOrder(currentTempOrder, remoteRecord, 'preserve-local') : remoteRecord;
1499
+ record = filterPendingPaymentsFromLoadedSalesDetail(mergedRecord);
1500
+ _context13.next = 28;
1308
1501
  return this.hydrateLatestLoadedSalesDetail(record, loadSequence);
1309
- case 27:
1310
- return _context13.abrupt("return", _context13.sent);
1311
1502
  case 28:
1312
- _context13.prev = 28;
1503
+ return _context13.abrupt("return", _context13.sent);
1504
+ case 29:
1505
+ _context13.prev = 29;
1313
1506
  this.salesDetailLoadInFlightCount = Math.max(0, this.salesDetailLoadInFlightCount - 1);
1314
1507
  if (!(this.salesDetailLoadInFlightCount === 0)) {
1315
- _context13.next = 39;
1508
+ _context13.next = 40;
1316
1509
  break;
1317
1510
  }
1318
- _context13.prev = 31;
1319
- _context13.next = 34;
1511
+ _context13.prev = 32;
1512
+ _context13.next = 35;
1320
1513
  return this.drainQueuedServerOrderChanges();
1321
- case 34:
1322
- _context13.next = 39;
1514
+ case 35:
1515
+ _context13.next = 40;
1323
1516
  break;
1324
- case 36:
1325
- _context13.prev = 36;
1326
- _context13.t1 = _context13["catch"](31);
1517
+ case 37:
1518
+ _context13.prev = 37;
1519
+ _context13.t1 = _context13["catch"](32);
1327
1520
  this.logError('drain queued server order changes failed', {
1328
1521
  error: _context13.t1 instanceof Error ? _context13.t1.message : String(_context13.t1)
1329
1522
  });
1330
- case 39:
1331
- return _context13.finish(28);
1332
1523
  case 40:
1524
+ return _context13.finish(29);
1525
+ case 41:
1333
1526
  case "end":
1334
1527
  return _context13.stop();
1335
1528
  }
1336
- }, _callee13, this, [[4,, 28, 40], [31, 36]]);
1529
+ }, _callee13, this, [[4,, 29, 41], [32, 37]]);
1337
1530
  }));
1338
1531
  function loadSalesDetail(_x11) {
1339
1532
  return _loadSalesDetail.apply(this, arguments);
@@ -1610,7 +1803,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1610
1803
  key: "restoreOrder",
1611
1804
  value: function () {
1612
1805
  var _restoreOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
1613
- var tempOrder;
1806
+ var _this$store$payment, tempOrder, wallet;
1614
1807
  return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1615
1808
  while (1) switch (_context17.prev = _context17.next) {
1616
1809
  case 0:
@@ -1626,29 +1819,39 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1626
1819
  this.currentSalesDetail = null;
1627
1820
  this.discountConfigCacheKey = null;
1628
1821
  this.hasManualDiscountSelection = false;
1629
- _context17.next = 9;
1822
+ wallet = (_this$store$payment = this.store.payment) === null || _this$store$payment === void 0 ? void 0 : _this$store$payment.wallet;
1823
+ if (!wallet) {
1824
+ _context17.next = 13;
1825
+ break;
1826
+ }
1827
+ this.walletAssetsRefreshSequence += 1;
1828
+ wallet.clearAllCache();
1829
+ _context17.next = 13;
1830
+ return this.publishWalletAssetsState(wallet.getWalletAssetsState());
1831
+ case 13:
1832
+ _context17.next = 15;
1630
1833
  return this.effectsEmit('onTempOrderReplaced', {
1631
1834
  tempOrder: tempOrder
1632
1835
  });
1633
- case 9:
1836
+ case 15:
1634
1837
  if (!(this.syncAppDataToTempOrder(tempOrder) && this.isTempOrderPersistEnabled())) {
1635
- _context17.next = 13;
1838
+ _context17.next = 19;
1636
1839
  break;
1637
1840
  }
1638
1841
  this.store.order.persistTempOrder();
1639
- _context17.next = 13;
1842
+ _context17.next = 19;
1640
1843
  return this.store.order.saveDraft();
1641
- case 13:
1844
+ case 19:
1642
1845
  return _context17.abrupt("return", tempOrder);
1643
- case 16:
1644
- _context17.prev = 16;
1846
+ case 22:
1847
+ _context17.prev = 22;
1645
1848
  _context17.t0 = _context17["catch"](0);
1646
1849
  throw _context17.t0;
1647
- case 19:
1850
+ case 25:
1648
1851
  case "end":
1649
1852
  return _context17.stop();
1650
1853
  }
1651
- }, _callee17, this, [[0, 16]]);
1854
+ }, _callee17, this, [[0, 22]]);
1652
1855
  }));
1653
1856
  function restoreOrder() {
1654
1857
  return _restoreOrder.apply(this, arguments);
@@ -1761,10 +1964,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1761
1964
  }, {
1762
1965
  key: "getHistoricalProductDiscountList",
1763
1966
  value: function getHistoricalProductDiscountList(products) {
1764
- var _this9 = this;
1967
+ var _this11 = this;
1765
1968
  var historyDiscountList = [];
1766
1969
  products.forEach(function (item) {
1767
- if (!_this9.isPersistedOrderProduct(item)) return;
1970
+ if (!_this11.isPersistedOrderProduct(item)) return;
1768
1971
  (item.discount_list || []).forEach(function (discount) {
1769
1972
  var _discount$discount, _discount$metadata, _discount$discount2, _discount$discount3, _discount$discount4;
1770
1973
  var discountId = ((_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) || discount.id;
@@ -1824,11 +2027,11 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1824
2027
  }, {
1825
2028
  key: "shouldSkipAutoApplyFetchedDiscountsInEditMode",
1826
2029
  value: function shouldSkipAutoApplyFetchedDiscountsInEditMode(params) {
1827
- var _this10 = this;
2030
+ var _this12 = this;
1828
2031
  if (params.discountAction !== 'edit') return false;
1829
2032
  if (!params.products.length) return false;
1830
2033
  var hasDraftProduct = params.products.some(function (product) {
1831
- return !_this10.isPersistedOrderProduct(product);
2034
+ return !_this12.isPersistedOrderProduct(product);
1832
2035
  });
1833
2036
  if (hasDraftProduct) return false;
1834
2037
  var hasSelectedDiscount = params.currentDiscountList.some(function (discount) {
@@ -2276,12 +2479,15 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2276
2479
  tempOrder: tempOrder
2277
2480
  });
2278
2481
  case 13:
2279
- return _context23.abrupt("return", {
2280
- isAvailable: raw.isAvailable,
2482
+ return _context23.abrupt("return", _objectSpread(_objectSpread({
2483
+ isAvailable: raw.isAvailable
2484
+ }, raw.isAccepted !== undefined ? {
2485
+ isAccepted: raw.isAccepted
2486
+ } : {}), {}, {
2281
2487
  type: raw.type,
2282
2488
  unavailableReason: raw.unavailableReason,
2283
2489
  scannedDiscountList: raw.scannedDiscountList
2284
- });
2490
+ }));
2285
2491
  case 16:
2286
2492
  _context23.prev = 16;
2287
2493
  _context23.t0 = _context23["catch"](0);
@@ -2407,10 +2613,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2407
2613
  product.discount_list = filterSelectedDiscountDetails(product.discount_list);
2408
2614
  if (Array.isArray(product.product_bundle)) {
2409
2615
  product.product_bundle = product.product_bundle.map(function (bundle) {
2410
- var _ref21, _bundle$original_pric;
2616
+ var _ref28, _bundle$original_pric;
2411
2617
  var nextBundleDiscountList = filterSelectedDiscountDetails(bundle === null || bundle === void 0 ? void 0 : bundle.discount_list);
2412
2618
  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;
2619
+ 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
2620
  return _objectSpread(_objectSpread(_objectSpread({}, bundle), shouldRestoreBundlePrice ? {
2415
2621
  price: restoredBundlePrice,
2416
2622
  bundle_selling_price: restoredBundlePrice
@@ -2632,11 +2838,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2632
2838
  return submitSalesOrder;
2633
2839
  }())
2634
2840
  }, {
2635
- key: "submitTempOrderAsync",
2841
+ key: "saveSalesOrderDraft",
2636
2842
  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;
2843
+ var _saveSalesOrderDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(params) {
2844
+ var _params$platform, _this$otherParams10, _this$otherParams11, _this$otherParams12, _params$channel, _params$type, _this$otherParams13;
2640
2845
  return _regeneratorRuntime().wrap(function _callee28$(_context28) {
2641
2846
  while (1) switch (_context28.prev = _context28.next) {
2642
2847
  case 0:
@@ -2645,15 +2850,50 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2645
2850
  break;
2646
2851
  }
2647
2852
  throw new Error('BaseSales 解决方案需要 order 模块支持');
2853
+ case 2:
2854
+ return _context28.abrupt("return", this.store.order.saveTempOrderAsDraft(_objectSpread({
2855
+ cacheId: this.cacheId,
2856
+ 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,
2857
+ 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),
2858
+ channel: (_params$channel = params === null || params === void 0 ? void 0 : params.channel) !== null && _params$channel !== void 0 ? _params$channel : this.getSubmitOrderSalesChannel(),
2859
+ 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
2860
+ }, (params === null || params === void 0 ? void 0 : params.enhancePayload) !== undefined ? {
2861
+ enhancePayload: params.enhancePayload
2862
+ } : {})));
2863
+ case 3:
2864
+ case "end":
2865
+ return _context28.stop();
2866
+ }
2867
+ }, _callee28, this);
2868
+ }));
2869
+ function saveSalesOrderDraft(_x22) {
2870
+ return _saveSalesOrderDraft.apply(this, arguments);
2871
+ }
2872
+ return saveSalesOrderDraft;
2873
+ }()
2874
+ }, {
2875
+ key: "submitTempOrderAsync",
2876
+ value: function () {
2877
+ var _submitTempOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(params) {
2878
+ var _params$smallTicketDa2, _this$otherParams14, _this$otherParams15, _this$otherParams16, _this$otherParams17;
2879
+ var inferredPaymentStatus, smallTicketDataFlag, submitParams;
2880
+ return _regeneratorRuntime().wrap(function _callee29$(_context29) {
2881
+ while (1) switch (_context29.prev = _context29.next) {
2882
+ case 0:
2883
+ if (this.store.order) {
2884
+ _context29.next = 2;
2885
+ break;
2886
+ }
2887
+ throw new Error('BaseSales 解决方案需要 order 模块支持');
2648
2888
  case 2:
2649
2889
  inferredPaymentStatus = this.getSubmitPaymentStatus(params === null || params === void 0 ? void 0 : params.paymentStatus);
2650
2890
  smallTicketDataFlag = (_params$smallTicketDa2 = params === null || params === void 0 ? void 0 : params.smallTicketDataFlag) !== null && _params$smallTicketDa2 !== void 0 ? _params$smallTicketDa2 : this.getDefaultCheckoutSmallTicketDataFlag();
2651
2891
  submitParams = _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
2652
2892
  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),
2893
+ platform: (_this$otherParams14 = this.otherParams) === null || _this$otherParams14 === void 0 ? void 0 : _this$otherParams14.platform,
2894
+ 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
2895
  channel: this.getSubmitOrderSalesChannel(),
2656
- type: (_this$otherParams13 = this.otherParams) === null || _this$otherParams13 === void 0 ? void 0 : _this$otherParams13.type,
2896
+ type: (_this$otherParams17 = this.otherParams) === null || _this$otherParams17 === void 0 ? void 0 : _this$otherParams17.type,
2657
2897
  request_unique_idempotency_token: this.store.order.generateIdempotencyToken()
2658
2898
  }, (params === null || params === void 0 ? void 0 : params.payments) !== undefined ? {
2659
2899
  payments: params.payments
@@ -2666,14 +2906,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2666
2906
  } : {}), (params === null || params === void 0 ? void 0 : params.enhancePayload) !== undefined ? {
2667
2907
  enhancePayload: params.enhancePayload
2668
2908
  } : {});
2669
- return _context28.abrupt("return", this.store.order.submitTempOrderAsync(submitParams));
2909
+ return _context29.abrupt("return", this.store.order.submitTempOrderAsync(submitParams));
2670
2910
  case 6:
2671
2911
  case "end":
2672
- return _context28.stop();
2912
+ return _context29.stop();
2673
2913
  }
2674
- }, _callee28, this);
2914
+ }, _callee29, this);
2675
2915
  }));
2676
- function submitTempOrderAsync(_x22) {
2916
+ function submitTempOrderAsync(_x23) {
2677
2917
  return _submitTempOrderAsync.apply(this, arguments);
2678
2918
  }
2679
2919
  return submitTempOrderAsync;
@@ -2685,8 +2925,8 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2685
2925
  }, {
2686
2926
  key: "shouldUseCheckoutSyncTask",
2687
2927
  value: function shouldUseCheckoutSyncTask() {
2688
- var _this$otherParams14;
2689
- var configured = (_this$otherParams14 = this.otherParams) === null || _this$otherParams14 === void 0 ? void 0 : _this$otherParams14.checkoutSyncTaskEnabled;
2928
+ var _this$otherParams18;
2929
+ var configured = (_this$otherParams18 = this.otherParams) === null || _this$otherParams18 === void 0 ? void 0 : _this$otherParams18.checkoutSyncTaskEnabled;
2690
2930
  return typeof configured === 'boolean' ? configured : true;
2691
2931
  }
2692
2932
 
@@ -2699,14 +2939,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2699
2939
  }, {
2700
2940
  key: "printLocalOrderReceipt",
2701
2941
  value: function () {
2702
- var _printLocalOrderReceipt = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(lookup) {
2703
- var _this$otherParams15, _this$otherParams16, _this$otherParams17, _this$otherParams18;
2942
+ var _printLocalOrderReceipt = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(lookup) {
2943
+ var _this$otherParams19, _this$otherParams20, _this$otherParams21, _this$otherParams22;
2704
2944
  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) {
2945
+ return _regeneratorRuntime().wrap(function _callee30$(_context30) {
2946
+ while (1) switch (_context30.prev = _context30.next) {
2707
2947
  case 0:
2708
2948
  if (this.store.order) {
2709
- _context29.next = 2;
2949
+ _context30.next = 2;
2710
2950
  break;
2711
2951
  }
2712
2952
  throw new Error('BaseSales 解决方案需要 order 模块支持');
@@ -2718,10 +2958,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2718
2958
  external_sale_number: lookup
2719
2959
  };
2720
2960
  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),
2961
+ platform: (_this$otherParams19 = this.otherParams) === null || _this$otherParams19 === void 0 ? void 0 : _this$otherParams19.platform,
2962
+ 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
2963
  channel: this.getSubmitOrderSalesChannel(),
2724
- type: (_this$otherParams18 = this.otherParams) === null || _this$otherParams18 === void 0 ? void 0 : _this$otherParams18.type
2964
+ type: (_this$otherParams22 = this.otherParams) === null || _this$otherParams22 === void 0 ? void 0 : _this$otherParams22.type
2725
2965
  };
2726
2966
  payload = hasLookup ? _objectSpread(_objectSpread({}, lookupPayload), {}, {
2727
2967
  lookup_order_from_db: 1,
@@ -2737,28 +2977,28 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2737
2977
  channel: context.channel,
2738
2978
  type: context.type
2739
2979
  });
2740
- _context29.next = 8;
2980
+ _context30.next = 8;
2741
2981
  return this.request.post('/local/print-order', payload, {
2742
2982
  osServer: true,
2743
2983
  customToast: function customToast() {}
2744
2984
  });
2745
2985
  case 8:
2746
- response = _context29.sent;
2986
+ response = _context30.sent;
2747
2987
  if (hasLookup) {
2748
- _context29.next = 12;
2988
+ _context30.next = 12;
2749
2989
  break;
2750
2990
  }
2751
- _context29.next = 12;
2991
+ _context30.next = 12;
2752
2992
  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
2993
  case 12:
2754
- return _context29.abrupt("return", response);
2994
+ return _context30.abrupt("return", response);
2755
2995
  case 13:
2756
2996
  case "end":
2757
- return _context29.stop();
2997
+ return _context30.stop();
2758
2998
  }
2759
- }, _callee29, this);
2999
+ }, _callee30, this);
2760
3000
  }));
2761
- function printLocalOrderReceipt(_x23) {
3001
+ function printLocalOrderReceipt(_x24) {
2762
3002
  return _printLocalOrderReceipt.apply(this, arguments);
2763
3003
  }
2764
3004
  return printLocalOrderReceipt;
@@ -2772,27 +3012,27 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2772
3012
  if (!amountSnapshot) return undefined;
2773
3013
  try {
2774
3014
  return new Decimal(amountSnapshot.amountGap || 0).lte(0) ? 'paid' : undefined;
2775
- } catch (_unused2) {
3015
+ } catch (_unused4) {
2776
3016
  return undefined;
2777
3017
  }
2778
3018
  }
2779
3019
  }, {
2780
3020
  key: "syncPaymentsToOrder",
2781
3021
  value: function () {
2782
- var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(params) {
2783
- var _ref22, _params$businessCode, _this$otherParams19, _this$otherParams20, _params$channel;
3022
+ var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(params) {
3023
+ var _ref29, _params$businessCode, _this$otherParams23, _this$otherParams24, _params$channel2;
2784
3024
  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) {
3025
+ return _regeneratorRuntime().wrap(function _callee31$(_context31) {
3026
+ while (1) switch (_context31.prev = _context31.next) {
2787
3027
  case 0:
2788
3028
  if (this.store.order) {
2789
- _context30.next = 2;
3029
+ _context31.next = 2;
2790
3030
  break;
2791
3031
  }
2792
3032
  throw new Error('order 模块未初始化');
2793
3033
  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();
3034
+ 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;
3035
+ channel = (_params$channel2 = params.channel) !== null && _params$channel2 !== void 0 ? _params$channel2 : this.getSubmitOrderSalesChannel();
2796
3036
  syncParams = _objectSpread(_objectSpread(_objectSpread({}, params), {}, {
2797
3037
  checkoutSyncTaskEnabled: this.shouldUseCheckoutSyncTask()
2798
3038
  }, businessCode !== undefined ? {
@@ -2802,14 +3042,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2802
3042
  } : {});
2803
3043
  syncState = this.store.order.getOrderSyncState();
2804
3044
  if (!(params.submitWhenPaid && syncState === 'submitting')) {
2805
- _context30.next = 9;
3045
+ _context31.next = 9;
2806
3046
  break;
2807
3047
  }
2808
3048
  this.queueLatestAutoPaymentSync();
2809
- return _context30.abrupt("return", this.store.order.syncPaymentsToOrder(syncParams));
3049
+ return _context31.abrupt("return", this.store.order.syncPaymentsToOrder(syncParams));
2810
3050
  case 9:
2811
3051
  payments = params.payments || [];
2812
- _context30.next = 12;
3052
+ _context31.next = 12;
2813
3053
  return this.effectsEmit(BaseSalesHookNames.onPaymentSyncStart, {
2814
3054
  payments: payments,
2815
3055
  params: syncParams,
@@ -2817,11 +3057,11 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2817
3057
  orderSnapshot: this.store.order.getOrderSnapshot()
2818
3058
  });
2819
3059
  case 12:
2820
- _context30.prev = 12;
2821
- _context30.next = 15;
3060
+ _context31.prev = 12;
3061
+ _context31.next = 15;
2822
3062
  return this.store.order.syncPaymentsToOrder(syncParams);
2823
3063
  case 15:
2824
- syncResult = _context30.sent;
3064
+ syncResult = _context31.sent;
2825
3065
  latestPayments = this.store.order.getOrderPayments();
2826
3066
  amountSnapshot = this.store.order.getOrderAmountSnapshot();
2827
3067
  orderSnapshot = this.store.order.getOrderSnapshot();
@@ -2839,25 +3079,25 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2839
3079
  depositAmount: syncResult.depositAmount,
2840
3080
  orderExpectedAmount: syncResult.orderExpectedAmount
2841
3081
  };
2842
- _context30.next = 22;
3082
+ _context31.next = 22;
2843
3083
  return this.effectsEmit(BaseSalesHookNames.onPaymentSyncEnd, syncPayload);
2844
3084
  case 22:
2845
3085
  if (!(syncResult.isDepositFullyPaid && !syncResult.isOrderFullyPaid)) {
2846
- _context30.next = 25;
3086
+ _context31.next = 25;
2847
3087
  break;
2848
3088
  }
2849
- _context30.next = 25;
3089
+ _context31.next = 25;
2850
3090
  return this.effectsEmit(BaseSalesHookNames.onDepositPaymentSyncEnd, syncPayload);
2851
3091
  case 25:
2852
3092
  this.scheduleQueuedAutoPaymentSyncFlush(0);
2853
- return _context30.abrupt("return", syncResult);
3093
+ return _context31.abrupt("return", syncResult);
2854
3094
  case 29:
2855
- _context30.prev = 29;
2856
- _context30.t0 = _context30["catch"](12);
2857
- _context30.next = 33;
3095
+ _context31.prev = 29;
3096
+ _context31.t0 = _context31["catch"](12);
3097
+ _context31.next = 33;
2858
3098
  return this.effectsEmit(BaseSalesHookNames.onPaymentSyncEnd, {
2859
3099
  ok: false,
2860
- error: _context30.t0,
3100
+ error: _context31.t0,
2861
3101
  payments: this.store.order.getOrderPayments(),
2862
3102
  params: syncParams,
2863
3103
  amountSnapshot: this.store.order.getOrderAmountSnapshot(),
@@ -2865,14 +3105,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2865
3105
  });
2866
3106
  case 33:
2867
3107
  this.scheduleQueuedAutoPaymentSyncFlush(0);
2868
- throw _context30.t0;
3108
+ throw _context31.t0;
2869
3109
  case 35:
2870
3110
  case "end":
2871
- return _context30.stop();
3111
+ return _context31.stop();
2872
3112
  }
2873
- }, _callee30, this, [[12, 29]]);
3113
+ }, _callee31, this, [[12, 29]]);
2874
3114
  }));
2875
- function syncPaymentsToOrder(_x24) {
3115
+ function syncPaymentsToOrder(_x25) {
2876
3116
  return _syncPaymentsToOrder.apply(this, arguments);
2877
3117
  }
2878
3118
  return syncPaymentsToOrder;
@@ -2909,58 +3149,58 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2909
3149
  }, {
2910
3150
  key: "scheduleQueuedAutoPaymentSyncFlush",
2911
3151
  value: function scheduleQueuedAutoPaymentSyncFlush() {
2912
- var _this11 = this;
3152
+ var _this13 = this;
2913
3153
  var delay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 100;
2914
3154
  if (!this.queuedAutoPaymentSync) return;
2915
3155
  if (this.autoPaymentSyncTimer) return;
2916
3156
  this.autoPaymentSyncTimer = setTimeout(function () {
2917
- _this11.autoPaymentSyncTimer = null;
2918
- void _this11.flushQueuedAutoPaymentSync();
3157
+ _this13.autoPaymentSyncTimer = null;
3158
+ void _this13.flushQueuedAutoPaymentSync();
2919
3159
  }, delay);
2920
3160
  }
2921
3161
  }, {
2922
3162
  key: "flushQueuedAutoPaymentSync",
2923
3163
  value: function () {
2924
- var _flushQueuedAutoPaymentSync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31() {
3164
+ var _flushQueuedAutoPaymentSync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32() {
2925
3165
  var payments;
2926
- return _regeneratorRuntime().wrap(function _callee31$(_context31) {
2927
- while (1) switch (_context31.prev = _context31.next) {
3166
+ return _regeneratorRuntime().wrap(function _callee32$(_context32) {
3167
+ while (1) switch (_context32.prev = _context32.next) {
2928
3168
  case 0:
2929
3169
  if (this.store.order) {
2930
- _context31.next = 2;
3170
+ _context32.next = 2;
2931
3171
  break;
2932
3172
  }
2933
- return _context31.abrupt("return");
3173
+ return _context32.abrupt("return");
2934
3174
  case 2:
2935
3175
  if (!(!this.queuedAutoPaymentSync || this.autoPaymentSyncFlushing)) {
2936
- _context31.next = 4;
3176
+ _context32.next = 4;
2937
3177
  break;
2938
3178
  }
2939
- return _context31.abrupt("return");
3179
+ return _context32.abrupt("return");
2940
3180
  case 4:
2941
3181
  if (!(this.store.order.getOrderSyncState() === 'submitting')) {
2942
- _context31.next = 7;
3182
+ _context32.next = 7;
2943
3183
  break;
2944
3184
  }
2945
3185
  this.scheduleQueuedAutoPaymentSyncFlush();
2946
- return _context31.abrupt("return");
3186
+ return _context32.abrupt("return");
2947
3187
  case 7:
2948
3188
  this.autoPaymentSyncFlushing = true;
2949
- _context31.prev = 8;
3189
+ _context32.prev = 8;
2950
3190
  case 9:
2951
3191
  if (!this.queuedAutoPaymentSync) {
2952
- _context31.next = 18;
3192
+ _context32.next = 18;
2953
3193
  break;
2954
3194
  }
2955
3195
  this.queuedAutoPaymentSync = false;
2956
3196
  payments = this.store.order.getOrderPayments();
2957
3197
  if (payments.length) {
2958
- _context31.next = 14;
3198
+ _context32.next = 14;
2959
3199
  break;
2960
3200
  }
2961
- return _context31.abrupt("continue", 9);
3201
+ return _context32.abrupt("continue", 9);
2962
3202
  case 14:
2963
- _context31.next = 16;
3203
+ _context32.next = 16;
2964
3204
  return this.syncPaymentsToOrder({
2965
3205
  payments: payments,
2966
3206
  paymentStatus: this.getPaymentStatusForSync(payments),
@@ -2968,44 +3208,94 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2968
3208
  smallTicketDataFlag: 1
2969
3209
  });
2970
3210
  case 16:
2971
- _context31.next = 9;
3211
+ _context32.next = 9;
2972
3212
  break;
2973
3213
  case 18:
2974
- _context31.next = 23;
3214
+ _context32.next = 23;
2975
3215
  break;
2976
3216
  case 20:
2977
- _context31.prev = 20;
2978
- _context31.t0 = _context31["catch"](8);
3217
+ _context32.prev = 20;
3218
+ _context32.t0 = _context32["catch"](8);
2979
3219
  this.logError('queued auto sync payments failed', {
2980
- error: _context31.t0 instanceof Error ? _context31.t0.message : String(_context31.t0)
3220
+ error: _context32.t0 instanceof Error ? _context32.t0.message : String(_context32.t0)
2981
3221
  });
2982
3222
  case 23:
2983
- _context31.prev = 23;
3223
+ _context32.prev = 23;
2984
3224
  this.autoPaymentSyncFlushing = false;
2985
3225
  if (this.queuedAutoPaymentSync) {
2986
3226
  this.scheduleQueuedAutoPaymentSyncFlush(0);
2987
3227
  }
2988
- return _context31.finish(23);
3228
+ return _context32.finish(23);
2989
3229
  case 27:
2990
3230
  case "end":
2991
- return _context31.stop();
3231
+ return _context32.stop();
2992
3232
  }
2993
- }, _callee31, this, [[8, 20, 23, 27]]);
3233
+ }, _callee32, this, [[8, 20, 23, 27]]);
2994
3234
  }));
2995
3235
  function flushQueuedAutoPaymentSync() {
2996
3236
  return _flushQueuedAutoPaymentSync.apply(this, arguments);
2997
3237
  }
2998
3238
  return flushQueuedAutoPaymentSync;
2999
- }() /** 追加单个支付项到当前订单。 */
3239
+ }()
3240
+ /**
3241
+ * 同步兼容入口。无法等待 IoT 短号时,按调用当下的 device_id 或 LOCAL 生成。
3242
+ */
3000
3243
  }, {
3001
3244
  key: "addOrderPayment",
3002
3245
  value: function addOrderPayment(payment) {
3003
- var _this$otherParams21,
3246
+ var hasPaymentNumber = String(payment.payment_number || '').trim() !== '';
3247
+ return this.addOrderPaymentWithDevicePrefix(payment, hasPaymentNumber ? 'LOCAL' : this.getPaymentNumberDevicePrefixSync());
3248
+ }
3249
+
3250
+ /**
3251
+ * 创建新支付项时优先使用业务解决方案初始化阶段缓存的设备短号;
3252
+ * 未缓存的通用 BaseSales 保持实时读取设备信息的兼容语义。
3253
+ */
3254
+ }, {
3255
+ key: "addOrderPaymentAsync",
3256
+ value: (function () {
3257
+ var _addOrderPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(payment) {
3258
+ var paymentRecord, hasPaymentNumber, devicePrefix;
3259
+ return _regeneratorRuntime().wrap(function _callee33$(_context33) {
3260
+ while (1) switch (_context33.prev = _context33.next) {
3261
+ case 0:
3262
+ paymentRecord = payment;
3263
+ hasPaymentNumber = String(paymentRecord.payment_number || '').trim() !== '';
3264
+ if (!hasPaymentNumber) {
3265
+ _context33.next = 6;
3266
+ break;
3267
+ }
3268
+ _context33.t0 = 'LOCAL';
3269
+ _context33.next = 9;
3270
+ break;
3271
+ case 6:
3272
+ _context33.next = 8;
3273
+ return this.getPaymentNumberDevicePrefixAsync();
3274
+ case 8:
3275
+ _context33.t0 = _context33.sent;
3276
+ case 9:
3277
+ devicePrefix = _context33.t0;
3278
+ return _context33.abrupt("return", this.addOrderPaymentWithDevicePrefix(payment, devicePrefix));
3279
+ case 11:
3280
+ case "end":
3281
+ return _context33.stop();
3282
+ }
3283
+ }, _callee33, this);
3284
+ }));
3285
+ function addOrderPaymentAsync(_x26) {
3286
+ return _addOrderPaymentAsync.apply(this, arguments);
3287
+ }
3288
+ return addOrderPaymentAsync;
3289
+ }())
3290
+ }, {
3291
+ key: "addOrderPaymentWithDevicePrefix",
3292
+ value: function addOrderPaymentWithDevicePrefix(payment, devicePrefix) {
3293
+ var _this$otherParams25,
3004
3294
  _paymentRecord$paymen,
3005
3295
  _paymentRecord$create,
3006
- _ref23,
3296
+ _ref30,
3007
3297
  _paymentRecord$origin,
3008
- _this12 = this;
3298
+ _this14 = this;
3009
3299
  if (!this.store.order) throw new Error('order 模块未初始化');
3010
3300
  var paymentRecord = payment;
3011
3301
  var paymentAmount = new Decimal(paymentRecord.amount || 0);
@@ -3016,25 +3306,26 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3016
3306
  return this.store.order.getOrderPayments();
3017
3307
  }
3018
3308
  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;
3309
+ var shopWalletPassId = (_this$otherParams25 = this.otherParams) === null || _this$otherParams25 === void 0 ? void 0 : _this$otherParams25.shop_wallet_pass_id;
3020
3310
  if (shopWalletPassId !== undefined && shopWalletPassId !== null) {
3021
3311
  metadata.shop_wallet_pass_id = shopWalletPassId;
3022
3312
  }
3023
- if (!metadata.unique_payment_number) {
3024
- metadata.unique_payment_number = createUuidV4();
3025
- }
3313
+ var normalizedPaymentRecord = ensureOrderPaymentNumber(paymentRecord, devicePrefix, createUuidV4);
3026
3314
  var paymentTimestamp = dayjs().format('YYYY-MM-DD HH:mm:ss');
3027
3315
  var paymentTime = (_paymentRecord$paymen = paymentRecord.payment_time) !== null && _paymentRecord$paymen !== void 0 ? _paymentRecord$paymen : paymentTimestamp;
3028
3316
  var createdAt = (_paymentRecord$create = paymentRecord.created_at) !== null && _paymentRecord$create !== void 0 ? _paymentRecord$create : paymentTimestamp;
3029
3317
  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 ? {
3318
+ 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;
3319
+ var payments = this.store.order.addOrderPayment(_objectSpread(_objectSpread(_objectSpread({}, normalizedPaymentRecord), calculatedServiceFee !== undefined ? {
3032
3320
  service_fee: calculatedServiceFee
3033
3321
  } : {}), {}, {
3034
3322
  metadata: metadata,
3035
3323
  payment_time: paymentTime,
3036
3324
  created_at: createdAt
3037
3325
  }));
3326
+ if (paymentRecord.status === 'payment_pending') {
3327
+ return payments;
3328
+ }
3038
3329
  var amountSnapshot = this.store.order.getOrderAmountSnapshot();
3039
3330
  var syncState = this.store.order.getOrderSyncState();
3040
3331
  if (amountSnapshot) {
@@ -3048,7 +3339,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3048
3339
  submitWhenPaid: true,
3049
3340
  smallTicketDataFlag: 1
3050
3341
  }).catch(function (error) {
3051
- _this12.logError('auto sync payments failed', {
3342
+ _this14.logError('auto sync payments failed', {
3052
3343
  error: error instanceof Error ? error.message : String(error)
3053
3344
  });
3054
3345
  });
@@ -3059,12 +3350,131 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3059
3350
  /** 更新当前订单中的指定支付项。 */
3060
3351
  }, {
3061
3352
  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
- /** 删除当前订单中的指定支付项。 */
3353
+ value: (function () {
3354
+ var _updateOrderPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(paymentIdentity, updates) {
3355
+ var _result$payment, _result$payment2;
3356
+ var options,
3357
+ matchMode,
3358
+ previousMatch,
3359
+ previousPayment,
3360
+ _this$store$order$get2,
3361
+ currentPayments,
3362
+ _syncResult,
3363
+ _options$smallTicketD,
3364
+ result,
3365
+ draftResult,
3366
+ draftError,
3367
+ becamePaid,
3368
+ shouldSubmit,
3369
+ syncResult,
3370
+ _options$smallTicketD2,
3371
+ _args34 = arguments;
3372
+ return _regeneratorRuntime().wrap(function _callee34$(_context34) {
3373
+ while (1) switch (_context34.prev = _context34.next) {
3374
+ case 0:
3375
+ options = _args34.length > 2 && _args34[2] !== undefined ? _args34[2] : {};
3376
+ if (this.store.order) {
3377
+ _context34.next = 3;
3378
+ break;
3379
+ }
3380
+ throw new Error('order 模块未初始化');
3381
+ case 3:
3382
+ matchMode = options.matchBy === 'compat' || options.matchBy === 'legacy' ? 'compat' : 'payment_number';
3383
+ previousMatch = resolveOrderPaymentIdentity(this.store.order.getOrderPayments(), paymentIdentity, matchMode);
3384
+ previousPayment = previousMatch === null || previousMatch === void 0 ? void 0 : previousMatch.payment;
3385
+ if (!((previousPayment === null || previousPayment === void 0 ? void 0 : previousPayment.status) === 'paid' && !options.applyUpdatesWhenPaid)) {
3386
+ _context34.next = 13;
3387
+ break;
3388
+ }
3389
+ currentPayments = this.store.order.getOrderPayments();
3390
+ if (!(options.submitWhenPaid && options.forceSubmitIfPaid)) {
3391
+ _context34.next = 12;
3392
+ break;
3393
+ }
3394
+ _context34.next = 11;
3395
+ return this.syncPaymentsToOrder({
3396
+ payments: currentPayments,
3397
+ paymentStatus: this.getPaymentStatusForSync(currentPayments),
3398
+ submitWhenPaid: true,
3399
+ smallTicketDataFlag: (_options$smallTicketD = options.smallTicketDataFlag) !== null && _options$smallTicketD !== void 0 ? _options$smallTicketD : 1
3400
+ });
3401
+ case 11:
3402
+ _syncResult = _context34.sent;
3403
+ case 12:
3404
+ return _context34.abrupt("return", _objectSpread({
3405
+ updated: false,
3406
+ payment: previousPayment,
3407
+ payments: currentPayments,
3408
+ summary: ((_this$store$order$get2 = this.store.order.getOrderAmountSnapshot()) === null || _this$store$order$get2 === void 0 ? void 0 : _this$store$order$get2.summary) || null
3409
+ }, _syncResult !== undefined ? {
3410
+ syncResult: _syncResult
3411
+ } : {}));
3412
+ case 13:
3413
+ _context34.next = 15;
3414
+ return this.store.order.updateOrderPayment(paymentIdentity, updates, {
3415
+ matchBy: matchMode
3416
+ });
3417
+ case 15:
3418
+ result = _context34.sent;
3419
+ if (!(options.persistDraft !== false)) {
3420
+ _context34.next = 29;
3421
+ break;
3422
+ }
3423
+ _context34.prev = 17;
3424
+ _context34.next = 20;
3425
+ return this.saveSalesOrderDraft();
3426
+ case 20:
3427
+ draftResult = _context34.sent;
3428
+ _context34.next = 29;
3429
+ break;
3430
+ case 23:
3431
+ _context34.prev = 23;
3432
+ _context34.t0 = _context34["catch"](17);
3433
+ draftError = _context34.t0;
3434
+ this.logError('updateOrderPayment: 保存支付草稿失败', {
3435
+ paymentIdentity: paymentIdentity,
3436
+ error: _context34.t0 instanceof Error ? _context34.t0.message : String(_context34.t0)
3437
+ });
3438
+ if (options.submitWhenPaid) {
3439
+ _context34.next = 29;
3440
+ break;
3441
+ }
3442
+ throw _context34.t0;
3443
+ case 29:
3444
+ 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';
3445
+ shouldSubmit = Boolean(options.submitWhenPaid && ((_result$payment2 = result.payment) === null || _result$payment2 === void 0 ? void 0 : _result$payment2.status) === 'paid' && (becamePaid || options.forceSubmitIfPaid));
3446
+ if (!shouldSubmit) {
3447
+ _context34.next = 35;
3448
+ break;
3449
+ }
3450
+ _context34.next = 34;
3451
+ return this.syncPaymentsToOrder({
3452
+ payments: result.payments,
3453
+ paymentStatus: this.getPaymentStatusForSync(result.payments),
3454
+ submitWhenPaid: true,
3455
+ smallTicketDataFlag: (_options$smallTicketD2 = options.smallTicketDataFlag) !== null && _options$smallTicketD2 !== void 0 ? _options$smallTicketD2 : 1
3456
+ });
3457
+ case 34:
3458
+ syncResult = _context34.sent;
3459
+ case 35:
3460
+ return _context34.abrupt("return", _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, result), draftResult !== undefined ? {
3461
+ draftResult: draftResult
3462
+ } : {}), draftError !== undefined ? {
3463
+ draftError: draftError
3464
+ } : {}), syncResult !== undefined ? {
3465
+ syncResult: syncResult
3466
+ } : {}));
3467
+ case 36:
3468
+ case "end":
3469
+ return _context34.stop();
3470
+ }
3471
+ }, _callee34, this, [[17, 23]]);
3472
+ }));
3473
+ function updateOrderPayment(_x27, _x28) {
3474
+ return _updateOrderPayment.apply(this, arguments);
3475
+ }
3476
+ return updateOrderPayment;
3477
+ }() /** 删除当前订单中的指定支付项。 */)
3068
3478
  }, {
3069
3479
  key: "deleteOrderPayment",
3070
3480
  value: function deleteOrderPayment(paymentIdentity) {
@@ -3079,11 +3489,42 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3079
3489
  if (!this.store.order) throw new Error('order 模块未初始化');
3080
3490
  return this.store.order.updateVoucherOrderPayments(payments, options);
3081
3491
  }
3492
+ }, {
3493
+ key: "updateVoucherOrderPaymentsAsync",
3494
+ value: function () {
3495
+ var _updateVoucherOrderPaymentsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(payments, options) {
3496
+ return _regeneratorRuntime().wrap(function _callee35$(_context35) {
3497
+ while (1) switch (_context35.prev = _context35.next) {
3498
+ case 0:
3499
+ if (this.store.order) {
3500
+ _context35.next = 2;
3501
+ break;
3502
+ }
3503
+ throw new Error('order 模块未初始化');
3504
+ case 2:
3505
+ return _context35.abrupt("return", this.store.order.updateVoucherOrderPaymentsAsync(payments, options));
3506
+ case 3:
3507
+ case "end":
3508
+ return _context35.stop();
3509
+ }
3510
+ }, _callee35, this);
3511
+ }));
3512
+ function updateVoucherOrderPaymentsAsync(_x29, _x30) {
3513
+ return _updateVoucherOrderPaymentsAsync.apply(this, arguments);
3514
+ }
3515
+ return updateVoucherOrderPaymentsAsync;
3516
+ }()
3082
3517
  }, {
3083
3518
  key: "confirmPendingVoucherPayments",
3084
3519
  value: function confirmPendingVoucherPayments() {
3085
3520
  if (!this.store.order) throw new Error('order 模块未初始化');
3086
- return this.store.order.confirmPendingVoucherPayments();
3521
+ var payments = this.store.order.confirmPendingVoucherPayments();
3522
+ if (this.store.payment) {
3523
+ var committed = this.getCommittedWalletAssets();
3524
+ var state = this.store.payment.wallet.setCommittedWalletAssets(committed.ids, committed.assets);
3525
+ void this.publishWalletAssetsState(state);
3526
+ }
3527
+ return payments;
3087
3528
  }
3088
3529
  }, {
3089
3530
  key: "discardPendingVoucherPayments",
@@ -3152,64 +3593,72 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3152
3593
  });
3153
3594
  return walletProducts;
3154
3595
  }
3596
+ }, {
3597
+ key: "buildWalletInitBusinessData",
3598
+ value: function buildWalletInitBusinessData(params) {
3599
+ var _this$store$order8, _params$order_wait_pa, _ref31, _tempOrder$is_price_i;
3600
+ var snapshot = (_this$store$order8 = this.store.order) === null || _this$store$order8 === void 0 ? void 0 : _this$store$order8.getOrderSnapshot();
3601
+ var tempOrder = snapshot === null || snapshot === void 0 ? void 0 : snapshot.tempOrder;
3602
+ var amount = snapshot === null || snapshot === void 0 ? void 0 : snapshot.amount;
3603
+ if (!tempOrder || !amount) return null;
3604
+ return _objectSpread({
3605
+ customer_id: tempOrder.customer_id ? Number(tempOrder.customer_id) : undefined,
3606
+ holder: tempOrder.holder,
3607
+ amountInfo: {
3608
+ totalAmount: amount.totalAmount,
3609
+ subTotal: amount.summary.product_amount || amount.summary.product_expect_amount || amount.totalAmount,
3610
+ depositAmount: amount.depositAmount,
3611
+ isDeposit: tempOrder.is_deposit
3612
+ },
3613
+ products: this.getWalletProductList(),
3614
+ 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),
3615
+ 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
3616
+ }, snapshot.identity.orderId ? {
3617
+ payment_order_id: String(snapshot.identity.orderId)
3618
+ } : {});
3619
+ }
3155
3620
  }, {
3156
3621
  key: "initWalletData",
3157
3622
  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) {
3623
+ var _initWalletData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(params) {
3624
+ var _snapshot$identity;
3625
+ var snapshot, walletBusinessData, result;
3626
+ return _regeneratorRuntime().wrap(function _callee36$(_context36) {
3627
+ while (1) switch (_context36.prev = _context36.next) {
3163
3628
  case 0:
3164
3629
  if (this.store.order) {
3165
- _context32.next = 2;
3630
+ _context36.next = 2;
3166
3631
  break;
3167
3632
  }
3168
3633
  throw new Error('order 模块未初始化');
3169
3634
  case 2:
3170
3635
  if (this.store.payment) {
3171
- _context32.next = 4;
3636
+ _context36.next = 4;
3172
3637
  break;
3173
3638
  }
3174
3639
  throw new Error('payment 模块未初始化');
3175
3640
  case 4:
3176
3641
  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;
3642
+ walletBusinessData = this.buildWalletInitBusinessData(params);
3643
+ if (walletBusinessData) {
3644
+ _context36.next = 8;
3181
3645
  break;
3182
3646
  }
3183
- return _context32.abrupt("return", {
3647
+ return _context36.abrupt("return", {
3184
3648
  walletRecommendList: [],
3185
3649
  userIdentificationCodes: [],
3186
3650
  transformList: [],
3187
3651
  noApplicableVoucher: [],
3188
3652
  products: []
3189
3653
  });
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;
3654
+ case 8:
3655
+ _context36.next = 10;
3207
3656
  return this.store.payment.wallet.initializeWalletDataFromBusinessAsync(walletBusinessData);
3208
- case 12:
3209
- result = _context32.sent;
3210
- _context32.next = 15;
3657
+ case 10:
3658
+ result = _context36.sent;
3659
+ _context36.next = 13;
3211
3660
  return this.core.effects.emit("".concat(this.name, ":onWalletDataInitialized"), {
3212
- orderId: snapshot.identity.orderId,
3661
+ orderId: snapshot === null || snapshot === void 0 || (_snapshot$identity = snapshot.identity) === null || _snapshot$identity === void 0 ? void 0 : _snapshot$identity.orderId,
3213
3662
  customerId: walletBusinessData.customer_id,
3214
3663
  walletBusinessData: {
3215
3664
  customer_id: walletBusinessData.customer_id,
@@ -3218,25 +3667,421 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3218
3667
  },
3219
3668
  timestamp: Date.now()
3220
3669
  });
3221
- case 15:
3222
- return _context32.abrupt("return", result);
3223
- case 16:
3670
+ case 13:
3671
+ return _context36.abrupt("return", result);
3672
+ case 14:
3224
3673
  case "end":
3225
- return _context32.stop();
3674
+ return _context36.stop();
3226
3675
  }
3227
- }, _callee32, this);
3676
+ }, _callee36, this);
3228
3677
  }));
3229
- function initWalletData(_x25) {
3678
+ function initWalletData(_x31) {
3230
3679
  return _initWalletData.apply(this, arguments);
3231
3680
  }
3232
3681
  return initWalletData;
3233
3682
  }()
3683
+ }, {
3684
+ key: "getCommittedWalletAssets",
3685
+ value: function getCommittedWalletAssets() {
3686
+ var _this$store$order9, _this$store$order9$ge;
3687
+ 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)) || [];
3688
+ var committed = payments.filter(function (payment) {
3689
+ var voucherId = payment === null || payment === void 0 ? void 0 : payment.voucher_id;
3690
+ if (voucherId === undefined || voucherId === null || voucherId === 0) {
3691
+ return false;
3692
+ }
3693
+ 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) !== '';
3694
+ });
3695
+ return {
3696
+ ids: committed.map(function (payment) {
3697
+ return payment.voucher_id;
3698
+ }),
3699
+ assets: committed.map(function (payment) {
3700
+ var _Object$entries$find;
3701
+ var fundRecord = (payment === null || payment === void 0 ? void 0 : payment.fund_record) || {};
3702
+ var walletPassName = fundRecord.wallet_pass_name;
3703
+ var title = walletPassName && _typeof(walletPassName) === 'object' ? walletPassName.default || Object.values(walletPassName)[0] : walletPassName;
3704
+ var code = String((payment === null || payment === void 0 ? void 0 : payment.code) || '').toUpperCase();
3705
+ var tag = ((_Object$entries$find = Object.entries(WALLET_PAYMENT_CODE_BY_TAG).find(function (_ref32) {
3706
+ var _ref33 = _slicedToArray(_ref32, 2),
3707
+ paymentCode = _ref33[1];
3708
+ return paymentCode === code;
3709
+ })) === null || _Object$entries$find === void 0 ? void 0 : _Object$entries$find[0]) || fundRecord.tag;
3710
+ return {
3711
+ id: payment.voucher_id,
3712
+ voucher_id: payment.voucher_id,
3713
+ code: fundRecord.code,
3714
+ tag: tag,
3715
+ product_name: title || payment.name,
3716
+ name: title || payment.name,
3717
+ amount: Number(payment.amount || 0),
3718
+ _available_max_amount: Number(payment.amount || 0),
3719
+ unified_available_status: 1,
3720
+ _unified_available_status: 1,
3721
+ _committed_payment: payment
3722
+ };
3723
+ })
3724
+ };
3725
+ }
3726
+ }, {
3727
+ key: "publishWalletAssetsState",
3728
+ value: function () {
3729
+ var _publishWalletAssetsState = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(state) {
3730
+ return _regeneratorRuntime().wrap(function _callee37$(_context37) {
3731
+ while (1) switch (_context37.prev = _context37.next) {
3732
+ case 0:
3733
+ _context37.next = 2;
3734
+ return this.effectsEmit(BaseSalesHookNames.onWalletAssetsStateChanged, {
3735
+ state: state
3736
+ });
3737
+ case 2:
3738
+ return _context37.abrupt("return", state);
3739
+ case 3:
3740
+ case "end":
3741
+ return _context37.stop();
3742
+ }
3743
+ }, _callee37, this);
3744
+ }));
3745
+ function publishWalletAssetsState(_x32) {
3746
+ return _publishWalletAssetsState.apply(this, arguments);
3747
+ }
3748
+ return publishWalletAssetsState;
3749
+ }()
3750
+ }, {
3751
+ key: "syncSelectedWalletAssets",
3752
+ value: function () {
3753
+ var _syncSelectedWalletAssets = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(state) {
3754
+ var paymentMethods, methodByCode, preparePayments, selectedAssetById, voucherPayments, payments;
3755
+ return _regeneratorRuntime().wrap(function _callee38$(_context38) {
3756
+ while (1) switch (_context38.prev = _context38.next) {
3757
+ case 0:
3758
+ if (!(!this.store.order || !this.store.payment)) {
3759
+ _context38.next = 2;
3760
+ break;
3761
+ }
3762
+ throw new Error('订单或支付模块未初始化');
3763
+ case 2:
3764
+ paymentMethods = this.getPaymentMethods();
3765
+ if (!(!paymentMethods.length && state.selectedItems.length)) {
3766
+ _context38.next = 7;
3767
+ break;
3768
+ }
3769
+ _context38.next = 6;
3770
+ return this.getPaymentMethodsAsync();
3771
+ case 6:
3772
+ paymentMethods = _context38.sent;
3773
+ case 7:
3774
+ methodByCode = new Map(paymentMethods.map(function (method) {
3775
+ return [String(method.code || '').toUpperCase(), method];
3776
+ }));
3777
+ preparePayments = this.store.payment.wallet.formatWalletPassList2PreparePayments(state.selectedItems);
3778
+ selectedAssetById = new Map(state.selectedItems.map(function (asset) {
3779
+ return [String(getSharedWalletAssetId(asset)), asset];
3780
+ }));
3781
+ voucherPayments = preparePayments.flatMap(function (item) {
3782
+ var asset = selectedAssetById.get(String(item.voucher_id));
3783
+ 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();
3784
+ var paymentMethod = methodByCode.get(paymentCode);
3785
+ var formattedAmount = Number(item.amount);
3786
+ var amount = Number.isFinite(formattedAmount) && formattedAmount > 0 ? formattedAmount : getSharedWalletAssetAmount(asset);
3787
+ if (!asset || !paymentMethod || !Number.isFinite(amount) || amount <= 0) {
3788
+ return [];
3789
+ }
3790
+ var walletPassUseValue = getSharedWalletPassUseValue({
3791
+ asset: asset,
3792
+ amount: amount,
3793
+ paymentMethod: paymentMethod
3794
+ });
3795
+ return [{
3796
+ amount: amount.toFixed(2),
3797
+ code: paymentMethod.code,
3798
+ custom_payment_id: paymentMethod.id,
3799
+ name: paymentMethod.name,
3800
+ type: paymentMethod.type,
3801
+ voucher_id: item.voucher_id,
3802
+ wallet_pass_usage_unit: item.wallet_pass_usage_unit,
3803
+ wallet_pass_use_value: walletPassUseValue,
3804
+ fund_record: buildSharedWalletFundRecord({
3805
+ asset: asset,
3806
+ amount: amount,
3807
+ paymentMethod: paymentMethod
3808
+ })
3809
+ }];
3810
+ });
3811
+ payments = this.updateVoucherOrderPayments(voucherPayments, {
3812
+ status: 'payment_pending'
3813
+ });
3814
+ _context38.next = 14;
3815
+ return this.store.order.recalculateSummary({
3816
+ createIfMissing: true
3817
+ });
3818
+ case 14:
3819
+ return _context38.abrupt("return", payments);
3820
+ case 15:
3821
+ case "end":
3822
+ return _context38.stop();
3823
+ }
3824
+ }, _callee38, this);
3825
+ }));
3826
+ function syncSelectedWalletAssets(_x33) {
3827
+ return _syncSelectedWalletAssets.apply(this, arguments);
3828
+ }
3829
+ return syncSelectedWalletAssets;
3830
+ }() /** 读取购物车与 Shared Checkout 共用的钱包资产状态。 */
3831
+ }, {
3832
+ key: "getWalletAssetsState",
3833
+ value: function getWalletAssetsState() {
3834
+ if (!this.store.payment) throw new Error('payment 模块未初始化');
3835
+ return this.store.payment.wallet.getWalletAssetsState();
3836
+ }
3837
+
3838
+ /** 导出 Shared Checkout 跨运行时恢复所需的钱包状态与搜索缓存。 */
3839
+ }, {
3840
+ key: "exportWalletAssetsSnapshot",
3841
+ value: function exportWalletAssetsSnapshot() {
3842
+ if (!this.store.payment) throw new Error('payment 模块未初始化');
3843
+ return this.store.payment.wallet.exportWalletAssetsSnapshot();
3844
+ }
3845
+
3846
+ /** 配置仅影响 Wallet Assets,不改变 Promotion/Voucher 选择流程。 */
3847
+ }, {
3848
+ key: "configureWalletAssetsBehavior",
3849
+ value: function configureWalletAssetsBehavior(options) {
3850
+ if (!this.store.payment) throw new Error('payment 模块未初始化');
3851
+ this.store.payment.wallet.configureWalletAssetsBehavior(options);
3852
+ }
3853
+
3854
+ /**
3855
+ * 恢复 Shared Checkout 钱包快照,并把选择重新同步为订单 pending payment。
3856
+ */
3857
+ }, {
3858
+ key: "importWalletAssetsSnapshot",
3859
+ value: (function () {
3860
+ var _importWalletAssetsSnapshot = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(snapshot) {
3861
+ var state;
3862
+ return _regeneratorRuntime().wrap(function _callee39$(_context39) {
3863
+ while (1) switch (_context39.prev = _context39.next) {
3864
+ case 0:
3865
+ if (this.store.payment) {
3866
+ _context39.next = 2;
3867
+ break;
3868
+ }
3869
+ throw new Error('payment 模块未初始化');
3870
+ case 2:
3871
+ state = this.store.payment.wallet.importWalletAssetsSnapshot(snapshot);
3872
+ _context39.next = 5;
3873
+ return this.syncSelectedWalletAssets(state);
3874
+ case 5:
3875
+ return _context39.abrupt("return", this.publishWalletAssetsState(state));
3876
+ case 6:
3877
+ case "end":
3878
+ return _context39.stop();
3879
+ }
3880
+ }, _callee39, this);
3881
+ }));
3882
+ function importWalletAssetsSnapshot(_x34) {
3883
+ return _importWalletAssetsSnapshot.apply(this, arguments);
3884
+ }
3885
+ return importWalletAssetsSnapshot;
3886
+ }()
3887
+ /**
3888
+ * 基于当前订单快照刷新钱包资产。商品变化保留并重验选择;客户变化强制清空。
3889
+ */
3890
+ )
3891
+ }, {
3892
+ key: "refreshWalletAssets",
3893
+ value: (function () {
3894
+ var _refreshWalletAssets = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(params) {
3895
+ var _previousState$custom, _businessData$custome;
3896
+ var refreshSequence, wallet, businessData, emptyState, previousState, hasPreviousWalletContext, customerChanged, clearedState, refreshTask, state, committed;
3897
+ return _regeneratorRuntime().wrap(function _callee40$(_context40) {
3898
+ while (1) switch (_context40.prev = _context40.next) {
3899
+ case 0:
3900
+ if (this.store.order) {
3901
+ _context40.next = 2;
3902
+ break;
3903
+ }
3904
+ throw new Error('order 模块未初始化');
3905
+ case 2:
3906
+ if (this.store.payment) {
3907
+ _context40.next = 4;
3908
+ break;
3909
+ }
3910
+ throw new Error('payment 模块未初始化');
3911
+ case 4:
3912
+ refreshSequence = ++this.walletAssetsRefreshSequence;
3913
+ wallet = this.store.payment.wallet;
3914
+ businessData = this.buildWalletInitBusinessData(params);
3915
+ if (businessData) {
3916
+ _context40.next = 12;
3917
+ break;
3918
+ }
3919
+ wallet.clearAllCache();
3920
+ emptyState = wallet.getWalletAssetsState();
3921
+ this.updateVoucherOrderPayments([], {
3922
+ status: 'payment_pending'
3923
+ });
3924
+ return _context40.abrupt("return", this.publishWalletAssetsState(emptyState));
3925
+ case 12:
3926
+ previousState = wallet.getWalletAssetsState();
3927
+ hasPreviousWalletContext = previousState.status !== 'idle' || previousState.items.length > 0 || previousState.selectedIds.length > 0 || previousState.customerId !== undefined;
3928
+ 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 : '');
3929
+ if (!customerChanged) {
3930
+ _context40.next = 20;
3931
+ break;
3932
+ }
3933
+ clearedState = wallet.clearWalletAssetSelection();
3934
+ this.updateVoucherOrderPayments([], {
3935
+ status: 'payment_pending'
3936
+ });
3937
+ _context40.next = 20;
3938
+ return this.publishWalletAssetsState(clearedState);
3939
+ case 20:
3940
+ refreshTask = wallet.refreshWalletAssetsFromBusinessAsync(businessData, {
3941
+ preserveSelection: (params === null || params === void 0 ? void 0 : params.preserveSelection) !== false && !customerChanged
3942
+ });
3943
+ _context40.next = 23;
3944
+ return this.publishWalletAssetsState(wallet.getWalletAssetsState());
3945
+ case 23:
3946
+ _context40.next = 25;
3947
+ return refreshTask;
3948
+ case 25:
3949
+ state = _context40.sent;
3950
+ if (!(refreshSequence !== this.walletAssetsRefreshSequence)) {
3951
+ _context40.next = 28;
3952
+ break;
3953
+ }
3954
+ return _context40.abrupt("return", wallet.getWalletAssetsState());
3955
+ case 28:
3956
+ if (state.status !== 'error') {
3957
+ committed = this.getCommittedWalletAssets();
3958
+ state = wallet.setCommittedWalletAssets(committed.ids, committed.assets);
3959
+ }
3960
+ _context40.next = 31;
3961
+ return this.syncSelectedWalletAssets(state);
3962
+ case 31:
3963
+ return _context40.abrupt("return", this.publishWalletAssetsState(state));
3964
+ case 32:
3965
+ case "end":
3966
+ return _context40.stop();
3967
+ }
3968
+ }, _callee40, this);
3969
+ }));
3970
+ function refreshWalletAssets(_x35) {
3971
+ return _refreshWalletAssets.apply(this, arguments);
3972
+ }
3973
+ return refreshWalletAssets;
3974
+ }() /** 选择或取消单张钱包资产,并立即同步 pending wallet payments。 */)
3975
+ }, {
3976
+ key: "selectWalletAsset",
3977
+ value: (function () {
3978
+ var _selectWalletAsset = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(params) {
3979
+ var state;
3980
+ return _regeneratorRuntime().wrap(function _callee41$(_context41) {
3981
+ while (1) switch (_context41.prev = _context41.next) {
3982
+ case 0:
3983
+ if (this.store.payment) {
3984
+ _context41.next = 2;
3985
+ break;
3986
+ }
3987
+ throw new Error('payment 模块未初始化');
3988
+ case 2:
3989
+ state = this.store.payment.wallet.selectWalletAsset(params.assetId, {
3990
+ selected: params.selected,
3991
+ source: params.source
3992
+ });
3993
+ _context41.next = 5;
3994
+ return this.syncSelectedWalletAssets(state);
3995
+ case 5:
3996
+ return _context41.abrupt("return", this.publishWalletAssetsState(state));
3997
+ case 6:
3998
+ case "end":
3999
+ return _context41.stop();
4000
+ }
4001
+ }, _callee41, this);
4002
+ }));
4003
+ function selectWalletAsset(_x36) {
4004
+ return _selectWalletAsset.apply(this, arguments);
4005
+ }
4006
+ return selectWalletAsset;
4007
+ }() /** 扫码精确查券;仅可用资产会被自动选中。 */)
4008
+ }, {
4009
+ key: "scanWalletAsset",
4010
+ value: (function () {
4011
+ var _scanWalletAsset = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42(code) {
4012
+ var result;
4013
+ return _regeneratorRuntime().wrap(function _callee42$(_context42) {
4014
+ while (1) switch (_context42.prev = _context42.next) {
4015
+ case 0:
4016
+ if (this.store.payment) {
4017
+ _context42.next = 2;
4018
+ break;
4019
+ }
4020
+ throw new Error('payment 模块未初始化');
4021
+ case 2:
4022
+ _context42.next = 4;
4023
+ return this.store.payment.wallet.scanWalletAssetAsync(code);
4024
+ case 4:
4025
+ result = _context42.sent;
4026
+ if (!(result.type === 'normalCode')) {
4027
+ _context42.next = 10;
4028
+ break;
4029
+ }
4030
+ _context42.next = 8;
4031
+ return this.syncSelectedWalletAssets(result.state);
4032
+ case 8:
4033
+ _context42.next = 10;
4034
+ return this.publishWalletAssetsState(result.state);
4035
+ case 10:
4036
+ return _context42.abrupt("return", result);
4037
+ case 11:
4038
+ case "end":
4039
+ return _context42.stop();
4040
+ }
4041
+ }, _callee42, this);
4042
+ }));
4043
+ function scanWalletAsset(_x37) {
4044
+ return _scanWalletAsset.apply(this, arguments);
4045
+ }
4046
+ return scanWalletAsset;
4047
+ }() /** 清空全部未确认钱包选择,已支付钱包项由 Order 模块继续保留。 */)
4048
+ }, {
4049
+ key: "clearWalletAssetSelection",
4050
+ value: (function () {
4051
+ var _clearWalletAssetSelection = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43() {
4052
+ var state;
4053
+ return _regeneratorRuntime().wrap(function _callee43$(_context43) {
4054
+ while (1) switch (_context43.prev = _context43.next) {
4055
+ case 0:
4056
+ if (this.store.payment) {
4057
+ _context43.next = 2;
4058
+ break;
4059
+ }
4060
+ throw new Error('payment 模块未初始化');
4061
+ case 2:
4062
+ state = this.store.payment.wallet.clearWalletAssetSelection();
4063
+ _context43.next = 5;
4064
+ return this.syncSelectedWalletAssets(state);
4065
+ case 5:
4066
+ return _context43.abrupt("return", this.publishWalletAssetsState(state));
4067
+ case 6:
4068
+ case "end":
4069
+ return _context43.stop();
4070
+ }
4071
+ }, _callee43, this);
4072
+ }));
4073
+ function clearWalletAssetSelection() {
4074
+ return _clearWalletAssetSelection.apply(this, arguments);
4075
+ }
4076
+ return clearWalletAssetSelection;
4077
+ }()
3234
4078
  /**
3235
4079
  * 更新当前订单客户字段。
3236
4080
  *
3237
4081
  * 这是 PaymentModal 客户切换的订单事实入口;外部客户模块同步应由
3238
4082
  * 调用方通过 onCustomerChange 回调完成。
3239
4083
  */
4084
+ )
3240
4085
  }, {
3241
4086
  key: "updateOrderCustomer",
3242
4087
  value: function updateOrderCustomer(customer) {
@@ -3253,35 +4098,35 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3253
4098
  }, {
3254
4099
  key: "getPaymentMethodsAsync",
3255
4100
  value: (function () {
3256
- var _getPaymentMethodsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33() {
4101
+ var _getPaymentMethodsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee44() {
3257
4102
  var response, paymentMethods;
3258
- return _regeneratorRuntime().wrap(function _callee33$(_context33) {
3259
- while (1) switch (_context33.prev = _context33.next) {
4103
+ return _regeneratorRuntime().wrap(function _callee44$(_context44) {
4104
+ while (1) switch (_context44.prev = _context44.next) {
3260
4105
  case 0:
3261
- _context33.prev = 0;
3262
- _context33.next = 3;
4106
+ _context44.prev = 0;
4107
+ _context44.next = 3;
3263
4108
  return this.request.get('/pay/custom-payment/all', {
3264
4109
  filterPaymentMethods: true
3265
4110
  }, {
3266
4111
  osServer: true
3267
4112
  });
3268
4113
  case 3:
3269
- response = _context33.sent;
4114
+ response = _context44.sent;
3270
4115
  paymentMethods = (response === null || response === void 0 ? void 0 : response.data) || [];
3271
4116
  this.paymentMethodsCache = Array.isArray(paymentMethods) ? _toConsumableArray(paymentMethods) : [];
3272
- return _context33.abrupt("return", this.getPaymentMethods());
4117
+ return _context44.abrupt("return", this.getPaymentMethods());
3273
4118
  case 9:
3274
- _context33.prev = 9;
3275
- _context33.t0 = _context33["catch"](0);
4119
+ _context44.prev = 9;
4120
+ _context44.t0 = _context44["catch"](0);
3276
4121
  this.logWarning('getPaymentMethodsAsync: 获取支付方式列表失败,使用缓存列表', {
3277
- error: _context33.t0 instanceof Error ? _context33.t0.message : String(_context33.t0)
4122
+ error: _context44.t0 instanceof Error ? _context44.t0.message : String(_context44.t0)
3278
4123
  });
3279
- return _context33.abrupt("return", this.getPaymentMethods());
4124
+ return _context44.abrupt("return", this.getPaymentMethods());
3280
4125
  case 13:
3281
4126
  case "end":
3282
- return _context33.stop();
4127
+ return _context44.stop();
3283
4128
  }
3284
- }, _callee33, this, [[0, 9]]);
4129
+ }, _callee44, this, [[0, 9]]);
3285
4130
  }));
3286
4131
  function getPaymentMethodsAsync() {
3287
4132
  return _getPaymentMethodsAsync.apply(this, arguments);
@@ -3293,85 +4138,593 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3293
4138
  value: function getPaymentMethods() {
3294
4139
  return _toConsumableArray(this.paymentMethodsCache);
3295
4140
  }
3296
-
3297
- /** 轻量舍入能力,供现金支付 UI 计算 rounding_amount。 */
3298
4141
  }, {
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
- };
4142
+ key: "findCashPaymentMethod",
4143
+ value: function findCashPaymentMethod(paymentMethods) {
4144
+ return paymentMethods.find(function (method) {
4145
+ 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) {
4146
+ return String(value || '').toUpperCase();
4147
+ });
4148
+ return identifiers.includes('CASHMANUAL') && (method === null || method === void 0 ? void 0 : method.enabled) !== false && (method === null || method === void 0 ? void 0 : method.enable) !== false;
4149
+ });
4150
+ }
4151
+ }, {
4152
+ key: "getPendingWalletPaymentAmount",
4153
+ value: function getPendingWalletPaymentAmount() {
4154
+ var _this$store$order10, _this$store$order10$g;
4155
+ 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)) || [];
4156
+ return payments.reduce(function (total, payment) {
4157
+ 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) {
4158
+ return total;
4159
+ }
4160
+ try {
4161
+ return total.plus(payment.amount || 0).plus(payment.rounding_amount || 0);
4162
+ } catch (_unused5) {
4163
+ return total;
4164
+ }
4165
+ }, new Decimal(0));
3321
4166
  }
3322
4167
 
4168
+ /** 读取现金 action 所需的支付方式、待付金额和快捷金额。 */
4169
+ }, {
4170
+ key: "getCashPaymentConfig",
4171
+ value: (function () {
4172
+ var _getCashPaymentConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee45() {
4173
+ var _this$store$order11, _this$store$order11$g, _this$store$order12, _this$store$order12$g, _this$otherParams26;
4174
+ var paymentMethods, paymentMethod, amountSnapshot, pendingWalletAmount, amountDue, currency, recommendedAmounts;
4175
+ return _regeneratorRuntime().wrap(function _callee45$(_context45) {
4176
+ while (1) switch (_context45.prev = _context45.next) {
4177
+ case 0:
4178
+ if (this.store.payment) {
4179
+ _context45.next = 2;
4180
+ break;
4181
+ }
4182
+ throw new Error('payment 模块未初始化');
4183
+ case 2:
4184
+ paymentMethods = this.getPaymentMethods();
4185
+ paymentMethod = this.findCashPaymentMethod(paymentMethods);
4186
+ if (paymentMethod) {
4187
+ _context45.next = 9;
4188
+ break;
4189
+ }
4190
+ _context45.next = 7;
4191
+ return this.getPaymentMethodsAsync();
4192
+ case 7:
4193
+ paymentMethods = _context45.sent;
4194
+ paymentMethod = this.findCashPaymentMethod(paymentMethods);
4195
+ case 9:
4196
+ 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);
4197
+ pendingWalletAmount = this.getPendingWalletPaymentAmount();
4198
+ amountDue = Decimal.max(new Decimal((amountSnapshot === null || amountSnapshot === void 0 ? void 0 : amountSnapshot.amountGap) || 0).minus(pendingWalletAmount), 0).toDecimalPlaces(2).toNumber();
4199
+ 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';
4200
+ recommendedAmounts = amountDue > 0 ? this.store.payment.cash.getRecommendedAmount(amountDue, currency) : [];
4201
+ return _context45.abrupt("return", {
4202
+ available: Boolean(paymentMethod && amountDue > 0),
4203
+ paymentMethod: paymentMethod,
4204
+ amountDue: amountDue,
4205
+ recommendedAmounts: recommendedAmounts
4206
+ });
4207
+ case 15:
4208
+ case "end":
4209
+ return _context45.stop();
4210
+ }
4211
+ }, _callee45, this);
4212
+ }));
4213
+ function getCashPaymentConfig() {
4214
+ return _getCashPaymentConfig.apply(this, arguments);
4215
+ }
4216
+ return getCashPaymentConfig;
4217
+ }()
4218
+ /**
4219
+ * 确认足额覆盖订单的 pending Wallet 支付并提交订单。
4220
+ *
4221
+ * Order 模块在构造提交参数时将 pending voucher 转为 paid;只有提交成功后
4222
+ * 才同步 Wallet committed 状态。失败时恢复调用前 payments,允许用户重试。
4223
+ */
4224
+ )
4225
+ }, {
4226
+ key: "confirmWalletPayment",
4227
+ value: (function () {
4228
+ var _confirmWalletPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee46() {
4229
+ var _this$store$order$get3, _this$store$order13, _this$store$order$get4, _this$store$order$get5, _this$store$order14;
4230
+ var beforePayments, pendingWalletAmount, amountSnapshot, effectiveAmountDue, beforePaymentStatus, submitResult, restoredTempOrder, committed, walletState, latestAmountSnapshot;
4231
+ return _regeneratorRuntime().wrap(function _callee46$(_context46) {
4232
+ while (1) switch (_context46.prev = _context46.next) {
4233
+ case 0:
4234
+ if (this.store.order) {
4235
+ _context46.next = 2;
4236
+ break;
4237
+ }
4238
+ throw new Error('order 模块未初始化');
4239
+ case 2:
4240
+ beforePayments = cloneDeep(this.store.order.getOrderPayments());
4241
+ pendingWalletAmount = this.getPendingWalletPaymentAmount(beforePayments);
4242
+ if (!pendingWalletAmount.lte(0)) {
4243
+ _context46.next = 6;
4244
+ break;
4245
+ }
4246
+ throw new Error('当前订单没有待确认的 Wallet 支付');
4247
+ case 6:
4248
+ 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);
4249
+ effectiveAmountDue = Decimal.max(new Decimal((amountSnapshot === null || amountSnapshot === void 0 ? void 0 : amountSnapshot.amountGap) || 0).minus(pendingWalletAmount), 0);
4250
+ if (!effectiveAmountDue.gt(0.01)) {
4251
+ _context46.next = 10;
4252
+ break;
4253
+ }
4254
+ throw new Error('Wallet 支付尚未覆盖全部待支付金额');
4255
+ case 10:
4256
+ beforePaymentStatus = (_this$store$order$get4 = this.store.order.getTempOrder()) === null || _this$store$order$get4 === void 0 ? void 0 : _this$store$order$get4.payment_status;
4257
+ _context46.prev = 11;
4258
+ _context46.next = 14;
4259
+ return this.submitSalesOrder({
4260
+ smallTicketDataFlag: 1,
4261
+ confirmPendingVoucherPayments: true
4262
+ });
4263
+ case 14:
4264
+ submitResult = _context46.sent;
4265
+ if (!isRejectedSalesSubmitResult(submitResult)) {
4266
+ _context46.next = 17;
4267
+ break;
4268
+ }
4269
+ throw new Error(getSalesSubmitErrorMessage(submitResult));
4270
+ case 17:
4271
+ _context46.next = 27;
4272
+ break;
4273
+ case 19:
4274
+ _context46.prev = 19;
4275
+ _context46.t0 = _context46["catch"](11);
4276
+ this.store.order.setOrderPayments(beforePayments);
4277
+ restoredTempOrder = this.store.order.getTempOrder();
4278
+ if (restoredTempOrder && beforePaymentStatus !== undefined) {
4279
+ restoredTempOrder.payment_status = beforePaymentStatus;
4280
+ this.store.order.persistTempOrder();
4281
+ }
4282
+ _context46.next = 26;
4283
+ return this.store.order.recalculateSummary({
4284
+ createIfMissing: true
4285
+ });
4286
+ case 26:
4287
+ throw _context46.t0;
4288
+ case 27:
4289
+ if (!this.store.payment) {
4290
+ _context46.next = 38;
4291
+ break;
4292
+ }
4293
+ _context46.prev = 28;
4294
+ committed = this.getCommittedWalletAssets();
4295
+ walletState = this.store.payment.wallet.setCommittedWalletAssets(committed.ids, committed.assets);
4296
+ _context46.next = 33;
4297
+ return this.publishWalletAssetsState(walletState);
4298
+ case 33:
4299
+ _context46.next = 38;
4300
+ break;
4301
+ case 35:
4302
+ _context46.prev = 35;
4303
+ _context46.t1 = _context46["catch"](28);
4304
+ this.logWarning('confirmWalletPayment: Wallet committed 状态同步失败', {
4305
+ error: _context46.t1 instanceof Error ? _context46.t1.message : String(_context46.t1)
4306
+ });
4307
+ case 38:
4308
+ 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);
4309
+ return _context46.abrupt("return", {
4310
+ submitResult: submitResult,
4311
+ payments: this.store.order.getOrderPayments(),
4312
+ isOrderFullyPaid: new Decimal((latestAmountSnapshot === null || latestAmountSnapshot === void 0 ? void 0 : latestAmountSnapshot.amountGap) || 0).lte(0)
4313
+ });
4314
+ case 40:
4315
+ case "end":
4316
+ return _context46.stop();
4317
+ }
4318
+ }, _callee46, this, [[11, 19], [28, 35]]);
4319
+ }));
4320
+ function confirmWalletPayment() {
4321
+ return _confirmWalletPayment.apply(this, arguments);
4322
+ }
4323
+ return confirmWalletPayment;
4324
+ }()
4325
+ /**
4326
+ * 购物车现金直付:写入现金记录并等待支付同步完成。
4327
+ * 同步失败会恢复调用前 payments(包含 Wallet pending 状态)。
4328
+ */
4329
+ )
4330
+ }, {
4331
+ key: "payCash",
4332
+ value: (function () {
4333
+ var _payCash = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee47(params) {
4334
+ var _this$store$order$get6, _params$actualPaidAmo, _this$otherParams27, _this$window, _this$window$postMess;
4335
+ var amount, config, paymentMethod, roundingAmount, effectivePaymentAmount, beforePayments, beforePaymentStatus, uniquePaymentNumber, paymentTimestamp, actualPaidAmount, changeAmount, shopWalletPassId, payments, payment, syncResult, committed, walletState, restoredTempOrder;
4336
+ return _regeneratorRuntime().wrap(function _callee47$(_context47) {
4337
+ while (1) switch (_context47.prev = _context47.next) {
4338
+ case 0:
4339
+ if (this.store.order) {
4340
+ _context47.next = 2;
4341
+ break;
4342
+ }
4343
+ throw new Error('order 模块未初始化');
4344
+ case 2:
4345
+ amount = Number(params.amount || 0);
4346
+ if (!(!Number.isFinite(amount) || amount <= 0)) {
4347
+ _context47.next = 5;
4348
+ break;
4349
+ }
4350
+ throw new Error('现金支付金额必须大于 0');
4351
+ case 5:
4352
+ _context47.next = 7;
4353
+ return this.getCashPaymentConfig();
4354
+ case 7:
4355
+ config = _context47.sent;
4356
+ paymentMethod = config.paymentMethod;
4357
+ if (paymentMethod) {
4358
+ _context47.next = 11;
4359
+ break;
4360
+ }
4361
+ throw new Error('未找到可用的 CASHMANUAL 支付方式');
4362
+ case 11:
4363
+ if (!(config.amountDue <= 0)) {
4364
+ _context47.next = 13;
4365
+ break;
4366
+ }
4367
+ throw new Error('当前订单没有待支付金额');
4368
+ case 13:
4369
+ roundingAmount = Number(params.roundingAmount || 0);
4370
+ effectivePaymentAmount = new Decimal(amount).minus(roundingAmount);
4371
+ if (!effectivePaymentAmount.gt(new Decimal(config.amountDue).plus(0.01))) {
4372
+ _context47.next = 17;
4373
+ break;
4374
+ }
4375
+ throw new Error('现金支付金额超过当前待支付金额');
4376
+ case 17:
4377
+ beforePayments = cloneDeep(this.store.order.getOrderPayments());
4378
+ beforePaymentStatus = (_this$store$order$get6 = this.store.order.getTempOrder()) === null || _this$store$order$get6 === void 0 ? void 0 : _this$store$order$get6.payment_status;
4379
+ uniquePaymentNumber = createUuidV4();
4380
+ paymentTimestamp = dayjs().format('YYYY-MM-DD HH:mm:ss');
4381
+ actualPaidAmount = Number((_params$actualPaidAmo = params.actualPaidAmount) !== null && _params$actualPaidAmo !== void 0 ? _params$actualPaidAmo : amount);
4382
+ changeAmount = Number(params.changeAmount || 0);
4383
+ shopWalletPassId = (_this$otherParams27 = this.otherParams) === null || _this$otherParams27 === void 0 ? void 0 : _this$otherParams27.shop_wallet_pass_id;
4384
+ if (!(!Number.isFinite(actualPaidAmount) || actualPaidAmount + 0.01 < amount)) {
4385
+ _context47.next = 26;
4386
+ break;
4387
+ }
4388
+ throw new Error('顾客实收现金不能小于支付金额');
4389
+ case 26:
4390
+ (_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, {
4391
+ module: 'till',
4392
+ key: 'open_till',
4393
+ data: {
4394
+ type: 'cash'
4395
+ }
4396
+ });
4397
+ payments = this.store.order.addOrderPayment({
4398
+ amount: amount.toFixed(2),
4399
+ code: paymentMethod.code,
4400
+ custom_payment_id: paymentMethod.id,
4401
+ name: paymentMethod.name,
4402
+ custom_payment_type: paymentMethod.type,
4403
+ voucher_id: 0,
4404
+ rounding_amount: roundingAmount.toFixed(2),
4405
+ metadata: _objectSpread(_objectSpread({
4406
+ unique_payment_number: uniquePaymentNumber
4407
+ }, shopWalletPassId !== undefined && shopWalletPassId !== null ? {
4408
+ shop_wallet_pass_id: shopWalletPassId
4409
+ } : {}), {}, {
4410
+ actual_paid_amount: Number.isFinite(actualPaidAmount) ? actualPaidAmount : amount,
4411
+ change_given_amount: Number.isFinite(changeAmount) ? changeAmount : 0
4412
+ }),
4413
+ payment_time: paymentTimestamp,
4414
+ created_at: paymentTimestamp
4415
+ });
4416
+ payment = payments.find(function (item) {
4417
+ var _item$metadata2;
4418
+ return (item === null || item === void 0 || (_item$metadata2 = item.metadata) === null || _item$metadata2 === void 0 ? void 0 : _item$metadata2.unique_payment_number) === uniquePaymentNumber;
4419
+ });
4420
+ _context47.prev = 29;
4421
+ _context47.next = 32;
4422
+ return this.syncPaymentsToOrder({
4423
+ payments: payments,
4424
+ submitWhenPaid: true,
4425
+ smallTicketDataFlag: 1,
4426
+ confirmPendingVoucherPayments: true
4427
+ });
4428
+ case 32:
4429
+ syncResult = _context47.sent;
4430
+ if (!this.store.payment) {
4431
+ _context47.next = 38;
4432
+ break;
4433
+ }
4434
+ committed = this.getCommittedWalletAssets();
4435
+ walletState = this.store.payment.wallet.setCommittedWalletAssets(committed.ids, committed.assets);
4436
+ _context47.next = 38;
4437
+ return this.publishWalletAssetsState(walletState);
4438
+ case 38:
4439
+ return _context47.abrupt("return", {
4440
+ payment: payment || {},
4441
+ payments: this.store.order.getOrderPayments(),
4442
+ syncResult: syncResult,
4443
+ isOrderFullyPaid: syncResult.isOrderFullyPaid
4444
+ });
4445
+ case 41:
4446
+ _context47.prev = 41;
4447
+ _context47.t0 = _context47["catch"](29);
4448
+ this.store.order.setOrderPayments(beforePayments);
4449
+ restoredTempOrder = this.store.order.getTempOrder();
4450
+ if (restoredTempOrder && beforePaymentStatus !== undefined) {
4451
+ restoredTempOrder.payment_status = beforePaymentStatus;
4452
+ this.store.order.persistTempOrder();
4453
+ }
4454
+ _context47.next = 48;
4455
+ return this.store.order.recalculateSummary({
4456
+ createIfMissing: true
4457
+ });
4458
+ case 48:
4459
+ throw _context47.t0;
4460
+ case 49:
4461
+ case "end":
4462
+ return _context47.stop();
4463
+ }
4464
+ }, _callee47, this, [[29, 41]]);
4465
+ }));
4466
+ function payCash(_x38) {
4467
+ return _payCash.apply(this, arguments);
4468
+ }
4469
+ return payCash;
4470
+ }()
4471
+ /**
4472
+ * 提交一次已由支付设备确认成功的非 Wallet 支付。
4473
+ *
4474
+ * 与 addOrderPayment 不同,本入口不会启动后台 fire-and-forget 同步;调用方会等待
4475
+ * 本次 payment、当前 pending Wallet 以及订单提交共同完成。任何同步失败都会恢复
4476
+ * 调用前的 payments 与 payment_status,便于 UI 安全解锁并重试。
4477
+ */
4478
+ )
4479
+ }, {
4480
+ key: "commitPaymentMethodPayment",
4481
+ value: (function () {
4482
+ var _commitPaymentMethodPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee48(params) {
4483
+ var _this$store$order$get7, _this$store$order15, _this$store$order$get8, _params$metadata, _params$originAmount;
4484
+ var amount, paymentMethods, findPaymentMethod, paymentMethod, amountSnapshot, pendingWalletAmount, amountDue, beforePayments, beforePaymentStatus, paymentTimestamp, metadata, serviceCharge, serviceFee, payments, payment, syncResult, committed, walletState, restoredTempOrder;
4485
+ return _regeneratorRuntime().wrap(function _callee48$(_context48) {
4486
+ while (1) switch (_context48.prev = _context48.next) {
4487
+ case 0:
4488
+ if (this.store.order) {
4489
+ _context48.next = 2;
4490
+ break;
4491
+ }
4492
+ throw new Error('order 模块未初始化');
4493
+ case 2:
4494
+ amount = Number(params.amount || 0);
4495
+ if (!(!Number.isFinite(amount) || amount <= 0)) {
4496
+ _context48.next = 5;
4497
+ break;
4498
+ }
4499
+ throw new Error('支付金额必须大于 0');
4500
+ case 5:
4501
+ paymentMethods = this.getPaymentMethods();
4502
+ findPaymentMethod = function findPaymentMethod() {
4503
+ var methodCode = String(params.paymentMethodCode || '').toUpperCase();
4504
+ return paymentMethods.find(function (method) {
4505
+ var idMatched = params.paymentMethodId !== undefined && String(method.id) === String(params.paymentMethodId);
4506
+ var codeMatched = Boolean(methodCode) && String(method.code || '').toUpperCase() === methodCode;
4507
+ return (idMatched || codeMatched) && method.enabled !== false && method.enable !== false;
4508
+ });
4509
+ };
4510
+ paymentMethod = findPaymentMethod();
4511
+ if (paymentMethod) {
4512
+ _context48.next = 13;
4513
+ break;
4514
+ }
4515
+ _context48.next = 11;
4516
+ return this.getPaymentMethodsAsync();
4517
+ case 11:
4518
+ paymentMethods = _context48.sent;
4519
+ paymentMethod = findPaymentMethod();
4520
+ case 13:
4521
+ if (paymentMethod) {
4522
+ _context48.next = 15;
4523
+ break;
4524
+ }
4525
+ throw new Error("\u672A\u627E\u5230\u53EF\u7528\u7684\u652F\u4ED8\u65B9\u5F0F\uFF1A".concat(params.paymentMethodCode || params.paymentMethodId || ''));
4526
+ case 15:
4527
+ 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);
4528
+ pendingWalletAmount = this.getPendingWalletPaymentAmount();
4529
+ amountDue = Decimal.max(new Decimal((amountSnapshot === null || amountSnapshot === void 0 ? void 0 : amountSnapshot.amountGap) || 0).minus(pendingWalletAmount), 0);
4530
+ if (!amountDue.lte(0)) {
4531
+ _context48.next = 20;
4532
+ break;
4533
+ }
4534
+ throw new Error('当前订单没有待支付金额');
4535
+ case 20:
4536
+ if (!new Decimal(amount).gt(amountDue.plus(0.01))) {
4537
+ _context48.next = 22;
4538
+ break;
4539
+ }
4540
+ throw new Error('支付金额超过当前待支付金额');
4541
+ case 22:
4542
+ beforePayments = cloneDeep(this.store.order.getOrderPayments());
4543
+ beforePaymentStatus = (_this$store$order$get8 = this.store.order.getTempOrder()) === null || _this$store$order$get8 === void 0 ? void 0 : _this$store$order$get8.payment_status;
4544
+ paymentTimestamp = dayjs().format('YYYY-MM-DD HH:mm:ss');
4545
+ metadata = _objectSpread(_objectSpread({}, params.metadata || {}), {}, {
4546
+ unique_payment_number: ((_params$metadata = params.metadata) === null || _params$metadata === void 0 ? void 0 : _params$metadata.unique_payment_number) || createUuidV4()
4547
+ });
4548
+ serviceCharge = params.serviceCharge ? {
4549
+ amount: String(params.serviceCharge.amount || 0),
4550
+ percentage: String(params.serviceCharge.percentage || 0)
4551
+ } : undefined;
4552
+ 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;
4553
+ payments = this.store.order.addOrderPayment(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, params.paymentData || {}), {}, {
4554
+ amount: amount.toFixed(2)
4555
+ }, params.originAmount !== undefined ? {
4556
+ origin_amount: Number(params.originAmount).toFixed(2)
4557
+ } : {}), {}, {
4558
+ code: paymentMethod.code,
4559
+ custom_payment_id: paymentMethod.id,
4560
+ name: paymentMethod.name,
4561
+ custom_payment_type: paymentMethod.type,
4562
+ voucher_id: 0
4563
+ }, serviceCharge ? {
4564
+ service_charge: serviceCharge
4565
+ } : {}), serviceFee !== undefined ? {
4566
+ service_fee: serviceFee
4567
+ } : {}), {}, {
4568
+ metadata: metadata,
4569
+ payment_time: paymentTimestamp,
4570
+ created_at: paymentTimestamp
4571
+ }));
4572
+ payment = payments.find(function (item) {
4573
+ var _item$metadata3;
4574
+ 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;
4575
+ });
4576
+ _context48.prev = 30;
4577
+ _context48.next = 33;
4578
+ return this.syncPaymentsToOrder({
4579
+ payments: payments,
4580
+ submitWhenPaid: true,
4581
+ smallTicketDataFlag: 1,
4582
+ confirmPendingVoucherPayments: true
4583
+ });
4584
+ case 33:
4585
+ syncResult = _context48.sent;
4586
+ if (!this.store.payment) {
4587
+ _context48.next = 39;
4588
+ break;
4589
+ }
4590
+ committed = this.getCommittedWalletAssets();
4591
+ walletState = this.store.payment.wallet.setCommittedWalletAssets(committed.ids, committed.assets);
4592
+ _context48.next = 39;
4593
+ return this.publishWalletAssetsState(walletState);
4594
+ case 39:
4595
+ return _context48.abrupt("return", {
4596
+ payment: payment || {},
4597
+ payments: this.store.order.getOrderPayments(),
4598
+ syncResult: syncResult,
4599
+ isOrderFullyPaid: syncResult.isOrderFullyPaid
4600
+ });
4601
+ case 42:
4602
+ _context48.prev = 42;
4603
+ _context48.t0 = _context48["catch"](30);
4604
+ this.store.order.setOrderPayments(beforePayments);
4605
+ restoredTempOrder = this.store.order.getTempOrder();
4606
+ if (restoredTempOrder && beforePaymentStatus !== undefined) {
4607
+ restoredTempOrder.payment_status = beforePaymentStatus;
4608
+ this.store.order.persistTempOrder();
4609
+ }
4610
+ _context48.next = 49;
4611
+ return this.store.order.recalculateSummary({
4612
+ createIfMissing: true
4613
+ });
4614
+ case 49:
4615
+ throw _context48.t0;
4616
+ case 50:
4617
+ case "end":
4618
+ return _context48.stop();
4619
+ }
4620
+ }, _callee48, this, [[30, 42]]);
4621
+ }));
4622
+ function commitPaymentMethodPayment(_x39) {
4623
+ return _commitPaymentMethodPayment.apply(this, arguments);
4624
+ }
4625
+ return commitPaymentMethodPayment;
4626
+ }()
4627
+ /**
4628
+ * 按当前店铺的现金舍入配置计算金额,供现金支付 UI 使用。
4629
+ *
4630
+ * 舍入开关取自 CASHMANUAL 支付方式;舍入规则取自
4631
+ * otherParams.order_rounding_setting,金额算法统一由 PaymentModule 维护。
4632
+ */
4633
+ )
4634
+ }, {
4635
+ key: "roundAmount",
4636
+ value: (function () {
4637
+ var _roundAmount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee49(params) {
4638
+ var _cashManualPayment$me, _this$otherParams$ord2, _this$otherParams$ord3;
4639
+ var amount, cashManualPayment;
4640
+ return _regeneratorRuntime().wrap(function _callee49$(_context49) {
4641
+ while (1) switch (_context49.prev = _context49.next) {
4642
+ case 0:
4643
+ amount = params.amount;
4644
+ cashManualPayment = this.paymentMethodsCache.find(function (paymentMethod) {
4645
+ return paymentMethod.code === 'CASHMANUAL';
4646
+ });
4647
+ if (cashManualPayment !== null && cashManualPayment !== void 0 && (_cashManualPayment$me = cashManualPayment.metadata) !== null && _cashManualPayment$me !== void 0 && _cashManualPayment$me.order_rounding_switch) {
4648
+ _context49.next = 4;
4649
+ break;
4650
+ }
4651
+ return _context49.abrupt("return", {
4652
+ originalAmount: amount.toString(),
4653
+ roundedAmount: amount.toString(),
4654
+ roundingDifference: '0.00'
4655
+ });
4656
+ case 4:
4657
+ if (this.payment) {
4658
+ _context49.next = 6;
4659
+ break;
4660
+ }
4661
+ throw new Error('payment 模块未初始化');
4662
+ case 6:
4663
+ 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));
4664
+ case 7:
4665
+ case "end":
4666
+ return _context49.stop();
4667
+ }
4668
+ }, _callee49, this);
4669
+ }));
4670
+ function roundAmount(_x40) {
4671
+ return _roundAmount.apply(this, arguments);
4672
+ }
4673
+ return roundAmount;
4674
+ }()
3323
4675
  /**
3324
4676
  * 发送支付链接。
3325
4677
  *
3326
4678
  * 如果没有 orderIds 或显式 submitBeforeSend,会先提交当前本地订单到云端;
3327
4679
  * 只有成功拿到远端 order_id 后才调用 OrderModule 发送邮件。
3328
4680
  */
4681
+ )
3329
4682
  }, {
3330
4683
  key: "sendCustomerPayLink",
3331
4684
  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) {
4685
+ var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee50(params) {
4686
+ var orderIds, _ref34, _ref35, _submitResult$data$or, _submitResult$data, _submitResult$data2, submitResult, orderId;
4687
+ return _regeneratorRuntime().wrap(function _callee50$(_context50) {
4688
+ while (1) switch (_context50.prev = _context50.next) {
3336
4689
  case 0:
3337
4690
  if (this.store.order) {
3338
- _context34.next = 2;
4691
+ _context50.next = 2;
3339
4692
  break;
3340
4693
  }
3341
4694
  throw new Error('order 模块未初始化');
3342
4695
  case 2:
3343
4696
  orderIds = params.order_ids || params.orderIds || [];
3344
4697
  if (!(!orderIds.length || params.submitBeforeSend)) {
3345
- _context34.next = 11;
4698
+ _context50.next = 11;
3346
4699
  break;
3347
4700
  }
3348
- _context34.next = 6;
4701
+ _context50.next = 6;
3349
4702
  return this.submitSalesOrder({
3350
4703
  smallTicketDataFlag: 1
3351
4704
  });
3352
4705
  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;
4706
+ submitResult = _context50.sent;
4707
+ 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
4708
  if (orderId) {
3356
- _context34.next = 10;
4709
+ _context50.next = 10;
3357
4710
  break;
3358
4711
  }
3359
4712
  throw new Error('本地订单提交云端失败,无法发送支付链接');
3360
4713
  case 10:
3361
4714
  orderIds = [orderId];
3362
4715
  case 11:
3363
- return _context34.abrupt("return", this.store.order.sendCustomerPayLink({
4716
+ return _context50.abrupt("return", this.store.order.sendCustomerPayLink({
3364
4717
  emails: params.emails,
3365
4718
  notify_action: params.notify_action,
3366
4719
  order_ids: orderIds
3367
4720
  }));
3368
4721
  case 12:
3369
4722
  case "end":
3370
- return _context34.stop();
4723
+ return _context50.stop();
3371
4724
  }
3372
- }, _callee34, this);
4725
+ }, _callee50, this);
3373
4726
  }));
3374
- function sendCustomerPayLink(_x26) {
4727
+ function sendCustomerPayLink(_x41) {
3375
4728
  return _sendCustomerPayLink.apply(this, arguments);
3376
4729
  }
3377
4730
  return sendCustomerPayLink;
@@ -3384,27 +4737,27 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3384
4737
  }, {
3385
4738
  key: "calculateProductBookingPrice",
3386
4739
  value: function () {
3387
- var _calculateProductBookingPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(params) {
4740
+ var _calculateProductBookingPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee51(params) {
3388
4741
  var _params$customer_id;
3389
4742
  var quotation, customerId, authoritativeProduct, product;
3390
- return _regeneratorRuntime().wrap(function _callee35$(_context35) {
3391
- while (1) switch (_context35.prev = _context35.next) {
4743
+ return _regeneratorRuntime().wrap(function _callee51$(_context51) {
4744
+ while (1) switch (_context51.prev = _context51.next) {
3392
4745
  case 0:
3393
4746
  quotation = this.store.quotation;
3394
4747
  customerId = (_params$customer_id = params.customer_id) !== null && _params$customer_id !== void 0 ? _params$customer_id : this.getCurrentOrderCustomerId();
3395
- _context35.next = 4;
4748
+ _context51.next = 4;
3396
4749
  return this.loadProductForPriceQuery(params, customerId);
3397
4750
  case 4:
3398
- authoritativeProduct = _context35.sent;
4751
+ authoritativeProduct = _context51.sent;
3399
4752
  product = this.mergeProductForPriceQuery(params.product, authoritativeProduct);
3400
- _context35.next = 8;
4753
+ _context51.next = 8;
3401
4754
  return this.loadQuotationForPriceQuery({
3402
4755
  quotation: quotation,
3403
4756
  customer_id: customerId,
3404
4757
  channel: params.channel
3405
4758
  });
3406
4759
  case 8:
3407
- return _context35.abrupt("return", calculateBaseSalesProductBookingPrice(_objectSpread(_objectSpread({}, params), {}, {
4760
+ return _context51.abrupt("return", calculateBaseSalesProductBookingPrice(_objectSpread(_objectSpread({}, params), {}, {
3408
4761
  product: product,
3409
4762
  fallback_price: authoritativeProduct ? undefined : params.fallback_price,
3410
4763
  customer_id: customerId,
@@ -3412,11 +4765,11 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3412
4765
  })));
3413
4766
  case 9:
3414
4767
  case "end":
3415
- return _context35.stop();
4768
+ return _context51.stop();
3416
4769
  }
3417
- }, _callee35, this);
4770
+ }, _callee51, this);
3418
4771
  }));
3419
- function calculateProductBookingPrice(_x27) {
4772
+ function calculateProductBookingPrice(_x42) {
3420
4773
  return _calculateProductBookingPrice.apply(this, arguments);
3421
4774
  }
3422
4775
  return calculateProductBookingPrice;
@@ -3424,7 +4777,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3424
4777
  }, {
3425
4778
  key: "getQuotationCustomerScopeInfo",
3426
4779
  value: function getQuotationCustomerScopeInfo() {
3427
- var _this13 = this;
4780
+ var _this15 = this;
3428
4781
  var quotation = this.store.quotation;
3429
4782
  if (quotation && typeof quotation.getQuotationCustomerScopeInfo === 'function') {
3430
4783
  return quotation.getQuotationCustomerScopeInfo();
@@ -3436,7 +4789,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3436
4789
  }).map(function (item) {
3437
4790
  var localSeen = new Set();
3438
4791
  var customers = item.customer.filter(function (customer) {
3439
- var customerId = _this13.normalizePriceContextCustomerId(customer === null || customer === void 0 ? void 0 : customer.id);
4792
+ var customerId = _this15.normalizePriceContextCustomerId(customer === null || customer === void 0 ? void 0 : customer.id);
3440
4793
  if (!customerId || localSeen.has(customerId)) return false;
3441
4794
  localSeen.add(customerId);
3442
4795
  if (!customerById.has(customerId)) customerById.set(customerId, customer);
@@ -3486,32 +4839,32 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3486
4839
  }, {
3487
4840
  key: "calculateProductBookingPrices",
3488
4841
  value: function () {
3489
- var _calculateProductBookingPrices = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(paramsList) {
4842
+ var _calculateProductBookingPrices = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee53(paramsList) {
3490
4843
  var _paramsList$0$custome,
3491
4844
  _paramsList$,
3492
- _this14 = this,
4845
+ _this16 = this,
3493
4846
  _paramsList$2;
3494
4847
  var quotation, customerId, productMapsByGroup, groups;
3495
- return _regeneratorRuntime().wrap(function _callee37$(_context37) {
3496
- while (1) switch (_context37.prev = _context37.next) {
4848
+ return _regeneratorRuntime().wrap(function _callee53$(_context53) {
4849
+ while (1) switch (_context53.prev = _context53.next) {
3497
4850
  case 0:
3498
4851
  if (paramsList.length) {
3499
- _context37.next = 2;
4852
+ _context53.next = 2;
3500
4853
  break;
3501
4854
  }
3502
- return _context37.abrupt("return", []);
4855
+ return _context53.abrupt("return", []);
3503
4856
  case 2:
3504
4857
  quotation = this.store.quotation;
3505
4858
  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
4859
  productMapsByGroup = new Map();
3507
4860
  groups = new Map();
3508
4861
  paramsList.forEach(function (params) {
3509
- var _this14$otherParams;
4862
+ var _this16$otherParams;
3510
4863
  var product = params.product || {};
3511
- var productId = _this14.getPriceQueryProductId(product);
4864
+ var productId = _this16.getPriceQueryProductId(product);
3512
4865
  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);
4866
+ var schedule = _this16.getPriceQuerySchedule(params);
4867
+ var channel = params.channel || ((_this16$otherParams = _this16.otherParams) === null || _this16$otherParams === void 0 ? void 0 : _this16$otherParams.channel);
3515
4868
  var groupKey = [schedule.schedule_date, schedule.schedule_datetime, channel || ''].join('|');
3516
4869
  var group = groups.get(groupKey) || {
3517
4870
  ids: new Set(),
@@ -3521,51 +4874,51 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3521
4874
  group.ids.add(productId);
3522
4875
  groups.set(groupKey, group);
3523
4876
  });
3524
- _context37.next = 9;
4877
+ _context53.next = 9;
3525
4878
  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) {
4879
+ var _ref37 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee52(_ref36) {
4880
+ var _ref38, groupKey, group, productsById;
4881
+ return _regeneratorRuntime().wrap(function _callee52$(_context52) {
4882
+ while (1) switch (_context52.prev = _context52.next) {
3530
4883
  case 0:
3531
- _ref29 = _slicedToArray(_ref27, 2), groupKey = _ref29[0], group = _ref29[1];
3532
- _context36.next = 3;
3533
- return _this14.loadProductsForPriceQuery({
4884
+ _ref38 = _slicedToArray(_ref36, 2), groupKey = _ref38[0], group = _ref38[1];
4885
+ _context52.next = 3;
4886
+ return _this16.loadProductsForPriceQuery({
3534
4887
  ids: Array.from(group.ids),
3535
4888
  schedule: group.schedule,
3536
4889
  customerId: customerId,
3537
4890
  channel: group.channel
3538
4891
  });
3539
4892
  case 3:
3540
- productsById = _context36.sent;
4893
+ productsById = _context52.sent;
3541
4894
  productMapsByGroup.set(groupKey, productsById);
3542
4895
  case 5:
3543
4896
  case "end":
3544
- return _context36.stop();
4897
+ return _context52.stop();
3545
4898
  }
3546
- }, _callee36);
4899
+ }, _callee52);
3547
4900
  }));
3548
- return function (_x29) {
3549
- return _ref28.apply(this, arguments);
4901
+ return function (_x44) {
4902
+ return _ref37.apply(this, arguments);
3550
4903
  };
3551
4904
  }()));
3552
4905
  case 9:
3553
- _context37.next = 11;
4906
+ _context53.next = 11;
3554
4907
  return this.loadQuotationForPriceQuery({
3555
4908
  quotation: quotation,
3556
4909
  customer_id: customerId,
3557
4910
  channel: (_paramsList$2 = paramsList[0]) === null || _paramsList$2 === void 0 ? void 0 : _paramsList$2.channel
3558
4911
  });
3559
4912
  case 11:
3560
- return _context37.abrupt("return", paramsList.map(function (params) {
3561
- var _this14$otherParams2, _productMapsByGroup$g;
4913
+ return _context53.abrupt("return", paramsList.map(function (params) {
4914
+ var _this16$otherParams2, _productMapsByGroup$g;
3562
4915
  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);
4916
+ var productId = _this16.getPriceQueryProductId(productInput);
4917
+ var schedule = _this16.getPriceQuerySchedule(params);
4918
+ var channel = params.channel || ((_this16$otherParams2 = _this16.otherParams) === null || _this16$otherParams2 === void 0 ? void 0 : _this16$otherParams2.channel);
3566
4919
  var groupKey = [schedule.schedule_date, schedule.schedule_datetime, channel || ''].join('|');
3567
4920
  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);
4921
+ var product = _this16.mergeProductForPriceQuery(productInput, authoritativeProduct);
3569
4922
  return calculateBaseSalesProductBookingPrice(_objectSpread(_objectSpread({}, params), {}, {
3570
4923
  product: product,
3571
4924
  fallback_price: authoritativeProduct ? undefined : params.fallback_price,
@@ -3575,11 +4928,11 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3575
4928
  }));
3576
4929
  case 12:
3577
4930
  case "end":
3578
- return _context37.stop();
4931
+ return _context53.stop();
3579
4932
  }
3580
- }, _callee37, this);
4933
+ }, _callee53, this);
3581
4934
  }));
3582
- function calculateProductBookingPrices(_x28) {
4935
+ function calculateProductBookingPrices(_x43) {
3583
4936
  return _calculateProductBookingPrices.apply(this, arguments);
3584
4937
  }
3585
4938
  return calculateProductBookingPrices;
@@ -3587,34 +4940,34 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3587
4940
  }, {
3588
4941
  key: "addProductToOrder",
3589
4942
  value: function () {
3590
- var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(product, booking) {
4943
+ var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee54(product, booking) {
3591
4944
  var products;
3592
- return _regeneratorRuntime().wrap(function _callee38$(_context38) {
3593
- while (1) switch (_context38.prev = _context38.next) {
4945
+ return _regeneratorRuntime().wrap(function _callee54$(_context54) {
4946
+ while (1) switch (_context54.prev = _context54.next) {
3594
4947
  case 0:
3595
- _context38.prev = 0;
4948
+ _context54.prev = 0;
3596
4949
  if (this.store.order) {
3597
- _context38.next = 3;
4950
+ _context54.next = 3;
3598
4951
  break;
3599
4952
  }
3600
4953
  throw new Error('order 模块未初始化');
3601
4954
  case 3:
3602
- _context38.next = 5;
4955
+ _context54.next = 5;
3603
4956
  return this.store.order.addProductToOrder(product, booking);
3604
4957
  case 5:
3605
- products = _context38.sent;
3606
- return _context38.abrupt("return", products);
4958
+ products = _context54.sent;
4959
+ return _context54.abrupt("return", products);
3607
4960
  case 9:
3608
- _context38.prev = 9;
3609
- _context38.t0 = _context38["catch"](0);
3610
- throw _context38.t0;
4961
+ _context54.prev = 9;
4962
+ _context54.t0 = _context54["catch"](0);
4963
+ throw _context54.t0;
3611
4964
  case 12:
3612
4965
  case "end":
3613
- return _context38.stop();
4966
+ return _context54.stop();
3614
4967
  }
3615
- }, _callee38, this, [[0, 9]]);
4968
+ }, _callee54, this, [[0, 9]]);
3616
4969
  }));
3617
- function addProductToOrder(_x30, _x31) {
4970
+ function addProductToOrder(_x45, _x46) {
3618
4971
  return _addProductToOrder.apply(this, arguments);
3619
4972
  }
3620
4973
  return addProductToOrder;
@@ -3622,34 +4975,34 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3622
4975
  }, {
3623
4976
  key: "updateOrderProduct",
3624
4977
  value: function () {
3625
- var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(params) {
4978
+ var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee55(params) {
3626
4979
  var products;
3627
- return _regeneratorRuntime().wrap(function _callee39$(_context39) {
3628
- while (1) switch (_context39.prev = _context39.next) {
4980
+ return _regeneratorRuntime().wrap(function _callee55$(_context55) {
4981
+ while (1) switch (_context55.prev = _context55.next) {
3629
4982
  case 0:
3630
- _context39.prev = 0;
4983
+ _context55.prev = 0;
3631
4984
  if (this.store.order) {
3632
- _context39.next = 3;
4985
+ _context55.next = 3;
3633
4986
  break;
3634
4987
  }
3635
4988
  throw new Error('order 模块未初始化');
3636
4989
  case 3:
3637
- _context39.next = 5;
4990
+ _context55.next = 5;
3638
4991
  return this.store.order.updateOrderProduct(params);
3639
4992
  case 5:
3640
- products = _context39.sent;
3641
- return _context39.abrupt("return", products);
4993
+ products = _context55.sent;
4994
+ return _context55.abrupt("return", products);
3642
4995
  case 9:
3643
- _context39.prev = 9;
3644
- _context39.t0 = _context39["catch"](0);
3645
- throw _context39.t0;
4996
+ _context55.prev = 9;
4997
+ _context55.t0 = _context55["catch"](0);
4998
+ throw _context55.t0;
3646
4999
  case 12:
3647
5000
  case "end":
3648
- return _context39.stop();
5001
+ return _context55.stop();
3649
5002
  }
3650
- }, _callee39, this, [[0, 9]]);
5003
+ }, _callee55, this, [[0, 9]]);
3651
5004
  }));
3652
- function updateOrderProduct(_x32) {
5005
+ function updateOrderProduct(_x47) {
3653
5006
  return _updateOrderProduct.apply(this, arguments);
3654
5007
  }
3655
5008
  return updateOrderProduct;
@@ -3657,34 +5010,34 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3657
5010
  }, {
3658
5011
  key: "updateOrderProducts",
3659
5012
  value: function () {
3660
- var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(paramsList) {
5013
+ var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee56(paramsList) {
3661
5014
  var products;
3662
- return _regeneratorRuntime().wrap(function _callee40$(_context40) {
3663
- while (1) switch (_context40.prev = _context40.next) {
5015
+ return _regeneratorRuntime().wrap(function _callee56$(_context56) {
5016
+ while (1) switch (_context56.prev = _context56.next) {
3664
5017
  case 0:
3665
- _context40.prev = 0;
5018
+ _context56.prev = 0;
3666
5019
  if (this.store.order) {
3667
- _context40.next = 3;
5020
+ _context56.next = 3;
3668
5021
  break;
3669
5022
  }
3670
5023
  throw new Error('order 模块未初始化');
3671
5024
  case 3:
3672
- _context40.next = 5;
5025
+ _context56.next = 5;
3673
5026
  return this.store.order.updateOrderProducts(paramsList);
3674
5027
  case 5:
3675
- products = _context40.sent;
3676
- return _context40.abrupt("return", products);
5028
+ products = _context56.sent;
5029
+ return _context56.abrupt("return", products);
3677
5030
  case 9:
3678
- _context40.prev = 9;
3679
- _context40.t0 = _context40["catch"](0);
3680
- throw _context40.t0;
5031
+ _context56.prev = 9;
5032
+ _context56.t0 = _context56["catch"](0);
5033
+ throw _context56.t0;
3681
5034
  case 12:
3682
5035
  case "end":
3683
- return _context40.stop();
5036
+ return _context56.stop();
3684
5037
  }
3685
- }, _callee40, this, [[0, 9]]);
5038
+ }, _callee56, this, [[0, 9]]);
3686
5039
  }));
3687
- function updateOrderProducts(_x33) {
5040
+ function updateOrderProducts(_x48) {
3688
5041
  return _updateOrderProducts.apply(this, arguments);
3689
5042
  }
3690
5043
  return updateOrderProducts;
@@ -3692,34 +5045,34 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3692
5045
  }, {
3693
5046
  key: "updateOrderProductQuantity",
3694
5047
  value: function () {
3695
- var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(params) {
5048
+ var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee57(params) {
3696
5049
  var products;
3697
- return _regeneratorRuntime().wrap(function _callee41$(_context41) {
3698
- while (1) switch (_context41.prev = _context41.next) {
5050
+ return _regeneratorRuntime().wrap(function _callee57$(_context57) {
5051
+ while (1) switch (_context57.prev = _context57.next) {
3699
5052
  case 0:
3700
- _context41.prev = 0;
5053
+ _context57.prev = 0;
3701
5054
  if (this.store.order) {
3702
- _context41.next = 3;
5055
+ _context57.next = 3;
3703
5056
  break;
3704
5057
  }
3705
5058
  throw new Error('order 模块未初始化');
3706
5059
  case 3:
3707
- _context41.next = 5;
5060
+ _context57.next = 5;
3708
5061
  return this.store.order.updateOrderProductQuantity(params);
3709
5062
  case 5:
3710
- products = _context41.sent;
3711
- return _context41.abrupt("return", products);
5063
+ products = _context57.sent;
5064
+ return _context57.abrupt("return", products);
3712
5065
  case 9:
3713
- _context41.prev = 9;
3714
- _context41.t0 = _context41["catch"](0);
3715
- throw _context41.t0;
5066
+ _context57.prev = 9;
5067
+ _context57.t0 = _context57["catch"](0);
5068
+ throw _context57.t0;
3716
5069
  case 12:
3717
5070
  case "end":
3718
- return _context41.stop();
5071
+ return _context57.stop();
3719
5072
  }
3720
- }, _callee41, this, [[0, 9]]);
5073
+ }, _callee57, this, [[0, 9]]);
3721
5074
  }));
3722
- function updateOrderProductQuantity(_x34) {
5075
+ function updateOrderProductQuantity(_x49) {
3723
5076
  return _updateOrderProductQuantity.apply(this, arguments);
3724
5077
  }
3725
5078
  return updateOrderProductQuantity;
@@ -3742,12 +5095,12 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3742
5095
  }, {
3743
5096
  key: "setOrderProductLineNote",
3744
5097
  value: (function () {
3745
- var _setOrderProductLineNote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42(identity, note) {
5098
+ var _setOrderProductLineNote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee58(identity, note) {
3746
5099
  var params, products;
3747
- return _regeneratorRuntime().wrap(function _callee42$(_context42) {
3748
- while (1) switch (_context42.prev = _context42.next) {
5100
+ return _regeneratorRuntime().wrap(function _callee58$(_context58) {
5101
+ while (1) switch (_context58.prev = _context58.next) {
3749
5102
  case 0:
3750
- _context42.prev = 0;
5103
+ _context58.prev = 0;
3751
5104
  params = {
3752
5105
  product_id: identity.product_id,
3753
5106
  product_variant_id: identity.product_variant_id,
@@ -3762,22 +5115,22 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3762
5115
  params.product_sku = identity.product_sku;
3763
5116
  }
3764
5117
  if (identity.product_bundle !== undefined) params.product_bundle = identity.product_bundle;
3765
- _context42.next = 7;
5118
+ _context58.next = 7;
3766
5119
  return this.updateOrderProduct(params);
3767
5120
  case 7:
3768
- products = _context42.sent;
3769
- return _context42.abrupt("return", products);
5121
+ products = _context58.sent;
5122
+ return _context58.abrupt("return", products);
3770
5123
  case 11:
3771
- _context42.prev = 11;
3772
- _context42.t0 = _context42["catch"](0);
3773
- throw _context42.t0;
5124
+ _context58.prev = 11;
5125
+ _context58.t0 = _context58["catch"](0);
5126
+ throw _context58.t0;
3774
5127
  case 14:
3775
5128
  case "end":
3776
- return _context42.stop();
5129
+ return _context58.stop();
3777
5130
  }
3778
- }, _callee42, this, [[0, 11]]);
5131
+ }, _callee58, this, [[0, 11]]);
3779
5132
  }));
3780
- function setOrderProductLineNote(_x35, _x36) {
5133
+ function setOrderProductLineNote(_x50, _x51) {
3781
5134
  return _setOrderProductLineNote.apply(this, arguments);
3782
5135
  }
3783
5136
  return setOrderProductLineNote;
@@ -3792,32 +5145,32 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3792
5145
  }, {
3793
5146
  key: "removeProductsFromOrder",
3794
5147
  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) {
5148
+ var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee59(identities) {
5149
+ return _regeneratorRuntime().wrap(function _callee59$(_context59) {
5150
+ while (1) switch (_context59.prev = _context59.next) {
3798
5151
  case 0:
3799
- _context43.prev = 0;
5152
+ _context59.prev = 0;
3800
5153
  if (this.store.order) {
3801
- _context43.next = 3;
5154
+ _context59.next = 3;
3802
5155
  break;
3803
5156
  }
3804
5157
  throw new Error('order 模块未初始化');
3805
5158
  case 3:
3806
- _context43.next = 5;
5159
+ _context59.next = 5;
3807
5160
  return this.store.order.removeProductsFromOrder(identities);
3808
5161
  case 5:
3809
- return _context43.abrupt("return", _context43.sent);
5162
+ return _context59.abrupt("return", _context59.sent);
3810
5163
  case 8:
3811
- _context43.prev = 8;
3812
- _context43.t0 = _context43["catch"](0);
3813
- throw _context43.t0;
5164
+ _context59.prev = 8;
5165
+ _context59.t0 = _context59["catch"](0);
5166
+ throw _context59.t0;
3814
5167
  case 11:
3815
5168
  case "end":
3816
- return _context43.stop();
5169
+ return _context59.stop();
3817
5170
  }
3818
- }, _callee43, this, [[0, 8]]);
5171
+ }, _callee59, this, [[0, 8]]);
3819
5172
  }));
3820
- function removeProductsFromOrder(_x37) {
5173
+ function removeProductsFromOrder(_x52) {
3821
5174
  return _removeProductsFromOrder.apply(this, arguments);
3822
5175
  }
3823
5176
  return removeProductsFromOrder;
@@ -3825,18 +5178,18 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3825
5178
  }, {
3826
5179
  key: "removeProductFromOrder",
3827
5180
  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) {
5181
+ var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee60(identity) {
5182
+ return _regeneratorRuntime().wrap(function _callee60$(_context60) {
5183
+ while (1) switch (_context60.prev = _context60.next) {
3831
5184
  case 0:
3832
- return _context44.abrupt("return", this.removeProductsFromOrder([identity]));
5185
+ return _context60.abrupt("return", this.removeProductsFromOrder([identity]));
3833
5186
  case 1:
3834
5187
  case "end":
3835
- return _context44.stop();
5188
+ return _context60.stop();
3836
5189
  }
3837
- }, _callee44, this);
5190
+ }, _callee60, this);
3838
5191
  }));
3839
- function removeProductFromOrder(_x38) {
5192
+ function removeProductFromOrder(_x53) {
3840
5193
  return _removeProductFromOrder.apply(this, arguments);
3841
5194
  }
3842
5195
  return removeProductFromOrder;
@@ -3886,23 +5239,23 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3886
5239
  }, {
3887
5240
  key: "applyPromotion",
3888
5241
  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) {
5242
+ var _applyPromotion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee61() {
5243
+ return _regeneratorRuntime().wrap(function _callee61$(_context61) {
5244
+ while (1) switch (_context61.prev = _context61.next) {
3892
5245
  case 0:
3893
5246
  if (this.store.order) {
3894
- _context45.next = 2;
5247
+ _context61.next = 2;
3895
5248
  break;
3896
5249
  }
3897
5250
  throw new Error('order 模块未初始化');
3898
5251
  case 2:
3899
- _context45.next = 4;
5252
+ _context61.next = 4;
3900
5253
  return this.store.order.applyPromotion();
3901
5254
  case 4:
3902
5255
  case "end":
3903
- return _context45.stop();
5256
+ return _context61.stop();
3904
5257
  }
3905
- }, _callee45, this);
5258
+ }, _callee61, this);
3906
5259
  }));
3907
5260
  function applyPromotion() {
3908
5261
  return _applyPromotion.apply(this, arguments);
@@ -3912,16 +5265,16 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3912
5265
  }, {
3913
5266
  key: "getUnfulfilledPromotions",
3914
5267
  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()) || [];
5268
+ var _this$store$order16;
5269
+ return ((_this$store$order16 = this.store.order) === null || _this$store$order16 === void 0 ? void 0 : _this$store$order16.getUnfulfilledPromotions()) || [];
3917
5270
  }
3918
5271
 
3919
5272
  /** 最近一次促销计算输出的赠品操作 diff。 */
3920
5273
  }, {
3921
5274
  key: "getLastGiftActions",
3922
5275
  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;
5276
+ var _this$store$order17;
5277
+ return ((_this$store$order17 = this.store.order) === null || _this$store$order17 === void 0 ? void 0 : _this$store$order17.getLastGiftActions()) || null;
3925
5278
  }
3926
5279
 
3927
5280
  // 获取商品列表
@@ -3929,18 +5282,18 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3929
5282
  }, {
3930
5283
  key: "getProductList",
3931
5284
  value: function () {
3932
- var _getProductList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee46() {
3933
- var _this$otherParams22;
5285
+ var _getProductList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee62() {
5286
+ var _this$otherParams28;
3934
5287
  var menu_list_ids, _this$store$products, res;
3935
- return _regeneratorRuntime().wrap(function _callee46$(_context46) {
3936
- while (1) switch (_context46.prev = _context46.next) {
5288
+ return _regeneratorRuntime().wrap(function _callee62$(_context62) {
5289
+ while (1) switch (_context62.prev = _context62.next) {
3937
5290
  case 0:
3938
5291
  // 可以直接通过配置里的 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) {
5292
+ 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
5293
  return Number(n.value);
3941
5294
  })) || [];
3942
- _context46.prev = 1;
3943
- _context46.next = 4;
5295
+ _context62.prev = 1;
5296
+ _context62.next = 4;
3944
5297
  return (_this$store$products = this.store.products) === null || _this$store$products === void 0 ? void 0 : _this$store$products.loadProducts({
3945
5298
  menu_list_ids: menu_list_ids,
3946
5299
  cacheId: this.cacheId,
@@ -3948,17 +5301,17 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3948
5301
  schedule_datetime: dayjs().format('YYYY-MM-DD HH:mm:ss')
3949
5302
  });
3950
5303
  case 4:
3951
- res = _context46.sent;
3952
- return _context46.abrupt("return", res);
5304
+ res = _context62.sent;
5305
+ return _context62.abrupt("return", res);
3953
5306
  case 8:
3954
- _context46.prev = 8;
3955
- _context46.t0 = _context46["catch"](1);
3956
- throw _context46.t0;
5307
+ _context62.prev = 8;
5308
+ _context62.t0 = _context62["catch"](1);
5309
+ throw _context62.t0;
3957
5310
  case 11:
3958
5311
  case "end":
3959
- return _context46.stop();
5312
+ return _context62.stop();
3960
5313
  }
3961
- }, _callee46, this, [[1, 8]]);
5314
+ }, _callee62, this, [[1, 8]]);
3962
5315
  }));
3963
5316
  function getProductList() {
3964
5317
  return _getProductList.apply(this, arguments);
@@ -3973,33 +5326,33 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3973
5326
  }, {
3974
5327
  key: "setOtherParams",
3975
5328
  value: function () {
3976
- var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee47(params) {
3977
- var _this$otherParams23;
3978
- var _ref30,
3979
- _ref30$cover,
5329
+ var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee63(params) {
5330
+ var _this$otherParams29;
5331
+ var _ref39,
5332
+ _ref39$cover,
3980
5333
  cover,
3981
- _args47 = arguments;
3982
- return _regeneratorRuntime().wrap(function _callee47$(_context47) {
3983
- while (1) switch (_context47.prev = _context47.next) {
5334
+ _args63 = arguments;
5335
+ return _regeneratorRuntime().wrap(function _callee63$(_context63) {
5336
+ while (1) switch (_context63.prev = _context63.next) {
3984
5337
  case 0:
3985
- _ref30 = _args47.length > 1 && _args47[1] !== undefined ? _args47[1] : {}, _ref30$cover = _ref30.cover, cover = _ref30$cover === void 0 ? false : _ref30$cover;
5338
+ _ref39 = _args63.length > 1 && _args63[1] !== undefined ? _args63[1] : {}, _ref39$cover = _ref39.cover, cover = _ref39$cover === void 0 ? false : _ref39$cover;
3986
5339
  if (cover) {
3987
5340
  this.otherParams = _objectSpread({}, params);
3988
5341
  } else {
3989
5342
  this.otherParams = _objectSpread(_objectSpread({}, this.otherParams), params);
3990
5343
  }
3991
- this.cacheId = (_this$otherParams23 = this.otherParams) === null || _this$otherParams23 === void 0 ? void 0 : _this$otherParams23.cacheId;
3992
- _context47.next = 5;
5344
+ this.cacheId = (_this$otherParams29 = this.otherParams) === null || _this$otherParams29 === void 0 ? void 0 : _this$otherParams29.cacheId;
5345
+ _context63.next = 5;
3993
5346
  return this.syncOtherParamsToSubModules(params, {
3994
5347
  cover: cover
3995
5348
  });
3996
5349
  case 5:
3997
5350
  case "end":
3998
- return _context47.stop();
5351
+ return _context63.stop();
3999
5352
  }
4000
- }, _callee47, this);
5353
+ }, _callee63, this);
4001
5354
  }));
4002
- function setOtherParams(_x39) {
5355
+ function setOtherParams(_x54) {
4003
5356
  return _setOtherParams.apply(this, arguments);
4004
5357
  }
4005
5358
  return setOtherParams;