@pisell/pisellos 2.2.174 → 2.2.176
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/modules/Order/index.d.ts +52 -1
- package/dist/modules/Order/index.js +730 -348
- package/dist/modules/Order/types.d.ts +140 -1
- package/dist/modules/Order/types.js +29 -0
- package/dist/modules/Order/utils.d.ts +11 -0
- package/dist/modules/Order/utils.js +43 -2
- package/dist/modules/SalesSummary/utils.js +3 -3
- package/dist/server/index.js +77 -23
- package/dist/solution/BaseSales/index.d.ts +37 -1
- package/dist/solution/BaseSales/index.js +751 -457
- package/dist/solution/BaseSales/utils/cartPromotion.d.ts +275 -0
- package/dist/solution/BaseSales/utils/cartPromotion.js +1258 -0
- package/dist/solution/BookingTicket/index.js +4 -0
- package/dist/solution/BookingTicket/utils/cartView.js +4 -2
- package/lib/model/strategy/adapter/promotion/index.js +0 -49
- package/lib/modules/Order/index.d.ts +52 -1
- package/lib/modules/Order/index.js +195 -6
- package/lib/modules/Order/types.d.ts +140 -1
- package/lib/modules/Order/types.js +1 -0
- package/lib/modules/Order/utils.d.ts +11 -0
- package/lib/modules/Order/utils.js +34 -2
- package/lib/modules/SalesSummary/utils.js +3 -3
- package/lib/server/index.js +39 -4
- package/lib/solution/BaseSales/index.d.ts +37 -1
- package/lib/solution/BaseSales/index.js +207 -1
- package/lib/solution/BaseSales/utils/cartPromotion.d.ts +275 -0
- package/lib/solution/BaseSales/utils/cartPromotion.js +836 -0
- package/lib/solution/BookingTicket/index.js +3 -0
- package/lib/solution/BookingTicket/utils/cartView.js +4 -2
- package/package.json +1 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
2
1
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
3
2
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
5
3
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
6
4
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
7
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
8
5
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
6
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
7
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
8
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
9
9
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
10
10
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
11
11
|
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
@@ -26,9 +26,10 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
26
26
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
27
27
|
import { BaseModule } from "../BaseModule";
|
|
28
28
|
import { OrderHooks } from "./types";
|
|
29
|
-
import { composeLinePrice, generateDuration, getAllDiscountList, mergeRelationForms, buildSubmitPayload, createDefaultTempOrder, createDefaultOrderRulesHooks, createEmptySummary, createUuidV4, formatDateTime, isTempOrder, normalizeBookingIsAll, normalizeBookingSubType, mapPaymentItemsToOrderPayments, normalizeOrderProductDiscountList, sumOptionUnitPrice, clearTempOrderHolderAssignments } from "./utils";
|
|
29
|
+
import { composeLinePrice, generateDuration, getAllDiscountList, mergeRelationForms, buildSubmitPayload, createDefaultTempOrder, createDefaultOrderRulesHooks, createEmptySummary, createUuidV4, formatDateTime, isTempOrder, normalizeBookingIsAll, normalizeBookingSubType, mapPaymentItemsToOrderPayments, normalizeOrderProductDiscountList, resolveEffectivePerUnitDiscount, sumOptionUnitPrice, clearTempOrderHolderAssignments } from "./utils";
|
|
30
30
|
import { isNormalProduct } from "../Product/utils";
|
|
31
31
|
import dayjs from 'dayjs';
|
|
32
|
+
import { processCartPromotion, appendPromotionTags as _appendPromotionTags, getOrderProductUid as getPromotionUid } from "../../solution/BaseSales/utils/cartPromotion";
|
|
32
33
|
import { buildProductLineFingerprint, getProductIdentityIndex, getSafeProductNum, isIdentityMatch, normalizeOrderProduct } from "../../solution/ScanOrder/utils";
|
|
33
34
|
import { syncManualProductDiscountProductNum } from "./utils/manualProductDiscount";
|
|
34
35
|
import { DiscountModule } from "../Discount";
|
|
@@ -57,6 +58,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
57
58
|
_defineProperty(_assertThisInitialized(_this), "rulesHooksOverride", void 0);
|
|
58
59
|
_defineProperty(_assertThisInitialized(_this), "orderHooks", void 0);
|
|
59
60
|
_defineProperty(_assertThisInitialized(_this), "otherParams", void 0);
|
|
61
|
+
// ─── 促销/赠品 ────────────────────────────────────
|
|
62
|
+
/** 评估器引用;由 SalesSdkProvider 注入,未注入时 applyPromotion 静默跳过 */
|
|
63
|
+
_defineProperty(_assertThisInitialized(_this), "promotionEvaluator", null);
|
|
64
|
+
/** 赠品选择 resolver;由 SDK host bridge 注入 */
|
|
65
|
+
_defineProperty(_assertThisInitialized(_this), "giftSelectResolver", null);
|
|
66
|
+
/** applyPromotion 递归保护 flag(写路径同步调 applyPromotion,禁止重入) */
|
|
67
|
+
_defineProperty(_assertThisInitialized(_this), "isApplyingPromotion", false);
|
|
68
|
+
/** 最近一次 applyPromotion 的未满足促销提示 */
|
|
69
|
+
_defineProperty(_assertThisInitialized(_this), "lastUnfulfilledPromotions", []);
|
|
70
|
+
/** 最近一次 applyPromotion 的赠品操作 diff(debug / SDK 读取使用) */
|
|
71
|
+
_defineProperty(_assertThisInitialized(_this), "lastGiftActions", null);
|
|
60
72
|
return _this;
|
|
61
73
|
}
|
|
62
74
|
_createClass(OrderModule, [{
|
|
@@ -65,9 +77,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
65
77
|
return (products || []).map(function (product) {
|
|
66
78
|
var _product$metadata, _product$metadata$sou, _product$metadata2, _product$metadata3, _product$original_pri;
|
|
67
79
|
if ((_product$metadata = product.metadata) !== null && _product$metadata !== void 0 && _product$metadata.is_manual_discount) return product;
|
|
68
|
-
var totalPerUnitDiscount = (product
|
|
69
|
-
return sum + Number(discount.amount || 0);
|
|
70
|
-
}, 0);
|
|
80
|
+
var totalPerUnitDiscount = resolveEffectivePerUnitDiscount(product);
|
|
71
81
|
var optionSum = sumOptionUnitPrice(product.product_option_item);
|
|
72
82
|
var sourcePrice = (_product$metadata$sou = (_product$metadata2 = product.metadata) === null || _product$metadata2 === void 0 ? void 0 : _product$metadata2.source_product_price) !== null && _product$metadata$sou !== void 0 ? _product$metadata$sou : ((_product$metadata3 = product.metadata) === null || _product$metadata3 === void 0 ? void 0 : _product$metadata3.main_product_original_price) != null ? new Decimal(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : (_product$original_pri = product.original_price) !== null && _product$original_pri !== void 0 ? _product$original_pri : '0';
|
|
73
83
|
var newSourceSellingPrice = new Decimal(Number(sourcePrice) || 0).minus(totalPerUnitDiscount).toDecimalPlaces(2).toString();
|
|
@@ -413,6 +423,344 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
413
423
|
}
|
|
414
424
|
}
|
|
415
425
|
|
|
426
|
+
// ─── 促销/赠品 ──────────────────────────────────────
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* 注入促销评估器。
|
|
430
|
+
*
|
|
431
|
+
* @example
|
|
432
|
+
* order.setPromotionEvaluator(appHelper.utils.promotionEvaluator);
|
|
433
|
+
*/
|
|
434
|
+
}, {
|
|
435
|
+
key: "setPromotionEvaluator",
|
|
436
|
+
value: function setPromotionEvaluator(evaluator) {
|
|
437
|
+
this.promotionEvaluator = evaluator || null;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* 注入赠品选择 resolver。OS 需要补赠品时会 await 调用 resolver;缺省时跳过新增并 console.warn。
|
|
442
|
+
*
|
|
443
|
+
* @example
|
|
444
|
+
* order.setGiftSelectResolver(async (ctx) => {
|
|
445
|
+
* // SDK 内部决定弹窗 or 自动选第一项,返回完整 OrderProduct[]
|
|
446
|
+
* return giftSelectBridge.request(ctx);
|
|
447
|
+
* });
|
|
448
|
+
*/
|
|
449
|
+
}, {
|
|
450
|
+
key: "setGiftSelectResolver",
|
|
451
|
+
value: function setGiftSelectResolver(resolver) {
|
|
452
|
+
this.giftSelectResolver = resolver || null;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* 为商品目录追加促销标签,供上层 Sales 门面复用。
|
|
457
|
+
*
|
|
458
|
+
* @example
|
|
459
|
+
* const products = order.appendPromotionTags(catalogProducts);
|
|
460
|
+
*/
|
|
461
|
+
}, {
|
|
462
|
+
key: "appendPromotionTags",
|
|
463
|
+
value: function appendPromotionTags(products) {
|
|
464
|
+
return _appendPromotionTags(products, this.promotionEvaluator);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* 应用购物车促销:计算 → 差异化赠品 → 写回 tempOrder.products → emit onPromotionApplied。
|
|
469
|
+
*
|
|
470
|
+
* 调用时机:写路径(add/update/remove/clear/setCustomer)末尾自动触发;外部一般无需手动调。
|
|
471
|
+
*
|
|
472
|
+
* 关键约束:
|
|
473
|
+
* - 不调用任何公开 CRUD API(如 removeProductFromOrder),全部内部 mutate tempOrder.products,避免事件风暴;
|
|
474
|
+
* - 用 `isApplyingPromotion` 防递归;
|
|
475
|
+
* - 多选项赠品依赖 giftSelectResolver,未注入则跳过且 console.warn;
|
|
476
|
+
* - 不主动调用 applyDiscount / recalculateSummary,调用方负责跟进。
|
|
477
|
+
*/
|
|
478
|
+
}, {
|
|
479
|
+
key: "applyPromotion",
|
|
480
|
+
value: (function () {
|
|
481
|
+
var _applyPromotion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
|
482
|
+
var _this2 = this;
|
|
483
|
+
var tempOrder, result, removeSet, _iterator, _step, reduce, _iterator4, _step4, _loop2, _iterator2, _step2, _loop, payload;
|
|
484
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context6) {
|
|
485
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
486
|
+
case 0:
|
|
487
|
+
if (!this.isApplyingPromotion) {
|
|
488
|
+
_context6.next = 2;
|
|
489
|
+
break;
|
|
490
|
+
}
|
|
491
|
+
return _context6.abrupt("return");
|
|
492
|
+
case 2:
|
|
493
|
+
if (this.promotionEvaluator) {
|
|
494
|
+
_context6.next = 4;
|
|
495
|
+
break;
|
|
496
|
+
}
|
|
497
|
+
return _context6.abrupt("return");
|
|
498
|
+
case 4:
|
|
499
|
+
tempOrder = this.store.tempOrder;
|
|
500
|
+
if (tempOrder) {
|
|
501
|
+
_context6.next = 7;
|
|
502
|
+
break;
|
|
503
|
+
}
|
|
504
|
+
return _context6.abrupt("return");
|
|
505
|
+
case 7:
|
|
506
|
+
this.isApplyingPromotion = true;
|
|
507
|
+
_context6.prev = 8;
|
|
508
|
+
result = processCartPromotion(tempOrder.products, this.promotionEvaluator); // step 1: toRemove —— 直接过滤
|
|
509
|
+
if (result.giftActions.toRemove.length > 0) {
|
|
510
|
+
removeSet = new Set(result.giftActions.toRemove.map(String));
|
|
511
|
+
result.products = result.products.filter(function (p) {
|
|
512
|
+
var uid = getPromotionUid(p);
|
|
513
|
+
return uid ? !removeSet.has(String(uid)) : true;
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
// step 2: toReduce —— 调整数量
|
|
518
|
+
_iterator = _createForOfIteratorHelper(result.giftActions.toReduce);
|
|
519
|
+
_context6.prev = 12;
|
|
520
|
+
_iterator.s();
|
|
521
|
+
case 14:
|
|
522
|
+
if ((_step = _iterator.n()).done) {
|
|
523
|
+
_context6.next = 34;
|
|
524
|
+
break;
|
|
525
|
+
}
|
|
526
|
+
reduce = _step.value;
|
|
527
|
+
_iterator4 = _createForOfIteratorHelper(reduce.items);
|
|
528
|
+
_context6.prev = 17;
|
|
529
|
+
_loop2 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop2() {
|
|
530
|
+
var item, product;
|
|
531
|
+
return _regeneratorRuntime().wrap(function _loop2$(_context5) {
|
|
532
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
533
|
+
case 0:
|
|
534
|
+
item = _step4.value;
|
|
535
|
+
product = result.products.find(function (p) {
|
|
536
|
+
return getPromotionUid(p) === item.uid;
|
|
537
|
+
});
|
|
538
|
+
if (product) {
|
|
539
|
+
product.num = item.newQuantity;
|
|
540
|
+
}
|
|
541
|
+
case 3:
|
|
542
|
+
case "end":
|
|
543
|
+
return _context5.stop();
|
|
544
|
+
}
|
|
545
|
+
}, _loop2);
|
|
546
|
+
});
|
|
547
|
+
_iterator4.s();
|
|
548
|
+
case 20:
|
|
549
|
+
if ((_step4 = _iterator4.n()).done) {
|
|
550
|
+
_context6.next = 24;
|
|
551
|
+
break;
|
|
552
|
+
}
|
|
553
|
+
return _context6.delegateYield(_loop2(), "t0", 22);
|
|
554
|
+
case 22:
|
|
555
|
+
_context6.next = 20;
|
|
556
|
+
break;
|
|
557
|
+
case 24:
|
|
558
|
+
_context6.next = 29;
|
|
559
|
+
break;
|
|
560
|
+
case 26:
|
|
561
|
+
_context6.prev = 26;
|
|
562
|
+
_context6.t1 = _context6["catch"](17);
|
|
563
|
+
_iterator4.e(_context6.t1);
|
|
564
|
+
case 29:
|
|
565
|
+
_context6.prev = 29;
|
|
566
|
+
_iterator4.f();
|
|
567
|
+
return _context6.finish(29);
|
|
568
|
+
case 32:
|
|
569
|
+
_context6.next = 14;
|
|
570
|
+
break;
|
|
571
|
+
case 34:
|
|
572
|
+
_context6.next = 39;
|
|
573
|
+
break;
|
|
574
|
+
case 36:
|
|
575
|
+
_context6.prev = 36;
|
|
576
|
+
_context6.t2 = _context6["catch"](12);
|
|
577
|
+
_iterator.e(_context6.t2);
|
|
578
|
+
case 39:
|
|
579
|
+
_context6.prev = 39;
|
|
580
|
+
_iterator.f();
|
|
581
|
+
return _context6.finish(39);
|
|
582
|
+
case 42:
|
|
583
|
+
if (!(result.giftActions.toAdd.length > 0)) {
|
|
584
|
+
_context6.next = 65;
|
|
585
|
+
break;
|
|
586
|
+
}
|
|
587
|
+
if (this.giftSelectResolver) {
|
|
588
|
+
_context6.next = 47;
|
|
589
|
+
break;
|
|
590
|
+
}
|
|
591
|
+
if (result.giftActions.toAdd.some(function (g) {
|
|
592
|
+
return g.giftOptions.length > 1;
|
|
593
|
+
})) {
|
|
594
|
+
// 多选项必须走 resolver;单选项也建议走(避免 OS 自造 stub),但允许跳过
|
|
595
|
+
console.warn('[OrderModule] giftSelectResolver not set, skip applying gifts', result.giftActions.toAdd);
|
|
596
|
+
} else {
|
|
597
|
+
console.warn('[OrderModule] giftSelectResolver not set, skip applying single-option gifts', result.giftActions.toAdd);
|
|
598
|
+
}
|
|
599
|
+
_context6.next = 65;
|
|
600
|
+
break;
|
|
601
|
+
case 47:
|
|
602
|
+
_iterator2 = _createForOfIteratorHelper(result.giftActions.toAdd);
|
|
603
|
+
_context6.prev = 48;
|
|
604
|
+
_loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
|
|
605
|
+
var addAction, sameStrategy, giftProducts, _iterator3, _step3, gp;
|
|
606
|
+
return _regeneratorRuntime().wrap(function _loop$(_context4) {
|
|
607
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
608
|
+
case 0:
|
|
609
|
+
addAction = _step2.value;
|
|
610
|
+
if (!(addAction.giftOptions.length === 1)) {
|
|
611
|
+
_context4.next = 6;
|
|
612
|
+
break;
|
|
613
|
+
}
|
|
614
|
+
sameStrategy = result.products.find(function (p) {
|
|
615
|
+
var _p$metadata;
|
|
616
|
+
return ((_p$metadata = p.metadata) === null || _p$metadata === void 0 || (_p$metadata = _p$metadata._giftInfo) === null || _p$metadata === void 0 ? void 0 : _p$metadata.strategyId) === addAction.strategyId;
|
|
617
|
+
});
|
|
618
|
+
if (!sameStrategy) {
|
|
619
|
+
_context4.next = 6;
|
|
620
|
+
break;
|
|
621
|
+
}
|
|
622
|
+
sameStrategy.num = (Number(sameStrategy.num) || 0) + (addAction.giftCount || 1);
|
|
623
|
+
return _context4.abrupt("return", 1);
|
|
624
|
+
case 6:
|
|
625
|
+
_context4.prev = 6;
|
|
626
|
+
_context4.next = 9;
|
|
627
|
+
return _this2.giftSelectResolver({
|
|
628
|
+
strategyId: addAction.strategyId,
|
|
629
|
+
strategyName: addAction.strategyName,
|
|
630
|
+
giftCount: addAction.giftCount,
|
|
631
|
+
giftOptions: addAction.giftOptions,
|
|
632
|
+
sourceProductIds: addAction.sourceProductIds
|
|
633
|
+
});
|
|
634
|
+
case 9:
|
|
635
|
+
giftProducts = _context4.sent;
|
|
636
|
+
if (!(Array.isArray(giftProducts) && giftProducts.length > 0)) {
|
|
637
|
+
_context4.next = 29;
|
|
638
|
+
break;
|
|
639
|
+
}
|
|
640
|
+
_iterator3 = _createForOfIteratorHelper(giftProducts);
|
|
641
|
+
_context4.prev = 12;
|
|
642
|
+
_iterator3.s();
|
|
643
|
+
case 14:
|
|
644
|
+
if ((_step3 = _iterator3.n()).done) {
|
|
645
|
+
_context4.next = 21;
|
|
646
|
+
break;
|
|
647
|
+
}
|
|
648
|
+
gp = _step3.value;
|
|
649
|
+
if (gp) {
|
|
650
|
+
_context4.next = 18;
|
|
651
|
+
break;
|
|
652
|
+
}
|
|
653
|
+
return _context4.abrupt("continue", 19);
|
|
654
|
+
case 18:
|
|
655
|
+
// normalize 略过:调用方应保证返回完整 OrderProduct
|
|
656
|
+
result.products.push(gp);
|
|
657
|
+
case 19:
|
|
658
|
+
_context4.next = 14;
|
|
659
|
+
break;
|
|
660
|
+
case 21:
|
|
661
|
+
_context4.next = 26;
|
|
662
|
+
break;
|
|
663
|
+
case 23:
|
|
664
|
+
_context4.prev = 23;
|
|
665
|
+
_context4.t0 = _context4["catch"](12);
|
|
666
|
+
_iterator3.e(_context4.t0);
|
|
667
|
+
case 26:
|
|
668
|
+
_context4.prev = 26;
|
|
669
|
+
_iterator3.f();
|
|
670
|
+
return _context4.finish(26);
|
|
671
|
+
case 29:
|
|
672
|
+
_context4.next = 34;
|
|
673
|
+
break;
|
|
674
|
+
case 31:
|
|
675
|
+
_context4.prev = 31;
|
|
676
|
+
_context4.t1 = _context4["catch"](6);
|
|
677
|
+
// 用户取消 / 选择失败 → 视为放弃本次新增
|
|
678
|
+
console.warn('[OrderModule] giftSelectResolver rejected, skip add gift', addAction.strategyId, _context4.t1);
|
|
679
|
+
case 34:
|
|
680
|
+
case "end":
|
|
681
|
+
return _context4.stop();
|
|
682
|
+
}
|
|
683
|
+
}, _loop, null, [[6, 31], [12, 23, 26, 29]]);
|
|
684
|
+
});
|
|
685
|
+
_iterator2.s();
|
|
686
|
+
case 51:
|
|
687
|
+
if ((_step2 = _iterator2.n()).done) {
|
|
688
|
+
_context6.next = 57;
|
|
689
|
+
break;
|
|
690
|
+
}
|
|
691
|
+
return _context6.delegateYield(_loop(), "t3", 53);
|
|
692
|
+
case 53:
|
|
693
|
+
if (!_context6.t3) {
|
|
694
|
+
_context6.next = 55;
|
|
695
|
+
break;
|
|
696
|
+
}
|
|
697
|
+
return _context6.abrupt("continue", 55);
|
|
698
|
+
case 55:
|
|
699
|
+
_context6.next = 51;
|
|
700
|
+
break;
|
|
701
|
+
case 57:
|
|
702
|
+
_context6.next = 62;
|
|
703
|
+
break;
|
|
704
|
+
case 59:
|
|
705
|
+
_context6.prev = 59;
|
|
706
|
+
_context6.t4 = _context6["catch"](48);
|
|
707
|
+
_iterator2.e(_context6.t4);
|
|
708
|
+
case 62:
|
|
709
|
+
_context6.prev = 62;
|
|
710
|
+
_iterator2.f();
|
|
711
|
+
return _context6.finish(62);
|
|
712
|
+
case 65:
|
|
713
|
+
tempOrder.products = result.products;
|
|
714
|
+
this.lastUnfulfilledPromotions = result.unfulfilledPromotions;
|
|
715
|
+
this.lastGiftActions = result.giftActions;
|
|
716
|
+
payload = {
|
|
717
|
+
unfulfilledPromotions: result.unfulfilledPromotions,
|
|
718
|
+
giftActions: result.giftActions,
|
|
719
|
+
gifts: result.gifts.map(function (g) {
|
|
720
|
+
return {
|
|
721
|
+
strategyId: g.strategyId,
|
|
722
|
+
strategyName: g.strategyName,
|
|
723
|
+
giftCount: g.giftCount,
|
|
724
|
+
giftOptions: g.giftOptions
|
|
725
|
+
};
|
|
726
|
+
}),
|
|
727
|
+
products: tempOrder.products
|
|
728
|
+
};
|
|
729
|
+
this.effectsEmit('onPromotionApplied', payload);
|
|
730
|
+
_context6.next = 75;
|
|
731
|
+
break;
|
|
732
|
+
case 72:
|
|
733
|
+
_context6.prev = 72;
|
|
734
|
+
_context6.t5 = _context6["catch"](8);
|
|
735
|
+
console.error('[OrderModule] applyPromotion failed', _context6.t5);
|
|
736
|
+
case 75:
|
|
737
|
+
_context6.prev = 75;
|
|
738
|
+
this.isApplyingPromotion = false;
|
|
739
|
+
return _context6.finish(75);
|
|
740
|
+
case 78:
|
|
741
|
+
case "end":
|
|
742
|
+
return _context6.stop();
|
|
743
|
+
}
|
|
744
|
+
}, _callee4, this, [[8, 72, 75, 78], [12, 36, 39, 42], [17, 26, 29, 32], [48, 59, 62, 65]]);
|
|
745
|
+
}));
|
|
746
|
+
function applyPromotion() {
|
|
747
|
+
return _applyPromotion.apply(this, arguments);
|
|
748
|
+
}
|
|
749
|
+
return applyPromotion;
|
|
750
|
+
}() /** 最近一次 applyPromotion 输出的未满足促销列表 */)
|
|
751
|
+
}, {
|
|
752
|
+
key: "getUnfulfilledPromotions",
|
|
753
|
+
value: function getUnfulfilledPromotions() {
|
|
754
|
+
return this.lastUnfulfilledPromotions;
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
/** 最近一次 applyPromotion 输出的赠品操作 diff */
|
|
758
|
+
}, {
|
|
759
|
+
key: "getLastGiftActions",
|
|
760
|
+
value: function getLastGiftActions() {
|
|
761
|
+
return this.lastGiftActions;
|
|
762
|
+
}
|
|
763
|
+
|
|
416
764
|
// ─── TempOrder: 初始化入口 ───
|
|
417
765
|
}, {
|
|
418
766
|
key: "initTempOrder",
|
|
@@ -494,6 +842,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
494
842
|
}
|
|
495
843
|
return tempOrder.request_unique_idempotency_token;
|
|
496
844
|
}
|
|
845
|
+
}, {
|
|
846
|
+
key: "buildPaymentSyncIdempotencyToken",
|
|
847
|
+
value: function buildPaymentSyncIdempotencyToken(tempOrder, payments) {
|
|
848
|
+
var baseToken = this.ensureRequestUniqueIdempotencyToken(tempOrder);
|
|
849
|
+
var paidPaymentsCount = (payments || []).filter(function (payment) {
|
|
850
|
+
return String((payment === null || payment === void 0 ? void 0 : payment.status) || '').toLowerCase() === 'paid';
|
|
851
|
+
}).length;
|
|
852
|
+
var paidCount = paidPaymentsCount > 0 ? paidPaymentsCount : payments.length;
|
|
853
|
+
return "".concat(baseToken, "_payment_").concat(paidCount);
|
|
854
|
+
}
|
|
497
855
|
}, {
|
|
498
856
|
key: "hasLocalDatabase",
|
|
499
857
|
value: function hasLocalDatabase() {
|
|
@@ -514,48 +872,48 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
514
872
|
}, {
|
|
515
873
|
key: "getLocalOrderByOrderId",
|
|
516
874
|
value: function () {
|
|
517
|
-
var _getLocalOrderByOrderId = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
875
|
+
var _getLocalOrderByOrderId = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(orderId) {
|
|
518
876
|
var _this$dbManager$get, _this$dbManager, _this$dbManager$getAl, _this$dbManager2, direct, orders;
|
|
519
|
-
return _regeneratorRuntime().wrap(function
|
|
520
|
-
while (1) switch (
|
|
877
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context7) {
|
|
878
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
521
879
|
case 0:
|
|
522
880
|
if (!(!this.dbManager || orderId === undefined || orderId === null)) {
|
|
523
|
-
|
|
881
|
+
_context7.next = 2;
|
|
524
882
|
break;
|
|
525
883
|
}
|
|
526
|
-
return
|
|
884
|
+
return _context7.abrupt("return", null);
|
|
527
885
|
case 2:
|
|
528
|
-
|
|
529
|
-
|
|
886
|
+
_context7.prev = 2;
|
|
887
|
+
_context7.next = 5;
|
|
530
888
|
return (_this$dbManager$get = (_this$dbManager = this.dbManager).get) === null || _this$dbManager$get === void 0 ? void 0 : _this$dbManager$get.call(_this$dbManager, LOCAL_ORDER_STORE_NAME, orderId);
|
|
531
889
|
case 5:
|
|
532
|
-
direct =
|
|
890
|
+
direct = _context7.sent;
|
|
533
891
|
if (!direct) {
|
|
534
|
-
|
|
892
|
+
_context7.next = 8;
|
|
535
893
|
break;
|
|
536
894
|
}
|
|
537
|
-
return
|
|
895
|
+
return _context7.abrupt("return", direct);
|
|
538
896
|
case 8:
|
|
539
|
-
|
|
897
|
+
_context7.next = 10;
|
|
540
898
|
return (_this$dbManager$getAl = (_this$dbManager2 = this.dbManager).getAll) === null || _this$dbManager$getAl === void 0 ? void 0 : _this$dbManager$getAl.call(_this$dbManager2, LOCAL_ORDER_STORE_NAME);
|
|
541
899
|
case 10:
|
|
542
|
-
orders =
|
|
543
|
-
return
|
|
900
|
+
orders = _context7.sent;
|
|
901
|
+
return _context7.abrupt("return", (orders || []).find(function (order) {
|
|
544
902
|
return String(order === null || order === void 0 ? void 0 : order.order_id) === String(orderId);
|
|
545
903
|
}) || null);
|
|
546
904
|
case 14:
|
|
547
|
-
|
|
548
|
-
|
|
905
|
+
_context7.prev = 14;
|
|
906
|
+
_context7.t0 = _context7["catch"](2);
|
|
549
907
|
this.logWarning('getLocalOrderByOrderId failed', {
|
|
550
908
|
orderId: orderId,
|
|
551
|
-
error:
|
|
909
|
+
error: _context7.t0 instanceof Error ? _context7.t0.message : String(_context7.t0)
|
|
552
910
|
});
|
|
553
|
-
return
|
|
911
|
+
return _context7.abrupt("return", null);
|
|
554
912
|
case 18:
|
|
555
913
|
case "end":
|
|
556
|
-
return
|
|
914
|
+
return _context7.stop();
|
|
557
915
|
}
|
|
558
|
-
},
|
|
916
|
+
}, _callee5, this, [[2, 14]]);
|
|
559
917
|
}));
|
|
560
918
|
function getLocalOrderByOrderId(_x6) {
|
|
561
919
|
return _getLocalOrderByOrderId.apply(this, arguments);
|
|
@@ -565,48 +923,48 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
565
923
|
}, {
|
|
566
924
|
key: "getLocalOrderByOrderNumber",
|
|
567
925
|
value: function () {
|
|
568
|
-
var _getLocalOrderByOrderNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
926
|
+
var _getLocalOrderByOrderNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(orderNumber) {
|
|
569
927
|
var _this$dbManager$get2, _this$dbManager3, _this$dbManager$getAl2, _this$dbManager4, direct, orders;
|
|
570
|
-
return _regeneratorRuntime().wrap(function
|
|
571
|
-
while (1) switch (
|
|
928
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context8) {
|
|
929
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
572
930
|
case 0:
|
|
573
931
|
if (!(!this.dbManager || !orderNumber)) {
|
|
574
|
-
|
|
932
|
+
_context8.next = 2;
|
|
575
933
|
break;
|
|
576
934
|
}
|
|
577
|
-
return
|
|
935
|
+
return _context8.abrupt("return", null);
|
|
578
936
|
case 2:
|
|
579
|
-
|
|
580
|
-
|
|
937
|
+
_context8.prev = 2;
|
|
938
|
+
_context8.next = 5;
|
|
581
939
|
return (_this$dbManager$get2 = (_this$dbManager3 = this.dbManager).get) === null || _this$dbManager$get2 === void 0 ? void 0 : _this$dbManager$get2.call(_this$dbManager3, LOCAL_ORDER_STORE_NAME, orderNumber);
|
|
582
940
|
case 5:
|
|
583
|
-
direct =
|
|
941
|
+
direct = _context8.sent;
|
|
584
942
|
if (!direct) {
|
|
585
|
-
|
|
943
|
+
_context8.next = 8;
|
|
586
944
|
break;
|
|
587
945
|
}
|
|
588
|
-
return
|
|
946
|
+
return _context8.abrupt("return", direct);
|
|
589
947
|
case 8:
|
|
590
|
-
|
|
948
|
+
_context8.next = 10;
|
|
591
949
|
return (_this$dbManager$getAl2 = (_this$dbManager4 = this.dbManager).getAll) === null || _this$dbManager$getAl2 === void 0 ? void 0 : _this$dbManager$getAl2.call(_this$dbManager4, LOCAL_ORDER_STORE_NAME);
|
|
592
950
|
case 10:
|
|
593
|
-
orders =
|
|
594
|
-
return
|
|
951
|
+
orders = _context8.sent;
|
|
952
|
+
return _context8.abrupt("return", (orders || []).find(function (order) {
|
|
595
953
|
return String(order === null || order === void 0 ? void 0 : order.order_number) === String(orderNumber);
|
|
596
954
|
}) || null);
|
|
597
955
|
case 14:
|
|
598
|
-
|
|
599
|
-
|
|
956
|
+
_context8.prev = 14;
|
|
957
|
+
_context8.t0 = _context8["catch"](2);
|
|
600
958
|
this.logWarning('getLocalOrderByOrderNumber failed', {
|
|
601
959
|
orderNumber: orderNumber,
|
|
602
|
-
error:
|
|
960
|
+
error: _context8.t0 instanceof Error ? _context8.t0.message : String(_context8.t0)
|
|
603
961
|
});
|
|
604
|
-
return
|
|
962
|
+
return _context8.abrupt("return", null);
|
|
605
963
|
case 18:
|
|
606
964
|
case "end":
|
|
607
|
-
return
|
|
965
|
+
return _context8.stop();
|
|
608
966
|
}
|
|
609
|
-
},
|
|
967
|
+
}, _callee6, this, [[2, 14]]);
|
|
610
968
|
}));
|
|
611
969
|
function getLocalOrderByOrderNumber(_x7) {
|
|
612
970
|
return _getLocalOrderByOrderNumber.apply(this, arguments);
|
|
@@ -616,48 +974,48 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
616
974
|
}, {
|
|
617
975
|
key: "getLocalOrderByExternalSaleNumber",
|
|
618
976
|
value: function () {
|
|
619
|
-
var _getLocalOrderByExternalSaleNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
977
|
+
var _getLocalOrderByExternalSaleNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(externalSaleNumber) {
|
|
620
978
|
var _this$dbManager$get3, _this$dbManager5, _this$dbManager$getAl3, _this$dbManager6, direct, orders;
|
|
621
|
-
return _regeneratorRuntime().wrap(function
|
|
622
|
-
while (1) switch (
|
|
979
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context9) {
|
|
980
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
623
981
|
case 0:
|
|
624
982
|
if (!(!this.dbManager || !externalSaleNumber)) {
|
|
625
|
-
|
|
983
|
+
_context9.next = 2;
|
|
626
984
|
break;
|
|
627
985
|
}
|
|
628
|
-
return
|
|
986
|
+
return _context9.abrupt("return", null);
|
|
629
987
|
case 2:
|
|
630
|
-
|
|
631
|
-
|
|
988
|
+
_context9.prev = 2;
|
|
989
|
+
_context9.next = 5;
|
|
632
990
|
return (_this$dbManager$get3 = (_this$dbManager5 = this.dbManager).get) === null || _this$dbManager$get3 === void 0 ? void 0 : _this$dbManager$get3.call(_this$dbManager5, LOCAL_ORDER_STORE_NAME, externalSaleNumber);
|
|
633
991
|
case 5:
|
|
634
|
-
direct =
|
|
992
|
+
direct = _context9.sent;
|
|
635
993
|
if (!direct) {
|
|
636
|
-
|
|
994
|
+
_context9.next = 8;
|
|
637
995
|
break;
|
|
638
996
|
}
|
|
639
|
-
return
|
|
997
|
+
return _context9.abrupt("return", direct);
|
|
640
998
|
case 8:
|
|
641
|
-
|
|
999
|
+
_context9.next = 10;
|
|
642
1000
|
return (_this$dbManager$getAl3 = (_this$dbManager6 = this.dbManager).getAll) === null || _this$dbManager$getAl3 === void 0 ? void 0 : _this$dbManager$getAl3.call(_this$dbManager6, LOCAL_ORDER_STORE_NAME);
|
|
643
1001
|
case 10:
|
|
644
|
-
orders =
|
|
645
|
-
return
|
|
1002
|
+
orders = _context9.sent;
|
|
1003
|
+
return _context9.abrupt("return", (orders || []).find(function (order) {
|
|
646
1004
|
return String(order === null || order === void 0 ? void 0 : order.external_sale_number) === String(externalSaleNumber);
|
|
647
1005
|
}) || null);
|
|
648
1006
|
case 14:
|
|
649
|
-
|
|
650
|
-
|
|
1007
|
+
_context9.prev = 14;
|
|
1008
|
+
_context9.t0 = _context9["catch"](2);
|
|
651
1009
|
this.logWarning('getLocalOrderByExternalSaleNumber failed', {
|
|
652
1010
|
externalSaleNumber: externalSaleNumber,
|
|
653
|
-
error:
|
|
1011
|
+
error: _context9.t0 instanceof Error ? _context9.t0.message : String(_context9.t0)
|
|
654
1012
|
});
|
|
655
|
-
return
|
|
1013
|
+
return _context9.abrupt("return", null);
|
|
656
1014
|
case 18:
|
|
657
1015
|
case "end":
|
|
658
|
-
return
|
|
1016
|
+
return _context9.stop();
|
|
659
1017
|
}
|
|
660
|
-
},
|
|
1018
|
+
}, _callee7, this, [[2, 14]]);
|
|
661
1019
|
}));
|
|
662
1020
|
function getLocalOrderByExternalSaleNumber(_x8) {
|
|
663
1021
|
return _getLocalOrderByExternalSaleNumber.apply(this, arguments);
|
|
@@ -667,39 +1025,39 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
667
1025
|
}, {
|
|
668
1026
|
key: "saveDraft",
|
|
669
1027
|
value: function () {
|
|
670
|
-
var _saveDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1028
|
+
var _saveDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
|
|
671
1029
|
var tempOrder, record, _this$dbManager$updat, _this$dbManager7;
|
|
672
|
-
return _regeneratorRuntime().wrap(function
|
|
673
|
-
while (1) switch (
|
|
1030
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context10) {
|
|
1031
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
674
1032
|
case 0:
|
|
675
1033
|
if (this.dbManager) {
|
|
676
|
-
|
|
1034
|
+
_context10.next = 2;
|
|
677
1035
|
break;
|
|
678
1036
|
}
|
|
679
|
-
return
|
|
1037
|
+
return _context10.abrupt("return");
|
|
680
1038
|
case 2:
|
|
681
1039
|
tempOrder = this.ensureTempOrder();
|
|
682
1040
|
record = this.buildLocalOrderRecord(tempOrder);
|
|
683
|
-
|
|
684
|
-
|
|
1041
|
+
_context10.prev = 4;
|
|
1042
|
+
_context10.next = 7;
|
|
685
1043
|
return (_this$dbManager$updat = (_this$dbManager7 = this.dbManager).update) === null || _this$dbManager$updat === void 0 ? void 0 : _this$dbManager$updat.call(_this$dbManager7, LOCAL_ORDER_STORE_NAME, record);
|
|
686
1044
|
case 7:
|
|
687
|
-
|
|
1045
|
+
_context10.next = 12;
|
|
688
1046
|
break;
|
|
689
1047
|
case 9:
|
|
690
|
-
|
|
691
|
-
|
|
1048
|
+
_context10.prev = 9;
|
|
1049
|
+
_context10.t0 = _context10["catch"](4);
|
|
692
1050
|
this.logWarning('saveDraft failed', {
|
|
693
1051
|
externalSaleNumber: tempOrder.external_sale_number,
|
|
694
1052
|
orderNumber: tempOrder.order_number,
|
|
695
1053
|
orderId: tempOrder.order_id,
|
|
696
|
-
error:
|
|
1054
|
+
error: _context10.t0 instanceof Error ? _context10.t0.message : String(_context10.t0)
|
|
697
1055
|
});
|
|
698
1056
|
case 12:
|
|
699
1057
|
case "end":
|
|
700
|
-
return
|
|
1058
|
+
return _context10.stop();
|
|
701
1059
|
}
|
|
702
|
-
},
|
|
1060
|
+
}, _callee8, this, [[4, 9]]);
|
|
703
1061
|
}));
|
|
704
1062
|
function saveDraft() {
|
|
705
1063
|
return _saveDraft.apply(this, arguments);
|
|
@@ -714,16 +1072,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
714
1072
|
}, {
|
|
715
1073
|
key: "hydrateTempOrderFromLocalRecord",
|
|
716
1074
|
value: function () {
|
|
717
|
-
var _hydrateTempOrderFromLocalRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
718
|
-
return _regeneratorRuntime().wrap(function
|
|
719
|
-
while (1) switch (
|
|
1075
|
+
var _hydrateTempOrderFromLocalRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(record) {
|
|
1076
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context11) {
|
|
1077
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
720
1078
|
case 0:
|
|
721
|
-
return
|
|
1079
|
+
return _context11.abrupt("return", this.hydrateTempOrderFromRecord(record));
|
|
722
1080
|
case 1:
|
|
723
1081
|
case "end":
|
|
724
|
-
return
|
|
1082
|
+
return _context11.stop();
|
|
725
1083
|
}
|
|
726
|
-
},
|
|
1084
|
+
}, _callee9, this);
|
|
727
1085
|
}));
|
|
728
1086
|
function hydrateTempOrderFromLocalRecord(_x9) {
|
|
729
1087
|
return _hydrateTempOrderFromLocalRecord.apply(this, arguments);
|
|
@@ -750,14 +1108,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
750
1108
|
}, {
|
|
751
1109
|
key: "calculatePaidPaymentSummary",
|
|
752
1110
|
value: function calculatePaidPaymentSummary(payments) {
|
|
753
|
-
var
|
|
1111
|
+
var _this3 = this;
|
|
754
1112
|
return (payments || []).reduce(function (summary, payment) {
|
|
755
1113
|
var paymentRecord = payment;
|
|
756
1114
|
if ((paymentRecord === null || paymentRecord === void 0 ? void 0 : paymentRecord.status) !== 'paid') return summary;
|
|
757
1115
|
return {
|
|
758
1116
|
customerPaidAmount: summary.customerPaidAmount.plus(paymentRecord.amount || 0),
|
|
759
1117
|
orderPaidAmount: summary.orderPaidAmount.plus(paymentRecord.origin_amount || 0),
|
|
760
|
-
payServiceChargeAmount: summary.payServiceChargeAmount.plus(
|
|
1118
|
+
payServiceChargeAmount: summary.payServiceChargeAmount.plus(_this3.calculatePaymentServiceFee(paymentRecord))
|
|
761
1119
|
};
|
|
762
1120
|
}, {
|
|
763
1121
|
customerPaidAmount: new Decimal(0),
|
|
@@ -822,13 +1180,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
822
1180
|
}, {
|
|
823
1181
|
key: "replaceTempOrder",
|
|
824
1182
|
value: function () {
|
|
825
|
-
var _replaceTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1183
|
+
var _replaceTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(tempOrder, options) {
|
|
826
1184
|
var nextTempOrder;
|
|
827
|
-
return _regeneratorRuntime().wrap(function
|
|
828
|
-
while (1) switch (
|
|
1185
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context12) {
|
|
1186
|
+
while (1) switch (_context12.prev = _context12.next) {
|
|
829
1187
|
case 0:
|
|
830
1188
|
if (isTempOrder(tempOrder)) {
|
|
831
|
-
|
|
1189
|
+
_context12.next = 2;
|
|
832
1190
|
break;
|
|
833
1191
|
}
|
|
834
1192
|
throw new Error('无效的 tempOrder 数据');
|
|
@@ -838,15 +1196,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
838
1196
|
});
|
|
839
1197
|
this.store.tempOrder = nextTempOrder;
|
|
840
1198
|
if (!((options === null || options === void 0 ? void 0 : options.recalculateSummary) !== false)) {
|
|
841
|
-
|
|
1199
|
+
_context12.next = 9;
|
|
842
1200
|
break;
|
|
843
1201
|
}
|
|
844
|
-
|
|
1202
|
+
_context12.next = 7;
|
|
845
1203
|
return this.recalculateSummary({
|
|
846
1204
|
createIfMissing: false
|
|
847
1205
|
});
|
|
848
1206
|
case 7:
|
|
849
|
-
|
|
1207
|
+
_context12.next = 10;
|
|
850
1208
|
break;
|
|
851
1209
|
case 9:
|
|
852
1210
|
this.store.summary = createEmptySummary();
|
|
@@ -855,18 +1213,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
855
1213
|
this.persistTempOrder();
|
|
856
1214
|
}
|
|
857
1215
|
if (!(options !== null && options !== void 0 && options.saveDraft)) {
|
|
858
|
-
|
|
1216
|
+
_context12.next = 14;
|
|
859
1217
|
break;
|
|
860
1218
|
}
|
|
861
|
-
|
|
1219
|
+
_context12.next = 14;
|
|
862
1220
|
return this.saveDraft();
|
|
863
1221
|
case 14:
|
|
864
|
-
return
|
|
1222
|
+
return _context12.abrupt("return", nextTempOrder);
|
|
865
1223
|
case 15:
|
|
866
1224
|
case "end":
|
|
867
|
-
return
|
|
1225
|
+
return _context12.stop();
|
|
868
1226
|
}
|
|
869
|
-
},
|
|
1227
|
+
}, _callee10, this);
|
|
870
1228
|
}));
|
|
871
1229
|
function replaceTempOrder(_x10, _x11) {
|
|
872
1230
|
return _replaceTempOrder.apply(this, arguments);
|
|
@@ -951,28 +1309,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
951
1309
|
}, {
|
|
952
1310
|
key: "addNewOrder",
|
|
953
1311
|
value: function () {
|
|
954
|
-
var _addNewOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1312
|
+
var _addNewOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
|
|
955
1313
|
var tempOrder;
|
|
956
|
-
return _regeneratorRuntime().wrap(function
|
|
957
|
-
while (1) switch (
|
|
1314
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context13) {
|
|
1315
|
+
while (1) switch (_context13.prev = _context13.next) {
|
|
958
1316
|
case 0:
|
|
959
1317
|
tempOrder = this.ensureTempOrder();
|
|
960
1318
|
this.ensureExternalSaleNumber(tempOrder);
|
|
961
|
-
|
|
1319
|
+
_context13.next = 4;
|
|
962
1320
|
return this.recalculateSummary({
|
|
963
1321
|
createIfMissing: true
|
|
964
1322
|
});
|
|
965
1323
|
case 4:
|
|
966
1324
|
this.persistTempOrder();
|
|
967
|
-
|
|
1325
|
+
_context13.next = 7;
|
|
968
1326
|
return this.saveDraft();
|
|
969
1327
|
case 7:
|
|
970
|
-
return
|
|
1328
|
+
return _context13.abrupt("return", tempOrder);
|
|
971
1329
|
case 8:
|
|
972
1330
|
case "end":
|
|
973
|
-
return
|
|
1331
|
+
return _context13.stop();
|
|
974
1332
|
}
|
|
975
|
-
},
|
|
1333
|
+
}, _callee11, this);
|
|
976
1334
|
}));
|
|
977
1335
|
function addNewOrder() {
|
|
978
1336
|
return _addNewOrder.apply(this, arguments);
|
|
@@ -1059,9 +1417,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1059
1417
|
}, {
|
|
1060
1418
|
key: "findBookingIndexByUniqueIdentificationNumber",
|
|
1061
1419
|
value: function findBookingIndexByUniqueIdentificationNumber(tempOrder, uniqueIdentificationNumber) {
|
|
1062
|
-
var
|
|
1420
|
+
var _this4 = this;
|
|
1063
1421
|
return (tempOrder.bookings || []).findIndex(function (booking) {
|
|
1064
|
-
return
|
|
1422
|
+
return _this4.getBookingUniqueIdentificationNumber(booking) === uniqueIdentificationNumber;
|
|
1065
1423
|
});
|
|
1066
1424
|
}
|
|
1067
1425
|
}, {
|
|
@@ -1069,12 +1427,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1069
1427
|
value: function removeLinkedBookingsForProduct(tempOrder, product) {
|
|
1070
1428
|
var _product$metadata4,
|
|
1071
1429
|
_product$metadata5,
|
|
1072
|
-
|
|
1430
|
+
_this5 = this;
|
|
1073
1431
|
var productUid = (product === null || product === void 0 || (_product$metadata4 = product.metadata) === null || _product$metadata4 === void 0 ? void 0 : _product$metadata4.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
|
|
1074
1432
|
var bookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_product$metadata5 = product.metadata) === null || _product$metadata5 === void 0 ? void 0 : _product$metadata5.booking_uid);
|
|
1075
1433
|
if (!productUid && !bookingUid) return;
|
|
1076
1434
|
tempOrder.bookings = (tempOrder.bookings || []).filter(function (booking) {
|
|
1077
|
-
var currentBookingUid =
|
|
1435
|
+
var currentBookingUid = _this5.getBookingUniqueIdentificationNumber(booking);
|
|
1078
1436
|
if (bookingUid && currentBookingUid === String(bookingUid)) return false;
|
|
1079
1437
|
if (productUid && String((booking === null || booking === void 0 ? void 0 : booking.product_uid) || '') === String(productUid)) return false;
|
|
1080
1438
|
return true;
|
|
@@ -1091,23 +1449,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1091
1449
|
}, {
|
|
1092
1450
|
key: "recalculateSummary",
|
|
1093
1451
|
value: function () {
|
|
1094
|
-
var _recalculateSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1452
|
+
var _recalculateSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(options) {
|
|
1095
1453
|
var tempOrder, salesSummary, existedSummary, paidPaymentSummary, emptySummary, salesSummaryResult, summary;
|
|
1096
|
-
return _regeneratorRuntime().wrap(function
|
|
1097
|
-
while (1) switch (
|
|
1454
|
+
return _regeneratorRuntime().wrap(function _callee12$(_context14) {
|
|
1455
|
+
while (1) switch (_context14.prev = _context14.next) {
|
|
1098
1456
|
case 0:
|
|
1099
1457
|
tempOrder = options !== null && options !== void 0 && options.createIfMissing ? this.ensureTempOrder() : this.store.tempOrder;
|
|
1100
1458
|
if (tempOrder) {
|
|
1101
|
-
|
|
1459
|
+
_context14.next = 3;
|
|
1102
1460
|
break;
|
|
1103
1461
|
}
|
|
1104
|
-
return
|
|
1462
|
+
return _context14.abrupt("return", null);
|
|
1105
1463
|
case 3:
|
|
1106
1464
|
salesSummary = this.getSalesSummary();
|
|
1107
1465
|
existedSummary = this.store.summary || createEmptySummary();
|
|
1108
1466
|
paidPaymentSummary = this.calculatePaidPaymentSummary(tempOrder.payments || []);
|
|
1109
1467
|
if (salesSummary) {
|
|
1110
|
-
|
|
1468
|
+
_context14.next = 11;
|
|
1111
1469
|
break;
|
|
1112
1470
|
}
|
|
1113
1471
|
emptySummary = _objectSpread(_objectSpread({}, createEmptySummary()), {}, {
|
|
@@ -1118,16 +1476,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1118
1476
|
});
|
|
1119
1477
|
this.store.summary = emptySummary;
|
|
1120
1478
|
tempOrder.surcharge_fee = emptySummary.surcharge_fee;
|
|
1121
|
-
return
|
|
1479
|
+
return _context14.abrupt("return", this.store.summary);
|
|
1122
1480
|
case 11:
|
|
1123
|
-
|
|
1481
|
+
_context14.next = 13;
|
|
1124
1482
|
return salesSummary.getSummary({
|
|
1125
1483
|
products: tempOrder.products,
|
|
1126
1484
|
isPriceIncludeTax: tempOrder.is_price_include_tax,
|
|
1127
1485
|
shopDiscount: tempOrder.shop_discount
|
|
1128
1486
|
});
|
|
1129
1487
|
case 13:
|
|
1130
|
-
salesSummaryResult =
|
|
1488
|
+
salesSummaryResult = _context14.sent;
|
|
1131
1489
|
summary = _objectSpread(_objectSpread({}, salesSummaryResult), {}, {
|
|
1132
1490
|
total_refund_amount: existedSummary.total_refund_amount || '0.00',
|
|
1133
1491
|
customer_paid_amount: paidPaymentSummary.customerPaidAmount.toFixed(2),
|
|
@@ -1145,12 +1503,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1145
1503
|
tempOrder.surcharges = summary.surcharges || [];
|
|
1146
1504
|
tempOrder.deposit_amount = summary.deposit_amount || '0.00';
|
|
1147
1505
|
tempOrder.is_deposit = summary.deposit_amount !== '0.00' ? 1 : 0;
|
|
1148
|
-
return
|
|
1506
|
+
return _context14.abrupt("return", this.store.summary);
|
|
1149
1507
|
case 23:
|
|
1150
1508
|
case "end":
|
|
1151
|
-
return
|
|
1509
|
+
return _context14.stop();
|
|
1152
1510
|
}
|
|
1153
|
-
},
|
|
1511
|
+
}, _callee12, this);
|
|
1154
1512
|
}));
|
|
1155
1513
|
function recalculateSummary(_x12) {
|
|
1156
1514
|
return _recalculateSummary.apply(this, arguments);
|
|
@@ -1160,30 +1518,30 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1160
1518
|
}, {
|
|
1161
1519
|
key: "getOrderSummary",
|
|
1162
1520
|
value: function () {
|
|
1163
|
-
var _getOrderSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1521
|
+
var _getOrderSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
|
|
1164
1522
|
var summary;
|
|
1165
|
-
return _regeneratorRuntime().wrap(function
|
|
1166
|
-
while (1) switch (
|
|
1523
|
+
return _regeneratorRuntime().wrap(function _callee13$(_context15) {
|
|
1524
|
+
while (1) switch (_context15.prev = _context15.next) {
|
|
1167
1525
|
case 0:
|
|
1168
|
-
|
|
1526
|
+
_context15.next = 2;
|
|
1169
1527
|
return this.recalculateSummary({
|
|
1170
1528
|
createIfMissing: true
|
|
1171
1529
|
});
|
|
1172
1530
|
case 2:
|
|
1173
|
-
summary =
|
|
1531
|
+
summary = _context15.sent;
|
|
1174
1532
|
if (summary) {
|
|
1175
|
-
|
|
1533
|
+
_context15.next = 5;
|
|
1176
1534
|
break;
|
|
1177
1535
|
}
|
|
1178
|
-
return
|
|
1536
|
+
return _context15.abrupt("return", createEmptySummary());
|
|
1179
1537
|
case 5:
|
|
1180
1538
|
this.persistTempOrder();
|
|
1181
|
-
return
|
|
1539
|
+
return _context15.abrupt("return", summary);
|
|
1182
1540
|
case 7:
|
|
1183
1541
|
case "end":
|
|
1184
|
-
return
|
|
1542
|
+
return _context15.stop();
|
|
1185
1543
|
}
|
|
1186
|
-
},
|
|
1544
|
+
}, _callee13, this);
|
|
1187
1545
|
}));
|
|
1188
1546
|
function getOrderSummary() {
|
|
1189
1547
|
return _getOrderSummary.apply(this, arguments);
|
|
@@ -1207,21 +1565,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1207
1565
|
}, {
|
|
1208
1566
|
key: "syncTempOrderNoteToRemote",
|
|
1209
1567
|
value: function () {
|
|
1210
|
-
var _syncTempOrderNoteToRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1211
|
-
return _regeneratorRuntime().wrap(function
|
|
1212
|
-
while (1) switch (
|
|
1568
|
+
var _syncTempOrderNoteToRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(orderId, note) {
|
|
1569
|
+
return _regeneratorRuntime().wrap(function _callee14$(_context16) {
|
|
1570
|
+
while (1) switch (_context16.prev = _context16.next) {
|
|
1213
1571
|
case 0:
|
|
1214
|
-
|
|
1572
|
+
_context16.next = 2;
|
|
1215
1573
|
return this.request.put("/order/order/".concat(orderId, "/note"), {
|
|
1216
1574
|
note: note
|
|
1217
1575
|
});
|
|
1218
1576
|
case 2:
|
|
1219
|
-
return
|
|
1577
|
+
return _context16.abrupt("return", note);
|
|
1220
1578
|
case 3:
|
|
1221
1579
|
case "end":
|
|
1222
|
-
return
|
|
1580
|
+
return _context16.stop();
|
|
1223
1581
|
}
|
|
1224
|
-
},
|
|
1582
|
+
}, _callee14, this);
|
|
1225
1583
|
}));
|
|
1226
1584
|
function syncTempOrderNoteToRemote(_x13, _x14) {
|
|
1227
1585
|
return _syncTempOrderNoteToRemote.apply(this, arguments);
|
|
@@ -1515,43 +1873,43 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1515
1873
|
}, {
|
|
1516
1874
|
key: "shouldMergeProductToOrder",
|
|
1517
1875
|
value: function () {
|
|
1518
|
-
var _shouldMergeProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1876
|
+
var _shouldMergeProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(params) {
|
|
1519
1877
|
var _this$orderHooks;
|
|
1520
1878
|
var onBeforeMergeProductToOrder, result;
|
|
1521
|
-
return _regeneratorRuntime().wrap(function
|
|
1522
|
-
while (1) switch (
|
|
1879
|
+
return _regeneratorRuntime().wrap(function _callee15$(_context17) {
|
|
1880
|
+
while (1) switch (_context17.prev = _context17.next) {
|
|
1523
1881
|
case 0:
|
|
1524
1882
|
onBeforeMergeProductToOrder = (_this$orderHooks = this.orderHooks) === null || _this$orderHooks === void 0 ? void 0 : _this$orderHooks.onBeforeMergeProductToOrder;
|
|
1525
1883
|
if (onBeforeMergeProductToOrder) {
|
|
1526
|
-
|
|
1884
|
+
_context17.next = 3;
|
|
1527
1885
|
break;
|
|
1528
1886
|
}
|
|
1529
|
-
return
|
|
1887
|
+
return _context17.abrupt("return", true);
|
|
1530
1888
|
case 3:
|
|
1531
|
-
|
|
1889
|
+
_context17.next = 5;
|
|
1532
1890
|
return onBeforeMergeProductToOrder(_objectSpread(_objectSpread({}, params), {}, {
|
|
1533
1891
|
defaultShouldMerge: true
|
|
1534
1892
|
}));
|
|
1535
1893
|
case 5:
|
|
1536
|
-
result =
|
|
1894
|
+
result = _context17.sent;
|
|
1537
1895
|
if (!(typeof result === 'boolean')) {
|
|
1538
|
-
|
|
1896
|
+
_context17.next = 8;
|
|
1539
1897
|
break;
|
|
1540
1898
|
}
|
|
1541
|
-
return
|
|
1899
|
+
return _context17.abrupt("return", result);
|
|
1542
1900
|
case 8:
|
|
1543
1901
|
if (!(result && _typeof(result) === 'object' && typeof result.shouldMerge === 'boolean')) {
|
|
1544
|
-
|
|
1902
|
+
_context17.next = 10;
|
|
1545
1903
|
break;
|
|
1546
1904
|
}
|
|
1547
|
-
return
|
|
1905
|
+
return _context17.abrupt("return", result.shouldMerge);
|
|
1548
1906
|
case 10:
|
|
1549
|
-
return
|
|
1907
|
+
return _context17.abrupt("return", true);
|
|
1550
1908
|
case 11:
|
|
1551
1909
|
case "end":
|
|
1552
|
-
return
|
|
1910
|
+
return _context17.stop();
|
|
1553
1911
|
}
|
|
1554
|
-
},
|
|
1912
|
+
}, _callee15, this);
|
|
1555
1913
|
}));
|
|
1556
1914
|
function shouldMergeProductToOrder(_x15) {
|
|
1557
1915
|
return _shouldMergeProductToOrder.apply(this, arguments);
|
|
@@ -1561,11 +1919,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1561
1919
|
}, {
|
|
1562
1920
|
key: "addProductToOrder",
|
|
1563
1921
|
value: function () {
|
|
1564
|
-
var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1565
|
-
var
|
|
1922
|
+
var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(product, booking) {
|
|
1923
|
+
var _this6 = this;
|
|
1566
1924
|
var tempOrder, linked, productToAdd, incomingFingerprint, normalizedIncoming, hasIncomingGoodPass, shouldForceNewLine, matchedIndex, matchedProduct, existedFingerprint, shouldMerge, _targetProduct$metada, targetProduct, targetUid, normalizedProduct;
|
|
1567
|
-
return _regeneratorRuntime().wrap(function
|
|
1568
|
-
while (1) switch (
|
|
1925
|
+
return _regeneratorRuntime().wrap(function _callee16$(_context18) {
|
|
1926
|
+
while (1) switch (_context18.prev = _context18.next) {
|
|
1569
1927
|
case 0:
|
|
1570
1928
|
tempOrder = this.ensureTempOrder();
|
|
1571
1929
|
linked = booking ? this.createLinkedProductAndBooking({
|
|
@@ -1579,7 +1937,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1579
1937
|
hasIncomingGoodPass = this.hasGoodPassDiscount(normalizedIncoming);
|
|
1580
1938
|
shouldForceNewLine = !!booking;
|
|
1581
1939
|
matchedIndex = hasIncomingGoodPass || shouldForceNewLine ? -1 : tempOrder.products.findIndex(function (item) {
|
|
1582
|
-
if (
|
|
1940
|
+
if (_this6.hasGoodPassDiscount(item)) return false;
|
|
1583
1941
|
if (item.product_id !== productToAdd.product_id) return false;
|
|
1584
1942
|
if (item.product_variant_id !== productToAdd.product_variant_id) return false;
|
|
1585
1943
|
var existedFingerprint = buildProductLineFingerprint(item.product_option_item, item.product_bundle);
|
|
@@ -1588,10 +1946,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1588
1946
|
matchedProduct = matchedIndex === -1 ? null : tempOrder.products[matchedIndex];
|
|
1589
1947
|
existedFingerprint = matchedProduct ? buildProductLineFingerprint(matchedProduct.product_option_item, matchedProduct.product_bundle) : '';
|
|
1590
1948
|
if (!matchedProduct) {
|
|
1591
|
-
|
|
1949
|
+
_context18.next = 17;
|
|
1592
1950
|
break;
|
|
1593
1951
|
}
|
|
1594
|
-
|
|
1952
|
+
_context18.next = 14;
|
|
1595
1953
|
return this.shouldMergeProductToOrder({
|
|
1596
1954
|
incomingProduct: productToAdd,
|
|
1597
1955
|
normalizedIncoming: normalizedIncoming,
|
|
@@ -1603,13 +1961,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1603
1961
|
booking: booking
|
|
1604
1962
|
});
|
|
1605
1963
|
case 14:
|
|
1606
|
-
|
|
1607
|
-
|
|
1964
|
+
_context18.t0 = _context18.sent;
|
|
1965
|
+
_context18.next = 18;
|
|
1608
1966
|
break;
|
|
1609
1967
|
case 17:
|
|
1610
|
-
|
|
1968
|
+
_context18.t0 = false;
|
|
1611
1969
|
case 18:
|
|
1612
|
-
shouldMerge =
|
|
1970
|
+
shouldMerge = _context18.t0;
|
|
1613
1971
|
if (matchedIndex === -1 || !matchedProduct || !shouldMerge) {
|
|
1614
1972
|
this.captureProductRuntime(tempOrder, productToAdd, normalizedIncoming);
|
|
1615
1973
|
if (linked) {
|
|
@@ -1641,19 +1999,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1641
1999
|
if (linked) {
|
|
1642
2000
|
tempOrder.bookings = [].concat(_toConsumableArray(tempOrder.bookings || []), [linked.booking]);
|
|
1643
2001
|
}
|
|
2002
|
+
_context18.next = 23;
|
|
2003
|
+
return this.applyPromotion();
|
|
2004
|
+
case 23:
|
|
1644
2005
|
this.applyDiscount();
|
|
1645
|
-
|
|
2006
|
+
_context18.next = 26;
|
|
1646
2007
|
return this.recalculateSummary({
|
|
1647
2008
|
createIfMissing: true
|
|
1648
2009
|
});
|
|
1649
|
-
case 24:
|
|
1650
|
-
this.persistTempOrder();
|
|
1651
|
-
return _context15.abrupt("return", tempOrder.products);
|
|
1652
2010
|
case 26:
|
|
2011
|
+
this.persistTempOrder();
|
|
2012
|
+
return _context18.abrupt("return", tempOrder.products);
|
|
2013
|
+
case 28:
|
|
1653
2014
|
case "end":
|
|
1654
|
-
return
|
|
2015
|
+
return _context18.stop();
|
|
1655
2016
|
}
|
|
1656
|
-
},
|
|
2017
|
+
}, _callee16, this);
|
|
1657
2018
|
}));
|
|
1658
2019
|
function addProductToOrder(_x16, _x17) {
|
|
1659
2020
|
return _addProductToOrder.apply(this, arguments);
|
|
@@ -1682,11 +2043,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1682
2043
|
}, {
|
|
1683
2044
|
key: "updateOrderProduct",
|
|
1684
2045
|
value: function () {
|
|
1685
|
-
var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2046
|
+
var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(params) {
|
|
1686
2047
|
var _targetProduct$metada2, _metadata, _metadata2, _metadata3, _tempOrder$products$p;
|
|
1687
2048
|
var product_id, product_variant_id, updates, unique_identification_number, identity_key, product_option_item, product_bundle, booking, tempOrder, identityLookup, productIndex, targetUid, targetProduct, nextProduct, callerUpdatesTopPrice, callerUpdatesMainMeta, existedMeta, normalizedProduct, _normalizedProduct$me, _targetProduct$metada3, productUid, linked;
|
|
1688
|
-
return _regeneratorRuntime().wrap(function
|
|
1689
|
-
while (1) switch (
|
|
2049
|
+
return _regeneratorRuntime().wrap(function _callee17$(_context19) {
|
|
2050
|
+
while (1) switch (_context19.prev = _context19.next) {
|
|
1690
2051
|
case 0:
|
|
1691
2052
|
product_id = params.product_id, product_variant_id = params.product_variant_id, updates = params.updates, unique_identification_number = params.unique_identification_number, identity_key = params.identity_key, product_option_item = params.product_option_item, product_bundle = params.product_bundle, booking = params.booking;
|
|
1692
2053
|
tempOrder = this.ensureTempOrder();
|
|
@@ -1717,7 +2078,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1717
2078
|
productIndex = getProductIdentityIndex(tempOrder.products, identityLookup);
|
|
1718
2079
|
}
|
|
1719
2080
|
if (!(productIndex === -1)) {
|
|
1720
|
-
|
|
2081
|
+
_context19.next = 12;
|
|
1721
2082
|
break;
|
|
1722
2083
|
}
|
|
1723
2084
|
throw new Error('[Order] 目标商品不存在,无法更新');
|
|
@@ -1774,19 +2135,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1774
2135
|
}
|
|
1775
2136
|
tempOrder.products[productIndex] = normalizedProduct;
|
|
1776
2137
|
this.captureProductRuntime(tempOrder, updates, tempOrder.products[productIndex], (_tempOrder$products$p = tempOrder.products[productIndex].metadata) === null || _tempOrder$products$p === void 0 ? void 0 : _tempOrder$products$p.unique_identification_number);
|
|
2138
|
+
_context19.next = 25;
|
|
2139
|
+
return this.applyPromotion();
|
|
2140
|
+
case 25:
|
|
1777
2141
|
this.applyDiscount();
|
|
1778
|
-
|
|
2142
|
+
_context19.next = 28;
|
|
1779
2143
|
return this.recalculateSummary({
|
|
1780
2144
|
createIfMissing: true
|
|
1781
2145
|
});
|
|
1782
|
-
case 26:
|
|
1783
|
-
this.persistTempOrder();
|
|
1784
|
-
return _context16.abrupt("return", tempOrder.products);
|
|
1785
2146
|
case 28:
|
|
2147
|
+
this.persistTempOrder();
|
|
2148
|
+
return _context19.abrupt("return", tempOrder.products);
|
|
2149
|
+
case 30:
|
|
1786
2150
|
case "end":
|
|
1787
|
-
return
|
|
2151
|
+
return _context19.stop();
|
|
1788
2152
|
}
|
|
1789
|
-
},
|
|
2153
|
+
}, _callee17, this);
|
|
1790
2154
|
}));
|
|
1791
2155
|
function updateOrderProduct(_x18) {
|
|
1792
2156
|
return _updateOrderProduct.apply(this, arguments);
|
|
@@ -1796,11 +2160,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1796
2160
|
}, {
|
|
1797
2161
|
key: "updateOrderProductQuantity",
|
|
1798
2162
|
value: function () {
|
|
1799
|
-
var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2163
|
+
var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(params) {
|
|
1800
2164
|
var _targetProduct$metada4;
|
|
1801
2165
|
var product_id, product_variant_id, num, unique_identification_number, identity_key, product_option_item, product_bundle, tempOrder, identityLookup, productIndex, targetUid, targetProduct, normalizedProduct;
|
|
1802
|
-
return _regeneratorRuntime().wrap(function
|
|
1803
|
-
while (1) switch (
|
|
2166
|
+
return _regeneratorRuntime().wrap(function _callee18$(_context20) {
|
|
2167
|
+
while (1) switch (_context20.prev = _context20.next) {
|
|
1804
2168
|
case 0:
|
|
1805
2169
|
product_id = params.product_id, product_variant_id = params.product_variant_id, num = params.num, unique_identification_number = params.unique_identification_number, identity_key = params.identity_key, product_option_item = params.product_option_item, product_bundle = params.product_bundle;
|
|
1806
2170
|
tempOrder = this.ensureTempOrder();
|
|
@@ -1829,7 +2193,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1829
2193
|
productIndex = getProductIdentityIndex(tempOrder.products, identityLookup);
|
|
1830
2194
|
}
|
|
1831
2195
|
if (!(productIndex === -1)) {
|
|
1832
|
-
|
|
2196
|
+
_context20.next = 12;
|
|
1833
2197
|
break;
|
|
1834
2198
|
}
|
|
1835
2199
|
throw new Error('[Order] 目标商品不存在,无法更新数量');
|
|
@@ -1843,19 +2207,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1843
2207
|
}));
|
|
1844
2208
|
normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
|
|
1845
2209
|
tempOrder.products[productIndex] = normalizedProduct;
|
|
2210
|
+
_context20.next = 18;
|
|
2211
|
+
return this.applyPromotion();
|
|
2212
|
+
case 18:
|
|
1846
2213
|
this.applyDiscount();
|
|
1847
|
-
|
|
2214
|
+
_context20.next = 21;
|
|
1848
2215
|
return this.recalculateSummary({
|
|
1849
2216
|
createIfMissing: true
|
|
1850
2217
|
});
|
|
1851
|
-
case 19:
|
|
1852
|
-
this.persistTempOrder();
|
|
1853
|
-
return _context17.abrupt("return", tempOrder.products);
|
|
1854
2218
|
case 21:
|
|
2219
|
+
this.persistTempOrder();
|
|
2220
|
+
return _context20.abrupt("return", tempOrder.products);
|
|
2221
|
+
case 23:
|
|
1855
2222
|
case "end":
|
|
1856
|
-
return
|
|
2223
|
+
return _context20.stop();
|
|
1857
2224
|
}
|
|
1858
|
-
},
|
|
2225
|
+
}, _callee18, this);
|
|
1859
2226
|
}));
|
|
1860
2227
|
function updateOrderProductQuantity(_x19) {
|
|
1861
2228
|
return _updateOrderProductQuantity.apply(this, arguments);
|
|
@@ -1888,10 +2255,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1888
2255
|
}, {
|
|
1889
2256
|
key: "removeProductFromOrder",
|
|
1890
2257
|
value: function () {
|
|
1891
|
-
var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2258
|
+
var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(identity) {
|
|
1892
2259
|
var tempOrder, removedProducts, _i, _removedProducts, product;
|
|
1893
|
-
return _regeneratorRuntime().wrap(function
|
|
1894
|
-
while (1) switch (
|
|
2260
|
+
return _regeneratorRuntime().wrap(function _callee19$(_context21) {
|
|
2261
|
+
while (1) switch (_context21.prev = _context21.next) {
|
|
1895
2262
|
case 0:
|
|
1896
2263
|
tempOrder = this.ensureTempOrder();
|
|
1897
2264
|
removedProducts = [];
|
|
@@ -1904,19 +2271,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1904
2271
|
product = _removedProducts[_i];
|
|
1905
2272
|
this.removeLinkedBookingsForProduct(tempOrder, product);
|
|
1906
2273
|
}
|
|
2274
|
+
_context21.next = 6;
|
|
2275
|
+
return this.applyPromotion();
|
|
2276
|
+
case 6:
|
|
1907
2277
|
this.applyDiscount();
|
|
1908
|
-
|
|
2278
|
+
_context21.next = 9;
|
|
1909
2279
|
return this.recalculateSummary({
|
|
1910
2280
|
createIfMissing: true
|
|
1911
2281
|
});
|
|
1912
|
-
case 7:
|
|
1913
|
-
this.persistTempOrder();
|
|
1914
|
-
return _context18.abrupt("return", tempOrder.products);
|
|
1915
2282
|
case 9:
|
|
2283
|
+
this.persistTempOrder();
|
|
2284
|
+
return _context21.abrupt("return", tempOrder.products);
|
|
2285
|
+
case 11:
|
|
1916
2286
|
case "end":
|
|
1917
|
-
return
|
|
2287
|
+
return _context21.stop();
|
|
1918
2288
|
}
|
|
1919
|
-
},
|
|
2289
|
+
}, _callee19, this);
|
|
1920
2290
|
}));
|
|
1921
2291
|
function removeProductFromOrder(_x20) {
|
|
1922
2292
|
return _removeProductFromOrder.apply(this, arguments);
|
|
@@ -1930,10 +2300,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1930
2300
|
}, {
|
|
1931
2301
|
key: "clearOrderCartLines",
|
|
1932
2302
|
value: (function () {
|
|
1933
|
-
var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2303
|
+
var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
|
|
1934
2304
|
var tempOrder;
|
|
1935
|
-
return _regeneratorRuntime().wrap(function
|
|
1936
|
-
while (1) switch (
|
|
2305
|
+
return _regeneratorRuntime().wrap(function _callee20$(_context22) {
|
|
2306
|
+
while (1) switch (_context22.prev = _context22.next) {
|
|
1937
2307
|
case 0:
|
|
1938
2308
|
tempOrder = this.ensureTempOrder();
|
|
1939
2309
|
tempOrder.products = [];
|
|
@@ -1943,19 +2313,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1943
2313
|
productsByUid: {}
|
|
1944
2314
|
});
|
|
1945
2315
|
}
|
|
2316
|
+
_context22.next = 6;
|
|
2317
|
+
return this.applyPromotion();
|
|
2318
|
+
case 6:
|
|
1946
2319
|
this.applyDiscount();
|
|
1947
|
-
|
|
2320
|
+
_context22.next = 9;
|
|
1948
2321
|
return this.recalculateSummary({
|
|
1949
2322
|
createIfMissing: true
|
|
1950
2323
|
});
|
|
1951
|
-
case 7:
|
|
1952
|
-
this.persistTempOrder();
|
|
1953
|
-
return _context19.abrupt("return", tempOrder);
|
|
1954
2324
|
case 9:
|
|
2325
|
+
this.persistTempOrder();
|
|
2326
|
+
return _context22.abrupt("return", tempOrder);
|
|
2327
|
+
case 11:
|
|
1955
2328
|
case "end":
|
|
1956
|
-
return
|
|
2329
|
+
return _context22.stop();
|
|
1957
2330
|
}
|
|
1958
|
-
},
|
|
2331
|
+
}, _callee20, this);
|
|
1959
2332
|
}));
|
|
1960
2333
|
function clearOrderCartLines() {
|
|
1961
2334
|
return _clearOrderCartLines.apply(this, arguments);
|
|
@@ -1972,11 +2345,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1972
2345
|
}, {
|
|
1973
2346
|
key: "submitTempOrder",
|
|
1974
2347
|
value: function () {
|
|
1975
|
-
var _submitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2348
|
+
var _submitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(params) {
|
|
1976
2349
|
var _params$cacheId, _this$otherParams;
|
|
1977
2350
|
var tempOrder, effectiveCacheId, hasPaymentOverride, hasPaymentStatusOverride, hasSmallTicketDataFlagOverride, enhancePayload, payload, result, _payload$payments, _payload$payments2, backendErrorResponse, submittedOrderId, resultRecord;
|
|
1978
|
-
return _regeneratorRuntime().wrap(function
|
|
1979
|
-
while (1) switch (
|
|
2351
|
+
return _regeneratorRuntime().wrap(function _callee21$(_context23) {
|
|
2352
|
+
while (1) switch (_context23.prev = _context23.next) {
|
|
1980
2353
|
case 0:
|
|
1981
2354
|
tempOrder = this.ensureTempOrder();
|
|
1982
2355
|
this.persistTempOrder();
|
|
@@ -1992,7 +2365,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1992
2365
|
} : {}), hasSmallTicketDataFlagOverride ? {
|
|
1993
2366
|
small_ticket_data_flag: params === null || params === void 0 ? void 0 : params.smallTicketDataFlag
|
|
1994
2367
|
} : {});
|
|
1995
|
-
|
|
2368
|
+
var enhancedPayload = params !== null && params !== void 0 && params.enhancePayload ? params.enhancePayload(nextPayload, ctx) : nextPayload;
|
|
2369
|
+
return enhancedPayload;
|
|
1996
2370
|
} : undefined;
|
|
1997
2371
|
payload = buildSubmitPayload({
|
|
1998
2372
|
tempOrder: tempOrder,
|
|
@@ -2003,71 +2377,72 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2003
2377
|
type: params === null || params === void 0 ? void 0 : params.type,
|
|
2004
2378
|
enhance: enhancePayload
|
|
2005
2379
|
});
|
|
2006
|
-
|
|
2380
|
+
_context23.next = 10;
|
|
2007
2381
|
return this.saveDraft();
|
|
2008
2382
|
case 10:
|
|
2009
|
-
|
|
2383
|
+
_context23.prev = 10;
|
|
2010
2384
|
this.logInfo('submitTempOrder calling sales checkout', {
|
|
2011
2385
|
orderId: payload.order_id,
|
|
2012
2386
|
externalSaleNumber: payload.external_sale_number,
|
|
2387
|
+
requestUniqueIdempotencyToken: payload.request_unique_idempotency_token,
|
|
2013
2388
|
paymentStatus: payload.payment_status,
|
|
2014
2389
|
paymentsCount: ((_payload$payments = payload.payments) === null || _payload$payments === void 0 ? void 0 : _payload$payments.length) || 0,
|
|
2015
2390
|
smallTicketDataFlag: payload.small_ticket_data_flag
|
|
2016
2391
|
});
|
|
2017
|
-
|
|
2392
|
+
_context23.next = 14;
|
|
2018
2393
|
return this.submitSalesOrder({
|
|
2019
2394
|
query: payload
|
|
2020
2395
|
});
|
|
2021
2396
|
case 14:
|
|
2022
|
-
result =
|
|
2023
|
-
|
|
2397
|
+
result = _context23.sent;
|
|
2398
|
+
_context23.next = 27;
|
|
2024
2399
|
break;
|
|
2025
2400
|
case 17:
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
backendErrorResponse = this.extractSubmitErrorResponse(
|
|
2401
|
+
_context23.prev = 17;
|
|
2402
|
+
_context23.t0 = _context23["catch"](10);
|
|
2403
|
+
backendErrorResponse = this.extractSubmitErrorResponse(_context23.t0);
|
|
2029
2404
|
if (!backendErrorResponse) {
|
|
2030
|
-
|
|
2405
|
+
_context23.next = 24;
|
|
2031
2406
|
break;
|
|
2032
2407
|
}
|
|
2033
2408
|
this.store.syncState = 'failed';
|
|
2034
2409
|
this.logSubmitBackendRejected(backendErrorResponse, payload);
|
|
2035
|
-
return
|
|
2410
|
+
return _context23.abrupt("return", backendErrorResponse);
|
|
2036
2411
|
case 24:
|
|
2037
2412
|
this.store.syncState = 'failed';
|
|
2038
2413
|
this.logError('submitTempOrder failed', {
|
|
2039
|
-
error:
|
|
2414
|
+
error: _context23.t0 instanceof Error ? _context23.t0.message : String(_context23.t0),
|
|
2040
2415
|
orderId: payload.order_id,
|
|
2041
2416
|
externalSaleNumber: payload.external_sale_number,
|
|
2042
2417
|
paymentStatus: payload.payment_status,
|
|
2043
2418
|
paymentsCount: ((_payload$payments2 = payload.payments) === null || _payload$payments2 === void 0 ? void 0 : _payload$payments2.length) || 0
|
|
2044
2419
|
});
|
|
2045
|
-
throw
|
|
2420
|
+
throw _context23.t0;
|
|
2046
2421
|
case 27:
|
|
2047
2422
|
if (!this.isSubmitResponseRejected(result)) {
|
|
2048
|
-
|
|
2423
|
+
_context23.next = 31;
|
|
2049
2424
|
break;
|
|
2050
2425
|
}
|
|
2051
2426
|
this.store.syncState = 'failed';
|
|
2052
2427
|
this.logSubmitBackendRejected(result, payload);
|
|
2053
|
-
return
|
|
2428
|
+
return _context23.abrupt("return", result);
|
|
2054
2429
|
case 31:
|
|
2055
2430
|
submittedOrderId = this.extractOrderIdFromSubmitResult(result);
|
|
2056
2431
|
if (!(submittedOrderId !== null && submittedOrderId !== undefined)) {
|
|
2057
|
-
|
|
2432
|
+
_context23.next = 37;
|
|
2058
2433
|
break;
|
|
2059
2434
|
}
|
|
2060
2435
|
tempOrder.order_id = submittedOrderId;
|
|
2061
2436
|
resultRecord = result;
|
|
2062
|
-
|
|
2437
|
+
_context23.next = 37;
|
|
2063
2438
|
return this.markLocalOrderSynced(submittedOrderId, (resultRecord === null || resultRecord === void 0 ? void 0 : resultRecord.data) || resultRecord || {});
|
|
2064
2439
|
case 37:
|
|
2065
|
-
return
|
|
2440
|
+
return _context23.abrupt("return", result);
|
|
2066
2441
|
case 38:
|
|
2067
2442
|
case "end":
|
|
2068
|
-
return
|
|
2443
|
+
return _context23.stop();
|
|
2069
2444
|
}
|
|
2070
|
-
},
|
|
2445
|
+
}, _callee21, this, [[10, 17]]);
|
|
2071
2446
|
}));
|
|
2072
2447
|
function submitTempOrder(_x21) {
|
|
2073
2448
|
return _submitTempOrder.apply(this, arguments);
|
|
@@ -2077,23 +2452,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2077
2452
|
}, {
|
|
2078
2453
|
key: "markLocalOrderSynced",
|
|
2079
2454
|
value: function () {
|
|
2080
|
-
var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2455
|
+
var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(orderId, remoteOrder) {
|
|
2081
2456
|
var tempOrder;
|
|
2082
|
-
return _regeneratorRuntime().wrap(function
|
|
2083
|
-
while (1) switch (
|
|
2457
|
+
return _regeneratorRuntime().wrap(function _callee22$(_context24) {
|
|
2458
|
+
while (1) switch (_context24.prev = _context24.next) {
|
|
2084
2459
|
case 0:
|
|
2085
2460
|
tempOrder = this.ensureTempOrder();
|
|
2086
2461
|
tempOrder.order_id = orderId;
|
|
2087
2462
|
this.store.lastOrderInfo = remoteOrder;
|
|
2088
2463
|
this.store.syncState = 'submitted';
|
|
2089
2464
|
this.persistTempOrder();
|
|
2090
|
-
|
|
2465
|
+
_context24.next = 7;
|
|
2091
2466
|
return this.saveDraft();
|
|
2092
2467
|
case 7:
|
|
2093
2468
|
case "end":
|
|
2094
|
-
return
|
|
2469
|
+
return _context24.stop();
|
|
2095
2470
|
}
|
|
2096
|
-
},
|
|
2471
|
+
}, _callee22, this);
|
|
2097
2472
|
}));
|
|
2098
2473
|
function markLocalOrderSynced(_x22, _x23) {
|
|
2099
2474
|
return _markLocalOrderSynced.apply(this, arguments);
|
|
@@ -2119,10 +2494,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2119
2494
|
value: function extractSubmitErrorResponse(error) {
|
|
2120
2495
|
var _error$response,
|
|
2121
2496
|
_error$response2,
|
|
2122
|
-
|
|
2497
|
+
_this7 = this;
|
|
2123
2498
|
var candidates = [error === null || error === void 0 || (_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.data, error === null || error === void 0 ? void 0 : error.data, error === null || error === void 0 || (_error$response2 = error.response) === null || _error$response2 === void 0 ? void 0 : _error$response2.body, error === null || error === void 0 ? void 0 : error.body];
|
|
2124
2499
|
return candidates.find(function (candidate) {
|
|
2125
|
-
return
|
|
2500
|
+
return _this7.isSubmitErrorResponse(candidate);
|
|
2126
2501
|
}) || null;
|
|
2127
2502
|
}
|
|
2128
2503
|
}, {
|
|
@@ -2142,10 +2517,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2142
2517
|
}, {
|
|
2143
2518
|
key: "syncPaymentsToOrder",
|
|
2144
2519
|
value: function () {
|
|
2145
|
-
var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2146
|
-
var tempOrder, mappedPayments, paymentTotal, targetAmount, isFullyPaid, paymentStatus, submitResult;
|
|
2147
|
-
return _regeneratorRuntime().wrap(function
|
|
2148
|
-
while (1) switch (
|
|
2520
|
+
var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(params) {
|
|
2521
|
+
var tempOrder, mappedPayments, paymentTotal, targetAmount, isFullyPaid, paymentStatus, paymentSyncIdempotencyToken, submitResult;
|
|
2522
|
+
return _regeneratorRuntime().wrap(function _callee23$(_context25) {
|
|
2523
|
+
while (1) switch (_context25.prev = _context25.next) {
|
|
2149
2524
|
case 0:
|
|
2150
2525
|
tempOrder = this.ensureTempOrder();
|
|
2151
2526
|
mappedPayments = mapPaymentItemsToOrderPayments(params.payments || []);
|
|
@@ -2156,44 +2531,51 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2156
2531
|
tempOrder.payments = mappedPayments;
|
|
2157
2532
|
tempOrder.payment_status = paymentStatus;
|
|
2158
2533
|
this.persistTempOrder();
|
|
2159
|
-
|
|
2534
|
+
_context25.next = 11;
|
|
2160
2535
|
return this.saveDraft();
|
|
2161
2536
|
case 11:
|
|
2162
2537
|
if (params.submitWhenPaid) {
|
|
2163
|
-
|
|
2538
|
+
_context25.next = 13;
|
|
2164
2539
|
break;
|
|
2165
2540
|
}
|
|
2166
|
-
return
|
|
2541
|
+
return _context25.abrupt("return", {
|
|
2167
2542
|
isFullyPaid: isFullyPaid
|
|
2168
2543
|
});
|
|
2169
2544
|
case 13:
|
|
2170
2545
|
if (!(this.store.syncState === 'submitting')) {
|
|
2171
|
-
|
|
2546
|
+
_context25.next = 15;
|
|
2172
2547
|
break;
|
|
2173
2548
|
}
|
|
2174
|
-
return
|
|
2549
|
+
return _context25.abrupt("return", {
|
|
2175
2550
|
isFullyPaid: isFullyPaid
|
|
2176
2551
|
});
|
|
2177
2552
|
case 15:
|
|
2178
2553
|
this.store.syncState = 'submitting';
|
|
2179
|
-
|
|
2554
|
+
paymentSyncIdempotencyToken = this.buildPaymentSyncIdempotencyToken(tempOrder, mappedPayments);
|
|
2555
|
+
_context25.next = 19;
|
|
2180
2556
|
return this.submitTempOrder({
|
|
2181
2557
|
payments: mappedPayments,
|
|
2182
2558
|
paymentStatus: paymentStatus,
|
|
2183
2559
|
smallTicketDataFlag: params.smallTicketDataFlag,
|
|
2184
|
-
channel: params.channel
|
|
2560
|
+
channel: params.channel,
|
|
2561
|
+
enhancePayload: function enhancePayload(payload) {
|
|
2562
|
+
var nextPayload = _objectSpread(_objectSpread({}, payload), {}, {
|
|
2563
|
+
request_unique_idempotency_token: paymentSyncIdempotencyToken
|
|
2564
|
+
});
|
|
2565
|
+
return nextPayload;
|
|
2566
|
+
}
|
|
2185
2567
|
});
|
|
2186
|
-
case
|
|
2187
|
-
submitResult =
|
|
2188
|
-
return
|
|
2568
|
+
case 19:
|
|
2569
|
+
submitResult = _context25.sent;
|
|
2570
|
+
return _context25.abrupt("return", {
|
|
2189
2571
|
isFullyPaid: isFullyPaid,
|
|
2190
2572
|
submitResult: submitResult
|
|
2191
2573
|
});
|
|
2192
|
-
case
|
|
2574
|
+
case 21:
|
|
2193
2575
|
case "end":
|
|
2194
|
-
return
|
|
2576
|
+
return _context25.stop();
|
|
2195
2577
|
}
|
|
2196
|
-
},
|
|
2578
|
+
}, _callee23, this);
|
|
2197
2579
|
}));
|
|
2198
2580
|
function syncPaymentsToOrder(_x24) {
|
|
2199
2581
|
return _syncPaymentsToOrder.apply(this, arguments);
|
|
@@ -2284,11 +2666,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2284
2666
|
}, {
|
|
2285
2667
|
key: "submitOrder",
|
|
2286
2668
|
value: function () {
|
|
2287
|
-
var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2669
|
+
var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(order) {
|
|
2288
2670
|
var _order$query$cartItem, _params$bookings, _params$relation_prod;
|
|
2289
2671
|
var url, query, fetchUrl, params;
|
|
2290
|
-
return _regeneratorRuntime().wrap(function
|
|
2291
|
-
while (1) switch (
|
|
2672
|
+
return _regeneratorRuntime().wrap(function _callee24$(_context26) {
|
|
2673
|
+
while (1) switch (_context26.prev = _context26.next) {
|
|
2292
2674
|
case 0:
|
|
2293
2675
|
this.logInfo('submitOrder called', {
|
|
2294
2676
|
url: order.url,
|
|
@@ -2308,12 +2690,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2308
2690
|
relationProductsCount: ((_params$relation_prod = params.relation_products) === null || _params$relation_prod === void 0 ? void 0 : _params$relation_prod.length) || 0,
|
|
2309
2691
|
scheduleDate: params.schedule_date
|
|
2310
2692
|
});
|
|
2311
|
-
return
|
|
2693
|
+
return _context26.abrupt("return", this.request.post(fetchUrl, params));
|
|
2312
2694
|
case 6:
|
|
2313
2695
|
case "end":
|
|
2314
|
-
return
|
|
2696
|
+
return _context26.stop();
|
|
2315
2697
|
}
|
|
2316
|
-
},
|
|
2698
|
+
}, _callee24, this);
|
|
2317
2699
|
}));
|
|
2318
2700
|
function submitOrder(_x25) {
|
|
2319
2701
|
return _submitOrder.apply(this, arguments);
|
|
@@ -2323,13 +2705,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2323
2705
|
}, {
|
|
2324
2706
|
key: "cancelOrder",
|
|
2325
2707
|
value: function () {
|
|
2326
|
-
var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2708
|
+
var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(params) {
|
|
2327
2709
|
var payload;
|
|
2328
|
-
return _regeneratorRuntime().wrap(function
|
|
2329
|
-
while (1) switch (
|
|
2710
|
+
return _regeneratorRuntime().wrap(function _callee25$(_context27) {
|
|
2711
|
+
while (1) switch (_context27.prev = _context27.next) {
|
|
2330
2712
|
case 0:
|
|
2331
2713
|
if (!(!Array.isArray(params.order_ids) || params.order_ids.length === 0)) {
|
|
2332
|
-
|
|
2714
|
+
_context27.next = 2;
|
|
2333
2715
|
break;
|
|
2334
2716
|
}
|
|
2335
2717
|
throw new Error('取消订单失败:order_ids 不能为空');
|
|
@@ -2345,14 +2727,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2345
2727
|
method: 'PUT',
|
|
2346
2728
|
orderIdsCount: params.order_ids.length
|
|
2347
2729
|
});
|
|
2348
|
-
return
|
|
2730
|
+
return _context27.abrupt("return", this.request.put('/order/update-status', payload, {
|
|
2349
2731
|
isShopApi: true
|
|
2350
2732
|
}));
|
|
2351
2733
|
case 5:
|
|
2352
2734
|
case "end":
|
|
2353
|
-
return
|
|
2735
|
+
return _context27.stop();
|
|
2354
2736
|
}
|
|
2355
|
-
},
|
|
2737
|
+
}, _callee25, this);
|
|
2356
2738
|
}));
|
|
2357
2739
|
function cancelOrder(_x26) {
|
|
2358
2740
|
return _cancelOrder.apply(this, arguments);
|
|
@@ -2362,19 +2744,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2362
2744
|
}, {
|
|
2363
2745
|
key: "changeBookingStatus",
|
|
2364
2746
|
value: function () {
|
|
2365
|
-
var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2747
|
+
var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(params) {
|
|
2366
2748
|
var url, payload;
|
|
2367
|
-
return _regeneratorRuntime().wrap(function
|
|
2368
|
-
while (1) switch (
|
|
2749
|
+
return _regeneratorRuntime().wrap(function _callee26$(_context28) {
|
|
2750
|
+
while (1) switch (_context28.prev = _context28.next) {
|
|
2369
2751
|
case 0:
|
|
2370
2752
|
if (params.booking_id) {
|
|
2371
|
-
|
|
2753
|
+
_context28.next = 2;
|
|
2372
2754
|
break;
|
|
2373
2755
|
}
|
|
2374
2756
|
throw new Error('变更预约状态失败:booking_id 不能为空');
|
|
2375
2757
|
case 2:
|
|
2376
2758
|
if (params.appointment_status) {
|
|
2377
|
-
|
|
2759
|
+
_context28.next = 4;
|
|
2378
2760
|
break;
|
|
2379
2761
|
}
|
|
2380
2762
|
throw new Error('变更预约状态失败:appointment_status 不能为空');
|
|
@@ -2389,14 +2771,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2389
2771
|
bookingId: params.booking_id,
|
|
2390
2772
|
appointmentStatus: params.appointment_status
|
|
2391
2773
|
});
|
|
2392
|
-
return
|
|
2774
|
+
return _context28.abrupt("return", this.request.put(url, payload, {
|
|
2393
2775
|
isShopApi: true
|
|
2394
2776
|
}));
|
|
2395
2777
|
case 8:
|
|
2396
2778
|
case "end":
|
|
2397
|
-
return
|
|
2779
|
+
return _context28.stop();
|
|
2398
2780
|
}
|
|
2399
|
-
},
|
|
2781
|
+
}, _callee26, this);
|
|
2400
2782
|
}));
|
|
2401
2783
|
function changeBookingStatus(_x27) {
|
|
2402
2784
|
return _changeBookingStatus.apply(this, arguments);
|
|
@@ -2416,11 +2798,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2416
2798
|
}, {
|
|
2417
2799
|
key: "createOrderByCheckout",
|
|
2418
2800
|
value: (function () {
|
|
2419
|
-
var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2801
|
+
var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(params) {
|
|
2420
2802
|
var _params$payments, _params$bookings2, _params$relation_prod2, _params$payments2, _params$payments3, _params$bookings3, _params$relation_prod3, _params$payments4;
|
|
2421
2803
|
var onlineStorePaymentCodeList, _orderData$payments, _orderData$bookings, _orderData$relation_p, _orderData$payments2, _orderData$payments3, _orderData$bookings2, _orderData$relation_p2, _orderData$payments4, _orderData$payments5, _response$data, orderData, response;
|
|
2422
|
-
return _regeneratorRuntime().wrap(function
|
|
2423
|
-
while (1) switch (
|
|
2804
|
+
return _regeneratorRuntime().wrap(function _callee27$(_context29) {
|
|
2805
|
+
while (1) switch (_context29.prev = _context29.next) {
|
|
2424
2806
|
case 0:
|
|
2425
2807
|
// 过滤掉由在线店铺下单的 payment 支付数据
|
|
2426
2808
|
onlineStorePaymentCodeList = ['WXPAY', 'WECHAT', 'ALIPAY', 'APPLE_PAY', 'CREDIT_CARD_3DS', 'CREDIT_CARD_TOKEN', 'GOOGLE_PAY', 'GOOGLE_PAY_3DS', 'CREDIT_CARD'];
|
|
@@ -2454,7 +2836,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2454
2836
|
relationProductsCount: ((_params$relation_prod3 = params.relation_products) === null || _params$relation_prod3 === void 0 ? void 0 : _params$relation_prod3.length) || 0,
|
|
2455
2837
|
paymentsCount: ((_params$payments4 = params.payments) === null || _params$payments4 === void 0 ? void 0 : _params$payments4.length) || 0
|
|
2456
2838
|
});
|
|
2457
|
-
|
|
2839
|
+
_context29.prev = 4;
|
|
2458
2840
|
// 构建订单数据,设置默认值并允许 params 覆盖
|
|
2459
2841
|
orderData = _objectSpread({
|
|
2460
2842
|
sales_channel: 'my_pisel',
|
|
@@ -2518,10 +2900,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2518
2900
|
});
|
|
2519
2901
|
|
|
2520
2902
|
// 调用后端接口
|
|
2521
|
-
|
|
2903
|
+
_context29.next = 12;
|
|
2522
2904
|
return this.request.post('/order/checkout', orderData);
|
|
2523
2905
|
case 12:
|
|
2524
|
-
response =
|
|
2906
|
+
response = _context29.sent;
|
|
2525
2907
|
this.logInfo('Order API called successfully', {
|
|
2526
2908
|
response: response
|
|
2527
2909
|
});
|
|
@@ -2529,20 +2911,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2529
2911
|
success: !!response,
|
|
2530
2912
|
hasOrderId: !!(response !== null && response !== void 0 && (_response$data = response.data) !== null && _response$data !== void 0 && _response$data.order_id || response !== null && response !== void 0 && response.order_id)
|
|
2531
2913
|
});
|
|
2532
|
-
return
|
|
2914
|
+
return _context29.abrupt("return", response);
|
|
2533
2915
|
case 18:
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
console.error('[Order] createOrderByCheckout 创建订单失败:',
|
|
2916
|
+
_context29.prev = 18;
|
|
2917
|
+
_context29.t0 = _context29["catch"](4);
|
|
2918
|
+
console.error('[Order] createOrderByCheckout 创建订单失败:', _context29.t0);
|
|
2537
2919
|
this.logInfo('Order API called failed', {
|
|
2538
|
-
error:
|
|
2920
|
+
error: _context29.t0 instanceof Error ? _context29.t0.message : String(_context29.t0)
|
|
2539
2921
|
});
|
|
2540
|
-
throw
|
|
2922
|
+
throw _context29.t0;
|
|
2541
2923
|
case 23:
|
|
2542
2924
|
case "end":
|
|
2543
|
-
return
|
|
2925
|
+
return _context29.stop();
|
|
2544
2926
|
}
|
|
2545
|
-
},
|
|
2927
|
+
}, _callee27, this, [[4, 18]]);
|
|
2546
2928
|
}));
|
|
2547
2929
|
function createOrderByCheckout(_x28) {
|
|
2548
2930
|
return _createOrderByCheckout.apply(this, arguments);
|
|
@@ -2552,21 +2934,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2552
2934
|
}, {
|
|
2553
2935
|
key: "submitSalesOrder",
|
|
2554
2936
|
value: function () {
|
|
2555
|
-
var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2937
|
+
var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(params) {
|
|
2556
2938
|
var url, query, fetchUrl;
|
|
2557
|
-
return _regeneratorRuntime().wrap(function
|
|
2558
|
-
while (1) switch (
|
|
2939
|
+
return _regeneratorRuntime().wrap(function _callee28$(_context30) {
|
|
2940
|
+
while (1) switch (_context30.prev = _context30.next) {
|
|
2559
2941
|
case 0:
|
|
2560
2942
|
url = params.url, query = params.query;
|
|
2561
2943
|
fetchUrl = url || '/order/sales/checkout';
|
|
2562
|
-
return
|
|
2944
|
+
return _context30.abrupt("return", this.request.post(fetchUrl, query, {
|
|
2563
2945
|
customToast: function customToast() {}
|
|
2564
2946
|
}));
|
|
2565
2947
|
case 3:
|
|
2566
2948
|
case "end":
|
|
2567
|
-
return
|
|
2949
|
+
return _context30.stop();
|
|
2568
2950
|
}
|
|
2569
|
-
},
|
|
2951
|
+
}, _callee28, this);
|
|
2570
2952
|
}));
|
|
2571
2953
|
function submitSalesOrder(_x29) {
|
|
2572
2954
|
return _submitSalesOrder.apply(this, arguments);
|
|
@@ -2582,35 +2964,35 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2582
2964
|
}, {
|
|
2583
2965
|
key: "sendCustomerPayLink",
|
|
2584
2966
|
value: (function () {
|
|
2585
|
-
var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2967
|
+
var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(params) {
|
|
2586
2968
|
var _params$emails;
|
|
2587
2969
|
var orderIds;
|
|
2588
|
-
return _regeneratorRuntime().wrap(function
|
|
2589
|
-
while (1) switch (
|
|
2970
|
+
return _regeneratorRuntime().wrap(function _callee29$(_context31) {
|
|
2971
|
+
while (1) switch (_context31.prev = _context31.next) {
|
|
2590
2972
|
case 0:
|
|
2591
2973
|
orderIds = params.order_ids || params.orderIds || [];
|
|
2592
2974
|
if (orderIds.length) {
|
|
2593
|
-
|
|
2975
|
+
_context31.next = 3;
|
|
2594
2976
|
break;
|
|
2595
2977
|
}
|
|
2596
2978
|
throw new Error('发送支付链接前必须先提交本地订单并取得订单 ID');
|
|
2597
2979
|
case 3:
|
|
2598
2980
|
if ((_params$emails = params.emails) !== null && _params$emails !== void 0 && _params$emails.length) {
|
|
2599
|
-
|
|
2981
|
+
_context31.next = 5;
|
|
2600
2982
|
break;
|
|
2601
2983
|
}
|
|
2602
2984
|
throw new Error('发送支付链接需要至少一个邮箱');
|
|
2603
2985
|
case 5:
|
|
2604
|
-
return
|
|
2986
|
+
return _context31.abrupt("return", this.request.post('/order/batch-email', {
|
|
2605
2987
|
order_ids: orderIds,
|
|
2606
2988
|
notify_action: params.notify_action || 'order_payment_reminder',
|
|
2607
2989
|
emails: params.emails
|
|
2608
2990
|
}));
|
|
2609
2991
|
case 6:
|
|
2610
2992
|
case "end":
|
|
2611
|
-
return
|
|
2993
|
+
return _context31.stop();
|
|
2612
2994
|
}
|
|
2613
|
-
},
|
|
2995
|
+
}, _callee29, this);
|
|
2614
2996
|
}));
|
|
2615
2997
|
function sendCustomerPayLink(_x30) {
|
|
2616
2998
|
return _sendCustomerPayLink.apply(this, arguments);
|
|
@@ -2621,26 +3003,26 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2621
3003
|
}, {
|
|
2622
3004
|
key: "getOrderInfoByRemote",
|
|
2623
3005
|
value: function () {
|
|
2624
|
-
var _getOrderInfoByRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
3006
|
+
var _getOrderInfoByRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(order_id) {
|
|
2625
3007
|
var res;
|
|
2626
|
-
return _regeneratorRuntime().wrap(function
|
|
2627
|
-
while (1) switch (
|
|
3008
|
+
return _regeneratorRuntime().wrap(function _callee30$(_context32) {
|
|
3009
|
+
while (1) switch (_context32.prev = _context32.next) {
|
|
2628
3010
|
case 0:
|
|
2629
|
-
|
|
3011
|
+
_context32.next = 2;
|
|
2630
3012
|
return this.request.get("/order/sales/".concat(order_id), {
|
|
2631
3013
|
with: ['products', 'bookings', 'payments', 'customer', 'summary', 'contacts_info']
|
|
2632
3014
|
});
|
|
2633
3015
|
case 2:
|
|
2634
|
-
res =
|
|
3016
|
+
res = _context32.sent;
|
|
2635
3017
|
if (res.code === 200) {
|
|
2636
3018
|
this.store.lastOrderInfo = res.data;
|
|
2637
3019
|
}
|
|
2638
|
-
return
|
|
3020
|
+
return _context32.abrupt("return", res);
|
|
2639
3021
|
case 5:
|
|
2640
3022
|
case "end":
|
|
2641
|
-
return
|
|
3023
|
+
return _context32.stop();
|
|
2642
3024
|
}
|
|
2643
|
-
},
|
|
3025
|
+
}, _callee30, this);
|
|
2644
3026
|
}));
|
|
2645
3027
|
function getOrderInfoByRemote(_x31) {
|
|
2646
3028
|
return _getOrderInfoByRemote.apply(this, arguments);
|
|
@@ -2656,10 +3038,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2656
3038
|
}, {
|
|
2657
3039
|
key: "hydrateTempOrderFromRecord",
|
|
2658
3040
|
value: (function () {
|
|
2659
|
-
var _hydrateTempOrderFromRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
3041
|
+
var _hydrateTempOrderFromRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(record, options) {
|
|
2660
3042
|
var raw, nextTempOrder;
|
|
2661
|
-
return _regeneratorRuntime().wrap(function
|
|
2662
|
-
while (1) switch (
|
|
3043
|
+
return _regeneratorRuntime().wrap(function _callee31$(_context33) {
|
|
3044
|
+
while (1) switch (_context33.prev = _context33.next) {
|
|
2663
3045
|
case 0:
|
|
2664
3046
|
raw = record && _typeof(record) === 'object' && record.data && record.order_id == null ? record.data : record || {};
|
|
2665
3047
|
nextTempOrder = this.normalizeTempOrderForRuntime(raw, {
|
|
@@ -2669,21 +3051,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2669
3051
|
this.store.summary = raw.summary && _typeof(raw.summary) === 'object' ? _objectSpread(_objectSpread({}, createEmptySummary()), raw.summary) : createEmptySummary();
|
|
2670
3052
|
this.store.lastOrderInfo = raw.lastOrderInfo || raw;
|
|
2671
3053
|
if (!(options !== null && options !== void 0 && options.recalcOnHydrate)) {
|
|
2672
|
-
|
|
3054
|
+
_context33.next = 8;
|
|
2673
3055
|
break;
|
|
2674
3056
|
}
|
|
2675
|
-
|
|
3057
|
+
_context33.next = 8;
|
|
2676
3058
|
return this.recalculateSummary({
|
|
2677
3059
|
createIfMissing: false
|
|
2678
3060
|
});
|
|
2679
3061
|
case 8:
|
|
2680
3062
|
this.persistTempOrder();
|
|
2681
|
-
return
|
|
3063
|
+
return _context33.abrupt("return", nextTempOrder);
|
|
2682
3064
|
case 10:
|
|
2683
3065
|
case "end":
|
|
2684
|
-
return
|
|
3066
|
+
return _context33.stop();
|
|
2685
3067
|
}
|
|
2686
|
-
},
|
|
3068
|
+
}, _callee31, this);
|
|
2687
3069
|
}));
|
|
2688
3070
|
function hydrateTempOrderFromRecord(_x32, _x33) {
|
|
2689
3071
|
return _hydrateTempOrderFromRecord.apply(this, arguments);
|
|
@@ -2693,7 +3075,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2693
3075
|
}, {
|
|
2694
3076
|
key: "normalizeTempOrderForRuntime",
|
|
2695
3077
|
value: function normalizeTempOrderForRuntime(raw, options) {
|
|
2696
|
-
var
|
|
3078
|
+
var _this8 = this;
|
|
2697
3079
|
var nextTempOrder = _objectSpread(_objectSpread({}, this.createDefaultTempOrderInstance()), raw || {});
|
|
2698
3080
|
delete nextTempOrder.summary;
|
|
2699
3081
|
delete nextTempOrder.lastOrderInfo;
|
|
@@ -2711,7 +3093,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2711
3093
|
nextTempOrder.metadata = raw.metadata && _typeof(raw.metadata) === 'object' ? _objectSpread({}, raw.metadata) : {};
|
|
2712
3094
|
nextTempOrder.holder = raw.holder && _typeof(raw.holder) === 'object' ? _objectSpread({}, raw.holder) : null;
|
|
2713
3095
|
nextTempOrder.products = Array.isArray(raw.products) ? raw.products.map(function (p) {
|
|
2714
|
-
return
|
|
3096
|
+
return _this8.normalizeHydratedOrderProduct(p);
|
|
2715
3097
|
}) : [];
|
|
2716
3098
|
nextTempOrder.bookings = Array.isArray(raw.bookings) ? raw.bookings.map(function (b) {
|
|
2717
3099
|
return _objectSpread(_objectSpread({}, b || {}), {}, {
|
|
@@ -2773,23 +3155,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2773
3155
|
}, {
|
|
2774
3156
|
key: "getOrderInfo",
|
|
2775
3157
|
value: function () {
|
|
2776
|
-
var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
3158
|
+
var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(order_id) {
|
|
2777
3159
|
var res;
|
|
2778
|
-
return _regeneratorRuntime().wrap(function
|
|
2779
|
-
while (1) switch (
|
|
3160
|
+
return _regeneratorRuntime().wrap(function _callee32$(_context34) {
|
|
3161
|
+
while (1) switch (_context34.prev = _context34.next) {
|
|
2780
3162
|
case 0:
|
|
2781
|
-
|
|
3163
|
+
_context34.next = 2;
|
|
2782
3164
|
return this.request.get("/order/sales/".concat(order_id), {
|
|
2783
3165
|
with: ['products', 'bookings']
|
|
2784
3166
|
});
|
|
2785
3167
|
case 2:
|
|
2786
|
-
res =
|
|
2787
|
-
return
|
|
3168
|
+
res = _context34.sent;
|
|
3169
|
+
return _context34.abrupt("return", res);
|
|
2788
3170
|
case 4:
|
|
2789
3171
|
case "end":
|
|
2790
|
-
return
|
|
3172
|
+
return _context34.stop();
|
|
2791
3173
|
}
|
|
2792
|
-
},
|
|
3174
|
+
}, _callee32, this);
|
|
2793
3175
|
}));
|
|
2794
3176
|
function getOrderInfo(_x34) {
|
|
2795
3177
|
return _getOrderInfo.apply(this, arguments);
|
|
@@ -2805,46 +3187,46 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2805
3187
|
*/
|
|
2806
3188
|
function populateSavedAmounts(productList, discountList) {
|
|
2807
3189
|
var savedMap = new Map();
|
|
2808
|
-
var
|
|
2809
|
-
|
|
3190
|
+
var _iterator5 = _createForOfIteratorHelper(productList),
|
|
3191
|
+
_step5;
|
|
2810
3192
|
try {
|
|
2811
|
-
for (
|
|
2812
|
-
var product =
|
|
3193
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
3194
|
+
var product = _step5.value;
|
|
2813
3195
|
var qty = product.num || 1;
|
|
2814
|
-
var
|
|
2815
|
-
|
|
3196
|
+
var _iterator7 = _createForOfIteratorHelper(product.discount_list || []),
|
|
3197
|
+
_step7;
|
|
2816
3198
|
try {
|
|
2817
|
-
for (
|
|
3199
|
+
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
2818
3200
|
var _pd$discount, _pd$metadata;
|
|
2819
|
-
var pd =
|
|
3201
|
+
var pd = _step7.value;
|
|
2820
3202
|
var discountKey = ((_pd$discount = pd.discount) === null || _pd$discount === void 0 ? void 0 : _pd$discount.resource_id) || pd.id;
|
|
2821
3203
|
if (discountKey == null) continue;
|
|
2822
3204
|
var amount = new Decimal(pd.amount || 0).times(qty).plus(((_pd$metadata = pd.metadata) === null || _pd$metadata === void 0 ? void 0 : _pd$metadata.product_discount_difference) || 0);
|
|
2823
3205
|
savedMap.set(discountKey, (savedMap.get(discountKey) || new Decimal(0)).plus(amount));
|
|
2824
3206
|
}
|
|
2825
3207
|
} catch (err) {
|
|
2826
|
-
|
|
3208
|
+
_iterator7.e(err);
|
|
2827
3209
|
} finally {
|
|
2828
|
-
|
|
3210
|
+
_iterator7.f();
|
|
2829
3211
|
}
|
|
2830
3212
|
}
|
|
2831
3213
|
} catch (err) {
|
|
2832
|
-
|
|
3214
|
+
_iterator5.e(err);
|
|
2833
3215
|
} finally {
|
|
2834
|
-
|
|
3216
|
+
_iterator5.f();
|
|
2835
3217
|
}
|
|
2836
|
-
var
|
|
2837
|
-
|
|
3218
|
+
var _iterator6 = _createForOfIteratorHelper(discountList),
|
|
3219
|
+
_step6;
|
|
2838
3220
|
try {
|
|
2839
|
-
for (
|
|
2840
|
-
var d =
|
|
3221
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
3222
|
+
var d = _step6.value;
|
|
2841
3223
|
var key = d.id;
|
|
2842
3224
|
d.savedAmount = d.isSelected && key != null && savedMap.has(key) ? savedMap.get(key).toNumber() : 0;
|
|
2843
3225
|
}
|
|
2844
3226
|
} catch (err) {
|
|
2845
|
-
|
|
3227
|
+
_iterator6.e(err);
|
|
2846
3228
|
} finally {
|
|
2847
|
-
|
|
3229
|
+
_iterator6.f();
|
|
2848
3230
|
}
|
|
2849
3231
|
}
|
|
2850
3232
|
}]);
|