@pisell/pisellos 2.2.178 → 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 (182) 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 -88
  9. package/dist/modules/Order/index.js +501 -1357
  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 +7 -21
  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/modules/Customer/index.d.ts +0 -6
  55. package/lib/modules/Customer/index.js +11 -26
  56. package/lib/modules/Customer/types.d.ts +0 -2
  57. package/lib/modules/Discount/index.d.ts +4 -2
  58. package/lib/modules/Discount/index.js +63 -8
  59. package/lib/modules/Discount/types.d.ts +7 -1
  60. package/lib/modules/Order/index.d.ts +18 -88
  61. package/lib/modules/Order/index.js +149 -677
  62. package/lib/modules/Order/types.d.ts +19 -198
  63. package/lib/modules/Order/types.js +0 -1
  64. package/lib/modules/Order/utils.d.ts +1 -50
  65. package/lib/modules/Order/utils.js +22 -229
  66. package/lib/modules/Quotation/index.d.ts +1 -0
  67. package/lib/modules/Quotation/index.js +15 -18
  68. package/lib/modules/Rules/index.d.ts +0 -4
  69. package/lib/modules/Rules/index.js +14 -22
  70. package/lib/modules/SalesSummary/index.js +2 -4
  71. package/lib/modules/SalesSummary/utils.js +7 -21
  72. package/lib/modules/Schedule/index.js +1 -3
  73. package/lib/modules/index.d.ts +0 -1
  74. package/lib/modules/index.js +1 -3
  75. package/lib/server/index.js +4 -41
  76. package/lib/server/modules/order/index.d.ts +0 -23
  77. package/lib/server/modules/order/index.js +14 -46
  78. package/lib/server/modules/order/types.d.ts +2 -0
  79. package/lib/server/modules/order/utils/filterOrders.js +4 -12
  80. package/lib/server/modules/products/index.d.ts +1 -1
  81. package/lib/server/modules/products/index.js +20 -30
  82. package/lib/server/modules/schedule/index.js +1 -2
  83. package/lib/solution/BaseSales/index.d.ts +7 -89
  84. package/lib/solution/BaseSales/index.js +22 -736
  85. package/lib/solution/BaseSales/types.d.ts +1 -67
  86. package/lib/solution/BaseSales/types.js +1 -3
  87. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +1 -0
  88. package/lib/solution/BaseSales/utils/parseSalesResponse.js +1 -0
  89. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +12 -71
  90. package/lib/solution/BaseSales/utils.js +6 -46
  91. package/lib/solution/BookingByStep/index.d.ts +1 -1
  92. package/lib/solution/BookingTicket/index.d.ts +1 -133
  93. package/lib/solution/BookingTicket/index.js +8 -352
  94. package/lib/solution/BookingTicket/types.d.ts +0 -2
  95. package/lib/solution/BookingTicket/types.js +0 -6
  96. package/lib/solution/BookingTicket/utils/cartView.js +2 -4
  97. package/lib/solution/ScanOrder/index.d.ts +3 -9
  98. package/lib/solution/ScanOrder/index.js +66 -147
  99. package/lib/solution/ScanOrder/utils.js +6 -46
  100. package/lib/solution/ShopDiscount/index.d.ts +1 -0
  101. package/lib/solution/ShopDiscount/index.js +4 -2
  102. package/lib/solution/VenueBooking/index.d.ts +9 -5
  103. package/lib/solution/VenueBooking/index.js +14 -50
  104. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +0 -4
  105. package/lib/solution/VenueBooking/utils/slotMerge.js +0 -10
  106. package/package.json +2 -2
  107. package/dist/modules/BookingContext/index.d.ts +0 -37
  108. package/dist/modules/BookingContext/index.js +0 -436
  109. package/dist/modules/BookingContext/types.d.ts +0 -102
  110. package/dist/modules/BookingContext/types.js +0 -51
  111. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +0 -16
  112. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +0 -193
  113. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +0 -8
  114. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +0 -137
  115. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +0 -75
  116. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +0 -215
  117. package/dist/modules/BookingContext/utils/flexible.d.ts +0 -28
  118. package/dist/modules/BookingContext/utils/flexible.js +0 -56
  119. package/dist/modules/BookingContext/utils/formatResourceList.d.ts +0 -8
  120. package/dist/modules/BookingContext/utils/formatResourceList.js +0 -38
  121. package/dist/modules/BookingContext/utils/index.d.ts +0 -11
  122. package/dist/modules/BookingContext/utils/index.js +0 -11
  123. package/dist/modules/BookingContext/utils/noResource.d.ts +0 -13
  124. package/dist/modules/BookingContext/utils/noResource.js +0 -77
  125. package/dist/modules/BookingContext/utils/productExtend.d.ts +0 -72
  126. package/dist/modules/BookingContext/utils/productExtend.js +0 -339
  127. package/dist/modules/BookingContext/utils/resourceErrors.d.ts +0 -41
  128. package/dist/modules/BookingContext/utils/resourceErrors.js +0 -74
  129. package/dist/modules/BookingContext/utils/resourceSelection.d.ts +0 -7
  130. package/dist/modules/BookingContext/utils/resourceSelection.js +0 -24
  131. package/dist/modules/BookingContext/utils/resources.d.ts +0 -80
  132. package/dist/modules/BookingContext/utils/resources.js +0 -486
  133. package/dist/modules/BookingContext/utils/serviceTimes.d.ts +0 -55
  134. package/dist/modules/BookingContext/utils/serviceTimes.js +0 -151
  135. package/dist/modules/BookingContext/utils/timeSlices.d.ts +0 -42
  136. package/dist/modules/BookingContext/utils/timeSlices.js +0 -100
  137. package/dist/modules/Order/utils/manualProductDiscount.d.ts +0 -106
  138. package/dist/modules/Order/utils/manualProductDiscount.js +0 -212
  139. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +0 -275
  140. package/dist/solution/BaseSales/utils/cartPromotion.js +0 -1258
  141. package/dist/solution/BaseSales/utils/quotationPrice.d.ts +0 -7
  142. package/dist/solution/BaseSales/utils/quotationPrice.js +0 -237
  143. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +0 -113
  144. package/dist/solution/BookingTicket/utils/addProductDecision.js +0 -346
  145. package/lib/modules/BookingContext/index.d.ts +0 -37
  146. package/lib/modules/BookingContext/index.js +0 -297
  147. package/lib/modules/BookingContext/types.d.ts +0 -102
  148. package/lib/modules/BookingContext/types.js +0 -34
  149. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +0 -16
  150. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +0 -207
  151. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +0 -8
  152. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +0 -141
  153. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +0 -75
  154. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +0 -198
  155. package/lib/modules/BookingContext/utils/flexible.d.ts +0 -28
  156. package/lib/modules/BookingContext/utils/flexible.js +0 -80
  157. package/lib/modules/BookingContext/utils/formatResourceList.d.ts +0 -8
  158. package/lib/modules/BookingContext/utils/formatResourceList.js +0 -50
  159. package/lib/modules/BookingContext/utils/index.d.ts +0 -11
  160. package/lib/modules/BookingContext/utils/index.js +0 -43
  161. package/lib/modules/BookingContext/utils/noResource.d.ts +0 -13
  162. package/lib/modules/BookingContext/utils/noResource.js +0 -90
  163. package/lib/modules/BookingContext/utils/productExtend.d.ts +0 -72
  164. package/lib/modules/BookingContext/utils/productExtend.js +0 -283
  165. package/lib/modules/BookingContext/utils/resourceErrors.d.ts +0 -41
  166. package/lib/modules/BookingContext/utils/resourceErrors.js +0 -80
  167. package/lib/modules/BookingContext/utils/resourceSelection.d.ts +0 -7
  168. package/lib/modules/BookingContext/utils/resourceSelection.js +0 -46
  169. package/lib/modules/BookingContext/utils/resources.d.ts +0 -80
  170. package/lib/modules/BookingContext/utils/resources.js +0 -377
  171. package/lib/modules/BookingContext/utils/serviceTimes.d.ts +0 -55
  172. package/lib/modules/BookingContext/utils/serviceTimes.js +0 -162
  173. package/lib/modules/BookingContext/utils/timeSlices.d.ts +0 -42
  174. package/lib/modules/BookingContext/utils/timeSlices.js +0 -124
  175. package/lib/modules/Order/utils/manualProductDiscount.d.ts +0 -106
  176. package/lib/modules/Order/utils/manualProductDiscount.js +0 -207
  177. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +0 -275
  178. package/lib/solution/BaseSales/utils/cartPromotion.js +0 -836
  179. package/lib/solution/BaseSales/utils/quotationPrice.d.ts +0 -7
  180. package/lib/solution/BaseSales/utils/quotationPrice.js +0 -277
  181. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +0 -113
  182. 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,91 +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
- if (!Array.isArray(productRecord.product_bundle)) continue;
1177
- var _iterator7 = _createForOfIteratorHelper(productRecord.product_bundle),
1178
- _step7;
1179
- try {
1180
- for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
1181
- var bundle = _step7.value;
1182
- var bundleRecord = bundle;
1183
- var bundleMetadata = bundleRecord.metadata && _typeof(bundleRecord.metadata) === 'object' ? _objectSpread({}, bundleRecord.metadata) : {};
1184
- var hasBundleMetadataPatch = false;
1185
- var bundleSurchargeFee = this.formatSummaryMetadataMoney(bundleRecord.surcharge_fee);
1186
- if (bundleSurchargeFee !== undefined) {
1187
- bundleMetadata.surcharge_fee = bundleSurchargeFee;
1188
- hasBundleMetadataPatch = true;
1189
- }
1190
- if (Array.isArray(bundleRecord.relation_surcharge_ids)) {
1191
- bundleMetadata.relation_surcharge_ids = bundleRecord.relation_surcharge_ids;
1192
- hasBundleMetadataPatch = true;
1193
- }
1194
- if (hasBundleMetadataPatch) bundleRecord.metadata = bundleMetadata;
1195
- }
1196
- } catch (err) {
1197
- _iterator7.e(err);
1198
- } finally {
1199
- _iterator7.f();
1200
- }
1201
- }
1202
- } catch (err) {
1203
- _iterator5.e(err);
1204
- } finally {
1205
- _iterator5.f();
1206
- }
1207
- }
1208
- }, {
1209
- key: "calculateSummaryPaymentBalance",
1210
- value: function calculateSummaryPaymentBalance(params) {
1211
- var tempOrder = params.tempOrder,
1212
- summary = params.summary,
1213
- orderPaidAmount = params.orderPaidAmount;
1214
- var depositAmount = summary.deposit_amount || tempOrder.deposit_amount || '0.00';
1215
- var isDeposit = tempOrder.is_deposit === 1 || new Decimal(depositAmount || 0).gt(0);
1216
- var targetAmount = isDeposit ? new Decimal(depositAmount || 0) : new Decimal(summary.total_amount || summary.expect_amount || 0);
1217
- return {
1218
- amountGap: Decimal.max(0, targetAmount.minus(orderPaidAmount)).toFixed(2),
1219
- totalRefundAmount: Decimal.max(0, orderPaidAmount.minus(targetAmount)).toFixed(2)
1220
- };
1221
- }
1222
789
  }, {
1223
790
  key: "getPaymentTargetAmount",
1224
791
  value: function getPaymentTargetAmount() {
@@ -1245,15 +812,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1245
812
  }, {
1246
813
  key: "restoreOrder",
1247
814
  value: function restoreOrder() {
1248
- var _this$store$discount9, _this$store$discount10;
1249
815
  var freshTempOrder = this.createDefaultTempOrderInstance();
1250
816
  this.ensureExternalSaleNumber(freshTempOrder);
1251
817
  this.store.tempOrder = freshTempOrder;
1252
818
  this.store.summary = createEmptySummary();
1253
819
  this.store.lastOrderInfo = undefined;
1254
- this.store.syncState = undefined;
1255
- void ((_this$store$discount9 = this.store.discount) === null || _this$store$discount9 === void 0 ? void 0 : _this$store$discount9.setOriginalDiscountList([]));
1256
- void ((_this$store$discount10 = this.store.discount) === null || _this$store$discount10 === void 0 ? void 0 : _this$store$discount10.setDiscountList([]));
1257
820
  this.persistTempOrder();
1258
821
  return freshTempOrder;
1259
822
  }
@@ -1262,60 +825,6 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1262
825
  value: function getTempOrder() {
1263
826
  return this.store.tempOrder;
1264
827
  }
1265
- }, {
1266
- key: "replaceTempOrder",
1267
- value: function () {
1268
- var _replaceTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(tempOrder, options) {
1269
- var nextTempOrder;
1270
- return _regeneratorRuntime().wrap(function _callee10$(_context12) {
1271
- while (1) switch (_context12.prev = _context12.next) {
1272
- case 0:
1273
- if (isTempOrder(tempOrder)) {
1274
- _context12.next = 2;
1275
- break;
1276
- }
1277
- throw new Error('无效的 tempOrder 数据');
1278
- case 2:
1279
- nextTempOrder = this.normalizeTempOrderForRuntime(cloneDeep(tempOrder), {
1280
- ensureIdentity: false
1281
- });
1282
- this.store.tempOrder = nextTempOrder;
1283
- if (!((options === null || options === void 0 ? void 0 : options.recalculateSummary) !== false)) {
1284
- _context12.next = 9;
1285
- break;
1286
- }
1287
- _context12.next = 7;
1288
- return this.recalculateSummary({
1289
- createIfMissing: false
1290
- });
1291
- case 7:
1292
- _context12.next = 10;
1293
- break;
1294
- case 9:
1295
- this.store.summary = createEmptySummary();
1296
- case 10:
1297
- if ((options === null || options === void 0 ? void 0 : options.persist) !== false) {
1298
- this.persistTempOrder();
1299
- }
1300
- if (!(options !== null && options !== void 0 && options.saveDraft)) {
1301
- _context12.next = 14;
1302
- break;
1303
- }
1304
- _context12.next = 14;
1305
- return this.saveDraft();
1306
- case 14:
1307
- return _context12.abrupt("return", nextTempOrder);
1308
- case 15:
1309
- case "end":
1310
- return _context12.stop();
1311
- }
1312
- }, _callee10, this);
1313
- }));
1314
- function replaceTempOrder(_x10, _x11) {
1315
- return _replaceTempOrder.apply(this, arguments);
1316
- }
1317
- return replaceTempOrder;
1318
- }()
1319
828
  }, {
1320
829
  key: "getOrderIdentity",
1321
830
  value: function getOrderIdentity() {
@@ -1394,28 +903,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1394
903
  }, {
1395
904
  key: "addNewOrder",
1396
905
  value: function () {
1397
- var _addNewOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
906
+ var _addNewOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
1398
907
  var tempOrder;
1399
- return _regeneratorRuntime().wrap(function _callee11$(_context13) {
1400
- while (1) switch (_context13.prev = _context13.next) {
908
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
909
+ while (1) switch (_context9.prev = _context9.next) {
1401
910
  case 0:
1402
911
  tempOrder = this.ensureTempOrder();
1403
912
  this.ensureExternalSaleNumber(tempOrder);
1404
- _context13.next = 4;
913
+ _context9.next = 4;
1405
914
  return this.recalculateSummary({
1406
915
  createIfMissing: true
1407
916
  });
1408
917
  case 4:
1409
918
  this.persistTempOrder();
1410
- _context13.next = 7;
919
+ _context9.next = 7;
1411
920
  return this.saveDraft();
1412
921
  case 7:
1413
- return _context13.abrupt("return", tempOrder);
922
+ return _context9.abrupt("return", tempOrder);
1414
923
  case 8:
1415
924
  case "end":
1416
- return _context13.stop();
925
+ return _context9.stop();
1417
926
  }
1418
- }, _callee11, this);
927
+ }, _callee9, this);
1419
928
  }));
1420
929
  function addNewOrder() {
1421
930
  return _addNewOrder.apply(this, arguments);
@@ -1491,38 +1000,6 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1491
1000
  })
1492
1001
  };
1493
1002
  }
1494
- }, {
1495
- key: "getBookingUniqueIdentificationNumber",
1496
- value: function getBookingUniqueIdentificationNumber(booking) {
1497
- var _booking$metadata;
1498
- var uid = booking === null || booking === void 0 || (_booking$metadata = booking.metadata) === null || _booking$metadata === void 0 ? void 0 : _booking$metadata.unique_identification_number;
1499
- if (uid === undefined || uid === null || uid === '') return null;
1500
- return String(uid);
1501
- }
1502
- }, {
1503
- key: "findBookingIndexByUniqueIdentificationNumber",
1504
- value: function findBookingIndexByUniqueIdentificationNumber(tempOrder, uniqueIdentificationNumber) {
1505
- var _this4 = this;
1506
- return (tempOrder.bookings || []).findIndex(function (booking) {
1507
- return _this4.getBookingUniqueIdentificationNumber(booking) === uniqueIdentificationNumber;
1508
- });
1509
- }
1510
- }, {
1511
- key: "removeLinkedBookingsForProduct",
1512
- value: function removeLinkedBookingsForProduct(tempOrder, product) {
1513
- var _product$metadata4,
1514
- _product$metadata5,
1515
- _this5 = this;
1516
- 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);
1517
- 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);
1518
- if (!productUid && !bookingUid) return;
1519
- tempOrder.bookings = (tempOrder.bookings || []).filter(function (booking) {
1520
- var currentBookingUid = _this5.getBookingUniqueIdentificationNumber(booking);
1521
- if (bookingUid && currentBookingUid === String(bookingUid)) return false;
1522
- if (productUid && String((booking === null || booking === void 0 ? void 0 : booking.product_uid) || '') === String(productUid)) return false;
1523
- return true;
1524
- });
1525
- }
1526
1003
 
1527
1004
  // ─── TempOrder: 金额汇总 ───
1528
1005
  }, {
@@ -1534,59 +1011,47 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1534
1011
  }, {
1535
1012
  key: "recalculateSummary",
1536
1013
  value: function () {
1537
- var _recalculateSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(options) {
1538
- var tempOrder, salesSummary, paidPaymentSummary, _paymentBalance, emptySummary, salesSummaryResult, paymentBalance, summary;
1539
- return _regeneratorRuntime().wrap(function _callee12$(_context14) {
1540
- while (1) switch (_context14.prev = _context14.next) {
1014
+ var _recalculateSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(options) {
1015
+ var tempOrder, salesSummary, existedSummary, paidPaymentSummary, emptySummary, salesSummaryResult, summary;
1016
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1017
+ while (1) switch (_context10.prev = _context10.next) {
1541
1018
  case 0:
1542
1019
  tempOrder = options !== null && options !== void 0 && options.createIfMissing ? this.ensureTempOrder() : this.store.tempOrder;
1543
1020
  if (tempOrder) {
1544
- _context14.next = 3;
1021
+ _context10.next = 3;
1545
1022
  break;
1546
1023
  }
1547
- return _context14.abrupt("return", null);
1024
+ return _context10.abrupt("return", null);
1548
1025
  case 3:
1549
1026
  salesSummary = this.getSalesSummary();
1027
+ existedSummary = this.store.summary || createEmptySummary();
1550
1028
  paidPaymentSummary = this.calculatePaidPaymentSummary(tempOrder.payments || []);
1551
1029
  if (salesSummary) {
1552
- _context14.next = 11;
1030
+ _context10.next = 11;
1553
1031
  break;
1554
1032
  }
1555
- _paymentBalance = this.calculateSummaryPaymentBalance({
1556
- tempOrder: tempOrder,
1557
- summary: createEmptySummary(),
1558
- orderPaidAmount: paidPaymentSummary.orderPaidAmount
1559
- });
1560
1033
  emptySummary = _objectSpread(_objectSpread({}, createEmptySummary()), {}, {
1561
- total_refund_amount: _paymentBalance.totalRefundAmount,
1034
+ total_refund_amount: existedSummary.total_refund_amount || '0.00',
1562
1035
  customer_paid_amount: paidPaymentSummary.customerPaidAmount.toFixed(2),
1563
1036
  order_paid_amount: paidPaymentSummary.orderPaidAmount.toFixed(2),
1564
- amount_gap: _paymentBalance.amountGap,
1565
1037
  pay_service_charge_amount: paidPaymentSummary.payServiceChargeAmount.toFixed(2)
1566
1038
  });
1567
1039
  this.store.summary = emptySummary;
1568
1040
  tempOrder.surcharge_fee = emptySummary.surcharge_fee;
1569
- return _context14.abrupt("return", this.store.summary);
1041
+ return _context10.abrupt("return", this.store.summary);
1570
1042
  case 11:
1571
- _context14.next = 13;
1043
+ _context10.next = 13;
1572
1044
  return salesSummary.getSummary({
1573
1045
  products: tempOrder.products,
1574
1046
  isPriceIncludeTax: tempOrder.is_price_include_tax,
1575
1047
  shopDiscount: tempOrder.shop_discount
1576
1048
  });
1577
1049
  case 13:
1578
- salesSummaryResult = _context14.sent;
1579
- this.syncSummaryProductMetadata(tempOrder.products || []);
1580
- paymentBalance = this.calculateSummaryPaymentBalance({
1581
- tempOrder: tempOrder,
1582
- summary: salesSummaryResult,
1583
- orderPaidAmount: paidPaymentSummary.orderPaidAmount
1584
- });
1050
+ salesSummaryResult = _context10.sent;
1585
1051
  summary = _objectSpread(_objectSpread({}, salesSummaryResult), {}, {
1586
- total_refund_amount: paymentBalance.totalRefundAmount,
1052
+ total_refund_amount: existedSummary.total_refund_amount || '0.00',
1587
1053
  customer_paid_amount: paidPaymentSummary.customerPaidAmount.toFixed(2),
1588
1054
  order_paid_amount: paidPaymentSummary.orderPaidAmount.toFixed(2),
1589
- amount_gap: paymentBalance.amountGap,
1590
1055
  pay_service_charge_amount: paidPaymentSummary.payServiceChargeAmount.toFixed(2)
1591
1056
  });
1592
1057
  this.store.summary = summary;
@@ -1600,14 +1065,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1600
1065
  tempOrder.surcharges = summary.surcharges || [];
1601
1066
  tempOrder.deposit_amount = summary.deposit_amount || '0.00';
1602
1067
  tempOrder.is_deposit = summary.deposit_amount !== '0.00' ? 1 : 0;
1603
- return _context14.abrupt("return", this.store.summary);
1604
- case 25:
1068
+ return _context10.abrupt("return", this.store.summary);
1069
+ case 23:
1605
1070
  case "end":
1606
- return _context14.stop();
1071
+ return _context10.stop();
1607
1072
  }
1608
- }, _callee12, this);
1073
+ }, _callee10, this);
1609
1074
  }));
1610
- function recalculateSummary(_x12) {
1075
+ function recalculateSummary(_x10) {
1611
1076
  return _recalculateSummary.apply(this, arguments);
1612
1077
  }
1613
1078
  return recalculateSummary;
@@ -1615,30 +1080,30 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1615
1080
  }, {
1616
1081
  key: "getOrderSummary",
1617
1082
  value: function () {
1618
- var _getOrderSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
1083
+ var _getOrderSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
1619
1084
  var summary;
1620
- return _regeneratorRuntime().wrap(function _callee13$(_context15) {
1621
- while (1) switch (_context15.prev = _context15.next) {
1085
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1086
+ while (1) switch (_context11.prev = _context11.next) {
1622
1087
  case 0:
1623
- _context15.next = 2;
1088
+ _context11.next = 2;
1624
1089
  return this.recalculateSummary({
1625
1090
  createIfMissing: true
1626
1091
  });
1627
1092
  case 2:
1628
- summary = _context15.sent;
1093
+ summary = _context11.sent;
1629
1094
  if (summary) {
1630
- _context15.next = 5;
1095
+ _context11.next = 5;
1631
1096
  break;
1632
1097
  }
1633
- return _context15.abrupt("return", createEmptySummary());
1098
+ return _context11.abrupt("return", createEmptySummary());
1634
1099
  case 5:
1635
1100
  this.persistTempOrder();
1636
- return _context15.abrupt("return", summary);
1101
+ return _context11.abrupt("return", summary);
1637
1102
  case 7:
1638
1103
  case "end":
1639
- return _context15.stop();
1104
+ return _context11.stop();
1640
1105
  }
1641
- }, _callee13, this);
1106
+ }, _callee11, this);
1642
1107
  }));
1643
1108
  function getOrderSummary() {
1644
1109
  return _getOrderSummary.apply(this, arguments);
@@ -1648,46 +1113,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1648
1113
  }, {
1649
1114
  key: "updateTempOrderNote",
1650
1115
  value: function updateTempOrderNote(note) {
1651
- var sync = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1652
1116
  var tempOrder = this.ensureTempOrder();
1653
1117
  tempOrder.note = String(note || '');
1654
1118
  this.persistTempOrder();
1655
- if (sync) {
1656
- var orderId = tempOrder.order_id;
1657
- if (!orderId) return tempOrder.note;
1658
- return this.syncTempOrderNoteToRemote(orderId, tempOrder.note);
1659
- }
1660
1119
  return tempOrder.note;
1661
1120
  }
1662
- }, {
1663
- key: "syncTempOrderNoteToRemote",
1664
- value: function () {
1665
- var _syncTempOrderNoteToRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(orderId, note) {
1666
- return _regeneratorRuntime().wrap(function _callee14$(_context16) {
1667
- while (1) switch (_context16.prev = _context16.next) {
1668
- case 0:
1669
- _context16.next = 2;
1670
- return this.request.put("/order/order/".concat(orderId, "/note"), {
1671
- note: note
1672
- });
1673
- case 2:
1674
- return _context16.abrupt("return", note);
1675
- case 3:
1676
- case "end":
1677
- return _context16.stop();
1678
- }
1679
- }, _callee14, this);
1680
- }));
1681
- function syncTempOrderNoteToRemote(_x13, _x14) {
1682
- return _syncTempOrderNoteToRemote.apply(this, arguments);
1683
- }
1684
- return syncTempOrderNoteToRemote;
1685
- }()
1686
1121
  }, {
1687
1122
  key: "getTempOrderNote",
1688
1123
  value: function getTempOrderNote() {
1689
- var _this$store$tempOrder3;
1690
- 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) || '';
1691
1126
  }
1692
1127
  }, {
1693
1128
  key: "updateTempOrderShopDiscount",
@@ -1714,51 +1149,25 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1714
1149
  this.persistTempOrder();
1715
1150
  return tempOrder.contacts_info;
1716
1151
  }
1717
- }, {
1718
- key: "buildTempOrderCustomer",
1719
- value: function buildTempOrderCustomer(params) {
1720
- 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;
1721
- if (!params.customerId) return null;
1722
- var source = params.source ? cloneDeep(params.source) : {};
1723
- 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;
1724
- 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;
1725
- return _objectSpread(_objectSpread({}, source), {}, {
1726
- id: (_source$id = source.id) !== null && _source$id !== void 0 ? _source$id : params.customerId,
1727
- customer_id: (_source$customer_id = source.customer_id) !== null && _source$customer_id !== void 0 ? _source$customer_id : params.customerId,
1728
- name: String(name || ''),
1729
- customer_name: String(customerName || ''),
1730
- 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),
1731
- phone: String((_source$phone = source.phone) !== null && _source$phone !== void 0 ? _source$phone : params.phone),
1732
- email: String((_source$email = source.email) !== null && _source$email !== void 0 ? _source$email : params.email)
1733
- });
1734
- }
1735
1152
 
1736
1153
  /**
1737
1154
  * 更新当前 tempOrder 的客户协议字段。
1738
1155
  *
1739
- * PaymentModal 只需要修改订单里的客户事实;如果外部还有客户模块需要同步,
1156
+ * PaymentModal 只需要修改订单里的客户字段;如果外部还有客户模块需要同步,
1740
1157
  * 应由调用方通过回调处理,不能把外部 UI 状态写进 tempOrder。
1741
1158
  */
1742
1159
  }, {
1743
1160
  key: "updateTempOrderCustomer",
1744
1161
  value: function updateTempOrderCustomer(customer) {
1745
- 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;
1746
1163
  var tempOrder = this.ensureTempOrder();
1747
- 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;
1748
- 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 : '';
1749
1166
  tempOrder.customer_id = customerId === null || customerId === undefined || customerId === '' ? null : Number(customerId);
1750
1167
  tempOrder.customer_name = String(customerName || '');
1751
- 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 : '');
1752
1169
  tempOrder.phone = String(customer.phone || '');
1753
1170
  tempOrder.email = String(customer.email || '');
1754
- tempOrder.customer = this.buildTempOrderCustomer({
1755
- source: customer,
1756
- customerId: tempOrder.customer_id,
1757
- customerName: tempOrder.customer_name,
1758
- countryCallingCode: tempOrder.country_calling_code,
1759
- phone: tempOrder.phone,
1760
- email: tempOrder.email
1761
- });
1762
1171
  this.persistTempOrder();
1763
1172
  return {
1764
1173
  customerId: tempOrder.customer_id,
@@ -1770,43 +1179,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1770
1179
  }, {
1771
1180
  key: "setOrderCustomer",
1772
1181
  value: function setOrderCustomer(patch, snapshot) {
1773
- var _tempOrder$customer_i2, _tempOrder$customer_i3;
1774
1182
  if (!patch) {
1775
1183
  this.clearOrderCustomer();
1776
1184
  return;
1777
1185
  }
1778
1186
  var tempOrder = this.ensureTempOrder();
1779
- var previousCustomerId = (_tempOrder$customer_i2 = tempOrder.customer_id) !== null && _tempOrder$customer_i2 !== void 0 ? _tempOrder$customer_i2 : null;
1780
1187
  tempOrder.customer_id = patch.customer_id || patch.id || null;
1781
1188
  tempOrder.customer_name = String(patch.customer_name || '');
1782
1189
  tempOrder.country_calling_code = String(patch.country_calling_code || '');
1783
1190
  tempOrder.phone = String(patch.phone || '');
1784
1191
  tempOrder.email = String(patch.email || '');
1785
- tempOrder.customer = this.buildTempOrderCustomer({
1786
- source: snapshot || null,
1787
- customerId: tempOrder.customer_id,
1788
- customerName: tempOrder.customer_name,
1789
- countryCallingCode: tempOrder.country_calling_code,
1790
- phone: tempOrder.phone,
1791
- email: tempOrder.email
1792
- });
1793
1192
  if (snapshot !== undefined) {
1794
1193
  var extend = this.ensureExtend(tempOrder);
1795
1194
  if (snapshot === null) delete extend.customerSnapshot;else extend.customerSnapshot = cloneDeep(snapshot);
1796
1195
  }
1797
- var nextCustomerId = (_tempOrder$customer_i3 = tempOrder.customer_id) !== null && _tempOrder$customer_i3 !== void 0 ? _tempOrder$customer_i3 : null;
1798
- if (String(previousCustomerId !== null && previousCustomerId !== void 0 ? previousCustomerId : '') !== String(nextCustomerId !== null && nextCustomerId !== void 0 ? nextCustomerId : '')) {
1799
- clearTempOrderHolderAssignments(tempOrder);
1800
- }
1801
1196
  this.persistTempOrder();
1802
- this.saveDraftInBackground();
1803
1197
  this.emitOrderCustomerChange();
1804
1198
  }
1805
1199
  }, {
1806
1200
  key: "getOrderCustomer",
1807
1201
  value: function getOrderCustomer() {
1808
1202
  var tempOrder = this.store.tempOrder;
1809
- if (!tempOrder || !tempOrder.customer_id) {
1203
+ if (!tempOrder || tempOrder.customer_id === null || tempOrder.customer_id === undefined) {
1810
1204
  return null;
1811
1205
  }
1812
1206
  return {
@@ -1820,24 +1214,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1820
1214
  }, {
1821
1215
  key: "getOrderCustomerSnapshot",
1822
1216
  value: function getOrderCustomerSnapshot() {
1823
- var _this$store$tempOrder4;
1824
- 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;
1825
1219
  return snapshot ? cloneDeep(snapshot) : null;
1826
1220
  }
1827
1221
  }, {
1828
1222
  key: "clearOrderCustomer",
1829
1223
  value: function clearOrderCustomer() {
1830
1224
  var tempOrder = this.ensureTempOrder();
1831
- clearTempOrderHolderAssignments(tempOrder);
1832
1225
  tempOrder.customer_id = null;
1833
1226
  tempOrder.customer_name = '';
1834
1227
  tempOrder.country_calling_code = '';
1835
1228
  tempOrder.phone = '';
1836
1229
  tempOrder.email = '';
1837
- tempOrder.customer = null;
1838
1230
  if (tempOrder._extend) delete tempOrder._extend.customerSnapshot;
1839
1231
  this.persistTempOrder();
1840
- this.saveDraftInBackground();
1841
1232
  this.core.effects.emit(OrderHooks.OnOrderCustomerChange, null);
1842
1233
  }
1843
1234
  }, {
@@ -1888,28 +1279,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1888
1279
  }, {
1889
1280
  key: "addOrderPayment",
1890
1281
  value: function addOrderPayment(payment) {
1891
- var _paymentRecord$status,
1892
- _ref21,
1893
- _paymentRecord$origin,
1894
- _this6 = this;
1895
- this.logInfo('addOrderPayment', {
1896
- payment: payment
1897
- });
1898
1282
  var tempOrder = this.ensureTempOrder();
1899
- var paymentRecord = payment;
1900
- var mapped = mapPaymentItemsToOrderPayments([_objectSpread(_objectSpread({}, paymentRecord), {}, {
1901
- status: (_paymentRecord$status = paymentRecord.status) !== null && _paymentRecord$status !== void 0 ? _paymentRecord$status : 'paid',
1902
- origin_amount: (_ref21 = (_paymentRecord$origin = paymentRecord.origin_amount) !== null && _paymentRecord$origin !== void 0 ? _paymentRecord$origin : paymentRecord.amount) !== null && _ref21 !== void 0 ? _ref21 : '0.00'
1903
- })]);
1283
+ var mapped = mapPaymentItemsToOrderPayments([payment]);
1904
1284
  tempOrder.payments = [].concat(_toConsumableArray(tempOrder.payments || []), _toConsumableArray(mapped));
1905
1285
  this.persistTempOrder();
1906
- void this.recalculateSummary({
1907
- createIfMissing: true
1908
- }).catch(function (error) {
1909
- _this6.logError('recalculate summary after addOrderPayment failed', {
1910
- error: error instanceof Error ? error.message : String(error)
1911
- });
1912
- });
1913
1286
  return tempOrder.payments;
1914
1287
  }
1915
1288
 
@@ -1985,45 +1358,45 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1985
1358
  }, {
1986
1359
  key: "shouldMergeProductToOrder",
1987
1360
  value: function () {
1988
- var _shouldMergeProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(params) {
1361
+ var _shouldMergeProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(params) {
1989
1362
  var _this$orderHooks;
1990
1363
  var onBeforeMergeProductToOrder, result;
1991
- return _regeneratorRuntime().wrap(function _callee15$(_context17) {
1992
- while (1) switch (_context17.prev = _context17.next) {
1364
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1365
+ while (1) switch (_context12.prev = _context12.next) {
1993
1366
  case 0:
1994
1367
  onBeforeMergeProductToOrder = (_this$orderHooks = this.orderHooks) === null || _this$orderHooks === void 0 ? void 0 : _this$orderHooks.onBeforeMergeProductToOrder;
1995
1368
  if (onBeforeMergeProductToOrder) {
1996
- _context17.next = 3;
1369
+ _context12.next = 3;
1997
1370
  break;
1998
1371
  }
1999
- return _context17.abrupt("return", true);
1372
+ return _context12.abrupt("return", true);
2000
1373
  case 3:
2001
- _context17.next = 5;
1374
+ _context12.next = 5;
2002
1375
  return onBeforeMergeProductToOrder(_objectSpread(_objectSpread({}, params), {}, {
2003
1376
  defaultShouldMerge: true
2004
1377
  }));
2005
1378
  case 5:
2006
- result = _context17.sent;
1379
+ result = _context12.sent;
2007
1380
  if (!(typeof result === 'boolean')) {
2008
- _context17.next = 8;
1381
+ _context12.next = 8;
2009
1382
  break;
2010
1383
  }
2011
- return _context17.abrupt("return", result);
1384
+ return _context12.abrupt("return", result);
2012
1385
  case 8:
2013
1386
  if (!(result && _typeof(result) === 'object' && typeof result.shouldMerge === 'boolean')) {
2014
- _context17.next = 10;
1387
+ _context12.next = 10;
2015
1388
  break;
2016
1389
  }
2017
- return _context17.abrupt("return", result.shouldMerge);
1390
+ return _context12.abrupt("return", result.shouldMerge);
2018
1391
  case 10:
2019
- return _context17.abrupt("return", true);
1392
+ return _context12.abrupt("return", true);
2020
1393
  case 11:
2021
1394
  case "end":
2022
- return _context17.stop();
1395
+ return _context12.stop();
2023
1396
  }
2024
- }, _callee15, this);
1397
+ }, _callee12, this);
2025
1398
  }));
2026
- function shouldMergeProductToOrder(_x15) {
1399
+ function shouldMergeProductToOrder(_x11) {
2027
1400
  return _shouldMergeProductToOrder.apply(this, arguments);
2028
1401
  }
2029
1402
  return shouldMergeProductToOrder;
@@ -2031,11 +1404,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2031
1404
  }, {
2032
1405
  key: "addProductToOrder",
2033
1406
  value: function () {
2034
- var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(product, booking) {
2035
- var _this7 = this;
1407
+ var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(product, booking) {
1408
+ var _this3 = this;
2036
1409
  var tempOrder, linked, productToAdd, incomingFingerprint, normalizedIncoming, hasIncomingGoodPass, shouldForceNewLine, matchedIndex, matchedProduct, existedFingerprint, shouldMerge, _targetProduct$metada, targetProduct, targetUid, normalizedProduct;
2037
- return _regeneratorRuntime().wrap(function _callee16$(_context18) {
2038
- while (1) switch (_context18.prev = _context18.next) {
1410
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1411
+ while (1) switch (_context13.prev = _context13.next) {
2039
1412
  case 0:
2040
1413
  tempOrder = this.ensureTempOrder();
2041
1414
  linked = booking ? this.createLinkedProductAndBooking({
@@ -2045,11 +1418,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2045
1418
  productToAdd = (linked === null || linked === void 0 ? void 0 : linked.product) || product;
2046
1419
  incomingFingerprint = buildProductLineFingerprint(productToAdd.product_option_item, productToAdd.product_bundle);
2047
1420
  normalizedIncoming = normalizeOrderProduct(productToAdd);
2048
- normalizedIncoming.discount_list = normalizeOrderProductDiscountList(normalizedIncoming.discount_list);
2049
1421
  hasIncomingGoodPass = this.hasGoodPassDiscount(normalizedIncoming);
2050
1422
  shouldForceNewLine = !!booking;
2051
1423
  matchedIndex = hasIncomingGoodPass || shouldForceNewLine ? -1 : tempOrder.products.findIndex(function (item) {
2052
- if (_this7.hasGoodPassDiscount(item)) return false;
1424
+ if (_this3.hasGoodPassDiscount(item)) return false;
2053
1425
  if (item.product_id !== productToAdd.product_id) return false;
2054
1426
  if (item.product_variant_id !== productToAdd.product_variant_id) return false;
2055
1427
  var existedFingerprint = buildProductLineFingerprint(item.product_option_item, item.product_bundle);
@@ -2058,10 +1430,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2058
1430
  matchedProduct = matchedIndex === -1 ? null : tempOrder.products[matchedIndex];
2059
1431
  existedFingerprint = matchedProduct ? buildProductLineFingerprint(matchedProduct.product_option_item, matchedProduct.product_bundle) : '';
2060
1432
  if (!matchedProduct) {
2061
- _context18.next = 17;
1433
+ _context13.next = 16;
2062
1434
  break;
2063
1435
  }
2064
- _context18.next = 14;
1436
+ _context13.next = 13;
2065
1437
  return this.shouldMergeProductToOrder({
2066
1438
  incomingProduct: productToAdd,
2067
1439
  normalizedIncoming: normalizedIncoming,
@@ -2072,14 +1444,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2072
1444
  tempOrder: tempOrder,
2073
1445
  booking: booking
2074
1446
  });
2075
- case 14:
2076
- _context18.t0 = _context18.sent;
2077
- _context18.next = 18;
1447
+ case 13:
1448
+ _context13.t0 = _context13.sent;
1449
+ _context13.next = 17;
2078
1450
  break;
1451
+ case 16:
1452
+ _context13.t0 = false;
2079
1453
  case 17:
2080
- _context18.t0 = false;
2081
- case 18:
2082
- shouldMerge = _context18.t0;
1454
+ shouldMerge = _context13.t0;
2083
1455
  if (matchedIndex === -1 || !matchedProduct || !shouldMerge) {
2084
1456
  this.captureProductRuntime(tempOrder, productToAdd, normalizedIncoming);
2085
1457
  if (linked) {
@@ -2097,7 +1469,6 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2097
1469
  unique_identification_number: targetUid
2098
1470
  })
2099
1471
  }));
2100
- normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
2101
1472
  tempOrder.products[matchedIndex] = _objectSpread(_objectSpread(_objectSpread({}, targetProduct), normalizedProduct), {}, {
2102
1473
  metadata: _objectSpread(_objectSpread(_objectSpread({}, targetProduct.metadata || {}), normalizedProduct.metadata || {}), {}, {
2103
1474
  unique_identification_number: targetUid
@@ -2111,24 +1482,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2111
1482
  if (linked) {
2112
1483
  tempOrder.bookings = [].concat(_toConsumableArray(tempOrder.bookings || []), [linked.booking]);
2113
1484
  }
2114
- _context18.next = 23;
2115
- return this.applyPromotion();
2116
- case 23:
2117
1485
  this.applyDiscount();
2118
- _context18.next = 26;
1486
+ _context13.next = 23;
2119
1487
  return this.recalculateSummary({
2120
1488
  createIfMissing: true
2121
1489
  });
2122
- case 26:
1490
+ case 23:
2123
1491
  this.persistTempOrder();
2124
- return _context18.abrupt("return", tempOrder.products);
2125
- case 28:
1492
+ return _context13.abrupt("return", tempOrder.products);
1493
+ case 25:
2126
1494
  case "end":
2127
- return _context18.stop();
1495
+ return _context13.stop();
2128
1496
  }
2129
- }, _callee16, this);
1497
+ }, _callee13, this);
2130
1498
  }));
2131
- function addProductToOrder(_x16, _x17) {
1499
+ function addProductToOrder(_x12, _x13) {
2132
1500
  return _addProductToOrder.apply(this, arguments);
2133
1501
  }
2134
1502
  return addProductToOrder;
@@ -2153,15 +1521,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2153
1521
  });
2154
1522
  }
2155
1523
  }, {
2156
- key: "updateOrderProduct",
1524
+ key: "updateProductInOrder",
2157
1525
  value: function () {
2158
- var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(params) {
1526
+ var _updateProductInOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(params) {
2159
1527
  var _targetProduct$metada2, _metadata, _metadata2, _metadata3, _tempOrder$products$p;
2160
- 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;
2161
- return _regeneratorRuntime().wrap(function _callee17$(_context19) {
2162
- 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) {
2163
1531
  case 0:
2164
- 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;
2165
1533
  tempOrder = this.ensureTempOrder();
2166
1534
  identityLookup = {
2167
1535
  product_id: product_id,
@@ -2169,32 +1537,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2169
1537
  };
2170
1538
  if (unique_identification_number !== undefined) {
2171
1539
  identityLookup.unique_identification_number = unique_identification_number;
2172
- if (identity_key === undefined) {
2173
- identityLookup.identity_key = unique_identification_number;
2174
- }
2175
- }
2176
- if (identity_key !== undefined) {
2177
- identityLookup.identity_key = identity_key;
2178
1540
  }
2179
1541
  if (product_option_item !== undefined) identityLookup.product_option_item = product_option_item;
2180
1542
  if (product_bundle !== undefined) identityLookup.product_bundle = product_bundle;
2181
- productIndex = -1;
2182
- if (unique_identification_number !== undefined) {
2183
- targetUid = String(unique_identification_number);
2184
- productIndex = tempOrder.products.findIndex(function (item) {
2185
- var _item$metadata;
2186
- return String(((_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.unique_identification_number) || item.unique_identification_number || '') === targetUid;
2187
- });
2188
- }
2189
- if (productIndex === -1) {
2190
- productIndex = getProductIdentityIndex(tempOrder.products, identityLookup);
2191
- }
1543
+ productIndex = getProductIdentityIndex(tempOrder.products, identityLookup);
2192
1544
  if (!(productIndex === -1)) {
2193
- _context19.next = 12;
1545
+ _context14.next = 9;
2194
1546
  break;
2195
1547
  }
2196
1548
  throw new Error('[Order] 目标商品不存在,无法更新');
2197
- case 12:
1549
+ case 9:
2198
1550
  targetProduct = tempOrder.products[productIndex];
2199
1551
  nextProduct = _objectSpread(_objectSpread(_objectSpread({}, targetProduct), updates), {}, {
2200
1552
  product_id: product_id,
@@ -2222,230 +1574,57 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2222
1574
  }
2223
1575
  // normalizeOrderProduct 幂等:v2 metadata 存在 → 保留 main_product_* 折扣重算 composite;
2224
1576
  // 否则 → 把顶层 selling_price 视作 source,派生 main_product_* 并写 price_schema_version: 2。
2225
- normalizedProduct = normalizeOrderProduct(nextProduct);
2226
- normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
2227
- if (booking) {
2228
- 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());
2229
- normalizedProduct.metadata = _objectSpread(_objectSpread({}, normalizedProduct.metadata || {}), {}, {
2230
- unique_identification_number: productUid
2231
- });
2232
- linked = this.createLinkedProductAndBooking({
2233
- product: _objectSpread(_objectSpread({}, normalizedProduct), {}, {
2234
- unique_identification_number: productUid
2235
- }),
2236
- booking: booking
2237
- });
2238
- this.removeLinkedBookingsForProduct(tempOrder, targetProduct);
2239
- normalizedProduct = _objectSpread(_objectSpread({}, normalizedProduct), {}, {
2240
- booking_uid: linked.bookingUid,
2241
- metadata: _objectSpread(_objectSpread({}, normalizedProduct.metadata || {}), {}, {
2242
- booking_uid: linked.bookingUid,
2243
- unique_identification_number: productUid
2244
- })
2245
- });
2246
- tempOrder.bookings = [].concat(_toConsumableArray(tempOrder.bookings || []), [linked.booking]);
2247
- }
2248
- tempOrder.products[productIndex] = normalizedProduct;
1577
+ tempOrder.products[productIndex] = normalizeOrderProduct(nextProduct);
2249
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);
2250
- _context19.next = 25;
2251
- return this.applyPromotion();
2252
- case 25:
2253
1579
  this.applyDiscount();
2254
- _context19.next = 28;
1580
+ _context14.next = 20;
2255
1581
  return this.recalculateSummary({
2256
1582
  createIfMissing: true
2257
1583
  });
2258
- case 28:
2259
- this.persistTempOrder();
2260
- return _context19.abrupt("return", tempOrder.products);
2261
- case 30:
2262
- case "end":
2263
- return _context19.stop();
2264
- }
2265
- }, _callee17, this);
2266
- }));
2267
- function updateOrderProduct(_x18) {
2268
- return _updateOrderProduct.apply(this, arguments);
2269
- }
2270
- return updateOrderProduct;
2271
- }()
2272
- }, {
2273
- key: "updateOrderProductQuantity",
2274
- value: function () {
2275
- var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(params) {
2276
- var _targetProduct$metada4;
2277
- var product_id, product_variant_id, num, unique_identification_number, identity_key, product_option_item, product_bundle, tempOrder, identityLookup, productIndex, targetUid, targetProduct, normalizedProduct;
2278
- return _regeneratorRuntime().wrap(function _callee18$(_context20) {
2279
- while (1) switch (_context20.prev = _context20.next) {
2280
- case 0:
2281
- 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;
2282
- tempOrder = this.ensureTempOrder();
2283
- identityLookup = {
2284
- product_id: product_id,
2285
- product_variant_id: product_variant_id
2286
- };
2287
- if (unique_identification_number !== undefined) {
2288
- identityLookup.unique_identification_number = unique_identification_number;
2289
- if (identity_key === undefined) {
2290
- identityLookup.identity_key = unique_identification_number;
2291
- }
2292
- }
2293
- if (identity_key !== undefined) identityLookup.identity_key = identity_key;
2294
- if (product_option_item !== undefined) identityLookup.product_option_item = product_option_item;
2295
- if (product_bundle !== undefined) identityLookup.product_bundle = product_bundle;
2296
- productIndex = -1;
2297
- if (unique_identification_number !== undefined) {
2298
- targetUid = String(unique_identification_number);
2299
- productIndex = tempOrder.products.findIndex(function (item) {
2300
- var _item$metadata2;
2301
- return String(((_item$metadata2 = item.metadata) === null || _item$metadata2 === void 0 ? void 0 : _item$metadata2.unique_identification_number) || item.unique_identification_number || '') === targetUid;
2302
- });
2303
- }
2304
- if (productIndex === -1) {
2305
- productIndex = getProductIdentityIndex(tempOrder.products, identityLookup);
2306
- }
2307
- if (!(productIndex === -1)) {
2308
- _context20.next = 12;
2309
- break;
2310
- }
2311
- throw new Error('[Order] 目标商品不存在,无法更新数量');
2312
- case 12:
2313
- targetProduct = tempOrder.products[productIndex];
2314
- normalizedProduct = normalizeOrderProduct(_objectSpread(_objectSpread({}, targetProduct), {}, {
2315
- num: getSafeProductNum(num),
2316
- metadata: _objectSpread(_objectSpread({}, targetProduct.metadata || {}), {}, {
2317
- unique_identification_number: ((_targetProduct$metada4 = targetProduct.metadata) === null || _targetProduct$metada4 === void 0 ? void 0 : _targetProduct$metada4.unique_identification_number) || unique_identification_number
2318
- })
2319
- }));
2320
- normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
2321
- tempOrder.products[productIndex] = normalizedProduct;
2322
- _context20.next = 18;
2323
- return this.applyPromotion();
2324
- case 18:
2325
- this.applyDiscount();
2326
- _context20.next = 21;
2327
- return this.recalculateSummary({
2328
- createIfMissing: true
2329
- });
2330
- case 21:
1584
+ case 20:
2331
1585
  this.persistTempOrder();
2332
- return _context20.abrupt("return", tempOrder.products);
2333
- case 23:
1586
+ return _context14.abrupt("return", tempOrder.products);
1587
+ case 22:
2334
1588
  case "end":
2335
- return _context20.stop();
1589
+ return _context14.stop();
2336
1590
  }
2337
- }, _callee18, this);
1591
+ }, _callee14, this);
2338
1592
  }));
2339
- function updateOrderProductQuantity(_x19) {
2340
- return _updateOrderProductQuantity.apply(this, arguments);
1593
+ function updateProductInOrder(_x14) {
1594
+ return _updateProductInOrder.apply(this, arguments);
2341
1595
  }
2342
- return updateOrderProductQuantity;
1596
+ return updateProductInOrder;
2343
1597
  }()
2344
- }, {
2345
- key: "updateOrderBooking",
2346
- value: function updateOrderBooking(params) {
2347
- var unique_identification_number = params.unique_identification_number,
2348
- updates = params.updates;
2349
- var tempOrder = this.ensureTempOrder();
2350
- var bookingUid = String(unique_identification_number || '');
2351
- var bookingIndex = this.findBookingIndexByUniqueIdentificationNumber(tempOrder, bookingUid);
2352
- if (!bookingUid || bookingIndex === -1) {
2353
- throw new Error('[Order] 目标 booking 不存在,无法更新');
2354
- }
2355
- var targetBooking = tempOrder.bookings[bookingIndex] || {};
2356
- var nextBooking = _objectSpread(_objectSpread(_objectSpread({}, targetBooking), updates), {}, {
2357
- metadata: _objectSpread(_objectSpread(_objectSpread({}, targetBooking.metadata || {}), updates.metadata || {}), {}, {
2358
- unique_identification_number: bookingUid
2359
- })
2360
- });
2361
- nextBooking.is_all = normalizeBookingIsAll(nextBooking);
2362
- nextBooking.sub_type = normalizeBookingSubType(nextBooking);
2363
- tempOrder.bookings[bookingIndex] = nextBooking;
2364
- this.persistTempOrder();
2365
- return tempOrder.bookings;
2366
- }
2367
1598
  }, {
2368
1599
  key: "removeProductFromOrder",
2369
1600
  value: function () {
2370
- var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(identity) {
2371
- var tempOrder, removedProducts, _i, _removedProducts, product;
2372
- return _regeneratorRuntime().wrap(function _callee19$(_context21) {
2373
- 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) {
2374
1605
  case 0:
2375
1606
  tempOrder = this.ensureTempOrder();
2376
- removedProducts = [];
2377
1607
  tempOrder.products = tempOrder.products.filter(function (item) {
2378
- var shouldRemove = isIdentityMatch(item, identity);
2379
- if (shouldRemove) removedProducts.push(item);
2380
- return !shouldRemove;
1608
+ return !isIdentityMatch(item, identity);
2381
1609
  });
2382
- for (_i = 0, _removedProducts = removedProducts; _i < _removedProducts.length; _i++) {
2383
- product = _removedProducts[_i];
2384
- this.removeLinkedBookingsForProduct(tempOrder, product);
2385
- }
2386
- _context21.next = 6;
2387
- return this.applyPromotion();
2388
- case 6:
2389
1610
  this.applyDiscount();
2390
- _context21.next = 9;
1611
+ _context15.next = 5;
2391
1612
  return this.recalculateSummary({
2392
1613
  createIfMissing: true
2393
1614
  });
2394
- case 9:
1615
+ case 5:
2395
1616
  this.persistTempOrder();
2396
- return _context21.abrupt("return", tempOrder.products);
2397
- case 11:
1617
+ return _context15.abrupt("return", tempOrder.products);
1618
+ case 7:
2398
1619
  case "end":
2399
- return _context21.stop();
1620
+ return _context15.stop();
2400
1621
  }
2401
- }, _callee19, this);
1622
+ }, _callee15, this);
2402
1623
  }));
2403
- function removeProductFromOrder(_x20) {
1624
+ function removeProductFromOrder(_x15) {
2404
1625
  return _removeProductFromOrder.apply(this, arguments);
2405
1626
  }
2406
1627
  return removeProductFromOrder;
2407
- }()
2408
- /**
2409
- * 仅清空购物车行(products / bookings),不重置整单。
2410
- * 用于「仅清空商品」;客户、备注、支付等协议字段保持不变。
2411
- */
2412
- }, {
2413
- key: "clearOrderCartLines",
2414
- value: (function () {
2415
- var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
2416
- var tempOrder;
2417
- return _regeneratorRuntime().wrap(function _callee20$(_context22) {
2418
- while (1) switch (_context22.prev = _context22.next) {
2419
- case 0:
2420
- tempOrder = this.ensureTempOrder();
2421
- tempOrder.products = [];
2422
- tempOrder.bookings = [];
2423
- if (tempOrder._extend && _typeof(tempOrder._extend) === 'object') {
2424
- tempOrder._extend = _objectSpread(_objectSpread({}, tempOrder._extend), {}, {
2425
- productsByUid: {}
2426
- });
2427
- }
2428
- _context22.next = 6;
2429
- return this.applyPromotion();
2430
- case 6:
2431
- this.applyDiscount();
2432
- _context22.next = 9;
2433
- return this.recalculateSummary({
2434
- createIfMissing: true
2435
- });
2436
- case 9:
2437
- this.persistTempOrder();
2438
- return _context22.abrupt("return", tempOrder);
2439
- case 11:
2440
- case "end":
2441
- return _context22.stop();
2442
- }
2443
- }, _callee20, this);
2444
- }));
2445
- function clearOrderCartLines() {
2446
- return _clearOrderCartLines.apply(this, arguments);
2447
- }
2448
- return clearOrderCartLines;
2449
1628
  }() // ─── TempOrder: 提交 ───
2450
1629
  /**
2451
1630
  * 提交当前 Sales tempOrder。
@@ -2453,15 +1632,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2453
1632
  * smallTicketDataFlag 用于 B 端 checkout 小票数据返回。PaymentModal 在支付提交时
2454
1633
  * 应传 1,确保 /order/sales/checkout 返回打印所需数据。
2455
1634
  */
2456
- )
2457
1635
  }, {
2458
1636
  key: "submitTempOrder",
2459
1637
  value: function () {
2460
- var _submitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(params) {
1638
+ var _submitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(params) {
2461
1639
  var _params$cacheId, _this$otherParams;
2462
1640
  var tempOrder, effectiveCacheId, hasPaymentOverride, hasPaymentStatusOverride, hasSmallTicketDataFlagOverride, enhancePayload, payload, result, _payload$payments, _payload$payments2, backendErrorResponse, submittedOrderId, resultRecord;
2463
- return _regeneratorRuntime().wrap(function _callee21$(_context23) {
2464
- while (1) switch (_context23.prev = _context23.next) {
1641
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1642
+ while (1) switch (_context16.prev = _context16.next) {
2465
1643
  case 0:
2466
1644
  tempOrder = this.ensureTempOrder();
2467
1645
  this.persistTempOrder();
@@ -2477,8 +1655,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2477
1655
  } : {}), hasSmallTicketDataFlagOverride ? {
2478
1656
  small_ticket_data_flag: params === null || params === void 0 ? void 0 : params.smallTicketDataFlag
2479
1657
  } : {});
2480
- var enhancedPayload = params !== null && params !== void 0 && params.enhancePayload ? params.enhancePayload(nextPayload, ctx) : nextPayload;
2481
- return enhancedPayload;
1658
+ return params !== null && params !== void 0 && params.enhancePayload ? params.enhancePayload(nextPayload, ctx) : nextPayload;
2482
1659
  } : undefined;
2483
1660
  payload = buildSubmitPayload({
2484
1661
  tempOrder: tempOrder,
@@ -2489,74 +1666,73 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2489
1666
  type: params === null || params === void 0 ? void 0 : params.type,
2490
1667
  enhance: enhancePayload
2491
1668
  });
2492
- _context23.next = 10;
1669
+ _context16.next = 10;
2493
1670
  return this.saveDraft();
2494
1671
  case 10:
2495
- _context23.prev = 10;
1672
+ _context16.prev = 10;
2496
1673
  this.logInfo('submitTempOrder calling sales checkout', {
2497
1674
  orderId: payload.order_id,
2498
1675
  externalSaleNumber: payload.external_sale_number,
2499
- requestUniqueIdempotencyToken: payload.request_unique_idempotency_token,
2500
1676
  paymentStatus: payload.payment_status,
2501
1677
  paymentsCount: ((_payload$payments = payload.payments) === null || _payload$payments === void 0 ? void 0 : _payload$payments.length) || 0,
2502
1678
  smallTicketDataFlag: payload.small_ticket_data_flag
2503
1679
  });
2504
- _context23.next = 14;
1680
+ _context16.next = 14;
2505
1681
  return this.submitSalesOrder({
2506
1682
  query: payload
2507
1683
  });
2508
1684
  case 14:
2509
- result = _context23.sent;
2510
- _context23.next = 27;
1685
+ result = _context16.sent;
1686
+ _context16.next = 27;
2511
1687
  break;
2512
1688
  case 17:
2513
- _context23.prev = 17;
2514
- _context23.t0 = _context23["catch"](10);
2515
- backendErrorResponse = this.extractSubmitErrorResponse(_context23.t0);
1689
+ _context16.prev = 17;
1690
+ _context16.t0 = _context16["catch"](10);
1691
+ backendErrorResponse = this.extractSubmitErrorResponse(_context16.t0);
2516
1692
  if (!backendErrorResponse) {
2517
- _context23.next = 24;
1693
+ _context16.next = 24;
2518
1694
  break;
2519
1695
  }
2520
1696
  this.store.syncState = 'failed';
2521
1697
  this.logSubmitBackendRejected(backendErrorResponse, payload);
2522
- return _context23.abrupt("return", backendErrorResponse);
1698
+ return _context16.abrupt("return", backendErrorResponse);
2523
1699
  case 24:
2524
1700
  this.store.syncState = 'failed';
2525
1701
  this.logError('submitTempOrder failed', {
2526
- error: _context23.t0 instanceof Error ? _context23.t0.message : String(_context23.t0),
1702
+ error: _context16.t0 instanceof Error ? _context16.t0.message : String(_context16.t0),
2527
1703
  orderId: payload.order_id,
2528
1704
  externalSaleNumber: payload.external_sale_number,
2529
1705
  paymentStatus: payload.payment_status,
2530
1706
  paymentsCount: ((_payload$payments2 = payload.payments) === null || _payload$payments2 === void 0 ? void 0 : _payload$payments2.length) || 0
2531
1707
  });
2532
- throw _context23.t0;
1708
+ throw _context16.t0;
2533
1709
  case 27:
2534
1710
  if (!this.isSubmitResponseRejected(result)) {
2535
- _context23.next = 31;
1711
+ _context16.next = 31;
2536
1712
  break;
2537
1713
  }
2538
1714
  this.store.syncState = 'failed';
2539
1715
  this.logSubmitBackendRejected(result, payload);
2540
- return _context23.abrupt("return", result);
1716
+ return _context16.abrupt("return", result);
2541
1717
  case 31:
2542
1718
  submittedOrderId = this.extractOrderIdFromSubmitResult(result);
2543
1719
  if (!(submittedOrderId !== null && submittedOrderId !== undefined)) {
2544
- _context23.next = 37;
1720
+ _context16.next = 37;
2545
1721
  break;
2546
1722
  }
2547
1723
  tempOrder.order_id = submittedOrderId;
2548
1724
  resultRecord = result;
2549
- _context23.next = 37;
1725
+ _context16.next = 37;
2550
1726
  return this.markLocalOrderSynced(submittedOrderId, (resultRecord === null || resultRecord === void 0 ? void 0 : resultRecord.data) || resultRecord || {});
2551
1727
  case 37:
2552
- return _context23.abrupt("return", result);
1728
+ return _context16.abrupt("return", result);
2553
1729
  case 38:
2554
1730
  case "end":
2555
- return _context23.stop();
1731
+ return _context16.stop();
2556
1732
  }
2557
- }, _callee21, this, [[10, 17]]);
1733
+ }, _callee16, this, [[10, 17]]);
2558
1734
  }));
2559
- function submitTempOrder(_x21) {
1735
+ function submitTempOrder(_x16) {
2560
1736
  return _submitTempOrder.apply(this, arguments);
2561
1737
  }
2562
1738
  return submitTempOrder;
@@ -2564,25 +1740,25 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2564
1740
  }, {
2565
1741
  key: "markLocalOrderSynced",
2566
1742
  value: function () {
2567
- var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(orderId, remoteOrder) {
1743
+ var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(orderId, remoteOrder) {
2568
1744
  var tempOrder;
2569
- return _regeneratorRuntime().wrap(function _callee22$(_context24) {
2570
- while (1) switch (_context24.prev = _context24.next) {
1745
+ return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1746
+ while (1) switch (_context17.prev = _context17.next) {
2571
1747
  case 0:
2572
1748
  tempOrder = this.ensureTempOrder();
2573
1749
  tempOrder.order_id = orderId;
2574
1750
  this.store.lastOrderInfo = remoteOrder;
2575
1751
  this.store.syncState = 'submitted';
2576
1752
  this.persistTempOrder();
2577
- _context24.next = 7;
1753
+ _context17.next = 7;
2578
1754
  return this.saveDraft();
2579
1755
  case 7:
2580
1756
  case "end":
2581
- return _context24.stop();
1757
+ return _context17.stop();
2582
1758
  }
2583
- }, _callee22, this);
1759
+ }, _callee17, this);
2584
1760
  }));
2585
- function markLocalOrderSynced(_x22, _x23) {
1761
+ function markLocalOrderSynced(_x17, _x18) {
2586
1762
  return _markLocalOrderSynced.apply(this, arguments);
2587
1763
  }
2588
1764
  return markLocalOrderSynced;
@@ -2606,10 +1782,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2606
1782
  value: function extractSubmitErrorResponse(error) {
2607
1783
  var _error$response,
2608
1784
  _error$response2,
2609
- _this8 = this;
1785
+ _this4 = this;
2610
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];
2611
1787
  return candidates.find(function (candidate) {
2612
- return _this8.isSubmitErrorResponse(candidate);
1788
+ return _this4.isSubmitErrorResponse(candidate);
2613
1789
  }) || null;
2614
1790
  }
2615
1791
  }, {
@@ -2629,67 +1805,49 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2629
1805
  }, {
2630
1806
  key: "syncPaymentsToOrder",
2631
1807
  value: function () {
2632
- var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(params) {
2633
- var tempOrder, mappedPayments, paymentTotal, targetAmount, isFullyPaid, paymentStatus, paymentSyncIdempotencyToken, submitResult;
2634
- return _regeneratorRuntime().wrap(function _callee23$(_context25) {
2635
- 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) {
2636
1812
  case 0:
2637
1813
  tempOrder = this.ensureTempOrder();
2638
1814
  mappedPayments = mapPaymentItemsToOrderPayments(params.payments || []);
2639
- paymentTotal = this.calculatePaymentTotal(mappedPayments);
2640
- targetAmount = this.getPaymentTargetAmount();
2641
- isFullyPaid = targetAmount.lte(0) ? false : paymentTotal.gte(targetAmount);
2642
- paymentStatus = isFullyPaid ? params.paymentStatus || 'paid' : 'partially_paid';
2643
1815
  tempOrder.payments = mappedPayments;
2644
- tempOrder.payment_status = paymentStatus;
1816
+ if (params.paymentStatus) tempOrder.payment_status = params.paymentStatus;
2645
1817
  this.persistTempOrder();
2646
- _context25.next = 11;
1818
+ _context18.next = 7;
2647
1819
  return this.saveDraft();
2648
- case 11:
2649
- if (params.submitWhenPaid) {
2650
- _context25.next = 13;
2651
- break;
2652
- }
2653
- return _context25.abrupt("return", {
2654
- isFullyPaid: isFullyPaid
2655
- });
2656
- case 13:
2657
- if (!(this.store.syncState === 'submitting')) {
2658
- _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;
2659
1826
  break;
2660
1827
  }
2661
- return _context25.abrupt("return", {
1828
+ return _context18.abrupt("return", {
2662
1829
  isFullyPaid: isFullyPaid
2663
1830
  });
2664
- case 15:
2665
- this.store.syncState = 'submitting';
2666
- paymentSyncIdempotencyToken = this.buildPaymentSyncIdempotencyToken(tempOrder, mappedPayments);
2667
- _context25.next = 19;
1831
+ case 12:
1832
+ _context18.next = 14;
2668
1833
  return this.submitTempOrder({
2669
1834
  payments: mappedPayments,
2670
- paymentStatus: paymentStatus,
2671
- smallTicketDataFlag: params.smallTicketDataFlag,
2672
- channel: params.channel,
2673
- enhancePayload: function enhancePayload(payload) {
2674
- var nextPayload = _objectSpread(_objectSpread({}, payload), {}, {
2675
- request_unique_idempotency_token: paymentSyncIdempotencyToken
2676
- });
2677
- return nextPayload;
2678
- }
1835
+ paymentStatus: params.paymentStatus || 'paid',
1836
+ smallTicketDataFlag: params.smallTicketDataFlag
2679
1837
  });
2680
- case 19:
2681
- submitResult = _context25.sent;
2682
- return _context25.abrupt("return", {
1838
+ case 14:
1839
+ submitResult = _context18.sent;
1840
+ return _context18.abrupt("return", {
2683
1841
  isFullyPaid: isFullyPaid,
2684
1842
  submitResult: submitResult
2685
1843
  });
2686
- case 21:
1844
+ case 16:
2687
1845
  case "end":
2688
- return _context25.stop();
1846
+ return _context18.stop();
2689
1847
  }
2690
- }, _callee23, this);
1848
+ }, _callee18, this);
2691
1849
  }));
2692
- function syncPaymentsToOrder(_x24) {
1850
+ function syncPaymentsToOrder(_x19) {
2693
1851
  return _syncPaymentsToOrder.apply(this, arguments);
2694
1852
  }
2695
1853
  return syncPaymentsToOrder;
@@ -2778,11 +1936,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2778
1936
  }, {
2779
1937
  key: "submitOrder",
2780
1938
  value: function () {
2781
- var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(order) {
1939
+ var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(order) {
2782
1940
  var _order$query$cartItem, _params$bookings, _params$relation_prod;
2783
1941
  var url, query, fetchUrl, params;
2784
- return _regeneratorRuntime().wrap(function _callee24$(_context26) {
2785
- while (1) switch (_context26.prev = _context26.next) {
1942
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1943
+ while (1) switch (_context19.prev = _context19.next) {
2786
1944
  case 0:
2787
1945
  this.logInfo('submitOrder called', {
2788
1946
  url: order.url,
@@ -2802,14 +1960,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2802
1960
  relationProductsCount: ((_params$relation_prod = params.relation_products) === null || _params$relation_prod === void 0 ? void 0 : _params$relation_prod.length) || 0,
2803
1961
  scheduleDate: params.schedule_date
2804
1962
  });
2805
- return _context26.abrupt("return", this.request.post(fetchUrl, params));
1963
+ return _context19.abrupt("return", this.request.post(fetchUrl, params));
2806
1964
  case 6:
2807
1965
  case "end":
2808
- return _context26.stop();
1966
+ return _context19.stop();
2809
1967
  }
2810
- }, _callee24, this);
1968
+ }, _callee19, this);
2811
1969
  }));
2812
- function submitOrder(_x25) {
1970
+ function submitOrder(_x20) {
2813
1971
  return _submitOrder.apply(this, arguments);
2814
1972
  }
2815
1973
  return submitOrder;
@@ -2817,13 +1975,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2817
1975
  }, {
2818
1976
  key: "cancelOrder",
2819
1977
  value: function () {
2820
- var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(params) {
1978
+ var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(params) {
2821
1979
  var payload;
2822
- return _regeneratorRuntime().wrap(function _callee25$(_context27) {
2823
- while (1) switch (_context27.prev = _context27.next) {
1980
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1981
+ while (1) switch (_context20.prev = _context20.next) {
2824
1982
  case 0:
2825
1983
  if (!(!Array.isArray(params.order_ids) || params.order_ids.length === 0)) {
2826
- _context27.next = 2;
1984
+ _context20.next = 2;
2827
1985
  break;
2828
1986
  }
2829
1987
  throw new Error('取消订单失败:order_ids 不能为空');
@@ -2839,16 +1997,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2839
1997
  method: 'PUT',
2840
1998
  orderIdsCount: params.order_ids.length
2841
1999
  });
2842
- return _context27.abrupt("return", this.request.put('/order/update-status', payload, {
2000
+ return _context20.abrupt("return", this.request.put('/order/update-status', payload, {
2843
2001
  isShopApi: true
2844
2002
  }));
2845
2003
  case 5:
2846
2004
  case "end":
2847
- return _context27.stop();
2005
+ return _context20.stop();
2848
2006
  }
2849
- }, _callee25, this);
2007
+ }, _callee20, this);
2850
2008
  }));
2851
- function cancelOrder(_x26) {
2009
+ function cancelOrder(_x21) {
2852
2010
  return _cancelOrder.apply(this, arguments);
2853
2011
  }
2854
2012
  return cancelOrder;
@@ -2856,19 +2014,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2856
2014
  }, {
2857
2015
  key: "changeBookingStatus",
2858
2016
  value: function () {
2859
- var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(params) {
2017
+ var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(params) {
2860
2018
  var url, payload;
2861
- return _regeneratorRuntime().wrap(function _callee26$(_context28) {
2862
- while (1) switch (_context28.prev = _context28.next) {
2019
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
2020
+ while (1) switch (_context21.prev = _context21.next) {
2863
2021
  case 0:
2864
2022
  if (params.booking_id) {
2865
- _context28.next = 2;
2023
+ _context21.next = 2;
2866
2024
  break;
2867
2025
  }
2868
2026
  throw new Error('变更预约状态失败:booking_id 不能为空');
2869
2027
  case 2:
2870
2028
  if (params.appointment_status) {
2871
- _context28.next = 4;
2029
+ _context21.next = 4;
2872
2030
  break;
2873
2031
  }
2874
2032
  throw new Error('变更预约状态失败:appointment_status 不能为空');
@@ -2883,16 +2041,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2883
2041
  bookingId: params.booking_id,
2884
2042
  appointmentStatus: params.appointment_status
2885
2043
  });
2886
- return _context28.abrupt("return", this.request.put(url, payload, {
2044
+ return _context21.abrupt("return", this.request.put(url, payload, {
2887
2045
  isShopApi: true
2888
2046
  }));
2889
2047
  case 8:
2890
2048
  case "end":
2891
- return _context28.stop();
2049
+ return _context21.stop();
2892
2050
  }
2893
- }, _callee26, this);
2051
+ }, _callee21, this);
2894
2052
  }));
2895
- function changeBookingStatus(_x27) {
2053
+ function changeBookingStatus(_x22) {
2896
2054
  return _changeBookingStatus.apply(this, arguments);
2897
2055
  }
2898
2056
  return changeBookingStatus;
@@ -2910,11 +2068,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2910
2068
  }, {
2911
2069
  key: "createOrderByCheckout",
2912
2070
  value: (function () {
2913
- var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(params) {
2071
+ var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(params) {
2914
2072
  var _params$payments, _params$bookings2, _params$relation_prod2, _params$payments2, _params$payments3, _params$bookings3, _params$relation_prod3, _params$payments4;
2915
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;
2916
- return _regeneratorRuntime().wrap(function _callee27$(_context29) {
2917
- while (1) switch (_context29.prev = _context29.next) {
2074
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
2075
+ while (1) switch (_context22.prev = _context22.next) {
2918
2076
  case 0:
2919
2077
  // 过滤掉由在线店铺下单的 payment 支付数据
2920
2078
  onlineStorePaymentCodeList = ['WXPAY', 'WECHAT', 'ALIPAY', 'APPLE_PAY', 'CREDIT_CARD_3DS', 'CREDIT_CARD_TOKEN', 'GOOGLE_PAY', 'GOOGLE_PAY_3DS', 'CREDIT_CARD'];
@@ -2948,7 +2106,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2948
2106
  relationProductsCount: ((_params$relation_prod3 = params.relation_products) === null || _params$relation_prod3 === void 0 ? void 0 : _params$relation_prod3.length) || 0,
2949
2107
  paymentsCount: ((_params$payments4 = params.payments) === null || _params$payments4 === void 0 ? void 0 : _params$payments4.length) || 0
2950
2108
  });
2951
- _context29.prev = 4;
2109
+ _context22.prev = 4;
2952
2110
  // 构建订单数据,设置默认值并允许 params 覆盖
2953
2111
  orderData = _objectSpread({
2954
2112
  sales_channel: 'my_pisel',
@@ -3012,10 +2170,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3012
2170
  });
3013
2171
 
3014
2172
  // 调用后端接口
3015
- _context29.next = 12;
2173
+ _context22.next = 12;
3016
2174
  return this.request.post('/order/checkout', orderData);
3017
2175
  case 12:
3018
- response = _context29.sent;
2176
+ response = _context22.sent;
3019
2177
  this.logInfo('Order API called successfully', {
3020
2178
  response: response
3021
2179
  });
@@ -3023,22 +2181,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3023
2181
  success: !!response,
3024
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)
3025
2183
  });
3026
- return _context29.abrupt("return", response);
2184
+ return _context22.abrupt("return", response);
3027
2185
  case 18:
3028
- _context29.prev = 18;
3029
- _context29.t0 = _context29["catch"](4);
3030
- console.error('[Order] createOrderByCheckout 创建订单失败:', _context29.t0);
2186
+ _context22.prev = 18;
2187
+ _context22.t0 = _context22["catch"](4);
2188
+ console.error('[Order] createOrderByCheckout 创建订单失败:', _context22.t0);
3031
2189
  this.logInfo('Order API called failed', {
3032
- error: _context29.t0 instanceof Error ? _context29.t0.message : String(_context29.t0)
2190
+ error: _context22.t0 instanceof Error ? _context22.t0.message : String(_context22.t0)
3033
2191
  });
3034
- throw _context29.t0;
2192
+ throw _context22.t0;
3035
2193
  case 23:
3036
2194
  case "end":
3037
- return _context29.stop();
2195
+ return _context22.stop();
3038
2196
  }
3039
- }, _callee27, this, [[4, 18]]);
2197
+ }, _callee22, this, [[4, 18]]);
3040
2198
  }));
3041
- function createOrderByCheckout(_x28) {
2199
+ function createOrderByCheckout(_x23) {
3042
2200
  return _createOrderByCheckout.apply(this, arguments);
3043
2201
  }
3044
2202
  return createOrderByCheckout;
@@ -3046,23 +2204,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3046
2204
  }, {
3047
2205
  key: "submitSalesOrder",
3048
2206
  value: function () {
3049
- var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(params) {
2207
+ var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(params) {
3050
2208
  var url, query, fetchUrl;
3051
- return _regeneratorRuntime().wrap(function _callee28$(_context30) {
3052
- while (1) switch (_context30.prev = _context30.next) {
2209
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
2210
+ while (1) switch (_context23.prev = _context23.next) {
3053
2211
  case 0:
3054
2212
  url = params.url, query = params.query;
3055
2213
  fetchUrl = url || '/order/sales/checkout';
3056
- return _context30.abrupt("return", this.request.post(fetchUrl, query, {
2214
+ return _context23.abrupt("return", this.request.post(fetchUrl, query, {
3057
2215
  customToast: function customToast() {}
3058
2216
  }));
3059
2217
  case 3:
3060
2218
  case "end":
3061
- return _context30.stop();
2219
+ return _context23.stop();
3062
2220
  }
3063
- }, _callee28, this);
2221
+ }, _callee23, this);
3064
2222
  }));
3065
- function submitSalesOrder(_x29) {
2223
+ function submitSalesOrder(_x24) {
3066
2224
  return _submitSalesOrder.apply(this, arguments);
3067
2225
  }
3068
2226
  return submitSalesOrder;
@@ -3076,37 +2234,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3076
2234
  }, {
3077
2235
  key: "sendCustomerPayLink",
3078
2236
  value: (function () {
3079
- var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(params) {
2237
+ var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(params) {
3080
2238
  var _params$emails;
3081
2239
  var orderIds;
3082
- return _regeneratorRuntime().wrap(function _callee29$(_context31) {
3083
- while (1) switch (_context31.prev = _context31.next) {
2240
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2241
+ while (1) switch (_context24.prev = _context24.next) {
3084
2242
  case 0:
3085
2243
  orderIds = params.order_ids || params.orderIds || [];
3086
2244
  if (orderIds.length) {
3087
- _context31.next = 3;
2245
+ _context24.next = 3;
3088
2246
  break;
3089
2247
  }
3090
2248
  throw new Error('发送支付链接前必须先提交本地订单并取得订单 ID');
3091
2249
  case 3:
3092
2250
  if ((_params$emails = params.emails) !== null && _params$emails !== void 0 && _params$emails.length) {
3093
- _context31.next = 5;
2251
+ _context24.next = 5;
3094
2252
  break;
3095
2253
  }
3096
2254
  throw new Error('发送支付链接需要至少一个邮箱');
3097
2255
  case 5:
3098
- return _context31.abrupt("return", this.request.post('/order/batch-email', {
2256
+ return _context24.abrupt("return", this.request.post('/order/batch-email', {
3099
2257
  order_ids: orderIds,
3100
2258
  notify_action: params.notify_action || 'order_payment_reminder',
3101
2259
  emails: params.emails
3102
2260
  }));
3103
2261
  case 6:
3104
2262
  case "end":
3105
- return _context31.stop();
2263
+ return _context24.stop();
3106
2264
  }
3107
- }, _callee29, this);
2265
+ }, _callee24, this);
3108
2266
  }));
3109
- function sendCustomerPayLink(_x30) {
2267
+ function sendCustomerPayLink(_x25) {
3110
2268
  return _sendCustomerPayLink.apply(this, arguments);
3111
2269
  }
3112
2270
  return sendCustomerPayLink;
@@ -3115,28 +2273,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3115
2273
  }, {
3116
2274
  key: "getOrderInfoByRemote",
3117
2275
  value: function () {
3118
- var _getOrderInfoByRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(order_id) {
2276
+ var _getOrderInfoByRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(order_id) {
3119
2277
  var res;
3120
- return _regeneratorRuntime().wrap(function _callee30$(_context32) {
3121
- while (1) switch (_context32.prev = _context32.next) {
2278
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
2279
+ while (1) switch (_context25.prev = _context25.next) {
3122
2280
  case 0:
3123
- _context32.next = 2;
2281
+ _context25.next = 2;
3124
2282
  return this.request.get("/order/sales/".concat(order_id), {
3125
2283
  with: ['products', 'bookings', 'payments', 'customer', 'summary', 'contacts_info']
3126
2284
  });
3127
2285
  case 2:
3128
- res = _context32.sent;
2286
+ res = _context25.sent;
3129
2287
  if (res.code === 200) {
3130
2288
  this.store.lastOrderInfo = res.data;
3131
2289
  }
3132
- return _context32.abrupt("return", res);
2290
+ return _context25.abrupt("return", res);
3133
2291
  case 5:
3134
2292
  case "end":
3135
- return _context32.stop();
2293
+ return _context25.stop();
3136
2294
  }
3137
- }, _callee30, this);
2295
+ }, _callee25, this);
3138
2296
  }));
3139
- function getOrderInfoByRemote(_x31) {
2297
+ function getOrderInfoByRemote(_x26) {
3140
2298
  return _getOrderInfoByRemote.apply(this, arguments);
3141
2299
  }
3142
2300
  return getOrderInfoByRemote;
@@ -3150,92 +2308,79 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3150
2308
  }, {
3151
2309
  key: "hydrateTempOrderFromRecord",
3152
2310
  value: (function () {
3153
- var _hydrateTempOrderFromRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(record, options) {
3154
- var raw, nextTempOrder;
3155
- return _regeneratorRuntime().wrap(function _callee31$(_context33) {
3156
- 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) {
3157
2316
  case 0:
3158
2317
  raw = record && _typeof(record) === 'object' && record.data && record.order_id == null ? record.data : record || {};
3159
- nextTempOrder = this.normalizeTempOrderForRuntime(raw, {
3160
- 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
+ }
3161
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);
3162
2359
  this.store.tempOrder = nextTempOrder;
3163
2360
  this.store.summary = raw.summary && _typeof(raw.summary) === 'object' ? _objectSpread(_objectSpread({}, createEmptySummary()), raw.summary) : createEmptySummary();
3164
2361
  this.store.lastOrderInfo = raw.lastOrderInfo || raw;
3165
2362
  if (!(options !== null && options !== void 0 && options.recalcOnHydrate)) {
3166
- _context33.next = 8;
2363
+ _context26.next = 23;
3167
2364
  break;
3168
2365
  }
3169
- _context33.next = 8;
2366
+ _context26.next = 23;
3170
2367
  return this.recalculateSummary({
3171
2368
  createIfMissing: false
3172
2369
  });
3173
- case 8:
2370
+ case 23:
3174
2371
  this.persistTempOrder();
3175
- return _context33.abrupt("return", nextTempOrder);
3176
- case 10:
2372
+ return _context26.abrupt("return", nextTempOrder);
2373
+ case 25:
3177
2374
  case "end":
3178
- return _context33.stop();
2375
+ return _context26.stop();
3179
2376
  }
3180
- }, _callee31, this);
2377
+ }, _callee26, this);
3181
2378
  }));
3182
- function hydrateTempOrderFromRecord(_x32, _x33) {
2379
+ function hydrateTempOrderFromRecord(_x27, _x28) {
3183
2380
  return _hydrateTempOrderFromRecord.apply(this, arguments);
3184
2381
  }
3185
2382
  return hydrateTempOrderFromRecord;
3186
2383
  }())
3187
- }, {
3188
- key: "normalizeTempOrderForRuntime",
3189
- value: function normalizeTempOrderForRuntime(raw, options) {
3190
- var _this9 = this;
3191
- var nextTempOrder = _objectSpread(_objectSpread({}, this.createDefaultTempOrderInstance()), raw || {});
3192
- delete nextTempOrder.summary;
3193
- delete nextTempOrder.lastOrderInfo;
3194
- delete nextTempOrder.discount_list;
3195
- delete nextTempOrder.shop_id;
3196
- delete nextTempOrder.create_date;
3197
- delete nextTempOrder.total_amount;
3198
- delete nextTempOrder.expect_amount;
3199
- delete nextTempOrder.paid_amount;
3200
- delete nextTempOrder.shop_note;
3201
- delete nextTempOrder.start_time;
3202
- delete nextTempOrder.tax_fee;
3203
- delete nextTempOrder.total_refund_amount;
3204
- delete nextTempOrder.holder_id;
3205
- nextTempOrder.metadata = raw.metadata && _typeof(raw.metadata) === 'object' ? _objectSpread({}, raw.metadata) : {};
3206
- nextTempOrder.holder = raw.holder && _typeof(raw.holder) === 'object' ? _objectSpread({}, raw.holder) : null;
3207
- nextTempOrder.products = Array.isArray(raw.products) ? raw.products.map(function (p) {
3208
- return _this9.normalizeHydratedOrderProduct(p);
3209
- }) : [];
3210
- nextTempOrder.bookings = Array.isArray(raw.bookings) ? raw.bookings.map(function (b) {
3211
- return _objectSpread(_objectSpread({}, b || {}), {}, {
3212
- is_all: normalizeBookingIsAll(b || {}),
3213
- sub_type: normalizeBookingSubType(b || {})
3214
- });
3215
- }) : [];
3216
- nextTempOrder.payments = Array.isArray(raw.payments) ? raw.payments.map(function (p) {
3217
- return _objectSpread({}, p || {});
3218
- }) : [];
3219
- nextTempOrder.surcharges = Array.isArray(raw.surcharges) ? raw.surcharges.map(function (s) {
3220
- return _objectSpread({}, s || {});
3221
- }) : [];
3222
- nextTempOrder.relation_forms = Array.isArray(raw.relation_forms) ? raw.relation_forms.map(function (f) {
3223
- return _objectSpread({}, f || {});
3224
- }) : [];
3225
- nextTempOrder.contacts = Array.isArray(raw.contacts) ? raw.contacts.map(function (c) {
3226
- return _objectSpread({}, c || {});
3227
- }) : [];
3228
- nextTempOrder.contacts_info = raw.contacts_info && _typeof(raw.contacts_info) === 'object' && !Array.isArray(raw.contacts_info) ? _objectSpread({}, raw.contacts_info) : null;
3229
- nextTempOrder._extend = raw._extend && _typeof(raw._extend) === 'object' ? _objectSpread(_objectSpread({}, raw._extend), {}, {
3230
- productsByUid: raw._extend.productsByUid || {}
3231
- }) : {
3232
- productsByUid: {}
3233
- };
3234
- if ((options === null || options === void 0 ? void 0 : options.ensureIdentity) !== false) {
3235
- this.ensureExternalSaleNumber(nextTempOrder);
3236
- }
3237
- return nextTempOrder;
3238
- }
3239
2384
  }, {
3240
2385
  key: "normalizeHydratedOrderProduct",
3241
2386
  value: function normalizeHydratedOrderProduct(product) {
@@ -3251,7 +2396,6 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3251
2396
  row.metadata.unique_identification_number = createUuidV4();
3252
2397
  }
3253
2398
  var normalized = normalizeOrderProduct(row);
3254
- normalized.discount_list = normalizeOrderProductDiscountList(normalized.discount_list);
3255
2399
  var result = _objectSpread(_objectSpread(_objectSpread({}, row), normalized), {}, {
3256
2400
  metadata: _objectSpread(_objectSpread({}, row.metadata), normalized.metadata)
3257
2401
  });
@@ -3267,25 +2411,25 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3267
2411
  }, {
3268
2412
  key: "getOrderInfo",
3269
2413
  value: function () {
3270
- var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(order_id) {
2414
+ var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(order_id) {
3271
2415
  var res;
3272
- return _regeneratorRuntime().wrap(function _callee32$(_context34) {
3273
- while (1) switch (_context34.prev = _context34.next) {
2416
+ return _regeneratorRuntime().wrap(function _callee27$(_context27) {
2417
+ while (1) switch (_context27.prev = _context27.next) {
3274
2418
  case 0:
3275
- _context34.next = 2;
2419
+ _context27.next = 2;
3276
2420
  return this.request.get("/order/sales/".concat(order_id), {
3277
2421
  with: ['products', 'bookings']
3278
2422
  });
3279
2423
  case 2:
3280
- res = _context34.sent;
3281
- return _context34.abrupt("return", res);
2424
+ res = _context27.sent;
2425
+ return _context27.abrupt("return", res);
3282
2426
  case 4:
3283
2427
  case "end":
3284
- return _context34.stop();
2428
+ return _context27.stop();
3285
2429
  }
3286
- }, _callee32, this);
2430
+ }, _callee27, this);
3287
2431
  }));
3288
- function getOrderInfo(_x34) {
2432
+ function getOrderInfo(_x29) {
3289
2433
  return _getOrderInfo.apply(this, arguments);
3290
2434
  }
3291
2435
  return getOrderInfo;
@@ -3299,46 +2443,46 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3299
2443
  */
3300
2444
  function populateSavedAmounts(productList, discountList) {
3301
2445
  var savedMap = new Map();
3302
- var _iterator8 = _createForOfIteratorHelper(productList),
3303
- _step8;
2446
+ var _iterator = _createForOfIteratorHelper(productList),
2447
+ _step;
3304
2448
  try {
3305
- for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
3306
- var product = _step8.value;
2449
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
2450
+ var product = _step.value;
3307
2451
  var qty = product.num || 1;
3308
- var _iterator10 = _createForOfIteratorHelper(product.discount_list || []),
3309
- _step10;
2452
+ var _iterator3 = _createForOfIteratorHelper(product.discount_list || []),
2453
+ _step3;
3310
2454
  try {
3311
- for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
2455
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
3312
2456
  var _pd$discount, _pd$metadata;
3313
- var pd = _step10.value;
2457
+ var pd = _step3.value;
3314
2458
  var discountKey = ((_pd$discount = pd.discount) === null || _pd$discount === void 0 ? void 0 : _pd$discount.resource_id) || pd.id;
3315
2459
  if (discountKey == null) continue;
3316
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);
3317
2461
  savedMap.set(discountKey, (savedMap.get(discountKey) || new Decimal(0)).plus(amount));
3318
2462
  }
3319
2463
  } catch (err) {
3320
- _iterator10.e(err);
2464
+ _iterator3.e(err);
3321
2465
  } finally {
3322
- _iterator10.f();
2466
+ _iterator3.f();
3323
2467
  }
3324
2468
  }
3325
2469
  } catch (err) {
3326
- _iterator8.e(err);
2470
+ _iterator.e(err);
3327
2471
  } finally {
3328
- _iterator8.f();
2472
+ _iterator.f();
3329
2473
  }
3330
- var _iterator9 = _createForOfIteratorHelper(discountList),
3331
- _step9;
2474
+ var _iterator2 = _createForOfIteratorHelper(discountList),
2475
+ _step2;
3332
2476
  try {
3333
- for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
3334
- var d = _step9.value;
2477
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
2478
+ var d = _step2.value;
3335
2479
  var key = d.id;
3336
2480
  d.savedAmount = d.isSelected && key != null && savedMap.has(key) ? savedMap.get(key).toNumber() : 0;
3337
2481
  }
3338
2482
  } catch (err) {
3339
- _iterator9.e(err);
2483
+ _iterator2.e(err);
3340
2484
  } finally {
3341
- _iterator9.f();
2485
+ _iterator2.f();
3342
2486
  }
3343
2487
  }
3344
2488
  }]);