@pisell/pisellos 2.2.177 → 2.2.179

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