@pisell/pisellos 0.10.2 → 0.10.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/dist/core/index.d.ts +2 -0
  2. package/dist/core/index.js +7 -0
  3. package/dist/model/strategy/adapter/promotion/adapter.d.ts +4 -0
  4. package/dist/model/strategy/adapter/promotion/adapter.js +23 -0
  5. package/dist/model/strategy/adapter/promotion/evaluator.d.ts +17 -0
  6. package/dist/model/strategy/adapter/promotion/evaluator.js +279 -6
  7. package/dist/model/strategy/adapter/promotion/examples.d.ts +86 -0
  8. package/dist/model/strategy/adapter/promotion/examples.js +99 -0
  9. package/dist/model/strategy/adapter/promotion/index.d.ts +1 -1
  10. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  11. package/dist/model/strategy/adapter/promotion/type.d.ts +90 -2
  12. package/dist/model/strategy/adapter/promotion/type.js +45 -0
  13. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +5 -3
  14. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +6 -3
  15. package/dist/modules/OpenData/index.d.ts +2 -0
  16. package/dist/modules/OpenData/index.js +8 -0
  17. package/dist/modules/Order/index.d.ts +28 -8
  18. package/dist/modules/Order/index.js +818 -503
  19. package/dist/modules/Order/payment-utils.d.ts +26 -0
  20. package/dist/modules/Order/payment-utils.js +225 -0
  21. package/dist/modules/Order/types.d.ts +35 -1
  22. package/dist/modules/Order/utils/orderCollectionIdentity.js +7 -2
  23. package/dist/modules/Order/utils.js +10 -6
  24. package/dist/modules/Payment/index.d.ts +2 -0
  25. package/dist/modules/Payment/index.js +79 -50
  26. package/dist/modules/Payment/types.d.ts +107 -28
  27. package/dist/modules/Payment/types.js +20 -3
  28. package/dist/modules/Payment/walletpass.d.ts +38 -1
  29. package/dist/modules/Payment/walletpass.js +917 -114
  30. package/dist/modules/ProductList/index.js +1 -1
  31. package/dist/modules/Rules/index.d.ts +3 -0
  32. package/dist/modules/Rules/index.js +130 -99
  33. package/dist/server/index.d.ts +16 -0
  34. package/dist/server/index.js +2084 -1188
  35. package/dist/server/modules/index.d.ts +1 -1
  36. package/dist/server/modules/order/index.d.ts +70 -4
  37. package/dist/server/modules/order/index.js +1816 -728
  38. package/dist/server/modules/order/types.d.ts +25 -3
  39. package/dist/server/modules/order/types.js +7 -1
  40. package/dist/solution/BaseSales/index.d.ts +111 -13
  41. package/dist/solution/BaseSales/index.js +1799 -446
  42. package/dist/solution/BaseSales/types.d.ts +55 -1
  43. package/dist/solution/BaseSales/types.js +2 -1
  44. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +3 -1
  45. package/dist/solution/BaseSales/utils/cartPromotion.js +90 -31
  46. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +6 -1
  47. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +6 -3
  48. package/dist/solution/BookingByStep/index.d.ts +1 -1
  49. package/dist/solution/BookingTicket/index.d.ts +7 -3
  50. package/dist/solution/BookingTicket/index.js +138 -52
  51. package/dist/solution/BookingTicket/types.d.ts +1 -0
  52. package/dist/solution/BookingTicket/utils/addProductDecision.js +6 -0
  53. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +8 -0
  54. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +173 -83
  55. package/dist/solution/BookingTicket/utils/weighingProductSku.d.ts +5 -0
  56. package/dist/solution/BookingTicket/utils/weighingProductSku.js +45 -0
  57. package/dist/solution/Sales/index.d.ts +1 -0
  58. package/dist/solution/Sales/index.js +10 -2
  59. package/dist/solution/ScanOrder/index.js +31 -20
  60. package/dist/solution/UnifiedBookingSales/index.js +23 -3
  61. package/dist/solution/VenueBooking/index.d.ts +1 -0
  62. package/dist/solution/VenueBooking/index.js +34 -24
  63. package/dist/types/index.d.ts +1 -0
  64. package/dist/utils/payment-number.d.ts +9 -0
  65. package/dist/utils/payment-number.js +69 -0
  66. package/lib/core/index.d.ts +2 -0
  67. package/lib/core/index.js +4 -0
  68. package/lib/model/strategy/adapter/promotion/adapter.d.ts +4 -0
  69. package/lib/model/strategy/adapter/promotion/adapter.js +20 -0
  70. package/lib/model/strategy/adapter/promotion/evaluator.d.ts +17 -0
  71. package/lib/model/strategy/adapter/promotion/evaluator.js +235 -0
  72. package/lib/model/strategy/adapter/promotion/examples.d.ts +86 -0
  73. package/lib/model/strategy/adapter/promotion/examples.js +91 -0
  74. package/lib/model/strategy/adapter/promotion/index.d.ts +1 -1
  75. package/lib/model/strategy/adapter/promotion/index.js +0 -49
  76. package/lib/model/strategy/adapter/promotion/type.d.ts +90 -2
  77. package/lib/model/strategy/adapter/promotion/type.js +2 -0
  78. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +2 -1
  79. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +2 -1
  80. package/lib/modules/OpenData/index.d.ts +2 -0
  81. package/lib/modules/OpenData/index.js +5 -0
  82. package/lib/modules/Order/index.d.ts +28 -8
  83. package/lib/modules/Order/index.js +233 -68
  84. package/lib/modules/Order/payment-utils.d.ts +26 -0
  85. package/lib/modules/Order/payment-utils.js +224 -0
  86. package/lib/modules/Order/types.d.ts +35 -1
  87. package/lib/modules/Order/utils/orderCollectionIdentity.js +3 -0
  88. package/lib/modules/Order/utils.js +11 -4
  89. package/lib/modules/Payment/index.d.ts +2 -0
  90. package/lib/modules/Payment/index.js +34 -13
  91. package/lib/modules/Payment/types.d.ts +107 -28
  92. package/lib/modules/Payment/types.js +4 -3
  93. package/lib/modules/Payment/walletpass.d.ts +38 -1
  94. package/lib/modules/Payment/walletpass.js +730 -21
  95. package/lib/modules/ProductList/index.js +9 -1
  96. package/lib/modules/Rules/index.d.ts +3 -0
  97. package/lib/modules/Rules/index.js +39 -10
  98. package/lib/server/index.d.ts +16 -0
  99. package/lib/server/index.js +677 -28
  100. package/lib/server/modules/index.d.ts +1 -1
  101. package/lib/server/modules/order/index.d.ts +70 -4
  102. package/lib/server/modules/order/index.js +818 -69
  103. package/lib/server/modules/order/types.d.ts +25 -3
  104. package/lib/server/modules/order/types.js +1 -0
  105. package/lib/solution/BaseSales/index.d.ts +111 -13
  106. package/lib/solution/BaseSales/index.js +882 -46
  107. package/lib/solution/BaseSales/types.d.ts +55 -1
  108. package/lib/solution/BaseSales/types.js +2 -1
  109. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +3 -1
  110. package/lib/solution/BaseSales/utils/cartPromotion.js +63 -12
  111. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +6 -1
  112. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +3 -2
  113. package/lib/solution/BookingByStep/index.d.ts +1 -1
  114. package/lib/solution/BookingTicket/index.d.ts +7 -3
  115. package/lib/solution/BookingTicket/index.js +63 -9
  116. package/lib/solution/BookingTicket/types.d.ts +1 -0
  117. package/lib/solution/BookingTicket/utils/addProductDecision.js +4 -0
  118. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +8 -0
  119. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +37 -5
  120. package/lib/solution/BookingTicket/utils/weighingProductSku.d.ts +5 -0
  121. package/lib/solution/BookingTicket/utils/weighingProductSku.js +63 -0
  122. package/lib/solution/Sales/index.d.ts +1 -0
  123. package/lib/solution/Sales/index.js +5 -3
  124. package/lib/solution/ScanOrder/index.js +8 -0
  125. package/lib/solution/UnifiedBookingSales/index.js +10 -2
  126. package/lib/solution/VenueBooking/index.d.ts +1 -0
  127. package/lib/solution/VenueBooking/index.js +13 -6
  128. package/lib/types/index.d.ts +1 -0
  129. package/lib/utils/payment-number.d.ts +9 -0
  130. package/lib/utils/payment-number.js +64 -0
  131. package/package.json +1 -1
@@ -10,8 +10,6 @@ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableTo
10
10
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
11
11
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
12
12
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
13
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
14
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
15
13
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
16
14
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
17
15
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
@@ -27,6 +25,8 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) ===
27
25
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
28
26
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
29
27
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
28
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
29
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
30
30
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
31
31
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
32
32
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
@@ -35,6 +35,8 @@ import { OrderHooks } from "./types";
35
35
  import { composeLinePrice, generateDuration, getAllDiscountList, mergeRelationForms, ensureCartItemOriginHolder, buildSubmitPayload, createDefaultTempOrder, createDefaultOrderRulesHooks, createEmptySummary, createUuidV4, formatDateTime, isTempOrder, normalizeBookingIsAll, normalizeBookingSubType, mapPaymentItemsToOrderPayments, normalizeOrderProductDiscountList, resolveEffectivePerUnitDiscount, ensureProductSku, getProductSkuOptions, normalizeProductSkuOptions, sumOptionUnitPrice, clearTempOrderHolderAssignments, getOrderProductLineUid, indexOrderProductsByUid, calculateOrderProductsDeposit, mergeOrderProductDisplayFields, resolveIsFormSubject } from "./utils";
36
36
  import { isNormalProduct } from "../Product/utils";
37
37
  import dayjs from 'dayjs';
38
+ import { ensureOrderPaymentNumber, mergeOrderPaymentRecord, resolveOrderPaymentIdentity } from "./payment-utils";
39
+ import { resolvePaymentNumberDevicePrefix, resolvePaymentNumberDevicePrefixFromDeviceId } from "../../utils/payment-number";
38
40
  import { processCartPromotion, appendPromotionTags as _appendPromotionTags, getOrderProductUid as getPromotionUid } from "../../solution/BaseSales/utils/cartPromotion";
39
41
  import { buildProductLineFingerprint, getProductIdentityIndex, getSafeProductNum, isIdentityMatch, normalizeOrderProduct } from "../../solution/ScanOrder/utils";
40
42
  import { syncManualProductDiscountProductNum } from "./utils/manualProductDiscount";
@@ -68,6 +70,22 @@ function isManualProductDiscountProduct(product) {
68
70
  }
69
71
  var ORDER_PAYMENT_STATUS_PAID = 'paid';
70
72
  var ORDER_PAYMENT_STATUS_PENDING = 'payment_pending';
73
+ var CUSTOMER_PROMOTION_DISCOUNT_TAGS = new Set(['good_pass', 'product_discount_card', 'discount_card']);
74
+ function isCustomerPromotionDiscount(discount) {
75
+ return CUSTOMER_PROMOTION_DISCOUNT_TAGS.has(String((discount === null || discount === void 0 ? void 0 : discount.tag) || (discount === null || discount === void 0 ? void 0 : discount.type) || '').toLowerCase());
76
+ }
77
+ function markScannedDiscounts(discountList, scannedDiscountList) {
78
+ var scannedIds = new Set(scannedDiscountList.map(function (discount) {
79
+ return discount === null || discount === void 0 ? void 0 : discount.id;
80
+ }).filter(function (id) {
81
+ return id !== undefined && id !== null;
82
+ }).map(String));
83
+ return discountList.map(function (discount) {
84
+ return scannedIds.has(String(discount === null || discount === void 0 ? void 0 : discount.id)) ? _objectSpread(_objectSpread({}, discount), {}, {
85
+ isScan: true
86
+ }) : discount;
87
+ });
88
+ }
71
89
  function isVoucherPaymentRecord(payment) {
72
90
  return (payment === null || payment === void 0 ? void 0 : payment.voucher_id) !== undefined && Number(payment.voucher_id) !== 0;
73
91
  }
@@ -83,6 +101,10 @@ function isPaidPaymentRecord(payment) {
83
101
  function isCommittedVoucherPaymentRecord(payment) {
84
102
  return isVoucherPaymentRecord(payment) && (payment === null || payment === void 0 ? void 0 : payment.status) !== 'voided' && (hasSyncedOrderPaymentRecord(payment) || isPaidPaymentRecord(payment));
85
103
  }
104
+ function getVoucherPaymentLifecycleKey(payment) {
105
+ if (!isVoucherPaymentRecord(payment)) return null;
106
+ return "".concat(String(payment.voucher_id), "::").concat(String(payment.status || ''));
107
+ }
86
108
  export var OrderModule = /*#__PURE__*/function (_BaseModule) {
87
109
  _inherits(OrderModule, _BaseModule);
88
110
  var _super = _createSuper(OrderModule);
@@ -97,6 +119,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
97
119
  _defineProperty(_assertThisInitialized(_this), "logger", void 0);
98
120
  // LoggerManager 实例
99
121
  _defineProperty(_assertThisInitialized(_this), "window", void 0);
122
+ _defineProperty(_assertThisInitialized(_this), "appPlugin", void 0);
100
123
  _defineProperty(_assertThisInitialized(_this), "cacheId", void 0);
101
124
  _defineProperty(_assertThisInitialized(_this), "salesSummaryModuleName", void 0);
102
125
  _defineProperty(_assertThisInitialized(_this), "rulesHooksOverride", void 0);
@@ -140,6 +163,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
140
163
  var item = _step2.value;
141
164
  var type = (_item$type2 = item === null || item === void 0 ? void 0 : item.type) !== null && _item$type2 !== void 0 ? _item$type2 : item === null || item === void 0 ? void 0 : item.tag;
142
165
  if (!type || type === 'product') continue;
166
+ var isDiscountCard = type === 'discount_card' || type === 'product_discount_card';
143
167
  var resourceId = (_ref = (_ref2 = (_item$discount$resour = item === null || item === void 0 || (_item$discount = item.discount) === null || _item$discount === void 0 ? void 0 : _item$discount.resource_id) !== null && _item$discount$resour !== void 0 ? _item$discount$resour : item === null || item === void 0 ? void 0 : item.resource_id) !== null && _ref2 !== void 0 ? _ref2 : item === null || item === void 0 ? void 0 : item.discount_id) !== null && _ref !== void 0 ? _ref : item === null || item === void 0 ? void 0 : item.order_discount_id;
144
168
  if (resourceId === undefined || resourceId === null || resourceId === '') continue;
145
169
  var id = Number(resourceId);
@@ -162,7 +186,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
162
186
  var _existed$limited_rela;
163
187
  existed.amount = Number(existed.amount || 0) + amount;
164
188
  existed.used_par_value = String(Number(existed.used_par_value || 0) + amount);
165
- existed.balance = String(Number(existed.balance || 0) + amount);
189
+ if (!isDiscountCard) {
190
+ existed.balance = String(Number(existed.balance || 0) + amount);
191
+ }
166
192
  var productIds = Array.isArray((_existed$limited_rela = existed.limited_relation_product_data) === null || _existed$limited_rela === void 0 ? void 0 : _existed$limited_rela.product_ids) ? existed.limited_relation_product_data.product_ids : [];
167
193
  if ((product === null || product === void 0 ? void 0 : product.product_id) !== undefined && (product === null || product === void 0 ? void 0 : product.product_id) !== null && !productIds.includes(product.product_id)) {
168
194
  existed.limited_relation_product_data = _objectSpread(_objectSpread({}, existed.limited_relation_product_data || {}), {}, {
@@ -194,7 +220,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
194
220
  filter: 0,
195
221
  exclude_product_ids: []
196
222
  },
197
- balance: String((_item$amount3 = item === null || item === void 0 ? void 0 : item.amount) !== null && _item$amount3 !== void 0 ? _item$amount3 : '0'),
223
+ balance: isDiscountCard ? undefined : String((_item$amount3 = item === null || item === void 0 ? void 0 : item.amount) !== null && _item$amount3 !== void 0 ? _item$amount3 : '0'),
198
224
  format_title: title,
199
225
  product: {
200
226
  id: (_product$product_id = product === null || product === void 0 ? void 0 : product.product_id) !== null && _product$product_id !== void 0 ? _product$product_id : 0,
@@ -657,7 +683,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
657
683
  value: function () {
658
684
  var _scanCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(code, customerId) {
659
685
  var _this$store$discount11, _tempOrder$holder, _this$store$summary;
660
- var resultDiscountWithReason, resultDiscountList, unavailableReasonKey, rulesModule, withScanList, currentSelected, tempOrder, holders, _ref13, isAvailable, newDiscountList, unavailableReason, _this$store$discount12;
686
+ var resultDiscountWithReason, resultDiscountList, unavailableReasonKey, rulesModule, withScanList, currentSelected, tempOrder, holders, _ref13, isAvailable, newDiscountList, evaluatedDiscountList, unavailableReason, shouldRetainForLater, normalizedNewDiscountList, retainedDiscountList, resolvedDiscountList, _this$store$discount12, _this$store$discount13;
661
687
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
662
688
  while (1) switch (_context6.prev = _context6.next) {
663
689
  case 0:
@@ -686,6 +712,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
686
712
  return _context6.abrupt("return", {
687
713
  type: 'clientCalc',
688
714
  isAvailable: false,
715
+ isAccepted: false,
689
716
  discountList: this.getDiscountList(),
690
717
  scannedDiscountList: resultDiscountList,
691
718
  unavailableReason: UnavailableReason.Unknown
@@ -698,6 +725,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
698
725
  return _context6.abrupt("return", {
699
726
  type: 'server',
700
727
  isAvailable: false,
728
+ isAccepted: false,
701
729
  discountList: this.getDiscountList(),
702
730
  scannedDiscountList: resultDiscountList,
703
731
  unavailableReasonKey: unavailableReasonKey
@@ -725,6 +753,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
725
753
  return _context6.abrupt("return", {
726
754
  type: 'clientCalc',
727
755
  isAvailable: true,
756
+ isAccepted: true,
728
757
  discountList: this.getDiscountList(),
729
758
  scannedDiscountList: resultDiscountList
730
759
  });
@@ -743,24 +772,47 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
743
772
  }) || {
744
773
  isAvailable: false,
745
774
  discountList: this.getDiscountList()
746
- }, isAvailable = _ref13.isAvailable, newDiscountList = _ref13.discountList, unavailableReason = _ref13.unavailableReason;
747
- if (!(isAvailable && newDiscountList)) {
748
- _context6.next = 26;
775
+ }, isAvailable = _ref13.isAvailable, newDiscountList = _ref13.discountList, evaluatedDiscountList = _ref13.evaluatedDiscountList, unavailableReason = _ref13.unavailableReason;
776
+ shouldRetainForLater = !isAvailable && unavailableReason === UnavailableReason.ProductNotApplicable && withScanList.some(isCustomerPromotionDiscount);
777
+ normalizedNewDiscountList = newDiscountList ? markScannedDiscounts(newDiscountList, withScanList) : undefined;
778
+ retainedDiscountList = evaluatedDiscountList ? markScannedDiscounts(evaluatedDiscountList, withScanList) : normalizedNewDiscountList;
779
+ resolvedDiscountList = normalizedNewDiscountList || this.getDiscountList();
780
+ if (!(isAvailable && normalizedNewDiscountList)) {
781
+ _context6.next = 34;
749
782
  break;
750
783
  }
751
- (_this$store$discount12 = this.store.discount) === null || _this$store$discount12 === void 0 || _this$store$discount12.setDiscountList(newDiscountList);
784
+ _context6.next = 28;
785
+ return (_this$store$discount12 = this.store.discount) === null || _this$store$discount12 === void 0 ? void 0 : _this$store$discount12.setDiscountList(normalizedNewDiscountList);
786
+ case 28:
752
787
  this.applyDiscount();
753
- _context6.next = 26;
788
+ _context6.next = 31;
754
789
  return this.syncScannedDiscountsToOriginalDiscountList(this.getDiscountList());
755
- case 26:
790
+ case 31:
791
+ resolvedDiscountList = this.getDiscountList();
792
+ _context6.next = 40;
793
+ break;
794
+ case 34:
795
+ if (!(shouldRetainForLater && retainedDiscountList)) {
796
+ _context6.next = 40;
797
+ break;
798
+ }
799
+ _context6.next = 37;
800
+ return (_this$store$discount13 = this.store.discount) === null || _this$store$discount13 === void 0 ? void 0 : _this$store$discount13.setDiscountList(retainedDiscountList);
801
+ case 37:
802
+ _context6.next = 39;
803
+ return this.syncScannedDiscountsToOriginalDiscountList(this.getDiscountList());
804
+ case 39:
805
+ resolvedDiscountList = this.getDiscountList();
806
+ case 40:
756
807
  return _context6.abrupt("return", {
757
808
  type: 'clientCalc',
758
809
  isAvailable: isAvailable || false,
759
- discountList: newDiscountList || this.getDiscountList(),
810
+ isAccepted: Boolean(isAvailable || shouldRetainForLater),
811
+ discountList: resolvedDiscountList,
760
812
  scannedDiscountList: resultDiscountList,
761
813
  unavailableReason: unavailableReason
762
814
  });
763
- case 27:
815
+ case 41:
764
816
  case "end":
765
817
  return _context6.stop();
766
818
  }
@@ -774,7 +826,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
774
826
  }, {
775
827
  key: "applyDiscount",
776
828
  value: function applyDiscount(options) {
777
- var _this$store$discount13,
829
+ var _this$store$discount14,
778
830
  _this$store$summary2,
779
831
  _this2 = this;
780
832
  var tempOrder = this.store.tempOrder;
@@ -784,7 +836,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
784
836
  if (!tempOrder) return;
785
837
  this.syncLinkedBookingHoldersToProducts(tempOrder);
786
838
  delete tempOrder.discount_list;
787
- var discountList = ((_this$store$discount13 = this.store.discount) === null || _this$store$discount13 === void 0 ? void 0 : _this$store$discount13.getDiscountList()) || [];
839
+ var discountList = ((_this$store$discount14 = this.store.discount) === null || _this$store$discount14 === void 0 ? void 0 : _this$store$discount14.getDiscountList()) || [];
788
840
  var shouldSkipDiscountCalculation = this.shouldSkipDiscountCalculation(tempOrder);
789
841
  if (shouldSkipDiscountCalculation) return;
790
842
  var rulesModule = this.store.rules;
@@ -816,9 +868,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
816
868
  }));
817
869
  }
818
870
  if (result !== null && result !== void 0 && result.discountList) {
819
- var _this$store$discount14;
871
+ var _this$store$discount15;
820
872
  OrderModule.populateSavedAmounts(result.productList || tempOrder.products, result.discountList);
821
- (_this$store$discount14 = this.store.discount) === null || _this$store$discount14 === void 0 || _this$store$discount14.setDiscountList(result.discountList);
873
+ (_this$store$discount15 = this.store.discount) === null || _this$store$discount15 === void 0 || _this$store$discount15.setDiscountList(result.discountList);
822
874
  }
823
875
  this.hasActiveCustomerBoundDiscount = (tempOrder.products || []).some(function (product) {
824
876
  return _this2.productHasCustomerBoundDiscount(product);
@@ -1517,19 +1569,44 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1517
1569
  var depositPaidAmount = this.calculateDepositPaidAmount(tempOrder.payments || []);
1518
1570
  return depositPaidAmount.lt(depositAmount) ? 'deposit' : 'normal';
1519
1571
  }
1572
+ }, {
1573
+ key: "getPaymentNumberAppData",
1574
+ value: function getPaymentNumberAppData(key) {
1575
+ var _appPlugin$getData, _app$models, _app$models$getStore, _app$models$getStore$, _app$models$getStore$2;
1576
+ var appPlugin = this.appPlugin;
1577
+ if (!appPlugin) return undefined;
1578
+ var getData = (_appPlugin$getData = appPlugin.getData) === null || _appPlugin$getData === void 0 ? void 0 : _appPlugin$getData.call(appPlugin);
1579
+ if (typeof getData === 'function') return getData(key);
1580
+ var app = appPlugin.getApp();
1581
+ 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');
1582
+ return coreData === null || coreData === void 0 ? void 0 : coreData[key];
1583
+ }
1584
+ }, {
1585
+ key: "getPaymentNumberDevicePrefixSync",
1586
+ value: function getPaymentNumberDevicePrefixSync() {
1587
+ var _this7 = this;
1588
+ return resolvePaymentNumberDevicePrefixFromDeviceId(function (key) {
1589
+ return _this7.getPaymentNumberAppData(key);
1590
+ });
1591
+ }
1592
+ }, {
1593
+ key: "getPaymentNumberDevicePrefixAsync",
1594
+ value: function getPaymentNumberDevicePrefixAsync() {
1595
+ var _this8 = this;
1596
+ return resolvePaymentNumberDevicePrefix(function (key) {
1597
+ return _this8.getPaymentNumberAppData(key);
1598
+ });
1599
+ }
1520
1600
  }, {
1521
1601
  key: "normalizePaymentSource",
1522
1602
  value: function normalizePaymentSource(payment, options) {
1523
1603
  var _ref19, _paymentRecord$origin;
1524
1604
  var paymentRecord = payment;
1525
1605
  var metadata = paymentRecord.metadata && _typeof(paymentRecord.metadata) === 'object' ? _objectSpread({}, paymentRecord.metadata) : {};
1526
- if (!metadata.unique_payment_number) {
1527
- metadata.unique_payment_number = createUuidV4();
1528
- }
1529
- var normalized = _objectSpread(_objectSpread({}, paymentRecord), {}, {
1606
+ var normalized = ensureOrderPaymentNumber(_objectSpread(_objectSpread({}, paymentRecord), {}, {
1530
1607
  metadata: metadata,
1531
1608
  origin_amount: (_ref19 = (_paymentRecord$origin = paymentRecord.origin_amount) !== null && _paymentRecord$origin !== void 0 ? _paymentRecord$origin : paymentRecord.amount) !== null && _ref19 !== void 0 ? _ref19 : '0.00'
1532
- });
1609
+ }), (options === null || options === void 0 ? void 0 : options.devicePrefix) || this.getPaymentNumberDevicePrefixSync(), createUuidV4);
1533
1610
  if (paymentRecord.status !== undefined) {
1534
1611
  normalized.status = paymentRecord.status;
1535
1612
  } else if ((options === null || options === void 0 ? void 0 : options.defaultPaid) !== false) {
@@ -1647,16 +1724,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1647
1724
  }, {
1648
1725
  key: "calculatePaidPaymentSummary",
1649
1726
  value: function calculatePaidPaymentSummary(payments) {
1650
- var _this7 = this;
1727
+ var _this9 = this;
1651
1728
  return (payments || []).reduce(function (summary, payment) {
1652
1729
  var paymentRecord = payment;
1653
1730
  if (!isPaidPaymentRecord(paymentRecord)) return summary;
1654
1731
  return {
1655
1732
  customerPaidAmount: summary.customerPaidAmount.plus(paymentRecord.amount || 0),
1656
- orderPaidAmount: summary.orderPaidAmount.plus(_this7.calculatePaymentOrderAmount(paymentRecord)),
1657
- gapPaidAmount: summary.gapPaidAmount.plus(_this7.calculatePaymentGapAmount(paymentRecord)),
1658
- payServiceChargeAmount: summary.payServiceChargeAmount.plus(_this7.calculatePaymentServiceFee(paymentRecord)),
1659
- roundingAmount: summary.roundingAmount.plus(_this7.calculatePaymentRoundingAmount(paymentRecord))
1733
+ orderPaidAmount: summary.orderPaidAmount.plus(_this9.calculatePaymentOrderAmount(paymentRecord)),
1734
+ gapPaidAmount: summary.gapPaidAmount.plus(_this9.calculatePaymentGapAmount(paymentRecord)),
1735
+ payServiceChargeAmount: summary.payServiceChargeAmount.plus(_this9.calculatePaymentServiceFee(paymentRecord)),
1736
+ roundingAmount: summary.roundingAmount.plus(_this9.calculatePaymentRoundingAmount(paymentRecord))
1660
1737
  };
1661
1738
  }, {
1662
1739
  customerPaidAmount: new Decimal(0),
@@ -1858,15 +1935,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1858
1935
  }, {
1859
1936
  key: "normalizeFingerprintValue",
1860
1937
  value: function normalizeFingerprintValue(value) {
1861
- var _this8 = this;
1938
+ var _this10 = this;
1862
1939
  if (Array.isArray(value)) {
1863
1940
  return value.map(function (item) {
1864
- return _this8.normalizeFingerprintValue(item);
1941
+ return _this10.normalizeFingerprintValue(item);
1865
1942
  });
1866
1943
  }
1867
1944
  if (!value || _typeof(value) !== 'object') return value !== null && value !== void 0 ? value : '';
1868
1945
  return Object.keys(value).sort().reduce(function (result, key) {
1869
- result[key] = _this8.normalizeFingerprintValue(value[key]);
1946
+ result[key] = _this10.normalizeFingerprintValue(value[key]);
1870
1947
  return result;
1871
1948
  }, {});
1872
1949
  }
@@ -1881,7 +1958,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1881
1958
  _sku$barcode,
1882
1959
  _ref20,
1883
1960
  _sku$variant_id,
1884
- _this9 = this;
1961
+ _this11 = this;
1885
1962
  var sku = (product === null || product === void 0 ? void 0 : product.product_sku) || {};
1886
1963
  var metadata = (product === null || product === void 0 ? void 0 : product.metadata) || {};
1887
1964
  var discountTypes = ((product === null || product === void 0 ? void 0 : product.discount_list) || []).map(function (discount) {
@@ -1915,7 +1992,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1915
1992
  option_group_id: (_option$option_group_ = option === null || option === void 0 ? void 0 : option.option_group_id) !== null && _option$option_group_ !== void 0 ? _option$option_group_ : null,
1916
1993
  option_group_item_id: (_ref22 = (_option$option_group_2 = option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _option$option_group_2 !== void 0 ? _option$option_group_2 : option === null || option === void 0 ? void 0 : option.id) !== null && _ref22 !== void 0 ? _ref22 : null,
1917
1994
  num: Number((_option$num = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num !== void 0 ? _option$num : 1) || 1,
1918
- add_price: _this9.normalizeFingerprintMoney((_option$add_price = option === null || option === void 0 ? void 0 : option.add_price) !== null && _option$add_price !== void 0 ? _option$add_price : option === null || option === void 0 ? void 0 : option.price)
1995
+ add_price: _this11.normalizeFingerprintMoney((_option$add_price = option === null || option === void 0 ? void 0 : option.add_price) !== null && _option$add_price !== void 0 ? _option$add_price : option === null || option === void 0 ? void 0 : option.price)
1919
1996
  };
1920
1997
  })
1921
1998
  }),
@@ -1925,8 +2002,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1925
2002
  bundle_product_id: (_ref23 = (_ref24 = (_bundle$bundle_produc = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_product_id) !== null && _bundle$bundle_produc !== void 0 ? _bundle$bundle_produc : bundle === null || bundle === void 0 ? void 0 : bundle._bundle_product_id) !== null && _ref24 !== void 0 ? _ref24 : bundle === null || bundle === void 0 ? void 0 : bundle.product_id) !== null && _ref23 !== void 0 ? _ref23 : null,
1926
2003
  bundle_variant_id: (_ref25 = (_bundle$bundle_varian = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_variant_id) !== null && _bundle$bundle_varian !== void 0 ? _bundle$bundle_varian : bundle === null || bundle === void 0 ? void 0 : bundle.product_variant_id) !== null && _ref25 !== void 0 ? _ref25 : 0,
1927
2004
  num: getSafeProductNum((_bundle$num = bundle === null || bundle === void 0 ? void 0 : bundle.num) !== null && _bundle$num !== void 0 ? _bundle$num : bundle === null || bundle === void 0 ? void 0 : bundle.quantity),
1928
- price: _this9.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.price),
1929
- bundle_selling_price: _this9.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.bundle_selling_price),
2005
+ price: _this11.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.price),
2006
+ bundle_selling_price: _this11.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.bundle_selling_price),
1930
2007
  price_type: (_bundle$price_type = bundle === null || bundle === void 0 ? void 0 : bundle.price_type) !== null && _bundle$price_type !== void 0 ? _bundle$price_type : '',
1931
2008
  price_type_ext: (_bundle$price_type_ex = bundle === null || bundle === void 0 ? void 0 : bundle.price_type_ext) !== null && _bundle$price_type_ex !== void 0 ? _bundle$price_type_ex : ''
1932
2009
  };
@@ -1936,7 +2013,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1936
2013
  return {
1937
2014
  type: (_ref26 = (_discount$type2 = discount === null || discount === void 0 ? void 0 : discount.type) !== null && _discount$type2 !== void 0 ? _discount$type2 : discount === null || discount === void 0 ? void 0 : discount.tag) !== null && _ref26 !== void 0 ? _ref26 : '',
1938
2015
  discount_id: (_ref27 = (_ref28 = (_discount$discount_id = discount === null || discount === void 0 ? void 0 : discount.discount_id) !== null && _discount$discount_id !== void 0 ? _discount$discount_id : discount === null || discount === void 0 ? void 0 : discount.order_discount_id) !== null && _ref28 !== void 0 ? _ref28 : discount === null || discount === void 0 || (_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) !== null && _ref27 !== void 0 ? _ref27 : null,
1939
- amount: _this9.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
2016
+ amount: _this11.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
1940
2017
  };
1941
2018
  }))
1942
2019
  };
@@ -1944,9 +2021,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1944
2021
  }, {
1945
2022
  key: "buildOrderProductsFingerprint",
1946
2023
  value: function buildOrderProductsFingerprint(products) {
1947
- var _this10 = this;
2024
+ var _this12 = this;
1948
2025
  var items = (products || []).map(function (product) {
1949
- return _this10.buildProductFingerprintItem(product);
2026
+ return _this12.buildProductFingerprintItem(product);
1950
2027
  });
1951
2028
  items.sort(function (left, right) {
1952
2029
  return JSON.stringify(left).localeCompare(JSON.stringify(right));
@@ -1968,7 +2045,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1968
2045
  _sku$barcode2,
1969
2046
  _ref30,
1970
2047
  _sku$variant_id2,
1971
- _this11 = this;
2048
+ _this13 = this;
1972
2049
  var sku = (product === null || product === void 0 ? void 0 : product.product_sku) || {};
1973
2050
  var metadata = (product === null || product === void 0 ? void 0 : product.metadata) || {};
1974
2051
  var discountTypes = ((product === null || product === void 0 ? void 0 : product.discount_list) || []).map(function (discount) {
@@ -1999,7 +2076,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1999
2076
  option_group_id: (_option$option_group_3 = option === null || option === void 0 ? void 0 : option.option_group_id) !== null && _option$option_group_3 !== void 0 ? _option$option_group_3 : null,
2000
2077
  option_group_item_id: (_ref32 = (_option$option_group_4 = option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _option$option_group_4 !== void 0 ? _option$option_group_4 : option === null || option === void 0 ? void 0 : option.id) !== null && _ref32 !== void 0 ? _ref32 : null,
2001
2078
  num: Number((_option$num2 = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num2 !== void 0 ? _option$num2 : 1) || 1,
2002
- add_price: _this11.normalizeFingerprintMoney((_option$add_price2 = option === null || option === void 0 ? void 0 : option.add_price) !== null && _option$add_price2 !== void 0 ? _option$add_price2 : option === null || option === void 0 ? void 0 : option.price)
2079
+ add_price: _this13.normalizeFingerprintMoney((_option$add_price2 = option === null || option === void 0 ? void 0 : option.add_price) !== null && _option$add_price2 !== void 0 ? _option$add_price2 : option === null || option === void 0 ? void 0 : option.price)
2003
2080
  };
2004
2081
  })
2005
2082
  }),
@@ -2013,14 +2090,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2013
2090
  num: getSafeProductNum((_bundle$num2 = bundle === null || bundle === void 0 ? void 0 : bundle.num) !== null && _bundle$num2 !== void 0 ? _bundle$num2 : bundle === null || bundle === void 0 ? void 0 : bundle.quantity),
2014
2091
  price_type: (_bundle$price_type2 = bundle === null || bundle === void 0 ? void 0 : bundle.price_type) !== null && _bundle$price_type2 !== void 0 ? _bundle$price_type2 : '',
2015
2092
  price_type_ext: (_bundle$price_type_ex2 = bundle === null || bundle === void 0 ? void 0 : bundle.price_type_ext) !== null && _bundle$price_type_ex2 !== void 0 ? _bundle$price_type_ex2 : '',
2016
- option: _this11.normalizeFingerprintValue(((bundle === null || bundle === void 0 ? void 0 : bundle.option) || []).map(function (option) {
2093
+ option: _this13.normalizeFingerprintValue(((bundle === null || bundle === void 0 ? void 0 : bundle.option) || []).map(function (option) {
2017
2094
  var _ref38, _option$id3, _option$option_group_5, _ref39, _option$option_group_6, _option$num3, _option$add_price3;
2018
2095
  return {
2019
2096
  id: (_ref38 = (_option$id3 = option === null || option === void 0 ? void 0 : option.id) !== null && _option$id3 !== void 0 ? _option$id3 : option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _ref38 !== void 0 ? _ref38 : null,
2020
2097
  option_group_id: (_option$option_group_5 = option === null || option === void 0 ? void 0 : option.option_group_id) !== null && _option$option_group_5 !== void 0 ? _option$option_group_5 : null,
2021
2098
  option_group_item_id: (_ref39 = (_option$option_group_6 = option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _option$option_group_6 !== void 0 ? _option$option_group_6 : option === null || option === void 0 ? void 0 : option.id) !== null && _ref39 !== void 0 ? _ref39 : null,
2022
2099
  num: Number((_option$num3 = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num3 !== void 0 ? _option$num3 : 1) || 1,
2023
- add_price: _this11.normalizeFingerprintMoney((_option$add_price3 = option === null || option === void 0 ? void 0 : option.add_price) !== null && _option$add_price3 !== void 0 ? _option$add_price3 : option === null || option === void 0 ? void 0 : option.price)
2100
+ add_price: _this13.normalizeFingerprintMoney((_option$add_price3 = option === null || option === void 0 ? void 0 : option.add_price) !== null && _option$add_price3 !== void 0 ? _option$add_price3 : option === null || option === void 0 ? void 0 : option.price)
2024
2101
  };
2025
2102
  }))
2026
2103
  };
@@ -2030,7 +2107,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2030
2107
  return {
2031
2108
  type: (_ref40 = (_discount$type4 = discount === null || discount === void 0 ? void 0 : discount.type) !== null && _discount$type4 !== void 0 ? _discount$type4 : discount === null || discount === void 0 ? void 0 : discount.tag) !== null && _ref40 !== void 0 ? _ref40 : '',
2032
2109
  discount_id: (_ref41 = (_ref42 = (_discount$discount_id2 = discount === null || discount === void 0 ? void 0 : discount.discount_id) !== null && _discount$discount_id2 !== void 0 ? _discount$discount_id2 : discount === null || discount === void 0 ? void 0 : discount.order_discount_id) !== null && _ref42 !== void 0 ? _ref42 : discount === null || discount === void 0 || (_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.resource_id) !== null && _ref41 !== void 0 ? _ref41 : null,
2033
- amount: _this11.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
2110
+ amount: _this13.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
2034
2111
  };
2035
2112
  }))
2036
2113
  };
@@ -2038,9 +2115,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2038
2115
  }, {
2039
2116
  key: "buildOrderProductsStructuralFingerprint",
2040
2117
  value: function buildOrderProductsStructuralFingerprint(products) {
2041
- var _this12 = this;
2118
+ var _this14 = this;
2042
2119
  var items = (products || []).map(function (product) {
2043
- return _this12.buildProductStructuralFingerprintItem(product);
2120
+ return _this14.buildProductStructuralFingerprintItem(product);
2044
2121
  });
2045
2122
  items.sort(function (left, right) {
2046
2123
  return JSON.stringify(left).localeCompare(JSON.stringify(right));
@@ -2257,7 +2334,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2257
2334
  }, {
2258
2335
  key: "restoreOrder",
2259
2336
  value: function restoreOrder() {
2260
- var _this$store$discount15, _this$store$discount16;
2337
+ var _this$store$discount16, _this$store$discount17;
2261
2338
  this.logInfo('restoreOrder start', {});
2262
2339
  var freshTempOrder = this.createDefaultTempOrderInstance();
2263
2340
  this.ensureExternalSaleNumber(freshTempOrder);
@@ -2265,8 +2342,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2265
2342
  this.store.summary = createEmptySummary();
2266
2343
  this.store.lastOrderInfo = undefined;
2267
2344
  this.store.syncState = undefined;
2268
- void ((_this$store$discount15 = this.store.discount) === null || _this$store$discount15 === void 0 ? void 0 : _this$store$discount15.setOriginalDiscountList([]));
2269
- void ((_this$store$discount16 = this.store.discount) === null || _this$store$discount16 === void 0 ? void 0 : _this$store$discount16.setDiscountList([]));
2345
+ void ((_this$store$discount16 = this.store.discount) === null || _this$store$discount16 === void 0 ? void 0 : _this$store$discount16.setOriginalDiscountList([]));
2346
+ void ((_this$store$discount17 = this.store.discount) === null || _this$store$discount17 === void 0 ? void 0 : _this$store$discount17.setDiscountList([]));
2270
2347
  this.persistTempOrder();
2271
2348
  return freshTempOrder;
2272
2349
  }
@@ -2468,9 +2545,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2468
2545
  }, {
2469
2546
  key: "sanitizeTempOrderProducts",
2470
2547
  value: function sanitizeTempOrderProducts(tempOrder) {
2471
- var _this13 = this;
2548
+ var _this15 = this;
2472
2549
  tempOrder.products = (tempOrder.products || []).map(function (product) {
2473
- return _this13.sanitizeOrderProductForTempOrder(product);
2550
+ return _this15.sanitizeOrderProductForTempOrder(product);
2474
2551
  });
2475
2552
  }
2476
2553
  }, {
@@ -2573,7 +2650,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2573
2650
  }, {
2574
2651
  key: "syncLinkedBookingHoldersToProducts",
2575
2652
  value: function syncLinkedBookingHoldersToProducts(tempOrder) {
2576
- var _this14 = this;
2653
+ var _this16 = this;
2577
2654
  var bookings = tempOrder.bookings || [];
2578
2655
  var products = tempOrder.products || [];
2579
2656
  if (!bookings.length || !products.length) return;
@@ -2598,7 +2675,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2598
2675
  var bookingUid = product.booking_uid || ((_product$metadata6 = product.metadata) === null || _product$metadata6 === void 0 ? void 0 : _product$metadata6.booking_uid);
2599
2676
  var linkedBooking = (productUid !== undefined && productUid !== null && String(productUid) !== '' ? bookingByProductUid.get(String(productUid)) : undefined) || (bookingUid !== undefined && bookingUid !== null && String(bookingUid) !== '' ? bookingByBookingUid.get(String(bookingUid)) : undefined);
2600
2677
  if (linkedBooking) {
2601
- _this14.setProductHolderFromBooking(product, linkedBooking);
2678
+ _this16.setProductHolderFromBooking(product, linkedBooking);
2602
2679
  }
2603
2680
  });
2604
2681
  }
@@ -2726,9 +2803,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2726
2803
  }, {
2727
2804
  key: "findBookingIndexByUniqueIdentificationNumber",
2728
2805
  value: function findBookingIndexByUniqueIdentificationNumber(tempOrder, uniqueIdentificationNumber) {
2729
- var _this15 = this;
2806
+ var _this17 = this;
2730
2807
  return (tempOrder.bookings || []).findIndex(function (booking) {
2731
- return _this15.getBookingUniqueIdentificationNumber(booking) === uniqueIdentificationNumber;
2808
+ return _this17.getBookingUniqueIdentificationNumber(booking) === uniqueIdentificationNumber;
2732
2809
  });
2733
2810
  }
2734
2811
  }, {
@@ -2736,12 +2813,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2736
2813
  value: function removeLinkedBookingsForProduct(tempOrder, product) {
2737
2814
  var _product$metadata7,
2738
2815
  _product$metadata8,
2739
- _this16 = this;
2816
+ _this18 = this;
2740
2817
  var productUid = (product === null || product === void 0 || (_product$metadata7 = product.metadata) === null || _product$metadata7 === void 0 ? void 0 : _product$metadata7.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
2741
2818
  var bookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_product$metadata8 = product.metadata) === null || _product$metadata8 === void 0 ? void 0 : _product$metadata8.booking_uid);
2742
2819
  if (!productUid && !bookingUid) return;
2743
2820
  tempOrder.bookings = (tempOrder.bookings || []).filter(function (booking) {
2744
- var currentBookingUid = _this16.getBookingUniqueIdentificationNumber(booking);
2821
+ var currentBookingUid = _this18.getBookingUniqueIdentificationNumber(booking);
2745
2822
  if (bookingUid && currentBookingUid === String(bookingUid)) return false;
2746
2823
  if (productUid && String((booking === null || booking === void 0 ? void 0 : booking.product_uid) || '') === String(productUid)) return false;
2747
2824
  return true;
@@ -3074,35 +3151,35 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3074
3151
  }, {
3075
3152
  key: "productHasCustomerBoundDiscount",
3076
3153
  value: function productHasCustomerBoundDiscount(product) {
3077
- var _this17 = this;
3154
+ var _this19 = this;
3078
3155
  if (((product === null || product === void 0 ? void 0 : product.discount_list) || []).some(function (discount) {
3079
- return _this17.isCustomerBoundDiscount(discount);
3156
+ return _this19.isCustomerBoundDiscount(discount);
3080
3157
  })) {
3081
3158
  return true;
3082
3159
  }
3083
3160
  return ((product === null || product === void 0 ? void 0 : product.product_bundle) || []).some(function (bundle) {
3084
3161
  return ((bundle === null || bundle === void 0 ? void 0 : bundle.discount_list) || []).some(function (discount) {
3085
- return _this17.isCustomerBoundDiscount(discount);
3162
+ return _this19.isCustomerBoundDiscount(discount);
3086
3163
  });
3087
3164
  });
3088
3165
  }
3089
3166
  }, {
3090
3167
  key: "shouldSkipDiscountCalculation",
3091
3168
  value: function shouldSkipDiscountCalculation(tempOrder) {
3092
- var _this$store$discount17,
3093
- _this$store$discount18,
3094
- _this18 = this;
3169
+ var _this$store$discount18,
3170
+ _this$store$discount19,
3171
+ _this20 = this;
3095
3172
  if (this.hasActiveCustomerBoundDiscount) return false;
3096
- var discountList = ((_this$store$discount17 = this.store.discount) === null || _this$store$discount17 === void 0 || (_this$store$discount18 = _this$store$discount17.getDiscountList) === null || _this$store$discount18 === void 0 ? void 0 : _this$store$discount18.call(_this$store$discount17)) || [];
3173
+ var discountList = ((_this$store$discount18 = this.store.discount) === null || _this$store$discount18 === void 0 || (_this$store$discount19 = _this$store$discount18.getDiscountList) === null || _this$store$discount19 === void 0 ? void 0 : _this$store$discount19.call(_this$store$discount18)) || [];
3097
3174
  if (discountList.length > 0) return false;
3098
3175
  return !(tempOrder.products || []).some(function (product) {
3099
- return _this18.productHasCustomerBoundDiscount(product);
3176
+ return _this20.productHasCustomerBoundDiscount(product);
3100
3177
  });
3101
3178
  }
3102
3179
  }, {
3103
3180
  key: "clearCustomerBoundDiscounts",
3104
3181
  value: function clearCustomerBoundDiscounts(tempOrder) {
3105
- var _this19 = this,
3182
+ var _this21 = this,
3106
3183
  _discountModule$getDi,
3107
3184
  _discountModule$getOr,
3108
3185
  _discountModule$setDi,
@@ -3111,7 +3188,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3111
3188
  var filterDiscountList = function filterDiscountList(discountList) {
3112
3189
  if (!Array.isArray(discountList)) return [];
3113
3190
  return discountList.filter(function (discount) {
3114
- var shouldRemove = _this19.isCustomerBoundDiscount(discount);
3191
+ var shouldRemove = _this21.isCustomerBoundDiscount(discount);
3115
3192
  if (shouldRemove) didRemoveCustomerBoundDiscount = true;
3116
3193
  return !shouldRemove;
3117
3194
  });
@@ -3138,12 +3215,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3138
3215
  var currentDiscounts = ((_discountModule$getDi = discountModule.getDiscountList) === null || _discountModule$getDi === void 0 ? void 0 : _discountModule$getDi.call(discountModule)) || [];
3139
3216
  var currentOriginalDiscounts = ((_discountModule$getOr = discountModule.getOriginalDiscountList) === null || _discountModule$getOr === void 0 ? void 0 : _discountModule$getOr.call(discountModule)) || [];
3140
3217
  var nextDiscounts = currentDiscounts.filter(function (discount) {
3141
- if (_this19.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount)) return true;
3142
- return !_this19.isCustomerBoundDiscount(discount);
3218
+ if (_this21.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount)) return true;
3219
+ return !_this21.isCustomerBoundDiscount(discount);
3143
3220
  });
3144
3221
  var nextOriginalDiscounts = currentOriginalDiscounts.filter(function (discount) {
3145
- if (_this19.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount)) return true;
3146
- return !_this19.isCustomerBoundDiscount(discount);
3222
+ if (_this21.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount)) return true;
3223
+ return !_this21.isCustomerBoundDiscount(discount);
3147
3224
  });
3148
3225
  void ((_discountModule$setDi = discountModule.setDiscountList) === null || _discountModule$setDi === void 0 ? void 0 : _discountModule$setDi.call(discountModule, nextDiscounts));
3149
3226
  void ((_discountModule$setOr = discountModule.setOriginalDiscountList) === null || _discountModule$setOr === void 0 ? void 0 : _discountModule$setOr.call(discountModule, nextOriginalDiscounts));
@@ -3297,23 +3374,71 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3297
3374
  * 用一组支付来源覆盖当前订单支付项。
3298
3375
  *
3299
3376
  * 入参允许来自 PaymentModule 的 PaymentItem,内部统一映射为 Sales 协议:
3300
- * uuid -> metadata.unique_payment_number,id -> custom_payment_id,
3377
+ * 新支付来源的 uuid 会作为 payment_number 的唯一号段,id -> custom_payment_id,
3301
3378
  * isSynced 等运行态字段不会进入 tempOrder.payments。
3302
3379
  */
3303
3380
  }, {
3304
3381
  key: "setOrderPayments",
3305
3382
  value: function setOrderPayments(payments) {
3383
+ var _this22 = this;
3306
3384
  var tempOrder = this.ensureTempOrder();
3307
- tempOrder.payments = mapPaymentItemsToOrderPayments(payments);
3385
+ tempOrder.payments = mapPaymentItemsToOrderPayments((payments || []).map(function (payment) {
3386
+ return _this22.normalizePaymentSource(payment, {
3387
+ defaultPaid: false
3388
+ });
3389
+ }));
3308
3390
  this.persistTempOrder();
3309
3391
  return tempOrder.payments;
3310
3392
  }
3311
3393
 
3312
- /** 追加单个支付项,并立即持久化当前 tempOrder。 */
3394
+ /** 同步兼容入口:按调用当下的 device_id 或 LOCAL 生成支付编号。 */
3313
3395
  }, {
3314
3396
  key: "addOrderPayment",
3315
3397
  value: function addOrderPayment(payment) {
3316
- var _this20 = this;
3398
+ var hasPaymentNumber = String(payment.payment_number || '').trim() !== '';
3399
+ return this.addOrderPaymentWithDevicePrefix(payment, hasPaymentNumber ? 'LOCAL' : this.getPaymentNumberDevicePrefixSync());
3400
+ }
3401
+
3402
+ /** 异步入口:创建支付项时读取最新 IoT 设备短号。 */
3403
+ }, {
3404
+ key: "addOrderPaymentAsync",
3405
+ value: (function () {
3406
+ var _addOrderPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(payment) {
3407
+ var hasPaymentNumber, devicePrefix;
3408
+ return _regeneratorRuntime().wrap(function _callee15$(_context17) {
3409
+ while (1) switch (_context17.prev = _context17.next) {
3410
+ case 0:
3411
+ hasPaymentNumber = String(payment.payment_number || '').trim() !== '';
3412
+ if (!hasPaymentNumber) {
3413
+ _context17.next = 5;
3414
+ break;
3415
+ }
3416
+ _context17.t0 = 'LOCAL';
3417
+ _context17.next = 8;
3418
+ break;
3419
+ case 5:
3420
+ _context17.next = 7;
3421
+ return this.getPaymentNumberDevicePrefixAsync();
3422
+ case 7:
3423
+ _context17.t0 = _context17.sent;
3424
+ case 8:
3425
+ devicePrefix = _context17.t0;
3426
+ return _context17.abrupt("return", this.addOrderPaymentWithDevicePrefix(payment, devicePrefix));
3427
+ case 10:
3428
+ case "end":
3429
+ return _context17.stop();
3430
+ }
3431
+ }, _callee15, this);
3432
+ }));
3433
+ function addOrderPaymentAsync(_x14) {
3434
+ return _addOrderPaymentAsync.apply(this, arguments);
3435
+ }
3436
+ return addOrderPaymentAsync;
3437
+ }())
3438
+ }, {
3439
+ key: "addOrderPaymentWithDevicePrefix",
3440
+ value: function addOrderPaymentWithDevicePrefix(payment, devicePrefix) {
3441
+ var _this23 = this;
3317
3442
  this.logInfo('addOrderPayment', {
3318
3443
  payment: payment
3319
3444
  });
@@ -3323,14 +3448,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3323
3448
  type: orderPaymentType,
3324
3449
  order_payment_type: orderPaymentType
3325
3450
  }), {
3326
- defaultPaid: true
3451
+ defaultPaid: true,
3452
+ devicePrefix: devicePrefix
3327
3453
  })]);
3328
3454
  tempOrder.payments = [].concat(_toConsumableArray(tempOrder.payments || []), _toConsumableArray(mapped));
3329
3455
  this.persistTempOrder();
3330
3456
  void this.recalculateSummary({
3331
3457
  createIfMissing: true
3332
3458
  }).catch(function (error) {
3333
- _this20.logError('recalculate summary after addOrderPayment failed', {
3459
+ _this23.logError('recalculate summary after addOrderPayment failed', {
3334
3460
  error: error instanceof Error ? error.message : String(error)
3335
3461
  });
3336
3462
  });
@@ -3338,49 +3464,80 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3338
3464
  }
3339
3465
 
3340
3466
  /**
3341
- * 按支付唯一号、后端支付 ID、自定义支付方式 ID 或旧 uuid 更新支付项。
3342
- *
3343
- * 该方法服务 PaymentModal 的 void / 编辑场景;更新 metadata 时会做浅合并,
3344
- * 避免覆盖 unique_payment_number、现金实付/找零等已有元数据。
3467
+ * 默认按支付唯一号精确更新;仅显式指定 legacy 时兼容历史支付标识。
3468
+ * metadata 与 transactions 会分别合并,避免覆盖支付会话号和已有交易记录。
3345
3469
  */
3346
3470
  }, {
3347
3471
  key: "updateOrderPayment",
3348
- value: function updateOrderPayment(paymentIdentity, updates) {
3349
- var tempOrder = this.ensureTempOrder();
3350
- var identity = String(paymentIdentity);
3351
- tempOrder.payments = (tempOrder.payments || []).map(function (payment) {
3352
- var _payment$metadata;
3353
- var uniquePaymentNumber = payment === null || payment === void 0 || (_payment$metadata = payment.metadata) === null || _payment$metadata === void 0 ? void 0 : _payment$metadata.unique_payment_number;
3354
- var orderPaymentId = payment === null || payment === void 0 ? void 0 : payment.order_payment_id;
3355
- var customPaymentId = payment === null || payment === void 0 ? void 0 : payment.custom_payment_id;
3356
- var uuid = payment === null || payment === void 0 ? void 0 : payment.uuid;
3357
- var matched = [uniquePaymentNumber, orderPaymentId, customPaymentId, uuid].some(function (value) {
3358
- return value !== undefined && String(value) === identity;
3359
- });
3360
- if (!matched) return payment;
3361
- return _objectSpread(_objectSpread(_objectSpread({}, payment), updates), {}, {
3362
- metadata: _objectSpread(_objectSpread({}, payment.metadata || {}), updates.metadata || {})
3363
- });
3364
- });
3365
- this.persistTempOrder();
3366
- return tempOrder.payments;
3367
- }
3368
-
3369
- /** 从当前订单支付项中移除指定支付项。 */
3472
+ value: (function () {
3473
+ var _updateOrderPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(paymentIdentity, updates) {
3474
+ var options,
3475
+ tempOrder,
3476
+ identity,
3477
+ matchMode,
3478
+ matchedPayment,
3479
+ updatedPayment,
3480
+ summary,
3481
+ payments,
3482
+ _args18 = arguments;
3483
+ return _regeneratorRuntime().wrap(function _callee16$(_context18) {
3484
+ while (1) switch (_context18.prev = _context18.next) {
3485
+ case 0:
3486
+ options = _args18.length > 2 && _args18[2] !== undefined ? _args18[2] : {};
3487
+ tempOrder = this.ensureTempOrder();
3488
+ identity = String(paymentIdentity);
3489
+ matchMode = options.matchBy === 'compat' || options.matchBy === 'legacy' ? 'compat' : 'payment_number';
3490
+ matchedPayment = resolveOrderPaymentIdentity(tempOrder.payments || [], identity, matchMode);
3491
+ if (matchedPayment) {
3492
+ _context18.next = 7;
3493
+ break;
3494
+ }
3495
+ throw new Error("\u672A\u627E\u5230\u652F\u4ED8\u9879: ".concat(identity));
3496
+ case 7:
3497
+ updatedPayment = null;
3498
+ tempOrder.payments = (tempOrder.payments || []).map(function (payment, index) {
3499
+ if (index !== matchedPayment.index) return payment;
3500
+ var nextPayment = mergeOrderPaymentRecord(payment, _objectSpread(_objectSpread({}, updates), {}, {
3501
+ updated_at: updates.updated_at || dayjs().format('YYYY-MM-DD HH:mm:ss')
3502
+ }));
3503
+ updatedPayment = nextPayment;
3504
+ return nextPayment;
3505
+ });
3506
+ this.persistTempOrder();
3507
+ _context18.next = 12;
3508
+ return this.recalculateSummary({
3509
+ createIfMissing: true
3510
+ });
3511
+ case 12:
3512
+ summary = _context18.sent;
3513
+ this.persistTempOrder();
3514
+ payments = tempOrder.payments;
3515
+ return _context18.abrupt("return", {
3516
+ updated: true,
3517
+ payment: payments[matchedPayment.index] || updatedPayment,
3518
+ payments: payments,
3519
+ summary: summary
3520
+ });
3521
+ case 16:
3522
+ case "end":
3523
+ return _context18.stop();
3524
+ }
3525
+ }, _callee16, this);
3526
+ }));
3527
+ function updateOrderPayment(_x15, _x16) {
3528
+ return _updateOrderPayment.apply(this, arguments);
3529
+ }
3530
+ return updateOrderPayment;
3531
+ }() /** 从当前订单支付项中移除指定支付项。 */)
3370
3532
  }, {
3371
3533
  key: "deleteOrderPayment",
3372
3534
  value: function deleteOrderPayment(paymentIdentity) {
3373
3535
  var tempOrder = this.ensureTempOrder();
3374
3536
  var identity = String(paymentIdentity);
3375
- tempOrder.payments = (tempOrder.payments || []).filter(function (payment) {
3376
- var _payment$metadata2;
3377
- var uniquePaymentNumber = payment === null || payment === void 0 || (_payment$metadata2 = payment.metadata) === null || _payment$metadata2 === void 0 ? void 0 : _payment$metadata2.unique_payment_number;
3378
- var orderPaymentId = payment === null || payment === void 0 ? void 0 : payment.order_payment_id;
3379
- var customPaymentId = payment === null || payment === void 0 ? void 0 : payment.custom_payment_id;
3380
- var uuid = payment === null || payment === void 0 ? void 0 : payment.uuid;
3381
- return ![uniquePaymentNumber, orderPaymentId, customPaymentId, uuid].some(function (value) {
3382
- return value !== undefined && String(value) === identity;
3383
- });
3537
+ var matchedPayment = resolveOrderPaymentIdentity(tempOrder.payments || [], identity, 'compat');
3538
+ if (!matchedPayment) return tempOrder.payments;
3539
+ tempOrder.payments = (tempOrder.payments || []).filter(function (_, index) {
3540
+ return index !== matchedPayment.index;
3384
3541
  });
3385
3542
  this.persistTempOrder();
3386
3543
  return tempOrder.payments;
@@ -3412,7 +3569,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3412
3569
  }, {
3413
3570
  key: "applyPaymentLifecycleChange",
3414
3571
  value: function applyPaymentLifecycleChange(tempOrder, options) {
3415
- var _this21 = this;
3572
+ var _this24 = this;
3416
3573
  this.updateTempOrderPaymentStatus(tempOrder);
3417
3574
  if ((options === null || options === void 0 ? void 0 : options.persist) !== false) {
3418
3575
  this.persistTempOrder();
@@ -3422,7 +3579,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3422
3579
  void this.recalculateSummary({
3423
3580
  createIfMissing: true
3424
3581
  }).catch(function (error) {
3425
- _this21.logError("recalculate summary after ".concat(logContext, " failed"), {
3582
+ _this24.logError("recalculate summary after ".concat(logContext, " failed"), {
3426
3583
  error: error instanceof Error ? error.message : String(error)
3427
3584
  });
3428
3585
  });
@@ -3466,7 +3623,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3466
3623
  }, {
3467
3624
  key: "updateVoucherOrderPayments",
3468
3625
  value: function updateVoucherOrderPayments(payments, options) {
3469
- var _this22 = this;
3626
+ var _this25 = this;
3470
3627
  var tempOrder = this.ensureTempOrder();
3471
3628
  var isOrderPaymentType = function isOrderPaymentType(value) {
3472
3629
  return value === 'normal' || value === 'deposit';
@@ -3501,8 +3658,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3501
3658
  });
3502
3659
  };
3503
3660
  var mappedVouchers = mapPaymentItemsToOrderPayments(payments.map(function (payment) {
3504
- return _this22.normalizePaymentSource(normalizeVoucherPaymentStatus(withVoucherPaymentType(payment)), {
3505
- defaultPaid: false
3661
+ return _this25.normalizePaymentSource(normalizeVoucherPaymentStatus(withVoucherPaymentType(payment)), {
3662
+ defaultPaid: false,
3663
+ devicePrefix: options === null || options === void 0 ? void 0 : options.devicePrefix
3506
3664
  });
3507
3665
  })).filter(function (payment) {
3508
3666
  return isVoucherPaymentRecord(payment);
@@ -3528,14 +3686,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3528
3686
  }).map(function (payment) {
3529
3687
  return String(payment.order_payment_id);
3530
3688
  }));
3531
- var committedVoucherIds = new Set(committedVoucherPayments.map(function (payment) {
3532
- return String(payment.voucher_id);
3689
+ var committedVoucherLifecycleKeys = new Set(committedVoucherPayments.map(function (payment) {
3690
+ return getVoucherPaymentLifecycleKey(payment);
3691
+ }).filter(function (key) {
3692
+ return key !== null;
3533
3693
  }));
3534
3694
  var replaceableVouchers = mappedVouchers.filter(function (payment) {
3535
3695
  if (hasSyncedOrderPaymentRecord(payment) && committedVoucherPaymentIds.has(String(payment.order_payment_id))) {
3536
3696
  return false;
3537
3697
  }
3538
- if (payment.voucher_id !== undefined && committedVoucherIds.has(String(payment.voucher_id))) {
3698
+ var lifecycleKey = getVoucherPaymentLifecycleKey(payment);
3699
+ if (lifecycleKey && committedVoucherLifecycleKeys.has(lifecycleKey)) {
3539
3700
  return false;
3540
3701
  }
3541
3702
  return true;
@@ -3550,54 +3711,93 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3550
3711
  void this.recalculateSummary({
3551
3712
  createIfMissing: true
3552
3713
  }).catch(function (error) {
3553
- _this22.logError('recalculate summary after updateVoucherOrderPayments failed', {
3714
+ _this25.logError('recalculate summary after updateVoucherOrderPayments failed', {
3554
3715
  error: error instanceof Error ? error.message : String(error)
3555
3716
  });
3556
3717
  });
3557
3718
  return tempOrder.payments;
3558
3719
  }
3720
+ }, {
3721
+ key: "updateVoucherOrderPaymentsAsync",
3722
+ value: function () {
3723
+ var _updateVoucherOrderPaymentsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(payments, options) {
3724
+ var needsPaymentNumber, devicePrefix;
3725
+ return _regeneratorRuntime().wrap(function _callee17$(_context19) {
3726
+ while (1) switch (_context19.prev = _context19.next) {
3727
+ case 0:
3728
+ needsPaymentNumber = (payments || []).some(function (payment) {
3729
+ return String(payment.payment_number || '').trim() === '';
3730
+ });
3731
+ if (!needsPaymentNumber) {
3732
+ _context19.next = 7;
3733
+ break;
3734
+ }
3735
+ _context19.next = 4;
3736
+ return this.getPaymentNumberDevicePrefixAsync();
3737
+ case 4:
3738
+ _context19.t0 = _context19.sent;
3739
+ _context19.next = 8;
3740
+ break;
3741
+ case 7:
3742
+ _context19.t0 = 'LOCAL';
3743
+ case 8:
3744
+ devicePrefix = _context19.t0;
3745
+ return _context19.abrupt("return", this.updateVoucherOrderPayments(payments, _objectSpread(_objectSpread({}, options), {}, {
3746
+ devicePrefix: devicePrefix
3747
+ })));
3748
+ case 10:
3749
+ case "end":
3750
+ return _context19.stop();
3751
+ }
3752
+ }, _callee17, this);
3753
+ }));
3754
+ function updateVoucherOrderPaymentsAsync(_x17, _x18) {
3755
+ return _updateVoucherOrderPaymentsAsync.apply(this, arguments);
3756
+ }
3757
+ return updateVoucherOrderPaymentsAsync;
3758
+ }()
3559
3759
  }, {
3560
3760
  key: "shouldMergeProductToOrder",
3561
3761
  value: function () {
3562
- var _shouldMergeProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(params) {
3762
+ var _shouldMergeProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(params) {
3563
3763
  var _this$orderHooks;
3564
3764
  var onBeforeMergeProductToOrder, result;
3565
- return _regeneratorRuntime().wrap(function _callee15$(_context17) {
3566
- while (1) switch (_context17.prev = _context17.next) {
3765
+ return _regeneratorRuntime().wrap(function _callee18$(_context20) {
3766
+ while (1) switch (_context20.prev = _context20.next) {
3567
3767
  case 0:
3568
3768
  onBeforeMergeProductToOrder = (_this$orderHooks = this.orderHooks) === null || _this$orderHooks === void 0 ? void 0 : _this$orderHooks.onBeforeMergeProductToOrder;
3569
3769
  if (onBeforeMergeProductToOrder) {
3570
- _context17.next = 3;
3770
+ _context20.next = 3;
3571
3771
  break;
3572
3772
  }
3573
- return _context17.abrupt("return", true);
3773
+ return _context20.abrupt("return", true);
3574
3774
  case 3:
3575
- _context17.next = 5;
3775
+ _context20.next = 5;
3576
3776
  return onBeforeMergeProductToOrder(_objectSpread(_objectSpread({}, params), {}, {
3577
3777
  defaultShouldMerge: true
3578
3778
  }));
3579
3779
  case 5:
3580
- result = _context17.sent;
3780
+ result = _context20.sent;
3581
3781
  if (!(typeof result === 'boolean')) {
3582
- _context17.next = 8;
3782
+ _context20.next = 8;
3583
3783
  break;
3584
3784
  }
3585
- return _context17.abrupt("return", result);
3785
+ return _context20.abrupt("return", result);
3586
3786
  case 8:
3587
3787
  if (!(result && _typeof(result) === 'object' && typeof result.shouldMerge === 'boolean')) {
3588
- _context17.next = 10;
3788
+ _context20.next = 10;
3589
3789
  break;
3590
3790
  }
3591
- return _context17.abrupt("return", result.shouldMerge);
3791
+ return _context20.abrupt("return", result.shouldMerge);
3592
3792
  case 10:
3593
- return _context17.abrupt("return", true);
3793
+ return _context20.abrupt("return", true);
3594
3794
  case 11:
3595
3795
  case "end":
3596
- return _context17.stop();
3796
+ return _context20.stop();
3597
3797
  }
3598
- }, _callee15, this);
3798
+ }, _callee18, this);
3599
3799
  }));
3600
- function shouldMergeProductToOrder(_x14) {
3800
+ function shouldMergeProductToOrder(_x19) {
3601
3801
  return _shouldMergeProductToOrder.apply(this, arguments);
3602
3802
  }
3603
3803
  return shouldMergeProductToOrder;
@@ -3633,30 +3833,30 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3633
3833
  }, {
3634
3834
  key: "finalizeProductOrderMutation",
3635
3835
  value: function () {
3636
- var _finalizeProductOrderMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(tempOrder, options) {
3637
- return _regeneratorRuntime().wrap(function _callee16$(_context18) {
3638
- while (1) switch (_context18.prev = _context18.next) {
3836
+ var _finalizeProductOrderMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(tempOrder, options) {
3837
+ return _regeneratorRuntime().wrap(function _callee19$(_context21) {
3838
+ while (1) switch (_context21.prev = _context21.next) {
3639
3839
  case 0:
3640
3840
  this.syncTempOrderHolderFromBookings(tempOrder);
3641
3841
  if (options !== null && options !== void 0 && options.skipEditDiscountConfigRefresh) {
3642
- _context18.next = 4;
3842
+ _context21.next = 4;
3643
3843
  break;
3644
3844
  }
3645
- _context18.next = 4;
3845
+ _context21.next = 4;
3646
3846
  return this.ensureEditDiscountConfigForProductChange(tempOrder);
3647
3847
  case 4:
3648
3848
  if (options !== null && options !== void 0 && options.skipDiscountRecalculation) {
3649
- _context18.next = 7;
3849
+ _context21.next = 7;
3650
3850
  break;
3651
3851
  }
3652
- _context18.next = 7;
3852
+ _context21.next = 7;
3653
3853
  return this.applyPromotion();
3654
3854
  case 7:
3655
3855
  if (!(options !== null && options !== void 0 && options.skipDiscountRecalculation)) {
3656
3856
  this.applyDiscount();
3657
3857
  }
3658
3858
  this.sanitizeTempOrderProducts(tempOrder);
3659
- _context18.next = 11;
3859
+ _context21.next = 11;
3660
3860
  return this.recalculateSummary({
3661
3861
  createIfMissing: true
3662
3862
  });
@@ -3664,11 +3864,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3664
3864
  this.persistTempOrder();
3665
3865
  case 12:
3666
3866
  case "end":
3667
- return _context18.stop();
3867
+ return _context21.stop();
3668
3868
  }
3669
- }, _callee16, this);
3869
+ }, _callee19, this);
3670
3870
  }));
3671
- function finalizeProductOrderMutation(_x15, _x16) {
3871
+ function finalizeProductOrderMutation(_x20, _x21) {
3672
3872
  return _finalizeProductOrderMutation.apply(this, arguments);
3673
3873
  }
3674
3874
  return finalizeProductOrderMutation;
@@ -3683,13 +3883,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3683
3883
  }, {
3684
3884
  key: "appendProductLineToTempOrder",
3685
3885
  value: (function () {
3686
- var _appendProductLineToTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(tempOrder, product, booking) {
3886
+ var _appendProductLineToTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(tempOrder, product, booking) {
3687
3887
  var _booking_uid,
3688
3888
  _metadata,
3689
- _this23 = this;
3889
+ _this26 = this;
3690
3890
  var linked, productToAdd, incomingFingerprint, normalizedIncoming, incomingBookingUid, hasIncomingGoodPass, hasIncomingProductNote, hasIncomingBookingUid, shouldForceNewLine, matchedIndex, matchedProduct, existedFingerprint, shouldMerge, _targetProduct$metada, targetProduct, targetUid, normalizedProduct, nextNum, targetIsManualProductDiscount, nextDiscountList;
3691
- return _regeneratorRuntime().wrap(function _callee17$(_context19) {
3692
- while (1) switch (_context19.prev = _context19.next) {
3891
+ return _regeneratorRuntime().wrap(function _callee20$(_context22) {
3892
+ while (1) switch (_context22.prev = _context22.next) {
3693
3893
  case 0:
3694
3894
  linked = booking ? this.createLinkedProductAndBooking({
3695
3895
  product: product,
@@ -3712,8 +3912,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3712
3912
  shouldForceNewLine = !!booking || hasIncomingProductNote || hasIncomingBookingUid;
3713
3913
  matchedIndex = hasIncomingGoodPass || shouldForceNewLine ? -1 : tempOrder.products.findIndex(function (item) {
3714
3914
  var _item$metadata3;
3715
- if (_this23.hasGoodPassDiscount(item)) return false;
3716
- if (_this23.hasOrderProductLineNote(item)) return false;
3915
+ if (_this26.hasGoodPassDiscount(item)) return false;
3916
+ if (_this26.hasOrderProductLineNote(item)) return false;
3717
3917
  if (item.order_detail_id !== undefined && item.order_detail_id !== null) return false;
3718
3918
  if ((_item$metadata3 = item.metadata) !== null && _item$metadata3 !== void 0 && _item$metadata3.is_edit_for_runtime) return false;
3719
3919
  if (item.product_id !== productToAdd.product_id) return false;
@@ -3724,10 +3924,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3724
3924
  matchedProduct = matchedIndex === -1 ? null : tempOrder.products[matchedIndex];
3725
3925
  existedFingerprint = matchedProduct ? buildProductLineFingerprint(getProductSkuOptions(matchedProduct), matchedProduct.product_bundle) : '';
3726
3926
  if (!matchedProduct) {
3727
- _context19.next = 20;
3927
+ _context22.next = 20;
3728
3928
  break;
3729
3929
  }
3730
- _context19.next = 17;
3930
+ _context22.next = 17;
3731
3931
  return this.shouldMergeProductToOrder({
3732
3932
  incomingProduct: productToAdd,
3733
3933
  normalizedIncoming: normalizedIncoming,
@@ -3739,13 +3939,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3739
3939
  booking: booking
3740
3940
  });
3741
3941
  case 17:
3742
- _context19.t0 = _context19.sent;
3743
- _context19.next = 21;
3942
+ _context22.t0 = _context22.sent;
3943
+ _context22.next = 21;
3744
3944
  break;
3745
3945
  case 20:
3746
- _context19.t0 = false;
3946
+ _context22.t0 = false;
3747
3947
  case 21:
3748
- shouldMerge = _context19.t0;
3948
+ shouldMerge = _context22.t0;
3749
3949
  if (matchedIndex === -1 || !matchedProduct || !shouldMerge) {
3750
3950
  this.captureProductRuntime(tempOrder, productToAdd, normalizedIncoming);
3751
3951
  if (linked) {
@@ -3799,11 +3999,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3799
3999
  }
3800
4000
  case 24:
3801
4001
  case "end":
3802
- return _context19.stop();
4002
+ return _context22.stop();
3803
4003
  }
3804
- }, _callee17, this);
4004
+ }, _callee20, this);
3805
4005
  }));
3806
- function appendProductLineToTempOrder(_x17, _x18, _x19) {
4006
+ function appendProductLineToTempOrder(_x22, _x23, _x24) {
3807
4007
  return _appendProductLineToTempOrder.apply(this, arguments);
3808
4008
  }
3809
4009
  return appendProductLineToTempOrder;
@@ -3819,61 +4019,61 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3819
4019
  }, {
3820
4020
  key: "addProductToOrder",
3821
4021
  value: (function () {
3822
- var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(product, booking) {
4022
+ var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(product, booking) {
3823
4023
  var tempOrder, _ref61, _productRecord$num, productRecord, splitCount, i, singleLine;
3824
- return _regeneratorRuntime().wrap(function _callee18$(_context20) {
3825
- while (1) switch (_context20.prev = _context20.next) {
4024
+ return _regeneratorRuntime().wrap(function _callee21$(_context23) {
4025
+ while (1) switch (_context23.prev = _context23.next) {
3826
4026
  case 0:
3827
4027
  tempOrder = this.ensureTempOrder();
3828
4028
  if (!booking) {
3829
- _context20.next = 18;
4029
+ _context23.next = 18;
3830
4030
  break;
3831
4031
  }
3832
4032
  productRecord = product;
3833
4033
  splitCount = getSafeProductNum((_ref61 = (_productRecord$num = productRecord.num) !== null && _productRecord$num !== void 0 ? _productRecord$num : productRecord.product_quantity) !== null && _ref61 !== void 0 ? _ref61 : 1);
3834
4034
  if (!(splitCount > 1)) {
3835
- _context20.next = 18;
4035
+ _context23.next = 18;
3836
4036
  break;
3837
4037
  }
3838
4038
  i = 0;
3839
4039
  case 6:
3840
4040
  if (!(i < splitCount)) {
3841
- _context20.next = 15;
4041
+ _context23.next = 15;
3842
4042
  break;
3843
4043
  }
3844
4044
  singleLine = cloneDeep(productRecord);
3845
4045
  singleLine.num = 1;
3846
4046
  delete singleLine.product_quantity;
3847
- _context20.next = 12;
4047
+ _context23.next = 12;
3848
4048
  return this.appendProductLineToTempOrder(tempOrder, singleLine, cloneDeep(booking));
3849
4049
  case 12:
3850
4050
  i += 1;
3851
- _context20.next = 6;
4051
+ _context23.next = 6;
3852
4052
  break;
3853
4053
  case 15:
3854
- _context20.next = 17;
4054
+ _context23.next = 17;
3855
4055
  return this.finalizeProductOrderMutation(tempOrder);
3856
4056
  case 17:
3857
- return _context20.abrupt("return", tempOrder.products);
4057
+ return _context23.abrupt("return", tempOrder.products);
3858
4058
  case 18:
3859
- _context20.next = 20;
4059
+ _context23.next = 20;
3860
4060
  return this.appendProductLineToTempOrder(tempOrder, product, booking);
3861
4061
  case 20:
3862
- _context20.next = 22;
4062
+ _context23.next = 22;
3863
4063
  return this.finalizeProductOrderMutation(tempOrder);
3864
4064
  case 22:
3865
4065
  this.logInfo('addProductToOrder success', {
3866
4066
  product_id: product.product_id,
3867
4067
  with_booking: !!booking
3868
4068
  });
3869
- return _context20.abrupt("return", tempOrder.products);
4069
+ return _context23.abrupt("return", tempOrder.products);
3870
4070
  case 24:
3871
4071
  case "end":
3872
- return _context20.stop();
4072
+ return _context23.stop();
3873
4073
  }
3874
- }, _callee18, this);
4074
+ }, _callee21, this);
3875
4075
  }));
3876
- function addProductToOrder(_x20, _x21) {
4076
+ function addProductToOrder(_x25, _x26) {
3877
4077
  return _addProductToOrder.apply(this, arguments);
3878
4078
  }
3879
4079
  return addProductToOrder;
@@ -3891,93 +4091,93 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3891
4091
  }, {
3892
4092
  key: "addProductsToOrder",
3893
4093
  value: (function () {
3894
- var _addProductsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(items, options) {
4094
+ var _addProductsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(items, options) {
3895
4095
  var tempOrder, _iterator20, _step20, item, product, booking, _ref62, _productRecord$num2, productRecord, splitCount, i, singleLine;
3896
- return _regeneratorRuntime().wrap(function _callee19$(_context21) {
3897
- while (1) switch (_context21.prev = _context21.next) {
4096
+ return _regeneratorRuntime().wrap(function _callee22$(_context24) {
4097
+ while (1) switch (_context24.prev = _context24.next) {
3898
4098
  case 0:
3899
4099
  tempOrder = this.ensureTempOrder();
3900
4100
  if (!(!Array.isArray(items) || items.length === 0)) {
3901
- _context21.next = 3;
4101
+ _context24.next = 3;
3902
4102
  break;
3903
4103
  }
3904
- return _context21.abrupt("return", tempOrder.products);
4104
+ return _context24.abrupt("return", tempOrder.products);
3905
4105
  case 3:
3906
4106
  _iterator20 = _createForOfIteratorHelper(items || []);
3907
- _context21.prev = 4;
4107
+ _context24.prev = 4;
3908
4108
  _iterator20.s();
3909
4109
  case 6:
3910
4110
  if ((_step20 = _iterator20.n()).done) {
3911
- _context21.next = 30;
4111
+ _context24.next = 30;
3912
4112
  break;
3913
4113
  }
3914
4114
  item = _step20.value;
3915
4115
  product = item.product, booking = item.booking;
3916
4116
  if (product) {
3917
- _context21.next = 11;
4117
+ _context24.next = 11;
3918
4118
  break;
3919
4119
  }
3920
- return _context21.abrupt("continue", 28);
4120
+ return _context24.abrupt("continue", 28);
3921
4121
  case 11:
3922
4122
  if (!booking) {
3923
- _context21.next = 26;
4123
+ _context24.next = 26;
3924
4124
  break;
3925
4125
  }
3926
4126
  productRecord = product;
3927
4127
  splitCount = getSafeProductNum((_ref62 = (_productRecord$num2 = productRecord.num) !== null && _productRecord$num2 !== void 0 ? _productRecord$num2 : productRecord.product_quantity) !== null && _ref62 !== void 0 ? _ref62 : 1);
3928
4128
  if (!(splitCount > 1)) {
3929
- _context21.next = 26;
4129
+ _context24.next = 26;
3930
4130
  break;
3931
4131
  }
3932
4132
  i = 0;
3933
4133
  case 16:
3934
4134
  if (!(i < splitCount)) {
3935
- _context21.next = 25;
4135
+ _context24.next = 25;
3936
4136
  break;
3937
4137
  }
3938
4138
  singleLine = cloneDeep(productRecord);
3939
4139
  singleLine.num = 1;
3940
4140
  delete singleLine.product_quantity;
3941
- _context21.next = 22;
4141
+ _context24.next = 22;
3942
4142
  return this.appendProductLineToTempOrder(tempOrder, singleLine, cloneDeep(booking));
3943
4143
  case 22:
3944
4144
  i += 1;
3945
- _context21.next = 16;
4145
+ _context24.next = 16;
3946
4146
  break;
3947
4147
  case 25:
3948
- return _context21.abrupt("continue", 28);
4148
+ return _context24.abrupt("continue", 28);
3949
4149
  case 26:
3950
- _context21.next = 28;
4150
+ _context24.next = 28;
3951
4151
  return this.appendProductLineToTempOrder(tempOrder, product, booking);
3952
4152
  case 28:
3953
- _context21.next = 6;
4153
+ _context24.next = 6;
3954
4154
  break;
3955
4155
  case 30:
3956
- _context21.next = 35;
4156
+ _context24.next = 35;
3957
4157
  break;
3958
4158
  case 32:
3959
- _context21.prev = 32;
3960
- _context21.t0 = _context21["catch"](4);
3961
- _iterator20.e(_context21.t0);
4159
+ _context24.prev = 32;
4160
+ _context24.t0 = _context24["catch"](4);
4161
+ _iterator20.e(_context24.t0);
3962
4162
  case 35:
3963
- _context21.prev = 35;
4163
+ _context24.prev = 35;
3964
4164
  _iterator20.f();
3965
- return _context21.finish(35);
4165
+ return _context24.finish(35);
3966
4166
  case 38:
3967
- _context21.next = 40;
4167
+ _context24.next = 40;
3968
4168
  return this.finalizeProductOrderMutation(tempOrder, options);
3969
4169
  case 40:
3970
4170
  this.logInfo('addProductsToOrder success', {
3971
4171
  itemsCount: items.length
3972
4172
  });
3973
- return _context21.abrupt("return", tempOrder.products);
4173
+ return _context24.abrupt("return", tempOrder.products);
3974
4174
  case 42:
3975
4175
  case "end":
3976
- return _context21.stop();
4176
+ return _context24.stop();
3977
4177
  }
3978
- }, _callee19, this, [[4, 32, 35, 38]]);
4178
+ }, _callee22, this, [[4, 32, 35, 38]]);
3979
4179
  }));
3980
- function addProductsToOrder(_x22, _x23) {
4180
+ function addProductsToOrder(_x27, _x28) {
3981
4181
  return _addProductsToOrder.apply(this, arguments);
3982
4182
  }
3983
4183
  return addProductsToOrder;
@@ -4011,17 +4211,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4011
4211
  }, {
4012
4212
  key: "preservePersistedBundlePriceFields",
4013
4213
  value: function preservePersistedBundlePriceFields(previousBundles, nextBundles) {
4014
- var _this24 = this;
4214
+ var _this27 = this;
4015
4215
  if (!Array.isArray(nextBundles)) return nextBundles;
4016
4216
  if (!Array.isArray(previousBundles) || previousBundles.length === 0) return nextBundles;
4017
4217
  var previousByIdentity = new Map();
4018
4218
  previousBundles.forEach(function (bundle) {
4019
- var identity = _this24.getBundleRuntimeIdentity(bundle);
4219
+ var identity = _this27.getBundleRuntimeIdentity(bundle);
4020
4220
  if (identity) previousByIdentity.set(identity, bundle);
4021
4221
  });
4022
4222
  return nextBundles.map(function (bundle, index) {
4023
4223
  if (!bundle || _typeof(bundle) !== 'object') return bundle;
4024
- var previous = previousByIdentity.get(_this24.getBundleRuntimeIdentity(bundle)) || previousBundles[index];
4224
+ var previous = previousByIdentity.get(_this27.getBundleRuntimeIdentity(bundle)) || previousBundles[index];
4025
4225
  if (!previous || _typeof(previous) !== 'object') return bundle;
4026
4226
  return _objectSpread(_objectSpread(_objectSpread({}, bundle), (bundle.cover === undefined || bundle.cover === null || bundle.cover === '') && previous.cover !== undefined && previous.cover !== null && previous.cover !== '' ? {
4027
4227
  cover: previous.cover
@@ -4222,21 +4422,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4222
4422
  }, {
4223
4423
  key: "updateOrderProduct",
4224
4424
  value: function () {
4225
- var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(params) {
4425
+ var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(params) {
4226
4426
  var tempOrder, updatedProductUid;
4227
- return _regeneratorRuntime().wrap(function _callee20$(_context22) {
4228
- while (1) switch (_context22.prev = _context22.next) {
4427
+ return _regeneratorRuntime().wrap(function _callee23$(_context25) {
4428
+ while (1) switch (_context25.prev = _context25.next) {
4229
4429
  case 0:
4230
4430
  tempOrder = this.ensureTempOrder();
4231
4431
  updatedProductUid = this.applyOrderProductUpdateToTempOrder(tempOrder, params);
4232
- _context22.next = 4;
4432
+ _context25.next = 4;
4233
4433
  return this.applyPromotion();
4234
4434
  case 4:
4235
4435
  this.applyDiscount({
4236
4436
  reapplyBookingDiscountProductUids: params.allow_booking_discount_reapply && updatedProductUid ? [String(updatedProductUid)] : undefined
4237
4437
  });
4238
4438
  this.sanitizeTempOrderProducts(tempOrder);
4239
- _context22.next = 8;
4439
+ _context25.next = 8;
4240
4440
  return this.recalculateSummary({
4241
4441
  createIfMissing: true
4242
4442
  });
@@ -4245,14 +4445,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4245
4445
  this.logInfo('updateOrderProduct success', {
4246
4446
  params: params
4247
4447
  });
4248
- return _context22.abrupt("return", tempOrder.products);
4448
+ return _context25.abrupt("return", tempOrder.products);
4249
4449
  case 11:
4250
4450
  case "end":
4251
- return _context22.stop();
4451
+ return _context25.stop();
4252
4452
  }
4253
- }, _callee20, this);
4453
+ }, _callee23, this);
4254
4454
  }));
4255
- function updateOrderProduct(_x24) {
4455
+ function updateOrderProduct(_x29) {
4256
4456
  return _updateOrderProduct.apply(this, arguments);
4257
4457
  }
4258
4458
  return updateOrderProduct;
@@ -4260,28 +4460,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4260
4460
  }, {
4261
4461
  key: "updateOrderProducts",
4262
4462
  value: function () {
4263
- var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(paramsList) {
4264
- var _this25 = this;
4463
+ var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(paramsList) {
4464
+ var _this28 = this;
4265
4465
  var tempOrder, reapplyBookingDiscountProductUids;
4266
- return _regeneratorRuntime().wrap(function _callee21$(_context23) {
4267
- while (1) switch (_context23.prev = _context23.next) {
4466
+ return _regeneratorRuntime().wrap(function _callee24$(_context26) {
4467
+ while (1) switch (_context26.prev = _context26.next) {
4268
4468
  case 0:
4269
4469
  tempOrder = this.ensureTempOrder();
4270
4470
  if (paramsList.length) {
4271
- _context23.next = 3;
4471
+ _context26.next = 3;
4272
4472
  break;
4273
4473
  }
4274
- return _context23.abrupt("return", tempOrder.products);
4474
+ return _context26.abrupt("return", tempOrder.products);
4275
4475
  case 3:
4276
4476
  reapplyBookingDiscountProductUids = paramsList.reduce(function (acc, params) {
4277
- var updatedProductUid = _this25.applyOrderProductUpdateToTempOrder(tempOrder, params);
4477
+ var updatedProductUid = _this28.applyOrderProductUpdateToTempOrder(tempOrder, params);
4278
4478
  // 批量改预约时间时,延迟到最后一次折扣计算里统一恢复已选预约折扣卡。
4279
4479
  if (params.allow_booking_discount_reapply && updatedProductUid) {
4280
4480
  acc.push(String(updatedProductUid));
4281
4481
  }
4282
4482
  return acc;
4283
4483
  }, []);
4284
- _context23.next = 6;
4484
+ _context26.next = 6;
4285
4485
  return this.finalizeAfterProductsMutation(tempOrder, {
4286
4486
  reapplyBookingDiscountProductUids: reapplyBookingDiscountProductUids.length ? reapplyBookingDiscountProductUids : undefined
4287
4487
  });
@@ -4289,14 +4489,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4289
4489
  this.logInfo('updateOrderProduct success', {
4290
4490
  paramsList: paramsList
4291
4491
  });
4292
- return _context23.abrupt("return", tempOrder.products);
4492
+ return _context26.abrupt("return", tempOrder.products);
4293
4493
  case 8:
4294
4494
  case "end":
4295
- return _context23.stop();
4495
+ return _context26.stop();
4296
4496
  }
4297
- }, _callee21, this);
4497
+ }, _callee24, this);
4298
4498
  }));
4299
- function updateOrderProducts(_x25) {
4499
+ function updateOrderProducts(_x30) {
4300
4500
  return _updateOrderProducts.apply(this, arguments);
4301
4501
  }
4302
4502
  return updateOrderProducts;
@@ -4304,11 +4504,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4304
4504
  }, {
4305
4505
  key: "updateOrderProductQuantity",
4306
4506
  value: function () {
4307
- var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(params) {
4507
+ var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(params) {
4308
4508
  var _targetProduct$metada17;
4309
4509
  var product_id, product_variant_id, num, unique_identification_number, identity_key, product_sku, product_bundle, tempOrder, identityLookup, productIndex, targetUid, targetProduct, normalizedProduct;
4310
- return _regeneratorRuntime().wrap(function _callee22$(_context24) {
4311
- while (1) switch (_context24.prev = _context24.next) {
4510
+ return _regeneratorRuntime().wrap(function _callee25$(_context27) {
4511
+ while (1) switch (_context27.prev = _context27.next) {
4312
4512
  case 0:
4313
4513
  product_id = params.product_id, product_variant_id = params.product_variant_id, num = params.num, unique_identification_number = params.unique_identification_number, identity_key = params.identity_key, product_sku = params.product_sku, product_bundle = params.product_bundle;
4314
4514
  tempOrder = this.ensureTempOrder();
@@ -4337,7 +4537,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4337
4537
  productIndex = getProductIdentityIndex(tempOrder.products, identityLookup);
4338
4538
  }
4339
4539
  if (!(productIndex === -1)) {
4340
- _context24.next = 12;
4540
+ _context27.next = 12;
4341
4541
  break;
4342
4542
  }
4343
4543
  throw new Error('[Order] 目标商品不存在,无法更新数量');
@@ -4351,12 +4551,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4351
4551
  }));
4352
4552
  normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
4353
4553
  tempOrder.products[productIndex] = normalizedProduct;
4354
- _context24.next = 18;
4554
+ _context27.next = 18;
4355
4555
  return this.applyPromotion();
4356
4556
  case 18:
4357
4557
  this.applyDiscount();
4358
4558
  this.sanitizeTempOrderProducts(tempOrder);
4359
- _context24.next = 22;
4559
+ _context27.next = 22;
4360
4560
  return this.recalculateSummary({
4361
4561
  createIfMissing: true
4362
4562
  });
@@ -4365,14 +4565,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4365
4565
  this.logInfo('updateOrderProductQuantity success', {
4366
4566
  params: params
4367
4567
  });
4368
- return _context24.abrupt("return", tempOrder.products);
4568
+ return _context27.abrupt("return", tempOrder.products);
4369
4569
  case 25:
4370
4570
  case "end":
4371
- return _context24.stop();
4571
+ return _context27.stop();
4372
4572
  }
4373
- }, _callee22, this);
4573
+ }, _callee25, this);
4374
4574
  }));
4375
- function updateOrderProductQuantity(_x26) {
4575
+ function updateOrderProductQuantity(_x31) {
4376
4576
  return _updateOrderProductQuantity.apply(this, arguments);
4377
4577
  }
4378
4578
  return updateOrderProductQuantity;
@@ -4413,19 +4613,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4413
4613
  }, {
4414
4614
  key: "finalizeAfterProductsMutation",
4415
4615
  value: (function () {
4416
- var _finalizeAfterProductsMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(tempOrder, options) {
4417
- return _regeneratorRuntime().wrap(function _callee23$(_context25) {
4418
- while (1) switch (_context25.prev = _context25.next) {
4616
+ var _finalizeAfterProductsMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(tempOrder, options) {
4617
+ return _regeneratorRuntime().wrap(function _callee26$(_context28) {
4618
+ while (1) switch (_context28.prev = _context28.next) {
4419
4619
  case 0:
4420
4620
  this.syncTempOrderHolderFromBookings(tempOrder);
4421
- _context25.next = 3;
4621
+ _context28.next = 3;
4422
4622
  return this.applyPromotion();
4423
4623
  case 3:
4424
4624
  this.applyDiscount({
4425
4625
  reapplyBookingDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyBookingDiscountProductUids
4426
4626
  });
4427
4627
  this.sanitizeTempOrderProducts(tempOrder);
4428
- _context25.next = 7;
4628
+ _context28.next = 7;
4429
4629
  return this.recalculateSummary({
4430
4630
  createIfMissing: true
4431
4631
  });
@@ -4433,11 +4633,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4433
4633
  this.persistTempOrder();
4434
4634
  case 8:
4435
4635
  case "end":
4436
- return _context25.stop();
4636
+ return _context28.stop();
4437
4637
  }
4438
- }, _callee23, this);
4638
+ }, _callee26, this);
4439
4639
  }));
4440
- function finalizeAfterProductsMutation(_x27, _x28) {
4640
+ function finalizeAfterProductsMutation(_x32, _x33) {
4441
4641
  return _finalizeAfterProductsMutation.apply(this, arguments);
4442
4642
  }
4443
4643
  return finalizeAfterProductsMutation;
@@ -4452,18 +4652,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4452
4652
  }, {
4453
4653
  key: "removeProductsFromOrder",
4454
4654
  value: (function () {
4455
- var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(identities) {
4456
- var _this26 = this;
4655
+ var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(identities) {
4656
+ var _this29 = this;
4457
4657
  var tempOrder, productsBeforeRemove, bookingsBeforeRemove, matchedProducts, removedProducts, _i2, _removedProducts, product, linkedBookingUidsToRemove, _iterator21, _step21, _loop3;
4458
- return _regeneratorRuntime().wrap(function _callee24$(_context27) {
4459
- while (1) switch (_context27.prev = _context27.next) {
4658
+ return _regeneratorRuntime().wrap(function _callee27$(_context30) {
4659
+ while (1) switch (_context30.prev = _context30.next) {
4460
4660
  case 0:
4461
4661
  tempOrder = this.ensureTempOrder();
4462
4662
  if (identities.length) {
4463
- _context27.next = 3;
4663
+ _context30.next = 3;
4464
4664
  break;
4465
4665
  }
4466
- return _context27.abrupt("return", tempOrder.products);
4666
+ return _context30.abrupt("return", tempOrder.products);
4467
4667
  case 3:
4468
4668
  productsBeforeRemove = tempOrder.products || [];
4469
4669
  bookingsBeforeRemove = tempOrder.bookings || [];
@@ -4486,29 +4686,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4486
4686
  }
4487
4687
  linkedBookingUidsToRemove = new Set();
4488
4688
  _iterator21 = _createForOfIteratorHelper(matchedProducts);
4489
- _context27.prev = 11;
4689
+ _context30.prev = 11;
4490
4690
  _loop3 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop3() {
4491
4691
  var _metadata11, _metadata12, _metadata13, _metadata14;
4492
4692
  var product, productUid, productBookingUid, isAddTimeProduct;
4493
- return _regeneratorRuntime().wrap(function _loop3$(_context26) {
4494
- while (1) switch (_context26.prev = _context26.next) {
4693
+ return _regeneratorRuntime().wrap(function _loop3$(_context29) {
4694
+ while (1) switch (_context29.prev = _context29.next) {
4495
4695
  case 0:
4496
4696
  product = _step21.value;
4497
4697
  productUid = (product === null || product === void 0 || (_metadata11 = product.metadata) === null || _metadata11 === void 0 ? void 0 : _metadata11.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
4498
4698
  productBookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_metadata12 = product.metadata) === null || _metadata12 === void 0 ? void 0 : _metadata12.booking_uid);
4499
4699
  isAddTimeProduct = (product === null || product === void 0 || (_metadata13 = product.metadata) === null || _metadata13 === void 0 ? void 0 : _metadata13.product_add_schedule_time) !== undefined && (product === null || product === void 0 || (_metadata14 = product.metadata) === null || _metadata14 === void 0 ? void 0 : _metadata14.product_add_schedule_time) !== null;
4500
4700
  if (!isAddTimeProduct) {
4501
- _context26.next = 6;
4701
+ _context29.next = 6;
4502
4702
  break;
4503
4703
  }
4504
- return _context26.abrupt("return", 1);
4704
+ return _context29.abrupt("return", 1);
4505
4705
  case 6:
4506
4706
  if (productBookingUid !== undefined && productBookingUid !== null && productBookingUid !== '') {
4507
4707
  linkedBookingUidsToRemove.add(String(productBookingUid));
4508
4708
  }
4509
4709
  if (productUid !== undefined && productUid !== null && productUid !== '') {
4510
4710
  bookingsBeforeRemove.forEach(function (booking) {
4511
- var bookingUid = _this26.getBookingUniqueIdentificationNumber(booking);
4711
+ var bookingUid = _this29.getBookingUniqueIdentificationNumber(booking);
4512
4712
  if (bookingUid && String((booking === null || booking === void 0 ? void 0 : booking.product_uid) || '') === String(productUid)) {
4513
4713
  linkedBookingUidsToRemove.add(bookingUid);
4514
4714
  }
@@ -4516,37 +4716,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4516
4716
  }
4517
4717
  case 8:
4518
4718
  case "end":
4519
- return _context26.stop();
4719
+ return _context29.stop();
4520
4720
  }
4521
4721
  }, _loop3);
4522
4722
  });
4523
4723
  _iterator21.s();
4524
4724
  case 14:
4525
4725
  if ((_step21 = _iterator21.n()).done) {
4526
- _context27.next = 20;
4726
+ _context30.next = 20;
4527
4727
  break;
4528
4728
  }
4529
- return _context27.delegateYield(_loop3(), "t0", 16);
4729
+ return _context30.delegateYield(_loop3(), "t0", 16);
4530
4730
  case 16:
4531
- if (!_context27.t0) {
4532
- _context27.next = 18;
4731
+ if (!_context30.t0) {
4732
+ _context30.next = 18;
4533
4733
  break;
4534
4734
  }
4535
- return _context27.abrupt("continue", 18);
4735
+ return _context30.abrupt("continue", 18);
4536
4736
  case 18:
4537
- _context27.next = 14;
4737
+ _context30.next = 14;
4538
4738
  break;
4539
4739
  case 20:
4540
- _context27.next = 25;
4740
+ _context30.next = 25;
4541
4741
  break;
4542
4742
  case 22:
4543
- _context27.prev = 22;
4544
- _context27.t1 = _context27["catch"](11);
4545
- _iterator21.e(_context27.t1);
4743
+ _context30.prev = 22;
4744
+ _context30.t1 = _context30["catch"](11);
4745
+ _iterator21.e(_context30.t1);
4546
4746
  case 25:
4547
- _context27.prev = 25;
4747
+ _context30.prev = 25;
4548
4748
  _iterator21.f();
4549
- return _context27.finish(25);
4749
+ return _context30.finish(25);
4550
4750
  case 28:
4551
4751
  if (linkedBookingUidsToRemove.size > 0) {
4552
4752
  // 删除主预约商品时,同步移除挂在同一 booking_uid 下的加时商品,避免残留孤儿行。
@@ -4557,20 +4757,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4557
4757
  return !(isAddTimeProduct && lineBookingUid !== undefined && lineBookingUid !== null && linkedBookingUidsToRemove.has(String(lineBookingUid)));
4558
4758
  });
4559
4759
  }
4560
- _context27.next = 31;
4760
+ _context30.next = 31;
4561
4761
  return this.finalizeAfterProductsMutation(tempOrder);
4562
4762
  case 31:
4563
4763
  this.logInfo('removeProductsFromOrder success', {
4564
4764
  identities: identities
4565
4765
  });
4566
- return _context27.abrupt("return", tempOrder.products);
4766
+ return _context30.abrupt("return", tempOrder.products);
4567
4767
  case 33:
4568
4768
  case "end":
4569
- return _context27.stop();
4769
+ return _context30.stop();
4570
4770
  }
4571
- }, _callee24, this, [[11, 22, 25, 28]]);
4771
+ }, _callee27, this, [[11, 22, 25, 28]]);
4572
4772
  }));
4573
- function removeProductsFromOrder(_x29) {
4773
+ function removeProductsFromOrder(_x34) {
4574
4774
  return _removeProductsFromOrder.apply(this, arguments);
4575
4775
  }
4576
4776
  return removeProductsFromOrder;
@@ -4578,18 +4778,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4578
4778
  }, {
4579
4779
  key: "removeProductFromOrder",
4580
4780
  value: function () {
4581
- var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(identity) {
4582
- return _regeneratorRuntime().wrap(function _callee25$(_context28) {
4583
- while (1) switch (_context28.prev = _context28.next) {
4781
+ var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(identity) {
4782
+ return _regeneratorRuntime().wrap(function _callee28$(_context31) {
4783
+ while (1) switch (_context31.prev = _context31.next) {
4584
4784
  case 0:
4585
- return _context28.abrupt("return", this.removeProductsFromOrder([identity]));
4785
+ return _context31.abrupt("return", this.removeProductsFromOrder([identity]));
4586
4786
  case 1:
4587
4787
  case "end":
4588
- return _context28.stop();
4788
+ return _context31.stop();
4589
4789
  }
4590
- }, _callee25, this);
4790
+ }, _callee28, this);
4591
4791
  }));
4592
- function removeProductFromOrder(_x30) {
4792
+ function removeProductFromOrder(_x35) {
4593
4793
  return _removeProductFromOrder.apply(this, arguments);
4594
4794
  }
4595
4795
  return removeProductFromOrder;
@@ -4601,10 +4801,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4601
4801
  }, {
4602
4802
  key: "clearOrderCartLines",
4603
4803
  value: (function () {
4604
- var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
4804
+ var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
4605
4805
  var tempOrder;
4606
- return _regeneratorRuntime().wrap(function _callee26$(_context29) {
4607
- while (1) switch (_context29.prev = _context29.next) {
4806
+ return _regeneratorRuntime().wrap(function _callee29$(_context32) {
4807
+ while (1) switch (_context32.prev = _context32.next) {
4608
4808
  case 0:
4609
4809
  tempOrder = this.ensureTempOrder();
4610
4810
  tempOrder.products = [];
@@ -4615,24 +4815,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4615
4815
  productsByUid: {}
4616
4816
  });
4617
4817
  }
4618
- _context29.next = 7;
4818
+ _context32.next = 7;
4619
4819
  return this.applyPromotion();
4620
4820
  case 7:
4621
4821
  this.applyDiscount();
4622
4822
  this.sanitizeTempOrderProducts(tempOrder);
4623
- _context29.next = 11;
4823
+ _context32.next = 11;
4624
4824
  return this.recalculateSummary({
4625
4825
  createIfMissing: true
4626
4826
  });
4627
4827
  case 11:
4628
4828
  this.persistTempOrder();
4629
4829
  this.logInfo('clearOrderCartLines success', {});
4630
- return _context29.abrupt("return", tempOrder);
4830
+ return _context32.abrupt("return", tempOrder);
4631
4831
  case 14:
4632
4832
  case "end":
4633
- return _context29.stop();
4833
+ return _context32.stop();
4634
4834
  }
4635
- }, _callee26, this);
4835
+ }, _callee29, this);
4636
4836
  }));
4637
4837
  function clearOrderCartLines() {
4638
4838
  return _clearOrderCartLines.apply(this, arguments);
@@ -4670,17 +4870,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4670
4870
  }, {
4671
4871
  key: "applyLocalPrintOrderNumbers",
4672
4872
  value: function () {
4673
- var _applyLocalPrintOrderNumbers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(order) {
4873
+ var _applyLocalPrintOrderNumbers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(order) {
4674
4874
  var tempOrder, shopOrderNumber, shopFullOrderNumber;
4675
- return _regeneratorRuntime().wrap(function _callee27$(_context30) {
4676
- while (1) switch (_context30.prev = _context30.next) {
4875
+ return _regeneratorRuntime().wrap(function _callee30$(_context33) {
4876
+ while (1) switch (_context33.prev = _context33.next) {
4677
4877
  case 0:
4678
4878
  tempOrder = this.ensureTempOrder();
4679
4879
  if (!(!order || _typeof(order) !== 'object')) {
4680
- _context30.next = 3;
4880
+ _context33.next = 3;
4681
4881
  break;
4682
4882
  }
4683
- return _context30.abrupt("return", tempOrder);
4883
+ return _context33.abrupt("return", tempOrder);
4684
4884
  case 3:
4685
4885
  shopOrderNumber = order.shop_order_number;
4686
4886
  shopFullOrderNumber = order.shop_full_order_number;
@@ -4691,21 +4891,88 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4691
4891
  tempOrder.shop_full_order_number = String(shopFullOrderNumber);
4692
4892
  }
4693
4893
  this.persistTempOrder();
4694
- _context30.next = 10;
4894
+ _context33.next = 10;
4695
4895
  return this.saveDraft();
4696
4896
  case 10:
4697
- return _context30.abrupt("return", tempOrder);
4897
+ return _context33.abrupt("return", tempOrder);
4698
4898
  case 11:
4699
4899
  case "end":
4700
- return _context30.stop();
4900
+ return _context33.stop();
4701
4901
  }
4702
- }, _callee27, this);
4902
+ }, _callee30, this);
4703
4903
  }));
4704
- function applyLocalPrintOrderNumbers(_x31) {
4904
+ function applyLocalPrintOrderNumbers(_x36) {
4705
4905
  return _applyLocalPrintOrderNumbers.apply(this, arguments);
4706
4906
  }
4707
4907
  return applyLocalPrintOrderNumbers;
4708
4908
  }()
4909
+ }, {
4910
+ key: "saveTempOrderAsDraft",
4911
+ value: function () {
4912
+ var _saveTempOrderAsDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(params) {
4913
+ var _params$cacheId2, _this$otherParams6, _this$otherParams7, _this$otherParams8, _params$type, _this$otherParams9, _payload$products;
4914
+ var tempOrder, latestSummary, payload;
4915
+ return _regeneratorRuntime().wrap(function _callee31$(_context34) {
4916
+ while (1) switch (_context34.prev = _context34.next) {
4917
+ case 0:
4918
+ tempOrder = this.ensureTempOrder();
4919
+ this.ensureExternalSaleNumber(tempOrder);
4920
+ this.persistTempOrder();
4921
+ _context34.next = 5;
4922
+ return this.recalculateSummary({
4923
+ createIfMissing: true
4924
+ });
4925
+ case 5:
4926
+ _context34.t1 = _context34.sent;
4927
+ if (_context34.t1) {
4928
+ _context34.next = 8;
4929
+ break;
4930
+ }
4931
+ _context34.t1 = this.store.summary;
4932
+ case 8:
4933
+ _context34.t0 = _context34.t1;
4934
+ if (_context34.t0) {
4935
+ _context34.next = 11;
4936
+ break;
4937
+ }
4938
+ _context34.t0 = createEmptySummary();
4939
+ case 11:
4940
+ latestSummary = _context34.t0;
4941
+ payload = buildSubmitPayload({
4942
+ tempOrder: tempOrder,
4943
+ cacheId: (_params$cacheId2 = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId2 !== void 0 ? _params$cacheId2 : this.cacheId,
4944
+ platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6.platform),
4945
+ businessCode: (params === null || params === void 0 ? void 0 : params.businessCode) || ((_this$otherParams7 = this.otherParams) === null || _this$otherParams7 === void 0 ? void 0 : _this$otherParams7.businessCode) || ((_this$otherParams8 = this.otherParams) === null || _this$otherParams8 === void 0 ? void 0 : _this$otherParams8.business_code) || tempOrder.business_code,
4946
+ channel: params === null || params === void 0 ? void 0 : params.channel,
4947
+ type: (_params$type = params === null || params === void 0 ? void 0 : params.type) !== null && _params$type !== void 0 ? _params$type : (_this$otherParams9 = this.otherParams) === null || _this$otherParams9 === void 0 ? void 0 : _this$otherParams9.type,
4948
+ summary: latestSummary,
4949
+ enhance: params === null || params === void 0 ? void 0 : params.enhancePayload
4950
+ });
4951
+ if (!payload.created_at) {
4952
+ payload.created_at = dayjs().format('YYYY-MM-DD HH:mm:ss');
4953
+ }
4954
+ payload.need_sync = 0;
4955
+ payload.is_draft_order = 1;
4956
+ this.logInfo('saveTempOrderAsDraft calling sales draft', {
4957
+ orderId: payload.order_id,
4958
+ externalSaleNumber: payload.external_sale_number,
4959
+ productsCount: ((_payload$products = payload.products) === null || _payload$products === void 0 ? void 0 : _payload$products.length) || 0
4960
+ });
4961
+ return _context34.abrupt("return", this.request.post('/order/sales/draft', payload, {
4962
+ osServer: true,
4963
+ customToast: function customToast() {}
4964
+ }));
4965
+ case 18:
4966
+ case "end":
4967
+ return _context34.stop();
4968
+ }
4969
+ }, _callee31, this);
4970
+ }));
4971
+ function saveTempOrderAsDraft(_x37) {
4972
+ return _saveTempOrderAsDraft.apply(this, arguments);
4973
+ }
4974
+ return saveTempOrderAsDraft;
4975
+ }()
4709
4976
  /**
4710
4977
  * 提交当前 Sales tempOrder。
4711
4978
  *
@@ -4715,18 +4982,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4715
4982
  }, {
4716
4983
  key: "submitTempOrder",
4717
4984
  value: (function () {
4718
- var _submitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(params) {
4719
- return _regeneratorRuntime().wrap(function _callee28$(_context31) {
4720
- while (1) switch (_context31.prev = _context31.next) {
4985
+ var _submitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(params) {
4986
+ return _regeneratorRuntime().wrap(function _callee32$(_context35) {
4987
+ while (1) switch (_context35.prev = _context35.next) {
4721
4988
  case 0:
4722
- return _context31.abrupt("return", this.runSubmitTempOrder(params));
4989
+ return _context35.abrupt("return", this.runSubmitTempOrder(params));
4723
4990
  case 1:
4724
4991
  case "end":
4725
- return _context31.stop();
4992
+ return _context35.stop();
4726
4993
  }
4727
- }, _callee28, this);
4994
+ }, _callee32, this);
4728
4995
  }));
4729
- function submitTempOrder(_x32) {
4996
+ function submitTempOrder(_x38) {
4730
4997
  return _submitTempOrder.apply(this, arguments);
4731
4998
  }
4732
4999
  return submitTempOrder;
@@ -4734,20 +5001,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4734
5001
  }, {
4735
5002
  key: "submitTempOrderAsync",
4736
5003
  value: function () {
4737
- var _submitTempOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(params) {
4738
- return _regeneratorRuntime().wrap(function _callee29$(_context32) {
4739
- while (1) switch (_context32.prev = _context32.next) {
5004
+ var _submitTempOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(params) {
5005
+ return _regeneratorRuntime().wrap(function _callee33$(_context36) {
5006
+ while (1) switch (_context36.prev = _context36.next) {
4740
5007
  case 0:
4741
- return _context32.abrupt("return", this.runSubmitTempOrder(_objectSpread(_objectSpread({}, params), {}, {
5008
+ return _context36.abrupt("return", this.runSubmitTempOrder(_objectSpread(_objectSpread({}, params), {}, {
4742
5009
  syncMode: true
4743
5010
  })));
4744
5011
  case 1:
4745
5012
  case "end":
4746
- return _context32.stop();
5013
+ return _context36.stop();
4747
5014
  }
4748
- }, _callee29, this);
5015
+ }, _callee33, this);
4749
5016
  }));
4750
- function submitTempOrderAsync(_x33) {
5017
+ function submitTempOrderAsync(_x39) {
4751
5018
  return _submitTempOrderAsync.apply(this, arguments);
4752
5019
  }
4753
5020
  return submitTempOrderAsync;
@@ -4755,11 +5022,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4755
5022
  }, {
4756
5023
  key: "runSubmitTempOrder",
4757
5024
  value: function () {
4758
- var _runSubmitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(params) {
4759
- var _params$cacheId2, _this$otherParams6, _ref74, _ref75, _submitSnapshot$busin, _this$otherParams7, _this$otherParams8, _submitSnapshot$type;
5025
+ var _runSubmitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(params) {
5026
+ var _params$cacheId3, _this$otherParams10, _ref74, _ref75, _submitSnapshot$busin, _this$otherParams11, _this$otherParams12, _submitSnapshot$type;
4760
5027
  var tempOrder, shouldConfirmPendingVoucherPayments, hasPaymentOverride, preparedPaymentOverride, latestSummary, effectiveCacheId, hasPaymentStatusOverride, hasSmallTicketDataFlagOverride, enhancePayload, submitSnapshot, payload, result, _payload$payments, _payload$payments2, backendErrorResponse, submittedOrderId, resultRecord;
4761
- return _regeneratorRuntime().wrap(function _callee30$(_context33) {
4762
- while (1) switch (_context33.prev = _context33.next) {
5028
+ return _regeneratorRuntime().wrap(function _callee34$(_context37) {
5029
+ while (1) switch (_context37.prev = _context37.next) {
4763
5030
  case 0:
4764
5031
  tempOrder = this.ensureTempOrder();
4765
5032
  shouldConfirmPendingVoucherPayments = (params === null || params === void 0 ? void 0 : params.confirmPendingVoucherPayments) !== false;
@@ -4779,27 +5046,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4779
5046
  }
4780
5047
  }
4781
5048
  this.persistTempOrder();
4782
- _context33.next = 8;
5049
+ _context37.next = 8;
4783
5050
  return this.recalculateSummary({
4784
5051
  createIfMissing: true
4785
5052
  });
4786
5053
  case 8:
4787
- _context33.t1 = _context33.sent;
4788
- if (_context33.t1) {
4789
- _context33.next = 11;
5054
+ _context37.t1 = _context37.sent;
5055
+ if (_context37.t1) {
5056
+ _context37.next = 11;
4790
5057
  break;
4791
5058
  }
4792
- _context33.t1 = this.store.summary;
5059
+ _context37.t1 = this.store.summary;
4793
5060
  case 11:
4794
- _context33.t0 = _context33.t1;
4795
- if (_context33.t0) {
4796
- _context33.next = 14;
5061
+ _context37.t0 = _context37.t1;
5062
+ if (_context37.t0) {
5063
+ _context37.next = 14;
4797
5064
  break;
4798
5065
  }
4799
- _context33.t0 = createEmptySummary();
5066
+ _context37.t0 = createEmptySummary();
4800
5067
  case 14:
4801
- latestSummary = _context33.t0;
4802
- effectiveCacheId = (_params$cacheId2 = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId2 !== void 0 ? _params$cacheId2 : this.cacheId;
5068
+ latestSummary = _context37.t0;
5069
+ effectiveCacheId = (_params$cacheId3 = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId3 !== void 0 ? _params$cacheId3 : this.cacheId;
4803
5070
  hasPaymentStatusOverride = (params === null || params === void 0 ? void 0 : params.paymentStatus) !== undefined;
4804
5071
  hasSmallTicketDataFlagOverride = (params === null || params === void 0 ? void 0 : params.smallTicketDataFlag) !== undefined;
4805
5072
  enhancePayload = hasPaymentOverride || hasPaymentStatusOverride || hasSmallTicketDataFlagOverride || params !== null && params !== void 0 && params.enhancePayload ? function (payload, ctx) {
@@ -4817,8 +5084,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4817
5084
  payload = buildSubmitPayload({
4818
5085
  tempOrder: tempOrder,
4819
5086
  cacheId: effectiveCacheId,
4820
- platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6.platform),
4821
- businessCode: (_ref74 = (_ref75 = (_submitSnapshot$busin = submitSnapshot.businessCode) !== null && _submitSnapshot$busin !== void 0 ? _submitSnapshot$busin : params === null || params === void 0 ? void 0 : params.businessCode) !== null && _ref75 !== void 0 ? _ref75 : (_this$otherParams7 = this.otherParams) === null || _this$otherParams7 === void 0 ? void 0 : _this$otherParams7.businessCode) !== null && _ref74 !== void 0 ? _ref74 : (_this$otherParams8 = this.otherParams) === null || _this$otherParams8 === void 0 ? void 0 : _this$otherParams8.business_code,
5087
+ platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams10 = this.otherParams) === null || _this$otherParams10 === void 0 ? void 0 : _this$otherParams10.platform),
5088
+ businessCode: (_ref74 = (_ref75 = (_submitSnapshot$busin = submitSnapshot.businessCode) !== null && _submitSnapshot$busin !== void 0 ? _submitSnapshot$busin : params === null || params === void 0 ? void 0 : params.businessCode) !== null && _ref75 !== void 0 ? _ref75 : (_this$otherParams11 = this.otherParams) === null || _this$otherParams11 === void 0 ? void 0 : _this$otherParams11.businessCode) !== null && _ref74 !== void 0 ? _ref74 : (_this$otherParams12 = this.otherParams) === null || _this$otherParams12 === void 0 ? void 0 : _this$otherParams12.business_code,
4822
5089
  channel: params === null || params === void 0 ? void 0 : params.channel,
4823
5090
  type: (_submitSnapshot$type = submitSnapshot.type) !== null && _submitSnapshot$type !== void 0 ? _submitSnapshot$type : params === null || params === void 0 ? void 0 : params.type,
4824
5091
  summary: latestSummary,
@@ -4833,10 +5100,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4833
5100
  if (!payload.created_at) {
4834
5101
  payload.created_at = dayjs().format('YYYY-MM-DD HH:mm:ss');
4835
5102
  }
4836
- _context33.next = 26;
5103
+ _context37.next = 26;
4837
5104
  return this.saveDraft();
4838
5105
  case 26:
4839
- _context33.prev = 26;
5106
+ _context37.prev = 26;
4840
5107
  this.logInfo('submitTempOrder calling sales checkout', {
4841
5108
  orderId: payload.order_id,
4842
5109
  externalSaleNumber: payload.external_sale_number,
@@ -4846,43 +5113,43 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4846
5113
  smallTicketDataFlag: payload.small_ticket_data_flag,
4847
5114
  syncMode: payload.sync_mode
4848
5115
  });
4849
- _context33.next = 30;
5116
+ _context37.next = 30;
4850
5117
  return this.submitSalesOrder({
4851
5118
  query: payload
4852
5119
  });
4853
5120
  case 30:
4854
- result = _context33.sent;
4855
- _context33.next = 43;
5121
+ result = _context37.sent;
5122
+ _context37.next = 43;
4856
5123
  break;
4857
5124
  case 33:
4858
- _context33.prev = 33;
4859
- _context33.t2 = _context33["catch"](26);
4860
- backendErrorResponse = this.extractSubmitErrorResponse(_context33.t2);
5125
+ _context37.prev = 33;
5126
+ _context37.t2 = _context37["catch"](26);
5127
+ backendErrorResponse = this.extractSubmitErrorResponse(_context37.t2);
4861
5128
  if (!backendErrorResponse) {
4862
- _context33.next = 40;
5129
+ _context37.next = 40;
4863
5130
  break;
4864
5131
  }
4865
5132
  this.store.syncState = 'failed';
4866
5133
  this.logSubmitBackendRejected(backendErrorResponse, payload);
4867
- return _context33.abrupt("return", backendErrorResponse);
5134
+ return _context37.abrupt("return", backendErrorResponse);
4868
5135
  case 40:
4869
5136
  this.store.syncState = 'failed';
4870
5137
  this.logError('submitTempOrder failed', {
4871
- error: _context33.t2 instanceof Error ? _context33.t2.message : String(_context33.t2),
5138
+ error: _context37.t2 instanceof Error ? _context37.t2.message : String(_context37.t2),
4872
5139
  orderId: payload.order_id,
4873
5140
  externalSaleNumber: payload.external_sale_number,
4874
5141
  paymentStatus: payload.payment_status,
4875
5142
  paymentsCount: ((_payload$payments2 = payload.payments) === null || _payload$payments2 === void 0 ? void 0 : _payload$payments2.length) || 0
4876
5143
  });
4877
- throw _context33.t2;
5144
+ throw _context37.t2;
4878
5145
  case 43:
4879
5146
  if (!this.isSubmitResponseRejected(result)) {
4880
- _context33.next = 47;
5147
+ _context37.next = 47;
4881
5148
  break;
4882
5149
  }
4883
5150
  this.store.syncState = 'failed';
4884
5151
  this.logSubmitBackendRejected(result, payload);
4885
- return _context33.abrupt("return", result);
5152
+ return _context37.abrupt("return", result);
4886
5153
  case 47:
4887
5154
  submittedOrderId = this.extractOrderIdFromSubmitResult(result);
4888
5155
  this.logInfo('runSubmitTempOrder: 提交成功', {
@@ -4893,15 +5160,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4893
5160
  })
4894
5161
  });
4895
5162
  if (!(submittedOrderId !== null && submittedOrderId !== undefined)) {
4896
- _context33.next = 56;
5163
+ _context37.next = 56;
4897
5164
  break;
4898
5165
  }
4899
5166
  tempOrder.order_id = submittedOrderId;
4900
5167
  resultRecord = result;
4901
- _context33.next = 54;
5168
+ _context37.next = 54;
4902
5169
  return this.markLocalOrderSynced(submittedOrderId, (resultRecord === null || resultRecord === void 0 ? void 0 : resultRecord.data) || resultRecord || {});
4903
5170
  case 54:
4904
- _context33.next = 57;
5171
+ _context37.next = 57;
4905
5172
  break;
4906
5173
  case 56:
4907
5174
  if (this.isLocalPendingSubmitResult(result)) {
@@ -4910,14 +5177,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4910
5177
  this.store.syncState = 'submitted';
4911
5178
  }
4912
5179
  case 57:
4913
- return _context33.abrupt("return", result);
5180
+ return _context37.abrupt("return", result);
4914
5181
  case 58:
4915
5182
  case "end":
4916
- return _context33.stop();
5183
+ return _context37.stop();
4917
5184
  }
4918
- }, _callee30, this, [[26, 33]]);
5185
+ }, _callee34, this, [[26, 33]]);
4919
5186
  }));
4920
- function runSubmitTempOrder(_x34) {
5187
+ function runSubmitTempOrder(_x40) {
4921
5188
  return _runSubmitTempOrder.apply(this, arguments);
4922
5189
  }
4923
5190
  return runSubmitTempOrder;
@@ -4925,10 +5192,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4925
5192
  }, {
4926
5193
  key: "markLocalOrderSynced",
4927
5194
  value: function () {
4928
- var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(orderId, remoteOrder) {
5195
+ var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(orderId, remoteOrder) {
4929
5196
  var tempOrder;
4930
- return _regeneratorRuntime().wrap(function _callee31$(_context34) {
4931
- while (1) switch (_context34.prev = _context34.next) {
5197
+ return _regeneratorRuntime().wrap(function _callee35$(_context38) {
5198
+ while (1) switch (_context38.prev = _context38.next) {
4932
5199
  case 0:
4933
5200
  tempOrder = this.ensureTempOrder();
4934
5201
  tempOrder.order_id = orderId;
@@ -4936,15 +5203,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4936
5203
  this.store.lastOrderInfo = remoteOrder;
4937
5204
  this.store.syncState = 'submitted';
4938
5205
  this.persistTempOrder();
4939
- _context34.next = 8;
5206
+ _context38.next = 8;
4940
5207
  return this.saveDraft();
4941
5208
  case 8:
4942
5209
  case "end":
4943
- return _context34.stop();
5210
+ return _context38.stop();
4944
5211
  }
4945
- }, _callee31, this);
5212
+ }, _callee35, this);
4946
5213
  }));
4947
- function markLocalOrderSynced(_x35, _x36) {
5214
+ function markLocalOrderSynced(_x41, _x42) {
4948
5215
  return _markLocalOrderSynced.apply(this, arguments);
4949
5216
  }
4950
5217
  return markLocalOrderSynced;
@@ -4987,10 +5254,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4987
5254
  value: function extractSubmitErrorResponse(error) {
4988
5255
  var _error$response,
4989
5256
  _error$response2,
4990
- _this27 = this;
5257
+ _this30 = this;
4991
5258
  var candidates = [error === null || error === void 0 || (_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.data, error === null || error === void 0 ? void 0 : error.data, error === null || error === void 0 || (_error$response2 = error.response) === null || _error$response2 === void 0 ? void 0 : _error$response2.body, error === null || error === void 0 ? void 0 : error.body];
4992
5259
  return candidates.find(function (candidate) {
4993
- return _this27.isSubmitErrorResponse(candidate);
5260
+ return _this30.isSubmitErrorResponse(candidate);
4994
5261
  }) || null;
4995
5262
  }
4996
5263
  }, {
@@ -5017,14 +5284,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5017
5284
  }, {
5018
5285
  key: "syncPaymentsToOrder",
5019
5286
  value: function () {
5020
- var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(params) {
5021
- var _params$confirmPendin;
5022
- var tempOrder, mappedPayments, shouldConfirmPendingVoucherPayments, effectivePayments, completion, orderPaidPaymentTotal, paymentStatus, paymentSyncIdempotencyToken, submitParams, submitResult;
5023
- return _regeneratorRuntime().wrap(function _callee32$(_context35) {
5024
- while (1) switch (_context35.prev = _context35.next) {
5287
+ var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(params) {
5288
+ var _this31 = this,
5289
+ _params$confirmPendin;
5290
+ var tempOrder, needsPaymentNumber, devicePrefix, mappedPayments, shouldConfirmPendingVoucherPayments, effectivePayments, completion, orderPaidPaymentTotal, paymentStatus, paymentSyncIdempotencyToken, submitParams, submitResult;
5291
+ return _regeneratorRuntime().wrap(function _callee36$(_context39) {
5292
+ while (1) switch (_context39.prev = _context39.next) {
5025
5293
  case 0:
5026
5294
  tempOrder = this.ensureTempOrder();
5027
- mappedPayments = mapPaymentItemsToOrderPayments(params.payments || []);
5295
+ needsPaymentNumber = (params.payments || []).some(function (payment) {
5296
+ return String(payment.payment_number || '').trim() === '';
5297
+ });
5298
+ if (!needsPaymentNumber) {
5299
+ _context39.next = 8;
5300
+ break;
5301
+ }
5302
+ _context39.next = 5;
5303
+ return this.getPaymentNumberDevicePrefixAsync();
5304
+ case 5:
5305
+ _context39.t0 = _context39.sent;
5306
+ _context39.next = 9;
5307
+ break;
5308
+ case 8:
5309
+ _context39.t0 = 'LOCAL';
5310
+ case 9:
5311
+ devicePrefix = _context39.t0;
5312
+ mappedPayments = mapPaymentItemsToOrderPayments((params.payments || []).map(function (payment) {
5313
+ return _this31.normalizePaymentSource(payment, {
5314
+ defaultPaid: false,
5315
+ devicePrefix: devicePrefix
5316
+ });
5317
+ }));
5028
5318
  shouldConfirmPendingVoucherPayments = (_params$confirmPendin = params.confirmPendingVoucherPayments) !== null && _params$confirmPendin !== void 0 ? _params$confirmPendin : params.submitWhenPaid === true;
5029
5319
  effectivePayments = shouldConfirmPendingVoucherPayments ? this.confirmPendingVoucherPaymentsInList(mappedPayments) : params.confirmPendingVoucherPayments === false ? this.discardPendingVoucherPaymentsFromList(mappedPayments) : mappedPayments;
5030
5320
  completion = this.getPaymentCompletion(effectivePayments);
@@ -5033,21 +5323,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5033
5323
  tempOrder.payments = effectivePayments;
5034
5324
  tempOrder.payment_status = paymentStatus;
5035
5325
  this.persistTempOrder();
5036
- _context35.next = 12;
5326
+ _context39.next = 21;
5037
5327
  return this.saveDraft();
5038
- case 12:
5328
+ case 21:
5039
5329
  if (params.submitWhenPaid) {
5040
- _context35.next = 14;
5330
+ _context39.next = 23;
5041
5331
  break;
5042
5332
  }
5043
- return _context35.abrupt("return", completion);
5044
- case 14:
5333
+ return _context39.abrupt("return", completion);
5334
+ case 23:
5045
5335
  if (!(this.store.syncState === 'submitting')) {
5046
- _context35.next = 16;
5336
+ _context39.next = 25;
5047
5337
  break;
5048
5338
  }
5049
- return _context35.abrupt("return", completion);
5050
- case 16:
5339
+ return _context39.abrupt("return", completion);
5340
+ case 25:
5051
5341
  this.store.syncState = 'submitting';
5052
5342
  paymentSyncIdempotencyToken = this.buildPaymentSyncIdempotencyToken(tempOrder, effectivePayments);
5053
5343
  submitParams = {
@@ -5065,32 +5355,32 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5065
5355
  }
5066
5356
  };
5067
5357
  if (!(params.checkoutSyncTaskEnabled === false)) {
5068
- _context35.next = 25;
5358
+ _context39.next = 34;
5069
5359
  break;
5070
5360
  }
5071
- _context35.next = 22;
5361
+ _context39.next = 31;
5072
5362
  return this.submitTempOrderAsync(submitParams);
5073
- case 22:
5074
- _context35.t0 = _context35.sent;
5075
- _context35.next = 28;
5363
+ case 31:
5364
+ _context39.t1 = _context39.sent;
5365
+ _context39.next = 37;
5076
5366
  break;
5077
- case 25:
5078
- _context35.next = 27;
5367
+ case 34:
5368
+ _context39.next = 36;
5079
5369
  return this.submitTempOrder(submitParams);
5080
- case 27:
5081
- _context35.t0 = _context35.sent;
5082
- case 28:
5083
- submitResult = _context35.t0;
5084
- return _context35.abrupt("return", _objectSpread(_objectSpread({}, completion), {}, {
5370
+ case 36:
5371
+ _context39.t1 = _context39.sent;
5372
+ case 37:
5373
+ submitResult = _context39.t1;
5374
+ return _context39.abrupt("return", _objectSpread(_objectSpread({}, completion), {}, {
5085
5375
  submitResult: submitResult
5086
5376
  }));
5087
- case 30:
5377
+ case 39:
5088
5378
  case "end":
5089
- return _context35.stop();
5379
+ return _context39.stop();
5090
5380
  }
5091
- }, _callee32, this);
5381
+ }, _callee36, this);
5092
5382
  }));
5093
- function syncPaymentsToOrder(_x37) {
5383
+ function syncPaymentsToOrder(_x43) {
5094
5384
  return _syncPaymentsToOrder.apply(this, arguments);
5095
5385
  }
5096
5386
  return syncPaymentsToOrder;
@@ -5098,7 +5388,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5098
5388
  }, {
5099
5389
  key: "createOrder",
5100
5390
  value: function createOrder(params) {
5101
- var _this28 = this;
5391
+ var _this32 = this;
5102
5392
  var order = _objectSpread({
5103
5393
  type: (params === null || params === void 0 ? void 0 : params.type) || 'appointment_booking',
5104
5394
  // 要从外面拿,virtual
@@ -5130,7 +5420,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5130
5420
 
5131
5421
  // 为预约补齐 holder 信息
5132
5422
  if (params !== null && params !== void 0 && (_params$extraData = params.extraData) !== null && _params$extraData !== void 0 && _params$extraData.is_add_holder_info) {
5133
- ensureCartItemOriginHolder(item, _this28.window);
5423
+ ensureCartItemOriginHolder(item, _this32.window);
5134
5424
  }
5135
5425
 
5136
5426
  // 购物车是否为普通商品
@@ -5187,11 +5477,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5187
5477
  }, {
5188
5478
  key: "submitOrder",
5189
5479
  value: function () {
5190
- var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(order) {
5480
+ var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(order) {
5191
5481
  var _order$query$cartItem, _params$bookings, _params$relation_prod;
5192
5482
  var url, query, fetchUrl, params;
5193
- return _regeneratorRuntime().wrap(function _callee33$(_context36) {
5194
- while (1) switch (_context36.prev = _context36.next) {
5483
+ return _regeneratorRuntime().wrap(function _callee37$(_context40) {
5484
+ while (1) switch (_context40.prev = _context40.next) {
5195
5485
  case 0:
5196
5486
  this.logInfo('submitOrder called', {
5197
5487
  url: order.url,
@@ -5211,14 +5501,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5211
5501
  relationProductsCount: ((_params$relation_prod = params.relation_products) === null || _params$relation_prod === void 0 ? void 0 : _params$relation_prod.length) || 0,
5212
5502
  scheduleDate: params.schedule_date
5213
5503
  });
5214
- return _context36.abrupt("return", this.request.post(fetchUrl, params));
5504
+ return _context40.abrupt("return", this.request.post(fetchUrl, params));
5215
5505
  case 6:
5216
5506
  case "end":
5217
- return _context36.stop();
5507
+ return _context40.stop();
5218
5508
  }
5219
- }, _callee33, this);
5509
+ }, _callee37, this);
5220
5510
  }));
5221
- function submitOrder(_x38) {
5511
+ function submitOrder(_x44) {
5222
5512
  return _submitOrder.apply(this, arguments);
5223
5513
  }
5224
5514
  return submitOrder;
@@ -5226,13 +5516,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5226
5516
  }, {
5227
5517
  key: "cancelOrder",
5228
5518
  value: function () {
5229
- var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(params) {
5519
+ var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(params) {
5230
5520
  var payload;
5231
- return _regeneratorRuntime().wrap(function _callee34$(_context37) {
5232
- while (1) switch (_context37.prev = _context37.next) {
5521
+ return _regeneratorRuntime().wrap(function _callee38$(_context41) {
5522
+ while (1) switch (_context41.prev = _context41.next) {
5233
5523
  case 0:
5234
5524
  if (!(!Array.isArray(params.order_ids) || params.order_ids.length === 0)) {
5235
- _context37.next = 2;
5525
+ _context41.next = 2;
5236
5526
  break;
5237
5527
  }
5238
5528
  throw new Error('取消订单失败:order_ids 不能为空');
@@ -5248,16 +5538,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5248
5538
  method: 'PUT',
5249
5539
  orderIdsCount: params.order_ids.length
5250
5540
  });
5251
- return _context37.abrupt("return", this.request.put('/order/update-status', payload, {
5541
+ return _context41.abrupt("return", this.request.put('/order/update-status', payload, {
5252
5542
  isShopApi: true
5253
5543
  }));
5254
5544
  case 5:
5255
5545
  case "end":
5256
- return _context37.stop();
5546
+ return _context41.stop();
5257
5547
  }
5258
- }, _callee34, this);
5548
+ }, _callee38, this);
5259
5549
  }));
5260
- function cancelOrder(_x39) {
5550
+ function cancelOrder(_x45) {
5261
5551
  return _cancelOrder.apply(this, arguments);
5262
5552
  }
5263
5553
  return cancelOrder;
@@ -5265,19 +5555,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5265
5555
  }, {
5266
5556
  key: "changeBookingStatus",
5267
5557
  value: function () {
5268
- var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(params) {
5558
+ var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(params) {
5269
5559
  var url, payload;
5270
- return _regeneratorRuntime().wrap(function _callee35$(_context38) {
5271
- while (1) switch (_context38.prev = _context38.next) {
5560
+ return _regeneratorRuntime().wrap(function _callee39$(_context42) {
5561
+ while (1) switch (_context42.prev = _context42.next) {
5272
5562
  case 0:
5273
5563
  if (params.booking_id) {
5274
- _context38.next = 2;
5564
+ _context42.next = 2;
5275
5565
  break;
5276
5566
  }
5277
5567
  throw new Error('变更预约状态失败:booking_id 不能为空');
5278
5568
  case 2:
5279
5569
  if (params.appointment_status) {
5280
- _context38.next = 4;
5570
+ _context42.next = 4;
5281
5571
  break;
5282
5572
  }
5283
5573
  throw new Error('变更预约状态失败:appointment_status 不能为空');
@@ -5292,16 +5582,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5292
5582
  bookingId: params.booking_id,
5293
5583
  appointmentStatus: params.appointment_status
5294
5584
  });
5295
- return _context38.abrupt("return", this.request.put(url, payload, {
5585
+ return _context42.abrupt("return", this.request.put(url, payload, {
5296
5586
  isShopApi: true
5297
5587
  }));
5298
5588
  case 8:
5299
5589
  case "end":
5300
- return _context38.stop();
5590
+ return _context42.stop();
5301
5591
  }
5302
- }, _callee35, this);
5592
+ }, _callee39, this);
5303
5593
  }));
5304
- function changeBookingStatus(_x40) {
5594
+ function changeBookingStatus(_x46) {
5305
5595
  return _changeBookingStatus.apply(this, arguments);
5306
5596
  }
5307
5597
  return changeBookingStatus;
@@ -5319,11 +5609,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5319
5609
  }, {
5320
5610
  key: "createOrderByCheckout",
5321
5611
  value: (function () {
5322
- var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(params) {
5612
+ var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(params) {
5323
5613
  var _params$payments, _params$bookings2, _params$relation_prod2, _params$payments2, _params$payments3, _params$bookings3, _params$relation_prod3, _params$payments4;
5324
5614
  var onlineStorePaymentCodeList, _orderData$payments, _orderData$bookings, _orderData$relation_p, _orderData$payments2, _orderData$payments3, _orderData$bookings2, _orderData$relation_p2, _orderData$payments4, _orderData$payments5, _response$data, orderData, response;
5325
- return _regeneratorRuntime().wrap(function _callee36$(_context39) {
5326
- while (1) switch (_context39.prev = _context39.next) {
5615
+ return _regeneratorRuntime().wrap(function _callee40$(_context43) {
5616
+ while (1) switch (_context43.prev = _context43.next) {
5327
5617
  case 0:
5328
5618
  // 过滤掉由在线店铺下单的 payment 支付数据
5329
5619
  onlineStorePaymentCodeList = ['WXPAY', 'WECHAT', 'ALIPAY', 'APPLE_PAY', 'CREDIT_CARD_3DS', 'CREDIT_CARD_TOKEN', 'GOOGLE_PAY', 'GOOGLE_PAY_3DS', 'CREDIT_CARD'];
@@ -5357,7 +5647,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5357
5647
  relationProductsCount: ((_params$relation_prod3 = params.relation_products) === null || _params$relation_prod3 === void 0 ? void 0 : _params$relation_prod3.length) || 0,
5358
5648
  paymentsCount: ((_params$payments4 = params.payments) === null || _params$payments4 === void 0 ? void 0 : _params$payments4.length) || 0
5359
5649
  });
5360
- _context39.prev = 4;
5650
+ _context43.prev = 4;
5361
5651
  // 构建订单数据,设置默认值并允许 params 覆盖
5362
5652
  orderData = _objectSpread({
5363
5653
  sales_channel: 'my_pisel',
@@ -5419,13 +5709,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5419
5709
  hasOrderId: !!orderData.order_id,
5420
5710
  smallTicketDataFlag: orderData.small_ticket_data_flag
5421
5711
  });
5422
- _context39.next = 12;
5712
+ _context43.next = 12;
5423
5713
  return this.request.post('/order/checkout', orderData, {
5424
5714
  osServer: true,
5425
5715
  customToast: function customToast() {}
5426
5716
  });
5427
5717
  case 12:
5428
- response = _context39.sent;
5718
+ response = _context43.sent;
5429
5719
  this.logInfo('Order API called successfully', {
5430
5720
  response: response
5431
5721
  });
@@ -5433,22 +5723,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5433
5723
  success: !!response,
5434
5724
  hasOrderId: !!(response !== null && response !== void 0 && (_response$data = response.data) !== null && _response$data !== void 0 && _response$data.order_id || response !== null && response !== void 0 && response.order_id)
5435
5725
  });
5436
- return _context39.abrupt("return", response);
5726
+ return _context43.abrupt("return", response);
5437
5727
  case 18:
5438
- _context39.prev = 18;
5439
- _context39.t0 = _context39["catch"](4);
5440
- console.error('[Order] createOrderByCheckout 创建订单失败:', _context39.t0);
5728
+ _context43.prev = 18;
5729
+ _context43.t0 = _context43["catch"](4);
5730
+ console.error('[Order] createOrderByCheckout 创建订单失败:', _context43.t0);
5441
5731
  this.logInfo('Order API called failed', {
5442
- error: _context39.t0 instanceof Error ? _context39.t0.message : String(_context39.t0)
5732
+ error: _context43.t0 instanceof Error ? _context43.t0.message : String(_context43.t0)
5443
5733
  });
5444
- throw _context39.t0;
5734
+ throw _context43.t0;
5445
5735
  case 23:
5446
5736
  case "end":
5447
- return _context39.stop();
5737
+ return _context43.stop();
5448
5738
  }
5449
- }, _callee36, this, [[4, 18]]);
5739
+ }, _callee40, this, [[4, 18]]);
5450
5740
  }));
5451
- function createOrderByCheckout(_x41) {
5741
+ function createOrderByCheckout(_x47) {
5452
5742
  return _createOrderByCheckout.apply(this, arguments);
5453
5743
  }
5454
5744
  return createOrderByCheckout;
@@ -5456,24 +5746,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5456
5746
  }, {
5457
5747
  key: "submitSalesOrder",
5458
5748
  value: function () {
5459
- var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(params) {
5749
+ var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(params) {
5460
5750
  var url, query, fetchUrl;
5461
- return _regeneratorRuntime().wrap(function _callee37$(_context40) {
5462
- while (1) switch (_context40.prev = _context40.next) {
5751
+ return _regeneratorRuntime().wrap(function _callee41$(_context44) {
5752
+ while (1) switch (_context44.prev = _context44.next) {
5463
5753
  case 0:
5464
5754
  url = params.url, query = params.query;
5465
5755
  fetchUrl = url || '/order/sales/checkout';
5466
- return _context40.abrupt("return", this.request.post(fetchUrl, query, {
5756
+ return _context44.abrupt("return", this.request.post(fetchUrl, query, {
5467
5757
  osServer: true,
5468
5758
  customToast: function customToast() {}
5469
5759
  }));
5470
5760
  case 3:
5471
5761
  case "end":
5472
- return _context40.stop();
5762
+ return _context44.stop();
5473
5763
  }
5474
- }, _callee37, this);
5764
+ }, _callee41, this);
5475
5765
  }));
5476
- function submitSalesOrder(_x42) {
5766
+ function submitSalesOrder(_x48) {
5477
5767
  return _submitSalesOrder.apply(this, arguments);
5478
5768
  }
5479
5769
  return submitSalesOrder;
@@ -5487,37 +5777,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5487
5777
  }, {
5488
5778
  key: "sendCustomerPayLink",
5489
5779
  value: (function () {
5490
- var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(params) {
5780
+ var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42(params) {
5491
5781
  var _params$emails;
5492
5782
  var orderIds;
5493
- return _regeneratorRuntime().wrap(function _callee38$(_context41) {
5494
- while (1) switch (_context41.prev = _context41.next) {
5783
+ return _regeneratorRuntime().wrap(function _callee42$(_context45) {
5784
+ while (1) switch (_context45.prev = _context45.next) {
5495
5785
  case 0:
5496
5786
  orderIds = params.order_ids || params.orderIds || [];
5497
5787
  if (orderIds.length) {
5498
- _context41.next = 3;
5788
+ _context45.next = 3;
5499
5789
  break;
5500
5790
  }
5501
5791
  throw new Error('发送支付链接前必须先提交本地订单并取得订单 ID');
5502
5792
  case 3:
5503
5793
  if ((_params$emails = params.emails) !== null && _params$emails !== void 0 && _params$emails.length) {
5504
- _context41.next = 5;
5794
+ _context45.next = 5;
5505
5795
  break;
5506
5796
  }
5507
5797
  throw new Error('发送支付链接需要至少一个邮箱');
5508
5798
  case 5:
5509
- return _context41.abrupt("return", this.request.post('/order/batch-email', {
5799
+ return _context45.abrupt("return", this.request.post('/order/batch-email', {
5510
5800
  order_ids: orderIds,
5511
5801
  notify_action: params.notify_action || 'order_payment_reminder',
5512
5802
  emails: params.emails
5513
5803
  }));
5514
5804
  case 6:
5515
5805
  case "end":
5516
- return _context41.stop();
5806
+ return _context45.stop();
5517
5807
  }
5518
- }, _callee38, this);
5808
+ }, _callee42, this);
5519
5809
  }));
5520
- function sendCustomerPayLink(_x43) {
5810
+ function sendCustomerPayLink(_x49) {
5521
5811
  return _sendCustomerPayLink.apply(this, arguments);
5522
5812
  }
5523
5813
  return sendCustomerPayLink;
@@ -5525,14 +5815,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5525
5815
  }, {
5526
5816
  key: "getSalesOrderByLookup",
5527
5817
  value: function () {
5528
- var _getSalesOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(params) {
5818
+ var _getSalesOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43(params) {
5529
5819
  var lookup, res;
5530
- return _regeneratorRuntime().wrap(function _callee39$(_context42) {
5531
- while (1) switch (_context42.prev = _context42.next) {
5820
+ return _regeneratorRuntime().wrap(function _callee43$(_context46) {
5821
+ while (1) switch (_context46.prev = _context46.next) {
5532
5822
  case 0:
5533
5823
  lookup = params.lookup === undefined || params.lookup === null ? '' : String(params.lookup).trim();
5534
5824
  if (lookup) {
5535
- _context42.next = 3;
5825
+ _context46.next = 3;
5536
5826
  break;
5537
5827
  }
5538
5828
  throw new Error('加载销售详情需要 lookup');
@@ -5541,27 +5831,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5541
5831
  if (lookup.startsWith('LOCAL_')) {
5542
5832
  params.forceRemote = false;
5543
5833
  }
5544
- _context42.next = 6;
5834
+ _context46.next = 6;
5545
5835
  return this.request.get("/order/sales/".concat(encodeURIComponent(lookup)), _objectSpread({
5546
- with: ['products', 'bookings', 'payments', 'customer', 'summary', 'contacts_info']
5836
+ with: ['products', 'bookings', 'payments', 'customer', 'summary', 'contacts_info', 'refunds']
5547
5837
  }, params.forceRemote ? {
5548
5838
  forceRemote: true
5549
5839
  } : {}), {
5550
5840
  osServer: true
5551
5841
  });
5552
5842
  case 6:
5553
- res = _context42.sent;
5843
+ res = _context46.sent;
5554
5844
  if (res.code === 200) {
5555
5845
  this.store.lastOrderInfo = res.data;
5556
5846
  }
5557
- return _context42.abrupt("return", res);
5847
+ return _context46.abrupt("return", res);
5558
5848
  case 9:
5559
5849
  case "end":
5560
- return _context42.stop();
5850
+ return _context46.stop();
5561
5851
  }
5562
- }, _callee39, this);
5852
+ }, _callee43, this);
5563
5853
  }));
5564
- function getSalesOrderByLookup(_x44) {
5854
+ function getSalesOrderByLookup(_x50) {
5565
5855
  return _getSalesOrderByLookup.apply(this, arguments);
5566
5856
  }
5567
5857
  return getSalesOrderByLookup;
@@ -5575,11 +5865,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5575
5865
  }, {
5576
5866
  key: "hydrateTempOrderFromRecord",
5577
5867
  value: (function () {
5578
- var _hydrateTempOrderFromRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(record, options) {
5579
- var _this$store$discount19;
5580
- var sourceRaw, identityReadySource, normalizedCollections, raw, hasIdentityChanges, identityLogMetadata, hasIdentityWarnings, nextTempOrder, rawSummary, summarySurcharges, hydratedEditDiscounts, currentDiscounts, currentScanDiscounts, hydratedDiscountIds, retainedScanDiscounts, nextDiscounts, shouldSkipEmptyDiscountSync, _this$store$discount20, _this$store$discount21;
5581
- return _regeneratorRuntime().wrap(function _callee40$(_context43) {
5582
- while (1) switch (_context43.prev = _context43.next) {
5868
+ var _hydrateTempOrderFromRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee44(record, options) {
5869
+ var _this$store$discount20;
5870
+ var sourceRaw, identityReadySource, normalizedCollections, raw, hasIdentityChanges, identityLogMetadata, hasIdentityWarnings, nextTempOrder, sourceLastOrderInfo, isDraftOrder, syntheticIdentityOptions, rawSummary, summarySurcharges, hadSyntheticDraftOrderId, hydratedEditDiscounts, currentDiscounts, currentScanDiscounts, hydratedDiscountIds, retainedScanDiscounts, nextDiscounts, shouldSkipEmptyDiscountSync, _this$store$discount21, _this$store$discount22;
5871
+ return _regeneratorRuntime().wrap(function _callee44$(_context47) {
5872
+ while (1) switch (_context47.prev = _context47.next) {
5583
5873
  case 0:
5584
5874
  sourceRaw = record && _typeof(record) === 'object' && record.data && record.order_id == null ? record.data : record || {};
5585
5875
  identityReadySource = this.seedAnonymousBookingUidsFromProducts(sourceRaw);
@@ -5604,7 +5894,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5604
5894
  }
5605
5895
  nextTempOrder = this.normalizeTempOrderForRuntime(raw, {
5606
5896
  makeEditMark: true
5607
- });
5897
+ }); // Server list compatibility may synthesize order_id from external_sale_number; tempOrder must not.
5898
+ sourceLastOrderInfo = raw.lastOrderInfo || raw;
5899
+ isDraftOrder = Number(nextTempOrder.is_draft_order || 0) === 1;
5900
+ syntheticIdentityOptions = {
5901
+ isDraftOrder: isDraftOrder,
5902
+ externalSaleNumber: nextTempOrder.external_sale_number
5903
+ };
5608
5904
  rawSummary = raw.summary && _typeof(raw.summary) === 'object' ? raw.summary : {};
5609
5905
  summarySurcharges = Array.isArray(rawSummary.surcharges) ? rawSummary.surcharges.map(function (s) {
5610
5906
  return _objectSpread({}, s || {});
@@ -5624,12 +5920,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5624
5920
  productFingerprint: this.buildOrderProductsFingerprint(nextTempOrder.products || [])
5625
5921
  }
5626
5922
  });
5627
- // lastOrderInfo carries the exact backend snapshot used by deposit/type recovery.
5628
- // Runtime collection repair lives in tempOrder/originalSalesSnapshot and must not
5629
- // rewrite this protocol snapshot as a side effect of hydration.
5630
- this.store.lastOrderInfo = sourceRaw.lastOrderInfo || sourceRaw;
5923
+ this.store.lastOrderInfo = this.withoutSyntheticDraftOrderIdForRuntime(sourceLastOrderInfo, syntheticIdentityOptions);
5924
+ hadSyntheticDraftOrderId = this.isSyntheticDraftOrderIdForRuntime(raw, syntheticIdentityOptions) || this.isSyntheticDraftOrderIdForRuntime(sourceLastOrderInfo, syntheticIdentityOptions);
5925
+ if (hadSyntheticDraftOrderId && this.store.syncState !== 'submitting') {
5926
+ this.store.syncState = 'local';
5927
+ }
5631
5928
  hydratedEditDiscounts = this.collectHydratedEditDiscounts(nextTempOrder.products);
5632
- currentDiscounts = typeof ((_this$store$discount19 = this.store.discount) === null || _this$store$discount19 === void 0 ? void 0 : _this$store$discount19.getDiscountList) === 'function' ? this.store.discount.getDiscountList() || [] : [];
5929
+ currentDiscounts = typeof ((_this$store$discount20 = this.store.discount) === null || _this$store$discount20 === void 0 ? void 0 : _this$store$discount20.getDiscountList) === 'function' ? this.store.discount.getDiscountList() || [] : [];
5633
5930
  currentScanDiscounts = currentDiscounts.filter(function (discount) {
5634
5931
  return discount === null || discount === void 0 ? void 0 : discount.isScan;
5635
5932
  });
@@ -5642,34 +5939,34 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5642
5939
  nextDiscounts = [].concat(_toConsumableArray(hydratedEditDiscounts), _toConsumableArray(retainedScanDiscounts));
5643
5940
  shouldSkipEmptyDiscountSync = nextDiscounts.length === 0 && currentDiscounts.length === 0;
5644
5941
  if (shouldSkipEmptyDiscountSync) {
5645
- _context43.next = 26;
5942
+ _context47.next = 31;
5646
5943
  break;
5647
5944
  }
5648
5945
  OrderModule.populateSavedAmounts(nextTempOrder.products, nextDiscounts);
5649
- _context43.next = 24;
5650
- return (_this$store$discount20 = this.store.discount) === null || _this$store$discount20 === void 0 ? void 0 : _this$store$discount20.setOriginalDiscountList(nextDiscounts);
5651
- case 24:
5652
- _context43.next = 26;
5653
- return (_this$store$discount21 = this.store.discount) === null || _this$store$discount21 === void 0 ? void 0 : _this$store$discount21.setDiscountList(nextDiscounts);
5654
- case 26:
5946
+ _context47.next = 29;
5947
+ return (_this$store$discount21 = this.store.discount) === null || _this$store$discount21 === void 0 ? void 0 : _this$store$discount21.setOriginalDiscountList(nextDiscounts);
5948
+ case 29:
5949
+ _context47.next = 31;
5950
+ return (_this$store$discount22 = this.store.discount) === null || _this$store$discount22 === void 0 ? void 0 : _this$store$discount22.setDiscountList(nextDiscounts);
5951
+ case 31:
5655
5952
  if (!(options !== null && options !== void 0 && options.recalcOnHydrate)) {
5656
- _context43.next = 29;
5953
+ _context47.next = 34;
5657
5954
  break;
5658
5955
  }
5659
- _context43.next = 29;
5956
+ _context47.next = 34;
5660
5957
  return this.recalculateSummary({
5661
5958
  createIfMissing: false
5662
5959
  });
5663
- case 29:
5960
+ case 34:
5664
5961
  this.persistTempOrder();
5665
- return _context43.abrupt("return", nextTempOrder);
5666
- case 31:
5962
+ return _context47.abrupt("return", nextTempOrder);
5963
+ case 36:
5667
5964
  case "end":
5668
- return _context43.stop();
5965
+ return _context47.stop();
5669
5966
  }
5670
- }, _callee40, this);
5967
+ }, _callee44, this);
5671
5968
  }));
5672
- function hydrateTempOrderFromRecord(_x45, _x46) {
5969
+ function hydrateTempOrderFromRecord(_x51, _x52) {
5673
5970
  return _hydrateTempOrderFromRecord.apply(this, arguments);
5674
5971
  }
5675
5972
  return hydrateTempOrderFromRecord;
@@ -5783,11 +6080,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5783
6080
  }, {
5784
6081
  key: "normalizeTempOrderForRuntime",
5785
6082
  value: function normalizeTempOrderForRuntime(raw, options) {
5786
- var _this29 = this;
5787
- var nextTempOrder = _objectSpread(_objectSpread({}, this.createDefaultTempOrderInstance()), raw || {});
6083
+ var _this33 = this;
6084
+ var runtimeRaw = this.withoutSyntheticDraftOrderIdForRuntime(raw);
6085
+ var nextTempOrder = _objectSpread(_objectSpread({}, this.createDefaultTempOrderInstance()), runtimeRaw || {});
5788
6086
  // ES 列表详情使用 id 表示订单主键;OS 详情态统一依赖 order_id 驱动操作按钮。
5789
- if ((nextTempOrder.order_id === undefined || nextTempOrder.order_id === null) && (raw === null || raw === void 0 ? void 0 : raw.id) !== undefined && (raw === null || raw === void 0 ? void 0 : raw.id) !== null) {
5790
- nextTempOrder.order_id = raw.id;
6087
+ if ((nextTempOrder.order_id === undefined || nextTempOrder.order_id === null) && (runtimeRaw === null || runtimeRaw === void 0 ? void 0 : runtimeRaw.id) !== undefined && (runtimeRaw === null || runtimeRaw === void 0 ? void 0 : runtimeRaw.id) !== null) {
6088
+ nextTempOrder.order_id = runtimeRaw.id;
5791
6089
  }
5792
6090
  delete nextTempOrder.summary;
5793
6091
  delete nextTempOrder.lastOrderInfo;
@@ -5806,12 +6104,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5806
6104
  nextTempOrder.holder = raw.holder && _typeof(raw.holder) === 'object' ? _objectSpread({}, raw.holder) : null;
5807
6105
  var rawProducts = Array.isArray(raw.products) ? raw.products : [];
5808
6106
  nextTempOrder.products = rawProducts.length > 0 ? rawProducts.map(function (p) {
5809
- return _this29.normalizeHydratedOrderProduct(p, {
6107
+ return _this33.normalizeHydratedOrderProduct(p, {
5810
6108
  makeEditMark: options === null || options === void 0 ? void 0 : options.makeEditMark
5811
6109
  });
5812
6110
  }) : [];
5813
6111
  nextTempOrder.bookings = Array.isArray(raw.bookings) ? raw.bookings.map(function (b) {
5814
- var booking = _this29.normalizeHydratedBookingHolder(b || {});
6112
+ var booking = _this33.normalizeHydratedBookingHolder(b || {});
5815
6113
  return _objectSpread(_objectSpread({}, booking), {}, {
5816
6114
  is_all: normalizeBookingIsAll(booking),
5817
6115
  sub_type: normalizeBookingSubType(booking)
@@ -5877,6 +6175,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5877
6175
  nextTempOrder.vouchers = raw.vouchers || [];
5878
6176
  return nextTempOrder;
5879
6177
  }
6178
+ }, {
6179
+ key: "isSyntheticDraftOrderIdForRuntime",
6180
+ value: function isSyntheticDraftOrderIdForRuntime(record, options) {
6181
+ var _options$isDraftOrder, _record$external_sale;
6182
+ var isDraftOrder = (_options$isDraftOrder = options === null || options === void 0 ? void 0 : options.isDraftOrder) !== null && _options$isDraftOrder !== void 0 ? _options$isDraftOrder : Number((record === null || record === void 0 ? void 0 : record.is_draft_order) || 0) === 1;
6183
+ var externalSaleNumber = (_record$external_sale = record === null || record === void 0 ? void 0 : record.external_sale_number) !== null && _record$external_sale !== void 0 ? _record$external_sale : options === null || options === void 0 ? void 0 : options.externalSaleNumber;
6184
+ var orderId = record === null || record === void 0 ? void 0 : record.order_id;
6185
+ return Boolean(isDraftOrder && orderId !== undefined && orderId !== null && orderId !== '' && externalSaleNumber !== undefined && externalSaleNumber !== null && externalSaleNumber !== '' && String(orderId) === String(externalSaleNumber));
6186
+ }
6187
+ }, {
6188
+ key: "withoutSyntheticDraftOrderIdForRuntime",
6189
+ value: function withoutSyntheticDraftOrderIdForRuntime(record, options) {
6190
+ if (!this.isSyntheticDraftOrderIdForRuntime(record, options)) return record;
6191
+ return _objectSpread(_objectSpread({}, record), {}, {
6192
+ order_id: null
6193
+ });
6194
+ }
5880
6195
  }, {
5881
6196
  key: "hydrateLinkedBookingIdentity",
5882
6197
  value: function hydrateLinkedBookingIdentity(tempOrder) {
@@ -5981,7 +6296,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5981
6296
  }, {
5982
6297
  key: "normalizeHydratedOrderProduct",
5983
6298
  value: function normalizeHydratedOrderProduct(product, options) {
5984
- var _this30 = this;
6299
+ var _this34 = this;
5985
6300
  var row = _objectSpread({}, product || {});
5986
6301
  if (row.num === undefined && row.product_quantity !== undefined) {
5987
6302
  row.num = row.product_quantity;
@@ -5989,7 +6304,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5989
6304
  var productSku = ensureProductSku(row);
5990
6305
  row.product_sku = _objectSpread(_objectSpread({}, productSku), {}, {
5991
6306
  option: normalizeProductSkuOptions(productSku.option.map(function (optionItem) {
5992
- return _this30.normalizeHydratedProductOptionItem(optionItem || {});
6307
+ return _this34.normalizeHydratedProductOptionItem(optionItem || {});
5993
6308
  }))
5994
6309
  });
5995
6310
  delete row["product_".concat('option', "_item")];
@@ -6026,27 +6341,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6026
6341
  }, {
6027
6342
  key: "getOrderInfo",
6028
6343
  value: function () {
6029
- var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(order_id) {
6344
+ var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee45(order_id) {
6030
6345
  var res;
6031
- return _regeneratorRuntime().wrap(function _callee41$(_context44) {
6032
- while (1) switch (_context44.prev = _context44.next) {
6346
+ return _regeneratorRuntime().wrap(function _callee45$(_context48) {
6347
+ while (1) switch (_context48.prev = _context48.next) {
6033
6348
  case 0:
6034
- _context44.next = 2;
6349
+ _context48.next = 2;
6035
6350
  return this.request.get("/order/sales/".concat(order_id), {
6036
6351
  with: ['products', 'bookings']
6037
6352
  }, {
6038
6353
  osServer: true
6039
6354
  });
6040
6355
  case 2:
6041
- res = _context44.sent;
6042
- return _context44.abrupt("return", res);
6356
+ res = _context48.sent;
6357
+ return _context48.abrupt("return", res);
6043
6358
  case 4:
6044
6359
  case "end":
6045
- return _context44.stop();
6360
+ return _context48.stop();
6046
6361
  }
6047
- }, _callee41, this);
6362
+ }, _callee45, this);
6048
6363
  }));
6049
- function getOrderInfo(_x47) {
6364
+ function getOrderInfo(_x53) {
6050
6365
  return _getOrderInfo.apply(this, arguments);
6051
6366
  }
6052
6367
  return getOrderInfo;