@pisell/pisellos 2.2.274 → 2.2.276

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 (117) 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 +1 -1
  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/OpenData/index.d.ts +2 -0
  14. package/dist/modules/OpenData/index.js +8 -0
  15. package/dist/modules/Order/index.d.ts +28 -8
  16. package/dist/modules/Order/index.js +907 -588
  17. package/dist/modules/Order/payment-utils.d.ts +26 -0
  18. package/dist/modules/Order/payment-utils.js +225 -0
  19. package/dist/modules/Order/types.d.ts +35 -1
  20. package/dist/modules/Order/utils/orderCollectionIdentity.js +7 -2
  21. package/dist/modules/Order/utils.js +10 -6
  22. package/dist/modules/Payment/index.d.ts +2 -0
  23. package/dist/modules/Payment/index.js +78 -49
  24. package/dist/modules/Payment/types.d.ts +104 -25
  25. package/dist/modules/Payment/types.js +17 -0
  26. package/dist/modules/Payment/walletpass.d.ts +38 -1
  27. package/dist/modules/Payment/walletpass.js +917 -114
  28. package/dist/modules/Rules/index.d.ts +3 -0
  29. package/dist/modules/Rules/index.js +100 -70
  30. package/dist/server/index.d.ts +25 -0
  31. package/dist/server/index.js +1993 -1061
  32. package/dist/server/modules/index.d.ts +1 -1
  33. package/dist/server/modules/order/index.d.ts +70 -4
  34. package/dist/server/modules/order/index.js +1816 -728
  35. package/dist/server/modules/order/types.d.ts +25 -3
  36. package/dist/server/modules/order/types.js +7 -1
  37. package/dist/solution/BaseSales/index.d.ts +104 -5
  38. package/dist/solution/BaseSales/index.js +1767 -436
  39. package/dist/solution/BaseSales/types.d.ts +55 -1
  40. package/dist/solution/BaseSales/types.js +2 -1
  41. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +3 -1
  42. package/dist/solution/BaseSales/utils/cartPromotion.js +94 -32
  43. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +6 -1
  44. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +7 -4
  45. package/dist/solution/BookingByStep/index.d.ts +1 -1
  46. package/dist/solution/BookingTicket/index.d.ts +21 -5
  47. package/dist/solution/BookingTicket/index.js +139 -56
  48. package/dist/solution/BookingTicket/types.d.ts +1 -0
  49. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +8 -0
  50. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +173 -83
  51. package/dist/solution/Sales/index.d.ts +2 -0
  52. package/dist/solution/Sales/index.js +26 -4
  53. package/dist/solution/ScanOrder/index.js +31 -20
  54. package/dist/solution/VenueBooking/index.d.ts +1 -0
  55. package/dist/solution/VenueBooking/index.js +30 -19
  56. package/dist/types/index.d.ts +1 -0
  57. package/dist/utils/payment-number.d.ts +9 -0
  58. package/dist/utils/payment-number.js +69 -0
  59. package/lib/core/index.d.ts +2 -0
  60. package/lib/core/index.js +4 -0
  61. package/lib/model/strategy/adapter/promotion/adapter.d.ts +4 -0
  62. package/lib/model/strategy/adapter/promotion/adapter.js +20 -0
  63. package/lib/model/strategy/adapter/promotion/evaluator.d.ts +17 -0
  64. package/lib/model/strategy/adapter/promotion/evaluator.js +235 -0
  65. package/lib/model/strategy/adapter/promotion/examples.d.ts +86 -0
  66. package/lib/model/strategy/adapter/promotion/examples.js +91 -0
  67. package/lib/model/strategy/adapter/promotion/index.d.ts +1 -1
  68. package/lib/model/strategy/adapter/promotion/index.js +2 -0
  69. package/lib/model/strategy/adapter/promotion/type.d.ts +90 -2
  70. package/lib/model/strategy/adapter/promotion/type.js +2 -0
  71. package/lib/modules/OpenData/index.d.ts +2 -0
  72. package/lib/modules/OpenData/index.js +5 -0
  73. package/lib/modules/Order/index.d.ts +28 -8
  74. package/lib/modules/Order/index.js +252 -84
  75. package/lib/modules/Order/payment-utils.d.ts +26 -0
  76. package/lib/modules/Order/payment-utils.js +224 -0
  77. package/lib/modules/Order/types.d.ts +35 -1
  78. package/lib/modules/Order/utils/orderCollectionIdentity.js +3 -0
  79. package/lib/modules/Order/utils.js +11 -4
  80. package/lib/modules/Payment/index.d.ts +2 -0
  81. package/lib/modules/Payment/index.js +33 -12
  82. package/lib/modules/Payment/types.d.ts +104 -25
  83. package/lib/modules/Payment/types.js +1 -0
  84. package/lib/modules/Payment/walletpass.d.ts +38 -1
  85. package/lib/modules/Payment/walletpass.js +730 -21
  86. package/lib/modules/Rules/index.d.ts +3 -0
  87. package/lib/modules/Rules/index.js +38 -9
  88. package/lib/server/index.d.ts +25 -0
  89. package/lib/server/index.js +726 -31
  90. package/lib/server/modules/index.d.ts +1 -1
  91. package/lib/server/modules/order/index.d.ts +70 -4
  92. package/lib/server/modules/order/index.js +818 -69
  93. package/lib/server/modules/order/types.d.ts +25 -3
  94. package/lib/server/modules/order/types.js +1 -0
  95. package/lib/solution/BaseSales/index.d.ts +104 -5
  96. package/lib/solution/BaseSales/index.js +858 -27
  97. package/lib/solution/BaseSales/types.d.ts +55 -1
  98. package/lib/solution/BaseSales/types.js +2 -1
  99. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +3 -1
  100. package/lib/solution/BaseSales/utils/cartPromotion.js +66 -12
  101. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +6 -1
  102. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +4 -3
  103. package/lib/solution/BookingByStep/index.d.ts +1 -1
  104. package/lib/solution/BookingTicket/index.d.ts +21 -5
  105. package/lib/solution/BookingTicket/index.js +64 -13
  106. package/lib/solution/BookingTicket/types.d.ts +1 -0
  107. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +8 -0
  108. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +37 -5
  109. package/lib/solution/Sales/index.d.ts +2 -0
  110. package/lib/solution/Sales/index.js +20 -6
  111. package/lib/solution/ScanOrder/index.js +8 -0
  112. package/lib/solution/VenueBooking/index.d.ts +1 -0
  113. package/lib/solution/VenueBooking/index.js +8 -0
  114. package/lib/types/index.d.ts +1 -0
  115. package/lib/utils/payment-number.d.ts +9 -0
  116. package/lib/utils/payment-number.js +64 -0
  117. 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
  });
@@ -713,9 +870,9 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
713
870
  }, {
714
871
  key: "getPriceQueryChannel",
715
872
  value: function getPriceQueryChannel(channel) {
716
- var _this$otherParams2, _ref5, _ref6, _this$otherParams3, _this$otherParams4;
873
+ var _this$otherParams2, _ref12, _ref13, _this$otherParams3, _this$otherParams4;
717
874
  var strategyContext = (_this$otherParams2 = this.otherParams) !== null && _this$otherParams2 !== void 0 && _this$otherParams2.strategy_context && _typeof(this.otherParams.strategy_context) === 'object' ? this.otherParams.strategy_context : {};
718
- var value = (_ref5 = (_ref6 = channel !== null && channel !== void 0 ? channel : strategyContext.channel) !== null && _ref6 !== void 0 ? _ref6 : (_this$otherParams3 = this.otherParams) === null || _this$otherParams3 === void 0 ? void 0 : _this$otherParams3.channel) !== null && _ref5 !== void 0 ? _ref5 : (_this$otherParams4 = this.otherParams) === null || _this$otherParams4 === void 0 ? void 0 : _this$otherParams4.platform;
875
+ var value = (_ref12 = (_ref13 = channel !== null && channel !== void 0 ? channel : strategyContext.channel) !== null && _ref13 !== void 0 ? _ref13 : (_this$otherParams3 = this.otherParams) === null || _this$otherParams3 === void 0 ? void 0 : _this$otherParams3.channel) !== null && _ref12 !== void 0 ? _ref12 : (_this$otherParams4 = this.otherParams) === null || _this$otherParams4 === void 0 ? void 0 : _this$otherParams4.platform;
719
876
  if (value === undefined || value === null || String(value).trim() === '') {
720
877
  return undefined;
721
878
  }
@@ -728,11 +885,11 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
728
885
  }, {
729
886
  key: "getPriceQueryStrategyContext",
730
887
  value: function getPriceQueryStrategyContext(channel) {
731
- var _this$otherParams5, _ref7, _strategyContext$busi, _this$otherParams6, _this$otherParams7;
888
+ var _this$otherParams5, _ref14, _strategyContext$busi, _this$otherParams6, _this$otherParams7;
732
889
  var inherited = (_this$otherParams5 = this.otherParams) !== null && _this$otherParams5 !== void 0 && _this$otherParams5.strategy_context && _typeof(this.otherParams.strategy_context) === 'object' ? this.otherParams.strategy_context : {};
733
890
  var strategyContext = _objectSpread({}, inherited);
734
891
  var resolvedChannel = this.getPriceQueryChannel(channel);
735
- var businessCode = (_ref7 = (_strategyContext$busi = strategyContext.business_code) !== null && _strategyContext$busi !== void 0 ? _strategyContext$busi : (_this$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6.businessCode) !== null && _ref7 !== void 0 ? _ref7 : (_this$otherParams7 = this.otherParams) === null || _this$otherParams7 === void 0 ? void 0 : _this$otherParams7.business_code;
892
+ var businessCode = (_ref14 = (_strategyContext$busi = strategyContext.business_code) !== null && _strategyContext$busi !== void 0 ? _strategyContext$busi : (_this$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6.businessCode) !== null && _ref14 !== void 0 ? _ref14 : (_this$otherParams7 = this.otherParams) === null || _this$otherParams7 === void 0 ? void 0 : _this$otherParams7.business_code;
736
893
  if (resolvedChannel) strategyContext.channel = resolvedChannel;
737
894
  if (businessCode !== undefined && businessCode !== null && String(businessCode).trim() !== '') {
738
895
  strategyContext.business_code = String(businessCode).trim();
@@ -886,10 +1043,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
886
1043
  return groups.flatMap(function (group) {
887
1044
  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 : [];
888
1045
  return items.map(function (item) {
889
- var _item$group_id, _ref8, _item$bundle_group_id;
1046
+ var _item$group_id, _ref15, _item$bundle_group_id;
890
1047
  return _objectSpread(_objectSpread({}, item), {}, {
891
1048
  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,
892
- bundle_group_id: (_ref8 = (_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 && _ref8 !== void 0 ? _ref8 : group === null || group === void 0 ? void 0 : group.id
1049
+ bundle_group_id: (_ref15 = (_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 && _ref15 !== void 0 ? _ref15 : group === null || group === void 0 ? void 0 : group.id
893
1050
  });
894
1051
  });
895
1052
  });
@@ -920,21 +1077,21 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
920
1077
  }, {
921
1078
  key: "getAuthoritativeBundleUnitPrice",
922
1079
  value: function getAuthoritativeBundleUnitPrice(bundle) {
923
- var _ref9, _ref10, _ref11, _bundle$price;
924
- return (_ref9 = (_ref10 = (_ref11 = (_bundle$price = bundle.price) !== null && _bundle$price !== void 0 ? _bundle$price : bundle.bundle_selling_price) !== null && _ref11 !== void 0 ? _ref11 : bundle.custom_price) !== null && _ref10 !== void 0 ? _ref10 : bundle.product_price) !== null && _ref9 !== void 0 ? _ref9 : bundle.base_price;
1080
+ var _ref16, _ref17, _ref18, _bundle$price;
1081
+ return (_ref16 = (_ref17 = (_ref18 = (_bundle$price = bundle.price) !== null && _bundle$price !== void 0 ? _bundle$price : bundle.bundle_selling_price) !== null && _ref18 !== void 0 ? _ref18 : bundle.custom_price) !== null && _ref17 !== void 0 ? _ref17 : bundle.product_price) !== null && _ref16 !== void 0 ? _ref16 : bundle.base_price;
925
1082
  }
926
1083
  }, {
927
1084
  key: "mergeProductForPriceQuery",
928
1085
  value: function mergeProductForPriceQuery(product, authoritativeProduct) {
929
1086
  var _this5 = this,
930
1087
  _product$id,
931
- _ref12,
1088
+ _ref19,
932
1089
  _product$product_id2,
933
- _ref13,
1090
+ _ref20,
934
1091
  _product$product_vari,
935
- _ref14,
1092
+ _ref21,
936
1093
  _product$num,
937
- _ref15,
1094
+ _ref22,
938
1095
  _product$quantity,
939
1096
  _product$metadata4;
940
1097
  if (!authoritativeProduct) return product;
@@ -954,10 +1111,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
954
1111
  });
955
1112
  return _objectSpread(_objectSpread(_objectSpread({}, product), authoritativeProduct), {}, {
956
1113
  id: (_product$id = product.id) !== null && _product$id !== void 0 ? _product$id : authoritativeProduct.id,
957
- product_id: (_ref12 = (_product$product_id2 = product.product_id) !== null && _product$product_id2 !== void 0 ? _product$product_id2 : authoritativeProduct.product_id) !== null && _ref12 !== void 0 ? _ref12 : authoritativeProduct.id,
958
- product_variant_id: (_ref13 = (_product$product_vari = product.product_variant_id) !== null && _product$product_vari !== void 0 ? _product$product_vari : authoritativeProduct.product_variant_id) !== null && _ref13 !== void 0 ? _ref13 : 0,
959
- num: (_ref14 = (_product$num = product.num) !== null && _product$num !== void 0 ? _product$num : product.quantity) !== null && _ref14 !== void 0 ? _ref14 : authoritativeProduct.num,
960
- quantity: (_ref15 = (_product$quantity = product.quantity) !== null && _product$quantity !== void 0 ? _product$quantity : product.num) !== null && _ref15 !== void 0 ? _ref15 : authoritativeProduct.quantity,
1114
+ product_id: (_ref19 = (_product$product_id2 = product.product_id) !== null && _product$product_id2 !== void 0 ? _product$product_id2 : authoritativeProduct.product_id) !== null && _ref19 !== void 0 ? _ref19 : authoritativeProduct.id,
1115
+ product_variant_id: (_ref20 = (_product$product_vari = product.product_variant_id) !== null && _product$product_vari !== void 0 ? _product$product_vari : authoritativeProduct.product_variant_id) !== null && _ref20 !== void 0 ? _ref20 : 0,
1116
+ num: (_ref21 = (_product$num = product.num) !== null && _product$num !== void 0 ? _product$num : product.quantity) !== null && _ref21 !== void 0 ? _ref21 : authoritativeProduct.num,
1117
+ quantity: (_ref22 = (_product$quantity = product.quantity) !== null && _product$quantity !== void 0 ? _product$quantity : product.num) !== null && _ref22 !== void 0 ? _ref22 : authoritativeProduct.quantity,
961
1118
  product_sku: function () {
962
1119
  var authoritativeSku = ensureProductSku(authoritativeProduct);
963
1120
  var productSku = ensureProductSku(product);
@@ -1033,24 +1190,24 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1033
1190
  value: (function () {
1034
1191
  var _syncOtherParamsToSubModules = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(changedParams) {
1035
1192
  var _this6 = this;
1036
- var _ref16,
1037
- _ref16$cover,
1193
+ var _ref23,
1194
+ _ref23$cover,
1038
1195
  cover,
1039
1196
  nextSubModuleOtherParams,
1040
1197
  _args10 = arguments;
1041
1198
  return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1042
1199
  while (1) switch (_context10.prev = _context10.next) {
1043
1200
  case 0:
1044
- _ref16 = _args10.length > 1 && _args10[1] !== undefined ? _args10[1] : {}, _ref16$cover = _ref16.cover, cover = _ref16$cover === void 0 ? false : _ref16$cover;
1201
+ _ref23 = _args10.length > 1 && _args10[1] !== undefined ? _args10[1] : {}, _ref23$cover = _ref23.cover, cover = _ref23$cover === void 0 ? false : _ref23$cover;
1045
1202
  nextSubModuleOtherParams = this.buildSubModuleOtherParams();
1046
1203
  _context10.next = 4;
1047
1204
  return Promise.all(Object.entries(this.store).map( /*#__PURE__*/function () {
1048
- var _ref18 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(_ref17) {
1049
- var _ref19, moduleName, subModule, targetModule;
1205
+ var _ref25 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(_ref24) {
1206
+ var _ref26, moduleName, subModule, targetModule;
1050
1207
  return _regeneratorRuntime().wrap(function _callee9$(_context9) {
1051
1208
  while (1) switch (_context9.prev = _context9.next) {
1052
1209
  case 0:
1053
- _ref19 = _slicedToArray(_ref17, 2), moduleName = _ref19[0], subModule = _ref19[1];
1210
+ _ref26 = _slicedToArray(_ref24, 2), moduleName = _ref26[0], subModule = _ref26[1];
1054
1211
  if (!_this6.reusedSharedSubModuleNames.has(moduleName)) {
1055
1212
  _context9.next = 3;
1056
1213
  break;
@@ -1076,7 +1233,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1076
1233
  }, _callee9);
1077
1234
  }));
1078
1235
  return function (_x9) {
1079
- return _ref18.apply(this, arguments);
1236
+ return _ref25.apply(this, arguments);
1080
1237
  };
1081
1238
  }()));
1082
1239
  case 4:
@@ -1104,7 +1261,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1104
1261
  if (!sessionData) return {};
1105
1262
  var data = JSON.parse(sessionData);
1106
1263
  return data && data[this.cacheId] || {};
1107
- } catch (_unused) {
1264
+ } catch (_unused3) {
1108
1265
  return {};
1109
1266
  }
1110
1267
  }
@@ -1118,6 +1275,38 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1118
1275
  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');
1119
1276
  return coreData === null || coreData === void 0 ? void 0 : coreData[key];
1120
1277
  }
1278
+
1279
+ /**
1280
+ * 复用业务解决方案初始化时已解析的支付设备短号。
1281
+ * 空值会清除缓存,使后续支付恢复实时读取设备信息的兼容路径。
1282
+ */
1283
+ }, {
1284
+ key: "setPaymentNumberDevicePrefix",
1285
+ value: function setPaymentNumberDevicePrefix(prefix) {
1286
+ var normalized = String(prefix !== null && prefix !== void 0 ? prefix : '').trim();
1287
+ this.paymentNumberDevicePrefix = normalized || null;
1288
+ }
1289
+ }, {
1290
+ key: "getPaymentNumberDevicePrefixSync",
1291
+ value: function getPaymentNumberDevicePrefixSync() {
1292
+ var _this7 = this;
1293
+ if (!this.appPlugin) return 'LOCAL';
1294
+ return resolvePaymentNumberDevicePrefixFromDeviceId(function (key) {
1295
+ return _this7.getAppData(key);
1296
+ });
1297
+ }
1298
+ }, {
1299
+ key: "getPaymentNumberDevicePrefixAsync",
1300
+ value: function getPaymentNumberDevicePrefixAsync() {
1301
+ var _this8 = this;
1302
+ if (!this.appPlugin) return Promise.resolve('LOCAL');
1303
+ if (this.paymentNumberDevicePrefix) {
1304
+ return Promise.resolve(this.paymentNumberDevicePrefix);
1305
+ }
1306
+ return resolvePaymentNumberDevicePrefix(function (key) {
1307
+ return _this8.getAppData(key);
1308
+ });
1309
+ }
1121
1310
  }, {
1122
1311
  key: "syncAppDataToTempOrder",
1123
1312
  value: function syncAppDataToTempOrder(tempOrder) {
@@ -1161,7 +1350,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1161
1350
  value: function () {
1162
1351
  var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(core) {
1163
1352
  var _this$otherParams9,
1164
- _this7 = this,
1353
+ _this9 = this,
1165
1354
  _this$otherParams10;
1166
1355
  var options,
1167
1356
  app,
@@ -1174,6 +1363,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1174
1363
  options = _args11.length > 1 && _args11[1] !== undefined ? _args11[1] : {};
1175
1364
  this.core = core;
1176
1365
  this.initializeOptions = options || {};
1366
+ this.paymentNumberDevicePrefix = null;
1177
1367
  // this.store = { ...this.store, ...(options.store as Partial<BaseSalesState>) };
1178
1368
  this.otherParams = options.otherParams || {};
1179
1369
  this.cacheId = (_this$otherParams9 = this.otherParams) === null || _this$otherParams9 === void 0 ? void 0 : _this$otherParams9.cacheId;
@@ -1184,52 +1374,52 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1184
1374
  // 获取 logger 实例
1185
1375
  this.appPlugin = core.getPlugin('app');
1186
1376
  if (this.appPlugin) {
1187
- _context11.next = 11;
1377
+ _context11.next = 12;
1188
1378
  break;
1189
1379
  }
1190
1380
  throw new Error('Checkout 解决方案需要 app 插件支持');
1191
- case 11:
1381
+ case 12:
1192
1382
  app = this.appPlugin.getApp();
1193
1383
  this.logger = app.logger;
1194
1384
  targetCacheData = this.readSessionCacheData();
1195
1385
  moduleNames = this.getRegisteredModuleNames();
1196
1386
  moduleNames.forEach(function (step) {
1197
- var reusedModule = _this7.getReusableSharedSubModule(step);
1387
+ var reusedModule = _this9.getReusableSharedSubModule(step);
1198
1388
  if (reusedModule) {
1199
- _this7.store[step] = reusedModule;
1200
- _this7.reusedSharedSubModuleNames.add(step);
1389
+ _this9.store[step] = reusedModule;
1390
+ _this9.reusedSharedSubModuleNames.add(step);
1201
1391
  return;
1202
1392
  }
1203
- var targetModule = _this7.createSubModule(step);
1393
+ var targetModule = _this9.createSubModule(step);
1204
1394
  if (!targetModule) {
1205
1395
  throw new Error("\u6A21\u5757 ".concat(step, " \u4E0D\u5B58\u5728"));
1206
1396
  }
1207
- var hooks = _this7.getSubModuleHooks(step);
1208
- _this7.store[step] = targetModule;
1209
- _this7.core.registerModule(targetModule, _objectSpread(_objectSpread({
1397
+ var hooks = _this9.getSubModuleHooks(step);
1398
+ _this9.store[step] = targetModule;
1399
+ _this9.core.registerModule(targetModule, _objectSpread(_objectSpread({
1210
1400
  initialState: (targetCacheData === null || targetCacheData === void 0 ? void 0 : targetCacheData[targetModule.name]) || {}
1211
1401
  }, hooks ? {
1212
1402
  hooks: hooks
1213
1403
  } : {}), {}, {
1214
- otherParams: _this7.buildSubModuleOtherParams()
1404
+ otherParams: _this9.buildSubModuleOtherParams()
1215
1405
  }));
1216
1406
  });
1217
1407
  if (!(this.store.schedule && !this.isScheduleListLoaded(this.store.schedule))) {
1218
- _context11.next = 19;
1408
+ _context11.next = 20;
1219
1409
  break;
1220
1410
  }
1221
- _context11.next = 19;
1411
+ _context11.next = 20;
1222
1412
  return this.store.schedule.loadAllSchedule();
1223
- case 19:
1413
+ case 20:
1224
1414
  if (this.store.order && typeof ((_this$otherParams10 = this.otherParams) === null || _this$otherParams10 === void 0 ? void 0 : _this$otherParams10.enableTempOrderPersist) === 'boolean') {
1225
1415
  this.store.order.setEnableTempOrderPersist(this.otherParams.enableTempOrderPersist);
1226
1416
  }
1227
- _context11.next = 22;
1417
+ _context11.next = 23;
1228
1418
  return this.getPaymentMethodsAsync();
1229
- case 22:
1419
+ case 23:
1230
1420
  this.registerServerOrderChangeSync();
1231
1421
  this.core.effects.emit("".concat(this.name, ":onInited"), {});
1232
- case 24:
1422
+ case 25:
1233
1423
  case "end":
1234
1424
  return _context11.stop();
1235
1425
  }
@@ -1245,15 +1435,15 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1245
1435
  value: function () {
1246
1436
  var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
1247
1437
  var _this$serverOrderChan2,
1248
- _this8 = this;
1438
+ _this10 = this;
1249
1439
  return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1250
1440
  while (1) switch (_context12.prev = _context12.next) {
1251
1441
  case 0:
1252
1442
  (_this$serverOrderChan2 = this.serverOrderChangeUnsubscribe) === null || _this$serverOrderChan2 === void 0 || _this$serverOrderChan2.call(this);
1253
1443
  this.serverOrderChangeUnsubscribe = null;
1254
1444
  Object.keys(this.store).forEach(function (key) {
1255
- if (_this8.reusedSharedSubModuleNames.has(key)) return;
1256
- var sub = _this8.store[key];
1445
+ if (_this10.reusedSharedSubModuleNames.has(key)) return;
1446
+ var sub = _this10.store[key];
1257
1447
  if (sub && typeof sub.destroy === 'function') {
1258
1448
  try {
1259
1449
  sub.destroy();
@@ -1263,13 +1453,15 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1263
1453
  }
1264
1454
  });
1265
1455
  this.currentSalesDetail = null;
1456
+ this.paymentNumberDevicePrefix = null;
1266
1457
  this.queuedServerOrderChanges = [];
1267
1458
  this.salesDetailLoadSequence += 1;
1268
- _context12.next = 8;
1459
+ this.walletAssetsRefreshSequence += 1;
1460
+ _context12.next = 10;
1269
1461
  return this.core.effects.emit("".concat(this.name, ":onDestroy"), {});
1270
- case 8:
1462
+ case 10:
1271
1463
  _get(_getPrototypeOf(BaseSalesImpl.prototype), "destroy", this).call(this);
1272
- case 9:
1464
+ case 11:
1273
1465
  case "end":
1274
1466
  return _context12.stop();
1275
1467
  }
@@ -1291,7 +1483,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1291
1483
  key: "loadSalesDetail",
1292
1484
  value: (function () {
1293
1485
  var _loadSalesDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(orderIdOrParams) {
1294
- var loadSequence, _ref20, _ref21, _ref22, _ref23, _params$orderId, params, externalSaleNumber, preloadedSalesDetail, lookup, loadedRecord, message, remoteRecord, currentTempOrder, record;
1486
+ var loadSequence, _ref27, _ref28, _ref29, _ref30, _params$orderId, params, externalSaleNumber, preloadedSalesDetail, lookup, loadedRecord, message, remoteRecord, currentTempOrder, mergedRecord, record;
1295
1487
  return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1296
1488
  while (1) switch (_context13.prev = _context13.next) {
1297
1489
  case 0:
@@ -1309,7 +1501,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1309
1501
  };
1310
1502
  externalSaleNumber = params.externalSaleNumber || params.external_sale_number;
1311
1503
  preloadedSalesDetail = params.preloadedSalesDetail;
1312
- lookup = (_ref20 = (_ref21 = (_ref22 = (_ref23 = (_params$orderId = params.orderId) !== null && _params$orderId !== void 0 ? _params$orderId : externalSaleNumber) !== null && _ref23 !== void 0 ? _ref23 : params.orderNumber) !== null && _ref22 !== void 0 ? _ref22 : preloadedSalesDetail === null || preloadedSalesDetail === void 0 ? void 0 : preloadedSalesDetail.order_id) !== null && _ref21 !== void 0 ? _ref21 : preloadedSalesDetail === null || preloadedSalesDetail === void 0 ? void 0 : preloadedSalesDetail.external_sale_number) !== null && _ref20 !== void 0 ? _ref20 : preloadedSalesDetail === null || preloadedSalesDetail === void 0 ? void 0 : preloadedSalesDetail.order_number;
1504
+ lookup = (_ref27 = (_ref28 = (_ref29 = (_ref30 = (_params$orderId = params.orderId) !== null && _params$orderId !== void 0 ? _params$orderId : externalSaleNumber) !== null && _ref30 !== void 0 ? _ref30 : params.orderNumber) !== null && _ref29 !== void 0 ? _ref29 : preloadedSalesDetail === null || preloadedSalesDetail === void 0 ? void 0 : preloadedSalesDetail.order_id) !== null && _ref28 !== void 0 ? _ref28 : preloadedSalesDetail === null || preloadedSalesDetail === void 0 ? void 0 : preloadedSalesDetail.external_sale_number) !== null && _ref27 !== void 0 ? _ref27 : preloadedSalesDetail === null || preloadedSalesDetail === void 0 ? void 0 : preloadedSalesDetail.order_number;
1313
1505
  if (!(!preloadedSalesDetail && (lookup === undefined || lookup === null || lookup === ''))) {
1314
1506
  _context13.next = 11;
1315
1507
  break;
@@ -1340,39 +1532,40 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1340
1532
  message = loadedRecord && (loadedRecord.message || loadedRecord.msg) || "\u52A0\u8F7D\u9500\u552E\u8BE6\u60C5\u5931\u8D25: ".concat(lookup);
1341
1533
  throw new Error(message);
1342
1534
  case 22:
1343
- remoteRecord = preloadedSalesDetail !== null && preloadedSalesDetail !== void 0 ? preloadedSalesDetail : loadedRecord.data;
1535
+ remoteRecord = filterPendingPaymentsFromLoadedSalesDetail(preloadedSalesDetail !== null && preloadedSalesDetail !== void 0 ? preloadedSalesDetail : loadedRecord.data);
1344
1536
  currentTempOrder = params.merge ? this.store.order.getTempOrder() : null;
1345
- record = params.merge ? mergeSalesDetailRecordWithTempOrder(currentTempOrder, remoteRecord, 'preserve-local') : remoteRecord;
1346
- _context13.next = 27;
1537
+ mergedRecord = params.merge ? mergeSalesDetailRecordWithTempOrder(currentTempOrder, remoteRecord, 'preserve-local') : remoteRecord;
1538
+ record = filterPendingPaymentsFromLoadedSalesDetail(mergedRecord);
1539
+ _context13.next = 28;
1347
1540
  return this.hydrateLatestLoadedSalesDetail(record, loadSequence);
1348
- case 27:
1349
- return _context13.abrupt("return", _context13.sent);
1350
1541
  case 28:
1351
- _context13.prev = 28;
1542
+ return _context13.abrupt("return", _context13.sent);
1543
+ case 29:
1544
+ _context13.prev = 29;
1352
1545
  this.salesDetailLoadInFlightCount = Math.max(0, this.salesDetailLoadInFlightCount - 1);
1353
1546
  if (!(this.salesDetailLoadInFlightCount === 0)) {
1354
- _context13.next = 39;
1547
+ _context13.next = 40;
1355
1548
  break;
1356
1549
  }
1357
- _context13.prev = 31;
1358
- _context13.next = 34;
1550
+ _context13.prev = 32;
1551
+ _context13.next = 35;
1359
1552
  return this.drainQueuedServerOrderChanges();
1360
- case 34:
1361
- _context13.next = 39;
1553
+ case 35:
1554
+ _context13.next = 40;
1362
1555
  break;
1363
- case 36:
1364
- _context13.prev = 36;
1365
- _context13.t1 = _context13["catch"](31);
1556
+ case 37:
1557
+ _context13.prev = 37;
1558
+ _context13.t1 = _context13["catch"](32);
1366
1559
  this.logError('drain queued server order changes failed', {
1367
1560
  error: _context13.t1 instanceof Error ? _context13.t1.message : String(_context13.t1)
1368
1561
  });
1369
- case 39:
1370
- return _context13.finish(28);
1371
1562
  case 40:
1563
+ return _context13.finish(29);
1564
+ case 41:
1372
1565
  case "end":
1373
1566
  return _context13.stop();
1374
1567
  }
1375
- }, _callee13, this, [[4,, 28, 40], [31, 36]]);
1568
+ }, _callee13, this, [[4,, 29, 41], [32, 37]]);
1376
1569
  }));
1377
1570
  function loadSalesDetail(_x11) {
1378
1571
  return _loadSalesDetail.apply(this, arguments);
@@ -1649,7 +1842,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1649
1842
  key: "restoreOrder",
1650
1843
  value: function () {
1651
1844
  var _restoreOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
1652
- var tempOrder;
1845
+ var _this$store$payment, tempOrder, wallet;
1653
1846
  return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1654
1847
  while (1) switch (_context17.prev = _context17.next) {
1655
1848
  case 0:
@@ -1665,29 +1858,39 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1665
1858
  this.currentSalesDetail = null;
1666
1859
  this.discountConfigCacheKey = null;
1667
1860
  this.hasManualDiscountSelection = false;
1668
- _context17.next = 9;
1861
+ wallet = (_this$store$payment = this.store.payment) === null || _this$store$payment === void 0 ? void 0 : _this$store$payment.wallet;
1862
+ if (!wallet) {
1863
+ _context17.next = 13;
1864
+ break;
1865
+ }
1866
+ this.walletAssetsRefreshSequence += 1;
1867
+ wallet.clearAllCache();
1868
+ _context17.next = 13;
1869
+ return this.publishWalletAssetsState(wallet.getWalletAssetsState());
1870
+ case 13:
1871
+ _context17.next = 15;
1669
1872
  return this.effectsEmit('onTempOrderReplaced', {
1670
1873
  tempOrder: tempOrder
1671
1874
  });
1672
- case 9:
1875
+ case 15:
1673
1876
  if (!(this.syncAppDataToTempOrder(tempOrder) && this.isTempOrderPersistEnabled())) {
1674
- _context17.next = 13;
1877
+ _context17.next = 19;
1675
1878
  break;
1676
1879
  }
1677
1880
  this.store.order.persistTempOrder();
1678
- _context17.next = 13;
1881
+ _context17.next = 19;
1679
1882
  return this.store.order.saveDraft();
1680
- case 13:
1883
+ case 19:
1681
1884
  return _context17.abrupt("return", tempOrder);
1682
- case 16:
1683
- _context17.prev = 16;
1885
+ case 22:
1886
+ _context17.prev = 22;
1684
1887
  _context17.t0 = _context17["catch"](0);
1685
1888
  throw _context17.t0;
1686
- case 19:
1889
+ case 25:
1687
1890
  case "end":
1688
1891
  return _context17.stop();
1689
1892
  }
1690
- }, _callee17, this, [[0, 16]]);
1893
+ }, _callee17, this, [[0, 22]]);
1691
1894
  }));
1692
1895
  function restoreOrder() {
1693
1896
  return _restoreOrder.apply(this, arguments);
@@ -1800,10 +2003,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1800
2003
  }, {
1801
2004
  key: "getHistoricalProductDiscountList",
1802
2005
  value: function getHistoricalProductDiscountList(products) {
1803
- var _this9 = this;
2006
+ var _this11 = this;
1804
2007
  var historyDiscountList = [];
1805
2008
  products.forEach(function (item) {
1806
- if (!_this9.isPersistedOrderProduct(item)) return;
2009
+ if (!_this11.isPersistedOrderProduct(item)) return;
1807
2010
  (item.discount_list || []).forEach(function (discount) {
1808
2011
  var _discount$discount, _discount$metadata, _discount$discount2, _discount$discount3, _discount$discount4;
1809
2012
  var discountId = ((_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) || discount.id;
@@ -1863,11 +2066,11 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1863
2066
  }, {
1864
2067
  key: "shouldSkipAutoApplyFetchedDiscountsInEditMode",
1865
2068
  value: function shouldSkipAutoApplyFetchedDiscountsInEditMode(params) {
1866
- var _this10 = this;
2069
+ var _this12 = this;
1867
2070
  if (params.discountAction !== 'edit') return false;
1868
2071
  if (!params.products.length) return false;
1869
2072
  var hasDraftProduct = params.products.some(function (product) {
1870
- return !_this10.isPersistedOrderProduct(product);
2073
+ return !_this12.isPersistedOrderProduct(product);
1871
2074
  });
1872
2075
  if (hasDraftProduct) return false;
1873
2076
  var hasSelectedDiscount = params.currentDiscountList.some(function (discount) {
@@ -2315,12 +2518,15 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2315
2518
  tempOrder: tempOrder
2316
2519
  });
2317
2520
  case 13:
2318
- return _context23.abrupt("return", {
2319
- isAvailable: raw.isAvailable,
2521
+ return _context23.abrupt("return", _objectSpread(_objectSpread({
2522
+ isAvailable: raw.isAvailable
2523
+ }, raw.isAccepted !== undefined ? {
2524
+ isAccepted: raw.isAccepted
2525
+ } : {}), {}, {
2320
2526
  type: raw.type,
2321
2527
  unavailableReason: raw.unavailableReason,
2322
2528
  scannedDiscountList: raw.scannedDiscountList
2323
- });
2529
+ }));
2324
2530
  case 16:
2325
2531
  _context23.prev = 16;
2326
2532
  _context23.t0 = _context23["catch"](0);
@@ -2446,10 +2652,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2446
2652
  product.discount_list = filterSelectedDiscountDetails(product.discount_list);
2447
2653
  if (Array.isArray(product.product_bundle)) {
2448
2654
  product.product_bundle = product.product_bundle.map(function (bundle) {
2449
- var _ref24, _bundle$original_pric;
2655
+ var _ref31, _bundle$original_pric;
2450
2656
  var nextBundleDiscountList = filterSelectedDiscountDetails(bundle === null || bundle === void 0 ? void 0 : bundle.discount_list);
2451
2657
  var shouldRestoreBundlePrice = nextBundleDiscountList.length === 0;
2452
- var restoredBundlePrice = (_ref24 = (_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 && _ref24 !== void 0 ? _ref24 : bundle === null || bundle === void 0 ? void 0 : bundle.price;
2658
+ var restoredBundlePrice = (_ref31 = (_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 && _ref31 !== void 0 ? _ref31 : bundle === null || bundle === void 0 ? void 0 : bundle.price;
2453
2659
  return _objectSpread(_objectSpread(_objectSpread({}, bundle), shouldRestoreBundlePrice ? {
2454
2660
  price: restoredBundlePrice,
2455
2661
  bundle_selling_price: restoredBundlePrice
@@ -2670,11 +2876,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2670
2876
  return submitSalesOrder;
2671
2877
  }())
2672
2878
  }, {
2673
- key: "submitTempOrderAsync",
2879
+ key: "saveSalesOrderDraft",
2674
2880
  value: function () {
2675
- var _submitTempOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(params) {
2676
- var _this$otherParams15, _this$otherParams16, _this$otherParams17, _this$otherParams18;
2677
- var inferredPaymentStatus, submitParams;
2881
+ var _saveSalesOrderDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(params) {
2882
+ var _params$platform, _this$otherParams15, _this$otherParams16, _this$otherParams17, _params$channel, _params$type, _this$otherParams18;
2678
2883
  return _regeneratorRuntime().wrap(function _callee28$(_context28) {
2679
2884
  while (1) switch (_context28.prev = _context28.next) {
2680
2885
  case 0:
@@ -2683,14 +2888,49 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2683
2888
  break;
2684
2889
  }
2685
2890
  throw new Error('BaseSales 解决方案需要 order 模块支持');
2891
+ case 2:
2892
+ return _context28.abrupt("return", this.store.order.saveTempOrderAsDraft(_objectSpread({
2893
+ cacheId: this.cacheId,
2894
+ platform: (_params$platform = params === null || params === void 0 ? void 0 : params.platform) !== null && _params$platform !== void 0 ? _params$platform : (_this$otherParams15 = this.otherParams) === null || _this$otherParams15 === void 0 ? void 0 : _this$otherParams15.platform,
2895
+ businessCode: (params === null || params === void 0 ? void 0 : params.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),
2896
+ channel: (_params$channel = params === null || params === void 0 ? void 0 : params.channel) !== null && _params$channel !== void 0 ? _params$channel : this.getSubmitOrderSalesChannel(),
2897
+ type: (_params$type = params === null || params === void 0 ? void 0 : params.type) !== null && _params$type !== void 0 ? _params$type : (_this$otherParams18 = this.otherParams) === null || _this$otherParams18 === void 0 ? void 0 : _this$otherParams18.type
2898
+ }, (params === null || params === void 0 ? void 0 : params.enhancePayload) !== undefined ? {
2899
+ enhancePayload: params.enhancePayload
2900
+ } : {})));
2901
+ case 3:
2902
+ case "end":
2903
+ return _context28.stop();
2904
+ }
2905
+ }, _callee28, this);
2906
+ }));
2907
+ function saveSalesOrderDraft(_x23) {
2908
+ return _saveSalesOrderDraft.apply(this, arguments);
2909
+ }
2910
+ return saveSalesOrderDraft;
2911
+ }()
2912
+ }, {
2913
+ key: "submitTempOrderAsync",
2914
+ value: function () {
2915
+ var _submitTempOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(params) {
2916
+ var _this$otherParams19, _this$otherParams20, _this$otherParams21, _this$otherParams22;
2917
+ var inferredPaymentStatus, submitParams;
2918
+ return _regeneratorRuntime().wrap(function _callee29$(_context29) {
2919
+ while (1) switch (_context29.prev = _context29.next) {
2920
+ case 0:
2921
+ if (this.store.order) {
2922
+ _context29.next = 2;
2923
+ break;
2924
+ }
2925
+ throw new Error('BaseSales 解决方案需要 order 模块支持');
2686
2926
  case 2:
2687
2927
  inferredPaymentStatus = this.getSubmitPaymentStatus(params === null || params === void 0 ? void 0 : params.paymentStatus);
2688
2928
  submitParams = _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
2689
2929
  cacheId: this.cacheId,
2690
- platform: (_this$otherParams15 = this.otherParams) === null || _this$otherParams15 === void 0 ? void 0 : _this$otherParams15.platform,
2691
- 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),
2930
+ platform: (_this$otherParams19 = this.otherParams) === null || _this$otherParams19 === void 0 ? void 0 : _this$otherParams19.platform,
2931
+ 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),
2692
2932
  channel: this.getSubmitOrderSalesChannel(),
2693
- type: (_this$otherParams18 = this.otherParams) === null || _this$otherParams18 === void 0 ? void 0 : _this$otherParams18.type
2933
+ type: (_this$otherParams22 = this.otherParams) === null || _this$otherParams22 === void 0 ? void 0 : _this$otherParams22.type
2694
2934
  }, (params === null || params === void 0 ? void 0 : params.payments) !== undefined ? {
2695
2935
  payments: params.payments
2696
2936
  } : {}), inferredPaymentStatus !== undefined ? {
@@ -2702,14 +2942,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2702
2942
  } : {}), (params === null || params === void 0 ? void 0 : params.enhancePayload) !== undefined ? {
2703
2943
  enhancePayload: params.enhancePayload
2704
2944
  } : {});
2705
- return _context28.abrupt("return", this.store.order.submitTempOrderAsync(submitParams));
2945
+ return _context29.abrupt("return", this.store.order.submitTempOrderAsync(submitParams));
2706
2946
  case 5:
2707
2947
  case "end":
2708
- return _context28.stop();
2948
+ return _context29.stop();
2709
2949
  }
2710
- }, _callee28, this);
2950
+ }, _callee29, this);
2711
2951
  }));
2712
- function submitTempOrderAsync(_x23) {
2952
+ function submitTempOrderAsync(_x24) {
2713
2953
  return _submitTempOrderAsync.apply(this, arguments);
2714
2954
  }
2715
2955
  return submitTempOrderAsync;
@@ -2717,14 +2957,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2717
2957
  }, {
2718
2958
  key: "printLocalOrderReceipt",
2719
2959
  value: function () {
2720
- var _printLocalOrderReceipt = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(lookup) {
2721
- var _this$otherParams19, _this$otherParams20, _this$otherParams21, _this$otherParams22;
2960
+ var _printLocalOrderReceipt = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(lookup) {
2961
+ var _this$otherParams23, _this$otherParams24, _this$otherParams25, _this$otherParams26;
2722
2962
  var hasLookup, lookupPayload, context, payload, response, _this$store$order$app, _this$store$order5, _data;
2723
- return _regeneratorRuntime().wrap(function _callee29$(_context29) {
2724
- while (1) switch (_context29.prev = _context29.next) {
2963
+ return _regeneratorRuntime().wrap(function _callee30$(_context30) {
2964
+ while (1) switch (_context30.prev = _context30.next) {
2725
2965
  case 0:
2726
2966
  if (this.store.order) {
2727
- _context29.next = 2;
2967
+ _context30.next = 2;
2728
2968
  break;
2729
2969
  }
2730
2970
  throw new Error('BaseSales 解决方案需要 order 模块支持');
@@ -2736,10 +2976,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2736
2976
  external_sale_number: lookup
2737
2977
  };
2738
2978
  context = {
2739
- platform: (_this$otherParams19 = this.otherParams) === null || _this$otherParams19 === void 0 ? void 0 : _this$otherParams19.platform,
2740
- 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),
2979
+ platform: (_this$otherParams23 = this.otherParams) === null || _this$otherParams23 === void 0 ? void 0 : _this$otherParams23.platform,
2980
+ businessCode: ((_this$otherParams24 = this.otherParams) === null || _this$otherParams24 === void 0 ? void 0 : _this$otherParams24.businessCode) || ((_this$otherParams25 = this.otherParams) === null || _this$otherParams25 === void 0 ? void 0 : _this$otherParams25.business_code),
2741
2981
  channel: this.getSubmitOrderSalesChannel(),
2742
- type: (_this$otherParams22 = this.otherParams) === null || _this$otherParams22 === void 0 ? void 0 : _this$otherParams22.type
2982
+ type: (_this$otherParams26 = this.otherParams) === null || _this$otherParams26 === void 0 ? void 0 : _this$otherParams26.type
2743
2983
  };
2744
2984
  payload = hasLookup ? _objectSpread(_objectSpread({}, lookupPayload), {}, {
2745
2985
  lookup_order_from_db: 1,
@@ -2755,28 +2995,28 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2755
2995
  channel: context.channel,
2756
2996
  type: context.type
2757
2997
  });
2758
- _context29.next = 8;
2998
+ _context30.next = 8;
2759
2999
  return this.request.post('/local/print-order', payload, {
2760
3000
  osServer: true,
2761
3001
  customToast: function customToast() {}
2762
3002
  });
2763
3003
  case 8:
2764
- response = _context29.sent;
3004
+ response = _context30.sent;
2765
3005
  if (hasLookup) {
2766
- _context29.next = 12;
3006
+ _context30.next = 12;
2767
3007
  break;
2768
3008
  }
2769
- _context29.next = 12;
3009
+ _context30.next = 12;
2770
3010
  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);
2771
3011
  case 12:
2772
- return _context29.abrupt("return", response);
3012
+ return _context30.abrupt("return", response);
2773
3013
  case 13:
2774
3014
  case "end":
2775
- return _context29.stop();
3015
+ return _context30.stop();
2776
3016
  }
2777
- }, _callee29, this);
3017
+ }, _callee30, this);
2778
3018
  }));
2779
- function printLocalOrderReceipt(_x24) {
3019
+ function printLocalOrderReceipt(_x25) {
2780
3020
  return _printLocalOrderReceipt.apply(this, arguments);
2781
3021
  }
2782
3022
  return printLocalOrderReceipt;
@@ -2790,27 +3030,27 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2790
3030
  if (!amountSnapshot) return undefined;
2791
3031
  try {
2792
3032
  return new Decimal(amountSnapshot.amountGap || 0).lte(0) ? 'paid' : undefined;
2793
- } catch (_unused2) {
3033
+ } catch (_unused4) {
2794
3034
  return undefined;
2795
3035
  }
2796
3036
  }
2797
3037
  }, {
2798
3038
  key: "syncPaymentsToOrder",
2799
3039
  value: function () {
2800
- var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(params) {
2801
- var _ref25, _params$businessCode, _this$otherParams23, _this$otherParams24, _params$channel;
3040
+ var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(params) {
3041
+ var _ref32, _params$businessCode, _this$otherParams27, _this$otherParams28, _params$channel2;
2802
3042
  var businessCode, channel, syncParams, syncState, payments, syncResult, latestPayments, amountSnapshot, orderSnapshot, syncPayload;
2803
- return _regeneratorRuntime().wrap(function _callee30$(_context30) {
2804
- while (1) switch (_context30.prev = _context30.next) {
3043
+ return _regeneratorRuntime().wrap(function _callee31$(_context31) {
3044
+ while (1) switch (_context31.prev = _context31.next) {
2805
3045
  case 0:
2806
3046
  if (this.store.order) {
2807
- _context30.next = 2;
3047
+ _context31.next = 2;
2808
3048
  break;
2809
3049
  }
2810
3050
  throw new Error('order 模块未初始化');
2811
3051
  case 2:
2812
- businessCode = (_ref25 = (_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 && _ref25 !== void 0 ? _ref25 : (_this$otherParams24 = this.otherParams) === null || _this$otherParams24 === void 0 ? void 0 : _this$otherParams24.business_code;
2813
- channel = (_params$channel = params.channel) !== null && _params$channel !== void 0 ? _params$channel : this.getSubmitOrderSalesChannel();
3052
+ businessCode = (_ref32 = (_params$businessCode = params.businessCode) !== null && _params$businessCode !== void 0 ? _params$businessCode : (_this$otherParams27 = this.otherParams) === null || _this$otherParams27 === void 0 ? void 0 : _this$otherParams27.businessCode) !== null && _ref32 !== void 0 ? _ref32 : (_this$otherParams28 = this.otherParams) === null || _this$otherParams28 === void 0 ? void 0 : _this$otherParams28.business_code;
3053
+ channel = (_params$channel2 = params.channel) !== null && _params$channel2 !== void 0 ? _params$channel2 : this.getSubmitOrderSalesChannel();
2814
3054
  syncParams = _objectSpread(_objectSpread(_objectSpread({}, params), businessCode !== undefined ? {
2815
3055
  businessCode: businessCode
2816
3056
  } : {}), channel !== undefined ? {
@@ -2818,14 +3058,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2818
3058
  } : {});
2819
3059
  syncState = this.store.order.getOrderSyncState();
2820
3060
  if (!(params.submitWhenPaid && syncState === 'submitting')) {
2821
- _context30.next = 9;
3061
+ _context31.next = 9;
2822
3062
  break;
2823
3063
  }
2824
3064
  this.queueLatestAutoPaymentSync();
2825
- return _context30.abrupt("return", this.store.order.syncPaymentsToOrder(syncParams));
3065
+ return _context31.abrupt("return", this.store.order.syncPaymentsToOrder(syncParams));
2826
3066
  case 9:
2827
3067
  payments = params.payments || [];
2828
- _context30.next = 12;
3068
+ _context31.next = 12;
2829
3069
  return this.effectsEmit(BaseSalesHookNames.onPaymentSyncStart, {
2830
3070
  payments: payments,
2831
3071
  params: syncParams,
@@ -2833,11 +3073,11 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2833
3073
  orderSnapshot: this.store.order.getOrderSnapshot()
2834
3074
  });
2835
3075
  case 12:
2836
- _context30.prev = 12;
2837
- _context30.next = 15;
3076
+ _context31.prev = 12;
3077
+ _context31.next = 15;
2838
3078
  return this.store.order.syncPaymentsToOrder(syncParams);
2839
3079
  case 15:
2840
- syncResult = _context30.sent;
3080
+ syncResult = _context31.sent;
2841
3081
  latestPayments = this.store.order.getOrderPayments();
2842
3082
  amountSnapshot = this.store.order.getOrderAmountSnapshot();
2843
3083
  orderSnapshot = this.store.order.getOrderSnapshot();
@@ -2855,25 +3095,25 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2855
3095
  depositAmount: syncResult.depositAmount,
2856
3096
  orderExpectedAmount: syncResult.orderExpectedAmount
2857
3097
  };
2858
- _context30.next = 22;
3098
+ _context31.next = 22;
2859
3099
  return this.effectsEmit(BaseSalesHookNames.onPaymentSyncEnd, syncPayload);
2860
3100
  case 22:
2861
3101
  if (!(syncResult.isDepositFullyPaid && !syncResult.isOrderFullyPaid)) {
2862
- _context30.next = 25;
3102
+ _context31.next = 25;
2863
3103
  break;
2864
3104
  }
2865
- _context30.next = 25;
3105
+ _context31.next = 25;
2866
3106
  return this.effectsEmit(BaseSalesHookNames.onDepositPaymentSyncEnd, syncPayload);
2867
3107
  case 25:
2868
3108
  this.scheduleQueuedAutoPaymentSyncFlush(0);
2869
- return _context30.abrupt("return", syncResult);
3109
+ return _context31.abrupt("return", syncResult);
2870
3110
  case 29:
2871
- _context30.prev = 29;
2872
- _context30.t0 = _context30["catch"](12);
2873
- _context30.next = 33;
3111
+ _context31.prev = 29;
3112
+ _context31.t0 = _context31["catch"](12);
3113
+ _context31.next = 33;
2874
3114
  return this.effectsEmit(BaseSalesHookNames.onPaymentSyncEnd, {
2875
3115
  ok: false,
2876
- error: _context30.t0,
3116
+ error: _context31.t0,
2877
3117
  payments: this.store.order.getOrderPayments(),
2878
3118
  params: syncParams,
2879
3119
  amountSnapshot: this.store.order.getOrderAmountSnapshot(),
@@ -2881,14 +3121,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2881
3121
  });
2882
3122
  case 33:
2883
3123
  this.scheduleQueuedAutoPaymentSyncFlush(0);
2884
- throw _context30.t0;
3124
+ throw _context31.t0;
2885
3125
  case 35:
2886
3126
  case "end":
2887
- return _context30.stop();
3127
+ return _context31.stop();
2888
3128
  }
2889
- }, _callee30, this, [[12, 29]]);
3129
+ }, _callee31, this, [[12, 29]]);
2890
3130
  }));
2891
- function syncPaymentsToOrder(_x25) {
3131
+ function syncPaymentsToOrder(_x26) {
2892
3132
  return _syncPaymentsToOrder.apply(this, arguments);
2893
3133
  }
2894
3134
  return syncPaymentsToOrder;
@@ -2925,58 +3165,58 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2925
3165
  }, {
2926
3166
  key: "scheduleQueuedAutoPaymentSyncFlush",
2927
3167
  value: function scheduleQueuedAutoPaymentSyncFlush() {
2928
- var _this11 = this;
3168
+ var _this13 = this;
2929
3169
  var delay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 100;
2930
3170
  if (!this.queuedAutoPaymentSync) return;
2931
3171
  if (this.autoPaymentSyncTimer) return;
2932
3172
  this.autoPaymentSyncTimer = setTimeout(function () {
2933
- _this11.autoPaymentSyncTimer = null;
2934
- void _this11.flushQueuedAutoPaymentSync();
3173
+ _this13.autoPaymentSyncTimer = null;
3174
+ void _this13.flushQueuedAutoPaymentSync();
2935
3175
  }, delay);
2936
3176
  }
2937
3177
  }, {
2938
3178
  key: "flushQueuedAutoPaymentSync",
2939
3179
  value: function () {
2940
- var _flushQueuedAutoPaymentSync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31() {
3180
+ var _flushQueuedAutoPaymentSync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32() {
2941
3181
  var payments;
2942
- return _regeneratorRuntime().wrap(function _callee31$(_context31) {
2943
- while (1) switch (_context31.prev = _context31.next) {
3182
+ return _regeneratorRuntime().wrap(function _callee32$(_context32) {
3183
+ while (1) switch (_context32.prev = _context32.next) {
2944
3184
  case 0:
2945
3185
  if (this.store.order) {
2946
- _context31.next = 2;
3186
+ _context32.next = 2;
2947
3187
  break;
2948
3188
  }
2949
- return _context31.abrupt("return");
3189
+ return _context32.abrupt("return");
2950
3190
  case 2:
2951
3191
  if (!(!this.queuedAutoPaymentSync || this.autoPaymentSyncFlushing)) {
2952
- _context31.next = 4;
3192
+ _context32.next = 4;
2953
3193
  break;
2954
3194
  }
2955
- return _context31.abrupt("return");
3195
+ return _context32.abrupt("return");
2956
3196
  case 4:
2957
3197
  if (!(this.store.order.getOrderSyncState() === 'submitting')) {
2958
- _context31.next = 7;
3198
+ _context32.next = 7;
2959
3199
  break;
2960
3200
  }
2961
3201
  this.scheduleQueuedAutoPaymentSyncFlush();
2962
- return _context31.abrupt("return");
3202
+ return _context32.abrupt("return");
2963
3203
  case 7:
2964
3204
  this.autoPaymentSyncFlushing = true;
2965
- _context31.prev = 8;
3205
+ _context32.prev = 8;
2966
3206
  case 9:
2967
3207
  if (!this.queuedAutoPaymentSync) {
2968
- _context31.next = 18;
3208
+ _context32.next = 18;
2969
3209
  break;
2970
3210
  }
2971
3211
  this.queuedAutoPaymentSync = false;
2972
3212
  payments = this.store.order.getOrderPayments();
2973
3213
  if (payments.length) {
2974
- _context31.next = 14;
3214
+ _context32.next = 14;
2975
3215
  break;
2976
3216
  }
2977
- return _context31.abrupt("continue", 9);
3217
+ return _context32.abrupt("continue", 9);
2978
3218
  case 14:
2979
- _context31.next = 16;
3219
+ _context32.next = 16;
2980
3220
  return this.syncPaymentsToOrder({
2981
3221
  payments: payments,
2982
3222
  paymentStatus: this.getPaymentStatusForSync(payments),
@@ -2984,44 +3224,94 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2984
3224
  smallTicketDataFlag: 1
2985
3225
  });
2986
3226
  case 16:
2987
- _context31.next = 9;
3227
+ _context32.next = 9;
2988
3228
  break;
2989
3229
  case 18:
2990
- _context31.next = 23;
3230
+ _context32.next = 23;
2991
3231
  break;
2992
3232
  case 20:
2993
- _context31.prev = 20;
2994
- _context31.t0 = _context31["catch"](8);
3233
+ _context32.prev = 20;
3234
+ _context32.t0 = _context32["catch"](8);
2995
3235
  this.logError('queued auto sync payments failed', {
2996
- error: _context31.t0 instanceof Error ? _context31.t0.message : String(_context31.t0)
3236
+ error: _context32.t0 instanceof Error ? _context32.t0.message : String(_context32.t0)
2997
3237
  });
2998
3238
  case 23:
2999
- _context31.prev = 23;
3239
+ _context32.prev = 23;
3000
3240
  this.autoPaymentSyncFlushing = false;
3001
3241
  if (this.queuedAutoPaymentSync) {
3002
3242
  this.scheduleQueuedAutoPaymentSyncFlush(0);
3003
3243
  }
3004
- return _context31.finish(23);
3244
+ return _context32.finish(23);
3005
3245
  case 27:
3006
3246
  case "end":
3007
- return _context31.stop();
3247
+ return _context32.stop();
3008
3248
  }
3009
- }, _callee31, this, [[8, 20, 23, 27]]);
3249
+ }, _callee32, this, [[8, 20, 23, 27]]);
3010
3250
  }));
3011
3251
  function flushQueuedAutoPaymentSync() {
3012
3252
  return _flushQueuedAutoPaymentSync.apply(this, arguments);
3013
3253
  }
3014
3254
  return flushQueuedAutoPaymentSync;
3015
- }() /** 追加单个支付项到当前订单。 */
3255
+ }()
3256
+ /**
3257
+ * 同步兼容入口。无法等待 IoT 短号时,按调用当下的 device_id 或 LOCAL 生成。
3258
+ */
3016
3259
  }, {
3017
3260
  key: "addOrderPayment",
3018
3261
  value: function addOrderPayment(payment) {
3019
- var _this$otherParams25,
3262
+ var hasPaymentNumber = String(payment.payment_number || '').trim() !== '';
3263
+ return this.addOrderPaymentWithDevicePrefix(payment, hasPaymentNumber ? 'LOCAL' : this.getPaymentNumberDevicePrefixSync());
3264
+ }
3265
+
3266
+ /**
3267
+ * 创建新支付项时优先使用业务解决方案初始化阶段缓存的设备短号;
3268
+ * 未缓存的通用 BaseSales 保持实时读取设备信息的兼容语义。
3269
+ */
3270
+ }, {
3271
+ key: "addOrderPaymentAsync",
3272
+ value: (function () {
3273
+ var _addOrderPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(payment) {
3274
+ var paymentRecord, hasPaymentNumber, devicePrefix;
3275
+ return _regeneratorRuntime().wrap(function _callee33$(_context33) {
3276
+ while (1) switch (_context33.prev = _context33.next) {
3277
+ case 0:
3278
+ paymentRecord = payment;
3279
+ hasPaymentNumber = String(paymentRecord.payment_number || '').trim() !== '';
3280
+ if (!hasPaymentNumber) {
3281
+ _context33.next = 6;
3282
+ break;
3283
+ }
3284
+ _context33.t0 = 'LOCAL';
3285
+ _context33.next = 9;
3286
+ break;
3287
+ case 6:
3288
+ _context33.next = 8;
3289
+ return this.getPaymentNumberDevicePrefixAsync();
3290
+ case 8:
3291
+ _context33.t0 = _context33.sent;
3292
+ case 9:
3293
+ devicePrefix = _context33.t0;
3294
+ return _context33.abrupt("return", this.addOrderPaymentWithDevicePrefix(payment, devicePrefix));
3295
+ case 11:
3296
+ case "end":
3297
+ return _context33.stop();
3298
+ }
3299
+ }, _callee33, this);
3300
+ }));
3301
+ function addOrderPaymentAsync(_x27) {
3302
+ return _addOrderPaymentAsync.apply(this, arguments);
3303
+ }
3304
+ return addOrderPaymentAsync;
3305
+ }())
3306
+ }, {
3307
+ key: "addOrderPaymentWithDevicePrefix",
3308
+ value: function addOrderPaymentWithDevicePrefix(payment, devicePrefix) {
3309
+ var _this$otherParams29,
3020
3310
  _paymentRecord$paymen,
3021
3311
  _paymentRecord$create,
3022
- _ref26,
3312
+ _ref33,
3023
3313
  _paymentRecord$origin,
3024
- _this12 = this;
3314
+ _this14 = this;
3025
3315
  if (!this.store.order) throw new Error('order 模块未初始化');
3026
3316
  var paymentRecord = payment;
3027
3317
  var paymentAmount = new Decimal(paymentRecord.amount || 0);
@@ -3032,25 +3322,26 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3032
3322
  return this.store.order.getOrderPayments();
3033
3323
  }
3034
3324
  var metadata = paymentRecord.metadata && _typeof(paymentRecord.metadata) === 'object' ? _objectSpread({}, paymentRecord.metadata) : {};
3035
- var shopWalletPassId = (_this$otherParams25 = this.otherParams) === null || _this$otherParams25 === void 0 ? void 0 : _this$otherParams25.shop_wallet_pass_id;
3325
+ var shopWalletPassId = (_this$otherParams29 = this.otherParams) === null || _this$otherParams29 === void 0 ? void 0 : _this$otherParams29.shop_wallet_pass_id;
3036
3326
  if (shopWalletPassId !== undefined && shopWalletPassId !== null) {
3037
3327
  metadata.shop_wallet_pass_id = shopWalletPassId;
3038
3328
  }
3039
- if (!metadata.unique_payment_number) {
3040
- metadata.unique_payment_number = createUuidV4();
3041
- }
3329
+ var normalizedPaymentRecord = ensureOrderPaymentNumber(paymentRecord, devicePrefix, createUuidV4);
3042
3330
  var paymentTimestamp = dayjs().format('YYYY-MM-DD HH:mm:ss');
3043
3331
  var paymentTime = (_paymentRecord$paymen = paymentRecord.payment_time) !== null && _paymentRecord$paymen !== void 0 ? _paymentRecord$paymen : paymentTimestamp;
3044
3332
  var createdAt = (_paymentRecord$create = paymentRecord.created_at) !== null && _paymentRecord$create !== void 0 ? _paymentRecord$create : paymentTimestamp;
3045
3333
  var serviceCharge = paymentRecord.service_charge && _typeof(paymentRecord.service_charge) === 'object' ? paymentRecord.service_charge : null;
3046
- var calculatedServiceFee = serviceCharge ? new Decimal((_ref26 = (_paymentRecord$origin = paymentRecord.origin_amount) !== null && _paymentRecord$origin !== void 0 ? _paymentRecord$origin : paymentRecord.amount) !== null && _ref26 !== void 0 ? _ref26 : 0).times(serviceCharge.percentage || 0).plus(serviceCharge.amount || 0).toDecimalPlaces(2).toFixed(2) : undefined;
3047
- var payments = this.store.order.addOrderPayment(_objectSpread(_objectSpread(_objectSpread({}, paymentRecord), calculatedServiceFee !== undefined ? {
3334
+ var calculatedServiceFee = serviceCharge ? new Decimal((_ref33 = (_paymentRecord$origin = paymentRecord.origin_amount) !== null && _paymentRecord$origin !== void 0 ? _paymentRecord$origin : paymentRecord.amount) !== null && _ref33 !== void 0 ? _ref33 : 0).times(serviceCharge.percentage || 0).plus(serviceCharge.amount || 0).toDecimalPlaces(2).toFixed(2) : undefined;
3335
+ var payments = this.store.order.addOrderPayment(_objectSpread(_objectSpread(_objectSpread({}, normalizedPaymentRecord), calculatedServiceFee !== undefined ? {
3048
3336
  service_fee: calculatedServiceFee
3049
3337
  } : {}), {}, {
3050
3338
  metadata: metadata,
3051
3339
  payment_time: paymentTime,
3052
3340
  created_at: createdAt
3053
3341
  }));
3342
+ if (paymentRecord.status === 'payment_pending') {
3343
+ return payments;
3344
+ }
3054
3345
  var amountSnapshot = this.store.order.getOrderAmountSnapshot();
3055
3346
  var syncState = this.store.order.getOrderSyncState();
3056
3347
  if (amountSnapshot) {
@@ -3064,7 +3355,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3064
3355
  submitWhenPaid: true,
3065
3356
  smallTicketDataFlag: 1
3066
3357
  }).catch(function (error) {
3067
- _this12.logError('auto sync payments failed', {
3358
+ _this14.logError('auto sync payments failed', {
3068
3359
  error: error instanceof Error ? error.message : String(error)
3069
3360
  });
3070
3361
  });
@@ -3075,12 +3366,131 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3075
3366
  /** 更新当前订单中的指定支付项。 */
3076
3367
  }, {
3077
3368
  key: "updateOrderPayment",
3078
- value: function updateOrderPayment(paymentIdentity, updates) {
3079
- if (!this.store.order) throw new Error('order 模块未初始化');
3080
- return this.store.order.updateOrderPayment(paymentIdentity, updates);
3081
- }
3082
-
3083
- /** 删除当前订单中的指定支付项。 */
3369
+ value: (function () {
3370
+ var _updateOrderPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(paymentIdentity, updates) {
3371
+ var _result$payment, _result$payment2;
3372
+ var options,
3373
+ matchMode,
3374
+ previousMatch,
3375
+ previousPayment,
3376
+ _this$store$order$get2,
3377
+ currentPayments,
3378
+ _syncResult,
3379
+ _options$smallTicketD,
3380
+ result,
3381
+ draftResult,
3382
+ draftError,
3383
+ becamePaid,
3384
+ shouldSubmit,
3385
+ syncResult,
3386
+ _options$smallTicketD2,
3387
+ _args34 = arguments;
3388
+ return _regeneratorRuntime().wrap(function _callee34$(_context34) {
3389
+ while (1) switch (_context34.prev = _context34.next) {
3390
+ case 0:
3391
+ options = _args34.length > 2 && _args34[2] !== undefined ? _args34[2] : {};
3392
+ if (this.store.order) {
3393
+ _context34.next = 3;
3394
+ break;
3395
+ }
3396
+ throw new Error('order 模块未初始化');
3397
+ case 3:
3398
+ matchMode = options.matchBy === 'compat' || options.matchBy === 'legacy' ? 'compat' : 'payment_number';
3399
+ previousMatch = resolveOrderPaymentIdentity(this.store.order.getOrderPayments(), paymentIdentity, matchMode);
3400
+ previousPayment = previousMatch === null || previousMatch === void 0 ? void 0 : previousMatch.payment;
3401
+ if (!((previousPayment === null || previousPayment === void 0 ? void 0 : previousPayment.status) === 'paid' && !options.applyUpdatesWhenPaid)) {
3402
+ _context34.next = 13;
3403
+ break;
3404
+ }
3405
+ currentPayments = this.store.order.getOrderPayments();
3406
+ if (!(options.submitWhenPaid && options.forceSubmitIfPaid)) {
3407
+ _context34.next = 12;
3408
+ break;
3409
+ }
3410
+ _context34.next = 11;
3411
+ return this.syncPaymentsToOrder({
3412
+ payments: currentPayments,
3413
+ paymentStatus: this.getPaymentStatusForSync(currentPayments),
3414
+ submitWhenPaid: true,
3415
+ smallTicketDataFlag: (_options$smallTicketD = options.smallTicketDataFlag) !== null && _options$smallTicketD !== void 0 ? _options$smallTicketD : 1
3416
+ });
3417
+ case 11:
3418
+ _syncResult = _context34.sent;
3419
+ case 12:
3420
+ return _context34.abrupt("return", _objectSpread({
3421
+ updated: false,
3422
+ payment: previousPayment,
3423
+ payments: currentPayments,
3424
+ summary: ((_this$store$order$get2 = this.store.order.getOrderAmountSnapshot()) === null || _this$store$order$get2 === void 0 ? void 0 : _this$store$order$get2.summary) || null
3425
+ }, _syncResult !== undefined ? {
3426
+ syncResult: _syncResult
3427
+ } : {}));
3428
+ case 13:
3429
+ _context34.next = 15;
3430
+ return this.store.order.updateOrderPayment(paymentIdentity, updates, {
3431
+ matchBy: matchMode
3432
+ });
3433
+ case 15:
3434
+ result = _context34.sent;
3435
+ if (!(options.persistDraft !== false)) {
3436
+ _context34.next = 29;
3437
+ break;
3438
+ }
3439
+ _context34.prev = 17;
3440
+ _context34.next = 20;
3441
+ return this.saveSalesOrderDraft();
3442
+ case 20:
3443
+ draftResult = _context34.sent;
3444
+ _context34.next = 29;
3445
+ break;
3446
+ case 23:
3447
+ _context34.prev = 23;
3448
+ _context34.t0 = _context34["catch"](17);
3449
+ draftError = _context34.t0;
3450
+ this.logError('updateOrderPayment: 保存支付草稿失败', {
3451
+ paymentIdentity: paymentIdentity,
3452
+ error: _context34.t0 instanceof Error ? _context34.t0.message : String(_context34.t0)
3453
+ });
3454
+ if (options.submitWhenPaid) {
3455
+ _context34.next = 29;
3456
+ break;
3457
+ }
3458
+ throw _context34.t0;
3459
+ case 29:
3460
+ 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';
3461
+ shouldSubmit = Boolean(options.submitWhenPaid && ((_result$payment2 = result.payment) === null || _result$payment2 === void 0 ? void 0 : _result$payment2.status) === 'paid' && (becamePaid || options.forceSubmitIfPaid));
3462
+ if (!shouldSubmit) {
3463
+ _context34.next = 35;
3464
+ break;
3465
+ }
3466
+ _context34.next = 34;
3467
+ return this.syncPaymentsToOrder({
3468
+ payments: result.payments,
3469
+ paymentStatus: this.getPaymentStatusForSync(result.payments),
3470
+ submitWhenPaid: true,
3471
+ smallTicketDataFlag: (_options$smallTicketD2 = options.smallTicketDataFlag) !== null && _options$smallTicketD2 !== void 0 ? _options$smallTicketD2 : 1
3472
+ });
3473
+ case 34:
3474
+ syncResult = _context34.sent;
3475
+ case 35:
3476
+ return _context34.abrupt("return", _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, result), draftResult !== undefined ? {
3477
+ draftResult: draftResult
3478
+ } : {}), draftError !== undefined ? {
3479
+ draftError: draftError
3480
+ } : {}), syncResult !== undefined ? {
3481
+ syncResult: syncResult
3482
+ } : {}));
3483
+ case 36:
3484
+ case "end":
3485
+ return _context34.stop();
3486
+ }
3487
+ }, _callee34, this, [[17, 23]]);
3488
+ }));
3489
+ function updateOrderPayment(_x28, _x29) {
3490
+ return _updateOrderPayment.apply(this, arguments);
3491
+ }
3492
+ return updateOrderPayment;
3493
+ }() /** 删除当前订单中的指定支付项。 */)
3084
3494
  }, {
3085
3495
  key: "deleteOrderPayment",
3086
3496
  value: function deleteOrderPayment(paymentIdentity) {
@@ -3095,11 +3505,42 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3095
3505
  if (!this.store.order) throw new Error('order 模块未初始化');
3096
3506
  return this.store.order.updateVoucherOrderPayments(payments, options);
3097
3507
  }
3508
+ }, {
3509
+ key: "updateVoucherOrderPaymentsAsync",
3510
+ value: function () {
3511
+ var _updateVoucherOrderPaymentsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(payments, options) {
3512
+ return _regeneratorRuntime().wrap(function _callee35$(_context35) {
3513
+ while (1) switch (_context35.prev = _context35.next) {
3514
+ case 0:
3515
+ if (this.store.order) {
3516
+ _context35.next = 2;
3517
+ break;
3518
+ }
3519
+ throw new Error('order 模块未初始化');
3520
+ case 2:
3521
+ return _context35.abrupt("return", this.store.order.updateVoucherOrderPaymentsAsync(payments, options));
3522
+ case 3:
3523
+ case "end":
3524
+ return _context35.stop();
3525
+ }
3526
+ }, _callee35, this);
3527
+ }));
3528
+ function updateVoucherOrderPaymentsAsync(_x30, _x31) {
3529
+ return _updateVoucherOrderPaymentsAsync.apply(this, arguments);
3530
+ }
3531
+ return updateVoucherOrderPaymentsAsync;
3532
+ }()
3098
3533
  }, {
3099
3534
  key: "confirmPendingVoucherPayments",
3100
3535
  value: function confirmPendingVoucherPayments() {
3101
3536
  if (!this.store.order) throw new Error('order 模块未初始化');
3102
- return this.store.order.confirmPendingVoucherPayments();
3537
+ var payments = this.store.order.confirmPendingVoucherPayments();
3538
+ if (this.store.payment) {
3539
+ var committed = this.getCommittedWalletAssets();
3540
+ var state = this.store.payment.wallet.setCommittedWalletAssets(committed.ids, committed.assets);
3541
+ void this.publishWalletAssetsState(state);
3542
+ }
3543
+ return payments;
3103
3544
  }
3104
3545
  }, {
3105
3546
  key: "discardPendingVoucherPayments",
@@ -3168,64 +3609,72 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3168
3609
  });
3169
3610
  return walletProducts;
3170
3611
  }
3612
+ }, {
3613
+ key: "buildWalletInitBusinessData",
3614
+ value: function buildWalletInitBusinessData(params) {
3615
+ var _this$store$order8, _params$order_wait_pa, _ref34, _tempOrder$is_price_i;
3616
+ var snapshot = (_this$store$order8 = this.store.order) === null || _this$store$order8 === void 0 ? void 0 : _this$store$order8.getOrderSnapshot();
3617
+ var tempOrder = snapshot === null || snapshot === void 0 ? void 0 : snapshot.tempOrder;
3618
+ var amount = snapshot === null || snapshot === void 0 ? void 0 : snapshot.amount;
3619
+ if (!tempOrder || !amount) return null;
3620
+ return _objectSpread({
3621
+ customer_id: tempOrder.customer_id ? Number(tempOrder.customer_id) : undefined,
3622
+ holder: tempOrder.holder,
3623
+ amountInfo: {
3624
+ totalAmount: amount.totalAmount,
3625
+ subTotal: amount.summary.product_amount || amount.summary.product_expect_amount || amount.totalAmount,
3626
+ depositAmount: amount.depositAmount,
3627
+ isDeposit: tempOrder.is_deposit
3628
+ },
3629
+ products: this.getWalletProductList(),
3630
+ 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),
3631
+ is_price_include_tax: (_ref34 = (_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 && _ref34 !== void 0 ? _ref34 : 1
3632
+ }, snapshot.identity.orderId ? {
3633
+ payment_order_id: String(snapshot.identity.orderId)
3634
+ } : {});
3635
+ }
3171
3636
  }, {
3172
3637
  key: "initWalletData",
3173
3638
  value: function () {
3174
- var _initWalletData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(params) {
3175
- var _params$order_wait_pa, _ref27, _tempOrder$is_price_i;
3176
- var snapshot, tempOrder, amount, walletBusinessData, result;
3177
- return _regeneratorRuntime().wrap(function _callee32$(_context32) {
3178
- while (1) switch (_context32.prev = _context32.next) {
3639
+ var _initWalletData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(params) {
3640
+ var _snapshot$identity;
3641
+ var snapshot, walletBusinessData, result;
3642
+ return _regeneratorRuntime().wrap(function _callee36$(_context36) {
3643
+ while (1) switch (_context36.prev = _context36.next) {
3179
3644
  case 0:
3180
3645
  if (this.store.order) {
3181
- _context32.next = 2;
3646
+ _context36.next = 2;
3182
3647
  break;
3183
3648
  }
3184
3649
  throw new Error('order 模块未初始化');
3185
3650
  case 2:
3186
3651
  if (this.store.payment) {
3187
- _context32.next = 4;
3652
+ _context36.next = 4;
3188
3653
  break;
3189
3654
  }
3190
3655
  throw new Error('payment 模块未初始化');
3191
3656
  case 4:
3192
3657
  snapshot = this.store.order.getOrderSnapshot();
3193
- tempOrder = snapshot === null || snapshot === void 0 ? void 0 : snapshot.tempOrder;
3194
- amount = snapshot === null || snapshot === void 0 ? void 0 : snapshot.amount;
3195
- if (!(!tempOrder || !amount)) {
3196
- _context32.next = 9;
3658
+ walletBusinessData = this.buildWalletInitBusinessData(params);
3659
+ if (walletBusinessData) {
3660
+ _context36.next = 8;
3197
3661
  break;
3198
3662
  }
3199
- return _context32.abrupt("return", {
3663
+ return _context36.abrupt("return", {
3200
3664
  walletRecommendList: [],
3201
3665
  userIdentificationCodes: [],
3202
3666
  transformList: [],
3203
3667
  noApplicableVoucher: [],
3204
3668
  products: []
3205
3669
  });
3206
- case 9:
3207
- walletBusinessData = _objectSpread({
3208
- customer_id: tempOrder.customer_id ? Number(tempOrder.customer_id) : undefined,
3209
- holder: tempOrder.holder,
3210
- amountInfo: {
3211
- totalAmount: amount.totalAmount,
3212
- subTotal: amount.summary.product_amount || amount.summary.product_expect_amount || amount.totalAmount,
3213
- depositAmount: amount.depositAmount,
3214
- isDeposit: tempOrder.is_deposit
3215
- },
3216
- products: this.getWalletProductList(),
3217
- 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),
3218
- is_price_include_tax: (_ref27 = (_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 && _ref27 !== void 0 ? _ref27 : 1
3219
- }, snapshot.identity.orderId ? {
3220
- payment_order_id: String(snapshot.identity.orderId)
3221
- } : {});
3222
- _context32.next = 12;
3670
+ case 8:
3671
+ _context36.next = 10;
3223
3672
  return this.store.payment.wallet.initializeWalletDataFromBusinessAsync(walletBusinessData);
3224
- case 12:
3225
- result = _context32.sent;
3226
- _context32.next = 15;
3673
+ case 10:
3674
+ result = _context36.sent;
3675
+ _context36.next = 13;
3227
3676
  return this.core.effects.emit("".concat(this.name, ":onWalletDataInitialized"), {
3228
- orderId: snapshot.identity.orderId,
3677
+ orderId: snapshot === null || snapshot === void 0 || (_snapshot$identity = snapshot.identity) === null || _snapshot$identity === void 0 ? void 0 : _snapshot$identity.orderId,
3229
3678
  customerId: walletBusinessData.customer_id,
3230
3679
  walletBusinessData: {
3231
3680
  customer_id: walletBusinessData.customer_id,
@@ -3234,25 +3683,421 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3234
3683
  },
3235
3684
  timestamp: Date.now()
3236
3685
  });
3237
- case 15:
3238
- return _context32.abrupt("return", result);
3239
- case 16:
3686
+ case 13:
3687
+ return _context36.abrupt("return", result);
3688
+ case 14:
3240
3689
  case "end":
3241
- return _context32.stop();
3690
+ return _context36.stop();
3242
3691
  }
3243
- }, _callee32, this);
3692
+ }, _callee36, this);
3244
3693
  }));
3245
- function initWalletData(_x26) {
3694
+ function initWalletData(_x32) {
3246
3695
  return _initWalletData.apply(this, arguments);
3247
3696
  }
3248
3697
  return initWalletData;
3249
3698
  }()
3699
+ }, {
3700
+ key: "getCommittedWalletAssets",
3701
+ value: function getCommittedWalletAssets() {
3702
+ var _this$store$order9, _this$store$order9$ge;
3703
+ 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)) || [];
3704
+ var committed = payments.filter(function (payment) {
3705
+ var voucherId = payment === null || payment === void 0 ? void 0 : payment.voucher_id;
3706
+ if (voucherId === undefined || voucherId === null || voucherId === 0) {
3707
+ return false;
3708
+ }
3709
+ 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) !== '';
3710
+ });
3711
+ return {
3712
+ ids: committed.map(function (payment) {
3713
+ return payment.voucher_id;
3714
+ }),
3715
+ assets: committed.map(function (payment) {
3716
+ var _Object$entries$find;
3717
+ var fundRecord = (payment === null || payment === void 0 ? void 0 : payment.fund_record) || {};
3718
+ var walletPassName = fundRecord.wallet_pass_name;
3719
+ var title = walletPassName && _typeof(walletPassName) === 'object' ? walletPassName.default || Object.values(walletPassName)[0] : walletPassName;
3720
+ var code = String((payment === null || payment === void 0 ? void 0 : payment.code) || '').toUpperCase();
3721
+ var tag = ((_Object$entries$find = Object.entries(WALLET_PAYMENT_CODE_BY_TAG).find(function (_ref35) {
3722
+ var _ref36 = _slicedToArray(_ref35, 2),
3723
+ paymentCode = _ref36[1];
3724
+ return paymentCode === code;
3725
+ })) === null || _Object$entries$find === void 0 ? void 0 : _Object$entries$find[0]) || fundRecord.tag;
3726
+ return {
3727
+ id: payment.voucher_id,
3728
+ voucher_id: payment.voucher_id,
3729
+ code: fundRecord.code,
3730
+ tag: tag,
3731
+ product_name: title || payment.name,
3732
+ name: title || payment.name,
3733
+ amount: Number(payment.amount || 0),
3734
+ _available_max_amount: Number(payment.amount || 0),
3735
+ unified_available_status: 1,
3736
+ _unified_available_status: 1,
3737
+ _committed_payment: payment
3738
+ };
3739
+ })
3740
+ };
3741
+ }
3742
+ }, {
3743
+ key: "publishWalletAssetsState",
3744
+ value: function () {
3745
+ var _publishWalletAssetsState = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(state) {
3746
+ return _regeneratorRuntime().wrap(function _callee37$(_context37) {
3747
+ while (1) switch (_context37.prev = _context37.next) {
3748
+ case 0:
3749
+ _context37.next = 2;
3750
+ return this.effectsEmit(BaseSalesHookNames.onWalletAssetsStateChanged, {
3751
+ state: state
3752
+ });
3753
+ case 2:
3754
+ return _context37.abrupt("return", state);
3755
+ case 3:
3756
+ case "end":
3757
+ return _context37.stop();
3758
+ }
3759
+ }, _callee37, this);
3760
+ }));
3761
+ function publishWalletAssetsState(_x33) {
3762
+ return _publishWalletAssetsState.apply(this, arguments);
3763
+ }
3764
+ return publishWalletAssetsState;
3765
+ }()
3766
+ }, {
3767
+ key: "syncSelectedWalletAssets",
3768
+ value: function () {
3769
+ var _syncSelectedWalletAssets = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(state) {
3770
+ var paymentMethods, methodByCode, preparePayments, selectedAssetById, voucherPayments, payments;
3771
+ return _regeneratorRuntime().wrap(function _callee38$(_context38) {
3772
+ while (1) switch (_context38.prev = _context38.next) {
3773
+ case 0:
3774
+ if (!(!this.store.order || !this.store.payment)) {
3775
+ _context38.next = 2;
3776
+ break;
3777
+ }
3778
+ throw new Error('订单或支付模块未初始化');
3779
+ case 2:
3780
+ paymentMethods = this.getPaymentMethods();
3781
+ if (!(!paymentMethods.length && state.selectedItems.length)) {
3782
+ _context38.next = 7;
3783
+ break;
3784
+ }
3785
+ _context38.next = 6;
3786
+ return this.getPaymentMethodsAsync();
3787
+ case 6:
3788
+ paymentMethods = _context38.sent;
3789
+ case 7:
3790
+ methodByCode = new Map(paymentMethods.map(function (method) {
3791
+ return [String(method.code || '').toUpperCase(), method];
3792
+ }));
3793
+ preparePayments = this.store.payment.wallet.formatWalletPassList2PreparePayments(state.selectedItems);
3794
+ selectedAssetById = new Map(state.selectedItems.map(function (asset) {
3795
+ return [String(getSharedWalletAssetId(asset)), asset];
3796
+ }));
3797
+ voucherPayments = preparePayments.flatMap(function (item) {
3798
+ var asset = selectedAssetById.get(String(item.voucher_id));
3799
+ 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();
3800
+ var paymentMethod = methodByCode.get(paymentCode);
3801
+ var formattedAmount = Number(item.amount);
3802
+ var amount = Number.isFinite(formattedAmount) && formattedAmount > 0 ? formattedAmount : getSharedWalletAssetAmount(asset);
3803
+ if (!asset || !paymentMethod || !Number.isFinite(amount) || amount <= 0) {
3804
+ return [];
3805
+ }
3806
+ var walletPassUseValue = getSharedWalletPassUseValue({
3807
+ asset: asset,
3808
+ amount: amount,
3809
+ paymentMethod: paymentMethod
3810
+ });
3811
+ return [{
3812
+ amount: amount.toFixed(2),
3813
+ code: paymentMethod.code,
3814
+ custom_payment_id: paymentMethod.id,
3815
+ name: paymentMethod.name,
3816
+ type: paymentMethod.type,
3817
+ voucher_id: item.voucher_id,
3818
+ wallet_pass_usage_unit: item.wallet_pass_usage_unit,
3819
+ wallet_pass_use_value: walletPassUseValue,
3820
+ fund_record: buildSharedWalletFundRecord({
3821
+ asset: asset,
3822
+ amount: amount,
3823
+ paymentMethod: paymentMethod
3824
+ })
3825
+ }];
3826
+ });
3827
+ payments = this.updateVoucherOrderPayments(voucherPayments, {
3828
+ status: 'payment_pending'
3829
+ });
3830
+ _context38.next = 14;
3831
+ return this.store.order.recalculateSummary({
3832
+ createIfMissing: true
3833
+ });
3834
+ case 14:
3835
+ return _context38.abrupt("return", payments);
3836
+ case 15:
3837
+ case "end":
3838
+ return _context38.stop();
3839
+ }
3840
+ }, _callee38, this);
3841
+ }));
3842
+ function syncSelectedWalletAssets(_x34) {
3843
+ return _syncSelectedWalletAssets.apply(this, arguments);
3844
+ }
3845
+ return syncSelectedWalletAssets;
3846
+ }() /** 读取购物车与 Shared Checkout 共用的钱包资产状态。 */
3847
+ }, {
3848
+ key: "getWalletAssetsState",
3849
+ value: function getWalletAssetsState() {
3850
+ if (!this.store.payment) throw new Error('payment 模块未初始化');
3851
+ return this.store.payment.wallet.getWalletAssetsState();
3852
+ }
3853
+
3854
+ /** 导出 Shared Checkout 跨运行时恢复所需的钱包状态与搜索缓存。 */
3855
+ }, {
3856
+ key: "exportWalletAssetsSnapshot",
3857
+ value: function exportWalletAssetsSnapshot() {
3858
+ if (!this.store.payment) throw new Error('payment 模块未初始化');
3859
+ return this.store.payment.wallet.exportWalletAssetsSnapshot();
3860
+ }
3861
+
3862
+ /** 配置仅影响 Wallet Assets,不改变 Promotion/Voucher 选择流程。 */
3863
+ }, {
3864
+ key: "configureWalletAssetsBehavior",
3865
+ value: function configureWalletAssetsBehavior(options) {
3866
+ if (!this.store.payment) throw new Error('payment 模块未初始化');
3867
+ this.store.payment.wallet.configureWalletAssetsBehavior(options);
3868
+ }
3869
+
3870
+ /**
3871
+ * 恢复 Shared Checkout 钱包快照,并把选择重新同步为订单 pending payment。
3872
+ */
3873
+ }, {
3874
+ key: "importWalletAssetsSnapshot",
3875
+ value: (function () {
3876
+ var _importWalletAssetsSnapshot = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(snapshot) {
3877
+ var state;
3878
+ return _regeneratorRuntime().wrap(function _callee39$(_context39) {
3879
+ while (1) switch (_context39.prev = _context39.next) {
3880
+ case 0:
3881
+ if (this.store.payment) {
3882
+ _context39.next = 2;
3883
+ break;
3884
+ }
3885
+ throw new Error('payment 模块未初始化');
3886
+ case 2:
3887
+ state = this.store.payment.wallet.importWalletAssetsSnapshot(snapshot);
3888
+ _context39.next = 5;
3889
+ return this.syncSelectedWalletAssets(state);
3890
+ case 5:
3891
+ return _context39.abrupt("return", this.publishWalletAssetsState(state));
3892
+ case 6:
3893
+ case "end":
3894
+ return _context39.stop();
3895
+ }
3896
+ }, _callee39, this);
3897
+ }));
3898
+ function importWalletAssetsSnapshot(_x35) {
3899
+ return _importWalletAssetsSnapshot.apply(this, arguments);
3900
+ }
3901
+ return importWalletAssetsSnapshot;
3902
+ }()
3903
+ /**
3904
+ * 基于当前订单快照刷新钱包资产。商品变化保留并重验选择;客户变化强制清空。
3905
+ */
3906
+ )
3907
+ }, {
3908
+ key: "refreshWalletAssets",
3909
+ value: (function () {
3910
+ var _refreshWalletAssets = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(params) {
3911
+ var _previousState$custom, _businessData$custome;
3912
+ var refreshSequence, wallet, businessData, emptyState, previousState, hasPreviousWalletContext, customerChanged, clearedState, refreshTask, state, committed;
3913
+ return _regeneratorRuntime().wrap(function _callee40$(_context40) {
3914
+ while (1) switch (_context40.prev = _context40.next) {
3915
+ case 0:
3916
+ if (this.store.order) {
3917
+ _context40.next = 2;
3918
+ break;
3919
+ }
3920
+ throw new Error('order 模块未初始化');
3921
+ case 2:
3922
+ if (this.store.payment) {
3923
+ _context40.next = 4;
3924
+ break;
3925
+ }
3926
+ throw new Error('payment 模块未初始化');
3927
+ case 4:
3928
+ refreshSequence = ++this.walletAssetsRefreshSequence;
3929
+ wallet = this.store.payment.wallet;
3930
+ businessData = this.buildWalletInitBusinessData(params);
3931
+ if (businessData) {
3932
+ _context40.next = 12;
3933
+ break;
3934
+ }
3935
+ wallet.clearAllCache();
3936
+ emptyState = wallet.getWalletAssetsState();
3937
+ this.updateVoucherOrderPayments([], {
3938
+ status: 'payment_pending'
3939
+ });
3940
+ return _context40.abrupt("return", this.publishWalletAssetsState(emptyState));
3941
+ case 12:
3942
+ previousState = wallet.getWalletAssetsState();
3943
+ hasPreviousWalletContext = previousState.status !== 'idle' || previousState.items.length > 0 || previousState.selectedIds.length > 0 || previousState.customerId !== undefined;
3944
+ 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 : '');
3945
+ if (!customerChanged) {
3946
+ _context40.next = 20;
3947
+ break;
3948
+ }
3949
+ clearedState = wallet.clearWalletAssetSelection();
3950
+ this.updateVoucherOrderPayments([], {
3951
+ status: 'payment_pending'
3952
+ });
3953
+ _context40.next = 20;
3954
+ return this.publishWalletAssetsState(clearedState);
3955
+ case 20:
3956
+ refreshTask = wallet.refreshWalletAssetsFromBusinessAsync(businessData, {
3957
+ preserveSelection: (params === null || params === void 0 ? void 0 : params.preserveSelection) !== false && !customerChanged
3958
+ });
3959
+ _context40.next = 23;
3960
+ return this.publishWalletAssetsState(wallet.getWalletAssetsState());
3961
+ case 23:
3962
+ _context40.next = 25;
3963
+ return refreshTask;
3964
+ case 25:
3965
+ state = _context40.sent;
3966
+ if (!(refreshSequence !== this.walletAssetsRefreshSequence)) {
3967
+ _context40.next = 28;
3968
+ break;
3969
+ }
3970
+ return _context40.abrupt("return", wallet.getWalletAssetsState());
3971
+ case 28:
3972
+ if (state.status !== 'error') {
3973
+ committed = this.getCommittedWalletAssets();
3974
+ state = wallet.setCommittedWalletAssets(committed.ids, committed.assets);
3975
+ }
3976
+ _context40.next = 31;
3977
+ return this.syncSelectedWalletAssets(state);
3978
+ case 31:
3979
+ return _context40.abrupt("return", this.publishWalletAssetsState(state));
3980
+ case 32:
3981
+ case "end":
3982
+ return _context40.stop();
3983
+ }
3984
+ }, _callee40, this);
3985
+ }));
3986
+ function refreshWalletAssets(_x36) {
3987
+ return _refreshWalletAssets.apply(this, arguments);
3988
+ }
3989
+ return refreshWalletAssets;
3990
+ }() /** 选择或取消单张钱包资产,并立即同步 pending wallet payments。 */)
3991
+ }, {
3992
+ key: "selectWalletAsset",
3993
+ value: (function () {
3994
+ var _selectWalletAsset = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(params) {
3995
+ var state;
3996
+ return _regeneratorRuntime().wrap(function _callee41$(_context41) {
3997
+ while (1) switch (_context41.prev = _context41.next) {
3998
+ case 0:
3999
+ if (this.store.payment) {
4000
+ _context41.next = 2;
4001
+ break;
4002
+ }
4003
+ throw new Error('payment 模块未初始化');
4004
+ case 2:
4005
+ state = this.store.payment.wallet.selectWalletAsset(params.assetId, {
4006
+ selected: params.selected,
4007
+ source: params.source
4008
+ });
4009
+ _context41.next = 5;
4010
+ return this.syncSelectedWalletAssets(state);
4011
+ case 5:
4012
+ return _context41.abrupt("return", this.publishWalletAssetsState(state));
4013
+ case 6:
4014
+ case "end":
4015
+ return _context41.stop();
4016
+ }
4017
+ }, _callee41, this);
4018
+ }));
4019
+ function selectWalletAsset(_x37) {
4020
+ return _selectWalletAsset.apply(this, arguments);
4021
+ }
4022
+ return selectWalletAsset;
4023
+ }() /** 扫码精确查券;仅可用资产会被自动选中。 */)
4024
+ }, {
4025
+ key: "scanWalletAsset",
4026
+ value: (function () {
4027
+ var _scanWalletAsset = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42(code) {
4028
+ var result;
4029
+ return _regeneratorRuntime().wrap(function _callee42$(_context42) {
4030
+ while (1) switch (_context42.prev = _context42.next) {
4031
+ case 0:
4032
+ if (this.store.payment) {
4033
+ _context42.next = 2;
4034
+ break;
4035
+ }
4036
+ throw new Error('payment 模块未初始化');
4037
+ case 2:
4038
+ _context42.next = 4;
4039
+ return this.store.payment.wallet.scanWalletAssetAsync(code);
4040
+ case 4:
4041
+ result = _context42.sent;
4042
+ if (!(result.type === 'normalCode')) {
4043
+ _context42.next = 10;
4044
+ break;
4045
+ }
4046
+ _context42.next = 8;
4047
+ return this.syncSelectedWalletAssets(result.state);
4048
+ case 8:
4049
+ _context42.next = 10;
4050
+ return this.publishWalletAssetsState(result.state);
4051
+ case 10:
4052
+ return _context42.abrupt("return", result);
4053
+ case 11:
4054
+ case "end":
4055
+ return _context42.stop();
4056
+ }
4057
+ }, _callee42, this);
4058
+ }));
4059
+ function scanWalletAsset(_x38) {
4060
+ return _scanWalletAsset.apply(this, arguments);
4061
+ }
4062
+ return scanWalletAsset;
4063
+ }() /** 清空全部未确认钱包选择,已支付钱包项由 Order 模块继续保留。 */)
4064
+ }, {
4065
+ key: "clearWalletAssetSelection",
4066
+ value: (function () {
4067
+ var _clearWalletAssetSelection = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43() {
4068
+ var state;
4069
+ return _regeneratorRuntime().wrap(function _callee43$(_context43) {
4070
+ while (1) switch (_context43.prev = _context43.next) {
4071
+ case 0:
4072
+ if (this.store.payment) {
4073
+ _context43.next = 2;
4074
+ break;
4075
+ }
4076
+ throw new Error('payment 模块未初始化');
4077
+ case 2:
4078
+ state = this.store.payment.wallet.clearWalletAssetSelection();
4079
+ _context43.next = 5;
4080
+ return this.syncSelectedWalletAssets(state);
4081
+ case 5:
4082
+ return _context43.abrupt("return", this.publishWalletAssetsState(state));
4083
+ case 6:
4084
+ case "end":
4085
+ return _context43.stop();
4086
+ }
4087
+ }, _callee43, this);
4088
+ }));
4089
+ function clearWalletAssetSelection() {
4090
+ return _clearWalletAssetSelection.apply(this, arguments);
4091
+ }
4092
+ return clearWalletAssetSelection;
4093
+ }()
3250
4094
  /**
3251
4095
  * 更新当前订单客户字段。
3252
4096
  *
3253
4097
  * 这是 PaymentModal 客户切换的订单事实入口;外部客户模块同步应由
3254
4098
  * 调用方通过 onCustomerChange 回调完成。
3255
4099
  */
4100
+ )
3256
4101
  }, {
3257
4102
  key: "updateOrderCustomer",
3258
4103
  value: function updateOrderCustomer(customer) {
@@ -3269,35 +4114,35 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3269
4114
  }, {
3270
4115
  key: "getPaymentMethodsAsync",
3271
4116
  value: (function () {
3272
- var _getPaymentMethodsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33() {
4117
+ var _getPaymentMethodsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee44() {
3273
4118
  var response, paymentMethods;
3274
- return _regeneratorRuntime().wrap(function _callee33$(_context33) {
3275
- while (1) switch (_context33.prev = _context33.next) {
4119
+ return _regeneratorRuntime().wrap(function _callee44$(_context44) {
4120
+ while (1) switch (_context44.prev = _context44.next) {
3276
4121
  case 0:
3277
- _context33.prev = 0;
3278
- _context33.next = 3;
4122
+ _context44.prev = 0;
4123
+ _context44.next = 3;
3279
4124
  return this.request.get('/pay/custom-payment/all', {
3280
4125
  filterPaymentMethods: true
3281
4126
  }, {
3282
4127
  osServer: true
3283
4128
  });
3284
4129
  case 3:
3285
- response = _context33.sent;
4130
+ response = _context44.sent;
3286
4131
  paymentMethods = (response === null || response === void 0 ? void 0 : response.data) || [];
3287
4132
  this.paymentMethodsCache = Array.isArray(paymentMethods) ? _toConsumableArray(paymentMethods) : [];
3288
- return _context33.abrupt("return", this.getPaymentMethods());
4133
+ return _context44.abrupt("return", this.getPaymentMethods());
3289
4134
  case 9:
3290
- _context33.prev = 9;
3291
- _context33.t0 = _context33["catch"](0);
4135
+ _context44.prev = 9;
4136
+ _context44.t0 = _context44["catch"](0);
3292
4137
  this.logWarning('getPaymentMethodsAsync: 获取支付方式列表失败,使用缓存列表', {
3293
- error: _context33.t0 instanceof Error ? _context33.t0.message : String(_context33.t0)
4138
+ error: _context44.t0 instanceof Error ? _context44.t0.message : String(_context44.t0)
3294
4139
  });
3295
- return _context33.abrupt("return", this.getPaymentMethods());
4140
+ return _context44.abrupt("return", this.getPaymentMethods());
3296
4141
  case 13:
3297
4142
  case "end":
3298
- return _context33.stop();
4143
+ return _context44.stop();
3299
4144
  }
3300
- }, _callee33, this, [[0, 9]]);
4145
+ }, _callee44, this, [[0, 9]]);
3301
4146
  }));
3302
4147
  function getPaymentMethodsAsync() {
3303
4148
  return _getPaymentMethodsAsync.apply(this, arguments);
@@ -3309,50 +4154,536 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3309
4154
  value: function getPaymentMethods() {
3310
4155
  return _toConsumableArray(this.paymentMethodsCache);
3311
4156
  }
4157
+ }, {
4158
+ key: "findCashPaymentMethod",
4159
+ value: function findCashPaymentMethod(paymentMethods) {
4160
+ return paymentMethods.find(function (method) {
4161
+ 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) {
4162
+ return String(value || '').toUpperCase();
4163
+ });
4164
+ return identifiers.includes('CASHMANUAL') && (method === null || method === void 0 ? void 0 : method.enabled) !== false && (method === null || method === void 0 ? void 0 : method.enable) !== false;
4165
+ });
4166
+ }
4167
+ }, {
4168
+ key: "getPendingWalletPaymentAmount",
4169
+ value: function getPendingWalletPaymentAmount() {
4170
+ var _this$store$order10, _this$store$order10$g;
4171
+ 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)) || [];
4172
+ return payments.reduce(function (total, payment) {
4173
+ 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) {
4174
+ return total;
4175
+ }
4176
+ try {
4177
+ return total.plus(payment.amount || 0).plus(payment.rounding_amount || 0);
4178
+ } catch (_unused5) {
4179
+ return total;
4180
+ }
4181
+ }, new Decimal(0));
4182
+ }
3312
4183
 
4184
+ /** 读取现金 action 所需的支付方式、待付金额和快捷金额。 */
4185
+ }, {
4186
+ key: "getCashPaymentConfig",
4187
+ value: (function () {
4188
+ var _getCashPaymentConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee45() {
4189
+ var _this$store$order11, _this$store$order11$g, _this$store$order12, _this$store$order12$g, _this$otherParams30;
4190
+ var paymentMethods, paymentMethod, amountSnapshot, pendingWalletAmount, amountDue, currency, recommendedAmounts;
4191
+ return _regeneratorRuntime().wrap(function _callee45$(_context45) {
4192
+ while (1) switch (_context45.prev = _context45.next) {
4193
+ case 0:
4194
+ if (this.store.payment) {
4195
+ _context45.next = 2;
4196
+ break;
4197
+ }
4198
+ throw new Error('payment 模块未初始化');
4199
+ case 2:
4200
+ paymentMethods = this.getPaymentMethods();
4201
+ paymentMethod = this.findCashPaymentMethod(paymentMethods);
4202
+ if (paymentMethod) {
4203
+ _context45.next = 9;
4204
+ break;
4205
+ }
4206
+ _context45.next = 7;
4207
+ return this.getPaymentMethodsAsync();
4208
+ case 7:
4209
+ paymentMethods = _context45.sent;
4210
+ paymentMethod = this.findCashPaymentMethod(paymentMethods);
4211
+ case 9:
4212
+ 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);
4213
+ pendingWalletAmount = this.getPendingWalletPaymentAmount();
4214
+ amountDue = Decimal.max(new Decimal((amountSnapshot === null || amountSnapshot === void 0 ? void 0 : amountSnapshot.amountGap) || 0).minus(pendingWalletAmount), 0).toDecimalPlaces(2).toNumber();
4215
+ 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$otherParams30 = this.otherParams) === null || _this$otherParams30 === void 0 ? void 0 : _this$otherParams30.currency) || 'USD';
4216
+ recommendedAmounts = amountDue > 0 ? this.store.payment.cash.getRecommendedAmount(amountDue, currency) : [];
4217
+ return _context45.abrupt("return", {
4218
+ available: Boolean(paymentMethod && amountDue > 0),
4219
+ paymentMethod: paymentMethod,
4220
+ amountDue: amountDue,
4221
+ recommendedAmounts: recommendedAmounts
4222
+ });
4223
+ case 15:
4224
+ case "end":
4225
+ return _context45.stop();
4226
+ }
4227
+ }, _callee45, this);
4228
+ }));
4229
+ function getCashPaymentConfig() {
4230
+ return _getCashPaymentConfig.apply(this, arguments);
4231
+ }
4232
+ return getCashPaymentConfig;
4233
+ }()
4234
+ /**
4235
+ * 确认足额覆盖订单的 pending Wallet 支付并提交订单。
4236
+ *
4237
+ * Order 模块在构造提交参数时将 pending voucher 转为 paid;只有提交成功后
4238
+ * 才同步 Wallet committed 状态。失败时恢复调用前 payments,允许用户重试。
4239
+ */
4240
+ )
4241
+ }, {
4242
+ key: "confirmWalletPayment",
4243
+ value: (function () {
4244
+ var _confirmWalletPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee46() {
4245
+ var _this$store$order$get3, _this$store$order13, _this$store$order$get4, _this$store$order$get5, _this$store$order14;
4246
+ var beforePayments, pendingWalletAmount, amountSnapshot, effectiveAmountDue, beforePaymentStatus, submitResult, restoredTempOrder, committed, walletState, latestAmountSnapshot;
4247
+ return _regeneratorRuntime().wrap(function _callee46$(_context46) {
4248
+ while (1) switch (_context46.prev = _context46.next) {
4249
+ case 0:
4250
+ if (this.store.order) {
4251
+ _context46.next = 2;
4252
+ break;
4253
+ }
4254
+ throw new Error('order 模块未初始化');
4255
+ case 2:
4256
+ beforePayments = cloneDeep(this.store.order.getOrderPayments());
4257
+ pendingWalletAmount = this.getPendingWalletPaymentAmount(beforePayments);
4258
+ if (!pendingWalletAmount.lte(0)) {
4259
+ _context46.next = 6;
4260
+ break;
4261
+ }
4262
+ throw new Error('当前订单没有待确认的 Wallet 支付');
4263
+ case 6:
4264
+ 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);
4265
+ effectiveAmountDue = Decimal.max(new Decimal((amountSnapshot === null || amountSnapshot === void 0 ? void 0 : amountSnapshot.amountGap) || 0).minus(pendingWalletAmount), 0);
4266
+ if (!effectiveAmountDue.gt(0.01)) {
4267
+ _context46.next = 10;
4268
+ break;
4269
+ }
4270
+ throw new Error('Wallet 支付尚未覆盖全部待支付金额');
4271
+ case 10:
4272
+ beforePaymentStatus = (_this$store$order$get4 = this.store.order.getTempOrder()) === null || _this$store$order$get4 === void 0 ? void 0 : _this$store$order$get4.payment_status;
4273
+ _context46.prev = 11;
4274
+ _context46.next = 14;
4275
+ return this.submitSalesOrder({
4276
+ smallTicketDataFlag: 1,
4277
+ confirmPendingVoucherPayments: true
4278
+ });
4279
+ case 14:
4280
+ submitResult = _context46.sent;
4281
+ if (!isRejectedSalesSubmitResult(submitResult)) {
4282
+ _context46.next = 17;
4283
+ break;
4284
+ }
4285
+ throw new Error(getSalesSubmitErrorMessage(submitResult));
4286
+ case 17:
4287
+ _context46.next = 27;
4288
+ break;
4289
+ case 19:
4290
+ _context46.prev = 19;
4291
+ _context46.t0 = _context46["catch"](11);
4292
+ this.store.order.setOrderPayments(beforePayments);
4293
+ restoredTempOrder = this.store.order.getTempOrder();
4294
+ if (restoredTempOrder && beforePaymentStatus !== undefined) {
4295
+ restoredTempOrder.payment_status = beforePaymentStatus;
4296
+ this.store.order.persistTempOrder();
4297
+ }
4298
+ _context46.next = 26;
4299
+ return this.store.order.recalculateSummary({
4300
+ createIfMissing: true
4301
+ });
4302
+ case 26:
4303
+ throw _context46.t0;
4304
+ case 27:
4305
+ if (!this.store.payment) {
4306
+ _context46.next = 38;
4307
+ break;
4308
+ }
4309
+ _context46.prev = 28;
4310
+ committed = this.getCommittedWalletAssets();
4311
+ walletState = this.store.payment.wallet.setCommittedWalletAssets(committed.ids, committed.assets);
4312
+ _context46.next = 33;
4313
+ return this.publishWalletAssetsState(walletState);
4314
+ case 33:
4315
+ _context46.next = 38;
4316
+ break;
4317
+ case 35:
4318
+ _context46.prev = 35;
4319
+ _context46.t1 = _context46["catch"](28);
4320
+ this.logWarning('confirmWalletPayment: Wallet committed 状态同步失败', {
4321
+ error: _context46.t1 instanceof Error ? _context46.t1.message : String(_context46.t1)
4322
+ });
4323
+ case 38:
4324
+ 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);
4325
+ return _context46.abrupt("return", {
4326
+ submitResult: submitResult,
4327
+ payments: this.store.order.getOrderPayments(),
4328
+ isOrderFullyPaid: new Decimal((latestAmountSnapshot === null || latestAmountSnapshot === void 0 ? void 0 : latestAmountSnapshot.amountGap) || 0).lte(0)
4329
+ });
4330
+ case 40:
4331
+ case "end":
4332
+ return _context46.stop();
4333
+ }
4334
+ }, _callee46, this, [[11, 19], [28, 35]]);
4335
+ }));
4336
+ function confirmWalletPayment() {
4337
+ return _confirmWalletPayment.apply(this, arguments);
4338
+ }
4339
+ return confirmWalletPayment;
4340
+ }()
4341
+ /**
4342
+ * 购物车现金直付:写入现金记录并等待支付同步完成。
4343
+ * 同步失败会恢复调用前 payments(包含 Wallet pending 状态)。
4344
+ */
4345
+ )
4346
+ }, {
4347
+ key: "payCash",
4348
+ value: (function () {
4349
+ var _payCash = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee47(params) {
4350
+ var _this$store$order$get6, _params$actualPaidAmo, _this$otherParams31, _this$window, _this$window$postMess;
4351
+ var amount, config, paymentMethod, roundingAmount, effectivePaymentAmount, beforePayments, beforePaymentStatus, uniquePaymentNumber, paymentTimestamp, actualPaidAmount, changeAmount, shopWalletPassId, payments, payment, syncResult, committed, walletState, restoredTempOrder;
4352
+ return _regeneratorRuntime().wrap(function _callee47$(_context47) {
4353
+ while (1) switch (_context47.prev = _context47.next) {
4354
+ case 0:
4355
+ if (this.store.order) {
4356
+ _context47.next = 2;
4357
+ break;
4358
+ }
4359
+ throw new Error('order 模块未初始化');
4360
+ case 2:
4361
+ amount = Number(params.amount || 0);
4362
+ if (!(!Number.isFinite(amount) || amount <= 0)) {
4363
+ _context47.next = 5;
4364
+ break;
4365
+ }
4366
+ throw new Error('现金支付金额必须大于 0');
4367
+ case 5:
4368
+ _context47.next = 7;
4369
+ return this.getCashPaymentConfig();
4370
+ case 7:
4371
+ config = _context47.sent;
4372
+ paymentMethod = config.paymentMethod;
4373
+ if (paymentMethod) {
4374
+ _context47.next = 11;
4375
+ break;
4376
+ }
4377
+ throw new Error('未找到可用的 CASHMANUAL 支付方式');
4378
+ case 11:
4379
+ if (!(config.amountDue <= 0)) {
4380
+ _context47.next = 13;
4381
+ break;
4382
+ }
4383
+ throw new Error('当前订单没有待支付金额');
4384
+ case 13:
4385
+ roundingAmount = Number(params.roundingAmount || 0);
4386
+ effectivePaymentAmount = new Decimal(amount).minus(roundingAmount);
4387
+ if (!effectivePaymentAmount.gt(new Decimal(config.amountDue).plus(0.01))) {
4388
+ _context47.next = 17;
4389
+ break;
4390
+ }
4391
+ throw new Error('现金支付金额超过当前待支付金额');
4392
+ case 17:
4393
+ beforePayments = cloneDeep(this.store.order.getOrderPayments());
4394
+ beforePaymentStatus = (_this$store$order$get6 = this.store.order.getTempOrder()) === null || _this$store$order$get6 === void 0 ? void 0 : _this$store$order$get6.payment_status;
4395
+ uniquePaymentNumber = createUuidV4();
4396
+ paymentTimestamp = dayjs().format('YYYY-MM-DD HH:mm:ss');
4397
+ actualPaidAmount = Number((_params$actualPaidAmo = params.actualPaidAmount) !== null && _params$actualPaidAmo !== void 0 ? _params$actualPaidAmo : amount);
4398
+ changeAmount = Number(params.changeAmount || 0);
4399
+ shopWalletPassId = (_this$otherParams31 = this.otherParams) === null || _this$otherParams31 === void 0 ? void 0 : _this$otherParams31.shop_wallet_pass_id;
4400
+ if (!(!Number.isFinite(actualPaidAmount) || actualPaidAmount + 0.01 < amount)) {
4401
+ _context47.next = 26;
4402
+ break;
4403
+ }
4404
+ throw new Error('顾客实收现金不能小于支付金额');
4405
+ case 26:
4406
+ (_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, {
4407
+ module: 'till',
4408
+ key: 'open_till',
4409
+ data: {
4410
+ type: 'cash'
4411
+ }
4412
+ });
4413
+ payments = this.store.order.addOrderPayment({
4414
+ amount: amount.toFixed(2),
4415
+ code: paymentMethod.code,
4416
+ custom_payment_id: paymentMethod.id,
4417
+ name: paymentMethod.name,
4418
+ custom_payment_type: paymentMethod.type,
4419
+ voucher_id: 0,
4420
+ rounding_amount: roundingAmount.toFixed(2),
4421
+ metadata: _objectSpread(_objectSpread({
4422
+ unique_payment_number: uniquePaymentNumber
4423
+ }, shopWalletPassId !== undefined && shopWalletPassId !== null ? {
4424
+ shop_wallet_pass_id: shopWalletPassId
4425
+ } : {}), {}, {
4426
+ actual_paid_amount: Number.isFinite(actualPaidAmount) ? actualPaidAmount : amount,
4427
+ change_given_amount: Number.isFinite(changeAmount) ? changeAmount : 0
4428
+ }),
4429
+ payment_time: paymentTimestamp,
4430
+ created_at: paymentTimestamp
4431
+ });
4432
+ payment = payments.find(function (item) {
4433
+ var _item$metadata2;
4434
+ return (item === null || item === void 0 || (_item$metadata2 = item.metadata) === null || _item$metadata2 === void 0 ? void 0 : _item$metadata2.unique_payment_number) === uniquePaymentNumber;
4435
+ });
4436
+ _context47.prev = 29;
4437
+ _context47.next = 32;
4438
+ return this.syncPaymentsToOrder({
4439
+ payments: payments,
4440
+ submitWhenPaid: true,
4441
+ smallTicketDataFlag: 1,
4442
+ confirmPendingVoucherPayments: true
4443
+ });
4444
+ case 32:
4445
+ syncResult = _context47.sent;
4446
+ if (!this.store.payment) {
4447
+ _context47.next = 38;
4448
+ break;
4449
+ }
4450
+ committed = this.getCommittedWalletAssets();
4451
+ walletState = this.store.payment.wallet.setCommittedWalletAssets(committed.ids, committed.assets);
4452
+ _context47.next = 38;
4453
+ return this.publishWalletAssetsState(walletState);
4454
+ case 38:
4455
+ return _context47.abrupt("return", {
4456
+ payment: payment || {},
4457
+ payments: this.store.order.getOrderPayments(),
4458
+ syncResult: syncResult,
4459
+ isOrderFullyPaid: syncResult.isOrderFullyPaid
4460
+ });
4461
+ case 41:
4462
+ _context47.prev = 41;
4463
+ _context47.t0 = _context47["catch"](29);
4464
+ this.store.order.setOrderPayments(beforePayments);
4465
+ restoredTempOrder = this.store.order.getTempOrder();
4466
+ if (restoredTempOrder && beforePaymentStatus !== undefined) {
4467
+ restoredTempOrder.payment_status = beforePaymentStatus;
4468
+ this.store.order.persistTempOrder();
4469
+ }
4470
+ _context47.next = 48;
4471
+ return this.store.order.recalculateSummary({
4472
+ createIfMissing: true
4473
+ });
4474
+ case 48:
4475
+ throw _context47.t0;
4476
+ case 49:
4477
+ case "end":
4478
+ return _context47.stop();
4479
+ }
4480
+ }, _callee47, this, [[29, 41]]);
4481
+ }));
4482
+ function payCash(_x39) {
4483
+ return _payCash.apply(this, arguments);
4484
+ }
4485
+ return payCash;
4486
+ }()
4487
+ /**
4488
+ * 提交一次已由支付设备确认成功的非 Wallet 支付。
4489
+ *
4490
+ * 与 addOrderPayment 不同,本入口不会启动后台 fire-and-forget 同步;调用方会等待
4491
+ * 本次 payment、当前 pending Wallet 以及订单提交共同完成。任何同步失败都会恢复
4492
+ * 调用前的 payments 与 payment_status,便于 UI 安全解锁并重试。
4493
+ */
4494
+ )
4495
+ }, {
4496
+ key: "commitPaymentMethodPayment",
4497
+ value: (function () {
4498
+ var _commitPaymentMethodPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee48(params) {
4499
+ var _this$store$order$get7, _this$store$order15, _this$store$order$get8, _params$metadata, _params$originAmount;
4500
+ var amount, paymentMethods, findPaymentMethod, paymentMethod, amountSnapshot, pendingWalletAmount, amountDue, beforePayments, beforePaymentStatus, paymentTimestamp, metadata, serviceCharge, serviceFee, payments, payment, syncResult, committed, walletState, restoredTempOrder;
4501
+ return _regeneratorRuntime().wrap(function _callee48$(_context48) {
4502
+ while (1) switch (_context48.prev = _context48.next) {
4503
+ case 0:
4504
+ if (this.store.order) {
4505
+ _context48.next = 2;
4506
+ break;
4507
+ }
4508
+ throw new Error('order 模块未初始化');
4509
+ case 2:
4510
+ amount = Number(params.amount || 0);
4511
+ if (!(!Number.isFinite(amount) || amount <= 0)) {
4512
+ _context48.next = 5;
4513
+ break;
4514
+ }
4515
+ throw new Error('支付金额必须大于 0');
4516
+ case 5:
4517
+ paymentMethods = this.getPaymentMethods();
4518
+ findPaymentMethod = function findPaymentMethod() {
4519
+ var methodCode = String(params.paymentMethodCode || '').toUpperCase();
4520
+ return paymentMethods.find(function (method) {
4521
+ var idMatched = params.paymentMethodId !== undefined && String(method.id) === String(params.paymentMethodId);
4522
+ var codeMatched = Boolean(methodCode) && String(method.code || '').toUpperCase() === methodCode;
4523
+ return (idMatched || codeMatched) && method.enabled !== false && method.enable !== false;
4524
+ });
4525
+ };
4526
+ paymentMethod = findPaymentMethod();
4527
+ if (paymentMethod) {
4528
+ _context48.next = 13;
4529
+ break;
4530
+ }
4531
+ _context48.next = 11;
4532
+ return this.getPaymentMethodsAsync();
4533
+ case 11:
4534
+ paymentMethods = _context48.sent;
4535
+ paymentMethod = findPaymentMethod();
4536
+ case 13:
4537
+ if (paymentMethod) {
4538
+ _context48.next = 15;
4539
+ break;
4540
+ }
4541
+ throw new Error("\u672A\u627E\u5230\u53EF\u7528\u7684\u652F\u4ED8\u65B9\u5F0F\uFF1A".concat(params.paymentMethodCode || params.paymentMethodId || ''));
4542
+ case 15:
4543
+ 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);
4544
+ pendingWalletAmount = this.getPendingWalletPaymentAmount();
4545
+ amountDue = Decimal.max(new Decimal((amountSnapshot === null || amountSnapshot === void 0 ? void 0 : amountSnapshot.amountGap) || 0).minus(pendingWalletAmount), 0);
4546
+ if (!amountDue.lte(0)) {
4547
+ _context48.next = 20;
4548
+ break;
4549
+ }
4550
+ throw new Error('当前订单没有待支付金额');
4551
+ case 20:
4552
+ if (!new Decimal(amount).gt(amountDue.plus(0.01))) {
4553
+ _context48.next = 22;
4554
+ break;
4555
+ }
4556
+ throw new Error('支付金额超过当前待支付金额');
4557
+ case 22:
4558
+ beforePayments = cloneDeep(this.store.order.getOrderPayments());
4559
+ beforePaymentStatus = (_this$store$order$get8 = this.store.order.getTempOrder()) === null || _this$store$order$get8 === void 0 ? void 0 : _this$store$order$get8.payment_status;
4560
+ paymentTimestamp = dayjs().format('YYYY-MM-DD HH:mm:ss');
4561
+ metadata = _objectSpread(_objectSpread({}, params.metadata || {}), {}, {
4562
+ unique_payment_number: ((_params$metadata = params.metadata) === null || _params$metadata === void 0 ? void 0 : _params$metadata.unique_payment_number) || createUuidV4()
4563
+ });
4564
+ serviceCharge = params.serviceCharge ? {
4565
+ amount: String(params.serviceCharge.amount || 0),
4566
+ percentage: String(params.serviceCharge.percentage || 0)
4567
+ } : undefined;
4568
+ 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;
4569
+ payments = this.store.order.addOrderPayment(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, params.paymentData || {}), {}, {
4570
+ amount: amount.toFixed(2)
4571
+ }, params.originAmount !== undefined ? {
4572
+ origin_amount: Number(params.originAmount).toFixed(2)
4573
+ } : {}), {}, {
4574
+ code: paymentMethod.code,
4575
+ custom_payment_id: paymentMethod.id,
4576
+ name: paymentMethod.name,
4577
+ custom_payment_type: paymentMethod.type,
4578
+ voucher_id: 0
4579
+ }, serviceCharge ? {
4580
+ service_charge: serviceCharge
4581
+ } : {}), serviceFee !== undefined ? {
4582
+ service_fee: serviceFee
4583
+ } : {}), {}, {
4584
+ metadata: metadata,
4585
+ payment_time: paymentTimestamp,
4586
+ created_at: paymentTimestamp
4587
+ }));
4588
+ payment = payments.find(function (item) {
4589
+ var _item$metadata3;
4590
+ 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;
4591
+ });
4592
+ _context48.prev = 30;
4593
+ _context48.next = 33;
4594
+ return this.syncPaymentsToOrder({
4595
+ payments: payments,
4596
+ submitWhenPaid: true,
4597
+ smallTicketDataFlag: 1,
4598
+ confirmPendingVoucherPayments: true
4599
+ });
4600
+ case 33:
4601
+ syncResult = _context48.sent;
4602
+ if (!this.store.payment) {
4603
+ _context48.next = 39;
4604
+ break;
4605
+ }
4606
+ committed = this.getCommittedWalletAssets();
4607
+ walletState = this.store.payment.wallet.setCommittedWalletAssets(committed.ids, committed.assets);
4608
+ _context48.next = 39;
4609
+ return this.publishWalletAssetsState(walletState);
4610
+ case 39:
4611
+ return _context48.abrupt("return", {
4612
+ payment: payment || {},
4613
+ payments: this.store.order.getOrderPayments(),
4614
+ syncResult: syncResult,
4615
+ isOrderFullyPaid: syncResult.isOrderFullyPaid
4616
+ });
4617
+ case 42:
4618
+ _context48.prev = 42;
4619
+ _context48.t0 = _context48["catch"](30);
4620
+ this.store.order.setOrderPayments(beforePayments);
4621
+ restoredTempOrder = this.store.order.getTempOrder();
4622
+ if (restoredTempOrder && beforePaymentStatus !== undefined) {
4623
+ restoredTempOrder.payment_status = beforePaymentStatus;
4624
+ this.store.order.persistTempOrder();
4625
+ }
4626
+ _context48.next = 49;
4627
+ return this.store.order.recalculateSummary({
4628
+ createIfMissing: true
4629
+ });
4630
+ case 49:
4631
+ throw _context48.t0;
4632
+ case 50:
4633
+ case "end":
4634
+ return _context48.stop();
4635
+ }
4636
+ }, _callee48, this, [[30, 42]]);
4637
+ }));
4638
+ function commitPaymentMethodPayment(_x40) {
4639
+ return _commitPaymentMethodPayment.apply(this, arguments);
4640
+ }
4641
+ return commitPaymentMethodPayment;
4642
+ }()
3313
4643
  /**
3314
4644
  * 按当前店铺的现金舍入配置计算金额,供现金支付 UI 使用。
3315
4645
  *
3316
4646
  * 舍入开关取自 CASHMANUAL 支付方式;舍入规则取自
3317
4647
  * otherParams.order_rounding_setting,金额算法统一由 PaymentModule 维护。
3318
4648
  */
4649
+ )
3319
4650
  }, {
3320
4651
  key: "roundAmount",
3321
4652
  value: (function () {
3322
- var _roundAmount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(params) {
4653
+ var _roundAmount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee49(params) {
3323
4654
  var _cashManualPayment$me, _this$otherParams$ord2, _this$otherParams$ord3;
3324
4655
  var amount, cashManualPayment;
3325
- return _regeneratorRuntime().wrap(function _callee34$(_context34) {
3326
- while (1) switch (_context34.prev = _context34.next) {
4656
+ return _regeneratorRuntime().wrap(function _callee49$(_context49) {
4657
+ while (1) switch (_context49.prev = _context49.next) {
3327
4658
  case 0:
3328
4659
  amount = params.amount;
3329
4660
  cashManualPayment = this.paymentMethodsCache.find(function (paymentMethod) {
3330
4661
  return paymentMethod.code === 'CASHMANUAL';
3331
4662
  });
3332
4663
  if (cashManualPayment !== null && cashManualPayment !== void 0 && (_cashManualPayment$me = cashManualPayment.metadata) !== null && _cashManualPayment$me !== void 0 && _cashManualPayment$me.order_rounding_switch) {
3333
- _context34.next = 4;
4664
+ _context49.next = 4;
3334
4665
  break;
3335
4666
  }
3336
- return _context34.abrupt("return", {
4667
+ return _context49.abrupt("return", {
3337
4668
  originalAmount: amount.toString(),
3338
4669
  roundedAmount: amount.toString(),
3339
4670
  roundingDifference: '0.00'
3340
4671
  });
3341
4672
  case 4:
3342
4673
  if (this.payment) {
3343
- _context34.next = 6;
4674
+ _context49.next = 6;
3344
4675
  break;
3345
4676
  }
3346
4677
  throw new Error('payment 模块未初始化');
3347
4678
  case 6:
3348
- return _context34.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));
4679
+ 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));
3349
4680
  case 7:
3350
4681
  case "end":
3351
- return _context34.stop();
4682
+ return _context49.stop();
3352
4683
  }
3353
- }, _callee34, this);
4684
+ }, _callee49, this);
3354
4685
  }));
3355
- function roundAmount(_x27) {
4686
+ function roundAmount(_x41) {
3356
4687
  return _roundAmount.apply(this, arguments);
3357
4688
  }
3358
4689
  return roundAmount;
@@ -3367,49 +4698,49 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3367
4698
  }, {
3368
4699
  key: "sendCustomerPayLink",
3369
4700
  value: (function () {
3370
- var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(params) {
3371
- var orderIds, _ref28, _ref29, _submitResult$data$or, _submitResult$data, _submitResult$data2, submitResult, orderId;
3372
- return _regeneratorRuntime().wrap(function _callee35$(_context35) {
3373
- while (1) switch (_context35.prev = _context35.next) {
4701
+ var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee50(params) {
4702
+ var orderIds, _ref37, _ref38, _submitResult$data$or, _submitResult$data, _submitResult$data2, submitResult, orderId;
4703
+ return _regeneratorRuntime().wrap(function _callee50$(_context50) {
4704
+ while (1) switch (_context50.prev = _context50.next) {
3374
4705
  case 0:
3375
4706
  if (this.store.order) {
3376
- _context35.next = 2;
4707
+ _context50.next = 2;
3377
4708
  break;
3378
4709
  }
3379
4710
  throw new Error('order 模块未初始化');
3380
4711
  case 2:
3381
4712
  orderIds = params.order_ids || params.orderIds || [];
3382
4713
  if (!(!orderIds.length || params.submitBeforeSend)) {
3383
- _context35.next = 11;
4714
+ _context50.next = 11;
3384
4715
  break;
3385
4716
  }
3386
- _context35.next = 6;
4717
+ _context50.next = 6;
3387
4718
  return this.submitSalesOrder({
3388
4719
  smallTicketDataFlag: 1
3389
4720
  });
3390
4721
  case 6:
3391
- submitResult = _context35.sent;
3392
- orderId = (_ref28 = (_ref29 = (_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 && _ref29 !== void 0 ? _ref29 : submitResult === null || submitResult === void 0 || (_submitResult$data2 = submitResult.data) === null || _submitResult$data2 === void 0 ? void 0 : _submitResult$data2.id) !== null && _ref28 !== void 0 ? _ref28 : submitResult === null || submitResult === void 0 ? void 0 : submitResult.id;
4722
+ submitResult = _context50.sent;
4723
+ orderId = (_ref37 = (_ref38 = (_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 && _ref38 !== void 0 ? _ref38 : submitResult === null || submitResult === void 0 || (_submitResult$data2 = submitResult.data) === null || _submitResult$data2 === void 0 ? void 0 : _submitResult$data2.id) !== null && _ref37 !== void 0 ? _ref37 : submitResult === null || submitResult === void 0 ? void 0 : submitResult.id;
3393
4724
  if (orderId) {
3394
- _context35.next = 10;
4725
+ _context50.next = 10;
3395
4726
  break;
3396
4727
  }
3397
4728
  throw new Error('本地订单提交云端失败,无法发送支付链接');
3398
4729
  case 10:
3399
4730
  orderIds = [orderId];
3400
4731
  case 11:
3401
- return _context35.abrupt("return", this.store.order.sendCustomerPayLink({
4732
+ return _context50.abrupt("return", this.store.order.sendCustomerPayLink({
3402
4733
  emails: params.emails,
3403
4734
  notify_action: params.notify_action,
3404
4735
  order_ids: orderIds
3405
4736
  }));
3406
4737
  case 12:
3407
4738
  case "end":
3408
- return _context35.stop();
4739
+ return _context50.stop();
3409
4740
  }
3410
- }, _callee35, this);
4741
+ }, _callee50, this);
3411
4742
  }));
3412
- function sendCustomerPayLink(_x28) {
4743
+ function sendCustomerPayLink(_x42) {
3413
4744
  return _sendCustomerPayLink.apply(this, arguments);
3414
4745
  }
3415
4746
  return sendCustomerPayLink;
@@ -3422,27 +4753,27 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3422
4753
  }, {
3423
4754
  key: "calculateProductBookingPrice",
3424
4755
  value: function () {
3425
- var _calculateProductBookingPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(params) {
4756
+ var _calculateProductBookingPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee51(params) {
3426
4757
  var _params$customer_id;
3427
4758
  var quotation, customerId, authoritativeProduct, product;
3428
- return _regeneratorRuntime().wrap(function _callee36$(_context36) {
3429
- while (1) switch (_context36.prev = _context36.next) {
4759
+ return _regeneratorRuntime().wrap(function _callee51$(_context51) {
4760
+ while (1) switch (_context51.prev = _context51.next) {
3430
4761
  case 0:
3431
4762
  quotation = this.store.quotation;
3432
4763
  customerId = (_params$customer_id = params.customer_id) !== null && _params$customer_id !== void 0 ? _params$customer_id : this.getCurrentOrderCustomerId();
3433
- _context36.next = 4;
4764
+ _context51.next = 4;
3434
4765
  return this.loadProductForPriceQuery(params, customerId);
3435
4766
  case 4:
3436
- authoritativeProduct = _context36.sent;
4767
+ authoritativeProduct = _context51.sent;
3437
4768
  product = this.mergeProductForPriceQuery(params.product, authoritativeProduct);
3438
- _context36.next = 8;
4769
+ _context51.next = 8;
3439
4770
  return this.loadQuotationForPriceQuery({
3440
4771
  quotation: quotation,
3441
4772
  customer_id: customerId,
3442
4773
  channel: params.channel
3443
4774
  });
3444
4775
  case 8:
3445
- return _context36.abrupt("return", calculateBaseSalesProductBookingPrice(_objectSpread(_objectSpread({}, params), {}, {
4776
+ return _context51.abrupt("return", calculateBaseSalesProductBookingPrice(_objectSpread(_objectSpread({}, params), {}, {
3446
4777
  product: product,
3447
4778
  fallback_price: authoritativeProduct ? undefined : params.fallback_price,
3448
4779
  customer_id: customerId,
@@ -3450,11 +4781,11 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3450
4781
  })));
3451
4782
  case 9:
3452
4783
  case "end":
3453
- return _context36.stop();
4784
+ return _context51.stop();
3454
4785
  }
3455
- }, _callee36, this);
4786
+ }, _callee51, this);
3456
4787
  }));
3457
- function calculateProductBookingPrice(_x29) {
4788
+ function calculateProductBookingPrice(_x43) {
3458
4789
  return _calculateProductBookingPrice.apply(this, arguments);
3459
4790
  }
3460
4791
  return calculateProductBookingPrice;
@@ -3462,7 +4793,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3462
4793
  }, {
3463
4794
  key: "getQuotationCustomerScopeInfo",
3464
4795
  value: function getQuotationCustomerScopeInfo() {
3465
- var _this13 = this;
4796
+ var _this15 = this;
3466
4797
  var quotation = this.store.quotation;
3467
4798
  if (quotation && typeof quotation.getQuotationCustomerScopeInfo === 'function') {
3468
4799
  return quotation.getQuotationCustomerScopeInfo();
@@ -3474,7 +4805,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3474
4805
  }).map(function (item) {
3475
4806
  var localSeen = new Set();
3476
4807
  var customers = item.customer.filter(function (customer) {
3477
- var customerId = _this13.normalizePriceContextCustomerId(customer === null || customer === void 0 ? void 0 : customer.id);
4808
+ var customerId = _this15.normalizePriceContextCustomerId(customer === null || customer === void 0 ? void 0 : customer.id);
3478
4809
  if (!customerId || localSeen.has(customerId)) return false;
3479
4810
  localSeen.add(customerId);
3480
4811
  if (!customerById.has(customerId)) customerById.set(customerId, customer);
@@ -3524,32 +4855,32 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3524
4855
  }, {
3525
4856
  key: "calculateProductBookingPrices",
3526
4857
  value: function () {
3527
- var _calculateProductBookingPrices = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(paramsList) {
4858
+ var _calculateProductBookingPrices = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee53(paramsList) {
3528
4859
  var _paramsList$0$custome,
3529
4860
  _paramsList$,
3530
- _this14 = this,
4861
+ _this16 = this,
3531
4862
  _paramsList$2;
3532
4863
  var quotation, customerId, productMapsByGroup, groups;
3533
- return _regeneratorRuntime().wrap(function _callee38$(_context38) {
3534
- while (1) switch (_context38.prev = _context38.next) {
4864
+ return _regeneratorRuntime().wrap(function _callee53$(_context53) {
4865
+ while (1) switch (_context53.prev = _context53.next) {
3535
4866
  case 0:
3536
4867
  if (paramsList.length) {
3537
- _context38.next = 2;
4868
+ _context53.next = 2;
3538
4869
  break;
3539
4870
  }
3540
- return _context38.abrupt("return", []);
4871
+ return _context53.abrupt("return", []);
3541
4872
  case 2:
3542
4873
  quotation = this.store.quotation;
3543
4874
  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();
3544
4875
  productMapsByGroup = new Map();
3545
4876
  groups = new Map();
3546
4877
  paramsList.forEach(function (params) {
3547
- var _this14$otherParams;
4878
+ var _this16$otherParams;
3548
4879
  var product = params.product || {};
3549
- var productId = _this14.getPriceQueryProductId(product);
4880
+ var productId = _this16.getPriceQueryProductId(product);
3550
4881
  if (productId === null) return;
3551
- var schedule = _this14.getPriceQuerySchedule(params);
3552
- var channel = params.channel || ((_this14$otherParams = _this14.otherParams) === null || _this14$otherParams === void 0 ? void 0 : _this14$otherParams.channel);
4882
+ var schedule = _this16.getPriceQuerySchedule(params);
4883
+ var channel = params.channel || ((_this16$otherParams = _this16.otherParams) === null || _this16$otherParams === void 0 ? void 0 : _this16$otherParams.channel);
3553
4884
  var groupKey = [schedule.schedule_date, schedule.schedule_datetime, channel || ''].join('|');
3554
4885
  var group = groups.get(groupKey) || {
3555
4886
  ids: new Set(),
@@ -3559,51 +4890,51 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3559
4890
  group.ids.add(productId);
3560
4891
  groups.set(groupKey, group);
3561
4892
  });
3562
- _context38.next = 9;
4893
+ _context53.next = 9;
3563
4894
  return Promise.all(Array.from(groups.entries()).map( /*#__PURE__*/function () {
3564
- var _ref31 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(_ref30) {
3565
- var _ref32, groupKey, group, productsById;
3566
- return _regeneratorRuntime().wrap(function _callee37$(_context37) {
3567
- while (1) switch (_context37.prev = _context37.next) {
4895
+ var _ref40 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee52(_ref39) {
4896
+ var _ref41, groupKey, group, productsById;
4897
+ return _regeneratorRuntime().wrap(function _callee52$(_context52) {
4898
+ while (1) switch (_context52.prev = _context52.next) {
3568
4899
  case 0:
3569
- _ref32 = _slicedToArray(_ref30, 2), groupKey = _ref32[0], group = _ref32[1];
3570
- _context37.next = 3;
3571
- return _this14.loadProductsForPriceQuery({
4900
+ _ref41 = _slicedToArray(_ref39, 2), groupKey = _ref41[0], group = _ref41[1];
4901
+ _context52.next = 3;
4902
+ return _this16.loadProductsForPriceQuery({
3572
4903
  ids: Array.from(group.ids),
3573
4904
  schedule: group.schedule,
3574
4905
  customerId: customerId,
3575
4906
  channel: group.channel
3576
4907
  });
3577
4908
  case 3:
3578
- productsById = _context37.sent;
4909
+ productsById = _context52.sent;
3579
4910
  productMapsByGroup.set(groupKey, productsById);
3580
4911
  case 5:
3581
4912
  case "end":
3582
- return _context37.stop();
4913
+ return _context52.stop();
3583
4914
  }
3584
- }, _callee37);
4915
+ }, _callee52);
3585
4916
  }));
3586
- return function (_x31) {
3587
- return _ref31.apply(this, arguments);
4917
+ return function (_x45) {
4918
+ return _ref40.apply(this, arguments);
3588
4919
  };
3589
4920
  }()));
3590
4921
  case 9:
3591
- _context38.next = 11;
4922
+ _context53.next = 11;
3592
4923
  return this.loadQuotationForPriceQuery({
3593
4924
  quotation: quotation,
3594
4925
  customer_id: customerId,
3595
4926
  channel: (_paramsList$2 = paramsList[0]) === null || _paramsList$2 === void 0 ? void 0 : _paramsList$2.channel
3596
4927
  });
3597
4928
  case 11:
3598
- return _context38.abrupt("return", paramsList.map(function (params) {
3599
- var _this14$otherParams2, _productMapsByGroup$g;
4929
+ return _context53.abrupt("return", paramsList.map(function (params) {
4930
+ var _this16$otherParams2, _productMapsByGroup$g;
3600
4931
  var productInput = params.product || {};
3601
- var productId = _this14.getPriceQueryProductId(productInput);
3602
- var schedule = _this14.getPriceQuerySchedule(params);
3603
- var channel = params.channel || ((_this14$otherParams2 = _this14.otherParams) === null || _this14$otherParams2 === void 0 ? void 0 : _this14$otherParams2.channel);
4932
+ var productId = _this16.getPriceQueryProductId(productInput);
4933
+ var schedule = _this16.getPriceQuerySchedule(params);
4934
+ var channel = params.channel || ((_this16$otherParams2 = _this16.otherParams) === null || _this16$otherParams2 === void 0 ? void 0 : _this16$otherParams2.channel);
3604
4935
  var groupKey = [schedule.schedule_date, schedule.schedule_datetime, channel || ''].join('|');
3605
4936
  var authoritativeProduct = productId === null ? null : ((_productMapsByGroup$g = productMapsByGroup.get(groupKey)) === null || _productMapsByGroup$g === void 0 ? void 0 : _productMapsByGroup$g.get(productId)) || null;
3606
- var product = _this14.mergeProductForPriceQuery(productInput, authoritativeProduct);
4937
+ var product = _this16.mergeProductForPriceQuery(productInput, authoritativeProduct);
3607
4938
  return calculateBaseSalesProductBookingPrice(_objectSpread(_objectSpread({}, params), {}, {
3608
4939
  product: product,
3609
4940
  fallback_price: authoritativeProduct ? undefined : params.fallback_price,
@@ -3613,11 +4944,11 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3613
4944
  }));
3614
4945
  case 12:
3615
4946
  case "end":
3616
- return _context38.stop();
4947
+ return _context53.stop();
3617
4948
  }
3618
- }, _callee38, this);
4949
+ }, _callee53, this);
3619
4950
  }));
3620
- function calculateProductBookingPrices(_x30) {
4951
+ function calculateProductBookingPrices(_x44) {
3621
4952
  return _calculateProductBookingPrices.apply(this, arguments);
3622
4953
  }
3623
4954
  return calculateProductBookingPrices;
@@ -3625,34 +4956,34 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3625
4956
  }, {
3626
4957
  key: "addProductToOrder",
3627
4958
  value: function () {
3628
- var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(product, booking, options) {
4959
+ var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee54(product, booking, options) {
3629
4960
  var products;
3630
- return _regeneratorRuntime().wrap(function _callee39$(_context39) {
3631
- while (1) switch (_context39.prev = _context39.next) {
4961
+ return _regeneratorRuntime().wrap(function _callee54$(_context54) {
4962
+ while (1) switch (_context54.prev = _context54.next) {
3632
4963
  case 0:
3633
- _context39.prev = 0;
4964
+ _context54.prev = 0;
3634
4965
  if (this.store.order) {
3635
- _context39.next = 3;
4966
+ _context54.next = 3;
3636
4967
  break;
3637
4968
  }
3638
4969
  throw new Error('order 模块未初始化');
3639
4970
  case 3:
3640
- _context39.next = 5;
4971
+ _context54.next = 5;
3641
4972
  return this.store.order.addProductToOrder(product, booking, options);
3642
4973
  case 5:
3643
- products = _context39.sent;
3644
- return _context39.abrupt("return", products);
4974
+ products = _context54.sent;
4975
+ return _context54.abrupt("return", products);
3645
4976
  case 9:
3646
- _context39.prev = 9;
3647
- _context39.t0 = _context39["catch"](0);
3648
- throw _context39.t0;
4977
+ _context54.prev = 9;
4978
+ _context54.t0 = _context54["catch"](0);
4979
+ throw _context54.t0;
3649
4980
  case 12:
3650
4981
  case "end":
3651
- return _context39.stop();
4982
+ return _context54.stop();
3652
4983
  }
3653
- }, _callee39, this, [[0, 9]]);
4984
+ }, _callee54, this, [[0, 9]]);
3654
4985
  }));
3655
- function addProductToOrder(_x32, _x33, _x34) {
4986
+ function addProductToOrder(_x46, _x47, _x48) {
3656
4987
  return _addProductToOrder.apply(this, arguments);
3657
4988
  }
3658
4989
  return addProductToOrder;
@@ -3660,34 +4991,34 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3660
4991
  }, {
3661
4992
  key: "updateOrderProduct",
3662
4993
  value: function () {
3663
- var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(params) {
4994
+ var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee55(params) {
3664
4995
  var products;
3665
- return _regeneratorRuntime().wrap(function _callee40$(_context40) {
3666
- while (1) switch (_context40.prev = _context40.next) {
4996
+ return _regeneratorRuntime().wrap(function _callee55$(_context55) {
4997
+ while (1) switch (_context55.prev = _context55.next) {
3667
4998
  case 0:
3668
- _context40.prev = 0;
4999
+ _context55.prev = 0;
3669
5000
  if (this.store.order) {
3670
- _context40.next = 3;
5001
+ _context55.next = 3;
3671
5002
  break;
3672
5003
  }
3673
5004
  throw new Error('order 模块未初始化');
3674
5005
  case 3:
3675
- _context40.next = 5;
5006
+ _context55.next = 5;
3676
5007
  return this.store.order.updateOrderProduct(params);
3677
5008
  case 5:
3678
- products = _context40.sent;
3679
- return _context40.abrupt("return", products);
5009
+ products = _context55.sent;
5010
+ return _context55.abrupt("return", products);
3680
5011
  case 9:
3681
- _context40.prev = 9;
3682
- _context40.t0 = _context40["catch"](0);
3683
- throw _context40.t0;
5012
+ _context55.prev = 9;
5013
+ _context55.t0 = _context55["catch"](0);
5014
+ throw _context55.t0;
3684
5015
  case 12:
3685
5016
  case "end":
3686
- return _context40.stop();
5017
+ return _context55.stop();
3687
5018
  }
3688
- }, _callee40, this, [[0, 9]]);
5019
+ }, _callee55, this, [[0, 9]]);
3689
5020
  }));
3690
- function updateOrderProduct(_x35) {
5021
+ function updateOrderProduct(_x49) {
3691
5022
  return _updateOrderProduct.apply(this, arguments);
3692
5023
  }
3693
5024
  return updateOrderProduct;
@@ -3695,34 +5026,34 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3695
5026
  }, {
3696
5027
  key: "updateOrderProducts",
3697
5028
  value: function () {
3698
- var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(paramsList) {
5029
+ var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee56(paramsList) {
3699
5030
  var products;
3700
- return _regeneratorRuntime().wrap(function _callee41$(_context41) {
3701
- while (1) switch (_context41.prev = _context41.next) {
5031
+ return _regeneratorRuntime().wrap(function _callee56$(_context56) {
5032
+ while (1) switch (_context56.prev = _context56.next) {
3702
5033
  case 0:
3703
- _context41.prev = 0;
5034
+ _context56.prev = 0;
3704
5035
  if (this.store.order) {
3705
- _context41.next = 3;
5036
+ _context56.next = 3;
3706
5037
  break;
3707
5038
  }
3708
5039
  throw new Error('order 模块未初始化');
3709
5040
  case 3:
3710
- _context41.next = 5;
5041
+ _context56.next = 5;
3711
5042
  return this.store.order.updateOrderProducts(paramsList);
3712
5043
  case 5:
3713
- products = _context41.sent;
3714
- return _context41.abrupt("return", products);
5044
+ products = _context56.sent;
5045
+ return _context56.abrupt("return", products);
3715
5046
  case 9:
3716
- _context41.prev = 9;
3717
- _context41.t0 = _context41["catch"](0);
3718
- throw _context41.t0;
5047
+ _context56.prev = 9;
5048
+ _context56.t0 = _context56["catch"](0);
5049
+ throw _context56.t0;
3719
5050
  case 12:
3720
5051
  case "end":
3721
- return _context41.stop();
5052
+ return _context56.stop();
3722
5053
  }
3723
- }, _callee41, this, [[0, 9]]);
5054
+ }, _callee56, this, [[0, 9]]);
3724
5055
  }));
3725
- function updateOrderProducts(_x36) {
5056
+ function updateOrderProducts(_x50) {
3726
5057
  return _updateOrderProducts.apply(this, arguments);
3727
5058
  }
3728
5059
  return updateOrderProducts;
@@ -3730,34 +5061,34 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3730
5061
  }, {
3731
5062
  key: "updateOrderProductQuantity",
3732
5063
  value: function () {
3733
- var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42(params) {
5064
+ var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee57(params) {
3734
5065
  var products;
3735
- return _regeneratorRuntime().wrap(function _callee42$(_context42) {
3736
- while (1) switch (_context42.prev = _context42.next) {
5066
+ return _regeneratorRuntime().wrap(function _callee57$(_context57) {
5067
+ while (1) switch (_context57.prev = _context57.next) {
3737
5068
  case 0:
3738
- _context42.prev = 0;
5069
+ _context57.prev = 0;
3739
5070
  if (this.store.order) {
3740
- _context42.next = 3;
5071
+ _context57.next = 3;
3741
5072
  break;
3742
5073
  }
3743
5074
  throw new Error('order 模块未初始化');
3744
5075
  case 3:
3745
- _context42.next = 5;
5076
+ _context57.next = 5;
3746
5077
  return this.store.order.updateOrderProductQuantity(params);
3747
5078
  case 5:
3748
- products = _context42.sent;
3749
- return _context42.abrupt("return", products);
5079
+ products = _context57.sent;
5080
+ return _context57.abrupt("return", products);
3750
5081
  case 9:
3751
- _context42.prev = 9;
3752
- _context42.t0 = _context42["catch"](0);
3753
- throw _context42.t0;
5082
+ _context57.prev = 9;
5083
+ _context57.t0 = _context57["catch"](0);
5084
+ throw _context57.t0;
3754
5085
  case 12:
3755
5086
  case "end":
3756
- return _context42.stop();
5087
+ return _context57.stop();
3757
5088
  }
3758
- }, _callee42, this, [[0, 9]]);
5089
+ }, _callee57, this, [[0, 9]]);
3759
5090
  }));
3760
- function updateOrderProductQuantity(_x37) {
5091
+ function updateOrderProductQuantity(_x51) {
3761
5092
  return _updateOrderProductQuantity.apply(this, arguments);
3762
5093
  }
3763
5094
  return updateOrderProductQuantity;
@@ -3780,12 +5111,12 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3780
5111
  }, {
3781
5112
  key: "setOrderProductLineNote",
3782
5113
  value: (function () {
3783
- var _setOrderProductLineNote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43(identity, note) {
5114
+ var _setOrderProductLineNote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee58(identity, note) {
3784
5115
  var params, products;
3785
- return _regeneratorRuntime().wrap(function _callee43$(_context43) {
3786
- while (1) switch (_context43.prev = _context43.next) {
5116
+ return _regeneratorRuntime().wrap(function _callee58$(_context58) {
5117
+ while (1) switch (_context58.prev = _context58.next) {
3787
5118
  case 0:
3788
- _context43.prev = 0;
5119
+ _context58.prev = 0;
3789
5120
  params = {
3790
5121
  product_id: identity.product_id,
3791
5122
  product_variant_id: identity.product_variant_id,
@@ -3800,22 +5131,22 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3800
5131
  params.product_sku = identity.product_sku;
3801
5132
  }
3802
5133
  if (identity.product_bundle !== undefined) params.product_bundle = identity.product_bundle;
3803
- _context43.next = 7;
5134
+ _context58.next = 7;
3804
5135
  return this.updateOrderProduct(params);
3805
5136
  case 7:
3806
- products = _context43.sent;
3807
- return _context43.abrupt("return", products);
5137
+ products = _context58.sent;
5138
+ return _context58.abrupt("return", products);
3808
5139
  case 11:
3809
- _context43.prev = 11;
3810
- _context43.t0 = _context43["catch"](0);
3811
- throw _context43.t0;
5140
+ _context58.prev = 11;
5141
+ _context58.t0 = _context58["catch"](0);
5142
+ throw _context58.t0;
3812
5143
  case 14:
3813
5144
  case "end":
3814
- return _context43.stop();
5145
+ return _context58.stop();
3815
5146
  }
3816
- }, _callee43, this, [[0, 11]]);
5147
+ }, _callee58, this, [[0, 11]]);
3817
5148
  }));
3818
- function setOrderProductLineNote(_x38, _x39) {
5149
+ function setOrderProductLineNote(_x52, _x53) {
3819
5150
  return _setOrderProductLineNote.apply(this, arguments);
3820
5151
  }
3821
5152
  return setOrderProductLineNote;
@@ -3830,32 +5161,32 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3830
5161
  }, {
3831
5162
  key: "removeProductsFromOrder",
3832
5163
  value: (function () {
3833
- var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee44(identities, options) {
3834
- return _regeneratorRuntime().wrap(function _callee44$(_context44) {
3835
- while (1) switch (_context44.prev = _context44.next) {
5164
+ var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee59(identities, options) {
5165
+ return _regeneratorRuntime().wrap(function _callee59$(_context59) {
5166
+ while (1) switch (_context59.prev = _context59.next) {
3836
5167
  case 0:
3837
- _context44.prev = 0;
5168
+ _context59.prev = 0;
3838
5169
  if (this.store.order) {
3839
- _context44.next = 3;
5170
+ _context59.next = 3;
3840
5171
  break;
3841
5172
  }
3842
5173
  throw new Error('order 模块未初始化');
3843
5174
  case 3:
3844
- _context44.next = 5;
5175
+ _context59.next = 5;
3845
5176
  return this.store.order.removeProductsFromOrder(identities, options);
3846
5177
  case 5:
3847
- return _context44.abrupt("return", _context44.sent);
5178
+ return _context59.abrupt("return", _context59.sent);
3848
5179
  case 8:
3849
- _context44.prev = 8;
3850
- _context44.t0 = _context44["catch"](0);
3851
- throw _context44.t0;
5180
+ _context59.prev = 8;
5181
+ _context59.t0 = _context59["catch"](0);
5182
+ throw _context59.t0;
3852
5183
  case 11:
3853
5184
  case "end":
3854
- return _context44.stop();
5185
+ return _context59.stop();
3855
5186
  }
3856
- }, _callee44, this, [[0, 8]]);
5187
+ }, _callee59, this, [[0, 8]]);
3857
5188
  }));
3858
- function removeProductsFromOrder(_x40, _x41) {
5189
+ function removeProductsFromOrder(_x54, _x55) {
3859
5190
  return _removeProductsFromOrder.apply(this, arguments);
3860
5191
  }
3861
5192
  return removeProductsFromOrder;
@@ -3863,18 +5194,18 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3863
5194
  }, {
3864
5195
  key: "removeProductFromOrder",
3865
5196
  value: function () {
3866
- var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee45(identity, options) {
3867
- return _regeneratorRuntime().wrap(function _callee45$(_context45) {
3868
- while (1) switch (_context45.prev = _context45.next) {
5197
+ var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee60(identity, options) {
5198
+ return _regeneratorRuntime().wrap(function _callee60$(_context60) {
5199
+ while (1) switch (_context60.prev = _context60.next) {
3869
5200
  case 0:
3870
- return _context45.abrupt("return", this.removeProductsFromOrder([identity], options));
5201
+ return _context60.abrupt("return", this.removeProductsFromOrder([identity], options));
3871
5202
  case 1:
3872
5203
  case "end":
3873
- return _context45.stop();
5204
+ return _context60.stop();
3874
5205
  }
3875
- }, _callee45, this);
5206
+ }, _callee60, this);
3876
5207
  }));
3877
- function removeProductFromOrder(_x42, _x43) {
5208
+ function removeProductFromOrder(_x56, _x57) {
3878
5209
  return _removeProductFromOrder.apply(this, arguments);
3879
5210
  }
3880
5211
  return removeProductFromOrder;
@@ -3924,23 +5255,23 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3924
5255
  }, {
3925
5256
  key: "applyPromotion",
3926
5257
  value: (function () {
3927
- var _applyPromotion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee46() {
3928
- return _regeneratorRuntime().wrap(function _callee46$(_context46) {
3929
- while (1) switch (_context46.prev = _context46.next) {
5258
+ var _applyPromotion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee61() {
5259
+ return _regeneratorRuntime().wrap(function _callee61$(_context61) {
5260
+ while (1) switch (_context61.prev = _context61.next) {
3930
5261
  case 0:
3931
5262
  if (this.store.order) {
3932
- _context46.next = 2;
5263
+ _context61.next = 2;
3933
5264
  break;
3934
5265
  }
3935
5266
  throw new Error('order 模块未初始化');
3936
5267
  case 2:
3937
- _context46.next = 4;
5268
+ _context61.next = 4;
3938
5269
  return this.store.order.applyPromotion();
3939
5270
  case 4:
3940
5271
  case "end":
3941
- return _context46.stop();
5272
+ return _context61.stop();
3942
5273
  }
3943
- }, _callee46, this);
5274
+ }, _callee61, this);
3944
5275
  }));
3945
5276
  function applyPromotion() {
3946
5277
  return _applyPromotion.apply(this, arguments);
@@ -3950,16 +5281,16 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3950
5281
  }, {
3951
5282
  key: "getUnfulfilledPromotions",
3952
5283
  value: function getUnfulfilledPromotions() {
3953
- var _this$store$order8;
3954
- return ((_this$store$order8 = this.store.order) === null || _this$store$order8 === void 0 ? void 0 : _this$store$order8.getUnfulfilledPromotions()) || [];
5284
+ var _this$store$order16;
5285
+ return ((_this$store$order16 = this.store.order) === null || _this$store$order16 === void 0 ? void 0 : _this$store$order16.getUnfulfilledPromotions()) || [];
3955
5286
  }
3956
5287
 
3957
5288
  /** 最近一次促销计算输出的赠品操作 diff。 */
3958
5289
  }, {
3959
5290
  key: "getLastGiftActions",
3960
5291
  value: function getLastGiftActions() {
3961
- var _this$store$order9;
3962
- return ((_this$store$order9 = this.store.order) === null || _this$store$order9 === void 0 ? void 0 : _this$store$order9.getLastGiftActions()) || null;
5292
+ var _this$store$order17;
5293
+ return ((_this$store$order17 = this.store.order) === null || _this$store$order17 === void 0 ? void 0 : _this$store$order17.getLastGiftActions()) || null;
3963
5294
  }
3964
5295
 
3965
5296
  // 获取商品列表
@@ -3967,18 +5298,18 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3967
5298
  }, {
3968
5299
  key: "getProductList",
3969
5300
  value: function () {
3970
- var _getProductList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee47() {
3971
- var _this$otherParams26;
5301
+ var _getProductList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee62() {
5302
+ var _this$otherParams32;
3972
5303
  var menu_list_ids, _this$store$products, res;
3973
- return _regeneratorRuntime().wrap(function _callee47$(_context47) {
3974
- while (1) switch (_context47.prev = _context47.next) {
5304
+ return _regeneratorRuntime().wrap(function _callee62$(_context62) {
5305
+ while (1) switch (_context62.prev = _context62.next) {
3975
5306
  case 0:
3976
5307
  // 可以直接通过配置里的 menu 读取
3977
- menu_list_ids = ((_this$otherParams26 = this.otherParams) === null || _this$otherParams26 === void 0 || (_this$otherParams26 = _this$otherParams26.dineInConfig) === null || _this$otherParams26 === void 0 ? void 0 : _this$otherParams26['menu.associated_menus'].map(function (n) {
5308
+ menu_list_ids = ((_this$otherParams32 = this.otherParams) === null || _this$otherParams32 === void 0 || (_this$otherParams32 = _this$otherParams32.dineInConfig) === null || _this$otherParams32 === void 0 ? void 0 : _this$otherParams32['menu.associated_menus'].map(function (n) {
3978
5309
  return Number(n.value);
3979
5310
  })) || [];
3980
- _context47.prev = 1;
3981
- _context47.next = 4;
5311
+ _context62.prev = 1;
5312
+ _context62.next = 4;
3982
5313
  return (_this$store$products = this.store.products) === null || _this$store$products === void 0 ? void 0 : _this$store$products.loadProducts({
3983
5314
  menu_list_ids: menu_list_ids,
3984
5315
  cacheId: this.cacheId,
@@ -3986,17 +5317,17 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3986
5317
  schedule_datetime: dayjs().format('YYYY-MM-DD HH:mm:ss')
3987
5318
  });
3988
5319
  case 4:
3989
- res = _context47.sent;
3990
- return _context47.abrupt("return", res);
5320
+ res = _context62.sent;
5321
+ return _context62.abrupt("return", res);
3991
5322
  case 8:
3992
- _context47.prev = 8;
3993
- _context47.t0 = _context47["catch"](1);
3994
- throw _context47.t0;
5323
+ _context62.prev = 8;
5324
+ _context62.t0 = _context62["catch"](1);
5325
+ throw _context62.t0;
3995
5326
  case 11:
3996
5327
  case "end":
3997
- return _context47.stop();
5328
+ return _context62.stop();
3998
5329
  }
3999
- }, _callee47, this, [[1, 8]]);
5330
+ }, _callee62, this, [[1, 8]]);
4000
5331
  }));
4001
5332
  function getProductList() {
4002
5333
  return _getProductList.apply(this, arguments);
@@ -4011,33 +5342,33 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
4011
5342
  }, {
4012
5343
  key: "setOtherParams",
4013
5344
  value: function () {
4014
- var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee48(params) {
4015
- var _this$otherParams27;
4016
- var _ref33,
4017
- _ref33$cover,
5345
+ var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee63(params) {
5346
+ var _this$otherParams33;
5347
+ var _ref42,
5348
+ _ref42$cover,
4018
5349
  cover,
4019
- _args48 = arguments;
4020
- return _regeneratorRuntime().wrap(function _callee48$(_context48) {
4021
- while (1) switch (_context48.prev = _context48.next) {
5350
+ _args63 = arguments;
5351
+ return _regeneratorRuntime().wrap(function _callee63$(_context63) {
5352
+ while (1) switch (_context63.prev = _context63.next) {
4022
5353
  case 0:
4023
- _ref33 = _args48.length > 1 && _args48[1] !== undefined ? _args48[1] : {}, _ref33$cover = _ref33.cover, cover = _ref33$cover === void 0 ? false : _ref33$cover;
5354
+ _ref42 = _args63.length > 1 && _args63[1] !== undefined ? _args63[1] : {}, _ref42$cover = _ref42.cover, cover = _ref42$cover === void 0 ? false : _ref42$cover;
4024
5355
  if (cover) {
4025
5356
  this.otherParams = _objectSpread({}, params);
4026
5357
  } else {
4027
5358
  this.otherParams = _objectSpread(_objectSpread({}, this.otherParams), params);
4028
5359
  }
4029
- this.cacheId = (_this$otherParams27 = this.otherParams) === null || _this$otherParams27 === void 0 ? void 0 : _this$otherParams27.cacheId;
4030
- _context48.next = 5;
5360
+ this.cacheId = (_this$otherParams33 = this.otherParams) === null || _this$otherParams33 === void 0 ? void 0 : _this$otherParams33.cacheId;
5361
+ _context63.next = 5;
4031
5362
  return this.syncOtherParamsToSubModules(params, {
4032
5363
  cover: cover
4033
5364
  });
4034
5365
  case 5:
4035
5366
  case "end":
4036
- return _context48.stop();
5367
+ return _context63.stop();
4037
5368
  }
4038
- }, _callee48, this);
5369
+ }, _callee63, this);
4039
5370
  }));
4040
- function setOtherParams(_x44) {
5371
+ function setOtherParams(_x58) {
4041
5372
  return _setOtherParams.apply(this, arguments);
4042
5373
  }
4043
5374
  return setOtherParams;