@pisell/pisellos 2.2.264 → 2.2.265

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 (152) hide show
  1. package/dist/model/strategy/adapter/dataVariant/adapter.d.ts +50 -0
  2. package/dist/model/strategy/adapter/dataVariant/adapter.js +167 -0
  3. package/dist/model/strategy/adapter/dataVariant/evaluator.d.ts +89 -0
  4. package/dist/model/strategy/adapter/dataVariant/evaluator.js +780 -0
  5. package/dist/model/strategy/adapter/dataVariant/examples.d.ts +39 -0
  6. package/dist/model/strategy/adapter/dataVariant/examples.js +277 -0
  7. package/dist/model/strategy/adapter/dataVariant/index.d.ts +4 -0
  8. package/dist/model/strategy/adapter/dataVariant/index.js +4 -0
  9. package/dist/model/strategy/adapter/dataVariant/type.d.ts +148 -0
  10. package/dist/model/strategy/adapter/dataVariant/type.js +54 -0
  11. package/dist/model/strategy/adapter/index.d.ts +4 -0
  12. package/dist/model/strategy/adapter/index.js +5 -1
  13. package/dist/model/strategy/adapter/promotion/adapter.d.ts +0 -4
  14. package/dist/model/strategy/adapter/promotion/adapter.js +0 -23
  15. package/dist/model/strategy/adapter/promotion/evaluator.d.ts +0 -17
  16. package/dist/model/strategy/adapter/promotion/evaluator.js +6 -279
  17. package/dist/model/strategy/adapter/promotion/examples.d.ts +0 -86
  18. package/dist/model/strategy/adapter/promotion/examples.js +0 -99
  19. package/dist/model/strategy/adapter/promotion/index.d.ts +1 -1
  20. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  21. package/dist/model/strategy/adapter/promotion/type.d.ts +2 -90
  22. package/dist/model/strategy/adapter/promotion/type.js +0 -45
  23. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +16 -10
  24. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +2 -1
  25. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +1 -1
  26. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +32 -1
  27. package/dist/modules/Discount/index.d.ts +5 -2
  28. package/dist/modules/Discount/index.js +30 -7
  29. package/dist/modules/Discount/types.d.ts +4 -0
  30. package/dist/modules/Order/index.d.ts +41 -10
  31. package/dist/modules/Order/index.js +1370 -808
  32. package/dist/modules/Order/payment-utils.d.ts +26 -0
  33. package/dist/modules/Order/payment-utils.js +225 -0
  34. package/dist/modules/Order/types.d.ts +49 -1
  35. package/dist/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
  36. package/dist/modules/Order/utils/orderCollectionIdentity.js +410 -0
  37. package/dist/modules/Order/utils.d.ts +4 -3
  38. package/dist/modules/Order/utils.js +62 -66
  39. package/dist/modules/Payment/index.d.ts +2 -0
  40. package/dist/modules/Payment/index.js +78 -49
  41. package/dist/modules/Payment/types.d.ts +26 -24
  42. package/dist/modules/Payment/types.js +2 -0
  43. package/dist/modules/Product/types.d.ts +22 -0
  44. package/dist/modules/ProductList/index.d.ts +1 -1
  45. package/dist/modules/ProductList/index.js +4 -2
  46. package/dist/modules/ProductList/types.d.ts +2 -0
  47. package/dist/modules/Rules/index.d.ts +2 -9
  48. package/dist/modules/Rules/index.js +69 -43
  49. package/dist/modules/Rules/types.d.ts +10 -1
  50. package/dist/server/index.d.ts +71 -0
  51. package/dist/server/index.js +2504 -1187
  52. package/dist/server/modules/order/index.d.ts +56 -5
  53. package/dist/server/modules/order/index.js +1718 -834
  54. package/dist/server/modules/order/types.d.ts +15 -3
  55. package/dist/server/modules/order/types.js +1 -1
  56. package/dist/server/modules/products/index.d.ts +31 -8
  57. package/dist/server/modules/products/index.js +549 -390
  58. package/dist/server/modules/products/types.d.ts +18 -0
  59. package/dist/solution/BaseSales/index.d.ts +54 -4
  60. package/dist/solution/BaseSales/index.js +1448 -788
  61. package/dist/solution/BaseSales/types.d.ts +6 -1
  62. package/dist/solution/BaseSales/types.js +1 -1
  63. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +1 -3
  64. package/dist/solution/BaseSales/utils/cartPromotion.js +50 -97
  65. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +9 -4
  66. package/dist/solution/BaseSales/utils/parseSalesResponse.js +6 -8
  67. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +14 -1
  68. package/dist/solution/BookingByStep/index.d.ts +1 -1
  69. package/dist/solution/BookingTicket/index.js +61 -26
  70. package/dist/solution/BookingTicket/types.d.ts +2 -0
  71. package/dist/solution/Sales/index.d.ts +1 -0
  72. package/dist/solution/Sales/index.js +10 -2
  73. package/dist/solution/ScanOrder/index.js +20 -31
  74. package/dist/solution/ShopDiscount/index.js +15 -14
  75. package/dist/solution/VenueBooking/index.js +19 -30
  76. package/dist/utils/payment-number.d.ts +9 -0
  77. package/dist/utils/payment-number.js +69 -0
  78. package/lib/model/strategy/adapter/dataVariant/adapter.d.ts +50 -0
  79. package/lib/model/strategy/adapter/dataVariant/adapter.js +149 -0
  80. package/lib/model/strategy/adapter/dataVariant/evaluator.d.ts +89 -0
  81. package/lib/model/strategy/adapter/dataVariant/evaluator.js +583 -0
  82. package/lib/model/strategy/adapter/dataVariant/examples.d.ts +39 -0
  83. package/lib/model/strategy/adapter/dataVariant/examples.js +293 -0
  84. package/lib/model/strategy/adapter/dataVariant/index.d.ts +4 -0
  85. package/lib/model/strategy/adapter/dataVariant/index.js +38 -0
  86. package/lib/model/strategy/adapter/dataVariant/type.d.ts +148 -0
  87. package/lib/model/strategy/adapter/dataVariant/type.js +31 -0
  88. package/lib/model/strategy/adapter/index.d.ts +4 -0
  89. package/lib/model/strategy/adapter/index.js +13 -2
  90. package/lib/model/strategy/adapter/promotion/adapter.d.ts +0 -4
  91. package/lib/model/strategy/adapter/promotion/adapter.js +0 -20
  92. package/lib/model/strategy/adapter/promotion/evaluator.d.ts +0 -17
  93. package/lib/model/strategy/adapter/promotion/evaluator.js +0 -235
  94. package/lib/model/strategy/adapter/promotion/examples.d.ts +0 -86
  95. package/lib/model/strategy/adapter/promotion/examples.js +0 -91
  96. package/lib/model/strategy/adapter/promotion/index.d.ts +1 -1
  97. package/lib/model/strategy/adapter/promotion/index.js +0 -2
  98. package/lib/model/strategy/adapter/promotion/type.d.ts +2 -90
  99. package/lib/model/strategy/adapter/promotion/type.js +0 -2
  100. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +5 -0
  101. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +1 -0
  102. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +1 -1
  103. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +23 -2
  104. package/lib/modules/Discount/index.d.ts +5 -2
  105. package/lib/modules/Discount/index.js +23 -3
  106. package/lib/modules/Discount/types.d.ts +4 -0
  107. package/lib/modules/Order/index.d.ts +41 -10
  108. package/lib/modules/Order/index.js +505 -119
  109. package/lib/modules/Order/payment-utils.d.ts +26 -0
  110. package/lib/modules/Order/payment-utils.js +224 -0
  111. package/lib/modules/Order/types.d.ts +49 -1
  112. package/lib/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
  113. package/lib/modules/Order/utils/orderCollectionIdentity.js +418 -0
  114. package/lib/modules/Order/utils.d.ts +4 -3
  115. package/lib/modules/Order/utils.js +27 -26
  116. package/lib/modules/Payment/index.d.ts +2 -0
  117. package/lib/modules/Payment/index.js +33 -12
  118. package/lib/modules/Payment/types.d.ts +26 -24
  119. package/lib/modules/Product/types.d.ts +22 -0
  120. package/lib/modules/ProductList/index.d.ts +1 -1
  121. package/lib/modules/ProductList/index.js +4 -2
  122. package/lib/modules/ProductList/types.d.ts +2 -0
  123. package/lib/modules/Rules/index.d.ts +2 -9
  124. package/lib/modules/Rules/index.js +61 -29
  125. package/lib/modules/Rules/types.d.ts +10 -1
  126. package/lib/server/index.d.ts +71 -0
  127. package/lib/server/index.js +1002 -52
  128. package/lib/server/modules/order/index.d.ts +56 -5
  129. package/lib/server/modules/order/index.js +798 -148
  130. package/lib/server/modules/order/types.d.ts +15 -3
  131. package/lib/server/modules/products/index.d.ts +31 -8
  132. package/lib/server/modules/products/index.js +134 -35
  133. package/lib/server/modules/products/types.d.ts +18 -0
  134. package/lib/solution/BaseSales/index.d.ts +54 -4
  135. package/lib/solution/BaseSales/index.js +475 -50
  136. package/lib/solution/BaseSales/types.d.ts +6 -1
  137. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +1 -3
  138. package/lib/solution/BaseSales/utils/cartPromotion.js +25 -64
  139. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +9 -4
  140. package/lib/solution/BaseSales/utils/parseSalesResponse.js +4 -5
  141. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +8 -0
  142. package/lib/solution/BookingByStep/index.d.ts +1 -1
  143. package/lib/solution/BookingTicket/index.js +35 -9
  144. package/lib/solution/BookingTicket/types.d.ts +2 -0
  145. package/lib/solution/Sales/index.d.ts +1 -0
  146. package/lib/solution/Sales/index.js +5 -3
  147. package/lib/solution/ScanOrder/index.js +0 -8
  148. package/lib/solution/ShopDiscount/index.js +2 -1
  149. package/lib/solution/VenueBooking/index.js +0 -8
  150. package/lib/utils/payment-number.d.ts +9 -0
  151. package/lib/utils/payment-number.js +64 -0
  152. package/package.json +1 -1
@@ -6,12 +6,12 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
6
6
  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; }
7
7
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
8
8
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
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
- 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
9
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
12
10
  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."); }
13
11
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
14
12
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
13
+ 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; }
14
+ 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; }
15
15
  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; } } }; }
16
16
  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); }
17
17
  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; }
@@ -35,10 +35,13 @@ import { OrderHooks } from "./types";
35
35
  import { composeLinePrice, generateDuration, getAllDiscountList, mergeRelationForms, buildSubmitPayload, createDefaultTempOrder, createDefaultOrderRulesHooks, createEmptySummary, createUuidV4, formatDateTime, isTempOrder, normalizeBookingIsAll, normalizeBookingSubType, mapPaymentItemsToOrderPayments, normalizeOrderProductDiscountList, resolveEffectivePerUnitDiscount, ensureProductSku, getProductSkuOptions, normalizeProductSkuOptions, sumOptionUnitPrice, clearTempOrderHolderAssignments, getOrderProductLineUid, indexOrderProductsByUid, calculateOrderProductsDeposit, mergeOrderProductDisplayFields, resolveIsFormSubject } from "./utils";
36
36
  import { isNormalProduct } from "../Product/utils";
37
37
  import dayjs from 'dayjs';
38
+ import { ensureOrderPaymentNumber, mergeOrderPaymentRecord, resolveOrderPaymentIdentity } from "./payment-utils";
39
+ import { resolvePaymentNumberDevicePrefix, resolvePaymentNumberDevicePrefixFromDeviceId } from "../../utils/payment-number";
38
40
  import { processCartPromotion, appendPromotionTags as _appendPromotionTags, getOrderProductUid as getPromotionUid } from "../../solution/BaseSales/utils/cartPromotion";
39
41
  import { buildProductLineFingerprint, getProductIdentityIndex, getSafeProductNum, isIdentityMatch, normalizeOrderProduct } from "../../solution/ScanOrder/utils";
40
42
  import { syncManualProductDiscountProductNum } from "./utils/manualProductDiscount";
41
43
  import { expandHydratedProductsForDiscountCollection, restoreHydratedBundleDiscounts } from "./utils/bundleDiscountHydration";
44
+ import { getOrderCollectionPersistentId, getOrderCollectionUid, normalizeOrderCollections, setOrderCollectionUid } from "./utils/orderCollectionIdentity";
42
45
  import { DiscountModule } from "../Discount";
43
46
  import { RulesModule } from "../Rules";
44
47
  import { UnavailableReason } from "../Rules/types";
@@ -96,6 +99,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
96
99
  _defineProperty(_assertThisInitialized(_this), "logger", void 0);
97
100
  // LoggerManager 实例
98
101
  _defineProperty(_assertThisInitialized(_this), "window", void 0);
102
+ _defineProperty(_assertThisInitialized(_this), "appPlugin", void 0);
99
103
  _defineProperty(_assertThisInitialized(_this), "cacheId", void 0);
100
104
  _defineProperty(_assertThisInitialized(_this), "salesSummaryModuleName", void 0);
101
105
  _defineProperty(_assertThisInitialized(_this), "rulesHooksOverride", void 0);
@@ -158,9 +162,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
158
162
  };
159
163
  var existed = discountMap.get(key);
160
164
  if (existed) {
165
+ var _existed$limited_rela;
161
166
  existed.amount = Number(existed.amount || 0) + amount;
162
167
  existed.used_par_value = String(Number(existed.used_par_value || 0) + amount);
163
168
  existed.balance = String(Number(existed.balance || 0) + amount);
169
+ var productIds = Array.isArray((_existed$limited_rela = existed.limited_relation_product_data) === null || _existed$limited_rela === void 0 ? void 0 : _existed$limited_rela.product_ids) ? existed.limited_relation_product_data.product_ids : [];
170
+ if ((product === null || product === void 0 ? void 0 : product.product_id) !== undefined && (product === null || product === void 0 ? void 0 : product.product_id) !== null && !productIds.includes(product.product_id)) {
171
+ existed.limited_relation_product_data = _objectSpread(_objectSpread({}, existed.limited_relation_product_data || {}), {}, {
172
+ product_ids: [].concat(_toConsumableArray(productIds), [product.product_id])
173
+ });
174
+ }
164
175
  existed.applicableProductDetails = [].concat(_toConsumableArray(existed.applicableProductDetails || []), [detail]);
165
176
  existed.appliedProductDetails = [].concat(_toConsumableArray(existed.appliedProductDetails || []), [detail]);
166
177
  continue;
@@ -276,7 +287,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
276
287
  value: function () {
277
288
  var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
278
289
  var _otherParams$rules, _otherParams$order, _otherParams$hooks;
279
- var appPlugin, app, otherParams;
290
+ var app, otherParams;
280
291
  return _regeneratorRuntime().wrap(function _callee$(_context) {
281
292
  while (1) switch (_context.prev = _context.next) {
282
293
  case 0:
@@ -288,15 +299,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
288
299
  if (!this.store.summary) {
289
300
  this.store.summary = createEmptySummary();
290
301
  }
302
+ if (!Array.isArray(this.store.availableWalletIds)) {
303
+ this.store.availableWalletIds = [];
304
+ }
291
305
  this.request = this.core.getPlugin('request');
292
- appPlugin = this.core.getPlugin('app');
293
- if (appPlugin) {
294
- _context.next = 8;
306
+ this.appPlugin = this.core.getPlugin('app');
307
+ if (this.appPlugin) {
308
+ _context.next = 9;
295
309
  break;
296
310
  }
297
311
  throw new Error('Order 模块需要 app 插件支持');
298
- case 8:
299
- app = appPlugin.getApp();
312
+ case 9:
313
+ app = this.appPlugin.getApp();
300
314
  this.logger = app.logger;
301
315
  this.window = this.core.getPlugin('window');
302
316
  otherParams = options.otherParams || {};
@@ -308,7 +322,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
308
322
  this.otherParams = otherParams;
309
323
  this.registerDiscountModules(options);
310
324
  this.logInfo('OrderModule initialized successfully');
311
- case 20:
325
+ case 21:
312
326
  case "end":
313
327
  return _context.stop();
314
328
  }
@@ -485,7 +499,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
485
499
  value: function () {
486
500
  var _loadDiscountConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params) {
487
501
  var _this$store$tempOrder, _this$store$discount, _this$store$tempOrder2;
488
- var orderId, discountList, _this$store$discount2, _this$store$discount3, _this$store$discount4, currentEditDiscounts, runtimeDiscountIds, runtimeDiscounts, mergedDiscountList;
502
+ var orderId, prepareConfigResult, discountList, _this$store$discount2, _this$store$discount3, _this$store$discount4, currentDiscountList, currentEditDiscounts, currentScanDiscounts, currentScanDiscountIds, runtimeDiscountIds, runtimeDiscounts, mergedDiscountList;
489
503
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
490
504
  while (1) switch (_context3.prev = _context3.next) {
491
505
  case 0:
@@ -497,37 +511,49 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
497
511
  with_good_pass: 1,
498
512
  with_discount_card: 1,
499
513
  with_wallet_pass_holder: 1,
514
+ with_available_wallet_flag: 1,
515
+ with_available_wallet_pass_flag: 1,
500
516
  request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
501
517
  }, orderId ? {
502
518
  order_id: orderId
503
519
  } : {}));
504
520
  case 3:
505
- discountList = _context3.sent;
521
+ prepareConfigResult = _context3.sent;
522
+ discountList = prepareConfigResult === null || prepareConfigResult === void 0 ? void 0 : prepareConfigResult.discountList;
523
+ this.store.availableWalletIds = (prepareConfigResult === null || prepareConfigResult === void 0 ? void 0 : prepareConfigResult.availableWalletIds) || [];
506
524
  if (!discountList) {
507
- _context3.next = 13;
525
+ _context3.next = 18;
508
526
  break;
509
527
  }
510
- currentEditDiscounts = (((_this$store$discount2 = this.store.discount) === null || _this$store$discount2 === void 0 ? void 0 : _this$store$discount2.getDiscountList()) || []).filter(function (discount) {
528
+ currentDiscountList = ((_this$store$discount2 = this.store.discount) === null || _this$store$discount2 === void 0 ? void 0 : _this$store$discount2.getDiscountList()) || [];
529
+ currentEditDiscounts = currentDiscountList.filter(function (discount) {
511
530
  return discount === null || discount === void 0 ? void 0 : discount.isEditMode;
512
531
  });
532
+ currentScanDiscounts = currentDiscountList.filter(function (discount) {
533
+ return discount === null || discount === void 0 ? void 0 : discount.isScan;
534
+ });
535
+ currentScanDiscountIds = new Set(currentScanDiscounts.map(function (discount) {
536
+ return discount === null || discount === void 0 ? void 0 : discount.id;
537
+ }));
513
538
  runtimeDiscountIds = new Set();
514
539
  runtimeDiscounts = discountList.filter(function (discount) {
540
+ if (currentScanDiscountIds.has(discount === null || discount === void 0 ? void 0 : discount.id)) return false;
515
541
  if (runtimeDiscountIds.has(discount === null || discount === void 0 ? void 0 : discount.id)) return false;
516
542
  runtimeDiscountIds.add(discount === null || discount === void 0 ? void 0 : discount.id);
517
543
  return true;
518
544
  });
519
- mergedDiscountList = [].concat(_toConsumableArray(currentEditDiscounts), _toConsumableArray(runtimeDiscounts));
520
- _context3.next = 11;
545
+ mergedDiscountList = [].concat(_toConsumableArray(currentEditDiscounts), _toConsumableArray(currentScanDiscounts), _toConsumableArray(runtimeDiscounts));
546
+ _context3.next = 16;
521
547
  return (_this$store$discount3 = this.store.discount) === null || _this$store$discount3 === void 0 ? void 0 : _this$store$discount3.setOriginalDiscountList(mergedDiscountList);
522
- case 11:
523
- _context3.next = 13;
548
+ case 16:
549
+ _context3.next = 18;
524
550
  return (_this$store$discount4 = this.store.discount) === null || _this$store$discount4 === void 0 ? void 0 : _this$store$discount4.setDiscountList(mergedDiscountList);
525
- case 13:
551
+ case 18:
526
552
  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) {
527
553
  this.applyDiscount();
528
554
  }
529
555
  return _context3.abrupt("return", this.getDiscountList());
530
- case 15:
556
+ case 20:
531
557
  case "end":
532
558
  return _context3.stop();
533
559
  }
@@ -545,33 +571,76 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
545
571
  return ((_this$store$discount5 = this.store.discount) === null || _this$store$discount5 === void 0 ? void 0 : _this$store$discount5.getDiscountList()) || [];
546
572
  }
547
573
  }, {
548
- key: "ensureEditDiscountConfigForProductChange",
574
+ key: "getAvailableWalletIds",
575
+ value: function getAvailableWalletIds() {
576
+ return Array.isArray(this.store.availableWalletIds) ? _toConsumableArray(this.store.availableWalletIds) : [];
577
+ }
578
+ }, {
579
+ key: "syncScannedDiscountsToOriginalDiscountList",
549
580
  value: function () {
550
- var _ensureEditDiscountConfigForProductChange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(tempOrder) {
551
- var _tempOrder$customer, _tempOrder$_extend, _tempOrder$_extend2, _this$store$discount6;
552
- var orderId, customerId, currentDiscountList, hasRuntimeDiscounts;
581
+ var _syncScannedDiscountsToOriginalDiscountList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(discountList) {
582
+ var _this$store$discount6, _this$store$discount7, _this$store$discount8, _this$store$discount9;
583
+ var scanDiscounts, scanDiscountIds, originalDiscounts, nextOriginalDiscounts;
553
584
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
554
585
  while (1) switch (_context4.prev = _context4.next) {
586
+ case 0:
587
+ scanDiscounts = (discountList || []).filter(function (discount) {
588
+ return discount === null || discount === void 0 ? void 0 : discount.isScan;
589
+ });
590
+ if (scanDiscounts.length) {
591
+ _context4.next = 3;
592
+ break;
593
+ }
594
+ return _context4.abrupt("return");
595
+ case 3:
596
+ scanDiscountIds = new Set(scanDiscounts.map(function (discount) {
597
+ return discount === null || discount === void 0 ? void 0 : discount.id;
598
+ }));
599
+ originalDiscounts = ((_this$store$discount6 = this.store.discount) === null || _this$store$discount6 === void 0 || (_this$store$discount7 = _this$store$discount6.getOriginalDiscountList) === null || _this$store$discount7 === void 0 ? void 0 : _this$store$discount7.call(_this$store$discount6)) || [];
600
+ nextOriginalDiscounts = [].concat(_toConsumableArray(scanDiscounts), _toConsumableArray(originalDiscounts.filter(function (discount) {
601
+ return !scanDiscountIds.has(discount === null || discount === void 0 ? void 0 : discount.id);
602
+ })));
603
+ _context4.next = 8;
604
+ return (_this$store$discount8 = this.store.discount) === null || _this$store$discount8 === void 0 || (_this$store$discount9 = _this$store$discount8.setOriginalDiscountList) === null || _this$store$discount9 === void 0 ? void 0 : _this$store$discount9.call(_this$store$discount8, nextOriginalDiscounts);
605
+ case 8:
606
+ case "end":
607
+ return _context4.stop();
608
+ }
609
+ }, _callee4, this);
610
+ }));
611
+ function syncScannedDiscountsToOriginalDiscountList(_x4) {
612
+ return _syncScannedDiscountsToOriginalDiscountList.apply(this, arguments);
613
+ }
614
+ return syncScannedDiscountsToOriginalDiscountList;
615
+ }()
616
+ }, {
617
+ key: "ensureEditDiscountConfigForProductChange",
618
+ value: function () {
619
+ var _ensureEditDiscountConfigForProductChange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(tempOrder) {
620
+ var _tempOrder$customer, _tempOrder$_extend, _tempOrder$_extend2, _this$store$discount10;
621
+ var orderId, customerId, currentDiscountList, hasRuntimeDiscounts;
622
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
623
+ while (1) switch (_context5.prev = _context5.next) {
555
624
  case 0:
556
625
  orderId = tempOrder.order_id;
557
626
  customerId = Number(tempOrder.customer_id || ((_tempOrder$customer = tempOrder.customer) === null || _tempOrder$customer === void 0 ? void 0 : _tempOrder$customer.id) || ((_tempOrder$_extend = tempOrder._extend) === null || _tempOrder$_extend === void 0 || (_tempOrder$_extend = _tempOrder$_extend.customerSnapshot) === null || _tempOrder$_extend === void 0 ? void 0 : _tempOrder$_extend.id) || ((_tempOrder$_extend2 = tempOrder._extend) === null || _tempOrder$_extend2 === void 0 || (_tempOrder$_extend2 = _tempOrder$_extend2.customerSnapshot) === null || _tempOrder$_extend2 === void 0 ? void 0 : _tempOrder$_extend2.customer_id) || 0);
558
627
  if (!(!orderId || !customerId || customerId === 1)) {
559
- _context4.next = 4;
628
+ _context5.next = 4;
560
629
  break;
561
630
  }
562
- return _context4.abrupt("return");
631
+ return _context5.abrupt("return");
563
632
  case 4:
564
- currentDiscountList = ((_this$store$discount6 = this.store.discount) === null || _this$store$discount6 === void 0 ? void 0 : _this$store$discount6.getDiscountList()) || [];
633
+ currentDiscountList = ((_this$store$discount10 = this.store.discount) === null || _this$store$discount10 === void 0 ? void 0 : _this$store$discount10.getDiscountList()) || [];
565
634
  hasRuntimeDiscounts = currentDiscountList.some(function (discount) {
566
635
  return !(discount !== null && discount !== void 0 && discount.isEditMode);
567
636
  });
568
637
  if (!hasRuntimeDiscounts) {
569
- _context4.next = 8;
638
+ _context5.next = 8;
570
639
  break;
571
640
  }
572
- return _context4.abrupt("return");
641
+ return _context5.abrupt("return");
573
642
  case 8:
574
- _context4.next = 10;
643
+ _context5.next = 10;
575
644
  return this.loadDiscountConfig({
576
645
  customerId: customerId,
577
646
  action: 'edit',
@@ -580,11 +649,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
580
649
  });
581
650
  case 10:
582
651
  case "end":
583
- return _context4.stop();
652
+ return _context5.stop();
584
653
  }
585
- }, _callee4, this);
654
+ }, _callee5, this);
586
655
  }));
587
- function ensureEditDiscountConfigForProductChange(_x4) {
656
+ function ensureEditDiscountConfigForProductChange(_x5) {
588
657
  return _ensureEditDiscountConfigForProductChange.apply(this, arguments);
589
658
  }
590
659
  return ensureEditDiscountConfigForProductChange;
@@ -592,35 +661,35 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
592
661
  }, {
593
662
  key: "scanCode",
594
663
  value: function () {
595
- var _scanCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(code, customerId) {
596
- var _this$store$discount7, _tempOrder$holder, _this$store$summary;
597
- var resultDiscountWithReason, resultDiscountList, unavailableReasonKey, rulesModule, withScanList, currentSelected, tempOrder, holders, _ref13, isAvailable, newDiscountList, unavailableReason, _this$store$discount8;
598
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
599
- while (1) switch (_context5.prev = _context5.next) {
664
+ var _scanCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(code, customerId) {
665
+ var _this$store$discount11, _tempOrder$holder, _this$store$summary;
666
+ var resultDiscountWithReason, resultDiscountList, unavailableReasonKey, rulesModule, withScanList, currentSelected, tempOrder, holders, _ref13, isAvailable, newDiscountList, unavailableReason, _this$store$discount12;
667
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
668
+ while (1) switch (_context6.prev = _context6.next) {
600
669
  case 0:
601
- _context5.next = 2;
602
- return (_this$store$discount7 = this.store.discount) === null || _this$store$discount7 === void 0 ? void 0 : _this$store$discount7.batchSearch(code, {
670
+ _context6.next = 2;
671
+ return (_this$store$discount11 = this.store.discount) === null || _this$store$discount11 === void 0 ? void 0 : _this$store$discount11.batchSearch(code, {
603
672
  customerId: customerId
604
673
  });
605
674
  case 2:
606
- _context5.t0 = _context5.sent;
607
- if (_context5.t0) {
608
- _context5.next = 5;
675
+ _context6.t0 = _context6.sent;
676
+ if (_context6.t0) {
677
+ _context6.next = 5;
609
678
  break;
610
679
  }
611
- _context5.t0 = {
680
+ _context6.t0 = {
612
681
  discountList: [],
613
682
  unavailableReasonKey: null
614
683
  };
615
684
  case 5:
616
- resultDiscountWithReason = _context5.t0;
685
+ resultDiscountWithReason = _context6.t0;
617
686
  resultDiscountList = resultDiscountWithReason.discountList, unavailableReasonKey = resultDiscountWithReason.unavailableReasonKey;
618
687
  rulesModule = this.store.rules;
619
688
  if (rulesModule) {
620
- _context5.next = 10;
689
+ _context6.next = 10;
621
690
  break;
622
691
  }
623
- return _context5.abrupt("return", {
692
+ return _context6.abrupt("return", {
624
693
  type: 'clientCalc',
625
694
  isAvailable: false,
626
695
  discountList: this.getDiscountList(),
@@ -629,10 +698,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
629
698
  });
630
699
  case 10:
631
700
  if (resultDiscountList.length) {
632
- _context5.next = 12;
701
+ _context6.next = 12;
633
702
  break;
634
703
  }
635
- return _context5.abrupt("return", {
704
+ return _context6.abrupt("return", {
636
705
  type: 'server',
637
706
  isAvailable: false,
638
707
  discountList: this.getDiscountList(),
@@ -653,16 +722,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
653
722
  return m.id === n.id;
654
723
  });
655
724
  }))) {
656
- _context5.next = 16;
725
+ _context6.next = 18;
657
726
  break;
658
727
  }
659
- return _context5.abrupt("return", {
728
+ _context6.next = 17;
729
+ return this.syncScannedDiscountsToOriginalDiscountList(this.getDiscountList());
730
+ case 17:
731
+ return _context6.abrupt("return", {
660
732
  type: 'clientCalc',
661
733
  isAvailable: true,
662
734
  discountList: this.getDiscountList(),
663
735
  scannedDiscountList: resultDiscountList
664
736
  });
665
- case 16:
737
+ case 18:
666
738
  tempOrder = this.store.tempOrder;
667
739
  holders = (tempOrder === null || tempOrder === void 0 || (_tempOrder$holder = tempOrder.holder) === null || _tempOrder$holder === void 0 ? void 0 : _tempOrder$holder.form_record) || [];
668
740
  _ref13 = rulesModule.isDiscountListAvailable({
@@ -678,33 +750,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
678
750
  isAvailable: false,
679
751
  discountList: this.getDiscountList()
680
752
  }, isAvailable = _ref13.isAvailable, newDiscountList = _ref13.discountList, unavailableReason = _ref13.unavailableReason;
681
- if (isAvailable && newDiscountList) {
682
- (_this$store$discount8 = this.store.discount) === null || _this$store$discount8 === void 0 || _this$store$discount8.setDiscountList(newDiscountList);
683
- this.applyDiscount();
753
+ if (!(isAvailable && newDiscountList)) {
754
+ _context6.next = 26;
755
+ break;
684
756
  }
685
- return _context5.abrupt("return", {
757
+ (_this$store$discount12 = this.store.discount) === null || _this$store$discount12 === void 0 || _this$store$discount12.setDiscountList(newDiscountList);
758
+ this.applyDiscount();
759
+ _context6.next = 26;
760
+ return this.syncScannedDiscountsToOriginalDiscountList(this.getDiscountList());
761
+ case 26:
762
+ return _context6.abrupt("return", {
686
763
  type: 'clientCalc',
687
764
  isAvailable: isAvailable || false,
688
765
  discountList: newDiscountList || this.getDiscountList(),
689
766
  scannedDiscountList: resultDiscountList,
690
767
  unavailableReason: unavailableReason
691
768
  });
692
- case 21:
769
+ case 27:
693
770
  case "end":
694
- return _context5.stop();
771
+ return _context6.stop();
695
772
  }
696
- }, _callee5, this);
773
+ }, _callee6, this);
697
774
  }));
698
- function scanCode(_x5, _x6) {
775
+ function scanCode(_x6, _x7) {
699
776
  return _scanCode.apply(this, arguments);
700
777
  }
701
778
  return scanCode;
702
779
  }()
703
780
  }, {
704
781
  key: "applyDiscount",
705
- value: function applyDiscount() {
706
- var _this$store$discount9,
707
- _tempOrder$holder2,
782
+ value: function applyDiscount(options) {
783
+ var _this$store$discount13,
708
784
  _this$store$summary2,
709
785
  _this2 = this;
710
786
  var tempOrder = this.store.tempOrder;
@@ -714,20 +790,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
714
790
  if (!tempOrder) return;
715
791
  this.syncLinkedBookingHoldersToProducts(tempOrder);
716
792
  delete tempOrder.discount_list;
717
- var discountList = ((_this$store$discount9 = this.store.discount) === null || _this$store$discount9 === void 0 ? void 0 : _this$store$discount9.getDiscountList()) || [];
793
+ var discountList = ((_this$store$discount13 = this.store.discount) === null || _this$store$discount13 === void 0 ? void 0 : _this$store$discount13.getDiscountList()) || [];
718
794
  var shouldSkipDiscountCalculation = this.shouldSkipDiscountCalculation(tempOrder);
719
795
  if (shouldSkipDiscountCalculation) return;
720
796
  var rulesModule = this.store.rules;
721
797
  if (!rulesModule) return;
722
- var holders = ((_tempOrder$holder2 = tempOrder.holder) === null || _tempOrder$holder2 === void 0 ? void 0 : _tempOrder$holder2.form_record) || [];
723
798
  var result = rulesModule.calcDiscount({
724
799
  productList: tempOrder.products,
725
800
  discountList: discountList,
726
- holders: holders,
801
+ holders: [],
727
802
  isFormSubject: function isFormSubject(product) {
728
803
  return resolveIsFormSubject(tempOrder, product);
729
804
  },
730
805
  orderTotalAmount: Number(((_this$store$summary2 = this.store.summary) === null || _this$store$summary2 === void 0 ? void 0 : _this$store$summary2.total_amount) || 0)
806
+ }, {
807
+ reapplyBookingDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyBookingDiscountProductUids
731
808
  });
732
809
  if (result !== null && result !== void 0 && result.productList) {
733
810
  var previousProductsByUid = indexOrderProductsByUid(tempOrder.products);
@@ -745,9 +822,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
745
822
  }));
746
823
  }
747
824
  if (result !== null && result !== void 0 && result.discountList) {
748
- var _this$store$discount10;
825
+ var _this$store$discount14;
749
826
  OrderModule.populateSavedAmounts(result.productList || tempOrder.products, result.discountList);
750
- (_this$store$discount10 = this.store.discount) === null || _this$store$discount10 === void 0 || _this$store$discount10.setDiscountList(result.discountList);
827
+ (_this$store$discount14 = this.store.discount) === null || _this$store$discount14 === void 0 || _this$store$discount14.setDiscountList(result.discountList);
751
828
  }
752
829
  this.hasActiveCustomerBoundDiscount = (tempOrder.products || []).some(function (product) {
753
830
  return _this2.productHasCustomerBoundDiscount(product);
@@ -809,42 +886,42 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
809
886
  }, {
810
887
  key: "applyPromotion",
811
888
  value: (function () {
812
- var _applyPromotion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
889
+ var _applyPromotion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
813
890
  var _this$promotionEvalua,
814
891
  _this$promotionEvalua2,
815
892
  _this3 = this;
816
893
  var tempOrder, strategyConfigs, result, removeSet, _iterator3, _step3, reduce, _iterator6, _step6, _loop2, _iterator4, _step4, _loop, payload;
817
- return _regeneratorRuntime().wrap(function _callee6$(_context8) {
818
- while (1) switch (_context8.prev = _context8.next) {
894
+ return _regeneratorRuntime().wrap(function _callee7$(_context9) {
895
+ while (1) switch (_context9.prev = _context9.next) {
819
896
  case 0:
820
897
  if (!this.isApplyingPromotion) {
821
- _context8.next = 2;
898
+ _context9.next = 2;
822
899
  break;
823
900
  }
824
- return _context8.abrupt("return");
901
+ return _context9.abrupt("return");
825
902
  case 2:
826
903
  if (this.promotionEvaluator) {
827
- _context8.next = 4;
904
+ _context9.next = 4;
828
905
  break;
829
906
  }
830
- return _context8.abrupt("return");
907
+ return _context9.abrupt("return");
831
908
  case 4:
832
909
  tempOrder = this.store.tempOrder;
833
910
  if (tempOrder) {
834
- _context8.next = 7;
911
+ _context9.next = 7;
835
912
  break;
836
913
  }
837
- return _context8.abrupt("return");
914
+ return _context9.abrupt("return");
838
915
  case 7:
839
916
  strategyConfigs = (_this$promotionEvalua = (_this$promotionEvalua2 = this.promotionEvaluator).getStrategyConfigs) === null || _this$promotionEvalua === void 0 ? void 0 : _this$promotionEvalua.call(_this$promotionEvalua2);
840
917
  if (!(Array.isArray(strategyConfigs) && strategyConfigs.length === 0)) {
841
- _context8.next = 10;
918
+ _context9.next = 10;
842
919
  break;
843
920
  }
844
- return _context8.abrupt("return");
921
+ return _context9.abrupt("return");
845
922
  case 10:
846
923
  this.isApplyingPromotion = true;
847
- _context8.prev = 11;
924
+ _context9.prev = 11;
848
925
  result = processCartPromotion(tempOrder.products, this.promotionEvaluator); // step 1: toRemove —— 直接过滤
849
926
  if (result.giftActions.toRemove.length > 0) {
850
927
  removeSet = new Set(result.giftActions.toRemove.map(String));
@@ -856,20 +933,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
856
933
 
857
934
  // step 2: toReduce —— 调整数量
858
935
  _iterator3 = _createForOfIteratorHelper(result.giftActions.toReduce);
859
- _context8.prev = 15;
936
+ _context9.prev = 15;
860
937
  _iterator3.s();
861
938
  case 17:
862
939
  if ((_step3 = _iterator3.n()).done) {
863
- _context8.next = 37;
940
+ _context9.next = 37;
864
941
  break;
865
942
  }
866
943
  reduce = _step3.value;
867
944
  _iterator6 = _createForOfIteratorHelper(reduce.items);
868
- _context8.prev = 20;
945
+ _context9.prev = 20;
869
946
  _loop2 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop2() {
870
947
  var item, product;
871
- return _regeneratorRuntime().wrap(function _loop2$(_context7) {
872
- while (1) switch (_context7.prev = _context7.next) {
948
+ return _regeneratorRuntime().wrap(function _loop2$(_context8) {
949
+ while (1) switch (_context8.prev = _context8.next) {
873
950
  case 0:
874
951
  item = _step6.value;
875
952
  product = result.products.find(function (p) {
@@ -880,52 +957,52 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
880
957
  }
881
958
  case 3:
882
959
  case "end":
883
- return _context7.stop();
960
+ return _context8.stop();
884
961
  }
885
962
  }, _loop2);
886
963
  });
887
964
  _iterator6.s();
888
965
  case 23:
889
966
  if ((_step6 = _iterator6.n()).done) {
890
- _context8.next = 27;
967
+ _context9.next = 27;
891
968
  break;
892
969
  }
893
- return _context8.delegateYield(_loop2(), "t0", 25);
970
+ return _context9.delegateYield(_loop2(), "t0", 25);
894
971
  case 25:
895
- _context8.next = 23;
972
+ _context9.next = 23;
896
973
  break;
897
974
  case 27:
898
- _context8.next = 32;
975
+ _context9.next = 32;
899
976
  break;
900
977
  case 29:
901
- _context8.prev = 29;
902
- _context8.t1 = _context8["catch"](20);
903
- _iterator6.e(_context8.t1);
978
+ _context9.prev = 29;
979
+ _context9.t1 = _context9["catch"](20);
980
+ _iterator6.e(_context9.t1);
904
981
  case 32:
905
- _context8.prev = 32;
982
+ _context9.prev = 32;
906
983
  _iterator6.f();
907
- return _context8.finish(32);
984
+ return _context9.finish(32);
908
985
  case 35:
909
- _context8.next = 17;
986
+ _context9.next = 17;
910
987
  break;
911
988
  case 37:
912
- _context8.next = 42;
989
+ _context9.next = 42;
913
990
  break;
914
991
  case 39:
915
- _context8.prev = 39;
916
- _context8.t2 = _context8["catch"](15);
917
- _iterator3.e(_context8.t2);
992
+ _context9.prev = 39;
993
+ _context9.t2 = _context9["catch"](15);
994
+ _iterator3.e(_context9.t2);
918
995
  case 42:
919
- _context8.prev = 42;
996
+ _context9.prev = 42;
920
997
  _iterator3.f();
921
- return _context8.finish(42);
998
+ return _context9.finish(42);
922
999
  case 45:
923
1000
  if (!(result.giftActions.toAdd.length > 0)) {
924
- _context8.next = 68;
1001
+ _context9.next = 68;
925
1002
  break;
926
1003
  }
927
1004
  if (this.giftSelectResolver) {
928
- _context8.next = 50;
1005
+ _context9.next = 50;
929
1006
  break;
930
1007
  }
931
1008
  if (result.giftActions.toAdd.some(function (g) {
@@ -936,19 +1013,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
936
1013
  } else {
937
1014
  console.warn('[OrderModule] giftSelectResolver not set, skip applying single-option gifts', result.giftActions.toAdd);
938
1015
  }
939
- _context8.next = 68;
1016
+ _context9.next = 68;
940
1017
  break;
941
1018
  case 50:
942
1019
  _iterator4 = _createForOfIteratorHelper(result.giftActions.toAdd);
943
- _context8.prev = 51;
1020
+ _context9.prev = 51;
944
1021
  _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
945
1022
  var addAction, _sameStrategy$metadat, sameStrategy, giftResult, giftProducts, giftBookings, _iterator5, _step5, _step5$value, index, gp, booking, linked;
946
- return _regeneratorRuntime().wrap(function _loop$(_context6) {
947
- while (1) switch (_context6.prev = _context6.next) {
1023
+ return _regeneratorRuntime().wrap(function _loop$(_context7) {
1024
+ while (1) switch (_context7.prev = _context7.next) {
948
1025
  case 0:
949
1026
  addAction = _step4.value;
950
1027
  if (!(addAction.giftOptions.length === 1)) {
951
- _context6.next = 6;
1028
+ _context7.next = 6;
952
1029
  break;
953
1030
  }
954
1031
  sameStrategy = result.products.find(function (p) {
@@ -956,14 +1033,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
956
1033
  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;
957
1034
  });
958
1035
  if (!(sameStrategy && !sameStrategy.booking_uid && !((_sameStrategy$metadat = sameStrategy.metadata) !== null && _sameStrategy$metadat !== void 0 && _sameStrategy$metadat.booking_uid))) {
959
- _context6.next = 6;
1036
+ _context7.next = 6;
960
1037
  break;
961
1038
  }
962
1039
  sameStrategy.num = (Number(sameStrategy.num) || 0) + (addAction.giftCount || 1);
963
- return _context6.abrupt("return", 1);
1040
+ return _context7.abrupt("return", 1);
964
1041
  case 6:
965
- _context6.prev = 6;
966
- _context6.next = 9;
1042
+ _context7.prev = 6;
1043
+ _context7.next = 9;
967
1044
  return _this3.giftSelectResolver({
968
1045
  strategyId: addAction.strategyId,
969
1046
  strategyName: addAction.strategyName,
@@ -972,31 +1049,31 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
972
1049
  sourceProductIds: addAction.sourceProductIds
973
1050
  });
974
1051
  case 9:
975
- giftResult = _context6.sent;
1052
+ giftResult = _context7.sent;
976
1053
  giftProducts = Array.isArray(giftResult) ? giftResult : giftResult === null || giftResult === void 0 ? void 0 : giftResult.products;
977
1054
  giftBookings = Array.isArray(giftResult) ? [] : (giftResult === null || giftResult === void 0 ? void 0 : giftResult.bookings) || [];
978
1055
  if (!(Array.isArray(giftProducts) && giftProducts.length > 0)) {
979
- _context6.next = 37;
1056
+ _context7.next = 37;
980
1057
  break;
981
1058
  }
982
1059
  _iterator5 = _createForOfIteratorHelper(giftProducts.entries());
983
- _context6.prev = 14;
1060
+ _context7.prev = 14;
984
1061
  _iterator5.s();
985
1062
  case 16:
986
1063
  if ((_step5 = _iterator5.n()).done) {
987
- _context6.next = 29;
1064
+ _context7.next = 29;
988
1065
  break;
989
1066
  }
990
1067
  _step5$value = _slicedToArray(_step5.value, 2), index = _step5$value[0], gp = _step5$value[1];
991
1068
  if (gp) {
992
- _context6.next = 20;
1069
+ _context7.next = 20;
993
1070
  break;
994
1071
  }
995
- return _context6.abrupt("continue", 27);
1072
+ return _context7.abrupt("continue", 27);
996
1073
  case 20:
997
1074
  booking = giftBookings[index];
998
1075
  if (!booking) {
999
- _context6.next = 26;
1076
+ _context7.next = 26;
1000
1077
  break;
1001
1078
  }
1002
1079
  linked = _this3.createLinkedProductAndBooking({
@@ -1005,65 +1082,65 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1005
1082
  });
1006
1083
  result.products.push(linked.product);
1007
1084
  tempOrder.bookings = [].concat(_toConsumableArray(tempOrder.bookings || []), [linked.booking]);
1008
- return _context6.abrupt("continue", 27);
1085
+ return _context7.abrupt("continue", 27);
1009
1086
  case 26:
1010
1087
  // normalize 略过:调用方应保证返回完整 OrderProduct。
1011
1088
  result.products.push(gp);
1012
1089
  case 27:
1013
- _context6.next = 16;
1090
+ _context7.next = 16;
1014
1091
  break;
1015
1092
  case 29:
1016
- _context6.next = 34;
1093
+ _context7.next = 34;
1017
1094
  break;
1018
1095
  case 31:
1019
- _context6.prev = 31;
1020
- _context6.t0 = _context6["catch"](14);
1021
- _iterator5.e(_context6.t0);
1096
+ _context7.prev = 31;
1097
+ _context7.t0 = _context7["catch"](14);
1098
+ _iterator5.e(_context7.t0);
1022
1099
  case 34:
1023
- _context6.prev = 34;
1100
+ _context7.prev = 34;
1024
1101
  _iterator5.f();
1025
- return _context6.finish(34);
1102
+ return _context7.finish(34);
1026
1103
  case 37:
1027
- _context6.next = 42;
1104
+ _context7.next = 42;
1028
1105
  break;
1029
1106
  case 39:
1030
- _context6.prev = 39;
1031
- _context6.t1 = _context6["catch"](6);
1107
+ _context7.prev = 39;
1108
+ _context7.t1 = _context7["catch"](6);
1032
1109
  // 用户取消 / 选择失败 → 视为放弃本次新增
1033
- console.warn('[OrderModule] giftSelectResolver rejected, skip add gift', addAction.strategyId, _context6.t1);
1110
+ console.warn('[OrderModule] giftSelectResolver rejected, skip add gift', addAction.strategyId, _context7.t1);
1034
1111
  case 42:
1035
1112
  case "end":
1036
- return _context6.stop();
1113
+ return _context7.stop();
1037
1114
  }
1038
1115
  }, _loop, null, [[6, 39], [14, 31, 34, 37]]);
1039
1116
  });
1040
1117
  _iterator4.s();
1041
1118
  case 54:
1042
1119
  if ((_step4 = _iterator4.n()).done) {
1043
- _context8.next = 60;
1120
+ _context9.next = 60;
1044
1121
  break;
1045
1122
  }
1046
- return _context8.delegateYield(_loop(), "t3", 56);
1123
+ return _context9.delegateYield(_loop(), "t3", 56);
1047
1124
  case 56:
1048
- if (!_context8.t3) {
1049
- _context8.next = 58;
1125
+ if (!_context9.t3) {
1126
+ _context9.next = 58;
1050
1127
  break;
1051
1128
  }
1052
- return _context8.abrupt("continue", 58);
1129
+ return _context9.abrupt("continue", 58);
1053
1130
  case 58:
1054
- _context8.next = 54;
1131
+ _context9.next = 54;
1055
1132
  break;
1056
1133
  case 60:
1057
- _context8.next = 65;
1134
+ _context9.next = 65;
1058
1135
  break;
1059
1136
  case 62:
1060
- _context8.prev = 62;
1061
- _context8.t4 = _context8["catch"](51);
1062
- _iterator4.e(_context8.t4);
1137
+ _context9.prev = 62;
1138
+ _context9.t4 = _context9["catch"](51);
1139
+ _iterator4.e(_context9.t4);
1063
1140
  case 65:
1064
- _context8.prev = 65;
1141
+ _context9.prev = 65;
1065
1142
  _iterator4.f();
1066
- return _context8.finish(65);
1143
+ return _context9.finish(65);
1067
1144
  case 68:
1068
1145
  tempOrder.products = result.products;
1069
1146
  this.lastUnfulfilledPromotions = result.unfulfilledPromotions;
@@ -1082,21 +1159,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1082
1159
  products: tempOrder.products
1083
1160
  };
1084
1161
  this.effectsEmit('onPromotionApplied', payload);
1085
- _context8.next = 78;
1162
+ _context9.next = 78;
1086
1163
  break;
1087
1164
  case 75:
1088
- _context8.prev = 75;
1089
- _context8.t5 = _context8["catch"](11);
1090
- console.error('[OrderModule] applyPromotion failed', _context8.t5);
1165
+ _context9.prev = 75;
1166
+ _context9.t5 = _context9["catch"](11);
1167
+ console.error('[OrderModule] applyPromotion failed', _context9.t5);
1091
1168
  case 78:
1092
- _context8.prev = 78;
1169
+ _context9.prev = 78;
1093
1170
  this.isApplyingPromotion = false;
1094
- return _context8.finish(78);
1171
+ return _context9.finish(78);
1095
1172
  case 81:
1096
1173
  case "end":
1097
- return _context8.stop();
1174
+ return _context9.stop();
1098
1175
  }
1099
- }, _callee6, this, [[11, 75, 78, 81], [15, 39, 42, 45], [20, 29, 32, 35], [51, 62, 65, 68]]);
1176
+ }, _callee7, this, [[11, 75, 78, 81], [15, 39, 42, 45], [20, 29, 32, 35], [51, 62, 65, 68]]);
1100
1177
  }));
1101
1178
  function applyPromotion() {
1102
1179
  return _applyPromotion.apply(this, arguments);
@@ -1218,14 +1295,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1218
1295
  }, {
1219
1296
  key: "saveDraft",
1220
1297
  value: function () {
1221
- var _saveDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
1222
- return _regeneratorRuntime().wrap(function _callee7$(_context9) {
1223
- while (1) switch (_context9.prev = _context9.next) {
1298
+ var _saveDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
1299
+ return _regeneratorRuntime().wrap(function _callee8$(_context10) {
1300
+ while (1) switch (_context10.prev = _context10.next) {
1224
1301
  case 0:
1225
1302
  case "end":
1226
- return _context9.stop();
1303
+ return _context10.stop();
1227
1304
  }
1228
- }, _callee7);
1305
+ }, _callee8);
1229
1306
  }));
1230
1307
  function saveDraft() {
1231
1308
  return _saveDraft.apply(this, arguments);
@@ -1240,18 +1317,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1240
1317
  }, {
1241
1318
  key: "hydrateTempOrderFromLocalRecord",
1242
1319
  value: function () {
1243
- var _hydrateTempOrderFromLocalRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(record) {
1244
- return _regeneratorRuntime().wrap(function _callee8$(_context10) {
1245
- while (1) switch (_context10.prev = _context10.next) {
1320
+ var _hydrateTempOrderFromLocalRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(record) {
1321
+ return _regeneratorRuntime().wrap(function _callee9$(_context11) {
1322
+ while (1) switch (_context11.prev = _context11.next) {
1246
1323
  case 0:
1247
- return _context10.abrupt("return", this.hydrateTempOrderFromRecord(record));
1324
+ return _context11.abrupt("return", this.hydrateTempOrderFromRecord(record));
1248
1325
  case 1:
1249
1326
  case "end":
1250
- return _context10.stop();
1327
+ return _context11.stop();
1251
1328
  }
1252
- }, _callee8, this);
1329
+ }, _callee9, this);
1253
1330
  }));
1254
- function hydrateTempOrderFromLocalRecord(_x7) {
1331
+ function hydrateTempOrderFromLocalRecord(_x8) {
1255
1332
  return _hydrateTempOrderFromLocalRecord.apply(this, arguments);
1256
1333
  }
1257
1334
  return hydrateTempOrderFromLocalRecord;
@@ -1285,6 +1362,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1285
1362
  return sum.plus(_this4.calculatePaymentEffectiveAmount(payment));
1286
1363
  }, new Decimal(0));
1287
1364
  }
1365
+ }, {
1366
+ key: "calculateOrderPaidPaymentTotal",
1367
+ value: function calculateOrderPaidPaymentTotal(payments) {
1368
+ var _this5 = this;
1369
+ return mapPaymentItemsToOrderPayments(payments, {
1370
+ includeVoided: false
1371
+ }).reduce(function (sum, payment) {
1372
+ if (!isPaidPaymentRecord(payment)) return sum;
1373
+ return sum.plus(_this5.calculatePaymentGapAmount(payment));
1374
+ }, new Decimal(0));
1375
+ }
1288
1376
  }, {
1289
1377
  key: "getDepositAmount",
1290
1378
  value: function getDepositAmount(tempOrder, summary) {
@@ -1385,7 +1473,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1385
1473
  var summary = this.store.summary || createEmptySummary();
1386
1474
  var paymentList = payments || tempOrder.payments || [];
1387
1475
  var refundAmount = this.getSummaryRefundAmount(summary);
1388
- var netPaidAmount = Decimal.max(this.calculatePaymentTotal(paymentList).minus(refundAmount), 0);
1476
+ var netPaidAmount = Decimal.max(this.calculateOrderPaidPaymentTotal(paymentList).minus(refundAmount), 0);
1389
1477
  var depositAmount = this.getDepositAmount(tempOrder, summary);
1390
1478
  var orderExpectedAmount = this.getOrderExpectedAmount(summary);
1391
1479
  var isDepositFullyPaid = this.isDepositCovered({
@@ -1407,17 +1495,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1407
1495
  }, {
1408
1496
  key: "calculateDepositPaidAmount",
1409
1497
  value: function calculateDepositPaidAmount(payments) {
1410
- var _this5 = this;
1498
+ var _this6 = this;
1411
1499
  return (payments || []).reduce(function (sum, payment) {
1412
1500
  var paymentRecord = payment;
1413
1501
  if (!isPaidPaymentRecord(paymentRecord)) return sum;
1414
1502
  var isDepositPayment = paymentRecord.type === 'deposit' || paymentRecord.order_payment_type === 'deposit';
1415
1503
  if (!isDepositPayment) return sum;
1416
- if (paymentRecord.origin_amount !== undefined && paymentRecord.origin_amount !== null && paymentRecord.origin_amount !== '') {
1417
- return sum.plus(_this5.calculatePaymentGapAmount(paymentRecord));
1418
- }
1419
- var rounding = new Decimal(paymentRecord.rounding_amount || 0);
1420
- return sum.plus(new Decimal(paymentRecord.amount || 0).minus(rounding));
1504
+ return sum.plus(_this6.calculatePaymentGapAmount(paymentRecord));
1421
1505
  }, new Decimal(0));
1422
1506
  }
1423
1507
  }, {
@@ -1429,19 +1513,44 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1429
1513
  var depositPaidAmount = this.calculateDepositPaidAmount(tempOrder.payments || []);
1430
1514
  return depositPaidAmount.lt(depositAmount) ? 'deposit' : 'normal';
1431
1515
  }
1516
+ }, {
1517
+ key: "getPaymentNumberAppData",
1518
+ value: function getPaymentNumberAppData(key) {
1519
+ var _appPlugin$getData, _app$models, _app$models$getStore, _app$models$getStore$, _app$models$getStore$2;
1520
+ var appPlugin = this.appPlugin;
1521
+ if (!appPlugin) return undefined;
1522
+ var getData = (_appPlugin$getData = appPlugin.getData) === null || _appPlugin$getData === void 0 ? void 0 : _appPlugin$getData.call(appPlugin);
1523
+ if (typeof getData === 'function') return getData(key);
1524
+ var app = appPlugin.getApp();
1525
+ var coreData = app === null || app === void 0 || (_app$models = app.models) === null || _app$models === void 0 || (_app$models$getStore = _app$models.getStore) === null || _app$models$getStore === void 0 || (_app$models$getStore$ = (_app$models$getStore$2 = _app$models$getStore.call(_app$models)).getDataByModel) === null || _app$models$getStore$ === void 0 ? void 0 : _app$models$getStore$.call(_app$models$getStore$2, 'core', 'core');
1526
+ return coreData === null || coreData === void 0 ? void 0 : coreData[key];
1527
+ }
1528
+ }, {
1529
+ key: "getPaymentNumberDevicePrefixSync",
1530
+ value: function getPaymentNumberDevicePrefixSync() {
1531
+ var _this7 = this;
1532
+ return resolvePaymentNumberDevicePrefixFromDeviceId(function (key) {
1533
+ return _this7.getPaymentNumberAppData(key);
1534
+ });
1535
+ }
1536
+ }, {
1537
+ key: "getPaymentNumberDevicePrefixAsync",
1538
+ value: function getPaymentNumberDevicePrefixAsync() {
1539
+ var _this8 = this;
1540
+ return resolvePaymentNumberDevicePrefix(function (key) {
1541
+ return _this8.getPaymentNumberAppData(key);
1542
+ });
1543
+ }
1432
1544
  }, {
1433
1545
  key: "normalizePaymentSource",
1434
1546
  value: function normalizePaymentSource(payment, options) {
1435
1547
  var _ref19, _paymentRecord$origin;
1436
1548
  var paymentRecord = payment;
1437
1549
  var metadata = paymentRecord.metadata && _typeof(paymentRecord.metadata) === 'object' ? _objectSpread({}, paymentRecord.metadata) : {};
1438
- if (!metadata.unique_payment_number) {
1439
- metadata.unique_payment_number = createUuidV4();
1440
- }
1441
- var normalized = _objectSpread(_objectSpread({}, paymentRecord), {}, {
1550
+ var normalized = ensureOrderPaymentNumber(_objectSpread(_objectSpread({}, paymentRecord), {}, {
1442
1551
  metadata: metadata,
1443
1552
  origin_amount: (_ref19 = (_paymentRecord$origin = paymentRecord.origin_amount) !== null && _paymentRecord$origin !== void 0 ? _paymentRecord$origin : paymentRecord.amount) !== null && _ref19 !== void 0 ? _ref19 : '0.00'
1444
- });
1553
+ }), (options === null || options === void 0 ? void 0 : options.devicePrefix) || this.getPaymentNumberDevicePrefixSync(), createUuidV4);
1445
1554
  if (paymentRecord.status !== undefined) {
1446
1555
  normalized.status = paymentRecord.status;
1447
1556
  } else if ((options === null || options === void 0 ? void 0 : options.defaultPaid) !== false) {
@@ -1454,8 +1563,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1454
1563
  value: function updateTempOrderPaymentStatus(tempOrder, options) {
1455
1564
  var summary = (options === null || options === void 0 ? void 0 : options.summary) || this.store.summary || createEmptySummary();
1456
1565
  var paymentTotal = this.calculatePaymentTotal(tempOrder.payments || []);
1566
+ var orderPaymentTotal = this.calculateOrderPaidPaymentTotal(tempOrder.payments || []);
1457
1567
  var refundAmount = this.getSummaryRefundAmount(summary);
1458
- var netPaymentTotal = Decimal.max(paymentTotal.minus(refundAmount), 0);
1568
+ var netPaymentTotal = Decimal.max(orderPaymentTotal.minus(refundAmount), 0);
1459
1569
  var targetAmount = this.calculatePaymentTargetAmount(tempOrder, summary, netPaymentTotal);
1460
1570
  if (this.shouldKeepPaymentStatusAfterAmountRecalc(tempOrder.payment_status, {
1461
1571
  netPaymentTotal: netPaymentTotal,
@@ -1521,7 +1631,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1521
1631
  key: "capVoucherPaymentsByRemainingAmount",
1522
1632
  value: function capVoucherPaymentsByRemainingAmount(params) {
1523
1633
  var targetAmount = this.getPaymentTargetAmount();
1524
- var nonVoucherTotal = this.calculatePaymentTotal(params.nonVoucherPayments);
1634
+ var nonVoucherTotal = this.calculateOrderPaidPaymentTotal(params.nonVoucherPayments);
1525
1635
  if (targetAmount.lte(0)) return [];
1526
1636
  var remainingAmount = Decimal.max(targetAmount.minus(nonVoucherTotal), 0);
1527
1637
  var cappedVouchers = [];
@@ -1558,16 +1668,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1558
1668
  }, {
1559
1669
  key: "calculatePaidPaymentSummary",
1560
1670
  value: function calculatePaidPaymentSummary(payments) {
1561
- var _this6 = this;
1671
+ var _this9 = this;
1562
1672
  return (payments || []).reduce(function (summary, payment) {
1563
1673
  var paymentRecord = payment;
1564
1674
  if (!isPaidPaymentRecord(paymentRecord)) return summary;
1565
1675
  return {
1566
1676
  customerPaidAmount: summary.customerPaidAmount.plus(paymentRecord.amount || 0),
1567
- orderPaidAmount: summary.orderPaidAmount.plus(paymentRecord.origin_amount || 0),
1568
- gapPaidAmount: summary.gapPaidAmount.plus(_this6.calculatePaymentGapAmount(paymentRecord)),
1569
- payServiceChargeAmount: summary.payServiceChargeAmount.plus(_this6.calculatePaymentServiceFee(paymentRecord)),
1570
- roundingAmount: summary.roundingAmount.plus(_this6.calculatePaymentRoundingAmount(paymentRecord))
1677
+ orderPaidAmount: summary.orderPaidAmount.plus(_this9.calculatePaymentOrderAmount(paymentRecord)),
1678
+ gapPaidAmount: summary.gapPaidAmount.plus(_this9.calculatePaymentGapAmount(paymentRecord)),
1679
+ payServiceChargeAmount: summary.payServiceChargeAmount.plus(_this9.calculatePaymentServiceFee(paymentRecord)),
1680
+ roundingAmount: summary.roundingAmount.plus(_this9.calculatePaymentRoundingAmount(paymentRecord))
1571
1681
  };
1572
1682
  }, {
1573
1683
  customerPaidAmount: new Decimal(0),
@@ -1591,11 +1701,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1591
1701
  }, {
1592
1702
  key: "calculatePaymentGapAmount",
1593
1703
  value: function calculatePaymentGapAmount(payment) {
1594
- if (payment.origin_amount === undefined || payment.origin_amount === null || payment.origin_amount === '') {
1595
- return new Decimal(0);
1704
+ if (payment.origin_amount !== undefined && payment.origin_amount !== null && payment.origin_amount !== '') {
1705
+ var _rounding = new Decimal(payment.rounding_amount || 0);
1706
+ return new Decimal(payment.origin_amount || 0).minus(_rounding);
1596
1707
  }
1597
1708
  var rounding = new Decimal(payment.rounding_amount || 0);
1598
- return new Decimal(payment.origin_amount || 0).minus(rounding);
1709
+ var amount = new Decimal(payment.amount || 0);
1710
+ var serviceFee = this.calculatePaymentServiceFee(payment);
1711
+ if (serviceFee.lte(0)) return amount.minus(rounding);
1712
+ if (!hasSyncedOrderPaymentRecord(payment)) return new Decimal(0);
1713
+ return Decimal.max(amount.minus(serviceFee), 0).minus(rounding);
1714
+ }
1715
+ }, {
1716
+ key: "calculatePaymentOrderAmount",
1717
+ value: function calculatePaymentOrderAmount(payment) {
1718
+ if (payment.origin_amount !== undefined && payment.origin_amount !== null && payment.origin_amount !== '') {
1719
+ return new Decimal(payment.origin_amount || 0);
1720
+ }
1721
+ var amount = new Decimal(payment.amount || 0);
1722
+ var serviceFee = this.calculatePaymentServiceFee(payment);
1723
+ if (serviceFee.lte(0)) return amount;
1724
+ if (!hasSyncedOrderPaymentRecord(payment)) return new Decimal(0);
1725
+ return Decimal.max(amount.minus(serviceFee), 0);
1599
1726
  }
1600
1727
  }, {
1601
1728
  key: "calculatePaymentRoundingAmount",
@@ -1752,15 +1879,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1752
1879
  }, {
1753
1880
  key: "normalizeFingerprintValue",
1754
1881
  value: function normalizeFingerprintValue(value) {
1755
- var _this7 = this;
1882
+ var _this10 = this;
1756
1883
  if (Array.isArray(value)) {
1757
1884
  return value.map(function (item) {
1758
- return _this7.normalizeFingerprintValue(item);
1885
+ return _this10.normalizeFingerprintValue(item);
1759
1886
  });
1760
1887
  }
1761
1888
  if (!value || _typeof(value) !== 'object') return value !== null && value !== void 0 ? value : '';
1762
1889
  return Object.keys(value).sort().reduce(function (result, key) {
1763
- result[key] = _this7.normalizeFingerprintValue(value[key]);
1890
+ result[key] = _this10.normalizeFingerprintValue(value[key]);
1764
1891
  return result;
1765
1892
  }, {});
1766
1893
  }
@@ -1775,7 +1902,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1775
1902
  _sku$barcode,
1776
1903
  _ref20,
1777
1904
  _sku$variant_id,
1778
- _this8 = this;
1905
+ _this11 = this;
1779
1906
  var sku = (product === null || product === void 0 ? void 0 : product.product_sku) || {};
1780
1907
  var metadata = (product === null || product === void 0 ? void 0 : product.metadata) || {};
1781
1908
  var discountTypes = ((product === null || product === void 0 ? void 0 : product.discount_list) || []).map(function (discount) {
@@ -1809,7 +1936,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1809
1936
  option_group_id: (_option$option_group_ = option === null || option === void 0 ? void 0 : option.option_group_id) !== null && _option$option_group_ !== void 0 ? _option$option_group_ : null,
1810
1937
  option_group_item_id: (_ref22 = (_option$option_group_2 = option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _option$option_group_2 !== void 0 ? _option$option_group_2 : option === null || option === void 0 ? void 0 : option.id) !== null && _ref22 !== void 0 ? _ref22 : null,
1811
1938
  num: Number((_option$num = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num !== void 0 ? _option$num : 1) || 1,
1812
- add_price: _this8.normalizeFingerprintMoney((_option$add_price = option === null || option === void 0 ? void 0 : option.add_price) !== null && _option$add_price !== void 0 ? _option$add_price : option === null || option === void 0 ? void 0 : option.price)
1939
+ add_price: _this11.normalizeFingerprintMoney((_option$add_price = option === null || option === void 0 ? void 0 : option.add_price) !== null && _option$add_price !== void 0 ? _option$add_price : option === null || option === void 0 ? void 0 : option.price)
1813
1940
  };
1814
1941
  })
1815
1942
  }),
@@ -1819,8 +1946,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1819
1946
  bundle_product_id: (_ref23 = (_ref24 = (_bundle$bundle_produc = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_product_id) !== null && _bundle$bundle_produc !== void 0 ? _bundle$bundle_produc : bundle === null || bundle === void 0 ? void 0 : bundle._bundle_product_id) !== null && _ref24 !== void 0 ? _ref24 : bundle === null || bundle === void 0 ? void 0 : bundle.product_id) !== null && _ref23 !== void 0 ? _ref23 : null,
1820
1947
  bundle_variant_id: (_ref25 = (_bundle$bundle_varian = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_variant_id) !== null && _bundle$bundle_varian !== void 0 ? _bundle$bundle_varian : bundle === null || bundle === void 0 ? void 0 : bundle.product_variant_id) !== null && _ref25 !== void 0 ? _ref25 : 0,
1821
1948
  num: getSafeProductNum((_bundle$num = bundle === null || bundle === void 0 ? void 0 : bundle.num) !== null && _bundle$num !== void 0 ? _bundle$num : bundle === null || bundle === void 0 ? void 0 : bundle.quantity),
1822
- price: _this8.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.price),
1823
- bundle_selling_price: _this8.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.bundle_selling_price),
1949
+ price: _this11.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.price),
1950
+ bundle_selling_price: _this11.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.bundle_selling_price),
1824
1951
  price_type: (_bundle$price_type = bundle === null || bundle === void 0 ? void 0 : bundle.price_type) !== null && _bundle$price_type !== void 0 ? _bundle$price_type : '',
1825
1952
  price_type_ext: (_bundle$price_type_ex = bundle === null || bundle === void 0 ? void 0 : bundle.price_type_ext) !== null && _bundle$price_type_ex !== void 0 ? _bundle$price_type_ex : ''
1826
1953
  };
@@ -1830,7 +1957,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1830
1957
  return {
1831
1958
  type: (_ref26 = (_discount$type2 = discount === null || discount === void 0 ? void 0 : discount.type) !== null && _discount$type2 !== void 0 ? _discount$type2 : discount === null || discount === void 0 ? void 0 : discount.tag) !== null && _ref26 !== void 0 ? _ref26 : '',
1832
1959
  discount_id: (_ref27 = (_ref28 = (_discount$discount_id = discount === null || discount === void 0 ? void 0 : discount.discount_id) !== null && _discount$discount_id !== void 0 ? _discount$discount_id : discount === null || discount === void 0 ? void 0 : discount.order_discount_id) !== null && _ref28 !== void 0 ? _ref28 : discount === null || discount === void 0 || (_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) !== null && _ref27 !== void 0 ? _ref27 : null,
1833
- amount: _this8.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
1960
+ amount: _this11.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
1834
1961
  };
1835
1962
  }))
1836
1963
  };
@@ -1838,9 +1965,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1838
1965
  }, {
1839
1966
  key: "buildOrderProductsFingerprint",
1840
1967
  value: function buildOrderProductsFingerprint(products) {
1841
- var _this9 = this;
1968
+ var _this12 = this;
1842
1969
  var items = (products || []).map(function (product) {
1843
- return _this9.buildProductFingerprintItem(product);
1970
+ return _this12.buildProductFingerprintItem(product);
1844
1971
  });
1845
1972
  items.sort(function (left, right) {
1846
1973
  return JSON.stringify(left).localeCompare(JSON.stringify(right));
@@ -1862,7 +1989,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1862
1989
  _sku$barcode2,
1863
1990
  _ref30,
1864
1991
  _sku$variant_id2,
1865
- _this10 = this;
1992
+ _this13 = this;
1866
1993
  var sku = (product === null || product === void 0 ? void 0 : product.product_sku) || {};
1867
1994
  var metadata = (product === null || product === void 0 ? void 0 : product.metadata) || {};
1868
1995
  var discountTypes = ((product === null || product === void 0 ? void 0 : product.discount_list) || []).map(function (discount) {
@@ -1893,7 +2020,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1893
2020
  option_group_id: (_option$option_group_3 = option === null || option === void 0 ? void 0 : option.option_group_id) !== null && _option$option_group_3 !== void 0 ? _option$option_group_3 : null,
1894
2021
  option_group_item_id: (_ref32 = (_option$option_group_4 = option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _option$option_group_4 !== void 0 ? _option$option_group_4 : option === null || option === void 0 ? void 0 : option.id) !== null && _ref32 !== void 0 ? _ref32 : null,
1895
2022
  num: Number((_option$num2 = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num2 !== void 0 ? _option$num2 : 1) || 1,
1896
- add_price: _this10.normalizeFingerprintMoney((_option$add_price2 = option === null || option === void 0 ? void 0 : option.add_price) !== null && _option$add_price2 !== void 0 ? _option$add_price2 : option === null || option === void 0 ? void 0 : option.price)
2023
+ add_price: _this13.normalizeFingerprintMoney((_option$add_price2 = option === null || option === void 0 ? void 0 : option.add_price) !== null && _option$add_price2 !== void 0 ? _option$add_price2 : option === null || option === void 0 ? void 0 : option.price)
1897
2024
  };
1898
2025
  })
1899
2026
  }),
@@ -1907,14 +2034,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1907
2034
  num: getSafeProductNum((_bundle$num2 = bundle === null || bundle === void 0 ? void 0 : bundle.num) !== null && _bundle$num2 !== void 0 ? _bundle$num2 : bundle === null || bundle === void 0 ? void 0 : bundle.quantity),
1908
2035
  price_type: (_bundle$price_type2 = bundle === null || bundle === void 0 ? void 0 : bundle.price_type) !== null && _bundle$price_type2 !== void 0 ? _bundle$price_type2 : '',
1909
2036
  price_type_ext: (_bundle$price_type_ex2 = bundle === null || bundle === void 0 ? void 0 : bundle.price_type_ext) !== null && _bundle$price_type_ex2 !== void 0 ? _bundle$price_type_ex2 : '',
1910
- option: _this10.normalizeFingerprintValue(((bundle === null || bundle === void 0 ? void 0 : bundle.option) || []).map(function (option) {
2037
+ option: _this13.normalizeFingerprintValue(((bundle === null || bundle === void 0 ? void 0 : bundle.option) || []).map(function (option) {
1911
2038
  var _ref38, _option$id3, _option$option_group_5, _ref39, _option$option_group_6, _option$num3, _option$add_price3;
1912
2039
  return {
1913
2040
  id: (_ref38 = (_option$id3 = option === null || option === void 0 ? void 0 : option.id) !== null && _option$id3 !== void 0 ? _option$id3 : option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _ref38 !== void 0 ? _ref38 : null,
1914
2041
  option_group_id: (_option$option_group_5 = option === null || option === void 0 ? void 0 : option.option_group_id) !== null && _option$option_group_5 !== void 0 ? _option$option_group_5 : null,
1915
2042
  option_group_item_id: (_ref39 = (_option$option_group_6 = option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _option$option_group_6 !== void 0 ? _option$option_group_6 : option === null || option === void 0 ? void 0 : option.id) !== null && _ref39 !== void 0 ? _ref39 : null,
1916
2043
  num: Number((_option$num3 = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num3 !== void 0 ? _option$num3 : 1) || 1,
1917
- add_price: _this10.normalizeFingerprintMoney((_option$add_price3 = option === null || option === void 0 ? void 0 : option.add_price) !== null && _option$add_price3 !== void 0 ? _option$add_price3 : option === null || option === void 0 ? void 0 : option.price)
2044
+ add_price: _this13.normalizeFingerprintMoney((_option$add_price3 = option === null || option === void 0 ? void 0 : option.add_price) !== null && _option$add_price3 !== void 0 ? _option$add_price3 : option === null || option === void 0 ? void 0 : option.price)
1918
2045
  };
1919
2046
  }))
1920
2047
  };
@@ -1924,7 +2051,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1924
2051
  return {
1925
2052
  type: (_ref40 = (_discount$type4 = discount === null || discount === void 0 ? void 0 : discount.type) !== null && _discount$type4 !== void 0 ? _discount$type4 : discount === null || discount === void 0 ? void 0 : discount.tag) !== null && _ref40 !== void 0 ? _ref40 : '',
1926
2053
  discount_id: (_ref41 = (_ref42 = (_discount$discount_id2 = discount === null || discount === void 0 ? void 0 : discount.discount_id) !== null && _discount$discount_id2 !== void 0 ? _discount$discount_id2 : discount === null || discount === void 0 ? void 0 : discount.order_discount_id) !== null && _ref42 !== void 0 ? _ref42 : discount === null || discount === void 0 || (_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.resource_id) !== null && _ref41 !== void 0 ? _ref41 : null,
1927
- amount: _this10.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
2054
+ amount: _this13.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
1928
2055
  };
1929
2056
  }))
1930
2057
  };
@@ -1932,9 +2059,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1932
2059
  }, {
1933
2060
  key: "buildOrderProductsStructuralFingerprint",
1934
2061
  value: function buildOrderProductsStructuralFingerprint(products) {
1935
- var _this11 = this;
2062
+ var _this14 = this;
1936
2063
  var items = (products || []).map(function (product) {
1937
- return _this11.buildProductStructuralFingerprintItem(product);
2064
+ return _this14.buildProductStructuralFingerprintItem(product);
1938
2065
  });
1939
2066
  items.sort(function (left, right) {
1940
2067
  return JSON.stringify(left).localeCompare(JSON.stringify(right));
@@ -2010,13 +2137,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2010
2137
  key: "restoreOriginalSnapshotIfProductsUnchanged",
2011
2138
  value: function restoreOriginalSnapshotIfProductsUnchanged(tempOrder, snapshot) {
2012
2139
  var currentFingerprint = this.buildOrderProductsFingerprint(tempOrder.products);
2140
+ var manualDepositOverride = this.getManualDepositOverride(tempOrder);
2013
2141
  if (currentFingerprint !== snapshot.productFingerprint) {
2014
2142
  var currentStructuralFingerprint = this.buildOrderProductsStructuralFingerprint(tempOrder.products);
2015
2143
  var snapshotStructuralFingerprint = this.buildOrderProductsStructuralFingerprint(Array.isArray(snapshot.products) ? snapshot.products : []);
2016
2144
  if (currentStructuralFingerprint !== snapshotStructuralFingerprint) return null;
2017
2145
  }
2018
2146
  var summary = _objectSpread(_objectSpread({}, createEmptySummary()), cloneDeep(snapshot.summary || {}));
2019
- if (!this.isSnapshotPayableAmountUnchanged(tempOrder, snapshot, summary)) return null;
2147
+ var shouldUseManualDepositOverride = Boolean(manualDepositOverride && manualDepositOverride.productStructuralFingerprint === this.buildOrderProductsStructuralFingerprint(tempOrder.products));
2148
+ if (shouldUseManualDepositOverride) {
2149
+ summary = this.applyDepositAmountToSummary(tempOrder, summary, manualDepositOverride.amount);
2150
+ } else if (manualDepositOverride) {
2151
+ this.clearManualDepositOverride(tempOrder);
2152
+ }
2153
+ var isPayableAmountUnchanged = this.isSnapshotPayableAmountUnchanged(tempOrder, snapshot, summary);
2154
+ if (!isPayableAmountUnchanged) return null;
2020
2155
  if (Array.isArray(snapshot.products)) {
2021
2156
  tempOrder.products = cloneDeep(snapshot.products);
2022
2157
  }
@@ -2026,7 +2161,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2026
2161
  tempOrder.surcharge_fee = summary.surcharge_fee || tempOrder.surcharge_fee;
2027
2162
  tempOrder.deposit_amount = summary.deposit_amount || '0.00';
2028
2163
  tempOrder.is_deposit = summary.deposit_amount !== '0.00' ? 1 : 0;
2164
+ var previousSummary = this.store.summary;
2029
2165
  this.store.summary = summary;
2166
+ this.updateTempOrderPaymentStatus(tempOrder, {
2167
+ previousSummary: previousSummary,
2168
+ summary: summary
2169
+ });
2030
2170
  return summary;
2031
2171
  }
2032
2172
  }, {
@@ -2138,7 +2278,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2138
2278
  }, {
2139
2279
  key: "restoreOrder",
2140
2280
  value: function restoreOrder() {
2141
- var _this$store$discount11, _this$store$discount12;
2281
+ var _this$store$discount15, _this$store$discount16;
2142
2282
  this.logInfo('restoreOrder start', {});
2143
2283
  var freshTempOrder = this.createDefaultTempOrderInstance();
2144
2284
  this.ensureExternalSaleNumber(freshTempOrder);
@@ -2146,8 +2286,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2146
2286
  this.store.summary = createEmptySummary();
2147
2287
  this.store.lastOrderInfo = undefined;
2148
2288
  this.store.syncState = undefined;
2149
- void ((_this$store$discount11 = this.store.discount) === null || _this$store$discount11 === void 0 ? void 0 : _this$store$discount11.setOriginalDiscountList([]));
2150
- void ((_this$store$discount12 = this.store.discount) === null || _this$store$discount12 === void 0 ? void 0 : _this$store$discount12.setDiscountList([]));
2289
+ void ((_this$store$discount15 = this.store.discount) === null || _this$store$discount15 === void 0 ? void 0 : _this$store$discount15.setOriginalDiscountList([]));
2290
+ void ((_this$store$discount16 = this.store.discount) === null || _this$store$discount16 === void 0 ? void 0 : _this$store$discount16.setDiscountList([]));
2151
2291
  this.persistTempOrder();
2152
2292
  return freshTempOrder;
2153
2293
  }
@@ -2159,13 +2299,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2159
2299
  }, {
2160
2300
  key: "replaceTempOrder",
2161
2301
  value: function () {
2162
- var _replaceTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(tempOrder, options) {
2302
+ var _replaceTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(tempOrder, options) {
2163
2303
  var nextTempOrder;
2164
- return _regeneratorRuntime().wrap(function _callee9$(_context11) {
2165
- while (1) switch (_context11.prev = _context11.next) {
2304
+ return _regeneratorRuntime().wrap(function _callee10$(_context12) {
2305
+ while (1) switch (_context12.prev = _context12.next) {
2166
2306
  case 0:
2167
2307
  if (isTempOrder(tempOrder)) {
2168
- _context11.next = 2;
2308
+ _context12.next = 2;
2169
2309
  break;
2170
2310
  }
2171
2311
  throw new Error('无效的 tempOrder 数据');
@@ -2175,15 +2315,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2175
2315
  });
2176
2316
  this.store.tempOrder = nextTempOrder;
2177
2317
  if (!((options === null || options === void 0 ? void 0 : options.recalculateSummary) !== false)) {
2178
- _context11.next = 9;
2318
+ _context12.next = 9;
2179
2319
  break;
2180
2320
  }
2181
- _context11.next = 7;
2321
+ _context12.next = 7;
2182
2322
  return this.recalculateSummary({
2183
2323
  createIfMissing: false
2184
2324
  });
2185
2325
  case 7:
2186
- _context11.next = 10;
2326
+ _context12.next = 10;
2187
2327
  break;
2188
2328
  case 9:
2189
2329
  this.store.summary = createEmptySummary();
@@ -2192,20 +2332,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2192
2332
  this.persistTempOrder();
2193
2333
  }
2194
2334
  if (!(options !== null && options !== void 0 && options.saveDraft)) {
2195
- _context11.next = 14;
2335
+ _context12.next = 14;
2196
2336
  break;
2197
2337
  }
2198
- _context11.next = 14;
2338
+ _context12.next = 14;
2199
2339
  return this.saveDraft();
2200
2340
  case 14:
2201
- return _context11.abrupt("return", nextTempOrder);
2341
+ return _context12.abrupt("return", nextTempOrder);
2202
2342
  case 15:
2203
2343
  case "end":
2204
- return _context11.stop();
2344
+ return _context12.stop();
2205
2345
  }
2206
- }, _callee9, this);
2346
+ }, _callee10, this);
2207
2347
  }));
2208
- function replaceTempOrder(_x8, _x9) {
2348
+ function replaceTempOrder(_x9, _x10) {
2209
2349
  return _replaceTempOrder.apply(this, arguments);
2210
2350
  }
2211
2351
  return replaceTempOrder;
@@ -2291,32 +2431,32 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2291
2431
  }, {
2292
2432
  key: "addNewOrder",
2293
2433
  value: function () {
2294
- var _addNewOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
2434
+ var _addNewOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
2295
2435
  var tempOrder;
2296
- return _regeneratorRuntime().wrap(function _callee10$(_context12) {
2297
- while (1) switch (_context12.prev = _context12.next) {
2436
+ return _regeneratorRuntime().wrap(function _callee11$(_context13) {
2437
+ while (1) switch (_context13.prev = _context13.next) {
2298
2438
  case 0:
2299
2439
  tempOrder = this.ensureTempOrder();
2300
2440
  this.ensureExternalSaleNumber(tempOrder);
2301
- _context12.next = 4;
2441
+ _context13.next = 4;
2302
2442
  return this.recalculateSummary({
2303
2443
  createIfMissing: true
2304
2444
  });
2305
2445
  case 4:
2306
2446
  this.persistTempOrder();
2307
2447
  if (!this.draftPersistEnabled) {
2308
- _context12.next = 8;
2448
+ _context13.next = 8;
2309
2449
  break;
2310
2450
  }
2311
- _context12.next = 8;
2451
+ _context13.next = 8;
2312
2452
  return this.saveDraft();
2313
2453
  case 8:
2314
- return _context12.abrupt("return", tempOrder);
2454
+ return _context13.abrupt("return", tempOrder);
2315
2455
  case 9:
2316
2456
  case "end":
2317
- return _context12.stop();
2457
+ return _context13.stop();
2318
2458
  }
2319
- }, _callee10, this);
2459
+ }, _callee11, this);
2320
2460
  }));
2321
2461
  function addNewOrder() {
2322
2462
  return _addNewOrder.apply(this, arguments);
@@ -2349,9 +2489,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2349
2489
  }, {
2350
2490
  key: "sanitizeTempOrderProducts",
2351
2491
  value: function sanitizeTempOrderProducts(tempOrder) {
2352
- var _this12 = this;
2492
+ var _this15 = this;
2353
2493
  tempOrder.products = (tempOrder.products || []).map(function (product) {
2354
- return _this12.sanitizeOrderProductForTempOrder(product);
2494
+ return _this15.sanitizeOrderProductForTempOrder(product);
2355
2495
  });
2356
2496
  }
2357
2497
  }, {
@@ -2454,7 +2594,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2454
2594
  }, {
2455
2595
  key: "syncLinkedBookingHoldersToProducts",
2456
2596
  value: function syncLinkedBookingHoldersToProducts(tempOrder) {
2457
- var _this13 = this;
2597
+ var _this16 = this;
2458
2598
  var bookings = tempOrder.bookings || [];
2459
2599
  var products = tempOrder.products || [];
2460
2600
  if (!bookings.length || !products.length) return;
@@ -2479,7 +2619,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2479
2619
  var bookingUid = product.booking_uid || ((_product$metadata6 = product.metadata) === null || _product$metadata6 === void 0 ? void 0 : _product$metadata6.booking_uid);
2480
2620
  var linkedBooking = (productUid !== undefined && productUid !== null && String(productUid) !== '' ? bookingByProductUid.get(String(productUid)) : undefined) || (bookingUid !== undefined && bookingUid !== null && String(bookingUid) !== '' ? bookingByBookingUid.get(String(bookingUid)) : undefined);
2481
2621
  if (linkedBooking) {
2482
- _this13.setProductHolderFromBooking(product, linkedBooking);
2622
+ _this16.setProductHolderFromBooking(product, linkedBooking);
2483
2623
  }
2484
2624
  });
2485
2625
  }
@@ -2517,7 +2657,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2517
2657
  }, {
2518
2658
  key: "buildTempOrderHolderFromBookings",
2519
2659
  value: function buildTempOrderHolderFromBookings(tempOrder) {
2520
- var _baseHolder$customer_, _baseHolder, _ref46, _baseHolder$form_id, _baseHolder2, _tempOrder$holder3, _baseHolder3, _this$otherParams;
2660
+ var _baseHolder$customer_, _baseHolder, _ref46, _baseHolder$form_id, _baseHolder2, _tempOrder$holder2, _baseHolder3, _this$otherParams;
2521
2661
  var holderRecords = [];
2522
2662
  var holderNames = [];
2523
2663
  var baseHolder = null;
@@ -2564,7 +2704,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2564
2704
  }
2565
2705
  var nextHolder = {
2566
2706
  customer_id: (_baseHolder$customer_ = (_baseHolder = baseHolder) === null || _baseHolder === void 0 ? void 0 : _baseHolder.customer_id) !== null && _baseHolder$customer_ !== void 0 ? _baseHolder$customer_ : tempOrder.customer_id,
2567
- form_id: (_ref46 = (_baseHolder$form_id = (_baseHolder2 = baseHolder) === null || _baseHolder2 === void 0 ? void 0 : _baseHolder2.form_id) !== null && _baseHolder$form_id !== void 0 ? _baseHolder$form_id : (_tempOrder$holder3 = tempOrder.holder) === null || _tempOrder$holder3 === void 0 ? void 0 : _tempOrder$holder3.form_id) !== null && _ref46 !== void 0 ? _ref46 : 0,
2707
+ form_id: (_ref46 = (_baseHolder$form_id = (_baseHolder2 = baseHolder) === null || _baseHolder2 === void 0 ? void 0 : _baseHolder2.form_id) !== null && _baseHolder$form_id !== void 0 ? _baseHolder$form_id : (_tempOrder$holder2 = tempOrder.holder) === null || _tempOrder$holder2 === void 0 ? void 0 : _tempOrder$holder2.form_id) !== null && _ref46 !== void 0 ? _ref46 : 0,
2568
2708
  form_record: holderRecords
2569
2709
  };
2570
2710
  if (holderNames.length) {
@@ -2607,9 +2747,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2607
2747
  }, {
2608
2748
  key: "findBookingIndexByUniqueIdentificationNumber",
2609
2749
  value: function findBookingIndexByUniqueIdentificationNumber(tempOrder, uniqueIdentificationNumber) {
2610
- var _this14 = this;
2750
+ var _this17 = this;
2611
2751
  return (tempOrder.bookings || []).findIndex(function (booking) {
2612
- return _this14.getBookingUniqueIdentificationNumber(booking) === uniqueIdentificationNumber;
2752
+ return _this17.getBookingUniqueIdentificationNumber(booking) === uniqueIdentificationNumber;
2613
2753
  });
2614
2754
  }
2615
2755
  }, {
@@ -2617,12 +2757,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2617
2757
  value: function removeLinkedBookingsForProduct(tempOrder, product) {
2618
2758
  var _product$metadata7,
2619
2759
  _product$metadata8,
2620
- _this15 = this;
2760
+ _this18 = this;
2621
2761
  var productUid = (product === null || product === void 0 || (_product$metadata7 = product.metadata) === null || _product$metadata7 === void 0 ? void 0 : _product$metadata7.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
2622
2762
  var bookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_product$metadata8 = product.metadata) === null || _product$metadata8 === void 0 ? void 0 : _product$metadata8.booking_uid);
2623
2763
  if (!productUid && !bookingUid) return;
2624
2764
  tempOrder.bookings = (tempOrder.bookings || []).filter(function (booking) {
2625
- var currentBookingUid = _this15.getBookingUniqueIdentificationNumber(booking);
2765
+ var currentBookingUid = _this18.getBookingUniqueIdentificationNumber(booking);
2626
2766
  if (bookingUid && currentBookingUid === String(bookingUid)) return false;
2627
2767
  if (productUid && String((booking === null || booking === void 0 ? void 0 : booking.product_uid) || '') === String(productUid)) return false;
2628
2768
  return true;
@@ -2668,18 +2808,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2668
2808
  }, {
2669
2809
  key: "recalculateSummary",
2670
2810
  value: function () {
2671
- var _recalculateSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(options) {
2811
+ var _recalculateSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(options) {
2672
2812
  var _this$otherParams2, _ref47, _salesSummaryResult$e;
2673
2813
  var tempOrder, originalSnapshot, hasShopDiscountChanged, shouldReuseOriginalSnapshot, snapshotSummary, shouldFullRecalculateFromSnapshot, summaryProducts, salesSummary, existedSummary, totalRefundAmount, paidPaymentSummary, emptyBaseSummary, emptySummaryBase, emptySummaryWithDeposit, emptySummary, salesSummaryResult, roundingAmount, payServiceChargeAmount, hasSalesSummaryAmount, expectAmount, amountPaymentPatch, normalizedExpectAmountPatch, summaryForGap, summary;
2674
- return _regeneratorRuntime().wrap(function _callee11$(_context13) {
2675
- while (1) switch (_context13.prev = _context13.next) {
2814
+ return _regeneratorRuntime().wrap(function _callee12$(_context14) {
2815
+ while (1) switch (_context14.prev = _context14.next) {
2676
2816
  case 0:
2677
2817
  tempOrder = options !== null && options !== void 0 && options.createIfMissing ? this.ensureTempOrder() : this.store.tempOrder;
2678
2818
  if (tempOrder) {
2679
- _context13.next = 3;
2819
+ _context14.next = 3;
2680
2820
  break;
2681
2821
  }
2682
- return _context13.abrupt("return", null);
2822
+ return _context14.abrupt("return", null);
2683
2823
  case 3:
2684
2824
  this.sanitizeTempOrderProducts(tempOrder);
2685
2825
  originalSnapshot = this.getOriginalSalesSnapshot(tempOrder);
@@ -2687,10 +2827,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2687
2827
  shouldReuseOriginalSnapshot = originalSnapshot && !hasShopDiscountChanged;
2688
2828
  snapshotSummary = shouldReuseOriginalSnapshot ? this.restoreOriginalSnapshotIfProductsUnchanged(tempOrder, originalSnapshot) : null;
2689
2829
  if (!snapshotSummary) {
2690
- _context13.next = 10;
2830
+ _context14.next = 10;
2691
2831
  break;
2692
2832
  }
2693
- return _context13.abrupt("return", snapshotSummary);
2833
+ return _context14.abrupt("return", snapshotSummary);
2694
2834
  case 10:
2695
2835
  shouldFullRecalculateFromSnapshot = Boolean(originalSnapshot);
2696
2836
  summaryProducts = shouldFullRecalculateFromSnapshot ? cloneDeep(tempOrder.products || []) : tempOrder.products;
@@ -2702,7 +2842,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2702
2842
  totalRefundAmount = existedSummary.total_refund_amount || '0.00';
2703
2843
  paidPaymentSummary = this.calculatePaidPaymentSummary(tempOrder.payments || []);
2704
2844
  if (salesSummary) {
2705
- _context13.next = 26;
2845
+ _context14.next = 26;
2706
2846
  break;
2707
2847
  }
2708
2848
  emptyBaseSummary = _objectSpread(_objectSpread(_objectSpread({}, createEmptySummary()), existedSummary), {}, {
@@ -2728,9 +2868,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2728
2868
  previousSummary: existedSummary,
2729
2869
  summary: emptySummary
2730
2870
  });
2731
- return _context13.abrupt("return", this.store.summary);
2871
+ return _context14.abrupt("return", this.store.summary);
2732
2872
  case 26:
2733
- _context13.next = 28;
2873
+ _context14.next = 28;
2734
2874
  return salesSummary.getSummary(_objectSpread({
2735
2875
  products: summaryProducts,
2736
2876
  isPriceIncludeTax: tempOrder.is_price_include_tax,
@@ -2739,7 +2879,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2739
2879
  channel: this.otherParams.channel
2740
2880
  } : {}));
2741
2881
  case 28:
2742
- salesSummaryResult = _context13.sent;
2882
+ salesSummaryResult = _context14.sent;
2743
2883
  if (shouldFullRecalculateFromSnapshot) {
2744
2884
  tempOrder.products = summaryProducts;
2745
2885
  }
@@ -2784,14 +2924,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2784
2924
  previousSummary: existedSummary,
2785
2925
  summary: summary
2786
2926
  });
2787
- return _context13.abrupt("return", this.store.summary);
2927
+ return _context14.abrupt("return", this.store.summary);
2788
2928
  case 46:
2789
2929
  case "end":
2790
- return _context13.stop();
2930
+ return _context14.stop();
2791
2931
  }
2792
- }, _callee11, this);
2932
+ }, _callee12, this);
2793
2933
  }));
2794
- function recalculateSummary(_x10) {
2934
+ function recalculateSummary(_x11) {
2795
2935
  return _recalculateSummary.apply(this, arguments);
2796
2936
  }
2797
2937
  return recalculateSummary;
@@ -2799,30 +2939,30 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2799
2939
  }, {
2800
2940
  key: "getOrderSummary",
2801
2941
  value: function () {
2802
- var _getOrderSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
2942
+ var _getOrderSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
2803
2943
  var summary;
2804
- return _regeneratorRuntime().wrap(function _callee12$(_context14) {
2805
- while (1) switch (_context14.prev = _context14.next) {
2944
+ return _regeneratorRuntime().wrap(function _callee13$(_context15) {
2945
+ while (1) switch (_context15.prev = _context15.next) {
2806
2946
  case 0:
2807
- _context14.next = 2;
2947
+ _context15.next = 2;
2808
2948
  return this.recalculateSummary({
2809
2949
  createIfMissing: true
2810
2950
  });
2811
2951
  case 2:
2812
- summary = _context14.sent;
2952
+ summary = _context15.sent;
2813
2953
  if (summary) {
2814
- _context14.next = 5;
2954
+ _context15.next = 5;
2815
2955
  break;
2816
2956
  }
2817
- return _context14.abrupt("return", createEmptySummary());
2957
+ return _context15.abrupt("return", createEmptySummary());
2818
2958
  case 5:
2819
2959
  this.persistTempOrder();
2820
- return _context14.abrupt("return", summary);
2960
+ return _context15.abrupt("return", summary);
2821
2961
  case 7:
2822
2962
  case "end":
2823
- return _context14.stop();
2963
+ return _context15.stop();
2824
2964
  }
2825
- }, _callee12, this);
2965
+ }, _callee13, this);
2826
2966
  }));
2827
2967
  function getOrderSummary() {
2828
2968
  return _getOrderSummary.apply(this, arguments);
@@ -2846,23 +2986,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2846
2986
  }, {
2847
2987
  key: "syncTempOrderNoteToRemote",
2848
2988
  value: function () {
2849
- var _syncTempOrderNoteToRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(orderId, note) {
2850
- return _regeneratorRuntime().wrap(function _callee13$(_context15) {
2851
- while (1) switch (_context15.prev = _context15.next) {
2989
+ var _syncTempOrderNoteToRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(orderId, note) {
2990
+ return _regeneratorRuntime().wrap(function _callee14$(_context16) {
2991
+ while (1) switch (_context16.prev = _context16.next) {
2852
2992
  case 0:
2853
- _context15.next = 2;
2993
+ _context16.next = 2;
2854
2994
  return this.request.put("/order/order/".concat(orderId, "/note"), {
2855
2995
  note: note
2856
2996
  });
2857
2997
  case 2:
2858
- return _context15.abrupt("return", note);
2998
+ return _context16.abrupt("return", note);
2859
2999
  case 3:
2860
3000
  case "end":
2861
- return _context15.stop();
3001
+ return _context16.stop();
2862
3002
  }
2863
- }, _callee13, this);
3003
+ }, _callee14, this);
2864
3004
  }));
2865
- function syncTempOrderNoteToRemote(_x11, _x12) {
3005
+ function syncTempOrderNoteToRemote(_x12, _x13) {
2866
3006
  return _syncTempOrderNoteToRemote.apply(this, arguments);
2867
3007
  }
2868
3008
  return syncTempOrderNoteToRemote;
@@ -2947,38 +3087,43 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2947
3087
  var type = (_discount$type5 = discount === null || discount === void 0 ? void 0 : discount.type) !== null && _discount$type5 !== void 0 ? _discount$type5 : discount === null || discount === void 0 ? void 0 : discount.tag;
2948
3088
  return type === 'good_pass' || type === 'discount_card' || type === 'product_discount_card';
2949
3089
  }
3090
+ }, {
3091
+ key: "shouldKeepCustomerBoundDiscountAfterCustomerChange",
3092
+ value: function shouldKeepCustomerBoundDiscountAfterCustomerChange(discount) {
3093
+ return Boolean((discount === null || discount === void 0 ? void 0 : discount.isScan) || (discount === null || discount === void 0 ? void 0 : discount.isEditMode));
3094
+ }
2950
3095
  }, {
2951
3096
  key: "productHasCustomerBoundDiscount",
2952
3097
  value: function productHasCustomerBoundDiscount(product) {
2953
- var _this16 = this;
3098
+ var _this19 = this;
2954
3099
  if (((product === null || product === void 0 ? void 0 : product.discount_list) || []).some(function (discount) {
2955
- return _this16.isCustomerBoundDiscount(discount);
3100
+ return _this19.isCustomerBoundDiscount(discount);
2956
3101
  })) {
2957
3102
  return true;
2958
3103
  }
2959
3104
  return ((product === null || product === void 0 ? void 0 : product.product_bundle) || []).some(function (bundle) {
2960
3105
  return ((bundle === null || bundle === void 0 ? void 0 : bundle.discount_list) || []).some(function (discount) {
2961
- return _this16.isCustomerBoundDiscount(discount);
3106
+ return _this19.isCustomerBoundDiscount(discount);
2962
3107
  });
2963
3108
  });
2964
3109
  }
2965
3110
  }, {
2966
3111
  key: "shouldSkipDiscountCalculation",
2967
3112
  value: function shouldSkipDiscountCalculation(tempOrder) {
2968
- var _this$store$discount13,
2969
- _this$store$discount14,
2970
- _this17 = this;
3113
+ var _this$store$discount17,
3114
+ _this$store$discount18,
3115
+ _this20 = this;
2971
3116
  if (this.hasActiveCustomerBoundDiscount) return false;
2972
- var discountList = ((_this$store$discount13 = this.store.discount) === null || _this$store$discount13 === void 0 || (_this$store$discount14 = _this$store$discount13.getDiscountList) === null || _this$store$discount14 === void 0 ? void 0 : _this$store$discount14.call(_this$store$discount13)) || [];
3117
+ var discountList = ((_this$store$discount17 = this.store.discount) === null || _this$store$discount17 === void 0 || (_this$store$discount18 = _this$store$discount17.getDiscountList) === null || _this$store$discount18 === void 0 ? void 0 : _this$store$discount18.call(_this$store$discount17)) || [];
2973
3118
  if (discountList.length > 0) return false;
2974
3119
  return !(tempOrder.products || []).some(function (product) {
2975
- return _this17.productHasCustomerBoundDiscount(product);
3120
+ return _this20.productHasCustomerBoundDiscount(product);
2976
3121
  });
2977
3122
  }
2978
3123
  }, {
2979
3124
  key: "clearCustomerBoundDiscounts",
2980
3125
  value: function clearCustomerBoundDiscounts(tempOrder) {
2981
- var _this18 = this,
3126
+ var _this21 = this,
2982
3127
  _discountModule$getDi,
2983
3128
  _discountModule$getOr,
2984
3129
  _discountModule$setDi,
@@ -2987,7 +3132,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2987
3132
  var filterDiscountList = function filterDiscountList(discountList) {
2988
3133
  if (!Array.isArray(discountList)) return [];
2989
3134
  return discountList.filter(function (discount) {
2990
- var shouldRemove = _this18.isCustomerBoundDiscount(discount);
3135
+ var shouldRemove = _this21.isCustomerBoundDiscount(discount);
2991
3136
  if (shouldRemove) didRemoveCustomerBoundDiscount = true;
2992
3137
  return !shouldRemove;
2993
3138
  });
@@ -3014,12 +3159,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3014
3159
  var currentDiscounts = ((_discountModule$getDi = discountModule.getDiscountList) === null || _discountModule$getDi === void 0 ? void 0 : _discountModule$getDi.call(discountModule)) || [];
3015
3160
  var currentOriginalDiscounts = ((_discountModule$getOr = discountModule.getOriginalDiscountList) === null || _discountModule$getOr === void 0 ? void 0 : _discountModule$getOr.call(discountModule)) || [];
3016
3161
  var nextDiscounts = currentDiscounts.filter(function (discount) {
3017
- if (discount !== null && discount !== void 0 && discount.isEditMode) return true;
3018
- return !_this18.isCustomerBoundDiscount(discount);
3162
+ if (_this21.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount)) return true;
3163
+ return !_this21.isCustomerBoundDiscount(discount);
3019
3164
  });
3020
3165
  var nextOriginalDiscounts = currentOriginalDiscounts.filter(function (discount) {
3021
- if (discount !== null && discount !== void 0 && discount.isEditMode) return true;
3022
- return !_this18.isCustomerBoundDiscount(discount);
3166
+ if (_this21.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount)) return true;
3167
+ return !_this21.isCustomerBoundDiscount(discount);
3023
3168
  });
3024
3169
  void ((_discountModule$setDi = discountModule.setDiscountList) === null || _discountModule$setDi === void 0 ? void 0 : _discountModule$setDi.call(discountModule, nextDiscounts));
3025
3170
  void ((_discountModule$setOr = discountModule.setOriginalDiscountList) === null || _discountModule$setOr === void 0 ? void 0 : _discountModule$setOr.call(discountModule, nextOriginalDiscounts));
@@ -3090,6 +3235,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3090
3235
  }
3091
3236
  var nextCustomerId = (_tempOrder$customer_i5 = tempOrder.customer_id) !== null && _tempOrder$customer_i5 !== void 0 ? _tempOrder$customer_i5 : null;
3092
3237
  if (String(previousCustomerId !== null && previousCustomerId !== void 0 ? previousCustomerId : '') !== String(nextCustomerId !== null && nextCustomerId !== void 0 ? nextCustomerId : '')) {
3238
+ this.store.availableWalletIds = [];
3093
3239
  clearTempOrderHolderAssignments(tempOrder);
3094
3240
  this.clearCustomerBoundDiscounts(tempOrder);
3095
3241
  this.applyDiscount();
@@ -3134,6 +3280,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3134
3280
  tempOrder.email = '';
3135
3281
  tempOrder.customer = null;
3136
3282
  if (tempOrder._extend) delete tempOrder._extend.customerSnapshot;
3283
+ this.store.availableWalletIds = [];
3137
3284
  this.clearCustomerBoundDiscounts(tempOrder);
3138
3285
  this.persistTempOrder();
3139
3286
  this.saveDraftInBackground();
@@ -3171,23 +3318,71 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3171
3318
  * 用一组支付来源覆盖当前订单支付项。
3172
3319
  *
3173
3320
  * 入参允许来自 PaymentModule 的 PaymentItem,内部统一映射为 Sales 协议:
3174
- * uuid -> metadata.unique_payment_number,id -> custom_payment_id,
3321
+ * 新支付来源的 uuid 会作为 payment_number 的唯一号段,id -> custom_payment_id,
3175
3322
  * isSynced 等运行态字段不会进入 tempOrder.payments。
3176
3323
  */
3177
3324
  }, {
3178
3325
  key: "setOrderPayments",
3179
3326
  value: function setOrderPayments(payments) {
3327
+ var _this22 = this;
3180
3328
  var tempOrder = this.ensureTempOrder();
3181
- tempOrder.payments = mapPaymentItemsToOrderPayments(payments);
3329
+ tempOrder.payments = mapPaymentItemsToOrderPayments((payments || []).map(function (payment) {
3330
+ return _this22.normalizePaymentSource(payment, {
3331
+ defaultPaid: false
3332
+ });
3333
+ }));
3182
3334
  this.persistTempOrder();
3183
3335
  return tempOrder.payments;
3184
3336
  }
3185
3337
 
3186
- /** 追加单个支付项,并立即持久化当前 tempOrder。 */
3338
+ /** 同步兼容入口:按调用当下的 device_id 或 LOCAL 生成支付编号。 */
3187
3339
  }, {
3188
3340
  key: "addOrderPayment",
3189
3341
  value: function addOrderPayment(payment) {
3190
- var _this19 = this;
3342
+ var hasPaymentNumber = String(payment.payment_number || '').trim() !== '';
3343
+ return this.addOrderPaymentWithDevicePrefix(payment, hasPaymentNumber ? 'LOCAL' : this.getPaymentNumberDevicePrefixSync());
3344
+ }
3345
+
3346
+ /** 异步入口:创建支付项时读取最新 IoT 设备短号。 */
3347
+ }, {
3348
+ key: "addOrderPaymentAsync",
3349
+ value: (function () {
3350
+ var _addOrderPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(payment) {
3351
+ var hasPaymentNumber, devicePrefix;
3352
+ return _regeneratorRuntime().wrap(function _callee15$(_context17) {
3353
+ while (1) switch (_context17.prev = _context17.next) {
3354
+ case 0:
3355
+ hasPaymentNumber = String(payment.payment_number || '').trim() !== '';
3356
+ if (!hasPaymentNumber) {
3357
+ _context17.next = 5;
3358
+ break;
3359
+ }
3360
+ _context17.t0 = 'LOCAL';
3361
+ _context17.next = 8;
3362
+ break;
3363
+ case 5:
3364
+ _context17.next = 7;
3365
+ return this.getPaymentNumberDevicePrefixAsync();
3366
+ case 7:
3367
+ _context17.t0 = _context17.sent;
3368
+ case 8:
3369
+ devicePrefix = _context17.t0;
3370
+ return _context17.abrupt("return", this.addOrderPaymentWithDevicePrefix(payment, devicePrefix));
3371
+ case 10:
3372
+ case "end":
3373
+ return _context17.stop();
3374
+ }
3375
+ }, _callee15, this);
3376
+ }));
3377
+ function addOrderPaymentAsync(_x14) {
3378
+ return _addOrderPaymentAsync.apply(this, arguments);
3379
+ }
3380
+ return addOrderPaymentAsync;
3381
+ }())
3382
+ }, {
3383
+ key: "addOrderPaymentWithDevicePrefix",
3384
+ value: function addOrderPaymentWithDevicePrefix(payment, devicePrefix) {
3385
+ var _this23 = this;
3191
3386
  this.logInfo('addOrderPayment', {
3192
3387
  payment: payment
3193
3388
  });
@@ -3197,14 +3392,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3197
3392
  type: orderPaymentType,
3198
3393
  order_payment_type: orderPaymentType
3199
3394
  }), {
3200
- defaultPaid: true
3395
+ defaultPaid: true,
3396
+ devicePrefix: devicePrefix
3201
3397
  })]);
3202
3398
  tempOrder.payments = [].concat(_toConsumableArray(tempOrder.payments || []), _toConsumableArray(mapped));
3203
3399
  this.persistTempOrder();
3204
3400
  void this.recalculateSummary({
3205
3401
  createIfMissing: true
3206
3402
  }).catch(function (error) {
3207
- _this19.logError('recalculate summary after addOrderPayment failed', {
3403
+ _this23.logError('recalculate summary after addOrderPayment failed', {
3208
3404
  error: error instanceof Error ? error.message : String(error)
3209
3405
  });
3210
3406
  });
@@ -3212,49 +3408,80 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3212
3408
  }
3213
3409
 
3214
3410
  /**
3215
- * 按支付唯一号、后端支付 ID、自定义支付方式 ID 或旧 uuid 更新支付项。
3216
- *
3217
- * 该方法服务 PaymentModal 的 void / 编辑场景;更新 metadata 时会做浅合并,
3218
- * 避免覆盖 unique_payment_number、现金实付/找零等已有元数据。
3411
+ * 默认按支付唯一号精确更新;仅显式指定 legacy 时兼容历史支付标识。
3412
+ * metadata 与 transactions 会分别合并,避免覆盖支付会话号和已有交易记录。
3219
3413
  */
3220
3414
  }, {
3221
3415
  key: "updateOrderPayment",
3222
- value: function updateOrderPayment(paymentIdentity, updates) {
3223
- var tempOrder = this.ensureTempOrder();
3224
- var identity = String(paymentIdentity);
3225
- tempOrder.payments = (tempOrder.payments || []).map(function (payment) {
3226
- var _payment$metadata;
3227
- var uniquePaymentNumber = payment === null || payment === void 0 || (_payment$metadata = payment.metadata) === null || _payment$metadata === void 0 ? void 0 : _payment$metadata.unique_payment_number;
3228
- var orderPaymentId = payment === null || payment === void 0 ? void 0 : payment.order_payment_id;
3229
- var customPaymentId = payment === null || payment === void 0 ? void 0 : payment.custom_payment_id;
3230
- var uuid = payment === null || payment === void 0 ? void 0 : payment.uuid;
3231
- var matched = [uniquePaymentNumber, orderPaymentId, customPaymentId, uuid].some(function (value) {
3232
- return value !== undefined && String(value) === identity;
3233
- });
3234
- if (!matched) return payment;
3235
- return _objectSpread(_objectSpread(_objectSpread({}, payment), updates), {}, {
3236
- metadata: _objectSpread(_objectSpread({}, payment.metadata || {}), updates.metadata || {})
3237
- });
3238
- });
3239
- this.persistTempOrder();
3240
- return tempOrder.payments;
3241
- }
3242
-
3243
- /** 从当前订单支付项中移除指定支付项。 */
3416
+ value: (function () {
3417
+ var _updateOrderPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(paymentIdentity, updates) {
3418
+ var options,
3419
+ tempOrder,
3420
+ identity,
3421
+ matchMode,
3422
+ matchedPayment,
3423
+ updatedPayment,
3424
+ summary,
3425
+ payments,
3426
+ _args18 = arguments;
3427
+ return _regeneratorRuntime().wrap(function _callee16$(_context18) {
3428
+ while (1) switch (_context18.prev = _context18.next) {
3429
+ case 0:
3430
+ options = _args18.length > 2 && _args18[2] !== undefined ? _args18[2] : {};
3431
+ tempOrder = this.ensureTempOrder();
3432
+ identity = String(paymentIdentity);
3433
+ matchMode = options.matchBy === 'compat' || options.matchBy === 'legacy' ? 'compat' : 'payment_number';
3434
+ matchedPayment = resolveOrderPaymentIdentity(tempOrder.payments || [], identity, matchMode);
3435
+ if (matchedPayment) {
3436
+ _context18.next = 7;
3437
+ break;
3438
+ }
3439
+ throw new Error("\u672A\u627E\u5230\u652F\u4ED8\u9879: ".concat(identity));
3440
+ case 7:
3441
+ updatedPayment = null;
3442
+ tempOrder.payments = (tempOrder.payments || []).map(function (payment, index) {
3443
+ if (index !== matchedPayment.index) return payment;
3444
+ var nextPayment = mergeOrderPaymentRecord(payment, _objectSpread(_objectSpread({}, updates), {}, {
3445
+ updated_at: updates.updated_at || dayjs().format('YYYY-MM-DD HH:mm:ss')
3446
+ }));
3447
+ updatedPayment = nextPayment;
3448
+ return nextPayment;
3449
+ });
3450
+ this.persistTempOrder();
3451
+ _context18.next = 12;
3452
+ return this.recalculateSummary({
3453
+ createIfMissing: true
3454
+ });
3455
+ case 12:
3456
+ summary = _context18.sent;
3457
+ this.persistTempOrder();
3458
+ payments = tempOrder.payments;
3459
+ return _context18.abrupt("return", {
3460
+ updated: true,
3461
+ payment: payments[matchedPayment.index] || updatedPayment,
3462
+ payments: payments,
3463
+ summary: summary
3464
+ });
3465
+ case 16:
3466
+ case "end":
3467
+ return _context18.stop();
3468
+ }
3469
+ }, _callee16, this);
3470
+ }));
3471
+ function updateOrderPayment(_x15, _x16) {
3472
+ return _updateOrderPayment.apply(this, arguments);
3473
+ }
3474
+ return updateOrderPayment;
3475
+ }() /** 从当前订单支付项中移除指定支付项。 */)
3244
3476
  }, {
3245
3477
  key: "deleteOrderPayment",
3246
3478
  value: function deleteOrderPayment(paymentIdentity) {
3247
3479
  var tempOrder = this.ensureTempOrder();
3248
3480
  var identity = String(paymentIdentity);
3249
- tempOrder.payments = (tempOrder.payments || []).filter(function (payment) {
3250
- var _payment$metadata2;
3251
- var uniquePaymentNumber = payment === null || payment === void 0 || (_payment$metadata2 = payment.metadata) === null || _payment$metadata2 === void 0 ? void 0 : _payment$metadata2.unique_payment_number;
3252
- var orderPaymentId = payment === null || payment === void 0 ? void 0 : payment.order_payment_id;
3253
- var customPaymentId = payment === null || payment === void 0 ? void 0 : payment.custom_payment_id;
3254
- var uuid = payment === null || payment === void 0 ? void 0 : payment.uuid;
3255
- return ![uniquePaymentNumber, orderPaymentId, customPaymentId, uuid].some(function (value) {
3256
- return value !== undefined && String(value) === identity;
3257
- });
3481
+ var matchedPayment = resolveOrderPaymentIdentity(tempOrder.payments || [], identity, 'compat');
3482
+ if (!matchedPayment) return tempOrder.payments;
3483
+ tempOrder.payments = (tempOrder.payments || []).filter(function (_, index) {
3484
+ return index !== matchedPayment.index;
3258
3485
  });
3259
3486
  this.persistTempOrder();
3260
3487
  return tempOrder.payments;
@@ -3286,7 +3513,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3286
3513
  }, {
3287
3514
  key: "applyPaymentLifecycleChange",
3288
3515
  value: function applyPaymentLifecycleChange(tempOrder, options) {
3289
- var _this20 = this;
3516
+ var _this24 = this;
3290
3517
  this.updateTempOrderPaymentStatus(tempOrder);
3291
3518
  if ((options === null || options === void 0 ? void 0 : options.persist) !== false) {
3292
3519
  this.persistTempOrder();
@@ -3296,7 +3523,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3296
3523
  void this.recalculateSummary({
3297
3524
  createIfMissing: true
3298
3525
  }).catch(function (error) {
3299
- _this20.logError("recalculate summary after ".concat(logContext, " failed"), {
3526
+ _this24.logError("recalculate summary after ".concat(logContext, " failed"), {
3300
3527
  error: error instanceof Error ? error.message : String(error)
3301
3528
  });
3302
3529
  });
@@ -3340,7 +3567,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3340
3567
  }, {
3341
3568
  key: "updateVoucherOrderPayments",
3342
3569
  value: function updateVoucherOrderPayments(payments, options) {
3343
- var _this21 = this;
3570
+ var _this25 = this;
3344
3571
  var tempOrder = this.ensureTempOrder();
3345
3572
  var isOrderPaymentType = function isOrderPaymentType(value) {
3346
3573
  return value === 'normal' || value === 'deposit';
@@ -3375,8 +3602,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3375
3602
  });
3376
3603
  };
3377
3604
  var mappedVouchers = mapPaymentItemsToOrderPayments(payments.map(function (payment) {
3378
- return _this21.normalizePaymentSource(normalizeVoucherPaymentStatus(withVoucherPaymentType(payment)), {
3379
- defaultPaid: false
3605
+ return _this25.normalizePaymentSource(normalizeVoucherPaymentStatus(withVoucherPaymentType(payment)), {
3606
+ defaultPaid: false,
3607
+ devicePrefix: options === null || options === void 0 ? void 0 : options.devicePrefix
3380
3608
  });
3381
3609
  })).filter(function (payment) {
3382
3610
  return isVoucherPaymentRecord(payment);
@@ -3424,54 +3652,93 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3424
3652
  void this.recalculateSummary({
3425
3653
  createIfMissing: true
3426
3654
  }).catch(function (error) {
3427
- _this21.logError('recalculate summary after updateVoucherOrderPayments failed', {
3655
+ _this25.logError('recalculate summary after updateVoucherOrderPayments failed', {
3428
3656
  error: error instanceof Error ? error.message : String(error)
3429
3657
  });
3430
3658
  });
3431
3659
  return tempOrder.payments;
3432
3660
  }
3433
3661
  }, {
3434
- key: "shouldMergeProductToOrder",
3662
+ key: "updateVoucherOrderPaymentsAsync",
3435
3663
  value: function () {
3436
- var _shouldMergeProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(params) {
3437
- var _this$orderHooks;
3438
- var onBeforeMergeProductToOrder, result;
3439
- return _regeneratorRuntime().wrap(function _callee14$(_context16) {
3440
- while (1) switch (_context16.prev = _context16.next) {
3664
+ var _updateVoucherOrderPaymentsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(payments, options) {
3665
+ var needsPaymentNumber, devicePrefix;
3666
+ return _regeneratorRuntime().wrap(function _callee17$(_context19) {
3667
+ while (1) switch (_context19.prev = _context19.next) {
3441
3668
  case 0:
3442
- onBeforeMergeProductToOrder = (_this$orderHooks = this.orderHooks) === null || _this$orderHooks === void 0 ? void 0 : _this$orderHooks.onBeforeMergeProductToOrder;
3443
- if (onBeforeMergeProductToOrder) {
3444
- _context16.next = 3;
3669
+ needsPaymentNumber = (payments || []).some(function (payment) {
3670
+ return String(payment.payment_number || '').trim() === '';
3671
+ });
3672
+ if (!needsPaymentNumber) {
3673
+ _context19.next = 7;
3445
3674
  break;
3446
3675
  }
3447
- return _context16.abrupt("return", true);
3448
- case 3:
3449
- _context16.next = 5;
3450
- return onBeforeMergeProductToOrder(_objectSpread(_objectSpread({}, params), {}, {
3451
- defaultShouldMerge: true
3452
- }));
3453
- case 5:
3454
- result = _context16.sent;
3455
- if (!(typeof result === 'boolean')) {
3456
- _context16.next = 8;
3676
+ _context19.next = 4;
3677
+ return this.getPaymentNumberDevicePrefixAsync();
3678
+ case 4:
3679
+ _context19.t0 = _context19.sent;
3680
+ _context19.next = 8;
3681
+ break;
3682
+ case 7:
3683
+ _context19.t0 = 'LOCAL';
3684
+ case 8:
3685
+ devicePrefix = _context19.t0;
3686
+ return _context19.abrupt("return", this.updateVoucherOrderPayments(payments, _objectSpread(_objectSpread({}, options), {}, {
3687
+ devicePrefix: devicePrefix
3688
+ })));
3689
+ case 10:
3690
+ case "end":
3691
+ return _context19.stop();
3692
+ }
3693
+ }, _callee17, this);
3694
+ }));
3695
+ function updateVoucherOrderPaymentsAsync(_x17, _x18) {
3696
+ return _updateVoucherOrderPaymentsAsync.apply(this, arguments);
3697
+ }
3698
+ return updateVoucherOrderPaymentsAsync;
3699
+ }()
3700
+ }, {
3701
+ key: "shouldMergeProductToOrder",
3702
+ value: function () {
3703
+ var _shouldMergeProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(params) {
3704
+ var _this$orderHooks;
3705
+ var onBeforeMergeProductToOrder, result;
3706
+ return _regeneratorRuntime().wrap(function _callee18$(_context20) {
3707
+ while (1) switch (_context20.prev = _context20.next) {
3708
+ case 0:
3709
+ onBeforeMergeProductToOrder = (_this$orderHooks = this.orderHooks) === null || _this$orderHooks === void 0 ? void 0 : _this$orderHooks.onBeforeMergeProductToOrder;
3710
+ if (onBeforeMergeProductToOrder) {
3711
+ _context20.next = 3;
3712
+ break;
3713
+ }
3714
+ return _context20.abrupt("return", true);
3715
+ case 3:
3716
+ _context20.next = 5;
3717
+ return onBeforeMergeProductToOrder(_objectSpread(_objectSpread({}, params), {}, {
3718
+ defaultShouldMerge: true
3719
+ }));
3720
+ case 5:
3721
+ result = _context20.sent;
3722
+ if (!(typeof result === 'boolean')) {
3723
+ _context20.next = 8;
3457
3724
  break;
3458
3725
  }
3459
- return _context16.abrupt("return", result);
3726
+ return _context20.abrupt("return", result);
3460
3727
  case 8:
3461
3728
  if (!(result && _typeof(result) === 'object' && typeof result.shouldMerge === 'boolean')) {
3462
- _context16.next = 10;
3729
+ _context20.next = 10;
3463
3730
  break;
3464
3731
  }
3465
- return _context16.abrupt("return", result.shouldMerge);
3732
+ return _context20.abrupt("return", result.shouldMerge);
3466
3733
  case 10:
3467
- return _context16.abrupt("return", true);
3734
+ return _context20.abrupt("return", true);
3468
3735
  case 11:
3469
3736
  case "end":
3470
- return _context16.stop();
3737
+ return _context20.stop();
3471
3738
  }
3472
- }, _callee14, this);
3739
+ }, _callee18, this);
3473
3740
  }));
3474
- function shouldMergeProductToOrder(_x13) {
3741
+ function shouldMergeProductToOrder(_x19) {
3475
3742
  return _shouldMergeProductToOrder.apply(this, arguments);
3476
3743
  }
3477
3744
  return shouldMergeProductToOrder;
@@ -3507,30 +3774,30 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3507
3774
  }, {
3508
3775
  key: "finalizeProductOrderMutation",
3509
3776
  value: function () {
3510
- var _finalizeProductOrderMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(tempOrder, options) {
3511
- return _regeneratorRuntime().wrap(function _callee15$(_context17) {
3512
- while (1) switch (_context17.prev = _context17.next) {
3777
+ var _finalizeProductOrderMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(tempOrder, options) {
3778
+ return _regeneratorRuntime().wrap(function _callee19$(_context21) {
3779
+ while (1) switch (_context21.prev = _context21.next) {
3513
3780
  case 0:
3514
3781
  this.syncTempOrderHolderFromBookings(tempOrder);
3515
3782
  if (options !== null && options !== void 0 && options.skipEditDiscountConfigRefresh) {
3516
- _context17.next = 4;
3783
+ _context21.next = 4;
3517
3784
  break;
3518
3785
  }
3519
- _context17.next = 4;
3786
+ _context21.next = 4;
3520
3787
  return this.ensureEditDiscountConfigForProductChange(tempOrder);
3521
3788
  case 4:
3522
3789
  if (options !== null && options !== void 0 && options.skipDiscountRecalculation) {
3523
- _context17.next = 7;
3790
+ _context21.next = 7;
3524
3791
  break;
3525
3792
  }
3526
- _context17.next = 7;
3793
+ _context21.next = 7;
3527
3794
  return this.applyPromotion();
3528
3795
  case 7:
3529
3796
  if (!(options !== null && options !== void 0 && options.skipDiscountRecalculation)) {
3530
3797
  this.applyDiscount();
3531
3798
  }
3532
3799
  this.sanitizeTempOrderProducts(tempOrder);
3533
- _context17.next = 11;
3800
+ _context21.next = 11;
3534
3801
  return this.recalculateSummary({
3535
3802
  createIfMissing: true
3536
3803
  });
@@ -3538,11 +3805,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3538
3805
  this.persistTempOrder();
3539
3806
  case 12:
3540
3807
  case "end":
3541
- return _context17.stop();
3808
+ return _context21.stop();
3542
3809
  }
3543
- }, _callee15, this);
3810
+ }, _callee19, this);
3544
3811
  }));
3545
- function finalizeProductOrderMutation(_x14, _x15) {
3812
+ function finalizeProductOrderMutation(_x20, _x21) {
3546
3813
  return _finalizeProductOrderMutation.apply(this, arguments);
3547
3814
  }
3548
3815
  return finalizeProductOrderMutation;
@@ -3557,13 +3824,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3557
3824
  }, {
3558
3825
  key: "appendProductLineToTempOrder",
3559
3826
  value: (function () {
3560
- var _appendProductLineToTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(tempOrder, product, booking) {
3827
+ var _appendProductLineToTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(tempOrder, product, booking) {
3561
3828
  var _booking_uid,
3562
3829
  _metadata,
3563
- _this22 = this;
3830
+ _this26 = this;
3564
3831
  var linked, productToAdd, incomingFingerprint, normalizedIncoming, incomingBookingUid, hasIncomingGoodPass, hasIncomingProductNote, hasIncomingBookingUid, shouldForceNewLine, matchedIndex, matchedProduct, existedFingerprint, shouldMerge, _targetProduct$metada, targetProduct, targetUid, normalizedProduct, nextNum, targetIsManualProductDiscount, nextDiscountList;
3565
- return _regeneratorRuntime().wrap(function _callee16$(_context18) {
3566
- while (1) switch (_context18.prev = _context18.next) {
3832
+ return _regeneratorRuntime().wrap(function _callee20$(_context22) {
3833
+ while (1) switch (_context22.prev = _context22.next) {
3567
3834
  case 0:
3568
3835
  linked = booking ? this.createLinkedProductAndBooking({
3569
3836
  product: product,
@@ -3585,9 +3852,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3585
3852
  hasIncomingBookingUid = this.hasLinkedBookingUid(productToAdd) || this.hasLinkedBookingUid(normalizedIncoming);
3586
3853
  shouldForceNewLine = !!booking || hasIncomingProductNote || hasIncomingBookingUid;
3587
3854
  matchedIndex = hasIncomingGoodPass || shouldForceNewLine ? -1 : tempOrder.products.findIndex(function (item) {
3588
- if (_this22.hasGoodPassDiscount(item)) return false;
3589
- if (_this22.hasOrderProductLineNote(item)) return false;
3855
+ var _item$metadata3;
3856
+ if (_this26.hasGoodPassDiscount(item)) return false;
3857
+ if (_this26.hasOrderProductLineNote(item)) return false;
3590
3858
  if (item.order_detail_id !== undefined && item.order_detail_id !== null) return false;
3859
+ if ((_item$metadata3 = item.metadata) !== null && _item$metadata3 !== void 0 && _item$metadata3.is_edit_for_runtime) return false;
3591
3860
  if (item.product_id !== productToAdd.product_id) return false;
3592
3861
  if (item.product_variant_id !== productToAdd.product_variant_id) return false;
3593
3862
  var existedFingerprint = buildProductLineFingerprint(getProductSkuOptions(item), item.product_bundle);
@@ -3596,10 +3865,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3596
3865
  matchedProduct = matchedIndex === -1 ? null : tempOrder.products[matchedIndex];
3597
3866
  existedFingerprint = matchedProduct ? buildProductLineFingerprint(getProductSkuOptions(matchedProduct), matchedProduct.product_bundle) : '';
3598
3867
  if (!matchedProduct) {
3599
- _context18.next = 20;
3868
+ _context22.next = 20;
3600
3869
  break;
3601
3870
  }
3602
- _context18.next = 17;
3871
+ _context22.next = 17;
3603
3872
  return this.shouldMergeProductToOrder({
3604
3873
  incomingProduct: productToAdd,
3605
3874
  normalizedIncoming: normalizedIncoming,
@@ -3611,13 +3880,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3611
3880
  booking: booking
3612
3881
  });
3613
3882
  case 17:
3614
- _context18.t0 = _context18.sent;
3615
- _context18.next = 21;
3883
+ _context22.t0 = _context22.sent;
3884
+ _context22.next = 21;
3616
3885
  break;
3617
3886
  case 20:
3618
- _context18.t0 = false;
3887
+ _context22.t0 = false;
3619
3888
  case 21:
3620
- shouldMerge = _context18.t0;
3889
+ shouldMerge = _context22.t0;
3621
3890
  if (matchedIndex === -1 || !matchedProduct || !shouldMerge) {
3622
3891
  this.captureProductRuntime(tempOrder, productToAdd, normalizedIncoming);
3623
3892
  if (linked) {
@@ -3671,11 +3940,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3671
3940
  }
3672
3941
  case 24:
3673
3942
  case "end":
3674
- return _context18.stop();
3943
+ return _context22.stop();
3675
3944
  }
3676
- }, _callee16, this);
3945
+ }, _callee20, this);
3677
3946
  }));
3678
- function appendProductLineToTempOrder(_x16, _x17, _x18) {
3947
+ function appendProductLineToTempOrder(_x22, _x23, _x24) {
3679
3948
  return _appendProductLineToTempOrder.apply(this, arguments);
3680
3949
  }
3681
3950
  return appendProductLineToTempOrder;
@@ -3691,61 +3960,61 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3691
3960
  }, {
3692
3961
  key: "addProductToOrder",
3693
3962
  value: (function () {
3694
- var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(product, booking) {
3963
+ var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(product, booking) {
3695
3964
  var tempOrder, _ref61, _productRecord$num, productRecord, splitCount, i, singleLine;
3696
- return _regeneratorRuntime().wrap(function _callee17$(_context19) {
3697
- while (1) switch (_context19.prev = _context19.next) {
3965
+ return _regeneratorRuntime().wrap(function _callee21$(_context23) {
3966
+ while (1) switch (_context23.prev = _context23.next) {
3698
3967
  case 0:
3699
3968
  tempOrder = this.ensureTempOrder();
3700
3969
  if (!booking) {
3701
- _context19.next = 18;
3970
+ _context23.next = 18;
3702
3971
  break;
3703
3972
  }
3704
3973
  productRecord = product;
3705
3974
  splitCount = getSafeProductNum((_ref61 = (_productRecord$num = productRecord.num) !== null && _productRecord$num !== void 0 ? _productRecord$num : productRecord.product_quantity) !== null && _ref61 !== void 0 ? _ref61 : 1);
3706
3975
  if (!(splitCount > 1)) {
3707
- _context19.next = 18;
3976
+ _context23.next = 18;
3708
3977
  break;
3709
3978
  }
3710
3979
  i = 0;
3711
3980
  case 6:
3712
3981
  if (!(i < splitCount)) {
3713
- _context19.next = 15;
3982
+ _context23.next = 15;
3714
3983
  break;
3715
3984
  }
3716
3985
  singleLine = cloneDeep(productRecord);
3717
3986
  singleLine.num = 1;
3718
3987
  delete singleLine.product_quantity;
3719
- _context19.next = 12;
3988
+ _context23.next = 12;
3720
3989
  return this.appendProductLineToTempOrder(tempOrder, singleLine, cloneDeep(booking));
3721
3990
  case 12:
3722
3991
  i += 1;
3723
- _context19.next = 6;
3992
+ _context23.next = 6;
3724
3993
  break;
3725
3994
  case 15:
3726
- _context19.next = 17;
3995
+ _context23.next = 17;
3727
3996
  return this.finalizeProductOrderMutation(tempOrder);
3728
3997
  case 17:
3729
- return _context19.abrupt("return", tempOrder.products);
3998
+ return _context23.abrupt("return", tempOrder.products);
3730
3999
  case 18:
3731
- _context19.next = 20;
4000
+ _context23.next = 20;
3732
4001
  return this.appendProductLineToTempOrder(tempOrder, product, booking);
3733
4002
  case 20:
3734
- _context19.next = 22;
4003
+ _context23.next = 22;
3735
4004
  return this.finalizeProductOrderMutation(tempOrder);
3736
4005
  case 22:
3737
4006
  this.logInfo('addProductToOrder success', {
3738
4007
  product_id: product.product_id,
3739
4008
  with_booking: !!booking
3740
4009
  });
3741
- return _context19.abrupt("return", tempOrder.products);
4010
+ return _context23.abrupt("return", tempOrder.products);
3742
4011
  case 24:
3743
4012
  case "end":
3744
- return _context19.stop();
4013
+ return _context23.stop();
3745
4014
  }
3746
- }, _callee17, this);
4015
+ }, _callee21, this);
3747
4016
  }));
3748
- function addProductToOrder(_x19, _x20) {
4017
+ function addProductToOrder(_x25, _x26) {
3749
4018
  return _addProductToOrder.apply(this, arguments);
3750
4019
  }
3751
4020
  return addProductToOrder;
@@ -3763,93 +4032,93 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3763
4032
  }, {
3764
4033
  key: "addProductsToOrder",
3765
4034
  value: (function () {
3766
- var _addProductsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(items, options) {
4035
+ var _addProductsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(items, options) {
3767
4036
  var tempOrder, _iterator20, _step20, item, product, booking, _ref62, _productRecord$num2, productRecord, splitCount, i, singleLine;
3768
- return _regeneratorRuntime().wrap(function _callee18$(_context20) {
3769
- while (1) switch (_context20.prev = _context20.next) {
4037
+ return _regeneratorRuntime().wrap(function _callee22$(_context24) {
4038
+ while (1) switch (_context24.prev = _context24.next) {
3770
4039
  case 0:
3771
4040
  tempOrder = this.ensureTempOrder();
3772
4041
  if (!(!Array.isArray(items) || items.length === 0)) {
3773
- _context20.next = 3;
4042
+ _context24.next = 3;
3774
4043
  break;
3775
4044
  }
3776
- return _context20.abrupt("return", tempOrder.products);
4045
+ return _context24.abrupt("return", tempOrder.products);
3777
4046
  case 3:
3778
4047
  _iterator20 = _createForOfIteratorHelper(items || []);
3779
- _context20.prev = 4;
4048
+ _context24.prev = 4;
3780
4049
  _iterator20.s();
3781
4050
  case 6:
3782
4051
  if ((_step20 = _iterator20.n()).done) {
3783
- _context20.next = 30;
4052
+ _context24.next = 30;
3784
4053
  break;
3785
4054
  }
3786
4055
  item = _step20.value;
3787
4056
  product = item.product, booking = item.booking;
3788
4057
  if (product) {
3789
- _context20.next = 11;
4058
+ _context24.next = 11;
3790
4059
  break;
3791
4060
  }
3792
- return _context20.abrupt("continue", 28);
4061
+ return _context24.abrupt("continue", 28);
3793
4062
  case 11:
3794
4063
  if (!booking) {
3795
- _context20.next = 26;
4064
+ _context24.next = 26;
3796
4065
  break;
3797
4066
  }
3798
4067
  productRecord = product;
3799
4068
  splitCount = getSafeProductNum((_ref62 = (_productRecord$num2 = productRecord.num) !== null && _productRecord$num2 !== void 0 ? _productRecord$num2 : productRecord.product_quantity) !== null && _ref62 !== void 0 ? _ref62 : 1);
3800
4069
  if (!(splitCount > 1)) {
3801
- _context20.next = 26;
4070
+ _context24.next = 26;
3802
4071
  break;
3803
4072
  }
3804
4073
  i = 0;
3805
4074
  case 16:
3806
4075
  if (!(i < splitCount)) {
3807
- _context20.next = 25;
4076
+ _context24.next = 25;
3808
4077
  break;
3809
4078
  }
3810
4079
  singleLine = cloneDeep(productRecord);
3811
4080
  singleLine.num = 1;
3812
4081
  delete singleLine.product_quantity;
3813
- _context20.next = 22;
4082
+ _context24.next = 22;
3814
4083
  return this.appendProductLineToTempOrder(tempOrder, singleLine, cloneDeep(booking));
3815
4084
  case 22:
3816
4085
  i += 1;
3817
- _context20.next = 16;
4086
+ _context24.next = 16;
3818
4087
  break;
3819
4088
  case 25:
3820
- return _context20.abrupt("continue", 28);
4089
+ return _context24.abrupt("continue", 28);
3821
4090
  case 26:
3822
- _context20.next = 28;
4091
+ _context24.next = 28;
3823
4092
  return this.appendProductLineToTempOrder(tempOrder, product, booking);
3824
4093
  case 28:
3825
- _context20.next = 6;
4094
+ _context24.next = 6;
3826
4095
  break;
3827
4096
  case 30:
3828
- _context20.next = 35;
4097
+ _context24.next = 35;
3829
4098
  break;
3830
4099
  case 32:
3831
- _context20.prev = 32;
3832
- _context20.t0 = _context20["catch"](4);
3833
- _iterator20.e(_context20.t0);
4100
+ _context24.prev = 32;
4101
+ _context24.t0 = _context24["catch"](4);
4102
+ _iterator20.e(_context24.t0);
3834
4103
  case 35:
3835
- _context20.prev = 35;
4104
+ _context24.prev = 35;
3836
4105
  _iterator20.f();
3837
- return _context20.finish(35);
4106
+ return _context24.finish(35);
3838
4107
  case 38:
3839
- _context20.next = 40;
4108
+ _context24.next = 40;
3840
4109
  return this.finalizeProductOrderMutation(tempOrder, options);
3841
4110
  case 40:
3842
4111
  this.logInfo('addProductsToOrder success', {
3843
4112
  itemsCount: items.length
3844
4113
  });
3845
- return _context20.abrupt("return", tempOrder.products);
4114
+ return _context24.abrupt("return", tempOrder.products);
3846
4115
  case 42:
3847
4116
  case "end":
3848
- return _context20.stop();
4117
+ return _context24.stop();
3849
4118
  }
3850
- }, _callee18, this, [[4, 32, 35, 38]]);
4119
+ }, _callee22, this, [[4, 32, 35, 38]]);
3851
4120
  }));
3852
- function addProductsToOrder(_x21, _x22) {
4121
+ function addProductsToOrder(_x27, _x28) {
3853
4122
  return _addProductsToOrder.apply(this, arguments);
3854
4123
  }
3855
4124
  return addProductsToOrder;
@@ -3883,19 +4152,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3883
4152
  }, {
3884
4153
  key: "preservePersistedBundlePriceFields",
3885
4154
  value: function preservePersistedBundlePriceFields(previousBundles, nextBundles) {
3886
- var _this23 = this;
4155
+ var _this27 = this;
3887
4156
  if (!Array.isArray(nextBundles)) return nextBundles;
3888
4157
  if (!Array.isArray(previousBundles) || previousBundles.length === 0) return nextBundles;
3889
4158
  var previousByIdentity = new Map();
3890
4159
  previousBundles.forEach(function (bundle) {
3891
- var identity = _this23.getBundleRuntimeIdentity(bundle);
4160
+ var identity = _this27.getBundleRuntimeIdentity(bundle);
3892
4161
  if (identity) previousByIdentity.set(identity, bundle);
3893
4162
  });
3894
4163
  return nextBundles.map(function (bundle, index) {
3895
4164
  if (!bundle || _typeof(bundle) !== 'object') return bundle;
3896
- var previous = previousByIdentity.get(_this23.getBundleRuntimeIdentity(bundle)) || previousBundles[index];
4165
+ var previous = previousByIdentity.get(_this27.getBundleRuntimeIdentity(bundle)) || previousBundles[index];
3897
4166
  if (!previous || _typeof(previous) !== 'object') return bundle;
3898
- return _objectSpread(_objectSpread({}, bundle), {}, {
4167
+ return _objectSpread(_objectSpread(_objectSpread({}, bundle), (bundle.cover === undefined || bundle.cover === null || bundle.cover === '') && previous.cover !== undefined && previous.cover !== null && previous.cover !== '' ? {
4168
+ cover: previous.cover
4169
+ } : {}), {}, {
3899
4170
  price: previous.price,
3900
4171
  custom_price: previous.custom_price,
3901
4172
  bundle_payment_price: previous.bundle_payment_price,
@@ -3908,7 +4179,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3908
4179
  }, {
3909
4180
  key: "applyOrderProductUpdateToTempOrder",
3910
4181
  value: function applyOrderProductUpdateToTempOrder(tempOrder, params) {
3911
- var _targetProduct$metada2, _product_sku, _metadata2, _metadata3, _metadata4, _metadata5, _metadata6, _metadata7, _nextProduct$metadata, _targetProduct$metada8, _tempOrder$products$p;
4182
+ var _targetProduct$metada2, _product_sku, _metadata2, _metadata3, _metadata4, _metadata5, _metadata6, _metadata7, _metadata8, _metadata9, _metadata10, _nextProduct$metadata, _targetProduct$metada15, _tempOrder$products$p, _tempOrder$products$p2;
3912
4183
  var product_id = params.product_id,
3913
4184
  product_variant_id = params.product_variant_id,
3914
4185
  updates = params.updates,
@@ -3936,8 +4207,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3936
4207
  if (unique_identification_number !== undefined) {
3937
4208
  var targetUid = String(unique_identification_number);
3938
4209
  productIndex = tempOrder.products.findIndex(function (item) {
3939
- var _item$metadata3;
3940
- return String(((_item$metadata3 = item.metadata) === null || _item$metadata3 === void 0 ? void 0 : _item$metadata3.unique_identification_number) || item.unique_identification_number || '') === targetUid;
4210
+ var _item$metadata4;
4211
+ return String(((_item$metadata4 = item.metadata) === null || _item$metadata4 === void 0 ? void 0 : _item$metadata4.unique_identification_number) || item.unique_identification_number || '') === targetUid;
3941
4212
  });
3942
4213
  }
3943
4214
  if (productIndex === -1) {
@@ -3968,9 +4239,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3968
4239
  // 如果 caller 走推荐路径(updates.metadata.* 显式指定主价),保留 metadata 由 normalize 认它。
3969
4240
  var callerUpdatesTopPrice = Object.prototype.hasOwnProperty.call(updates || {}, 'selling_price') || Object.prototype.hasOwnProperty.call(updates || {}, 'original_price');
3970
4241
  var callerUpdatesMainMeta = (updates === null || updates === void 0 || (_metadata2 = updates.metadata) === null || _metadata2 === void 0 ? void 0 : _metadata2.main_product_selling_price) !== undefined || (updates === null || updates === void 0 || (_metadata3 = updates.metadata) === null || _metadata3 === void 0 ? void 0 : _metadata3.main_product_original_price) !== undefined || (updates === null || updates === void 0 || (_metadata4 = updates.metadata) === null || _metadata4 === void 0 ? void 0 : _metadata4.source_product_price) !== undefined;
4242
+ var callerUpdatesSourcePrice = (updates === null || updates === void 0 || (_metadata5 = updates.metadata) === null || _metadata5 === void 0 ? void 0 : _metadata5.source_product_price) !== undefined;
4243
+ var callerUpdatesMainSellingPrice = (updates === null || updates === void 0 || (_metadata6 = updates.metadata) === null || _metadata6 === void 0 ? void 0 : _metadata6.main_product_selling_price) !== undefined;
4244
+ var callerUpdatesMainOriginalPrice = (updates === null || updates === void 0 || (_metadata7 = updates.metadata) === null || _metadata7 === void 0 ? void 0 : _metadata7.main_product_original_price) !== undefined;
4245
+ var previousLineFingerprint = buildProductLineFingerprint(getProductSkuOptions(targetProduct), targetProduct.product_bundle);
4246
+ var nextLineFingerprint = buildProductLineFingerprint(getProductSkuOptions(nextProduct), nextProduct.product_bundle);
4247
+ var callerChangesVariant = Number(product_variant_id || 0) !== Number(targetProduct.product_variant_id || 0);
4248
+ var callerChangesLineConfiguration = callerChangesVariant || previousLineFingerprint !== nextLineFingerprint;
3971
4249
  var isPersistedOrderLine = targetProduct.order_detail_id !== undefined && targetProduct.order_detail_id !== null;
3972
4250
  var callerChangesDiscountList = Array.isArray(updates === null || updates === void 0 ? void 0 : updates.discount_list) && updates.discount_list.length > 0 && !isSameDiscountList(updates.discount_list, targetProduct.discount_list);
3973
- var callerUpdatesManualPrice = (updates === null || updates === void 0 || (_metadata5 = updates.metadata) === null || _metadata5 === void 0 ? void 0 : _metadata5.price_override) !== undefined || (updates === null || updates === void 0 || (_metadata6 = updates.metadata) === null || _metadata6 === void 0 ? void 0 : _metadata6.is_manual_discount) !== undefined || (updates === null || updates === void 0 || (_metadata7 = updates.metadata) === null || _metadata7 === void 0 ? void 0 : _metadata7.product_discount_reason) !== undefined || callerChangesDiscountList;
4251
+ var callerUpdatesManualPrice = (updates === null || updates === void 0 || (_metadata8 = updates.metadata) === null || _metadata8 === void 0 ? void 0 : _metadata8.price_override) !== undefined || (updates === null || updates === void 0 || (_metadata9 = updates.metadata) === null || _metadata9 === void 0 ? void 0 : _metadata9.is_manual_discount) !== undefined || (updates === null || updates === void 0 || (_metadata10 = updates.metadata) === null || _metadata10 === void 0 ? void 0 : _metadata10.product_discount_reason) !== undefined || callerChangesDiscountList;
3974
4252
  var callerAllowsBookingReprice = function () {
3975
4253
  if (params.allow_booking_reprice !== true || !booking || !callerUpdatesTopPrice || !callerUpdatesMainMeta) {
3976
4254
  return false;
@@ -3983,7 +4261,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3983
4261
  };
3984
4262
  return hasChangedPrice(updates.selling_price, targetProduct.selling_price) || hasChangedPrice(updates.original_price, targetProduct.original_price);
3985
4263
  }();
3986
- if (isPersistedOrderLine && !callerUpdatesManualPrice && !callerAllowsBookingReprice) {
4264
+ if (isPersistedOrderLine && !callerChangesLineConfiguration && !callerUpdatesManualPrice && !callerAllowsBookingReprice) {
3987
4265
  var _targetProduct$metada3, _targetProduct$metada4, _targetProduct$metada5, _targetProduct$metada6, _targetProduct$metada7;
3988
4266
  nextProduct.selling_price = targetProduct.selling_price;
3989
4267
  nextProduct.original_price = targetProduct.original_price;
@@ -3995,19 +4273,60 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3995
4273
  price_schema_version: (_targetProduct$metada6 = (_targetProduct$metada7 = targetProduct.metadata) === null || _targetProduct$metada7 === void 0 ? void 0 : _targetProduct$metada7.price_schema_version) !== null && _targetProduct$metada6 !== void 0 ? _targetProduct$metada6 : 2
3996
4274
  });
3997
4275
  nextProduct.product_bundle = this.preservePersistedBundlePriceFields(targetProduct.product_bundle, nextProduct.product_bundle);
3998
- } else if (callerUpdatesTopPrice && !callerUpdatesMainMeta) {
4276
+ } else if (callerChangesLineConfiguration && callerUpdatesSourcePrice && (!callerUpdatesMainSellingPrice || !callerUpdatesMainOriginalPrice)) {
4277
+ var _targetProduct$metada8, _targetProduct$metada9;
4278
+ // 新配置只传了 source 时,不能把未传的 main_product_* 从旧行继承下来。
4279
+ // 以新 source + 新 option 重建券前价;券后价未显式提供时保留旧主商品折扣额。
4280
+ var previousMainOriginal = new Decimal(Number((_targetProduct$metada8 = targetProduct.metadata) === null || _targetProduct$metada8 === void 0 ? void 0 : _targetProduct$metada8.main_product_original_price) || 0);
4281
+ var previousMainSelling = new Decimal(Number((_targetProduct$metada9 = targetProduct.metadata) === null || _targetProduct$metada9 === void 0 ? void 0 : _targetProduct$metada9.main_product_selling_price) || previousMainOriginal.toNumber());
4282
+ var preservedDiscount = previousMainOriginal.minus(previousMainSelling);
4283
+ var nextMainOriginal = new Decimal(Number(updates.metadata.source_product_price) || 0).plus(sumOptionUnitPrice(getProductSkuOptions(nextProduct)));
4284
+ nextProduct.metadata = _objectSpread(_objectSpread({}, nextProduct.metadata || {}), {}, {
4285
+ source_product_price: String(updates.metadata.source_product_price),
4286
+ main_product_original_price: callerUpdatesMainOriginalPrice ? String(updates.metadata.main_product_original_price) : nextMainOriginal.toDecimalPlaces(2).toFixed(2),
4287
+ main_product_selling_price: callerUpdatesMainSellingPrice ? String(updates.metadata.main_product_selling_price) : nextMainOriginal.minus(preservedDiscount).toDecimalPlaces(2).toFixed(2),
4288
+ price_schema_version: 2
4289
+ });
4290
+ } else if (callerChangesVariant && !callerUpdatesTopPrice && !callerUpdatesMainMeta) {
4291
+ // variant 已变化但 caller 没有显式报价时,旧 v2 metadata 不能继续充当权威价格源。
4292
+ // 清理后由 normalize 优先读取 metadata.origin.variant 中新 variant 的目录价;
4293
+ // 顶层 original/selling 的旧差额仍会作为 legacy discount 迁移到新价格。
3999
4294
  var existedMeta = nextProduct.metadata || {};
4000
4295
  nextProduct.metadata = _objectSpread({}, existedMeta);
4001
4296
  delete nextProduct.metadata.source_product_price;
4002
4297
  delete nextProduct.metadata.main_product_selling_price;
4003
4298
  delete nextProduct.metadata.main_product_original_price;
4004
4299
  delete nextProduct.metadata.price_schema_version;
4300
+ } else if (callerChangesLineConfiguration && !callerUpdatesTopPrice && !callerUpdatesMainMeta) {
4301
+ var _ref68, _targetProduct$metada10, _targetProduct$metada11, _ref69, _targetProduct$metada12, _targetProduct$metada13, _targetProduct$metada14;
4302
+ // 仅 option / bundle 变化时,保留历史 source 和主商品折扣金额,
4303
+ // 但必须让 original 与 selling 一起随新的 option 金额移动。
4304
+ var previousOptionSum = sumOptionUnitPrice(getProductSkuOptions(targetProduct));
4305
+ var nextOptionSum = sumOptionUnitPrice(getProductSkuOptions(nextProduct));
4306
+ var _previousMainOriginal = new Decimal(Number((_ref68 = (_targetProduct$metada10 = (_targetProduct$metada11 = targetProduct.metadata) === null || _targetProduct$metada11 === void 0 ? void 0 : _targetProduct$metada11.main_product_original_price) !== null && _targetProduct$metada10 !== void 0 ? _targetProduct$metada10 : targetProduct.original_price) !== null && _ref68 !== void 0 ? _ref68 : 0) || 0);
4307
+ var _previousMainSelling = new Decimal(Number((_ref69 = (_targetProduct$metada12 = (_targetProduct$metada13 = targetProduct.metadata) === null || _targetProduct$metada13 === void 0 ? void 0 : _targetProduct$metada13.main_product_selling_price) !== null && _targetProduct$metada12 !== void 0 ? _targetProduct$metada12 : targetProduct.selling_price) !== null && _ref69 !== void 0 ? _ref69 : _previousMainOriginal.toNumber()) || 0);
4308
+ var _preservedDiscount = _previousMainOriginal.minus(_previousMainSelling);
4309
+ var previousSource = ((_targetProduct$metada14 = targetProduct.metadata) === null || _targetProduct$metada14 === void 0 ? void 0 : _targetProduct$metada14.source_product_price) != null ? new Decimal(Number(targetProduct.metadata.source_product_price) || 0) : _previousMainOriginal.minus(previousOptionSum);
4310
+ var _nextMainOriginal = previousSource.plus(nextOptionSum);
4311
+ nextProduct.metadata = _objectSpread(_objectSpread({}, nextProduct.metadata || {}), {}, {
4312
+ source_product_price: previousSource.toDecimalPlaces(2).toFixed(2),
4313
+ main_product_original_price: _nextMainOriginal.toDecimalPlaces(2).toFixed(2),
4314
+ main_product_selling_price: _nextMainOriginal.minus(_preservedDiscount).toDecimalPlaces(2).toFixed(2),
4315
+ price_schema_version: 2
4316
+ });
4317
+ } else if (callerUpdatesTopPrice && !callerUpdatesMainMeta) {
4318
+ var _existedMeta = nextProduct.metadata || {};
4319
+ nextProduct.metadata = _objectSpread({}, _existedMeta);
4320
+ delete nextProduct.metadata.source_product_price;
4321
+ delete nextProduct.metadata.main_product_selling_price;
4322
+ delete nextProduct.metadata.main_product_original_price;
4323
+ delete nextProduct.metadata.price_schema_version;
4005
4324
  }
4006
4325
  // normalizeOrderProduct 幂等:v2 metadata 存在 → 保留 main_product_* 折扣重算 composite;
4007
4326
  // 否则 → 把顶层 selling_price 视作 source,派生 main_product_* 并写 price_schema_version: 2。
4008
4327
  var normalizedProduct = mergeOrderProductDisplayFields(nextProduct, normalizeOrderProduct(nextProduct));
4009
4328
  normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
4010
- var preservedBookingUid = nextProduct.booking_uid || ((_nextProduct$metadata = nextProduct.metadata) === null || _nextProduct$metadata === void 0 ? void 0 : _nextProduct$metadata.booking_uid) || targetProduct.booking_uid || ((_targetProduct$metada8 = targetProduct.metadata) === null || _targetProduct$metada8 === void 0 ? void 0 : _targetProduct$metada8.booking_uid);
4329
+ var preservedBookingUid = nextProduct.booking_uid || ((_nextProduct$metadata = nextProduct.metadata) === null || _nextProduct$metadata === void 0 ? void 0 : _nextProduct$metadata.booking_uid) || targetProduct.booking_uid || ((_targetProduct$metada15 = targetProduct.metadata) === null || _targetProduct$metada15 === void 0 ? void 0 : _targetProduct$metada15.booking_uid);
4011
4330
  if (!booking && preservedBookingUid) {
4012
4331
  normalizedProduct.booking_uid = preservedBookingUid;
4013
4332
  normalizedProduct.metadata = _objectSpread(_objectSpread({}, normalizedProduct.metadata || {}), {}, {
@@ -4015,8 +4334,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4015
4334
  });
4016
4335
  }
4017
4336
  if (booking) {
4018
- var _normalizedProduct$me, _targetProduct$metada9;
4019
- var productUid = String(((_normalizedProduct$me = normalizedProduct.metadata) === null || _normalizedProduct$me === void 0 ? void 0 : _normalizedProduct$me.unique_identification_number) || ((_targetProduct$metada9 = targetProduct.metadata) === null || _targetProduct$metada9 === void 0 ? void 0 : _targetProduct$metada9.unique_identification_number) || unique_identification_number || createUuidV4());
4337
+ var _normalizedProduct$me, _targetProduct$metada16;
4338
+ var productUid = String(((_normalizedProduct$me = normalizedProduct.metadata) === null || _normalizedProduct$me === void 0 ? void 0 : _normalizedProduct$me.unique_identification_number) || ((_targetProduct$metada16 = targetProduct.metadata) === null || _targetProduct$metada16 === void 0 ? void 0 : _targetProduct$metada16.unique_identification_number) || unique_identification_number || createUuidV4());
4020
4339
  normalizedProduct.metadata = _objectSpread(_objectSpread({}, normalizedProduct.metadata || {}), {}, {
4021
4340
  unique_identification_number: productUid
4022
4341
  });
@@ -4039,23 +4358,26 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4039
4358
  tempOrder.products[productIndex] = normalizedProduct;
4040
4359
  this.syncTempOrderHolderFromBookings(tempOrder);
4041
4360
  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);
4361
+ return (_tempOrder$products$p2 = tempOrder.products[productIndex].metadata) === null || _tempOrder$products$p2 === void 0 ? void 0 : _tempOrder$products$p2.unique_identification_number;
4042
4362
  }
4043
4363
  }, {
4044
4364
  key: "updateOrderProduct",
4045
4365
  value: function () {
4046
- var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(params) {
4047
- var tempOrder;
4048
- return _regeneratorRuntime().wrap(function _callee19$(_context21) {
4049
- while (1) switch (_context21.prev = _context21.next) {
4366
+ var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(params) {
4367
+ var tempOrder, updatedProductUid;
4368
+ return _regeneratorRuntime().wrap(function _callee23$(_context25) {
4369
+ while (1) switch (_context25.prev = _context25.next) {
4050
4370
  case 0:
4051
4371
  tempOrder = this.ensureTempOrder();
4052
- this.applyOrderProductUpdateToTempOrder(tempOrder, params);
4053
- _context21.next = 4;
4372
+ updatedProductUid = this.applyOrderProductUpdateToTempOrder(tempOrder, params);
4373
+ _context25.next = 4;
4054
4374
  return this.applyPromotion();
4055
4375
  case 4:
4056
- this.applyDiscount();
4376
+ this.applyDiscount({
4377
+ reapplyBookingDiscountProductUids: params.allow_booking_discount_reapply && updatedProductUid ? [String(updatedProductUid)] : undefined
4378
+ });
4057
4379
  this.sanitizeTempOrderProducts(tempOrder);
4058
- _context21.next = 8;
4380
+ _context25.next = 8;
4059
4381
  return this.recalculateSummary({
4060
4382
  createIfMissing: true
4061
4383
  });
@@ -4064,14 +4386,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4064
4386
  this.logInfo('updateOrderProduct success', {
4065
4387
  params: params
4066
4388
  });
4067
- return _context21.abrupt("return", tempOrder.products);
4389
+ return _context25.abrupt("return", tempOrder.products);
4068
4390
  case 11:
4069
4391
  case "end":
4070
- return _context21.stop();
4392
+ return _context25.stop();
4071
4393
  }
4072
- }, _callee19, this);
4394
+ }, _callee23, this);
4073
4395
  }));
4074
- function updateOrderProduct(_x23) {
4396
+ function updateOrderProduct(_x29) {
4075
4397
  return _updateOrderProduct.apply(this, arguments);
4076
4398
  }
4077
4399
  return updateOrderProduct;
@@ -4079,36 +4401,43 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4079
4401
  }, {
4080
4402
  key: "updateOrderProducts",
4081
4403
  value: function () {
4082
- var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(paramsList) {
4083
- var _this24 = this;
4084
- var tempOrder;
4085
- return _regeneratorRuntime().wrap(function _callee20$(_context22) {
4086
- while (1) switch (_context22.prev = _context22.next) {
4404
+ var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(paramsList) {
4405
+ var _this28 = this;
4406
+ var tempOrder, reapplyBookingDiscountProductUids;
4407
+ return _regeneratorRuntime().wrap(function _callee24$(_context26) {
4408
+ while (1) switch (_context26.prev = _context26.next) {
4087
4409
  case 0:
4088
4410
  tempOrder = this.ensureTempOrder();
4089
4411
  if (paramsList.length) {
4090
- _context22.next = 3;
4412
+ _context26.next = 3;
4091
4413
  break;
4092
4414
  }
4093
- return _context22.abrupt("return", tempOrder.products);
4415
+ return _context26.abrupt("return", tempOrder.products);
4094
4416
  case 3:
4095
- paramsList.forEach(function (params) {
4096
- _this24.applyOrderProductUpdateToTempOrder(tempOrder, params);
4417
+ reapplyBookingDiscountProductUids = paramsList.reduce(function (acc, params) {
4418
+ var updatedProductUid = _this28.applyOrderProductUpdateToTempOrder(tempOrder, params);
4419
+ // 批量改预约时间时,延迟到最后一次折扣计算里统一恢复已选预约折扣卡。
4420
+ if (params.allow_booking_discount_reapply && updatedProductUid) {
4421
+ acc.push(String(updatedProductUid));
4422
+ }
4423
+ return acc;
4424
+ }, []);
4425
+ _context26.next = 6;
4426
+ return this.finalizeAfterProductsMutation(tempOrder, {
4427
+ reapplyBookingDiscountProductUids: reapplyBookingDiscountProductUids.length ? reapplyBookingDiscountProductUids : undefined
4097
4428
  });
4098
- _context22.next = 6;
4099
- return this.finalizeAfterProductsMutation(tempOrder);
4100
4429
  case 6:
4101
4430
  this.logInfo('updateOrderProduct success', {
4102
4431
  paramsList: paramsList
4103
4432
  });
4104
- return _context22.abrupt("return", tempOrder.products);
4433
+ return _context26.abrupt("return", tempOrder.products);
4105
4434
  case 8:
4106
4435
  case "end":
4107
- return _context22.stop();
4436
+ return _context26.stop();
4108
4437
  }
4109
- }, _callee20, this);
4438
+ }, _callee24, this);
4110
4439
  }));
4111
- function updateOrderProducts(_x24) {
4440
+ function updateOrderProducts(_x30) {
4112
4441
  return _updateOrderProducts.apply(this, arguments);
4113
4442
  }
4114
4443
  return updateOrderProducts;
@@ -4116,11 +4445,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4116
4445
  }, {
4117
4446
  key: "updateOrderProductQuantity",
4118
4447
  value: function () {
4119
- var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(params) {
4120
- var _targetProduct$metada10;
4448
+ var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(params) {
4449
+ var _targetProduct$metada17;
4121
4450
  var product_id, product_variant_id, num, unique_identification_number, identity_key, product_sku, product_bundle, tempOrder, identityLookup, productIndex, targetUid, targetProduct, normalizedProduct;
4122
- return _regeneratorRuntime().wrap(function _callee21$(_context23) {
4123
- while (1) switch (_context23.prev = _context23.next) {
4451
+ return _regeneratorRuntime().wrap(function _callee25$(_context27) {
4452
+ while (1) switch (_context27.prev = _context27.next) {
4124
4453
  case 0:
4125
4454
  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_sku = params.product_sku, product_bundle = params.product_bundle;
4126
4455
  tempOrder = this.ensureTempOrder();
@@ -4141,15 +4470,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4141
4470
  if (unique_identification_number !== undefined) {
4142
4471
  targetUid = String(unique_identification_number);
4143
4472
  productIndex = tempOrder.products.findIndex(function (item) {
4144
- var _item$metadata4;
4145
- return String(((_item$metadata4 = item.metadata) === null || _item$metadata4 === void 0 ? void 0 : _item$metadata4.unique_identification_number) || item.unique_identification_number || '') === targetUid;
4473
+ var _item$metadata5;
4474
+ return String(((_item$metadata5 = item.metadata) === null || _item$metadata5 === void 0 ? void 0 : _item$metadata5.unique_identification_number) || item.unique_identification_number || '') === targetUid;
4146
4475
  });
4147
4476
  }
4148
4477
  if (productIndex === -1) {
4149
4478
  productIndex = getProductIdentityIndex(tempOrder.products, identityLookup);
4150
4479
  }
4151
4480
  if (!(productIndex === -1)) {
4152
- _context23.next = 12;
4481
+ _context27.next = 12;
4153
4482
  break;
4154
4483
  }
4155
4484
  throw new Error('[Order] 目标商品不存在,无法更新数量');
@@ -4158,17 +4487,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4158
4487
  normalizedProduct = normalizeOrderProduct(_objectSpread(_objectSpread({}, targetProduct), {}, {
4159
4488
  num: getSafeProductNum(num),
4160
4489
  metadata: _objectSpread(_objectSpread({}, targetProduct.metadata || {}), {}, {
4161
- unique_identification_number: ((_targetProduct$metada10 = targetProduct.metadata) === null || _targetProduct$metada10 === void 0 ? void 0 : _targetProduct$metada10.unique_identification_number) || unique_identification_number
4490
+ unique_identification_number: ((_targetProduct$metada17 = targetProduct.metadata) === null || _targetProduct$metada17 === void 0 ? void 0 : _targetProduct$metada17.unique_identification_number) || unique_identification_number
4162
4491
  })
4163
4492
  }));
4164
4493
  normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
4165
4494
  tempOrder.products[productIndex] = normalizedProduct;
4166
- _context23.next = 18;
4495
+ _context27.next = 18;
4167
4496
  return this.applyPromotion();
4168
4497
  case 18:
4169
4498
  this.applyDiscount();
4170
4499
  this.sanitizeTempOrderProducts(tempOrder);
4171
- _context23.next = 22;
4500
+ _context27.next = 22;
4172
4501
  return this.recalculateSummary({
4173
4502
  createIfMissing: true
4174
4503
  });
@@ -4177,14 +4506,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4177
4506
  this.logInfo('updateOrderProductQuantity success', {
4178
4507
  params: params
4179
4508
  });
4180
- return _context23.abrupt("return", tempOrder.products);
4509
+ return _context27.abrupt("return", tempOrder.products);
4181
4510
  case 25:
4182
4511
  case "end":
4183
- return _context23.stop();
4512
+ return _context27.stop();
4184
4513
  }
4185
- }, _callee21, this);
4514
+ }, _callee25, this);
4186
4515
  }));
4187
- function updateOrderProductQuantity(_x25) {
4516
+ function updateOrderProductQuantity(_x31) {
4188
4517
  return _updateOrderProductQuantity.apply(this, arguments);
4189
4518
  }
4190
4519
  return updateOrderProductQuantity;
@@ -4225,17 +4554,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4225
4554
  }, {
4226
4555
  key: "finalizeAfterProductsMutation",
4227
4556
  value: (function () {
4228
- var _finalizeAfterProductsMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(tempOrder) {
4229
- return _regeneratorRuntime().wrap(function _callee22$(_context24) {
4230
- while (1) switch (_context24.prev = _context24.next) {
4557
+ var _finalizeAfterProductsMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(tempOrder, options) {
4558
+ return _regeneratorRuntime().wrap(function _callee26$(_context28) {
4559
+ while (1) switch (_context28.prev = _context28.next) {
4231
4560
  case 0:
4232
4561
  this.syncTempOrderHolderFromBookings(tempOrder);
4233
- _context24.next = 3;
4562
+ _context28.next = 3;
4234
4563
  return this.applyPromotion();
4235
4564
  case 3:
4236
- this.applyDiscount();
4565
+ this.applyDiscount({
4566
+ reapplyBookingDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyBookingDiscountProductUids
4567
+ });
4237
4568
  this.sanitizeTempOrderProducts(tempOrder);
4238
- _context24.next = 7;
4569
+ _context28.next = 7;
4239
4570
  return this.recalculateSummary({
4240
4571
  createIfMissing: true
4241
4572
  });
@@ -4243,11 +4574,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4243
4574
  this.persistTempOrder();
4244
4575
  case 8:
4245
4576
  case "end":
4246
- return _context24.stop();
4577
+ return _context28.stop();
4247
4578
  }
4248
- }, _callee22, this);
4579
+ }, _callee26, this);
4249
4580
  }));
4250
- function finalizeAfterProductsMutation(_x26) {
4581
+ function finalizeAfterProductsMutation(_x32, _x33) {
4251
4582
  return _finalizeAfterProductsMutation.apply(this, arguments);
4252
4583
  }
4253
4584
  return finalizeAfterProductsMutation;
@@ -4262,18 +4593,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4262
4593
  }, {
4263
4594
  key: "removeProductsFromOrder",
4264
4595
  value: (function () {
4265
- var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(identities) {
4266
- var _this25 = this;
4596
+ var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(identities) {
4597
+ var _this29 = this;
4267
4598
  var tempOrder, productsBeforeRemove, bookingsBeforeRemove, matchedProducts, removedProducts, _i2, _removedProducts, product, linkedBookingUidsToRemove, _iterator21, _step21, _loop3;
4268
- return _regeneratorRuntime().wrap(function _callee23$(_context26) {
4269
- while (1) switch (_context26.prev = _context26.next) {
4599
+ return _regeneratorRuntime().wrap(function _callee27$(_context30) {
4600
+ while (1) switch (_context30.prev = _context30.next) {
4270
4601
  case 0:
4271
4602
  tempOrder = this.ensureTempOrder();
4272
4603
  if (identities.length) {
4273
- _context26.next = 3;
4604
+ _context30.next = 3;
4274
4605
  break;
4275
4606
  }
4276
- return _context26.abrupt("return", tempOrder.products);
4607
+ return _context30.abrupt("return", tempOrder.products);
4277
4608
  case 3:
4278
4609
  productsBeforeRemove = tempOrder.products || [];
4279
4610
  bookingsBeforeRemove = tempOrder.bookings || [];
@@ -4296,29 +4627,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4296
4627
  }
4297
4628
  linkedBookingUidsToRemove = new Set();
4298
4629
  _iterator21 = _createForOfIteratorHelper(matchedProducts);
4299
- _context26.prev = 11;
4630
+ _context30.prev = 11;
4300
4631
  _loop3 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop3() {
4301
- var _metadata8, _metadata9, _metadata10, _metadata11;
4632
+ var _metadata11, _metadata12, _metadata13, _metadata14;
4302
4633
  var product, productUid, productBookingUid, isAddTimeProduct;
4303
- return _regeneratorRuntime().wrap(function _loop3$(_context25) {
4304
- while (1) switch (_context25.prev = _context25.next) {
4634
+ return _regeneratorRuntime().wrap(function _loop3$(_context29) {
4635
+ while (1) switch (_context29.prev = _context29.next) {
4305
4636
  case 0:
4306
4637
  product = _step21.value;
4307
- productUid = (product === null || product === void 0 || (_metadata8 = product.metadata) === null || _metadata8 === void 0 ? void 0 : _metadata8.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
4308
- productBookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_metadata9 = product.metadata) === null || _metadata9 === void 0 ? void 0 : _metadata9.booking_uid);
4309
- isAddTimeProduct = (product === null || product === void 0 || (_metadata10 = product.metadata) === null || _metadata10 === void 0 ? void 0 : _metadata10.product_add_schedule_time) !== undefined && (product === null || product === void 0 || (_metadata11 = product.metadata) === null || _metadata11 === void 0 ? void 0 : _metadata11.product_add_schedule_time) !== null;
4638
+ productUid = (product === null || product === void 0 || (_metadata11 = product.metadata) === null || _metadata11 === void 0 ? void 0 : _metadata11.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
4639
+ productBookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_metadata12 = product.metadata) === null || _metadata12 === void 0 ? void 0 : _metadata12.booking_uid);
4640
+ isAddTimeProduct = (product === null || product === void 0 || (_metadata13 = product.metadata) === null || _metadata13 === void 0 ? void 0 : _metadata13.product_add_schedule_time) !== undefined && (product === null || product === void 0 || (_metadata14 = product.metadata) === null || _metadata14 === void 0 ? void 0 : _metadata14.product_add_schedule_time) !== null;
4310
4641
  if (!isAddTimeProduct) {
4311
- _context25.next = 6;
4642
+ _context29.next = 6;
4312
4643
  break;
4313
4644
  }
4314
- return _context25.abrupt("return", 1);
4645
+ return _context29.abrupt("return", 1);
4315
4646
  case 6:
4316
4647
  if (productBookingUid !== undefined && productBookingUid !== null && productBookingUid !== '') {
4317
4648
  linkedBookingUidsToRemove.add(String(productBookingUid));
4318
4649
  }
4319
4650
  if (productUid !== undefined && productUid !== null && productUid !== '') {
4320
4651
  bookingsBeforeRemove.forEach(function (booking) {
4321
- var bookingUid = _this25.getBookingUniqueIdentificationNumber(booking);
4652
+ var bookingUid = _this29.getBookingUniqueIdentificationNumber(booking);
4322
4653
  if (bookingUid && String((booking === null || booking === void 0 ? void 0 : booking.product_uid) || '') === String(productUid)) {
4323
4654
  linkedBookingUidsToRemove.add(bookingUid);
4324
4655
  }
@@ -4326,37 +4657,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4326
4657
  }
4327
4658
  case 8:
4328
4659
  case "end":
4329
- return _context25.stop();
4660
+ return _context29.stop();
4330
4661
  }
4331
4662
  }, _loop3);
4332
4663
  });
4333
4664
  _iterator21.s();
4334
4665
  case 14:
4335
4666
  if ((_step21 = _iterator21.n()).done) {
4336
- _context26.next = 20;
4667
+ _context30.next = 20;
4337
4668
  break;
4338
4669
  }
4339
- return _context26.delegateYield(_loop3(), "t0", 16);
4670
+ return _context30.delegateYield(_loop3(), "t0", 16);
4340
4671
  case 16:
4341
- if (!_context26.t0) {
4342
- _context26.next = 18;
4672
+ if (!_context30.t0) {
4673
+ _context30.next = 18;
4343
4674
  break;
4344
4675
  }
4345
- return _context26.abrupt("continue", 18);
4676
+ return _context30.abrupt("continue", 18);
4346
4677
  case 18:
4347
- _context26.next = 14;
4678
+ _context30.next = 14;
4348
4679
  break;
4349
4680
  case 20:
4350
- _context26.next = 25;
4681
+ _context30.next = 25;
4351
4682
  break;
4352
4683
  case 22:
4353
- _context26.prev = 22;
4354
- _context26.t1 = _context26["catch"](11);
4355
- _iterator21.e(_context26.t1);
4684
+ _context30.prev = 22;
4685
+ _context30.t1 = _context30["catch"](11);
4686
+ _iterator21.e(_context30.t1);
4356
4687
  case 25:
4357
- _context26.prev = 25;
4688
+ _context30.prev = 25;
4358
4689
  _iterator21.f();
4359
- return _context26.finish(25);
4690
+ return _context30.finish(25);
4360
4691
  case 28:
4361
4692
  if (linkedBookingUidsToRemove.size > 0) {
4362
4693
  // 删除主预约商品时,同步移除挂在同一 booking_uid 下的加时商品,避免残留孤儿行。
@@ -4367,20 +4698,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4367
4698
  return !(isAddTimeProduct && lineBookingUid !== undefined && lineBookingUid !== null && linkedBookingUidsToRemove.has(String(lineBookingUid)));
4368
4699
  });
4369
4700
  }
4370
- _context26.next = 31;
4701
+ _context30.next = 31;
4371
4702
  return this.finalizeAfterProductsMutation(tempOrder);
4372
4703
  case 31:
4373
4704
  this.logInfo('removeProductsFromOrder success', {
4374
4705
  identities: identities
4375
4706
  });
4376
- return _context26.abrupt("return", tempOrder.products);
4707
+ return _context30.abrupt("return", tempOrder.products);
4377
4708
  case 33:
4378
4709
  case "end":
4379
- return _context26.stop();
4710
+ return _context30.stop();
4380
4711
  }
4381
- }, _callee23, this, [[11, 22, 25, 28]]);
4712
+ }, _callee27, this, [[11, 22, 25, 28]]);
4382
4713
  }));
4383
- function removeProductsFromOrder(_x27) {
4714
+ function removeProductsFromOrder(_x34) {
4384
4715
  return _removeProductsFromOrder.apply(this, arguments);
4385
4716
  }
4386
4717
  return removeProductsFromOrder;
@@ -4388,18 +4719,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4388
4719
  }, {
4389
4720
  key: "removeProductFromOrder",
4390
4721
  value: function () {
4391
- var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(identity) {
4392
- return _regeneratorRuntime().wrap(function _callee24$(_context27) {
4393
- while (1) switch (_context27.prev = _context27.next) {
4722
+ var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(identity) {
4723
+ return _regeneratorRuntime().wrap(function _callee28$(_context31) {
4724
+ while (1) switch (_context31.prev = _context31.next) {
4394
4725
  case 0:
4395
- return _context27.abrupt("return", this.removeProductsFromOrder([identity]));
4726
+ return _context31.abrupt("return", this.removeProductsFromOrder([identity]));
4396
4727
  case 1:
4397
4728
  case "end":
4398
- return _context27.stop();
4729
+ return _context31.stop();
4399
4730
  }
4400
- }, _callee24, this);
4731
+ }, _callee28, this);
4401
4732
  }));
4402
- function removeProductFromOrder(_x28) {
4733
+ function removeProductFromOrder(_x35) {
4403
4734
  return _removeProductFromOrder.apply(this, arguments);
4404
4735
  }
4405
4736
  return removeProductFromOrder;
@@ -4411,10 +4742,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4411
4742
  }, {
4412
4743
  key: "clearOrderCartLines",
4413
4744
  value: (function () {
4414
- var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
4745
+ var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
4415
4746
  var tempOrder;
4416
- return _regeneratorRuntime().wrap(function _callee25$(_context28) {
4417
- while (1) switch (_context28.prev = _context28.next) {
4747
+ return _regeneratorRuntime().wrap(function _callee29$(_context32) {
4748
+ while (1) switch (_context32.prev = _context32.next) {
4418
4749
  case 0:
4419
4750
  tempOrder = this.ensureTempOrder();
4420
4751
  tempOrder.products = [];
@@ -4425,24 +4756,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4425
4756
  productsByUid: {}
4426
4757
  });
4427
4758
  }
4428
- _context28.next = 7;
4759
+ _context32.next = 7;
4429
4760
  return this.applyPromotion();
4430
4761
  case 7:
4431
4762
  this.applyDiscount();
4432
4763
  this.sanitizeTempOrderProducts(tempOrder);
4433
- _context28.next = 11;
4764
+ _context32.next = 11;
4434
4765
  return this.recalculateSummary({
4435
4766
  createIfMissing: true
4436
4767
  });
4437
4768
  case 11:
4438
4769
  this.persistTempOrder();
4439
4770
  this.logInfo('clearOrderCartLines success', {});
4440
- return _context28.abrupt("return", tempOrder);
4771
+ return _context32.abrupt("return", tempOrder);
4441
4772
  case 14:
4442
4773
  case "end":
4443
- return _context28.stop();
4774
+ return _context32.stop();
4444
4775
  }
4445
- }, _callee25, this);
4776
+ }, _callee29, this);
4446
4777
  }));
4447
4778
  function clearOrderCartLines() {
4448
4779
  return _clearOrderCartLines.apply(this, arguments);
@@ -4453,23 +4784,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4453
4784
  }, {
4454
4785
  key: "buildCurrentSubmitPayloadForLocalPrint",
4455
4786
  value: function buildCurrentSubmitPayloadForLocalPrint(params) {
4456
- var _params$cacheId, _this$otherParams3, _ref68, _params$businessCode, _this$otherParams4, _this$otherParams5;
4787
+ var _params$cacheId, _this$otherParams3, _ref70, _params$businessCode, _this$otherParams4, _this$otherParams5;
4457
4788
  var tempOrder = this.ensureTempOrder();
4458
4789
  this.persistTempOrder();
4459
4790
  var payload = buildSubmitPayload({
4460
4791
  tempOrder: tempOrder,
4461
4792
  cacheId: (_params$cacheId = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId !== void 0 ? _params$cacheId : this.cacheId,
4462
4793
  platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams3 = this.otherParams) === null || _this$otherParams3 === void 0 ? void 0 : _this$otherParams3.platform),
4463
- businessCode: (_ref68 = (_params$businessCode = params === null || params === void 0 ? void 0 : params.businessCode) !== null && _params$businessCode !== void 0 ? _params$businessCode : (_this$otherParams4 = this.otherParams) === null || _this$otherParams4 === void 0 ? void 0 : _this$otherParams4.businessCode) !== null && _ref68 !== void 0 ? _ref68 : (_this$otherParams5 = this.otherParams) === null || _this$otherParams5 === void 0 ? void 0 : _this$otherParams5.business_code,
4794
+ businessCode: (_ref70 = (_params$businessCode = params === null || params === void 0 ? void 0 : params.businessCode) !== null && _params$businessCode !== void 0 ? _params$businessCode : (_this$otherParams4 = this.otherParams) === null || _this$otherParams4 === void 0 ? void 0 : _this$otherParams4.businessCode) !== null && _ref70 !== void 0 ? _ref70 : (_this$otherParams5 = this.otherParams) === null || _this$otherParams5 === void 0 ? void 0 : _this$otherParams5.business_code,
4464
4795
  channel: params === null || params === void 0 ? void 0 : params.channel,
4465
4796
  type: params === null || params === void 0 ? void 0 : params.type,
4466
4797
  summary: this.store.summary || createEmptySummary(),
4467
4798
  enhance: function enhance(nextPayload) {
4468
- var _ref69, _tempOrder$order_numb, _ref70, _tempOrder$shop_order, _ref71, _tempOrder$shop_full_;
4799
+ var _ref71, _tempOrder$order_numb, _ref72, _tempOrder$shop_order, _ref73, _tempOrder$shop_full_;
4469
4800
  return _objectSpread(_objectSpread({}, nextPayload), {}, {
4470
- order_number: (_ref69 = (_tempOrder$order_numb = tempOrder.order_number) !== null && _tempOrder$order_numb !== void 0 ? _tempOrder$order_numb : nextPayload.order_number) !== null && _ref69 !== void 0 ? _ref69 : null,
4471
- shop_order_number: (_ref70 = (_tempOrder$shop_order = tempOrder.shop_order_number) !== null && _tempOrder$shop_order !== void 0 ? _tempOrder$shop_order : nextPayload.shop_order_number) !== null && _ref70 !== void 0 ? _ref70 : null,
4472
- shop_full_order_number: (_ref71 = (_tempOrder$shop_full_ = tempOrder.shop_full_order_number) !== null && _tempOrder$shop_full_ !== void 0 ? _tempOrder$shop_full_ : nextPayload.shop_full_order_number) !== null && _ref71 !== void 0 ? _ref71 : null,
4801
+ order_number: (_ref71 = (_tempOrder$order_numb = tempOrder.order_number) !== null && _tempOrder$order_numb !== void 0 ? _tempOrder$order_numb : nextPayload.order_number) !== null && _ref71 !== void 0 ? _ref71 : null,
4802
+ shop_order_number: (_ref72 = (_tempOrder$shop_order = tempOrder.shop_order_number) !== null && _tempOrder$shop_order !== void 0 ? _tempOrder$shop_order : nextPayload.shop_order_number) !== null && _ref72 !== void 0 ? _ref72 : null,
4803
+ shop_full_order_number: (_ref73 = (_tempOrder$shop_full_ = tempOrder.shop_full_order_number) !== null && _tempOrder$shop_full_ !== void 0 ? _tempOrder$shop_full_ : nextPayload.shop_full_order_number) !== null && _ref73 !== void 0 ? _ref73 : null,
4473
4804
  small_ticket_data_flag: 1
4474
4805
  });
4475
4806
  }
@@ -4480,17 +4811,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4480
4811
  }, {
4481
4812
  key: "applyLocalPrintOrderNumbers",
4482
4813
  value: function () {
4483
- var _applyLocalPrintOrderNumbers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(order) {
4814
+ var _applyLocalPrintOrderNumbers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(order) {
4484
4815
  var tempOrder, shopOrderNumber, shopFullOrderNumber;
4485
- return _regeneratorRuntime().wrap(function _callee26$(_context29) {
4486
- while (1) switch (_context29.prev = _context29.next) {
4816
+ return _regeneratorRuntime().wrap(function _callee30$(_context33) {
4817
+ while (1) switch (_context33.prev = _context33.next) {
4487
4818
  case 0:
4488
4819
  tempOrder = this.ensureTempOrder();
4489
4820
  if (!(!order || _typeof(order) !== 'object')) {
4490
- _context29.next = 3;
4821
+ _context33.next = 3;
4491
4822
  break;
4492
4823
  }
4493
- return _context29.abrupt("return", tempOrder);
4824
+ return _context33.abrupt("return", tempOrder);
4494
4825
  case 3:
4495
4826
  shopOrderNumber = order.shop_order_number;
4496
4827
  shopFullOrderNumber = order.shop_full_order_number;
@@ -4501,21 +4832,88 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4501
4832
  tempOrder.shop_full_order_number = String(shopFullOrderNumber);
4502
4833
  }
4503
4834
  this.persistTempOrder();
4504
- _context29.next = 10;
4835
+ _context33.next = 10;
4505
4836
  return this.saveDraft();
4506
4837
  case 10:
4507
- return _context29.abrupt("return", tempOrder);
4838
+ return _context33.abrupt("return", tempOrder);
4508
4839
  case 11:
4509
4840
  case "end":
4510
- return _context29.stop();
4841
+ return _context33.stop();
4511
4842
  }
4512
- }, _callee26, this);
4843
+ }, _callee30, this);
4513
4844
  }));
4514
- function applyLocalPrintOrderNumbers(_x29) {
4845
+ function applyLocalPrintOrderNumbers(_x36) {
4515
4846
  return _applyLocalPrintOrderNumbers.apply(this, arguments);
4516
4847
  }
4517
4848
  return applyLocalPrintOrderNumbers;
4518
4849
  }()
4850
+ }, {
4851
+ key: "saveTempOrderAsDraft",
4852
+ value: function () {
4853
+ var _saveTempOrderAsDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(params) {
4854
+ var _params$cacheId2, _this$otherParams6, _ref74, _params$businessCode2, _this$otherParams7, _this$otherParams8, _params$type, _this$otherParams9, _payload$products;
4855
+ var tempOrder, latestSummary, payload;
4856
+ return _regeneratorRuntime().wrap(function _callee31$(_context34) {
4857
+ while (1) switch (_context34.prev = _context34.next) {
4858
+ case 0:
4859
+ tempOrder = this.ensureTempOrder();
4860
+ this.ensureExternalSaleNumber(tempOrder);
4861
+ this.persistTempOrder();
4862
+ _context34.next = 5;
4863
+ return this.recalculateSummary({
4864
+ createIfMissing: true
4865
+ });
4866
+ case 5:
4867
+ _context34.t1 = _context34.sent;
4868
+ if (_context34.t1) {
4869
+ _context34.next = 8;
4870
+ break;
4871
+ }
4872
+ _context34.t1 = this.store.summary;
4873
+ case 8:
4874
+ _context34.t0 = _context34.t1;
4875
+ if (_context34.t0) {
4876
+ _context34.next = 11;
4877
+ break;
4878
+ }
4879
+ _context34.t0 = createEmptySummary();
4880
+ case 11:
4881
+ latestSummary = _context34.t0;
4882
+ payload = buildSubmitPayload({
4883
+ tempOrder: tempOrder,
4884
+ cacheId: (_params$cacheId2 = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId2 !== void 0 ? _params$cacheId2 : this.cacheId,
4885
+ platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6.platform),
4886
+ businessCode: (_ref74 = (_params$businessCode2 = params === null || params === void 0 ? void 0 : params.businessCode) !== null && _params$businessCode2 !== void 0 ? _params$businessCode2 : (_this$otherParams7 = this.otherParams) === null || _this$otherParams7 === void 0 ? void 0 : _this$otherParams7.businessCode) !== null && _ref74 !== void 0 ? _ref74 : (_this$otherParams8 = this.otherParams) === null || _this$otherParams8 === void 0 ? void 0 : _this$otherParams8.business_code,
4887
+ channel: params === null || params === void 0 ? void 0 : params.channel,
4888
+ type: (_params$type = params === null || params === void 0 ? void 0 : params.type) !== null && _params$type !== void 0 ? _params$type : (_this$otherParams9 = this.otherParams) === null || _this$otherParams9 === void 0 ? void 0 : _this$otherParams9.type,
4889
+ summary: latestSummary,
4890
+ enhance: params === null || params === void 0 ? void 0 : params.enhancePayload
4891
+ });
4892
+ if (!payload.created_at) {
4893
+ payload.created_at = dayjs().format('YYYY-MM-DD HH:mm:ss');
4894
+ }
4895
+ payload.need_sync = 0;
4896
+ payload.is_draft_order = 1;
4897
+ this.logInfo('saveTempOrderAsDraft calling sales draft', {
4898
+ orderId: payload.order_id,
4899
+ externalSaleNumber: payload.external_sale_number,
4900
+ productsCount: ((_payload$products = payload.products) === null || _payload$products === void 0 ? void 0 : _payload$products.length) || 0
4901
+ });
4902
+ return _context34.abrupt("return", this.request.post('/order/sales/draft', payload, {
4903
+ osServer: true,
4904
+ customToast: function customToast() {}
4905
+ }));
4906
+ case 18:
4907
+ case "end":
4908
+ return _context34.stop();
4909
+ }
4910
+ }, _callee31, this);
4911
+ }));
4912
+ function saveTempOrderAsDraft(_x37) {
4913
+ return _saveTempOrderAsDraft.apply(this, arguments);
4914
+ }
4915
+ return saveTempOrderAsDraft;
4916
+ }()
4519
4917
  /**
4520
4918
  * 提交当前 Sales tempOrder。
4521
4919
  *
@@ -4525,18 +4923,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4525
4923
  }, {
4526
4924
  key: "submitTempOrder",
4527
4925
  value: (function () {
4528
- var _submitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(params) {
4529
- return _regeneratorRuntime().wrap(function _callee27$(_context30) {
4530
- while (1) switch (_context30.prev = _context30.next) {
4926
+ var _submitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(params) {
4927
+ return _regeneratorRuntime().wrap(function _callee32$(_context35) {
4928
+ while (1) switch (_context35.prev = _context35.next) {
4531
4929
  case 0:
4532
- return _context30.abrupt("return", this.runSubmitTempOrder(params));
4930
+ return _context35.abrupt("return", this.runSubmitTempOrder(params));
4533
4931
  case 1:
4534
4932
  case "end":
4535
- return _context30.stop();
4933
+ return _context35.stop();
4536
4934
  }
4537
- }, _callee27, this);
4935
+ }, _callee32, this);
4538
4936
  }));
4539
- function submitTempOrder(_x30) {
4937
+ function submitTempOrder(_x38) {
4540
4938
  return _submitTempOrder.apply(this, arguments);
4541
4939
  }
4542
4940
  return submitTempOrder;
@@ -4544,20 +4942,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4544
4942
  }, {
4545
4943
  key: "submitTempOrderAsync",
4546
4944
  value: function () {
4547
- var _submitTempOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(params) {
4548
- return _regeneratorRuntime().wrap(function _callee28$(_context31) {
4549
- while (1) switch (_context31.prev = _context31.next) {
4945
+ var _submitTempOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(params) {
4946
+ return _regeneratorRuntime().wrap(function _callee33$(_context36) {
4947
+ while (1) switch (_context36.prev = _context36.next) {
4550
4948
  case 0:
4551
- return _context31.abrupt("return", this.runSubmitTempOrder(_objectSpread(_objectSpread({}, params), {}, {
4949
+ return _context36.abrupt("return", this.runSubmitTempOrder(_objectSpread(_objectSpread({}, params), {}, {
4552
4950
  syncMode: true
4553
4951
  })));
4554
4952
  case 1:
4555
4953
  case "end":
4556
- return _context31.stop();
4954
+ return _context36.stop();
4557
4955
  }
4558
- }, _callee28, this);
4956
+ }, _callee33, this);
4559
4957
  }));
4560
- function submitTempOrderAsync(_x31) {
4958
+ function submitTempOrderAsync(_x39) {
4561
4959
  return _submitTempOrderAsync.apply(this, arguments);
4562
4960
  }
4563
4961
  return submitTempOrderAsync;
@@ -4565,11 +4963,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4565
4963
  }, {
4566
4964
  key: "runSubmitTempOrder",
4567
4965
  value: function () {
4568
- var _runSubmitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(params) {
4569
- var _params$cacheId2, _this$otherParams6, _ref72, _ref73, _submitSnapshot$busin, _this$otherParams7, _this$otherParams8, _submitSnapshot$type;
4966
+ var _runSubmitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(params) {
4967
+ var _params$cacheId3, _this$otherParams10, _ref75, _ref76, _submitSnapshot$busin, _this$otherParams11, _this$otherParams12, _submitSnapshot$type;
4570
4968
  var tempOrder, shouldConfirmPendingVoucherPayments, hasPaymentOverride, preparedPaymentOverride, latestSummary, effectiveCacheId, hasPaymentStatusOverride, hasSmallTicketDataFlagOverride, enhancePayload, submitSnapshot, payload, result, _payload$payments, _payload$payments2, backendErrorResponse, submittedOrderId, resultRecord;
4571
- return _regeneratorRuntime().wrap(function _callee29$(_context32) {
4572
- while (1) switch (_context32.prev = _context32.next) {
4969
+ return _regeneratorRuntime().wrap(function _callee34$(_context37) {
4970
+ while (1) switch (_context37.prev = _context37.next) {
4573
4971
  case 0:
4574
4972
  tempOrder = this.ensureTempOrder();
4575
4973
  shouldConfirmPendingVoucherPayments = (params === null || params === void 0 ? void 0 : params.confirmPendingVoucherPayments) !== false;
@@ -4589,27 +4987,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4589
4987
  }
4590
4988
  }
4591
4989
  this.persistTempOrder();
4592
- _context32.next = 8;
4990
+ _context37.next = 8;
4593
4991
  return this.recalculateSummary({
4594
4992
  createIfMissing: true
4595
4993
  });
4596
4994
  case 8:
4597
- _context32.t1 = _context32.sent;
4598
- if (_context32.t1) {
4599
- _context32.next = 11;
4995
+ _context37.t1 = _context37.sent;
4996
+ if (_context37.t1) {
4997
+ _context37.next = 11;
4600
4998
  break;
4601
4999
  }
4602
- _context32.t1 = this.store.summary;
5000
+ _context37.t1 = this.store.summary;
4603
5001
  case 11:
4604
- _context32.t0 = _context32.t1;
4605
- if (_context32.t0) {
4606
- _context32.next = 14;
5002
+ _context37.t0 = _context37.t1;
5003
+ if (_context37.t0) {
5004
+ _context37.next = 14;
4607
5005
  break;
4608
5006
  }
4609
- _context32.t0 = createEmptySummary();
5007
+ _context37.t0 = createEmptySummary();
4610
5008
  case 14:
4611
- latestSummary = _context32.t0;
4612
- effectiveCacheId = (_params$cacheId2 = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId2 !== void 0 ? _params$cacheId2 : this.cacheId;
5009
+ latestSummary = _context37.t0;
5010
+ effectiveCacheId = (_params$cacheId3 = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId3 !== void 0 ? _params$cacheId3 : this.cacheId;
4613
5011
  hasPaymentStatusOverride = (params === null || params === void 0 ? void 0 : params.paymentStatus) !== undefined;
4614
5012
  hasSmallTicketDataFlagOverride = (params === null || params === void 0 ? void 0 : params.smallTicketDataFlag) !== undefined;
4615
5013
  enhancePayload = hasPaymentOverride || hasPaymentStatusOverride || hasSmallTicketDataFlagOverride || params !== null && params !== void 0 && params.enhancePayload ? function (payload, ctx) {
@@ -4627,8 +5025,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4627
5025
  payload = buildSubmitPayload({
4628
5026
  tempOrder: tempOrder,
4629
5027
  cacheId: effectiveCacheId,
4630
- platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6.platform),
4631
- businessCode: (_ref72 = (_ref73 = (_submitSnapshot$busin = submitSnapshot.businessCode) !== null && _submitSnapshot$busin !== void 0 ? _submitSnapshot$busin : params === null || params === void 0 ? void 0 : params.businessCode) !== null && _ref73 !== void 0 ? _ref73 : (_this$otherParams7 = this.otherParams) === null || _this$otherParams7 === void 0 ? void 0 : _this$otherParams7.businessCode) !== null && _ref72 !== void 0 ? _ref72 : (_this$otherParams8 = this.otherParams) === null || _this$otherParams8 === void 0 ? void 0 : _this$otherParams8.business_code,
5028
+ platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams10 = this.otherParams) === null || _this$otherParams10 === void 0 ? void 0 : _this$otherParams10.platform),
5029
+ businessCode: (_ref75 = (_ref76 = (_submitSnapshot$busin = submitSnapshot.businessCode) !== null && _submitSnapshot$busin !== void 0 ? _submitSnapshot$busin : params === null || params === void 0 ? void 0 : params.businessCode) !== null && _ref76 !== void 0 ? _ref76 : (_this$otherParams11 = this.otherParams) === null || _this$otherParams11 === void 0 ? void 0 : _this$otherParams11.businessCode) !== null && _ref75 !== void 0 ? _ref75 : (_this$otherParams12 = this.otherParams) === null || _this$otherParams12 === void 0 ? void 0 : _this$otherParams12.business_code,
4632
5030
  channel: params === null || params === void 0 ? void 0 : params.channel,
4633
5031
  type: (_submitSnapshot$type = submitSnapshot.type) !== null && _submitSnapshot$type !== void 0 ? _submitSnapshot$type : params === null || params === void 0 ? void 0 : params.type,
4634
5032
  summary: latestSummary,
@@ -4643,10 +5041,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4643
5041
  if (!payload.created_at) {
4644
5042
  payload.created_at = dayjs().format('YYYY-MM-DD HH:mm:ss');
4645
5043
  }
4646
- _context32.next = 26;
5044
+ _context37.next = 26;
4647
5045
  return this.saveDraft();
4648
5046
  case 26:
4649
- _context32.prev = 26;
5047
+ _context37.prev = 26;
4650
5048
  this.logInfo('submitTempOrder calling sales checkout', {
4651
5049
  orderId: payload.order_id,
4652
5050
  externalSaleNumber: payload.external_sale_number,
@@ -4656,43 +5054,43 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4656
5054
  smallTicketDataFlag: payload.small_ticket_data_flag,
4657
5055
  syncMode: payload.sync_mode
4658
5056
  });
4659
- _context32.next = 30;
5057
+ _context37.next = 30;
4660
5058
  return this.submitSalesOrder({
4661
5059
  query: payload
4662
5060
  });
4663
5061
  case 30:
4664
- result = _context32.sent;
4665
- _context32.next = 43;
5062
+ result = _context37.sent;
5063
+ _context37.next = 43;
4666
5064
  break;
4667
5065
  case 33:
4668
- _context32.prev = 33;
4669
- _context32.t2 = _context32["catch"](26);
4670
- backendErrorResponse = this.extractSubmitErrorResponse(_context32.t2);
5066
+ _context37.prev = 33;
5067
+ _context37.t2 = _context37["catch"](26);
5068
+ backendErrorResponse = this.extractSubmitErrorResponse(_context37.t2);
4671
5069
  if (!backendErrorResponse) {
4672
- _context32.next = 40;
5070
+ _context37.next = 40;
4673
5071
  break;
4674
5072
  }
4675
5073
  this.store.syncState = 'failed';
4676
5074
  this.logSubmitBackendRejected(backendErrorResponse, payload);
4677
- return _context32.abrupt("return", backendErrorResponse);
5075
+ return _context37.abrupt("return", backendErrorResponse);
4678
5076
  case 40:
4679
5077
  this.store.syncState = 'failed';
4680
5078
  this.logError('submitTempOrder failed', {
4681
- error: _context32.t2 instanceof Error ? _context32.t2.message : String(_context32.t2),
5079
+ error: _context37.t2 instanceof Error ? _context37.t2.message : String(_context37.t2),
4682
5080
  orderId: payload.order_id,
4683
5081
  externalSaleNumber: payload.external_sale_number,
4684
5082
  paymentStatus: payload.payment_status,
4685
5083
  paymentsCount: ((_payload$payments2 = payload.payments) === null || _payload$payments2 === void 0 ? void 0 : _payload$payments2.length) || 0
4686
5084
  });
4687
- throw _context32.t2;
5085
+ throw _context37.t2;
4688
5086
  case 43:
4689
5087
  if (!this.isSubmitResponseRejected(result)) {
4690
- _context32.next = 47;
5088
+ _context37.next = 47;
4691
5089
  break;
4692
5090
  }
4693
5091
  this.store.syncState = 'failed';
4694
5092
  this.logSubmitBackendRejected(result, payload);
4695
- return _context32.abrupt("return", result);
5093
+ return _context37.abrupt("return", result);
4696
5094
  case 47:
4697
5095
  submittedOrderId = this.extractOrderIdFromSubmitResult(result);
4698
5096
  this.logInfo('runSubmitTempOrder: 提交成功', {
@@ -4703,15 +5101,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4703
5101
  })
4704
5102
  });
4705
5103
  if (!(submittedOrderId !== null && submittedOrderId !== undefined)) {
4706
- _context32.next = 56;
5104
+ _context37.next = 56;
4707
5105
  break;
4708
5106
  }
4709
5107
  tempOrder.order_id = submittedOrderId;
4710
5108
  resultRecord = result;
4711
- _context32.next = 54;
5109
+ _context37.next = 54;
4712
5110
  return this.markLocalOrderSynced(submittedOrderId, (resultRecord === null || resultRecord === void 0 ? void 0 : resultRecord.data) || resultRecord || {});
4713
5111
  case 54:
4714
- _context32.next = 57;
5112
+ _context37.next = 57;
4715
5113
  break;
4716
5114
  case 56:
4717
5115
  if (this.isLocalPendingSubmitResult(result)) {
@@ -4720,14 +5118,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4720
5118
  this.store.syncState = 'submitted';
4721
5119
  }
4722
5120
  case 57:
4723
- return _context32.abrupt("return", result);
5121
+ return _context37.abrupt("return", result);
4724
5122
  case 58:
4725
5123
  case "end":
4726
- return _context32.stop();
5124
+ return _context37.stop();
4727
5125
  }
4728
- }, _callee29, this, [[26, 33]]);
5126
+ }, _callee34, this, [[26, 33]]);
4729
5127
  }));
4730
- function runSubmitTempOrder(_x32) {
5128
+ function runSubmitTempOrder(_x40) {
4731
5129
  return _runSubmitTempOrder.apply(this, arguments);
4732
5130
  }
4733
5131
  return runSubmitTempOrder;
@@ -4735,10 +5133,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4735
5133
  }, {
4736
5134
  key: "markLocalOrderSynced",
4737
5135
  value: function () {
4738
- var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(orderId, remoteOrder) {
5136
+ var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(orderId, remoteOrder) {
4739
5137
  var tempOrder;
4740
- return _regeneratorRuntime().wrap(function _callee30$(_context33) {
4741
- while (1) switch (_context33.prev = _context33.next) {
5138
+ return _regeneratorRuntime().wrap(function _callee35$(_context38) {
5139
+ while (1) switch (_context38.prev = _context38.next) {
4742
5140
  case 0:
4743
5141
  tempOrder = this.ensureTempOrder();
4744
5142
  tempOrder.order_id = orderId;
@@ -4746,15 +5144,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4746
5144
  this.store.lastOrderInfo = remoteOrder;
4747
5145
  this.store.syncState = 'submitted';
4748
5146
  this.persistTempOrder();
4749
- _context33.next = 8;
5147
+ _context38.next = 8;
4750
5148
  return this.saveDraft();
4751
5149
  case 8:
4752
5150
  case "end":
4753
- return _context33.stop();
5151
+ return _context38.stop();
4754
5152
  }
4755
- }, _callee30, this);
5153
+ }, _callee35, this);
4756
5154
  }));
4757
- function markLocalOrderSynced(_x33, _x34) {
5155
+ function markLocalOrderSynced(_x41, _x42) {
4758
5156
  return _markLocalOrderSynced.apply(this, arguments);
4759
5157
  }
4760
5158
  return markLocalOrderSynced;
@@ -4797,10 +5195,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4797
5195
  value: function extractSubmitErrorResponse(error) {
4798
5196
  var _error$response,
4799
5197
  _error$response2,
4800
- _this26 = this;
5198
+ _this30 = this;
4801
5199
  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];
4802
5200
  return candidates.find(function (candidate) {
4803
- return _this26.isSubmitErrorResponse(candidate);
5201
+ return _this30.isSubmitErrorResponse(candidate);
4804
5202
  }) || null;
4805
5203
  }
4806
5204
  }, {
@@ -4827,40 +5225,63 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4827
5225
  }, {
4828
5226
  key: "syncPaymentsToOrder",
4829
5227
  value: function () {
4830
- var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(params) {
4831
- var _params$confirmPendin;
4832
- var tempOrder, mappedPayments, shouldConfirmPendingVoucherPayments, effectivePayments, completion, paidPaymentTotal, paymentStatus, paymentSyncIdempotencyToken, submitResult;
4833
- return _regeneratorRuntime().wrap(function _callee31$(_context34) {
4834
- while (1) switch (_context34.prev = _context34.next) {
5228
+ var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(params) {
5229
+ var _this31 = this,
5230
+ _params$confirmPendin;
5231
+ var tempOrder, needsPaymentNumber, devicePrefix, mappedPayments, shouldConfirmPendingVoucherPayments, effectivePayments, completion, orderPaidPaymentTotal, paymentStatus, paymentSyncIdempotencyToken, submitResult;
5232
+ return _regeneratorRuntime().wrap(function _callee36$(_context39) {
5233
+ while (1) switch (_context39.prev = _context39.next) {
4835
5234
  case 0:
4836
5235
  tempOrder = this.ensureTempOrder();
4837
- mappedPayments = mapPaymentItemsToOrderPayments(params.payments || []);
5236
+ needsPaymentNumber = (params.payments || []).some(function (payment) {
5237
+ return String(payment.payment_number || '').trim() === '';
5238
+ });
5239
+ if (!needsPaymentNumber) {
5240
+ _context39.next = 8;
5241
+ break;
5242
+ }
5243
+ _context39.next = 5;
5244
+ return this.getPaymentNumberDevicePrefixAsync();
5245
+ case 5:
5246
+ _context39.t0 = _context39.sent;
5247
+ _context39.next = 9;
5248
+ break;
5249
+ case 8:
5250
+ _context39.t0 = 'LOCAL';
5251
+ case 9:
5252
+ devicePrefix = _context39.t0;
5253
+ mappedPayments = mapPaymentItemsToOrderPayments((params.payments || []).map(function (payment) {
5254
+ return _this31.normalizePaymentSource(payment, {
5255
+ defaultPaid: false,
5256
+ devicePrefix: devicePrefix
5257
+ });
5258
+ }));
4838
5259
  shouldConfirmPendingVoucherPayments = (_params$confirmPendin = params.confirmPendingVoucherPayments) !== null && _params$confirmPendin !== void 0 ? _params$confirmPendin : params.submitWhenPaid === true;
4839
5260
  effectivePayments = shouldConfirmPendingVoucherPayments ? this.confirmPendingVoucherPaymentsInList(mappedPayments) : params.confirmPendingVoucherPayments === false ? this.discardPendingVoucherPaymentsFromList(mappedPayments) : mappedPayments;
4840
5261
  completion = this.getPaymentCompletion(effectivePayments);
4841
- paidPaymentTotal = this.calculatePaymentTotal(effectivePayments);
4842
- paymentStatus = completion.isOrderFullyPaid ? params.paymentStatus || 'paid' : paidPaymentTotal.gt(0) ? 'partially_paid' : 'payment_processing';
5262
+ orderPaidPaymentTotal = this.calculateOrderPaidPaymentTotal(effectivePayments);
5263
+ paymentStatus = completion.isOrderFullyPaid ? params.paymentStatus || 'paid' : orderPaidPaymentTotal.gt(0) ? 'partially_paid' : 'payment_processing';
4843
5264
  tempOrder.payments = effectivePayments;
4844
5265
  tempOrder.payment_status = paymentStatus;
4845
5266
  this.persistTempOrder();
4846
- _context34.next = 12;
5267
+ _context39.next = 21;
4847
5268
  return this.saveDraft();
4848
- case 12:
5269
+ case 21:
4849
5270
  if (params.submitWhenPaid) {
4850
- _context34.next = 14;
5271
+ _context39.next = 23;
4851
5272
  break;
4852
5273
  }
4853
- return _context34.abrupt("return", completion);
4854
- case 14:
5274
+ return _context39.abrupt("return", completion);
5275
+ case 23:
4855
5276
  if (!(this.store.syncState === 'submitting')) {
4856
- _context34.next = 16;
5277
+ _context39.next = 25;
4857
5278
  break;
4858
5279
  }
4859
- return _context34.abrupt("return", completion);
4860
- case 16:
5280
+ return _context39.abrupt("return", completion);
5281
+ case 25:
4861
5282
  this.store.syncState = 'submitting';
4862
5283
  paymentSyncIdempotencyToken = this.buildPaymentSyncIdempotencyToken(tempOrder, effectivePayments);
4863
- _context34.next = 20;
5284
+ _context39.next = 29;
4864
5285
  return this.submitTempOrder({
4865
5286
  payments: effectivePayments,
4866
5287
  paymentStatus: paymentStatus,
@@ -4875,18 +5296,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4875
5296
  return nextPayload;
4876
5297
  }
4877
5298
  });
4878
- case 20:
4879
- submitResult = _context34.sent;
4880
- return _context34.abrupt("return", _objectSpread(_objectSpread({}, completion), {}, {
5299
+ case 29:
5300
+ submitResult = _context39.sent;
5301
+ return _context39.abrupt("return", _objectSpread(_objectSpread({}, completion), {}, {
4881
5302
  submitResult: submitResult
4882
5303
  }));
4883
- case 22:
5304
+ case 31:
4884
5305
  case "end":
4885
- return _context34.stop();
5306
+ return _context39.stop();
4886
5307
  }
4887
- }, _callee31, this);
5308
+ }, _callee36, this);
4888
5309
  }));
4889
- function syncPaymentsToOrder(_x35) {
5310
+ function syncPaymentsToOrder(_x43) {
4890
5311
  return _syncPaymentsToOrder.apply(this, arguments);
4891
5312
  }
4892
5313
  return syncPaymentsToOrder;
@@ -4975,11 +5396,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4975
5396
  }, {
4976
5397
  key: "submitOrder",
4977
5398
  value: function () {
4978
- var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(order) {
5399
+ var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(order) {
4979
5400
  var _order$query$cartItem, _params$bookings, _params$relation_prod;
4980
5401
  var url, query, fetchUrl, params;
4981
- return _regeneratorRuntime().wrap(function _callee32$(_context35) {
4982
- while (1) switch (_context35.prev = _context35.next) {
5402
+ return _regeneratorRuntime().wrap(function _callee37$(_context40) {
5403
+ while (1) switch (_context40.prev = _context40.next) {
4983
5404
  case 0:
4984
5405
  this.logInfo('submitOrder called', {
4985
5406
  url: order.url,
@@ -4999,14 +5420,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4999
5420
  relationProductsCount: ((_params$relation_prod = params.relation_products) === null || _params$relation_prod === void 0 ? void 0 : _params$relation_prod.length) || 0,
5000
5421
  scheduleDate: params.schedule_date
5001
5422
  });
5002
- return _context35.abrupt("return", this.request.post(fetchUrl, params));
5423
+ return _context40.abrupt("return", this.request.post(fetchUrl, params));
5003
5424
  case 6:
5004
5425
  case "end":
5005
- return _context35.stop();
5426
+ return _context40.stop();
5006
5427
  }
5007
- }, _callee32, this);
5428
+ }, _callee37, this);
5008
5429
  }));
5009
- function submitOrder(_x36) {
5430
+ function submitOrder(_x44) {
5010
5431
  return _submitOrder.apply(this, arguments);
5011
5432
  }
5012
5433
  return submitOrder;
@@ -5014,13 +5435,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5014
5435
  }, {
5015
5436
  key: "cancelOrder",
5016
5437
  value: function () {
5017
- var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(params) {
5438
+ var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(params) {
5018
5439
  var payload;
5019
- return _regeneratorRuntime().wrap(function _callee33$(_context36) {
5020
- while (1) switch (_context36.prev = _context36.next) {
5440
+ return _regeneratorRuntime().wrap(function _callee38$(_context41) {
5441
+ while (1) switch (_context41.prev = _context41.next) {
5021
5442
  case 0:
5022
5443
  if (!(!Array.isArray(params.order_ids) || params.order_ids.length === 0)) {
5023
- _context36.next = 2;
5444
+ _context41.next = 2;
5024
5445
  break;
5025
5446
  }
5026
5447
  throw new Error('取消订单失败:order_ids 不能为空');
@@ -5036,16 +5457,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5036
5457
  method: 'PUT',
5037
5458
  orderIdsCount: params.order_ids.length
5038
5459
  });
5039
- return _context36.abrupt("return", this.request.put('/order/update-status', payload, {
5460
+ return _context41.abrupt("return", this.request.put('/order/update-status', payload, {
5040
5461
  isShopApi: true
5041
5462
  }));
5042
5463
  case 5:
5043
5464
  case "end":
5044
- return _context36.stop();
5465
+ return _context41.stop();
5045
5466
  }
5046
- }, _callee33, this);
5467
+ }, _callee38, this);
5047
5468
  }));
5048
- function cancelOrder(_x37) {
5469
+ function cancelOrder(_x45) {
5049
5470
  return _cancelOrder.apply(this, arguments);
5050
5471
  }
5051
5472
  return cancelOrder;
@@ -5053,19 +5474,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5053
5474
  }, {
5054
5475
  key: "changeBookingStatus",
5055
5476
  value: function () {
5056
- var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(params) {
5477
+ var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(params) {
5057
5478
  var url, payload;
5058
- return _regeneratorRuntime().wrap(function _callee34$(_context37) {
5059
- while (1) switch (_context37.prev = _context37.next) {
5479
+ return _regeneratorRuntime().wrap(function _callee39$(_context42) {
5480
+ while (1) switch (_context42.prev = _context42.next) {
5060
5481
  case 0:
5061
5482
  if (params.booking_id) {
5062
- _context37.next = 2;
5483
+ _context42.next = 2;
5063
5484
  break;
5064
5485
  }
5065
5486
  throw new Error('变更预约状态失败:booking_id 不能为空');
5066
5487
  case 2:
5067
5488
  if (params.appointment_status) {
5068
- _context37.next = 4;
5489
+ _context42.next = 4;
5069
5490
  break;
5070
5491
  }
5071
5492
  throw new Error('变更预约状态失败:appointment_status 不能为空');
@@ -5080,16 +5501,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5080
5501
  bookingId: params.booking_id,
5081
5502
  appointmentStatus: params.appointment_status
5082
5503
  });
5083
- return _context37.abrupt("return", this.request.put(url, payload, {
5504
+ return _context42.abrupt("return", this.request.put(url, payload, {
5084
5505
  isShopApi: true
5085
5506
  }));
5086
5507
  case 8:
5087
5508
  case "end":
5088
- return _context37.stop();
5509
+ return _context42.stop();
5089
5510
  }
5090
- }, _callee34, this);
5511
+ }, _callee39, this);
5091
5512
  }));
5092
- function changeBookingStatus(_x38) {
5513
+ function changeBookingStatus(_x46) {
5093
5514
  return _changeBookingStatus.apply(this, arguments);
5094
5515
  }
5095
5516
  return changeBookingStatus;
@@ -5107,11 +5528,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5107
5528
  }, {
5108
5529
  key: "createOrderByCheckout",
5109
5530
  value: (function () {
5110
- var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(params) {
5531
+ var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(params) {
5111
5532
  var _params$payments, _params$bookings2, _params$relation_prod2, _params$payments2, _params$payments3, _params$bookings3, _params$relation_prod3, _params$payments4;
5112
5533
  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;
5113
- return _regeneratorRuntime().wrap(function _callee35$(_context38) {
5114
- while (1) switch (_context38.prev = _context38.next) {
5534
+ return _regeneratorRuntime().wrap(function _callee40$(_context43) {
5535
+ while (1) switch (_context43.prev = _context43.next) {
5115
5536
  case 0:
5116
5537
  // 过滤掉由在线店铺下单的 payment 支付数据
5117
5538
  onlineStorePaymentCodeList = ['WXPAY', 'WECHAT', 'ALIPAY', 'APPLE_PAY', 'CREDIT_CARD_3DS', 'CREDIT_CARD_TOKEN', 'GOOGLE_PAY', 'GOOGLE_PAY_3DS', 'CREDIT_CARD'];
@@ -5145,7 +5566,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5145
5566
  relationProductsCount: ((_params$relation_prod3 = params.relation_products) === null || _params$relation_prod3 === void 0 ? void 0 : _params$relation_prod3.length) || 0,
5146
5567
  paymentsCount: ((_params$payments4 = params.payments) === null || _params$payments4 === void 0 ? void 0 : _params$payments4.length) || 0
5147
5568
  });
5148
- _context38.prev = 4;
5569
+ _context43.prev = 4;
5149
5570
  // 构建订单数据,设置默认值并允许 params 覆盖
5150
5571
  orderData = _objectSpread({
5151
5572
  sales_channel: 'my_pisel',
@@ -5207,13 +5628,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5207
5628
  hasOrderId: !!orderData.order_id,
5208
5629
  smallTicketDataFlag: orderData.small_ticket_data_flag
5209
5630
  });
5210
- _context38.next = 12;
5631
+ _context43.next = 12;
5211
5632
  return this.request.post('/order/checkout', orderData, {
5212
5633
  osServer: true,
5213
5634
  customToast: function customToast() {}
5214
5635
  });
5215
5636
  case 12:
5216
- response = _context38.sent;
5637
+ response = _context43.sent;
5217
5638
  this.logInfo('Order API called successfully', {
5218
5639
  response: response
5219
5640
  });
@@ -5221,22 +5642,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5221
5642
  success: !!response,
5222
5643
  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)
5223
5644
  });
5224
- return _context38.abrupt("return", response);
5645
+ return _context43.abrupt("return", response);
5225
5646
  case 18:
5226
- _context38.prev = 18;
5227
- _context38.t0 = _context38["catch"](4);
5228
- console.error('[Order] createOrderByCheckout 创建订单失败:', _context38.t0);
5647
+ _context43.prev = 18;
5648
+ _context43.t0 = _context43["catch"](4);
5649
+ console.error('[Order] createOrderByCheckout 创建订单失败:', _context43.t0);
5229
5650
  this.logInfo('Order API called failed', {
5230
- error: _context38.t0 instanceof Error ? _context38.t0.message : String(_context38.t0)
5651
+ error: _context43.t0 instanceof Error ? _context43.t0.message : String(_context43.t0)
5231
5652
  });
5232
- throw _context38.t0;
5653
+ throw _context43.t0;
5233
5654
  case 23:
5234
5655
  case "end":
5235
- return _context38.stop();
5656
+ return _context43.stop();
5236
5657
  }
5237
- }, _callee35, this, [[4, 18]]);
5658
+ }, _callee40, this, [[4, 18]]);
5238
5659
  }));
5239
- function createOrderByCheckout(_x39) {
5660
+ function createOrderByCheckout(_x47) {
5240
5661
  return _createOrderByCheckout.apply(this, arguments);
5241
5662
  }
5242
5663
  return createOrderByCheckout;
@@ -5244,24 +5665,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5244
5665
  }, {
5245
5666
  key: "submitSalesOrder",
5246
5667
  value: function () {
5247
- var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(params) {
5668
+ var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(params) {
5248
5669
  var url, query, fetchUrl;
5249
- return _regeneratorRuntime().wrap(function _callee36$(_context39) {
5250
- while (1) switch (_context39.prev = _context39.next) {
5670
+ return _regeneratorRuntime().wrap(function _callee41$(_context44) {
5671
+ while (1) switch (_context44.prev = _context44.next) {
5251
5672
  case 0:
5252
5673
  url = params.url, query = params.query;
5253
5674
  fetchUrl = url || '/order/sales/checkout';
5254
- return _context39.abrupt("return", this.request.post(fetchUrl, query, {
5675
+ return _context44.abrupt("return", this.request.post(fetchUrl, query, {
5255
5676
  osServer: true,
5256
5677
  customToast: function customToast() {}
5257
5678
  }));
5258
5679
  case 3:
5259
5680
  case "end":
5260
- return _context39.stop();
5681
+ return _context44.stop();
5261
5682
  }
5262
- }, _callee36, this);
5683
+ }, _callee41, this);
5263
5684
  }));
5264
- function submitSalesOrder(_x40) {
5685
+ function submitSalesOrder(_x48) {
5265
5686
  return _submitSalesOrder.apply(this, arguments);
5266
5687
  }
5267
5688
  return submitSalesOrder;
@@ -5275,37 +5696,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5275
5696
  }, {
5276
5697
  key: "sendCustomerPayLink",
5277
5698
  value: (function () {
5278
- var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(params) {
5699
+ var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42(params) {
5279
5700
  var _params$emails;
5280
5701
  var orderIds;
5281
- return _regeneratorRuntime().wrap(function _callee37$(_context40) {
5282
- while (1) switch (_context40.prev = _context40.next) {
5702
+ return _regeneratorRuntime().wrap(function _callee42$(_context45) {
5703
+ while (1) switch (_context45.prev = _context45.next) {
5283
5704
  case 0:
5284
5705
  orderIds = params.order_ids || params.orderIds || [];
5285
5706
  if (orderIds.length) {
5286
- _context40.next = 3;
5707
+ _context45.next = 3;
5287
5708
  break;
5288
5709
  }
5289
5710
  throw new Error('发送支付链接前必须先提交本地订单并取得订单 ID');
5290
5711
  case 3:
5291
5712
  if ((_params$emails = params.emails) !== null && _params$emails !== void 0 && _params$emails.length) {
5292
- _context40.next = 5;
5713
+ _context45.next = 5;
5293
5714
  break;
5294
5715
  }
5295
5716
  throw new Error('发送支付链接需要至少一个邮箱');
5296
5717
  case 5:
5297
- return _context40.abrupt("return", this.request.post('/order/batch-email', {
5718
+ return _context45.abrupt("return", this.request.post('/order/batch-email', {
5298
5719
  order_ids: orderIds,
5299
5720
  notify_action: params.notify_action || 'order_payment_reminder',
5300
5721
  emails: params.emails
5301
5722
  }));
5302
5723
  case 6:
5303
5724
  case "end":
5304
- return _context40.stop();
5725
+ return _context45.stop();
5305
5726
  }
5306
- }, _callee37, this);
5727
+ }, _callee42, this);
5307
5728
  }));
5308
- function sendCustomerPayLink(_x41) {
5729
+ function sendCustomerPayLink(_x49) {
5309
5730
  return _sendCustomerPayLink.apply(this, arguments);
5310
5731
  }
5311
5732
  return sendCustomerPayLink;
@@ -5313,14 +5734,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5313
5734
  }, {
5314
5735
  key: "getSalesOrderByLookup",
5315
5736
  value: function () {
5316
- var _getSalesOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(params) {
5737
+ var _getSalesOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43(params) {
5317
5738
  var lookup, res;
5318
- return _regeneratorRuntime().wrap(function _callee38$(_context41) {
5319
- while (1) switch (_context41.prev = _context41.next) {
5739
+ return _regeneratorRuntime().wrap(function _callee43$(_context46) {
5740
+ while (1) switch (_context46.prev = _context46.next) {
5320
5741
  case 0:
5321
5742
  lookup = params.lookup === undefined || params.lookup === null ? '' : String(params.lookup).trim();
5322
5743
  if (lookup) {
5323
- _context41.next = 3;
5744
+ _context46.next = 3;
5324
5745
  break;
5325
5746
  }
5326
5747
  throw new Error('加载销售详情需要 lookup');
@@ -5329,7 +5750,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5329
5750
  if (lookup.startsWith('LOCAL_')) {
5330
5751
  params.forceRemote = false;
5331
5752
  }
5332
- _context41.next = 6;
5753
+ _context46.next = 6;
5333
5754
  return this.request.get("/order/sales/".concat(encodeURIComponent(lookup)), _objectSpread({
5334
5755
  with: ['products', 'bookings', 'payments', 'customer', 'summary', 'contacts_info']
5335
5756
  }, params.forceRemote ? {
@@ -5338,18 +5759,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5338
5759
  osServer: true
5339
5760
  });
5340
5761
  case 6:
5341
- res = _context41.sent;
5762
+ res = _context46.sent;
5342
5763
  if (res.code === 200) {
5343
5764
  this.store.lastOrderInfo = res.data;
5344
5765
  }
5345
- return _context41.abrupt("return", res);
5766
+ return _context46.abrupt("return", res);
5346
5767
  case 9:
5347
5768
  case "end":
5348
- return _context41.stop();
5769
+ return _context46.stop();
5349
5770
  }
5350
- }, _callee38, this);
5771
+ }, _callee43, this);
5351
5772
  }));
5352
- function getSalesOrderByLookup(_x42) {
5773
+ function getSalesOrderByLookup(_x50) {
5353
5774
  return _getSalesOrderByLookup.apply(this, arguments);
5354
5775
  }
5355
5776
  return getSalesOrderByLookup;
@@ -5363,14 +5784,42 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5363
5784
  }, {
5364
5785
  key: "hydrateTempOrderFromRecord",
5365
5786
  value: (function () {
5366
- var _hydrateTempOrderFromRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(record, options) {
5367
- var _this$store$discount15;
5368
- var raw, nextTempOrder, rawSummary, summarySurcharges, hydratedEditDiscounts, currentDiscounts, shouldSkipEmptyDiscountSync, _this$store$discount16, _this$store$discount17;
5369
- return _regeneratorRuntime().wrap(function _callee39$(_context42) {
5370
- while (1) switch (_context42.prev = _context42.next) {
5787
+ var _hydrateTempOrderFromRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee44(record, options) {
5788
+ var _this$store$discount19;
5789
+ var sourceRaw, identityReadySource, normalizedCollections, raw, hasIdentityChanges, identityLogMetadata, hasIdentityWarnings, nextTempOrder, sourceLastOrderInfo, isDraftOrder, syntheticIdentityOptions, rawSummary, summarySurcharges, hadSyntheticDraftOrderId, hydratedEditDiscounts, currentDiscounts, currentScanDiscounts, hydratedDiscountIds, retainedScanDiscounts, nextDiscounts, shouldSkipEmptyDiscountSync, _this$store$discount20, _this$store$discount21;
5790
+ return _regeneratorRuntime().wrap(function _callee44$(_context47) {
5791
+ while (1) switch (_context47.prev = _context47.next) {
5371
5792
  case 0:
5372
- raw = record && _typeof(record) === 'object' && record.data && record.order_id == null ? record.data : record || {};
5373
- nextTempOrder = this.normalizeTempOrderForRuntime(raw);
5793
+ sourceRaw = record && _typeof(record) === 'object' && record.data && record.order_id == null ? record.data : record || {};
5794
+ identityReadySource = this.seedAnonymousBookingUidsFromProducts(sourceRaw);
5795
+ normalizedCollections = normalizeOrderCollections(identityReadySource);
5796
+ raw = normalizedCollections.order;
5797
+ hasIdentityChanges = Object.values(normalizedCollections.stats).some(function (stats) {
5798
+ return stats.backfilledUidCount > 0 || stats.collapsedDuplicateCount > 0 || stats.uidConflictCount > 0 || stats.anonymousRowCount > 0;
5799
+ });
5800
+ if (hasIdentityChanges) {
5801
+ identityLogMetadata = {
5802
+ collections: normalizedCollections.stats,
5803
+ uidRemapCount: normalizedCollections.uidRemaps.length
5804
+ };
5805
+ hasIdentityWarnings = Object.values(normalizedCollections.stats).some(function (stats) {
5806
+ return stats.uidConflictCount > 0 || stats.anonymousRowCount > 0;
5807
+ });
5808
+ if (hasIdentityWarnings) {
5809
+ this.logWarning('Normalized hydrated order collection identities', identityLogMetadata);
5810
+ } else {
5811
+ this.logInfo('Normalized hydrated order collection identities', identityLogMetadata);
5812
+ }
5813
+ }
5814
+ nextTempOrder = this.normalizeTempOrderForRuntime(raw, {
5815
+ makeEditMark: true
5816
+ }); // Server list compatibility may synthesize order_id from external_sale_number; tempOrder must not.
5817
+ sourceLastOrderInfo = raw.lastOrderInfo || raw;
5818
+ isDraftOrder = Number(nextTempOrder.is_draft_order || 0) === 1;
5819
+ syntheticIdentityOptions = {
5820
+ isDraftOrder: isDraftOrder,
5821
+ externalSaleNumber: nextTempOrder.external_sale_number
5822
+ };
5374
5823
  rawSummary = raw.summary && _typeof(raw.summary) === 'object' ? raw.summary : {};
5375
5824
  summarySurcharges = Array.isArray(rawSummary.surcharges) ? rawSummary.surcharges.map(function (s) {
5376
5825
  return _objectSpread({}, s || {});
@@ -5383,45 +5832,60 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5383
5832
  originalSalesSnapshot: {
5384
5833
  summary: cloneDeep(this.store.summary),
5385
5834
  products: cloneDeep(nextTempOrder.products || []),
5835
+ bookings: cloneDeep(nextTempOrder.bookings || []),
5386
5836
  payments: cloneDeep(nextTempOrder.payments || []),
5387
5837
  surcharges: cloneDeep(nextTempOrder.surcharges || []),
5388
5838
  shop_discount: nextTempOrder.shop_discount || '0.00',
5389
5839
  productFingerprint: this.buildOrderProductsFingerprint(nextTempOrder.products || [])
5390
5840
  }
5391
5841
  });
5392
- this.store.lastOrderInfo = raw.lastOrderInfo || raw;
5842
+ this.store.lastOrderInfo = this.withoutSyntheticDraftOrderIdForRuntime(sourceLastOrderInfo, syntheticIdentityOptions);
5843
+ hadSyntheticDraftOrderId = this.isSyntheticDraftOrderIdForRuntime(raw, syntheticIdentityOptions) || this.isSyntheticDraftOrderIdForRuntime(sourceLastOrderInfo, syntheticIdentityOptions);
5844
+ if (hadSyntheticDraftOrderId && this.store.syncState !== 'submitting') {
5845
+ this.store.syncState = 'local';
5846
+ }
5393
5847
  hydratedEditDiscounts = this.collectHydratedEditDiscounts(nextTempOrder.products);
5394
- currentDiscounts = typeof ((_this$store$discount15 = this.store.discount) === null || _this$store$discount15 === void 0 ? void 0 : _this$store$discount15.getDiscountList) === 'function' ? this.store.discount.getDiscountList() || [] : [];
5395
- shouldSkipEmptyDiscountSync = hydratedEditDiscounts.length === 0 && currentDiscounts.length === 0;
5848
+ currentDiscounts = typeof ((_this$store$discount19 = this.store.discount) === null || _this$store$discount19 === void 0 ? void 0 : _this$store$discount19.getDiscountList) === 'function' ? this.store.discount.getDiscountList() || [] : [];
5849
+ currentScanDiscounts = currentDiscounts.filter(function (discount) {
5850
+ return discount === null || discount === void 0 ? void 0 : discount.isScan;
5851
+ });
5852
+ hydratedDiscountIds = new Set(hydratedEditDiscounts.map(function (discount) {
5853
+ return discount === null || discount === void 0 ? void 0 : discount.id;
5854
+ }));
5855
+ retainedScanDiscounts = currentScanDiscounts.filter(function (discount) {
5856
+ return !hydratedDiscountIds.has(discount === null || discount === void 0 ? void 0 : discount.id);
5857
+ });
5858
+ nextDiscounts = [].concat(_toConsumableArray(hydratedEditDiscounts), _toConsumableArray(retainedScanDiscounts));
5859
+ shouldSkipEmptyDiscountSync = nextDiscounts.length === 0 && currentDiscounts.length === 0;
5396
5860
  if (shouldSkipEmptyDiscountSync) {
5397
- _context42.next = 17;
5861
+ _context47.next = 31;
5398
5862
  break;
5399
5863
  }
5400
- OrderModule.populateSavedAmounts(nextTempOrder.products, hydratedEditDiscounts);
5401
- _context42.next = 15;
5402
- return (_this$store$discount16 = this.store.discount) === null || _this$store$discount16 === void 0 ? void 0 : _this$store$discount16.setOriginalDiscountList(hydratedEditDiscounts);
5403
- case 15:
5404
- _context42.next = 17;
5405
- return (_this$store$discount17 = this.store.discount) === null || _this$store$discount17 === void 0 ? void 0 : _this$store$discount17.setDiscountList(hydratedEditDiscounts);
5406
- case 17:
5864
+ OrderModule.populateSavedAmounts(nextTempOrder.products, nextDiscounts);
5865
+ _context47.next = 29;
5866
+ return (_this$store$discount20 = this.store.discount) === null || _this$store$discount20 === void 0 ? void 0 : _this$store$discount20.setOriginalDiscountList(nextDiscounts);
5867
+ case 29:
5868
+ _context47.next = 31;
5869
+ return (_this$store$discount21 = this.store.discount) === null || _this$store$discount21 === void 0 ? void 0 : _this$store$discount21.setDiscountList(nextDiscounts);
5870
+ case 31:
5407
5871
  if (!(options !== null && options !== void 0 && options.recalcOnHydrate)) {
5408
- _context42.next = 20;
5872
+ _context47.next = 34;
5409
5873
  break;
5410
5874
  }
5411
- _context42.next = 20;
5875
+ _context47.next = 34;
5412
5876
  return this.recalculateSummary({
5413
5877
  createIfMissing: false
5414
5878
  });
5415
- case 20:
5879
+ case 34:
5416
5880
  this.persistTempOrder();
5417
- return _context42.abrupt("return", nextTempOrder);
5418
- case 22:
5881
+ return _context47.abrupt("return", nextTempOrder);
5882
+ case 36:
5419
5883
  case "end":
5420
- return _context42.stop();
5884
+ return _context47.stop();
5421
5885
  }
5422
- }, _callee39, this);
5886
+ }, _callee44, this);
5423
5887
  }));
5424
- function hydrateTempOrderFromRecord(_x43, _x44) {
5888
+ function hydrateTempOrderFromRecord(_x51, _x52) {
5425
5889
  return _hydrateTempOrderFromRecord.apply(this, arguments);
5426
5890
  }
5427
5891
  return hydrateTempOrderFromRecord;
@@ -5459,14 +5923,88 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5459
5923
  }
5460
5924
  return next;
5461
5925
  }
5926
+
5927
+ /**
5928
+ * 匿名 booking 没有服务端行 ID 时,商品侧已有的 booking_uid 就是唯一可用的强引用。
5929
+ * 在统一规范化生成 UUID 前先复用它;已落库 booking 仍按 schedule_event_id 派生稳定 UID。
5930
+ */
5931
+ }, {
5932
+ key: "seedAnonymousBookingUidsFromProducts",
5933
+ value: function seedAnonymousBookingUidsFromProducts(raw) {
5934
+ if (!raw || _typeof(raw) !== 'object') return {};
5935
+ if (!Array.isArray(raw.bookings) || !Array.isArray(raw.products)) return raw;
5936
+ var bookingUidsByProductUid = new Map();
5937
+ var _iterator22 = _createForOfIteratorHelper(raw.products),
5938
+ _step22;
5939
+ try {
5940
+ for (_iterator22.s(); !(_step22 = _iterator22.n()).done;) {
5941
+ var _product$metadata10;
5942
+ var product = _step22.value;
5943
+ var productUid = getOrderCollectionUid('product', product);
5944
+ var bookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_product$metadata10 = product.metadata) === null || _product$metadata10 === void 0 ? void 0 : _product$metadata10.booking_uid);
5945
+ if (!productUid || bookingUid === undefined || bookingUid === null || bookingUid === '') {
5946
+ continue;
5947
+ }
5948
+ var candidates = bookingUidsByProductUid.get(productUid) || new Set();
5949
+ candidates.add(String(bookingUid));
5950
+ bookingUidsByProductUid.set(productUid, candidates);
5951
+ }
5952
+ } catch (err) {
5953
+ _iterator22.e(err);
5954
+ } finally {
5955
+ _iterator22.f();
5956
+ }
5957
+ if (bookingUidsByProductUid.size === 0) return raw;
5958
+ var anonymousBookingCountByProductUid = new Map();
5959
+ var _iterator23 = _createForOfIteratorHelper(raw.bookings),
5960
+ _step23;
5961
+ try {
5962
+ for (_iterator23.s(); !(_step23 = _iterator23.n()).done;) {
5963
+ var _booking$metadata7;
5964
+ var booking = _step23.value;
5965
+ if (getOrderCollectionPersistentId('booking', booking) || getOrderCollectionUid('booking', booking)) {
5966
+ continue;
5967
+ }
5968
+ var _productUid = (booking === null || booking === void 0 ? void 0 : booking.product_uid) || (booking === null || booking === void 0 || (_booking$metadata7 = booking.metadata) === null || _booking$metadata7 === void 0 ? void 0 : _booking$metadata7.product_uid);
5969
+ if (_productUid === undefined || _productUid === null || _productUid === '') continue;
5970
+ var key = String(_productUid);
5971
+ anonymousBookingCountByProductUid.set(key, (anonymousBookingCountByProductUid.get(key) || 0) + 1);
5972
+ }
5973
+ } catch (err) {
5974
+ _iterator23.e(err);
5975
+ } finally {
5976
+ _iterator23.f();
5977
+ }
5978
+ return _objectSpread(_objectSpread({}, raw), {}, {
5979
+ bookings: raw.bookings.map(function (booking) {
5980
+ var _booking$metadata6;
5981
+ if (getOrderCollectionPersistentId('booking', booking) || getOrderCollectionUid('booking', booking)) {
5982
+ return booking;
5983
+ }
5984
+ var productUid = (booking === null || booking === void 0 ? void 0 : booking.product_uid) || (booking === null || booking === void 0 || (_booking$metadata6 = booking.metadata) === null || _booking$metadata6 === void 0 ? void 0 : _booking$metadata6.product_uid);
5985
+ if (productUid === undefined || productUid === null || productUid === '') {
5986
+ return booking;
5987
+ }
5988
+ var productUidKey = String(productUid);
5989
+ // 多条匿名 booking 共用同一商品引用时身份仍然不明确,不能借商品字段猜测合并。
5990
+ if (anonymousBookingCountByProductUid.get(productUidKey) !== 1) {
5991
+ return booking;
5992
+ }
5993
+ var bookingUidCandidates = bookingUidsByProductUid.get(productUidKey);
5994
+ var bookingUid = (bookingUidCandidates === null || bookingUidCandidates === void 0 ? void 0 : bookingUidCandidates.size) === 1 ? _toConsumableArray(bookingUidCandidates)[0] : null;
5995
+ return bookingUid ? setOrderCollectionUid('booking', booking, bookingUid) : booking;
5996
+ })
5997
+ });
5998
+ }
5462
5999
  }, {
5463
6000
  key: "normalizeTempOrderForRuntime",
5464
6001
  value: function normalizeTempOrderForRuntime(raw, options) {
5465
- var _this27 = this;
5466
- var nextTempOrder = _objectSpread(_objectSpread({}, this.createDefaultTempOrderInstance()), raw || {});
6002
+ var _this32 = this;
6003
+ var runtimeRaw = this.withoutSyntheticDraftOrderIdForRuntime(raw);
6004
+ var nextTempOrder = _objectSpread(_objectSpread({}, this.createDefaultTempOrderInstance()), runtimeRaw || {});
5467
6005
  // ES 列表详情使用 id 表示订单主键;OS 详情态统一依赖 order_id 驱动操作按钮。
5468
- if ((nextTempOrder.order_id === undefined || nextTempOrder.order_id === null) && (raw === null || raw === void 0 ? void 0 : raw.id) !== undefined && (raw === null || raw === void 0 ? void 0 : raw.id) !== null) {
5469
- nextTempOrder.order_id = raw.id;
6006
+ if ((nextTempOrder.order_id === undefined || nextTempOrder.order_id === null) && (runtimeRaw === null || runtimeRaw === void 0 ? void 0 : runtimeRaw.id) !== undefined && (runtimeRaw === null || runtimeRaw === void 0 ? void 0 : runtimeRaw.id) !== null) {
6007
+ nextTempOrder.order_id = runtimeRaw.id;
5470
6008
  }
5471
6009
  delete nextTempOrder.summary;
5472
6010
  delete nextTempOrder.lastOrderInfo;
@@ -5485,10 +6023,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5485
6023
  nextTempOrder.holder = raw.holder && _typeof(raw.holder) === 'object' ? _objectSpread({}, raw.holder) : null;
5486
6024
  var rawProducts = Array.isArray(raw.products) ? raw.products : [];
5487
6025
  nextTempOrder.products = rawProducts.length > 0 ? rawProducts.map(function (p) {
5488
- return _this27.normalizeHydratedOrderProduct(p);
6026
+ return _this32.normalizeHydratedOrderProduct(p, {
6027
+ makeEditMark: options === null || options === void 0 ? void 0 : options.makeEditMark
6028
+ });
5489
6029
  }) : [];
5490
6030
  nextTempOrder.bookings = Array.isArray(raw.bookings) ? raw.bookings.map(function (b) {
5491
- var booking = _this27.normalizeHydratedBookingHolder(b || {});
6031
+ var booking = _this32.normalizeHydratedBookingHolder(b || {});
5492
6032
  return _objectSpread(_objectSpread({}, booking), {}, {
5493
6033
  is_all: normalizeBookingIsAll(booking),
5494
6034
  sub_type: normalizeBookingSubType(booking)
@@ -5514,19 +6054,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5514
6054
  };
5515
6055
  var tempOrderExtend = nextTempOrder._extend;
5516
6056
  var productsByUid = tempOrderExtend.productsByUid || {};
5517
- var _iterator22 = _createForOfIteratorHelper(nextTempOrder.products.entries()),
5518
- _step22;
6057
+ var _iterator24 = _createForOfIteratorHelper(nextTempOrder.products.entries()),
6058
+ _step24;
5519
6059
  try {
5520
- for (_iterator22.s(); !(_step22 = _iterator22.n()).done;) {
5521
- var _product$metadata10, _ref74, _ref75, _existed$origin, _rawProduct$metadata;
5522
- var _step22$value = _slicedToArray(_step22.value, 2),
5523
- index = _step22$value[0],
5524
- product = _step22$value[1];
5525
- var uid = (_product$metadata10 = product.metadata) === null || _product$metadata10 === void 0 ? void 0 : _product$metadata10.unique_identification_number;
6060
+ for (_iterator24.s(); !(_step24 = _iterator24.n()).done;) {
6061
+ var _product$metadata11, _ref77, _ref78, _existed$origin, _rawProduct$metadata;
6062
+ var _step24$value = _slicedToArray(_step24.value, 2),
6063
+ index = _step24$value[0],
6064
+ product = _step24$value[1];
6065
+ var uid = (_product$metadata11 = product.metadata) === null || _product$metadata11 === void 0 ? void 0 : _product$metadata11.unique_identification_number;
5526
6066
  if (!uid) continue;
5527
6067
  var existed = productsByUid[uid] && _typeof(productsByUid[uid]) === 'object' ? productsByUid[uid] : {};
5528
6068
  var rawProduct = rawProducts[index] && _typeof(rawProducts[index]) === 'object' ? rawProducts[index] : product;
5529
- var origin = (_ref74 = (_ref75 = (_existed$origin = existed.origin) !== null && _existed$origin !== void 0 ? _existed$origin : rawProduct._origin) !== null && _ref75 !== void 0 ? _ref75 : (_rawProduct$metadata = rawProduct.metadata) === null || _rawProduct$metadata === void 0 ? void 0 : _rawProduct$metadata.origin) !== null && _ref74 !== void 0 ? _ref74 : rawProduct;
6069
+ var origin = (_ref77 = (_ref78 = (_existed$origin = existed.origin) !== null && _existed$origin !== void 0 ? _existed$origin : rawProduct._origin) !== null && _ref78 !== void 0 ? _ref78 : (_rawProduct$metadata = rawProduct.metadata) === null || _rawProduct$metadata === void 0 ? void 0 : _rawProduct$metadata.origin) !== null && _ref77 !== void 0 ? _ref77 : rawProduct;
5530
6070
  var originSnapshot = cloneDeep(origin);
5531
6071
  var productOptionString = this.buildHydratedProductOptionString(rawProduct) || this.buildHydratedProductOptionString(product);
5532
6072
  if (productOptionString && originSnapshot && _typeof(originSnapshot) === 'object') {
@@ -5542,9 +6082,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5542
6082
  });
5543
6083
  }
5544
6084
  } catch (err) {
5545
- _iterator22.e(err);
6085
+ _iterator24.e(err);
5546
6086
  } finally {
5547
- _iterator22.f();
6087
+ _iterator24.f();
5548
6088
  }
5549
6089
  tempOrderExtend.productsByUid = productsByUid;
5550
6090
  this.hydrateLinkedBookingIdentity(nextTempOrder);
@@ -5554,14 +6094,31 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5554
6094
  nextTempOrder.vouchers = raw.vouchers || [];
5555
6095
  return nextTempOrder;
5556
6096
  }
6097
+ }, {
6098
+ key: "isSyntheticDraftOrderIdForRuntime",
6099
+ value: function isSyntheticDraftOrderIdForRuntime(record, options) {
6100
+ var _options$isDraftOrder, _record$external_sale;
6101
+ var isDraftOrder = (_options$isDraftOrder = options === null || options === void 0 ? void 0 : options.isDraftOrder) !== null && _options$isDraftOrder !== void 0 ? _options$isDraftOrder : Number((record === null || record === void 0 ? void 0 : record.is_draft_order) || 0) === 1;
6102
+ var externalSaleNumber = (_record$external_sale = record === null || record === void 0 ? void 0 : record.external_sale_number) !== null && _record$external_sale !== void 0 ? _record$external_sale : options === null || options === void 0 ? void 0 : options.externalSaleNumber;
6103
+ var orderId = record === null || record === void 0 ? void 0 : record.order_id;
6104
+ return Boolean(isDraftOrder && orderId !== undefined && orderId !== null && orderId !== '' && externalSaleNumber !== undefined && externalSaleNumber !== null && externalSaleNumber !== '' && String(orderId) === String(externalSaleNumber));
6105
+ }
6106
+ }, {
6107
+ key: "withoutSyntheticDraftOrderIdForRuntime",
6108
+ value: function withoutSyntheticDraftOrderIdForRuntime(record, options) {
6109
+ if (!this.isSyntheticDraftOrderIdForRuntime(record, options)) return record;
6110
+ return _objectSpread(_objectSpread({}, record), {}, {
6111
+ order_id: null
6112
+ });
6113
+ }
5557
6114
  }, {
5558
6115
  key: "hydrateLinkedBookingIdentity",
5559
6116
  value: function hydrateLinkedBookingIdentity(tempOrder) {
5560
6117
  var bookingUidByProductUid = new Map();
5561
6118
  var productByUid = new Map();
5562
6119
  (tempOrder.products || []).forEach(function (product) {
5563
- var _product$metadata11;
5564
- var productUid = (product === null || product === void 0 || (_product$metadata11 = product.metadata) === null || _product$metadata11 === void 0 ? void 0 : _product$metadata11.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
6120
+ var _product$metadata12;
6121
+ var productUid = (product === null || product === void 0 || (_product$metadata12 = product.metadata) === null || _product$metadata12 === void 0 ? void 0 : _product$metadata12.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
5565
6122
  if (productUid !== undefined && productUid !== null && String(productUid) !== '') {
5566
6123
  productByUid.set(String(productUid), product);
5567
6124
  }
@@ -5582,15 +6139,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5582
6139
  bookingUidByProductUid.set(String(productUid), bookingUid);
5583
6140
  });
5584
6141
  (tempOrder.products || []).forEach(function (product) {
5585
- var _product$metadata12;
5586
- var productUid = (product === null || product === void 0 || (_product$metadata12 = product.metadata) === null || _product$metadata12 === void 0 ? void 0 : _product$metadata12.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
6142
+ var _product$metadata13;
6143
+ var productUid = (product === null || product === void 0 || (_product$metadata13 = product.metadata) === null || _product$metadata13 === void 0 ? void 0 : _product$metadata13.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
5587
6144
  if (productUid === undefined || productUid === null || String(productUid) === '') return;
5588
6145
  var bookingUid = bookingUidByProductUid.get(String(productUid));
5589
6146
  if (!bookingUid) return;
5590
6147
  if (!product.metadata || _typeof(product.metadata) !== 'object') {
5591
6148
  product.metadata = {};
5592
6149
  }
5593
- var linkedBookingUid = String(product.booking_uid || product.metadata.booking_uid || bookingUid);
6150
+ // booking 已经过统一身份规范化;以它为准同步商品侧旧引用,避免两侧 UID 断链。
6151
+ var linkedBookingUid = String(bookingUid);
5594
6152
  product.booking_uid = linkedBookingUid;
5595
6153
  product.metadata.booking_uid = linkedBookingUid;
5596
6154
  });
@@ -5618,18 +6176,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5618
6176
  var segments = [];
5619
6177
  var sku = (product === null || product === void 0 ? void 0 : product.product_sku) || {};
5620
6178
  if (Array.isArray(sku.variant)) {
5621
- var _iterator23 = _createForOfIteratorHelper(sku.variant),
5622
- _step23;
6179
+ var _iterator25 = _createForOfIteratorHelper(sku.variant),
6180
+ _step25;
5623
6181
  try {
5624
- for (_iterator23.s(); !(_step23 = _iterator23.n()).done;) {
5625
- var variant = _step23.value;
6182
+ for (_iterator25.s(); !(_step25 = _iterator25.n()).done;) {
6183
+ var variant = _step25.value;
5626
6184
  var segment = this.formatHydratedNamePair(variant === null || variant === void 0 ? void 0 : variant.group, variant === null || variant === void 0 ? void 0 : variant.item);
5627
6185
  if (segment) segments.push(segment);
5628
6186
  }
5629
6187
  } catch (err) {
5630
- _iterator23.e(err);
6188
+ _iterator25.e(err);
5631
6189
  } finally {
5632
- _iterator23.f();
6190
+ _iterator25.f();
5633
6191
  }
5634
6192
  }
5635
6193
  return segments.join(', ');
@@ -5637,10 +6195,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5637
6195
  }, {
5638
6196
  key: "normalizeHydratedProductOptionItem",
5639
6197
  value: function normalizeHydratedProductOptionItem(optionItem) {
5640
- var _ref76, _optionItem$num, _ref77, _optionItem$add_price;
5641
- var rawNum = (_ref76 = (_optionItem$num = optionItem === null || optionItem === void 0 ? void 0 : optionItem.num) !== null && _optionItem$num !== void 0 ? _optionItem$num : optionItem === null || optionItem === void 0 ? void 0 : optionItem.quantity) !== null && _ref76 !== void 0 ? _ref76 : 1;
6198
+ var _ref79, _optionItem$num, _ref80, _optionItem$add_price;
6199
+ var rawNum = (_ref79 = (_optionItem$num = optionItem === null || optionItem === void 0 ? void 0 : optionItem.num) !== null && _optionItem$num !== void 0 ? _optionItem$num : optionItem === null || optionItem === void 0 ? void 0 : optionItem.quantity) !== null && _ref79 !== void 0 ? _ref79 : 1;
5642
6200
  var parsedNum = Number(rawNum);
5643
- var rawPrice = (_ref77 = (_optionItem$add_price = optionItem === null || optionItem === void 0 ? void 0 : optionItem.add_price) !== null && _optionItem$add_price !== void 0 ? _optionItem$add_price : optionItem === null || optionItem === void 0 ? void 0 : optionItem.price) !== null && _ref77 !== void 0 ? _ref77 : 0;
6201
+ var rawPrice = (_ref80 = (_optionItem$add_price = optionItem === null || optionItem === void 0 ? void 0 : optionItem.add_price) !== null && _optionItem$add_price !== void 0 ? _optionItem$add_price : optionItem === null || optionItem === void 0 ? void 0 : optionItem.price) !== null && _ref80 !== void 0 ? _ref80 : 0;
5644
6202
  var parsedPrice = Number(rawPrice);
5645
6203
  var normalized = _objectSpread(_objectSpread({}, optionItem), {}, {
5646
6204
  option_group_item_id: optionItem === null || optionItem === void 0 ? void 0 : optionItem.option_group_item_id,
@@ -5656,8 +6214,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5656
6214
  }
5657
6215
  }, {
5658
6216
  key: "normalizeHydratedOrderProduct",
5659
- value: function normalizeHydratedOrderProduct(product) {
5660
- var _this28 = this;
6217
+ value: function normalizeHydratedOrderProduct(product, options) {
6218
+ var _this33 = this;
5661
6219
  var row = _objectSpread({}, product || {});
5662
6220
  if (row.num === undefined && row.product_quantity !== undefined) {
5663
6221
  row.num = row.product_quantity;
@@ -5665,7 +6223,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5665
6223
  var productSku = ensureProductSku(row);
5666
6224
  row.product_sku = _objectSpread(_objectSpread({}, productSku), {}, {
5667
6225
  option: normalizeProductSkuOptions(productSku.option.map(function (optionItem) {
5668
- return _this28.normalizeHydratedProductOptionItem(optionItem || {});
6226
+ return _this33.normalizeHydratedProductOptionItem(optionItem || {});
5669
6227
  }))
5670
6228
  });
5671
6229
  delete row["product_".concat('option', "_item")];
@@ -5679,6 +6237,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5679
6237
  if (!existingIdentity) {
5680
6238
  row.metadata.unique_identification_number = createUuidV4();
5681
6239
  }
6240
+ // 从云端、本地数据库中获取到的商品数据,先打上 runtime 标记,提供给 UI 做 saved items.
6241
+ if (options !== null && options !== void 0 && options.makeEditMark) {
6242
+ row.metadata.is_edit_for_runtime = true;
6243
+ }
5682
6244
  var normalized = normalizeOrderProduct(row);
5683
6245
  normalized.discount_list = normalizeOrderProductDiscountList(normalized.discount_list);
5684
6246
  var result = _objectSpread(_objectSpread(_objectSpread({}, row), normalized), {}, {
@@ -5698,27 +6260,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5698
6260
  }, {
5699
6261
  key: "getOrderInfo",
5700
6262
  value: function () {
5701
- var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(order_id) {
6263
+ var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee45(order_id) {
5702
6264
  var res;
5703
- return _regeneratorRuntime().wrap(function _callee40$(_context43) {
5704
- while (1) switch (_context43.prev = _context43.next) {
6265
+ return _regeneratorRuntime().wrap(function _callee45$(_context48) {
6266
+ while (1) switch (_context48.prev = _context48.next) {
5705
6267
  case 0:
5706
- _context43.next = 2;
6268
+ _context48.next = 2;
5707
6269
  return this.request.get("/order/sales/".concat(order_id), {
5708
6270
  with: ['products', 'bookings']
5709
6271
  }, {
5710
6272
  osServer: true
5711
6273
  });
5712
6274
  case 2:
5713
- res = _context43.sent;
5714
- return _context43.abrupt("return", res);
6275
+ res = _context48.sent;
6276
+ return _context48.abrupt("return", res);
5715
6277
  case 4:
5716
6278
  case "end":
5717
- return _context43.stop();
6279
+ return _context48.stop();
5718
6280
  }
5719
- }, _callee40, this);
6281
+ }, _callee45, this);
5720
6282
  }));
5721
- function getOrderInfo(_x45) {
6283
+ function getOrderInfo(_x53) {
5722
6284
  return _getOrderInfo.apply(this, arguments);
5723
6285
  }
5724
6286
  return getOrderInfo;
@@ -5754,70 +6316,70 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5754
6316
  addDiscountAmount(savedMap, discountKey, amount);
5755
6317
  addDiscountAmount(isPersistedProduct || discount.order_discount_id != null ? editModeSavedMap : runtimeSavedMap, discountKey, amount);
5756
6318
  };
5757
- var _iterator24 = _createForOfIteratorHelper(productList),
5758
- _step24;
6319
+ var _iterator26 = _createForOfIteratorHelper(productList),
6320
+ _step26;
5759
6321
  try {
5760
- for (_iterator24.s(); !(_step24 = _iterator24.n()).done;) {
5761
- var product = _step24.value;
6322
+ for (_iterator26.s(); !(_step26 = _iterator26.n()).done;) {
6323
+ var product = _step26.value;
5762
6324
  var qty = product.num || 1;
5763
6325
  var isPersistedProduct = Boolean(product.order_detail_id || product.orderDetailId || product.booking_id);
5764
- var _iterator26 = _createForOfIteratorHelper(product.discount_list || []),
5765
- _step26;
6326
+ var _iterator28 = _createForOfIteratorHelper(product.discount_list || []),
6327
+ _step28;
5766
6328
  try {
5767
- for (_iterator26.s(); !(_step26 = _iterator26.n()).done;) {
5768
- var pd = _step26.value;
6329
+ for (_iterator28.s(); !(_step28 = _iterator28.n()).done;) {
6330
+ var pd = _step28.value;
5769
6331
  addProductDiscountAmount(pd, qty, isPersistedProduct);
5770
6332
  }
5771
6333
  } catch (err) {
5772
- _iterator26.e(err);
6334
+ _iterator28.e(err);
5773
6335
  } finally {
5774
- _iterator26.f();
6336
+ _iterator28.f();
5775
6337
  }
5776
- var _iterator27 = _createForOfIteratorHelper(product.product_bundle || []),
5777
- _step27;
6338
+ var _iterator29 = _createForOfIteratorHelper(product.product_bundle || []),
6339
+ _step29;
5778
6340
  try {
5779
- for (_iterator27.s(); !(_step27 = _iterator27.n()).done;) {
5780
- var _ref78, _bundle$num3;
5781
- var bundle = _step27.value;
6341
+ for (_iterator29.s(); !(_step29 = _iterator29.n()).done;) {
6342
+ var _ref81, _bundle$num3;
6343
+ var bundle = _step29.value;
5782
6344
  var isPersistedBundleProduct = isPersistedProduct || Boolean((bundle === null || bundle === void 0 ? void 0 : bundle.order_detail_id) || (bundle === null || bundle === void 0 ? void 0 : bundle.orderDetailId) || (bundle === null || bundle === void 0 ? void 0 : bundle.booking_id));
5783
- var bundleQty = new Decimal(Number(qty) || 1).times(Number((_ref78 = (_bundle$num3 = bundle === null || bundle === void 0 ? void 0 : bundle.num) !== null && _bundle$num3 !== void 0 ? _bundle$num3 : bundle === null || bundle === void 0 ? void 0 : bundle.quantity) !== null && _ref78 !== void 0 ? _ref78 : 1) || 1).toNumber();
5784
- var _iterator28 = _createForOfIteratorHelper((bundle === null || bundle === void 0 ? void 0 : bundle.discount_list) || []),
5785
- _step28;
6345
+ var bundleQty = new Decimal(Number(qty) || 1).times(Number((_ref81 = (_bundle$num3 = bundle === null || bundle === void 0 ? void 0 : bundle.num) !== null && _bundle$num3 !== void 0 ? _bundle$num3 : bundle === null || bundle === void 0 ? void 0 : bundle.quantity) !== null && _ref81 !== void 0 ? _ref81 : 1) || 1).toNumber();
6346
+ var _iterator30 = _createForOfIteratorHelper((bundle === null || bundle === void 0 ? void 0 : bundle.discount_list) || []),
6347
+ _step30;
5786
6348
  try {
5787
- for (_iterator28.s(); !(_step28 = _iterator28.n()).done;) {
5788
- var _pd = _step28.value;
6349
+ for (_iterator30.s(); !(_step30 = _iterator30.n()).done;) {
6350
+ var _pd = _step30.value;
5789
6351
  addProductDiscountAmount(_pd, bundleQty, isPersistedBundleProduct);
5790
6352
  }
5791
6353
  } catch (err) {
5792
- _iterator28.e(err);
6354
+ _iterator30.e(err);
5793
6355
  } finally {
5794
- _iterator28.f();
6356
+ _iterator30.f();
5795
6357
  }
5796
6358
  }
5797
6359
  } catch (err) {
5798
- _iterator27.e(err);
6360
+ _iterator29.e(err);
5799
6361
  } finally {
5800
- _iterator27.f();
6362
+ _iterator29.f();
5801
6363
  }
5802
6364
  }
5803
6365
  } catch (err) {
5804
- _iterator24.e(err);
6366
+ _iterator26.e(err);
5805
6367
  } finally {
5806
- _iterator24.f();
6368
+ _iterator26.f();
5807
6369
  }
5808
- var _iterator25 = _createForOfIteratorHelper(discountList),
5809
- _step25;
6370
+ var _iterator27 = _createForOfIteratorHelper(discountList),
6371
+ _step27;
5810
6372
  try {
5811
- for (_iterator25.s(); !(_step25 = _iterator25.n()).done;) {
5812
- var d = _step25.value;
6373
+ for (_iterator27.s(); !(_step27 = _iterator27.n()).done;) {
6374
+ var d = _step27.value;
5813
6375
  var key = d.id;
5814
6376
  var sourceMap = d.isEditMode ? editModeSavedMap : editModeDiscountKeys.has(key) ? runtimeSavedMap : savedMap;
5815
6377
  d.savedAmount = d.isSelected && key != null && sourceMap.has(key) ? sourceMap.get(key).toNumber() : 0;
5816
6378
  }
5817
6379
  } catch (err) {
5818
- _iterator25.e(err);
6380
+ _iterator27.e(err);
5819
6381
  } finally {
5820
- _iterator25.f();
6382
+ _iterator27.f();
5821
6383
  }
5822
6384
  }
5823
6385
  }]);