@pisell/pisellos 0.0.444 → 0.0.446
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/Cart/types.d.ts +2 -0
- package/dist/modules/Cart/utils/cartProduct.js +19 -0
- package/dist/modules/Cart/utils/changePrice.js +6 -0
- package/dist/modules/Rules/index.js +14 -14
- package/dist/modules/Summary/index.js +48 -6
- package/dist/modules/Summary/utils.d.ts +4 -2
- package/dist/modules/Summary/utils.js +52 -19
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingByStep/index.js +84 -35
- package/lib/modules/Cart/types.d.ts +2 -0
- package/lib/modules/Cart/utils/cartProduct.js +14 -0
- package/lib/modules/Cart/utils/changePrice.js +5 -0
- package/lib/modules/Rules/index.js +3 -3
- package/lib/modules/Summary/index.js +21 -3
- package/lib/modules/Summary/utils.d.ts +4 -2
- package/lib/modules/Summary/utils.js +55 -19
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingByStep/index.js +34 -3
- package/package.json +1 -1
|
@@ -13,6 +13,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
13
13
|
import Decimal from 'decimal.js';
|
|
14
14
|
import { isNormalProduct } from "../../Product/utils";
|
|
15
15
|
import { getDiscountAmount } from "../../../solution/ShopDiscount/utils";
|
|
16
|
+
import { calcDiscountListDifference } from "../../Summary/utils";
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
19
|
* @title 处理组合商品
|
|
@@ -70,6 +71,11 @@ export var formatProductToCartItem = function formatProductToCartItem(params) {
|
|
|
70
71
|
num: num,
|
|
71
72
|
discounts: discounts
|
|
72
73
|
});
|
|
74
|
+
cartItem.totalDifference = getTotalDifference({
|
|
75
|
+
product: product,
|
|
76
|
+
bundle: bundle,
|
|
77
|
+
discounts: discounts
|
|
78
|
+
});
|
|
73
79
|
cartItem.summaryTotal = cartItem.total * (num || 1);
|
|
74
80
|
cartItem.origin_total = getProductOriginTotalPrice({
|
|
75
81
|
product: product,
|
|
@@ -229,6 +235,19 @@ export var getProductTotalPrice = function getProductTotalPrice(params) {
|
|
|
229
235
|
}
|
|
230
236
|
return Math.max(0, price);
|
|
231
237
|
};
|
|
238
|
+
var getTotalDifference = function getTotalDifference(params) {
|
|
239
|
+
var bundle = params.bundle,
|
|
240
|
+
discounts = params.discounts;
|
|
241
|
+
var bundleDiscountList = [];
|
|
242
|
+
if (bundle !== null && bundle !== void 0 && bundle.length) {
|
|
243
|
+
bundle.forEach(function (currentValue) {
|
|
244
|
+
bundleDiscountList.push.apply(bundleDiscountList, _toConsumableArray((currentValue === null || currentValue === void 0 ? void 0 : currentValue.discount_list) || []));
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
var allDiscounts = [].concat(_toConsumableArray(discounts || []), bundleDiscountList);
|
|
248
|
+
var productDiscountProductDiscountDifference = calcDiscountListDifference(allDiscounts);
|
|
249
|
+
return productDiscountProductDiscountDifference || 0;
|
|
250
|
+
};
|
|
232
251
|
|
|
233
252
|
/**
|
|
234
253
|
* 获取商品原始总价
|
|
@@ -57,6 +57,12 @@ function _updateAllCartItemPrice() {
|
|
|
57
57
|
if (targetBundleItem.price_type === 'markdown') {
|
|
58
58
|
targetBundleItem.price = new Decimal(targetBundleItem.price || 0).mul(-1).toNumber();
|
|
59
59
|
}
|
|
60
|
+
// 如果有选择 option,还需要加上 option 的价格
|
|
61
|
+
if (n.option) {
|
|
62
|
+
targetBundleItem.price = new Decimal(targetBundleItem.price || 0).add(n.option.reduce(function (pre, cur) {
|
|
63
|
+
return pre + new Decimal(cur.price || 0).mul(cur.num || 1).toNumber();
|
|
64
|
+
}, 0)).toNumber();
|
|
65
|
+
}
|
|
60
66
|
if (targetBundleItem) {
|
|
61
67
|
return _objectSpread(_objectSpread({}, n), {}, {
|
|
62
68
|
price: targetBundleItem.price,
|
|
@@ -760,7 +760,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
760
760
|
// 收集该折扣卡适用的商品(排除被其他专属折扣卡占用的商品)
|
|
761
761
|
var applicableProducts = [];
|
|
762
762
|
sortedFlattenedList.forEach(function (flatItem) {
|
|
763
|
-
var _flatItem$parentProdu2, _product$price, _ref5, _flatItem$original_pr;
|
|
763
|
+
var _flatItem$parentProdu2, _flatItem$parentProdu3, _product$price, _ref5, _flatItem$original_pr;
|
|
764
764
|
// 🔥 检查该商品是否被其他专属折扣卡占用
|
|
765
765
|
var occupyingDiscountId = occupiedItems.get(flatItem._id);
|
|
766
766
|
if (occupyingDiscountId !== undefined && occupyingDiscountId !== discount.id) {
|
|
@@ -784,7 +784,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
784
784
|
}
|
|
785
785
|
|
|
786
786
|
// 对于 bundle 子商品,quantity 需要乘以主商品的购买数量
|
|
787
|
-
var quantity = flatItem.type === 'main' ? product.quantity || 1 : (product.num || 1) * (((_flatItem$parentProdu2 = flatItem.parentProduct) === null || _flatItem$parentProdu2 === void 0 ? void 0 : _flatItem$parentProdu2.quantity) || 1);
|
|
787
|
+
var quantity = flatItem.type === 'main' ? product.num || product.quantity || 1 : (product.num || product.quantity || 1) * (((_flatItem$parentProdu2 = flatItem.parentProduct) === null || _flatItem$parentProdu2 === void 0 ? void 0 : _flatItem$parentProdu2.num) || ((_flatItem$parentProdu3 = flatItem.parentProduct) === null || _flatItem$parentProdu3 === void 0 ? void 0 : _flatItem$parentProdu3.quantity) || 1);
|
|
788
788
|
|
|
789
789
|
// 对于主商品:使用 price
|
|
790
790
|
// 对于子商品:优先使用 flatItem.original_price,否则使用 flatItem.price
|
|
@@ -799,8 +799,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
799
799
|
|
|
800
800
|
// 子商品需要传递主商品数量
|
|
801
801
|
if (flatItem.type === 'bundle') {
|
|
802
|
-
var _flatItem$
|
|
803
|
-
productData.parentQuantity = ((_flatItem$
|
|
802
|
+
var _flatItem$parentProdu4;
|
|
803
|
+
productData.parentQuantity = ((_flatItem$parentProdu4 = flatItem.parentProduct) === null || _flatItem$parentProdu4 === void 0 ? void 0 : _flatItem$parentProdu4.quantity) || 1;
|
|
804
804
|
}
|
|
805
805
|
applicableProducts.push(productData);
|
|
806
806
|
});
|
|
@@ -827,10 +827,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
827
827
|
product = flatItem.product;
|
|
828
828
|
originProduct = flatItem.originProduct;
|
|
829
829
|
} else {
|
|
830
|
-
var _flatItem$
|
|
830
|
+
var _flatItem$parentProdu5;
|
|
831
831
|
// bundle子商品:构造虚拟商品对象
|
|
832
832
|
product = {
|
|
833
|
-
startDate: flatItem === null || flatItem === void 0 || (_flatItem$
|
|
833
|
+
startDate: flatItem === null || flatItem === void 0 || (_flatItem$parentProdu5 = flatItem.parentProduct) === null || _flatItem$parentProdu5 === void 0 ? void 0 : _flatItem$parentProdu5.startDate,
|
|
834
834
|
_id: flatItem._id,
|
|
835
835
|
id: flatItem.id,
|
|
836
836
|
price: flatItem.price,
|
|
@@ -918,10 +918,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
918
918
|
product = flatItem.product;
|
|
919
919
|
originProduct = flatItem.originProduct;
|
|
920
920
|
} else {
|
|
921
|
-
var _flatItem$
|
|
921
|
+
var _flatItem$parentProdu6, _flatItem$bundleItem5, _flatItem$bundleItem6, _flatItem$bundleItem7;
|
|
922
922
|
// bundle子商品
|
|
923
923
|
product = {
|
|
924
|
-
startDate: flatItem === null || flatItem === void 0 || (_flatItem$
|
|
924
|
+
startDate: flatItem === null || flatItem === void 0 || (_flatItem$parentProdu6 = flatItem.parentProduct) === null || _flatItem$parentProdu6 === void 0 ? void 0 : _flatItem$parentProdu6.startDate,
|
|
925
925
|
_id: flatItem._id,
|
|
926
926
|
id: flatItem.id,
|
|
927
927
|
price: flatItem.price,
|
|
@@ -1067,11 +1067,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1067
1067
|
}
|
|
1068
1068
|
// bundle子商品:检查自己的 discount_list 或父主商品的 discount_list
|
|
1069
1069
|
if (flatItem.type === 'bundle') {
|
|
1070
|
-
var _product$discount_lis7, _flatItem$
|
|
1070
|
+
var _product$discount_lis7, _flatItem$parentProdu7;
|
|
1071
1071
|
if ((_product$discount_lis7 = product.discount_list) !== null && _product$discount_lis7 !== void 0 && _product$discount_lis7.some(function (item) {
|
|
1072
1072
|
var _item$discount2;
|
|
1073
1073
|
return ((_item$discount2 = item.discount) === null || _item$discount2 === void 0 ? void 0 : _item$discount2.resource_id) === options.discountId;
|
|
1074
|
-
}) || (_flatItem$
|
|
1074
|
+
}) || (_flatItem$parentProdu7 = flatItem.parentProduct) !== null && _flatItem$parentProdu7 !== void 0 && (_flatItem$parentProdu7 = _flatItem$parentProdu7.discount_list) !== null && _flatItem$parentProdu7 !== void 0 && _flatItem$parentProdu7.some(function (item) {
|
|
1075
1075
|
var _item$discount3;
|
|
1076
1076
|
return ((_item$discount3 = item.discount) === null || _item$discount3 === void 0 ? void 0 : _item$discount3.resource_id) === options.discountId;
|
|
1077
1077
|
})) {
|
|
@@ -1093,14 +1093,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1093
1093
|
}
|
|
1094
1094
|
// bundle子商品:检查自己的 discount_list 或父主商品的 discount_list
|
|
1095
1095
|
if (flatItem.type === 'bundle') {
|
|
1096
|
-
var _product$discount_lis9, _flatItem$
|
|
1096
|
+
var _product$discount_lis9, _flatItem$parentProdu8;
|
|
1097
1097
|
if ((_product$discount_lis9 = product.discount_list) !== null && _product$discount_lis9 !== void 0 && _product$discount_lis9.some(function (item) {
|
|
1098
1098
|
var _options$selectedList2;
|
|
1099
1099
|
return options === null || options === void 0 || (_options$selectedList2 = options.selectedList) === null || _options$selectedList2 === void 0 ? void 0 : _options$selectedList2.some(function (n) {
|
|
1100
1100
|
var _item$discount5;
|
|
1101
1101
|
return n.discountId === ((_item$discount5 = item.discount) === null || _item$discount5 === void 0 ? void 0 : _item$discount5.resource_id);
|
|
1102
1102
|
});
|
|
1103
|
-
}) || (_flatItem$
|
|
1103
|
+
}) || (_flatItem$parentProdu8 = flatItem.parentProduct) !== null && _flatItem$parentProdu8 !== void 0 && (_flatItem$parentProdu8 = _flatItem$parentProdu8.discount_list) !== null && _flatItem$parentProdu8 !== void 0 && _flatItem$parentProdu8.some(function (item) {
|
|
1104
1104
|
var _options$selectedList3;
|
|
1105
1105
|
return options === null || options === void 0 || (_options$selectedList3 = options.selectedList) === null || _options$selectedList3 === void 0 ? void 0 : _options$selectedList3.some(function (n) {
|
|
1106
1106
|
var _item$discount6;
|
|
@@ -1384,7 +1384,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1384
1384
|
}));
|
|
1385
1385
|
}
|
|
1386
1386
|
} else {
|
|
1387
|
-
var _selectedDiscount3$me, _selectedDiscount3$me2, _flatItem$
|
|
1387
|
+
var _selectedDiscount3$me, _selectedDiscount3$me2, _flatItem$parentProdu9;
|
|
1388
1388
|
// 折扣卡:不拆分数量,直接应用
|
|
1389
1389
|
var _selectedDiscount3 = selectedDiscountCard || applicableDiscounts[0];
|
|
1390
1390
|
usedDiscounts.set(_selectedDiscount3.id, true);
|
|
@@ -1437,7 +1437,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1437
1437
|
product_discount_difference: _productDiscountDifference
|
|
1438
1438
|
}),
|
|
1439
1439
|
config: _selectedDiscount3 === null || _selectedDiscount3 === void 0 ? void 0 : _selectedDiscount3.config,
|
|
1440
|
-
_num: (product.num || 1) * ((flatItem === null || flatItem === void 0 || (_flatItem$
|
|
1440
|
+
_num: (product.num || 1) * ((flatItem === null || flatItem === void 0 || (_flatItem$parentProdu9 = flatItem.parentProduct) === null || _flatItem$parentProdu9 === void 0 ? void 0 : _flatItem$parentProdu9.num) || 1)
|
|
1441
1441
|
};
|
|
1442
1442
|
|
|
1443
1443
|
// 记录实际应用的折扣
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
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); }
|
|
2
|
+
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; } } }; }
|
|
3
|
+
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); }
|
|
4
|
+
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; }
|
|
2
5
|
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; }
|
|
3
6
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
4
7
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
@@ -86,7 +89,7 @@ export var SummaryModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
86
89
|
while (1) switch (_context2.prev = _context2.next) {
|
|
87
90
|
case 0:
|
|
88
91
|
_context2.next = 2;
|
|
89
|
-
return this.request.get('/order/custom-surcharge/available', {
|
|
92
|
+
return this.request.get('/order/custom-surcharge/available/v2', {
|
|
90
93
|
channel: 'online-store',
|
|
91
94
|
is_assemble_product_data: 1,
|
|
92
95
|
is_assemble_schedule_data: 1,
|
|
@@ -111,15 +114,34 @@ export var SummaryModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
111
114
|
value: function () {
|
|
112
115
|
var _getSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(cartItems) {
|
|
113
116
|
var _this$shopStore$get;
|
|
114
|
-
var shopInfo, summary;
|
|
117
|
+
var shopInfo, scheduleModule, needScheduleIds, scheduleList, scheduleById, _iterator, _step, item, summary;
|
|
115
118
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
116
119
|
while (1) switch (_context3.prev = _context3.next) {
|
|
117
120
|
case 0:
|
|
118
|
-
shopInfo = ((_this$shopStore$get = this.shopStore.get('core')) === null || _this$shopStore$get === void 0 || (_this$shopStore$get = _this$shopStore$get.core) === null || _this$shopStore$get === void 0 ? void 0 : _this$shopStore$get.shop) || {};
|
|
119
|
-
|
|
121
|
+
shopInfo = ((_this$shopStore$get = this.shopStore.get('core')) === null || _this$shopStore$get === void 0 || (_this$shopStore$get = _this$shopStore$get.core) === null || _this$shopStore$get === void 0 ? void 0 : _this$shopStore$get.shop) || {};
|
|
122
|
+
scheduleModule = this.core.getModule('appointmentBooking_schedule');
|
|
123
|
+
needScheduleIds = this.store.surchargeList.map(function (item) {
|
|
124
|
+
return item.available_schedule_ids;
|
|
125
|
+
}).flat();
|
|
126
|
+
scheduleList = scheduleModule === null || scheduleModule === void 0 ? void 0 : scheduleModule.getScheduleListByIds(needScheduleIds);
|
|
127
|
+
scheduleById = {};
|
|
128
|
+
if (Array.isArray(scheduleList)) {
|
|
129
|
+
_iterator = _createForOfIteratorHelper(scheduleList);
|
|
130
|
+
try {
|
|
131
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
132
|
+
item = _step.value;
|
|
133
|
+
scheduleById[item.id] = item;
|
|
134
|
+
}
|
|
135
|
+
} catch (err) {
|
|
136
|
+
_iterator.e(err);
|
|
137
|
+
} finally {
|
|
138
|
+
_iterator.f();
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
summary = calculatePriceDetails(shopInfo, cartItems, ScheduleModule === null || ScheduleModule === void 0 ? void 0 : ScheduleModule.isInScheduleByDate, this.store.surchargeList, scheduleById);
|
|
120
142
|
this.store.summary = summary;
|
|
121
143
|
return _context3.abrupt("return", this.store.summary);
|
|
122
|
-
case
|
|
144
|
+
case 9:
|
|
123
145
|
case "end":
|
|
124
146
|
return _context3.stop();
|
|
125
147
|
}
|
|
@@ -187,6 +209,26 @@ export var SummaryModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
187
209
|
key: "getSurchargeforUtils",
|
|
188
210
|
value: function getSurchargeforUtils(items) {
|
|
189
211
|
// const surchargeList = this.store.surchargeList;
|
|
212
|
+
var scheduleModule = this.core.getModule('appointmentBooking_schedule');
|
|
213
|
+
var needScheduleIds = this.store.surchargeList.map(function (item) {
|
|
214
|
+
return item.available_schedule_ids;
|
|
215
|
+
}).flat();
|
|
216
|
+
var scheduleList = scheduleModule === null || scheduleModule === void 0 ? void 0 : scheduleModule.getScheduleListByIds(needScheduleIds);
|
|
217
|
+
var scheduleById = {};
|
|
218
|
+
if (Array.isArray(scheduleList)) {
|
|
219
|
+
var _iterator2 = _createForOfIteratorHelper(scheduleList),
|
|
220
|
+
_step2;
|
|
221
|
+
try {
|
|
222
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
223
|
+
var item = _step2.value;
|
|
224
|
+
scheduleById[item.id] = item;
|
|
225
|
+
}
|
|
226
|
+
} catch (err) {
|
|
227
|
+
_iterator2.e(err);
|
|
228
|
+
} finally {
|
|
229
|
+
_iterator2.f();
|
|
230
|
+
}
|
|
231
|
+
}
|
|
190
232
|
var surchargeList = getSurcharge({
|
|
191
233
|
service: items,
|
|
192
234
|
addons: [],
|
|
@@ -196,7 +238,7 @@ export var SummaryModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
196
238
|
isEdit: false,
|
|
197
239
|
isInScheduleByDate: ScheduleModule.isInScheduleByDate,
|
|
198
240
|
surcharge_list: this.store.surchargeList,
|
|
199
|
-
scheduleById:
|
|
241
|
+
scheduleById: scheduleById
|
|
200
242
|
});
|
|
201
243
|
var surchargeAmount = new Decimal(getSurchargeAmount({
|
|
202
244
|
bookingDetail: null,
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import Decimal from 'decimal.js';
|
|
2
2
|
import { CartItem } from '../Cart/types';
|
|
3
3
|
import { ISummaryState } from './types';
|
|
4
|
-
export declare const calculatePriceDetails: (shopInfo: any, items: CartItem[], isInScheduleByDate: any, surchargeList: any[]) => ISummaryState['summary'];
|
|
4
|
+
export declare const calculatePriceDetails: (shopInfo: any, items: CartItem[], isInScheduleByDate: any, surchargeList: any[], scheduleById: Record<string, any>) => ISummaryState['summary'];
|
|
5
5
|
/**
|
|
6
6
|
* 获取子商品折扣信息
|
|
7
7
|
* @param item
|
|
8
8
|
*/
|
|
9
9
|
export declare const getBundleDiscountList: (bundle: any[]) => any[];
|
|
10
|
+
export declare const calcDiscountListDifference: (discountList: any[]) => any;
|
|
11
|
+
export declare const getProductDiscountProductDiscountDifference: (item: CartItem) => any;
|
|
10
12
|
/**
|
|
11
13
|
* 计算订单税费(折扣前/折扣后),并把单品税费信息回写到商品数据上(用于明细展示/后续计算)。
|
|
12
14
|
*
|
|
@@ -70,7 +72,7 @@ export declare const calculateOriginSubtotal: (items: CartItem[]) => string;
|
|
|
70
72
|
* @return {*}
|
|
71
73
|
* @Author: xiangfeng.xue
|
|
72
74
|
*/
|
|
73
|
-
export declare const calculateTaxFee: (shopInfo: any, items: CartItem[]) =>
|
|
75
|
+
export declare const calculateTaxFee: (shopInfo: any, items: CartItem[]) => "0.00" | Decimal;
|
|
74
76
|
/**
|
|
75
77
|
* @title: 计算定金
|
|
76
78
|
* @param items - 购物车商品数组
|
|
@@ -16,7 +16,7 @@ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symb
|
|
|
16
16
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
17
17
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
18
18
|
import Decimal from 'decimal.js';
|
|
19
|
-
export var calculatePriceDetails = function calculatePriceDetails(shopInfo, items, isInScheduleByDate, surchargeList) {
|
|
19
|
+
export var calculatePriceDetails = function calculatePriceDetails(shopInfo, items, isInScheduleByDate, surchargeList, scheduleById) {
|
|
20
20
|
var subtotal = new Decimal(calculateSubtotal(items));
|
|
21
21
|
var subOriginTotal = new Decimal(calculateOriginSubtotal(items));
|
|
22
22
|
var totalTaxFee = new Decimal(calculateTaxFee(shopInfo, items));
|
|
@@ -30,7 +30,7 @@ export var calculatePriceDetails = function calculatePriceDetails(shopInfo, item
|
|
|
30
30
|
isEdit: false,
|
|
31
31
|
isInScheduleByDate: isInScheduleByDate,
|
|
32
32
|
surcharge_list: surchargeList,
|
|
33
|
-
scheduleById:
|
|
33
|
+
scheduleById: scheduleById
|
|
34
34
|
});
|
|
35
35
|
// 订单附加费金额
|
|
36
36
|
var surchargeAmount = new Decimal(getSurchargeAmount({
|
|
@@ -94,14 +94,18 @@ export var getBundleDiscountList = function getBundleDiscountList(bundle) {
|
|
|
94
94
|
});
|
|
95
95
|
return discountList;
|
|
96
96
|
};
|
|
97
|
-
var
|
|
97
|
+
export var calcDiscountListDifference = function calcDiscountListDifference(discountList) {
|
|
98
|
+
return discountList.reduce(function (pre, cur) {
|
|
99
|
+
var _cur$metadata;
|
|
100
|
+
return pre + ((cur === null || cur === void 0 || (_cur$metadata = cur.metadata) === null || _cur$metadata === void 0 ? void 0 : _cur$metadata.product_discount_difference) || 0);
|
|
101
|
+
}, 0);
|
|
102
|
+
};
|
|
103
|
+
export var getProductDiscountProductDiscountDifference = function getProductDiscountProductDiscountDifference(item) {
|
|
98
104
|
var _item$_origin, _item$_origin2;
|
|
99
105
|
var mainDiscountList = ((_item$_origin = item._origin) === null || _item$_origin === void 0 || (_item$_origin = _item$_origin.product) === null || _item$_origin === void 0 ? void 0 : _item$_origin.discount_list) || [];
|
|
100
106
|
var bundleDiscountList = getBundleDiscountList(((_item$_origin2 = item._origin) === null || _item$_origin2 === void 0 || (_item$_origin2 = _item$_origin2.product) === null || _item$_origin2 === void 0 ? void 0 : _item$_origin2.product_bundle) || []);
|
|
101
107
|
var discountList = [].concat(_toConsumableArray(mainDiscountList), _toConsumableArray(bundleDiscountList));
|
|
102
|
-
return discountList
|
|
103
|
-
return pre + (cur.metadata.product_discount_difference || 0);
|
|
104
|
-
}, 0);
|
|
108
|
+
return calcDiscountListDifference(discountList);
|
|
105
109
|
};
|
|
106
110
|
|
|
107
111
|
/**
|
|
@@ -189,6 +193,15 @@ export var getTax = function getTax(_ref, options) {
|
|
|
189
193
|
tax: totalTax.toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber()
|
|
190
194
|
};
|
|
191
195
|
};
|
|
196
|
+
function getDiscountedTaxableBase(input) {
|
|
197
|
+
var basePrice = input.basePrice,
|
|
198
|
+
discount = input.discount,
|
|
199
|
+
surchargeFee = input.surchargeFee;
|
|
200
|
+
if (surchargeFee.lte(0) && basePrice.lte(0)) return new Decimal(0);
|
|
201
|
+
var discountedBase = basePrice.minus(discount);
|
|
202
|
+
if (discountedBase.lte(0)) return surchargeFee;
|
|
203
|
+
return discountedBase.plus(surchargeFee);
|
|
204
|
+
}
|
|
192
205
|
|
|
193
206
|
/**
|
|
194
207
|
* 处理商品税费计算(折扣前后)
|
|
@@ -233,8 +246,13 @@ var processItemsTax = function processItemsTax(items, _ref2, options) {
|
|
|
233
246
|
})) || 0);
|
|
234
247
|
|
|
235
248
|
// 计算原始税费(折扣前)- 单个商品(精确值)
|
|
249
|
+
var originalTaxableBase = getDiscountedTaxableBase({
|
|
250
|
+
basePrice: mainProductPrice,
|
|
251
|
+
discount: new Decimal(0),
|
|
252
|
+
surchargeFee: new Decimal((item === null || item === void 0 ? void 0 : item.surcharge_fee) || 0)
|
|
253
|
+
});
|
|
236
254
|
var originalTaxPerItemPrecise = getProductItemTax(_objectSpread(_objectSpread({}, item), {}, {
|
|
237
|
-
total:
|
|
255
|
+
total: originalTaxableBase.toNumber(),
|
|
238
256
|
quantity: 1
|
|
239
257
|
}), {
|
|
240
258
|
bookingDetail: bookingDetail,
|
|
@@ -255,7 +273,11 @@ var processItemsTax = function processItemsTax(items, _ref2, options) {
|
|
|
255
273
|
if (unitPrice.greaterThan(0)) {
|
|
256
274
|
mainItemDiscount = mainProductPrice.dividedBy(productExpectAmount).times(shopDiscount);
|
|
257
275
|
}
|
|
258
|
-
var mainItemDiscountedUnitPrice =
|
|
276
|
+
var mainItemDiscountedUnitPrice = getDiscountedTaxableBase({
|
|
277
|
+
basePrice: mainProductPrice,
|
|
278
|
+
discount: mainItemDiscount,
|
|
279
|
+
surchargeFee: new Decimal((item === null || item === void 0 ? void 0 : item.surcharge_fee) || 0)
|
|
280
|
+
});
|
|
259
281
|
|
|
260
282
|
// 计算折后税费(折扣后)- 主商品的税费(精确值)
|
|
261
283
|
var maxDiscountedTaxPerItemPrecise = getProductItemTax(_objectSpread(_objectSpread({}, item), {}, {
|
|
@@ -295,12 +317,14 @@ var processItemsTax = function processItemsTax(items, _ref2, options) {
|
|
|
295
317
|
var atItem = _step2.value;
|
|
296
318
|
// 计算单件加时商品折扣后价格
|
|
297
319
|
var _originTotal = new Decimal(atItem.selling_price || atItem.price || 0);
|
|
298
|
-
var
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
320
|
+
var addTimeDiscount = productExpectAmount > 0 ? _originTotal.dividedBy(productExpectAmount).times(shopDiscount) : new Decimal(0);
|
|
321
|
+
var _discountedTotal = getDiscountedTaxableBase({
|
|
322
|
+
basePrice: _originTotal,
|
|
323
|
+
discount: addTimeDiscount,
|
|
324
|
+
surchargeFee: new Decimal((atItem === null || atItem === void 0 ? void 0 : atItem.surcharge_fee) || 0)
|
|
325
|
+
});
|
|
302
326
|
var addTimeTaxPerItemPrecise = getProductItemTax(_objectSpread(_objectSpread({}, atItem), {}, {
|
|
303
|
-
total: _discountedTotal.
|
|
327
|
+
total: _discountedTotal.toNumber(),
|
|
304
328
|
quantity: atItem.product_quantity || atItem.num || 1
|
|
305
329
|
}), {
|
|
306
330
|
bookingDetail: bookingDetail,
|
|
@@ -349,8 +373,13 @@ var processItemsTax = function processItemsTax(items, _ref2, options) {
|
|
|
349
373
|
var bundleUnitPrice = new Decimal((_ref3 = (_bundleItem$bundle_se = bundleItem.bundle_selling_price) !== null && _bundleItem$bundle_se !== void 0 ? _bundleItem$bundle_se : bundleItem.price) !== null && _ref3 !== void 0 ? _ref3 : 0);
|
|
350
374
|
|
|
351
375
|
// 计算原始税费(折扣前)- 单个商品(精确值)
|
|
376
|
+
var bundleOriginalTaxableBase = getDiscountedTaxableBase({
|
|
377
|
+
basePrice: bundleUnitPrice,
|
|
378
|
+
discount: new Decimal(0),
|
|
379
|
+
surchargeFee: new Decimal((bundleItem === null || bundleItem === void 0 ? void 0 : bundleItem.surcharge_fee) || 0)
|
|
380
|
+
});
|
|
352
381
|
var bundleOriginalTaxPerItemPrecise = getProductItemTax(_objectSpread(_objectSpread({}, bundleItem), {}, {
|
|
353
|
-
total:
|
|
382
|
+
total: bundleOriginalTaxableBase.toNumber(),
|
|
354
383
|
quantity: 1
|
|
355
384
|
}), {
|
|
356
385
|
bookingDetail: bookingDetail,
|
|
@@ -367,7 +396,11 @@ var processItemsTax = function processItemsTax(items, _ref2, options) {
|
|
|
367
396
|
}
|
|
368
397
|
|
|
369
398
|
// bundle商品折后单价
|
|
370
|
-
var bundleDiscountedUnitPrice =
|
|
399
|
+
var bundleDiscountedUnitPrice = getDiscountedTaxableBase({
|
|
400
|
+
basePrice: bundleUnitPrice,
|
|
401
|
+
discount: bundleItemDiscount,
|
|
402
|
+
surchargeFee: new Decimal((bundleItem === null || bundleItem === void 0 ? void 0 : bundleItem.surcharge_fee) || 0)
|
|
403
|
+
});
|
|
371
404
|
|
|
372
405
|
// 计算折后税费(折扣后)- 单个商品(精确值)
|
|
373
406
|
var bundleDiscountedTaxPerItemPrecise = getProductItemTax(_objectSpread(_objectSpread({}, bundleItem), {}, {
|
|
@@ -719,7 +752,6 @@ var getMainProductTotal = function getMainProductTotal(item) {
|
|
|
719
752
|
}
|
|
720
753
|
return total.toNumber();
|
|
721
754
|
};
|
|
722
|
-
|
|
723
755
|
/**
|
|
724
756
|
* 判断商品是否符合附加费条件
|
|
725
757
|
*/
|
|
@@ -834,6 +866,7 @@ export var getSurcharge = function getSurcharge(_ref11, options) {
|
|
|
834
866
|
addons = _ref11.addons,
|
|
835
867
|
bookingDetail = _ref11.bookingDetail,
|
|
836
868
|
bookingId = _ref11.bookingId;
|
|
869
|
+
debugger;
|
|
837
870
|
var isEdit = options.isEdit,
|
|
838
871
|
isInScheduleByDate = options.isInScheduleByDate,
|
|
839
872
|
surcharge_list = options.surcharge_list,
|
|
@@ -904,7 +937,7 @@ export var getSurcharge = function getSurcharge(_ref11, options) {
|
|
|
904
937
|
// 主商品符合附加费条件
|
|
905
938
|
if (isProductMatchSurchargeCondition({
|
|
906
939
|
isCustomItem: item.isCustomItem,
|
|
907
|
-
startDate: (item === null || item === void 0 ? void 0 : item.startDate) || '',
|
|
940
|
+
startDate: (item === null || item === void 0 ? void 0 : item.startDate) || (item === null || item === void 0 ? void 0 : item.start_date) || '',
|
|
908
941
|
product_id: item.id
|
|
909
942
|
}, {
|
|
910
943
|
surchargeConfig: surchargeConfig,
|
|
@@ -938,7 +971,7 @@ export var getSurcharge = function getSurcharge(_ref11, options) {
|
|
|
938
971
|
// bundle商品是原价且符合附加费条件
|
|
939
972
|
if (getBundleItemIsOriginalPrice(bundleItem) && isProductMatchSurchargeCondition({
|
|
940
973
|
isCustomItem: false,
|
|
941
|
-
startDate: item.startDate,
|
|
974
|
+
startDate: item.startDate || item.start_date || '',
|
|
942
975
|
product_id: bundleItem._bundle_product_id
|
|
943
976
|
}, {
|
|
944
977
|
surchargeConfig: surchargeConfig,
|
|
@@ -970,7 +1003,7 @@ export var getSurcharge = function getSurcharge(_ref11, options) {
|
|
|
970
1003
|
var relationDetail = _step7.value;
|
|
971
1004
|
if (isProductMatchSurchargeCondition({
|
|
972
1005
|
isCustomItem: false,
|
|
973
|
-
startDate: item.startDate,
|
|
1006
|
+
startDate: item.startDate || item.start_date || '',
|
|
974
1007
|
product_id: relationDetail.product_id
|
|
975
1008
|
}, {
|
|
976
1009
|
surchargeConfig: surchargeConfig,
|
|
@@ -311,7 +311,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
311
311
|
date: string;
|
|
312
312
|
status: string;
|
|
313
313
|
week: string;
|
|
314
|
-
weekNum: 0 |
|
|
314
|
+
weekNum: 0 | 2 | 4 | 3 | 1 | 5 | 6;
|
|
315
315
|
}[]>;
|
|
316
316
|
submitTimeSlot(timeSlots: TimeSliceItem): void;
|
|
317
317
|
private getScheduleDataByIds;
|
|
@@ -2554,14 +2554,63 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2554
2554
|
var targetResourceTimes = allResources === null || allResources === void 0 || (_allResources$find = allResources.find(function (n) {
|
|
2555
2555
|
return n.id === resource.id;
|
|
2556
2556
|
})) === null || _allResources$find === void 0 ? void 0 : _allResources$find.times;
|
|
2557
|
+
// 找到最晚的 end_at 还没用,因为可能存在资源工作时间是 10:00-19:00,但是资源的 times 里有 16:30-19:00 被 block 的情况
|
|
2558
|
+
// 所以还需要排除掉 block 时间
|
|
2559
|
+
function getEarliestBlockedStartTime(_ref11) {
|
|
2560
|
+
var _earliestBlockStart;
|
|
2561
|
+
var currentStartTime = _ref11.currentStartTime,
|
|
2562
|
+
times = _ref11.times;
|
|
2563
|
+
var currentStart = dayjs(currentStartTime);
|
|
2564
|
+
var earliestBlockStart;
|
|
2565
|
+
var _iterator3 = _createForOfIteratorHelper(times || []),
|
|
2566
|
+
_step3;
|
|
2567
|
+
try {
|
|
2568
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
2569
|
+
var time = _step3.value;
|
|
2570
|
+
var _iterator4 = _createForOfIteratorHelper(time.event_list || []),
|
|
2571
|
+
_step4;
|
|
2572
|
+
try {
|
|
2573
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
2574
|
+
var event = _step4.value;
|
|
2575
|
+
var eventStart = dayjs(event.start_at);
|
|
2576
|
+
var eventEnd = dayjs(event.end_at);
|
|
2577
|
+
if (eventStart.isBefore(currentStart) && eventEnd.isAfter(currentStart)) {
|
|
2578
|
+
return currentStart.format('YYYY-MM-DD HH:mm');
|
|
2579
|
+
}
|
|
2580
|
+
if (eventStart.isAfter(currentStart)) {
|
|
2581
|
+
if (!earliestBlockStart || eventStart.isBefore(earliestBlockStart)) {
|
|
2582
|
+
earliestBlockStart = eventStart;
|
|
2583
|
+
}
|
|
2584
|
+
}
|
|
2585
|
+
}
|
|
2586
|
+
} catch (err) {
|
|
2587
|
+
_iterator4.e(err);
|
|
2588
|
+
} finally {
|
|
2589
|
+
_iterator4.f();
|
|
2590
|
+
}
|
|
2591
|
+
}
|
|
2592
|
+
} catch (err) {
|
|
2593
|
+
_iterator3.e(err);
|
|
2594
|
+
} finally {
|
|
2595
|
+
_iterator3.f();
|
|
2596
|
+
}
|
|
2597
|
+
return (_earliestBlockStart = earliestBlockStart) === null || _earliestBlockStart === void 0 ? void 0 : _earliestBlockStart.format('YYYY-MM-DD HH:mm');
|
|
2598
|
+
}
|
|
2557
2599
|
var resourcesEndTime = targetResourceTimes.reduce(function (acc, curr) {
|
|
2558
2600
|
return dayjs(curr.end_at).isAfter(dayjs(acc.end_at)) ? curr : acc;
|
|
2559
2601
|
}, targetResourceTimes[0]);
|
|
2602
|
+
var earliestBlockedStartTime = getEarliestBlockedStartTime({
|
|
2603
|
+
currentStartTime: currentStartTime,
|
|
2604
|
+
times: targetResourceTimes
|
|
2605
|
+
});
|
|
2560
2606
|
|
|
2561
2607
|
// 将 operating_day_boundary 转换为与 resourcesEndTime.end_at 相同日期的完整日期时间
|
|
2562
2608
|
var resourceDate = dayjs(resourcesEndTime.end_at).format('YYYY-MM-DD');
|
|
2563
2609
|
var operatingBoundaryDateTime = "".concat(resourceDate, " ").concat(operating_day_boundary.type === 'start_time' ? '23:59' : operating_day_boundary.time);
|
|
2564
|
-
var
|
|
2610
|
+
var endTimeCandidates = [resourcesEndTime.end_at, operatingBoundaryDateTime].concat(_toConsumableArray(earliestBlockedStartTime ? [earliestBlockedStartTime] : []));
|
|
2611
|
+
var endTime = endTimeCandidates.reduce(function (earliest, value) {
|
|
2612
|
+
return dayjs(value).isBefore(dayjs(earliest)) ? value : earliest;
|
|
2613
|
+
}, endTimeCandidates[0]);
|
|
2565
2614
|
// 修复:如果 endTime 只是时间格式(如 "17:00"),需要加上日期
|
|
2566
2615
|
var formattedEndTime;
|
|
2567
2616
|
if (typeof endTime === 'string' && endTime.includes(':') && !endTime.includes(' ') && !endTime.includes('T')) {
|
|
@@ -2702,14 +2751,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2702
2751
|
// 通过商品和 schedule 来获取视频可用的时间片、时间片内资源可用的数据
|
|
2703
2752
|
}, {
|
|
2704
2753
|
key: "getTimeslotBySchedule",
|
|
2705
|
-
value: function getTimeslotBySchedule(
|
|
2754
|
+
value: function getTimeslotBySchedule(_ref12) {
|
|
2706
2755
|
var _this$store$currentPr2,
|
|
2707
2756
|
_targetProductData$pr,
|
|
2708
2757
|
_this15 = this;
|
|
2709
|
-
var date =
|
|
2710
|
-
scheduleIds =
|
|
2711
|
-
resources =
|
|
2712
|
-
product =
|
|
2758
|
+
var date = _ref12.date,
|
|
2759
|
+
scheduleIds = _ref12.scheduleIds,
|
|
2760
|
+
resources = _ref12.resources,
|
|
2761
|
+
product = _ref12.product;
|
|
2713
2762
|
var targetProduct = this.store.currentProduct;
|
|
2714
2763
|
// 如果外面传递了product 优先用外面的
|
|
2715
2764
|
var targetProductData = product || targetProduct;
|
|
@@ -3268,12 +3317,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3268
3317
|
// 检查资源类型(单个预约 vs 多个预约)
|
|
3269
3318
|
// 从商品配置中获取资源类型信息
|
|
3270
3319
|
var resourceTypeConfig = null;
|
|
3271
|
-
var
|
|
3272
|
-
|
|
3320
|
+
var _iterator5 = _createForOfIteratorHelper(items),
|
|
3321
|
+
_step5;
|
|
3273
3322
|
try {
|
|
3274
|
-
for (
|
|
3323
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
3275
3324
|
var _cartItem$_productOri12;
|
|
3276
|
-
var cartItem =
|
|
3325
|
+
var cartItem = _step5.value;
|
|
3277
3326
|
if ((_cartItem$_productOri12 = cartItem._productOrigin) !== null && _cartItem$_productOri12 !== void 0 && (_cartItem$_productOri12 = _cartItem$_productOri12.product_resource) !== null && _cartItem$_productOri12 !== void 0 && _cartItem$_productOri12.resources) {
|
|
3278
3327
|
resourceTypeConfig = cartItem._productOrigin.product_resource.resources.find(function (r) {
|
|
3279
3328
|
return r.code === resourceCode && r.status === 1;
|
|
@@ -3282,9 +3331,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3282
3331
|
}
|
|
3283
3332
|
}
|
|
3284
3333
|
} catch (err) {
|
|
3285
|
-
|
|
3334
|
+
_iterator5.e(err);
|
|
3286
3335
|
} finally {
|
|
3287
|
-
|
|
3336
|
+
_iterator5.f();
|
|
3288
3337
|
}
|
|
3289
3338
|
var isMultipleBooking = ((_resourceTypeConfig = resourceTypeConfig) === null || _resourceTypeConfig === void 0 ? void 0 : _resourceTypeConfig.type) === 'multiple';
|
|
3290
3339
|
var totalAvailable;
|
|
@@ -3487,17 +3536,17 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3487
3536
|
*/
|
|
3488
3537
|
}, {
|
|
3489
3538
|
key: "convertProductToCartItem",
|
|
3490
|
-
value: function convertProductToCartItem(
|
|
3491
|
-
var product =
|
|
3492
|
-
date =
|
|
3493
|
-
account =
|
|
3494
|
-
var
|
|
3495
|
-
bundle =
|
|
3496
|
-
options =
|
|
3497
|
-
origin =
|
|
3498
|
-
product_variant_id =
|
|
3499
|
-
|
|
3500
|
-
quantity =
|
|
3539
|
+
value: function convertProductToCartItem(_ref13) {
|
|
3540
|
+
var product = _ref13.product,
|
|
3541
|
+
date = _ref13.date,
|
|
3542
|
+
account = _ref13.account;
|
|
3543
|
+
var _ref14 = product || {},
|
|
3544
|
+
bundle = _ref14.bundle,
|
|
3545
|
+
options = _ref14.options,
|
|
3546
|
+
origin = _ref14.origin,
|
|
3547
|
+
product_variant_id = _ref14.product_variant_id,
|
|
3548
|
+
_ref14$quantity = _ref14.quantity,
|
|
3549
|
+
quantity = _ref14$quantity === void 0 ? 1 : _ref14$quantity;
|
|
3501
3550
|
|
|
3502
3551
|
// 处理商品数据,类似 addProductToCart 中的逻辑
|
|
3503
3552
|
var productData = _objectSpread(_objectSpread({}, origin), {}, {
|
|
@@ -3552,11 +3601,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3552
3601
|
}
|
|
3553
3602
|
}, {
|
|
3554
3603
|
key: "checkMaxDurationCapacityForDetailNums",
|
|
3555
|
-
value: function checkMaxDurationCapacityForDetailNums(
|
|
3604
|
+
value: function checkMaxDurationCapacityForDetailNums(_ref15) {
|
|
3556
3605
|
var _this17 = this;
|
|
3557
|
-
var product =
|
|
3558
|
-
date =
|
|
3559
|
-
account =
|
|
3606
|
+
var product = _ref15.product,
|
|
3607
|
+
date = _ref15.date,
|
|
3608
|
+
account = _ref15.account;
|
|
3560
3609
|
var cartItems = this.store.cart.getItems().filter(function (item) {
|
|
3561
3610
|
return !isNormalProduct(item._productOrigin);
|
|
3562
3611
|
});
|
|
@@ -3701,12 +3750,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3701
3750
|
// 检查资源类型(单个预约 vs 多个预约)
|
|
3702
3751
|
// 从商品配置中获取资源类型信息
|
|
3703
3752
|
var resourceTypeConfig = null;
|
|
3704
|
-
var
|
|
3705
|
-
|
|
3753
|
+
var _iterator6 = _createForOfIteratorHelper(items),
|
|
3754
|
+
_step6;
|
|
3706
3755
|
try {
|
|
3707
|
-
for (
|
|
3756
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
3708
3757
|
var _cartItem$_productOri15;
|
|
3709
|
-
var cartItem =
|
|
3758
|
+
var cartItem = _step6.value;
|
|
3710
3759
|
if ((_cartItem$_productOri15 = cartItem._productOrigin) !== null && _cartItem$_productOri15 !== void 0 && (_cartItem$_productOri15 = _cartItem$_productOri15.product_resource) !== null && _cartItem$_productOri15 !== void 0 && _cartItem$_productOri15.resources) {
|
|
3711
3760
|
resourceTypeConfig = cartItem._productOrigin.product_resource.resources.find(function (r) {
|
|
3712
3761
|
return r.code === resourceCode && r.status === 1;
|
|
@@ -3715,9 +3764,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3715
3764
|
}
|
|
3716
3765
|
}
|
|
3717
3766
|
} catch (err) {
|
|
3718
|
-
|
|
3767
|
+
_iterator6.e(err);
|
|
3719
3768
|
} finally {
|
|
3720
|
-
|
|
3769
|
+
_iterator6.f();
|
|
3721
3770
|
}
|
|
3722
3771
|
var isMultipleBooking = ((_resourceTypeConfig2 = resourceTypeConfig) === null || _resourceTypeConfig2 === void 0 ? void 0 : _resourceTypeConfig2.type) === 'multiple';
|
|
3723
3772
|
var totalAvailable;
|
|
@@ -4088,12 +4137,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
4088
4137
|
}, {
|
|
4089
4138
|
key: "getTimeslotsScheduleByDateRange",
|
|
4090
4139
|
value: (function () {
|
|
4091
|
-
var _getTimeslotsScheduleByDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(
|
|
4140
|
+
var _getTimeslotsScheduleByDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(_ref16) {
|
|
4092
4141
|
var startDate, endDate, scheduleIds, resources, dates, currentDate, end, results, _i5, _dates, date;
|
|
4093
4142
|
return _regeneratorRuntime().wrap(function _callee27$(_context28) {
|
|
4094
4143
|
while (1) switch (_context28.prev = _context28.next) {
|
|
4095
4144
|
case 0:
|
|
4096
|
-
startDate =
|
|
4145
|
+
startDate = _ref16.startDate, endDate = _ref16.endDate, scheduleIds = _ref16.scheduleIds, resources = _ref16.resources;
|
|
4097
4146
|
console.log('appoimentBooking-session-date-getTimeslotsScheduleByDateRange', {
|
|
4098
4147
|
startDate: startDate,
|
|
4099
4148
|
endDate: endDate,
|
|
@@ -45,6 +45,7 @@ module.exports = __toCommonJS(cartProduct_exports);
|
|
|
45
45
|
var import_decimal = __toESM(require("decimal.js"));
|
|
46
46
|
var import_utils = require("../../Product/utils");
|
|
47
47
|
var import_utils2 = require("../../../solution/ShopDiscount/utils");
|
|
48
|
+
var import_utils3 = require("../../Summary/utils");
|
|
48
49
|
var handleVariantProduct = (product) => {
|
|
49
50
|
var _a;
|
|
50
51
|
if (product == null ? void 0 : product.product_variant_id) {
|
|
@@ -80,6 +81,7 @@ var formatProductToCartItem = (params) => {
|
|
|
80
81
|
cartItem.price = product == null ? void 0 : product.price;
|
|
81
82
|
cartItem.num = num;
|
|
82
83
|
cartItem.total = getProductTotalPrice({ product, bundle, options, num, discounts });
|
|
84
|
+
cartItem.totalDifference = getTotalDifference({ product, bundle, discounts });
|
|
83
85
|
cartItem.summaryTotal = cartItem.total * (num || 1);
|
|
84
86
|
cartItem.origin_total = getProductOriginTotalPrice({
|
|
85
87
|
product,
|
|
@@ -216,6 +218,18 @@ var getProductTotalPrice = (params) => {
|
|
|
216
218
|
}
|
|
217
219
|
return Math.max(0, price);
|
|
218
220
|
};
|
|
221
|
+
var getTotalDifference = (params) => {
|
|
222
|
+
const { bundle, discounts } = params;
|
|
223
|
+
const bundleDiscountList = [];
|
|
224
|
+
if (bundle == null ? void 0 : bundle.length) {
|
|
225
|
+
bundle.forEach((currentValue) => {
|
|
226
|
+
bundleDiscountList.push(...(currentValue == null ? void 0 : currentValue.discount_list) || []);
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
const allDiscounts = [...discounts || [], ...bundleDiscountList];
|
|
230
|
+
const productDiscountProductDiscountDifference = (0, import_utils3.calcDiscountListDifference)(allDiscounts);
|
|
231
|
+
return productDiscountProductDiscountDifference || 0;
|
|
232
|
+
};
|
|
219
233
|
var getProductOriginTotalPrice = (params) => {
|
|
220
234
|
const { product, bundle, options, discounts } = params;
|
|
221
235
|
const num = (params == null ? void 0 : params.num) || 1;
|
|
@@ -60,6 +60,11 @@ async function updateAllCartItemPrice(cartItems, priceData, getProduct, updateCa
|
|
|
60
60
|
if (targetBundleItem.price_type === "markdown") {
|
|
61
61
|
targetBundleItem.price = new import_decimal.default(targetBundleItem.price || 0).mul(-1).toNumber();
|
|
62
62
|
}
|
|
63
|
+
if (n.option) {
|
|
64
|
+
targetBundleItem.price = new import_decimal.default(targetBundleItem.price || 0).add(n.option.reduce((pre, cur) => {
|
|
65
|
+
return pre + new import_decimal.default(cur.price || 0).mul(cur.num || 1).toNumber();
|
|
66
|
+
}, 0)).toNumber();
|
|
67
|
+
}
|
|
63
68
|
if (targetBundleItem) {
|
|
64
69
|
return {
|
|
65
70
|
...n,
|
|
@@ -505,7 +505,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
505
505
|
}
|
|
506
506
|
const applicableProducts = [];
|
|
507
507
|
sortedFlattenedList.forEach((flatItem) => {
|
|
508
|
-
var _a, _b;
|
|
508
|
+
var _a, _b, _c;
|
|
509
509
|
const occupyingDiscountId = occupiedItems.get(flatItem._id);
|
|
510
510
|
if (occupyingDiscountId !== void 0 && occupyingDiscountId !== discount.id) {
|
|
511
511
|
return;
|
|
@@ -525,7 +525,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
525
525
|
num: flatItem.num
|
|
526
526
|
};
|
|
527
527
|
}
|
|
528
|
-
const quantity = flatItem.type === "main" ? product.quantity || 1 : (product.num || 1) * (((_a = flatItem.parentProduct) == null ? void 0 : _a.quantity) || 1);
|
|
528
|
+
const quantity = flatItem.type === "main" ? product.num || product.quantity || 1 : (product.num || product.quantity || 1) * (((_a = flatItem.parentProduct) == null ? void 0 : _a.num) || ((_b = flatItem.parentProduct) == null ? void 0 : _b.quantity) || 1);
|
|
529
529
|
const originalAmount = flatItem.type === "main" ? Number(product.price ?? 0) : Number(flatItem.original_price ?? flatItem.price ?? 0);
|
|
530
530
|
const productData = {
|
|
531
531
|
productId: flatItem._id,
|
|
@@ -533,7 +533,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
533
533
|
quantity
|
|
534
534
|
};
|
|
535
535
|
if (flatItem.type === "bundle") {
|
|
536
|
-
productData.parentQuantity = ((
|
|
536
|
+
productData.parentQuantity = ((_c = flatItem.parentProduct) == null ? void 0 : _c.quantity) || 1;
|
|
537
537
|
}
|
|
538
538
|
applicableProducts.push(productData);
|
|
539
539
|
});
|
|
@@ -65,7 +65,7 @@ var SummaryModule = class extends import_BaseModule.BaseModule {
|
|
|
65
65
|
this.getSurchargeList();
|
|
66
66
|
}
|
|
67
67
|
async getSurchargeList() {
|
|
68
|
-
const surchargeList = await this.request.get("/order/custom-surcharge/available", {
|
|
68
|
+
const surchargeList = await this.request.get("/order/custom-surcharge/available/v2", {
|
|
69
69
|
channel: "online-store",
|
|
70
70
|
is_assemble_product_data: 1,
|
|
71
71
|
is_assemble_schedule_data: 1,
|
|
@@ -76,7 +76,16 @@ var SummaryModule = class extends import_BaseModule.BaseModule {
|
|
|
76
76
|
async getSummary(cartItems) {
|
|
77
77
|
var _a, _b, _c;
|
|
78
78
|
const shopInfo = ((_b = (_a = this.shopStore.get("core")) == null ? void 0 : _a.core) == null ? void 0 : _b.shop) || {};
|
|
79
|
-
const
|
|
79
|
+
const scheduleModule = this.core.getModule("appointmentBooking_schedule");
|
|
80
|
+
const needScheduleIds = this.store.surchargeList.map((item) => item.available_schedule_ids).flat();
|
|
81
|
+
const scheduleList = scheduleModule == null ? void 0 : scheduleModule.getScheduleListByIds(needScheduleIds);
|
|
82
|
+
const scheduleById = {};
|
|
83
|
+
if (Array.isArray(scheduleList)) {
|
|
84
|
+
for (let item of scheduleList) {
|
|
85
|
+
scheduleById[item.id] = item;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const summary = (0, import_utils.calculatePriceDetails)(shopInfo, cartItems, (_c = import_Schedule.ScheduleModule) == null ? void 0 : _c.isInScheduleByDate, this.store.surchargeList, scheduleById);
|
|
80
89
|
this.store.summary = summary;
|
|
81
90
|
return this.store.summary;
|
|
82
91
|
}
|
|
@@ -110,7 +119,16 @@ var SummaryModule = class extends import_BaseModule.BaseModule {
|
|
|
110
119
|
});
|
|
111
120
|
}
|
|
112
121
|
getSurchargeforUtils(items) {
|
|
113
|
-
const
|
|
122
|
+
const scheduleModule = this.core.getModule("appointmentBooking_schedule");
|
|
123
|
+
const needScheduleIds = this.store.surchargeList.map((item) => item.available_schedule_ids).flat();
|
|
124
|
+
const scheduleList = scheduleModule == null ? void 0 : scheduleModule.getScheduleListByIds(needScheduleIds);
|
|
125
|
+
const scheduleById = {};
|
|
126
|
+
if (Array.isArray(scheduleList)) {
|
|
127
|
+
for (let item of scheduleList) {
|
|
128
|
+
scheduleById[item.id] = item;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const surchargeList = (0, import_utils.getSurcharge)({ service: items, addons: [], bookingDetail: null, bookingId: void 0 }, { isEdit: false, isInScheduleByDate: import_Schedule.ScheduleModule.isInScheduleByDate, surcharge_list: this.store.surchargeList, scheduleById });
|
|
114
132
|
const surchargeAmount = new import_decimal.default((0, import_utils.getSurchargeAmount)({ bookingDetail: null, bookingId: void 0 }, surchargeList, { isEdit: false }));
|
|
115
133
|
return {
|
|
116
134
|
surchargeList,
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import Decimal from 'decimal.js';
|
|
2
2
|
import { CartItem } from '../Cart/types';
|
|
3
3
|
import { ISummaryState } from './types';
|
|
4
|
-
export declare const calculatePriceDetails: (shopInfo: any, items: CartItem[], isInScheduleByDate: any, surchargeList: any[]) => ISummaryState['summary'];
|
|
4
|
+
export declare const calculatePriceDetails: (shopInfo: any, items: CartItem[], isInScheduleByDate: any, surchargeList: any[], scheduleById: Record<string, any>) => ISummaryState['summary'];
|
|
5
5
|
/**
|
|
6
6
|
* 获取子商品折扣信息
|
|
7
7
|
* @param item
|
|
8
8
|
*/
|
|
9
9
|
export declare const getBundleDiscountList: (bundle: any[]) => any[];
|
|
10
|
+
export declare const calcDiscountListDifference: (discountList: any[]) => any;
|
|
11
|
+
export declare const getProductDiscountProductDiscountDifference: (item: CartItem) => any;
|
|
10
12
|
/**
|
|
11
13
|
* 计算订单税费(折扣前/折扣后),并把单品税费信息回写到商品数据上(用于明细展示/后续计算)。
|
|
12
14
|
*
|
|
@@ -70,7 +72,7 @@ export declare const calculateOriginSubtotal: (items: CartItem[]) => string;
|
|
|
70
72
|
* @return {*}
|
|
71
73
|
* @Author: xiangfeng.xue
|
|
72
74
|
*/
|
|
73
|
-
export declare const calculateTaxFee: (shopInfo: any, items: CartItem[]) =>
|
|
75
|
+
export declare const calculateTaxFee: (shopInfo: any, items: CartItem[]) => "0.00" | Decimal;
|
|
74
76
|
/**
|
|
75
77
|
* @title: 计算定金
|
|
76
78
|
* @param items - 购物车商品数组
|
|
@@ -29,23 +29,25 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
// src/modules/Summary/utils.ts
|
|
30
30
|
var utils_exports = {};
|
|
31
31
|
__export(utils_exports, {
|
|
32
|
+
calcDiscountListDifference: () => calcDiscountListDifference,
|
|
32
33
|
calculateDeposit: () => calculateDeposit,
|
|
33
34
|
calculateOriginSubtotal: () => calculateOriginSubtotal,
|
|
34
35
|
calculatePriceDetails: () => calculatePriceDetails,
|
|
35
36
|
calculateSubtotal: () => calculateSubtotal,
|
|
36
37
|
calculateTaxFee: () => calculateTaxFee,
|
|
37
38
|
getBundleDiscountList: () => getBundleDiscountList,
|
|
39
|
+
getProductDiscountProductDiscountDifference: () => getProductDiscountProductDiscountDifference,
|
|
38
40
|
getSurcharge: () => getSurcharge,
|
|
39
41
|
getSurchargeAmount: () => getSurchargeAmount,
|
|
40
42
|
getTax: () => getTax
|
|
41
43
|
});
|
|
42
44
|
module.exports = __toCommonJS(utils_exports);
|
|
43
45
|
var import_decimal = __toESM(require("decimal.js"));
|
|
44
|
-
var calculatePriceDetails = (shopInfo, items, isInScheduleByDate, surchargeList) => {
|
|
46
|
+
var calculatePriceDetails = (shopInfo, items, isInScheduleByDate, surchargeList, scheduleById) => {
|
|
45
47
|
const subtotal = new import_decimal.default(calculateSubtotal(items));
|
|
46
48
|
const subOriginTotal = new import_decimal.default(calculateOriginSubtotal(items));
|
|
47
49
|
const totalTaxFee = new import_decimal.default(calculateTaxFee(shopInfo, items));
|
|
48
|
-
const surcharge = getSurcharge({ service: items, addons: [], bookingDetail: null, bookingId: void 0 }, { isEdit: false, isInScheduleByDate, surcharge_list: surchargeList, scheduleById
|
|
50
|
+
const surcharge = getSurcharge({ service: items, addons: [], bookingDetail: null, bookingId: void 0 }, { isEdit: false, isInScheduleByDate, surcharge_list: surchargeList, scheduleById });
|
|
49
51
|
const surchargeAmount = new import_decimal.default(getSurchargeAmount({ bookingDetail: null, bookingId: void 0 }, surcharge, { isEdit: false }));
|
|
50
52
|
const { tax, originTax } = getTax({ service: items, bookingDetail: null, bookingId: void 0 }, {
|
|
51
53
|
computed: {
|
|
@@ -84,14 +86,18 @@ var getBundleDiscountList = (bundle) => {
|
|
|
84
86
|
});
|
|
85
87
|
return discountList;
|
|
86
88
|
};
|
|
89
|
+
var calcDiscountListDifference = (discountList) => {
|
|
90
|
+
return discountList.reduce((pre, cur) => {
|
|
91
|
+
var _a;
|
|
92
|
+
return pre + (((_a = cur == null ? void 0 : cur.metadata) == null ? void 0 : _a.product_discount_difference) || 0);
|
|
93
|
+
}, 0);
|
|
94
|
+
};
|
|
87
95
|
var getProductDiscountProductDiscountDifference = (item) => {
|
|
88
96
|
var _a, _b, _c, _d;
|
|
89
97
|
const mainDiscountList = ((_b = (_a = item._origin) == null ? void 0 : _a.product) == null ? void 0 : _b.discount_list) || [];
|
|
90
98
|
const bundleDiscountList = getBundleDiscountList(((_d = (_c = item._origin) == null ? void 0 : _c.product) == null ? void 0 : _d.product_bundle) || []);
|
|
91
99
|
const discountList = [...mainDiscountList, ...bundleDiscountList];
|
|
92
|
-
return discountList
|
|
93
|
-
return pre + (cur.metadata.product_discount_difference || 0);
|
|
94
|
-
}, 0);
|
|
100
|
+
return calcDiscountListDifference(discountList);
|
|
95
101
|
};
|
|
96
102
|
var getTax = ({ service, addons, bookingDetail, bookingId }, options) => {
|
|
97
103
|
const { isEdit, computed, tax_rate, is_price_include_tax } = options;
|
|
@@ -128,6 +134,15 @@ var getTax = ({ service, addons, bookingDetail, bookingId }, options) => {
|
|
|
128
134
|
tax: totalTax.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toNumber()
|
|
129
135
|
};
|
|
130
136
|
};
|
|
137
|
+
function getDiscountedTaxableBase(input) {
|
|
138
|
+
const { basePrice, discount, surchargeFee } = input;
|
|
139
|
+
if (surchargeFee.lte(0) && basePrice.lte(0))
|
|
140
|
+
return new import_decimal.default(0);
|
|
141
|
+
const discountedBase = basePrice.minus(discount);
|
|
142
|
+
if (discountedBase.lte(0))
|
|
143
|
+
return surchargeFee;
|
|
144
|
+
return discountedBase.plus(surchargeFee);
|
|
145
|
+
}
|
|
131
146
|
var processItemsTax = (items, { bookingDetail, bookingId }, options) => {
|
|
132
147
|
const { tax_rate, is_price_include_tax, computed } = options;
|
|
133
148
|
const { shopDiscount, productExpectAmount } = computed;
|
|
@@ -144,10 +159,15 @@ var processItemsTax = (items, { bookingDetail, bookingId }, options) => {
|
|
|
144
159
|
option: (item == null ? void 0 : item.option) || (item == null ? void 0 : item.options) || [],
|
|
145
160
|
bundle: (item == null ? void 0 : item.bundle) || (item == null ? void 0 : item.bundles) || []
|
|
146
161
|
}) || 0);
|
|
162
|
+
const originalTaxableBase = getDiscountedTaxableBase({
|
|
163
|
+
basePrice: mainProductPrice,
|
|
164
|
+
discount: new import_decimal.default(0),
|
|
165
|
+
surchargeFee: new import_decimal.default((item == null ? void 0 : item.surcharge_fee) || 0)
|
|
166
|
+
});
|
|
147
167
|
let originalTaxPerItemPrecise = getProductItemTax(
|
|
148
168
|
{
|
|
149
169
|
...item,
|
|
150
|
-
total:
|
|
170
|
+
total: originalTaxableBase.toNumber(),
|
|
151
171
|
quantity: 1
|
|
152
172
|
},
|
|
153
173
|
{ bookingDetail, bookingId },
|
|
@@ -161,7 +181,11 @@ var processItemsTax = (items, { bookingDetail, bookingId }, options) => {
|
|
|
161
181
|
if (unitPrice.greaterThan(0)) {
|
|
162
182
|
mainItemDiscount = mainProductPrice.dividedBy(productExpectAmount).times(shopDiscount);
|
|
163
183
|
}
|
|
164
|
-
const mainItemDiscountedUnitPrice =
|
|
184
|
+
const mainItemDiscountedUnitPrice = getDiscountedTaxableBase({
|
|
185
|
+
basePrice: mainProductPrice,
|
|
186
|
+
discount: mainItemDiscount,
|
|
187
|
+
surchargeFee: new import_decimal.default((item == null ? void 0 : item.surcharge_fee) || 0)
|
|
188
|
+
});
|
|
165
189
|
const maxDiscountedTaxPerItemPrecise = getProductItemTax(
|
|
166
190
|
{
|
|
167
191
|
...item,
|
|
@@ -184,16 +208,16 @@ var processItemsTax = (items, { bookingDetail, bookingId }, options) => {
|
|
|
184
208
|
const _originTotal = new import_decimal.default(
|
|
185
209
|
atItem.selling_price || atItem.price || 0
|
|
186
210
|
);
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
)
|
|
192
|
-
}
|
|
211
|
+
const addTimeDiscount = productExpectAmount > 0 ? _originTotal.dividedBy(productExpectAmount).times(shopDiscount) : new import_decimal.default(0);
|
|
212
|
+
const _discountedTotal = getDiscountedTaxableBase({
|
|
213
|
+
basePrice: _originTotal,
|
|
214
|
+
discount: addTimeDiscount,
|
|
215
|
+
surchargeFee: new import_decimal.default((atItem == null ? void 0 : atItem.surcharge_fee) || 0)
|
|
216
|
+
});
|
|
193
217
|
const addTimeTaxPerItemPrecise = getProductItemTax(
|
|
194
218
|
{
|
|
195
219
|
...atItem,
|
|
196
|
-
total: _discountedTotal.
|
|
220
|
+
total: _discountedTotal.toNumber(),
|
|
197
221
|
quantity: atItem.product_quantity || atItem.num || 1
|
|
198
222
|
},
|
|
199
223
|
{ bookingDetail, bookingId },
|
|
@@ -219,10 +243,15 @@ var processItemsTax = (items, { bookingDetail, bookingId }, options) => {
|
|
|
219
243
|
const bundleUnitPrice = new import_decimal.default(
|
|
220
244
|
bundleItem.bundle_selling_price ?? bundleItem.price ?? 0
|
|
221
245
|
);
|
|
246
|
+
const bundleOriginalTaxableBase = getDiscountedTaxableBase({
|
|
247
|
+
basePrice: bundleUnitPrice,
|
|
248
|
+
discount: new import_decimal.default(0),
|
|
249
|
+
surchargeFee: new import_decimal.default((bundleItem == null ? void 0 : bundleItem.surcharge_fee) || 0)
|
|
250
|
+
});
|
|
222
251
|
const bundleOriginalTaxPerItemPrecise = getProductItemTax(
|
|
223
252
|
{
|
|
224
253
|
...bundleItem,
|
|
225
|
-
total:
|
|
254
|
+
total: bundleOriginalTaxableBase.toNumber(),
|
|
226
255
|
quantity: 1
|
|
227
256
|
},
|
|
228
257
|
{ bookingDetail, bookingId },
|
|
@@ -232,7 +261,11 @@ var processItemsTax = (items, { bookingDetail, bookingId }, options) => {
|
|
|
232
261
|
if (productExpectAmount > 0) {
|
|
233
262
|
bundleItemDiscount = bundleUnitPrice.dividedBy(productExpectAmount).times(shopDiscount);
|
|
234
263
|
}
|
|
235
|
-
const bundleDiscountedUnitPrice =
|
|
264
|
+
const bundleDiscountedUnitPrice = getDiscountedTaxableBase({
|
|
265
|
+
basePrice: bundleUnitPrice,
|
|
266
|
+
discount: bundleItemDiscount,
|
|
267
|
+
surchargeFee: new import_decimal.default((bundleItem == null ? void 0 : bundleItem.surcharge_fee) || 0)
|
|
268
|
+
});
|
|
236
269
|
const bundleDiscountedTaxPerItemPrecise = getProductItemTax(
|
|
237
270
|
{
|
|
238
271
|
...bundleItem,
|
|
@@ -490,6 +523,7 @@ var isProductMatchSurchargeCondition = (item, options) => {
|
|
|
490
523
|
};
|
|
491
524
|
var getSurcharge = ({ service, addons, bookingDetail, bookingId }, options) => {
|
|
492
525
|
var _a, _b, _c;
|
|
526
|
+
debugger;
|
|
493
527
|
const { isEdit, isInScheduleByDate, surcharge_list, scheduleById } = options;
|
|
494
528
|
if (!isEdit && bookingId) {
|
|
495
529
|
if (Array.isArray(bookingDetail == null ? void 0 : bookingDetail.surcharge)) {
|
|
@@ -537,7 +571,7 @@ var getSurcharge = ({ service, addons, bookingDetail, bookingId }, options) => {
|
|
|
537
571
|
if (isProductMatchSurchargeCondition(
|
|
538
572
|
{
|
|
539
573
|
isCustomItem: item.isCustomItem,
|
|
540
|
-
startDate: (item == null ? void 0 : item.startDate) || "",
|
|
574
|
+
startDate: (item == null ? void 0 : item.startDate) || (item == null ? void 0 : item.start_date) || "",
|
|
541
575
|
product_id: item.id
|
|
542
576
|
},
|
|
543
577
|
{
|
|
@@ -569,7 +603,7 @@ var getSurcharge = ({ service, addons, bookingDetail, bookingId }, options) => {
|
|
|
569
603
|
if (getBundleItemIsOriginalPrice(bundleItem) && isProductMatchSurchargeCondition(
|
|
570
604
|
{
|
|
571
605
|
isCustomItem: false,
|
|
572
|
-
startDate: item.startDate,
|
|
606
|
+
startDate: item.startDate || item.start_date || "",
|
|
573
607
|
product_id: bundleItem._bundle_product_id
|
|
574
608
|
},
|
|
575
609
|
{
|
|
@@ -595,7 +629,7 @@ var getSurcharge = ({ service, addons, bookingDetail, bookingId }, options) => {
|
|
|
595
629
|
if (isProductMatchSurchargeCondition(
|
|
596
630
|
{
|
|
597
631
|
isCustomItem: false,
|
|
598
|
-
startDate: item.startDate,
|
|
632
|
+
startDate: item.startDate || item.start_date || "",
|
|
599
633
|
product_id: relationDetail.product_id
|
|
600
634
|
},
|
|
601
635
|
{
|
|
@@ -755,12 +789,14 @@ function resetItemsSurchargeSideEffects({ service, addons }) {
|
|
|
755
789
|
}
|
|
756
790
|
// Annotate the CommonJS export names for ESM import in node:
|
|
757
791
|
0 && (module.exports = {
|
|
792
|
+
calcDiscountListDifference,
|
|
758
793
|
calculateDeposit,
|
|
759
794
|
calculateOriginSubtotal,
|
|
760
795
|
calculatePriceDetails,
|
|
761
796
|
calculateSubtotal,
|
|
762
797
|
calculateTaxFee,
|
|
763
798
|
getBundleDiscountList,
|
|
799
|
+
getProductDiscountProductDiscountDifference,
|
|
764
800
|
getSurcharge,
|
|
765
801
|
getSurchargeAmount,
|
|
766
802
|
getTax
|
|
@@ -311,7 +311,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
311
311
|
date: string;
|
|
312
312
|
status: string;
|
|
313
313
|
week: string;
|
|
314
|
-
weekNum: 0 |
|
|
314
|
+
weekNum: 0 | 2 | 4 | 3 | 1 | 5 | 6;
|
|
315
315
|
}[]>;
|
|
316
316
|
submitTimeSlot(timeSlots: TimeSliceItem): void;
|
|
317
317
|
private getScheduleDataByIds;
|
|
@@ -1768,6 +1768,28 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1768
1768
|
newResources.forEach((resource) => {
|
|
1769
1769
|
var _a3, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
1770
1770
|
if (((_b2 = (_a3 = item._productOrigin) == null ? void 0 : _a3.duration) == null ? void 0 : _b2.type) === "flexible") {
|
|
1771
|
+
let getEarliestBlockedStartTime = function({
|
|
1772
|
+
currentStartTime: currentStartTime2,
|
|
1773
|
+
times
|
|
1774
|
+
}) {
|
|
1775
|
+
const currentStart = (0, import_dayjs.default)(currentStartTime2);
|
|
1776
|
+
let earliestBlockStart;
|
|
1777
|
+
for (const time of times || []) {
|
|
1778
|
+
for (const event of time.event_list || []) {
|
|
1779
|
+
const eventStart = (0, import_dayjs.default)(event.start_at);
|
|
1780
|
+
const eventEnd = (0, import_dayjs.default)(event.end_at);
|
|
1781
|
+
if (eventStart.isBefore(currentStart) && eventEnd.isAfter(currentStart)) {
|
|
1782
|
+
return currentStart.format("YYYY-MM-DD HH:mm");
|
|
1783
|
+
}
|
|
1784
|
+
if (eventStart.isAfter(currentStart)) {
|
|
1785
|
+
if (!earliestBlockStart || eventStart.isBefore(earliestBlockStart)) {
|
|
1786
|
+
earliestBlockStart = eventStart;
|
|
1787
|
+
}
|
|
1788
|
+
}
|
|
1789
|
+
}
|
|
1790
|
+
}
|
|
1791
|
+
return earliestBlockStart == null ? void 0 : earliestBlockStart.format("YYYY-MM-DD HH:mm");
|
|
1792
|
+
};
|
|
1771
1793
|
item.duration = {
|
|
1772
1794
|
type: "minutes",
|
|
1773
1795
|
value: 10
|
|
@@ -1782,13 +1804,22 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1782
1804
|
},
|
|
1783
1805
|
targetResourceTimes[0]
|
|
1784
1806
|
);
|
|
1807
|
+
const earliestBlockedStartTime = getEarliestBlockedStartTime({
|
|
1808
|
+
currentStartTime,
|
|
1809
|
+
times: targetResourceTimes
|
|
1810
|
+
});
|
|
1785
1811
|
const resourceDate = (0, import_dayjs.default)(resourcesEndTime.end_at).format(
|
|
1786
1812
|
"YYYY-MM-DD"
|
|
1787
1813
|
);
|
|
1788
1814
|
const operatingBoundaryDateTime = `${resourceDate} ${operating_day_boundary.type === "start_time" ? "23:59" : operating_day_boundary.time}`;
|
|
1789
|
-
const
|
|
1790
|
-
|
|
1791
|
-
|
|
1815
|
+
const endTimeCandidates = [
|
|
1816
|
+
resourcesEndTime.end_at,
|
|
1817
|
+
operatingBoundaryDateTime,
|
|
1818
|
+
...earliestBlockedStartTime ? [earliestBlockedStartTime] : []
|
|
1819
|
+
];
|
|
1820
|
+
const endTime = endTimeCandidates.reduce((earliest, value) => {
|
|
1821
|
+
return (0, import_dayjs.default)(value).isBefore((0, import_dayjs.default)(earliest)) ? value : earliest;
|
|
1822
|
+
}, endTimeCandidates[0]);
|
|
1792
1823
|
let formattedEndTime;
|
|
1793
1824
|
if (typeof endTime === "string" && endTime.includes(":") && !endTime.includes(" ") && !endTime.includes("T")) {
|
|
1794
1825
|
const currentDate = timeSlots.start_at.format("YYYY-MM-DD");
|