@pisell/pisellos 2.2.197 → 2.2.198

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.
@@ -2,19 +2,19 @@ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArra
2
2
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
3
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
4
4
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
5
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
5
6
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
6
7
  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."); }
7
8
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
8
9
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
9
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
10
- 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; } } }; }
11
- 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); }
12
- 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; }
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
10
  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; }
16
11
  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); } }
17
12
  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); }); }; }
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
+ 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
+ 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
+ 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; }
18
18
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
19
19
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
20
20
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
@@ -100,10 +100,108 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
100
100
  return _this;
101
101
  }
102
102
  _createClass(OrderModule, [{
103
+ key: "collectHydratedEditDiscounts",
104
+ value: function collectHydratedEditDiscounts(products) {
105
+ var discountMap = new Map();
106
+ var _iterator = _createForOfIteratorHelper(products || []),
107
+ _step;
108
+ try {
109
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
110
+ var product = _step.value;
111
+ var _iterator2 = _createForOfIteratorHelper((product === null || product === void 0 ? void 0 : product.discount_list) || []),
112
+ _step2;
113
+ try {
114
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
115
+ var _item$type2, _ref, _ref2, _item$discount$resour, _item$discount, _item$discount$title, _item$discount2, _item$amount, _ref3, _item$discount$origin, _item$discount3, _ref4, _ref5, _item$metadata$num, _item$metadata, _ref6, _ref7, _item$metadata$num2, _item$metadata2, _ref8, _item$discount$discou, _item$discount4, _ref9, _item$discount$origin2, _item$discount5, _item$amount2, _item$amount3, _product$product_id, _product$is_charge_ta, _ref10, _product$original_pri, _ref11, _item$discount$discou2, _item$discount6, _item$discount$discou3, _item$discount7;
116
+ var item = _step2.value;
117
+ var type = (_item$type2 = item === null || item === void 0 ? void 0 : item.type) !== null && _item$type2 !== void 0 ? _item$type2 : item === null || item === void 0 ? void 0 : item.tag;
118
+ if (!type || type === 'product') continue;
119
+ var resourceId = (_ref = (_ref2 = (_item$discount$resour = item === null || item === void 0 || (_item$discount = item.discount) === null || _item$discount === void 0 ? void 0 : _item$discount.resource_id) !== null && _item$discount$resour !== void 0 ? _item$discount$resour : item === null || item === void 0 ? void 0 : item.resource_id) !== null && _ref2 !== void 0 ? _ref2 : item === null || item === void 0 ? void 0 : item.discount_id) !== null && _ref !== void 0 ? _ref : item === null || item === void 0 ? void 0 : item.order_discount_id;
120
+ if (resourceId === undefined || resourceId === null || resourceId === '') continue;
121
+ var id = Number(resourceId);
122
+ var key = Number.isFinite(id) ? id : String(resourceId);
123
+ var title = (_item$discount$title = item === null || item === void 0 || (_item$discount2 = item.discount) === null || _item$discount2 === void 0 ? void 0 : _item$discount2.title) !== null && _item$discount$title !== void 0 ? _item$discount$title : {};
124
+ var amount = Number((item === null || item === void 0 ? void 0 : item.amount) || 0);
125
+ var detail = {
126
+ amount: String((_item$amount = item === null || item === void 0 ? void 0 : item.amount) !== null && _item$amount !== void 0 ? _item$amount : '0'),
127
+ type: type,
128
+ resource_id: key,
129
+ title: title,
130
+ original_amount: String((_ref3 = (_item$discount$origin = item === null || item === void 0 || (_item$discount3 = item.discount) === null || _item$discount3 === void 0 ? void 0 : _item$discount3.original_amount) !== null && _item$discount$origin !== void 0 ? _item$discount$origin : item === null || item === void 0 ? void 0 : item.amount) !== null && _ref3 !== void 0 ? _ref3 : '0'),
131
+ num: Number((_ref4 = (_ref5 = (_item$metadata$num = item === null || item === void 0 || (_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.num) !== null && _item$metadata$num !== void 0 ? _item$metadata$num : product === null || product === void 0 ? void 0 : product.num) !== null && _ref5 !== void 0 ? _ref5 : product === null || product === void 0 ? void 0 : product.product_quantity) !== null && _ref4 !== void 0 ? _ref4 : 1) || 1,
132
+ metadata: item === null || item === void 0 ? void 0 : item.metadata,
133
+ discount: item === null || item === void 0 ? void 0 : item.discount,
134
+ _num: Number((_ref6 = (_ref7 = (_item$metadata$num2 = item === null || item === void 0 || (_item$metadata2 = item.metadata) === null || _item$metadata2 === void 0 ? void 0 : _item$metadata2.num) !== null && _item$metadata$num2 !== void 0 ? _item$metadata$num2 : product === null || product === void 0 ? void 0 : product.num) !== null && _ref7 !== void 0 ? _ref7 : product === null || product === void 0 ? void 0 : product.product_quantity) !== null && _ref6 !== void 0 ? _ref6 : 1) || 1
135
+ };
136
+ discountMap.set(key, {
137
+ id: key,
138
+ product_name: '',
139
+ encoded: '',
140
+ code: '',
141
+ tag: type,
142
+ product_id: (_ref8 = (_item$discount$discou = item === null || item === void 0 || (_item$discount4 = item.discount) === null || _item$discount4 === void 0 ? void 0 : _item$discount4.discount_product_id) !== null && _item$discount$discou !== void 0 ? _item$discount$discou : product === null || product === void 0 ? void 0 : product.product_id) !== null && _ref8 !== void 0 ? _ref8 : 0,
143
+ relation_type: '',
144
+ par_value: String((_ref9 = (_item$discount$origin2 = item === null || item === void 0 || (_item$discount5 = item.discount) === null || _item$discount5 === void 0 ? void 0 : _item$discount5.original_amount) !== null && _item$discount$origin2 !== void 0 ? _item$discount$origin2 : item === null || item === void 0 ? void 0 : item.amount) !== null && _ref9 !== void 0 ? _ref9 : '0'),
145
+ used_par_value: String((_item$amount2 = item === null || item === void 0 ? void 0 : item.amount) !== null && _item$amount2 !== void 0 ? _item$amount2 : '0'),
146
+ limit_status: 'enable',
147
+ limited_relation_product_data: {
148
+ id: 0,
149
+ type: 'products',
150
+ product_ids: [product === null || product === void 0 ? void 0 : product.product_id].filter(function (value) {
151
+ return value !== undefined && value !== null;
152
+ }),
153
+ product_collection_id: [],
154
+ filter: 0,
155
+ exclude_product_ids: []
156
+ },
157
+ balance: String((_item$amount3 = item === null || item === void 0 ? void 0 : item.amount) !== null && _item$amount3 !== void 0 ? _item$amount3 : '0'),
158
+ format_title: title,
159
+ product: {
160
+ id: (_product$product_id = product === null || product === void 0 ? void 0 : product.product_id) !== null && _product$product_id !== void 0 ? _product$product_id : 0,
161
+ title: '',
162
+ is_charge_tax: (_product$is_charge_ta = product === null || product === void 0 ? void 0 : product.is_charge_tax) !== null && _product$is_charge_ta !== void 0 ? _product$is_charge_ta : 0,
163
+ base_price: String((_ref10 = (_product$original_pri = product === null || product === void 0 ? void 0 : product.original_price) !== null && _product$original_pri !== void 0 ? _product$original_pri : product === null || product === void 0 ? void 0 : product.selling_price) !== null && _ref10 !== void 0 ? _ref10 : '0')
164
+ },
165
+ type: type,
166
+ resource_id: key,
167
+ isEditMode: true,
168
+ isSelected: true,
169
+ isAvailable: true,
170
+ isUsed: true,
171
+ isDisabled: true,
172
+ amount: amount,
173
+ discount: _objectSpread(_objectSpread({}, (item === null || item === void 0 ? void 0 : item.discount) || {}), {}, {
174
+ resource_id: key,
175
+ discount_product_id: (_ref11 = (_item$discount$discou2 = item === null || item === void 0 || (_item$discount6 = item.discount) === null || _item$discount6 === void 0 ? void 0 : _item$discount6.discount_product_id) !== null && _item$discount$discou2 !== void 0 ? _item$discount$discou2 : product === null || product === void 0 ? void 0 : product.product_id) !== null && _ref11 !== void 0 ? _ref11 : 0,
176
+ discount_calculation_mode: (_item$discount$discou3 = item === null || item === void 0 || (_item$discount7 = item.discount) === null || _item$discount7 === void 0 ? void 0 : _item$discount7.discount_calculation_mode) !== null && _item$discount$discou3 !== void 0 ? _item$discount$discou3 : 'item_level'
177
+ }),
178
+ applicableProductDetails: [detail],
179
+ appliedProductDetails: [detail]
180
+ });
181
+ }
182
+ } catch (err) {
183
+ _iterator2.e(err);
184
+ } finally {
185
+ _iterator2.f();
186
+ }
187
+ }
188
+ } catch (err) {
189
+ _iterator.e(err);
190
+ } finally {
191
+ _iterator.f();
192
+ }
193
+ return Array.from(discountMap.values());
194
+ }
195
+
196
+ /**
197
+ * Populate `savedAmount` on each discount based on product-level discount details.
198
+ * Only selected discounts get a non-zero value.
199
+ */
200
+ }, {
103
201
  key: "applyProductDiscountPrices",
104
202
  value: function applyProductDiscountPrices(products) {
105
203
  return (products || []).map(function (product) {
106
- var _product$metadata$sou, _product$metadata3, _product$metadata4, _product$original_pri;
204
+ var _product$metadata$sou, _product$metadata3, _product$metadata4, _product$original_pri2;
107
205
  if (isManualProductDiscountProduct(product)) return product;
108
206
  var discountItems = Array.isArray(product.discount_list) ? product.discount_list : [];
109
207
  var hasOnlyPersistedDiscountSnapshots = product.order_detail_id !== undefined && product.order_detail_id !== null && discountItems.length > 0 && discountItems.every(function (discount) {
@@ -114,7 +212,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
114
212
  }
115
213
  var totalPerUnitDiscount = resolveEffectivePerUnitDiscount(product);
116
214
  var optionSum = sumOptionUnitPrice(getProductSkuOptions(product));
117
- var sourcePrice = (_product$metadata$sou = (_product$metadata3 = product.metadata) === null || _product$metadata3 === void 0 ? void 0 : _product$metadata3.source_product_price) !== null && _product$metadata$sou !== void 0 ? _product$metadata$sou : ((_product$metadata4 = product.metadata) === null || _product$metadata4 === void 0 ? void 0 : _product$metadata4.main_product_original_price) != null ? new Decimal(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : (_product$original_pri = product.original_price) !== null && _product$original_pri !== void 0 ? _product$original_pri : '0';
215
+ var sourcePrice = (_product$metadata$sou = (_product$metadata3 = product.metadata) === null || _product$metadata3 === void 0 ? void 0 : _product$metadata3.source_product_price) !== null && _product$metadata$sou !== void 0 ? _product$metadata$sou : ((_product$metadata4 = product.metadata) === null || _product$metadata4 === void 0 ? void 0 : _product$metadata4.main_product_original_price) != null ? new Decimal(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : (_product$original_pri2 = product.original_price) !== null && _product$original_pri2 !== void 0 ? _product$original_pri2 : '0';
118
216
  var newSourceSellingPrice = new Decimal(Number(sourcePrice) || 0).minus(totalPerUnitDiscount).toDecimalPlaces(2).toString();
119
217
  var newMainSellingPrice = new Decimal(Number(newSourceSellingPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
120
218
  if (product.metadata) {
@@ -265,7 +363,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
265
363
  value: function () {
266
364
  var _loadDiscountConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params) {
267
365
  var _this$store$tempOrder, _this$store$discount, _this$store$tempOrder2;
268
- var orderId, discountList, _this$store$discount2, _this$store$discount3;
366
+ var orderId, discountList, _this$store$discount2, _this$store$discount3, _this$store$discount4, currentEditDiscounts, currentEditDiscountIds, mergedDiscountList;
269
367
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
270
368
  while (1) switch (_context2.prev = _context2.next) {
271
369
  case 0:
@@ -284,20 +382,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
284
382
  case 3:
285
383
  discountList = _context2.sent;
286
384
  if (!discountList) {
287
- _context2.next = 9;
385
+ _context2.next = 12;
288
386
  break;
289
387
  }
290
- _context2.next = 7;
291
- return (_this$store$discount2 = this.store.discount) === null || _this$store$discount2 === void 0 ? void 0 : _this$store$discount2.setOriginalDiscountList(discountList);
292
- case 7:
293
- _context2.next = 9;
294
- return (_this$store$discount3 = this.store.discount) === null || _this$store$discount3 === void 0 ? void 0 : _this$store$discount3.setDiscountList(discountList);
295
- case 9:
388
+ currentEditDiscounts = (((_this$store$discount2 = this.store.discount) === null || _this$store$discount2 === void 0 ? void 0 : _this$store$discount2.getDiscountList()) || []).filter(function (discount) {
389
+ return discount === null || discount === void 0 ? void 0 : discount.isEditMode;
390
+ });
391
+ currentEditDiscountIds = new Set(currentEditDiscounts.map(function (discount) {
392
+ return discount === null || discount === void 0 ? void 0 : discount.id;
393
+ }));
394
+ mergedDiscountList = [].concat(_toConsumableArray(currentEditDiscounts), _toConsumableArray(discountList.filter(function (discount) {
395
+ return !currentEditDiscountIds.has(discount === null || discount === void 0 ? void 0 : discount.id);
396
+ })));
397
+ _context2.next = 10;
398
+ return (_this$store$discount3 = this.store.discount) === null || _this$store$discount3 === void 0 ? void 0 : _this$store$discount3.setOriginalDiscountList(mergedDiscountList);
399
+ case 10:
400
+ _context2.next = 12;
401
+ return (_this$store$discount4 = this.store.discount) === null || _this$store$discount4 === void 0 ? void 0 : _this$store$discount4.setDiscountList(mergedDiscountList);
402
+ case 12:
296
403
  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) {
297
404
  this.applyDiscount();
298
405
  }
299
406
  return _context2.abrupt("return", this.getDiscountList());
300
- case 11:
407
+ case 14:
301
408
  case "end":
302
409
  return _context2.stop();
303
410
  }
@@ -311,41 +418,86 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
311
418
  }, {
312
419
  key: "getDiscountList",
313
420
  value: function getDiscountList() {
314
- var _this$store$discount4;
315
- return ((_this$store$discount4 = this.store.discount) === null || _this$store$discount4 === void 0 ? void 0 : _this$store$discount4.getDiscountList()) || [];
421
+ var _this$store$discount5;
422
+ return ((_this$store$discount5 = this.store.discount) === null || _this$store$discount5 === void 0 ? void 0 : _this$store$discount5.getDiscountList()) || [];
316
423
  }
317
424
  }, {
318
- key: "scanCode",
425
+ key: "ensureEditDiscountConfigForProductChange",
319
426
  value: function () {
320
- var _scanCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(code, customerId) {
321
- var _this$store$discount5, _tempOrder$holder, _this$store$summary, _tempOrder$holder2;
322
- var resultDiscountWithReason, resultDiscountList, unavailableReasonKey, rulesModule, withScanList, currentSelected, tempOrder, holders, _ref, isAvailable, newDiscountList, unavailableReason, _this$store$discount6;
427
+ var _ensureEditDiscountConfigForProductChange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(tempOrder) {
428
+ var _tempOrder$customer, _tempOrder$_extend, _tempOrder$_extend2, _this$store$discount6;
429
+ var orderId, customerId, currentDiscountList, hasRuntimeDiscounts;
323
430
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
324
431
  while (1) switch (_context3.prev = _context3.next) {
325
432
  case 0:
326
- _context3.next = 2;
327
- return (_this$store$discount5 = this.store.discount) === null || _this$store$discount5 === void 0 ? void 0 : _this$store$discount5.batchSearch(code, {
433
+ orderId = tempOrder.order_id;
434
+ 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);
435
+ if (!(!orderId || !customerId || customerId === 1)) {
436
+ _context3.next = 4;
437
+ break;
438
+ }
439
+ return _context3.abrupt("return");
440
+ case 4:
441
+ currentDiscountList = ((_this$store$discount6 = this.store.discount) === null || _this$store$discount6 === void 0 ? void 0 : _this$store$discount6.getDiscountList()) || [];
442
+ hasRuntimeDiscounts = currentDiscountList.some(function (discount) {
443
+ return !(discount !== null && discount !== void 0 && discount.isEditMode);
444
+ });
445
+ if (!hasRuntimeDiscounts) {
446
+ _context3.next = 8;
447
+ break;
448
+ }
449
+ return _context3.abrupt("return");
450
+ case 8:
451
+ _context3.next = 10;
452
+ return this.loadDiscountConfig({
453
+ customerId: customerId,
454
+ action: 'edit',
455
+ orderId: Number(orderId),
456
+ apply: false
457
+ });
458
+ case 10:
459
+ case "end":
460
+ return _context3.stop();
461
+ }
462
+ }, _callee3, this);
463
+ }));
464
+ function ensureEditDiscountConfigForProductChange(_x4) {
465
+ return _ensureEditDiscountConfigForProductChange.apply(this, arguments);
466
+ }
467
+ return ensureEditDiscountConfigForProductChange;
468
+ }()
469
+ }, {
470
+ key: "scanCode",
471
+ value: function () {
472
+ var _scanCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(code, customerId) {
473
+ var _this$store$discount7, _tempOrder$holder, _this$store$summary, _tempOrder$holder2;
474
+ var resultDiscountWithReason, resultDiscountList, unavailableReasonKey, rulesModule, withScanList, currentSelected, tempOrder, holders, _ref12, isAvailable, newDiscountList, unavailableReason, _this$store$discount8;
475
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
476
+ while (1) switch (_context4.prev = _context4.next) {
477
+ case 0:
478
+ _context4.next = 2;
479
+ return (_this$store$discount7 = this.store.discount) === null || _this$store$discount7 === void 0 ? void 0 : _this$store$discount7.batchSearch(code, {
328
480
  customerId: customerId
329
481
  });
330
482
  case 2:
331
- _context3.t0 = _context3.sent;
332
- if (_context3.t0) {
333
- _context3.next = 5;
483
+ _context4.t0 = _context4.sent;
484
+ if (_context4.t0) {
485
+ _context4.next = 5;
334
486
  break;
335
487
  }
336
- _context3.t0 = {
488
+ _context4.t0 = {
337
489
  discountList: [],
338
490
  unavailableReasonKey: null
339
491
  };
340
492
  case 5:
341
- resultDiscountWithReason = _context3.t0;
493
+ resultDiscountWithReason = _context4.t0;
342
494
  resultDiscountList = resultDiscountWithReason.discountList, unavailableReasonKey = resultDiscountWithReason.unavailableReasonKey;
343
495
  rulesModule = this.store.rules;
344
496
  if (rulesModule) {
345
- _context3.next = 10;
497
+ _context4.next = 10;
346
498
  break;
347
499
  }
348
- return _context3.abrupt("return", {
500
+ return _context4.abrupt("return", {
349
501
  type: 'clientCalc',
350
502
  isAvailable: false,
351
503
  discountList: this.getDiscountList(),
@@ -354,10 +506,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
354
506
  });
355
507
  case 10:
356
508
  if (resultDiscountList.length) {
357
- _context3.next = 12;
509
+ _context4.next = 12;
358
510
  break;
359
511
  }
360
- return _context3.abrupt("return", {
512
+ return _context4.abrupt("return", {
361
513
  type: 'server',
362
514
  isAvailable: false,
363
515
  discountList: this.getDiscountList(),
@@ -378,10 +530,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
378
530
  return m.id === n.id;
379
531
  });
380
532
  }))) {
381
- _context3.next = 16;
533
+ _context4.next = 16;
382
534
  break;
383
535
  }
384
- return _context3.abrupt("return", {
536
+ return _context4.abrupt("return", {
385
537
  type: 'clientCalc',
386
538
  isAvailable: true,
387
539
  discountList: this.getDiscountList(),
@@ -392,7 +544,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
392
544
  holders = tempOrder !== null && tempOrder !== void 0 && (_tempOrder$holder = tempOrder.holder) !== null && _tempOrder$holder !== void 0 && _tempOrder$holder.form_record_id ? [{
393
545
  form_record_id: tempOrder.holder.form_record_id
394
546
  }] : [];
395
- _ref = rulesModule.isDiscountListAvailable({
547
+ _ref12 = rulesModule.isDiscountListAvailable({
396
548
  productList: (tempOrder === null || tempOrder === void 0 ? void 0 : tempOrder.products) || [],
397
549
  oldDiscountList: this.getDiscountList(),
398
550
  newDiscountList: withScanList,
@@ -402,12 +554,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
402
554
  }) || {
403
555
  isAvailable: false,
404
556
  discountList: this.getDiscountList()
405
- }, isAvailable = _ref.isAvailable, newDiscountList = _ref.discountList, unavailableReason = _ref.unavailableReason;
557
+ }, isAvailable = _ref12.isAvailable, newDiscountList = _ref12.discountList, unavailableReason = _ref12.unavailableReason;
406
558
  if (isAvailable && newDiscountList) {
407
- (_this$store$discount6 = this.store.discount) === null || _this$store$discount6 === void 0 || _this$store$discount6.setDiscountList(newDiscountList);
559
+ (_this$store$discount8 = this.store.discount) === null || _this$store$discount8 === void 0 || _this$store$discount8.setDiscountList(newDiscountList);
408
560
  this.applyDiscount();
409
561
  }
410
- return _context3.abrupt("return", {
562
+ return _context4.abrupt("return", {
411
563
  type: 'clientCalc',
412
564
  isAvailable: isAvailable || false,
413
565
  discountList: newDiscountList || this.getDiscountList(),
@@ -416,11 +568,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
416
568
  });
417
569
  case 21:
418
570
  case "end":
419
- return _context3.stop();
571
+ return _context4.stop();
420
572
  }
421
- }, _callee3, this);
573
+ }, _callee4, this);
422
574
  }));
423
- function scanCode(_x4, _x5) {
575
+ function scanCode(_x5, _x6) {
424
576
  return _scanCode.apply(this, arguments);
425
577
  }
426
578
  return scanCode;
@@ -428,7 +580,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
428
580
  }, {
429
581
  key: "applyDiscount",
430
582
  value: function applyDiscount() {
431
- var _this$store$discount7, _tempOrder$holder3, _tempOrder$holder4, _this$store$summary2;
583
+ var _this$store$discount9, _tempOrder$holder3, _tempOrder$holder4, _this$store$summary2;
432
584
  var tempOrder = this.store.tempOrder;
433
585
  // 任意 products CRUD 后都应当重算 discount 状态;即使 products 为空,
434
586
  // 也需要让 Rules.calcDiscount 把 DiscountModule 的 isSelected / isAvailable /
@@ -437,7 +589,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
437
589
  delete tempOrder.discount_list;
438
590
  var rulesModule = this.store.rules;
439
591
  if (!rulesModule) return;
440
- var discountList = ((_this$store$discount7 = this.store.discount) === null || _this$store$discount7 === void 0 ? void 0 : _this$store$discount7.getDiscountList()) || [];
592
+ var discountList = ((_this$store$discount9 = this.store.discount) === null || _this$store$discount9 === void 0 ? void 0 : _this$store$discount9.getDiscountList()) || [];
441
593
  var holders = (_tempOrder$holder3 = tempOrder.holder) !== null && _tempOrder$holder3 !== void 0 && _tempOrder$holder3.form_record_id ? [{
442
594
  form_record_id: tempOrder.holder.form_record_id
443
595
  }] : [];
@@ -451,9 +603,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
451
603
  if (result !== null && result !== void 0 && result.productList) {
452
604
  var previousProductsByUid = indexOrderProductsByUid(tempOrder.products);
453
605
  tempOrder.products = this.applyProductDiscountPrices((result.productList || []).map(function (product, index) {
454
- var _ref2;
606
+ var _ref13;
455
607
  var uid = getOrderProductLineUid(product);
456
- var previous = (_ref2 = uid ? previousProductsByUid.get(uid) : undefined) !== null && _ref2 !== void 0 ? _ref2 : previousProductsByUid.get("__index__:".concat(index));
608
+ var previous = (_ref13 = uid ? previousProductsByUid.get(uid) : undefined) !== null && _ref13 !== void 0 ? _ref13 : previousProductsByUid.get("__index__:".concat(index));
457
609
  if (isManualProductDiscountProduct(previous)) {
458
610
  return previous;
459
611
  }
@@ -464,9 +616,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
464
616
  }));
465
617
  }
466
618
  if (result !== null && result !== void 0 && result.discountList) {
467
- var _this$store$discount8;
619
+ var _this$store$discount10;
468
620
  OrderModule.populateSavedAmounts(result.productList || tempOrder.products, result.discountList);
469
- (_this$store$discount8 = this.store.discount) === null || _this$store$discount8 === void 0 || _this$store$discount8.setDiscountList(result.discountList);
621
+ (_this$store$discount10 = this.store.discount) === null || _this$store$discount10 === void 0 || _this$store$discount10.setDiscountList(result.discountList);
470
622
  }
471
623
  }
472
624
 
@@ -525,33 +677,33 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
525
677
  }, {
526
678
  key: "applyPromotion",
527
679
  value: (function () {
528
- var _applyPromotion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
680
+ var _applyPromotion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
529
681
  var _this2 = this;
530
- var tempOrder, result, removeSet, _iterator, _step, reduce, _iterator4, _step4, _loop2, _iterator2, _step2, _loop, payload;
531
- return _regeneratorRuntime().wrap(function _callee4$(_context6) {
532
- while (1) switch (_context6.prev = _context6.next) {
682
+ var tempOrder, result, removeSet, _iterator3, _step3, reduce, _iterator6, _step6, _loop2, _iterator4, _step4, _loop, payload;
683
+ return _regeneratorRuntime().wrap(function _callee5$(_context7) {
684
+ while (1) switch (_context7.prev = _context7.next) {
533
685
  case 0:
534
686
  if (!this.isApplyingPromotion) {
535
- _context6.next = 2;
687
+ _context7.next = 2;
536
688
  break;
537
689
  }
538
- return _context6.abrupt("return");
690
+ return _context7.abrupt("return");
539
691
  case 2:
540
692
  if (this.promotionEvaluator) {
541
- _context6.next = 4;
693
+ _context7.next = 4;
542
694
  break;
543
695
  }
544
- return _context6.abrupt("return");
696
+ return _context7.abrupt("return");
545
697
  case 4:
546
698
  tempOrder = this.store.tempOrder;
547
699
  if (tempOrder) {
548
- _context6.next = 7;
700
+ _context7.next = 7;
549
701
  break;
550
702
  }
551
- return _context6.abrupt("return");
703
+ return _context7.abrupt("return");
552
704
  case 7:
553
705
  this.isApplyingPromotion = true;
554
- _context6.prev = 8;
706
+ _context7.prev = 8;
555
707
  result = processCartPromotion(tempOrder.products, this.promotionEvaluator); // step 1: toRemove —— 直接过滤
556
708
  if (result.giftActions.toRemove.length > 0) {
557
709
  removeSet = new Set(result.giftActions.toRemove.map(String));
@@ -562,23 +714,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
562
714
  }
563
715
 
564
716
  // step 2: toReduce —— 调整数量
565
- _iterator = _createForOfIteratorHelper(result.giftActions.toReduce);
566
- _context6.prev = 12;
567
- _iterator.s();
717
+ _iterator3 = _createForOfIteratorHelper(result.giftActions.toReduce);
718
+ _context7.prev = 12;
719
+ _iterator3.s();
568
720
  case 14:
569
- if ((_step = _iterator.n()).done) {
570
- _context6.next = 34;
721
+ if ((_step3 = _iterator3.n()).done) {
722
+ _context7.next = 34;
571
723
  break;
572
724
  }
573
- reduce = _step.value;
574
- _iterator4 = _createForOfIteratorHelper(reduce.items);
575
- _context6.prev = 17;
725
+ reduce = _step3.value;
726
+ _iterator6 = _createForOfIteratorHelper(reduce.items);
727
+ _context7.prev = 17;
576
728
  _loop2 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop2() {
577
729
  var item, product;
578
- return _regeneratorRuntime().wrap(function _loop2$(_context5) {
579
- while (1) switch (_context5.prev = _context5.next) {
730
+ return _regeneratorRuntime().wrap(function _loop2$(_context6) {
731
+ while (1) switch (_context6.prev = _context6.next) {
580
732
  case 0:
581
- item = _step4.value;
733
+ item = _step6.value;
582
734
  product = result.products.find(function (p) {
583
735
  return getPromotionUid(p) === item.uid;
584
736
  });
@@ -587,52 +739,52 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
587
739
  }
588
740
  case 3:
589
741
  case "end":
590
- return _context5.stop();
742
+ return _context6.stop();
591
743
  }
592
744
  }, _loop2);
593
745
  });
594
- _iterator4.s();
746
+ _iterator6.s();
595
747
  case 20:
596
- if ((_step4 = _iterator4.n()).done) {
597
- _context6.next = 24;
748
+ if ((_step6 = _iterator6.n()).done) {
749
+ _context7.next = 24;
598
750
  break;
599
751
  }
600
- return _context6.delegateYield(_loop2(), "t0", 22);
752
+ return _context7.delegateYield(_loop2(), "t0", 22);
601
753
  case 22:
602
- _context6.next = 20;
754
+ _context7.next = 20;
603
755
  break;
604
756
  case 24:
605
- _context6.next = 29;
757
+ _context7.next = 29;
606
758
  break;
607
759
  case 26:
608
- _context6.prev = 26;
609
- _context6.t1 = _context6["catch"](17);
610
- _iterator4.e(_context6.t1);
760
+ _context7.prev = 26;
761
+ _context7.t1 = _context7["catch"](17);
762
+ _iterator6.e(_context7.t1);
611
763
  case 29:
612
- _context6.prev = 29;
613
- _iterator4.f();
614
- return _context6.finish(29);
764
+ _context7.prev = 29;
765
+ _iterator6.f();
766
+ return _context7.finish(29);
615
767
  case 32:
616
- _context6.next = 14;
768
+ _context7.next = 14;
617
769
  break;
618
770
  case 34:
619
- _context6.next = 39;
771
+ _context7.next = 39;
620
772
  break;
621
773
  case 36:
622
- _context6.prev = 36;
623
- _context6.t2 = _context6["catch"](12);
624
- _iterator.e(_context6.t2);
774
+ _context7.prev = 36;
775
+ _context7.t2 = _context7["catch"](12);
776
+ _iterator3.e(_context7.t2);
625
777
  case 39:
626
- _context6.prev = 39;
627
- _iterator.f();
628
- return _context6.finish(39);
778
+ _context7.prev = 39;
779
+ _iterator3.f();
780
+ return _context7.finish(39);
629
781
  case 42:
630
782
  if (!(result.giftActions.toAdd.length > 0)) {
631
- _context6.next = 65;
783
+ _context7.next = 65;
632
784
  break;
633
785
  }
634
786
  if (this.giftSelectResolver) {
635
- _context6.next = 47;
787
+ _context7.next = 47;
636
788
  break;
637
789
  }
638
790
  if (result.giftActions.toAdd.some(function (g) {
@@ -643,19 +795,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
643
795
  } else {
644
796
  console.warn('[OrderModule] giftSelectResolver not set, skip applying single-option gifts', result.giftActions.toAdd);
645
797
  }
646
- _context6.next = 65;
798
+ _context7.next = 65;
647
799
  break;
648
800
  case 47:
649
- _iterator2 = _createForOfIteratorHelper(result.giftActions.toAdd);
650
- _context6.prev = 48;
801
+ _iterator4 = _createForOfIteratorHelper(result.giftActions.toAdd);
802
+ _context7.prev = 48;
651
803
  _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
652
- var addAction, sameStrategy, giftProducts, _iterator3, _step3, gp;
653
- return _regeneratorRuntime().wrap(function _loop$(_context4) {
654
- while (1) switch (_context4.prev = _context4.next) {
804
+ var addAction, sameStrategy, giftProducts, _iterator5, _step5, gp;
805
+ return _regeneratorRuntime().wrap(function _loop$(_context5) {
806
+ while (1) switch (_context5.prev = _context5.next) {
655
807
  case 0:
656
- addAction = _step2.value;
808
+ addAction = _step4.value;
657
809
  if (!(addAction.giftOptions.length === 1)) {
658
- _context4.next = 6;
810
+ _context5.next = 6;
659
811
  break;
660
812
  }
661
813
  sameStrategy = result.products.find(function (p) {
@@ -663,14 +815,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
663
815
  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;
664
816
  });
665
817
  if (!sameStrategy) {
666
- _context4.next = 6;
818
+ _context5.next = 6;
667
819
  break;
668
820
  }
669
821
  sameStrategy.num = (Number(sameStrategy.num) || 0) + (addAction.giftCount || 1);
670
- return _context4.abrupt("return", 1);
822
+ return _context5.abrupt("return", 1);
671
823
  case 6:
672
- _context4.prev = 6;
673
- _context4.next = 9;
824
+ _context5.prev = 6;
825
+ _context5.next = 9;
674
826
  return _this2.giftSelectResolver({
675
827
  strategyId: addAction.strategyId,
676
828
  strategyName: addAction.strategyName,
@@ -679,83 +831,83 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
679
831
  sourceProductIds: addAction.sourceProductIds
680
832
  });
681
833
  case 9:
682
- giftProducts = _context4.sent;
834
+ giftProducts = _context5.sent;
683
835
  if (!(Array.isArray(giftProducts) && giftProducts.length > 0)) {
684
- _context4.next = 29;
836
+ _context5.next = 29;
685
837
  break;
686
838
  }
687
- _iterator3 = _createForOfIteratorHelper(giftProducts);
688
- _context4.prev = 12;
689
- _iterator3.s();
839
+ _iterator5 = _createForOfIteratorHelper(giftProducts);
840
+ _context5.prev = 12;
841
+ _iterator5.s();
690
842
  case 14:
691
- if ((_step3 = _iterator3.n()).done) {
692
- _context4.next = 21;
843
+ if ((_step5 = _iterator5.n()).done) {
844
+ _context5.next = 21;
693
845
  break;
694
846
  }
695
- gp = _step3.value;
847
+ gp = _step5.value;
696
848
  if (gp) {
697
- _context4.next = 18;
849
+ _context5.next = 18;
698
850
  break;
699
851
  }
700
- return _context4.abrupt("continue", 19);
852
+ return _context5.abrupt("continue", 19);
701
853
  case 18:
702
854
  // normalize 略过:调用方应保证返回完整 OrderProduct
703
855
  result.products.push(gp);
704
856
  case 19:
705
- _context4.next = 14;
857
+ _context5.next = 14;
706
858
  break;
707
859
  case 21:
708
- _context4.next = 26;
860
+ _context5.next = 26;
709
861
  break;
710
862
  case 23:
711
- _context4.prev = 23;
712
- _context4.t0 = _context4["catch"](12);
713
- _iterator3.e(_context4.t0);
863
+ _context5.prev = 23;
864
+ _context5.t0 = _context5["catch"](12);
865
+ _iterator5.e(_context5.t0);
714
866
  case 26:
715
- _context4.prev = 26;
716
- _iterator3.f();
717
- return _context4.finish(26);
867
+ _context5.prev = 26;
868
+ _iterator5.f();
869
+ return _context5.finish(26);
718
870
  case 29:
719
- _context4.next = 34;
871
+ _context5.next = 34;
720
872
  break;
721
873
  case 31:
722
- _context4.prev = 31;
723
- _context4.t1 = _context4["catch"](6);
874
+ _context5.prev = 31;
875
+ _context5.t1 = _context5["catch"](6);
724
876
  // 用户取消 / 选择失败 → 视为放弃本次新增
725
- console.warn('[OrderModule] giftSelectResolver rejected, skip add gift', addAction.strategyId, _context4.t1);
877
+ console.warn('[OrderModule] giftSelectResolver rejected, skip add gift', addAction.strategyId, _context5.t1);
726
878
  case 34:
727
879
  case "end":
728
- return _context4.stop();
880
+ return _context5.stop();
729
881
  }
730
882
  }, _loop, null, [[6, 31], [12, 23, 26, 29]]);
731
883
  });
732
- _iterator2.s();
884
+ _iterator4.s();
733
885
  case 51:
734
- if ((_step2 = _iterator2.n()).done) {
735
- _context6.next = 57;
886
+ if ((_step4 = _iterator4.n()).done) {
887
+ _context7.next = 57;
736
888
  break;
737
889
  }
738
- return _context6.delegateYield(_loop(), "t3", 53);
890
+ return _context7.delegateYield(_loop(), "t3", 53);
739
891
  case 53:
740
- if (!_context6.t3) {
741
- _context6.next = 55;
892
+ if (!_context7.t3) {
893
+ _context7.next = 55;
742
894
  break;
743
895
  }
744
- return _context6.abrupt("continue", 55);
896
+ return _context7.abrupt("continue", 55);
745
897
  case 55:
746
- _context6.next = 51;
898
+ _context7.next = 51;
747
899
  break;
748
900
  case 57:
749
- _context6.next = 62;
901
+ _context7.next = 62;
750
902
  break;
751
903
  case 59:
752
- _context6.prev = 59;
753
- _context6.t4 = _context6["catch"](48);
754
- _iterator2.e(_context6.t4);
904
+ _context7.prev = 59;
905
+ _context7.t4 = _context7["catch"](48);
906
+ _iterator4.e(_context7.t4);
755
907
  case 62:
756
- _context6.prev = 62;
757
- _iterator2.f();
758
- return _context6.finish(62);
908
+ _context7.prev = 62;
909
+ _iterator4.f();
910
+ return _context7.finish(62);
759
911
  case 65:
760
912
  tempOrder.products = result.products;
761
913
  this.lastUnfulfilledPromotions = result.unfulfilledPromotions;
@@ -774,21 +926,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
774
926
  products: tempOrder.products
775
927
  };
776
928
  this.effectsEmit('onPromotionApplied', payload);
777
- _context6.next = 75;
929
+ _context7.next = 75;
778
930
  break;
779
931
  case 72:
780
- _context6.prev = 72;
781
- _context6.t5 = _context6["catch"](8);
782
- console.error('[OrderModule] applyPromotion failed', _context6.t5);
932
+ _context7.prev = 72;
933
+ _context7.t5 = _context7["catch"](8);
934
+ console.error('[OrderModule] applyPromotion failed', _context7.t5);
783
935
  case 75:
784
- _context6.prev = 75;
936
+ _context7.prev = 75;
785
937
  this.isApplyingPromotion = false;
786
- return _context6.finish(75);
938
+ return _context7.finish(75);
787
939
  case 78:
788
940
  case "end":
789
- return _context6.stop();
941
+ return _context7.stop();
790
942
  }
791
- }, _callee4, this, [[8, 72, 75, 78], [12, 36, 39, 42], [17, 26, 29, 32], [48, 59, 62, 65]]);
943
+ }, _callee5, this, [[8, 72, 75, 78], [12, 36, 39, 42], [17, 26, 29, 32], [48, 59, 62, 65]]);
792
944
  }));
793
945
  function applyPromotion() {
794
946
  return _applyPromotion.apply(this, arguments);
@@ -910,14 +1062,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
910
1062
  }, {
911
1063
  key: "saveDraft",
912
1064
  value: function () {
913
- var _saveDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
914
- return _regeneratorRuntime().wrap(function _callee5$(_context7) {
915
- while (1) switch (_context7.prev = _context7.next) {
1065
+ var _saveDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
1066
+ return _regeneratorRuntime().wrap(function _callee6$(_context8) {
1067
+ while (1) switch (_context8.prev = _context8.next) {
916
1068
  case 0:
917
1069
  case "end":
918
- return _context7.stop();
1070
+ return _context8.stop();
919
1071
  }
920
- }, _callee5);
1072
+ }, _callee6);
921
1073
  }));
922
1074
  function saveDraft() {
923
1075
  return _saveDraft.apply(this, arguments);
@@ -932,18 +1084,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
932
1084
  }, {
933
1085
  key: "hydrateTempOrderFromLocalRecord",
934
1086
  value: function () {
935
- var _hydrateTempOrderFromLocalRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(record) {
936
- return _regeneratorRuntime().wrap(function _callee6$(_context8) {
937
- while (1) switch (_context8.prev = _context8.next) {
1087
+ var _hydrateTempOrderFromLocalRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(record) {
1088
+ return _regeneratorRuntime().wrap(function _callee7$(_context9) {
1089
+ while (1) switch (_context9.prev = _context9.next) {
938
1090
  case 0:
939
- return _context8.abrupt("return", this.hydrateTempOrderFromRecord(record));
1091
+ return _context9.abrupt("return", this.hydrateTempOrderFromRecord(record));
940
1092
  case 1:
941
1093
  case "end":
942
- return _context8.stop();
1094
+ return _context9.stop();
943
1095
  }
944
- }, _callee6, this);
1096
+ }, _callee7, this);
945
1097
  }));
946
- function hydrateTempOrderFromLocalRecord(_x6) {
1098
+ function hydrateTempOrderFromLocalRecord(_x7) {
947
1099
  return _hydrateTempOrderFromLocalRecord.apply(this, arguments);
948
1100
  }
949
1101
  return hydrateTempOrderFromLocalRecord;
@@ -951,8 +1103,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
951
1103
  }, {
952
1104
  key: "extractOrderIdFromSubmitResult",
953
1105
  value: function extractOrderIdFromSubmitResult(result) {
954
- var _ref3, _ref4, _ref5, _result$data$order_id, _result$data, _result$data2;
955
- return (_ref3 = (_ref4 = (_ref5 = (_result$data$order_id = result === null || result === void 0 || (_result$data = result.data) === null || _result$data === void 0 ? void 0 : _result$data.order_id) !== null && _result$data$order_id !== void 0 ? _result$data$order_id : result === null || result === void 0 ? void 0 : result.order_id) !== null && _ref5 !== void 0 ? _ref5 : result === null || result === void 0 || (_result$data2 = result.data) === null || _result$data2 === void 0 ? void 0 : _result$data2.id) !== null && _ref4 !== void 0 ? _ref4 : result === null || result === void 0 ? void 0 : result.id) !== null && _ref3 !== void 0 ? _ref3 : null;
1106
+ var _ref14, _ref15, _ref16, _result$data$order_id, _result$data, _result$data2;
1107
+ return (_ref14 = (_ref15 = (_ref16 = (_result$data$order_id = result === null || result === void 0 || (_result$data = result.data) === null || _result$data === void 0 ? void 0 : _result$data.order_id) !== null && _result$data$order_id !== void 0 ? _result$data$order_id : result === null || result === void 0 ? void 0 : result.order_id) !== null && _ref16 !== void 0 ? _ref16 : result === null || result === void 0 || (_result$data2 = result.data) === null || _result$data2 === void 0 ? void 0 : _result$data2.id) !== null && _ref15 !== void 0 ? _ref15 : result === null || result === void 0 ? void 0 : result.id) !== null && _ref14 !== void 0 ? _ref14 : null;
956
1108
  }
957
1109
  }, {
958
1110
  key: "calculatePaymentEffectiveAmount",
@@ -974,7 +1126,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
974
1126
  }, {
975
1127
  key: "normalizePaymentSource",
976
1128
  value: function normalizePaymentSource(payment, options) {
977
- var _ref6, _paymentRecord$origin;
1129
+ var _ref17, _paymentRecord$origin;
978
1130
  var paymentRecord = payment;
979
1131
  var metadata = paymentRecord.metadata && _typeof(paymentRecord.metadata) === 'object' ? _objectSpread({}, paymentRecord.metadata) : {};
980
1132
  if (!metadata.unique_identification_number) {
@@ -982,7 +1134,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
982
1134
  }
983
1135
  var normalized = _objectSpread(_objectSpread({}, paymentRecord), {}, {
984
1136
  metadata: metadata,
985
- origin_amount: (_ref6 = (_paymentRecord$origin = paymentRecord.origin_amount) !== null && _paymentRecord$origin !== void 0 ? _paymentRecord$origin : paymentRecord.amount) !== null && _ref6 !== void 0 ? _ref6 : '0.00'
1137
+ origin_amount: (_ref17 = (_paymentRecord$origin = paymentRecord.origin_amount) !== null && _paymentRecord$origin !== void 0 ? _paymentRecord$origin : paymentRecord.amount) !== null && _ref17 !== void 0 ? _ref17 : '0.00'
986
1138
  });
987
1139
  if (paymentRecord.status !== undefined) {
988
1140
  normalized.status = paymentRecord.status;
@@ -1054,11 +1206,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1054
1206
  if (targetAmount.lte(0)) return [];
1055
1207
  var remainingAmount = Decimal.max(targetAmount.minus(nonVoucherTotal), 0);
1056
1208
  var cappedVouchers = [];
1057
- var _iterator5 = _createForOfIteratorHelper(params.vouchers),
1058
- _step5;
1209
+ var _iterator7 = _createForOfIteratorHelper(params.vouchers),
1210
+ _step7;
1059
1211
  try {
1060
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
1061
- var voucher = _step5.value;
1212
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
1213
+ var voucher = _step7.value;
1062
1214
  if (remainingAmount.lte(0)) break;
1063
1215
  var voucherAmount = Decimal.max(new Decimal(voucher.amount || 0), 0);
1064
1216
  if (voucherAmount.lte(0)) continue;
@@ -1072,9 +1224,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1072
1224
  remainingAmount = remainingAmount.minus(cappedAmount);
1073
1225
  }
1074
1226
  } catch (err) {
1075
- _iterator5.e(err);
1227
+ _iterator7.e(err);
1076
1228
  } finally {
1077
- _iterator5.f();
1229
+ _iterator7.f();
1078
1230
  }
1079
1231
  return cappedVouchers;
1080
1232
  }
@@ -1089,13 +1241,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1089
1241
  customerPaidAmount: summary.customerPaidAmount.plus(paymentRecord.amount || 0),
1090
1242
  orderPaidAmount: summary.orderPaidAmount.plus(paymentRecord.origin_amount || 0),
1091
1243
  gapPaidAmount: summary.gapPaidAmount.plus(_this4.calculatePaymentGapAmount(paymentRecord)),
1092
- payServiceChargeAmount: summary.payServiceChargeAmount.plus(_this4.calculatePaymentServiceFee(paymentRecord))
1244
+ payServiceChargeAmount: summary.payServiceChargeAmount.plus(_this4.calculatePaymentServiceFee(paymentRecord)),
1245
+ roundingAmount: summary.roundingAmount.plus(_this4.calculatePaymentRoundingAmount(paymentRecord))
1093
1246
  };
1094
1247
  }, {
1095
1248
  customerPaidAmount: new Decimal(0),
1096
1249
  orderPaidAmount: new Decimal(0),
1097
1250
  gapPaidAmount: new Decimal(0),
1098
- payServiceChargeAmount: new Decimal(0)
1251
+ payServiceChargeAmount: new Decimal(0),
1252
+ roundingAmount: new Decimal(0)
1099
1253
  });
1100
1254
  }
1101
1255
  }, {
@@ -1118,6 +1272,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1118
1272
  var rounding = new Decimal(payment.rounding_amount || 0);
1119
1273
  return new Decimal(payment.origin_amount || 0).minus(rounding);
1120
1274
  }
1275
+ }, {
1276
+ key: "calculatePaymentRoundingAmount",
1277
+ value: function calculatePaymentRoundingAmount(payment) {
1278
+ if (payment.rounding_amount === undefined || payment.rounding_amount === null || payment.rounding_amount === '') {
1279
+ return new Decimal(0);
1280
+ }
1281
+ return new Decimal(payment.rounding_amount || 0);
1282
+ }
1121
1283
  }, {
1122
1284
  key: "formatSummaryMetadataMoney",
1123
1285
  value: function formatSummaryMetadataMoney(value) {
@@ -1129,28 +1291,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1129
1291
  key: "syncSummaryProductMetadata",
1130
1292
  value: function syncSummaryProductMetadata(products) {
1131
1293
  var moneyKeys = ['main_product_attached_bundle_surcharge_fee', 'main_product_attached_bundle_tax_fee', 'surcharge_rounding_remainder', 'tax_fee_rounding_remainder'];
1132
- var _iterator6 = _createForOfIteratorHelper(products || []),
1133
- _step6;
1294
+ var _iterator8 = _createForOfIteratorHelper(products || []),
1295
+ _step8;
1134
1296
  try {
1135
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
1136
- var product = _step6.value;
1297
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
1298
+ var product = _step8.value;
1137
1299
  var productRecord = product;
1138
1300
  var metadata = productRecord.metadata && _typeof(productRecord.metadata) === 'object' ? _objectSpread({}, productRecord.metadata) : {};
1139
1301
  var hasMetadataPatch = false;
1140
- var _iterator7 = _createForOfIteratorHelper(moneyKeys),
1141
- _step7;
1302
+ var _iterator9 = _createForOfIteratorHelper(moneyKeys),
1303
+ _step9;
1142
1304
  try {
1143
- for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
1144
- var key = _step7.value;
1305
+ for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
1306
+ var key = _step9.value;
1145
1307
  var value = this.formatSummaryMetadataMoney(productRecord[key]);
1146
1308
  if (value === undefined) continue;
1147
1309
  metadata[key] = value;
1148
1310
  hasMetadataPatch = true;
1149
1311
  }
1150
1312
  } catch (err) {
1151
- _iterator7.e(err);
1313
+ _iterator9.e(err);
1152
1314
  } finally {
1153
- _iterator7.f();
1315
+ _iterator9.f();
1154
1316
  }
1155
1317
  if (Array.isArray(productRecord.relation_surcharge_ids)) {
1156
1318
  metadata.relation_surcharge_ids = productRecord.relation_surcharge_ids;
@@ -1158,11 +1320,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1158
1320
  }
1159
1321
  if (hasMetadataPatch) productRecord.metadata = metadata;
1160
1322
  if (!Array.isArray(productRecord.product_bundle)) continue;
1161
- var _iterator8 = _createForOfIteratorHelper(productRecord.product_bundle),
1162
- _step8;
1323
+ var _iterator10 = _createForOfIteratorHelper(productRecord.product_bundle),
1324
+ _step10;
1163
1325
  try {
1164
- for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
1165
- var bundle = _step8.value;
1326
+ for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
1327
+ var bundle = _step10.value;
1166
1328
  var bundleRecord = bundle;
1167
1329
  var bundleMetadata = bundleRecord.metadata && _typeof(bundleRecord.metadata) === 'object' ? _objectSpread({}, bundleRecord.metadata) : {};
1168
1330
  var hasBundleMetadataPatch = false;
@@ -1178,15 +1340,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1178
1340
  if (hasBundleMetadataPatch) bundleRecord.metadata = bundleMetadata;
1179
1341
  }
1180
1342
  } catch (err) {
1181
- _iterator8.e(err);
1343
+ _iterator10.e(err);
1182
1344
  } finally {
1183
- _iterator8.f();
1345
+ _iterator10.f();
1184
1346
  }
1185
1347
  }
1186
1348
  } catch (err) {
1187
- _iterator6.e(err);
1349
+ _iterator8.e(err);
1188
1350
  } finally {
1189
- _iterator6.f();
1351
+ _iterator8.f();
1190
1352
  }
1191
1353
  }
1192
1354
  }, {
@@ -1210,7 +1372,326 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1210
1372
  value: function calculatePaymentTargetAmount(tempOrder, summary) {
1211
1373
  var depositAmount = summary.deposit_amount || tempOrder.deposit_amount || '0.00';
1212
1374
  var isDeposit = tempOrder.is_deposit === 1 || new Decimal(depositAmount || 0).gt(0);
1213
- return isDeposit ? new Decimal(depositAmount || 0) : new Decimal(summary.total_amount || summary.expect_amount || 0);
1375
+ return isDeposit ? new Decimal(depositAmount || 0) : new Decimal(summary.expect_amount || summary.total_amount || 0);
1376
+ }
1377
+ }, {
1378
+ key: "normalizeFingerprintMoney",
1379
+ value: function normalizeFingerprintMoney(value) {
1380
+ if (value === undefined || value === null || value === '') return '';
1381
+ try {
1382
+ var parsed = new Decimal(String(value || 0));
1383
+ return parsed.toFixed(4);
1384
+ } catch (_unused2) {
1385
+ return String(value);
1386
+ }
1387
+ }
1388
+ }, {
1389
+ key: "normalizeFingerprintValue",
1390
+ value: function normalizeFingerprintValue(value) {
1391
+ var _this5 = this;
1392
+ if (Array.isArray(value)) {
1393
+ return value.map(function (item) {
1394
+ return _this5.normalizeFingerprintValue(item);
1395
+ });
1396
+ }
1397
+ if (!value || _typeof(value) !== 'object') return value !== null && value !== void 0 ? value : '';
1398
+ return Object.keys(value).sort().reduce(function (result, key) {
1399
+ result[key] = _this5.normalizeFingerprintValue(value[key]);
1400
+ return result;
1401
+ }, {});
1402
+ }
1403
+ }, {
1404
+ key: "buildProductFingerprintItem",
1405
+ value: function buildProductFingerprintItem(product) {
1406
+ var _product$product_id2,
1407
+ _product$product_vari,
1408
+ _product$num,
1409
+ _product$payment_pric,
1410
+ _sku$code,
1411
+ _sku$barcode,
1412
+ _ref18,
1413
+ _sku$variant_id,
1414
+ _this6 = this;
1415
+ var sku = (product === null || product === void 0 ? void 0 : product.product_sku) || {};
1416
+ var metadata = (product === null || product === void 0 ? void 0 : product.metadata) || {};
1417
+ var discountTypes = ((product === null || product === void 0 ? void 0 : product.discount_list) || []).map(function (discount) {
1418
+ var _discount$type;
1419
+ return (_discount$type = discount === null || discount === void 0 ? void 0 : discount.type) !== null && _discount$type !== void 0 ? _discount$type : discount === null || discount === void 0 ? void 0 : discount.tag;
1420
+ });
1421
+ var extensionType = (product === null || product === void 0 ? void 0 : product.extension_type) || (discountTypes.includes('good_pass') ? 'good_pass' : 'normal');
1422
+ return {
1423
+ product_id: (_product$product_id2 = product === null || product === void 0 ? void 0 : product.product_id) !== null && _product$product_id2 !== void 0 ? _product$product_id2 : null,
1424
+ product_variant_id: (_product$product_vari = product === null || product === void 0 ? void 0 : product.product_variant_id) !== null && _product$product_vari !== void 0 ? _product$product_vari : null,
1425
+ extension_type: extensionType,
1426
+ num: getSafeProductNum((_product$num = product === null || product === void 0 ? void 0 : product.num) !== null && _product$num !== void 0 ? _product$num : product === null || product === void 0 ? void 0 : product.product_quantity),
1427
+ selling_price: this.normalizeFingerprintMoney(product === null || product === void 0 ? void 0 : product.selling_price),
1428
+ original_price: this.normalizeFingerprintMoney(product === null || product === void 0 ? void 0 : product.original_price),
1429
+ payment_price: this.normalizeFingerprintMoney((_product$payment_pric = product === null || product === void 0 ? void 0 : product.payment_price) !== null && _product$payment_pric !== void 0 ? _product$payment_pric : product === null || product === void 0 ? void 0 : product.selling_price),
1430
+ metadata: {
1431
+ source_product_price: this.normalizeFingerprintMoney(metadata.source_product_price),
1432
+ main_product_selling_price: this.normalizeFingerprintMoney(metadata.main_product_selling_price),
1433
+ main_product_original_price: this.normalizeFingerprintMoney(metadata.main_product_original_price),
1434
+ product_discount_difference: this.normalizeFingerprintMoney(metadata.product_discount_difference)
1435
+ },
1436
+ product_sku: this.normalizeFingerprintValue({
1437
+ code: (_sku$code = sku.code) !== null && _sku$code !== void 0 ? _sku$code : '',
1438
+ barcode: (_sku$barcode = sku.barcode) !== null && _sku$barcode !== void 0 ? _sku$barcode : '',
1439
+ variant_id: (_ref18 = (_sku$variant_id = sku.variant_id) !== null && _sku$variant_id !== void 0 ? _sku$variant_id : product === null || product === void 0 ? void 0 : product.product_variant_id) !== null && _ref18 !== void 0 ? _ref18 : 0,
1440
+ variant: sku.variant || [],
1441
+ option: getProductSkuOptions(product || {}).map(function (option) {
1442
+ var _ref19, _option$id, _option$option_group_, _ref20, _option$option_group_2, _option$num, _option$add_price;
1443
+ return {
1444
+ id: (_ref19 = (_option$id = option === null || option === void 0 ? void 0 : option.id) !== null && _option$id !== void 0 ? _option$id : option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _ref19 !== void 0 ? _ref19 : null,
1445
+ 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,
1446
+ option_group_item_id: (_ref20 = (_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 && _ref20 !== void 0 ? _ref20 : null,
1447
+ num: Number((_option$num = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num !== void 0 ? _option$num : 1) || 1,
1448
+ add_price: _this6.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)
1449
+ };
1450
+ })
1451
+ }),
1452
+ product_bundle: this.normalizeFingerprintValue(((product === null || product === void 0 ? void 0 : product.product_bundle) || []).map(function (bundle) {
1453
+ var _ref21, _ref22, _bundle$bundle_produc, _ref23, _bundle$bundle_varian, _bundle$num, _bundle$price_type, _bundle$price_type_ex;
1454
+ return {
1455
+ bundle_product_id: (_ref21 = (_ref22 = (_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 && _ref22 !== void 0 ? _ref22 : bundle === null || bundle === void 0 ? void 0 : bundle.product_id) !== null && _ref21 !== void 0 ? _ref21 : null,
1456
+ bundle_variant_id: (_ref23 = (_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 && _ref23 !== void 0 ? _ref23 : 0,
1457
+ 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),
1458
+ price: _this6.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.price),
1459
+ bundle_selling_price: _this6.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.bundle_selling_price),
1460
+ price_type: (_bundle$price_type = bundle === null || bundle === void 0 ? void 0 : bundle.price_type) !== null && _bundle$price_type !== void 0 ? _bundle$price_type : '',
1461
+ 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 : ''
1462
+ };
1463
+ })),
1464
+ discount_list: this.normalizeFingerprintValue(((product === null || product === void 0 ? void 0 : product.discount_list) || []).map(function (discount) {
1465
+ var _ref24, _discount$type2, _ref25, _ref26, _discount$discount_id, _discount$discount;
1466
+ return {
1467
+ type: (_ref24 = (_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 && _ref24 !== void 0 ? _ref24 : '',
1468
+ discount_id: (_ref25 = (_ref26 = (_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 && _ref26 !== void 0 ? _ref26 : discount === null || discount === void 0 || (_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) !== null && _ref25 !== void 0 ? _ref25 : null,
1469
+ amount: _this6.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
1470
+ };
1471
+ }))
1472
+ };
1473
+ }
1474
+ }, {
1475
+ key: "buildOrderProductsFingerprint",
1476
+ value: function buildOrderProductsFingerprint(products) {
1477
+ var _this7 = this;
1478
+ var items = (products || []).map(function (product) {
1479
+ return _this7.buildProductFingerprintItem(product);
1480
+ });
1481
+ items.sort(function (left, right) {
1482
+ return JSON.stringify(left).localeCompare(JSON.stringify(right));
1483
+ });
1484
+ return JSON.stringify(items);
1485
+ }
1486
+ }, {
1487
+ key: "buildProductStructuralFingerprintItem",
1488
+ value: function buildProductStructuralFingerprintItem(product) {
1489
+ var _product$product_id3,
1490
+ _product$product_vari2,
1491
+ _product$num2,
1492
+ _ref27,
1493
+ _metadata$unique_iden,
1494
+ _metadata$price_overr,
1495
+ _metadata$is_manual_d,
1496
+ _metadata$product_dis,
1497
+ _sku$code2,
1498
+ _sku$barcode2,
1499
+ _ref28,
1500
+ _sku$variant_id2,
1501
+ _this8 = this;
1502
+ var sku = (product === null || product === void 0 ? void 0 : product.product_sku) || {};
1503
+ var metadata = (product === null || product === void 0 ? void 0 : product.metadata) || {};
1504
+ var discountTypes = ((product === null || product === void 0 ? void 0 : product.discount_list) || []).map(function (discount) {
1505
+ var _discount$type3;
1506
+ return (_discount$type3 = discount === null || discount === void 0 ? void 0 : discount.type) !== null && _discount$type3 !== void 0 ? _discount$type3 : discount === null || discount === void 0 ? void 0 : discount.tag;
1507
+ });
1508
+ var extensionType = (product === null || product === void 0 ? void 0 : product.extension_type) || (discountTypes.includes('good_pass') ? 'good_pass' : 'normal');
1509
+ return {
1510
+ product_id: (_product$product_id3 = product === null || product === void 0 ? void 0 : product.product_id) !== null && _product$product_id3 !== void 0 ? _product$product_id3 : null,
1511
+ product_variant_id: (_product$product_vari2 = product === null || product === void 0 ? void 0 : product.product_variant_id) !== null && _product$product_vari2 !== void 0 ? _product$product_vari2 : null,
1512
+ extension_type: extensionType,
1513
+ num: getSafeProductNum((_product$num2 = product === null || product === void 0 ? void 0 : product.num) !== null && _product$num2 !== void 0 ? _product$num2 : product === null || product === void 0 ? void 0 : product.product_quantity),
1514
+ metadata: {
1515
+ unique_identification_number: (_ref27 = (_metadata$unique_iden = metadata.unique_identification_number) !== null && _metadata$unique_iden !== void 0 ? _metadata$unique_iden : product === null || product === void 0 ? void 0 : product.unique_identification_number) !== null && _ref27 !== void 0 ? _ref27 : '',
1516
+ price_override: (_metadata$price_overr = metadata.price_override) !== null && _metadata$price_overr !== void 0 ? _metadata$price_overr : '',
1517
+ is_manual_discount: (_metadata$is_manual_d = metadata.is_manual_discount) !== null && _metadata$is_manual_d !== void 0 ? _metadata$is_manual_d : '',
1518
+ product_discount_reason: (_metadata$product_dis = metadata.product_discount_reason) !== null && _metadata$product_dis !== void 0 ? _metadata$product_dis : ''
1519
+ },
1520
+ product_sku: this.normalizeFingerprintValue({
1521
+ code: (_sku$code2 = sku.code) !== null && _sku$code2 !== void 0 ? _sku$code2 : '',
1522
+ barcode: (_sku$barcode2 = sku.barcode) !== null && _sku$barcode2 !== void 0 ? _sku$barcode2 : '',
1523
+ variant_id: (_ref28 = (_sku$variant_id2 = sku.variant_id) !== null && _sku$variant_id2 !== void 0 ? _sku$variant_id2 : product === null || product === void 0 ? void 0 : product.product_variant_id) !== null && _ref28 !== void 0 ? _ref28 : 0,
1524
+ variant: sku.variant || [],
1525
+ option: getProductSkuOptions(product || {}).map(function (option) {
1526
+ var _ref29, _option$id2, _option$option_group_3, _ref30, _option$option_group_4, _option$num2, _option$add_price2;
1527
+ return {
1528
+ id: (_ref29 = (_option$id2 = option === null || option === void 0 ? void 0 : option.id) !== null && _option$id2 !== void 0 ? _option$id2 : option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _ref29 !== void 0 ? _ref29 : null,
1529
+ 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,
1530
+ option_group_item_id: (_ref30 = (_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 && _ref30 !== void 0 ? _ref30 : null,
1531
+ num: Number((_option$num2 = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num2 !== void 0 ? _option$num2 : 1) || 1,
1532
+ add_price: _this8.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)
1533
+ };
1534
+ })
1535
+ }),
1536
+ product_bundle: this.normalizeFingerprintValue(((product === null || product === void 0 ? void 0 : product.product_bundle) || []).map(function (bundle) {
1537
+ var _ref31, _bundle$bundle_id, _ref32, _bundle$bundle_group_, _ref33, _ref34, _bundle$bundle_produc2, _ref35, _bundle$bundle_varian2, _bundle$num2, _bundle$price_type2, _bundle$price_type_ex2;
1538
+ return {
1539
+ bundle_id: (_ref31 = (_bundle$bundle_id = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_id) !== null && _bundle$bundle_id !== void 0 ? _bundle$bundle_id : bundle === null || bundle === void 0 ? void 0 : bundle.id) !== null && _ref31 !== void 0 ? _ref31 : null,
1540
+ bundle_group_id: (_ref32 = (_bundle$bundle_group_ = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_group_id) !== null && _bundle$bundle_group_ !== void 0 ? _bundle$bundle_group_ : bundle === null || bundle === void 0 ? void 0 : bundle.group_id) !== null && _ref32 !== void 0 ? _ref32 : null,
1541
+ bundle_product_id: (_ref33 = (_ref34 = (_bundle$bundle_produc2 = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_product_id) !== null && _bundle$bundle_produc2 !== void 0 ? _bundle$bundle_produc2 : bundle === null || bundle === void 0 ? void 0 : bundle._bundle_product_id) !== null && _ref34 !== void 0 ? _ref34 : bundle === null || bundle === void 0 ? void 0 : bundle.product_id) !== null && _ref33 !== void 0 ? _ref33 : null,
1542
+ bundle_variant_id: (_ref35 = (_bundle$bundle_varian2 = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_variant_id) !== null && _bundle$bundle_varian2 !== void 0 ? _bundle$bundle_varian2 : bundle === null || bundle === void 0 ? void 0 : bundle.product_variant_id) !== null && _ref35 !== void 0 ? _ref35 : 0,
1543
+ 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),
1544
+ price_type: (_bundle$price_type2 = bundle === null || bundle === void 0 ? void 0 : bundle.price_type) !== null && _bundle$price_type2 !== void 0 ? _bundle$price_type2 : '',
1545
+ 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 : '',
1546
+ option: _this8.normalizeFingerprintValue(((bundle === null || bundle === void 0 ? void 0 : bundle.option) || []).map(function (option) {
1547
+ var _ref36, _option$id3, _option$option_group_5, _ref37, _option$option_group_6, _option$num3, _option$add_price3;
1548
+ return {
1549
+ id: (_ref36 = (_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 && _ref36 !== void 0 ? _ref36 : null,
1550
+ 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,
1551
+ option_group_item_id: (_ref37 = (_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 && _ref37 !== void 0 ? _ref37 : null,
1552
+ num: Number((_option$num3 = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num3 !== void 0 ? _option$num3 : 1) || 1,
1553
+ add_price: _this8.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)
1554
+ };
1555
+ }))
1556
+ };
1557
+ })),
1558
+ discount_list: this.normalizeFingerprintValue(((product === null || product === void 0 ? void 0 : product.discount_list) || []).map(function (discount) {
1559
+ var _ref38, _discount$type4, _ref39, _ref40, _discount$discount_id2, _discount$discount2;
1560
+ return {
1561
+ type: (_ref38 = (_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 && _ref38 !== void 0 ? _ref38 : '',
1562
+ discount_id: (_ref39 = (_ref40 = (_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 && _ref40 !== void 0 ? _ref40 : discount === null || discount === void 0 || (_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.resource_id) !== null && _ref39 !== void 0 ? _ref39 : null,
1563
+ amount: _this8.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
1564
+ };
1565
+ }))
1566
+ };
1567
+ }
1568
+ }, {
1569
+ key: "buildOrderProductsStructuralFingerprint",
1570
+ value: function buildOrderProductsStructuralFingerprint(products) {
1571
+ var _this9 = this;
1572
+ var items = (products || []).map(function (product) {
1573
+ return _this9.buildProductStructuralFingerprintItem(product);
1574
+ });
1575
+ items.sort(function (left, right) {
1576
+ return JSON.stringify(left).localeCompare(JSON.stringify(right));
1577
+ });
1578
+ return JSON.stringify(items);
1579
+ }
1580
+ }, {
1581
+ key: "getOriginalSalesSnapshot",
1582
+ value: function getOriginalSalesSnapshot(tempOrder) {
1583
+ var _tempOrder$_extend3;
1584
+ var snapshot = (_tempOrder$_extend3 = tempOrder._extend) === null || _tempOrder$_extend3 === void 0 ? void 0 : _tempOrder$_extend3.originalSalesSnapshot;
1585
+ if (!snapshot || _typeof(snapshot) !== 'object') return null;
1586
+ if (typeof snapshot.productFingerprint !== 'string') return null;
1587
+ return snapshot;
1588
+ }
1589
+ }, {
1590
+ key: "restoreOriginalSnapshotIfProductsUnchanged",
1591
+ value: function restoreOriginalSnapshotIfProductsUnchanged(tempOrder) {
1592
+ var snapshot = this.getOriginalSalesSnapshot(tempOrder);
1593
+ if (!snapshot) return null;
1594
+ var currentFingerprint = this.buildOrderProductsFingerprint(tempOrder.products);
1595
+ if (currentFingerprint !== snapshot.productFingerprint) {
1596
+ var currentStructuralFingerprint = this.buildOrderProductsStructuralFingerprint(tempOrder.products);
1597
+ var snapshotStructuralFingerprint = this.buildOrderProductsStructuralFingerprint(Array.isArray(snapshot.products) ? snapshot.products : []);
1598
+ if (currentStructuralFingerprint !== snapshotStructuralFingerprint) return null;
1599
+ }
1600
+ var summary = _objectSpread(_objectSpread({}, createEmptySummary()), cloneDeep(snapshot.summary || {}));
1601
+ if (Array.isArray(snapshot.products)) {
1602
+ tempOrder.products = cloneDeep(snapshot.products);
1603
+ }
1604
+ if (Array.isArray(snapshot.surcharges)) {
1605
+ tempOrder.surcharges = cloneDeep(snapshot.surcharges);
1606
+ }
1607
+ tempOrder.surcharge_fee = summary.surcharge_fee || tempOrder.surcharge_fee;
1608
+ tempOrder.deposit_amount = summary.deposit_amount || '0.00';
1609
+ tempOrder.is_deposit = summary.deposit_amount !== '0.00' ? 1 : 0;
1610
+ this.store.summary = summary;
1611
+ return summary;
1612
+ }
1613
+ }, {
1614
+ key: "clearPersistedAmountFieldsForFullRecalc",
1615
+ value: function clearPersistedAmountFieldsForFullRecalc(products) {
1616
+ var moneyKeys = ['surcharge_fee', 'main_product_attached_bundle_surcharge_fee', 'surcharge_rounding_remainder', 'main_product_attached_bundle_tax_fee', 'tax_fee', 'original_tax_fee', 'tax_fee_rounding_remainder', 'original_tax_fee_rounding_remainder'];
1617
+ var metadataMoneyKeys = ['main_product_attached_bundle_surcharge_fee', 'surcharge_rounding_remainder', 'main_product_attached_bundle_tax_fee', 'tax_fee_rounding_remainder'];
1618
+ var _iterator11 = _createForOfIteratorHelper(products || []),
1619
+ _step11;
1620
+ try {
1621
+ for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
1622
+ var product = _step11.value;
1623
+ var record = product;
1624
+ var _iterator12 = _createForOfIteratorHelper(moneyKeys),
1625
+ _step12;
1626
+ try {
1627
+ for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
1628
+ var _key = _step12.value;
1629
+ delete record[_key];
1630
+ }
1631
+ } catch (err) {
1632
+ _iterator12.e(err);
1633
+ } finally {
1634
+ _iterator12.f();
1635
+ }
1636
+ if (record.metadata && _typeof(record.metadata) === 'object') {
1637
+ record.metadata = _objectSpread({}, record.metadata);
1638
+ var _iterator13 = _createForOfIteratorHelper(metadataMoneyKeys),
1639
+ _step13;
1640
+ try {
1641
+ for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
1642
+ var key = _step13.value;
1643
+ delete record.metadata[key];
1644
+ }
1645
+ } catch (err) {
1646
+ _iterator13.e(err);
1647
+ } finally {
1648
+ _iterator13.f();
1649
+ }
1650
+ }
1651
+ var _iterator14 = _createForOfIteratorHelper(record.product_bundle || []),
1652
+ _step14;
1653
+ try {
1654
+ for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
1655
+ var bundle = _step14.value;
1656
+ var _iterator15 = _createForOfIteratorHelper(moneyKeys),
1657
+ _step15;
1658
+ try {
1659
+ for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
1660
+ var _key3 = _step15.value;
1661
+ delete bundle[_key3];
1662
+ }
1663
+ } catch (err) {
1664
+ _iterator15.e(err);
1665
+ } finally {
1666
+ _iterator15.f();
1667
+ }
1668
+ if (bundle.metadata && _typeof(bundle.metadata) === 'object') {
1669
+ bundle.metadata = _objectSpread({}, bundle.metadata);
1670
+ var _iterator16 = _createForOfIteratorHelper(metadataMoneyKeys),
1671
+ _step16;
1672
+ try {
1673
+ for (_iterator16.s(); !(_step16 = _iterator16.n()).done;) {
1674
+ var _key2 = _step16.value;
1675
+ delete bundle.metadata[_key2];
1676
+ }
1677
+ } catch (err) {
1678
+ _iterator16.e(err);
1679
+ } finally {
1680
+ _iterator16.f();
1681
+ }
1682
+ }
1683
+ }
1684
+ } catch (err) {
1685
+ _iterator14.e(err);
1686
+ } finally {
1687
+ _iterator14.f();
1688
+ }
1689
+ }
1690
+ } catch (err) {
1691
+ _iterator11.e(err);
1692
+ } finally {
1693
+ _iterator11.f();
1694
+ }
1214
1695
  }
1215
1696
  }, {
1216
1697
  key: "getPaymentTargetAmount",
@@ -1235,15 +1716,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1235
1716
  }, {
1236
1717
  key: "restoreOrder",
1237
1718
  value: function restoreOrder() {
1238
- var _this$store$discount9, _this$store$discount10;
1719
+ var _this$store$discount11, _this$store$discount12;
1239
1720
  var freshTempOrder = this.createDefaultTempOrderInstance();
1240
1721
  this.ensureExternalSaleNumber(freshTempOrder);
1241
1722
  this.store.tempOrder = freshTempOrder;
1242
1723
  this.store.summary = createEmptySummary();
1243
1724
  this.store.lastOrderInfo = undefined;
1244
1725
  this.store.syncState = undefined;
1245
- void ((_this$store$discount9 = this.store.discount) === null || _this$store$discount9 === void 0 ? void 0 : _this$store$discount9.setOriginalDiscountList([]));
1246
- void ((_this$store$discount10 = this.store.discount) === null || _this$store$discount10 === void 0 ? void 0 : _this$store$discount10.setDiscountList([]));
1726
+ void ((_this$store$discount11 = this.store.discount) === null || _this$store$discount11 === void 0 ? void 0 : _this$store$discount11.setOriginalDiscountList([]));
1727
+ void ((_this$store$discount12 = this.store.discount) === null || _this$store$discount12 === void 0 ? void 0 : _this$store$discount12.setDiscountList([]));
1247
1728
  this.persistTempOrder();
1248
1729
  return freshTempOrder;
1249
1730
  }
@@ -1255,13 +1736,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1255
1736
  }, {
1256
1737
  key: "replaceTempOrder",
1257
1738
  value: function () {
1258
- var _replaceTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(tempOrder, options) {
1739
+ var _replaceTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(tempOrder, options) {
1259
1740
  var nextTempOrder;
1260
- return _regeneratorRuntime().wrap(function _callee7$(_context9) {
1261
- while (1) switch (_context9.prev = _context9.next) {
1741
+ return _regeneratorRuntime().wrap(function _callee8$(_context10) {
1742
+ while (1) switch (_context10.prev = _context10.next) {
1262
1743
  case 0:
1263
1744
  if (isTempOrder(tempOrder)) {
1264
- _context9.next = 2;
1745
+ _context10.next = 2;
1265
1746
  break;
1266
1747
  }
1267
1748
  throw new Error('无效的 tempOrder 数据');
@@ -1271,15 +1752,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1271
1752
  });
1272
1753
  this.store.tempOrder = nextTempOrder;
1273
1754
  if (!((options === null || options === void 0 ? void 0 : options.recalculateSummary) !== false)) {
1274
- _context9.next = 9;
1755
+ _context10.next = 9;
1275
1756
  break;
1276
1757
  }
1277
- _context9.next = 7;
1758
+ _context10.next = 7;
1278
1759
  return this.recalculateSummary({
1279
1760
  createIfMissing: false
1280
1761
  });
1281
1762
  case 7:
1282
- _context9.next = 10;
1763
+ _context10.next = 10;
1283
1764
  break;
1284
1765
  case 9:
1285
1766
  this.store.summary = createEmptySummary();
@@ -1288,20 +1769,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1288
1769
  this.persistTempOrder();
1289
1770
  }
1290
1771
  if (!(options !== null && options !== void 0 && options.saveDraft)) {
1291
- _context9.next = 14;
1772
+ _context10.next = 14;
1292
1773
  break;
1293
1774
  }
1294
- _context9.next = 14;
1775
+ _context10.next = 14;
1295
1776
  return this.saveDraft();
1296
1777
  case 14:
1297
- return _context9.abrupt("return", nextTempOrder);
1778
+ return _context10.abrupt("return", nextTempOrder);
1298
1779
  case 15:
1299
1780
  case "end":
1300
- return _context9.stop();
1781
+ return _context10.stop();
1301
1782
  }
1302
- }, _callee7, this);
1783
+ }, _callee8, this);
1303
1784
  }));
1304
- function replaceTempOrder(_x7, _x8) {
1785
+ function replaceTempOrder(_x8, _x9) {
1305
1786
  return _replaceTempOrder.apply(this, arguments);
1306
1787
  }
1307
1788
  return replaceTempOrder;
@@ -1309,13 +1790,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1309
1790
  }, {
1310
1791
  key: "getOrderIdentity",
1311
1792
  value: function getOrderIdentity() {
1312
- var _ref7, _ref8, _tempOrder$order_id, _tempOrder$_extend;
1793
+ var _ref41, _ref42, _tempOrder$order_id, _tempOrder$_extend4;
1313
1794
  var tempOrder = this.store.tempOrder;
1314
1795
  if (!tempOrder) return null;
1315
1796
  var lastOrderInfo = this.store.lastOrderInfo || {};
1316
- var orderId = (_ref7 = (_ref8 = (_tempOrder$order_id = tempOrder.order_id) !== null && _tempOrder$order_id !== void 0 ? _tempOrder$order_id : lastOrderInfo.order_id) !== null && _ref8 !== void 0 ? _ref8 : lastOrderInfo.id) !== null && _ref7 !== void 0 ? _ref7 : null;
1797
+ var orderId = (_ref41 = (_ref42 = (_tempOrder$order_id = tempOrder.order_id) !== null && _tempOrder$order_id !== void 0 ? _tempOrder$order_id : lastOrderInfo.order_id) !== null && _ref42 !== void 0 ? _ref42 : lastOrderInfo.id) !== null && _ref41 !== void 0 ? _ref41 : null;
1317
1798
  return {
1318
- localId: this.cacheId || ((_tempOrder$_extend = tempOrder._extend) === null || _tempOrder$_extend === void 0 ? void 0 : _tempOrder$_extend.localId),
1799
+ localId: this.cacheId || ((_tempOrder$_extend4 = tempOrder._extend) === null || _tempOrder$_extend4 === void 0 ? void 0 : _tempOrder$_extend4.localId),
1319
1800
  orderId: orderId,
1320
1801
  externalSaleNumber: tempOrder.external_sale_number || lastOrderInfo.external_sale_number || '',
1321
1802
  orderNumber: tempOrder.order_number || lastOrderInfo.order_number || '',
@@ -1387,32 +1868,32 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1387
1868
  }, {
1388
1869
  key: "addNewOrder",
1389
1870
  value: function () {
1390
- var _addNewOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
1871
+ var _addNewOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
1391
1872
  var tempOrder;
1392
- return _regeneratorRuntime().wrap(function _callee8$(_context10) {
1393
- while (1) switch (_context10.prev = _context10.next) {
1873
+ return _regeneratorRuntime().wrap(function _callee9$(_context11) {
1874
+ while (1) switch (_context11.prev = _context11.next) {
1394
1875
  case 0:
1395
1876
  tempOrder = this.ensureTempOrder();
1396
1877
  this.ensureExternalSaleNumber(tempOrder);
1397
- _context10.next = 4;
1878
+ _context11.next = 4;
1398
1879
  return this.recalculateSummary({
1399
1880
  createIfMissing: true
1400
1881
  });
1401
1882
  case 4:
1402
1883
  this.persistTempOrder();
1403
1884
  if (!this.draftPersistEnabled) {
1404
- _context10.next = 8;
1885
+ _context11.next = 8;
1405
1886
  break;
1406
1887
  }
1407
- _context10.next = 8;
1888
+ _context11.next = 8;
1408
1889
  return this.saveDraft();
1409
1890
  case 8:
1410
- return _context10.abrupt("return", tempOrder);
1891
+ return _context11.abrupt("return", tempOrder);
1411
1892
  case 9:
1412
1893
  case "end":
1413
- return _context10.stop();
1894
+ return _context11.stop();
1414
1895
  }
1415
- }, _callee8, this);
1896
+ }, _callee9, this);
1416
1897
  }));
1417
1898
  function addNewOrder() {
1418
1899
  return _addNewOrder.apply(this, arguments);
@@ -1445,9 +1926,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1445
1926
  }, {
1446
1927
  key: "sanitizeTempOrderProducts",
1447
1928
  value: function sanitizeTempOrderProducts(tempOrder) {
1448
- var _this5 = this;
1929
+ var _this10 = this;
1449
1930
  tempOrder.products = (tempOrder.products || []).map(function (product) {
1450
- return _this5.sanitizeOrderProductForTempOrder(product);
1931
+ return _this10.sanitizeOrderProductForTempOrder(product);
1451
1932
  });
1452
1933
  }
1453
1934
  }, {
@@ -1466,11 +1947,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1466
1947
  }, {
1467
1948
  key: "captureProductRuntime",
1468
1949
  value: function captureProductRuntime(tempOrder, rawProduct, normalizedProduct, existedUid) {
1469
- var _extend$productsByUid, _ref9, _rawProduct$_origin;
1950
+ var _extend$productsByUid, _ref43, _rawProduct$_origin;
1470
1951
  var uid = existedUid || this.getProductUid(normalizedProduct);
1471
1952
  var extend = this.ensureExtend(tempOrder);
1472
1953
  var existed = ((_extend$productsByUid = extend.productsByUid) === null || _extend$productsByUid === void 0 ? void 0 : _extend$productsByUid[uid]) || {};
1473
- var origin = (_ref9 = (_rawProduct$_origin = rawProduct._origin) !== null && _rawProduct$_origin !== void 0 ? _rawProduct$_origin : normalizedProduct._origin) !== null && _ref9 !== void 0 ? _ref9 : existed.origin;
1954
+ var origin = (_ref43 = (_rawProduct$_origin = rawProduct._origin) !== null && _rawProduct$_origin !== void 0 ? _rawProduct$_origin : normalizedProduct._origin) !== null && _ref43 !== void 0 ? _ref43 : existed.origin;
1474
1955
  extend.productsByUid[uid] = _objectSpread(_objectSpread({}, existed), origin !== undefined ? {
1475
1956
  origin: origin
1476
1957
  } : {});
@@ -1515,9 +1996,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1515
1996
  }, {
1516
1997
  key: "findBookingIndexByUniqueIdentificationNumber",
1517
1998
  value: function findBookingIndexByUniqueIdentificationNumber(tempOrder, uniqueIdentificationNumber) {
1518
- var _this6 = this;
1999
+ var _this11 = this;
1519
2000
  return (tempOrder.bookings || []).findIndex(function (booking) {
1520
- return _this6.getBookingUniqueIdentificationNumber(booking) === uniqueIdentificationNumber;
2001
+ return _this11.getBookingUniqueIdentificationNumber(booking) === uniqueIdentificationNumber;
1521
2002
  });
1522
2003
  }
1523
2004
  }, {
@@ -1525,12 +2006,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1525
2006
  value: function removeLinkedBookingsForProduct(tempOrder, product) {
1526
2007
  var _product$metadata5,
1527
2008
  _product$metadata6,
1528
- _this7 = this;
2009
+ _this12 = this;
1529
2010
  var productUid = (product === null || product === void 0 || (_product$metadata5 = product.metadata) === null || _product$metadata5 === void 0 ? void 0 : _product$metadata5.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
1530
2011
  var bookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_product$metadata6 = product.metadata) === null || _product$metadata6 === void 0 ? void 0 : _product$metadata6.booking_uid);
1531
2012
  if (!productUid && !bookingUid) return;
1532
2013
  tempOrder.bookings = (tempOrder.bookings || []).filter(function (booking) {
1533
- var currentBookingUid = _this7.getBookingUniqueIdentificationNumber(booking);
2014
+ var currentBookingUid = _this12.getBookingUniqueIdentificationNumber(booking);
1534
2015
  if (bookingUid && currentBookingUid === String(bookingUid)) return false;
1535
2016
  if (productUid && String((booking === null || booking === void 0 ? void 0 : booking.product_uid) || '') === String(productUid)) return false;
1536
2017
  return true;
@@ -1547,25 +2028,38 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1547
2028
  }, {
1548
2029
  key: "recalculateSummary",
1549
2030
  value: function () {
1550
- var _recalculateSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(options) {
1551
- var tempOrder, salesSummary, existedSummary, totalRefundAmount, paidPaymentSummary, emptyBaseSummary, emptySummary, salesSummaryResult, summaryForGap, summary;
1552
- return _regeneratorRuntime().wrap(function _callee9$(_context11) {
1553
- while (1) switch (_context11.prev = _context11.next) {
2031
+ var _recalculateSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(options) {
2032
+ var _ref44, _salesSummaryResult$e;
2033
+ var tempOrder, snapshotSummary, shouldFullRecalculateFromSnapshot, summaryProducts, salesSummary, existedSummary, totalRefundAmount, paidPaymentSummary, emptyBaseSummary, emptySummary, salesSummaryResult, roundingAmount, payServiceChargeAmount, hasSalesSummaryAmount, expectAmount, amountPaymentPatch, normalizedExpectAmountPatch, summaryForGap, summary;
2034
+ return _regeneratorRuntime().wrap(function _callee10$(_context12) {
2035
+ while (1) switch (_context12.prev = _context12.next) {
1554
2036
  case 0:
1555
2037
  tempOrder = options !== null && options !== void 0 && options.createIfMissing ? this.ensureTempOrder() : this.store.tempOrder;
1556
2038
  if (tempOrder) {
1557
- _context11.next = 3;
2039
+ _context12.next = 3;
1558
2040
  break;
1559
2041
  }
1560
- return _context11.abrupt("return", null);
2042
+ return _context12.abrupt("return", null);
1561
2043
  case 3:
1562
2044
  this.sanitizeTempOrderProducts(tempOrder);
2045
+ snapshotSummary = this.restoreOriginalSnapshotIfProductsUnchanged(tempOrder);
2046
+ if (!snapshotSummary) {
2047
+ _context12.next = 7;
2048
+ break;
2049
+ }
2050
+ return _context12.abrupt("return", snapshotSummary);
2051
+ case 7:
2052
+ shouldFullRecalculateFromSnapshot = Boolean(this.getOriginalSalesSnapshot(tempOrder));
2053
+ summaryProducts = shouldFullRecalculateFromSnapshot ? cloneDeep(tempOrder.products || []) : tempOrder.products;
2054
+ if (shouldFullRecalculateFromSnapshot) {
2055
+ this.clearPersistedAmountFieldsForFullRecalc(summaryProducts || []);
2056
+ }
1563
2057
  salesSummary = this.getSalesSummary();
1564
2058
  existedSummary = this.store.summary || createEmptySummary();
1565
2059
  totalRefundAmount = existedSummary.total_refund_amount || '0.00';
1566
2060
  paidPaymentSummary = this.calculatePaidPaymentSummary(tempOrder.payments || []);
1567
2061
  if (salesSummary) {
1568
- _context11.next = 15;
2062
+ _context12.next = 21;
1569
2063
  break;
1570
2064
  }
1571
2065
  emptyBaseSummary = _objectSpread(_objectSpread({}, createEmptySummary()), {}, {
@@ -1579,7 +2073,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1579
2073
  summary: emptyBaseSummary,
1580
2074
  orderPaidAmount: paidPaymentSummary.gapPaidAmount
1581
2075
  }),
1582
- pay_service_charge_amount: paidPaymentSummary.payServiceChargeAmount.toFixed(2)
2076
+ pay_service_charge_amount: paidPaymentSummary.payServiceChargeAmount.toFixed(2),
2077
+ rounding_amount: paidPaymentSummary.roundingAmount.toFixed(2)
1583
2078
  });
1584
2079
  tempOrder.surcharge_fee = emptySummary.surcharge_fee;
1585
2080
  this.store.summary = emptySummary;
@@ -1587,30 +2082,46 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1587
2082
  previousSummary: existedSummary,
1588
2083
  summary: emptySummary
1589
2084
  });
1590
- return _context11.abrupt("return", this.store.summary);
1591
- case 15:
1592
- _context11.next = 17;
2085
+ return _context12.abrupt("return", this.store.summary);
2086
+ case 21:
2087
+ _context12.next = 23;
1593
2088
  return salesSummary.getSummary({
1594
- products: tempOrder.products,
2089
+ products: summaryProducts,
1595
2090
  isPriceIncludeTax: tempOrder.is_price_include_tax,
1596
2091
  shopDiscount: tempOrder.shop_discount
1597
2092
  });
1598
- case 17:
1599
- salesSummaryResult = _context11.sent;
2093
+ case 23:
2094
+ salesSummaryResult = _context12.sent;
2095
+ if (shouldFullRecalculateFromSnapshot) {
2096
+ tempOrder.products = summaryProducts;
2097
+ }
1600
2098
  this.syncSummaryProductMetadata(tempOrder.products || []);
1601
- summaryForGap = _objectSpread(_objectSpread({}, salesSummaryResult), {}, {
2099
+ roundingAmount = paidPaymentSummary.roundingAmount;
2100
+ payServiceChargeAmount = paidPaymentSummary.payServiceChargeAmount;
2101
+ hasSalesSummaryAmount = salesSummaryResult.expect_amount !== undefined || salesSummaryResult.total_amount !== undefined;
2102
+ expectAmount = hasSalesSummaryAmount ? new Decimal((_ref44 = (_salesSummaryResult$e = salesSummaryResult.expect_amount) !== null && _salesSummaryResult$e !== void 0 ? _salesSummaryResult$e : salesSummaryResult.total_amount) !== null && _ref44 !== void 0 ? _ref44 : 0) : null;
2103
+ amountPaymentPatch = hasSalesSummaryAmount || !roundingAmount.eq(0) || !payServiceChargeAmount.eq(0) ? _objectSpread({
2104
+ rounding_amount: roundingAmount.toFixed(2)
2105
+ }, expectAmount ? {
2106
+ total_amount: Decimal.max(0, expectAmount.plus(roundingAmount).plus(payServiceChargeAmount)).toFixed(2)
2107
+ } : {}) : {};
2108
+ normalizedExpectAmountPatch = expectAmount && salesSummaryResult.expect_amount === undefined ? {
2109
+ expect_amount: expectAmount.toFixed(2)
2110
+ } : {};
2111
+ summaryForGap = _objectSpread(_objectSpread(_objectSpread({}, salesSummaryResult), {}, {
1602
2112
  total_refund_amount: totalRefundAmount
1603
- });
1604
- summary = _objectSpread(_objectSpread({}, salesSummaryResult), {}, {
2113
+ }, amountPaymentPatch), normalizedExpectAmountPatch);
2114
+ summary = _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, salesSummaryResult), {}, {
1605
2115
  total_refund_amount: totalRefundAmount,
1606
2116
  customer_paid_amount: paidPaymentSummary.customerPaidAmount.toFixed(2),
1607
- order_paid_amount: paidPaymentSummary.orderPaidAmount.toFixed(2),
2117
+ order_paid_amount: paidPaymentSummary.orderPaidAmount.toFixed(2)
2118
+ }, amountPaymentPatch), normalizedExpectAmountPatch), {}, {
1608
2119
  amount_gap: this.calculateSummaryAmountGap({
1609
2120
  tempOrder: tempOrder,
1610
2121
  summary: summaryForGap,
1611
2122
  orderPaidAmount: paidPaymentSummary.gapPaidAmount
1612
2123
  }),
1613
- pay_service_charge_amount: paidPaymentSummary.payServiceChargeAmount.toFixed(2)
2124
+ pay_service_charge_amount: payServiceChargeAmount.toFixed(2)
1614
2125
  });
1615
2126
  this.store.summary = summary;
1616
2127
  if (summary.is_price_include_tax !== undefined) {
@@ -1627,14 +2138,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1627
2138
  previousSummary: existedSummary,
1628
2139
  summary: summary
1629
2140
  });
1630
- return _context11.abrupt("return", this.store.summary);
1631
- case 30:
2141
+ return _context12.abrupt("return", this.store.summary);
2142
+ case 43:
1632
2143
  case "end":
1633
- return _context11.stop();
2144
+ return _context12.stop();
1634
2145
  }
1635
- }, _callee9, this);
2146
+ }, _callee10, this);
1636
2147
  }));
1637
- function recalculateSummary(_x9) {
2148
+ function recalculateSummary(_x10) {
1638
2149
  return _recalculateSummary.apply(this, arguments);
1639
2150
  }
1640
2151
  return recalculateSummary;
@@ -1642,30 +2153,30 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1642
2153
  }, {
1643
2154
  key: "getOrderSummary",
1644
2155
  value: function () {
1645
- var _getOrderSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
2156
+ var _getOrderSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
1646
2157
  var summary;
1647
- return _regeneratorRuntime().wrap(function _callee10$(_context12) {
1648
- while (1) switch (_context12.prev = _context12.next) {
2158
+ return _regeneratorRuntime().wrap(function _callee11$(_context13) {
2159
+ while (1) switch (_context13.prev = _context13.next) {
1649
2160
  case 0:
1650
- _context12.next = 2;
2161
+ _context13.next = 2;
1651
2162
  return this.recalculateSummary({
1652
2163
  createIfMissing: true
1653
2164
  });
1654
2165
  case 2:
1655
- summary = _context12.sent;
2166
+ summary = _context13.sent;
1656
2167
  if (summary) {
1657
- _context12.next = 5;
2168
+ _context13.next = 5;
1658
2169
  break;
1659
2170
  }
1660
- return _context12.abrupt("return", createEmptySummary());
2171
+ return _context13.abrupt("return", createEmptySummary());
1661
2172
  case 5:
1662
2173
  this.persistTempOrder();
1663
- return _context12.abrupt("return", summary);
2174
+ return _context13.abrupt("return", summary);
1664
2175
  case 7:
1665
2176
  case "end":
1666
- return _context12.stop();
2177
+ return _context13.stop();
1667
2178
  }
1668
- }, _callee10, this);
2179
+ }, _callee11, this);
1669
2180
  }));
1670
2181
  function getOrderSummary() {
1671
2182
  return _getOrderSummary.apply(this, arguments);
@@ -1689,23 +2200,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1689
2200
  }, {
1690
2201
  key: "syncTempOrderNoteToRemote",
1691
2202
  value: function () {
1692
- var _syncTempOrderNoteToRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(orderId, note) {
1693
- return _regeneratorRuntime().wrap(function _callee11$(_context13) {
1694
- while (1) switch (_context13.prev = _context13.next) {
2203
+ var _syncTempOrderNoteToRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(orderId, note) {
2204
+ return _regeneratorRuntime().wrap(function _callee12$(_context14) {
2205
+ while (1) switch (_context14.prev = _context14.next) {
1695
2206
  case 0:
1696
- _context13.next = 2;
2207
+ _context14.next = 2;
1697
2208
  return this.request.put("/order/order/".concat(orderId, "/note"), {
1698
2209
  note: note
1699
2210
  });
1700
2211
  case 2:
1701
- return _context13.abrupt("return", note);
2212
+ return _context14.abrupt("return", note);
1702
2213
  case 3:
1703
2214
  case "end":
1704
- return _context13.stop();
2215
+ return _context14.stop();
1705
2216
  }
1706
- }, _callee11, this);
2217
+ }, _callee12, this);
1707
2218
  }));
1708
- function syncTempOrderNoteToRemote(_x10, _x11) {
2219
+ function syncTempOrderNoteToRemote(_x11, _x12) {
1709
2220
  return _syncTempOrderNoteToRemote.apply(this, arguments);
1710
2221
  }
1711
2222
  return syncTempOrderNoteToRemote;
@@ -1744,21 +2255,71 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1744
2255
  }, {
1745
2256
  key: "buildTempOrderCustomer",
1746
2257
  value: function buildTempOrderCustomer(params) {
1747
- var _ref10, _ref11, _ref12, _source$name, _ref13, _ref14, _ref15, _source$customer_name, _source$id, _source$customer_id, _ref16, _source$country_calli, _source$phone, _source$email;
2258
+ var _ref45, _ref46, _ref47, _source$name, _ref48, _ref49, _ref50, _source$customer_name, _source$id, _source$customer_id, _ref51, _source$country_calli, _source$phone, _source$email;
1748
2259
  if (!params.customerId) return null;
1749
2260
  var source = params.source ? cloneDeep(params.source) : {};
1750
- var name = (_ref10 = (_ref11 = (_ref12 = (_source$name = source.name) !== null && _source$name !== void 0 ? _source$name : source.display_name) !== null && _ref12 !== void 0 ? _ref12 : source.customerName) !== null && _ref11 !== void 0 ? _ref11 : source.customer_name) !== null && _ref10 !== void 0 ? _ref10 : params.customerName;
1751
- var customerName = (_ref13 = (_ref14 = (_ref15 = (_source$customer_name = source.customer_name) !== null && _source$customer_name !== void 0 ? _source$customer_name : source.customerName) !== null && _ref15 !== void 0 ? _ref15 : source.display_name) !== null && _ref14 !== void 0 ? _ref14 : source.name) !== null && _ref13 !== void 0 ? _ref13 : params.customerName;
2261
+ var name = (_ref45 = (_ref46 = (_ref47 = (_source$name = source.name) !== null && _source$name !== void 0 ? _source$name : source.display_name) !== null && _ref47 !== void 0 ? _ref47 : source.customerName) !== null && _ref46 !== void 0 ? _ref46 : source.customer_name) !== null && _ref45 !== void 0 ? _ref45 : params.customerName;
2262
+ var customerName = (_ref48 = (_ref49 = (_ref50 = (_source$customer_name = source.customer_name) !== null && _source$customer_name !== void 0 ? _source$customer_name : source.customerName) !== null && _ref50 !== void 0 ? _ref50 : source.display_name) !== null && _ref49 !== void 0 ? _ref49 : source.name) !== null && _ref48 !== void 0 ? _ref48 : params.customerName;
1752
2263
  return _objectSpread(_objectSpread({}, source), {}, {
1753
2264
  id: (_source$id = source.id) !== null && _source$id !== void 0 ? _source$id : params.customerId,
1754
2265
  customer_id: (_source$customer_id = source.customer_id) !== null && _source$customer_id !== void 0 ? _source$customer_id : params.customerId,
1755
2266
  name: String(name || ''),
1756
2267
  customer_name: String(customerName || ''),
1757
- country_calling_code: String((_ref16 = (_source$country_calli = source.country_calling_code) !== null && _source$country_calli !== void 0 ? _source$country_calli : source.countryCallingCode) !== null && _ref16 !== void 0 ? _ref16 : params.countryCallingCode),
2268
+ country_calling_code: String((_ref51 = (_source$country_calli = source.country_calling_code) !== null && _source$country_calli !== void 0 ? _source$country_calli : source.countryCallingCode) !== null && _ref51 !== void 0 ? _ref51 : params.countryCallingCode),
1758
2269
  phone: String((_source$phone = source.phone) !== null && _source$phone !== void 0 ? _source$phone : params.phone),
1759
2270
  email: String((_source$email = source.email) !== null && _source$email !== void 0 ? _source$email : params.email)
1760
2271
  });
1761
2272
  }
2273
+ }, {
2274
+ key: "isCustomerBoundDiscount",
2275
+ value: function isCustomerBoundDiscount(discount) {
2276
+ var _discount$type5;
2277
+ 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;
2278
+ return type === 'good_pass' || type === 'discount_card' || type === 'product_discount_card';
2279
+ }
2280
+ }, {
2281
+ key: "clearCustomerBoundDiscounts",
2282
+ value: function clearCustomerBoundDiscounts(tempOrder) {
2283
+ var _this13 = this,
2284
+ _discountModule$getDi,
2285
+ _discountModule$getOr,
2286
+ _discountModule$setDi,
2287
+ _discountModule$setOr;
2288
+ var filterDiscountList = function filterDiscountList(discountList) {
2289
+ if (!Array.isArray(discountList)) return [];
2290
+ return discountList.filter(function (discount) {
2291
+ return !_this13.isCustomerBoundDiscount(discount);
2292
+ });
2293
+ };
2294
+ tempOrder.products = (tempOrder.products || []).map(function (product) {
2295
+ var nextProduct = _objectSpread(_objectSpread({}, product), {}, {
2296
+ discount_list: filterDiscountList(product.discount_list)
2297
+ });
2298
+ if (Array.isArray(nextProduct.product_bundle)) {
2299
+ nextProduct.product_bundle = nextProduct.product_bundle.map(function (bundle) {
2300
+ return _objectSpread(_objectSpread({}, bundle), {}, {
2301
+ discount_list: filterDiscountList(bundle.discount_list)
2302
+ });
2303
+ });
2304
+ }
2305
+ return nextProduct;
2306
+ });
2307
+ delete tempOrder.discount_list;
2308
+ var discountModule = this.store.discount;
2309
+ if (!discountModule) return;
2310
+ var currentDiscounts = ((_discountModule$getDi = discountModule.getDiscountList) === null || _discountModule$getDi === void 0 ? void 0 : _discountModule$getDi.call(discountModule)) || [];
2311
+ var currentOriginalDiscounts = ((_discountModule$getOr = discountModule.getOriginalDiscountList) === null || _discountModule$getOr === void 0 ? void 0 : _discountModule$getOr.call(discountModule)) || [];
2312
+ var nextDiscounts = currentDiscounts.filter(function (discount) {
2313
+ if (discount !== null && discount !== void 0 && discount.isEditMode) return true;
2314
+ return !_this13.isCustomerBoundDiscount(discount);
2315
+ });
2316
+ var nextOriginalDiscounts = currentOriginalDiscounts.filter(function (discount) {
2317
+ if (discount !== null && discount !== void 0 && discount.isEditMode) return true;
2318
+ return !_this13.isCustomerBoundDiscount(discount);
2319
+ });
2320
+ void ((_discountModule$setDi = discountModule.setDiscountList) === null || _discountModule$setDi === void 0 ? void 0 : _discountModule$setDi.call(discountModule, nextDiscounts));
2321
+ void ((_discountModule$setOr = discountModule.setOriginalDiscountList) === null || _discountModule$setOr === void 0 ? void 0 : _discountModule$setOr.call(discountModule, nextOriginalDiscounts));
2322
+ }
1762
2323
 
1763
2324
  /**
1764
2325
  * 更新当前 tempOrder 的客户协议字段。
@@ -1769,13 +2330,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1769
2330
  }, {
1770
2331
  key: "updateTempOrderCustomer",
1771
2332
  value: function updateTempOrderCustomer(customer) {
1772
- var _ref17, _ref18, _customer$customer_id, _ref19, _ref20, _ref21, _customer$customer_na, _ref22, _customer$country_cal;
2333
+ var _tempOrder$customer_i2, _ref52, _ref53, _customer$customer_id, _ref54, _ref55, _ref56, _customer$customer_na, _ref57, _customer$country_cal, _tempOrder$customer_i3;
1773
2334
  var tempOrder = this.ensureTempOrder();
1774
- var customerId = (_ref17 = (_ref18 = (_customer$customer_id = customer.customer_id) !== null && _customer$customer_id !== void 0 ? _customer$customer_id : customer.customerId) !== null && _ref18 !== void 0 ? _ref18 : customer.id) !== null && _ref17 !== void 0 ? _ref17 : null;
1775
- var customerName = (_ref19 = (_ref20 = (_ref21 = (_customer$customer_na = customer.customer_name) !== null && _customer$customer_na !== void 0 ? _customer$customer_na : customer.customerName) !== null && _ref21 !== void 0 ? _ref21 : customer.display_name) !== null && _ref20 !== void 0 ? _ref20 : customer.name) !== null && _ref19 !== void 0 ? _ref19 : '';
2335
+ var previousCustomerId = (_tempOrder$customer_i2 = tempOrder.customer_id) !== null && _tempOrder$customer_i2 !== void 0 ? _tempOrder$customer_i2 : null;
2336
+ var customerId = (_ref52 = (_ref53 = (_customer$customer_id = customer.customer_id) !== null && _customer$customer_id !== void 0 ? _customer$customer_id : customer.customerId) !== null && _ref53 !== void 0 ? _ref53 : customer.id) !== null && _ref52 !== void 0 ? _ref52 : null;
2337
+ var customerName = (_ref54 = (_ref55 = (_ref56 = (_customer$customer_na = customer.customer_name) !== null && _customer$customer_na !== void 0 ? _customer$customer_na : customer.customerName) !== null && _ref56 !== void 0 ? _ref56 : customer.display_name) !== null && _ref55 !== void 0 ? _ref55 : customer.name) !== null && _ref54 !== void 0 ? _ref54 : '';
1776
2338
  tempOrder.customer_id = customerId === null || customerId === undefined || customerId === '' ? null : Number(customerId);
1777
2339
  tempOrder.customer_name = String(customerName || '');
1778
- tempOrder.country_calling_code = String((_ref22 = (_customer$country_cal = customer.country_calling_code) !== null && _customer$country_cal !== void 0 ? _customer$country_cal : customer.countryCallingCode) !== null && _ref22 !== void 0 ? _ref22 : '');
2340
+ tempOrder.country_calling_code = String((_ref57 = (_customer$country_cal = customer.country_calling_code) !== null && _customer$country_cal !== void 0 ? _customer$country_cal : customer.countryCallingCode) !== null && _ref57 !== void 0 ? _ref57 : '');
1779
2341
  tempOrder.phone = String(customer.phone || '');
1780
2342
  tempOrder.email = String(customer.email || '');
1781
2343
  tempOrder.customer = this.buildTempOrderCustomer({
@@ -1786,6 +2348,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1786
2348
  phone: tempOrder.phone,
1787
2349
  email: tempOrder.email
1788
2350
  });
2351
+ var nextCustomerId = (_tempOrder$customer_i3 = tempOrder.customer_id) !== null && _tempOrder$customer_i3 !== void 0 ? _tempOrder$customer_i3 : null;
1789
2352
  this.persistTempOrder();
1790
2353
  return {
1791
2354
  customerId: tempOrder.customer_id,
@@ -1797,13 +2360,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1797
2360
  }, {
1798
2361
  key: "setOrderCustomer",
1799
2362
  value: function setOrderCustomer(patch, snapshot) {
1800
- var _tempOrder$customer_i2, _tempOrder$customer_i3;
2363
+ var _tempOrder$customer_i4, _tempOrder$customer_i5;
1801
2364
  if (!patch) {
1802
2365
  this.clearOrderCustomer();
1803
2366
  return;
1804
2367
  }
1805
2368
  var tempOrder = this.ensureTempOrder();
1806
- var previousCustomerId = (_tempOrder$customer_i2 = tempOrder.customer_id) !== null && _tempOrder$customer_i2 !== void 0 ? _tempOrder$customer_i2 : null;
2369
+ var previousCustomerId = (_tempOrder$customer_i4 = tempOrder.customer_id) !== null && _tempOrder$customer_i4 !== void 0 ? _tempOrder$customer_i4 : null;
1807
2370
  tempOrder.customer_id = patch.customer_id || patch.id || null;
1808
2371
  tempOrder.customer_name = String(patch.customer_name || '');
1809
2372
  tempOrder.country_calling_code = String(patch.country_calling_code || '');
@@ -1821,9 +2384,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1821
2384
  var extend = this.ensureExtend(tempOrder);
1822
2385
  if (snapshot === null) delete extend.customerSnapshot;else extend.customerSnapshot = cloneDeep(snapshot);
1823
2386
  }
1824
- var nextCustomerId = (_tempOrder$customer_i3 = tempOrder.customer_id) !== null && _tempOrder$customer_i3 !== void 0 ? _tempOrder$customer_i3 : null;
2387
+ var nextCustomerId = (_tempOrder$customer_i5 = tempOrder.customer_id) !== null && _tempOrder$customer_i5 !== void 0 ? _tempOrder$customer_i5 : null;
1825
2388
  if (String(previousCustomerId !== null && previousCustomerId !== void 0 ? previousCustomerId : '') !== String(nextCustomerId !== null && nextCustomerId !== void 0 ? nextCustomerId : '')) {
1826
2389
  clearTempOrderHolderAssignments(tempOrder);
2390
+ this.clearCustomerBoundDiscounts(tempOrder);
1827
2391
  }
1828
2392
  this.persistTempOrder();
1829
2393
  this.saveDraftInBackground();
@@ -1865,6 +2429,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1865
2429
  tempOrder.email = '';
1866
2430
  tempOrder.customer = null;
1867
2431
  if (tempOrder._extend) delete tempOrder._extend.customerSnapshot;
2432
+ this.clearCustomerBoundDiscounts(tempOrder);
1868
2433
  this.persistTempOrder();
1869
2434
  this.saveDraftInBackground();
1870
2435
  this.core.effects.emit(OrderHooks.OnOrderCustomerChange, null);
@@ -1917,7 +2482,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1917
2482
  }, {
1918
2483
  key: "addOrderPayment",
1919
2484
  value: function addOrderPayment(payment) {
1920
- var _this8 = this;
2485
+ var _this14 = this;
1921
2486
  this.logInfo('addOrderPayment', {
1922
2487
  payment: payment
1923
2488
  });
@@ -1930,7 +2495,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1930
2495
  void this.recalculateSummary({
1931
2496
  createIfMissing: true
1932
2497
  }).catch(function (error) {
1933
- _this8.logError('recalculate summary after addOrderPayment failed', {
2498
+ _this14.logError('recalculate summary after addOrderPayment failed', {
1934
2499
  error: error instanceof Error ? error.message : String(error)
1935
2500
  });
1936
2501
  });
@@ -1995,10 +2560,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1995
2560
  }, {
1996
2561
  key: "updateVoucherOrderPayments",
1997
2562
  value: function updateVoucherOrderPayments(payments) {
1998
- var _this9 = this;
2563
+ var _this15 = this;
1999
2564
  var tempOrder = this.ensureTempOrder();
2000
2565
  var mappedVouchers = mapPaymentItemsToOrderPayments(payments.map(function (payment) {
2001
- return _this9.normalizePaymentSource(payment, {
2566
+ return _this15.normalizePaymentSource(payment, {
2002
2567
  defaultPaid: true
2003
2568
  });
2004
2569
  })).filter(function (payment) {
@@ -2017,7 +2582,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2017
2582
  void this.recalculateSummary({
2018
2583
  createIfMissing: true
2019
2584
  }).catch(function (error) {
2020
- _this9.logError('recalculate summary after updateVoucherOrderPayments failed', {
2585
+ _this15.logError('recalculate summary after updateVoucherOrderPayments failed', {
2021
2586
  error: error instanceof Error ? error.message : String(error)
2022
2587
  });
2023
2588
  });
@@ -2026,45 +2591,45 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2026
2591
  }, {
2027
2592
  key: "shouldMergeProductToOrder",
2028
2593
  value: function () {
2029
- var _shouldMergeProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(params) {
2594
+ var _shouldMergeProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(params) {
2030
2595
  var _this$orderHooks;
2031
2596
  var onBeforeMergeProductToOrder, result;
2032
- return _regeneratorRuntime().wrap(function _callee12$(_context14) {
2033
- while (1) switch (_context14.prev = _context14.next) {
2597
+ return _regeneratorRuntime().wrap(function _callee13$(_context15) {
2598
+ while (1) switch (_context15.prev = _context15.next) {
2034
2599
  case 0:
2035
2600
  onBeforeMergeProductToOrder = (_this$orderHooks = this.orderHooks) === null || _this$orderHooks === void 0 ? void 0 : _this$orderHooks.onBeforeMergeProductToOrder;
2036
2601
  if (onBeforeMergeProductToOrder) {
2037
- _context14.next = 3;
2602
+ _context15.next = 3;
2038
2603
  break;
2039
2604
  }
2040
- return _context14.abrupt("return", true);
2605
+ return _context15.abrupt("return", true);
2041
2606
  case 3:
2042
- _context14.next = 5;
2607
+ _context15.next = 5;
2043
2608
  return onBeforeMergeProductToOrder(_objectSpread(_objectSpread({}, params), {}, {
2044
2609
  defaultShouldMerge: true
2045
2610
  }));
2046
2611
  case 5:
2047
- result = _context14.sent;
2612
+ result = _context15.sent;
2048
2613
  if (!(typeof result === 'boolean')) {
2049
- _context14.next = 8;
2614
+ _context15.next = 8;
2050
2615
  break;
2051
2616
  }
2052
- return _context14.abrupt("return", result);
2617
+ return _context15.abrupt("return", result);
2053
2618
  case 8:
2054
2619
  if (!(result && _typeof(result) === 'object' && typeof result.shouldMerge === 'boolean')) {
2055
- _context14.next = 10;
2620
+ _context15.next = 10;
2056
2621
  break;
2057
2622
  }
2058
- return _context14.abrupt("return", result.shouldMerge);
2623
+ return _context15.abrupt("return", result.shouldMerge);
2059
2624
  case 10:
2060
- return _context14.abrupt("return", true);
2625
+ return _context15.abrupt("return", true);
2061
2626
  case 11:
2062
2627
  case "end":
2063
- return _context14.stop();
2628
+ return _context15.stop();
2064
2629
  }
2065
- }, _callee12, this);
2630
+ }, _callee13, this);
2066
2631
  }));
2067
- function shouldMergeProductToOrder(_x12) {
2632
+ function shouldMergeProductToOrder(_x13) {
2068
2633
  return _shouldMergeProductToOrder.apply(this, arguments);
2069
2634
  }
2070
2635
  return shouldMergeProductToOrder;
@@ -2072,11 +2637,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2072
2637
  }, {
2073
2638
  key: "addProductToOrder",
2074
2639
  value: function () {
2075
- var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(product, booking) {
2076
- var _this10 = this;
2640
+ var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(product, booking) {
2641
+ var _this16 = this;
2077
2642
  var tempOrder, linked, productToAdd, incomingFingerprint, normalizedIncoming, hasIncomingGoodPass, shouldForceNewLine, matchedIndex, matchedProduct, existedFingerprint, shouldMerge, _targetProduct$metada, targetProduct, targetUid, normalizedProduct, nextNum, targetIsManualProductDiscount, nextDiscountList;
2078
- return _regeneratorRuntime().wrap(function _callee13$(_context15) {
2079
- while (1) switch (_context15.prev = _context15.next) {
2643
+ return _regeneratorRuntime().wrap(function _callee14$(_context16) {
2644
+ while (1) switch (_context16.prev = _context16.next) {
2080
2645
  case 0:
2081
2646
  tempOrder = this.ensureTempOrder();
2082
2647
  linked = booking ? this.createLinkedProductAndBooking({
@@ -2090,7 +2655,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2090
2655
  hasIncomingGoodPass = this.hasGoodPassDiscount(normalizedIncoming);
2091
2656
  shouldForceNewLine = !!booking;
2092
2657
  matchedIndex = hasIncomingGoodPass || shouldForceNewLine ? -1 : tempOrder.products.findIndex(function (item) {
2093
- if (_this10.hasGoodPassDiscount(item)) return false;
2658
+ if (_this16.hasGoodPassDiscount(item)) return false;
2094
2659
  if (item.product_id !== productToAdd.product_id) return false;
2095
2660
  if (item.product_variant_id !== productToAdd.product_variant_id) return false;
2096
2661
  var existedFingerprint = buildProductLineFingerprint(getProductSkuOptions(item), item.product_bundle);
@@ -2099,10 +2664,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2099
2664
  matchedProduct = matchedIndex === -1 ? null : tempOrder.products[matchedIndex];
2100
2665
  existedFingerprint = matchedProduct ? buildProductLineFingerprint(getProductSkuOptions(matchedProduct), matchedProduct.product_bundle) : '';
2101
2666
  if (!matchedProduct) {
2102
- _context15.next = 17;
2667
+ _context16.next = 17;
2103
2668
  break;
2104
2669
  }
2105
- _context15.next = 14;
2670
+ _context16.next = 14;
2106
2671
  return this.shouldMergeProductToOrder({
2107
2672
  incomingProduct: productToAdd,
2108
2673
  normalizedIncoming: normalizedIncoming,
@@ -2114,13 +2679,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2114
2679
  booking: booking
2115
2680
  });
2116
2681
  case 14:
2117
- _context15.t0 = _context15.sent;
2118
- _context15.next = 18;
2682
+ _context16.t0 = _context16.sent;
2683
+ _context16.next = 18;
2119
2684
  break;
2120
2685
  case 17:
2121
- _context15.t0 = false;
2686
+ _context16.t0 = false;
2122
2687
  case 18:
2123
- shouldMerge = _context15.t0;
2688
+ shouldMerge = _context16.t0;
2124
2689
  if (matchedIndex === -1 || !matchedProduct || !shouldMerge) {
2125
2690
  this.captureProductRuntime(tempOrder, productToAdd, normalizedIncoming);
2126
2691
  if (linked) {
@@ -2171,25 +2736,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2171
2736
  if (linked) {
2172
2737
  tempOrder.bookings = [].concat(_toConsumableArray(tempOrder.bookings || []), [linked.booking]);
2173
2738
  }
2174
- _context15.next = 23;
2175
- return this.applyPromotion();
2739
+ _context16.next = 23;
2740
+ return this.ensureEditDiscountConfigForProductChange(tempOrder);
2176
2741
  case 23:
2742
+ _context16.next = 25;
2743
+ return this.applyPromotion();
2744
+ case 25:
2177
2745
  this.applyDiscount();
2178
2746
  this.sanitizeTempOrderProducts(tempOrder);
2179
- _context15.next = 27;
2747
+ _context16.next = 29;
2180
2748
  return this.recalculateSummary({
2181
2749
  createIfMissing: true
2182
2750
  });
2183
- case 27:
2184
- this.persistTempOrder();
2185
- return _context15.abrupt("return", tempOrder.products);
2186
2751
  case 29:
2752
+ this.persistTempOrder();
2753
+ return _context16.abrupt("return", tempOrder.products);
2754
+ case 31:
2187
2755
  case "end":
2188
- return _context15.stop();
2756
+ return _context16.stop();
2189
2757
  }
2190
- }, _callee13, this);
2758
+ }, _callee14, this);
2191
2759
  }));
2192
- function addProductToOrder(_x13, _x14) {
2760
+ function addProductToOrder(_x14, _x15) {
2193
2761
  return _addProductToOrder.apply(this, arguments);
2194
2762
  }
2195
2763
  return addProductToOrder;
@@ -2213,14 +2781,46 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2213
2781
  return (item === null || item === void 0 ? void 0 : item.type) === 'good_pass' || (item === null || item === void 0 ? void 0 : item.tag) === 'good_pass';
2214
2782
  });
2215
2783
  }
2784
+ }, {
2785
+ key: "getBundleRuntimeIdentity",
2786
+ value: function getBundleRuntimeIdentity(bundle) {
2787
+ var _ref58, _bundle$bundle_id2, _ref59, _bundle$bundle_group_2, _ref60, _ref61, _bundle$bundle_produc3, _ref62, _bundle$bundle_varian3;
2788
+ if (!bundle || _typeof(bundle) !== 'object') return '';
2789
+ return [(_ref58 = (_bundle$bundle_id2 = bundle.bundle_id) !== null && _bundle$bundle_id2 !== void 0 ? _bundle$bundle_id2 : bundle.id) !== null && _ref58 !== void 0 ? _ref58 : '', (_ref59 = (_bundle$bundle_group_2 = bundle.bundle_group_id) !== null && _bundle$bundle_group_2 !== void 0 ? _bundle$bundle_group_2 : bundle.group_id) !== null && _ref59 !== void 0 ? _ref59 : '', (_ref60 = (_ref61 = (_bundle$bundle_produc3 = bundle.bundle_product_id) !== null && _bundle$bundle_produc3 !== void 0 ? _bundle$bundle_produc3 : bundle._bundle_product_id) !== null && _ref61 !== void 0 ? _ref61 : bundle.product_id) !== null && _ref60 !== void 0 ? _ref60 : '', (_ref62 = (_bundle$bundle_varian3 = bundle.bundle_variant_id) !== null && _bundle$bundle_varian3 !== void 0 ? _bundle$bundle_varian3 : bundle.product_variant_id) !== null && _ref62 !== void 0 ? _ref62 : 0].join('|');
2790
+ }
2791
+ }, {
2792
+ key: "preservePersistedBundlePriceFields",
2793
+ value: function preservePersistedBundlePriceFields(previousBundles, nextBundles) {
2794
+ var _this17 = this;
2795
+ if (!Array.isArray(nextBundles)) return nextBundles;
2796
+ if (!Array.isArray(previousBundles) || previousBundles.length === 0) return nextBundles;
2797
+ var previousByIdentity = new Map();
2798
+ previousBundles.forEach(function (bundle) {
2799
+ var identity = _this17.getBundleRuntimeIdentity(bundle);
2800
+ if (identity) previousByIdentity.set(identity, bundle);
2801
+ });
2802
+ return nextBundles.map(function (bundle, index) {
2803
+ if (!bundle || _typeof(bundle) !== 'object') return bundle;
2804
+ var previous = previousByIdentity.get(_this17.getBundleRuntimeIdentity(bundle)) || previousBundles[index];
2805
+ if (!previous || _typeof(previous) !== 'object') return bundle;
2806
+ return _objectSpread(_objectSpread({}, bundle), {}, {
2807
+ price: previous.price,
2808
+ custom_price: previous.custom_price,
2809
+ bundle_payment_price: previous.bundle_payment_price,
2810
+ bundle_selling_price: previous.bundle_selling_price,
2811
+ original_price: previous.original_price,
2812
+ product_price: previous.product_price
2813
+ });
2814
+ });
2815
+ }
2216
2816
  }, {
2217
2817
  key: "updateOrderProduct",
2218
2818
  value: function () {
2219
- var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(params) {
2819
+ var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(params) {
2220
2820
  var _targetProduct$metada2, _product_sku, _metadata, _metadata2, _metadata3, _metadata4, _metadata5, _metadata6, _nextProduct$metadata, _targetProduct$metada8, _tempOrder$products$p;
2221
2821
  var product_id, product_variant_id, updates, unique_identification_number, identity_key, product_sku, product_bundle, booking, tempOrder, identityLookup, productIndex, targetUid, targetProduct, nextProduct, callerUpdatesTopPrice, callerUpdatesMainMeta, isPersistedOrderLine, callerChangesDiscountList, callerUpdatesManualPrice, _targetProduct$metada3, _targetProduct$metada4, _targetProduct$metada5, _targetProduct$metada6, _targetProduct$metada7, existedMeta, normalizedProduct, preservedBookingUid, _normalizedProduct$me, _targetProduct$metada9, productUid, linked;
2222
- return _regeneratorRuntime().wrap(function _callee14$(_context16) {
2223
- while (1) switch (_context16.prev = _context16.next) {
2822
+ return _regeneratorRuntime().wrap(function _callee15$(_context17) {
2823
+ while (1) switch (_context17.prev = _context17.next) {
2224
2824
  case 0:
2225
2825
  product_id = params.product_id, product_variant_id = params.product_variant_id, updates = params.updates, unique_identification_number = params.unique_identification_number, identity_key = params.identity_key, product_sku = params.product_sku, product_bundle = params.product_bundle, booking = params.booking;
2226
2826
  tempOrder = this.ensureTempOrder();
@@ -2243,15 +2843,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2243
2843
  if (unique_identification_number !== undefined) {
2244
2844
  targetUid = String(unique_identification_number);
2245
2845
  productIndex = tempOrder.products.findIndex(function (item) {
2246
- var _item$metadata;
2247
- return String(((_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.unique_identification_number) || item.unique_identification_number || '') === targetUid;
2846
+ var _item$metadata3;
2847
+ return String(((_item$metadata3 = item.metadata) === null || _item$metadata3 === void 0 ? void 0 : _item$metadata3.unique_identification_number) || item.unique_identification_number || '') === targetUid;
2248
2848
  });
2249
2849
  }
2250
2850
  if (productIndex === -1) {
2251
2851
  productIndex = getProductIdentityIndex(tempOrder.products, identityLookup);
2252
2852
  }
2253
2853
  if (!(productIndex === -1)) {
2254
- _context16.next = 12;
2854
+ _context17.next = 12;
2255
2855
  break;
2256
2856
  }
2257
2857
  throw new Error('[Order] 目标商品不存在,无法更新');
@@ -2291,6 +2891,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2291
2891
  main_product_original_price: (_targetProduct$metada5 = targetProduct.metadata) === null || _targetProduct$metada5 === void 0 ? void 0 : _targetProduct$metada5.main_product_original_price,
2292
2892
  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
2293
2893
  });
2894
+ nextProduct.product_bundle = this.preservePersistedBundlePriceFields(targetProduct.product_bundle, nextProduct.product_bundle);
2294
2895
  } else if (callerUpdatesTopPrice && !callerUpdatesMainMeta) {
2295
2896
  existedMeta = nextProduct.metadata || {};
2296
2897
  nextProduct.metadata = _objectSpread({}, existedMeta);
@@ -2333,25 +2934,25 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2333
2934
  }
2334
2935
  tempOrder.products[productIndex] = normalizedProduct;
2335
2936
  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);
2336
- _context16.next = 30;
2937
+ _context17.next = 30;
2337
2938
  return this.applyPromotion();
2338
2939
  case 30:
2339
2940
  this.applyDiscount();
2340
2941
  this.sanitizeTempOrderProducts(tempOrder);
2341
- _context16.next = 34;
2942
+ _context17.next = 34;
2342
2943
  return this.recalculateSummary({
2343
2944
  createIfMissing: true
2344
2945
  });
2345
2946
  case 34:
2346
2947
  this.persistTempOrder();
2347
- return _context16.abrupt("return", tempOrder.products);
2948
+ return _context17.abrupt("return", tempOrder.products);
2348
2949
  case 36:
2349
2950
  case "end":
2350
- return _context16.stop();
2951
+ return _context17.stop();
2351
2952
  }
2352
- }, _callee14, this);
2953
+ }, _callee15, this);
2353
2954
  }));
2354
- function updateOrderProduct(_x15) {
2955
+ function updateOrderProduct(_x16) {
2355
2956
  return _updateOrderProduct.apply(this, arguments);
2356
2957
  }
2357
2958
  return updateOrderProduct;
@@ -2359,11 +2960,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2359
2960
  }, {
2360
2961
  key: "updateOrderProductQuantity",
2361
2962
  value: function () {
2362
- var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(params) {
2963
+ var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(params) {
2363
2964
  var _targetProduct$metada10;
2364
2965
  var product_id, product_variant_id, num, unique_identification_number, identity_key, product_sku, product_bundle, tempOrder, identityLookup, productIndex, targetUid, targetProduct, normalizedProduct;
2365
- return _regeneratorRuntime().wrap(function _callee15$(_context17) {
2366
- while (1) switch (_context17.prev = _context17.next) {
2966
+ return _regeneratorRuntime().wrap(function _callee16$(_context18) {
2967
+ while (1) switch (_context18.prev = _context18.next) {
2367
2968
  case 0:
2368
2969
  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;
2369
2970
  tempOrder = this.ensureTempOrder();
@@ -2384,15 +2985,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2384
2985
  if (unique_identification_number !== undefined) {
2385
2986
  targetUid = String(unique_identification_number);
2386
2987
  productIndex = tempOrder.products.findIndex(function (item) {
2387
- var _item$metadata2;
2388
- return String(((_item$metadata2 = item.metadata) === null || _item$metadata2 === void 0 ? void 0 : _item$metadata2.unique_identification_number) || item.unique_identification_number || '') === targetUid;
2988
+ var _item$metadata4;
2989
+ return String(((_item$metadata4 = item.metadata) === null || _item$metadata4 === void 0 ? void 0 : _item$metadata4.unique_identification_number) || item.unique_identification_number || '') === targetUid;
2389
2990
  });
2390
2991
  }
2391
2992
  if (productIndex === -1) {
2392
2993
  productIndex = getProductIdentityIndex(tempOrder.products, identityLookup);
2393
2994
  }
2394
2995
  if (!(productIndex === -1)) {
2395
- _context17.next = 12;
2996
+ _context18.next = 12;
2396
2997
  break;
2397
2998
  }
2398
2999
  throw new Error('[Order] 目标商品不存在,无法更新数量');
@@ -2406,25 +3007,25 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2406
3007
  }));
2407
3008
  normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
2408
3009
  tempOrder.products[productIndex] = normalizedProduct;
2409
- _context17.next = 18;
3010
+ _context18.next = 18;
2410
3011
  return this.applyPromotion();
2411
3012
  case 18:
2412
3013
  this.applyDiscount();
2413
3014
  this.sanitizeTempOrderProducts(tempOrder);
2414
- _context17.next = 22;
3015
+ _context18.next = 22;
2415
3016
  return this.recalculateSummary({
2416
3017
  createIfMissing: true
2417
3018
  });
2418
3019
  case 22:
2419
3020
  this.persistTempOrder();
2420
- return _context17.abrupt("return", tempOrder.products);
3021
+ return _context18.abrupt("return", tempOrder.products);
2421
3022
  case 24:
2422
3023
  case "end":
2423
- return _context17.stop();
3024
+ return _context18.stop();
2424
3025
  }
2425
- }, _callee15, this);
3026
+ }, _callee16, this);
2426
3027
  }));
2427
- function updateOrderProductQuantity(_x16) {
3028
+ function updateOrderProductQuantity(_x17) {
2428
3029
  return _updateOrderProductQuantity.apply(this, arguments);
2429
3030
  }
2430
3031
  return updateOrderProductQuantity;
@@ -2455,10 +3056,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2455
3056
  }, {
2456
3057
  key: "removeProductFromOrder",
2457
3058
  value: function () {
2458
- var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(identity) {
3059
+ var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(identity) {
2459
3060
  var tempOrder, removedProducts, _i, _removedProducts, product;
2460
- return _regeneratorRuntime().wrap(function _callee16$(_context18) {
2461
- while (1) switch (_context18.prev = _context18.next) {
3061
+ return _regeneratorRuntime().wrap(function _callee17$(_context19) {
3062
+ while (1) switch (_context19.prev = _context19.next) {
2462
3063
  case 0:
2463
3064
  tempOrder = this.ensureTempOrder();
2464
3065
  removedProducts = [];
@@ -2471,25 +3072,25 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2471
3072
  product = _removedProducts[_i];
2472
3073
  this.removeLinkedBookingsForProduct(tempOrder, product);
2473
3074
  }
2474
- _context18.next = 6;
3075
+ _context19.next = 6;
2475
3076
  return this.applyPromotion();
2476
3077
  case 6:
2477
3078
  this.applyDiscount();
2478
3079
  this.sanitizeTempOrderProducts(tempOrder);
2479
- _context18.next = 10;
3080
+ _context19.next = 10;
2480
3081
  return this.recalculateSummary({
2481
3082
  createIfMissing: true
2482
3083
  });
2483
3084
  case 10:
2484
3085
  this.persistTempOrder();
2485
- return _context18.abrupt("return", tempOrder.products);
3086
+ return _context19.abrupt("return", tempOrder.products);
2486
3087
  case 12:
2487
3088
  case "end":
2488
- return _context18.stop();
3089
+ return _context19.stop();
2489
3090
  }
2490
- }, _callee16, this);
3091
+ }, _callee17, this);
2491
3092
  }));
2492
- function removeProductFromOrder(_x17) {
3093
+ function removeProductFromOrder(_x18) {
2493
3094
  return _removeProductFromOrder.apply(this, arguments);
2494
3095
  }
2495
3096
  return removeProductFromOrder;
@@ -2501,10 +3102,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2501
3102
  }, {
2502
3103
  key: "clearOrderCartLines",
2503
3104
  value: (function () {
2504
- var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
3105
+ var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18() {
2505
3106
  var tempOrder;
2506
- return _regeneratorRuntime().wrap(function _callee17$(_context19) {
2507
- while (1) switch (_context19.prev = _context19.next) {
3107
+ return _regeneratorRuntime().wrap(function _callee18$(_context20) {
3108
+ while (1) switch (_context20.prev = _context20.next) {
2508
3109
  case 0:
2509
3110
  tempOrder = this.ensureTempOrder();
2510
3111
  tempOrder.products = [];
@@ -2514,23 +3115,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2514
3115
  productsByUid: {}
2515
3116
  });
2516
3117
  }
2517
- _context19.next = 6;
3118
+ _context20.next = 6;
2518
3119
  return this.applyPromotion();
2519
3120
  case 6:
2520
3121
  this.applyDiscount();
2521
3122
  this.sanitizeTempOrderProducts(tempOrder);
2522
- _context19.next = 10;
3123
+ _context20.next = 10;
2523
3124
  return this.recalculateSummary({
2524
3125
  createIfMissing: true
2525
3126
  });
2526
3127
  case 10:
2527
3128
  this.persistTempOrder();
2528
- return _context19.abrupt("return", tempOrder);
3129
+ return _context20.abrupt("return", tempOrder);
2529
3130
  case 12:
2530
3131
  case "end":
2531
- return _context19.stop();
3132
+ return _context20.stop();
2532
3133
  }
2533
- }, _callee17, this);
3134
+ }, _callee18, this);
2534
3135
  }));
2535
3136
  function clearOrderCartLines() {
2536
3137
  return _clearOrderCartLines.apply(this, arguments);
@@ -2547,11 +3148,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2547
3148
  }, {
2548
3149
  key: "submitTempOrder",
2549
3150
  value: function () {
2550
- var _submitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(params) {
2551
- var _params$cacheId, _this$otherParams, _ref23, _params$businessCode, _this$otherParams2, _this$otherParams3;
3151
+ var _submitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(params) {
3152
+ var _params$cacheId, _this$otherParams, _ref63, _params$businessCode, _this$otherParams2, _this$otherParams3;
2552
3153
  var tempOrder, effectiveCacheId, hasPaymentOverride, hasPaymentStatusOverride, hasSmallTicketDataFlagOverride, enhancePayload, payload, result, _payload$payments, _payload$payments2, backendErrorResponse, submittedOrderId, resultRecord;
2553
- return _regeneratorRuntime().wrap(function _callee18$(_context20) {
2554
- while (1) switch (_context20.prev = _context20.next) {
3154
+ return _regeneratorRuntime().wrap(function _callee19$(_context21) {
3155
+ while (1) switch (_context21.prev = _context21.next) {
2555
3156
  case 0:
2556
3157
  tempOrder = this.ensureTempOrder();
2557
3158
  this.persistTempOrder();
@@ -2574,16 +3175,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2574
3175
  tempOrder: tempOrder,
2575
3176
  cacheId: effectiveCacheId,
2576
3177
  platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams = this.otherParams) === null || _this$otherParams === void 0 ? void 0 : _this$otherParams.platform),
2577
- businessCode: (_ref23 = (_params$businessCode = params === null || params === void 0 ? void 0 : params.businessCode) !== null && _params$businessCode !== void 0 ? _params$businessCode : (_this$otherParams2 = this.otherParams) === null || _this$otherParams2 === void 0 ? void 0 : _this$otherParams2.businessCode) !== null && _ref23 !== void 0 ? _ref23 : (_this$otherParams3 = this.otherParams) === null || _this$otherParams3 === void 0 ? void 0 : _this$otherParams3.business_code,
3178
+ businessCode: (_ref63 = (_params$businessCode = params === null || params === void 0 ? void 0 : params.businessCode) !== null && _params$businessCode !== void 0 ? _params$businessCode : (_this$otherParams2 = this.otherParams) === null || _this$otherParams2 === void 0 ? void 0 : _this$otherParams2.businessCode) !== null && _ref63 !== void 0 ? _ref63 : (_this$otherParams3 = this.otherParams) === null || _this$otherParams3 === void 0 ? void 0 : _this$otherParams3.business_code,
2578
3179
  channel: params === null || params === void 0 ? void 0 : params.channel,
2579
3180
  type: params === null || params === void 0 ? void 0 : params.type,
2580
3181
  enhance: enhancePayload
2581
3182
  }); // TODO: 前端生成的时间现在是有问题的,后面要统一优化
2582
3183
  payload.created_at = undefined;
2583
- _context20.next = 11;
3184
+ _context21.next = 11;
2584
3185
  return this.saveDraft();
2585
3186
  case 11:
2586
- _context20.prev = 11;
3187
+ _context21.prev = 11;
2587
3188
  this.logInfo('submitTempOrder calling sales checkout', {
2588
3189
  orderId: payload.order_id,
2589
3190
  externalSaleNumber: payload.external_sale_number,
@@ -2592,62 +3193,62 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2592
3193
  paymentsCount: ((_payload$payments = payload.payments) === null || _payload$payments === void 0 ? void 0 : _payload$payments.length) || 0,
2593
3194
  smallTicketDataFlag: payload.small_ticket_data_flag
2594
3195
  });
2595
- _context20.next = 15;
3196
+ _context21.next = 15;
2596
3197
  return this.submitSalesOrder({
2597
3198
  query: payload
2598
3199
  });
2599
3200
  case 15:
2600
- result = _context20.sent;
2601
- _context20.next = 28;
3201
+ result = _context21.sent;
3202
+ _context21.next = 28;
2602
3203
  break;
2603
3204
  case 18:
2604
- _context20.prev = 18;
2605
- _context20.t0 = _context20["catch"](11);
2606
- backendErrorResponse = this.extractSubmitErrorResponse(_context20.t0);
3205
+ _context21.prev = 18;
3206
+ _context21.t0 = _context21["catch"](11);
3207
+ backendErrorResponse = this.extractSubmitErrorResponse(_context21.t0);
2607
3208
  if (!backendErrorResponse) {
2608
- _context20.next = 25;
3209
+ _context21.next = 25;
2609
3210
  break;
2610
3211
  }
2611
3212
  this.store.syncState = 'failed';
2612
3213
  this.logSubmitBackendRejected(backendErrorResponse, payload);
2613
- return _context20.abrupt("return", backendErrorResponse);
3214
+ return _context21.abrupt("return", backendErrorResponse);
2614
3215
  case 25:
2615
3216
  this.store.syncState = 'failed';
2616
3217
  this.logError('submitTempOrder failed', {
2617
- error: _context20.t0 instanceof Error ? _context20.t0.message : String(_context20.t0),
3218
+ error: _context21.t0 instanceof Error ? _context21.t0.message : String(_context21.t0),
2618
3219
  orderId: payload.order_id,
2619
3220
  externalSaleNumber: payload.external_sale_number,
2620
3221
  paymentStatus: payload.payment_status,
2621
3222
  paymentsCount: ((_payload$payments2 = payload.payments) === null || _payload$payments2 === void 0 ? void 0 : _payload$payments2.length) || 0
2622
3223
  });
2623
- throw _context20.t0;
3224
+ throw _context21.t0;
2624
3225
  case 28:
2625
3226
  if (!this.isSubmitResponseRejected(result)) {
2626
- _context20.next = 32;
3227
+ _context21.next = 32;
2627
3228
  break;
2628
3229
  }
2629
3230
  this.store.syncState = 'failed';
2630
3231
  this.logSubmitBackendRejected(result, payload);
2631
- return _context20.abrupt("return", result);
3232
+ return _context21.abrupt("return", result);
2632
3233
  case 32:
2633
3234
  submittedOrderId = this.extractOrderIdFromSubmitResult(result);
2634
3235
  if (!(submittedOrderId !== null && submittedOrderId !== undefined)) {
2635
- _context20.next = 38;
3236
+ _context21.next = 38;
2636
3237
  break;
2637
3238
  }
2638
3239
  tempOrder.order_id = submittedOrderId;
2639
3240
  resultRecord = result;
2640
- _context20.next = 38;
3241
+ _context21.next = 38;
2641
3242
  return this.markLocalOrderSynced(submittedOrderId, (resultRecord === null || resultRecord === void 0 ? void 0 : resultRecord.data) || resultRecord || {});
2642
3243
  case 38:
2643
- return _context20.abrupt("return", result);
3244
+ return _context21.abrupt("return", result);
2644
3245
  case 39:
2645
3246
  case "end":
2646
- return _context20.stop();
3247
+ return _context21.stop();
2647
3248
  }
2648
- }, _callee18, this, [[11, 18]]);
3249
+ }, _callee19, this, [[11, 18]]);
2649
3250
  }));
2650
- function submitTempOrder(_x18) {
3251
+ function submitTempOrder(_x19) {
2651
3252
  return _submitTempOrder.apply(this, arguments);
2652
3253
  }
2653
3254
  return submitTempOrder;
@@ -2655,25 +3256,25 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2655
3256
  }, {
2656
3257
  key: "markLocalOrderSynced",
2657
3258
  value: function () {
2658
- var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(orderId, remoteOrder) {
3259
+ var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(orderId, remoteOrder) {
2659
3260
  var tempOrder;
2660
- return _regeneratorRuntime().wrap(function _callee19$(_context21) {
2661
- while (1) switch (_context21.prev = _context21.next) {
3261
+ return _regeneratorRuntime().wrap(function _callee20$(_context22) {
3262
+ while (1) switch (_context22.prev = _context22.next) {
2662
3263
  case 0:
2663
3264
  tempOrder = this.ensureTempOrder();
2664
3265
  tempOrder.order_id = orderId;
2665
3266
  this.store.lastOrderInfo = remoteOrder;
2666
3267
  this.store.syncState = 'submitted';
2667
3268
  this.persistTempOrder();
2668
- _context21.next = 7;
3269
+ _context22.next = 7;
2669
3270
  return this.saveDraft();
2670
3271
  case 7:
2671
3272
  case "end":
2672
- return _context21.stop();
3273
+ return _context22.stop();
2673
3274
  }
2674
- }, _callee19, this);
3275
+ }, _callee20, this);
2675
3276
  }));
2676
- function markLocalOrderSynced(_x19, _x20) {
3277
+ function markLocalOrderSynced(_x20, _x21) {
2677
3278
  return _markLocalOrderSynced.apply(this, arguments);
2678
3279
  }
2679
3280
  return markLocalOrderSynced;
@@ -2697,10 +3298,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2697
3298
  value: function extractSubmitErrorResponse(error) {
2698
3299
  var _error$response,
2699
3300
  _error$response2,
2700
- _this11 = this;
3301
+ _this18 = this;
2701
3302
  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];
2702
3303
  return candidates.find(function (candidate) {
2703
- return _this11.isSubmitErrorResponse(candidate);
3304
+ return _this18.isSubmitErrorResponse(candidate);
2704
3305
  }) || null;
2705
3306
  }
2706
3307
  }, {
@@ -2720,10 +3321,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2720
3321
  }, {
2721
3322
  key: "syncPaymentsToOrder",
2722
3323
  value: function () {
2723
- var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(params) {
3324
+ var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(params) {
2724
3325
  var tempOrder, mappedPayments, paymentTotal, targetAmount, isFullyPaid, paymentStatus, paymentSyncIdempotencyToken, submitResult;
2725
- return _regeneratorRuntime().wrap(function _callee20$(_context22) {
2726
- while (1) switch (_context22.prev = _context22.next) {
3326
+ return _regeneratorRuntime().wrap(function _callee21$(_context23) {
3327
+ while (1) switch (_context23.prev = _context23.next) {
2727
3328
  case 0:
2728
3329
  tempOrder = this.ensureTempOrder();
2729
3330
  mappedPayments = mapPaymentItemsToOrderPayments(params.payments || []);
@@ -2734,28 +3335,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2734
3335
  tempOrder.payments = mappedPayments;
2735
3336
  tempOrder.payment_status = paymentStatus;
2736
3337
  this.persistTempOrder();
2737
- _context22.next = 11;
3338
+ _context23.next = 11;
2738
3339
  return this.saveDraft();
2739
3340
  case 11:
2740
3341
  if (params.submitWhenPaid) {
2741
- _context22.next = 13;
3342
+ _context23.next = 13;
2742
3343
  break;
2743
3344
  }
2744
- return _context22.abrupt("return", {
3345
+ return _context23.abrupt("return", {
2745
3346
  isFullyPaid: isFullyPaid
2746
3347
  });
2747
3348
  case 13:
2748
3349
  if (!(this.store.syncState === 'submitting')) {
2749
- _context22.next = 15;
3350
+ _context23.next = 15;
2750
3351
  break;
2751
3352
  }
2752
- return _context22.abrupt("return", {
3353
+ return _context23.abrupt("return", {
2753
3354
  isFullyPaid: isFullyPaid
2754
3355
  });
2755
3356
  case 15:
2756
3357
  this.store.syncState = 'submitting';
2757
3358
  paymentSyncIdempotencyToken = this.buildPaymentSyncIdempotencyToken(tempOrder, mappedPayments);
2758
- _context22.next = 19;
3359
+ _context23.next = 19;
2759
3360
  return this.submitTempOrder({
2760
3361
  payments: mappedPayments,
2761
3362
  paymentStatus: paymentStatus,
@@ -2770,18 +3371,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2770
3371
  }
2771
3372
  });
2772
3373
  case 19:
2773
- submitResult = _context22.sent;
2774
- return _context22.abrupt("return", {
3374
+ submitResult = _context23.sent;
3375
+ return _context23.abrupt("return", {
2775
3376
  isFullyPaid: isFullyPaid,
2776
3377
  submitResult: submitResult
2777
3378
  });
2778
3379
  case 21:
2779
3380
  case "end":
2780
- return _context22.stop();
3381
+ return _context23.stop();
2781
3382
  }
2782
- }, _callee20, this);
3383
+ }, _callee21, this);
2783
3384
  }));
2784
- function syncPaymentsToOrder(_x21) {
3385
+ function syncPaymentsToOrder(_x22) {
2785
3386
  return _syncPaymentsToOrder.apply(this, arguments);
2786
3387
  }
2787
3388
  return syncPaymentsToOrder;
@@ -2870,11 +3471,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2870
3471
  }, {
2871
3472
  key: "submitOrder",
2872
3473
  value: function () {
2873
- var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(order) {
3474
+ var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(order) {
2874
3475
  var _order$query$cartItem, _params$bookings, _params$relation_prod;
2875
3476
  var url, query, fetchUrl, params;
2876
- return _regeneratorRuntime().wrap(function _callee21$(_context23) {
2877
- while (1) switch (_context23.prev = _context23.next) {
3477
+ return _regeneratorRuntime().wrap(function _callee22$(_context24) {
3478
+ while (1) switch (_context24.prev = _context24.next) {
2878
3479
  case 0:
2879
3480
  this.logInfo('submitOrder called', {
2880
3481
  url: order.url,
@@ -2894,14 +3495,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2894
3495
  relationProductsCount: ((_params$relation_prod = params.relation_products) === null || _params$relation_prod === void 0 ? void 0 : _params$relation_prod.length) || 0,
2895
3496
  scheduleDate: params.schedule_date
2896
3497
  });
2897
- return _context23.abrupt("return", this.request.post(fetchUrl, params));
3498
+ return _context24.abrupt("return", this.request.post(fetchUrl, params));
2898
3499
  case 6:
2899
3500
  case "end":
2900
- return _context23.stop();
3501
+ return _context24.stop();
2901
3502
  }
2902
- }, _callee21, this);
3503
+ }, _callee22, this);
2903
3504
  }));
2904
- function submitOrder(_x22) {
3505
+ function submitOrder(_x23) {
2905
3506
  return _submitOrder.apply(this, arguments);
2906
3507
  }
2907
3508
  return submitOrder;
@@ -2909,13 +3510,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2909
3510
  }, {
2910
3511
  key: "cancelOrder",
2911
3512
  value: function () {
2912
- var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(params) {
3513
+ var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(params) {
2913
3514
  var payload;
2914
- return _regeneratorRuntime().wrap(function _callee22$(_context24) {
2915
- while (1) switch (_context24.prev = _context24.next) {
3515
+ return _regeneratorRuntime().wrap(function _callee23$(_context25) {
3516
+ while (1) switch (_context25.prev = _context25.next) {
2916
3517
  case 0:
2917
3518
  if (!(!Array.isArray(params.order_ids) || params.order_ids.length === 0)) {
2918
- _context24.next = 2;
3519
+ _context25.next = 2;
2919
3520
  break;
2920
3521
  }
2921
3522
  throw new Error('取消订单失败:order_ids 不能为空');
@@ -2931,16 +3532,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2931
3532
  method: 'PUT',
2932
3533
  orderIdsCount: params.order_ids.length
2933
3534
  });
2934
- return _context24.abrupt("return", this.request.put('/order/update-status', payload, {
3535
+ return _context25.abrupt("return", this.request.put('/order/update-status', payload, {
2935
3536
  isShopApi: true
2936
3537
  }));
2937
3538
  case 5:
2938
3539
  case "end":
2939
- return _context24.stop();
3540
+ return _context25.stop();
2940
3541
  }
2941
- }, _callee22, this);
3542
+ }, _callee23, this);
2942
3543
  }));
2943
- function cancelOrder(_x23) {
3544
+ function cancelOrder(_x24) {
2944
3545
  return _cancelOrder.apply(this, arguments);
2945
3546
  }
2946
3547
  return cancelOrder;
@@ -2948,19 +3549,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2948
3549
  }, {
2949
3550
  key: "changeBookingStatus",
2950
3551
  value: function () {
2951
- var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(params) {
3552
+ var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(params) {
2952
3553
  var url, payload;
2953
- return _regeneratorRuntime().wrap(function _callee23$(_context25) {
2954
- while (1) switch (_context25.prev = _context25.next) {
3554
+ return _regeneratorRuntime().wrap(function _callee24$(_context26) {
3555
+ while (1) switch (_context26.prev = _context26.next) {
2955
3556
  case 0:
2956
3557
  if (params.booking_id) {
2957
- _context25.next = 2;
3558
+ _context26.next = 2;
2958
3559
  break;
2959
3560
  }
2960
3561
  throw new Error('变更预约状态失败:booking_id 不能为空');
2961
3562
  case 2:
2962
3563
  if (params.appointment_status) {
2963
- _context25.next = 4;
3564
+ _context26.next = 4;
2964
3565
  break;
2965
3566
  }
2966
3567
  throw new Error('变更预约状态失败:appointment_status 不能为空');
@@ -2975,16 +3576,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2975
3576
  bookingId: params.booking_id,
2976
3577
  appointmentStatus: params.appointment_status
2977
3578
  });
2978
- return _context25.abrupt("return", this.request.put(url, payload, {
3579
+ return _context26.abrupt("return", this.request.put(url, payload, {
2979
3580
  isShopApi: true
2980
3581
  }));
2981
3582
  case 8:
2982
3583
  case "end":
2983
- return _context25.stop();
3584
+ return _context26.stop();
2984
3585
  }
2985
- }, _callee23, this);
3586
+ }, _callee24, this);
2986
3587
  }));
2987
- function changeBookingStatus(_x24) {
3588
+ function changeBookingStatus(_x25) {
2988
3589
  return _changeBookingStatus.apply(this, arguments);
2989
3590
  }
2990
3591
  return changeBookingStatus;
@@ -3002,11 +3603,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3002
3603
  }, {
3003
3604
  key: "createOrderByCheckout",
3004
3605
  value: (function () {
3005
- var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(params) {
3606
+ var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(params) {
3006
3607
  var _params$payments, _params$bookings2, _params$relation_prod2, _params$payments2, _params$payments3, _params$bookings3, _params$relation_prod3, _params$payments4;
3007
3608
  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;
3008
- return _regeneratorRuntime().wrap(function _callee24$(_context26) {
3009
- while (1) switch (_context26.prev = _context26.next) {
3609
+ return _regeneratorRuntime().wrap(function _callee25$(_context27) {
3610
+ while (1) switch (_context27.prev = _context27.next) {
3010
3611
  case 0:
3011
3612
  // 过滤掉由在线店铺下单的 payment 支付数据
3012
3613
  onlineStorePaymentCodeList = ['WXPAY', 'WECHAT', 'ALIPAY', 'APPLE_PAY', 'CREDIT_CARD_3DS', 'CREDIT_CARD_TOKEN', 'GOOGLE_PAY', 'GOOGLE_PAY_3DS', 'CREDIT_CARD'];
@@ -3040,7 +3641,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3040
3641
  relationProductsCount: ((_params$relation_prod3 = params.relation_products) === null || _params$relation_prod3 === void 0 ? void 0 : _params$relation_prod3.length) || 0,
3041
3642
  paymentsCount: ((_params$payments4 = params.payments) === null || _params$payments4 === void 0 ? void 0 : _params$payments4.length) || 0
3042
3643
  });
3043
- _context26.prev = 4;
3644
+ _context27.prev = 4;
3044
3645
  // 构建订单数据,设置默认值并允许 params 覆盖
3045
3646
  orderData = _objectSpread({
3046
3647
  sales_channel: 'my_pisel',
@@ -3102,13 +3703,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3102
3703
  hasOrderId: !!orderData.order_id,
3103
3704
  smallTicketDataFlag: orderData.small_ticket_data_flag
3104
3705
  });
3105
- _context26.next = 12;
3706
+ _context27.next = 12;
3106
3707
  return this.request.post('/shop/order/checkout', orderData, {
3107
3708
  osServer: true,
3108
3709
  customToast: function customToast() {}
3109
3710
  });
3110
3711
  case 12:
3111
- response = _context26.sent;
3712
+ response = _context27.sent;
3112
3713
  this.logInfo('Order API called successfully', {
3113
3714
  response: response
3114
3715
  });
@@ -3116,22 +3717,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3116
3717
  success: !!response,
3117
3718
  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)
3118
3719
  });
3119
- return _context26.abrupt("return", response);
3720
+ return _context27.abrupt("return", response);
3120
3721
  case 18:
3121
- _context26.prev = 18;
3122
- _context26.t0 = _context26["catch"](4);
3123
- console.error('[Order] createOrderByCheckout 创建订单失败:', _context26.t0);
3722
+ _context27.prev = 18;
3723
+ _context27.t0 = _context27["catch"](4);
3724
+ console.error('[Order] createOrderByCheckout 创建订单失败:', _context27.t0);
3124
3725
  this.logInfo('Order API called failed', {
3125
- error: _context26.t0 instanceof Error ? _context26.t0.message : String(_context26.t0)
3726
+ error: _context27.t0 instanceof Error ? _context27.t0.message : String(_context27.t0)
3126
3727
  });
3127
- throw _context26.t0;
3728
+ throw _context27.t0;
3128
3729
  case 23:
3129
3730
  case "end":
3130
- return _context26.stop();
3731
+ return _context27.stop();
3131
3732
  }
3132
- }, _callee24, this, [[4, 18]]);
3733
+ }, _callee25, this, [[4, 18]]);
3133
3734
  }));
3134
- function createOrderByCheckout(_x25) {
3735
+ function createOrderByCheckout(_x26) {
3135
3736
  return _createOrderByCheckout.apply(this, arguments);
3136
3737
  }
3137
3738
  return createOrderByCheckout;
@@ -3139,24 +3740,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3139
3740
  }, {
3140
3741
  key: "submitSalesOrder",
3141
3742
  value: function () {
3142
- var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(params) {
3743
+ var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(params) {
3143
3744
  var url, query, fetchUrl;
3144
- return _regeneratorRuntime().wrap(function _callee25$(_context27) {
3145
- while (1) switch (_context27.prev = _context27.next) {
3745
+ return _regeneratorRuntime().wrap(function _callee26$(_context28) {
3746
+ while (1) switch (_context28.prev = _context28.next) {
3146
3747
  case 0:
3147
3748
  url = params.url, query = params.query;
3148
3749
  fetchUrl = url || '/order/sales/checkout';
3149
- return _context27.abrupt("return", this.request.post(fetchUrl, query, {
3750
+ return _context28.abrupt("return", this.request.post(fetchUrl, query, {
3150
3751
  osServer: true,
3151
3752
  customToast: function customToast() {}
3152
3753
  }));
3153
3754
  case 3:
3154
3755
  case "end":
3155
- return _context27.stop();
3756
+ return _context28.stop();
3156
3757
  }
3157
- }, _callee25, this);
3758
+ }, _callee26, this);
3158
3759
  }));
3159
- function submitSalesOrder(_x26) {
3760
+ function submitSalesOrder(_x27) {
3160
3761
  return _submitSalesOrder.apply(this, arguments);
3161
3762
  }
3162
3763
  return submitSalesOrder;
@@ -3170,37 +3771,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3170
3771
  }, {
3171
3772
  key: "sendCustomerPayLink",
3172
3773
  value: (function () {
3173
- var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(params) {
3774
+ var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(params) {
3174
3775
  var _params$emails;
3175
3776
  var orderIds;
3176
- return _regeneratorRuntime().wrap(function _callee26$(_context28) {
3177
- while (1) switch (_context28.prev = _context28.next) {
3777
+ return _regeneratorRuntime().wrap(function _callee27$(_context29) {
3778
+ while (1) switch (_context29.prev = _context29.next) {
3178
3779
  case 0:
3179
3780
  orderIds = params.order_ids || params.orderIds || [];
3180
3781
  if (orderIds.length) {
3181
- _context28.next = 3;
3782
+ _context29.next = 3;
3182
3783
  break;
3183
3784
  }
3184
3785
  throw new Error('发送支付链接前必须先提交本地订单并取得订单 ID');
3185
3786
  case 3:
3186
3787
  if ((_params$emails = params.emails) !== null && _params$emails !== void 0 && _params$emails.length) {
3187
- _context28.next = 5;
3788
+ _context29.next = 5;
3188
3789
  break;
3189
3790
  }
3190
3791
  throw new Error('发送支付链接需要至少一个邮箱');
3191
3792
  case 5:
3192
- return _context28.abrupt("return", this.request.post('/order/batch-email', {
3793
+ return _context29.abrupt("return", this.request.post('/order/batch-email', {
3193
3794
  order_ids: orderIds,
3194
3795
  notify_action: params.notify_action || 'order_payment_reminder',
3195
3796
  emails: params.emails
3196
3797
  }));
3197
3798
  case 6:
3198
3799
  case "end":
3199
- return _context28.stop();
3800
+ return _context29.stop();
3200
3801
  }
3201
- }, _callee26, this);
3802
+ }, _callee27, this);
3202
3803
  }));
3203
- function sendCustomerPayLink(_x27) {
3804
+ function sendCustomerPayLink(_x28) {
3204
3805
  return _sendCustomerPayLink.apply(this, arguments);
3205
3806
  }
3206
3807
  return sendCustomerPayLink;
@@ -3208,19 +3809,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3208
3809
  }, {
3209
3810
  key: "getSalesOrderByLookup",
3210
3811
  value: function () {
3211
- var _getSalesOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(params) {
3812
+ var _getSalesOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(params) {
3212
3813
  var lookup, res;
3213
- return _regeneratorRuntime().wrap(function _callee27$(_context29) {
3214
- while (1) switch (_context29.prev = _context29.next) {
3814
+ return _regeneratorRuntime().wrap(function _callee28$(_context30) {
3815
+ while (1) switch (_context30.prev = _context30.next) {
3215
3816
  case 0:
3216
3817
  lookup = params.lookup === undefined || params.lookup === null ? '' : String(params.lookup).trim();
3217
3818
  if (lookup) {
3218
- _context29.next = 3;
3819
+ _context30.next = 3;
3219
3820
  break;
3220
3821
  }
3221
3822
  throw new Error('加载销售详情需要 lookup');
3222
3823
  case 3:
3223
- _context29.next = 5;
3824
+ _context30.next = 5;
3224
3825
  return this.request.get("/order/sales/".concat(encodeURIComponent(lookup)), _objectSpread({
3225
3826
  with: ['products', 'bookings', 'payments', 'customer', 'summary', 'contacts_info']
3226
3827
  }, params.forceRemote ? {
@@ -3229,18 +3830,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3229
3830
  osServer: true
3230
3831
  });
3231
3832
  case 5:
3232
- res = _context29.sent;
3833
+ res = _context30.sent;
3233
3834
  if (res.code === 200) {
3234
3835
  this.store.lastOrderInfo = res.data;
3235
3836
  }
3236
- return _context29.abrupt("return", res);
3837
+ return _context30.abrupt("return", res);
3237
3838
  case 8:
3238
3839
  case "end":
3239
- return _context29.stop();
3840
+ return _context30.stop();
3240
3841
  }
3241
- }, _callee27, this);
3842
+ }, _callee28, this);
3242
3843
  }));
3243
- function getSalesOrderByLookup(_x28) {
3844
+ function getSalesOrderByLookup(_x29) {
3244
3845
  return _getSalesOrderByLookup.apply(this, arguments);
3245
3846
  }
3246
3847
  return getSalesOrderByLookup;
@@ -3254,34 +3855,51 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3254
3855
  }, {
3255
3856
  key: "hydrateTempOrderFromRecord",
3256
3857
  value: (function () {
3257
- var _hydrateTempOrderFromRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(record, options) {
3258
- var raw, nextTempOrder;
3259
- return _regeneratorRuntime().wrap(function _callee28$(_context30) {
3260
- while (1) switch (_context30.prev = _context30.next) {
3858
+ var _hydrateTempOrderFromRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(record, options) {
3859
+ var _this$store$discount13, _this$store$discount14;
3860
+ var raw, nextTempOrder, hydratedEditDiscounts;
3861
+ return _regeneratorRuntime().wrap(function _callee29$(_context31) {
3862
+ while (1) switch (_context31.prev = _context31.next) {
3261
3863
  case 0:
3262
3864
  raw = record && _typeof(record) === 'object' && record.data && record.order_id == null ? record.data : record || {};
3263
3865
  nextTempOrder = this.normalizeTempOrderForRuntime(raw);
3264
3866
  this.store.tempOrder = nextTempOrder;
3265
3867
  this.store.summary = raw.summary && _typeof(raw.summary) === 'object' ? _objectSpread(_objectSpread({}, createEmptySummary()), raw.summary) : createEmptySummary();
3868
+ nextTempOrder._extend = _objectSpread(_objectSpread({}, nextTempOrder._extend || {}), {}, {
3869
+ originalSalesSnapshot: {
3870
+ summary: cloneDeep(this.store.summary),
3871
+ products: cloneDeep(nextTempOrder.products || []),
3872
+ payments: cloneDeep(nextTempOrder.payments || []),
3873
+ surcharges: cloneDeep(nextTempOrder.surcharges || []),
3874
+ productFingerprint: this.buildOrderProductsFingerprint(nextTempOrder.products || [])
3875
+ }
3876
+ });
3266
3877
  this.store.lastOrderInfo = raw.lastOrderInfo || raw;
3878
+ hydratedEditDiscounts = this.collectHydratedEditDiscounts(nextTempOrder.products);
3879
+ _context31.next = 9;
3880
+ return (_this$store$discount13 = this.store.discount) === null || _this$store$discount13 === void 0 ? void 0 : _this$store$discount13.setOriginalDiscountList(hydratedEditDiscounts);
3881
+ case 9:
3882
+ _context31.next = 11;
3883
+ return (_this$store$discount14 = this.store.discount) === null || _this$store$discount14 === void 0 ? void 0 : _this$store$discount14.setDiscountList(hydratedEditDiscounts);
3884
+ case 11:
3267
3885
  if (!(options !== null && options !== void 0 && options.recalcOnHydrate)) {
3268
- _context30.next = 8;
3886
+ _context31.next = 14;
3269
3887
  break;
3270
3888
  }
3271
- _context30.next = 8;
3889
+ _context31.next = 14;
3272
3890
  return this.recalculateSummary({
3273
3891
  createIfMissing: false
3274
3892
  });
3275
- case 8:
3893
+ case 14:
3276
3894
  this.persistTempOrder();
3277
- return _context30.abrupt("return", nextTempOrder);
3278
- case 10:
3895
+ return _context31.abrupt("return", nextTempOrder);
3896
+ case 16:
3279
3897
  case "end":
3280
- return _context30.stop();
3898
+ return _context31.stop();
3281
3899
  }
3282
- }, _callee28, this);
3900
+ }, _callee29, this);
3283
3901
  }));
3284
- function hydrateTempOrderFromRecord(_x29, _x30) {
3902
+ function hydrateTempOrderFromRecord(_x30, _x31) {
3285
3903
  return _hydrateTempOrderFromRecord.apply(this, arguments);
3286
3904
  }
3287
3905
  return hydrateTempOrderFromRecord;
@@ -3289,7 +3907,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3289
3907
  }, {
3290
3908
  key: "normalizeTempOrderForRuntime",
3291
3909
  value: function normalizeTempOrderForRuntime(raw, options) {
3292
- var _this12 = this;
3910
+ var _this19 = this;
3293
3911
  var nextTempOrder = _objectSpread(_objectSpread({}, this.createDefaultTempOrderInstance()), raw || {});
3294
3912
  delete nextTempOrder.summary;
3295
3913
  delete nextTempOrder.lastOrderInfo;
@@ -3308,7 +3926,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3308
3926
  nextTempOrder.holder = raw.holder && _typeof(raw.holder) === 'object' ? _objectSpread({}, raw.holder) : null;
3309
3927
  var rawProducts = Array.isArray(raw.products) ? raw.products : [];
3310
3928
  nextTempOrder.products = rawProducts.length > 0 ? rawProducts.map(function (p) {
3311
- return _this12.normalizeHydratedOrderProduct(p);
3929
+ return _this19.normalizeHydratedOrderProduct(p);
3312
3930
  }) : [];
3313
3931
  nextTempOrder.bookings = Array.isArray(raw.bookings) ? raw.bookings.map(function (b) {
3314
3932
  return _objectSpread(_objectSpread({}, b || {}), {}, {
@@ -3336,19 +3954,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3336
3954
  };
3337
3955
  var tempOrderExtend = nextTempOrder._extend;
3338
3956
  var productsByUid = tempOrderExtend.productsByUid || {};
3339
- var _iterator9 = _createForOfIteratorHelper(nextTempOrder.products.entries()),
3340
- _step9;
3957
+ var _iterator17 = _createForOfIteratorHelper(nextTempOrder.products.entries()),
3958
+ _step17;
3341
3959
  try {
3342
- for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
3343
- var _product$metadata7, _ref24, _ref25, _existed$origin, _rawProduct$metadata;
3344
- var _step9$value = _slicedToArray(_step9.value, 2),
3345
- index = _step9$value[0],
3346
- product = _step9$value[1];
3960
+ for (_iterator17.s(); !(_step17 = _iterator17.n()).done;) {
3961
+ var _product$metadata7, _ref64, _ref65, _existed$origin, _rawProduct$metadata;
3962
+ var _step17$value = _slicedToArray(_step17.value, 2),
3963
+ index = _step17$value[0],
3964
+ product = _step17$value[1];
3347
3965
  var uid = (_product$metadata7 = product.metadata) === null || _product$metadata7 === void 0 ? void 0 : _product$metadata7.unique_identification_number;
3348
3966
  if (!uid) continue;
3349
3967
  var existed = productsByUid[uid] && _typeof(productsByUid[uid]) === 'object' ? productsByUid[uid] : {};
3350
3968
  var rawProduct = rawProducts[index] && _typeof(rawProducts[index]) === 'object' ? rawProducts[index] : product;
3351
- var origin = (_ref24 = (_ref25 = (_existed$origin = existed.origin) !== null && _existed$origin !== void 0 ? _existed$origin : rawProduct._origin) !== null && _ref25 !== void 0 ? _ref25 : (_rawProduct$metadata = rawProduct.metadata) === null || _rawProduct$metadata === void 0 ? void 0 : _rawProduct$metadata.origin) !== null && _ref24 !== void 0 ? _ref24 : rawProduct;
3969
+ var origin = (_ref64 = (_ref65 = (_existed$origin = existed.origin) !== null && _existed$origin !== void 0 ? _existed$origin : rawProduct._origin) !== null && _ref65 !== void 0 ? _ref65 : (_rawProduct$metadata = rawProduct.metadata) === null || _rawProduct$metadata === void 0 ? void 0 : _rawProduct$metadata.origin) !== null && _ref64 !== void 0 ? _ref64 : rawProduct;
3352
3970
  var originSnapshot = cloneDeep(origin);
3353
3971
  var productOptionString = this.buildHydratedProductOptionString(rawProduct) || this.buildHydratedProductOptionString(product);
3354
3972
  if (productOptionString && originSnapshot && _typeof(originSnapshot) === 'object') {
@@ -3364,9 +3982,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3364
3982
  });
3365
3983
  }
3366
3984
  } catch (err) {
3367
- _iterator9.e(err);
3985
+ _iterator17.e(err);
3368
3986
  } finally {
3369
- _iterator9.f();
3987
+ _iterator17.f();
3370
3988
  }
3371
3989
  tempOrderExtend.productsByUid = productsByUid;
3372
3990
  if ((options === null || options === void 0 ? void 0 : options.ensureIdentity) !== false) {
@@ -3397,18 +4015,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3397
4015
  var segments = [];
3398
4016
  var sku = (product === null || product === void 0 ? void 0 : product.product_sku) || {};
3399
4017
  if (Array.isArray(sku.variant)) {
3400
- var _iterator10 = _createForOfIteratorHelper(sku.variant),
3401
- _step10;
4018
+ var _iterator18 = _createForOfIteratorHelper(sku.variant),
4019
+ _step18;
3402
4020
  try {
3403
- for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
3404
- var variant = _step10.value;
4021
+ for (_iterator18.s(); !(_step18 = _iterator18.n()).done;) {
4022
+ var variant = _step18.value;
3405
4023
  var segment = this.formatHydratedNamePair(variant === null || variant === void 0 ? void 0 : variant.group, variant === null || variant === void 0 ? void 0 : variant.item);
3406
4024
  if (segment) segments.push(segment);
3407
4025
  }
3408
4026
  } catch (err) {
3409
- _iterator10.e(err);
4027
+ _iterator18.e(err);
3410
4028
  } finally {
3411
- _iterator10.f();
4029
+ _iterator18.f();
3412
4030
  }
3413
4031
  }
3414
4032
  return segments.join(', ');
@@ -3416,10 +4034,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3416
4034
  }, {
3417
4035
  key: "normalizeHydratedProductOptionItem",
3418
4036
  value: function normalizeHydratedProductOptionItem(optionItem) {
3419
- var _ref26, _optionItem$num, _ref27, _optionItem$add_price;
3420
- var rawNum = (_ref26 = (_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 && _ref26 !== void 0 ? _ref26 : 1;
4037
+ var _ref66, _optionItem$num, _ref67, _optionItem$add_price;
4038
+ var rawNum = (_ref66 = (_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 && _ref66 !== void 0 ? _ref66 : 1;
3421
4039
  var parsedNum = Number(rawNum);
3422
- var rawPrice = (_ref27 = (_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 && _ref27 !== void 0 ? _ref27 : 0;
4040
+ var rawPrice = (_ref67 = (_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 && _ref67 !== void 0 ? _ref67 : 0;
3423
4041
  var parsedPrice = Number(rawPrice);
3424
4042
  var normalized = _objectSpread(_objectSpread({}, optionItem), {}, {
3425
4043
  option_group_item_id: optionItem === null || optionItem === void 0 ? void 0 : optionItem.option_group_item_id,
@@ -3436,7 +4054,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3436
4054
  }, {
3437
4055
  key: "normalizeHydratedOrderProduct",
3438
4056
  value: function normalizeHydratedOrderProduct(product) {
3439
- var _this13 = this;
4057
+ var _this20 = this;
3440
4058
  var row = _objectSpread({}, product || {});
3441
4059
  if (row.num === undefined && row.product_quantity !== undefined) {
3442
4060
  row.num = row.product_quantity;
@@ -3444,7 +4062,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3444
4062
  var productSku = ensureProductSku(row);
3445
4063
  row.product_sku = _objectSpread(_objectSpread({}, productSku), {}, {
3446
4064
  option: normalizeProductSkuOptions(productSku.option.map(function (optionItem) {
3447
- return _this13.normalizeHydratedProductOptionItem(optionItem || {});
4065
+ return _this20.normalizeHydratedProductOptionItem(optionItem || {});
3448
4066
  }))
3449
4067
  });
3450
4068
  delete row["product_".concat('option', "_item")];
@@ -3475,107 +4093,102 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3475
4093
  }, {
3476
4094
  key: "getOrderInfo",
3477
4095
  value: function () {
3478
- var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(order_id) {
4096
+ var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(order_id) {
3479
4097
  var res;
3480
- return _regeneratorRuntime().wrap(function _callee29$(_context31) {
3481
- while (1) switch (_context31.prev = _context31.next) {
4098
+ return _regeneratorRuntime().wrap(function _callee30$(_context32) {
4099
+ while (1) switch (_context32.prev = _context32.next) {
3482
4100
  case 0:
3483
- _context31.next = 2;
4101
+ _context32.next = 2;
3484
4102
  return this.request.get("/order/sales/".concat(order_id), {
3485
4103
  with: ['products', 'bookings']
3486
4104
  });
3487
4105
  case 2:
3488
- res = _context31.sent;
3489
- return _context31.abrupt("return", res);
4106
+ res = _context32.sent;
4107
+ return _context32.abrupt("return", res);
3490
4108
  case 4:
3491
4109
  case "end":
3492
- return _context31.stop();
4110
+ return _context32.stop();
3493
4111
  }
3494
- }, _callee29, this);
4112
+ }, _callee30, this);
3495
4113
  }));
3496
- function getOrderInfo(_x31) {
4114
+ function getOrderInfo(_x32) {
3497
4115
  return _getOrderInfo.apply(this, arguments);
3498
4116
  }
3499
4117
  return getOrderInfo;
3500
4118
  }()
3501
4119
  }], [{
3502
4120
  key: "populateSavedAmounts",
3503
- value:
3504
- /**
3505
- * Populate `savedAmount` on each discount based on product-level discount details.
3506
- * Only selected discounts get a non-zero value.
3507
- */
3508
- function populateSavedAmounts(productList, discountList) {
4121
+ value: function populateSavedAmounts(productList, discountList) {
3509
4122
  var savedMap = new Map();
3510
4123
  var addDiscountAmount = function addDiscountAmount(discount, quantity) {
3511
- var _discount$discount, _discount$metadata;
3512
- var discountKey = ((_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) || discount.id;
4124
+ var _discount$discount3, _discount$metadata;
4125
+ var discountKey = ((_discount$discount3 = discount.discount) === null || _discount$discount3 === void 0 ? void 0 : _discount$discount3.resource_id) || discount.id;
3513
4126
  if (discountKey == null) return;
3514
4127
  var qty = Number(quantity) || 1;
3515
4128
  var amount = new Decimal(discount.amount || 0).times(qty).plus(((_discount$metadata = discount.metadata) === null || _discount$metadata === void 0 ? void 0 : _discount$metadata.product_discount_difference) || 0);
3516
4129
  savedMap.set(discountKey, (savedMap.get(discountKey) || new Decimal(0)).plus(amount));
3517
4130
  };
3518
- var _iterator11 = _createForOfIteratorHelper(productList),
3519
- _step11;
4131
+ var _iterator19 = _createForOfIteratorHelper(productList),
4132
+ _step19;
3520
4133
  try {
3521
- for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
3522
- var product = _step11.value;
4134
+ for (_iterator19.s(); !(_step19 = _iterator19.n()).done;) {
4135
+ var product = _step19.value;
3523
4136
  var qty = product.num || 1;
3524
- var _iterator13 = _createForOfIteratorHelper(product.discount_list || []),
3525
- _step13;
4137
+ var _iterator21 = _createForOfIteratorHelper(product.discount_list || []),
4138
+ _step21;
3526
4139
  try {
3527
- for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
3528
- var pd = _step13.value;
4140
+ for (_iterator21.s(); !(_step21 = _iterator21.n()).done;) {
4141
+ var pd = _step21.value;
3529
4142
  addDiscountAmount(pd, qty);
3530
4143
  }
3531
4144
  } catch (err) {
3532
- _iterator13.e(err);
4145
+ _iterator21.e(err);
3533
4146
  } finally {
3534
- _iterator13.f();
4147
+ _iterator21.f();
3535
4148
  }
3536
- var _iterator14 = _createForOfIteratorHelper(product.product_bundle || []),
3537
- _step14;
4149
+ var _iterator22 = _createForOfIteratorHelper(product.product_bundle || []),
4150
+ _step22;
3538
4151
  try {
3539
- for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
3540
- var _ref28, _bundle$num;
3541
- var bundle = _step14.value;
3542
- var bundleQty = new Decimal(Number(qty) || 1).times(Number((_ref28 = (_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) !== null && _ref28 !== void 0 ? _ref28 : 1) || 1).toNumber();
3543
- var _iterator15 = _createForOfIteratorHelper((bundle === null || bundle === void 0 ? void 0 : bundle.discount_list) || []),
3544
- _step15;
4152
+ for (_iterator22.s(); !(_step22 = _iterator22.n()).done;) {
4153
+ var _ref68, _bundle$num3;
4154
+ var bundle = _step22.value;
4155
+ var bundleQty = new Decimal(Number(qty) || 1).times(Number((_ref68 = (_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 && _ref68 !== void 0 ? _ref68 : 1) || 1).toNumber();
4156
+ var _iterator23 = _createForOfIteratorHelper((bundle === null || bundle === void 0 ? void 0 : bundle.discount_list) || []),
4157
+ _step23;
3545
4158
  try {
3546
- for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
3547
- var _pd = _step15.value;
4159
+ for (_iterator23.s(); !(_step23 = _iterator23.n()).done;) {
4160
+ var _pd = _step23.value;
3548
4161
  addDiscountAmount(_pd, bundleQty);
3549
4162
  }
3550
4163
  } catch (err) {
3551
- _iterator15.e(err);
4164
+ _iterator23.e(err);
3552
4165
  } finally {
3553
- _iterator15.f();
4166
+ _iterator23.f();
3554
4167
  }
3555
4168
  }
3556
4169
  } catch (err) {
3557
- _iterator14.e(err);
4170
+ _iterator22.e(err);
3558
4171
  } finally {
3559
- _iterator14.f();
4172
+ _iterator22.f();
3560
4173
  }
3561
4174
  }
3562
4175
  } catch (err) {
3563
- _iterator11.e(err);
4176
+ _iterator19.e(err);
3564
4177
  } finally {
3565
- _iterator11.f();
4178
+ _iterator19.f();
3566
4179
  }
3567
- var _iterator12 = _createForOfIteratorHelper(discountList),
3568
- _step12;
4180
+ var _iterator20 = _createForOfIteratorHelper(discountList),
4181
+ _step20;
3569
4182
  try {
3570
- for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
3571
- var d = _step12.value;
4183
+ for (_iterator20.s(); !(_step20 = _iterator20.n()).done;) {
4184
+ var d = _step20.value;
3572
4185
  var key = d.id;
3573
4186
  d.savedAmount = d.isSelected && key != null && savedMap.has(key) ? savedMap.get(key).toNumber() : 0;
3574
4187
  }
3575
4188
  } catch (err) {
3576
- _iterator12.e(err);
4189
+ _iterator20.e(err);
3577
4190
  } finally {
3578
- _iterator12.f();
4191
+ _iterator20.f();
3579
4192
  }
3580
4193
  }
3581
4194
  }]);