@pisell/pisellos 0.0.445 → 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.
@@ -148,6 +148,8 @@ export interface CartItem {
148
148
  _optionsOrigin?: any[];
149
149
  /** 操作系统提示 */
150
150
  osWarnTips?: string[];
151
+ /** 金额差值 */
152
+ totalDifference?: number;
151
153
  }
152
154
  /**
153
155
  * 购物车状态接口
@@ -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$parentProdu3;
803
- productData.parentQuantity = ((_flatItem$parentProdu3 = flatItem.parentProduct) === null || _flatItem$parentProdu3 === void 0 ? void 0 : _flatItem$parentProdu3.quantity) || 1;
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$parentProdu4;
830
+ var _flatItem$parentProdu5;
831
831
  // bundle子商品:构造虚拟商品对象
832
832
  product = {
833
- startDate: flatItem === null || flatItem === void 0 || (_flatItem$parentProdu4 = flatItem.parentProduct) === null || _flatItem$parentProdu4 === void 0 ? void 0 : _flatItem$parentProdu4.startDate,
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$parentProdu5, _flatItem$bundleItem5, _flatItem$bundleItem6, _flatItem$bundleItem7;
921
+ var _flatItem$parentProdu6, _flatItem$bundleItem5, _flatItem$bundleItem6, _flatItem$bundleItem7;
922
922
  // bundle子商品
923
923
  product = {
924
- startDate: flatItem === null || flatItem === void 0 || (_flatItem$parentProdu5 = flatItem.parentProduct) === null || _flatItem$parentProdu5 === void 0 ? void 0 : _flatItem$parentProdu5.startDate,
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$parentProdu6;
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$parentProdu6 = flatItem.parentProduct) !== null && _flatItem$parentProdu6 !== void 0 && (_flatItem$parentProdu6 = _flatItem$parentProdu6.discount_list) !== null && _flatItem$parentProdu6 !== void 0 && _flatItem$parentProdu6.some(function (item) {
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$parentProdu7;
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$parentProdu7 = flatItem.parentProduct) !== null && _flatItem$parentProdu7 !== void 0 && (_flatItem$parentProdu7 = _flatItem$parentProdu7.discount_list) !== null && _flatItem$parentProdu7 !== void 0 && _flatItem$parentProdu7.some(function (item) {
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$parentProdu8;
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$parentProdu8 = flatItem.parentProduct) === null || _flatItem$parentProdu8 === void 0 ? void 0 : _flatItem$parentProdu8.num) || 1)
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) || {}; // const scheduleModule = this.core.getModule<ScheduleModule>('appointmentBooking_schedule');
119
- summary = calculatePriceDetails(shopInfo, cartItems, ScheduleModule === null || ScheduleModule === void 0 ? void 0 : ScheduleModule.isInScheduleByDate, this.store.surchargeList);
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 4:
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[]) => Decimal | "0.00";
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 getProductDiscountProductDiscountDifference = function getProductDiscountProductDiscountDifference(item) {
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.reduce(function (pre, cur) {
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: mainProductPrice.add((item === null || item === void 0 ? void 0 : item.surcharge_fee) || 0).toNumber(),
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 = mainProductPrice.minus(mainItemDiscount).add((item === null || item === void 0 ? void 0 : item.surcharge_fee) || 0);
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 _discountedTotal = _originTotal;
299
- if (productExpectAmount > 0) {
300
- _discountedTotal = _originTotal.minus(_originTotal.dividedBy(productExpectAmount).times(shopDiscount));
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.add((atItem === null || atItem === void 0 ? void 0 : atItem.surcharge_fee) || 0).toNumber(),
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: bundleUnitPrice.add((bundleItem === null || bundleItem === void 0 ? void 0 : bundleItem.surcharge_fee) || 0).toNumber(),
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 = bundleUnitPrice.minus(bundleItemDiscount).add((bundleItem === null || bundleItem === void 0 ? void 0 : bundleItem.surcharge_fee) || 0);
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 | 1 | 2 | 3 | 4 | 5 | 6;
314
+ weekNum: 0 | 2 | 4 | 3 | 1 | 5 | 6;
315
315
  }[]>;
316
316
  submitTimeSlot(timeSlots: TimeSliceItem): void;
317
317
  private getScheduleDataByIds;
@@ -358,7 +358,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
358
358
  };
359
359
  setOtherData(key: string, value: any): void;
360
360
  getOtherData(key: string): any;
361
- getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
361
+ getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
362
362
  /**
363
363
  * 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
364
364
  *
@@ -123,7 +123,7 @@ export declare class BookingTicketImpl extends BaseModule implements Module {
123
123
  * 获取当前的客户搜索条件
124
124
  * @returns 当前搜索条件
125
125
  */
126
- getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
126
+ getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "num" | "skip">;
127
127
  /**
128
128
  * 获取客户列表状态(包含滚动加载相关状态)
129
129
  * @returns 客户状态
@@ -148,6 +148,8 @@ export interface CartItem {
148
148
  _optionsOrigin?: any[];
149
149
  /** 操作系统提示 */
150
150
  osWarnTips?: string[];
151
+ /** 金额差值 */
152
+ totalDifference?: number;
151
153
  }
152
154
  /**
153
155
  * 购物车状态接口
@@ -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 = ((_b = flatItem.parentProduct) == null ? void 0 : _b.quantity) || 1;
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 summary = (0, import_utils.calculatePriceDetails)(shopInfo, cartItems, (_c = import_Schedule.ScheduleModule) == null ? void 0 : _c.isInScheduleByDate, this.store.surchargeList);
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 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: {} });
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[]) => Decimal | "0.00";
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.reduce((pre, cur) => {
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: mainProductPrice.add((item == null ? void 0 : item.surcharge_fee) || 0).toNumber(),
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 = mainProductPrice.minus(mainItemDiscount).add((item == null ? void 0 : item.surcharge_fee) || 0);
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
- let _discountedTotal = _originTotal;
188
- if (productExpectAmount > 0) {
189
- _discountedTotal = _originTotal.minus(
190
- _originTotal.dividedBy(productExpectAmount).times(shopDiscount)
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.add((atItem == null ? void 0 : atItem.surcharge_fee) || 0).toNumber(),
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: bundleUnitPrice.add((bundleItem == null ? void 0 : bundleItem.surcharge_fee) || 0).toNumber(),
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 = bundleUnitPrice.minus(bundleItemDiscount).add((bundleItem == null ? void 0 : bundleItem.surcharge_fee) || 0);
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 | 1 | 2 | 3 | 4 | 5 | 6;
314
+ weekNum: 0 | 2 | 4 | 3 | 1 | 5 | 6;
315
315
  }[]>;
316
316
  submitTimeSlot(timeSlots: TimeSliceItem): void;
317
317
  private getScheduleDataByIds;
@@ -358,7 +358,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
358
358
  };
359
359
  setOtherData(key: string, value: any): void;
360
360
  getOtherData(key: string): any;
361
- getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
361
+ getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
362
362
  /**
363
363
  * 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
364
364
  *
@@ -123,7 +123,7 @@ export declare class BookingTicketImpl extends BaseModule implements Module {
123
123
  * 获取当前的客户搜索条件
124
124
  * @returns 当前搜索条件
125
125
  */
126
- getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
126
+ getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "num" | "skip">;
127
127
  /**
128
128
  * 获取客户列表状态(包含滚动加载相关状态)
129
129
  * @returns 客户状态
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.445",
4
+ "version": "0.0.446",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",