@pisell/pisellos 1.0.125 → 1.0.127
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/utils/changePrice.js +6 -0
- package/dist/modules/Summary/index.js +47 -5
- package/dist/modules/Summary/utils.d.ts +1 -1
- package/dist/modules/Summary/utils.js +23 -12
- package/lib/modules/Cart/utils/changePrice.js +5 -0
- package/lib/modules/Summary/index.js +22 -9
- package/lib/modules/Summary/utils.d.ts +1 -1
- package/lib/modules/Summary/utils.js +22 -13
- package/package.json +1 -1
|
@@ -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,
|
|
@@ -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
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) || {};
|
|
119
|
-
|
|
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,7 +1,7 @@
|
|
|
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
|
|
@@ -16,7 +16,9 @@ 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
|
-
|
|
19
|
+
import { isNormalProduct } from "../Product/utils";
|
|
20
|
+
import dayjs from 'dayjs';
|
|
21
|
+
export var calculatePriceDetails = function calculatePriceDetails(shopInfo, items, isInScheduleByDate, surchargeList, scheduleById) {
|
|
20
22
|
var subtotal = new Decimal(calculateSubtotal(items));
|
|
21
23
|
var subOriginTotal = new Decimal(calculateOriginSubtotal(items));
|
|
22
24
|
var totalTaxFee = new Decimal(calculateTaxFee(shopInfo, items));
|
|
@@ -30,7 +32,7 @@ export var calculatePriceDetails = function calculatePriceDetails(shopInfo, item
|
|
|
30
32
|
isEdit: false,
|
|
31
33
|
isInScheduleByDate: isInScheduleByDate,
|
|
32
34
|
surcharge_list: surchargeList,
|
|
33
|
-
scheduleById:
|
|
35
|
+
scheduleById: scheduleById
|
|
34
36
|
});
|
|
35
37
|
// 订单附加费金额
|
|
36
38
|
var surchargeAmount = new Decimal(getSurchargeAmount({
|
|
@@ -736,12 +738,8 @@ var getMainProductTotal = function getMainProductTotal(item) {
|
|
|
736
738
|
var bundleItem = _step4.value;
|
|
737
739
|
if (getBundleItemIsMarkupOrDiscountPrice(bundleItem)) {
|
|
738
740
|
var _ref10, _bundleItem$bundle_se2;
|
|
739
|
-
//
|
|
740
|
-
var
|
|
741
|
-
// 子商品价格
|
|
742
|
-
var bundleItemPrice = new Decimal((_ref10 = (_bundleItem$bundle_se2 = bundleItem.bundle_selling_price) !== null && _bundleItem$bundle_se2 !== void 0 ? _bundleItem$bundle_se2 : bundleItem.price) !== null && _ref10 !== void 0 ? _ref10 : 0);
|
|
743
|
-
// todo: 套餐子商品后不需要处理 子商品价格 - 子商品折扣金额
|
|
744
|
-
var bundleItemTotal = bundleItemPrice.minus(discountAmount);
|
|
741
|
+
// IMPORTANT: 套餐子商品如果应用了 discount,bundle_selling_price和 price 其实都已经是折后价格了,不需要单独再减一次
|
|
742
|
+
var bundleItemTotal = new Decimal((_ref10 = (_bundleItem$bundle_se2 = bundleItem.bundle_selling_price) !== null && _bundleItem$bundle_se2 !== void 0 ? _bundleItem$bundle_se2 : bundleItem.price) !== null && _ref10 !== void 0 ? _ref10 : 0);
|
|
745
743
|
total = total.add(bundleItemTotal);
|
|
746
744
|
}
|
|
747
745
|
}
|
|
@@ -862,6 +860,7 @@ var isProductMatchSurchargeCondition = function isProductMatchSurchargeCondition
|
|
|
862
860
|
* @returns 附加费列表(仅返回金额 > 0 的项)
|
|
863
861
|
*/
|
|
864
862
|
export var getSurcharge = function getSurcharge(_ref11, options) {
|
|
863
|
+
var _service$filter;
|
|
865
864
|
var service = _ref11.service,
|
|
866
865
|
addons = _ref11.addons,
|
|
867
866
|
bookingDetail = _ref11.bookingDetail,
|
|
@@ -870,6 +869,16 @@ export var getSurcharge = function getSurcharge(_ref11, options) {
|
|
|
870
869
|
isInScheduleByDate = options.isInScheduleByDate,
|
|
871
870
|
surcharge_list = options.surcharge_list,
|
|
872
871
|
scheduleById = options.scheduleById;
|
|
872
|
+
// 在所有商品里试着找 start_date,如果没有则用当前时间
|
|
873
|
+
var firstAppointmentCartItem = (_service$filter = service.filter(function (n) {
|
|
874
|
+
return !isNormalProduct(n._productOrigin);
|
|
875
|
+
})) === null || _service$filter === void 0 ? void 0 : _service$filter[0];
|
|
876
|
+
var startDate = '';
|
|
877
|
+
if (firstAppointmentCartItem) {
|
|
878
|
+
startDate = firstAppointmentCartItem.start_date + ' ' + firstAppointmentCartItem.start_time + ':00';
|
|
879
|
+
} else {
|
|
880
|
+
startDate = dayjs().format('YYYY-MM-DD HH:mm:ss');
|
|
881
|
+
}
|
|
873
882
|
// 编辑状态, 且未修改商品时直接从详情取出
|
|
874
883
|
if (!isEdit && bookingId) {
|
|
875
884
|
if (Array.isArray(bookingDetail === null || bookingDetail === void 0 ? void 0 : bookingDetail.surcharge)) {
|
|
@@ -936,7 +945,7 @@ export var getSurcharge = function getSurcharge(_ref11, options) {
|
|
|
936
945
|
// 主商品符合附加费条件
|
|
937
946
|
if (isProductMatchSurchargeCondition({
|
|
938
947
|
isCustomItem: item.isCustomItem,
|
|
939
|
-
startDate:
|
|
948
|
+
startDate: startDate,
|
|
940
949
|
product_id: item.id
|
|
941
950
|
}, {
|
|
942
951
|
surchargeConfig: surchargeConfig,
|
|
@@ -970,7 +979,7 @@ export var getSurcharge = function getSurcharge(_ref11, options) {
|
|
|
970
979
|
// bundle商品是原价且符合附加费条件
|
|
971
980
|
if (getBundleItemIsOriginalPrice(bundleItem) && isProductMatchSurchargeCondition({
|
|
972
981
|
isCustomItem: false,
|
|
973
|
-
startDate:
|
|
982
|
+
startDate: startDate,
|
|
974
983
|
product_id: bundleItem._bundle_product_id
|
|
975
984
|
}, {
|
|
976
985
|
surchargeConfig: surchargeConfig,
|
|
@@ -1002,7 +1011,7 @@ export var getSurcharge = function getSurcharge(_ref11, options) {
|
|
|
1002
1011
|
var relationDetail = _step7.value;
|
|
1003
1012
|
if (isProductMatchSurchargeCondition({
|
|
1004
1013
|
isCustomItem: false,
|
|
1005
|
-
startDate:
|
|
1014
|
+
startDate: startDate,
|
|
1006
1015
|
product_id: relationDetail.product_id
|
|
1007
1016
|
}, {
|
|
1008
1017
|
surchargeConfig: surchargeConfig,
|
|
@@ -1039,7 +1048,9 @@ export var getSurcharge = function getSurcharge(_ref11, options) {
|
|
|
1039
1048
|
try {
|
|
1040
1049
|
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
|
1041
1050
|
var _item = _step8.value;
|
|
1042
|
-
if (isProductMatchSurchargeCondition(_item, {
|
|
1051
|
+
if (isProductMatchSurchargeCondition(_objectSpread(_objectSpread({}, _item), {}, {
|
|
1052
|
+
startDate: startDate
|
|
1053
|
+
}), {
|
|
1043
1054
|
surchargeConfig: surchargeConfig,
|
|
1044
1055
|
scheduleById: scheduleById || {},
|
|
1045
1056
|
isInScheduleByDate: isInScheduleByDate
|
|
@@ -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,
|
|
@@ -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,
|
|
@@ -74,14 +74,18 @@ var SummaryModule = class extends import_BaseModule.BaseModule {
|
|
|
74
74
|
this.store.surchargeList = (surchargeList == null ? void 0 : surchargeList.data) || [];
|
|
75
75
|
}
|
|
76
76
|
async getSummary(cartItems) {
|
|
77
|
-
var _a, _b;
|
|
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
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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);
|
|
85
89
|
this.store.summary = summary;
|
|
86
90
|
return this.store.summary;
|
|
87
91
|
}
|
|
@@ -115,7 +119,16 @@ var SummaryModule = class extends import_BaseModule.BaseModule {
|
|
|
115
119
|
});
|
|
116
120
|
}
|
|
117
121
|
getSurchargeforUtils(items) {
|
|
118
|
-
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 });
|
|
119
132
|
const surchargeAmount = new import_decimal.default((0, import_utils.getSurchargeAmount)({ bookingDetail: null, bookingId: void 0 }, surchargeList, { isEdit: false }));
|
|
120
133
|
return {
|
|
121
134
|
surchargeList,
|
|
@@ -1,7 +1,7 @@
|
|
|
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
|
|
@@ -43,11 +43,13 @@ __export(utils_exports, {
|
|
|
43
43
|
});
|
|
44
44
|
module.exports = __toCommonJS(utils_exports);
|
|
45
45
|
var import_decimal = __toESM(require("decimal.js"));
|
|
46
|
-
var
|
|
46
|
+
var import_utils = require("../Product/utils");
|
|
47
|
+
var import_dayjs = __toESM(require("dayjs"));
|
|
48
|
+
var calculatePriceDetails = (shopInfo, items, isInScheduleByDate, surchargeList, scheduleById) => {
|
|
47
49
|
const subtotal = new import_decimal.default(calculateSubtotal(items));
|
|
48
50
|
const subOriginTotal = new import_decimal.default(calculateOriginSubtotal(items));
|
|
49
51
|
const totalTaxFee = new import_decimal.default(calculateTaxFee(shopInfo, items));
|
|
50
|
-
const surcharge = getSurcharge({ service: items, addons: [], bookingDetail: null, bookingId: void 0 }, { isEdit: false, isInScheduleByDate, surcharge_list: surchargeList, scheduleById
|
|
52
|
+
const surcharge = getSurcharge({ service: items, addons: [], bookingDetail: null, bookingId: void 0 }, { isEdit: false, isInScheduleByDate, surcharge_list: surchargeList, scheduleById });
|
|
51
53
|
const surchargeAmount = new import_decimal.default(getSurchargeAmount({ bookingDetail: null, bookingId: void 0 }, surcharge, { isEdit: false }));
|
|
52
54
|
const { tax, originTax } = getTax({ service: items, bookingDetail: null, bookingId: void 0 }, {
|
|
53
55
|
computed: {
|
|
@@ -456,9 +458,7 @@ var getMainProductTotal = (item) => {
|
|
|
456
458
|
}
|
|
457
459
|
for (let bundleItem of (item == null ? void 0 : item.bundle) || []) {
|
|
458
460
|
if (getBundleItemIsMarkupOrDiscountPrice(bundleItem)) {
|
|
459
|
-
const
|
|
460
|
-
const bundleItemPrice = new import_decimal.default(bundleItem.bundle_selling_price ?? bundleItem.price ?? 0);
|
|
461
|
-
const bundleItemTotal = bundleItemPrice.minus(discountAmount);
|
|
461
|
+
const bundleItemTotal = new import_decimal.default(bundleItem.bundle_selling_price ?? bundleItem.price ?? 0);
|
|
462
462
|
total = total.add(bundleItemTotal);
|
|
463
463
|
}
|
|
464
464
|
}
|
|
@@ -522,8 +522,17 @@ var isProductMatchSurchargeCondition = (item, options) => {
|
|
|
522
522
|
return isProductMatch && isScheduleMatch;
|
|
523
523
|
};
|
|
524
524
|
var getSurcharge = ({ service, addons, bookingDetail, bookingId }, options) => {
|
|
525
|
-
var _a, _b, _c;
|
|
525
|
+
var _a, _b, _c, _d;
|
|
526
526
|
const { isEdit, isInScheduleByDate, surcharge_list, scheduleById } = options;
|
|
527
|
+
const firstAppointmentCartItem = (_a = service.filter(
|
|
528
|
+
(n) => !(0, import_utils.isNormalProduct)(n._productOrigin)
|
|
529
|
+
)) == null ? void 0 : _a[0];
|
|
530
|
+
let startDate = "";
|
|
531
|
+
if (firstAppointmentCartItem) {
|
|
532
|
+
startDate = firstAppointmentCartItem.start_date + " " + firstAppointmentCartItem.start_time + ":00";
|
|
533
|
+
} else {
|
|
534
|
+
startDate = (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss");
|
|
535
|
+
}
|
|
527
536
|
if (!isEdit && bookingId) {
|
|
528
537
|
if (Array.isArray(bookingDetail == null ? void 0 : bookingDetail.surcharge)) {
|
|
529
538
|
return ((bookingDetail == null ? void 0 : bookingDetail.surcharge) || []).filter((d) => Number(d.amount) > 0).map(
|
|
@@ -570,7 +579,7 @@ var getSurcharge = ({ service, addons, bookingDetail, bookingId }, options) => {
|
|
|
570
579
|
if (isProductMatchSurchargeCondition(
|
|
571
580
|
{
|
|
572
581
|
isCustomItem: item.isCustomItem,
|
|
573
|
-
startDate
|
|
582
|
+
startDate,
|
|
574
583
|
product_id: item.id
|
|
575
584
|
},
|
|
576
585
|
{
|
|
@@ -602,7 +611,7 @@ var getSurcharge = ({ service, addons, bookingDetail, bookingId }, options) => {
|
|
|
602
611
|
if (getBundleItemIsOriginalPrice(bundleItem) && isProductMatchSurchargeCondition(
|
|
603
612
|
{
|
|
604
613
|
isCustomItem: false,
|
|
605
|
-
startDate
|
|
614
|
+
startDate,
|
|
606
615
|
product_id: bundleItem._bundle_product_id
|
|
607
616
|
},
|
|
608
617
|
{
|
|
@@ -628,7 +637,7 @@ var getSurcharge = ({ service, addons, bookingDetail, bookingId }, options) => {
|
|
|
628
637
|
if (isProductMatchSurchargeCondition(
|
|
629
638
|
{
|
|
630
639
|
isCustomItem: false,
|
|
631
|
-
startDate
|
|
640
|
+
startDate,
|
|
632
641
|
product_id: relationDetail.product_id
|
|
633
642
|
},
|
|
634
643
|
{
|
|
@@ -640,7 +649,7 @@ var getSurcharge = ({ service, addons, bookingDetail, bookingId }, options) => {
|
|
|
640
649
|
matchedItems.push({
|
|
641
650
|
isMain: false,
|
|
642
651
|
total: Number(
|
|
643
|
-
(relationDetail == null ? void 0 : relationDetail.price) || ((
|
|
652
|
+
(relationDetail == null ? void 0 : relationDetail.price) || ((_b = relationDetail == null ? void 0 : relationDetail.metadata) == null ? void 0 : _b.main_product_attached_bundle_selling_price)
|
|
644
653
|
),
|
|
645
654
|
quantity: relationDetail.num || relationDetail.quantity || 1,
|
|
646
655
|
item: relationDetail,
|
|
@@ -653,7 +662,7 @@ var getSurcharge = ({ service, addons, bookingDetail, bookingId }, options) => {
|
|
|
653
662
|
}
|
|
654
663
|
if (Array.isArray(addons == null ? void 0 : addons.value)) {
|
|
655
664
|
for (let item of addons.value) {
|
|
656
|
-
if (isProductMatchSurchargeCondition(item, {
|
|
665
|
+
if (isProductMatchSurchargeCondition({ ...item, startDate }, {
|
|
657
666
|
surchargeConfig,
|
|
658
667
|
scheduleById: scheduleById || {},
|
|
659
668
|
isInScheduleByDate
|
|
@@ -714,13 +723,13 @@ var getSurcharge = ({ service, addons, bookingDetail, bookingId }, options) => {
|
|
|
714
723
|
const surchargeFee = originSurchargeFee.plus(itemSurcharge).plus(fixedSurcharge).toDecimalPlaces(2, import_decimal.default.ROUND_DOWN).toNumber();
|
|
715
724
|
productTotalSurcharge = productTotalSurcharge.plus(new import_decimal.default(surchargeFee).times(itemQuantity).toNumber());
|
|
716
725
|
item.item.surcharge_fee = surchargeFee;
|
|
717
|
-
item.item.relation_surcharge_ids = [...((
|
|
726
|
+
item.item.relation_surcharge_ids = [...((_c = item.item) == null ? void 0 : _c.relation_surcharge_ids) || [], id];
|
|
718
727
|
} else {
|
|
719
728
|
const originSurchargeFee = new import_decimal.default(item.item.surcharge_fee || 0);
|
|
720
729
|
const surchargeFee = originSurchargeFee.plus(itemSurcharge).plus(fixedSurcharge).toDecimalPlaces(2, import_decimal.default.ROUND_DOWN).toNumber();
|
|
721
730
|
productTotalSurcharge = productTotalSurcharge.plus(new import_decimal.default(surchargeFee).times(itemQuantity).toNumber());
|
|
722
731
|
item.item.surcharge_fee = surchargeFee;
|
|
723
|
-
item.item.relation_surcharge_ids = [...((
|
|
732
|
+
item.item.relation_surcharge_ids = [...((_d = item.item) == null ? void 0 : _d.relation_surcharge_ids) || [], id];
|
|
724
733
|
}
|
|
725
734
|
}
|
|
726
735
|
if (isLast && configTotal.minus(productTotalSurcharge).gt(0)) {
|