@pisell/pisellos 2.2.181 → 2.2.182

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 (175) hide show
  1. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  2. package/dist/modules/BookingContext/index.d.ts +37 -0
  3. package/dist/modules/BookingContext/index.js +436 -0
  4. package/dist/modules/BookingContext/types.d.ts +102 -0
  5. package/dist/modules/BookingContext/types.js +51 -0
  6. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  7. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +276 -0
  8. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  9. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +137 -0
  10. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +75 -0
  11. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +215 -0
  12. package/dist/modules/BookingContext/utils/flexible.d.ts +28 -0
  13. package/dist/modules/BookingContext/utils/flexible.js +56 -0
  14. package/dist/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  15. package/dist/modules/BookingContext/utils/formatResourceList.js +38 -0
  16. package/dist/modules/BookingContext/utils/index.d.ts +11 -0
  17. package/dist/modules/BookingContext/utils/index.js +11 -0
  18. package/dist/modules/BookingContext/utils/noResource.d.ts +13 -0
  19. package/dist/modules/BookingContext/utils/noResource.js +77 -0
  20. package/dist/modules/BookingContext/utils/productExtend.d.ts +72 -0
  21. package/dist/modules/BookingContext/utils/productExtend.js +339 -0
  22. package/dist/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  23. package/dist/modules/BookingContext/utils/resourceErrors.js +74 -0
  24. package/dist/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  25. package/dist/modules/BookingContext/utils/resourceSelection.js +24 -0
  26. package/dist/modules/BookingContext/utils/resources.d.ts +80 -0
  27. package/dist/modules/BookingContext/utils/resources.js +486 -0
  28. package/dist/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  29. package/dist/modules/BookingContext/utils/serviceTimes.js +151 -0
  30. package/dist/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  31. package/dist/modules/BookingContext/utils/timeSlices.js +100 -0
  32. package/dist/modules/Customer/index.d.ts +6 -0
  33. package/dist/modules/Customer/index.js +129 -83
  34. package/dist/modules/Customer/types.d.ts +2 -0
  35. package/dist/modules/Discount/index.js +4 -3
  36. package/dist/modules/Discount/types.d.ts +1 -0
  37. package/dist/modules/Order/index.d.ts +101 -10
  38. package/dist/modules/Order/index.js +1444 -490
  39. package/dist/modules/Order/types.d.ts +201 -18
  40. package/dist/modules/Order/types.js +31 -0
  41. package/dist/modules/Order/utils/manualProductDiscount.d.ts +106 -0
  42. package/dist/modules/Order/utils/manualProductDiscount.js +210 -0
  43. package/dist/modules/Order/utils.d.ts +83 -1
  44. package/dist/modules/Order/utils.js +405 -61
  45. package/dist/modules/Product/index.d.ts +1 -1
  46. package/dist/modules/Quotation/index.d.ts +0 -1
  47. package/dist/modules/Quotation/index.js +23 -21
  48. package/dist/modules/Rules/index.d.ts +4 -0
  49. package/dist/modules/Rules/index.js +43 -39
  50. package/dist/modules/Rules/types.d.ts +1 -0
  51. package/dist/modules/SalesSummary/index.js +4 -2
  52. package/dist/modules/SalesSummary/utils.js +21 -7
  53. package/dist/modules/Schedule/index.js +6 -2
  54. package/dist/modules/index.d.ts +1 -0
  55. package/dist/modules/index.js +2 -1
  56. package/dist/server/index.js +87 -29
  57. package/dist/server/modules/order/index.d.ts +23 -0
  58. package/dist/server/modules/order/index.js +123 -46
  59. package/dist/server/modules/order/utils/filterOrders.js +20 -6
  60. package/dist/server/modules/products/index.d.ts +1 -1
  61. package/dist/server/modules/products/index.js +130 -113
  62. package/dist/server/modules/schedule/index.js +13 -6
  63. package/dist/solution/BaseSales/index.d.ts +89 -7
  64. package/dist/solution/BaseSales/index.js +1489 -366
  65. package/dist/solution/BaseSales/types.d.ts +67 -1
  66. package/dist/solution/BaseSales/types.js +3 -1
  67. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +275 -0
  68. package/dist/solution/BaseSales/utils/cartPromotion.js +1258 -0
  69. package/dist/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
  70. package/dist/solution/BaseSales/utils/quotationPrice.js +237 -0
  71. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +68 -16
  72. package/dist/solution/BaseSales/utils.js +46 -8
  73. package/dist/solution/BookingByStep/index.d.ts +1 -1
  74. package/dist/solution/BookingTicket/index.d.ts +152 -2
  75. package/dist/solution/BookingTicket/index.js +848 -184
  76. package/dist/solution/BookingTicket/types.d.ts +2 -0
  77. package/dist/solution/BookingTicket/types.js +3 -0
  78. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +113 -0
  79. package/dist/solution/BookingTicket/utils/addProductDecision.js +346 -0
  80. package/dist/solution/BookingTicket/utils/cartView.js +4 -2
  81. package/dist/solution/ScanOrder/index.d.ts +9 -3
  82. package/dist/solution/ScanOrder/index.js +231 -128
  83. package/dist/solution/ScanOrder/utils.js +46 -8
  84. package/dist/solution/VenueBooking/index.d.ts +5 -2
  85. package/dist/solution/VenueBooking/index.js +103 -55
  86. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
  87. package/dist/solution/VenueBooking/utils/slotMerge.js +10 -0
  88. package/lib/model/strategy/adapter/promotion/index.js +49 -0
  89. package/lib/modules/BookingContext/index.d.ts +37 -0
  90. package/lib/modules/BookingContext/index.js +297 -0
  91. package/lib/modules/BookingContext/types.d.ts +102 -0
  92. package/lib/modules/BookingContext/types.js +34 -0
  93. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  94. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +271 -0
  95. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  96. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +141 -0
  97. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +75 -0
  98. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +198 -0
  99. package/lib/modules/BookingContext/utils/flexible.d.ts +28 -0
  100. package/lib/modules/BookingContext/utils/flexible.js +80 -0
  101. package/lib/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  102. package/lib/modules/BookingContext/utils/formatResourceList.js +50 -0
  103. package/lib/modules/BookingContext/utils/index.d.ts +11 -0
  104. package/lib/modules/BookingContext/utils/index.js +43 -0
  105. package/lib/modules/BookingContext/utils/noResource.d.ts +13 -0
  106. package/lib/modules/BookingContext/utils/noResource.js +90 -0
  107. package/lib/modules/BookingContext/utils/productExtend.d.ts +72 -0
  108. package/lib/modules/BookingContext/utils/productExtend.js +283 -0
  109. package/lib/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  110. package/lib/modules/BookingContext/utils/resourceErrors.js +80 -0
  111. package/lib/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  112. package/lib/modules/BookingContext/utils/resourceSelection.js +46 -0
  113. package/lib/modules/BookingContext/utils/resources.d.ts +80 -0
  114. package/lib/modules/BookingContext/utils/resources.js +377 -0
  115. package/lib/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  116. package/lib/modules/BookingContext/utils/serviceTimes.js +162 -0
  117. package/lib/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  118. package/lib/modules/BookingContext/utils/timeSlices.js +124 -0
  119. package/lib/modules/Customer/index.d.ts +6 -0
  120. package/lib/modules/Customer/index.js +26 -11
  121. package/lib/modules/Customer/types.d.ts +2 -0
  122. package/lib/modules/Discount/index.js +5 -1
  123. package/lib/modules/Discount/types.d.ts +1 -0
  124. package/lib/modules/Order/index.d.ts +101 -10
  125. package/lib/modules/Order/index.js +751 -114
  126. package/lib/modules/Order/types.d.ts +201 -18
  127. package/lib/modules/Order/types.js +1 -0
  128. package/lib/modules/Order/utils/manualProductDiscount.d.ts +106 -0
  129. package/lib/modules/Order/utils/manualProductDiscount.js +206 -0
  130. package/lib/modules/Order/utils.d.ts +83 -1
  131. package/lib/modules/Order/utils.js +340 -22
  132. package/lib/modules/Product/index.d.ts +1 -1
  133. package/lib/modules/Quotation/index.d.ts +0 -1
  134. package/lib/modules/Quotation/index.js +18 -15
  135. package/lib/modules/Rules/index.d.ts +4 -0
  136. package/lib/modules/Rules/index.js +26 -27
  137. package/lib/modules/Rules/types.d.ts +1 -0
  138. package/lib/modules/SalesSummary/index.js +4 -2
  139. package/lib/modules/SalesSummary/utils.js +21 -7
  140. package/lib/modules/Schedule/index.js +3 -1
  141. package/lib/modules/index.d.ts +1 -0
  142. package/lib/modules/index.js +3 -1
  143. package/lib/server/index.js +41 -4
  144. package/lib/server/modules/order/index.d.ts +23 -0
  145. package/lib/server/modules/order/index.js +46 -14
  146. package/lib/server/modules/order/utils/filterOrders.js +12 -4
  147. package/lib/server/modules/products/index.d.ts +1 -1
  148. package/lib/server/modules/products/index.js +30 -20
  149. package/lib/server/modules/schedule/index.js +2 -1
  150. package/lib/solution/BaseSales/index.d.ts +89 -7
  151. package/lib/solution/BaseSales/index.js +742 -23
  152. package/lib/solution/BaseSales/types.d.ts +67 -1
  153. package/lib/solution/BaseSales/types.js +3 -1
  154. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +275 -0
  155. package/lib/solution/BaseSales/utils/cartPromotion.js +836 -0
  156. package/lib/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
  157. package/lib/solution/BaseSales/utils/quotationPrice.js +277 -0
  158. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +71 -12
  159. package/lib/solution/BaseSales/utils.js +46 -6
  160. package/lib/solution/BookingByStep/index.d.ts +1 -1
  161. package/lib/solution/BookingTicket/index.d.ts +152 -2
  162. package/lib/solution/BookingTicket/index.js +389 -9
  163. package/lib/solution/BookingTicket/types.d.ts +2 -0
  164. package/lib/solution/BookingTicket/types.js +6 -0
  165. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +113 -0
  166. package/lib/solution/BookingTicket/utils/addProductDecision.js +318 -0
  167. package/lib/solution/BookingTicket/utils/cartView.js +4 -2
  168. package/lib/solution/ScanOrder/index.d.ts +9 -3
  169. package/lib/solution/ScanOrder/index.js +147 -66
  170. package/lib/solution/ScanOrder/utils.js +46 -6
  171. package/lib/solution/VenueBooking/index.d.ts +5 -2
  172. package/lib/solution/VenueBooking/index.js +50 -14
  173. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
  174. package/lib/solution/VenueBooking/utils/slotMerge.js +10 -0
  175. package/package.json +1 -1
@@ -1,11 +1,11 @@
1
- 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; } } }; }
2
1
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
3
2
  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."); }
4
- 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); }
5
3
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
6
4
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
7
- 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; }
8
5
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
6
+ 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; } } }; }
7
+ 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); }
8
+ 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; }
9
9
  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; }
10
10
  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; }
11
11
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
@@ -26,10 +26,12 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
26
26
  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); }
27
27
  import { BaseModule } from "../BaseModule";
28
28
  import { OrderHooks } from "./types";
29
- import { generateDuration, getAllDiscountList, mergeRelationForms, buildSubmitPayload, createDefaultTempOrder, createDefaultOrderRulesHooks, createEmptySummary, createUuidV4, formatDateTime, isTempOrder, normalizeBookingIsAll, normalizeBookingSubType, mapPaymentItemsToOrderPayments } from "./utils";
29
+ import { composeLinePrice, generateDuration, getAllDiscountList, mergeRelationForms, buildSubmitPayload, createDefaultTempOrder, createDefaultOrderRulesHooks, createEmptySummary, createUuidV4, formatDateTime, isTempOrder, normalizeBookingIsAll, normalizeBookingSubType, mapPaymentItemsToOrderPayments, normalizeOrderProductDiscountList, resolveEffectivePerUnitDiscount, sumOptionUnitPrice, clearTempOrderHolderAssignments, getOrderProductLineUid, indexOrderProductsByUid, mergeOrderProductDisplayFields } from "./utils";
30
30
  import { isNormalProduct } from "../Product/utils";
31
31
  import dayjs from 'dayjs';
32
+ import { processCartPromotion, appendPromotionTags as _appendPromotionTags, getOrderProductUid as getPromotionUid } from "../../solution/BaseSales/utils/cartPromotion";
32
33
  import { buildProductLineFingerprint, getProductIdentityIndex, getSafeProductNum, isIdentityMatch, normalizeOrderProduct } from "../../solution/ScanOrder/utils";
34
+ import { syncManualProductDiscountProductNum } from "./utils/manualProductDiscount";
33
35
  import { DiscountModule } from "../Discount";
34
36
  import { RulesModule } from "../Rules";
35
37
  import { UnavailableReason } from "../Rules/types";
@@ -56,9 +58,47 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
56
58
  _defineProperty(_assertThisInitialized(_this), "rulesHooksOverride", void 0);
57
59
  _defineProperty(_assertThisInitialized(_this), "orderHooks", void 0);
58
60
  _defineProperty(_assertThisInitialized(_this), "otherParams", void 0);
61
+ // ─── 促销/赠品 ────────────────────────────────────
62
+ /** 评估器引用;由 SalesSdkProvider 注入,未注入时 applyPromotion 静默跳过 */
63
+ _defineProperty(_assertThisInitialized(_this), "promotionEvaluator", null);
64
+ /** 赠品选择 resolver;由 SDK host bridge 注入 */
65
+ _defineProperty(_assertThisInitialized(_this), "giftSelectResolver", null);
66
+ /** applyPromotion 递归保护 flag(写路径同步调 applyPromotion,禁止重入) */
67
+ _defineProperty(_assertThisInitialized(_this), "isApplyingPromotion", false);
68
+ /** 最近一次 applyPromotion 的未满足促销提示 */
69
+ _defineProperty(_assertThisInitialized(_this), "lastUnfulfilledPromotions", []);
70
+ /** 最近一次 applyPromotion 的赠品操作 diff(debug / SDK 读取使用) */
71
+ _defineProperty(_assertThisInitialized(_this), "lastGiftActions", null);
72
+ /**
73
+ * 是否将 tempOrder 写入 IndexedDB 草稿(orders store)。
74
+ * BigSale 弹窗等短生命周期场景通过 setEnableTempOrderPersist(false) 关闭。
75
+ */
76
+ _defineProperty(_assertThisInitialized(_this), "draftPersistEnabled", true);
59
77
  return _this;
60
78
  }
61
79
  _createClass(OrderModule, [{
80
+ key: "applyProductDiscountPrices",
81
+ value: function applyProductDiscountPrices(products) {
82
+ return (products || []).map(function (product) {
83
+ var _product$metadata, _product$metadata$sou, _product$metadata2, _product$metadata3, _product$original_pri;
84
+ if ((_product$metadata = product.metadata) !== null && _product$metadata !== void 0 && _product$metadata.is_manual_discount) return product;
85
+ var totalPerUnitDiscount = resolveEffectivePerUnitDiscount(product);
86
+ var optionSum = sumOptionUnitPrice(product.product_option_item);
87
+ var sourcePrice = (_product$metadata$sou = (_product$metadata2 = product.metadata) === null || _product$metadata2 === void 0 ? void 0 : _product$metadata2.source_product_price) !== null && _product$metadata$sou !== void 0 ? _product$metadata$sou : ((_product$metadata3 = product.metadata) === null || _product$metadata3 === void 0 ? void 0 : _product$metadata3.main_product_original_price) != null ? new Decimal(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : (_product$original_pri = product.original_price) !== null && _product$original_pri !== void 0 ? _product$original_pri : '0';
88
+ var newSourceSellingPrice = new Decimal(Number(sourcePrice) || 0).minus(totalPerUnitDiscount).toDecimalPlaces(2).toString();
89
+ var newMainSellingPrice = new Decimal(Number(newSourceSellingPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
90
+ if (product.metadata) {
91
+ product.metadata.main_product_selling_price = newMainSellingPrice;
92
+ product.metadata.price_schema_version = 2;
93
+ }
94
+ product.selling_price = composeLinePrice({
95
+ mainPrice: newMainSellingPrice,
96
+ bundle: product.product_bundle
97
+ });
98
+ return product;
99
+ });
100
+ }
101
+ }, {
62
102
  key: "initialize",
63
103
  value: function () {
64
104
  var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
@@ -94,9 +134,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
94
134
  this.orderHooks = options.hooks || ((_otherParams$order = otherParams.order) === null || _otherParams$order === void 0 ? void 0 : _otherParams$order.hooks) || ((_otherParams$hooks = otherParams.hooks) === null || _otherParams$hooks === void 0 ? void 0 : _otherParams$hooks.order);
95
135
  this.otherParams = otherParams;
96
136
  this.registerDiscountModules(options);
97
- this.restoreTempOrderFromStorage();
98
137
  this.logInfo('OrderModule initialized successfully');
99
- case 21:
138
+ case 20:
100
139
  case "end":
101
140
  return _context.stop();
102
141
  }
@@ -196,29 +235,40 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
196
235
  key: "loadDiscountConfig",
197
236
  value: function () {
198
237
  var _loadDiscountConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params) {
199
- var _this$store$discount, _this$store$tempOrder;
200
- var discountList, _this$store$discount2;
238
+ var _this$store$tempOrder, _this$store$discount, _this$store$tempOrder2;
239
+ var orderId, discountList, _this$store$discount2, _this$store$discount3;
201
240
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
202
241
  while (1) switch (_context2.prev = _context2.next) {
203
242
  case 0:
204
- _context2.next = 2;
205
- return (_this$store$discount = this.store.discount) === null || _this$store$discount === void 0 ? void 0 : _this$store$discount.loadPrepareConfig({
243
+ orderId = params.orderId || ((_this$store$tempOrder = this.store.tempOrder) === null || _this$store$tempOrder === void 0 ? void 0 : _this$store$tempOrder.order_id) || undefined;
244
+ _context2.next = 3;
245
+ return (_this$store$discount = this.store.discount) === null || _this$store$discount === void 0 ? void 0 : _this$store$discount.loadPrepareConfig(_objectSpread({
206
246
  customer_id: params.customerId,
207
- action: params.action || 'create',
247
+ action: params.action || (orderId ? 'edit' : 'create'),
208
248
  with_good_pass: 1,
209
249
  with_discount_card: 1,
210
250
  with_wallet_pass_holder: 1,
211
251
  request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
212
- });
213
- case 2:
252
+ }, orderId ? {
253
+ order_id: orderId
254
+ } : {}));
255
+ case 3:
214
256
  discountList = _context2.sent;
215
- if (discountList) {
216
- (_this$store$discount2 = this.store.discount) === null || _this$store$discount2 === void 0 || _this$store$discount2.setDiscountList(discountList);
257
+ if (!discountList) {
258
+ _context2.next = 9;
259
+ break;
217
260
  }
218
- if ((_this$store$tempOrder = this.store.tempOrder) !== null && _this$store$tempOrder !== void 0 && (_this$store$tempOrder = _this$store$tempOrder.products) !== null && _this$store$tempOrder !== void 0 && _this$store$tempOrder.length) {
261
+ _context2.next = 7;
262
+ return (_this$store$discount2 = this.store.discount) === null || _this$store$discount2 === void 0 ? void 0 : _this$store$discount2.setOriginalDiscountList(discountList);
263
+ case 7:
264
+ _context2.next = 9;
265
+ return (_this$store$discount3 = this.store.discount) === null || _this$store$discount3 === void 0 ? void 0 : _this$store$discount3.setDiscountList(discountList);
266
+ case 9:
267
+ if (params.apply !== false && (_this$store$tempOrder2 = this.store.tempOrder) !== null && _this$store$tempOrder2 !== void 0 && (_this$store$tempOrder2 = _this$store$tempOrder2.products) !== null && _this$store$tempOrder2 !== void 0 && _this$store$tempOrder2.length) {
219
268
  this.applyDiscount();
220
269
  }
221
- case 5:
270
+ return _context2.abrupt("return", this.getDiscountList());
271
+ case 11:
222
272
  case "end":
223
273
  return _context2.stop();
224
274
  }
@@ -232,20 +282,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
232
282
  }, {
233
283
  key: "getDiscountList",
234
284
  value: function getDiscountList() {
235
- var _this$store$discount3;
236
- return ((_this$store$discount3 = this.store.discount) === null || _this$store$discount3 === void 0 ? void 0 : _this$store$discount3.getDiscountList()) || [];
285
+ var _this$store$discount4;
286
+ return ((_this$store$discount4 = this.store.discount) === null || _this$store$discount4 === void 0 ? void 0 : _this$store$discount4.getDiscountList()) || [];
237
287
  }
238
288
  }, {
239
289
  key: "scanCode",
240
290
  value: function () {
241
291
  var _scanCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(code, customerId) {
242
- var _this$store$discount4, _tempOrder$holder, _this$store$summary, _tempOrder$holder2;
243
- var resultDiscountWithReason, resultDiscountList, unavailableReasonKey, rulesModule, withScanList, currentSelected, tempOrder, holders, _ref, isAvailable, newDiscountList, unavailableReason, _this$store$discount5;
292
+ var _this$store$discount5, _tempOrder$holder, _this$store$summary, _tempOrder$holder2;
293
+ var resultDiscountWithReason, resultDiscountList, unavailableReasonKey, rulesModule, withScanList, currentSelected, tempOrder, holders, _ref, isAvailable, newDiscountList, unavailableReason, _this$store$discount6;
244
294
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
245
295
  while (1) switch (_context3.prev = _context3.next) {
246
296
  case 0:
247
297
  _context3.next = 2;
248
- return (_this$store$discount4 = this.store.discount) === null || _this$store$discount4 === void 0 ? void 0 : _this$store$discount4.batchSearch(code, {
298
+ return (_this$store$discount5 = this.store.discount) === null || _this$store$discount5 === void 0 ? void 0 : _this$store$discount5.batchSearch(code, {
249
299
  customerId: customerId
250
300
  });
251
301
  case 2:
@@ -270,6 +320,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
270
320
  type: 'clientCalc',
271
321
  isAvailable: false,
272
322
  discountList: this.getDiscountList(),
323
+ scannedDiscountList: resultDiscountList,
273
324
  unavailableReason: UnavailableReason.Unknown
274
325
  });
275
326
  case 10:
@@ -281,6 +332,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
281
332
  type: 'server',
282
333
  isAvailable: false,
283
334
  discountList: this.getDiscountList(),
335
+ scannedDiscountList: resultDiscountList,
284
336
  unavailableReasonKey: unavailableReasonKey
285
337
  });
286
338
  case 12:
@@ -303,7 +355,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
303
355
  return _context3.abrupt("return", {
304
356
  type: 'clientCalc',
305
357
  isAvailable: true,
306
- discountList: this.getDiscountList()
358
+ discountList: this.getDiscountList(),
359
+ scannedDiscountList: resultDiscountList
307
360
  });
308
361
  case 16:
309
362
  tempOrder = this.store.tempOrder;
@@ -322,13 +375,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
322
375
  discountList: this.getDiscountList()
323
376
  }, isAvailable = _ref.isAvailable, newDiscountList = _ref.discountList, unavailableReason = _ref.unavailableReason;
324
377
  if (isAvailable && newDiscountList) {
325
- (_this$store$discount5 = this.store.discount) === null || _this$store$discount5 === void 0 || _this$store$discount5.setDiscountList(newDiscountList);
378
+ (_this$store$discount6 = this.store.discount) === null || _this$store$discount6 === void 0 || _this$store$discount6.setDiscountList(newDiscountList);
326
379
  this.applyDiscount();
327
380
  }
328
381
  return _context3.abrupt("return", {
329
382
  type: 'clientCalc',
330
383
  isAvailable: isAvailable || false,
331
384
  discountList: newDiscountList || this.getDiscountList(),
385
+ scannedDiscountList: resultDiscountList,
332
386
  unavailableReason: unavailableReason
333
387
  });
334
388
  case 21:
@@ -345,15 +399,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
345
399
  }, {
346
400
  key: "applyDiscount",
347
401
  value: function applyDiscount() {
348
- var _this$store$discount6, _tempOrder$holder3, _tempOrder$holder4, _this$store$summary2;
402
+ var _this$store$discount7, _tempOrder$holder3, _tempOrder$holder4, _this$store$summary2;
349
403
  var tempOrder = this.store.tempOrder;
350
404
  // 任意 products CRUD 后都应当重算 discount 状态;即使 products 为空,
351
405
  // 也需要让 Rules.calcDiscount 把 DiscountModule 的 isSelected / isAvailable /
352
- // appliedProductDetails / savedAmount 以及 tempOrder.discount_list 复位。
406
+ // appliedProductDetails / savedAmount 复位。
353
407
  if (!tempOrder) return;
408
+ delete tempOrder.discount_list;
354
409
  var rulesModule = this.store.rules;
355
410
  if (!rulesModule) return;
356
- var discountList = ((_this$store$discount6 = this.store.discount) === null || _this$store$discount6 === void 0 ? void 0 : _this$store$discount6.getDiscountList()) || [];
411
+ var discountList = ((_this$store$discount7 = this.store.discount) === null || _this$store$discount7 === void 0 ? void 0 : _this$store$discount7.getDiscountList()) || [];
357
412
  var holders = (_tempOrder$holder3 = tempOrder.holder) !== null && _tempOrder$holder3 !== void 0 && _tempOrder$holder3.form_record_id ? [{
358
413
  form_record_id: tempOrder.holder.form_record_id
359
414
  }] : [];
@@ -365,94 +420,395 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
365
420
  orderTotalAmount: Number(((_this$store$summary2 = this.store.summary) === null || _this$store$summary2 === void 0 ? void 0 : _this$store$summary2.total_amount) || 0)
366
421
  });
367
422
  if (result !== null && result !== void 0 && result.productList) {
368
- tempOrder.products = result.productList;
423
+ var previousProductsByUid = indexOrderProductsByUid(tempOrder.products);
424
+ tempOrder.products = this.applyProductDiscountPrices((result.productList || []).map(function (product, index) {
425
+ var _ref2;
426
+ var uid = getOrderProductLineUid(product);
427
+ var previous = (_ref2 = uid ? previousProductsByUid.get(uid) : undefined) !== null && _ref2 !== void 0 ? _ref2 : previousProductsByUid.get("__index__:".concat(index));
428
+ var mergedProduct = previous ? mergeOrderProductDisplayFields(previous, product) : product;
429
+ return _objectSpread(_objectSpread({}, mergedProduct), {}, {
430
+ discount_list: normalizeOrderProductDiscountList(syncManualProductDiscountProductNum(mergedProduct.discount_list, mergedProduct.num))
431
+ });
432
+ }));
369
433
  }
370
434
  if (result !== null && result !== void 0 && result.discountList) {
371
- var _this$store$discount7;
435
+ var _this$store$discount8;
372
436
  OrderModule.populateSavedAmounts(result.productList || tempOrder.products, result.discountList);
373
- (_this$store$discount7 = this.store.discount) === null || _this$store$discount7 === void 0 || _this$store$discount7.setDiscountList(result.discountList);
374
- tempOrder.discount_list = result.discountList.filter(function (d) {
375
- return d.isSelected;
376
- });
437
+ (_this$store$discount8 = this.store.discount) === null || _this$store$discount8 === void 0 || _this$store$discount8.setDiscountList(result.discountList);
377
438
  }
378
439
  }
379
440
 
441
+ // ─── 促销/赠品 ──────────────────────────────────────
442
+
443
+ /**
444
+ * 注入促销评估器。
445
+ *
446
+ * @example
447
+ * order.setPromotionEvaluator(appHelper.utils.promotionEvaluator);
448
+ */
449
+ }, {
450
+ key: "setPromotionEvaluator",
451
+ value: function setPromotionEvaluator(evaluator) {
452
+ this.promotionEvaluator = evaluator || null;
453
+ }
454
+
455
+ /**
456
+ * 注入赠品选择 resolver。OS 需要补赠品时会 await 调用 resolver;缺省时跳过新增并 console.warn。
457
+ *
458
+ * @example
459
+ * order.setGiftSelectResolver(async (ctx) => {
460
+ * // SDK 内部决定弹窗 or 自动选第一项,返回完整 OrderProduct[]
461
+ * return giftSelectBridge.request(ctx);
462
+ * });
463
+ */
464
+ }, {
465
+ key: "setGiftSelectResolver",
466
+ value: function setGiftSelectResolver(resolver) {
467
+ this.giftSelectResolver = resolver || null;
468
+ }
469
+
470
+ /**
471
+ * 为商品目录追加促销标签,供上层 Sales 门面复用。
472
+ *
473
+ * @example
474
+ * const products = order.appendPromotionTags(catalogProducts);
475
+ */
476
+ }, {
477
+ key: "appendPromotionTags",
478
+ value: function appendPromotionTags(products) {
479
+ return _appendPromotionTags(products, this.promotionEvaluator);
480
+ }
481
+
482
+ /**
483
+ * 应用购物车促销:计算 → 差异化赠品 → 写回 tempOrder.products → emit onPromotionApplied。
484
+ *
485
+ * 调用时机:写路径(add/update/remove/clear/setCustomer)末尾自动触发;外部一般无需手动调。
486
+ *
487
+ * 关键约束:
488
+ * - 不调用任何公开 CRUD API(如 removeProductFromOrder),全部内部 mutate tempOrder.products,避免事件风暴;
489
+ * - 用 `isApplyingPromotion` 防递归;
490
+ * - 多选项赠品依赖 giftSelectResolver,未注入则跳过且 console.warn;
491
+ * - 不主动调用 applyDiscount / recalculateSummary,调用方负责跟进。
492
+ */
493
+ }, {
494
+ key: "applyPromotion",
495
+ value: (function () {
496
+ var _applyPromotion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
497
+ var _this2 = this;
498
+ var tempOrder, result, removeSet, _iterator, _step, reduce, _iterator4, _step4, _loop2, _iterator2, _step2, _loop, payload;
499
+ return _regeneratorRuntime().wrap(function _callee4$(_context6) {
500
+ while (1) switch (_context6.prev = _context6.next) {
501
+ case 0:
502
+ if (!this.isApplyingPromotion) {
503
+ _context6.next = 2;
504
+ break;
505
+ }
506
+ return _context6.abrupt("return");
507
+ case 2:
508
+ if (this.promotionEvaluator) {
509
+ _context6.next = 4;
510
+ break;
511
+ }
512
+ return _context6.abrupt("return");
513
+ case 4:
514
+ tempOrder = this.store.tempOrder;
515
+ if (tempOrder) {
516
+ _context6.next = 7;
517
+ break;
518
+ }
519
+ return _context6.abrupt("return");
520
+ case 7:
521
+ this.isApplyingPromotion = true;
522
+ _context6.prev = 8;
523
+ result = processCartPromotion(tempOrder.products, this.promotionEvaluator); // step 1: toRemove —— 直接过滤
524
+ if (result.giftActions.toRemove.length > 0) {
525
+ removeSet = new Set(result.giftActions.toRemove.map(String));
526
+ result.products = result.products.filter(function (p) {
527
+ var uid = getPromotionUid(p);
528
+ return uid ? !removeSet.has(String(uid)) : true;
529
+ });
530
+ }
531
+
532
+ // step 2: toReduce —— 调整数量
533
+ _iterator = _createForOfIteratorHelper(result.giftActions.toReduce);
534
+ _context6.prev = 12;
535
+ _iterator.s();
536
+ case 14:
537
+ if ((_step = _iterator.n()).done) {
538
+ _context6.next = 34;
539
+ break;
540
+ }
541
+ reduce = _step.value;
542
+ _iterator4 = _createForOfIteratorHelper(reduce.items);
543
+ _context6.prev = 17;
544
+ _loop2 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop2() {
545
+ var item, product;
546
+ return _regeneratorRuntime().wrap(function _loop2$(_context5) {
547
+ while (1) switch (_context5.prev = _context5.next) {
548
+ case 0:
549
+ item = _step4.value;
550
+ product = result.products.find(function (p) {
551
+ return getPromotionUid(p) === item.uid;
552
+ });
553
+ if (product) {
554
+ product.num = item.newQuantity;
555
+ }
556
+ case 3:
557
+ case "end":
558
+ return _context5.stop();
559
+ }
560
+ }, _loop2);
561
+ });
562
+ _iterator4.s();
563
+ case 20:
564
+ if ((_step4 = _iterator4.n()).done) {
565
+ _context6.next = 24;
566
+ break;
567
+ }
568
+ return _context6.delegateYield(_loop2(), "t0", 22);
569
+ case 22:
570
+ _context6.next = 20;
571
+ break;
572
+ case 24:
573
+ _context6.next = 29;
574
+ break;
575
+ case 26:
576
+ _context6.prev = 26;
577
+ _context6.t1 = _context6["catch"](17);
578
+ _iterator4.e(_context6.t1);
579
+ case 29:
580
+ _context6.prev = 29;
581
+ _iterator4.f();
582
+ return _context6.finish(29);
583
+ case 32:
584
+ _context6.next = 14;
585
+ break;
586
+ case 34:
587
+ _context6.next = 39;
588
+ break;
589
+ case 36:
590
+ _context6.prev = 36;
591
+ _context6.t2 = _context6["catch"](12);
592
+ _iterator.e(_context6.t2);
593
+ case 39:
594
+ _context6.prev = 39;
595
+ _iterator.f();
596
+ return _context6.finish(39);
597
+ case 42:
598
+ if (!(result.giftActions.toAdd.length > 0)) {
599
+ _context6.next = 65;
600
+ break;
601
+ }
602
+ if (this.giftSelectResolver) {
603
+ _context6.next = 47;
604
+ break;
605
+ }
606
+ if (result.giftActions.toAdd.some(function (g) {
607
+ return g.giftOptions.length > 1;
608
+ })) {
609
+ // 多选项必须走 resolver;单选项也建议走(避免 OS 自造 stub),但允许跳过
610
+ console.warn('[OrderModule] giftSelectResolver not set, skip applying gifts', result.giftActions.toAdd);
611
+ } else {
612
+ console.warn('[OrderModule] giftSelectResolver not set, skip applying single-option gifts', result.giftActions.toAdd);
613
+ }
614
+ _context6.next = 65;
615
+ break;
616
+ case 47:
617
+ _iterator2 = _createForOfIteratorHelper(result.giftActions.toAdd);
618
+ _context6.prev = 48;
619
+ _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
620
+ var addAction, sameStrategy, giftProducts, _iterator3, _step3, gp;
621
+ return _regeneratorRuntime().wrap(function _loop$(_context4) {
622
+ while (1) switch (_context4.prev = _context4.next) {
623
+ case 0:
624
+ addAction = _step2.value;
625
+ if (!(addAction.giftOptions.length === 1)) {
626
+ _context4.next = 6;
627
+ break;
628
+ }
629
+ sameStrategy = result.products.find(function (p) {
630
+ var _p$metadata;
631
+ return ((_p$metadata = p.metadata) === null || _p$metadata === void 0 || (_p$metadata = _p$metadata._giftInfo) === null || _p$metadata === void 0 ? void 0 : _p$metadata.strategyId) === addAction.strategyId;
632
+ });
633
+ if (!sameStrategy) {
634
+ _context4.next = 6;
635
+ break;
636
+ }
637
+ sameStrategy.num = (Number(sameStrategy.num) || 0) + (addAction.giftCount || 1);
638
+ return _context4.abrupt("return", 1);
639
+ case 6:
640
+ _context4.prev = 6;
641
+ _context4.next = 9;
642
+ return _this2.giftSelectResolver({
643
+ strategyId: addAction.strategyId,
644
+ strategyName: addAction.strategyName,
645
+ giftCount: addAction.giftCount,
646
+ giftOptions: addAction.giftOptions,
647
+ sourceProductIds: addAction.sourceProductIds
648
+ });
649
+ case 9:
650
+ giftProducts = _context4.sent;
651
+ if (!(Array.isArray(giftProducts) && giftProducts.length > 0)) {
652
+ _context4.next = 29;
653
+ break;
654
+ }
655
+ _iterator3 = _createForOfIteratorHelper(giftProducts);
656
+ _context4.prev = 12;
657
+ _iterator3.s();
658
+ case 14:
659
+ if ((_step3 = _iterator3.n()).done) {
660
+ _context4.next = 21;
661
+ break;
662
+ }
663
+ gp = _step3.value;
664
+ if (gp) {
665
+ _context4.next = 18;
666
+ break;
667
+ }
668
+ return _context4.abrupt("continue", 19);
669
+ case 18:
670
+ // normalize 略过:调用方应保证返回完整 OrderProduct
671
+ result.products.push(gp);
672
+ case 19:
673
+ _context4.next = 14;
674
+ break;
675
+ case 21:
676
+ _context4.next = 26;
677
+ break;
678
+ case 23:
679
+ _context4.prev = 23;
680
+ _context4.t0 = _context4["catch"](12);
681
+ _iterator3.e(_context4.t0);
682
+ case 26:
683
+ _context4.prev = 26;
684
+ _iterator3.f();
685
+ return _context4.finish(26);
686
+ case 29:
687
+ _context4.next = 34;
688
+ break;
689
+ case 31:
690
+ _context4.prev = 31;
691
+ _context4.t1 = _context4["catch"](6);
692
+ // 用户取消 / 选择失败 → 视为放弃本次新增
693
+ console.warn('[OrderModule] giftSelectResolver rejected, skip add gift', addAction.strategyId, _context4.t1);
694
+ case 34:
695
+ case "end":
696
+ return _context4.stop();
697
+ }
698
+ }, _loop, null, [[6, 31], [12, 23, 26, 29]]);
699
+ });
700
+ _iterator2.s();
701
+ case 51:
702
+ if ((_step2 = _iterator2.n()).done) {
703
+ _context6.next = 57;
704
+ break;
705
+ }
706
+ return _context6.delegateYield(_loop(), "t3", 53);
707
+ case 53:
708
+ if (!_context6.t3) {
709
+ _context6.next = 55;
710
+ break;
711
+ }
712
+ return _context6.abrupt("continue", 55);
713
+ case 55:
714
+ _context6.next = 51;
715
+ break;
716
+ case 57:
717
+ _context6.next = 62;
718
+ break;
719
+ case 59:
720
+ _context6.prev = 59;
721
+ _context6.t4 = _context6["catch"](48);
722
+ _iterator2.e(_context6.t4);
723
+ case 62:
724
+ _context6.prev = 62;
725
+ _iterator2.f();
726
+ return _context6.finish(62);
727
+ case 65:
728
+ tempOrder.products = result.products;
729
+ this.lastUnfulfilledPromotions = result.unfulfilledPromotions;
730
+ this.lastGiftActions = result.giftActions;
731
+ payload = {
732
+ unfulfilledPromotions: result.unfulfilledPromotions,
733
+ giftActions: result.giftActions,
734
+ gifts: result.gifts.map(function (g) {
735
+ return {
736
+ strategyId: g.strategyId,
737
+ strategyName: g.strategyName,
738
+ giftCount: g.giftCount,
739
+ giftOptions: g.giftOptions
740
+ };
741
+ }),
742
+ products: tempOrder.products
743
+ };
744
+ this.effectsEmit('onPromotionApplied', payload);
745
+ _context6.next = 75;
746
+ break;
747
+ case 72:
748
+ _context6.prev = 72;
749
+ _context6.t5 = _context6["catch"](8);
750
+ console.error('[OrderModule] applyPromotion failed', _context6.t5);
751
+ case 75:
752
+ _context6.prev = 75;
753
+ this.isApplyingPromotion = false;
754
+ return _context6.finish(75);
755
+ case 78:
756
+ case "end":
757
+ return _context6.stop();
758
+ }
759
+ }, _callee4, this, [[8, 72, 75, 78], [12, 36, 39, 42], [17, 26, 29, 32], [48, 59, 62, 65]]);
760
+ }));
761
+ function applyPromotion() {
762
+ return _applyPromotion.apply(this, arguments);
763
+ }
764
+ return applyPromotion;
765
+ }() /** 最近一次 applyPromotion 输出的未满足促销列表 */)
766
+ }, {
767
+ key: "getUnfulfilledPromotions",
768
+ value: function getUnfulfilledPromotions() {
769
+ return this.lastUnfulfilledPromotions;
770
+ }
771
+
772
+ /** 最近一次 applyPromotion 输出的赠品操作 diff */
773
+ }, {
774
+ key: "getLastGiftActions",
775
+ value: function getLastGiftActions() {
776
+ return this.lastGiftActions;
777
+ }
778
+
380
779
  // ─── TempOrder: 初始化入口 ───
381
780
  }, {
382
781
  key: "initTempOrder",
383
782
  value: function initTempOrder(params) {
384
783
  if (params.cacheId !== undefined) this.cacheId = params.cacheId;
385
784
  if (params.salesSummaryModuleName !== undefined) this.salesSummaryModuleName = params.salesSummaryModuleName;
386
- this.restoreTempOrderFromStorage();
387
785
  }
388
786
 
389
- // ─── TempOrder: localStorage 持久化 ───
787
+ /**
788
+ * 控制 IndexedDB 草稿(saveDraft)是否写入。
789
+ * localStorage 版 tempOrder 持久化已废弃,此方法仅影响 saveDraft。
790
+ *
791
+ * @example
792
+ * order.setEnableTempOrderPersist(false); // BigSale 弹窗:跳过 ~1s 的 dbUpdate
793
+ */
390
794
  }, {
391
- key: "getTempOrderStorageKey",
392
- value: function getTempOrderStorageKey() {
393
- if (!this.cacheId) return null;
394
- return "scanOrder:tempOrder:".concat(this.cacheId);
795
+ key: "setEnableTempOrderPersist",
796
+ value: function setEnableTempOrderPersist(enabled) {
797
+ this.draftPersistEnabled = enabled;
395
798
  }
799
+
800
+ /** 是否允许 saveDraft 写入 IndexedDB 草稿。 */
396
801
  }, {
397
- key: "restoreTempOrderFromStorage",
398
- value: function restoreTempOrderFromStorage() {
399
- var key = this.getTempOrderStorageKey();
400
- if (!key) return;
401
- if (!this.window) return;
402
- var cachedData = this.window.localStorage.getItem(key);
403
- if (!cachedData) return;
404
- try {
405
- var parsedData = JSON.parse(cachedData);
406
- if (!isTempOrder(parsedData)) {
407
- this.window.localStorage.removeItem(key);
408
- return;
409
- }
410
- if (Array.isArray(parsedData.products)) {
411
- for (var i = 0; i < parsedData.products.length; i++) {
412
- var p = parsedData.products[i];
413
- if (!p || _typeof(p) !== 'object') continue;
414
- if (!Array.isArray(p.product_option_item)) {
415
- p.product_option_item = [];
416
- }
417
- if (!Array.isArray(p.product_bundle)) {
418
- p.product_bundle = [];
419
- }
420
- var row = p;
421
- // 价格 schema 迁移:重跑 normalizeOrderProduct。
422
- // `metadata.price_schema_version === 2` → 已是新语义,保留现有 main_product_* 折扣;
423
- // 否则(v1 或无 metadata)→ 走 legacyDiscount 反推分支,基于新的 source + options
424
- // 重算出含 option 的 main_product_*,并打上 price_schema_version: 2。
425
- // 幂等:多次 restore 不会重复叠加 option/bundle。
426
- parsedData.products[i] = normalizeOrderProduct(row);
427
- }
428
- }
429
- var parsedRecord = parsedData;
430
- this.store.summary = parsedRecord.summary || createEmptySummary();
431
- delete parsedData.summary;
432
- if (parsedRecord.lastOrderInfo) {
433
- this.store.lastOrderInfo = parsedRecord.lastOrderInfo;
434
- delete parsedData.lastOrderInfo;
435
- }
436
- if (!parsedData._extend || _typeof(parsedData._extend) !== 'object') {
437
- parsedData._extend = {
438
- productsByUid: {}
439
- };
440
- } else if (!parsedData._extend.productsByUid) {
441
- parsedData._extend.productsByUid = {};
442
- }
443
- this.store.tempOrder = parsedData;
444
- } catch (_unused2) {
445
- var _this$window;
446
- (_this$window = this.window) === null || _this$window === void 0 || (_this$window = _this$window.localStorage) === null || _this$window === void 0 || _this$window.removeItem(key);
447
- }
802
+ key: "isTempOrderPersistEnabled",
803
+ value: function isTempOrderPersistEnabled() {
804
+ return this.draftPersistEnabled;
448
805
  }
806
+
807
+ /** @deprecated OrderModule 不再负责 tempOrder localStorage 持久化;草稿保存请使用 IndexedDB saveDraft。 */
449
808
  }, {
450
809
  key: "persistTempOrder",
451
810
  value: function persistTempOrder() {
452
- var key = this.getTempOrderStorageKey();
453
- if (!key || !this.store.tempOrder) return;
454
- if (!this.window) return;
455
- this.window.localStorage.setItem(key, JSON.stringify(this.store.tempOrder));
811
+ // no-op: OrderModule 的刷新恢复不再依赖 localStorage。
456
812
  }
457
813
 
458
814
  // ─── TempOrder: 创建 & 获取 ───
@@ -509,6 +865,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
509
865
  }
510
866
  return tempOrder.request_unique_idempotency_token;
511
867
  }
868
+ }, {
869
+ key: "buildPaymentSyncIdempotencyToken",
870
+ value: function buildPaymentSyncIdempotencyToken(tempOrder, payments) {
871
+ var baseToken = this.ensureRequestUniqueIdempotencyToken(tempOrder);
872
+ var paidPaymentsCount = (payments || []).filter(function (payment) {
873
+ return String((payment === null || payment === void 0 ? void 0 : payment.status) || '').toLowerCase() === 'paid';
874
+ }).length;
875
+ var paidCount = paidPaymentsCount > 0 ? paidPaymentsCount : payments.length;
876
+ return "".concat(baseToken, "_payment_").concat(paidCount);
877
+ }
512
878
  }, {
513
879
  key: "hasLocalDatabase",
514
880
  value: function hasLocalDatabase() {
@@ -529,48 +895,48 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
529
895
  }, {
530
896
  key: "getLocalOrderByOrderId",
531
897
  value: function () {
532
- var _getLocalOrderByOrderId = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(orderId) {
898
+ var _getLocalOrderByOrderId = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(orderId) {
533
899
  var _this$dbManager$get, _this$dbManager, _this$dbManager$getAl, _this$dbManager2, direct, orders;
534
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
535
- while (1) switch (_context4.prev = _context4.next) {
900
+ return _regeneratorRuntime().wrap(function _callee5$(_context7) {
901
+ while (1) switch (_context7.prev = _context7.next) {
536
902
  case 0:
537
903
  if (!(!this.dbManager || orderId === undefined || orderId === null)) {
538
- _context4.next = 2;
904
+ _context7.next = 2;
539
905
  break;
540
906
  }
541
- return _context4.abrupt("return", null);
907
+ return _context7.abrupt("return", null);
542
908
  case 2:
543
- _context4.prev = 2;
544
- _context4.next = 5;
909
+ _context7.prev = 2;
910
+ _context7.next = 5;
545
911
  return (_this$dbManager$get = (_this$dbManager = this.dbManager).get) === null || _this$dbManager$get === void 0 ? void 0 : _this$dbManager$get.call(_this$dbManager, LOCAL_ORDER_STORE_NAME, orderId);
546
912
  case 5:
547
- direct = _context4.sent;
913
+ direct = _context7.sent;
548
914
  if (!direct) {
549
- _context4.next = 8;
915
+ _context7.next = 8;
550
916
  break;
551
917
  }
552
- return _context4.abrupt("return", direct);
918
+ return _context7.abrupt("return", direct);
553
919
  case 8:
554
- _context4.next = 10;
920
+ _context7.next = 10;
555
921
  return (_this$dbManager$getAl = (_this$dbManager2 = this.dbManager).getAll) === null || _this$dbManager$getAl === void 0 ? void 0 : _this$dbManager$getAl.call(_this$dbManager2, LOCAL_ORDER_STORE_NAME);
556
922
  case 10:
557
- orders = _context4.sent;
558
- return _context4.abrupt("return", (orders || []).find(function (order) {
923
+ orders = _context7.sent;
924
+ return _context7.abrupt("return", (orders || []).find(function (order) {
559
925
  return String(order === null || order === void 0 ? void 0 : order.order_id) === String(orderId);
560
926
  }) || null);
561
927
  case 14:
562
- _context4.prev = 14;
563
- _context4.t0 = _context4["catch"](2);
928
+ _context7.prev = 14;
929
+ _context7.t0 = _context7["catch"](2);
564
930
  this.logWarning('getLocalOrderByOrderId failed', {
565
931
  orderId: orderId,
566
- error: _context4.t0 instanceof Error ? _context4.t0.message : String(_context4.t0)
932
+ error: _context7.t0 instanceof Error ? _context7.t0.message : String(_context7.t0)
567
933
  });
568
- return _context4.abrupt("return", null);
934
+ return _context7.abrupt("return", null);
569
935
  case 18:
570
936
  case "end":
571
- return _context4.stop();
937
+ return _context7.stop();
572
938
  }
573
- }, _callee4, this, [[2, 14]]);
939
+ }, _callee5, this, [[2, 14]]);
574
940
  }));
575
941
  function getLocalOrderByOrderId(_x6) {
576
942
  return _getLocalOrderByOrderId.apply(this, arguments);
@@ -580,48 +946,48 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
580
946
  }, {
581
947
  key: "getLocalOrderByOrderNumber",
582
948
  value: function () {
583
- var _getLocalOrderByOrderNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(orderNumber) {
949
+ var _getLocalOrderByOrderNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(orderNumber) {
584
950
  var _this$dbManager$get2, _this$dbManager3, _this$dbManager$getAl2, _this$dbManager4, direct, orders;
585
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
586
- while (1) switch (_context5.prev = _context5.next) {
951
+ return _regeneratorRuntime().wrap(function _callee6$(_context8) {
952
+ while (1) switch (_context8.prev = _context8.next) {
587
953
  case 0:
588
954
  if (!(!this.dbManager || !orderNumber)) {
589
- _context5.next = 2;
955
+ _context8.next = 2;
590
956
  break;
591
957
  }
592
- return _context5.abrupt("return", null);
958
+ return _context8.abrupt("return", null);
593
959
  case 2:
594
- _context5.prev = 2;
595
- _context5.next = 5;
960
+ _context8.prev = 2;
961
+ _context8.next = 5;
596
962
  return (_this$dbManager$get2 = (_this$dbManager3 = this.dbManager).get) === null || _this$dbManager$get2 === void 0 ? void 0 : _this$dbManager$get2.call(_this$dbManager3, LOCAL_ORDER_STORE_NAME, orderNumber);
597
963
  case 5:
598
- direct = _context5.sent;
964
+ direct = _context8.sent;
599
965
  if (!direct) {
600
- _context5.next = 8;
966
+ _context8.next = 8;
601
967
  break;
602
968
  }
603
- return _context5.abrupt("return", direct);
969
+ return _context8.abrupt("return", direct);
604
970
  case 8:
605
- _context5.next = 10;
971
+ _context8.next = 10;
606
972
  return (_this$dbManager$getAl2 = (_this$dbManager4 = this.dbManager).getAll) === null || _this$dbManager$getAl2 === void 0 ? void 0 : _this$dbManager$getAl2.call(_this$dbManager4, LOCAL_ORDER_STORE_NAME);
607
973
  case 10:
608
- orders = _context5.sent;
609
- return _context5.abrupt("return", (orders || []).find(function (order) {
974
+ orders = _context8.sent;
975
+ return _context8.abrupt("return", (orders || []).find(function (order) {
610
976
  return String(order === null || order === void 0 ? void 0 : order.order_number) === String(orderNumber);
611
977
  }) || null);
612
978
  case 14:
613
- _context5.prev = 14;
614
- _context5.t0 = _context5["catch"](2);
979
+ _context8.prev = 14;
980
+ _context8.t0 = _context8["catch"](2);
615
981
  this.logWarning('getLocalOrderByOrderNumber failed', {
616
982
  orderNumber: orderNumber,
617
- error: _context5.t0 instanceof Error ? _context5.t0.message : String(_context5.t0)
983
+ error: _context8.t0 instanceof Error ? _context8.t0.message : String(_context8.t0)
618
984
  });
619
- return _context5.abrupt("return", null);
985
+ return _context8.abrupt("return", null);
620
986
  case 18:
621
987
  case "end":
622
- return _context5.stop();
988
+ return _context8.stop();
623
989
  }
624
- }, _callee5, this, [[2, 14]]);
990
+ }, _callee6, this, [[2, 14]]);
625
991
  }));
626
992
  function getLocalOrderByOrderNumber(_x7) {
627
993
  return _getLocalOrderByOrderNumber.apply(this, arguments);
@@ -631,48 +997,48 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
631
997
  }, {
632
998
  key: "getLocalOrderByExternalSaleNumber",
633
999
  value: function () {
634
- var _getLocalOrderByExternalSaleNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(externalSaleNumber) {
1000
+ var _getLocalOrderByExternalSaleNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(externalSaleNumber) {
635
1001
  var _this$dbManager$get3, _this$dbManager5, _this$dbManager$getAl3, _this$dbManager6, direct, orders;
636
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
637
- while (1) switch (_context6.prev = _context6.next) {
1002
+ return _regeneratorRuntime().wrap(function _callee7$(_context9) {
1003
+ while (1) switch (_context9.prev = _context9.next) {
638
1004
  case 0:
639
1005
  if (!(!this.dbManager || !externalSaleNumber)) {
640
- _context6.next = 2;
1006
+ _context9.next = 2;
641
1007
  break;
642
1008
  }
643
- return _context6.abrupt("return", null);
1009
+ return _context9.abrupt("return", null);
644
1010
  case 2:
645
- _context6.prev = 2;
646
- _context6.next = 5;
1011
+ _context9.prev = 2;
1012
+ _context9.next = 5;
647
1013
  return (_this$dbManager$get3 = (_this$dbManager5 = this.dbManager).get) === null || _this$dbManager$get3 === void 0 ? void 0 : _this$dbManager$get3.call(_this$dbManager5, LOCAL_ORDER_STORE_NAME, externalSaleNumber);
648
1014
  case 5:
649
- direct = _context6.sent;
1015
+ direct = _context9.sent;
650
1016
  if (!direct) {
651
- _context6.next = 8;
1017
+ _context9.next = 8;
652
1018
  break;
653
1019
  }
654
- return _context6.abrupt("return", direct);
1020
+ return _context9.abrupt("return", direct);
655
1021
  case 8:
656
- _context6.next = 10;
1022
+ _context9.next = 10;
657
1023
  return (_this$dbManager$getAl3 = (_this$dbManager6 = this.dbManager).getAll) === null || _this$dbManager$getAl3 === void 0 ? void 0 : _this$dbManager$getAl3.call(_this$dbManager6, LOCAL_ORDER_STORE_NAME);
658
1024
  case 10:
659
- orders = _context6.sent;
660
- return _context6.abrupt("return", (orders || []).find(function (order) {
1025
+ orders = _context9.sent;
1026
+ return _context9.abrupt("return", (orders || []).find(function (order) {
661
1027
  return String(order === null || order === void 0 ? void 0 : order.external_sale_number) === String(externalSaleNumber);
662
1028
  }) || null);
663
1029
  case 14:
664
- _context6.prev = 14;
665
- _context6.t0 = _context6["catch"](2);
1030
+ _context9.prev = 14;
1031
+ _context9.t0 = _context9["catch"](2);
666
1032
  this.logWarning('getLocalOrderByExternalSaleNumber failed', {
667
1033
  externalSaleNumber: externalSaleNumber,
668
- error: _context6.t0 instanceof Error ? _context6.t0.message : String(_context6.t0)
1034
+ error: _context9.t0 instanceof Error ? _context9.t0.message : String(_context9.t0)
669
1035
  });
670
- return _context6.abrupt("return", null);
1036
+ return _context9.abrupt("return", null);
671
1037
  case 18:
672
1038
  case "end":
673
- return _context6.stop();
1039
+ return _context9.stop();
674
1040
  }
675
- }, _callee6, this, [[2, 14]]);
1041
+ }, _callee7, this, [[2, 14]]);
676
1042
  }));
677
1043
  function getLocalOrderByExternalSaleNumber(_x8) {
678
1044
  return _getLocalOrderByExternalSaleNumber.apply(this, arguments);
@@ -682,58 +1048,63 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
682
1048
  }, {
683
1049
  key: "saveDraft",
684
1050
  value: function () {
685
- var _saveDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
1051
+ var _saveDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
686
1052
  var tempOrder, record, _this$dbManager$updat, _this$dbManager7;
687
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
688
- while (1) switch (_context7.prev = _context7.next) {
1053
+ return _regeneratorRuntime().wrap(function _callee8$(_context10) {
1054
+ while (1) switch (_context10.prev = _context10.next) {
689
1055
  case 0:
690
- if (this.dbManager) {
691
- _context7.next = 2;
1056
+ if (!(!this.draftPersistEnabled || !this.dbManager)) {
1057
+ _context10.next = 2;
692
1058
  break;
693
1059
  }
694
- return _context7.abrupt("return");
1060
+ return _context10.abrupt("return");
695
1061
  case 2:
696
1062
  tempOrder = this.ensureTempOrder();
697
1063
  record = this.buildLocalOrderRecord(tempOrder);
698
- _context7.prev = 4;
699
- _context7.next = 7;
1064
+ _context10.prev = 4;
1065
+ _context10.next = 7;
700
1066
  return (_this$dbManager$updat = (_this$dbManager7 = this.dbManager).update) === null || _this$dbManager$updat === void 0 ? void 0 : _this$dbManager$updat.call(_this$dbManager7, LOCAL_ORDER_STORE_NAME, record);
701
1067
  case 7:
702
- _context7.next = 12;
1068
+ _context10.next = 12;
703
1069
  break;
704
1070
  case 9:
705
- _context7.prev = 9;
706
- _context7.t0 = _context7["catch"](4);
1071
+ _context10.prev = 9;
1072
+ _context10.t0 = _context10["catch"](4);
707
1073
  this.logWarning('saveDraft failed', {
708
1074
  externalSaleNumber: tempOrder.external_sale_number,
709
1075
  orderNumber: tempOrder.order_number,
710
1076
  orderId: tempOrder.order_id,
711
- error: _context7.t0 instanceof Error ? _context7.t0.message : String(_context7.t0)
1077
+ error: _context10.t0 instanceof Error ? _context10.t0.message : String(_context10.t0)
712
1078
  });
713
1079
  case 12:
714
1080
  case "end":
715
- return _context7.stop();
1081
+ return _context10.stop();
716
1082
  }
717
- }, _callee7, this, [[4, 9]]);
1083
+ }, _callee8, this, [[4, 9]]);
718
1084
  }));
719
1085
  function saveDraft() {
720
1086
  return _saveDraft.apply(this, arguments);
721
1087
  }
722
1088
  return saveDraft;
723
1089
  }()
1090
+ }, {
1091
+ key: "saveDraftInBackground",
1092
+ value: function saveDraftInBackground() {
1093
+ void this.saveDraft();
1094
+ }
724
1095
  }, {
725
1096
  key: "hydrateTempOrderFromLocalRecord",
726
1097
  value: function () {
727
- var _hydrateTempOrderFromLocalRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(record) {
728
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
729
- while (1) switch (_context8.prev = _context8.next) {
1098
+ var _hydrateTempOrderFromLocalRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(record) {
1099
+ return _regeneratorRuntime().wrap(function _callee9$(_context11) {
1100
+ while (1) switch (_context11.prev = _context11.next) {
730
1101
  case 0:
731
- return _context8.abrupt("return", this.hydrateTempOrderFromRecord(record));
1102
+ return _context11.abrupt("return", this.hydrateTempOrderFromRecord(record));
732
1103
  case 1:
733
1104
  case "end":
734
- return _context8.stop();
1105
+ return _context11.stop();
735
1106
  }
736
- }, _callee8, this);
1107
+ }, _callee9, this);
737
1108
  }));
738
1109
  function hydrateTempOrderFromLocalRecord(_x9) {
739
1110
  return _hydrateTempOrderFromLocalRecord.apply(this, arguments);
@@ -743,8 +1114,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
743
1114
  }, {
744
1115
  key: "extractOrderIdFromSubmitResult",
745
1116
  value: function extractOrderIdFromSubmitResult(result) {
746
- var _ref2, _ref3, _ref4, _result$data$order_id, _result$data, _result$data2;
747
- return (_ref2 = (_ref3 = (_ref4 = (_result$data$order_id = result === null || result === void 0 || (_result$data = result.data) === null || _result$data === void 0 ? void 0 : _result$data.order_id) !== null && _result$data$order_id !== void 0 ? _result$data$order_id : result === null || result === void 0 ? void 0 : result.order_id) !== null && _ref4 !== void 0 ? _ref4 : result === null || result === void 0 || (_result$data2 = result.data) === null || _result$data2 === void 0 ? void 0 : _result$data2.id) !== null && _ref3 !== void 0 ? _ref3 : result === null || result === void 0 ? void 0 : result.id) !== null && _ref2 !== void 0 ? _ref2 : null;
1117
+ var _ref3, _ref4, _ref5, _result$data$order_id, _result$data, _result$data2;
1118
+ return (_ref3 = (_ref4 = (_ref5 = (_result$data$order_id = result === null || result === void 0 || (_result$data = result.data) === null || _result$data === void 0 ? void 0 : _result$data.order_id) !== null && _result$data$order_id !== void 0 ? _result$data$order_id : result === null || result === void 0 ? void 0 : result.order_id) !== null && _ref5 !== void 0 ? _ref5 : result === null || result === void 0 || (_result$data2 = result.data) === null || _result$data2 === void 0 ? void 0 : _result$data2.id) !== null && _ref4 !== void 0 ? _ref4 : result === null || result === void 0 ? void 0 : result.id) !== null && _ref3 !== void 0 ? _ref3 : null;
748
1119
  }
749
1120
  }, {
750
1121
  key: "calculatePaymentTotal",
@@ -757,17 +1128,48 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
757
1128
  return sum.plus(amount.minus(rounding));
758
1129
  }, new Decimal(0));
759
1130
  }
1131
+ }, {
1132
+ key: "normalizePaymentSource",
1133
+ value: function normalizePaymentSource(payment, options) {
1134
+ var _ref6, _paymentRecord$origin;
1135
+ var paymentRecord = payment;
1136
+ var metadata = paymentRecord.metadata && _typeof(paymentRecord.metadata) === 'object' ? _objectSpread({}, paymentRecord.metadata) : {};
1137
+ if (!metadata.unique_identification_number) {
1138
+ metadata.unique_identification_number = createUuidV4();
1139
+ }
1140
+ var normalized = _objectSpread(_objectSpread({}, paymentRecord), {}, {
1141
+ metadata: metadata,
1142
+ origin_amount: (_ref6 = (_paymentRecord$origin = paymentRecord.origin_amount) !== null && _paymentRecord$origin !== void 0 ? _paymentRecord$origin : paymentRecord.amount) !== null && _ref6 !== void 0 ? _ref6 : '0.00'
1143
+ });
1144
+ if (paymentRecord.status !== undefined) {
1145
+ normalized.status = paymentRecord.status;
1146
+ } else if ((options === null || options === void 0 ? void 0 : options.defaultPaid) !== false) {
1147
+ normalized.status = 'paid';
1148
+ }
1149
+ return normalized;
1150
+ }
1151
+ }, {
1152
+ key: "updateTempOrderPaymentStatus",
1153
+ value: function updateTempOrderPaymentStatus(tempOrder) {
1154
+ var paymentTotal = this.calculatePaymentTotal(tempOrder.payments || []);
1155
+ if (paymentTotal.lte(0)) {
1156
+ tempOrder.payment_status = tempOrder.payment_status || 'payment_processing';
1157
+ return;
1158
+ }
1159
+ var targetAmount = this.getPaymentTargetAmount();
1160
+ tempOrder.payment_status = targetAmount.gt(0) && paymentTotal.gte(targetAmount) ? 'paid' : 'partially_paid';
1161
+ }
760
1162
  }, {
761
1163
  key: "calculatePaidPaymentSummary",
762
1164
  value: function calculatePaidPaymentSummary(payments) {
763
- var _this2 = this;
1165
+ var _this3 = this;
764
1166
  return (payments || []).reduce(function (summary, payment) {
765
1167
  var paymentRecord = payment;
766
1168
  if ((paymentRecord === null || paymentRecord === void 0 ? void 0 : paymentRecord.status) !== 'paid') return summary;
767
1169
  return {
768
1170
  customerPaidAmount: summary.customerPaidAmount.plus(paymentRecord.amount || 0),
769
1171
  orderPaidAmount: summary.orderPaidAmount.plus(paymentRecord.origin_amount || 0),
770
- payServiceChargeAmount: summary.payServiceChargeAmount.plus(_this2.calculatePaymentServiceFee(paymentRecord))
1172
+ payServiceChargeAmount: summary.payServiceChargeAmount.plus(_this3.calculatePaymentServiceFee(paymentRecord))
771
1173
  };
772
1174
  }, {
773
1175
  customerPaidAmount: new Decimal(0),
@@ -786,6 +1188,88 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
786
1188
  var fixedAmount = new Decimal(serviceCharge.amount || 0);
787
1189
  return new Decimal(payment.amount || 0).times(percentage).plus(fixedAmount);
788
1190
  }
1191
+ }, {
1192
+ key: "formatSummaryMetadataMoney",
1193
+ value: function formatSummaryMetadataMoney(value) {
1194
+ if (value === undefined || value === null || value === '') return undefined;
1195
+ if (value instanceof Decimal) return value.toFixed(2);
1196
+ return new Decimal(String(value || 0)).toFixed(2);
1197
+ }
1198
+ }, {
1199
+ key: "syncSummaryProductMetadata",
1200
+ value: function syncSummaryProductMetadata(products) {
1201
+ var moneyKeys = ['main_product_attached_bundle_surcharge_fee', 'main_product_attached_bundle_tax_fee', 'surcharge_rounding_remainder', 'tax_fee_rounding_remainder'];
1202
+ var _iterator5 = _createForOfIteratorHelper(products || []),
1203
+ _step5;
1204
+ try {
1205
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
1206
+ var product = _step5.value;
1207
+ var productRecord = product;
1208
+ var metadata = productRecord.metadata && _typeof(productRecord.metadata) === 'object' ? _objectSpread({}, productRecord.metadata) : {};
1209
+ var hasMetadataPatch = false;
1210
+ var _iterator6 = _createForOfIteratorHelper(moneyKeys),
1211
+ _step6;
1212
+ try {
1213
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
1214
+ var key = _step6.value;
1215
+ var value = this.formatSummaryMetadataMoney(productRecord[key]);
1216
+ if (value === undefined) continue;
1217
+ metadata[key] = value;
1218
+ hasMetadataPatch = true;
1219
+ }
1220
+ } catch (err) {
1221
+ _iterator6.e(err);
1222
+ } finally {
1223
+ _iterator6.f();
1224
+ }
1225
+ if (Array.isArray(productRecord.relation_surcharge_ids)) {
1226
+ metadata.relation_surcharge_ids = productRecord.relation_surcharge_ids;
1227
+ hasMetadataPatch = true;
1228
+ }
1229
+ if (hasMetadataPatch) productRecord.metadata = metadata;
1230
+ if (!Array.isArray(productRecord.product_bundle)) continue;
1231
+ var _iterator7 = _createForOfIteratorHelper(productRecord.product_bundle),
1232
+ _step7;
1233
+ try {
1234
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
1235
+ var bundle = _step7.value;
1236
+ var bundleRecord = bundle;
1237
+ var bundleMetadata = bundleRecord.metadata && _typeof(bundleRecord.metadata) === 'object' ? _objectSpread({}, bundleRecord.metadata) : {};
1238
+ var hasBundleMetadataPatch = false;
1239
+ var bundleSurchargeFee = this.formatSummaryMetadataMoney(bundleRecord.surcharge_fee);
1240
+ if (bundleSurchargeFee !== undefined) {
1241
+ bundleMetadata.surcharge_fee = bundleSurchargeFee;
1242
+ hasBundleMetadataPatch = true;
1243
+ }
1244
+ if (Array.isArray(bundleRecord.relation_surcharge_ids)) {
1245
+ bundleMetadata.relation_surcharge_ids = bundleRecord.relation_surcharge_ids;
1246
+ hasBundleMetadataPatch = true;
1247
+ }
1248
+ if (hasBundleMetadataPatch) bundleRecord.metadata = bundleMetadata;
1249
+ }
1250
+ } catch (err) {
1251
+ _iterator7.e(err);
1252
+ } finally {
1253
+ _iterator7.f();
1254
+ }
1255
+ }
1256
+ } catch (err) {
1257
+ _iterator5.e(err);
1258
+ } finally {
1259
+ _iterator5.f();
1260
+ }
1261
+ }
1262
+ }, {
1263
+ key: "calculateSummaryAmountGap",
1264
+ value: function calculateSummaryAmountGap(params) {
1265
+ var tempOrder = params.tempOrder,
1266
+ summary = params.summary,
1267
+ orderPaidAmount = params.orderPaidAmount;
1268
+ var depositAmount = summary.deposit_amount || tempOrder.deposit_amount || '0.00';
1269
+ var isDeposit = tempOrder.is_deposit === 1 || new Decimal(depositAmount || 0).gt(0);
1270
+ var targetAmount = isDeposit ? new Decimal(depositAmount || 0) : new Decimal(summary.total_amount || summary.expect_amount || 0);
1271
+ return targetAmount.minus(orderPaidAmount).toFixed(2);
1272
+ }
789
1273
  }, {
790
1274
  key: "getPaymentTargetAmount",
791
1275
  value: function getPaymentTargetAmount() {
@@ -812,11 +1296,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
812
1296
  }, {
813
1297
  key: "restoreOrder",
814
1298
  value: function restoreOrder() {
1299
+ var _this$store$discount9, _this$store$discount10;
815
1300
  var freshTempOrder = this.createDefaultTempOrderInstance();
816
1301
  this.ensureExternalSaleNumber(freshTempOrder);
817
1302
  this.store.tempOrder = freshTempOrder;
818
1303
  this.store.summary = createEmptySummary();
819
1304
  this.store.lastOrderInfo = undefined;
1305
+ this.store.syncState = undefined;
1306
+ void ((_this$store$discount9 = this.store.discount) === null || _this$store$discount9 === void 0 ? void 0 : _this$store$discount9.setOriginalDiscountList([]));
1307
+ void ((_this$store$discount10 = this.store.discount) === null || _this$store$discount10 === void 0 ? void 0 : _this$store$discount10.setDiscountList([]));
820
1308
  this.persistTempOrder();
821
1309
  return freshTempOrder;
822
1310
  }
@@ -825,14 +1313,68 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
825
1313
  value: function getTempOrder() {
826
1314
  return this.store.tempOrder;
827
1315
  }
1316
+ }, {
1317
+ key: "replaceTempOrder",
1318
+ value: function () {
1319
+ var _replaceTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(tempOrder, options) {
1320
+ var nextTempOrder;
1321
+ return _regeneratorRuntime().wrap(function _callee10$(_context12) {
1322
+ while (1) switch (_context12.prev = _context12.next) {
1323
+ case 0:
1324
+ if (isTempOrder(tempOrder)) {
1325
+ _context12.next = 2;
1326
+ break;
1327
+ }
1328
+ throw new Error('无效的 tempOrder 数据');
1329
+ case 2:
1330
+ nextTempOrder = this.normalizeTempOrderForRuntime(cloneDeep(tempOrder), {
1331
+ ensureIdentity: false
1332
+ });
1333
+ this.store.tempOrder = nextTempOrder;
1334
+ if (!((options === null || options === void 0 ? void 0 : options.recalculateSummary) !== false)) {
1335
+ _context12.next = 9;
1336
+ break;
1337
+ }
1338
+ _context12.next = 7;
1339
+ return this.recalculateSummary({
1340
+ createIfMissing: false
1341
+ });
1342
+ case 7:
1343
+ _context12.next = 10;
1344
+ break;
1345
+ case 9:
1346
+ this.store.summary = createEmptySummary();
1347
+ case 10:
1348
+ if ((options === null || options === void 0 ? void 0 : options.persist) !== false) {
1349
+ this.persistTempOrder();
1350
+ }
1351
+ if (!(options !== null && options !== void 0 && options.saveDraft)) {
1352
+ _context12.next = 14;
1353
+ break;
1354
+ }
1355
+ _context12.next = 14;
1356
+ return this.saveDraft();
1357
+ case 14:
1358
+ return _context12.abrupt("return", nextTempOrder);
1359
+ case 15:
1360
+ case "end":
1361
+ return _context12.stop();
1362
+ }
1363
+ }, _callee10, this);
1364
+ }));
1365
+ function replaceTempOrder(_x10, _x11) {
1366
+ return _replaceTempOrder.apply(this, arguments);
1367
+ }
1368
+ return replaceTempOrder;
1369
+ }()
828
1370
  }, {
829
1371
  key: "getOrderIdentity",
830
1372
  value: function getOrderIdentity() {
831
- var _ref5, _ref6, _tempOrder$order_id2, _tempOrder$_extend;
1373
+ var _ref7, _ref8, _tempOrder$order_id2, _tempOrder$_extend;
832
1374
  var tempOrder = this.store.tempOrder;
833
1375
  if (!tempOrder) return null;
834
1376
  var lastOrderInfo = this.store.lastOrderInfo || {};
835
- var orderId = (_ref5 = (_ref6 = (_tempOrder$order_id2 = tempOrder.order_id) !== null && _tempOrder$order_id2 !== void 0 ? _tempOrder$order_id2 : lastOrderInfo.order_id) !== null && _ref6 !== void 0 ? _ref6 : lastOrderInfo.id) !== null && _ref5 !== void 0 ? _ref5 : null;
1377
+ var orderId = (_ref7 = (_ref8 = (_tempOrder$order_id2 = tempOrder.order_id) !== null && _tempOrder$order_id2 !== void 0 ? _tempOrder$order_id2 : lastOrderInfo.order_id) !== null && _ref8 !== void 0 ? _ref8 : lastOrderInfo.id) !== null && _ref7 !== void 0 ? _ref7 : null;
836
1378
  return {
837
1379
  localId: this.cacheId || ((_tempOrder$_extend = tempOrder._extend) === null || _tempOrder$_extend === void 0 ? void 0 : _tempOrder$_extend.localId),
838
1380
  orderId: orderId,
@@ -862,7 +1404,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
862
1404
  var depositAmount = tempOrder.deposit_amount || summary.deposit_amount || '0.00';
863
1405
  var targetAmount = tempOrder.is_deposit === 1 ? new Decimal(depositAmount || 0) : new Decimal(summary.total_amount || summary.expect_amount || 0);
864
1406
  var paymentTotal = this.calculatePaymentTotal(tempOrder.payments || []);
865
- var amountGap = Decimal.max(0, targetAmount.minus(paymentTotal)).toFixed(2);
1407
+ var amountGap = targetAmount.minus(paymentTotal).toFixed(2);
866
1408
  return {
867
1409
  isDeposit: tempOrder.is_deposit === 1 || depositAmount !== '0.00',
868
1410
  depositAmount: depositAmount,
@@ -903,28 +1445,32 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
903
1445
  }, {
904
1446
  key: "addNewOrder",
905
1447
  value: function () {
906
- var _addNewOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
1448
+ var _addNewOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
907
1449
  var tempOrder;
908
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
909
- while (1) switch (_context9.prev = _context9.next) {
1450
+ return _regeneratorRuntime().wrap(function _callee11$(_context13) {
1451
+ while (1) switch (_context13.prev = _context13.next) {
910
1452
  case 0:
911
1453
  tempOrder = this.ensureTempOrder();
912
1454
  this.ensureExternalSaleNumber(tempOrder);
913
- _context9.next = 4;
1455
+ _context13.next = 4;
914
1456
  return this.recalculateSummary({
915
1457
  createIfMissing: true
916
1458
  });
917
1459
  case 4:
918
1460
  this.persistTempOrder();
919
- _context9.next = 7;
1461
+ if (!this.draftPersistEnabled) {
1462
+ _context13.next = 8;
1463
+ break;
1464
+ }
1465
+ _context13.next = 8;
920
1466
  return this.saveDraft();
921
- case 7:
922
- return _context9.abrupt("return", tempOrder);
923
1467
  case 8:
1468
+ return _context13.abrupt("return", tempOrder);
1469
+ case 9:
924
1470
  case "end":
925
- return _context9.stop();
1471
+ return _context13.stop();
926
1472
  }
927
- }, _callee9, this);
1473
+ }, _callee11, this);
928
1474
  }));
929
1475
  function addNewOrder() {
930
1476
  return _addNewOrder.apply(this, arguments);
@@ -962,11 +1508,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
962
1508
  }, {
963
1509
  key: "captureProductRuntime",
964
1510
  value: function captureProductRuntime(tempOrder, rawProduct, normalizedProduct, existedUid) {
965
- var _extend$productsByUid, _ref7, _rawProduct$_origin;
1511
+ var _extend$productsByUid, _ref9, _rawProduct$_origin;
966
1512
  var uid = existedUid || this.getProductUid(normalizedProduct);
967
1513
  var extend = this.ensureExtend(tempOrder);
968
1514
  var existed = ((_extend$productsByUid = extend.productsByUid) === null || _extend$productsByUid === void 0 ? void 0 : _extend$productsByUid[uid]) || {};
969
- var origin = (_ref7 = (_rawProduct$_origin = rawProduct._origin) !== null && _rawProduct$_origin !== void 0 ? _rawProduct$_origin : normalizedProduct._origin) !== null && _ref7 !== void 0 ? _ref7 : existed.origin;
1515
+ var origin = (_ref9 = (_rawProduct$_origin = rawProduct._origin) !== null && _rawProduct$_origin !== void 0 ? _rawProduct$_origin : normalizedProduct._origin) !== null && _ref9 !== void 0 ? _ref9 : existed.origin;
970
1516
  extend.productsByUid[uid] = _objectSpread(_objectSpread({}, existed), origin !== undefined ? {
971
1517
  origin: origin
972
1518
  } : {});
@@ -1000,6 +1546,38 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1000
1546
  })
1001
1547
  };
1002
1548
  }
1549
+ }, {
1550
+ key: "getBookingUniqueIdentificationNumber",
1551
+ value: function getBookingUniqueIdentificationNumber(booking) {
1552
+ var _booking$metadata;
1553
+ var uid = booking === null || booking === void 0 || (_booking$metadata = booking.metadata) === null || _booking$metadata === void 0 ? void 0 : _booking$metadata.unique_identification_number;
1554
+ if (uid === undefined || uid === null || uid === '') return null;
1555
+ return String(uid);
1556
+ }
1557
+ }, {
1558
+ key: "findBookingIndexByUniqueIdentificationNumber",
1559
+ value: function findBookingIndexByUniqueIdentificationNumber(tempOrder, uniqueIdentificationNumber) {
1560
+ var _this4 = this;
1561
+ return (tempOrder.bookings || []).findIndex(function (booking) {
1562
+ return _this4.getBookingUniqueIdentificationNumber(booking) === uniqueIdentificationNumber;
1563
+ });
1564
+ }
1565
+ }, {
1566
+ key: "removeLinkedBookingsForProduct",
1567
+ value: function removeLinkedBookingsForProduct(tempOrder, product) {
1568
+ var _product$metadata4,
1569
+ _product$metadata5,
1570
+ _this5 = this;
1571
+ var productUid = (product === null || product === void 0 || (_product$metadata4 = product.metadata) === null || _product$metadata4 === void 0 ? void 0 : _product$metadata4.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
1572
+ var bookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_product$metadata5 = product.metadata) === null || _product$metadata5 === void 0 ? void 0 : _product$metadata5.booking_uid);
1573
+ if (!productUid && !bookingUid) return;
1574
+ tempOrder.bookings = (tempOrder.bookings || []).filter(function (booking) {
1575
+ var currentBookingUid = _this5.getBookingUniqueIdentificationNumber(booking);
1576
+ if (bookingUid && currentBookingUid === String(bookingUid)) return false;
1577
+ if (productUid && String((booking === null || booking === void 0 ? void 0 : booking.product_uid) || '') === String(productUid)) return false;
1578
+ return true;
1579
+ });
1580
+ }
1003
1581
 
1004
1582
  // ─── TempOrder: 金额汇总 ───
1005
1583
  }, {
@@ -1011,47 +1589,58 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1011
1589
  }, {
1012
1590
  key: "recalculateSummary",
1013
1591
  value: function () {
1014
- var _recalculateSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(options) {
1592
+ var _recalculateSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(options) {
1015
1593
  var tempOrder, salesSummary, existedSummary, paidPaymentSummary, emptySummary, salesSummaryResult, summary;
1016
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1017
- while (1) switch (_context10.prev = _context10.next) {
1594
+ return _regeneratorRuntime().wrap(function _callee12$(_context14) {
1595
+ while (1) switch (_context14.prev = _context14.next) {
1018
1596
  case 0:
1019
1597
  tempOrder = options !== null && options !== void 0 && options.createIfMissing ? this.ensureTempOrder() : this.store.tempOrder;
1020
1598
  if (tempOrder) {
1021
- _context10.next = 3;
1599
+ _context14.next = 3;
1022
1600
  break;
1023
1601
  }
1024
- return _context10.abrupt("return", null);
1602
+ return _context14.abrupt("return", null);
1025
1603
  case 3:
1026
1604
  salesSummary = this.getSalesSummary();
1027
1605
  existedSummary = this.store.summary || createEmptySummary();
1028
1606
  paidPaymentSummary = this.calculatePaidPaymentSummary(tempOrder.payments || []);
1029
1607
  if (salesSummary) {
1030
- _context10.next = 11;
1608
+ _context14.next = 11;
1031
1609
  break;
1032
1610
  }
1033
1611
  emptySummary = _objectSpread(_objectSpread({}, createEmptySummary()), {}, {
1034
1612
  total_refund_amount: existedSummary.total_refund_amount || '0.00',
1035
1613
  customer_paid_amount: paidPaymentSummary.customerPaidAmount.toFixed(2),
1036
1614
  order_paid_amount: paidPaymentSummary.orderPaidAmount.toFixed(2),
1615
+ amount_gap: this.calculateSummaryAmountGap({
1616
+ tempOrder: tempOrder,
1617
+ summary: createEmptySummary(),
1618
+ orderPaidAmount: paidPaymentSummary.orderPaidAmount
1619
+ }),
1037
1620
  pay_service_charge_amount: paidPaymentSummary.payServiceChargeAmount.toFixed(2)
1038
1621
  });
1039
1622
  this.store.summary = emptySummary;
1040
1623
  tempOrder.surcharge_fee = emptySummary.surcharge_fee;
1041
- return _context10.abrupt("return", this.store.summary);
1624
+ return _context14.abrupt("return", this.store.summary);
1042
1625
  case 11:
1043
- _context10.next = 13;
1626
+ _context14.next = 13;
1044
1627
  return salesSummary.getSummary({
1045
1628
  products: tempOrder.products,
1046
1629
  isPriceIncludeTax: tempOrder.is_price_include_tax,
1047
1630
  shopDiscount: tempOrder.shop_discount
1048
1631
  });
1049
1632
  case 13:
1050
- salesSummaryResult = _context10.sent;
1633
+ salesSummaryResult = _context14.sent;
1634
+ this.syncSummaryProductMetadata(tempOrder.products || []);
1051
1635
  summary = _objectSpread(_objectSpread({}, salesSummaryResult), {}, {
1052
1636
  total_refund_amount: existedSummary.total_refund_amount || '0.00',
1053
1637
  customer_paid_amount: paidPaymentSummary.customerPaidAmount.toFixed(2),
1054
1638
  order_paid_amount: paidPaymentSummary.orderPaidAmount.toFixed(2),
1639
+ amount_gap: this.calculateSummaryAmountGap({
1640
+ tempOrder: tempOrder,
1641
+ summary: salesSummaryResult,
1642
+ orderPaidAmount: paidPaymentSummary.orderPaidAmount
1643
+ }),
1055
1644
  pay_service_charge_amount: paidPaymentSummary.payServiceChargeAmount.toFixed(2)
1056
1645
  });
1057
1646
  this.store.summary = summary;
@@ -1065,14 +1654,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1065
1654
  tempOrder.surcharges = summary.surcharges || [];
1066
1655
  tempOrder.deposit_amount = summary.deposit_amount || '0.00';
1067
1656
  tempOrder.is_deposit = summary.deposit_amount !== '0.00' ? 1 : 0;
1068
- return _context10.abrupt("return", this.store.summary);
1069
- case 23:
1657
+ return _context14.abrupt("return", this.store.summary);
1658
+ case 24:
1070
1659
  case "end":
1071
- return _context10.stop();
1660
+ return _context14.stop();
1072
1661
  }
1073
- }, _callee10, this);
1662
+ }, _callee12, this);
1074
1663
  }));
1075
- function recalculateSummary(_x10) {
1664
+ function recalculateSummary(_x12) {
1076
1665
  return _recalculateSummary.apply(this, arguments);
1077
1666
  }
1078
1667
  return recalculateSummary;
@@ -1080,30 +1669,30 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1080
1669
  }, {
1081
1670
  key: "getOrderSummary",
1082
1671
  value: function () {
1083
- var _getOrderSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
1672
+ var _getOrderSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
1084
1673
  var summary;
1085
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1086
- while (1) switch (_context11.prev = _context11.next) {
1674
+ return _regeneratorRuntime().wrap(function _callee13$(_context15) {
1675
+ while (1) switch (_context15.prev = _context15.next) {
1087
1676
  case 0:
1088
- _context11.next = 2;
1677
+ _context15.next = 2;
1089
1678
  return this.recalculateSummary({
1090
1679
  createIfMissing: true
1091
1680
  });
1092
1681
  case 2:
1093
- summary = _context11.sent;
1682
+ summary = _context15.sent;
1094
1683
  if (summary) {
1095
- _context11.next = 5;
1684
+ _context15.next = 5;
1096
1685
  break;
1097
1686
  }
1098
- return _context11.abrupt("return", createEmptySummary());
1687
+ return _context15.abrupt("return", createEmptySummary());
1099
1688
  case 5:
1100
1689
  this.persistTempOrder();
1101
- return _context11.abrupt("return", summary);
1690
+ return _context15.abrupt("return", summary);
1102
1691
  case 7:
1103
1692
  case "end":
1104
- return _context11.stop();
1693
+ return _context15.stop();
1105
1694
  }
1106
- }, _callee11, this);
1695
+ }, _callee13, this);
1107
1696
  }));
1108
1697
  function getOrderSummary() {
1109
1698
  return _getOrderSummary.apply(this, arguments);
@@ -1113,16 +1702,46 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1113
1702
  }, {
1114
1703
  key: "updateTempOrderNote",
1115
1704
  value: function updateTempOrderNote(note) {
1705
+ var sync = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1116
1706
  var tempOrder = this.ensureTempOrder();
1117
1707
  tempOrder.note = String(note || '');
1118
1708
  this.persistTempOrder();
1709
+ if (sync) {
1710
+ var orderId = tempOrder.order_id;
1711
+ if (!orderId) return tempOrder.note;
1712
+ return this.syncTempOrderNoteToRemote(orderId, tempOrder.note);
1713
+ }
1119
1714
  return tempOrder.note;
1120
1715
  }
1716
+ }, {
1717
+ key: "syncTempOrderNoteToRemote",
1718
+ value: function () {
1719
+ var _syncTempOrderNoteToRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(orderId, note) {
1720
+ return _regeneratorRuntime().wrap(function _callee14$(_context16) {
1721
+ while (1) switch (_context16.prev = _context16.next) {
1722
+ case 0:
1723
+ _context16.next = 2;
1724
+ return this.request.put("/order/order/".concat(orderId, "/note"), {
1725
+ note: note
1726
+ });
1727
+ case 2:
1728
+ return _context16.abrupt("return", note);
1729
+ case 3:
1730
+ case "end":
1731
+ return _context16.stop();
1732
+ }
1733
+ }, _callee14, this);
1734
+ }));
1735
+ function syncTempOrderNoteToRemote(_x13, _x14) {
1736
+ return _syncTempOrderNoteToRemote.apply(this, arguments);
1737
+ }
1738
+ return syncTempOrderNoteToRemote;
1739
+ }()
1121
1740
  }, {
1122
1741
  key: "getTempOrderNote",
1123
1742
  value: function getTempOrderNote() {
1124
- var _this$store$tempOrder2;
1125
- return ((_this$store$tempOrder2 = this.store.tempOrder) === null || _this$store$tempOrder2 === void 0 ? void 0 : _this$store$tempOrder2.note) || '';
1743
+ var _this$store$tempOrder3;
1744
+ return ((_this$store$tempOrder3 = this.store.tempOrder) === null || _this$store$tempOrder3 === void 0 ? void 0 : _this$store$tempOrder3.note) || '';
1126
1745
  }
1127
1746
  }, {
1128
1747
  key: "updateTempOrderShopDiscount",
@@ -1149,25 +1768,51 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1149
1768
  this.persistTempOrder();
1150
1769
  return tempOrder.contacts_info;
1151
1770
  }
1771
+ }, {
1772
+ key: "buildTempOrderCustomer",
1773
+ value: function buildTempOrderCustomer(params) {
1774
+ var _ref10, _ref11, _ref12, _source$name, _ref13, _ref14, _ref15, _source$customer_name, _source$id, _source$customer_id, _ref16, _source$country_calli, _source$phone, _source$email;
1775
+ if (!params.customerId) return null;
1776
+ var source = params.source ? cloneDeep(params.source) : {};
1777
+ var name = (_ref10 = (_ref11 = (_ref12 = (_source$name = source.name) !== null && _source$name !== void 0 ? _source$name : source.display_name) !== null && _ref12 !== void 0 ? _ref12 : source.customerName) !== null && _ref11 !== void 0 ? _ref11 : source.customer_name) !== null && _ref10 !== void 0 ? _ref10 : params.customerName;
1778
+ var customerName = (_ref13 = (_ref14 = (_ref15 = (_source$customer_name = source.customer_name) !== null && _source$customer_name !== void 0 ? _source$customer_name : source.customerName) !== null && _ref15 !== void 0 ? _ref15 : source.display_name) !== null && _ref14 !== void 0 ? _ref14 : source.name) !== null && _ref13 !== void 0 ? _ref13 : params.customerName;
1779
+ return _objectSpread(_objectSpread({}, source), {}, {
1780
+ id: (_source$id = source.id) !== null && _source$id !== void 0 ? _source$id : params.customerId,
1781
+ customer_id: (_source$customer_id = source.customer_id) !== null && _source$customer_id !== void 0 ? _source$customer_id : params.customerId,
1782
+ name: String(name || ''),
1783
+ customer_name: String(customerName || ''),
1784
+ country_calling_code: String((_ref16 = (_source$country_calli = source.country_calling_code) !== null && _source$country_calli !== void 0 ? _source$country_calli : source.countryCallingCode) !== null && _ref16 !== void 0 ? _ref16 : params.countryCallingCode),
1785
+ phone: String((_source$phone = source.phone) !== null && _source$phone !== void 0 ? _source$phone : params.phone),
1786
+ email: String((_source$email = source.email) !== null && _source$email !== void 0 ? _source$email : params.email)
1787
+ });
1788
+ }
1152
1789
 
1153
1790
  /**
1154
1791
  * 更新当前 tempOrder 的客户协议字段。
1155
1792
  *
1156
- * PaymentModal 只需要修改订单里的客户字段;如果外部还有客户模块需要同步,
1793
+ * PaymentModal 只需要修改订单里的客户事实;如果外部还有客户模块需要同步,
1157
1794
  * 应由调用方通过回调处理,不能把外部 UI 状态写进 tempOrder。
1158
1795
  */
1159
1796
  }, {
1160
1797
  key: "updateTempOrderCustomer",
1161
1798
  value: function updateTempOrderCustomer(customer) {
1162
- var _ref8, _ref9, _customer$customer_id, _ref10, _ref11, _ref12, _customer$customer_na, _ref13, _customer$country_cal;
1799
+ var _ref17, _ref18, _customer$customer_id, _ref19, _ref20, _ref21, _customer$customer_na, _ref22, _customer$country_cal;
1163
1800
  var tempOrder = this.ensureTempOrder();
1164
- var customerId = (_ref8 = (_ref9 = (_customer$customer_id = customer.customer_id) !== null && _customer$customer_id !== void 0 ? _customer$customer_id : customer.customerId) !== null && _ref9 !== void 0 ? _ref9 : customer.id) !== null && _ref8 !== void 0 ? _ref8 : null;
1165
- var customerName = (_ref10 = (_ref11 = (_ref12 = (_customer$customer_na = customer.customer_name) !== null && _customer$customer_na !== void 0 ? _customer$customer_na : customer.customerName) !== null && _ref12 !== void 0 ? _ref12 : customer.display_name) !== null && _ref11 !== void 0 ? _ref11 : customer.name) !== null && _ref10 !== void 0 ? _ref10 : '';
1801
+ var customerId = (_ref17 = (_ref18 = (_customer$customer_id = customer.customer_id) !== null && _customer$customer_id !== void 0 ? _customer$customer_id : customer.customerId) !== null && _ref18 !== void 0 ? _ref18 : customer.id) !== null && _ref17 !== void 0 ? _ref17 : null;
1802
+ var customerName = (_ref19 = (_ref20 = (_ref21 = (_customer$customer_na = customer.customer_name) !== null && _customer$customer_na !== void 0 ? _customer$customer_na : customer.customerName) !== null && _ref21 !== void 0 ? _ref21 : customer.display_name) !== null && _ref20 !== void 0 ? _ref20 : customer.name) !== null && _ref19 !== void 0 ? _ref19 : '';
1166
1803
  tempOrder.customer_id = customerId === null || customerId === undefined || customerId === '' ? null : Number(customerId);
1167
1804
  tempOrder.customer_name = String(customerName || '');
1168
- tempOrder.country_calling_code = String((_ref13 = (_customer$country_cal = customer.country_calling_code) !== null && _customer$country_cal !== void 0 ? _customer$country_cal : customer.countryCallingCode) !== null && _ref13 !== void 0 ? _ref13 : '');
1805
+ tempOrder.country_calling_code = String((_ref22 = (_customer$country_cal = customer.country_calling_code) !== null && _customer$country_cal !== void 0 ? _customer$country_cal : customer.countryCallingCode) !== null && _ref22 !== void 0 ? _ref22 : '');
1169
1806
  tempOrder.phone = String(customer.phone || '');
1170
1807
  tempOrder.email = String(customer.email || '');
1808
+ tempOrder.customer = this.buildTempOrderCustomer({
1809
+ source: customer,
1810
+ customerId: tempOrder.customer_id,
1811
+ customerName: tempOrder.customer_name,
1812
+ countryCallingCode: tempOrder.country_calling_code,
1813
+ phone: tempOrder.phone,
1814
+ email: tempOrder.email
1815
+ });
1171
1816
  this.persistTempOrder();
1172
1817
  return {
1173
1818
  customerId: tempOrder.customer_id,
@@ -1179,28 +1824,45 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1179
1824
  }, {
1180
1825
  key: "setOrderCustomer",
1181
1826
  value: function setOrderCustomer(patch, snapshot) {
1827
+ var _tempOrder$customer_i2, _tempOrder$customer_i3;
1182
1828
  if (!patch) {
1183
1829
  this.clearOrderCustomer();
1184
1830
  return;
1185
1831
  }
1186
1832
  var tempOrder = this.ensureTempOrder();
1833
+ var previousCustomerId = (_tempOrder$customer_i2 = tempOrder.customer_id) !== null && _tempOrder$customer_i2 !== void 0 ? _tempOrder$customer_i2 : null;
1187
1834
  tempOrder.customer_id = patch.customer_id || patch.id || null;
1188
1835
  tempOrder.customer_name = String(patch.customer_name || '');
1189
1836
  tempOrder.country_calling_code = String(patch.country_calling_code || '');
1190
1837
  tempOrder.phone = String(patch.phone || '');
1191
1838
  tempOrder.email = String(patch.email || '');
1839
+ tempOrder.customer = this.buildTempOrderCustomer({
1840
+ source: snapshot || null,
1841
+ customerId: tempOrder.customer_id,
1842
+ customerName: tempOrder.customer_name,
1843
+ countryCallingCode: tempOrder.country_calling_code,
1844
+ phone: tempOrder.phone,
1845
+ email: tempOrder.email
1846
+ });
1192
1847
  if (snapshot !== undefined) {
1193
1848
  var extend = this.ensureExtend(tempOrder);
1194
1849
  if (snapshot === null) delete extend.customerSnapshot;else extend.customerSnapshot = cloneDeep(snapshot);
1195
1850
  }
1851
+ var nextCustomerId = (_tempOrder$customer_i3 = tempOrder.customer_id) !== null && _tempOrder$customer_i3 !== void 0 ? _tempOrder$customer_i3 : null;
1852
+ if (String(previousCustomerId !== null && previousCustomerId !== void 0 ? previousCustomerId : '') !== String(nextCustomerId !== null && nextCustomerId !== void 0 ? nextCustomerId : '')) {
1853
+ clearTempOrderHolderAssignments(tempOrder);
1854
+ }
1196
1855
  this.persistTempOrder();
1197
- this.emitOrderCustomerChange();
1856
+ this.saveDraftInBackground();
1857
+ if (String(previousCustomerId !== null && previousCustomerId !== void 0 ? previousCustomerId : '') !== String(nextCustomerId !== null && nextCustomerId !== void 0 ? nextCustomerId : '')) {
1858
+ this.emitOrderCustomerChange();
1859
+ }
1198
1860
  }
1199
1861
  }, {
1200
1862
  key: "getOrderCustomer",
1201
1863
  value: function getOrderCustomer() {
1202
1864
  var tempOrder = this.store.tempOrder;
1203
- if (!tempOrder || tempOrder.customer_id === null || tempOrder.customer_id === undefined) {
1865
+ if (!tempOrder || !tempOrder.customer_id) {
1204
1866
  return null;
1205
1867
  }
1206
1868
  return {
@@ -1214,21 +1876,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1214
1876
  }, {
1215
1877
  key: "getOrderCustomerSnapshot",
1216
1878
  value: function getOrderCustomerSnapshot() {
1217
- var _this$store$tempOrder3;
1218
- var snapshot = (_this$store$tempOrder3 = this.store.tempOrder) === null || _this$store$tempOrder3 === void 0 || (_this$store$tempOrder3 = _this$store$tempOrder3._extend) === null || _this$store$tempOrder3 === void 0 ? void 0 : _this$store$tempOrder3.customerSnapshot;
1879
+ var _this$store$tempOrder4;
1880
+ var snapshot = (_this$store$tempOrder4 = this.store.tempOrder) === null || _this$store$tempOrder4 === void 0 || (_this$store$tempOrder4 = _this$store$tempOrder4._extend) === null || _this$store$tempOrder4 === void 0 ? void 0 : _this$store$tempOrder4.customerSnapshot;
1219
1881
  return snapshot ? cloneDeep(snapshot) : null;
1220
1882
  }
1221
1883
  }, {
1222
1884
  key: "clearOrderCustomer",
1223
1885
  value: function clearOrderCustomer() {
1224
1886
  var tempOrder = this.ensureTempOrder();
1887
+ clearTempOrderHolderAssignments(tempOrder);
1225
1888
  tempOrder.customer_id = null;
1226
1889
  tempOrder.customer_name = '';
1227
1890
  tempOrder.country_calling_code = '';
1228
1891
  tempOrder.phone = '';
1229
1892
  tempOrder.email = '';
1893
+ tempOrder.customer = null;
1230
1894
  if (tempOrder._extend) delete tempOrder._extend.customerSnapshot;
1231
1895
  this.persistTempOrder();
1896
+ this.saveDraftInBackground();
1232
1897
  this.core.effects.emit(OrderHooks.OnOrderCustomerChange, null);
1233
1898
  }
1234
1899
  }, {
@@ -1279,10 +1944,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1279
1944
  }, {
1280
1945
  key: "addOrderPayment",
1281
1946
  value: function addOrderPayment(payment) {
1947
+ var _this6 = this;
1948
+ this.logInfo('addOrderPayment', {
1949
+ payment: payment
1950
+ });
1282
1951
  var tempOrder = this.ensureTempOrder();
1283
- var mapped = mapPaymentItemsToOrderPayments([payment]);
1952
+ var mapped = mapPaymentItemsToOrderPayments([this.normalizePaymentSource(payment, {
1953
+ defaultPaid: true
1954
+ })]);
1284
1955
  tempOrder.payments = [].concat(_toConsumableArray(tempOrder.payments || []), _toConsumableArray(mapped));
1285
1956
  this.persistTempOrder();
1957
+ void this.recalculateSummary({
1958
+ createIfMissing: true
1959
+ }).catch(function (error) {
1960
+ _this6.logError('recalculate summary after addOrderPayment failed', {
1961
+ error: error instanceof Error ? error.message : String(error)
1962
+ });
1963
+ });
1286
1964
  return tempOrder.payments;
1287
1965
  }
1288
1966
 
@@ -1344,59 +2022,72 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1344
2022
  }, {
1345
2023
  key: "updateVoucherOrderPayments",
1346
2024
  value: function updateVoucherOrderPayments(payments) {
2025
+ var _this7 = this;
1347
2026
  var tempOrder = this.ensureTempOrder();
1348
- var mappedVouchers = mapPaymentItemsToOrderPayments(payments).filter(function (payment) {
2027
+ var mappedVouchers = mapPaymentItemsToOrderPayments(payments.map(function (payment) {
2028
+ return _this7.normalizePaymentSource(payment, {
2029
+ defaultPaid: false
2030
+ });
2031
+ })).filter(function (payment) {
1349
2032
  return payment.voucher_id !== undefined && Number(payment.voucher_id) !== 0;
1350
2033
  });
1351
2034
  var nonVoucherPayments = (tempOrder.payments || []).filter(function (payment) {
1352
2035
  return payment.voucher_id === undefined || Number(payment.voucher_id) === 0;
1353
2036
  });
1354
2037
  tempOrder.payments = [].concat(_toConsumableArray(nonVoucherPayments), _toConsumableArray(mappedVouchers));
2038
+ this.updateTempOrderPaymentStatus(tempOrder);
1355
2039
  this.persistTempOrder();
2040
+ void this.recalculateSummary({
2041
+ createIfMissing: true
2042
+ }).catch(function (error) {
2043
+ _this7.logError('recalculate summary after updateVoucherOrderPayments failed', {
2044
+ error: error instanceof Error ? error.message : String(error)
2045
+ });
2046
+ });
1356
2047
  return tempOrder.payments;
1357
2048
  }
1358
2049
  }, {
1359
2050
  key: "shouldMergeProductToOrder",
1360
2051
  value: function () {
1361
- var _shouldMergeProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(params) {
2052
+ var _shouldMergeProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(params) {
1362
2053
  var _this$orderHooks;
1363
2054
  var onBeforeMergeProductToOrder, result;
1364
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1365
- while (1) switch (_context12.prev = _context12.next) {
2055
+ return _regeneratorRuntime().wrap(function _callee15$(_context17) {
2056
+ while (1) switch (_context17.prev = _context17.next) {
1366
2057
  case 0:
1367
2058
  onBeforeMergeProductToOrder = (_this$orderHooks = this.orderHooks) === null || _this$orderHooks === void 0 ? void 0 : _this$orderHooks.onBeforeMergeProductToOrder;
1368
2059
  if (onBeforeMergeProductToOrder) {
1369
- _context12.next = 3;
2060
+ _context17.next = 3;
1370
2061
  break;
1371
2062
  }
1372
- return _context12.abrupt("return", true);
2063
+ return _context17.abrupt("return", true);
1373
2064
  case 3:
1374
- _context12.next = 5;
2065
+ _context17.next = 5;
1375
2066
  return onBeforeMergeProductToOrder(_objectSpread(_objectSpread({}, params), {}, {
1376
2067
  defaultShouldMerge: true
1377
2068
  }));
1378
2069
  case 5:
1379
- result = _context12.sent;
2070
+ result = _context17.sent;
1380
2071
  if (!(typeof result === 'boolean')) {
1381
- _context12.next = 8;
2072
+ _context17.next = 8;
1382
2073
  break;
1383
2074
  }
1384
- return _context12.abrupt("return", result);
2075
+ return _context17.abrupt("return", result);
1385
2076
  case 8:
1386
2077
  if (!(result && _typeof(result) === 'object' && typeof result.shouldMerge === 'boolean')) {
1387
- _context12.next = 10;
2078
+ _context17.next = 10;
1388
2079
  break;
1389
2080
  }
1390
- return _context12.abrupt("return", result.shouldMerge);
2081
+ return _context17.abrupt("return", result.shouldMerge);
1391
2082
  case 10:
1392
- return _context12.abrupt("return", true);
2083
+ return _context17.abrupt("return", true);
1393
2084
  case 11:
1394
2085
  case "end":
1395
- return _context12.stop();
2086
+ return _context17.stop();
1396
2087
  }
1397
- }, _callee12, this);
2088
+ }, _callee15, this);
1398
2089
  }));
1399
- function shouldMergeProductToOrder(_x11) {
2090
+ function shouldMergeProductToOrder(_x15) {
1400
2091
  return _shouldMergeProductToOrder.apply(this, arguments);
1401
2092
  }
1402
2093
  return shouldMergeProductToOrder;
@@ -1404,11 +2095,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1404
2095
  }, {
1405
2096
  key: "addProductToOrder",
1406
2097
  value: function () {
1407
- var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(product, booking) {
1408
- var _this3 = this;
2098
+ var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(product, booking) {
2099
+ var _this8 = this;
1409
2100
  var tempOrder, linked, productToAdd, incomingFingerprint, normalizedIncoming, hasIncomingGoodPass, shouldForceNewLine, matchedIndex, matchedProduct, existedFingerprint, shouldMerge, _targetProduct$metada, targetProduct, targetUid, normalizedProduct;
1410
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1411
- while (1) switch (_context13.prev = _context13.next) {
2101
+ return _regeneratorRuntime().wrap(function _callee16$(_context18) {
2102
+ while (1) switch (_context18.prev = _context18.next) {
1412
2103
  case 0:
1413
2104
  tempOrder = this.ensureTempOrder();
1414
2105
  linked = booking ? this.createLinkedProductAndBooking({
@@ -1418,10 +2109,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1418
2109
  productToAdd = (linked === null || linked === void 0 ? void 0 : linked.product) || product;
1419
2110
  incomingFingerprint = buildProductLineFingerprint(productToAdd.product_option_item, productToAdd.product_bundle);
1420
2111
  normalizedIncoming = normalizeOrderProduct(productToAdd);
2112
+ normalizedIncoming.discount_list = normalizeOrderProductDiscountList(normalizedIncoming.discount_list);
1421
2113
  hasIncomingGoodPass = this.hasGoodPassDiscount(normalizedIncoming);
1422
2114
  shouldForceNewLine = !!booking;
1423
2115
  matchedIndex = hasIncomingGoodPass || shouldForceNewLine ? -1 : tempOrder.products.findIndex(function (item) {
1424
- if (_this3.hasGoodPassDiscount(item)) return false;
2116
+ if (_this8.hasGoodPassDiscount(item)) return false;
1425
2117
  if (item.product_id !== productToAdd.product_id) return false;
1426
2118
  if (item.product_variant_id !== productToAdd.product_variant_id) return false;
1427
2119
  var existedFingerprint = buildProductLineFingerprint(item.product_option_item, item.product_bundle);
@@ -1430,10 +2122,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1430
2122
  matchedProduct = matchedIndex === -1 ? null : tempOrder.products[matchedIndex];
1431
2123
  existedFingerprint = matchedProduct ? buildProductLineFingerprint(matchedProduct.product_option_item, matchedProduct.product_bundle) : '';
1432
2124
  if (!matchedProduct) {
1433
- _context13.next = 16;
2125
+ _context18.next = 17;
1434
2126
  break;
1435
2127
  }
1436
- _context13.next = 13;
2128
+ _context18.next = 14;
1437
2129
  return this.shouldMergeProductToOrder({
1438
2130
  incomingProduct: productToAdd,
1439
2131
  normalizedIncoming: normalizedIncoming,
@@ -1444,14 +2136,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1444
2136
  tempOrder: tempOrder,
1445
2137
  booking: booking
1446
2138
  });
1447
- case 13:
1448
- _context13.t0 = _context13.sent;
1449
- _context13.next = 17;
2139
+ case 14:
2140
+ _context18.t0 = _context18.sent;
2141
+ _context18.next = 18;
1450
2142
  break;
1451
- case 16:
1452
- _context13.t0 = false;
1453
2143
  case 17:
1454
- shouldMerge = _context13.t0;
2144
+ _context18.t0 = false;
2145
+ case 18:
2146
+ shouldMerge = _context18.t0;
1455
2147
  if (matchedIndex === -1 || !matchedProduct || !shouldMerge) {
1456
2148
  this.captureProductRuntime(tempOrder, productToAdd, normalizedIncoming);
1457
2149
  if (linked) {
@@ -1469,6 +2161,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1469
2161
  unique_identification_number: targetUid
1470
2162
  })
1471
2163
  }));
2164
+ normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
1472
2165
  tempOrder.products[matchedIndex] = _objectSpread(_objectSpread(_objectSpread({}, targetProduct), normalizedProduct), {}, {
1473
2166
  metadata: _objectSpread(_objectSpread(_objectSpread({}, targetProduct.metadata || {}), normalizedProduct.metadata || {}), {}, {
1474
2167
  unique_identification_number: targetUid
@@ -1482,21 +2175,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1482
2175
  if (linked) {
1483
2176
  tempOrder.bookings = [].concat(_toConsumableArray(tempOrder.bookings || []), [linked.booking]);
1484
2177
  }
2178
+ _context18.next = 23;
2179
+ return this.applyPromotion();
2180
+ case 23:
1485
2181
  this.applyDiscount();
1486
- _context13.next = 23;
2182
+ _context18.next = 26;
1487
2183
  return this.recalculateSummary({
1488
2184
  createIfMissing: true
1489
2185
  });
1490
- case 23:
2186
+ case 26:
1491
2187
  this.persistTempOrder();
1492
- return _context13.abrupt("return", tempOrder.products);
1493
- case 25:
2188
+ return _context18.abrupt("return", tempOrder.products);
2189
+ case 28:
1494
2190
  case "end":
1495
- return _context13.stop();
2191
+ return _context18.stop();
1496
2192
  }
1497
- }, _callee13, this);
2193
+ }, _callee16, this);
1498
2194
  }));
1499
- function addProductToOrder(_x12, _x13) {
2195
+ function addProductToOrder(_x16, _x17) {
1500
2196
  return _addProductToOrder.apply(this, arguments);
1501
2197
  }
1502
2198
  return addProductToOrder;
@@ -1521,15 +2217,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1521
2217
  });
1522
2218
  }
1523
2219
  }, {
1524
- key: "updateProductInOrder",
2220
+ key: "updateOrderProduct",
1525
2221
  value: function () {
1526
- var _updateProductInOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(params) {
2222
+ var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(params) {
1527
2223
  var _targetProduct$metada2, _metadata, _metadata2, _metadata3, _tempOrder$products$p;
1528
- var product_id, product_variant_id, updates, unique_identification_number, product_option_item, product_bundle, tempOrder, identityLookup, productIndex, targetProduct, nextProduct, callerUpdatesTopPrice, callerUpdatesMainMeta, existedMeta;
1529
- return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1530
- while (1) switch (_context14.prev = _context14.next) {
2224
+ var product_id, product_variant_id, updates, unique_identification_number, identity_key, product_option_item, product_bundle, booking, tempOrder, identityLookup, productIndex, targetUid, targetProduct, nextProduct, callerUpdatesTopPrice, callerUpdatesMainMeta, existedMeta, normalizedProduct, _normalizedProduct$me, _targetProduct$metada3, productUid, linked;
2225
+ return _regeneratorRuntime().wrap(function _callee17$(_context19) {
2226
+ while (1) switch (_context19.prev = _context19.next) {
1531
2227
  case 0:
1532
- product_id = params.product_id, product_variant_id = params.product_variant_id, updates = params.updates, unique_identification_number = params.unique_identification_number, product_option_item = params.product_option_item, product_bundle = params.product_bundle;
2228
+ product_id = params.product_id, product_variant_id = params.product_variant_id, updates = params.updates, unique_identification_number = params.unique_identification_number, identity_key = params.identity_key, product_option_item = params.product_option_item, product_bundle = params.product_bundle, booking = params.booking;
1533
2229
  tempOrder = this.ensureTempOrder();
1534
2230
  identityLookup = {
1535
2231
  product_id: product_id,
@@ -1537,16 +2233,32 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1537
2233
  };
1538
2234
  if (unique_identification_number !== undefined) {
1539
2235
  identityLookup.unique_identification_number = unique_identification_number;
2236
+ if (identity_key === undefined) {
2237
+ identityLookup.identity_key = unique_identification_number;
2238
+ }
2239
+ }
2240
+ if (identity_key !== undefined) {
2241
+ identityLookup.identity_key = identity_key;
1540
2242
  }
1541
2243
  if (product_option_item !== undefined) identityLookup.product_option_item = product_option_item;
1542
2244
  if (product_bundle !== undefined) identityLookup.product_bundle = product_bundle;
1543
- productIndex = getProductIdentityIndex(tempOrder.products, identityLookup);
2245
+ productIndex = -1;
2246
+ if (unique_identification_number !== undefined) {
2247
+ targetUid = String(unique_identification_number);
2248
+ productIndex = tempOrder.products.findIndex(function (item) {
2249
+ var _item$metadata;
2250
+ return String(((_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.unique_identification_number) || item.unique_identification_number || '') === targetUid;
2251
+ });
2252
+ }
2253
+ if (productIndex === -1) {
2254
+ productIndex = getProductIdentityIndex(tempOrder.products, identityLookup);
2255
+ }
1544
2256
  if (!(productIndex === -1)) {
1545
- _context14.next = 9;
2257
+ _context19.next = 12;
1546
2258
  break;
1547
2259
  }
1548
2260
  throw new Error('[Order] 目标商品不存在,无法更新');
1549
- case 9:
2261
+ case 12:
1550
2262
  targetProduct = tempOrder.products[productIndex];
1551
2263
  nextProduct = _objectSpread(_objectSpread(_objectSpread({}, targetProduct), updates), {}, {
1552
2264
  product_id: product_id,
@@ -1574,57 +2286,230 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1574
2286
  }
1575
2287
  // normalizeOrderProduct 幂等:v2 metadata 存在 → 保留 main_product_* 折扣重算 composite;
1576
2288
  // 否则 → 把顶层 selling_price 视作 source,派生 main_product_* 并写 price_schema_version: 2。
1577
- tempOrder.products[productIndex] = normalizeOrderProduct(nextProduct);
2289
+ normalizedProduct = normalizeOrderProduct(nextProduct);
2290
+ normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
2291
+ if (booking) {
2292
+ productUid = String(((_normalizedProduct$me = normalizedProduct.metadata) === null || _normalizedProduct$me === void 0 ? void 0 : _normalizedProduct$me.unique_identification_number) || ((_targetProduct$metada3 = targetProduct.metadata) === null || _targetProduct$metada3 === void 0 ? void 0 : _targetProduct$metada3.unique_identification_number) || unique_identification_number || createUuidV4());
2293
+ normalizedProduct.metadata = _objectSpread(_objectSpread({}, normalizedProduct.metadata || {}), {}, {
2294
+ unique_identification_number: productUid
2295
+ });
2296
+ linked = this.createLinkedProductAndBooking({
2297
+ product: _objectSpread(_objectSpread({}, normalizedProduct), {}, {
2298
+ unique_identification_number: productUid
2299
+ }),
2300
+ booking: booking
2301
+ });
2302
+ this.removeLinkedBookingsForProduct(tempOrder, targetProduct);
2303
+ normalizedProduct = _objectSpread(_objectSpread({}, normalizedProduct), {}, {
2304
+ booking_uid: linked.bookingUid,
2305
+ metadata: _objectSpread(_objectSpread({}, normalizedProduct.metadata || {}), {}, {
2306
+ booking_uid: linked.bookingUid,
2307
+ unique_identification_number: productUid
2308
+ })
2309
+ });
2310
+ tempOrder.bookings = [].concat(_toConsumableArray(tempOrder.bookings || []), [linked.booking]);
2311
+ }
2312
+ tempOrder.products[productIndex] = normalizedProduct;
1578
2313
  this.captureProductRuntime(tempOrder, updates, tempOrder.products[productIndex], (_tempOrder$products$p = tempOrder.products[productIndex].metadata) === null || _tempOrder$products$p === void 0 ? void 0 : _tempOrder$products$p.unique_identification_number);
2314
+ _context19.next = 25;
2315
+ return this.applyPromotion();
2316
+ case 25:
1579
2317
  this.applyDiscount();
1580
- _context14.next = 20;
2318
+ _context19.next = 28;
1581
2319
  return this.recalculateSummary({
1582
2320
  createIfMissing: true
1583
2321
  });
1584
- case 20:
2322
+ case 28:
1585
2323
  this.persistTempOrder();
1586
- return _context14.abrupt("return", tempOrder.products);
1587
- case 22:
2324
+ return _context19.abrupt("return", tempOrder.products);
2325
+ case 30:
1588
2326
  case "end":
1589
- return _context14.stop();
2327
+ return _context19.stop();
1590
2328
  }
1591
- }, _callee14, this);
2329
+ }, _callee17, this);
1592
2330
  }));
1593
- function updateProductInOrder(_x14) {
1594
- return _updateProductInOrder.apply(this, arguments);
2331
+ function updateOrderProduct(_x18) {
2332
+ return _updateOrderProduct.apply(this, arguments);
1595
2333
  }
1596
- return updateProductInOrder;
2334
+ return updateOrderProduct;
1597
2335
  }()
2336
+ }, {
2337
+ key: "updateOrderProductQuantity",
2338
+ value: function () {
2339
+ var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(params) {
2340
+ var _targetProduct$metada4;
2341
+ var product_id, product_variant_id, num, unique_identification_number, identity_key, product_option_item, product_bundle, tempOrder, identityLookup, productIndex, targetUid, targetProduct, normalizedProduct;
2342
+ return _regeneratorRuntime().wrap(function _callee18$(_context20) {
2343
+ while (1) switch (_context20.prev = _context20.next) {
2344
+ case 0:
2345
+ 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_option_item = params.product_option_item, product_bundle = params.product_bundle;
2346
+ tempOrder = this.ensureTempOrder();
2347
+ identityLookup = {
2348
+ product_id: product_id,
2349
+ product_variant_id: product_variant_id
2350
+ };
2351
+ if (unique_identification_number !== undefined) {
2352
+ identityLookup.unique_identification_number = unique_identification_number;
2353
+ if (identity_key === undefined) {
2354
+ identityLookup.identity_key = unique_identification_number;
2355
+ }
2356
+ }
2357
+ if (identity_key !== undefined) identityLookup.identity_key = identity_key;
2358
+ if (product_option_item !== undefined) identityLookup.product_option_item = product_option_item;
2359
+ if (product_bundle !== undefined) identityLookup.product_bundle = product_bundle;
2360
+ productIndex = -1;
2361
+ if (unique_identification_number !== undefined) {
2362
+ targetUid = String(unique_identification_number);
2363
+ productIndex = tempOrder.products.findIndex(function (item) {
2364
+ var _item$metadata2;
2365
+ return String(((_item$metadata2 = item.metadata) === null || _item$metadata2 === void 0 ? void 0 : _item$metadata2.unique_identification_number) || item.unique_identification_number || '') === targetUid;
2366
+ });
2367
+ }
2368
+ if (productIndex === -1) {
2369
+ productIndex = getProductIdentityIndex(tempOrder.products, identityLookup);
2370
+ }
2371
+ if (!(productIndex === -1)) {
2372
+ _context20.next = 12;
2373
+ break;
2374
+ }
2375
+ throw new Error('[Order] 目标商品不存在,无法更新数量');
2376
+ case 12:
2377
+ targetProduct = tempOrder.products[productIndex];
2378
+ normalizedProduct = normalizeOrderProduct(_objectSpread(_objectSpread({}, targetProduct), {}, {
2379
+ num: getSafeProductNum(num),
2380
+ metadata: _objectSpread(_objectSpread({}, targetProduct.metadata || {}), {}, {
2381
+ unique_identification_number: ((_targetProduct$metada4 = targetProduct.metadata) === null || _targetProduct$metada4 === void 0 ? void 0 : _targetProduct$metada4.unique_identification_number) || unique_identification_number
2382
+ })
2383
+ }));
2384
+ normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
2385
+ tempOrder.products[productIndex] = normalizedProduct;
2386
+ _context20.next = 18;
2387
+ return this.applyPromotion();
2388
+ case 18:
2389
+ this.applyDiscount();
2390
+ _context20.next = 21;
2391
+ return this.recalculateSummary({
2392
+ createIfMissing: true
2393
+ });
2394
+ case 21:
2395
+ this.persistTempOrder();
2396
+ return _context20.abrupt("return", tempOrder.products);
2397
+ case 23:
2398
+ case "end":
2399
+ return _context20.stop();
2400
+ }
2401
+ }, _callee18, this);
2402
+ }));
2403
+ function updateOrderProductQuantity(_x19) {
2404
+ return _updateOrderProductQuantity.apply(this, arguments);
2405
+ }
2406
+ return updateOrderProductQuantity;
2407
+ }()
2408
+ }, {
2409
+ key: "updateOrderBooking",
2410
+ value: function updateOrderBooking(params) {
2411
+ var unique_identification_number = params.unique_identification_number,
2412
+ updates = params.updates;
2413
+ var tempOrder = this.ensureTempOrder();
2414
+ var bookingUid = String(unique_identification_number || '');
2415
+ var bookingIndex = this.findBookingIndexByUniqueIdentificationNumber(tempOrder, bookingUid);
2416
+ if (!bookingUid || bookingIndex === -1) {
2417
+ throw new Error('[Order] 目标 booking 不存在,无法更新');
2418
+ }
2419
+ var targetBooking = tempOrder.bookings[bookingIndex] || {};
2420
+ var nextBooking = _objectSpread(_objectSpread(_objectSpread({}, targetBooking), updates), {}, {
2421
+ metadata: _objectSpread(_objectSpread(_objectSpread({}, targetBooking.metadata || {}), updates.metadata || {}), {}, {
2422
+ unique_identification_number: bookingUid
2423
+ })
2424
+ });
2425
+ nextBooking.is_all = normalizeBookingIsAll(nextBooking);
2426
+ nextBooking.sub_type = normalizeBookingSubType(nextBooking);
2427
+ tempOrder.bookings[bookingIndex] = nextBooking;
2428
+ this.persistTempOrder();
2429
+ return tempOrder.bookings;
2430
+ }
1598
2431
  }, {
1599
2432
  key: "removeProductFromOrder",
1600
2433
  value: function () {
1601
- var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(identity) {
1602
- var tempOrder;
1603
- return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1604
- while (1) switch (_context15.prev = _context15.next) {
2434
+ var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(identity) {
2435
+ var tempOrder, removedProducts, _i, _removedProducts, product;
2436
+ return _regeneratorRuntime().wrap(function _callee19$(_context21) {
2437
+ while (1) switch (_context21.prev = _context21.next) {
1605
2438
  case 0:
1606
2439
  tempOrder = this.ensureTempOrder();
2440
+ removedProducts = [];
1607
2441
  tempOrder.products = tempOrder.products.filter(function (item) {
1608
- return !isIdentityMatch(item, identity);
2442
+ var shouldRemove = isIdentityMatch(item, identity);
2443
+ if (shouldRemove) removedProducts.push(item);
2444
+ return !shouldRemove;
1609
2445
  });
2446
+ for (_i = 0, _removedProducts = removedProducts; _i < _removedProducts.length; _i++) {
2447
+ product = _removedProducts[_i];
2448
+ this.removeLinkedBookingsForProduct(tempOrder, product);
2449
+ }
2450
+ _context21.next = 6;
2451
+ return this.applyPromotion();
2452
+ case 6:
1610
2453
  this.applyDiscount();
1611
- _context15.next = 5;
2454
+ _context21.next = 9;
1612
2455
  return this.recalculateSummary({
1613
2456
  createIfMissing: true
1614
2457
  });
1615
- case 5:
2458
+ case 9:
1616
2459
  this.persistTempOrder();
1617
- return _context15.abrupt("return", tempOrder.products);
1618
- case 7:
2460
+ return _context21.abrupt("return", tempOrder.products);
2461
+ case 11:
1619
2462
  case "end":
1620
- return _context15.stop();
2463
+ return _context21.stop();
1621
2464
  }
1622
- }, _callee15, this);
2465
+ }, _callee19, this);
1623
2466
  }));
1624
- function removeProductFromOrder(_x15) {
2467
+ function removeProductFromOrder(_x20) {
1625
2468
  return _removeProductFromOrder.apply(this, arguments);
1626
2469
  }
1627
2470
  return removeProductFromOrder;
2471
+ }()
2472
+ /**
2473
+ * 仅清空购物车行(products / bookings),不重置整单。
2474
+ * 用于「仅清空商品」;客户、备注、支付等协议字段保持不变。
2475
+ */
2476
+ }, {
2477
+ key: "clearOrderCartLines",
2478
+ value: (function () {
2479
+ var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
2480
+ var tempOrder;
2481
+ return _regeneratorRuntime().wrap(function _callee20$(_context22) {
2482
+ while (1) switch (_context22.prev = _context22.next) {
2483
+ case 0:
2484
+ tempOrder = this.ensureTempOrder();
2485
+ tempOrder.products = [];
2486
+ tempOrder.bookings = [];
2487
+ if (tempOrder._extend && _typeof(tempOrder._extend) === 'object') {
2488
+ tempOrder._extend = _objectSpread(_objectSpread({}, tempOrder._extend), {}, {
2489
+ productsByUid: {}
2490
+ });
2491
+ }
2492
+ _context22.next = 6;
2493
+ return this.applyPromotion();
2494
+ case 6:
2495
+ this.applyDiscount();
2496
+ _context22.next = 9;
2497
+ return this.recalculateSummary({
2498
+ createIfMissing: true
2499
+ });
2500
+ case 9:
2501
+ this.persistTempOrder();
2502
+ return _context22.abrupt("return", tempOrder);
2503
+ case 11:
2504
+ case "end":
2505
+ return _context22.stop();
2506
+ }
2507
+ }, _callee20, this);
2508
+ }));
2509
+ function clearOrderCartLines() {
2510
+ return _clearOrderCartLines.apply(this, arguments);
2511
+ }
2512
+ return clearOrderCartLines;
1628
2513
  }() // ─── TempOrder: 提交 ───
1629
2514
  /**
1630
2515
  * 提交当前 Sales tempOrder。
@@ -1632,14 +2517,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1632
2517
  * smallTicketDataFlag 用于 B 端 checkout 小票数据返回。PaymentModal 在支付提交时
1633
2518
  * 应传 1,确保 /order/sales/checkout 返回打印所需数据。
1634
2519
  */
2520
+ )
1635
2521
  }, {
1636
2522
  key: "submitTempOrder",
1637
2523
  value: function () {
1638
- var _submitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(params) {
2524
+ var _submitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(params) {
1639
2525
  var _params$cacheId, _this$otherParams;
1640
2526
  var tempOrder, effectiveCacheId, hasPaymentOverride, hasPaymentStatusOverride, hasSmallTicketDataFlagOverride, enhancePayload, payload, result, _payload$payments, _payload$payments2, backendErrorResponse, submittedOrderId, resultRecord;
1641
- return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1642
- while (1) switch (_context16.prev = _context16.next) {
2527
+ return _regeneratorRuntime().wrap(function _callee21$(_context23) {
2528
+ while (1) switch (_context23.prev = _context23.next) {
1643
2529
  case 0:
1644
2530
  tempOrder = this.ensureTempOrder();
1645
2531
  this.persistTempOrder();
@@ -1655,7 +2541,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1655
2541
  } : {}), hasSmallTicketDataFlagOverride ? {
1656
2542
  small_ticket_data_flag: params === null || params === void 0 ? void 0 : params.smallTicketDataFlag
1657
2543
  } : {});
1658
- return params !== null && params !== void 0 && params.enhancePayload ? params.enhancePayload(nextPayload, ctx) : nextPayload;
2544
+ var enhancedPayload = params !== null && params !== void 0 && params.enhancePayload ? params.enhancePayload(nextPayload, ctx) : nextPayload;
2545
+ return enhancedPayload;
1659
2546
  } : undefined;
1660
2547
  payload = buildSubmitPayload({
1661
2548
  tempOrder: tempOrder,
@@ -1666,73 +2553,74 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1666
2553
  type: params === null || params === void 0 ? void 0 : params.type,
1667
2554
  enhance: enhancePayload
1668
2555
  });
1669
- _context16.next = 10;
2556
+ _context23.next = 10;
1670
2557
  return this.saveDraft();
1671
2558
  case 10:
1672
- _context16.prev = 10;
2559
+ _context23.prev = 10;
1673
2560
  this.logInfo('submitTempOrder calling sales checkout', {
1674
2561
  orderId: payload.order_id,
1675
2562
  externalSaleNumber: payload.external_sale_number,
2563
+ requestUniqueIdempotencyToken: payload.request_unique_idempotency_token,
1676
2564
  paymentStatus: payload.payment_status,
1677
2565
  paymentsCount: ((_payload$payments = payload.payments) === null || _payload$payments === void 0 ? void 0 : _payload$payments.length) || 0,
1678
2566
  smallTicketDataFlag: payload.small_ticket_data_flag
1679
2567
  });
1680
- _context16.next = 14;
2568
+ _context23.next = 14;
1681
2569
  return this.submitSalesOrder({
1682
2570
  query: payload
1683
2571
  });
1684
2572
  case 14:
1685
- result = _context16.sent;
1686
- _context16.next = 27;
2573
+ result = _context23.sent;
2574
+ _context23.next = 27;
1687
2575
  break;
1688
2576
  case 17:
1689
- _context16.prev = 17;
1690
- _context16.t0 = _context16["catch"](10);
1691
- backendErrorResponse = this.extractSubmitErrorResponse(_context16.t0);
2577
+ _context23.prev = 17;
2578
+ _context23.t0 = _context23["catch"](10);
2579
+ backendErrorResponse = this.extractSubmitErrorResponse(_context23.t0);
1692
2580
  if (!backendErrorResponse) {
1693
- _context16.next = 24;
2581
+ _context23.next = 24;
1694
2582
  break;
1695
2583
  }
1696
2584
  this.store.syncState = 'failed';
1697
2585
  this.logSubmitBackendRejected(backendErrorResponse, payload);
1698
- return _context16.abrupt("return", backendErrorResponse);
2586
+ return _context23.abrupt("return", backendErrorResponse);
1699
2587
  case 24:
1700
2588
  this.store.syncState = 'failed';
1701
2589
  this.logError('submitTempOrder failed', {
1702
- error: _context16.t0 instanceof Error ? _context16.t0.message : String(_context16.t0),
2590
+ error: _context23.t0 instanceof Error ? _context23.t0.message : String(_context23.t0),
1703
2591
  orderId: payload.order_id,
1704
2592
  externalSaleNumber: payload.external_sale_number,
1705
2593
  paymentStatus: payload.payment_status,
1706
2594
  paymentsCount: ((_payload$payments2 = payload.payments) === null || _payload$payments2 === void 0 ? void 0 : _payload$payments2.length) || 0
1707
2595
  });
1708
- throw _context16.t0;
2596
+ throw _context23.t0;
1709
2597
  case 27:
1710
2598
  if (!this.isSubmitResponseRejected(result)) {
1711
- _context16.next = 31;
2599
+ _context23.next = 31;
1712
2600
  break;
1713
2601
  }
1714
2602
  this.store.syncState = 'failed';
1715
2603
  this.logSubmitBackendRejected(result, payload);
1716
- return _context16.abrupt("return", result);
2604
+ return _context23.abrupt("return", result);
1717
2605
  case 31:
1718
2606
  submittedOrderId = this.extractOrderIdFromSubmitResult(result);
1719
2607
  if (!(submittedOrderId !== null && submittedOrderId !== undefined)) {
1720
- _context16.next = 37;
2608
+ _context23.next = 37;
1721
2609
  break;
1722
2610
  }
1723
2611
  tempOrder.order_id = submittedOrderId;
1724
2612
  resultRecord = result;
1725
- _context16.next = 37;
2613
+ _context23.next = 37;
1726
2614
  return this.markLocalOrderSynced(submittedOrderId, (resultRecord === null || resultRecord === void 0 ? void 0 : resultRecord.data) || resultRecord || {});
1727
2615
  case 37:
1728
- return _context16.abrupt("return", result);
2616
+ return _context23.abrupt("return", result);
1729
2617
  case 38:
1730
2618
  case "end":
1731
- return _context16.stop();
2619
+ return _context23.stop();
1732
2620
  }
1733
- }, _callee16, this, [[10, 17]]);
2621
+ }, _callee21, this, [[10, 17]]);
1734
2622
  }));
1735
- function submitTempOrder(_x16) {
2623
+ function submitTempOrder(_x21) {
1736
2624
  return _submitTempOrder.apply(this, arguments);
1737
2625
  }
1738
2626
  return submitTempOrder;
@@ -1740,25 +2628,25 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1740
2628
  }, {
1741
2629
  key: "markLocalOrderSynced",
1742
2630
  value: function () {
1743
- var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(orderId, remoteOrder) {
2631
+ var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(orderId, remoteOrder) {
1744
2632
  var tempOrder;
1745
- return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1746
- while (1) switch (_context17.prev = _context17.next) {
2633
+ return _regeneratorRuntime().wrap(function _callee22$(_context24) {
2634
+ while (1) switch (_context24.prev = _context24.next) {
1747
2635
  case 0:
1748
2636
  tempOrder = this.ensureTempOrder();
1749
2637
  tempOrder.order_id = orderId;
1750
2638
  this.store.lastOrderInfo = remoteOrder;
1751
2639
  this.store.syncState = 'submitted';
1752
2640
  this.persistTempOrder();
1753
- _context17.next = 7;
2641
+ _context24.next = 7;
1754
2642
  return this.saveDraft();
1755
2643
  case 7:
1756
2644
  case "end":
1757
- return _context17.stop();
2645
+ return _context24.stop();
1758
2646
  }
1759
- }, _callee17, this);
2647
+ }, _callee22, this);
1760
2648
  }));
1761
- function markLocalOrderSynced(_x17, _x18) {
2649
+ function markLocalOrderSynced(_x22, _x23) {
1762
2650
  return _markLocalOrderSynced.apply(this, arguments);
1763
2651
  }
1764
2652
  return markLocalOrderSynced;
@@ -1782,10 +2670,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1782
2670
  value: function extractSubmitErrorResponse(error) {
1783
2671
  var _error$response,
1784
2672
  _error$response2,
1785
- _this4 = this;
2673
+ _this9 = this;
1786
2674
  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];
1787
2675
  return candidates.find(function (candidate) {
1788
- return _this4.isSubmitErrorResponse(candidate);
2676
+ return _this9.isSubmitErrorResponse(candidate);
1789
2677
  }) || null;
1790
2678
  }
1791
2679
  }, {
@@ -1805,49 +2693,67 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1805
2693
  }, {
1806
2694
  key: "syncPaymentsToOrder",
1807
2695
  value: function () {
1808
- var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(params) {
1809
- var tempOrder, mappedPayments, paymentTotal, targetAmount, isFullyPaid, submitResult;
1810
- return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1811
- while (1) switch (_context18.prev = _context18.next) {
2696
+ var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(params) {
2697
+ var tempOrder, mappedPayments, paymentTotal, targetAmount, isFullyPaid, paymentStatus, paymentSyncIdempotencyToken, submitResult;
2698
+ return _regeneratorRuntime().wrap(function _callee23$(_context25) {
2699
+ while (1) switch (_context25.prev = _context25.next) {
1812
2700
  case 0:
1813
2701
  tempOrder = this.ensureTempOrder();
1814
2702
  mappedPayments = mapPaymentItemsToOrderPayments(params.payments || []);
1815
- tempOrder.payments = mappedPayments;
1816
- if (params.paymentStatus) tempOrder.payment_status = params.paymentStatus;
1817
- this.persistTempOrder();
1818
- _context18.next = 7;
1819
- return this.saveDraft();
1820
- case 7:
1821
2703
  paymentTotal = this.calculatePaymentTotal(mappedPayments);
1822
2704
  targetAmount = this.getPaymentTargetAmount();
1823
2705
  isFullyPaid = targetAmount.lte(0) ? false : paymentTotal.gte(targetAmount);
1824
- if (!(!isFullyPaid || !params.submitWhenPaid)) {
1825
- _context18.next = 12;
2706
+ paymentStatus = isFullyPaid ? params.paymentStatus || 'paid' : 'partially_paid';
2707
+ tempOrder.payments = mappedPayments;
2708
+ tempOrder.payment_status = paymentStatus;
2709
+ this.persistTempOrder();
2710
+ _context25.next = 11;
2711
+ return this.saveDraft();
2712
+ case 11:
2713
+ if (params.submitWhenPaid) {
2714
+ _context25.next = 13;
1826
2715
  break;
1827
2716
  }
1828
- return _context18.abrupt("return", {
2717
+ return _context25.abrupt("return", {
1829
2718
  isFullyPaid: isFullyPaid
1830
2719
  });
1831
- case 12:
1832
- _context18.next = 14;
2720
+ case 13:
2721
+ if (!(this.store.syncState === 'submitting')) {
2722
+ _context25.next = 15;
2723
+ break;
2724
+ }
2725
+ return _context25.abrupt("return", {
2726
+ isFullyPaid: isFullyPaid
2727
+ });
2728
+ case 15:
2729
+ this.store.syncState = 'submitting';
2730
+ paymentSyncIdempotencyToken = this.buildPaymentSyncIdempotencyToken(tempOrder, mappedPayments);
2731
+ _context25.next = 19;
1833
2732
  return this.submitTempOrder({
1834
2733
  payments: mappedPayments,
1835
- paymentStatus: params.paymentStatus || 'paid',
1836
- smallTicketDataFlag: params.smallTicketDataFlag
2734
+ paymentStatus: paymentStatus,
2735
+ smallTicketDataFlag: params.smallTicketDataFlag,
2736
+ channel: params.channel,
2737
+ enhancePayload: function enhancePayload(payload) {
2738
+ var nextPayload = _objectSpread(_objectSpread({}, payload), {}, {
2739
+ request_unique_idempotency_token: paymentSyncIdempotencyToken
2740
+ });
2741
+ return nextPayload;
2742
+ }
1837
2743
  });
1838
- case 14:
1839
- submitResult = _context18.sent;
1840
- return _context18.abrupt("return", {
2744
+ case 19:
2745
+ submitResult = _context25.sent;
2746
+ return _context25.abrupt("return", {
1841
2747
  isFullyPaid: isFullyPaid,
1842
2748
  submitResult: submitResult
1843
2749
  });
1844
- case 16:
2750
+ case 21:
1845
2751
  case "end":
1846
- return _context18.stop();
2752
+ return _context25.stop();
1847
2753
  }
1848
- }, _callee18, this);
2754
+ }, _callee23, this);
1849
2755
  }));
1850
- function syncPaymentsToOrder(_x19) {
2756
+ function syncPaymentsToOrder(_x24) {
1851
2757
  return _syncPaymentsToOrder.apply(this, arguments);
1852
2758
  }
1853
2759
  return syncPaymentsToOrder;
@@ -1936,11 +2842,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1936
2842
  }, {
1937
2843
  key: "submitOrder",
1938
2844
  value: function () {
1939
- var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(order) {
2845
+ var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(order) {
1940
2846
  var _order$query$cartItem, _params$bookings, _params$relation_prod;
1941
2847
  var url, query, fetchUrl, params;
1942
- return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1943
- while (1) switch (_context19.prev = _context19.next) {
2848
+ return _regeneratorRuntime().wrap(function _callee24$(_context26) {
2849
+ while (1) switch (_context26.prev = _context26.next) {
1944
2850
  case 0:
1945
2851
  this.logInfo('submitOrder called', {
1946
2852
  url: order.url,
@@ -1960,14 +2866,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1960
2866
  relationProductsCount: ((_params$relation_prod = params.relation_products) === null || _params$relation_prod === void 0 ? void 0 : _params$relation_prod.length) || 0,
1961
2867
  scheduleDate: params.schedule_date
1962
2868
  });
1963
- return _context19.abrupt("return", this.request.post(fetchUrl, params));
2869
+ return _context26.abrupt("return", this.request.post(fetchUrl, params));
1964
2870
  case 6:
1965
2871
  case "end":
1966
- return _context19.stop();
2872
+ return _context26.stop();
1967
2873
  }
1968
- }, _callee19, this);
2874
+ }, _callee24, this);
1969
2875
  }));
1970
- function submitOrder(_x20) {
2876
+ function submitOrder(_x25) {
1971
2877
  return _submitOrder.apply(this, arguments);
1972
2878
  }
1973
2879
  return submitOrder;
@@ -1975,13 +2881,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1975
2881
  }, {
1976
2882
  key: "cancelOrder",
1977
2883
  value: function () {
1978
- var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(params) {
2884
+ var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(params) {
1979
2885
  var payload;
1980
- return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1981
- while (1) switch (_context20.prev = _context20.next) {
2886
+ return _regeneratorRuntime().wrap(function _callee25$(_context27) {
2887
+ while (1) switch (_context27.prev = _context27.next) {
1982
2888
  case 0:
1983
2889
  if (!(!Array.isArray(params.order_ids) || params.order_ids.length === 0)) {
1984
- _context20.next = 2;
2890
+ _context27.next = 2;
1985
2891
  break;
1986
2892
  }
1987
2893
  throw new Error('取消订单失败:order_ids 不能为空');
@@ -1997,16 +2903,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1997
2903
  method: 'PUT',
1998
2904
  orderIdsCount: params.order_ids.length
1999
2905
  });
2000
- return _context20.abrupt("return", this.request.put('/order/update-status', payload, {
2906
+ return _context27.abrupt("return", this.request.put('/order/update-status', payload, {
2001
2907
  isShopApi: true
2002
2908
  }));
2003
2909
  case 5:
2004
2910
  case "end":
2005
- return _context20.stop();
2911
+ return _context27.stop();
2006
2912
  }
2007
- }, _callee20, this);
2913
+ }, _callee25, this);
2008
2914
  }));
2009
- function cancelOrder(_x21) {
2915
+ function cancelOrder(_x26) {
2010
2916
  return _cancelOrder.apply(this, arguments);
2011
2917
  }
2012
2918
  return cancelOrder;
@@ -2014,19 +2920,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2014
2920
  }, {
2015
2921
  key: "changeBookingStatus",
2016
2922
  value: function () {
2017
- var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(params) {
2923
+ var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(params) {
2018
2924
  var url, payload;
2019
- return _regeneratorRuntime().wrap(function _callee21$(_context21) {
2020
- while (1) switch (_context21.prev = _context21.next) {
2925
+ return _regeneratorRuntime().wrap(function _callee26$(_context28) {
2926
+ while (1) switch (_context28.prev = _context28.next) {
2021
2927
  case 0:
2022
2928
  if (params.booking_id) {
2023
- _context21.next = 2;
2929
+ _context28.next = 2;
2024
2930
  break;
2025
2931
  }
2026
2932
  throw new Error('变更预约状态失败:booking_id 不能为空');
2027
2933
  case 2:
2028
2934
  if (params.appointment_status) {
2029
- _context21.next = 4;
2935
+ _context28.next = 4;
2030
2936
  break;
2031
2937
  }
2032
2938
  throw new Error('变更预约状态失败:appointment_status 不能为空');
@@ -2041,16 +2947,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2041
2947
  bookingId: params.booking_id,
2042
2948
  appointmentStatus: params.appointment_status
2043
2949
  });
2044
- return _context21.abrupt("return", this.request.put(url, payload, {
2950
+ return _context28.abrupt("return", this.request.put(url, payload, {
2045
2951
  isShopApi: true
2046
2952
  }));
2047
2953
  case 8:
2048
2954
  case "end":
2049
- return _context21.stop();
2955
+ return _context28.stop();
2050
2956
  }
2051
- }, _callee21, this);
2957
+ }, _callee26, this);
2052
2958
  }));
2053
- function changeBookingStatus(_x22) {
2959
+ function changeBookingStatus(_x27) {
2054
2960
  return _changeBookingStatus.apply(this, arguments);
2055
2961
  }
2056
2962
  return changeBookingStatus;
@@ -2068,11 +2974,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2068
2974
  }, {
2069
2975
  key: "createOrderByCheckout",
2070
2976
  value: (function () {
2071
- var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(params) {
2977
+ var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(params) {
2072
2978
  var _params$payments, _params$bookings2, _params$relation_prod2, _params$payments2, _params$payments3, _params$bookings3, _params$relation_prod3, _params$payments4;
2073
2979
  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;
2074
- return _regeneratorRuntime().wrap(function _callee22$(_context22) {
2075
- while (1) switch (_context22.prev = _context22.next) {
2980
+ return _regeneratorRuntime().wrap(function _callee27$(_context29) {
2981
+ while (1) switch (_context29.prev = _context29.next) {
2076
2982
  case 0:
2077
2983
  // 过滤掉由在线店铺下单的 payment 支付数据
2078
2984
  onlineStorePaymentCodeList = ['WXPAY', 'WECHAT', 'ALIPAY', 'APPLE_PAY', 'CREDIT_CARD_3DS', 'CREDIT_CARD_TOKEN', 'GOOGLE_PAY', 'GOOGLE_PAY_3DS', 'CREDIT_CARD'];
@@ -2106,7 +3012,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2106
3012
  relationProductsCount: ((_params$relation_prod3 = params.relation_products) === null || _params$relation_prod3 === void 0 ? void 0 : _params$relation_prod3.length) || 0,
2107
3013
  paymentsCount: ((_params$payments4 = params.payments) === null || _params$payments4 === void 0 ? void 0 : _params$payments4.length) || 0
2108
3014
  });
2109
- _context22.prev = 4;
3015
+ _context29.prev = 4;
2110
3016
  // 构建订单数据,设置默认值并允许 params 覆盖
2111
3017
  orderData = _objectSpread({
2112
3018
  sales_channel: 'my_pisel',
@@ -2170,10 +3076,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2170
3076
  });
2171
3077
 
2172
3078
  // 调用后端接口
2173
- _context22.next = 12;
3079
+ _context29.next = 12;
2174
3080
  return this.request.post('/order/checkout', orderData);
2175
3081
  case 12:
2176
- response = _context22.sent;
3082
+ response = _context29.sent;
2177
3083
  this.logInfo('Order API called successfully', {
2178
3084
  response: response
2179
3085
  });
@@ -2181,22 +3087,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2181
3087
  success: !!response,
2182
3088
  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)
2183
3089
  });
2184
- return _context22.abrupt("return", response);
3090
+ return _context29.abrupt("return", response);
2185
3091
  case 18:
2186
- _context22.prev = 18;
2187
- _context22.t0 = _context22["catch"](4);
2188
- console.error('[Order] createOrderByCheckout 创建订单失败:', _context22.t0);
3092
+ _context29.prev = 18;
3093
+ _context29.t0 = _context29["catch"](4);
3094
+ console.error('[Order] createOrderByCheckout 创建订单失败:', _context29.t0);
2189
3095
  this.logInfo('Order API called failed', {
2190
- error: _context22.t0 instanceof Error ? _context22.t0.message : String(_context22.t0)
3096
+ error: _context29.t0 instanceof Error ? _context29.t0.message : String(_context29.t0)
2191
3097
  });
2192
- throw _context22.t0;
3098
+ throw _context29.t0;
2193
3099
  case 23:
2194
3100
  case "end":
2195
- return _context22.stop();
3101
+ return _context29.stop();
2196
3102
  }
2197
- }, _callee22, this, [[4, 18]]);
3103
+ }, _callee27, this, [[4, 18]]);
2198
3104
  }));
2199
- function createOrderByCheckout(_x23) {
3105
+ function createOrderByCheckout(_x28) {
2200
3106
  return _createOrderByCheckout.apply(this, arguments);
2201
3107
  }
2202
3108
  return createOrderByCheckout;
@@ -2204,23 +3110,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2204
3110
  }, {
2205
3111
  key: "submitSalesOrder",
2206
3112
  value: function () {
2207
- var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(params) {
3113
+ var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(params) {
2208
3114
  var url, query, fetchUrl;
2209
- return _regeneratorRuntime().wrap(function _callee23$(_context23) {
2210
- while (1) switch (_context23.prev = _context23.next) {
3115
+ return _regeneratorRuntime().wrap(function _callee28$(_context30) {
3116
+ while (1) switch (_context30.prev = _context30.next) {
2211
3117
  case 0:
2212
3118
  url = params.url, query = params.query;
2213
3119
  fetchUrl = url || '/order/sales/checkout';
2214
- return _context23.abrupt("return", this.request.post(fetchUrl, query, {
3120
+ return _context30.abrupt("return", this.request.post(fetchUrl, query, {
2215
3121
  customToast: function customToast() {}
2216
3122
  }));
2217
3123
  case 3:
2218
3124
  case "end":
2219
- return _context23.stop();
3125
+ return _context30.stop();
2220
3126
  }
2221
- }, _callee23, this);
3127
+ }, _callee28, this);
2222
3128
  }));
2223
- function submitSalesOrder(_x24) {
3129
+ function submitSalesOrder(_x29) {
2224
3130
  return _submitSalesOrder.apply(this, arguments);
2225
3131
  }
2226
3132
  return submitSalesOrder;
@@ -2234,37 +3140,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2234
3140
  }, {
2235
3141
  key: "sendCustomerPayLink",
2236
3142
  value: (function () {
2237
- var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(params) {
3143
+ var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(params) {
2238
3144
  var _params$emails;
2239
3145
  var orderIds;
2240
- return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2241
- while (1) switch (_context24.prev = _context24.next) {
3146
+ return _regeneratorRuntime().wrap(function _callee29$(_context31) {
3147
+ while (1) switch (_context31.prev = _context31.next) {
2242
3148
  case 0:
2243
3149
  orderIds = params.order_ids || params.orderIds || [];
2244
3150
  if (orderIds.length) {
2245
- _context24.next = 3;
3151
+ _context31.next = 3;
2246
3152
  break;
2247
3153
  }
2248
3154
  throw new Error('发送支付链接前必须先提交本地订单并取得订单 ID');
2249
3155
  case 3:
2250
3156
  if ((_params$emails = params.emails) !== null && _params$emails !== void 0 && _params$emails.length) {
2251
- _context24.next = 5;
3157
+ _context31.next = 5;
2252
3158
  break;
2253
3159
  }
2254
3160
  throw new Error('发送支付链接需要至少一个邮箱');
2255
3161
  case 5:
2256
- return _context24.abrupt("return", this.request.post('/order/batch-email', {
3162
+ return _context31.abrupt("return", this.request.post('/order/batch-email', {
2257
3163
  order_ids: orderIds,
2258
3164
  notify_action: params.notify_action || 'order_payment_reminder',
2259
3165
  emails: params.emails
2260
3166
  }));
2261
3167
  case 6:
2262
3168
  case "end":
2263
- return _context24.stop();
3169
+ return _context31.stop();
2264
3170
  }
2265
- }, _callee24, this);
3171
+ }, _callee29, this);
2266
3172
  }));
2267
- function sendCustomerPayLink(_x25) {
3173
+ function sendCustomerPayLink(_x30) {
2268
3174
  return _sendCustomerPayLink.apply(this, arguments);
2269
3175
  }
2270
3176
  return sendCustomerPayLink;
@@ -2273,28 +3179,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2273
3179
  }, {
2274
3180
  key: "getOrderInfoByRemote",
2275
3181
  value: function () {
2276
- var _getOrderInfoByRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(order_id) {
3182
+ var _getOrderInfoByRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(order_id) {
2277
3183
  var res;
2278
- return _regeneratorRuntime().wrap(function _callee25$(_context25) {
2279
- while (1) switch (_context25.prev = _context25.next) {
3184
+ return _regeneratorRuntime().wrap(function _callee30$(_context32) {
3185
+ while (1) switch (_context32.prev = _context32.next) {
2280
3186
  case 0:
2281
- _context25.next = 2;
3187
+ _context32.next = 2;
2282
3188
  return this.request.get("/order/sales/".concat(order_id), {
2283
3189
  with: ['products', 'bookings', 'payments', 'customer', 'summary', 'contacts_info']
2284
3190
  });
2285
3191
  case 2:
2286
- res = _context25.sent;
3192
+ res = _context32.sent;
2287
3193
  if (res.code === 200) {
2288
3194
  this.store.lastOrderInfo = res.data;
2289
3195
  }
2290
- return _context25.abrupt("return", res);
3196
+ return _context32.abrupt("return", res);
2291
3197
  case 5:
2292
3198
  case "end":
2293
- return _context25.stop();
3199
+ return _context32.stop();
2294
3200
  }
2295
- }, _callee25, this);
3201
+ }, _callee30, this);
2296
3202
  }));
2297
- function getOrderInfoByRemote(_x26) {
3203
+ function getOrderInfoByRemote(_x31) {
2298
3204
  return _getOrderInfoByRemote.apply(this, arguments);
2299
3205
  }
2300
3206
  return getOrderInfoByRemote;
@@ -2308,11 +3214,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2308
3214
  }, {
2309
3215
  key: "hydrateTempOrderFromRecord",
2310
3216
  value: (function () {
2311
- var _hydrateTempOrderFromRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(record, options) {
2312
- var _this5 = this;
3217
+ var _hydrateTempOrderFromRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(record, options) {
2313
3218
  var raw, defaults, nextTempOrder, TEMP_ORDER_KEYS;
2314
- return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2315
- while (1) switch (_context26.prev = _context26.next) {
3219
+ return _regeneratorRuntime().wrap(function _callee31$(_context33) {
3220
+ while (1) switch (_context33.prev = _context33.next) {
2316
3221
  case 0:
2317
3222
  raw = record && _typeof(record) === 'object' && record.data && record.order_id == null ? record.data : record || {};
2318
3223
  defaults = this.createDefaultTempOrderInstance();
@@ -2323,64 +3228,83 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2323
3228
  nextTempOrder[key] = raw[key];
2324
3229
  }
2325
3230
  });
2326
- nextTempOrder.metadata = raw.metadata && _typeof(raw.metadata) === 'object' ? _objectSpread({}, raw.metadata) : {};
2327
- nextTempOrder.holder = raw.holder && _typeof(raw.holder) === 'object' ? _objectSpread({}, raw.holder) : null;
2328
- nextTempOrder.products = Array.isArray(raw.products) ? raw.products.map(function (p) {
2329
- return _this5.normalizeHydratedOrderProduct(p);
2330
- }) : [];
2331
- nextTempOrder.bookings = Array.isArray(raw.bookings) ? raw.bookings.map(function (b) {
2332
- return _objectSpread(_objectSpread({}, b || {}), {}, {
2333
- is_all: normalizeBookingIsAll(b || {}),
2334
- sub_type: normalizeBookingSubType(b || {})
2335
- });
2336
- }) : [];
2337
- nextTempOrder.payments = Array.isArray(raw.payments) ? raw.payments.map(function (p) {
2338
- return _objectSpread({}, p || {});
2339
- }) : [];
2340
- nextTempOrder.surcharges = Array.isArray(raw.surcharges) ? raw.surcharges.map(function (s) {
2341
- return _objectSpread({}, s || {});
2342
- }) : [];
2343
- nextTempOrder.discount_list = Array.isArray(raw.discount_list) ? raw.discount_list.map(function (d) {
2344
- return _objectSpread({}, d || {});
2345
- }) : [];
2346
- nextTempOrder.relation_forms = Array.isArray(raw.relation_forms) ? raw.relation_forms.map(function (f) {
2347
- return _objectSpread({}, f || {});
2348
- }) : [];
2349
- nextTempOrder.contacts = Array.isArray(raw.contacts) ? raw.contacts.map(function (c) {
2350
- return _objectSpread({}, c || {});
2351
- }) : [];
2352
- nextTempOrder.contacts_info = raw.contacts_info && _typeof(raw.contacts_info) === 'object' && !Array.isArray(raw.contacts_info) ? _objectSpread({}, raw.contacts_info) : null;
2353
- nextTempOrder._extend = raw._extend && _typeof(raw._extend) === 'object' ? _objectSpread(_objectSpread({}, raw._extend), {}, {
2354
- productsByUid: raw._extend.productsByUid || {}
2355
- }) : {
2356
- productsByUid: {}
2357
- };
2358
- this.ensureExternalSaleNumber(nextTempOrder);
2359
3231
  this.store.tempOrder = nextTempOrder;
2360
3232
  this.store.summary = raw.summary && _typeof(raw.summary) === 'object' ? _objectSpread(_objectSpread({}, createEmptySummary()), raw.summary) : createEmptySummary();
2361
3233
  this.store.lastOrderInfo = raw.lastOrderInfo || raw;
2362
3234
  if (!(options !== null && options !== void 0 && options.recalcOnHydrate)) {
2363
- _context26.next = 23;
3235
+ _context33.next = 11;
2364
3236
  break;
2365
3237
  }
2366
- _context26.next = 23;
3238
+ _context33.next = 11;
2367
3239
  return this.recalculateSummary({
2368
3240
  createIfMissing: false
2369
3241
  });
2370
- case 23:
3242
+ case 11:
2371
3243
  this.persistTempOrder();
2372
- return _context26.abrupt("return", nextTempOrder);
2373
- case 25:
3244
+ return _context33.abrupt("return", nextTempOrder);
3245
+ case 13:
2374
3246
  case "end":
2375
- return _context26.stop();
3247
+ return _context33.stop();
2376
3248
  }
2377
- }, _callee26, this);
3249
+ }, _callee31, this);
2378
3250
  }));
2379
- function hydrateTempOrderFromRecord(_x27, _x28) {
3251
+ function hydrateTempOrderFromRecord(_x32, _x33) {
2380
3252
  return _hydrateTempOrderFromRecord.apply(this, arguments);
2381
3253
  }
2382
3254
  return hydrateTempOrderFromRecord;
2383
3255
  }())
3256
+ }, {
3257
+ key: "normalizeTempOrderForRuntime",
3258
+ value: function normalizeTempOrderForRuntime(raw, options) {
3259
+ var _this10 = this;
3260
+ var nextTempOrder = _objectSpread(_objectSpread({}, this.createDefaultTempOrderInstance()), raw || {});
3261
+ delete nextTempOrder.summary;
3262
+ delete nextTempOrder.lastOrderInfo;
3263
+ delete nextTempOrder.discount_list;
3264
+ delete nextTempOrder.shop_id;
3265
+ delete nextTempOrder.create_date;
3266
+ delete nextTempOrder.total_amount;
3267
+ delete nextTempOrder.expect_amount;
3268
+ delete nextTempOrder.paid_amount;
3269
+ delete nextTempOrder.shop_note;
3270
+ delete nextTempOrder.start_time;
3271
+ delete nextTempOrder.tax_fee;
3272
+ delete nextTempOrder.total_refund_amount;
3273
+ delete nextTempOrder.holder_id;
3274
+ nextTempOrder.metadata = raw.metadata && _typeof(raw.metadata) === 'object' ? _objectSpread({}, raw.metadata) : {};
3275
+ nextTempOrder.holder = raw.holder && _typeof(raw.holder) === 'object' ? _objectSpread({}, raw.holder) : null;
3276
+ nextTempOrder.products = Array.isArray(raw.products) ? raw.products.map(function (p) {
3277
+ return _this10.normalizeHydratedOrderProduct(p);
3278
+ }) : [];
3279
+ nextTempOrder.bookings = Array.isArray(raw.bookings) ? raw.bookings.map(function (b) {
3280
+ return _objectSpread(_objectSpread({}, b || {}), {}, {
3281
+ is_all: normalizeBookingIsAll(b || {}),
3282
+ sub_type: normalizeBookingSubType(b || {})
3283
+ });
3284
+ }) : [];
3285
+ nextTempOrder.payments = Array.isArray(raw.payments) ? raw.payments.map(function (p) {
3286
+ return _objectSpread({}, p || {});
3287
+ }) : [];
3288
+ nextTempOrder.surcharges = Array.isArray(raw.surcharges) ? raw.surcharges.map(function (s) {
3289
+ return _objectSpread({}, s || {});
3290
+ }) : [];
3291
+ nextTempOrder.relation_forms = Array.isArray(raw.relation_forms) ? raw.relation_forms.map(function (f) {
3292
+ return _objectSpread({}, f || {});
3293
+ }) : [];
3294
+ nextTempOrder.contacts = Array.isArray(raw.contacts) ? raw.contacts.map(function (c) {
3295
+ return _objectSpread({}, c || {});
3296
+ }) : [];
3297
+ nextTempOrder.contacts_info = raw.contacts_info && _typeof(raw.contacts_info) === 'object' && !Array.isArray(raw.contacts_info) ? _objectSpread({}, raw.contacts_info) : null;
3298
+ nextTempOrder._extend = raw._extend && _typeof(raw._extend) === 'object' ? _objectSpread(_objectSpread({}, raw._extend), {}, {
3299
+ productsByUid: raw._extend.productsByUid || {}
3300
+ }) : {
3301
+ productsByUid: {}
3302
+ };
3303
+ if ((options === null || options === void 0 ? void 0 : options.ensureIdentity) !== false) {
3304
+ this.ensureExternalSaleNumber(nextTempOrder);
3305
+ }
3306
+ return nextTempOrder;
3307
+ }
2384
3308
  }, {
2385
3309
  key: "normalizeHydratedOrderProduct",
2386
3310
  value: function normalizeHydratedOrderProduct(product) {
@@ -2396,6 +3320,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2396
3320
  row.metadata.unique_identification_number = createUuidV4();
2397
3321
  }
2398
3322
  var normalized = normalizeOrderProduct(row);
3323
+ normalized.discount_list = normalizeOrderProductDiscountList(normalized.discount_list);
2399
3324
  var result = _objectSpread(_objectSpread(_objectSpread({}, row), normalized), {}, {
2400
3325
  metadata: _objectSpread(_objectSpread({}, row.metadata), normalized.metadata)
2401
3326
  });
@@ -2411,25 +3336,25 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2411
3336
  }, {
2412
3337
  key: "getOrderInfo",
2413
3338
  value: function () {
2414
- var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(order_id) {
3339
+ var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(order_id) {
2415
3340
  var res;
2416
- return _regeneratorRuntime().wrap(function _callee27$(_context27) {
2417
- while (1) switch (_context27.prev = _context27.next) {
3341
+ return _regeneratorRuntime().wrap(function _callee32$(_context34) {
3342
+ while (1) switch (_context34.prev = _context34.next) {
2418
3343
  case 0:
2419
- _context27.next = 2;
3344
+ _context34.next = 2;
2420
3345
  return this.request.get("/order/sales/".concat(order_id), {
2421
3346
  with: ['products', 'bookings']
2422
3347
  });
2423
3348
  case 2:
2424
- res = _context27.sent;
2425
- return _context27.abrupt("return", res);
3349
+ res = _context34.sent;
3350
+ return _context34.abrupt("return", res);
2426
3351
  case 4:
2427
3352
  case "end":
2428
- return _context27.stop();
3353
+ return _context34.stop();
2429
3354
  }
2430
- }, _callee27, this);
3355
+ }, _callee32, this);
2431
3356
  }));
2432
- function getOrderInfo(_x29) {
3357
+ function getOrderInfo(_x34) {
2433
3358
  return _getOrderInfo.apply(this, arguments);
2434
3359
  }
2435
3360
  return getOrderInfo;
@@ -2443,46 +3368,75 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2443
3368
  */
2444
3369
  function populateSavedAmounts(productList, discountList) {
2445
3370
  var savedMap = new Map();
2446
- var _iterator = _createForOfIteratorHelper(productList),
2447
- _step;
3371
+ var addDiscountAmount = function addDiscountAmount(discount, quantity) {
3372
+ var _discount$discount, _discount$metadata;
3373
+ var discountKey = ((_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) || discount.id;
3374
+ if (discountKey == null) return;
3375
+ var qty = Number(quantity) || 1;
3376
+ var amount = new Decimal(discount.amount || 0).times(qty).plus(((_discount$metadata = discount.metadata) === null || _discount$metadata === void 0 ? void 0 : _discount$metadata.product_discount_difference) || 0);
3377
+ savedMap.set(discountKey, (savedMap.get(discountKey) || new Decimal(0)).plus(amount));
3378
+ };
3379
+ var _iterator8 = _createForOfIteratorHelper(productList),
3380
+ _step8;
2448
3381
  try {
2449
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
2450
- var product = _step.value;
3382
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
3383
+ var product = _step8.value;
2451
3384
  var qty = product.num || 1;
2452
- var _iterator3 = _createForOfIteratorHelper(product.discount_list || []),
2453
- _step3;
3385
+ var _iterator10 = _createForOfIteratorHelper(product.discount_list || []),
3386
+ _step10;
2454
3387
  try {
2455
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
2456
- var _pd$discount, _pd$metadata;
2457
- var pd = _step3.value;
2458
- var discountKey = ((_pd$discount = pd.discount) === null || _pd$discount === void 0 ? void 0 : _pd$discount.resource_id) || pd.id;
2459
- if (discountKey == null) continue;
2460
- var amount = new Decimal(pd.amount || 0).times(qty).plus(((_pd$metadata = pd.metadata) === null || _pd$metadata === void 0 ? void 0 : _pd$metadata.product_discount_difference) || 0);
2461
- savedMap.set(discountKey, (savedMap.get(discountKey) || new Decimal(0)).plus(amount));
3388
+ for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
3389
+ var pd = _step10.value;
3390
+ addDiscountAmount(pd, qty);
3391
+ }
3392
+ } catch (err) {
3393
+ _iterator10.e(err);
3394
+ } finally {
3395
+ _iterator10.f();
3396
+ }
3397
+ var _iterator11 = _createForOfIteratorHelper(product.product_bundle || []),
3398
+ _step11;
3399
+ try {
3400
+ for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
3401
+ var _ref23, _bundle$num;
3402
+ var bundle = _step11.value;
3403
+ var bundleQty = new Decimal(Number(qty) || 1).times(Number((_ref23 = (_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) !== null && _ref23 !== void 0 ? _ref23 : 1) || 1).toNumber();
3404
+ var _iterator12 = _createForOfIteratorHelper((bundle === null || bundle === void 0 ? void 0 : bundle.discount_list) || []),
3405
+ _step12;
3406
+ try {
3407
+ for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
3408
+ var _pd = _step12.value;
3409
+ addDiscountAmount(_pd, bundleQty);
3410
+ }
3411
+ } catch (err) {
3412
+ _iterator12.e(err);
3413
+ } finally {
3414
+ _iterator12.f();
3415
+ }
2462
3416
  }
2463
3417
  } catch (err) {
2464
- _iterator3.e(err);
3418
+ _iterator11.e(err);
2465
3419
  } finally {
2466
- _iterator3.f();
3420
+ _iterator11.f();
2467
3421
  }
2468
3422
  }
2469
3423
  } catch (err) {
2470
- _iterator.e(err);
3424
+ _iterator8.e(err);
2471
3425
  } finally {
2472
- _iterator.f();
3426
+ _iterator8.f();
2473
3427
  }
2474
- var _iterator2 = _createForOfIteratorHelper(discountList),
2475
- _step2;
3428
+ var _iterator9 = _createForOfIteratorHelper(discountList),
3429
+ _step9;
2476
3430
  try {
2477
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
2478
- var d = _step2.value;
3431
+ for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
3432
+ var d = _step9.value;
2479
3433
  var key = d.id;
2480
3434
  d.savedAmount = d.isSelected && key != null && savedMap.has(key) ? savedMap.get(key).toNumber() : 0;
2481
3435
  }
2482
3436
  } catch (err) {
2483
- _iterator2.e(err);
3437
+ _iterator9.e(err);
2484
3438
  } finally {
2485
- _iterator2.f();
3439
+ _iterator9.f();
2486
3440
  }
2487
3441
  }
2488
3442
  }]);