@pisell/pisellos 2.2.175 → 2.2.176

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 (172) 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 +84 -17
  38. package/dist/modules/Order/index.js +1239 -495
  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 +3 -3
  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/utils/filterOrders.js +20 -6
  56. package/dist/server/modules/products/index.d.ts +1 -1
  57. package/dist/server/modules/products/index.js +130 -113
  58. package/dist/server/modules/schedule/index.js +13 -6
  59. package/dist/solution/BaseSales/index.d.ts +89 -7
  60. package/dist/solution/BaseSales/index.js +1484 -365
  61. package/dist/solution/BaseSales/types.d.ts +67 -1
  62. package/dist/solution/BaseSales/types.js +3 -1
  63. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +275 -0
  64. package/dist/solution/BaseSales/utils/cartPromotion.js +1258 -0
  65. package/dist/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
  66. package/dist/solution/BaseSales/utils/quotationPrice.js +237 -0
  67. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +68 -16
  68. package/dist/solution/BaseSales/utils.js +46 -8
  69. package/dist/solution/BookingByStep/index.d.ts +1 -1
  70. package/dist/solution/BookingTicket/index.d.ts +133 -1
  71. package/dist/solution/BookingTicket/index.js +780 -175
  72. package/dist/solution/BookingTicket/types.d.ts +2 -0
  73. package/dist/solution/BookingTicket/types.js +3 -0
  74. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +113 -0
  75. package/dist/solution/BookingTicket/utils/addProductDecision.js +346 -0
  76. package/dist/solution/BookingTicket/utils/cartView.js +4 -2
  77. package/dist/solution/ScanOrder/index.d.ts +9 -3
  78. package/dist/solution/ScanOrder/index.js +231 -128
  79. package/dist/solution/ScanOrder/utils.js +46 -8
  80. package/dist/solution/ShopDiscount/index.d.ts +0 -1
  81. package/dist/solution/ShopDiscount/index.js +18 -23
  82. package/dist/solution/VenueBooking/index.d.ts +5 -9
  83. package/dist/solution/VenueBooking/index.js +103 -55
  84. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
  85. package/dist/solution/VenueBooking/utils/slotMerge.js +10 -0
  86. package/lib/model/strategy/adapter/promotion/index.js +0 -49
  87. package/lib/modules/BookingContext/index.d.ts +37 -0
  88. package/lib/modules/BookingContext/index.js +297 -0
  89. package/lib/modules/BookingContext/types.d.ts +102 -0
  90. package/lib/modules/BookingContext/types.js +34 -0
  91. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  92. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +207 -0
  93. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  94. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +141 -0
  95. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +75 -0
  96. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +198 -0
  97. package/lib/modules/BookingContext/utils/flexible.d.ts +28 -0
  98. package/lib/modules/BookingContext/utils/flexible.js +80 -0
  99. package/lib/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  100. package/lib/modules/BookingContext/utils/formatResourceList.js +50 -0
  101. package/lib/modules/BookingContext/utils/index.d.ts +11 -0
  102. package/lib/modules/BookingContext/utils/index.js +43 -0
  103. package/lib/modules/BookingContext/utils/noResource.d.ts +13 -0
  104. package/lib/modules/BookingContext/utils/noResource.js +90 -0
  105. package/lib/modules/BookingContext/utils/productExtend.d.ts +72 -0
  106. package/lib/modules/BookingContext/utils/productExtend.js +283 -0
  107. package/lib/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  108. package/lib/modules/BookingContext/utils/resourceErrors.js +80 -0
  109. package/lib/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  110. package/lib/modules/BookingContext/utils/resourceSelection.js +46 -0
  111. package/lib/modules/BookingContext/utils/resources.d.ts +80 -0
  112. package/lib/modules/BookingContext/utils/resources.js +377 -0
  113. package/lib/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  114. package/lib/modules/BookingContext/utils/serviceTimes.js +162 -0
  115. package/lib/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  116. package/lib/modules/BookingContext/utils/timeSlices.js +124 -0
  117. package/lib/modules/Customer/index.d.ts +6 -0
  118. package/lib/modules/Customer/index.js +26 -11
  119. package/lib/modules/Customer/types.d.ts +2 -0
  120. package/lib/modules/Discount/index.d.ts +2 -4
  121. package/lib/modules/Discount/index.js +8 -63
  122. package/lib/modules/Discount/types.d.ts +1 -7
  123. package/lib/modules/Order/index.d.ts +84 -17
  124. package/lib/modules/Order/index.js +588 -145
  125. package/lib/modules/Order/types.d.ts +198 -18
  126. package/lib/modules/Order/types.js +1 -0
  127. package/lib/modules/Order/utils/manualProductDiscount.d.ts +106 -0
  128. package/lib/modules/Order/utils/manualProductDiscount.js +207 -0
  129. package/lib/modules/Order/utils.d.ts +50 -1
  130. package/lib/modules/Order/utils.js +229 -21
  131. package/lib/modules/Quotation/index.d.ts +0 -1
  132. package/lib/modules/Quotation/index.js +18 -15
  133. package/lib/modules/Rules/index.d.ts +4 -0
  134. package/lib/modules/Rules/index.js +22 -14
  135. package/lib/modules/SalesSummary/index.js +4 -2
  136. package/lib/modules/SalesSummary/utils.js +3 -3
  137. package/lib/modules/Schedule/index.js +3 -1
  138. package/lib/modules/index.d.ts +1 -0
  139. package/lib/modules/index.js +3 -1
  140. package/lib/server/index.js +41 -4
  141. package/lib/server/modules/order/utils/filterOrders.js +12 -4
  142. package/lib/server/modules/products/index.d.ts +1 -1
  143. package/lib/server/modules/products/index.js +30 -20
  144. package/lib/server/modules/schedule/index.js +2 -1
  145. package/lib/solution/BaseSales/index.d.ts +89 -7
  146. package/lib/solution/BaseSales/index.js +736 -22
  147. package/lib/solution/BaseSales/types.d.ts +67 -1
  148. package/lib/solution/BaseSales/types.js +3 -1
  149. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +275 -0
  150. package/lib/solution/BaseSales/utils/cartPromotion.js +836 -0
  151. package/lib/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
  152. package/lib/solution/BaseSales/utils/quotationPrice.js +277 -0
  153. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +71 -12
  154. package/lib/solution/BaseSales/utils.js +46 -6
  155. package/lib/solution/BookingByStep/index.d.ts +1 -1
  156. package/lib/solution/BookingTicket/index.d.ts +133 -1
  157. package/lib/solution/BookingTicket/index.js +352 -8
  158. package/lib/solution/BookingTicket/types.d.ts +2 -0
  159. package/lib/solution/BookingTicket/types.js +6 -0
  160. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +113 -0
  161. package/lib/solution/BookingTicket/utils/addProductDecision.js +318 -0
  162. package/lib/solution/BookingTicket/utils/cartView.js +4 -2
  163. package/lib/solution/ScanOrder/index.d.ts +9 -3
  164. package/lib/solution/ScanOrder/index.js +147 -66
  165. package/lib/solution/ScanOrder/utils.js +46 -6
  166. package/lib/solution/ShopDiscount/index.d.ts +0 -1
  167. package/lib/solution/ShopDiscount/index.js +2 -4
  168. package/lib/solution/VenueBooking/index.d.ts +5 -9
  169. package/lib/solution/VenueBooking/index.js +50 -14
  170. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
  171. package/lib/solution/VenueBooking/utils/slotMerge.js +10 -0
  172. 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),
@@ -812,11 +1160,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
812
1160
  }, {
813
1161
  key: "restoreOrder",
814
1162
  value: function restoreOrder() {
1163
+ var _this$store$discount9, _this$store$discount10;
815
1164
  var freshTempOrder = this.createDefaultTempOrderInstance();
816
1165
  this.ensureExternalSaleNumber(freshTempOrder);
817
1166
  this.store.tempOrder = freshTempOrder;
818
1167
  this.store.summary = createEmptySummary();
819
1168
  this.store.lastOrderInfo = undefined;
1169
+ this.store.syncState = undefined;
1170
+ void ((_this$store$discount9 = this.store.discount) === null || _this$store$discount9 === void 0 ? void 0 : _this$store$discount9.setOriginalDiscountList([]));
1171
+ void ((_this$store$discount10 = this.store.discount) === null || _this$store$discount10 === void 0 ? void 0 : _this$store$discount10.setDiscountList([]));
820
1172
  this.persistTempOrder();
821
1173
  return freshTempOrder;
822
1174
  }
@@ -825,6 +1177,60 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
825
1177
  value: function getTempOrder() {
826
1178
  return this.store.tempOrder;
827
1179
  }
1180
+ }, {
1181
+ key: "replaceTempOrder",
1182
+ value: function () {
1183
+ var _replaceTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(tempOrder, options) {
1184
+ var nextTempOrder;
1185
+ return _regeneratorRuntime().wrap(function _callee10$(_context12) {
1186
+ while (1) switch (_context12.prev = _context12.next) {
1187
+ case 0:
1188
+ if (isTempOrder(tempOrder)) {
1189
+ _context12.next = 2;
1190
+ break;
1191
+ }
1192
+ throw new Error('无效的 tempOrder 数据');
1193
+ case 2:
1194
+ nextTempOrder = this.normalizeTempOrderForRuntime(cloneDeep(tempOrder), {
1195
+ ensureIdentity: false
1196
+ });
1197
+ this.store.tempOrder = nextTempOrder;
1198
+ if (!((options === null || options === void 0 ? void 0 : options.recalculateSummary) !== false)) {
1199
+ _context12.next = 9;
1200
+ break;
1201
+ }
1202
+ _context12.next = 7;
1203
+ return this.recalculateSummary({
1204
+ createIfMissing: false
1205
+ });
1206
+ case 7:
1207
+ _context12.next = 10;
1208
+ break;
1209
+ case 9:
1210
+ this.store.summary = createEmptySummary();
1211
+ case 10:
1212
+ if ((options === null || options === void 0 ? void 0 : options.persist) !== false) {
1213
+ this.persistTempOrder();
1214
+ }
1215
+ if (!(options !== null && options !== void 0 && options.saveDraft)) {
1216
+ _context12.next = 14;
1217
+ break;
1218
+ }
1219
+ _context12.next = 14;
1220
+ return this.saveDraft();
1221
+ case 14:
1222
+ return _context12.abrupt("return", nextTempOrder);
1223
+ case 15:
1224
+ case "end":
1225
+ return _context12.stop();
1226
+ }
1227
+ }, _callee10, this);
1228
+ }));
1229
+ function replaceTempOrder(_x10, _x11) {
1230
+ return _replaceTempOrder.apply(this, arguments);
1231
+ }
1232
+ return replaceTempOrder;
1233
+ }()
828
1234
  }, {
829
1235
  key: "getOrderIdentity",
830
1236
  value: function getOrderIdentity() {
@@ -903,28 +1309,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
903
1309
  }, {
904
1310
  key: "addNewOrder",
905
1311
  value: function () {
906
- var _addNewOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
1312
+ var _addNewOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
907
1313
  var tempOrder;
908
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
909
- while (1) switch (_context9.prev = _context9.next) {
1314
+ return _regeneratorRuntime().wrap(function _callee11$(_context13) {
1315
+ while (1) switch (_context13.prev = _context13.next) {
910
1316
  case 0:
911
1317
  tempOrder = this.ensureTempOrder();
912
1318
  this.ensureExternalSaleNumber(tempOrder);
913
- _context9.next = 4;
1319
+ _context13.next = 4;
914
1320
  return this.recalculateSummary({
915
1321
  createIfMissing: true
916
1322
  });
917
1323
  case 4:
918
1324
  this.persistTempOrder();
919
- _context9.next = 7;
1325
+ _context13.next = 7;
920
1326
  return this.saveDraft();
921
1327
  case 7:
922
- return _context9.abrupt("return", tempOrder);
1328
+ return _context13.abrupt("return", tempOrder);
923
1329
  case 8:
924
1330
  case "end":
925
- return _context9.stop();
1331
+ return _context13.stop();
926
1332
  }
927
- }, _callee9, this);
1333
+ }, _callee11, this);
928
1334
  }));
929
1335
  function addNewOrder() {
930
1336
  return _addNewOrder.apply(this, arguments);
@@ -1000,6 +1406,38 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1000
1406
  })
1001
1407
  };
1002
1408
  }
1409
+ }, {
1410
+ key: "getBookingUniqueIdentificationNumber",
1411
+ value: function getBookingUniqueIdentificationNumber(booking) {
1412
+ var _booking$metadata;
1413
+ var uid = booking === null || booking === void 0 || (_booking$metadata = booking.metadata) === null || _booking$metadata === void 0 ? void 0 : _booking$metadata.unique_identification_number;
1414
+ if (uid === undefined || uid === null || uid === '') return null;
1415
+ return String(uid);
1416
+ }
1417
+ }, {
1418
+ key: "findBookingIndexByUniqueIdentificationNumber",
1419
+ value: function findBookingIndexByUniqueIdentificationNumber(tempOrder, uniqueIdentificationNumber) {
1420
+ var _this4 = this;
1421
+ return (tempOrder.bookings || []).findIndex(function (booking) {
1422
+ return _this4.getBookingUniqueIdentificationNumber(booking) === uniqueIdentificationNumber;
1423
+ });
1424
+ }
1425
+ }, {
1426
+ key: "removeLinkedBookingsForProduct",
1427
+ value: function removeLinkedBookingsForProduct(tempOrder, product) {
1428
+ var _product$metadata4,
1429
+ _product$metadata5,
1430
+ _this5 = this;
1431
+ 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);
1432
+ 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);
1433
+ if (!productUid && !bookingUid) return;
1434
+ tempOrder.bookings = (tempOrder.bookings || []).filter(function (booking) {
1435
+ var currentBookingUid = _this5.getBookingUniqueIdentificationNumber(booking);
1436
+ if (bookingUid && currentBookingUid === String(bookingUid)) return false;
1437
+ if (productUid && String((booking === null || booking === void 0 ? void 0 : booking.product_uid) || '') === String(productUid)) return false;
1438
+ return true;
1439
+ });
1440
+ }
1003
1441
 
1004
1442
  // ─── TempOrder: 金额汇总 ───
1005
1443
  }, {
@@ -1011,23 +1449,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1011
1449
  }, {
1012
1450
  key: "recalculateSummary",
1013
1451
  value: function () {
1014
- var _recalculateSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(options) {
1452
+ var _recalculateSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(options) {
1015
1453
  var tempOrder, salesSummary, existedSummary, paidPaymentSummary, emptySummary, salesSummaryResult, summary;
1016
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1017
- while (1) switch (_context10.prev = _context10.next) {
1454
+ return _regeneratorRuntime().wrap(function _callee12$(_context14) {
1455
+ while (1) switch (_context14.prev = _context14.next) {
1018
1456
  case 0:
1019
1457
  tempOrder = options !== null && options !== void 0 && options.createIfMissing ? this.ensureTempOrder() : this.store.tempOrder;
1020
1458
  if (tempOrder) {
1021
- _context10.next = 3;
1459
+ _context14.next = 3;
1022
1460
  break;
1023
1461
  }
1024
- return _context10.abrupt("return", null);
1462
+ return _context14.abrupt("return", null);
1025
1463
  case 3:
1026
1464
  salesSummary = this.getSalesSummary();
1027
1465
  existedSummary = this.store.summary || createEmptySummary();
1028
1466
  paidPaymentSummary = this.calculatePaidPaymentSummary(tempOrder.payments || []);
1029
1467
  if (salesSummary) {
1030
- _context10.next = 11;
1468
+ _context14.next = 11;
1031
1469
  break;
1032
1470
  }
1033
1471
  emptySummary = _objectSpread(_objectSpread({}, createEmptySummary()), {}, {
@@ -1038,16 +1476,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1038
1476
  });
1039
1477
  this.store.summary = emptySummary;
1040
1478
  tempOrder.surcharge_fee = emptySummary.surcharge_fee;
1041
- return _context10.abrupt("return", this.store.summary);
1479
+ return _context14.abrupt("return", this.store.summary);
1042
1480
  case 11:
1043
- _context10.next = 13;
1481
+ _context14.next = 13;
1044
1482
  return salesSummary.getSummary({
1045
1483
  products: tempOrder.products,
1046
1484
  isPriceIncludeTax: tempOrder.is_price_include_tax,
1047
1485
  shopDiscount: tempOrder.shop_discount
1048
1486
  });
1049
1487
  case 13:
1050
- salesSummaryResult = _context10.sent;
1488
+ salesSummaryResult = _context14.sent;
1051
1489
  summary = _objectSpread(_objectSpread({}, salesSummaryResult), {}, {
1052
1490
  total_refund_amount: existedSummary.total_refund_amount || '0.00',
1053
1491
  customer_paid_amount: paidPaymentSummary.customerPaidAmount.toFixed(2),
@@ -1065,14 +1503,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1065
1503
  tempOrder.surcharges = summary.surcharges || [];
1066
1504
  tempOrder.deposit_amount = summary.deposit_amount || '0.00';
1067
1505
  tempOrder.is_deposit = summary.deposit_amount !== '0.00' ? 1 : 0;
1068
- return _context10.abrupt("return", this.store.summary);
1506
+ return _context14.abrupt("return", this.store.summary);
1069
1507
  case 23:
1070
1508
  case "end":
1071
- return _context10.stop();
1509
+ return _context14.stop();
1072
1510
  }
1073
- }, _callee10, this);
1511
+ }, _callee12, this);
1074
1512
  }));
1075
- function recalculateSummary(_x10) {
1513
+ function recalculateSummary(_x12) {
1076
1514
  return _recalculateSummary.apply(this, arguments);
1077
1515
  }
1078
1516
  return recalculateSummary;
@@ -1080,30 +1518,30 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1080
1518
  }, {
1081
1519
  key: "getOrderSummary",
1082
1520
  value: function () {
1083
- var _getOrderSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
1521
+ var _getOrderSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
1084
1522
  var summary;
1085
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1086
- while (1) switch (_context11.prev = _context11.next) {
1523
+ return _regeneratorRuntime().wrap(function _callee13$(_context15) {
1524
+ while (1) switch (_context15.prev = _context15.next) {
1087
1525
  case 0:
1088
- _context11.next = 2;
1526
+ _context15.next = 2;
1089
1527
  return this.recalculateSummary({
1090
1528
  createIfMissing: true
1091
1529
  });
1092
1530
  case 2:
1093
- summary = _context11.sent;
1531
+ summary = _context15.sent;
1094
1532
  if (summary) {
1095
- _context11.next = 5;
1533
+ _context15.next = 5;
1096
1534
  break;
1097
1535
  }
1098
- return _context11.abrupt("return", createEmptySummary());
1536
+ return _context15.abrupt("return", createEmptySummary());
1099
1537
  case 5:
1100
1538
  this.persistTempOrder();
1101
- return _context11.abrupt("return", summary);
1539
+ return _context15.abrupt("return", summary);
1102
1540
  case 7:
1103
1541
  case "end":
1104
- return _context11.stop();
1542
+ return _context15.stop();
1105
1543
  }
1106
- }, _callee11, this);
1544
+ }, _callee13, this);
1107
1545
  }));
1108
1546
  function getOrderSummary() {
1109
1547
  return _getOrderSummary.apply(this, arguments);
@@ -1113,16 +1551,46 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1113
1551
  }, {
1114
1552
  key: "updateTempOrderNote",
1115
1553
  value: function updateTempOrderNote(note) {
1554
+ var sync = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1116
1555
  var tempOrder = this.ensureTempOrder();
1117
1556
  tempOrder.note = String(note || '');
1118
1557
  this.persistTempOrder();
1558
+ if (sync) {
1559
+ var orderId = tempOrder.order_id;
1560
+ if (!orderId) return tempOrder.note;
1561
+ return this.syncTempOrderNoteToRemote(orderId, tempOrder.note);
1562
+ }
1119
1563
  return tempOrder.note;
1120
1564
  }
1565
+ }, {
1566
+ key: "syncTempOrderNoteToRemote",
1567
+ value: function () {
1568
+ var _syncTempOrderNoteToRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(orderId, note) {
1569
+ return _regeneratorRuntime().wrap(function _callee14$(_context16) {
1570
+ while (1) switch (_context16.prev = _context16.next) {
1571
+ case 0:
1572
+ _context16.next = 2;
1573
+ return this.request.put("/order/order/".concat(orderId, "/note"), {
1574
+ note: note
1575
+ });
1576
+ case 2:
1577
+ return _context16.abrupt("return", note);
1578
+ case 3:
1579
+ case "end":
1580
+ return _context16.stop();
1581
+ }
1582
+ }, _callee14, this);
1583
+ }));
1584
+ function syncTempOrderNoteToRemote(_x13, _x14) {
1585
+ return _syncTempOrderNoteToRemote.apply(this, arguments);
1586
+ }
1587
+ return syncTempOrderNoteToRemote;
1588
+ }()
1121
1589
  }, {
1122
1590
  key: "getTempOrderNote",
1123
1591
  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) || '';
1592
+ var _this$store$tempOrder3;
1593
+ return ((_this$store$tempOrder3 = this.store.tempOrder) === null || _this$store$tempOrder3 === void 0 ? void 0 : _this$store$tempOrder3.note) || '';
1126
1594
  }
1127
1595
  }, {
1128
1596
  key: "updateTempOrderShopDiscount",
@@ -1149,25 +1617,51 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1149
1617
  this.persistTempOrder();
1150
1618
  return tempOrder.contacts_info;
1151
1619
  }
1620
+ }, {
1621
+ key: "buildTempOrderCustomer",
1622
+ value: function buildTempOrderCustomer(params) {
1623
+ 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;
1624
+ if (!params.customerId) return null;
1625
+ var source = params.source ? cloneDeep(params.source) : {};
1626
+ 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;
1627
+ 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;
1628
+ return _objectSpread(_objectSpread({}, source), {}, {
1629
+ id: (_source$id = source.id) !== null && _source$id !== void 0 ? _source$id : params.customerId,
1630
+ customer_id: (_source$customer_id = source.customer_id) !== null && _source$customer_id !== void 0 ? _source$customer_id : params.customerId,
1631
+ name: String(name || ''),
1632
+ customer_name: String(customerName || ''),
1633
+ 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),
1634
+ phone: String((_source$phone = source.phone) !== null && _source$phone !== void 0 ? _source$phone : params.phone),
1635
+ email: String((_source$email = source.email) !== null && _source$email !== void 0 ? _source$email : params.email)
1636
+ });
1637
+ }
1152
1638
 
1153
1639
  /**
1154
1640
  * 更新当前 tempOrder 的客户协议字段。
1155
1641
  *
1156
- * PaymentModal 只需要修改订单里的客户字段;如果外部还有客户模块需要同步,
1642
+ * PaymentModal 只需要修改订单里的客户事实;如果外部还有客户模块需要同步,
1157
1643
  * 应由调用方通过回调处理,不能把外部 UI 状态写进 tempOrder。
1158
1644
  */
1159
1645
  }, {
1160
1646
  key: "updateTempOrderCustomer",
1161
1647
  value: function updateTempOrderCustomer(customer) {
1162
- var _ref8, _ref9, _customer$customer_id, _ref10, _ref11, _ref12, _customer$customer_na, _ref13, _customer$country_cal;
1648
+ var _ref15, _ref16, _customer$customer_id, _ref17, _ref18, _ref19, _customer$customer_na, _ref20, _customer$country_cal;
1163
1649
  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 : '';
1650
+ 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;
1651
+ 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
1652
  tempOrder.customer_id = customerId === null || customerId === undefined || customerId === '' ? null : Number(customerId);
1167
1653
  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 : '');
1654
+ 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
1655
  tempOrder.phone = String(customer.phone || '');
1170
1656
  tempOrder.email = String(customer.email || '');
1657
+ tempOrder.customer = this.buildTempOrderCustomer({
1658
+ source: customer,
1659
+ customerId: tempOrder.customer_id,
1660
+ customerName: tempOrder.customer_name,
1661
+ countryCallingCode: tempOrder.country_calling_code,
1662
+ phone: tempOrder.phone,
1663
+ email: tempOrder.email
1664
+ });
1171
1665
  this.persistTempOrder();
1172
1666
  return {
1173
1667
  customerId: tempOrder.customer_id,
@@ -1179,28 +1673,43 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1179
1673
  }, {
1180
1674
  key: "setOrderCustomer",
1181
1675
  value: function setOrderCustomer(patch, snapshot) {
1676
+ var _tempOrder$customer_i2, _tempOrder$customer_i3;
1182
1677
  if (!patch) {
1183
1678
  this.clearOrderCustomer();
1184
1679
  return;
1185
1680
  }
1186
1681
  var tempOrder = this.ensureTempOrder();
1682
+ var previousCustomerId = (_tempOrder$customer_i2 = tempOrder.customer_id) !== null && _tempOrder$customer_i2 !== void 0 ? _tempOrder$customer_i2 : null;
1187
1683
  tempOrder.customer_id = patch.customer_id || patch.id || null;
1188
1684
  tempOrder.customer_name = String(patch.customer_name || '');
1189
1685
  tempOrder.country_calling_code = String(patch.country_calling_code || '');
1190
1686
  tempOrder.phone = String(patch.phone || '');
1191
1687
  tempOrder.email = String(patch.email || '');
1688
+ tempOrder.customer = this.buildTempOrderCustomer({
1689
+ source: snapshot || null,
1690
+ customerId: tempOrder.customer_id,
1691
+ customerName: tempOrder.customer_name,
1692
+ countryCallingCode: tempOrder.country_calling_code,
1693
+ phone: tempOrder.phone,
1694
+ email: tempOrder.email
1695
+ });
1192
1696
  if (snapshot !== undefined) {
1193
1697
  var extend = this.ensureExtend(tempOrder);
1194
1698
  if (snapshot === null) delete extend.customerSnapshot;else extend.customerSnapshot = cloneDeep(snapshot);
1195
1699
  }
1700
+ var nextCustomerId = (_tempOrder$customer_i3 = tempOrder.customer_id) !== null && _tempOrder$customer_i3 !== void 0 ? _tempOrder$customer_i3 : null;
1701
+ if (String(previousCustomerId !== null && previousCustomerId !== void 0 ? previousCustomerId : '') !== String(nextCustomerId !== null && nextCustomerId !== void 0 ? nextCustomerId : '')) {
1702
+ clearTempOrderHolderAssignments(tempOrder);
1703
+ }
1196
1704
  this.persistTempOrder();
1705
+ this.saveDraftInBackground();
1197
1706
  this.emitOrderCustomerChange();
1198
1707
  }
1199
1708
  }, {
1200
1709
  key: "getOrderCustomer",
1201
1710
  value: function getOrderCustomer() {
1202
1711
  var tempOrder = this.store.tempOrder;
1203
- if (!tempOrder || tempOrder.customer_id === null || tempOrder.customer_id === undefined) {
1712
+ if (!tempOrder || !tempOrder.customer_id) {
1204
1713
  return null;
1205
1714
  }
1206
1715
  return {
@@ -1214,21 +1723,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1214
1723
  }, {
1215
1724
  key: "getOrderCustomerSnapshot",
1216
1725
  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;
1726
+ var _this$store$tempOrder4;
1727
+ 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
1728
  return snapshot ? cloneDeep(snapshot) : null;
1220
1729
  }
1221
1730
  }, {
1222
1731
  key: "clearOrderCustomer",
1223
1732
  value: function clearOrderCustomer() {
1224
1733
  var tempOrder = this.ensureTempOrder();
1734
+ clearTempOrderHolderAssignments(tempOrder);
1225
1735
  tempOrder.customer_id = null;
1226
1736
  tempOrder.customer_name = '';
1227
1737
  tempOrder.country_calling_code = '';
1228
1738
  tempOrder.phone = '';
1229
1739
  tempOrder.email = '';
1740
+ tempOrder.customer = null;
1230
1741
  if (tempOrder._extend) delete tempOrder._extend.customerSnapshot;
1231
1742
  this.persistTempOrder();
1743
+ this.saveDraftInBackground();
1232
1744
  this.core.effects.emit(OrderHooks.OnOrderCustomerChange, null);
1233
1745
  }
1234
1746
  }, {
@@ -1279,6 +1791,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1279
1791
  }, {
1280
1792
  key: "addOrderPayment",
1281
1793
  value: function addOrderPayment(payment) {
1794
+ this.logInfo('addOrderPayment', {
1795
+ payment: payment
1796
+ });
1282
1797
  var tempOrder = this.ensureTempOrder();
1283
1798
  var mapped = mapPaymentItemsToOrderPayments([payment]);
1284
1799
  tempOrder.payments = [].concat(_toConsumableArray(tempOrder.payments || []), _toConsumableArray(mapped));
@@ -1358,45 +1873,45 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1358
1873
  }, {
1359
1874
  key: "shouldMergeProductToOrder",
1360
1875
  value: function () {
1361
- var _shouldMergeProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(params) {
1876
+ var _shouldMergeProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(params) {
1362
1877
  var _this$orderHooks;
1363
1878
  var onBeforeMergeProductToOrder, result;
1364
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1365
- while (1) switch (_context12.prev = _context12.next) {
1879
+ return _regeneratorRuntime().wrap(function _callee15$(_context17) {
1880
+ while (1) switch (_context17.prev = _context17.next) {
1366
1881
  case 0:
1367
1882
  onBeforeMergeProductToOrder = (_this$orderHooks = this.orderHooks) === null || _this$orderHooks === void 0 ? void 0 : _this$orderHooks.onBeforeMergeProductToOrder;
1368
1883
  if (onBeforeMergeProductToOrder) {
1369
- _context12.next = 3;
1884
+ _context17.next = 3;
1370
1885
  break;
1371
1886
  }
1372
- return _context12.abrupt("return", true);
1887
+ return _context17.abrupt("return", true);
1373
1888
  case 3:
1374
- _context12.next = 5;
1889
+ _context17.next = 5;
1375
1890
  return onBeforeMergeProductToOrder(_objectSpread(_objectSpread({}, params), {}, {
1376
1891
  defaultShouldMerge: true
1377
1892
  }));
1378
1893
  case 5:
1379
- result = _context12.sent;
1894
+ result = _context17.sent;
1380
1895
  if (!(typeof result === 'boolean')) {
1381
- _context12.next = 8;
1896
+ _context17.next = 8;
1382
1897
  break;
1383
1898
  }
1384
- return _context12.abrupt("return", result);
1899
+ return _context17.abrupt("return", result);
1385
1900
  case 8:
1386
1901
  if (!(result && _typeof(result) === 'object' && typeof result.shouldMerge === 'boolean')) {
1387
- _context12.next = 10;
1902
+ _context17.next = 10;
1388
1903
  break;
1389
1904
  }
1390
- return _context12.abrupt("return", result.shouldMerge);
1905
+ return _context17.abrupt("return", result.shouldMerge);
1391
1906
  case 10:
1392
- return _context12.abrupt("return", true);
1907
+ return _context17.abrupt("return", true);
1393
1908
  case 11:
1394
1909
  case "end":
1395
- return _context12.stop();
1910
+ return _context17.stop();
1396
1911
  }
1397
- }, _callee12, this);
1912
+ }, _callee15, this);
1398
1913
  }));
1399
- function shouldMergeProductToOrder(_x11) {
1914
+ function shouldMergeProductToOrder(_x15) {
1400
1915
  return _shouldMergeProductToOrder.apply(this, arguments);
1401
1916
  }
1402
1917
  return shouldMergeProductToOrder;
@@ -1404,11 +1919,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1404
1919
  }, {
1405
1920
  key: "addProductToOrder",
1406
1921
  value: function () {
1407
- var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(product, booking) {
1408
- var _this3 = this;
1922
+ var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(product, booking) {
1923
+ var _this6 = this;
1409
1924
  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) {
1925
+ return _regeneratorRuntime().wrap(function _callee16$(_context18) {
1926
+ while (1) switch (_context18.prev = _context18.next) {
1412
1927
  case 0:
1413
1928
  tempOrder = this.ensureTempOrder();
1414
1929
  linked = booking ? this.createLinkedProductAndBooking({
@@ -1418,10 +1933,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1418
1933
  productToAdd = (linked === null || linked === void 0 ? void 0 : linked.product) || product;
1419
1934
  incomingFingerprint = buildProductLineFingerprint(productToAdd.product_option_item, productToAdd.product_bundle);
1420
1935
  normalizedIncoming = normalizeOrderProduct(productToAdd);
1936
+ normalizedIncoming.discount_list = normalizeOrderProductDiscountList(normalizedIncoming.discount_list);
1421
1937
  hasIncomingGoodPass = this.hasGoodPassDiscount(normalizedIncoming);
1422
1938
  shouldForceNewLine = !!booking;
1423
1939
  matchedIndex = hasIncomingGoodPass || shouldForceNewLine ? -1 : tempOrder.products.findIndex(function (item) {
1424
- if (_this3.hasGoodPassDiscount(item)) return false;
1940
+ if (_this6.hasGoodPassDiscount(item)) return false;
1425
1941
  if (item.product_id !== productToAdd.product_id) return false;
1426
1942
  if (item.product_variant_id !== productToAdd.product_variant_id) return false;
1427
1943
  var existedFingerprint = buildProductLineFingerprint(item.product_option_item, item.product_bundle);
@@ -1430,10 +1946,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1430
1946
  matchedProduct = matchedIndex === -1 ? null : tempOrder.products[matchedIndex];
1431
1947
  existedFingerprint = matchedProduct ? buildProductLineFingerprint(matchedProduct.product_option_item, matchedProduct.product_bundle) : '';
1432
1948
  if (!matchedProduct) {
1433
- _context13.next = 16;
1949
+ _context18.next = 17;
1434
1950
  break;
1435
1951
  }
1436
- _context13.next = 13;
1952
+ _context18.next = 14;
1437
1953
  return this.shouldMergeProductToOrder({
1438
1954
  incomingProduct: productToAdd,
1439
1955
  normalizedIncoming: normalizedIncoming,
@@ -1444,14 +1960,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1444
1960
  tempOrder: tempOrder,
1445
1961
  booking: booking
1446
1962
  });
1447
- case 13:
1448
- _context13.t0 = _context13.sent;
1449
- _context13.next = 17;
1963
+ case 14:
1964
+ _context18.t0 = _context18.sent;
1965
+ _context18.next = 18;
1450
1966
  break;
1451
- case 16:
1452
- _context13.t0 = false;
1453
1967
  case 17:
1454
- shouldMerge = _context13.t0;
1968
+ _context18.t0 = false;
1969
+ case 18:
1970
+ shouldMerge = _context18.t0;
1455
1971
  if (matchedIndex === -1 || !matchedProduct || !shouldMerge) {
1456
1972
  this.captureProductRuntime(tempOrder, productToAdd, normalizedIncoming);
1457
1973
  if (linked) {
@@ -1469,6 +1985,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1469
1985
  unique_identification_number: targetUid
1470
1986
  })
1471
1987
  }));
1988
+ normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
1472
1989
  tempOrder.products[matchedIndex] = _objectSpread(_objectSpread(_objectSpread({}, targetProduct), normalizedProduct), {}, {
1473
1990
  metadata: _objectSpread(_objectSpread(_objectSpread({}, targetProduct.metadata || {}), normalizedProduct.metadata || {}), {}, {
1474
1991
  unique_identification_number: targetUid
@@ -1482,21 +1999,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1482
1999
  if (linked) {
1483
2000
  tempOrder.bookings = [].concat(_toConsumableArray(tempOrder.bookings || []), [linked.booking]);
1484
2001
  }
2002
+ _context18.next = 23;
2003
+ return this.applyPromotion();
2004
+ case 23:
1485
2005
  this.applyDiscount();
1486
- _context13.next = 23;
2006
+ _context18.next = 26;
1487
2007
  return this.recalculateSummary({
1488
2008
  createIfMissing: true
1489
2009
  });
1490
- case 23:
2010
+ case 26:
1491
2011
  this.persistTempOrder();
1492
- return _context13.abrupt("return", tempOrder.products);
1493
- case 25:
2012
+ return _context18.abrupt("return", tempOrder.products);
2013
+ case 28:
1494
2014
  case "end":
1495
- return _context13.stop();
2015
+ return _context18.stop();
1496
2016
  }
1497
- }, _callee13, this);
2017
+ }, _callee16, this);
1498
2018
  }));
1499
- function addProductToOrder(_x12, _x13) {
2019
+ function addProductToOrder(_x16, _x17) {
1500
2020
  return _addProductToOrder.apply(this, arguments);
1501
2021
  }
1502
2022
  return addProductToOrder;
@@ -1521,15 +2041,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1521
2041
  });
1522
2042
  }
1523
2043
  }, {
1524
- key: "updateProductInOrder",
2044
+ key: "updateOrderProduct",
1525
2045
  value: function () {
1526
- var _updateProductInOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(params) {
2046
+ var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(params) {
1527
2047
  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) {
2048
+ 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;
2049
+ return _regeneratorRuntime().wrap(function _callee17$(_context19) {
2050
+ while (1) switch (_context19.prev = _context19.next) {
1531
2051
  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;
2052
+ 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
2053
  tempOrder = this.ensureTempOrder();
1534
2054
  identityLookup = {
1535
2055
  product_id: product_id,
@@ -1537,16 +2057,32 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1537
2057
  };
1538
2058
  if (unique_identification_number !== undefined) {
1539
2059
  identityLookup.unique_identification_number = unique_identification_number;
2060
+ if (identity_key === undefined) {
2061
+ identityLookup.identity_key = unique_identification_number;
2062
+ }
2063
+ }
2064
+ if (identity_key !== undefined) {
2065
+ identityLookup.identity_key = identity_key;
1540
2066
  }
1541
2067
  if (product_option_item !== undefined) identityLookup.product_option_item = product_option_item;
1542
2068
  if (product_bundle !== undefined) identityLookup.product_bundle = product_bundle;
1543
- productIndex = getProductIdentityIndex(tempOrder.products, identityLookup);
2069
+ productIndex = -1;
2070
+ if (unique_identification_number !== undefined) {
2071
+ targetUid = String(unique_identification_number);
2072
+ productIndex = tempOrder.products.findIndex(function (item) {
2073
+ var _item$metadata;
2074
+ return String(((_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.unique_identification_number) || item.unique_identification_number || '') === targetUid;
2075
+ });
2076
+ }
2077
+ if (productIndex === -1) {
2078
+ productIndex = getProductIdentityIndex(tempOrder.products, identityLookup);
2079
+ }
1544
2080
  if (!(productIndex === -1)) {
1545
- _context14.next = 9;
2081
+ _context19.next = 12;
1546
2082
  break;
1547
2083
  }
1548
2084
  throw new Error('[Order] 目标商品不存在,无法更新');
1549
- case 9:
2085
+ case 12:
1550
2086
  targetProduct = tempOrder.products[productIndex];
1551
2087
  nextProduct = _objectSpread(_objectSpread(_objectSpread({}, targetProduct), updates), {}, {
1552
2088
  product_id: product_id,
@@ -1574,57 +2110,230 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1574
2110
  }
1575
2111
  // normalizeOrderProduct 幂等:v2 metadata 存在 → 保留 main_product_* 折扣重算 composite;
1576
2112
  // 否则 → 把顶层 selling_price 视作 source,派生 main_product_* 并写 price_schema_version: 2。
1577
- tempOrder.products[productIndex] = normalizeOrderProduct(nextProduct);
2113
+ normalizedProduct = normalizeOrderProduct(nextProduct);
2114
+ normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
2115
+ if (booking) {
2116
+ 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());
2117
+ normalizedProduct.metadata = _objectSpread(_objectSpread({}, normalizedProduct.metadata || {}), {}, {
2118
+ unique_identification_number: productUid
2119
+ });
2120
+ linked = this.createLinkedProductAndBooking({
2121
+ product: _objectSpread(_objectSpread({}, normalizedProduct), {}, {
2122
+ unique_identification_number: productUid
2123
+ }),
2124
+ booking: booking
2125
+ });
2126
+ this.removeLinkedBookingsForProduct(tempOrder, targetProduct);
2127
+ normalizedProduct = _objectSpread(_objectSpread({}, normalizedProduct), {}, {
2128
+ booking_uid: linked.bookingUid,
2129
+ metadata: _objectSpread(_objectSpread({}, normalizedProduct.metadata || {}), {}, {
2130
+ booking_uid: linked.bookingUid,
2131
+ unique_identification_number: productUid
2132
+ })
2133
+ });
2134
+ tempOrder.bookings = [].concat(_toConsumableArray(tempOrder.bookings || []), [linked.booking]);
2135
+ }
2136
+ tempOrder.products[productIndex] = normalizedProduct;
1578
2137
  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);
2138
+ _context19.next = 25;
2139
+ return this.applyPromotion();
2140
+ case 25:
1579
2141
  this.applyDiscount();
1580
- _context14.next = 20;
2142
+ _context19.next = 28;
1581
2143
  return this.recalculateSummary({
1582
2144
  createIfMissing: true
1583
2145
  });
1584
- case 20:
2146
+ case 28:
1585
2147
  this.persistTempOrder();
1586
- return _context14.abrupt("return", tempOrder.products);
1587
- case 22:
2148
+ return _context19.abrupt("return", tempOrder.products);
2149
+ case 30:
1588
2150
  case "end":
1589
- return _context14.stop();
2151
+ return _context19.stop();
1590
2152
  }
1591
- }, _callee14, this);
2153
+ }, _callee17, this);
2154
+ }));
2155
+ function updateOrderProduct(_x18) {
2156
+ return _updateOrderProduct.apply(this, arguments);
2157
+ }
2158
+ return updateOrderProduct;
2159
+ }()
2160
+ }, {
2161
+ key: "updateOrderProductQuantity",
2162
+ value: function () {
2163
+ var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(params) {
2164
+ var _targetProduct$metada4;
2165
+ var product_id, product_variant_id, num, unique_identification_number, identity_key, product_option_item, product_bundle, tempOrder, identityLookup, productIndex, targetUid, targetProduct, normalizedProduct;
2166
+ return _regeneratorRuntime().wrap(function _callee18$(_context20) {
2167
+ while (1) switch (_context20.prev = _context20.next) {
2168
+ case 0:
2169
+ 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;
2170
+ tempOrder = this.ensureTempOrder();
2171
+ identityLookup = {
2172
+ product_id: product_id,
2173
+ product_variant_id: product_variant_id
2174
+ };
2175
+ if (unique_identification_number !== undefined) {
2176
+ identityLookup.unique_identification_number = unique_identification_number;
2177
+ if (identity_key === undefined) {
2178
+ identityLookup.identity_key = unique_identification_number;
2179
+ }
2180
+ }
2181
+ if (identity_key !== undefined) identityLookup.identity_key = identity_key;
2182
+ if (product_option_item !== undefined) identityLookup.product_option_item = product_option_item;
2183
+ if (product_bundle !== undefined) identityLookup.product_bundle = product_bundle;
2184
+ productIndex = -1;
2185
+ if (unique_identification_number !== undefined) {
2186
+ targetUid = String(unique_identification_number);
2187
+ productIndex = tempOrder.products.findIndex(function (item) {
2188
+ var _item$metadata2;
2189
+ return String(((_item$metadata2 = item.metadata) === null || _item$metadata2 === void 0 ? void 0 : _item$metadata2.unique_identification_number) || item.unique_identification_number || '') === targetUid;
2190
+ });
2191
+ }
2192
+ if (productIndex === -1) {
2193
+ productIndex = getProductIdentityIndex(tempOrder.products, identityLookup);
2194
+ }
2195
+ if (!(productIndex === -1)) {
2196
+ _context20.next = 12;
2197
+ break;
2198
+ }
2199
+ throw new Error('[Order] 目标商品不存在,无法更新数量');
2200
+ case 12:
2201
+ targetProduct = tempOrder.products[productIndex];
2202
+ normalizedProduct = normalizeOrderProduct(_objectSpread(_objectSpread({}, targetProduct), {}, {
2203
+ num: getSafeProductNum(num),
2204
+ metadata: _objectSpread(_objectSpread({}, targetProduct.metadata || {}), {}, {
2205
+ unique_identification_number: ((_targetProduct$metada4 = targetProduct.metadata) === null || _targetProduct$metada4 === void 0 ? void 0 : _targetProduct$metada4.unique_identification_number) || unique_identification_number
2206
+ })
2207
+ }));
2208
+ normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
2209
+ tempOrder.products[productIndex] = normalizedProduct;
2210
+ _context20.next = 18;
2211
+ return this.applyPromotion();
2212
+ case 18:
2213
+ this.applyDiscount();
2214
+ _context20.next = 21;
2215
+ return this.recalculateSummary({
2216
+ createIfMissing: true
2217
+ });
2218
+ case 21:
2219
+ this.persistTempOrder();
2220
+ return _context20.abrupt("return", tempOrder.products);
2221
+ case 23:
2222
+ case "end":
2223
+ return _context20.stop();
2224
+ }
2225
+ }, _callee18, this);
1592
2226
  }));
1593
- function updateProductInOrder(_x14) {
1594
- return _updateProductInOrder.apply(this, arguments);
2227
+ function updateOrderProductQuantity(_x19) {
2228
+ return _updateOrderProductQuantity.apply(this, arguments);
1595
2229
  }
1596
- return updateProductInOrder;
2230
+ return updateOrderProductQuantity;
1597
2231
  }()
2232
+ }, {
2233
+ key: "updateOrderBooking",
2234
+ value: function updateOrderBooking(params) {
2235
+ var unique_identification_number = params.unique_identification_number,
2236
+ updates = params.updates;
2237
+ var tempOrder = this.ensureTempOrder();
2238
+ var bookingUid = String(unique_identification_number || '');
2239
+ var bookingIndex = this.findBookingIndexByUniqueIdentificationNumber(tempOrder, bookingUid);
2240
+ if (!bookingUid || bookingIndex === -1) {
2241
+ throw new Error('[Order] 目标 booking 不存在,无法更新');
2242
+ }
2243
+ var targetBooking = tempOrder.bookings[bookingIndex] || {};
2244
+ var nextBooking = _objectSpread(_objectSpread(_objectSpread({}, targetBooking), updates), {}, {
2245
+ metadata: _objectSpread(_objectSpread(_objectSpread({}, targetBooking.metadata || {}), updates.metadata || {}), {}, {
2246
+ unique_identification_number: bookingUid
2247
+ })
2248
+ });
2249
+ nextBooking.is_all = normalizeBookingIsAll(nextBooking);
2250
+ nextBooking.sub_type = normalizeBookingSubType(nextBooking);
2251
+ tempOrder.bookings[bookingIndex] = nextBooking;
2252
+ this.persistTempOrder();
2253
+ return tempOrder.bookings;
2254
+ }
1598
2255
  }, {
1599
2256
  key: "removeProductFromOrder",
1600
2257
  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) {
2258
+ var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(identity) {
2259
+ var tempOrder, removedProducts, _i, _removedProducts, product;
2260
+ return _regeneratorRuntime().wrap(function _callee19$(_context21) {
2261
+ while (1) switch (_context21.prev = _context21.next) {
1605
2262
  case 0:
1606
2263
  tempOrder = this.ensureTempOrder();
2264
+ removedProducts = [];
1607
2265
  tempOrder.products = tempOrder.products.filter(function (item) {
1608
- return !isIdentityMatch(item, identity);
2266
+ var shouldRemove = isIdentityMatch(item, identity);
2267
+ if (shouldRemove) removedProducts.push(item);
2268
+ return !shouldRemove;
1609
2269
  });
2270
+ for (_i = 0, _removedProducts = removedProducts; _i < _removedProducts.length; _i++) {
2271
+ product = _removedProducts[_i];
2272
+ this.removeLinkedBookingsForProduct(tempOrder, product);
2273
+ }
2274
+ _context21.next = 6;
2275
+ return this.applyPromotion();
2276
+ case 6:
1610
2277
  this.applyDiscount();
1611
- _context15.next = 5;
2278
+ _context21.next = 9;
1612
2279
  return this.recalculateSummary({
1613
2280
  createIfMissing: true
1614
2281
  });
1615
- case 5:
2282
+ case 9:
1616
2283
  this.persistTempOrder();
1617
- return _context15.abrupt("return", tempOrder.products);
1618
- case 7:
2284
+ return _context21.abrupt("return", tempOrder.products);
2285
+ case 11:
1619
2286
  case "end":
1620
- return _context15.stop();
2287
+ return _context21.stop();
1621
2288
  }
1622
- }, _callee15, this);
2289
+ }, _callee19, this);
1623
2290
  }));
1624
- function removeProductFromOrder(_x15) {
2291
+ function removeProductFromOrder(_x20) {
1625
2292
  return _removeProductFromOrder.apply(this, arguments);
1626
2293
  }
1627
2294
  return removeProductFromOrder;
2295
+ }()
2296
+ /**
2297
+ * 仅清空购物车行(products / bookings),不重置整单。
2298
+ * 用于「仅清空商品」;客户、备注、支付等协议字段保持不变。
2299
+ */
2300
+ }, {
2301
+ key: "clearOrderCartLines",
2302
+ value: (function () {
2303
+ var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
2304
+ var tempOrder;
2305
+ return _regeneratorRuntime().wrap(function _callee20$(_context22) {
2306
+ while (1) switch (_context22.prev = _context22.next) {
2307
+ case 0:
2308
+ tempOrder = this.ensureTempOrder();
2309
+ tempOrder.products = [];
2310
+ tempOrder.bookings = [];
2311
+ if (tempOrder._extend && _typeof(tempOrder._extend) === 'object') {
2312
+ tempOrder._extend = _objectSpread(_objectSpread({}, tempOrder._extend), {}, {
2313
+ productsByUid: {}
2314
+ });
2315
+ }
2316
+ _context22.next = 6;
2317
+ return this.applyPromotion();
2318
+ case 6:
2319
+ this.applyDiscount();
2320
+ _context22.next = 9;
2321
+ return this.recalculateSummary({
2322
+ createIfMissing: true
2323
+ });
2324
+ case 9:
2325
+ this.persistTempOrder();
2326
+ return _context22.abrupt("return", tempOrder);
2327
+ case 11:
2328
+ case "end":
2329
+ return _context22.stop();
2330
+ }
2331
+ }, _callee20, this);
2332
+ }));
2333
+ function clearOrderCartLines() {
2334
+ return _clearOrderCartLines.apply(this, arguments);
2335
+ }
2336
+ return clearOrderCartLines;
1628
2337
  }() // ─── TempOrder: 提交 ───
1629
2338
  /**
1630
2339
  * 提交当前 Sales tempOrder。
@@ -1632,14 +2341,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1632
2341
  * smallTicketDataFlag 用于 B 端 checkout 小票数据返回。PaymentModal 在支付提交时
1633
2342
  * 应传 1,确保 /order/sales/checkout 返回打印所需数据。
1634
2343
  */
2344
+ )
1635
2345
  }, {
1636
2346
  key: "submitTempOrder",
1637
2347
  value: function () {
1638
- var _submitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(params) {
2348
+ var _submitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(params) {
1639
2349
  var _params$cacheId, _this$otherParams;
1640
2350
  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) {
2351
+ return _regeneratorRuntime().wrap(function _callee21$(_context23) {
2352
+ while (1) switch (_context23.prev = _context23.next) {
1643
2353
  case 0:
1644
2354
  tempOrder = this.ensureTempOrder();
1645
2355
  this.persistTempOrder();
@@ -1655,7 +2365,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1655
2365
  } : {}), hasSmallTicketDataFlagOverride ? {
1656
2366
  small_ticket_data_flag: params === null || params === void 0 ? void 0 : params.smallTicketDataFlag
1657
2367
  } : {});
1658
- return params !== null && params !== void 0 && params.enhancePayload ? params.enhancePayload(nextPayload, ctx) : nextPayload;
2368
+ var enhancedPayload = params !== null && params !== void 0 && params.enhancePayload ? params.enhancePayload(nextPayload, ctx) : nextPayload;
2369
+ return enhancedPayload;
1659
2370
  } : undefined;
1660
2371
  payload = buildSubmitPayload({
1661
2372
  tempOrder: tempOrder,
@@ -1666,73 +2377,74 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1666
2377
  type: params === null || params === void 0 ? void 0 : params.type,
1667
2378
  enhance: enhancePayload
1668
2379
  });
1669
- _context16.next = 10;
2380
+ _context23.next = 10;
1670
2381
  return this.saveDraft();
1671
2382
  case 10:
1672
- _context16.prev = 10;
2383
+ _context23.prev = 10;
1673
2384
  this.logInfo('submitTempOrder calling sales checkout', {
1674
2385
  orderId: payload.order_id,
1675
2386
  externalSaleNumber: payload.external_sale_number,
2387
+ requestUniqueIdempotencyToken: payload.request_unique_idempotency_token,
1676
2388
  paymentStatus: payload.payment_status,
1677
2389
  paymentsCount: ((_payload$payments = payload.payments) === null || _payload$payments === void 0 ? void 0 : _payload$payments.length) || 0,
1678
2390
  smallTicketDataFlag: payload.small_ticket_data_flag
1679
2391
  });
1680
- _context16.next = 14;
2392
+ _context23.next = 14;
1681
2393
  return this.submitSalesOrder({
1682
2394
  query: payload
1683
2395
  });
1684
2396
  case 14:
1685
- result = _context16.sent;
1686
- _context16.next = 27;
2397
+ result = _context23.sent;
2398
+ _context23.next = 27;
1687
2399
  break;
1688
2400
  case 17:
1689
- _context16.prev = 17;
1690
- _context16.t0 = _context16["catch"](10);
1691
- backendErrorResponse = this.extractSubmitErrorResponse(_context16.t0);
2401
+ _context23.prev = 17;
2402
+ _context23.t0 = _context23["catch"](10);
2403
+ backendErrorResponse = this.extractSubmitErrorResponse(_context23.t0);
1692
2404
  if (!backendErrorResponse) {
1693
- _context16.next = 24;
2405
+ _context23.next = 24;
1694
2406
  break;
1695
2407
  }
1696
2408
  this.store.syncState = 'failed';
1697
2409
  this.logSubmitBackendRejected(backendErrorResponse, payload);
1698
- return _context16.abrupt("return", backendErrorResponse);
2410
+ return _context23.abrupt("return", backendErrorResponse);
1699
2411
  case 24:
1700
2412
  this.store.syncState = 'failed';
1701
2413
  this.logError('submitTempOrder failed', {
1702
- error: _context16.t0 instanceof Error ? _context16.t0.message : String(_context16.t0),
2414
+ error: _context23.t0 instanceof Error ? _context23.t0.message : String(_context23.t0),
1703
2415
  orderId: payload.order_id,
1704
2416
  externalSaleNumber: payload.external_sale_number,
1705
2417
  paymentStatus: payload.payment_status,
1706
2418
  paymentsCount: ((_payload$payments2 = payload.payments) === null || _payload$payments2 === void 0 ? void 0 : _payload$payments2.length) || 0
1707
2419
  });
1708
- throw _context16.t0;
2420
+ throw _context23.t0;
1709
2421
  case 27:
1710
2422
  if (!this.isSubmitResponseRejected(result)) {
1711
- _context16.next = 31;
2423
+ _context23.next = 31;
1712
2424
  break;
1713
2425
  }
1714
2426
  this.store.syncState = 'failed';
1715
2427
  this.logSubmitBackendRejected(result, payload);
1716
- return _context16.abrupt("return", result);
2428
+ return _context23.abrupt("return", result);
1717
2429
  case 31:
1718
2430
  submittedOrderId = this.extractOrderIdFromSubmitResult(result);
1719
2431
  if (!(submittedOrderId !== null && submittedOrderId !== undefined)) {
1720
- _context16.next = 37;
2432
+ _context23.next = 37;
1721
2433
  break;
1722
2434
  }
1723
2435
  tempOrder.order_id = submittedOrderId;
1724
2436
  resultRecord = result;
1725
- _context16.next = 37;
2437
+ _context23.next = 37;
1726
2438
  return this.markLocalOrderSynced(submittedOrderId, (resultRecord === null || resultRecord === void 0 ? void 0 : resultRecord.data) || resultRecord || {});
1727
2439
  case 37:
1728
- return _context16.abrupt("return", result);
2440
+ return _context23.abrupt("return", result);
1729
2441
  case 38:
1730
2442
  case "end":
1731
- return _context16.stop();
2443
+ return _context23.stop();
1732
2444
  }
1733
- }, _callee16, this, [[10, 17]]);
2445
+ }, _callee21, this, [[10, 17]]);
1734
2446
  }));
1735
- function submitTempOrder(_x16) {
2447
+ function submitTempOrder(_x21) {
1736
2448
  return _submitTempOrder.apply(this, arguments);
1737
2449
  }
1738
2450
  return submitTempOrder;
@@ -1740,25 +2452,25 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1740
2452
  }, {
1741
2453
  key: "markLocalOrderSynced",
1742
2454
  value: function () {
1743
- var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(orderId, remoteOrder) {
2455
+ var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(orderId, remoteOrder) {
1744
2456
  var tempOrder;
1745
- return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1746
- while (1) switch (_context17.prev = _context17.next) {
2457
+ return _regeneratorRuntime().wrap(function _callee22$(_context24) {
2458
+ while (1) switch (_context24.prev = _context24.next) {
1747
2459
  case 0:
1748
2460
  tempOrder = this.ensureTempOrder();
1749
2461
  tempOrder.order_id = orderId;
1750
2462
  this.store.lastOrderInfo = remoteOrder;
1751
2463
  this.store.syncState = 'submitted';
1752
2464
  this.persistTempOrder();
1753
- _context17.next = 7;
2465
+ _context24.next = 7;
1754
2466
  return this.saveDraft();
1755
2467
  case 7:
1756
2468
  case "end":
1757
- return _context17.stop();
2469
+ return _context24.stop();
1758
2470
  }
1759
- }, _callee17, this);
2471
+ }, _callee22, this);
1760
2472
  }));
1761
- function markLocalOrderSynced(_x17, _x18) {
2473
+ function markLocalOrderSynced(_x22, _x23) {
1762
2474
  return _markLocalOrderSynced.apply(this, arguments);
1763
2475
  }
1764
2476
  return markLocalOrderSynced;
@@ -1782,10 +2494,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1782
2494
  value: function extractSubmitErrorResponse(error) {
1783
2495
  var _error$response,
1784
2496
  _error$response2,
1785
- _this4 = this;
2497
+ _this7 = this;
1786
2498
  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
2499
  return candidates.find(function (candidate) {
1788
- return _this4.isSubmitErrorResponse(candidate);
2500
+ return _this7.isSubmitErrorResponse(candidate);
1789
2501
  }) || null;
1790
2502
  }
1791
2503
  }, {
@@ -1805,49 +2517,67 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1805
2517
  }, {
1806
2518
  key: "syncPaymentsToOrder",
1807
2519
  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) {
2520
+ var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(params) {
2521
+ var tempOrder, mappedPayments, paymentTotal, targetAmount, isFullyPaid, paymentStatus, paymentSyncIdempotencyToken, submitResult;
2522
+ return _regeneratorRuntime().wrap(function _callee23$(_context25) {
2523
+ while (1) switch (_context25.prev = _context25.next) {
1812
2524
  case 0:
1813
2525
  tempOrder = this.ensureTempOrder();
1814
2526
  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
2527
  paymentTotal = this.calculatePaymentTotal(mappedPayments);
1822
2528
  targetAmount = this.getPaymentTargetAmount();
1823
2529
  isFullyPaid = targetAmount.lte(0) ? false : paymentTotal.gte(targetAmount);
1824
- if (!(!isFullyPaid || !params.submitWhenPaid)) {
1825
- _context18.next = 12;
2530
+ paymentStatus = isFullyPaid ? params.paymentStatus || 'paid' : 'partially_paid';
2531
+ tempOrder.payments = mappedPayments;
2532
+ tempOrder.payment_status = paymentStatus;
2533
+ this.persistTempOrder();
2534
+ _context25.next = 11;
2535
+ return this.saveDraft();
2536
+ case 11:
2537
+ if (params.submitWhenPaid) {
2538
+ _context25.next = 13;
1826
2539
  break;
1827
2540
  }
1828
- return _context18.abrupt("return", {
2541
+ return _context25.abrupt("return", {
1829
2542
  isFullyPaid: isFullyPaid
1830
2543
  });
1831
- case 12:
1832
- _context18.next = 14;
2544
+ case 13:
2545
+ if (!(this.store.syncState === 'submitting')) {
2546
+ _context25.next = 15;
2547
+ break;
2548
+ }
2549
+ return _context25.abrupt("return", {
2550
+ isFullyPaid: isFullyPaid
2551
+ });
2552
+ case 15:
2553
+ this.store.syncState = 'submitting';
2554
+ paymentSyncIdempotencyToken = this.buildPaymentSyncIdempotencyToken(tempOrder, mappedPayments);
2555
+ _context25.next = 19;
1833
2556
  return this.submitTempOrder({
1834
2557
  payments: mappedPayments,
1835
- paymentStatus: params.paymentStatus || 'paid',
1836
- smallTicketDataFlag: params.smallTicketDataFlag
2558
+ paymentStatus: paymentStatus,
2559
+ smallTicketDataFlag: params.smallTicketDataFlag,
2560
+ channel: params.channel,
2561
+ enhancePayload: function enhancePayload(payload) {
2562
+ var nextPayload = _objectSpread(_objectSpread({}, payload), {}, {
2563
+ request_unique_idempotency_token: paymentSyncIdempotencyToken
2564
+ });
2565
+ return nextPayload;
2566
+ }
1837
2567
  });
1838
- case 14:
1839
- submitResult = _context18.sent;
1840
- return _context18.abrupt("return", {
2568
+ case 19:
2569
+ submitResult = _context25.sent;
2570
+ return _context25.abrupt("return", {
1841
2571
  isFullyPaid: isFullyPaid,
1842
2572
  submitResult: submitResult
1843
2573
  });
1844
- case 16:
2574
+ case 21:
1845
2575
  case "end":
1846
- return _context18.stop();
2576
+ return _context25.stop();
1847
2577
  }
1848
- }, _callee18, this);
2578
+ }, _callee23, this);
1849
2579
  }));
1850
- function syncPaymentsToOrder(_x19) {
2580
+ function syncPaymentsToOrder(_x24) {
1851
2581
  return _syncPaymentsToOrder.apply(this, arguments);
1852
2582
  }
1853
2583
  return syncPaymentsToOrder;
@@ -1936,11 +2666,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1936
2666
  }, {
1937
2667
  key: "submitOrder",
1938
2668
  value: function () {
1939
- var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(order) {
2669
+ var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(order) {
1940
2670
  var _order$query$cartItem, _params$bookings, _params$relation_prod;
1941
2671
  var url, query, fetchUrl, params;
1942
- return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1943
- while (1) switch (_context19.prev = _context19.next) {
2672
+ return _regeneratorRuntime().wrap(function _callee24$(_context26) {
2673
+ while (1) switch (_context26.prev = _context26.next) {
1944
2674
  case 0:
1945
2675
  this.logInfo('submitOrder called', {
1946
2676
  url: order.url,
@@ -1960,14 +2690,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1960
2690
  relationProductsCount: ((_params$relation_prod = params.relation_products) === null || _params$relation_prod === void 0 ? void 0 : _params$relation_prod.length) || 0,
1961
2691
  scheduleDate: params.schedule_date
1962
2692
  });
1963
- return _context19.abrupt("return", this.request.post(fetchUrl, params));
2693
+ return _context26.abrupt("return", this.request.post(fetchUrl, params));
1964
2694
  case 6:
1965
2695
  case "end":
1966
- return _context19.stop();
2696
+ return _context26.stop();
1967
2697
  }
1968
- }, _callee19, this);
2698
+ }, _callee24, this);
1969
2699
  }));
1970
- function submitOrder(_x20) {
2700
+ function submitOrder(_x25) {
1971
2701
  return _submitOrder.apply(this, arguments);
1972
2702
  }
1973
2703
  return submitOrder;
@@ -1975,13 +2705,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1975
2705
  }, {
1976
2706
  key: "cancelOrder",
1977
2707
  value: function () {
1978
- var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(params) {
2708
+ var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(params) {
1979
2709
  var payload;
1980
- return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1981
- while (1) switch (_context20.prev = _context20.next) {
2710
+ return _regeneratorRuntime().wrap(function _callee25$(_context27) {
2711
+ while (1) switch (_context27.prev = _context27.next) {
1982
2712
  case 0:
1983
2713
  if (!(!Array.isArray(params.order_ids) || params.order_ids.length === 0)) {
1984
- _context20.next = 2;
2714
+ _context27.next = 2;
1985
2715
  break;
1986
2716
  }
1987
2717
  throw new Error('取消订单失败:order_ids 不能为空');
@@ -1997,16 +2727,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1997
2727
  method: 'PUT',
1998
2728
  orderIdsCount: params.order_ids.length
1999
2729
  });
2000
- return _context20.abrupt("return", this.request.put('/order/update-status', payload, {
2730
+ return _context27.abrupt("return", this.request.put('/order/update-status', payload, {
2001
2731
  isShopApi: true
2002
2732
  }));
2003
2733
  case 5:
2004
2734
  case "end":
2005
- return _context20.stop();
2735
+ return _context27.stop();
2006
2736
  }
2007
- }, _callee20, this);
2737
+ }, _callee25, this);
2008
2738
  }));
2009
- function cancelOrder(_x21) {
2739
+ function cancelOrder(_x26) {
2010
2740
  return _cancelOrder.apply(this, arguments);
2011
2741
  }
2012
2742
  return cancelOrder;
@@ -2014,19 +2744,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2014
2744
  }, {
2015
2745
  key: "changeBookingStatus",
2016
2746
  value: function () {
2017
- var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(params) {
2747
+ var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(params) {
2018
2748
  var url, payload;
2019
- return _regeneratorRuntime().wrap(function _callee21$(_context21) {
2020
- while (1) switch (_context21.prev = _context21.next) {
2749
+ return _regeneratorRuntime().wrap(function _callee26$(_context28) {
2750
+ while (1) switch (_context28.prev = _context28.next) {
2021
2751
  case 0:
2022
2752
  if (params.booking_id) {
2023
- _context21.next = 2;
2753
+ _context28.next = 2;
2024
2754
  break;
2025
2755
  }
2026
2756
  throw new Error('变更预约状态失败:booking_id 不能为空');
2027
2757
  case 2:
2028
2758
  if (params.appointment_status) {
2029
- _context21.next = 4;
2759
+ _context28.next = 4;
2030
2760
  break;
2031
2761
  }
2032
2762
  throw new Error('变更预约状态失败:appointment_status 不能为空');
@@ -2041,16 +2771,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2041
2771
  bookingId: params.booking_id,
2042
2772
  appointmentStatus: params.appointment_status
2043
2773
  });
2044
- return _context21.abrupt("return", this.request.put(url, payload, {
2774
+ return _context28.abrupt("return", this.request.put(url, payload, {
2045
2775
  isShopApi: true
2046
2776
  }));
2047
2777
  case 8:
2048
2778
  case "end":
2049
- return _context21.stop();
2779
+ return _context28.stop();
2050
2780
  }
2051
- }, _callee21, this);
2781
+ }, _callee26, this);
2052
2782
  }));
2053
- function changeBookingStatus(_x22) {
2783
+ function changeBookingStatus(_x27) {
2054
2784
  return _changeBookingStatus.apply(this, arguments);
2055
2785
  }
2056
2786
  return changeBookingStatus;
@@ -2068,11 +2798,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2068
2798
  }, {
2069
2799
  key: "createOrderByCheckout",
2070
2800
  value: (function () {
2071
- var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(params) {
2801
+ var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(params) {
2072
2802
  var _params$payments, _params$bookings2, _params$relation_prod2, _params$payments2, _params$payments3, _params$bookings3, _params$relation_prod3, _params$payments4;
2073
2803
  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) {
2804
+ return _regeneratorRuntime().wrap(function _callee27$(_context29) {
2805
+ while (1) switch (_context29.prev = _context29.next) {
2076
2806
  case 0:
2077
2807
  // 过滤掉由在线店铺下单的 payment 支付数据
2078
2808
  onlineStorePaymentCodeList = ['WXPAY', 'WECHAT', 'ALIPAY', 'APPLE_PAY', 'CREDIT_CARD_3DS', 'CREDIT_CARD_TOKEN', 'GOOGLE_PAY', 'GOOGLE_PAY_3DS', 'CREDIT_CARD'];
@@ -2106,7 +2836,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2106
2836
  relationProductsCount: ((_params$relation_prod3 = params.relation_products) === null || _params$relation_prod3 === void 0 ? void 0 : _params$relation_prod3.length) || 0,
2107
2837
  paymentsCount: ((_params$payments4 = params.payments) === null || _params$payments4 === void 0 ? void 0 : _params$payments4.length) || 0
2108
2838
  });
2109
- _context22.prev = 4;
2839
+ _context29.prev = 4;
2110
2840
  // 构建订单数据,设置默认值并允许 params 覆盖
2111
2841
  orderData = _objectSpread({
2112
2842
  sales_channel: 'my_pisel',
@@ -2170,10 +2900,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2170
2900
  });
2171
2901
 
2172
2902
  // 调用后端接口
2173
- _context22.next = 12;
2903
+ _context29.next = 12;
2174
2904
  return this.request.post('/order/checkout', orderData);
2175
2905
  case 12:
2176
- response = _context22.sent;
2906
+ response = _context29.sent;
2177
2907
  this.logInfo('Order API called successfully', {
2178
2908
  response: response
2179
2909
  });
@@ -2181,22 +2911,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2181
2911
  success: !!response,
2182
2912
  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
2913
  });
2184
- return _context22.abrupt("return", response);
2914
+ return _context29.abrupt("return", response);
2185
2915
  case 18:
2186
- _context22.prev = 18;
2187
- _context22.t0 = _context22["catch"](4);
2188
- console.error('[Order] createOrderByCheckout 创建订单失败:', _context22.t0);
2916
+ _context29.prev = 18;
2917
+ _context29.t0 = _context29["catch"](4);
2918
+ console.error('[Order] createOrderByCheckout 创建订单失败:', _context29.t0);
2189
2919
  this.logInfo('Order API called failed', {
2190
- error: _context22.t0 instanceof Error ? _context22.t0.message : String(_context22.t0)
2920
+ error: _context29.t0 instanceof Error ? _context29.t0.message : String(_context29.t0)
2191
2921
  });
2192
- throw _context22.t0;
2922
+ throw _context29.t0;
2193
2923
  case 23:
2194
2924
  case "end":
2195
- return _context22.stop();
2925
+ return _context29.stop();
2196
2926
  }
2197
- }, _callee22, this, [[4, 18]]);
2927
+ }, _callee27, this, [[4, 18]]);
2198
2928
  }));
2199
- function createOrderByCheckout(_x23) {
2929
+ function createOrderByCheckout(_x28) {
2200
2930
  return _createOrderByCheckout.apply(this, arguments);
2201
2931
  }
2202
2932
  return createOrderByCheckout;
@@ -2204,23 +2934,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2204
2934
  }, {
2205
2935
  key: "submitSalesOrder",
2206
2936
  value: function () {
2207
- var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(params) {
2937
+ var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(params) {
2208
2938
  var url, query, fetchUrl;
2209
- return _regeneratorRuntime().wrap(function _callee23$(_context23) {
2210
- while (1) switch (_context23.prev = _context23.next) {
2939
+ return _regeneratorRuntime().wrap(function _callee28$(_context30) {
2940
+ while (1) switch (_context30.prev = _context30.next) {
2211
2941
  case 0:
2212
2942
  url = params.url, query = params.query;
2213
2943
  fetchUrl = url || '/order/sales/checkout';
2214
- return _context23.abrupt("return", this.request.post(fetchUrl, query, {
2944
+ return _context30.abrupt("return", this.request.post(fetchUrl, query, {
2215
2945
  customToast: function customToast() {}
2216
2946
  }));
2217
2947
  case 3:
2218
2948
  case "end":
2219
- return _context23.stop();
2949
+ return _context30.stop();
2220
2950
  }
2221
- }, _callee23, this);
2951
+ }, _callee28, this);
2222
2952
  }));
2223
- function submitSalesOrder(_x24) {
2953
+ function submitSalesOrder(_x29) {
2224
2954
  return _submitSalesOrder.apply(this, arguments);
2225
2955
  }
2226
2956
  return submitSalesOrder;
@@ -2234,37 +2964,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2234
2964
  }, {
2235
2965
  key: "sendCustomerPayLink",
2236
2966
  value: (function () {
2237
- var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(params) {
2967
+ var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(params) {
2238
2968
  var _params$emails;
2239
2969
  var orderIds;
2240
- return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2241
- while (1) switch (_context24.prev = _context24.next) {
2970
+ return _regeneratorRuntime().wrap(function _callee29$(_context31) {
2971
+ while (1) switch (_context31.prev = _context31.next) {
2242
2972
  case 0:
2243
2973
  orderIds = params.order_ids || params.orderIds || [];
2244
2974
  if (orderIds.length) {
2245
- _context24.next = 3;
2975
+ _context31.next = 3;
2246
2976
  break;
2247
2977
  }
2248
2978
  throw new Error('发送支付链接前必须先提交本地订单并取得订单 ID');
2249
2979
  case 3:
2250
2980
  if ((_params$emails = params.emails) !== null && _params$emails !== void 0 && _params$emails.length) {
2251
- _context24.next = 5;
2981
+ _context31.next = 5;
2252
2982
  break;
2253
2983
  }
2254
2984
  throw new Error('发送支付链接需要至少一个邮箱');
2255
2985
  case 5:
2256
- return _context24.abrupt("return", this.request.post('/order/batch-email', {
2986
+ return _context31.abrupt("return", this.request.post('/order/batch-email', {
2257
2987
  order_ids: orderIds,
2258
2988
  notify_action: params.notify_action || 'order_payment_reminder',
2259
2989
  emails: params.emails
2260
2990
  }));
2261
2991
  case 6:
2262
2992
  case "end":
2263
- return _context24.stop();
2993
+ return _context31.stop();
2264
2994
  }
2265
- }, _callee24, this);
2995
+ }, _callee29, this);
2266
2996
  }));
2267
- function sendCustomerPayLink(_x25) {
2997
+ function sendCustomerPayLink(_x30) {
2268
2998
  return _sendCustomerPayLink.apply(this, arguments);
2269
2999
  }
2270
3000
  return sendCustomerPayLink;
@@ -2273,28 +3003,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2273
3003
  }, {
2274
3004
  key: "getOrderInfoByRemote",
2275
3005
  value: function () {
2276
- var _getOrderInfoByRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(order_id) {
3006
+ var _getOrderInfoByRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(order_id) {
2277
3007
  var res;
2278
- return _regeneratorRuntime().wrap(function _callee25$(_context25) {
2279
- while (1) switch (_context25.prev = _context25.next) {
3008
+ return _regeneratorRuntime().wrap(function _callee30$(_context32) {
3009
+ while (1) switch (_context32.prev = _context32.next) {
2280
3010
  case 0:
2281
- _context25.next = 2;
3011
+ _context32.next = 2;
2282
3012
  return this.request.get("/order/sales/".concat(order_id), {
2283
3013
  with: ['products', 'bookings', 'payments', 'customer', 'summary', 'contacts_info']
2284
3014
  });
2285
3015
  case 2:
2286
- res = _context25.sent;
3016
+ res = _context32.sent;
2287
3017
  if (res.code === 200) {
2288
3018
  this.store.lastOrderInfo = res.data;
2289
3019
  }
2290
- return _context25.abrupt("return", res);
3020
+ return _context32.abrupt("return", res);
2291
3021
  case 5:
2292
3022
  case "end":
2293
- return _context25.stop();
3023
+ return _context32.stop();
2294
3024
  }
2295
- }, _callee25, this);
3025
+ }, _callee30, this);
2296
3026
  }));
2297
- function getOrderInfoByRemote(_x26) {
3027
+ function getOrderInfoByRemote(_x31) {
2298
3028
  return _getOrderInfoByRemote.apply(this, arguments);
2299
3029
  }
2300
3030
  return getOrderInfoByRemote;
@@ -2308,79 +3038,92 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2308
3038
  }, {
2309
3039
  key: "hydrateTempOrderFromRecord",
2310
3040
  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) {
3041
+ var _hydrateTempOrderFromRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(record, options) {
3042
+ var raw, nextTempOrder;
3043
+ return _regeneratorRuntime().wrap(function _callee31$(_context33) {
3044
+ while (1) switch (_context33.prev = _context33.next) {
2316
3045
  case 0:
2317
3046
  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
- }
3047
+ nextTempOrder = this.normalizeTempOrderForRuntime(raw, {
3048
+ ensureIdentity: true
2325
3049
  });
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
3050
  this.store.tempOrder = nextTempOrder;
2360
3051
  this.store.summary = raw.summary && _typeof(raw.summary) === 'object' ? _objectSpread(_objectSpread({}, createEmptySummary()), raw.summary) : createEmptySummary();
2361
3052
  this.store.lastOrderInfo = raw.lastOrderInfo || raw;
2362
3053
  if (!(options !== null && options !== void 0 && options.recalcOnHydrate)) {
2363
- _context26.next = 23;
3054
+ _context33.next = 8;
2364
3055
  break;
2365
3056
  }
2366
- _context26.next = 23;
3057
+ _context33.next = 8;
2367
3058
  return this.recalculateSummary({
2368
3059
  createIfMissing: false
2369
3060
  });
2370
- case 23:
3061
+ case 8:
2371
3062
  this.persistTempOrder();
2372
- return _context26.abrupt("return", nextTempOrder);
2373
- case 25:
3063
+ return _context33.abrupt("return", nextTempOrder);
3064
+ case 10:
2374
3065
  case "end":
2375
- return _context26.stop();
3066
+ return _context33.stop();
2376
3067
  }
2377
- }, _callee26, this);
3068
+ }, _callee31, this);
2378
3069
  }));
2379
- function hydrateTempOrderFromRecord(_x27, _x28) {
3070
+ function hydrateTempOrderFromRecord(_x32, _x33) {
2380
3071
  return _hydrateTempOrderFromRecord.apply(this, arguments);
2381
3072
  }
2382
3073
  return hydrateTempOrderFromRecord;
2383
3074
  }())
3075
+ }, {
3076
+ key: "normalizeTempOrderForRuntime",
3077
+ value: function normalizeTempOrderForRuntime(raw, options) {
3078
+ var _this8 = this;
3079
+ var nextTempOrder = _objectSpread(_objectSpread({}, this.createDefaultTempOrderInstance()), raw || {});
3080
+ delete nextTempOrder.summary;
3081
+ delete nextTempOrder.lastOrderInfo;
3082
+ delete nextTempOrder.discount_list;
3083
+ delete nextTempOrder.shop_id;
3084
+ delete nextTempOrder.create_date;
3085
+ delete nextTempOrder.total_amount;
3086
+ delete nextTempOrder.expect_amount;
3087
+ delete nextTempOrder.paid_amount;
3088
+ delete nextTempOrder.shop_note;
3089
+ delete nextTempOrder.start_time;
3090
+ delete nextTempOrder.tax_fee;
3091
+ delete nextTempOrder.total_refund_amount;
3092
+ delete nextTempOrder.holder_id;
3093
+ nextTempOrder.metadata = raw.metadata && _typeof(raw.metadata) === 'object' ? _objectSpread({}, raw.metadata) : {};
3094
+ nextTempOrder.holder = raw.holder && _typeof(raw.holder) === 'object' ? _objectSpread({}, raw.holder) : null;
3095
+ nextTempOrder.products = Array.isArray(raw.products) ? raw.products.map(function (p) {
3096
+ return _this8.normalizeHydratedOrderProduct(p);
3097
+ }) : [];
3098
+ nextTempOrder.bookings = Array.isArray(raw.bookings) ? raw.bookings.map(function (b) {
3099
+ return _objectSpread(_objectSpread({}, b || {}), {}, {
3100
+ is_all: normalizeBookingIsAll(b || {}),
3101
+ sub_type: normalizeBookingSubType(b || {})
3102
+ });
3103
+ }) : [];
3104
+ nextTempOrder.payments = Array.isArray(raw.payments) ? raw.payments.map(function (p) {
3105
+ return _objectSpread({}, p || {});
3106
+ }) : [];
3107
+ nextTempOrder.surcharges = Array.isArray(raw.surcharges) ? raw.surcharges.map(function (s) {
3108
+ return _objectSpread({}, s || {});
3109
+ }) : [];
3110
+ nextTempOrder.relation_forms = Array.isArray(raw.relation_forms) ? raw.relation_forms.map(function (f) {
3111
+ return _objectSpread({}, f || {});
3112
+ }) : [];
3113
+ nextTempOrder.contacts = Array.isArray(raw.contacts) ? raw.contacts.map(function (c) {
3114
+ return _objectSpread({}, c || {});
3115
+ }) : [];
3116
+ nextTempOrder.contacts_info = raw.contacts_info && _typeof(raw.contacts_info) === 'object' && !Array.isArray(raw.contacts_info) ? _objectSpread({}, raw.contacts_info) : null;
3117
+ nextTempOrder._extend = raw._extend && _typeof(raw._extend) === 'object' ? _objectSpread(_objectSpread({}, raw._extend), {}, {
3118
+ productsByUid: raw._extend.productsByUid || {}
3119
+ }) : {
3120
+ productsByUid: {}
3121
+ };
3122
+ if ((options === null || options === void 0 ? void 0 : options.ensureIdentity) !== false) {
3123
+ this.ensureExternalSaleNumber(nextTempOrder);
3124
+ }
3125
+ return nextTempOrder;
3126
+ }
2384
3127
  }, {
2385
3128
  key: "normalizeHydratedOrderProduct",
2386
3129
  value: function normalizeHydratedOrderProduct(product) {
@@ -2396,6 +3139,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2396
3139
  row.metadata.unique_identification_number = createUuidV4();
2397
3140
  }
2398
3141
  var normalized = normalizeOrderProduct(row);
3142
+ normalized.discount_list = normalizeOrderProductDiscountList(normalized.discount_list);
2399
3143
  var result = _objectSpread(_objectSpread(_objectSpread({}, row), normalized), {}, {
2400
3144
  metadata: _objectSpread(_objectSpread({}, row.metadata), normalized.metadata)
2401
3145
  });
@@ -2411,25 +3155,25 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2411
3155
  }, {
2412
3156
  key: "getOrderInfo",
2413
3157
  value: function () {
2414
- var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(order_id) {
3158
+ var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(order_id) {
2415
3159
  var res;
2416
- return _regeneratorRuntime().wrap(function _callee27$(_context27) {
2417
- while (1) switch (_context27.prev = _context27.next) {
3160
+ return _regeneratorRuntime().wrap(function _callee32$(_context34) {
3161
+ while (1) switch (_context34.prev = _context34.next) {
2418
3162
  case 0:
2419
- _context27.next = 2;
3163
+ _context34.next = 2;
2420
3164
  return this.request.get("/order/sales/".concat(order_id), {
2421
3165
  with: ['products', 'bookings']
2422
3166
  });
2423
3167
  case 2:
2424
- res = _context27.sent;
2425
- return _context27.abrupt("return", res);
3168
+ res = _context34.sent;
3169
+ return _context34.abrupt("return", res);
2426
3170
  case 4:
2427
3171
  case "end":
2428
- return _context27.stop();
3172
+ return _context34.stop();
2429
3173
  }
2430
- }, _callee27, this);
3174
+ }, _callee32, this);
2431
3175
  }));
2432
- function getOrderInfo(_x29) {
3176
+ function getOrderInfo(_x34) {
2433
3177
  return _getOrderInfo.apply(this, arguments);
2434
3178
  }
2435
3179
  return getOrderInfo;
@@ -2443,46 +3187,46 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2443
3187
  */
2444
3188
  function populateSavedAmounts(productList, discountList) {
2445
3189
  var savedMap = new Map();
2446
- var _iterator = _createForOfIteratorHelper(productList),
2447
- _step;
3190
+ var _iterator5 = _createForOfIteratorHelper(productList),
3191
+ _step5;
2448
3192
  try {
2449
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
2450
- var product = _step.value;
3193
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
3194
+ var product = _step5.value;
2451
3195
  var qty = product.num || 1;
2452
- var _iterator3 = _createForOfIteratorHelper(product.discount_list || []),
2453
- _step3;
3196
+ var _iterator7 = _createForOfIteratorHelper(product.discount_list || []),
3197
+ _step7;
2454
3198
  try {
2455
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
3199
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
2456
3200
  var _pd$discount, _pd$metadata;
2457
- var pd = _step3.value;
3201
+ var pd = _step7.value;
2458
3202
  var discountKey = ((_pd$discount = pd.discount) === null || _pd$discount === void 0 ? void 0 : _pd$discount.resource_id) || pd.id;
2459
3203
  if (discountKey == null) continue;
2460
3204
  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
3205
  savedMap.set(discountKey, (savedMap.get(discountKey) || new Decimal(0)).plus(amount));
2462
3206
  }
2463
3207
  } catch (err) {
2464
- _iterator3.e(err);
3208
+ _iterator7.e(err);
2465
3209
  } finally {
2466
- _iterator3.f();
3210
+ _iterator7.f();
2467
3211
  }
2468
3212
  }
2469
3213
  } catch (err) {
2470
- _iterator.e(err);
3214
+ _iterator5.e(err);
2471
3215
  } finally {
2472
- _iterator.f();
3216
+ _iterator5.f();
2473
3217
  }
2474
- var _iterator2 = _createForOfIteratorHelper(discountList),
2475
- _step2;
3218
+ var _iterator6 = _createForOfIteratorHelper(discountList),
3219
+ _step6;
2476
3220
  try {
2477
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
2478
- var d = _step2.value;
3221
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
3222
+ var d = _step6.value;
2479
3223
  var key = d.id;
2480
3224
  d.savedAmount = d.isSelected && key != null && savedMap.has(key) ? savedMap.get(key).toNumber() : 0;
2481
3225
  }
2482
3226
  } catch (err) {
2483
- _iterator2.e(err);
3227
+ _iterator6.e(err);
2484
3228
  } finally {
2485
- _iterator2.f();
3229
+ _iterator6.f();
2486
3230
  }
2487
3231
  }
2488
3232
  }]);