@pisell/pisellos 2.2.175 → 2.2.177

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 (176) hide show
  1. package/dist/modules/BookingContext/index.d.ts +37 -0
  2. package/dist/modules/BookingContext/index.js +436 -0
  3. package/dist/modules/BookingContext/types.d.ts +102 -0
  4. package/dist/modules/BookingContext/types.js +51 -0
  5. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  6. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +193 -0
  7. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  8. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +137 -0
  9. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +75 -0
  10. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +215 -0
  11. package/dist/modules/BookingContext/utils/flexible.d.ts +28 -0
  12. package/dist/modules/BookingContext/utils/flexible.js +56 -0
  13. package/dist/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  14. package/dist/modules/BookingContext/utils/formatResourceList.js +38 -0
  15. package/dist/modules/BookingContext/utils/index.d.ts +11 -0
  16. package/dist/modules/BookingContext/utils/index.js +11 -0
  17. package/dist/modules/BookingContext/utils/noResource.d.ts +13 -0
  18. package/dist/modules/BookingContext/utils/noResource.js +77 -0
  19. package/dist/modules/BookingContext/utils/productExtend.d.ts +72 -0
  20. package/dist/modules/BookingContext/utils/productExtend.js +339 -0
  21. package/dist/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  22. package/dist/modules/BookingContext/utils/resourceErrors.js +74 -0
  23. package/dist/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  24. package/dist/modules/BookingContext/utils/resourceSelection.js +24 -0
  25. package/dist/modules/BookingContext/utils/resources.d.ts +80 -0
  26. package/dist/modules/BookingContext/utils/resources.js +486 -0
  27. package/dist/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  28. package/dist/modules/BookingContext/utils/serviceTimes.js +151 -0
  29. package/dist/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  30. package/dist/modules/BookingContext/utils/timeSlices.js +100 -0
  31. package/dist/modules/Customer/index.d.ts +6 -0
  32. package/dist/modules/Customer/index.js +129 -83
  33. package/dist/modules/Customer/types.d.ts +2 -0
  34. package/dist/modules/Discount/index.d.ts +2 -4
  35. package/dist/modules/Discount/index.js +8 -93
  36. package/dist/modules/Discount/types.d.ts +1 -7
  37. package/dist/modules/Order/index.d.ts +86 -17
  38. package/dist/modules/Order/index.js +1303 -497
  39. package/dist/modules/Order/types.d.ts +198 -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 +212 -0
  43. package/dist/modules/Order/utils.d.ts +50 -1
  44. package/dist/modules/Order/utils.js +261 -31
  45. package/dist/modules/Quotation/index.d.ts +0 -1
  46. package/dist/modules/Quotation/index.js +23 -21
  47. package/dist/modules/Rules/index.d.ts +4 -0
  48. package/dist/modules/Rules/index.js +26 -10
  49. package/dist/modules/SalesSummary/index.js +4 -2
  50. package/dist/modules/SalesSummary/utils.js +18 -5
  51. package/dist/modules/Schedule/index.js +6 -2
  52. package/dist/modules/index.d.ts +1 -0
  53. package/dist/modules/index.js +2 -1
  54. package/dist/server/index.js +87 -29
  55. package/dist/server/modules/order/index.d.ts +23 -0
  56. package/dist/server/modules/order/index.js +123 -46
  57. package/dist/server/modules/order/utils/filterOrders.js +20 -6
  58. package/dist/server/modules/products/index.d.ts +1 -1
  59. package/dist/server/modules/products/index.js +130 -113
  60. package/dist/server/modules/schedule/index.js +13 -6
  61. package/dist/solution/BaseSales/index.d.ts +89 -7
  62. package/dist/solution/BaseSales/index.js +1484 -365
  63. package/dist/solution/BaseSales/types.d.ts +67 -1
  64. package/dist/solution/BaseSales/types.js +3 -1
  65. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +275 -0
  66. package/dist/solution/BaseSales/utils/cartPromotion.js +1258 -0
  67. package/dist/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
  68. package/dist/solution/BaseSales/utils/quotationPrice.js +237 -0
  69. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +68 -16
  70. package/dist/solution/BaseSales/utils.js +46 -8
  71. package/dist/solution/BookingByStep/index.d.ts +1 -1
  72. package/dist/solution/BookingTicket/index.d.ts +133 -1
  73. package/dist/solution/BookingTicket/index.js +780 -175
  74. package/dist/solution/BookingTicket/types.d.ts +2 -0
  75. package/dist/solution/BookingTicket/types.js +3 -0
  76. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +113 -0
  77. package/dist/solution/BookingTicket/utils/addProductDecision.js +346 -0
  78. package/dist/solution/BookingTicket/utils/cartView.js +4 -2
  79. package/dist/solution/ScanOrder/index.d.ts +9 -3
  80. package/dist/solution/ScanOrder/index.js +231 -128
  81. package/dist/solution/ScanOrder/utils.js +46 -8
  82. package/dist/solution/ShopDiscount/index.d.ts +0 -1
  83. package/dist/solution/ShopDiscount/index.js +18 -23
  84. package/dist/solution/VenueBooking/index.d.ts +5 -9
  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 +0 -49
  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 +207 -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.d.ts +2 -4
  123. package/lib/modules/Discount/index.js +8 -63
  124. package/lib/modules/Discount/types.d.ts +1 -7
  125. package/lib/modules/Order/index.d.ts +86 -17
  126. package/lib/modules/Order/index.js +633 -146
  127. package/lib/modules/Order/types.d.ts +198 -18
  128. package/lib/modules/Order/types.js +1 -0
  129. package/lib/modules/Order/utils/manualProductDiscount.d.ts +106 -0
  130. package/lib/modules/Order/utils/manualProductDiscount.js +207 -0
  131. package/lib/modules/Order/utils.d.ts +50 -1
  132. package/lib/modules/Order/utils.js +229 -21
  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 +22 -14
  137. package/lib/modules/SalesSummary/index.js +4 -2
  138. package/lib/modules/SalesSummary/utils.js +18 -5
  139. package/lib/modules/Schedule/index.js +3 -1
  140. package/lib/modules/index.d.ts +1 -0
  141. package/lib/modules/index.js +3 -1
  142. package/lib/server/index.js +41 -4
  143. package/lib/server/modules/order/index.d.ts +23 -0
  144. package/lib/server/modules/order/index.js +46 -14
  145. package/lib/server/modules/order/utils/filterOrders.js +12 -4
  146. package/lib/server/modules/products/index.d.ts +1 -1
  147. package/lib/server/modules/products/index.js +30 -20
  148. package/lib/server/modules/schedule/index.js +2 -1
  149. package/lib/solution/BaseSales/index.d.ts +89 -7
  150. package/lib/solution/BaseSales/index.js +736 -22
  151. package/lib/solution/BaseSales/types.d.ts +67 -1
  152. package/lib/solution/BaseSales/types.js +3 -1
  153. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +275 -0
  154. package/lib/solution/BaseSales/utils/cartPromotion.js +836 -0
  155. package/lib/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
  156. package/lib/solution/BaseSales/utils/quotationPrice.js +277 -0
  157. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +71 -12
  158. package/lib/solution/BaseSales/utils.js +46 -6
  159. package/lib/solution/BookingByStep/index.d.ts +1 -1
  160. package/lib/solution/BookingTicket/index.d.ts +133 -1
  161. package/lib/solution/BookingTicket/index.js +352 -8
  162. package/lib/solution/BookingTicket/types.d.ts +2 -0
  163. package/lib/solution/BookingTicket/types.js +6 -0
  164. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +113 -0
  165. package/lib/solution/BookingTicket/utils/addProductDecision.js +318 -0
  166. package/lib/solution/BookingTicket/utils/cartView.js +4 -2
  167. package/lib/solution/ScanOrder/index.d.ts +9 -3
  168. package/lib/solution/ScanOrder/index.js +147 -66
  169. package/lib/solution/ScanOrder/utils.js +46 -6
  170. package/lib/solution/ShopDiscount/index.d.ts +0 -1
  171. package/lib/solution/ShopDiscount/index.js +2 -4
  172. package/lib/solution/VenueBooking/index.d.ts +5 -9
  173. package/lib/solution/VenueBooking/index.js +50 -14
  174. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
  175. package/lib/solution/VenueBooking/utils/slotMerge.js +10 -0
  176. package/package.json +2 -2
@@ -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 } 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,42 @@ 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);
59
72
  return _this;
60
73
  }
61
74
  _createClass(OrderModule, [{
75
+ key: "applyProductDiscountPrices",
76
+ value: function applyProductDiscountPrices(products) {
77
+ return (products || []).map(function (product) {
78
+ var _product$metadata, _product$metadata$sou, _product$metadata2, _product$metadata3, _product$original_pri;
79
+ if ((_product$metadata = product.metadata) !== null && _product$metadata !== void 0 && _product$metadata.is_manual_discount) return product;
80
+ var totalPerUnitDiscount = resolveEffectivePerUnitDiscount(product);
81
+ var optionSum = sumOptionUnitPrice(product.product_option_item);
82
+ 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';
83
+ var newSourceSellingPrice = new Decimal(Number(sourcePrice) || 0).minus(totalPerUnitDiscount).toDecimalPlaces(2).toString();
84
+ var newMainSellingPrice = new Decimal(Number(newSourceSellingPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
85
+ if (product.metadata) {
86
+ product.metadata.main_product_selling_price = newMainSellingPrice;
87
+ product.metadata.price_schema_version = 2;
88
+ }
89
+ product.selling_price = composeLinePrice({
90
+ mainPrice: newMainSellingPrice,
91
+ bundle: product.product_bundle
92
+ });
93
+ return product;
94
+ });
95
+ }
96
+ }, {
62
97
  key: "initialize",
63
98
  value: function () {
64
99
  var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
@@ -94,9 +129,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
94
129
  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
130
  this.otherParams = otherParams;
96
131
  this.registerDiscountModules(options);
97
- this.restoreTempOrderFromStorage();
98
132
  this.logInfo('OrderModule initialized successfully');
99
- case 21:
133
+ case 20:
100
134
  case "end":
101
135
  return _context.stop();
102
136
  }
@@ -196,29 +230,40 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
196
230
  key: "loadDiscountConfig",
197
231
  value: function () {
198
232
  var _loadDiscountConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params) {
199
- var _this$store$discount, _this$store$tempOrder;
200
- var discountList, _this$store$discount2;
233
+ var _this$store$tempOrder, _this$store$discount, _this$store$tempOrder2;
234
+ var orderId, discountList, _this$store$discount2, _this$store$discount3;
201
235
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
202
236
  while (1) switch (_context2.prev = _context2.next) {
203
237
  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({
238
+ orderId = params.orderId || ((_this$store$tempOrder = this.store.tempOrder) === null || _this$store$tempOrder === void 0 ? void 0 : _this$store$tempOrder.order_id) || undefined;
239
+ _context2.next = 3;
240
+ return (_this$store$discount = this.store.discount) === null || _this$store$discount === void 0 ? void 0 : _this$store$discount.loadPrepareConfig(_objectSpread({
206
241
  customer_id: params.customerId,
207
- action: params.action || 'create',
242
+ action: params.action || (orderId ? 'edit' : 'create'),
208
243
  with_good_pass: 1,
209
244
  with_discount_card: 1,
210
245
  with_wallet_pass_holder: 1,
211
246
  request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
212
- });
213
- case 2:
247
+ }, orderId ? {
248
+ order_id: orderId
249
+ } : {}));
250
+ case 3:
214
251
  discountList = _context2.sent;
215
- if (discountList) {
216
- (_this$store$discount2 = this.store.discount) === null || _this$store$discount2 === void 0 || _this$store$discount2.setDiscountList(discountList);
252
+ if (!discountList) {
253
+ _context2.next = 9;
254
+ break;
217
255
  }
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) {
256
+ _context2.next = 7;
257
+ return (_this$store$discount2 = this.store.discount) === null || _this$store$discount2 === void 0 ? void 0 : _this$store$discount2.setOriginalDiscountList(discountList);
258
+ case 7:
259
+ _context2.next = 9;
260
+ return (_this$store$discount3 = this.store.discount) === null || _this$store$discount3 === void 0 ? void 0 : _this$store$discount3.setDiscountList(discountList);
261
+ case 9:
262
+ 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
263
  this.applyDiscount();
220
264
  }
221
- case 5:
265
+ return _context2.abrupt("return", this.getDiscountList());
266
+ case 11:
222
267
  case "end":
223
268
  return _context2.stop();
224
269
  }
@@ -232,20 +277,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
232
277
  }, {
233
278
  key: "getDiscountList",
234
279
  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()) || [];
280
+ var _this$store$discount4;
281
+ return ((_this$store$discount4 = this.store.discount) === null || _this$store$discount4 === void 0 ? void 0 : _this$store$discount4.getDiscountList()) || [];
237
282
  }
238
283
  }, {
239
284
  key: "scanCode",
240
285
  value: function () {
241
286
  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;
287
+ var _this$store$discount5, _tempOrder$holder, _this$store$summary, _tempOrder$holder2;
288
+ var resultDiscountList, rulesModule, withScanList, currentSelected, tempOrder, holders, _ref, isAvailable, newDiscountList, unavailableReason, _this$store$discount6;
244
289
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
245
290
  while (1) switch (_context3.prev = _context3.next) {
246
291
  case 0:
247
292
  _context3.next = 2;
248
- return (_this$store$discount4 = this.store.discount) === null || _this$store$discount4 === void 0 ? void 0 : _this$store$discount4.batchSearch(code, {
293
+ return (_this$store$discount5 = this.store.discount) === null || _this$store$discount5 === void 0 ? void 0 : _this$store$discount5.batchSearch(code, {
249
294
  customerId: customerId
250
295
  });
251
296
  case 2:
@@ -254,36 +299,33 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
254
299
  _context3.next = 5;
255
300
  break;
256
301
  }
257
- _context3.t0 = {
258
- discountList: [],
259
- unavailableReasonKey: null
260
- };
302
+ _context3.t0 = [];
261
303
  case 5:
262
- resultDiscountWithReason = _context3.t0;
263
- resultDiscountList = resultDiscountWithReason.discountList, unavailableReasonKey = resultDiscountWithReason.unavailableReasonKey;
304
+ resultDiscountList = _context3.t0;
264
305
  rulesModule = this.store.rules;
265
306
  if (rulesModule) {
266
- _context3.next = 10;
307
+ _context3.next = 9;
267
308
  break;
268
309
  }
269
310
  return _context3.abrupt("return", {
270
311
  type: 'clientCalc',
271
312
  isAvailable: false,
272
313
  discountList: this.getDiscountList(),
314
+ scannedDiscountList: resultDiscountList,
273
315
  unavailableReason: UnavailableReason.Unknown
274
316
  });
275
- case 10:
317
+ case 9:
276
318
  if (resultDiscountList.length) {
277
- _context3.next = 12;
319
+ _context3.next = 11;
278
320
  break;
279
321
  }
280
322
  return _context3.abrupt("return", {
281
323
  type: 'server',
282
324
  isAvailable: false,
283
325
  discountList: this.getDiscountList(),
284
- unavailableReasonKey: unavailableReasonKey
326
+ scannedDiscountList: resultDiscountList
285
327
  });
286
- case 12:
328
+ case 11:
287
329
  withScanList = resultDiscountList.map(function (item) {
288
330
  return _objectSpread(_objectSpread({}, item), {}, {
289
331
  isScan: true
@@ -297,15 +339,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
297
339
  return m.id === n.id;
298
340
  });
299
341
  }))) {
300
- _context3.next = 16;
342
+ _context3.next = 15;
301
343
  break;
302
344
  }
303
345
  return _context3.abrupt("return", {
304
346
  type: 'clientCalc',
305
347
  isAvailable: true,
306
- discountList: this.getDiscountList()
348
+ discountList: this.getDiscountList(),
349
+ scannedDiscountList: resultDiscountList
307
350
  });
308
- case 16:
351
+ case 15:
309
352
  tempOrder = this.store.tempOrder;
310
353
  holders = tempOrder !== null && tempOrder !== void 0 && (_tempOrder$holder = tempOrder.holder) !== null && _tempOrder$holder !== void 0 && _tempOrder$holder.form_record_id ? [{
311
354
  form_record_id: tempOrder.holder.form_record_id
@@ -322,16 +365,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
322
365
  discountList: this.getDiscountList()
323
366
  }, isAvailable = _ref.isAvailable, newDiscountList = _ref.discountList, unavailableReason = _ref.unavailableReason;
324
367
  if (isAvailable && newDiscountList) {
325
- (_this$store$discount5 = this.store.discount) === null || _this$store$discount5 === void 0 || _this$store$discount5.setDiscountList(newDiscountList);
368
+ (_this$store$discount6 = this.store.discount) === null || _this$store$discount6 === void 0 || _this$store$discount6.setDiscountList(newDiscountList);
326
369
  this.applyDiscount();
327
370
  }
328
371
  return _context3.abrupt("return", {
329
372
  type: 'clientCalc',
330
373
  isAvailable: isAvailable || false,
331
374
  discountList: newDiscountList || this.getDiscountList(),
375
+ scannedDiscountList: resultDiscountList,
332
376
  unavailableReason: unavailableReason
333
377
  });
334
- case 21:
378
+ case 20:
335
379
  case "end":
336
380
  return _context3.stop();
337
381
  }
@@ -345,15 +389,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
345
389
  }, {
346
390
  key: "applyDiscount",
347
391
  value: function applyDiscount() {
348
- var _this$store$discount6, _tempOrder$holder3, _tempOrder$holder4, _this$store$summary2;
392
+ var _this$store$discount7, _tempOrder$holder3, _tempOrder$holder4, _this$store$summary2;
349
393
  var tempOrder = this.store.tempOrder;
350
394
  // 任意 products CRUD 后都应当重算 discount 状态;即使 products 为空,
351
395
  // 也需要让 Rules.calcDiscount 把 DiscountModule 的 isSelected / isAvailable /
352
- // appliedProductDetails / savedAmount 以及 tempOrder.discount_list 复位。
396
+ // appliedProductDetails / savedAmount 复位。
353
397
  if (!tempOrder) return;
398
+ delete tempOrder.discount_list;
354
399
  var rulesModule = this.store.rules;
355
400
  if (!rulesModule) return;
356
- var discountList = ((_this$store$discount6 = this.store.discount) === null || _this$store$discount6 === void 0 ? void 0 : _this$store$discount6.getDiscountList()) || [];
401
+ var discountList = ((_this$store$discount7 = this.store.discount) === null || _this$store$discount7 === void 0 ? void 0 : _this$store$discount7.getDiscountList()) || [];
357
402
  var holders = (_tempOrder$holder3 = tempOrder.holder) !== null && _tempOrder$holder3 !== void 0 && _tempOrder$holder3.form_record_id ? [{
358
403
  form_record_id: tempOrder.holder.form_record_id
359
404
  }] : [];
@@ -365,16 +410,355 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
365
410
  orderTotalAmount: Number(((_this$store$summary2 = this.store.summary) === null || _this$store$summary2 === void 0 ? void 0 : _this$store$summary2.total_amount) || 0)
366
411
  });
367
412
  if (result !== null && result !== void 0 && result.productList) {
368
- tempOrder.products = result.productList;
413
+ tempOrder.products = this.applyProductDiscountPrices((result.productList || []).map(function (product) {
414
+ return _objectSpread(_objectSpread({}, product), {}, {
415
+ discount_list: normalizeOrderProductDiscountList(syncManualProductDiscountProductNum(product.discount_list, product.num))
416
+ });
417
+ }));
369
418
  }
370
419
  if (result !== null && result !== void 0 && result.discountList) {
371
- var _this$store$discount7;
420
+ var _this$store$discount8;
372
421
  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
- });
422
+ (_this$store$discount8 = this.store.discount) === null || _this$store$discount8 === void 0 || _this$store$discount8.setDiscountList(result.discountList);
423
+ }
424
+ }
425
+
426
+ // ─── 促销/赠品 ──────────────────────────────────────
427
+
428
+ /**
429
+ * 注入促销评估器。
430
+ *
431
+ * @example
432
+ * order.setPromotionEvaluator(appHelper.utils.promotionEvaluator);
433
+ */
434
+ }, {
435
+ key: "setPromotionEvaluator",
436
+ value: function setPromotionEvaluator(evaluator) {
437
+ this.promotionEvaluator = evaluator || null;
438
+ }
439
+
440
+ /**
441
+ * 注入赠品选择 resolver。OS 需要补赠品时会 await 调用 resolver;缺省时跳过新增并 console.warn。
442
+ *
443
+ * @example
444
+ * order.setGiftSelectResolver(async (ctx) => {
445
+ * // SDK 内部决定弹窗 or 自动选第一项,返回完整 OrderProduct[]
446
+ * return giftSelectBridge.request(ctx);
447
+ * });
448
+ */
449
+ }, {
450
+ key: "setGiftSelectResolver",
451
+ value: function setGiftSelectResolver(resolver) {
452
+ this.giftSelectResolver = resolver || null;
453
+ }
454
+
455
+ /**
456
+ * 为商品目录追加促销标签,供上层 Sales 门面复用。
457
+ *
458
+ * @example
459
+ * const products = order.appendPromotionTags(catalogProducts);
460
+ */
461
+ }, {
462
+ key: "appendPromotionTags",
463
+ value: function appendPromotionTags(products) {
464
+ return _appendPromotionTags(products, this.promotionEvaluator);
465
+ }
466
+
467
+ /**
468
+ * 应用购物车促销:计算 → 差异化赠品 → 写回 tempOrder.products → emit onPromotionApplied。
469
+ *
470
+ * 调用时机:写路径(add/update/remove/clear/setCustomer)末尾自动触发;外部一般无需手动调。
471
+ *
472
+ * 关键约束:
473
+ * - 不调用任何公开 CRUD API(如 removeProductFromOrder),全部内部 mutate tempOrder.products,避免事件风暴;
474
+ * - 用 `isApplyingPromotion` 防递归;
475
+ * - 多选项赠品依赖 giftSelectResolver,未注入则跳过且 console.warn;
476
+ * - 不主动调用 applyDiscount / recalculateSummary,调用方负责跟进。
477
+ */
478
+ }, {
479
+ key: "applyPromotion",
480
+ value: (function () {
481
+ var _applyPromotion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
482
+ var _this2 = this;
483
+ var tempOrder, result, removeSet, _iterator, _step, reduce, _iterator4, _step4, _loop2, _iterator2, _step2, _loop, payload;
484
+ return _regeneratorRuntime().wrap(function _callee4$(_context6) {
485
+ while (1) switch (_context6.prev = _context6.next) {
486
+ case 0:
487
+ if (!this.isApplyingPromotion) {
488
+ _context6.next = 2;
489
+ break;
490
+ }
491
+ return _context6.abrupt("return");
492
+ case 2:
493
+ if (this.promotionEvaluator) {
494
+ _context6.next = 4;
495
+ break;
496
+ }
497
+ return _context6.abrupt("return");
498
+ case 4:
499
+ tempOrder = this.store.tempOrder;
500
+ if (tempOrder) {
501
+ _context6.next = 7;
502
+ break;
503
+ }
504
+ return _context6.abrupt("return");
505
+ case 7:
506
+ this.isApplyingPromotion = true;
507
+ _context6.prev = 8;
508
+ result = processCartPromotion(tempOrder.products, this.promotionEvaluator); // step 1: toRemove —— 直接过滤
509
+ if (result.giftActions.toRemove.length > 0) {
510
+ removeSet = new Set(result.giftActions.toRemove.map(String));
511
+ result.products = result.products.filter(function (p) {
512
+ var uid = getPromotionUid(p);
513
+ return uid ? !removeSet.has(String(uid)) : true;
514
+ });
515
+ }
516
+
517
+ // step 2: toReduce —— 调整数量
518
+ _iterator = _createForOfIteratorHelper(result.giftActions.toReduce);
519
+ _context6.prev = 12;
520
+ _iterator.s();
521
+ case 14:
522
+ if ((_step = _iterator.n()).done) {
523
+ _context6.next = 34;
524
+ break;
525
+ }
526
+ reduce = _step.value;
527
+ _iterator4 = _createForOfIteratorHelper(reduce.items);
528
+ _context6.prev = 17;
529
+ _loop2 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop2() {
530
+ var item, product;
531
+ return _regeneratorRuntime().wrap(function _loop2$(_context5) {
532
+ while (1) switch (_context5.prev = _context5.next) {
533
+ case 0:
534
+ item = _step4.value;
535
+ product = result.products.find(function (p) {
536
+ return getPromotionUid(p) === item.uid;
537
+ });
538
+ if (product) {
539
+ product.num = item.newQuantity;
540
+ }
541
+ case 3:
542
+ case "end":
543
+ return _context5.stop();
544
+ }
545
+ }, _loop2);
546
+ });
547
+ _iterator4.s();
548
+ case 20:
549
+ if ((_step4 = _iterator4.n()).done) {
550
+ _context6.next = 24;
551
+ break;
552
+ }
553
+ return _context6.delegateYield(_loop2(), "t0", 22);
554
+ case 22:
555
+ _context6.next = 20;
556
+ break;
557
+ case 24:
558
+ _context6.next = 29;
559
+ break;
560
+ case 26:
561
+ _context6.prev = 26;
562
+ _context6.t1 = _context6["catch"](17);
563
+ _iterator4.e(_context6.t1);
564
+ case 29:
565
+ _context6.prev = 29;
566
+ _iterator4.f();
567
+ return _context6.finish(29);
568
+ case 32:
569
+ _context6.next = 14;
570
+ break;
571
+ case 34:
572
+ _context6.next = 39;
573
+ break;
574
+ case 36:
575
+ _context6.prev = 36;
576
+ _context6.t2 = _context6["catch"](12);
577
+ _iterator.e(_context6.t2);
578
+ case 39:
579
+ _context6.prev = 39;
580
+ _iterator.f();
581
+ return _context6.finish(39);
582
+ case 42:
583
+ if (!(result.giftActions.toAdd.length > 0)) {
584
+ _context6.next = 65;
585
+ break;
586
+ }
587
+ if (this.giftSelectResolver) {
588
+ _context6.next = 47;
589
+ break;
590
+ }
591
+ if (result.giftActions.toAdd.some(function (g) {
592
+ return g.giftOptions.length > 1;
593
+ })) {
594
+ // 多选项必须走 resolver;单选项也建议走(避免 OS 自造 stub),但允许跳过
595
+ console.warn('[OrderModule] giftSelectResolver not set, skip applying gifts', result.giftActions.toAdd);
596
+ } else {
597
+ console.warn('[OrderModule] giftSelectResolver not set, skip applying single-option gifts', result.giftActions.toAdd);
598
+ }
599
+ _context6.next = 65;
600
+ break;
601
+ case 47:
602
+ _iterator2 = _createForOfIteratorHelper(result.giftActions.toAdd);
603
+ _context6.prev = 48;
604
+ _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
605
+ var addAction, sameStrategy, giftProducts, _iterator3, _step3, gp;
606
+ return _regeneratorRuntime().wrap(function _loop$(_context4) {
607
+ while (1) switch (_context4.prev = _context4.next) {
608
+ case 0:
609
+ addAction = _step2.value;
610
+ if (!(addAction.giftOptions.length === 1)) {
611
+ _context4.next = 6;
612
+ break;
613
+ }
614
+ sameStrategy = result.products.find(function (p) {
615
+ var _p$metadata;
616
+ 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;
617
+ });
618
+ if (!sameStrategy) {
619
+ _context4.next = 6;
620
+ break;
621
+ }
622
+ sameStrategy.num = (Number(sameStrategy.num) || 0) + (addAction.giftCount || 1);
623
+ return _context4.abrupt("return", 1);
624
+ case 6:
625
+ _context4.prev = 6;
626
+ _context4.next = 9;
627
+ return _this2.giftSelectResolver({
628
+ strategyId: addAction.strategyId,
629
+ strategyName: addAction.strategyName,
630
+ giftCount: addAction.giftCount,
631
+ giftOptions: addAction.giftOptions,
632
+ sourceProductIds: addAction.sourceProductIds
633
+ });
634
+ case 9:
635
+ giftProducts = _context4.sent;
636
+ if (!(Array.isArray(giftProducts) && giftProducts.length > 0)) {
637
+ _context4.next = 29;
638
+ break;
639
+ }
640
+ _iterator3 = _createForOfIteratorHelper(giftProducts);
641
+ _context4.prev = 12;
642
+ _iterator3.s();
643
+ case 14:
644
+ if ((_step3 = _iterator3.n()).done) {
645
+ _context4.next = 21;
646
+ break;
647
+ }
648
+ gp = _step3.value;
649
+ if (gp) {
650
+ _context4.next = 18;
651
+ break;
652
+ }
653
+ return _context4.abrupt("continue", 19);
654
+ case 18:
655
+ // normalize 略过:调用方应保证返回完整 OrderProduct
656
+ result.products.push(gp);
657
+ case 19:
658
+ _context4.next = 14;
659
+ break;
660
+ case 21:
661
+ _context4.next = 26;
662
+ break;
663
+ case 23:
664
+ _context4.prev = 23;
665
+ _context4.t0 = _context4["catch"](12);
666
+ _iterator3.e(_context4.t0);
667
+ case 26:
668
+ _context4.prev = 26;
669
+ _iterator3.f();
670
+ return _context4.finish(26);
671
+ case 29:
672
+ _context4.next = 34;
673
+ break;
674
+ case 31:
675
+ _context4.prev = 31;
676
+ _context4.t1 = _context4["catch"](6);
677
+ // 用户取消 / 选择失败 → 视为放弃本次新增
678
+ console.warn('[OrderModule] giftSelectResolver rejected, skip add gift', addAction.strategyId, _context4.t1);
679
+ case 34:
680
+ case "end":
681
+ return _context4.stop();
682
+ }
683
+ }, _loop, null, [[6, 31], [12, 23, 26, 29]]);
684
+ });
685
+ _iterator2.s();
686
+ case 51:
687
+ if ((_step2 = _iterator2.n()).done) {
688
+ _context6.next = 57;
689
+ break;
690
+ }
691
+ return _context6.delegateYield(_loop(), "t3", 53);
692
+ case 53:
693
+ if (!_context6.t3) {
694
+ _context6.next = 55;
695
+ break;
696
+ }
697
+ return _context6.abrupt("continue", 55);
698
+ case 55:
699
+ _context6.next = 51;
700
+ break;
701
+ case 57:
702
+ _context6.next = 62;
703
+ break;
704
+ case 59:
705
+ _context6.prev = 59;
706
+ _context6.t4 = _context6["catch"](48);
707
+ _iterator2.e(_context6.t4);
708
+ case 62:
709
+ _context6.prev = 62;
710
+ _iterator2.f();
711
+ return _context6.finish(62);
712
+ case 65:
713
+ tempOrder.products = result.products;
714
+ this.lastUnfulfilledPromotions = result.unfulfilledPromotions;
715
+ this.lastGiftActions = result.giftActions;
716
+ payload = {
717
+ unfulfilledPromotions: result.unfulfilledPromotions,
718
+ giftActions: result.giftActions,
719
+ gifts: result.gifts.map(function (g) {
720
+ return {
721
+ strategyId: g.strategyId,
722
+ strategyName: g.strategyName,
723
+ giftCount: g.giftCount,
724
+ giftOptions: g.giftOptions
725
+ };
726
+ }),
727
+ products: tempOrder.products
728
+ };
729
+ this.effectsEmit('onPromotionApplied', payload);
730
+ _context6.next = 75;
731
+ break;
732
+ case 72:
733
+ _context6.prev = 72;
734
+ _context6.t5 = _context6["catch"](8);
735
+ console.error('[OrderModule] applyPromotion failed', _context6.t5);
736
+ case 75:
737
+ _context6.prev = 75;
738
+ this.isApplyingPromotion = false;
739
+ return _context6.finish(75);
740
+ case 78:
741
+ case "end":
742
+ return _context6.stop();
743
+ }
744
+ }, _callee4, this, [[8, 72, 75, 78], [12, 36, 39, 42], [17, 26, 29, 32], [48, 59, 62, 65]]);
745
+ }));
746
+ function applyPromotion() {
747
+ return _applyPromotion.apply(this, arguments);
377
748
  }
749
+ return applyPromotion;
750
+ }() /** 最近一次 applyPromotion 输出的未满足促销列表 */)
751
+ }, {
752
+ key: "getUnfulfilledPromotions",
753
+ value: function getUnfulfilledPromotions() {
754
+ return this.lastUnfulfilledPromotions;
755
+ }
756
+
757
+ /** 最近一次 applyPromotion 输出的赠品操作 diff */
758
+ }, {
759
+ key: "getLastGiftActions",
760
+ value: function getLastGiftActions() {
761
+ return this.lastGiftActions;
378
762
  }
379
763
 
380
764
  // ─── TempOrder: 初始化入口 ───
@@ -383,76 +767,25 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
383
767
  value: function initTempOrder(params) {
384
768
  if (params.cacheId !== undefined) this.cacheId = params.cacheId;
385
769
  if (params.salesSummaryModuleName !== undefined) this.salesSummaryModuleName = params.salesSummaryModuleName;
386
- this.restoreTempOrderFromStorage();
387
770
  }
388
771
 
389
- // ─── TempOrder: localStorage 持久化 ───
772
+ /** @deprecated OrderModule 不再负责 tempOrder localStorage 持久化。 */
390
773
  }, {
391
- key: "getTempOrderStorageKey",
392
- value: function getTempOrderStorageKey() {
393
- if (!this.cacheId) return null;
394
- return "scanOrder:tempOrder:".concat(this.cacheId);
395
- }
774
+ key: "setEnableTempOrderPersist",
775
+ value: function setEnableTempOrderPersist(_enabled) {}
776
+
777
+ /** @deprecated OrderModule 不再负责 tempOrder localStorage 持久化。 */
396
778
  }, {
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
- }
779
+ key: "isTempOrderPersistEnabled",
780
+ value: function isTempOrderPersistEnabled() {
781
+ return false;
448
782
  }
783
+
784
+ /** @deprecated OrderModule 不再负责 tempOrder localStorage 持久化;草稿保存请使用 IndexedDB saveDraft。 */
449
785
  }, {
450
786
  key: "persistTempOrder",
451
787
  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));
788
+ // no-op: OrderModule 的刷新恢复不再依赖 localStorage。
456
789
  }
457
790
 
458
791
  // ─── TempOrder: 创建 & 获取 ───
@@ -509,6 +842,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
509
842
  }
510
843
  return tempOrder.request_unique_idempotency_token;
511
844
  }
845
+ }, {
846
+ key: "buildPaymentSyncIdempotencyToken",
847
+ value: function buildPaymentSyncIdempotencyToken(tempOrder, payments) {
848
+ var baseToken = this.ensureRequestUniqueIdempotencyToken(tempOrder);
849
+ var paidPaymentsCount = (payments || []).filter(function (payment) {
850
+ return String((payment === null || payment === void 0 ? void 0 : payment.status) || '').toLowerCase() === 'paid';
851
+ }).length;
852
+ var paidCount = paidPaymentsCount > 0 ? paidPaymentsCount : payments.length;
853
+ return "".concat(baseToken, "_payment_").concat(paidCount);
854
+ }
512
855
  }, {
513
856
  key: "hasLocalDatabase",
514
857
  value: function hasLocalDatabase() {
@@ -529,48 +872,48 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
529
872
  }, {
530
873
  key: "getLocalOrderByOrderId",
531
874
  value: function () {
532
- var _getLocalOrderByOrderId = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(orderId) {
875
+ var _getLocalOrderByOrderId = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(orderId) {
533
876
  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) {
877
+ return _regeneratorRuntime().wrap(function _callee5$(_context7) {
878
+ while (1) switch (_context7.prev = _context7.next) {
536
879
  case 0:
537
880
  if (!(!this.dbManager || orderId === undefined || orderId === null)) {
538
- _context4.next = 2;
881
+ _context7.next = 2;
539
882
  break;
540
883
  }
541
- return _context4.abrupt("return", null);
884
+ return _context7.abrupt("return", null);
542
885
  case 2:
543
- _context4.prev = 2;
544
- _context4.next = 5;
886
+ _context7.prev = 2;
887
+ _context7.next = 5;
545
888
  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
889
  case 5:
547
- direct = _context4.sent;
890
+ direct = _context7.sent;
548
891
  if (!direct) {
549
- _context4.next = 8;
892
+ _context7.next = 8;
550
893
  break;
551
894
  }
552
- return _context4.abrupt("return", direct);
895
+ return _context7.abrupt("return", direct);
553
896
  case 8:
554
- _context4.next = 10;
897
+ _context7.next = 10;
555
898
  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
899
  case 10:
557
- orders = _context4.sent;
558
- return _context4.abrupt("return", (orders || []).find(function (order) {
900
+ orders = _context7.sent;
901
+ return _context7.abrupt("return", (orders || []).find(function (order) {
559
902
  return String(order === null || order === void 0 ? void 0 : order.order_id) === String(orderId);
560
903
  }) || null);
561
904
  case 14:
562
- _context4.prev = 14;
563
- _context4.t0 = _context4["catch"](2);
905
+ _context7.prev = 14;
906
+ _context7.t0 = _context7["catch"](2);
564
907
  this.logWarning('getLocalOrderByOrderId failed', {
565
908
  orderId: orderId,
566
- error: _context4.t0 instanceof Error ? _context4.t0.message : String(_context4.t0)
909
+ error: _context7.t0 instanceof Error ? _context7.t0.message : String(_context7.t0)
567
910
  });
568
- return _context4.abrupt("return", null);
911
+ return _context7.abrupt("return", null);
569
912
  case 18:
570
913
  case "end":
571
- return _context4.stop();
914
+ return _context7.stop();
572
915
  }
573
- }, _callee4, this, [[2, 14]]);
916
+ }, _callee5, this, [[2, 14]]);
574
917
  }));
575
918
  function getLocalOrderByOrderId(_x6) {
576
919
  return _getLocalOrderByOrderId.apply(this, arguments);
@@ -580,48 +923,48 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
580
923
  }, {
581
924
  key: "getLocalOrderByOrderNumber",
582
925
  value: function () {
583
- var _getLocalOrderByOrderNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(orderNumber) {
926
+ var _getLocalOrderByOrderNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(orderNumber) {
584
927
  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) {
928
+ return _regeneratorRuntime().wrap(function _callee6$(_context8) {
929
+ while (1) switch (_context8.prev = _context8.next) {
587
930
  case 0:
588
931
  if (!(!this.dbManager || !orderNumber)) {
589
- _context5.next = 2;
932
+ _context8.next = 2;
590
933
  break;
591
934
  }
592
- return _context5.abrupt("return", null);
935
+ return _context8.abrupt("return", null);
593
936
  case 2:
594
- _context5.prev = 2;
595
- _context5.next = 5;
937
+ _context8.prev = 2;
938
+ _context8.next = 5;
596
939
  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
940
  case 5:
598
- direct = _context5.sent;
941
+ direct = _context8.sent;
599
942
  if (!direct) {
600
- _context5.next = 8;
943
+ _context8.next = 8;
601
944
  break;
602
945
  }
603
- return _context5.abrupt("return", direct);
946
+ return _context8.abrupt("return", direct);
604
947
  case 8:
605
- _context5.next = 10;
948
+ _context8.next = 10;
606
949
  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
950
  case 10:
608
- orders = _context5.sent;
609
- return _context5.abrupt("return", (orders || []).find(function (order) {
951
+ orders = _context8.sent;
952
+ return _context8.abrupt("return", (orders || []).find(function (order) {
610
953
  return String(order === null || order === void 0 ? void 0 : order.order_number) === String(orderNumber);
611
954
  }) || null);
612
955
  case 14:
613
- _context5.prev = 14;
614
- _context5.t0 = _context5["catch"](2);
956
+ _context8.prev = 14;
957
+ _context8.t0 = _context8["catch"](2);
615
958
  this.logWarning('getLocalOrderByOrderNumber failed', {
616
959
  orderNumber: orderNumber,
617
- error: _context5.t0 instanceof Error ? _context5.t0.message : String(_context5.t0)
960
+ error: _context8.t0 instanceof Error ? _context8.t0.message : String(_context8.t0)
618
961
  });
619
- return _context5.abrupt("return", null);
962
+ return _context8.abrupt("return", null);
620
963
  case 18:
621
964
  case "end":
622
- return _context5.stop();
965
+ return _context8.stop();
623
966
  }
624
- }, _callee5, this, [[2, 14]]);
967
+ }, _callee6, this, [[2, 14]]);
625
968
  }));
626
969
  function getLocalOrderByOrderNumber(_x7) {
627
970
  return _getLocalOrderByOrderNumber.apply(this, arguments);
@@ -631,48 +974,48 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
631
974
  }, {
632
975
  key: "getLocalOrderByExternalSaleNumber",
633
976
  value: function () {
634
- var _getLocalOrderByExternalSaleNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(externalSaleNumber) {
977
+ var _getLocalOrderByExternalSaleNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(externalSaleNumber) {
635
978
  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) {
979
+ return _regeneratorRuntime().wrap(function _callee7$(_context9) {
980
+ while (1) switch (_context9.prev = _context9.next) {
638
981
  case 0:
639
982
  if (!(!this.dbManager || !externalSaleNumber)) {
640
- _context6.next = 2;
983
+ _context9.next = 2;
641
984
  break;
642
985
  }
643
- return _context6.abrupt("return", null);
986
+ return _context9.abrupt("return", null);
644
987
  case 2:
645
- _context6.prev = 2;
646
- _context6.next = 5;
988
+ _context9.prev = 2;
989
+ _context9.next = 5;
647
990
  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
991
  case 5:
649
- direct = _context6.sent;
992
+ direct = _context9.sent;
650
993
  if (!direct) {
651
- _context6.next = 8;
994
+ _context9.next = 8;
652
995
  break;
653
996
  }
654
- return _context6.abrupt("return", direct);
997
+ return _context9.abrupt("return", direct);
655
998
  case 8:
656
- _context6.next = 10;
999
+ _context9.next = 10;
657
1000
  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
1001
  case 10:
659
- orders = _context6.sent;
660
- return _context6.abrupt("return", (orders || []).find(function (order) {
1002
+ orders = _context9.sent;
1003
+ return _context9.abrupt("return", (orders || []).find(function (order) {
661
1004
  return String(order === null || order === void 0 ? void 0 : order.external_sale_number) === String(externalSaleNumber);
662
1005
  }) || null);
663
1006
  case 14:
664
- _context6.prev = 14;
665
- _context6.t0 = _context6["catch"](2);
1007
+ _context9.prev = 14;
1008
+ _context9.t0 = _context9["catch"](2);
666
1009
  this.logWarning('getLocalOrderByExternalSaleNumber failed', {
667
1010
  externalSaleNumber: externalSaleNumber,
668
- error: _context6.t0 instanceof Error ? _context6.t0.message : String(_context6.t0)
1011
+ error: _context9.t0 instanceof Error ? _context9.t0.message : String(_context9.t0)
669
1012
  });
670
- return _context6.abrupt("return", null);
1013
+ return _context9.abrupt("return", null);
671
1014
  case 18:
672
1015
  case "end":
673
- return _context6.stop();
1016
+ return _context9.stop();
674
1017
  }
675
- }, _callee6, this, [[2, 14]]);
1018
+ }, _callee7, this, [[2, 14]]);
676
1019
  }));
677
1020
  function getLocalOrderByExternalSaleNumber(_x8) {
678
1021
  return _getLocalOrderByExternalSaleNumber.apply(this, arguments);
@@ -682,58 +1025,63 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
682
1025
  }, {
683
1026
  key: "saveDraft",
684
1027
  value: function () {
685
- var _saveDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
1028
+ var _saveDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
686
1029
  var tempOrder, record, _this$dbManager$updat, _this$dbManager7;
687
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
688
- while (1) switch (_context7.prev = _context7.next) {
1030
+ return _regeneratorRuntime().wrap(function _callee8$(_context10) {
1031
+ while (1) switch (_context10.prev = _context10.next) {
689
1032
  case 0:
690
1033
  if (this.dbManager) {
691
- _context7.next = 2;
1034
+ _context10.next = 2;
692
1035
  break;
693
1036
  }
694
- return _context7.abrupt("return");
1037
+ return _context10.abrupt("return");
695
1038
  case 2:
696
1039
  tempOrder = this.ensureTempOrder();
697
1040
  record = this.buildLocalOrderRecord(tempOrder);
698
- _context7.prev = 4;
699
- _context7.next = 7;
1041
+ _context10.prev = 4;
1042
+ _context10.next = 7;
700
1043
  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
1044
  case 7:
702
- _context7.next = 12;
1045
+ _context10.next = 12;
703
1046
  break;
704
1047
  case 9:
705
- _context7.prev = 9;
706
- _context7.t0 = _context7["catch"](4);
1048
+ _context10.prev = 9;
1049
+ _context10.t0 = _context10["catch"](4);
707
1050
  this.logWarning('saveDraft failed', {
708
1051
  externalSaleNumber: tempOrder.external_sale_number,
709
1052
  orderNumber: tempOrder.order_number,
710
1053
  orderId: tempOrder.order_id,
711
- error: _context7.t0 instanceof Error ? _context7.t0.message : String(_context7.t0)
1054
+ error: _context10.t0 instanceof Error ? _context10.t0.message : String(_context10.t0)
712
1055
  });
713
1056
  case 12:
714
1057
  case "end":
715
- return _context7.stop();
1058
+ return _context10.stop();
716
1059
  }
717
- }, _callee7, this, [[4, 9]]);
1060
+ }, _callee8, this, [[4, 9]]);
718
1061
  }));
719
1062
  function saveDraft() {
720
1063
  return _saveDraft.apply(this, arguments);
721
1064
  }
722
1065
  return saveDraft;
723
1066
  }()
1067
+ }, {
1068
+ key: "saveDraftInBackground",
1069
+ value: function saveDraftInBackground() {
1070
+ void this.saveDraft();
1071
+ }
724
1072
  }, {
725
1073
  key: "hydrateTempOrderFromLocalRecord",
726
1074
  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) {
1075
+ var _hydrateTempOrderFromLocalRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(record) {
1076
+ return _regeneratorRuntime().wrap(function _callee9$(_context11) {
1077
+ while (1) switch (_context11.prev = _context11.next) {
730
1078
  case 0:
731
- return _context8.abrupt("return", this.hydrateTempOrderFromRecord(record));
1079
+ return _context11.abrupt("return", this.hydrateTempOrderFromRecord(record));
732
1080
  case 1:
733
1081
  case "end":
734
- return _context8.stop();
1082
+ return _context11.stop();
735
1083
  }
736
- }, _callee8, this);
1084
+ }, _callee9, this);
737
1085
  }));
738
1086
  function hydrateTempOrderFromLocalRecord(_x9) {
739
1087
  return _hydrateTempOrderFromLocalRecord.apply(this, arguments);
@@ -760,14 +1108,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
760
1108
  }, {
761
1109
  key: "calculatePaidPaymentSummary",
762
1110
  value: function calculatePaidPaymentSummary(payments) {
763
- var _this2 = this;
1111
+ var _this3 = this;
764
1112
  return (payments || []).reduce(function (summary, payment) {
765
1113
  var paymentRecord = payment;
766
1114
  if ((paymentRecord === null || paymentRecord === void 0 ? void 0 : paymentRecord.status) !== 'paid') return summary;
767
1115
  return {
768
1116
  customerPaidAmount: summary.customerPaidAmount.plus(paymentRecord.amount || 0),
769
1117
  orderPaidAmount: summary.orderPaidAmount.plus(paymentRecord.origin_amount || 0),
770
- payServiceChargeAmount: summary.payServiceChargeAmount.plus(_this2.calculatePaymentServiceFee(paymentRecord))
1118
+ payServiceChargeAmount: summary.payServiceChargeAmount.plus(_this3.calculatePaymentServiceFee(paymentRecord))
771
1119
  };
772
1120
  }, {
773
1121
  customerPaidAmount: new Decimal(0),
@@ -786,6 +1134,52 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
786
1134
  var fixedAmount = new Decimal(serviceCharge.amount || 0);
787
1135
  return new Decimal(payment.amount || 0).times(percentage).plus(fixedAmount);
788
1136
  }
1137
+ }, {
1138
+ key: "formatSummaryMetadataMoney",
1139
+ value: function formatSummaryMetadataMoney(value) {
1140
+ if (value === undefined || value === null || value === '') return undefined;
1141
+ if (value instanceof Decimal) return value.toFixed(2);
1142
+ return new Decimal(String(value || 0)).toFixed(2);
1143
+ }
1144
+ }, {
1145
+ key: "syncSummaryProductMetadata",
1146
+ value: function syncSummaryProductMetadata(products) {
1147
+ var moneyKeys = ['main_product_attached_bundle_surcharge_fee', 'main_product_attached_bundle_tax_fee', 'surcharge_rounding_remainder', 'tax_fee_rounding_remainder'];
1148
+ var _iterator5 = _createForOfIteratorHelper(products || []),
1149
+ _step5;
1150
+ try {
1151
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
1152
+ var product = _step5.value;
1153
+ var productRecord = product;
1154
+ var metadata = productRecord.metadata && _typeof(productRecord.metadata) === 'object' ? _objectSpread({}, productRecord.metadata) : {};
1155
+ var hasMetadataPatch = false;
1156
+ var _iterator6 = _createForOfIteratorHelper(moneyKeys),
1157
+ _step6;
1158
+ try {
1159
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
1160
+ var key = _step6.value;
1161
+ var value = this.formatSummaryMetadataMoney(productRecord[key]);
1162
+ if (value === undefined) continue;
1163
+ metadata[key] = value;
1164
+ hasMetadataPatch = true;
1165
+ }
1166
+ } catch (err) {
1167
+ _iterator6.e(err);
1168
+ } finally {
1169
+ _iterator6.f();
1170
+ }
1171
+ if (Array.isArray(productRecord.relation_surcharge_ids)) {
1172
+ metadata.relation_surcharge_ids = productRecord.relation_surcharge_ids;
1173
+ hasMetadataPatch = true;
1174
+ }
1175
+ if (hasMetadataPatch) productRecord.metadata = metadata;
1176
+ }
1177
+ } catch (err) {
1178
+ _iterator5.e(err);
1179
+ } finally {
1180
+ _iterator5.f();
1181
+ }
1182
+ }
789
1183
  }, {
790
1184
  key: "getPaymentTargetAmount",
791
1185
  value: function getPaymentTargetAmount() {
@@ -812,11 +1206,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
812
1206
  }, {
813
1207
  key: "restoreOrder",
814
1208
  value: function restoreOrder() {
1209
+ var _this$store$discount9, _this$store$discount10;
815
1210
  var freshTempOrder = this.createDefaultTempOrderInstance();
816
1211
  this.ensureExternalSaleNumber(freshTempOrder);
817
1212
  this.store.tempOrder = freshTempOrder;
818
1213
  this.store.summary = createEmptySummary();
819
1214
  this.store.lastOrderInfo = undefined;
1215
+ this.store.syncState = undefined;
1216
+ void ((_this$store$discount9 = this.store.discount) === null || _this$store$discount9 === void 0 ? void 0 : _this$store$discount9.setOriginalDiscountList([]));
1217
+ void ((_this$store$discount10 = this.store.discount) === null || _this$store$discount10 === void 0 ? void 0 : _this$store$discount10.setDiscountList([]));
820
1218
  this.persistTempOrder();
821
1219
  return freshTempOrder;
822
1220
  }
@@ -825,6 +1223,60 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
825
1223
  value: function getTempOrder() {
826
1224
  return this.store.tempOrder;
827
1225
  }
1226
+ }, {
1227
+ key: "replaceTempOrder",
1228
+ value: function () {
1229
+ var _replaceTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(tempOrder, options) {
1230
+ var nextTempOrder;
1231
+ return _regeneratorRuntime().wrap(function _callee10$(_context12) {
1232
+ while (1) switch (_context12.prev = _context12.next) {
1233
+ case 0:
1234
+ if (isTempOrder(tempOrder)) {
1235
+ _context12.next = 2;
1236
+ break;
1237
+ }
1238
+ throw new Error('无效的 tempOrder 数据');
1239
+ case 2:
1240
+ nextTempOrder = this.normalizeTempOrderForRuntime(cloneDeep(tempOrder), {
1241
+ ensureIdentity: false
1242
+ });
1243
+ this.store.tempOrder = nextTempOrder;
1244
+ if (!((options === null || options === void 0 ? void 0 : options.recalculateSummary) !== false)) {
1245
+ _context12.next = 9;
1246
+ break;
1247
+ }
1248
+ _context12.next = 7;
1249
+ return this.recalculateSummary({
1250
+ createIfMissing: false
1251
+ });
1252
+ case 7:
1253
+ _context12.next = 10;
1254
+ break;
1255
+ case 9:
1256
+ this.store.summary = createEmptySummary();
1257
+ case 10:
1258
+ if ((options === null || options === void 0 ? void 0 : options.persist) !== false) {
1259
+ this.persistTempOrder();
1260
+ }
1261
+ if (!(options !== null && options !== void 0 && options.saveDraft)) {
1262
+ _context12.next = 14;
1263
+ break;
1264
+ }
1265
+ _context12.next = 14;
1266
+ return this.saveDraft();
1267
+ case 14:
1268
+ return _context12.abrupt("return", nextTempOrder);
1269
+ case 15:
1270
+ case "end":
1271
+ return _context12.stop();
1272
+ }
1273
+ }, _callee10, this);
1274
+ }));
1275
+ function replaceTempOrder(_x10, _x11) {
1276
+ return _replaceTempOrder.apply(this, arguments);
1277
+ }
1278
+ return replaceTempOrder;
1279
+ }()
828
1280
  }, {
829
1281
  key: "getOrderIdentity",
830
1282
  value: function getOrderIdentity() {
@@ -903,28 +1355,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
903
1355
  }, {
904
1356
  key: "addNewOrder",
905
1357
  value: function () {
906
- var _addNewOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
1358
+ var _addNewOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
907
1359
  var tempOrder;
908
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
909
- while (1) switch (_context9.prev = _context9.next) {
1360
+ return _regeneratorRuntime().wrap(function _callee11$(_context13) {
1361
+ while (1) switch (_context13.prev = _context13.next) {
910
1362
  case 0:
911
1363
  tempOrder = this.ensureTempOrder();
912
1364
  this.ensureExternalSaleNumber(tempOrder);
913
- _context9.next = 4;
1365
+ _context13.next = 4;
914
1366
  return this.recalculateSummary({
915
1367
  createIfMissing: true
916
1368
  });
917
1369
  case 4:
918
1370
  this.persistTempOrder();
919
- _context9.next = 7;
1371
+ _context13.next = 7;
920
1372
  return this.saveDraft();
921
1373
  case 7:
922
- return _context9.abrupt("return", tempOrder);
1374
+ return _context13.abrupt("return", tempOrder);
923
1375
  case 8:
924
1376
  case "end":
925
- return _context9.stop();
1377
+ return _context13.stop();
926
1378
  }
927
- }, _callee9, this);
1379
+ }, _callee11, this);
928
1380
  }));
929
1381
  function addNewOrder() {
930
1382
  return _addNewOrder.apply(this, arguments);
@@ -1000,6 +1452,38 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1000
1452
  })
1001
1453
  };
1002
1454
  }
1455
+ }, {
1456
+ key: "getBookingUniqueIdentificationNumber",
1457
+ value: function getBookingUniqueIdentificationNumber(booking) {
1458
+ var _booking$metadata;
1459
+ var uid = booking === null || booking === void 0 || (_booking$metadata = booking.metadata) === null || _booking$metadata === void 0 ? void 0 : _booking$metadata.unique_identification_number;
1460
+ if (uid === undefined || uid === null || uid === '') return null;
1461
+ return String(uid);
1462
+ }
1463
+ }, {
1464
+ key: "findBookingIndexByUniqueIdentificationNumber",
1465
+ value: function findBookingIndexByUniqueIdentificationNumber(tempOrder, uniqueIdentificationNumber) {
1466
+ var _this4 = this;
1467
+ return (tempOrder.bookings || []).findIndex(function (booking) {
1468
+ return _this4.getBookingUniqueIdentificationNumber(booking) === uniqueIdentificationNumber;
1469
+ });
1470
+ }
1471
+ }, {
1472
+ key: "removeLinkedBookingsForProduct",
1473
+ value: function removeLinkedBookingsForProduct(tempOrder, product) {
1474
+ var _product$metadata4,
1475
+ _product$metadata5,
1476
+ _this5 = this;
1477
+ 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);
1478
+ 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);
1479
+ if (!productUid && !bookingUid) return;
1480
+ tempOrder.bookings = (tempOrder.bookings || []).filter(function (booking) {
1481
+ var currentBookingUid = _this5.getBookingUniqueIdentificationNumber(booking);
1482
+ if (bookingUid && currentBookingUid === String(bookingUid)) return false;
1483
+ if (productUid && String((booking === null || booking === void 0 ? void 0 : booking.product_uid) || '') === String(productUid)) return false;
1484
+ return true;
1485
+ });
1486
+ }
1003
1487
 
1004
1488
  // ─── TempOrder: 金额汇总 ───
1005
1489
  }, {
@@ -1011,23 +1495,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1011
1495
  }, {
1012
1496
  key: "recalculateSummary",
1013
1497
  value: function () {
1014
- var _recalculateSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(options) {
1498
+ var _recalculateSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(options) {
1015
1499
  var tempOrder, salesSummary, existedSummary, paidPaymentSummary, emptySummary, salesSummaryResult, summary;
1016
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1017
- while (1) switch (_context10.prev = _context10.next) {
1500
+ return _regeneratorRuntime().wrap(function _callee12$(_context14) {
1501
+ while (1) switch (_context14.prev = _context14.next) {
1018
1502
  case 0:
1019
1503
  tempOrder = options !== null && options !== void 0 && options.createIfMissing ? this.ensureTempOrder() : this.store.tempOrder;
1020
1504
  if (tempOrder) {
1021
- _context10.next = 3;
1505
+ _context14.next = 3;
1022
1506
  break;
1023
1507
  }
1024
- return _context10.abrupt("return", null);
1508
+ return _context14.abrupt("return", null);
1025
1509
  case 3:
1026
1510
  salesSummary = this.getSalesSummary();
1027
1511
  existedSummary = this.store.summary || createEmptySummary();
1028
1512
  paidPaymentSummary = this.calculatePaidPaymentSummary(tempOrder.payments || []);
1029
1513
  if (salesSummary) {
1030
- _context10.next = 11;
1514
+ _context14.next = 11;
1031
1515
  break;
1032
1516
  }
1033
1517
  emptySummary = _objectSpread(_objectSpread({}, createEmptySummary()), {}, {
@@ -1038,16 +1522,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1038
1522
  });
1039
1523
  this.store.summary = emptySummary;
1040
1524
  tempOrder.surcharge_fee = emptySummary.surcharge_fee;
1041
- return _context10.abrupt("return", this.store.summary);
1525
+ return _context14.abrupt("return", this.store.summary);
1042
1526
  case 11:
1043
- _context10.next = 13;
1527
+ _context14.next = 13;
1044
1528
  return salesSummary.getSummary({
1045
1529
  products: tempOrder.products,
1046
1530
  isPriceIncludeTax: tempOrder.is_price_include_tax,
1047
1531
  shopDiscount: tempOrder.shop_discount
1048
1532
  });
1049
1533
  case 13:
1050
- salesSummaryResult = _context10.sent;
1534
+ salesSummaryResult = _context14.sent;
1535
+ this.syncSummaryProductMetadata(tempOrder.products || []);
1051
1536
  summary = _objectSpread(_objectSpread({}, salesSummaryResult), {}, {
1052
1537
  total_refund_amount: existedSummary.total_refund_amount || '0.00',
1053
1538
  customer_paid_amount: paidPaymentSummary.customerPaidAmount.toFixed(2),
@@ -1065,14 +1550,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1065
1550
  tempOrder.surcharges = summary.surcharges || [];
1066
1551
  tempOrder.deposit_amount = summary.deposit_amount || '0.00';
1067
1552
  tempOrder.is_deposit = summary.deposit_amount !== '0.00' ? 1 : 0;
1068
- return _context10.abrupt("return", this.store.summary);
1069
- case 23:
1553
+ return _context14.abrupt("return", this.store.summary);
1554
+ case 24:
1070
1555
  case "end":
1071
- return _context10.stop();
1556
+ return _context14.stop();
1072
1557
  }
1073
- }, _callee10, this);
1558
+ }, _callee12, this);
1074
1559
  }));
1075
- function recalculateSummary(_x10) {
1560
+ function recalculateSummary(_x12) {
1076
1561
  return _recalculateSummary.apply(this, arguments);
1077
1562
  }
1078
1563
  return recalculateSummary;
@@ -1080,30 +1565,30 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1080
1565
  }, {
1081
1566
  key: "getOrderSummary",
1082
1567
  value: function () {
1083
- var _getOrderSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
1568
+ var _getOrderSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
1084
1569
  var summary;
1085
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1086
- while (1) switch (_context11.prev = _context11.next) {
1570
+ return _regeneratorRuntime().wrap(function _callee13$(_context15) {
1571
+ while (1) switch (_context15.prev = _context15.next) {
1087
1572
  case 0:
1088
- _context11.next = 2;
1573
+ _context15.next = 2;
1089
1574
  return this.recalculateSummary({
1090
1575
  createIfMissing: true
1091
1576
  });
1092
1577
  case 2:
1093
- summary = _context11.sent;
1578
+ summary = _context15.sent;
1094
1579
  if (summary) {
1095
- _context11.next = 5;
1580
+ _context15.next = 5;
1096
1581
  break;
1097
1582
  }
1098
- return _context11.abrupt("return", createEmptySummary());
1583
+ return _context15.abrupt("return", createEmptySummary());
1099
1584
  case 5:
1100
1585
  this.persistTempOrder();
1101
- return _context11.abrupt("return", summary);
1586
+ return _context15.abrupt("return", summary);
1102
1587
  case 7:
1103
1588
  case "end":
1104
- return _context11.stop();
1589
+ return _context15.stop();
1105
1590
  }
1106
- }, _callee11, this);
1591
+ }, _callee13, this);
1107
1592
  }));
1108
1593
  function getOrderSummary() {
1109
1594
  return _getOrderSummary.apply(this, arguments);
@@ -1113,16 +1598,46 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1113
1598
  }, {
1114
1599
  key: "updateTempOrderNote",
1115
1600
  value: function updateTempOrderNote(note) {
1601
+ var sync = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1116
1602
  var tempOrder = this.ensureTempOrder();
1117
1603
  tempOrder.note = String(note || '');
1118
1604
  this.persistTempOrder();
1605
+ if (sync) {
1606
+ var orderId = tempOrder.order_id;
1607
+ if (!orderId) return tempOrder.note;
1608
+ return this.syncTempOrderNoteToRemote(orderId, tempOrder.note);
1609
+ }
1119
1610
  return tempOrder.note;
1120
1611
  }
1612
+ }, {
1613
+ key: "syncTempOrderNoteToRemote",
1614
+ value: function () {
1615
+ var _syncTempOrderNoteToRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(orderId, note) {
1616
+ return _regeneratorRuntime().wrap(function _callee14$(_context16) {
1617
+ while (1) switch (_context16.prev = _context16.next) {
1618
+ case 0:
1619
+ _context16.next = 2;
1620
+ return this.request.put("/order/order/".concat(orderId, "/note"), {
1621
+ note: note
1622
+ });
1623
+ case 2:
1624
+ return _context16.abrupt("return", note);
1625
+ case 3:
1626
+ case "end":
1627
+ return _context16.stop();
1628
+ }
1629
+ }, _callee14, this);
1630
+ }));
1631
+ function syncTempOrderNoteToRemote(_x13, _x14) {
1632
+ return _syncTempOrderNoteToRemote.apply(this, arguments);
1633
+ }
1634
+ return syncTempOrderNoteToRemote;
1635
+ }()
1121
1636
  }, {
1122
1637
  key: "getTempOrderNote",
1123
1638
  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) || '';
1639
+ var _this$store$tempOrder3;
1640
+ return ((_this$store$tempOrder3 = this.store.tempOrder) === null || _this$store$tempOrder3 === void 0 ? void 0 : _this$store$tempOrder3.note) || '';
1126
1641
  }
1127
1642
  }, {
1128
1643
  key: "updateTempOrderShopDiscount",
@@ -1149,25 +1664,51 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1149
1664
  this.persistTempOrder();
1150
1665
  return tempOrder.contacts_info;
1151
1666
  }
1667
+ }, {
1668
+ key: "buildTempOrderCustomer",
1669
+ value: function buildTempOrderCustomer(params) {
1670
+ var _ref8, _ref9, _ref10, _source$name, _ref11, _ref12, _ref13, _source$customer_name, _source$id, _source$customer_id, _ref14, _source$country_calli, _source$phone, _source$email;
1671
+ if (!params.customerId) return null;
1672
+ var source = params.source ? cloneDeep(params.source) : {};
1673
+ var name = (_ref8 = (_ref9 = (_ref10 = (_source$name = source.name) !== null && _source$name !== void 0 ? _source$name : source.display_name) !== null && _ref10 !== void 0 ? _ref10 : source.customerName) !== null && _ref9 !== void 0 ? _ref9 : source.customer_name) !== null && _ref8 !== void 0 ? _ref8 : params.customerName;
1674
+ var customerName = (_ref11 = (_ref12 = (_ref13 = (_source$customer_name = source.customer_name) !== null && _source$customer_name !== void 0 ? _source$customer_name : source.customerName) !== null && _ref13 !== void 0 ? _ref13 : source.display_name) !== null && _ref12 !== void 0 ? _ref12 : source.name) !== null && _ref11 !== void 0 ? _ref11 : params.customerName;
1675
+ return _objectSpread(_objectSpread({}, source), {}, {
1676
+ id: (_source$id = source.id) !== null && _source$id !== void 0 ? _source$id : params.customerId,
1677
+ customer_id: (_source$customer_id = source.customer_id) !== null && _source$customer_id !== void 0 ? _source$customer_id : params.customerId,
1678
+ name: String(name || ''),
1679
+ customer_name: String(customerName || ''),
1680
+ country_calling_code: String((_ref14 = (_source$country_calli = source.country_calling_code) !== null && _source$country_calli !== void 0 ? _source$country_calli : source.countryCallingCode) !== null && _ref14 !== void 0 ? _ref14 : params.countryCallingCode),
1681
+ phone: String((_source$phone = source.phone) !== null && _source$phone !== void 0 ? _source$phone : params.phone),
1682
+ email: String((_source$email = source.email) !== null && _source$email !== void 0 ? _source$email : params.email)
1683
+ });
1684
+ }
1152
1685
 
1153
1686
  /**
1154
1687
  * 更新当前 tempOrder 的客户协议字段。
1155
1688
  *
1156
- * PaymentModal 只需要修改订单里的客户字段;如果外部还有客户模块需要同步,
1689
+ * PaymentModal 只需要修改订单里的客户事实;如果外部还有客户模块需要同步,
1157
1690
  * 应由调用方通过回调处理,不能把外部 UI 状态写进 tempOrder。
1158
1691
  */
1159
1692
  }, {
1160
1693
  key: "updateTempOrderCustomer",
1161
1694
  value: function updateTempOrderCustomer(customer) {
1162
- var _ref8, _ref9, _customer$customer_id, _ref10, _ref11, _ref12, _customer$customer_na, _ref13, _customer$country_cal;
1695
+ var _ref15, _ref16, _customer$customer_id, _ref17, _ref18, _ref19, _customer$customer_na, _ref20, _customer$country_cal;
1163
1696
  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 : '';
1697
+ var customerId = (_ref15 = (_ref16 = (_customer$customer_id = customer.customer_id) !== null && _customer$customer_id !== void 0 ? _customer$customer_id : customer.customerId) !== null && _ref16 !== void 0 ? _ref16 : customer.id) !== null && _ref15 !== void 0 ? _ref15 : null;
1698
+ var customerName = (_ref17 = (_ref18 = (_ref19 = (_customer$customer_na = customer.customer_name) !== null && _customer$customer_na !== void 0 ? _customer$customer_na : customer.customerName) !== null && _ref19 !== void 0 ? _ref19 : customer.display_name) !== null && _ref18 !== void 0 ? _ref18 : customer.name) !== null && _ref17 !== void 0 ? _ref17 : '';
1166
1699
  tempOrder.customer_id = customerId === null || customerId === undefined || customerId === '' ? null : Number(customerId);
1167
1700
  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 : '');
1701
+ tempOrder.country_calling_code = String((_ref20 = (_customer$country_cal = customer.country_calling_code) !== null && _customer$country_cal !== void 0 ? _customer$country_cal : customer.countryCallingCode) !== null && _ref20 !== void 0 ? _ref20 : '');
1169
1702
  tempOrder.phone = String(customer.phone || '');
1170
1703
  tempOrder.email = String(customer.email || '');
1704
+ tempOrder.customer = this.buildTempOrderCustomer({
1705
+ source: customer,
1706
+ customerId: tempOrder.customer_id,
1707
+ customerName: tempOrder.customer_name,
1708
+ countryCallingCode: tempOrder.country_calling_code,
1709
+ phone: tempOrder.phone,
1710
+ email: tempOrder.email
1711
+ });
1171
1712
  this.persistTempOrder();
1172
1713
  return {
1173
1714
  customerId: tempOrder.customer_id,
@@ -1179,28 +1720,43 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1179
1720
  }, {
1180
1721
  key: "setOrderCustomer",
1181
1722
  value: function setOrderCustomer(patch, snapshot) {
1723
+ var _tempOrder$customer_i2, _tempOrder$customer_i3;
1182
1724
  if (!patch) {
1183
1725
  this.clearOrderCustomer();
1184
1726
  return;
1185
1727
  }
1186
1728
  var tempOrder = this.ensureTempOrder();
1729
+ var previousCustomerId = (_tempOrder$customer_i2 = tempOrder.customer_id) !== null && _tempOrder$customer_i2 !== void 0 ? _tempOrder$customer_i2 : null;
1187
1730
  tempOrder.customer_id = patch.customer_id || patch.id || null;
1188
1731
  tempOrder.customer_name = String(patch.customer_name || '');
1189
1732
  tempOrder.country_calling_code = String(patch.country_calling_code || '');
1190
1733
  tempOrder.phone = String(patch.phone || '');
1191
1734
  tempOrder.email = String(patch.email || '');
1735
+ tempOrder.customer = this.buildTempOrderCustomer({
1736
+ source: snapshot || null,
1737
+ customerId: tempOrder.customer_id,
1738
+ customerName: tempOrder.customer_name,
1739
+ countryCallingCode: tempOrder.country_calling_code,
1740
+ phone: tempOrder.phone,
1741
+ email: tempOrder.email
1742
+ });
1192
1743
  if (snapshot !== undefined) {
1193
1744
  var extend = this.ensureExtend(tempOrder);
1194
1745
  if (snapshot === null) delete extend.customerSnapshot;else extend.customerSnapshot = cloneDeep(snapshot);
1195
1746
  }
1747
+ var nextCustomerId = (_tempOrder$customer_i3 = tempOrder.customer_id) !== null && _tempOrder$customer_i3 !== void 0 ? _tempOrder$customer_i3 : null;
1748
+ if (String(previousCustomerId !== null && previousCustomerId !== void 0 ? previousCustomerId : '') !== String(nextCustomerId !== null && nextCustomerId !== void 0 ? nextCustomerId : '')) {
1749
+ clearTempOrderHolderAssignments(tempOrder);
1750
+ }
1196
1751
  this.persistTempOrder();
1752
+ this.saveDraftInBackground();
1197
1753
  this.emitOrderCustomerChange();
1198
1754
  }
1199
1755
  }, {
1200
1756
  key: "getOrderCustomer",
1201
1757
  value: function getOrderCustomer() {
1202
1758
  var tempOrder = this.store.tempOrder;
1203
- if (!tempOrder || tempOrder.customer_id === null || tempOrder.customer_id === undefined) {
1759
+ if (!tempOrder || !tempOrder.customer_id) {
1204
1760
  return null;
1205
1761
  }
1206
1762
  return {
@@ -1214,21 +1770,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1214
1770
  }, {
1215
1771
  key: "getOrderCustomerSnapshot",
1216
1772
  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;
1773
+ var _this$store$tempOrder4;
1774
+ 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
1775
  return snapshot ? cloneDeep(snapshot) : null;
1220
1776
  }
1221
1777
  }, {
1222
1778
  key: "clearOrderCustomer",
1223
1779
  value: function clearOrderCustomer() {
1224
1780
  var tempOrder = this.ensureTempOrder();
1781
+ clearTempOrderHolderAssignments(tempOrder);
1225
1782
  tempOrder.customer_id = null;
1226
1783
  tempOrder.customer_name = '';
1227
1784
  tempOrder.country_calling_code = '';
1228
1785
  tempOrder.phone = '';
1229
1786
  tempOrder.email = '';
1787
+ tempOrder.customer = null;
1230
1788
  if (tempOrder._extend) delete tempOrder._extend.customerSnapshot;
1231
1789
  this.persistTempOrder();
1790
+ this.saveDraftInBackground();
1232
1791
  this.core.effects.emit(OrderHooks.OnOrderCustomerChange, null);
1233
1792
  }
1234
1793
  }, {
@@ -1279,10 +1838,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1279
1838
  }, {
1280
1839
  key: "addOrderPayment",
1281
1840
  value: function addOrderPayment(payment) {
1841
+ var _paymentRecord$status,
1842
+ _ref21,
1843
+ _paymentRecord$origin,
1844
+ _this6 = this;
1845
+ this.logInfo('addOrderPayment', {
1846
+ payment: payment
1847
+ });
1282
1848
  var tempOrder = this.ensureTempOrder();
1283
- var mapped = mapPaymentItemsToOrderPayments([payment]);
1849
+ var paymentRecord = payment;
1850
+ var mapped = mapPaymentItemsToOrderPayments([_objectSpread(_objectSpread({}, paymentRecord), {}, {
1851
+ status: (_paymentRecord$status = paymentRecord.status) !== null && _paymentRecord$status !== void 0 ? _paymentRecord$status : 'paid',
1852
+ origin_amount: (_ref21 = (_paymentRecord$origin = paymentRecord.origin_amount) !== null && _paymentRecord$origin !== void 0 ? _paymentRecord$origin : paymentRecord.amount) !== null && _ref21 !== void 0 ? _ref21 : '0.00'
1853
+ })]);
1284
1854
  tempOrder.payments = [].concat(_toConsumableArray(tempOrder.payments || []), _toConsumableArray(mapped));
1285
1855
  this.persistTempOrder();
1856
+ void this.recalculateSummary({
1857
+ createIfMissing: true
1858
+ }).catch(function (error) {
1859
+ _this6.logError('recalculate summary after addOrderPayment failed', {
1860
+ error: error instanceof Error ? error.message : String(error)
1861
+ });
1862
+ });
1286
1863
  return tempOrder.payments;
1287
1864
  }
1288
1865
 
@@ -1358,45 +1935,45 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1358
1935
  }, {
1359
1936
  key: "shouldMergeProductToOrder",
1360
1937
  value: function () {
1361
- var _shouldMergeProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(params) {
1938
+ var _shouldMergeProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(params) {
1362
1939
  var _this$orderHooks;
1363
1940
  var onBeforeMergeProductToOrder, result;
1364
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1365
- while (1) switch (_context12.prev = _context12.next) {
1941
+ return _regeneratorRuntime().wrap(function _callee15$(_context17) {
1942
+ while (1) switch (_context17.prev = _context17.next) {
1366
1943
  case 0:
1367
1944
  onBeforeMergeProductToOrder = (_this$orderHooks = this.orderHooks) === null || _this$orderHooks === void 0 ? void 0 : _this$orderHooks.onBeforeMergeProductToOrder;
1368
1945
  if (onBeforeMergeProductToOrder) {
1369
- _context12.next = 3;
1946
+ _context17.next = 3;
1370
1947
  break;
1371
1948
  }
1372
- return _context12.abrupt("return", true);
1949
+ return _context17.abrupt("return", true);
1373
1950
  case 3:
1374
- _context12.next = 5;
1951
+ _context17.next = 5;
1375
1952
  return onBeforeMergeProductToOrder(_objectSpread(_objectSpread({}, params), {}, {
1376
1953
  defaultShouldMerge: true
1377
1954
  }));
1378
1955
  case 5:
1379
- result = _context12.sent;
1956
+ result = _context17.sent;
1380
1957
  if (!(typeof result === 'boolean')) {
1381
- _context12.next = 8;
1958
+ _context17.next = 8;
1382
1959
  break;
1383
1960
  }
1384
- return _context12.abrupt("return", result);
1961
+ return _context17.abrupt("return", result);
1385
1962
  case 8:
1386
1963
  if (!(result && _typeof(result) === 'object' && typeof result.shouldMerge === 'boolean')) {
1387
- _context12.next = 10;
1964
+ _context17.next = 10;
1388
1965
  break;
1389
1966
  }
1390
- return _context12.abrupt("return", result.shouldMerge);
1967
+ return _context17.abrupt("return", result.shouldMerge);
1391
1968
  case 10:
1392
- return _context12.abrupt("return", true);
1969
+ return _context17.abrupt("return", true);
1393
1970
  case 11:
1394
1971
  case "end":
1395
- return _context12.stop();
1972
+ return _context17.stop();
1396
1973
  }
1397
- }, _callee12, this);
1974
+ }, _callee15, this);
1398
1975
  }));
1399
- function shouldMergeProductToOrder(_x11) {
1976
+ function shouldMergeProductToOrder(_x15) {
1400
1977
  return _shouldMergeProductToOrder.apply(this, arguments);
1401
1978
  }
1402
1979
  return shouldMergeProductToOrder;
@@ -1404,11 +1981,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1404
1981
  }, {
1405
1982
  key: "addProductToOrder",
1406
1983
  value: function () {
1407
- var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(product, booking) {
1408
- var _this3 = this;
1984
+ var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(product, booking) {
1985
+ var _this7 = this;
1409
1986
  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) {
1987
+ return _regeneratorRuntime().wrap(function _callee16$(_context18) {
1988
+ while (1) switch (_context18.prev = _context18.next) {
1412
1989
  case 0:
1413
1990
  tempOrder = this.ensureTempOrder();
1414
1991
  linked = booking ? this.createLinkedProductAndBooking({
@@ -1418,10 +1995,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1418
1995
  productToAdd = (linked === null || linked === void 0 ? void 0 : linked.product) || product;
1419
1996
  incomingFingerprint = buildProductLineFingerprint(productToAdd.product_option_item, productToAdd.product_bundle);
1420
1997
  normalizedIncoming = normalizeOrderProduct(productToAdd);
1998
+ normalizedIncoming.discount_list = normalizeOrderProductDiscountList(normalizedIncoming.discount_list);
1421
1999
  hasIncomingGoodPass = this.hasGoodPassDiscount(normalizedIncoming);
1422
2000
  shouldForceNewLine = !!booking;
1423
2001
  matchedIndex = hasIncomingGoodPass || shouldForceNewLine ? -1 : tempOrder.products.findIndex(function (item) {
1424
- if (_this3.hasGoodPassDiscount(item)) return false;
2002
+ if (_this7.hasGoodPassDiscount(item)) return false;
1425
2003
  if (item.product_id !== productToAdd.product_id) return false;
1426
2004
  if (item.product_variant_id !== productToAdd.product_variant_id) return false;
1427
2005
  var existedFingerprint = buildProductLineFingerprint(item.product_option_item, item.product_bundle);
@@ -1430,10 +2008,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1430
2008
  matchedProduct = matchedIndex === -1 ? null : tempOrder.products[matchedIndex];
1431
2009
  existedFingerprint = matchedProduct ? buildProductLineFingerprint(matchedProduct.product_option_item, matchedProduct.product_bundle) : '';
1432
2010
  if (!matchedProduct) {
1433
- _context13.next = 16;
2011
+ _context18.next = 17;
1434
2012
  break;
1435
2013
  }
1436
- _context13.next = 13;
2014
+ _context18.next = 14;
1437
2015
  return this.shouldMergeProductToOrder({
1438
2016
  incomingProduct: productToAdd,
1439
2017
  normalizedIncoming: normalizedIncoming,
@@ -1444,14 +2022,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1444
2022
  tempOrder: tempOrder,
1445
2023
  booking: booking
1446
2024
  });
1447
- case 13:
1448
- _context13.t0 = _context13.sent;
1449
- _context13.next = 17;
2025
+ case 14:
2026
+ _context18.t0 = _context18.sent;
2027
+ _context18.next = 18;
1450
2028
  break;
1451
- case 16:
1452
- _context13.t0 = false;
1453
2029
  case 17:
1454
- shouldMerge = _context13.t0;
2030
+ _context18.t0 = false;
2031
+ case 18:
2032
+ shouldMerge = _context18.t0;
1455
2033
  if (matchedIndex === -1 || !matchedProduct || !shouldMerge) {
1456
2034
  this.captureProductRuntime(tempOrder, productToAdd, normalizedIncoming);
1457
2035
  if (linked) {
@@ -1469,6 +2047,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1469
2047
  unique_identification_number: targetUid
1470
2048
  })
1471
2049
  }));
2050
+ normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
1472
2051
  tempOrder.products[matchedIndex] = _objectSpread(_objectSpread(_objectSpread({}, targetProduct), normalizedProduct), {}, {
1473
2052
  metadata: _objectSpread(_objectSpread(_objectSpread({}, targetProduct.metadata || {}), normalizedProduct.metadata || {}), {}, {
1474
2053
  unique_identification_number: targetUid
@@ -1482,21 +2061,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1482
2061
  if (linked) {
1483
2062
  tempOrder.bookings = [].concat(_toConsumableArray(tempOrder.bookings || []), [linked.booking]);
1484
2063
  }
2064
+ _context18.next = 23;
2065
+ return this.applyPromotion();
2066
+ case 23:
1485
2067
  this.applyDiscount();
1486
- _context13.next = 23;
2068
+ _context18.next = 26;
1487
2069
  return this.recalculateSummary({
1488
2070
  createIfMissing: true
1489
2071
  });
1490
- case 23:
2072
+ case 26:
1491
2073
  this.persistTempOrder();
1492
- return _context13.abrupt("return", tempOrder.products);
1493
- case 25:
2074
+ return _context18.abrupt("return", tempOrder.products);
2075
+ case 28:
1494
2076
  case "end":
1495
- return _context13.stop();
2077
+ return _context18.stop();
1496
2078
  }
1497
- }, _callee13, this);
2079
+ }, _callee16, this);
1498
2080
  }));
1499
- function addProductToOrder(_x12, _x13) {
2081
+ function addProductToOrder(_x16, _x17) {
1500
2082
  return _addProductToOrder.apply(this, arguments);
1501
2083
  }
1502
2084
  return addProductToOrder;
@@ -1521,15 +2103,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1521
2103
  });
1522
2104
  }
1523
2105
  }, {
1524
- key: "updateProductInOrder",
2106
+ key: "updateOrderProduct",
1525
2107
  value: function () {
1526
- var _updateProductInOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(params) {
2108
+ var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(params) {
1527
2109
  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) {
2110
+ 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;
2111
+ return _regeneratorRuntime().wrap(function _callee17$(_context19) {
2112
+ while (1) switch (_context19.prev = _context19.next) {
1531
2113
  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;
2114
+ 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
2115
  tempOrder = this.ensureTempOrder();
1534
2116
  identityLookup = {
1535
2117
  product_id: product_id,
@@ -1537,16 +2119,32 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1537
2119
  };
1538
2120
  if (unique_identification_number !== undefined) {
1539
2121
  identityLookup.unique_identification_number = unique_identification_number;
2122
+ if (identity_key === undefined) {
2123
+ identityLookup.identity_key = unique_identification_number;
2124
+ }
2125
+ }
2126
+ if (identity_key !== undefined) {
2127
+ identityLookup.identity_key = identity_key;
1540
2128
  }
1541
2129
  if (product_option_item !== undefined) identityLookup.product_option_item = product_option_item;
1542
2130
  if (product_bundle !== undefined) identityLookup.product_bundle = product_bundle;
1543
- productIndex = getProductIdentityIndex(tempOrder.products, identityLookup);
2131
+ productIndex = -1;
2132
+ if (unique_identification_number !== undefined) {
2133
+ targetUid = String(unique_identification_number);
2134
+ productIndex = tempOrder.products.findIndex(function (item) {
2135
+ var _item$metadata;
2136
+ return String(((_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.unique_identification_number) || item.unique_identification_number || '') === targetUid;
2137
+ });
2138
+ }
2139
+ if (productIndex === -1) {
2140
+ productIndex = getProductIdentityIndex(tempOrder.products, identityLookup);
2141
+ }
1544
2142
  if (!(productIndex === -1)) {
1545
- _context14.next = 9;
2143
+ _context19.next = 12;
1546
2144
  break;
1547
2145
  }
1548
2146
  throw new Error('[Order] 目标商品不存在,无法更新');
1549
- case 9:
2147
+ case 12:
1550
2148
  targetProduct = tempOrder.products[productIndex];
1551
2149
  nextProduct = _objectSpread(_objectSpread(_objectSpread({}, targetProduct), updates), {}, {
1552
2150
  product_id: product_id,
@@ -1574,57 +2172,230 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1574
2172
  }
1575
2173
  // normalizeOrderProduct 幂等:v2 metadata 存在 → 保留 main_product_* 折扣重算 composite;
1576
2174
  // 否则 → 把顶层 selling_price 视作 source,派生 main_product_* 并写 price_schema_version: 2。
1577
- tempOrder.products[productIndex] = normalizeOrderProduct(nextProduct);
2175
+ normalizedProduct = normalizeOrderProduct(nextProduct);
2176
+ normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
2177
+ if (booking) {
2178
+ 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());
2179
+ normalizedProduct.metadata = _objectSpread(_objectSpread({}, normalizedProduct.metadata || {}), {}, {
2180
+ unique_identification_number: productUid
2181
+ });
2182
+ linked = this.createLinkedProductAndBooking({
2183
+ product: _objectSpread(_objectSpread({}, normalizedProduct), {}, {
2184
+ unique_identification_number: productUid
2185
+ }),
2186
+ booking: booking
2187
+ });
2188
+ this.removeLinkedBookingsForProduct(tempOrder, targetProduct);
2189
+ normalizedProduct = _objectSpread(_objectSpread({}, normalizedProduct), {}, {
2190
+ booking_uid: linked.bookingUid,
2191
+ metadata: _objectSpread(_objectSpread({}, normalizedProduct.metadata || {}), {}, {
2192
+ booking_uid: linked.bookingUid,
2193
+ unique_identification_number: productUid
2194
+ })
2195
+ });
2196
+ tempOrder.bookings = [].concat(_toConsumableArray(tempOrder.bookings || []), [linked.booking]);
2197
+ }
2198
+ tempOrder.products[productIndex] = normalizedProduct;
1578
2199
  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);
2200
+ _context19.next = 25;
2201
+ return this.applyPromotion();
2202
+ case 25:
1579
2203
  this.applyDiscount();
1580
- _context14.next = 20;
2204
+ _context19.next = 28;
1581
2205
  return this.recalculateSummary({
1582
2206
  createIfMissing: true
1583
2207
  });
1584
- case 20:
2208
+ case 28:
1585
2209
  this.persistTempOrder();
1586
- return _context14.abrupt("return", tempOrder.products);
1587
- case 22:
2210
+ return _context19.abrupt("return", tempOrder.products);
2211
+ case 30:
1588
2212
  case "end":
1589
- return _context14.stop();
2213
+ return _context19.stop();
1590
2214
  }
1591
- }, _callee14, this);
2215
+ }, _callee17, this);
1592
2216
  }));
1593
- function updateProductInOrder(_x14) {
1594
- return _updateProductInOrder.apply(this, arguments);
2217
+ function updateOrderProduct(_x18) {
2218
+ return _updateOrderProduct.apply(this, arguments);
1595
2219
  }
1596
- return updateProductInOrder;
2220
+ return updateOrderProduct;
1597
2221
  }()
2222
+ }, {
2223
+ key: "updateOrderProductQuantity",
2224
+ value: function () {
2225
+ var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(params) {
2226
+ var _targetProduct$metada4;
2227
+ var product_id, product_variant_id, num, unique_identification_number, identity_key, product_option_item, product_bundle, tempOrder, identityLookup, productIndex, targetUid, targetProduct, normalizedProduct;
2228
+ return _regeneratorRuntime().wrap(function _callee18$(_context20) {
2229
+ while (1) switch (_context20.prev = _context20.next) {
2230
+ case 0:
2231
+ 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;
2232
+ tempOrder = this.ensureTempOrder();
2233
+ identityLookup = {
2234
+ product_id: product_id,
2235
+ product_variant_id: product_variant_id
2236
+ };
2237
+ if (unique_identification_number !== undefined) {
2238
+ identityLookup.unique_identification_number = unique_identification_number;
2239
+ if (identity_key === undefined) {
2240
+ identityLookup.identity_key = unique_identification_number;
2241
+ }
2242
+ }
2243
+ if (identity_key !== undefined) identityLookup.identity_key = identity_key;
2244
+ if (product_option_item !== undefined) identityLookup.product_option_item = product_option_item;
2245
+ if (product_bundle !== undefined) identityLookup.product_bundle = product_bundle;
2246
+ productIndex = -1;
2247
+ if (unique_identification_number !== undefined) {
2248
+ targetUid = String(unique_identification_number);
2249
+ productIndex = tempOrder.products.findIndex(function (item) {
2250
+ var _item$metadata2;
2251
+ return String(((_item$metadata2 = item.metadata) === null || _item$metadata2 === void 0 ? void 0 : _item$metadata2.unique_identification_number) || item.unique_identification_number || '') === targetUid;
2252
+ });
2253
+ }
2254
+ if (productIndex === -1) {
2255
+ productIndex = getProductIdentityIndex(tempOrder.products, identityLookup);
2256
+ }
2257
+ if (!(productIndex === -1)) {
2258
+ _context20.next = 12;
2259
+ break;
2260
+ }
2261
+ throw new Error('[Order] 目标商品不存在,无法更新数量');
2262
+ case 12:
2263
+ targetProduct = tempOrder.products[productIndex];
2264
+ normalizedProduct = normalizeOrderProduct(_objectSpread(_objectSpread({}, targetProduct), {}, {
2265
+ num: getSafeProductNum(num),
2266
+ metadata: _objectSpread(_objectSpread({}, targetProduct.metadata || {}), {}, {
2267
+ unique_identification_number: ((_targetProduct$metada4 = targetProduct.metadata) === null || _targetProduct$metada4 === void 0 ? void 0 : _targetProduct$metada4.unique_identification_number) || unique_identification_number
2268
+ })
2269
+ }));
2270
+ normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
2271
+ tempOrder.products[productIndex] = normalizedProduct;
2272
+ _context20.next = 18;
2273
+ return this.applyPromotion();
2274
+ case 18:
2275
+ this.applyDiscount();
2276
+ _context20.next = 21;
2277
+ return this.recalculateSummary({
2278
+ createIfMissing: true
2279
+ });
2280
+ case 21:
2281
+ this.persistTempOrder();
2282
+ return _context20.abrupt("return", tempOrder.products);
2283
+ case 23:
2284
+ case "end":
2285
+ return _context20.stop();
2286
+ }
2287
+ }, _callee18, this);
2288
+ }));
2289
+ function updateOrderProductQuantity(_x19) {
2290
+ return _updateOrderProductQuantity.apply(this, arguments);
2291
+ }
2292
+ return updateOrderProductQuantity;
2293
+ }()
2294
+ }, {
2295
+ key: "updateOrderBooking",
2296
+ value: function updateOrderBooking(params) {
2297
+ var unique_identification_number = params.unique_identification_number,
2298
+ updates = params.updates;
2299
+ var tempOrder = this.ensureTempOrder();
2300
+ var bookingUid = String(unique_identification_number || '');
2301
+ var bookingIndex = this.findBookingIndexByUniqueIdentificationNumber(tempOrder, bookingUid);
2302
+ if (!bookingUid || bookingIndex === -1) {
2303
+ throw new Error('[Order] 目标 booking 不存在,无法更新');
2304
+ }
2305
+ var targetBooking = tempOrder.bookings[bookingIndex] || {};
2306
+ var nextBooking = _objectSpread(_objectSpread(_objectSpread({}, targetBooking), updates), {}, {
2307
+ metadata: _objectSpread(_objectSpread(_objectSpread({}, targetBooking.metadata || {}), updates.metadata || {}), {}, {
2308
+ unique_identification_number: bookingUid
2309
+ })
2310
+ });
2311
+ nextBooking.is_all = normalizeBookingIsAll(nextBooking);
2312
+ nextBooking.sub_type = normalizeBookingSubType(nextBooking);
2313
+ tempOrder.bookings[bookingIndex] = nextBooking;
2314
+ this.persistTempOrder();
2315
+ return tempOrder.bookings;
2316
+ }
1598
2317
  }, {
1599
2318
  key: "removeProductFromOrder",
1600
2319
  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) {
2320
+ var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(identity) {
2321
+ var tempOrder, removedProducts, _i, _removedProducts, product;
2322
+ return _regeneratorRuntime().wrap(function _callee19$(_context21) {
2323
+ while (1) switch (_context21.prev = _context21.next) {
1605
2324
  case 0:
1606
2325
  tempOrder = this.ensureTempOrder();
2326
+ removedProducts = [];
1607
2327
  tempOrder.products = tempOrder.products.filter(function (item) {
1608
- return !isIdentityMatch(item, identity);
2328
+ var shouldRemove = isIdentityMatch(item, identity);
2329
+ if (shouldRemove) removedProducts.push(item);
2330
+ return !shouldRemove;
1609
2331
  });
2332
+ for (_i = 0, _removedProducts = removedProducts; _i < _removedProducts.length; _i++) {
2333
+ product = _removedProducts[_i];
2334
+ this.removeLinkedBookingsForProduct(tempOrder, product);
2335
+ }
2336
+ _context21.next = 6;
2337
+ return this.applyPromotion();
2338
+ case 6:
1610
2339
  this.applyDiscount();
1611
- _context15.next = 5;
2340
+ _context21.next = 9;
1612
2341
  return this.recalculateSummary({
1613
2342
  createIfMissing: true
1614
2343
  });
1615
- case 5:
2344
+ case 9:
1616
2345
  this.persistTempOrder();
1617
- return _context15.abrupt("return", tempOrder.products);
1618
- case 7:
2346
+ return _context21.abrupt("return", tempOrder.products);
2347
+ case 11:
1619
2348
  case "end":
1620
- return _context15.stop();
2349
+ return _context21.stop();
1621
2350
  }
1622
- }, _callee15, this);
2351
+ }, _callee19, this);
1623
2352
  }));
1624
- function removeProductFromOrder(_x15) {
2353
+ function removeProductFromOrder(_x20) {
1625
2354
  return _removeProductFromOrder.apply(this, arguments);
1626
2355
  }
1627
2356
  return removeProductFromOrder;
2357
+ }()
2358
+ /**
2359
+ * 仅清空购物车行(products / bookings),不重置整单。
2360
+ * 用于「仅清空商品」;客户、备注、支付等协议字段保持不变。
2361
+ */
2362
+ }, {
2363
+ key: "clearOrderCartLines",
2364
+ value: (function () {
2365
+ var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
2366
+ var tempOrder;
2367
+ return _regeneratorRuntime().wrap(function _callee20$(_context22) {
2368
+ while (1) switch (_context22.prev = _context22.next) {
2369
+ case 0:
2370
+ tempOrder = this.ensureTempOrder();
2371
+ tempOrder.products = [];
2372
+ tempOrder.bookings = [];
2373
+ if (tempOrder._extend && _typeof(tempOrder._extend) === 'object') {
2374
+ tempOrder._extend = _objectSpread(_objectSpread({}, tempOrder._extend), {}, {
2375
+ productsByUid: {}
2376
+ });
2377
+ }
2378
+ _context22.next = 6;
2379
+ return this.applyPromotion();
2380
+ case 6:
2381
+ this.applyDiscount();
2382
+ _context22.next = 9;
2383
+ return this.recalculateSummary({
2384
+ createIfMissing: true
2385
+ });
2386
+ case 9:
2387
+ this.persistTempOrder();
2388
+ return _context22.abrupt("return", tempOrder);
2389
+ case 11:
2390
+ case "end":
2391
+ return _context22.stop();
2392
+ }
2393
+ }, _callee20, this);
2394
+ }));
2395
+ function clearOrderCartLines() {
2396
+ return _clearOrderCartLines.apply(this, arguments);
2397
+ }
2398
+ return clearOrderCartLines;
1628
2399
  }() // ─── TempOrder: 提交 ───
1629
2400
  /**
1630
2401
  * 提交当前 Sales tempOrder。
@@ -1632,14 +2403,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1632
2403
  * smallTicketDataFlag 用于 B 端 checkout 小票数据返回。PaymentModal 在支付提交时
1633
2404
  * 应传 1,确保 /order/sales/checkout 返回打印所需数据。
1634
2405
  */
2406
+ )
1635
2407
  }, {
1636
2408
  key: "submitTempOrder",
1637
2409
  value: function () {
1638
- var _submitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(params) {
2410
+ var _submitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(params) {
1639
2411
  var _params$cacheId, _this$otherParams;
1640
2412
  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) {
2413
+ return _regeneratorRuntime().wrap(function _callee21$(_context23) {
2414
+ while (1) switch (_context23.prev = _context23.next) {
1643
2415
  case 0:
1644
2416
  tempOrder = this.ensureTempOrder();
1645
2417
  this.persistTempOrder();
@@ -1655,7 +2427,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1655
2427
  } : {}), hasSmallTicketDataFlagOverride ? {
1656
2428
  small_ticket_data_flag: params === null || params === void 0 ? void 0 : params.smallTicketDataFlag
1657
2429
  } : {});
1658
- return params !== null && params !== void 0 && params.enhancePayload ? params.enhancePayload(nextPayload, ctx) : nextPayload;
2430
+ var enhancedPayload = params !== null && params !== void 0 && params.enhancePayload ? params.enhancePayload(nextPayload, ctx) : nextPayload;
2431
+ return enhancedPayload;
1659
2432
  } : undefined;
1660
2433
  payload = buildSubmitPayload({
1661
2434
  tempOrder: tempOrder,
@@ -1666,73 +2439,74 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1666
2439
  type: params === null || params === void 0 ? void 0 : params.type,
1667
2440
  enhance: enhancePayload
1668
2441
  });
1669
- _context16.next = 10;
2442
+ _context23.next = 10;
1670
2443
  return this.saveDraft();
1671
2444
  case 10:
1672
- _context16.prev = 10;
2445
+ _context23.prev = 10;
1673
2446
  this.logInfo('submitTempOrder calling sales checkout', {
1674
2447
  orderId: payload.order_id,
1675
2448
  externalSaleNumber: payload.external_sale_number,
2449
+ requestUniqueIdempotencyToken: payload.request_unique_idempotency_token,
1676
2450
  paymentStatus: payload.payment_status,
1677
2451
  paymentsCount: ((_payload$payments = payload.payments) === null || _payload$payments === void 0 ? void 0 : _payload$payments.length) || 0,
1678
2452
  smallTicketDataFlag: payload.small_ticket_data_flag
1679
2453
  });
1680
- _context16.next = 14;
2454
+ _context23.next = 14;
1681
2455
  return this.submitSalesOrder({
1682
2456
  query: payload
1683
2457
  });
1684
2458
  case 14:
1685
- result = _context16.sent;
1686
- _context16.next = 27;
2459
+ result = _context23.sent;
2460
+ _context23.next = 27;
1687
2461
  break;
1688
2462
  case 17:
1689
- _context16.prev = 17;
1690
- _context16.t0 = _context16["catch"](10);
1691
- backendErrorResponse = this.extractSubmitErrorResponse(_context16.t0);
2463
+ _context23.prev = 17;
2464
+ _context23.t0 = _context23["catch"](10);
2465
+ backendErrorResponse = this.extractSubmitErrorResponse(_context23.t0);
1692
2466
  if (!backendErrorResponse) {
1693
- _context16.next = 24;
2467
+ _context23.next = 24;
1694
2468
  break;
1695
2469
  }
1696
2470
  this.store.syncState = 'failed';
1697
2471
  this.logSubmitBackendRejected(backendErrorResponse, payload);
1698
- return _context16.abrupt("return", backendErrorResponse);
2472
+ return _context23.abrupt("return", backendErrorResponse);
1699
2473
  case 24:
1700
2474
  this.store.syncState = 'failed';
1701
2475
  this.logError('submitTempOrder failed', {
1702
- error: _context16.t0 instanceof Error ? _context16.t0.message : String(_context16.t0),
2476
+ error: _context23.t0 instanceof Error ? _context23.t0.message : String(_context23.t0),
1703
2477
  orderId: payload.order_id,
1704
2478
  externalSaleNumber: payload.external_sale_number,
1705
2479
  paymentStatus: payload.payment_status,
1706
2480
  paymentsCount: ((_payload$payments2 = payload.payments) === null || _payload$payments2 === void 0 ? void 0 : _payload$payments2.length) || 0
1707
2481
  });
1708
- throw _context16.t0;
2482
+ throw _context23.t0;
1709
2483
  case 27:
1710
2484
  if (!this.isSubmitResponseRejected(result)) {
1711
- _context16.next = 31;
2485
+ _context23.next = 31;
1712
2486
  break;
1713
2487
  }
1714
2488
  this.store.syncState = 'failed';
1715
2489
  this.logSubmitBackendRejected(result, payload);
1716
- return _context16.abrupt("return", result);
2490
+ return _context23.abrupt("return", result);
1717
2491
  case 31:
1718
2492
  submittedOrderId = this.extractOrderIdFromSubmitResult(result);
1719
2493
  if (!(submittedOrderId !== null && submittedOrderId !== undefined)) {
1720
- _context16.next = 37;
2494
+ _context23.next = 37;
1721
2495
  break;
1722
2496
  }
1723
2497
  tempOrder.order_id = submittedOrderId;
1724
2498
  resultRecord = result;
1725
- _context16.next = 37;
2499
+ _context23.next = 37;
1726
2500
  return this.markLocalOrderSynced(submittedOrderId, (resultRecord === null || resultRecord === void 0 ? void 0 : resultRecord.data) || resultRecord || {});
1727
2501
  case 37:
1728
- return _context16.abrupt("return", result);
2502
+ return _context23.abrupt("return", result);
1729
2503
  case 38:
1730
2504
  case "end":
1731
- return _context16.stop();
2505
+ return _context23.stop();
1732
2506
  }
1733
- }, _callee16, this, [[10, 17]]);
2507
+ }, _callee21, this, [[10, 17]]);
1734
2508
  }));
1735
- function submitTempOrder(_x16) {
2509
+ function submitTempOrder(_x21) {
1736
2510
  return _submitTempOrder.apply(this, arguments);
1737
2511
  }
1738
2512
  return submitTempOrder;
@@ -1740,25 +2514,25 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1740
2514
  }, {
1741
2515
  key: "markLocalOrderSynced",
1742
2516
  value: function () {
1743
- var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(orderId, remoteOrder) {
2517
+ var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(orderId, remoteOrder) {
1744
2518
  var tempOrder;
1745
- return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1746
- while (1) switch (_context17.prev = _context17.next) {
2519
+ return _regeneratorRuntime().wrap(function _callee22$(_context24) {
2520
+ while (1) switch (_context24.prev = _context24.next) {
1747
2521
  case 0:
1748
2522
  tempOrder = this.ensureTempOrder();
1749
2523
  tempOrder.order_id = orderId;
1750
2524
  this.store.lastOrderInfo = remoteOrder;
1751
2525
  this.store.syncState = 'submitted';
1752
2526
  this.persistTempOrder();
1753
- _context17.next = 7;
2527
+ _context24.next = 7;
1754
2528
  return this.saveDraft();
1755
2529
  case 7:
1756
2530
  case "end":
1757
- return _context17.stop();
2531
+ return _context24.stop();
1758
2532
  }
1759
- }, _callee17, this);
2533
+ }, _callee22, this);
1760
2534
  }));
1761
- function markLocalOrderSynced(_x17, _x18) {
2535
+ function markLocalOrderSynced(_x22, _x23) {
1762
2536
  return _markLocalOrderSynced.apply(this, arguments);
1763
2537
  }
1764
2538
  return markLocalOrderSynced;
@@ -1782,10 +2556,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1782
2556
  value: function extractSubmitErrorResponse(error) {
1783
2557
  var _error$response,
1784
2558
  _error$response2,
1785
- _this4 = this;
2559
+ _this8 = this;
1786
2560
  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
2561
  return candidates.find(function (candidate) {
1788
- return _this4.isSubmitErrorResponse(candidate);
2562
+ return _this8.isSubmitErrorResponse(candidate);
1789
2563
  }) || null;
1790
2564
  }
1791
2565
  }, {
@@ -1805,49 +2579,67 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1805
2579
  }, {
1806
2580
  key: "syncPaymentsToOrder",
1807
2581
  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) {
2582
+ var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(params) {
2583
+ var tempOrder, mappedPayments, paymentTotal, targetAmount, isFullyPaid, paymentStatus, paymentSyncIdempotencyToken, submitResult;
2584
+ return _regeneratorRuntime().wrap(function _callee23$(_context25) {
2585
+ while (1) switch (_context25.prev = _context25.next) {
1812
2586
  case 0:
1813
2587
  tempOrder = this.ensureTempOrder();
1814
2588
  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
2589
  paymentTotal = this.calculatePaymentTotal(mappedPayments);
1822
2590
  targetAmount = this.getPaymentTargetAmount();
1823
2591
  isFullyPaid = targetAmount.lte(0) ? false : paymentTotal.gte(targetAmount);
1824
- if (!(!isFullyPaid || !params.submitWhenPaid)) {
1825
- _context18.next = 12;
2592
+ paymentStatus = isFullyPaid ? params.paymentStatus || 'paid' : 'partially_paid';
2593
+ tempOrder.payments = mappedPayments;
2594
+ tempOrder.payment_status = paymentStatus;
2595
+ this.persistTempOrder();
2596
+ _context25.next = 11;
2597
+ return this.saveDraft();
2598
+ case 11:
2599
+ if (params.submitWhenPaid) {
2600
+ _context25.next = 13;
1826
2601
  break;
1827
2602
  }
1828
- return _context18.abrupt("return", {
2603
+ return _context25.abrupt("return", {
1829
2604
  isFullyPaid: isFullyPaid
1830
2605
  });
1831
- case 12:
1832
- _context18.next = 14;
2606
+ case 13:
2607
+ if (!(this.store.syncState === 'submitting')) {
2608
+ _context25.next = 15;
2609
+ break;
2610
+ }
2611
+ return _context25.abrupt("return", {
2612
+ isFullyPaid: isFullyPaid
2613
+ });
2614
+ case 15:
2615
+ this.store.syncState = 'submitting';
2616
+ paymentSyncIdempotencyToken = this.buildPaymentSyncIdempotencyToken(tempOrder, mappedPayments);
2617
+ _context25.next = 19;
1833
2618
  return this.submitTempOrder({
1834
2619
  payments: mappedPayments,
1835
- paymentStatus: params.paymentStatus || 'paid',
1836
- smallTicketDataFlag: params.smallTicketDataFlag
2620
+ paymentStatus: paymentStatus,
2621
+ smallTicketDataFlag: params.smallTicketDataFlag,
2622
+ channel: params.channel,
2623
+ enhancePayload: function enhancePayload(payload) {
2624
+ var nextPayload = _objectSpread(_objectSpread({}, payload), {}, {
2625
+ request_unique_idempotency_token: paymentSyncIdempotencyToken
2626
+ });
2627
+ return nextPayload;
2628
+ }
1837
2629
  });
1838
- case 14:
1839
- submitResult = _context18.sent;
1840
- return _context18.abrupt("return", {
2630
+ case 19:
2631
+ submitResult = _context25.sent;
2632
+ return _context25.abrupt("return", {
1841
2633
  isFullyPaid: isFullyPaid,
1842
2634
  submitResult: submitResult
1843
2635
  });
1844
- case 16:
2636
+ case 21:
1845
2637
  case "end":
1846
- return _context18.stop();
2638
+ return _context25.stop();
1847
2639
  }
1848
- }, _callee18, this);
2640
+ }, _callee23, this);
1849
2641
  }));
1850
- function syncPaymentsToOrder(_x19) {
2642
+ function syncPaymentsToOrder(_x24) {
1851
2643
  return _syncPaymentsToOrder.apply(this, arguments);
1852
2644
  }
1853
2645
  return syncPaymentsToOrder;
@@ -1936,11 +2728,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1936
2728
  }, {
1937
2729
  key: "submitOrder",
1938
2730
  value: function () {
1939
- var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(order) {
2731
+ var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(order) {
1940
2732
  var _order$query$cartItem, _params$bookings, _params$relation_prod;
1941
2733
  var url, query, fetchUrl, params;
1942
- return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1943
- while (1) switch (_context19.prev = _context19.next) {
2734
+ return _regeneratorRuntime().wrap(function _callee24$(_context26) {
2735
+ while (1) switch (_context26.prev = _context26.next) {
1944
2736
  case 0:
1945
2737
  this.logInfo('submitOrder called', {
1946
2738
  url: order.url,
@@ -1960,14 +2752,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1960
2752
  relationProductsCount: ((_params$relation_prod = params.relation_products) === null || _params$relation_prod === void 0 ? void 0 : _params$relation_prod.length) || 0,
1961
2753
  scheduleDate: params.schedule_date
1962
2754
  });
1963
- return _context19.abrupt("return", this.request.post(fetchUrl, params));
2755
+ return _context26.abrupt("return", this.request.post(fetchUrl, params));
1964
2756
  case 6:
1965
2757
  case "end":
1966
- return _context19.stop();
2758
+ return _context26.stop();
1967
2759
  }
1968
- }, _callee19, this);
2760
+ }, _callee24, this);
1969
2761
  }));
1970
- function submitOrder(_x20) {
2762
+ function submitOrder(_x25) {
1971
2763
  return _submitOrder.apply(this, arguments);
1972
2764
  }
1973
2765
  return submitOrder;
@@ -1975,13 +2767,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1975
2767
  }, {
1976
2768
  key: "cancelOrder",
1977
2769
  value: function () {
1978
- var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(params) {
2770
+ var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(params) {
1979
2771
  var payload;
1980
- return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1981
- while (1) switch (_context20.prev = _context20.next) {
2772
+ return _regeneratorRuntime().wrap(function _callee25$(_context27) {
2773
+ while (1) switch (_context27.prev = _context27.next) {
1982
2774
  case 0:
1983
2775
  if (!(!Array.isArray(params.order_ids) || params.order_ids.length === 0)) {
1984
- _context20.next = 2;
2776
+ _context27.next = 2;
1985
2777
  break;
1986
2778
  }
1987
2779
  throw new Error('取消订单失败:order_ids 不能为空');
@@ -1997,16 +2789,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1997
2789
  method: 'PUT',
1998
2790
  orderIdsCount: params.order_ids.length
1999
2791
  });
2000
- return _context20.abrupt("return", this.request.put('/order/update-status', payload, {
2792
+ return _context27.abrupt("return", this.request.put('/order/update-status', payload, {
2001
2793
  isShopApi: true
2002
2794
  }));
2003
2795
  case 5:
2004
2796
  case "end":
2005
- return _context20.stop();
2797
+ return _context27.stop();
2006
2798
  }
2007
- }, _callee20, this);
2799
+ }, _callee25, this);
2008
2800
  }));
2009
- function cancelOrder(_x21) {
2801
+ function cancelOrder(_x26) {
2010
2802
  return _cancelOrder.apply(this, arguments);
2011
2803
  }
2012
2804
  return cancelOrder;
@@ -2014,19 +2806,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2014
2806
  }, {
2015
2807
  key: "changeBookingStatus",
2016
2808
  value: function () {
2017
- var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(params) {
2809
+ var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(params) {
2018
2810
  var url, payload;
2019
- return _regeneratorRuntime().wrap(function _callee21$(_context21) {
2020
- while (1) switch (_context21.prev = _context21.next) {
2811
+ return _regeneratorRuntime().wrap(function _callee26$(_context28) {
2812
+ while (1) switch (_context28.prev = _context28.next) {
2021
2813
  case 0:
2022
2814
  if (params.booking_id) {
2023
- _context21.next = 2;
2815
+ _context28.next = 2;
2024
2816
  break;
2025
2817
  }
2026
2818
  throw new Error('变更预约状态失败:booking_id 不能为空');
2027
2819
  case 2:
2028
2820
  if (params.appointment_status) {
2029
- _context21.next = 4;
2821
+ _context28.next = 4;
2030
2822
  break;
2031
2823
  }
2032
2824
  throw new Error('变更预约状态失败:appointment_status 不能为空');
@@ -2041,16 +2833,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2041
2833
  bookingId: params.booking_id,
2042
2834
  appointmentStatus: params.appointment_status
2043
2835
  });
2044
- return _context21.abrupt("return", this.request.put(url, payload, {
2836
+ return _context28.abrupt("return", this.request.put(url, payload, {
2045
2837
  isShopApi: true
2046
2838
  }));
2047
2839
  case 8:
2048
2840
  case "end":
2049
- return _context21.stop();
2841
+ return _context28.stop();
2050
2842
  }
2051
- }, _callee21, this);
2843
+ }, _callee26, this);
2052
2844
  }));
2053
- function changeBookingStatus(_x22) {
2845
+ function changeBookingStatus(_x27) {
2054
2846
  return _changeBookingStatus.apply(this, arguments);
2055
2847
  }
2056
2848
  return changeBookingStatus;
@@ -2068,11 +2860,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2068
2860
  }, {
2069
2861
  key: "createOrderByCheckout",
2070
2862
  value: (function () {
2071
- var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(params) {
2863
+ var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(params) {
2072
2864
  var _params$payments, _params$bookings2, _params$relation_prod2, _params$payments2, _params$payments3, _params$bookings3, _params$relation_prod3, _params$payments4;
2073
2865
  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) {
2866
+ return _regeneratorRuntime().wrap(function _callee27$(_context29) {
2867
+ while (1) switch (_context29.prev = _context29.next) {
2076
2868
  case 0:
2077
2869
  // 过滤掉由在线店铺下单的 payment 支付数据
2078
2870
  onlineStorePaymentCodeList = ['WXPAY', 'WECHAT', 'ALIPAY', 'APPLE_PAY', 'CREDIT_CARD_3DS', 'CREDIT_CARD_TOKEN', 'GOOGLE_PAY', 'GOOGLE_PAY_3DS', 'CREDIT_CARD'];
@@ -2106,7 +2898,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2106
2898
  relationProductsCount: ((_params$relation_prod3 = params.relation_products) === null || _params$relation_prod3 === void 0 ? void 0 : _params$relation_prod3.length) || 0,
2107
2899
  paymentsCount: ((_params$payments4 = params.payments) === null || _params$payments4 === void 0 ? void 0 : _params$payments4.length) || 0
2108
2900
  });
2109
- _context22.prev = 4;
2901
+ _context29.prev = 4;
2110
2902
  // 构建订单数据,设置默认值并允许 params 覆盖
2111
2903
  orderData = _objectSpread({
2112
2904
  sales_channel: 'my_pisel',
@@ -2170,10 +2962,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2170
2962
  });
2171
2963
 
2172
2964
  // 调用后端接口
2173
- _context22.next = 12;
2965
+ _context29.next = 12;
2174
2966
  return this.request.post('/order/checkout', orderData);
2175
2967
  case 12:
2176
- response = _context22.sent;
2968
+ response = _context29.sent;
2177
2969
  this.logInfo('Order API called successfully', {
2178
2970
  response: response
2179
2971
  });
@@ -2181,22 +2973,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2181
2973
  success: !!response,
2182
2974
  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
2975
  });
2184
- return _context22.abrupt("return", response);
2976
+ return _context29.abrupt("return", response);
2185
2977
  case 18:
2186
- _context22.prev = 18;
2187
- _context22.t0 = _context22["catch"](4);
2188
- console.error('[Order] createOrderByCheckout 创建订单失败:', _context22.t0);
2978
+ _context29.prev = 18;
2979
+ _context29.t0 = _context29["catch"](4);
2980
+ console.error('[Order] createOrderByCheckout 创建订单失败:', _context29.t0);
2189
2981
  this.logInfo('Order API called failed', {
2190
- error: _context22.t0 instanceof Error ? _context22.t0.message : String(_context22.t0)
2982
+ error: _context29.t0 instanceof Error ? _context29.t0.message : String(_context29.t0)
2191
2983
  });
2192
- throw _context22.t0;
2984
+ throw _context29.t0;
2193
2985
  case 23:
2194
2986
  case "end":
2195
- return _context22.stop();
2987
+ return _context29.stop();
2196
2988
  }
2197
- }, _callee22, this, [[4, 18]]);
2989
+ }, _callee27, this, [[4, 18]]);
2198
2990
  }));
2199
- function createOrderByCheckout(_x23) {
2991
+ function createOrderByCheckout(_x28) {
2200
2992
  return _createOrderByCheckout.apply(this, arguments);
2201
2993
  }
2202
2994
  return createOrderByCheckout;
@@ -2204,23 +2996,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2204
2996
  }, {
2205
2997
  key: "submitSalesOrder",
2206
2998
  value: function () {
2207
- var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(params) {
2999
+ var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(params) {
2208
3000
  var url, query, fetchUrl;
2209
- return _regeneratorRuntime().wrap(function _callee23$(_context23) {
2210
- while (1) switch (_context23.prev = _context23.next) {
3001
+ return _regeneratorRuntime().wrap(function _callee28$(_context30) {
3002
+ while (1) switch (_context30.prev = _context30.next) {
2211
3003
  case 0:
2212
3004
  url = params.url, query = params.query;
2213
3005
  fetchUrl = url || '/order/sales/checkout';
2214
- return _context23.abrupt("return", this.request.post(fetchUrl, query, {
3006
+ return _context30.abrupt("return", this.request.post(fetchUrl, query, {
2215
3007
  customToast: function customToast() {}
2216
3008
  }));
2217
3009
  case 3:
2218
3010
  case "end":
2219
- return _context23.stop();
3011
+ return _context30.stop();
2220
3012
  }
2221
- }, _callee23, this);
3013
+ }, _callee28, this);
2222
3014
  }));
2223
- function submitSalesOrder(_x24) {
3015
+ function submitSalesOrder(_x29) {
2224
3016
  return _submitSalesOrder.apply(this, arguments);
2225
3017
  }
2226
3018
  return submitSalesOrder;
@@ -2234,37 +3026,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2234
3026
  }, {
2235
3027
  key: "sendCustomerPayLink",
2236
3028
  value: (function () {
2237
- var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(params) {
3029
+ var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(params) {
2238
3030
  var _params$emails;
2239
3031
  var orderIds;
2240
- return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2241
- while (1) switch (_context24.prev = _context24.next) {
3032
+ return _regeneratorRuntime().wrap(function _callee29$(_context31) {
3033
+ while (1) switch (_context31.prev = _context31.next) {
2242
3034
  case 0:
2243
3035
  orderIds = params.order_ids || params.orderIds || [];
2244
3036
  if (orderIds.length) {
2245
- _context24.next = 3;
3037
+ _context31.next = 3;
2246
3038
  break;
2247
3039
  }
2248
3040
  throw new Error('发送支付链接前必须先提交本地订单并取得订单 ID');
2249
3041
  case 3:
2250
3042
  if ((_params$emails = params.emails) !== null && _params$emails !== void 0 && _params$emails.length) {
2251
- _context24.next = 5;
3043
+ _context31.next = 5;
2252
3044
  break;
2253
3045
  }
2254
3046
  throw new Error('发送支付链接需要至少一个邮箱');
2255
3047
  case 5:
2256
- return _context24.abrupt("return", this.request.post('/order/batch-email', {
3048
+ return _context31.abrupt("return", this.request.post('/order/batch-email', {
2257
3049
  order_ids: orderIds,
2258
3050
  notify_action: params.notify_action || 'order_payment_reminder',
2259
3051
  emails: params.emails
2260
3052
  }));
2261
3053
  case 6:
2262
3054
  case "end":
2263
- return _context24.stop();
3055
+ return _context31.stop();
2264
3056
  }
2265
- }, _callee24, this);
3057
+ }, _callee29, this);
2266
3058
  }));
2267
- function sendCustomerPayLink(_x25) {
3059
+ function sendCustomerPayLink(_x30) {
2268
3060
  return _sendCustomerPayLink.apply(this, arguments);
2269
3061
  }
2270
3062
  return sendCustomerPayLink;
@@ -2273,28 +3065,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2273
3065
  }, {
2274
3066
  key: "getOrderInfoByRemote",
2275
3067
  value: function () {
2276
- var _getOrderInfoByRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(order_id) {
3068
+ var _getOrderInfoByRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(order_id) {
2277
3069
  var res;
2278
- return _regeneratorRuntime().wrap(function _callee25$(_context25) {
2279
- while (1) switch (_context25.prev = _context25.next) {
3070
+ return _regeneratorRuntime().wrap(function _callee30$(_context32) {
3071
+ while (1) switch (_context32.prev = _context32.next) {
2280
3072
  case 0:
2281
- _context25.next = 2;
3073
+ _context32.next = 2;
2282
3074
  return this.request.get("/order/sales/".concat(order_id), {
2283
3075
  with: ['products', 'bookings', 'payments', 'customer', 'summary', 'contacts_info']
2284
3076
  });
2285
3077
  case 2:
2286
- res = _context25.sent;
3078
+ res = _context32.sent;
2287
3079
  if (res.code === 200) {
2288
3080
  this.store.lastOrderInfo = res.data;
2289
3081
  }
2290
- return _context25.abrupt("return", res);
3082
+ return _context32.abrupt("return", res);
2291
3083
  case 5:
2292
3084
  case "end":
2293
- return _context25.stop();
3085
+ return _context32.stop();
2294
3086
  }
2295
- }, _callee25, this);
3087
+ }, _callee30, this);
2296
3088
  }));
2297
- function getOrderInfoByRemote(_x26) {
3089
+ function getOrderInfoByRemote(_x31) {
2298
3090
  return _getOrderInfoByRemote.apply(this, arguments);
2299
3091
  }
2300
3092
  return getOrderInfoByRemote;
@@ -2308,79 +3100,92 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2308
3100
  }, {
2309
3101
  key: "hydrateTempOrderFromRecord",
2310
3102
  value: (function () {
2311
- var _hydrateTempOrderFromRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(record, options) {
2312
- var _this5 = this;
2313
- var raw, defaults, nextTempOrder, TEMP_ORDER_KEYS;
2314
- return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2315
- while (1) switch (_context26.prev = _context26.next) {
3103
+ var _hydrateTempOrderFromRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(record, options) {
3104
+ var raw, nextTempOrder;
3105
+ return _regeneratorRuntime().wrap(function _callee31$(_context33) {
3106
+ while (1) switch (_context33.prev = _context33.next) {
2316
3107
  case 0:
2317
3108
  raw = record && _typeof(record) === 'object' && record.data && record.order_id == null ? record.data : record || {};
2318
- defaults = this.createDefaultTempOrderInstance();
2319
- nextTempOrder = _objectSpread({}, defaults);
2320
- TEMP_ORDER_KEYS = ['order_id', 'external_sale_number', 'order_number', 'shop_order_number', 'shop_full_order_number', 'type', 'business_code', 'platform', 'sales_channel', 'order_sales_channel', 'status', 'payment_status', 'shipping_status', 'customer_id', 'customer_name', 'country_calling_code', 'phone', 'email', 'customer', 'is_price_include_tax', 'tax_title', 'tax_country_code', 'currency_code', 'currency_symbol', 'currency_format', 'is_deposit', 'deposit_amount', 'shop_discount', 'surcharge_fee', 'note', 'buzzer', 'delivery_type', 'table_number', 'schedule_date', 'created_at', 'request_unique_idempotency_token'];
2321
- TEMP_ORDER_KEYS.forEach(function (key) {
2322
- if (raw[key] !== undefined) {
2323
- nextTempOrder[key] = raw[key];
2324
- }
3109
+ nextTempOrder = this.normalizeTempOrderForRuntime(raw, {
3110
+ ensureIdentity: true
2325
3111
  });
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
3112
  this.store.tempOrder = nextTempOrder;
2360
3113
  this.store.summary = raw.summary && _typeof(raw.summary) === 'object' ? _objectSpread(_objectSpread({}, createEmptySummary()), raw.summary) : createEmptySummary();
2361
3114
  this.store.lastOrderInfo = raw.lastOrderInfo || raw;
2362
3115
  if (!(options !== null && options !== void 0 && options.recalcOnHydrate)) {
2363
- _context26.next = 23;
3116
+ _context33.next = 8;
2364
3117
  break;
2365
3118
  }
2366
- _context26.next = 23;
3119
+ _context33.next = 8;
2367
3120
  return this.recalculateSummary({
2368
3121
  createIfMissing: false
2369
3122
  });
2370
- case 23:
3123
+ case 8:
2371
3124
  this.persistTempOrder();
2372
- return _context26.abrupt("return", nextTempOrder);
2373
- case 25:
3125
+ return _context33.abrupt("return", nextTempOrder);
3126
+ case 10:
2374
3127
  case "end":
2375
- return _context26.stop();
3128
+ return _context33.stop();
2376
3129
  }
2377
- }, _callee26, this);
3130
+ }, _callee31, this);
2378
3131
  }));
2379
- function hydrateTempOrderFromRecord(_x27, _x28) {
3132
+ function hydrateTempOrderFromRecord(_x32, _x33) {
2380
3133
  return _hydrateTempOrderFromRecord.apply(this, arguments);
2381
3134
  }
2382
3135
  return hydrateTempOrderFromRecord;
2383
3136
  }())
3137
+ }, {
3138
+ key: "normalizeTempOrderForRuntime",
3139
+ value: function normalizeTempOrderForRuntime(raw, options) {
3140
+ var _this9 = this;
3141
+ var nextTempOrder = _objectSpread(_objectSpread({}, this.createDefaultTempOrderInstance()), raw || {});
3142
+ delete nextTempOrder.summary;
3143
+ delete nextTempOrder.lastOrderInfo;
3144
+ delete nextTempOrder.discount_list;
3145
+ delete nextTempOrder.shop_id;
3146
+ delete nextTempOrder.create_date;
3147
+ delete nextTempOrder.total_amount;
3148
+ delete nextTempOrder.expect_amount;
3149
+ delete nextTempOrder.paid_amount;
3150
+ delete nextTempOrder.shop_note;
3151
+ delete nextTempOrder.start_time;
3152
+ delete nextTempOrder.tax_fee;
3153
+ delete nextTempOrder.total_refund_amount;
3154
+ delete nextTempOrder.holder_id;
3155
+ nextTempOrder.metadata = raw.metadata && _typeof(raw.metadata) === 'object' ? _objectSpread({}, raw.metadata) : {};
3156
+ nextTempOrder.holder = raw.holder && _typeof(raw.holder) === 'object' ? _objectSpread({}, raw.holder) : null;
3157
+ nextTempOrder.products = Array.isArray(raw.products) ? raw.products.map(function (p) {
3158
+ return _this9.normalizeHydratedOrderProduct(p);
3159
+ }) : [];
3160
+ nextTempOrder.bookings = Array.isArray(raw.bookings) ? raw.bookings.map(function (b) {
3161
+ return _objectSpread(_objectSpread({}, b || {}), {}, {
3162
+ is_all: normalizeBookingIsAll(b || {}),
3163
+ sub_type: normalizeBookingSubType(b || {})
3164
+ });
3165
+ }) : [];
3166
+ nextTempOrder.payments = Array.isArray(raw.payments) ? raw.payments.map(function (p) {
3167
+ return _objectSpread({}, p || {});
3168
+ }) : [];
3169
+ nextTempOrder.surcharges = Array.isArray(raw.surcharges) ? raw.surcharges.map(function (s) {
3170
+ return _objectSpread({}, s || {});
3171
+ }) : [];
3172
+ nextTempOrder.relation_forms = Array.isArray(raw.relation_forms) ? raw.relation_forms.map(function (f) {
3173
+ return _objectSpread({}, f || {});
3174
+ }) : [];
3175
+ nextTempOrder.contacts = Array.isArray(raw.contacts) ? raw.contacts.map(function (c) {
3176
+ return _objectSpread({}, c || {});
3177
+ }) : [];
3178
+ nextTempOrder.contacts_info = raw.contacts_info && _typeof(raw.contacts_info) === 'object' && !Array.isArray(raw.contacts_info) ? _objectSpread({}, raw.contacts_info) : null;
3179
+ nextTempOrder._extend = raw._extend && _typeof(raw._extend) === 'object' ? _objectSpread(_objectSpread({}, raw._extend), {}, {
3180
+ productsByUid: raw._extend.productsByUid || {}
3181
+ }) : {
3182
+ productsByUid: {}
3183
+ };
3184
+ if ((options === null || options === void 0 ? void 0 : options.ensureIdentity) !== false) {
3185
+ this.ensureExternalSaleNumber(nextTempOrder);
3186
+ }
3187
+ return nextTempOrder;
3188
+ }
2384
3189
  }, {
2385
3190
  key: "normalizeHydratedOrderProduct",
2386
3191
  value: function normalizeHydratedOrderProduct(product) {
@@ -2396,6 +3201,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2396
3201
  row.metadata.unique_identification_number = createUuidV4();
2397
3202
  }
2398
3203
  var normalized = normalizeOrderProduct(row);
3204
+ normalized.discount_list = normalizeOrderProductDiscountList(normalized.discount_list);
2399
3205
  var result = _objectSpread(_objectSpread(_objectSpread({}, row), normalized), {}, {
2400
3206
  metadata: _objectSpread(_objectSpread({}, row.metadata), normalized.metadata)
2401
3207
  });
@@ -2411,25 +3217,25 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2411
3217
  }, {
2412
3218
  key: "getOrderInfo",
2413
3219
  value: function () {
2414
- var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(order_id) {
3220
+ var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(order_id) {
2415
3221
  var res;
2416
- return _regeneratorRuntime().wrap(function _callee27$(_context27) {
2417
- while (1) switch (_context27.prev = _context27.next) {
3222
+ return _regeneratorRuntime().wrap(function _callee32$(_context34) {
3223
+ while (1) switch (_context34.prev = _context34.next) {
2418
3224
  case 0:
2419
- _context27.next = 2;
3225
+ _context34.next = 2;
2420
3226
  return this.request.get("/order/sales/".concat(order_id), {
2421
3227
  with: ['products', 'bookings']
2422
3228
  });
2423
3229
  case 2:
2424
- res = _context27.sent;
2425
- return _context27.abrupt("return", res);
3230
+ res = _context34.sent;
3231
+ return _context34.abrupt("return", res);
2426
3232
  case 4:
2427
3233
  case "end":
2428
- return _context27.stop();
3234
+ return _context34.stop();
2429
3235
  }
2430
- }, _callee27, this);
3236
+ }, _callee32, this);
2431
3237
  }));
2432
- function getOrderInfo(_x29) {
3238
+ function getOrderInfo(_x34) {
2433
3239
  return _getOrderInfo.apply(this, arguments);
2434
3240
  }
2435
3241
  return getOrderInfo;
@@ -2443,46 +3249,46 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2443
3249
  */
2444
3250
  function populateSavedAmounts(productList, discountList) {
2445
3251
  var savedMap = new Map();
2446
- var _iterator = _createForOfIteratorHelper(productList),
2447
- _step;
3252
+ var _iterator7 = _createForOfIteratorHelper(productList),
3253
+ _step7;
2448
3254
  try {
2449
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
2450
- var product = _step.value;
3255
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
3256
+ var product = _step7.value;
2451
3257
  var qty = product.num || 1;
2452
- var _iterator3 = _createForOfIteratorHelper(product.discount_list || []),
2453
- _step3;
3258
+ var _iterator9 = _createForOfIteratorHelper(product.discount_list || []),
3259
+ _step9;
2454
3260
  try {
2455
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
3261
+ for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
2456
3262
  var _pd$discount, _pd$metadata;
2457
- var pd = _step3.value;
3263
+ var pd = _step9.value;
2458
3264
  var discountKey = ((_pd$discount = pd.discount) === null || _pd$discount === void 0 ? void 0 : _pd$discount.resource_id) || pd.id;
2459
3265
  if (discountKey == null) continue;
2460
3266
  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
3267
  savedMap.set(discountKey, (savedMap.get(discountKey) || new Decimal(0)).plus(amount));
2462
3268
  }
2463
3269
  } catch (err) {
2464
- _iterator3.e(err);
3270
+ _iterator9.e(err);
2465
3271
  } finally {
2466
- _iterator3.f();
3272
+ _iterator9.f();
2467
3273
  }
2468
3274
  }
2469
3275
  } catch (err) {
2470
- _iterator.e(err);
3276
+ _iterator7.e(err);
2471
3277
  } finally {
2472
- _iterator.f();
3278
+ _iterator7.f();
2473
3279
  }
2474
- var _iterator2 = _createForOfIteratorHelper(discountList),
2475
- _step2;
3280
+ var _iterator8 = _createForOfIteratorHelper(discountList),
3281
+ _step8;
2476
3282
  try {
2477
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
2478
- var d = _step2.value;
3283
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
3284
+ var d = _step8.value;
2479
3285
  var key = d.id;
2480
3286
  d.savedAmount = d.isSelected && key != null && savedMap.has(key) ? savedMap.get(key).toNumber() : 0;
2481
3287
  }
2482
3288
  } catch (err) {
2483
- _iterator2.e(err);
3289
+ _iterator8.e(err);
2484
3290
  } finally {
2485
- _iterator2.f();
3291
+ _iterator8.f();
2486
3292
  }
2487
3293
  }
2488
3294
  }]);