@pisell/pisellos 2.2.277 → 2.2.800

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 (127) hide show
  1. package/dist/core/index.d.ts +0 -2
  2. package/dist/core/index.js +1 -7
  3. package/dist/model/strategy/adapter/promotion/adapter.d.ts +0 -4
  4. package/dist/model/strategy/adapter/promotion/adapter.js +0 -23
  5. package/dist/model/strategy/adapter/promotion/evaluator.d.ts +0 -17
  6. package/dist/model/strategy/adapter/promotion/evaluator.js +6 -279
  7. package/dist/model/strategy/adapter/promotion/examples.d.ts +0 -86
  8. package/dist/model/strategy/adapter/promotion/examples.js +0 -99
  9. package/dist/model/strategy/adapter/promotion/index.d.ts +1 -1
  10. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  11. package/dist/model/strategy/adapter/promotion/type.d.ts +2 -90
  12. package/dist/model/strategy/adapter/promotion/type.js +0 -45
  13. package/dist/model/strategy/adapter/walletPass/evaluator.js +2 -0
  14. package/dist/model/strategy/adapter/walletPass/type.d.ts +0 -5
  15. package/dist/model/strategy/adapter/walletPass/utils.js +26 -57
  16. package/dist/modules/OpenData/index.d.ts +0 -2
  17. package/dist/modules/OpenData/index.js +0 -8
  18. package/dist/modules/Order/index.d.ts +8 -28
  19. package/dist/modules/Order/index.js +496 -808
  20. package/dist/modules/Order/types.d.ts +1 -35
  21. package/dist/modules/Order/utils/orderCollectionIdentity.js +2 -7
  22. package/dist/modules/Order/utils.js +6 -10
  23. package/dist/modules/Payment/index.d.ts +0 -2
  24. package/dist/modules/Payment/index.js +49 -78
  25. package/dist/modules/Payment/types.d.ts +25 -106
  26. package/dist/modules/Payment/types.js +0 -17
  27. package/dist/modules/Payment/utils.js +1 -4
  28. package/dist/modules/Payment/walletpass.d.ts +1 -49
  29. package/dist/modules/Payment/walletpass.js +124 -1081
  30. package/dist/modules/Rules/index.d.ts +0 -3
  31. package/dist/modules/Rules/index.js +70 -100
  32. package/dist/server/index.d.ts +0 -25
  33. package/dist/server/index.js +1069 -2001
  34. package/dist/server/modules/index.d.ts +1 -1
  35. package/dist/server/modules/order/index.d.ts +4 -70
  36. package/dist/server/modules/order/index.js +728 -1816
  37. package/dist/server/modules/order/types.d.ts +3 -25
  38. package/dist/server/modules/order/types.js +1 -7
  39. package/dist/server/utils/small-ticket.js +2 -1
  40. package/dist/solution/BaseSales/index.d.ts +5 -109
  41. package/dist/solution/BaseSales/index.js +436 -1802
  42. package/dist/solution/BaseSales/types.d.ts +1 -55
  43. package/dist/solution/BaseSales/types.js +1 -2
  44. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +1 -3
  45. package/dist/solution/BaseSales/utils/cartPromotion.js +31 -90
  46. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +1 -6
  47. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +4 -7
  48. package/dist/solution/BookingByStep/index.d.ts +1 -1
  49. package/dist/solution/BookingTicket/index.d.ts +5 -21
  50. package/dist/solution/BookingTicket/index.js +56 -139
  51. package/dist/solution/BookingTicket/types.d.ts +0 -1
  52. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -8
  53. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +83 -173
  54. package/dist/solution/Sales/index.d.ts +0 -2
  55. package/dist/solution/Sales/index.js +4 -26
  56. package/dist/solution/ScanOrder/index.js +20 -31
  57. package/dist/solution/VenueBooking/index.d.ts +0 -1
  58. package/dist/solution/VenueBooking/index.js +19 -30
  59. package/dist/types/index.d.ts +0 -1
  60. package/lib/core/index.d.ts +0 -2
  61. package/lib/core/index.js +1 -4
  62. package/lib/model/strategy/adapter/promotion/adapter.d.ts +0 -4
  63. package/lib/model/strategy/adapter/promotion/adapter.js +0 -20
  64. package/lib/model/strategy/adapter/promotion/evaluator.d.ts +0 -17
  65. package/lib/model/strategy/adapter/promotion/evaluator.js +0 -235
  66. package/lib/model/strategy/adapter/promotion/examples.d.ts +0 -86
  67. package/lib/model/strategy/adapter/promotion/examples.js +0 -91
  68. package/lib/model/strategy/adapter/promotion/index.d.ts +1 -1
  69. package/lib/model/strategy/adapter/promotion/index.js +49 -0
  70. package/lib/model/strategy/adapter/promotion/type.d.ts +2 -90
  71. package/lib/model/strategy/adapter/promotion/type.js +0 -2
  72. package/lib/model/strategy/adapter/walletPass/evaluator.js +2 -0
  73. package/lib/model/strategy/adapter/walletPass/type.d.ts +0 -5
  74. package/lib/model/strategy/adapter/walletPass/utils.js +11 -62
  75. package/lib/modules/OpenData/index.d.ts +0 -2
  76. package/lib/modules/OpenData/index.js +0 -5
  77. package/lib/modules/Order/index.d.ts +8 -28
  78. package/lib/modules/Order/index.js +69 -231
  79. package/lib/modules/Order/types.d.ts +1 -35
  80. package/lib/modules/Order/utils/orderCollectionIdentity.js +0 -3
  81. package/lib/modules/Order/utils.js +4 -11
  82. package/lib/modules/Payment/index.d.ts +0 -2
  83. package/lib/modules/Payment/index.js +12 -33
  84. package/lib/modules/Payment/types.d.ts +25 -106
  85. package/lib/modules/Payment/types.js +0 -1
  86. package/lib/modules/Payment/utils.js +1 -5
  87. package/lib/modules/Payment/walletpass.d.ts +1 -49
  88. package/lib/modules/Payment/walletpass.js +22 -898
  89. package/lib/modules/Rules/index.d.ts +0 -3
  90. package/lib/modules/Rules/index.js +9 -38
  91. package/lib/server/index.d.ts +0 -25
  92. package/lib/server/index.js +31 -726
  93. package/lib/server/modules/index.d.ts +1 -1
  94. package/lib/server/modules/order/index.d.ts +4 -70
  95. package/lib/server/modules/order/index.js +69 -818
  96. package/lib/server/modules/order/types.d.ts +3 -25
  97. package/lib/server/modules/order/types.js +0 -1
  98. package/lib/server/utils/small-ticket.js +1 -1
  99. package/lib/solution/BaseSales/index.d.ts +5 -109
  100. package/lib/solution/BaseSales/index.js +27 -874
  101. package/lib/solution/BaseSales/types.d.ts +1 -55
  102. package/lib/solution/BaseSales/types.js +1 -2
  103. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +1 -3
  104. package/lib/solution/BaseSales/utils/cartPromotion.js +12 -63
  105. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +1 -6
  106. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +3 -4
  107. package/lib/solution/BookingByStep/index.d.ts +1 -1
  108. package/lib/solution/BookingTicket/index.d.ts +5 -21
  109. package/lib/solution/BookingTicket/index.js +13 -64
  110. package/lib/solution/BookingTicket/types.d.ts +0 -1
  111. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -8
  112. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +5 -37
  113. package/lib/solution/Sales/index.d.ts +0 -2
  114. package/lib/solution/Sales/index.js +6 -20
  115. package/lib/solution/ScanOrder/index.js +0 -8
  116. package/lib/solution/VenueBooking/index.d.ts +0 -1
  117. package/lib/solution/VenueBooking/index.js +0 -8
  118. package/lib/types/index.d.ts +0 -1
  119. package/package.json +1 -1
  120. package/dist/modules/Order/payment-utils.d.ts +0 -26
  121. package/dist/modules/Order/payment-utils.js +0 -225
  122. package/dist/utils/payment-number.d.ts +0 -9
  123. package/dist/utils/payment-number.js +0 -69
  124. package/lib/modules/Order/payment-utils.d.ts +0 -26
  125. package/lib/modules/Order/payment-utils.js +0 -224
  126. package/lib/utils/payment-number.d.ts +0 -9
  127. package/lib/utils/payment-number.js +0 -64
@@ -40,8 +40,6 @@ var import_decimal = __toESM(require("decimal.js"));
40
40
  var import_lodash_es = require("lodash-es");
41
41
  var import_types2 = require("../BookingByStep/types");
42
42
  var import_utils = require("../../modules/Order/utils");
43
- var import_payment_utils = require("../../modules/Order/payment-utils");
44
- var import_payment_number = require("../../utils/payment-number");
45
43
  var import_orderCollectionIdentity = require("../../modules/Order/utils/orderCollectionIdentity");
46
44
  var import_dayjs = __toESM(require("dayjs"));
47
45
  __reExport(BaseSales_exports, require("./types"), module.exports);
@@ -49,88 +47,6 @@ var import_Quotation = require("../../modules/Quotation");
49
47
  var import_transformBaseProductToOrderProduct = require("./utils/transformBaseProductToOrderProduct");
50
48
  var import_quotationPrice = require("./utils/quotationPrice");
51
49
  var SERVER_ORDER_CHANGED_EVENT = "order:onOrdersChanged";
52
- var WALLET_PAYMENT_CODE_BY_TAG = {
53
- product_voucher: "PRODUCTVOUCHER",
54
- gift_card: "GIFTCARD",
55
- point_card: "POINTCARD"
56
- };
57
- function getSharedWalletAssetId(asset) {
58
- return (asset == null ? void 0 : asset.id) ?? (asset == null ? void 0 : asset.voucher_id) ?? (asset == null ? void 0 : asset.code);
59
- }
60
- function getSharedWalletAssetAmount(asset) {
61
- const value = (asset == null ? void 0 : asset.edit_current_amount) ?? (asset == null ? void 0 : asset._available_max_amount) ?? ((asset == null ? void 0 : asset.tag) === "point_card" ? asset == null ? void 0 : asset.recommended_usage_amount : asset == null ? void 0 : asset.available_max_amount) ?? (asset == null ? void 0 : asset.actualDeduction) ?? (asset == null ? void 0 : asset.amount) ?? 0;
62
- const amount = Number(value);
63
- return Number.isFinite(amount) && amount > 0 ? amount : 0;
64
- }
65
- function isRejectedSalesSubmitResult(result) {
66
- var _a, _b;
67
- const candidates = [
68
- result,
69
- result == null ? void 0 : result.data,
70
- (_a = result == null ? void 0 : result.response) == null ? void 0 : _a.data,
71
- (_b = result == null ? void 0 : result.response) == null ? void 0 : _b.body
72
- ];
73
- return candidates.some((candidate) => {
74
- if (!candidate || typeof candidate !== "object")
75
- return false;
76
- const responseCode = Number(candidate.code ?? candidate.statusCode);
77
- if (Number.isFinite(responseCode) && responseCode >= 400)
78
- return true;
79
- if (candidate.status === false || candidate.success === false || candidate.result === false) {
80
- return true;
81
- }
82
- return ["failed", "error"].includes(
83
- String(candidate.status || "").toLowerCase()
84
- );
85
- });
86
- }
87
- function getSalesSubmitErrorMessage(result) {
88
- var _a, _b;
89
- return (result == null ? void 0 : result.message) || (result == null ? void 0 : result.msg) || ((_a = result == null ? void 0 : result.data) == null ? void 0 : _a.message) || ((_b = result == null ? void 0 : result.data) == null ? void 0 : _b.msg) || "Wallet 支付确认失败";
90
- }
91
- function toWalletFundValue(value) {
92
- try {
93
- return new import_decimal.default(value || 0).toDecimalPlaces(2).toFixed(2);
94
- } catch {
95
- return "0.00";
96
- }
97
- }
98
- function subtractWalletFundValue(left, right) {
99
- try {
100
- return new import_decimal.default(left || 0).minus(right || 0).toDecimalPlaces(2).toFixed(2);
101
- } catch {
102
- return "0.00";
103
- }
104
- }
105
- function getSharedWalletPassUseValue(params) {
106
- const { asset, amount, paymentMethod } = params;
107
- const configuredValue = Number(asset == null ? void 0 : asset.wallet_pass_use_value);
108
- if (Number.isFinite(configuredValue) && configuredValue > 0) {
109
- return configuredValue;
110
- }
111
- const isPointCard = (asset == null ? void 0 : asset.tag) === "point_card" || paymentMethod.code === "POINTCARD";
112
- const usageUnit = asset == null ? void 0 : asset.wallet_pass_usage_unit;
113
- if (isPointCard && (usageUnit == null ? void 0 : usageUnit.points) && (usageUnit == null ? void 0 : usageUnit.price)) {
114
- return new import_decimal.default(amount).div(usageUnit.price).mul(usageUnit.points).toDecimalPlaces(2, import_decimal.default.ROUND_DOWN).toNumber();
115
- }
116
- return amount;
117
- }
118
- function buildSharedWalletFundRecord(params) {
119
- const { asset, amount, paymentMethod } = params;
120
- const isPointCard = (asset == null ? void 0 : asset.tag) === "point_card" || paymentMethod.code === "POINTCARD";
121
- const usingBeforeValue = (asset == null ? void 0 : asset.balance_par_value) ?? (asset == null ? void 0 : asset.balance) ?? (asset == null ? void 0 : asset.using_before_value) ?? 0;
122
- const walletPassUseValue = getSharedWalletPassUseValue(params);
123
- const usingValue = isPointCard ? walletPassUseValue : amount;
124
- const walletPassName = (asset == null ? void 0 : asset.wallet_pass_name) || (asset == null ? void 0 : asset.format_title) || (asset == null ? void 0 : asset.product_name) || (asset == null ? void 0 : asset.name) || paymentMethod.name;
125
- return {
126
- voucher_id: (asset == null ? void 0 : asset.voucher_id) ?? (asset == null ? void 0 : asset.id),
127
- wallet_pass_name: walletPassName && typeof walletPassName === "object" ? walletPassName : { default: walletPassName || "" },
128
- code: (asset == null ? void 0 : asset.code) || (asset == null ? void 0 : asset.tag),
129
- encoded: asset == null ? void 0 : asset.encoded,
130
- using_before_value: toWalletFundValue(usingBeforeValue),
131
- using_after_value: subtractWalletFundValue(usingBeforeValue, usingValue)
132
- };
133
- }
134
50
  function isBaseSalesManualProductDiscountProduct(product) {
135
51
  var _a, _b;
136
52
  return ((_a = product == null ? void 0 : product.metadata) == null ? void 0 : _a.is_manual_discount) === true || ((_b = product == null ? void 0 : product.metadata) == null ? void 0 : _b.is_manual_discount) === 1 || ((product == null ? void 0 : product.discount_list) || []).some((item) => (item == null ? void 0 : item.type) === "product");
@@ -161,11 +77,6 @@ function isBaseSalesHistoricalDiscountEntry(discount) {
161
77
  (discount == null ? void 0 : discount.isEditMode) || (discount == null ? void 0 : discount.isDisabled) || (discount == null ? void 0 : discount.order_discount_id) != null
162
78
  );
163
79
  }
164
- function getBaseSalesUniqueArrayMetadataKey(key) {
165
- if (key === "products" || key === "bookings")
166
- return "unique_identification_number";
167
- return null;
168
- }
169
80
  var BASE_SALES_PERSISTENT_ID_FIELD_BY_KIND = {
170
81
  product: "order_detail_id",
171
82
  booking: "schedule_event_id",
@@ -239,15 +150,6 @@ function mergeBaseSalesCollectionItem(kind, currentItem, incomingItem, uidRemaps
239
150
  return kind === "product" ? mergeBaseSalesProductSnapshotFields(currentItem, mergedItem) : mergedItem;
240
151
  }
241
152
  function mergeBaseSalesOrderCollection(kind, currentValue, incomingValue, strategy, uidRemaps) {
242
- if (kind === "payment") {
243
- return (0, import_payment_utils.mergeOrderPaymentListsByIdentity)(
244
- currentValue,
245
- incomingValue,
246
- strategy === "preserve-local" ? { preserveUnmatchedExisting: true } : {
247
- preserveUnmatchedExistingWhen: (payment) => (0, import_payment_utils.isIdentifiedPendingOrderPayment)(payment) || !(0, import_orderCollectionIdentity.getOrderCollectionPersistentId)("payment", payment)
248
- }
249
- );
250
- }
251
153
  const currentItems = (0, import_orderCollectionIdentity.normalizeOrderCollection)(kind, currentValue, {
252
154
  ensureUid: false
253
155
  }).items;
@@ -307,35 +209,6 @@ function normalizeBaseSalesRecordCollections(sourceRecord, options) {
307
209
  }
308
210
  return normalizedRecord;
309
211
  }
310
- function getBaseSalesMetadataUid(item, metadataKey) {
311
- var _a;
312
- const uid = ((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a[metadataKey]) ?? (item == null ? void 0 : item[metadataKey]);
313
- if (uid === void 0 || uid === null || uid === "")
314
- return null;
315
- return String(uid);
316
- }
317
- function mergeBaseSalesUniqueArray(currentValue, loadedValue, metadataKey) {
318
- const result = [];
319
- const indexByUid = /* @__PURE__ */ new Map();
320
- const appendOrReplaceByUid = (item) => {
321
- const clonedItem = (0, import_lodash_es.cloneDeep)(item);
322
- const uid = getBaseSalesMetadataUid(clonedItem, metadataKey);
323
- if (!uid) {
324
- result.push(clonedItem);
325
- return;
326
- }
327
- const existingIndex = indexByUid.get(uid);
328
- if (existingIndex !== void 0) {
329
- result[existingIndex] = clonedItem;
330
- return;
331
- }
332
- indexByUid.set(uid, result.length);
333
- result.push(clonedItem);
334
- };
335
- currentValue.forEach(appendOrReplaceByUid);
336
- loadedValue.forEach(appendOrReplaceByUid);
337
- return result;
338
- }
339
212
  function mergeSalesDetailRecordWithTempOrder(currentTempOrder, loadedRecord, strategy) {
340
213
  const normalizedLoadedRecord = normalizeBaseSalesRecordCollections(
341
214
  loadedRecord || {},
@@ -364,15 +237,6 @@ function mergeSalesDetailRecordWithTempOrder(currentTempOrder, loadedRecord, str
364
237
  );
365
238
  }
366
239
  if (Array.isArray(currentValue) && Array.isArray(loadedValue)) {
367
- if (key === "payments" || key === "payment") {
368
- return (0, import_payment_utils.mergeOrderPaymentListsByIdentity)(currentValue, loadedValue, {
369
- preserveUnmatchedExisting: true
370
- });
371
- }
372
- const metadataKey = getBaseSalesUniqueArrayMetadataKey(key);
373
- if (metadataKey) {
374
- return mergeBaseSalesUniqueArray(currentValue, loadedValue, metadataKey);
375
- }
376
240
  return [
377
241
  ...(0, import_lodash_es.cloneDeep)(currentValue),
378
242
  ...(0, import_lodash_es.cloneDeep)(loadedValue)
@@ -391,18 +255,6 @@ function mergeSalesDetailRecordWithTempOrder(currentTempOrder, loadedRecord, str
391
255
  (0, import_orderCollectionIdentity.applyOrderCollectionUidRemaps)(mergedRecord, uidRemaps)
392
256
  );
393
257
  }
394
- function filterPendingPaymentsFromLoadedSalesDetail(sourceRecord) {
395
- if (!sourceRecord || typeof sourceRecord !== "object")
396
- return sourceRecord;
397
- const record = { ...sourceRecord };
398
- if (Array.isArray(sourceRecord.payments)) {
399
- record.payments = sourceRecord.payments.filter((payment) => !(0, import_payment_utils.isPendingOrderPayment)(payment));
400
- }
401
- if (Array.isArray(sourceRecord.payment)) {
402
- record.payment = sourceRecord.payment.filter((payment) => !(0, import_payment_utils.isPendingOrderPayment)(payment));
403
- }
404
- return record;
405
- }
406
258
  var BaseSalesImpl = class extends import_BaseModule.BaseModule {
407
259
  constructor(name, version) {
408
260
  super(name, version);
@@ -414,11 +266,6 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
414
266
  order: void 0
415
267
  };
416
268
  this.otherParams = {};
417
- /**
418
- * 由已在初始化阶段解析过设备短号的业务解决方案写入。
419
- * 未设置时,支付编号仍按原逻辑实时读取设备信息。
420
- */
421
- this.paymentNumberDevicePrefix = null;
422
269
  // 当前缓存中已加载的最新 SalesDetail;只读 getter 走它对外暴露详情数据。
423
270
  this.currentSalesDetail = null;
424
271
  this.discountConfigCacheKey = null;
@@ -430,7 +277,6 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
430
277
  this.autoPaymentSyncTimer = null;
431
278
  this.salesDetailLoadInFlightCount = 0;
432
279
  this.salesDetailLoadSequence = 0;
433
- this.walletAssetsRefreshSequence = 0;
434
280
  this.salesDetailHydrateQueue = Promise.resolve();
435
281
  this.serverOrderChangeUnsubscribe = null;
436
282
  this.serverOrderChangeHydrateInFlight = null;
@@ -983,27 +829,6 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
983
829
  const coreData = (_f = (_d = (_c = app == null ? void 0 : app.models) == null ? void 0 : _c.getStore) == null ? void 0 : (_e = _d.call(_c)).getDataByModel) == null ? void 0 : _f.call(_e, "core", "core");
984
830
  return coreData == null ? void 0 : coreData[key];
985
831
  }
986
- /**
987
- * 复用业务解决方案初始化时已解析的支付设备短号。
988
- * 空值会清除缓存,使后续支付恢复实时读取设备信息的兼容路径。
989
- */
990
- setPaymentNumberDevicePrefix(prefix) {
991
- const normalized = String(prefix ?? "").trim();
992
- this.paymentNumberDevicePrefix = normalized || null;
993
- }
994
- getPaymentNumberDevicePrefixSync() {
995
- if (!this.appPlugin)
996
- return "LOCAL";
997
- return (0, import_payment_number.resolvePaymentNumberDevicePrefixFromDeviceId)((key) => this.getAppData(key));
998
- }
999
- getPaymentNumberDevicePrefixAsync() {
1000
- if (!this.appPlugin)
1001
- return Promise.resolve("LOCAL");
1002
- if (this.paymentNumberDevicePrefix) {
1003
- return Promise.resolve(this.paymentNumberDevicePrefix);
1004
- }
1005
- return (0, import_payment_number.resolvePaymentNumberDevicePrefix)((key) => this.getAppData(key));
1006
- }
1007
832
  syncAppDataToTempOrder(tempOrder) {
1008
833
  const isPriceIncludeTax = this.getAppData("is_price_include_tax");
1009
834
  const taxCountryCode = this.getAppData("tax_country_code");
@@ -1044,7 +869,6 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1044
869
  var _a, _b;
1045
870
  this.core = core;
1046
871
  this.initializeOptions = options || {};
1047
- this.paymentNumberDevicePrefix = null;
1048
872
  this.otherParams = options.otherParams || {};
1049
873
  this.cacheId = (_a = this.otherParams) == null ? void 0 : _a.cacheId;
1050
874
  this.reusedSharedSubModuleNames.clear();
@@ -1106,10 +930,8 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1106
930
  }
1107
931
  });
1108
932
  this.currentSalesDetail = null;
1109
- this.paymentNumberDevicePrefix = null;
1110
933
  this.queuedServerOrderChanges = [];
1111
934
  this.salesDetailLoadSequence += 1;
1112
- this.walletAssetsRefreshSequence += 1;
1113
935
  await this.core.effects.emit(`${this.name}:onDestroy`, {});
1114
936
  super.destroy();
1115
937
  }
@@ -1141,16 +963,13 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1141
963
  const message = loadedRecord && (loadedRecord.message || loadedRecord.msg) || `加载销售详情失败: ${lookup}`;
1142
964
  throw new Error(message);
1143
965
  }
1144
- const remoteRecord = filterPendingPaymentsFromLoadedSalesDetail(
1145
- preloadedSalesDetail ?? loadedRecord.data
1146
- );
966
+ const remoteRecord = preloadedSalesDetail ?? loadedRecord.data;
1147
967
  const currentTempOrder = params.merge ? this.store.order.getTempOrder() : null;
1148
- const mergedRecord = params.merge ? mergeSalesDetailRecordWithTempOrder(
968
+ const record = params.merge ? mergeSalesDetailRecordWithTempOrder(
1149
969
  currentTempOrder,
1150
970
  remoteRecord,
1151
971
  "preserve-local"
1152
972
  ) : remoteRecord;
1153
- const record = filterPendingPaymentsFromLoadedSalesDetail(mergedRecord);
1154
973
  return await this.hydrateLatestLoadedSalesDetail(record, loadSequence);
1155
974
  } finally {
1156
975
  this.salesDetailLoadInFlightCount = Math.max(
@@ -1326,7 +1145,6 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1326
1145
  // 重置 tempOrder 与与上一单强相关的运行态(resource/entryPaxNumber/enabledReservationRuleProducts),
1327
1146
  // 适用于从支付页通过 react-router 跳回继续下单时清理残留数据
1328
1147
  async restoreOrder() {
1329
- var _a;
1330
1148
  try {
1331
1149
  if (!this.store.order) {
1332
1150
  throw new Error("scanOrder 解决方案需要 order 模块支持");
@@ -1335,12 +1153,6 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1335
1153
  this.currentSalesDetail = null;
1336
1154
  this.discountConfigCacheKey = null;
1337
1155
  this.hasManualDiscountSelection = false;
1338
- const wallet = (_a = this.store.payment) == null ? void 0 : _a.wallet;
1339
- if (wallet) {
1340
- this.walletAssetsRefreshSequence += 1;
1341
- wallet.clearAllCache();
1342
- await this.publishWalletAssetsState(wallet.getWalletAssetsState());
1343
- }
1344
1156
  await this.effectsEmit("onTempOrderReplaced", { tempOrder });
1345
1157
  if (this.syncAppDataToTempOrder(tempOrder) && this.isTempOrderPersistEnabled()) {
1346
1158
  this.store.order.persistTempOrder();
@@ -1753,7 +1565,6 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1753
1565
  }
1754
1566
  return {
1755
1567
  isAvailable: raw.isAvailable,
1756
- ...raw.isAccepted !== void 0 ? { isAccepted: raw.isAccepted } : {},
1757
1568
  type: raw.type,
1758
1569
  unavailableReason: raw.unavailableReason,
1759
1570
  scannedDiscountList: raw.scannedDiscountList
@@ -1949,20 +1760,6 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1949
1760
  };
1950
1761
  return this.store.order.submitTempOrder(submitParams);
1951
1762
  }
1952
- async saveSalesOrderDraft(params) {
1953
- var _a, _b, _c, _d;
1954
- if (!this.store.order) {
1955
- throw new Error("BaseSales 解决方案需要 order 模块支持");
1956
- }
1957
- return this.store.order.saveTempOrderAsDraft({
1958
- cacheId: this.cacheId,
1959
- platform: (params == null ? void 0 : params.platform) ?? ((_a = this.otherParams) == null ? void 0 : _a.platform),
1960
- businessCode: (params == null ? void 0 : params.businessCode) || ((_b = this.otherParams) == null ? void 0 : _b.businessCode) || ((_c = this.otherParams) == null ? void 0 : _c.business_code),
1961
- channel: (params == null ? void 0 : params.channel) ?? this.getSubmitOrderSalesChannel(),
1962
- type: (params == null ? void 0 : params.type) ?? ((_d = this.otherParams) == null ? void 0 : _d.type),
1963
- ...(params == null ? void 0 : params.enhancePayload) !== void 0 ? { enhancePayload: params.enhancePayload } : {}
1964
- });
1965
- }
1966
1763
  async submitTempOrderAsync(params) {
1967
1764
  var _a, _b, _c, _d;
1968
1765
  if (!this.store.order) {
@@ -2163,29 +1960,8 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
2163
1960
  }
2164
1961
  }
2165
1962
  }
2166
- /**
2167
- * 同步兼容入口。无法等待 IoT 短号时,按调用当下的 device_id 或 LOCAL 生成。
2168
- */
1963
+ /** 追加单个支付项到当前订单。 */
2169
1964
  addOrderPayment(payment) {
2170
- const hasPaymentNumber = String(
2171
- payment.payment_number || ""
2172
- ).trim() !== "";
2173
- return this.addOrderPaymentWithDevicePrefix(
2174
- payment,
2175
- hasPaymentNumber ? "LOCAL" : this.getPaymentNumberDevicePrefixSync()
2176
- );
2177
- }
2178
- /**
2179
- * 创建新支付项时优先使用业务解决方案初始化阶段缓存的设备短号;
2180
- * 未缓存的通用 BaseSales 保持实时读取设备信息的兼容语义。
2181
- */
2182
- async addOrderPaymentAsync(payment) {
2183
- const paymentRecord = payment;
2184
- const hasPaymentNumber = String(paymentRecord.payment_number || "").trim() !== "";
2185
- const devicePrefix = hasPaymentNumber ? "LOCAL" : await this.getPaymentNumberDevicePrefixAsync();
2186
- return this.addOrderPaymentWithDevicePrefix(payment, devicePrefix);
2187
- }
2188
- addOrderPaymentWithDevicePrefix(payment, devicePrefix) {
2189
1965
  var _a;
2190
1966
  if (!this.store.order)
2191
1967
  throw new Error("order 模块未初始化");
@@ -2202,26 +1978,21 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
2202
1978
  if (shopWalletPassId !== void 0 && shopWalletPassId !== null) {
2203
1979
  metadata.shop_wallet_pass_id = shopWalletPassId;
2204
1980
  }
2205
- const normalizedPaymentRecord = (0, import_payment_utils.ensureOrderPaymentNumber)(
2206
- paymentRecord,
2207
- devicePrefix,
2208
- import_utils.createUuidV4
2209
- );
1981
+ if (!metadata.unique_payment_number) {
1982
+ metadata.unique_payment_number = (0, import_utils.createUuidV4)();
1983
+ }
2210
1984
  const paymentTimestamp = (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss");
2211
1985
  const paymentTime = paymentRecord.payment_time ?? paymentTimestamp;
2212
1986
  const createdAt = paymentRecord.created_at ?? paymentTimestamp;
2213
1987
  const serviceCharge = paymentRecord.service_charge && typeof paymentRecord.service_charge === "object" ? paymentRecord.service_charge : null;
2214
1988
  const calculatedServiceFee = serviceCharge ? new import_decimal.default(paymentRecord.origin_amount ?? paymentRecord.amount ?? 0).times(serviceCharge.percentage || 0).plus(serviceCharge.amount || 0).toDecimalPlaces(2).toFixed(2) : void 0;
2215
1989
  const payments = this.store.order.addOrderPayment({
2216
- ...normalizedPaymentRecord,
1990
+ ...paymentRecord,
2217
1991
  ...calculatedServiceFee !== void 0 ? { service_fee: calculatedServiceFee } : {},
2218
1992
  metadata,
2219
1993
  payment_time: paymentTime,
2220
1994
  created_at: createdAt
2221
1995
  });
2222
- if (paymentRecord.status === "payment_pending") {
2223
- return payments;
2224
- }
2225
1996
  const amountSnapshot = this.store.order.getOrderAmountSnapshot();
2226
1997
  const syncState = this.store.order.getOrderSyncState();
2227
1998
  if (amountSnapshot) {
@@ -2243,73 +2014,10 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
2243
2014
  return payments;
2244
2015
  }
2245
2016
  /** 更新当前订单中的指定支付项。 */
2246
- async updateOrderPayment(paymentIdentity, updates, options = {}) {
2247
- var _a, _b, _c;
2017
+ updateOrderPayment(paymentIdentity, updates) {
2248
2018
  if (!this.store.order)
2249
2019
  throw new Error("order 模块未初始化");
2250
- const matchMode = options.matchBy === "compat" || options.matchBy === "legacy" ? "compat" : "payment_number";
2251
- const previousMatch = (0, import_payment_utils.resolveOrderPaymentIdentity)(
2252
- this.store.order.getOrderPayments(),
2253
- paymentIdentity,
2254
- matchMode
2255
- );
2256
- const previousPayment = previousMatch == null ? void 0 : previousMatch.payment;
2257
- if ((previousPayment == null ? void 0 : previousPayment.status) === "paid" && !options.applyUpdatesWhenPaid) {
2258
- const currentPayments = this.store.order.getOrderPayments();
2259
- let syncResult2;
2260
- if (options.submitWhenPaid && options.forceSubmitIfPaid) {
2261
- syncResult2 = await this.syncPaymentsToOrder({
2262
- payments: currentPayments,
2263
- paymentStatus: this.getPaymentStatusForSync(currentPayments),
2264
- submitWhenPaid: true,
2265
- smallTicketDataFlag: options.smallTicketDataFlag ?? 1
2266
- });
2267
- }
2268
- return {
2269
- updated: false,
2270
- payment: previousPayment,
2271
- payments: currentPayments,
2272
- summary: ((_a = this.store.order.getOrderAmountSnapshot()) == null ? void 0 : _a.summary) || null,
2273
- ...syncResult2 !== void 0 ? { syncResult: syncResult2 } : {}
2274
- };
2275
- }
2276
- const result = await this.store.order.updateOrderPayment(paymentIdentity, updates, {
2277
- matchBy: matchMode
2278
- });
2279
- let draftResult;
2280
- let draftError;
2281
- if (options.persistDraft !== false) {
2282
- try {
2283
- draftResult = await this.saveSalesOrderDraft();
2284
- } catch (error) {
2285
- draftError = error;
2286
- this.logError("updateOrderPayment: 保存支付草稿失败", {
2287
- paymentIdentity,
2288
- error: error instanceof Error ? error.message : String(error)
2289
- });
2290
- if (!options.submitWhenPaid)
2291
- throw error;
2292
- }
2293
- }
2294
- const becamePaid = (previousPayment == null ? void 0 : previousPayment.status) !== "paid" && ((_b = result.payment) == null ? void 0 : _b.status) === "paid";
2295
- const shouldSubmit = Boolean(
2296
- options.submitWhenPaid && ((_c = result.payment) == null ? void 0 : _c.status) === "paid" && (becamePaid || options.forceSubmitIfPaid)
2297
- );
2298
- let syncResult;
2299
- if (shouldSubmit) {
2300
- syncResult = await this.syncPaymentsToOrder({
2301
- payments: result.payments,
2302
- paymentStatus: this.getPaymentStatusForSync(result.payments),
2303
- submitWhenPaid: true,
2304
- smallTicketDataFlag: options.smallTicketDataFlag ?? 1
2305
- });
2306
- }
2307
- return {
2308
- ...result,
2309
- ...draftResult !== void 0 ? { draftResult } : {},
2310
- ...draftError !== void 0 ? { draftError } : {},
2311
- ...syncResult !== void 0 ? { syncResult } : {}
2312
- };
2020
+ return this.store.order.updateOrderPayment(paymentIdentity, updates);
2313
2021
  }
2314
2022
  /** 删除当前订单中的指定支付项。 */
2315
2023
  deleteOrderPayment(paymentIdentity) {
@@ -2323,24 +2031,10 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
2323
2031
  throw new Error("order 模块未初始化");
2324
2032
  return this.store.order.updateVoucherOrderPayments(payments, options);
2325
2033
  }
2326
- async updateVoucherOrderPaymentsAsync(payments, options) {
2327
- if (!this.store.order)
2328
- throw new Error("order 模块未初始化");
2329
- return this.store.order.updateVoucherOrderPaymentsAsync(payments, options);
2330
- }
2331
2034
  confirmPendingVoucherPayments() {
2332
2035
  if (!this.store.order)
2333
2036
  throw new Error("order 模块未初始化");
2334
- const payments = this.store.order.confirmPendingVoucherPayments();
2335
- if (this.store.payment) {
2336
- const committed = this.getCommittedWalletAssets();
2337
- const state = this.store.payment.wallet.setCommittedWalletAssets(
2338
- committed.ids,
2339
- committed.assets
2340
- );
2341
- void this.publishWalletAssetsState(state);
2342
- }
2343
- return payments;
2037
+ return this.store.order.confirmPendingVoucherPayments();
2344
2038
  }
2345
2039
  discardPendingVoucherPayments() {
2346
2040
  if (!this.store.order)
@@ -2401,14 +2095,24 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
2401
2095
  });
2402
2096
  return walletProducts;
2403
2097
  }
2404
- buildWalletInitBusinessData(params) {
2405
- var _a;
2406
- const snapshot = (_a = this.store.order) == null ? void 0 : _a.getOrderSnapshot();
2098
+ async initWalletData(params) {
2099
+ if (!this.store.order)
2100
+ throw new Error("order 模块未初始化");
2101
+ if (!this.store.payment)
2102
+ throw new Error("payment 模块未初始化");
2103
+ const snapshot = this.store.order.getOrderSnapshot();
2407
2104
  const tempOrder = snapshot == null ? void 0 : snapshot.tempOrder;
2408
2105
  const amount = snapshot == null ? void 0 : snapshot.amount;
2409
- if (!tempOrder || !amount)
2410
- return null;
2411
- return {
2106
+ if (!tempOrder || !amount) {
2107
+ return {
2108
+ walletRecommendList: [],
2109
+ userIdentificationCodes: [],
2110
+ transformList: [],
2111
+ noApplicableVoucher: [],
2112
+ products: []
2113
+ };
2114
+ }
2115
+ const walletBusinessData = {
2412
2116
  customer_id: tempOrder.customer_id ? Number(tempOrder.customer_id) : void 0,
2413
2117
  holder: tempOrder.holder,
2414
2118
  amountInfo: {
@@ -2422,29 +2126,11 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
2422
2126
  is_price_include_tax: tempOrder.is_price_include_tax ?? this.otherParams.is_price_include_tax ?? 1,
2423
2127
  ...snapshot.identity.orderId ? { payment_order_id: String(snapshot.identity.orderId) } : {}
2424
2128
  };
2425
- }
2426
- async initWalletData(params) {
2427
- var _a;
2428
- if (!this.store.order)
2429
- throw new Error("order 模块未初始化");
2430
- if (!this.store.payment)
2431
- throw new Error("payment 模块未初始化");
2432
- const snapshot = this.store.order.getOrderSnapshot();
2433
- const walletBusinessData = this.buildWalletInitBusinessData(params);
2434
- if (!walletBusinessData) {
2435
- return {
2436
- walletRecommendList: [],
2437
- userIdentificationCodes: [],
2438
- transformList: [],
2439
- noApplicableVoucher: [],
2440
- products: []
2441
- };
2442
- }
2443
2129
  const result = await this.store.payment.wallet.initializeWalletDataFromBusinessAsync(
2444
2130
  walletBusinessData
2445
2131
  );
2446
2132
  await this.core.effects.emit(`${this.name}:onWalletDataInitialized`, {
2447
- orderId: (_a = snapshot == null ? void 0 : snapshot.identity) == null ? void 0 : _a.orderId,
2133
+ orderId: snapshot.identity.orderId,
2448
2134
  customerId: walletBusinessData.customer_id,
2449
2135
  walletBusinessData: {
2450
2136
  customer_id: walletBusinessData.customer_id,
@@ -2455,224 +2141,6 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
2455
2141
  });
2456
2142
  return result;
2457
2143
  }
2458
- getCommittedWalletAssets() {
2459
- var _a, _b;
2460
- const payments = ((_b = (_a = this.store.order) == null ? void 0 : _a.getOrderPayments) == null ? void 0 : _b.call(_a)) || [];
2461
- const committed = payments.filter((payment) => {
2462
- const voucherId = payment == null ? void 0 : payment.voucher_id;
2463
- if (voucherId === void 0 || voucherId === null || voucherId === 0) {
2464
- return false;
2465
- }
2466
- return (payment == null ? void 0 : payment.status) === "paid" || (payment == null ? void 0 : payment.isSynced) === true || (payment == null ? void 0 : payment.order_payment_id) !== void 0 && (payment == null ? void 0 : payment.order_payment_id) !== null && (payment == null ? void 0 : payment.order_payment_id) !== "";
2467
- });
2468
- return {
2469
- ids: committed.map((payment) => payment.voucher_id),
2470
- assets: committed.map((payment) => {
2471
- var _a2;
2472
- const fundRecord = (payment == null ? void 0 : payment.fund_record) || {};
2473
- const walletPassName = fundRecord.wallet_pass_name;
2474
- const title = walletPassName && typeof walletPassName === "object" ? walletPassName.default || Object.values(walletPassName)[0] : walletPassName;
2475
- const code = String((payment == null ? void 0 : payment.code) || "").toUpperCase();
2476
- const tag = ((_a2 = Object.entries(WALLET_PAYMENT_CODE_BY_TAG).find(
2477
- ([, paymentCode]) => paymentCode === code
2478
- )) == null ? void 0 : _a2[0]) || fundRecord.tag;
2479
- return {
2480
- id: payment.voucher_id,
2481
- voucher_id: payment.voucher_id,
2482
- code: fundRecord.code,
2483
- tag,
2484
- product_name: title || payment.name,
2485
- name: title || payment.name,
2486
- amount: Number(payment.amount || 0),
2487
- _available_max_amount: Number(payment.amount || 0),
2488
- unified_available_status: 1,
2489
- _unified_available_status: 1,
2490
- _committed_payment: payment
2491
- };
2492
- })
2493
- };
2494
- }
2495
- async publishWalletAssetsState(state) {
2496
- await this.effectsEmit(import_types.BaseSalesHookNames.onWalletAssetsStateChanged, {
2497
- state
2498
- });
2499
- return state;
2500
- }
2501
- async syncSelectedWalletAssets(state) {
2502
- if (!this.store.order || !this.store.payment) {
2503
- throw new Error("订单或支付模块未初始化");
2504
- }
2505
- let paymentMethods = this.getPaymentMethods();
2506
- if (!paymentMethods.length && state.selectedItems.length) {
2507
- paymentMethods = await this.getPaymentMethodsAsync();
2508
- }
2509
- const methodByCode = new Map(
2510
- paymentMethods.map((method) => [String(method.code || "").toUpperCase(), method])
2511
- );
2512
- const preparePayments = this.store.payment.wallet.formatWalletPassList2PreparePayments(
2513
- state.selectedItems
2514
- );
2515
- const selectedAssetById = new Map(
2516
- state.selectedItems.map((asset) => [
2517
- String(getSharedWalletAssetId(asset)),
2518
- asset
2519
- ])
2520
- );
2521
- const voucherPayments = preparePayments.flatMap((item) => {
2522
- const asset = selectedAssetById.get(String(item.voucher_id));
2523
- const paymentCode = WALLET_PAYMENT_CODE_BY_TAG[String(item.tag || (asset == null ? void 0 : asset.tag) || "")] || String(item.tag || (asset == null ? void 0 : asset.tag) || "").toUpperCase();
2524
- const paymentMethod = methodByCode.get(paymentCode);
2525
- const formattedAmount = Number(item.amount);
2526
- const amount = Number.isFinite(formattedAmount) && formattedAmount > 0 ? formattedAmount : getSharedWalletAssetAmount(asset);
2527
- if (!asset || !paymentMethod || !Number.isFinite(amount) || amount <= 0) {
2528
- return [];
2529
- }
2530
- const walletPassUseValue = getSharedWalletPassUseValue({
2531
- asset,
2532
- amount,
2533
- paymentMethod
2534
- });
2535
- return [
2536
- {
2537
- amount: amount.toFixed(2),
2538
- code: paymentMethod.code,
2539
- custom_payment_id: paymentMethod.id,
2540
- name: paymentMethod.name,
2541
- type: paymentMethod.type,
2542
- voucher_id: item.voucher_id,
2543
- wallet_pass_usage_unit: item.wallet_pass_usage_unit,
2544
- wallet_pass_use_value: walletPassUseValue,
2545
- fund_record: buildSharedWalletFundRecord({
2546
- asset,
2547
- amount,
2548
- paymentMethod
2549
- })
2550
- }
2551
- ];
2552
- });
2553
- const payments = this.updateVoucherOrderPayments(voucherPayments, {
2554
- status: "payment_pending"
2555
- });
2556
- await this.store.order.recalculateSummary({ createIfMissing: true });
2557
- return payments;
2558
- }
2559
- /** 读取购物车与 Shared Checkout 共用的钱包资产状态。 */
2560
- getWalletAssetsState() {
2561
- if (!this.store.payment)
2562
- throw new Error("payment 模块未初始化");
2563
- return this.store.payment.wallet.getWalletAssetsState();
2564
- }
2565
- /** 导出 Shared Checkout 跨运行时恢复所需的钱包状态与搜索缓存。 */
2566
- exportWalletAssetsSnapshot() {
2567
- if (!this.store.payment)
2568
- throw new Error("payment 模块未初始化");
2569
- return this.store.payment.wallet.exportWalletAssetsSnapshot();
2570
- }
2571
- /** 配置仅影响 Wallet Assets,不改变 Promotion/Voucher 选择流程。 */
2572
- configureWalletAssetsBehavior(options) {
2573
- if (!this.store.payment)
2574
- throw new Error("payment 模块未初始化");
2575
- this.store.payment.wallet.configureWalletAssetsBehavior(options);
2576
- }
2577
- /**
2578
- * 恢复 Shared Checkout 钱包快照,并把选择重新同步为订单 pending payment。
2579
- */
2580
- async importWalletAssetsSnapshot(snapshot) {
2581
- if (!this.store.payment)
2582
- throw new Error("payment 模块未初始化");
2583
- const state = this.store.payment.wallet.importWalletAssetsSnapshot(snapshot);
2584
- await this.syncSelectedWalletAssets(state);
2585
- return this.publishWalletAssetsState(state);
2586
- }
2587
- /**
2588
- * 基于当前订单快照刷新钱包资产。商品变化保留并重验选择;客户变化强制清空。
2589
- */
2590
- async refreshWalletAssets(params) {
2591
- if (!this.store.order)
2592
- throw new Error("order 模块未初始化");
2593
- if (!this.store.payment)
2594
- throw new Error("payment 模块未初始化");
2595
- const refreshSequence = ++this.walletAssetsRefreshSequence;
2596
- const wallet = this.store.payment.wallet;
2597
- const businessData = this.buildWalletInitBusinessData(params);
2598
- if (!businessData) {
2599
- wallet.clearAllCache();
2600
- const emptyState = wallet.getWalletAssetsState();
2601
- this.updateVoucherOrderPayments([], { status: "payment_pending" });
2602
- return this.publishWalletAssetsState(emptyState);
2603
- }
2604
- const previousState = wallet.getWalletAssetsState();
2605
- const hasPreviousWalletContext = previousState.status !== "idle" || previousState.items.length > 0 || previousState.selectedIds.length > 0 || previousState.customerId !== void 0;
2606
- const customerChanged = hasPreviousWalletContext && String(previousState.customerId ?? "") !== String(businessData.customer_id ?? "");
2607
- if (customerChanged) {
2608
- const clearedState = wallet.clearWalletAssetSelection();
2609
- this.updateVoucherOrderPayments([], { status: "payment_pending" });
2610
- await this.publishWalletAssetsState(clearedState);
2611
- }
2612
- const refreshTask = wallet.refreshWalletAssetsFromBusinessAsync(
2613
- businessData,
2614
- {
2615
- preserveSelection: (params == null ? void 0 : params.preserveSelection) !== false && !customerChanged
2616
- }
2617
- );
2618
- await this.publishWalletAssetsState(wallet.getWalletAssetsState());
2619
- let state = await refreshTask;
2620
- if (refreshSequence !== this.walletAssetsRefreshSequence) {
2621
- return wallet.getWalletAssetsState();
2622
- }
2623
- if (state.status !== "error") {
2624
- const committed = this.getCommittedWalletAssets();
2625
- state = wallet.setCommittedWalletAssets(committed.ids, committed.assets);
2626
- }
2627
- await this.syncSelectedWalletAssets(state);
2628
- return this.publishWalletAssetsState(state);
2629
- }
2630
- /** 选择或取消单张钱包资产,并立即同步 pending wallet payments。 */
2631
- async selectWalletAsset(params) {
2632
- if (!this.store.payment)
2633
- throw new Error("payment 模块未初始化");
2634
- const state = this.store.payment.wallet.selectWalletAsset(params.assetId, {
2635
- selected: params.selected,
2636
- source: params.source
2637
- });
2638
- await this.syncSelectedWalletAssets(state);
2639
- return this.publishWalletAssetsState(state);
2640
- }
2641
- /** 更新已选钱包资产的手动使用金额,并同步 pending payment。 */
2642
- async updateWalletAssetAmount(params) {
2643
- if (!this.store.payment)
2644
- throw new Error("payment 模块未初始化");
2645
- const state = this.store.payment.wallet.updateWalletAssetAmount(
2646
- params.assetId,
2647
- params.amount
2648
- );
2649
- await this.syncSelectedWalletAssets(state);
2650
- return this.publishWalletAssetsState(state);
2651
- }
2652
- /** 扫码精确查券;仅可用资产会被自动选中。 */
2653
- async scanWalletAsset(code) {
2654
- if (!this.store.payment)
2655
- throw new Error("payment 模块未初始化");
2656
- const wallet = this.store.payment.wallet;
2657
- const businessData = this.buildWalletInitBusinessData();
2658
- if (businessData) {
2659
- wallet.generateWalletParams(businessData);
2660
- }
2661
- const result = await wallet.scanWalletAssetAsync(code);
2662
- if (result.type === "normalCode") {
2663
- await this.syncSelectedWalletAssets(result.state);
2664
- await this.publishWalletAssetsState(result.state);
2665
- }
2666
- return result;
2667
- }
2668
- /** 清空全部未确认钱包选择,已支付钱包项由 Order 模块继续保留。 */
2669
- async clearWalletAssetSelection() {
2670
- if (!this.store.payment)
2671
- throw new Error("payment 模块未初始化");
2672
- const state = this.store.payment.wallet.clearWalletAssetSelection();
2673
- await this.syncSelectedWalletAssets(state);
2674
- return this.publishWalletAssetsState(state);
2675
- }
2676
2144
  /**
2677
2145
  * 更新当前订单客户字段。
2678
2146
  *
@@ -2709,321 +2177,6 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
2709
2177
  getPaymentMethods() {
2710
2178
  return [...this.paymentMethodsCache];
2711
2179
  }
2712
- findCashPaymentMethod(paymentMethods) {
2713
- return paymentMethods.find((method) => {
2714
- const identifiers = [method == null ? void 0 : method.code, method == null ? void 0 : method.type, method == null ? void 0 : method.tag].map(
2715
- (value) => String(value || "").toUpperCase()
2716
- );
2717
- return identifiers.includes("CASHMANUAL") && (method == null ? void 0 : method.enabled) !== false && (method == null ? void 0 : method.enable) !== false;
2718
- });
2719
- }
2720
- getPendingWalletPaymentAmount(payments = ((_b) => (_b = ((_a) => (_a = this.store.order) == null ? void 0 : _a.getOrderPayments)()) == null ? void 0 : _b.call(_a))() || []) {
2721
- return payments.reduce((total, payment) => {
2722
- if ((payment == null ? void 0 : payment.status) !== "payment_pending" || (payment == null ? void 0 : payment.voucher_id) === void 0 || Number(payment.voucher_id) === 0) {
2723
- return total;
2724
- }
2725
- try {
2726
- return total.plus(payment.amount || 0).plus(payment.rounding_amount || 0);
2727
- } catch {
2728
- return total;
2729
- }
2730
- }, new import_decimal.default(0));
2731
- }
2732
- /** 读取现金 action 所需的支付方式、待付金额和快捷金额。 */
2733
- async getCashPaymentConfig() {
2734
- var _a, _b, _c, _d, _e, _f;
2735
- if (!this.store.payment)
2736
- throw new Error("payment 模块未初始化");
2737
- let paymentMethods = this.getPaymentMethods();
2738
- let paymentMethod = this.findCashPaymentMethod(paymentMethods);
2739
- if (!paymentMethod) {
2740
- paymentMethods = await this.getPaymentMethodsAsync();
2741
- paymentMethod = this.findCashPaymentMethod(paymentMethods);
2742
- }
2743
- const amountSnapshot = (_b = (_a = this.store.order) == null ? void 0 : _a.getOrderAmountSnapshot) == null ? void 0 : _b.call(_a);
2744
- const pendingWalletAmount = this.getPendingWalletPaymentAmount();
2745
- const amountDue = import_decimal.default.max(
2746
- new import_decimal.default((amountSnapshot == null ? void 0 : amountSnapshot.amountGap) || 0).minus(pendingWalletAmount),
2747
- 0
2748
- ).toDecimalPlaces(2).toNumber();
2749
- const currency = ((_e = (_d = (_c = this.store.order) == null ? void 0 : _c.getTempOrder) == null ? void 0 : _d.call(_c)) == null ? void 0 : _e.currency_code) || ((_f = this.otherParams) == null ? void 0 : _f.currency) || "USD";
2750
- const recommendedAmounts = amountDue > 0 ? this.store.payment.cash.getRecommendedAmount(amountDue, currency) : [];
2751
- return {
2752
- available: Boolean(paymentMethod && amountDue > 0),
2753
- paymentMethod,
2754
- amountDue,
2755
- recommendedAmounts
2756
- };
2757
- }
2758
- /**
2759
- * 确认足额覆盖订单的 pending Wallet 支付并提交订单。
2760
- *
2761
- * Order 模块在构造提交参数时将 pending voucher 转为 paid;只有提交成功后
2762
- * 才同步 Wallet committed 状态。失败时恢复调用前 payments,允许用户重试。
2763
- */
2764
- async confirmWalletPayment() {
2765
- var _a, _b, _c, _d, _e;
2766
- if (!this.store.order)
2767
- throw new Error("order 模块未初始化");
2768
- const beforePayments = (0, import_lodash_es.cloneDeep)(this.store.order.getOrderPayments());
2769
- const pendingWalletAmount = this.getPendingWalletPaymentAmount(beforePayments);
2770
- if (pendingWalletAmount.lte(0)) {
2771
- throw new Error("当前订单没有待确认的 Wallet 支付");
2772
- }
2773
- const amountSnapshot = (_b = (_a = this.store.order).getOrderAmountSnapshot) == null ? void 0 : _b.call(_a);
2774
- const effectiveAmountDue = import_decimal.default.max(
2775
- new import_decimal.default((amountSnapshot == null ? void 0 : amountSnapshot.amountGap) || 0).minus(pendingWalletAmount),
2776
- 0
2777
- );
2778
- if (effectiveAmountDue.gt(0.01)) {
2779
- throw new Error("Wallet 支付尚未覆盖全部待支付金额");
2780
- }
2781
- const beforePaymentStatus = (_c = this.store.order.getTempOrder()) == null ? void 0 : _c.payment_status;
2782
- let submitResult;
2783
- try {
2784
- submitResult = await this.submitSalesOrder({
2785
- smallTicketDataFlag: 1,
2786
- confirmPendingVoucherPayments: true
2787
- });
2788
- if (isRejectedSalesSubmitResult(submitResult)) {
2789
- throw new Error(getSalesSubmitErrorMessage(submitResult));
2790
- }
2791
- } catch (error) {
2792
- this.store.order.setOrderPayments(beforePayments);
2793
- const restoredTempOrder = this.store.order.getTempOrder();
2794
- if (restoredTempOrder && beforePaymentStatus !== void 0) {
2795
- restoredTempOrder.payment_status = beforePaymentStatus;
2796
- this.store.order.persistTempOrder();
2797
- }
2798
- await this.store.order.recalculateSummary({ createIfMissing: true });
2799
- throw error;
2800
- }
2801
- if (this.store.payment) {
2802
- try {
2803
- const committed = this.getCommittedWalletAssets();
2804
- const walletState = this.store.payment.wallet.setCommittedWalletAssets(
2805
- committed.ids,
2806
- committed.assets
2807
- );
2808
- await this.publishWalletAssetsState(walletState);
2809
- } catch (error) {
2810
- this.logWarning("confirmWalletPayment: Wallet committed 状态同步失败", {
2811
- error: error instanceof Error ? error.message : String(error)
2812
- });
2813
- }
2814
- }
2815
- const latestAmountSnapshot = (_e = (_d = this.store.order).getOrderAmountSnapshot) == null ? void 0 : _e.call(_d);
2816
- return {
2817
- submitResult,
2818
- payments: this.store.order.getOrderPayments(),
2819
- isOrderFullyPaid: new import_decimal.default(
2820
- (latestAmountSnapshot == null ? void 0 : latestAmountSnapshot.amountGap) || 0
2821
- ).lte(0)
2822
- };
2823
- }
2824
- /**
2825
- * 购物车现金直付:写入现金记录并等待支付同步完成。
2826
- * 同步失败会恢复调用前 payments(包含 Wallet pending 状态)。
2827
- */
2828
- async payCash(params) {
2829
- var _a, _b, _c, _d, _e, _f;
2830
- if (!this.store.order)
2831
- throw new Error("order 模块未初始化");
2832
- const amount = Number(params.amount || 0);
2833
- if (!Number.isFinite(amount) || amount <= 0) {
2834
- throw new Error("现金支付金额必须大于 0");
2835
- }
2836
- const config = await this.getCashPaymentConfig();
2837
- const paymentMethod = config.paymentMethod;
2838
- if (!paymentMethod)
2839
- throw new Error("未找到可用的 CASHMANUAL 支付方式");
2840
- if (config.amountDue <= 0)
2841
- throw new Error("当前订单没有待支付金额");
2842
- const roundingAmount = Number(params.roundingAmount || 0);
2843
- const effectivePaymentAmount = new import_decimal.default(amount).minus(roundingAmount);
2844
- if (effectivePaymentAmount.gt(new import_decimal.default(config.amountDue).plus(0.01))) {
2845
- throw new Error("现金支付金额超过当前待支付金额");
2846
- }
2847
- const beforePayments = (0, import_lodash_es.cloneDeep)(this.store.order.getOrderPayments());
2848
- const beforePaymentStatus = (_a = this.store.order.getTempOrder()) == null ? void 0 : _a.payment_status;
2849
- const uniquePaymentNumber = (0, import_utils.createUuidV4)();
2850
- const paymentTimestamp = (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss");
2851
- const actualPaidAmount = Number(params.actualPaidAmount ?? amount);
2852
- const changeAmount = Number(params.changeAmount || 0);
2853
- const shopWalletPassId = (_b = this.otherParams) == null ? void 0 : _b.shop_wallet_pass_id;
2854
- if (!Number.isFinite(actualPaidAmount) || actualPaidAmount + 0.01 < amount) {
2855
- throw new Error("顾客实收现金不能小于支付金额");
2856
- }
2857
- (_f = (_e = (_d = (_c = this.window) == null ? void 0 : _c.interaction) == null ? void 0 : _d.utils) == null ? void 0 : _e.postMessageToApp) == null ? void 0 : _f.call(_e, {
2858
- module: "till",
2859
- key: "open_till",
2860
- data: { type: "cash" }
2861
- });
2862
- const payments = this.store.order.addOrderPayment({
2863
- amount: amount.toFixed(2),
2864
- code: paymentMethod.code,
2865
- custom_payment_id: paymentMethod.id,
2866
- name: paymentMethod.name,
2867
- custom_payment_type: paymentMethod.type,
2868
- voucher_id: 0,
2869
- rounding_amount: roundingAmount.toFixed(2),
2870
- metadata: {
2871
- unique_payment_number: uniquePaymentNumber,
2872
- ...shopWalletPassId !== void 0 && shopWalletPassId !== null ? { shop_wallet_pass_id: shopWalletPassId } : {},
2873
- actual_paid_amount: Number.isFinite(actualPaidAmount) ? actualPaidAmount : amount,
2874
- change_given_amount: Number.isFinite(changeAmount) ? changeAmount : 0
2875
- },
2876
- payment_time: paymentTimestamp,
2877
- created_at: paymentTimestamp
2878
- });
2879
- const payment = payments.find(
2880
- (item) => {
2881
- var _a2;
2882
- return ((_a2 = item == null ? void 0 : item.metadata) == null ? void 0 : _a2.unique_payment_number) === uniquePaymentNumber;
2883
- }
2884
- );
2885
- try {
2886
- const syncResult = await this.syncPaymentsToOrder({
2887
- payments,
2888
- submitWhenPaid: true,
2889
- smallTicketDataFlag: 1,
2890
- confirmPendingVoucherPayments: true
2891
- });
2892
- if (this.store.payment) {
2893
- const committed = this.getCommittedWalletAssets();
2894
- const walletState = this.store.payment.wallet.setCommittedWalletAssets(
2895
- committed.ids,
2896
- committed.assets
2897
- );
2898
- await this.publishWalletAssetsState(walletState);
2899
- }
2900
- return {
2901
- payment: payment || {},
2902
- payments: this.store.order.getOrderPayments(),
2903
- syncResult,
2904
- isOrderFullyPaid: syncResult.isOrderFullyPaid
2905
- };
2906
- } catch (error) {
2907
- this.store.order.setOrderPayments(beforePayments);
2908
- const restoredTempOrder = this.store.order.getTempOrder();
2909
- if (restoredTempOrder && beforePaymentStatus !== void 0) {
2910
- restoredTempOrder.payment_status = beforePaymentStatus;
2911
- this.store.order.persistTempOrder();
2912
- }
2913
- await this.store.order.recalculateSummary({ createIfMissing: true });
2914
- throw error;
2915
- }
2916
- }
2917
- /**
2918
- * 提交一次已由支付设备确认成功的非 Wallet 支付。
2919
- *
2920
- * 与 addOrderPayment 不同,本入口不会启动后台 fire-and-forget 同步;调用方会等待
2921
- * 本次 payment、当前 pending Wallet 以及订单提交共同完成。任何同步失败都会恢复
2922
- * 调用前的 payments 与 payment_status,便于 UI 安全解锁并重试。
2923
- */
2924
- async commitPaymentMethodPayment(params) {
2925
- var _a, _b, _c, _d;
2926
- if (!this.store.order)
2927
- throw new Error("order 模块未初始化");
2928
- const amount = Number(params.amount || 0);
2929
- if (!Number.isFinite(amount) || amount <= 0) {
2930
- throw new Error("支付金额必须大于 0");
2931
- }
2932
- let paymentMethods = this.getPaymentMethods();
2933
- const findPaymentMethod = () => {
2934
- const methodCode = String(params.paymentMethodCode || "").toUpperCase();
2935
- return paymentMethods.find((method) => {
2936
- const idMatched = params.paymentMethodId !== void 0 && String(method.id) === String(params.paymentMethodId);
2937
- const codeMatched = Boolean(methodCode) && String(method.code || "").toUpperCase() === methodCode;
2938
- return (idMatched || codeMatched) && method.enabled !== false && method.enable !== false;
2939
- });
2940
- };
2941
- let paymentMethod = findPaymentMethod();
2942
- if (!paymentMethod) {
2943
- paymentMethods = await this.getPaymentMethodsAsync();
2944
- paymentMethod = findPaymentMethod();
2945
- }
2946
- if (!paymentMethod) {
2947
- throw new Error(
2948
- `未找到可用的支付方式:${params.paymentMethodCode || params.paymentMethodId || ""}`
2949
- );
2950
- }
2951
- const amountSnapshot = (_b = (_a = this.store.order).getOrderAmountSnapshot) == null ? void 0 : _b.call(_a);
2952
- const pendingWalletAmount = this.getPendingWalletPaymentAmount();
2953
- const amountDue = import_decimal.default.max(
2954
- new import_decimal.default((amountSnapshot == null ? void 0 : amountSnapshot.amountGap) || 0).minus(pendingWalletAmount),
2955
- 0
2956
- );
2957
- if (amountDue.lte(0))
2958
- throw new Error("当前订单没有待支付金额");
2959
- if (new import_decimal.default(amount).gt(amountDue.plus(0.01))) {
2960
- throw new Error("支付金额超过当前待支付金额");
2961
- }
2962
- const beforePayments = (0, import_lodash_es.cloneDeep)(this.store.order.getOrderPayments());
2963
- const beforePaymentStatus = (_c = this.store.order.getTempOrder()) == null ? void 0 : _c.payment_status;
2964
- const paymentTimestamp = (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss");
2965
- const metadata = {
2966
- ...params.metadata || {},
2967
- unique_payment_number: ((_d = params.metadata) == null ? void 0 : _d.unique_payment_number) || (0, import_utils.createUuidV4)()
2968
- };
2969
- const serviceCharge = params.serviceCharge ? {
2970
- amount: String(params.serviceCharge.amount || 0),
2971
- percentage: String(params.serviceCharge.percentage || 0)
2972
- } : void 0;
2973
- const serviceFee = serviceCharge ? new import_decimal.default(params.originAmount ?? amount).times(serviceCharge.percentage || 0).plus(serviceCharge.amount || 0).toDecimalPlaces(2).toFixed(2) : void 0;
2974
- const payments = this.store.order.addOrderPayment({
2975
- ...params.paymentData || {},
2976
- amount: amount.toFixed(2),
2977
- ...params.originAmount !== void 0 ? { origin_amount: Number(params.originAmount).toFixed(2) } : {},
2978
- code: paymentMethod.code,
2979
- custom_payment_id: paymentMethod.id,
2980
- name: paymentMethod.name,
2981
- custom_payment_type: paymentMethod.type,
2982
- voucher_id: 0,
2983
- ...serviceCharge ? { service_charge: serviceCharge } : {},
2984
- ...serviceFee !== void 0 ? { service_fee: serviceFee } : {},
2985
- metadata,
2986
- payment_time: paymentTimestamp,
2987
- created_at: paymentTimestamp
2988
- });
2989
- const payment = payments.find(
2990
- (item) => {
2991
- var _a2;
2992
- return ((_a2 = item == null ? void 0 : item.metadata) == null ? void 0 : _a2.unique_payment_number) === metadata.unique_payment_number;
2993
- }
2994
- );
2995
- try {
2996
- const syncResult = await this.syncPaymentsToOrder({
2997
- payments,
2998
- submitWhenPaid: true,
2999
- smallTicketDataFlag: 1,
3000
- confirmPendingVoucherPayments: true
3001
- });
3002
- if (this.store.payment) {
3003
- const committed = this.getCommittedWalletAssets();
3004
- const walletState = this.store.payment.wallet.setCommittedWalletAssets(
3005
- committed.ids,
3006
- committed.assets
3007
- );
3008
- await this.publishWalletAssetsState(walletState);
3009
- }
3010
- return {
3011
- payment: payment || {},
3012
- payments: this.store.order.getOrderPayments(),
3013
- syncResult,
3014
- isOrderFullyPaid: syncResult.isOrderFullyPaid
3015
- };
3016
- } catch (error) {
3017
- this.store.order.setOrderPayments(beforePayments);
3018
- const restoredTempOrder = this.store.order.getTempOrder();
3019
- if (restoredTempOrder && beforePaymentStatus !== void 0) {
3020
- restoredTempOrder.payment_status = beforePaymentStatus;
3021
- this.store.order.persistTempOrder();
3022
- }
3023
- await this.store.order.recalculateSummary({ createIfMissing: true });
3024
- throw error;
3025
- }
3026
- }
3027
2180
  /**
3028
2181
  * 按当前店铺的现金舍入配置计算金额,供现金支付 UI 使用。
3029
2182
  *